Skip to content

Commit

Permalink
fix vercel#1505 and add test (vercel#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
kldzj authored Feb 12, 2022
1 parent 72bc8b3 commit 64774c5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prelude/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1679,12 +1679,12 @@ function payloadFileSync(pointer) {
// this one use promisify on purpose
fs.promises.readdir = util.promisify(fs.readdir);
fs.promises.copyFile = util.promisify(fs.copyFile);
fs.promises.stat = util.promisify(fs.stat);
fs.promises.lstat = util.promisify(fs.lstat);

/*
fs.promises.read = util.promisify(fs.read);
fs.promises.realpath = util.promisify(fs.realpath);
fs.promises.stat = util.promisify(fs.stat);
fs.promises.lstat = util.promisify(fs.lstat);
fs.promises.fstat = util.promisify(fs.fstat);
fs.promises.access = util.promisify(fs.access);
*/
Expand Down
1 change: 1 addition & 0 deletions test/test-1505/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run-time
Empty file added test/test-1505/files/test.txt
Empty file.
29 changes: 29 additions & 0 deletions test/test-1505/main.js
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));
6 changes: 6 additions & 0 deletions test/test-1505/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"bin": "stat.js",
"pkg": {
"scripts": "files/*"
}
}
32 changes: 32 additions & 0 deletions test/test-1505/stat.js
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();

0 comments on commit 64774c5

Please sign in to comment.