-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Pull latest code from upstream * vendor in more of `internal/error` * tests are passing (!) * revert unnecessary primordials changes * Patch for Node.js v14.x * fix test * default to --test if no other flag is detected * Update nodejs/node HEAD sha * fixup! Update nodejs/node HEAD sha * add proper support for `--test-only`, separate entry point from Node.js code * remove unnecessary hack * add support for ESM entry point and TLA (if available) * read bin path from `package.json` * separate bin in two files: `node-core-test` and `node--test` * add noop files to match more closely the node implementation
- Loading branch information
Showing
50 changed files
with
1,527 additions
and
2,271 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,7 @@ | ||
#!/usr/bin/env node | ||
|
||
const { argv } = require('#internal/options') | ||
|
||
argv.test = true | ||
|
||
require('./node-core-test.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,81 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
|
||
const Module = require('node:module') | ||
const path = require('node:path') | ||
const { pathToFileURL } = require('node:url') | ||
const minimist = require('minimist') | ||
|
||
const { argv } = require('#internal/options') | ||
|
||
Object.assign(argv, minimist(process.argv.slice(2), { | ||
boolean: ['test', 'test-only'], | ||
default: Object.prototype.hasOwnProperty.call(argv, 'test') ? { test: argv.test } : undefined | ||
})) | ||
|
||
process.argv.splice(1, Infinity, ...argv._) | ||
if (argv.test) { | ||
require('#internal/main/test_runner') | ||
} else { | ||
const entryPointPath = path.resolve(argv._[0]) | ||
try { | ||
loadMainModule(entryPointPath) | ||
} catch (err) { | ||
if (err.code !== 'ERR_REQUIRE_ESM') throw err | ||
|
||
// Override process exit code logic to handle TLA: | ||
|
||
let shouldOverwriteExitCode = true | ||
const { exit: originalExitFunction } = process | ||
process.exit = function exit (code) { | ||
if (code === undefined && shouldOverwriteExitCode) { | ||
process.exitCode = 0 | ||
} | ||
Reflect.apply(originalExitFunction, process, arguments) | ||
} | ||
Object.defineProperty(process, 'exitCode', { | ||
get: () => 13, | ||
set (val) { | ||
shouldOverwriteExitCode = false | ||
delete process.exitCode | ||
process.exitCode = val | ||
}, | ||
configurable: true, | ||
enumerable: true | ||
}) | ||
|
||
// Import module | ||
|
||
import(pathToFileURL(entryPointPath)).then(() => { | ||
if (shouldOverwriteExitCode) process.exitCode = 0 | ||
}, (err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Loads a module as a main module, enabling the `require.main === module` pattern. | ||
* https://github.com/nodejs/corepack/blob/5ff6e82028e58448ba5ba986854b61ecdc69885b/sources/nodeUtils.ts#L24 | ||
*/ | ||
function loadMainModule (id) { | ||
const modulePath = Module._resolveFilename(id, null, true) | ||
|
||
const module = new Module(modulePath, undefined) | ||
|
||
module.filename = modulePath | ||
module.paths = Module._nodeModulePaths(path.dirname(modulePath)) | ||
|
||
Module._cache[modulePath] = module | ||
|
||
process.mainModule = module | ||
module.id = '.' | ||
|
||
try { | ||
return module.load(modulePath) | ||
} catch (error) { | ||
delete Module._cache[modulePath] | ||
throw error | ||
} | ||
} |
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,3 @@ | ||
'use strict' | ||
|
||
module.exports = require('assert') |
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,5 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
prepareMainThreadExecution () {} | ||
} |
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 = console |
Oops, something went wrong.