Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Fix readdirSync when using withFileTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtod committed Aug 27, 2021
1 parent 09c3f21 commit 36ceb58
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 24 deletions.
51 changes: 27 additions & 24 deletions prelude/bootstrap.js
Expand Up @@ -1145,7 +1145,7 @@ function payloadFileSync(pointer) {

const options = readdirOptions(options_, false);

if (!options || options.withFileTypes) {
if (!options) {
return ancestor.readdirSync.apply(fs, arguments);
}

Expand All @@ -1166,7 +1166,7 @@ function payloadFileSync(pointer) {

const options = readdirOptions(options_, true);

if (!options || options.withFileTypes) {
if (!options) {
return ancestor.readdir.apply(fs, arguments);
}

Expand Down Expand Up @@ -1969,29 +1969,31 @@ function payloadFileSync(pointer) {
// CHILD_PROCESS ///////////////////////////////////////////////
// /////////////////////////////////////////////////////////////

const customPromiseExecFunction = (o) => (...args) => {
let resolve;
let reject;
const p = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
const customPromiseExecFunction =
(o) =>
(...args) => {
let resolve;
let reject;
const p = new Promise((res, rej) => {
resolve = res;
reject = rej;
});

p.child = o.apply(
undefined,
args.concat((error, stdout, stderr) => {
if (error !== null) {
error.stdout = stdout;
error.stderr = stderr;
reject(error);
} else {
resolve({ stdout, stderr });
}
})
);
p.child = o.apply(
undefined,
args.concat((error, stdout, stderr) => {
if (error !== null) {
error.stdout = stdout;
error.stderr = stderr;
reject(error);
} else {
resolve({ stdout, stderr });
}
})
);

return p;
};
return p;
};

Object.defineProperty(childProcess.exec, custom, {
value: customPromiseExecFunction(childProcess.exec),
Expand Down Expand Up @@ -2020,7 +2022,8 @@ function payloadFileSync(pointer) {
const modulePath = revertMakingLong(args[1]);
const moduleBaseName = path.basename(modulePath);
const moduleFolder = path.dirname(modulePath);
const unknownModuleErrorRegex = /([^:]+): cannot open shared object file: No such file or directory/;
const unknownModuleErrorRegex =
/([^:]+): cannot open shared object file: No such file or directory/;

function tryImporting(_tmpFolder, previousErrorMessage) {
try {
Expand Down
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions test/test-1103-readdirsync-withfiletypes/main.js
@@ -0,0 +1,37 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

const target = process.argv[2] || 'host';
const input = './read.js';
const output = './run-time/test-output.exe';

utils.mkdirp.sync(path.dirname(output));
utils.pkg.sync([
'--target',
target,
'--assets',
'files/*.js',
'--output',
output,
'.',
]);

let left, right;
left = utils.spawn.sync('node', [path.basename(input)], {
cwd: path.dirname(input),
});

right = utils.spawn.sync(output, [], {
cwd: path.dirname(input),
});

assert.strictEqual(left, right);
utils.vacuum.sync(path.dirname(output));
6 changes: 6 additions & 0 deletions test/test-1103-readdirsync-withfiletypes/package.json
@@ -0,0 +1,6 @@
{
"bin": "read.js",
"pkg": {
"scripts": "files/*.js"
}
}
25 changes: 25 additions & 0 deletions test/test-1103-readdirsync-withfiletypes/read.js
@@ -0,0 +1,25 @@
'use strict';

const fs = require('fs');
const path = require('path');

console.log(process.version);

console.log('Starting sync read');

console.log(
fs.readdirSync(path.join(__dirname, 'files'), { withFileTypes: true })
);

console.log('Finishing sync read');

console.log('Starting async read');

fs.readdir(
path.join(__dirname, 'files'),
{ withFileTypes: true },
(_err, files) => {
console.log(files);
console.log('Finishing async read');
}
);

0 comments on commit 36ceb58

Please sign in to comment.