This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix readdirSync when using withFileTypes
- When withFileTypes options is passed fs.readdir should be bootstrapped else it won't read from the snapshot
- Loading branch information
rtod
committed
Aug 27, 2021
1 parent
09c3f21
commit 83d103a
Showing
6 changed files
with
99 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"bin": "read.js", | ||
"pkg": { | ||
"scripts": "files/*.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
console.log('Starting sync read'); | ||
|
||
console.log( | ||
serializeFiles( | ||
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(serializeFiles(files)); | ||
console.log('Finishing async read'); | ||
} | ||
); | ||
|
||
function serializeFiles(files) { | ||
return files.map((file) => `name: ${file.name}, isFile: ${file.isFile()}`); | ||
} |