forked from vercel/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
70 additions
and
2 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 |
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,29 @@ | ||
#!/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 = './stat.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": "stat.js", | ||
"pkg": { | ||
"scripts": "files/*" | ||
} | ||
} |
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'; | ||
|
||
const path = require('path'); | ||
const util = require('util'); | ||
const fs = require('fs'); | ||
let fsp; | ||
|
||
try { | ||
fsp = require('fs/promises'); | ||
} catch (_) { | ||
fsp = require('fs').promises; | ||
} | ||
|
||
const filePath = path.join(__dirname, 'files/test.txt'); | ||
|
||
async function test() { | ||
for (const key of ['stat', 'lstat']) { | ||
console.log(key, 'callback'); | ||
const promisified = util.promisify(fs[key]); | ||
console.log(serialize(await promisified(filePath))); | ||
|
||
console.log(key, 'promise'); | ||
console.log(serialize(await fsp[key](filePath))); | ||
} | ||
} | ||
|
||
function serialize(result) { | ||
if (!result) return null; | ||
return `${result.size} ${result.mode}`; | ||
} | ||
|
||
test(); |