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 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
182 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
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 @@ | ||
run-time |
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,3 @@ | ||
'use strict'; | ||
|
||
module.exports = {}; |
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,3 @@ | ||
'use strict'; | ||
|
||
module.exports = {}; |
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,32 @@ | ||
#!/usr/bin/env node | ||
|
||
// Thanks to @roberttod | ||
// https://github.com/vercel/pkg/blob/59b1afdb39613777150c17f77b45595864ba072e/test/test-1103-readdirsync-withfiletypes/main.js | ||
|
||
'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, '--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,32 @@ | ||
'use strict'; | ||
|
||
// Thanks to @roberttod | ||
// https://github.com/vercel/pkg/blob/59b1afdb39613777150c17f77b45595864ba072e/test/test-1103-readdirsync-withfiletypes/read.js | ||
|
||
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()}`); | ||
} |
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 @@ | ||
run-time |
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,25 @@ | ||
#!/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, '--output', output, '.']); | ||
|
||
let right; | ||
right = utils.spawn.sync(output, [], { | ||
cwd: path.dirname(input), | ||
}); | ||
|
||
assert.strictEqual('ok\n', 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,3 @@ | ||
{ | ||
"bin": "read.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,35 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
function isLastEntryString(files) { | ||
const last = files[files.length - 1]; | ||
return typeof last === 'string'; | ||
} | ||
|
||
function isLastEntryDirent(files) { | ||
const last = files[files.length - 1]; | ||
return ( | ||
typeof last === 'object' && | ||
typeof last.name === 'string' && | ||
typeof last.type === 'number' | ||
); | ||
} | ||
|
||
// readdir root and verify that last pushed entry (snapshot in the binary) has the expected type | ||
|
||
// expect Dirent array | ||
const a = fs.readdirSync('/', { encoding: 'utf8', withFileTypes: true }); | ||
fs.readdir('/', { encoding: 'utf8', withFileTypes: true }, (err, b) => { | ||
if (err) throw err; | ||
if (isLastEntryDirent(a) && isLastEntryDirent(b)) { | ||
// expect string array | ||
const c = fs.readdirSync('/', { encoding: 'utf8', withFileTypes: false }); | ||
fs.readdir('/', { encoding: 'utf8', withFileTypes: false }, (err_, d) => { | ||
if (err_) throw err_; | ||
if (isLastEntryString(c) && isLastEntryString(d)) { | ||
console.log('ok'); | ||
} | ||
}); | ||
} | ||
}); |
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