-
-
Notifications
You must be signed in to change notification settings - Fork 15
Convert codebase to ESM, mostly #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"$schema": "https://unpkg.com/knip@5/schema.json", | ||
"entry": ["lib/index.js", "bin/*/*.js", "test-workspace/tasks/*.js"], | ||
"entry": ["lib/cjs.cjs", "lib/esm.mjs", "bin/*/*.js", "test-workspace/tasks/*.cjs"], | ||
"ignoreDependencies": ["yarn", "spec"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ $ npm install npm-run-all2 --save-dev | |
$ yarn add npm-run-all2 --dev | ||
``` | ||
|
||
- It requires `Node@>=14`. It may work on older versions of Node, but no guarantees are given. | ||
- It requires `Node@>=22`. It may work on older versions of Node, but no guarantees are given. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
## 📖 Usage | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,34 +3,38 @@ | |||||
* @copyright 2016 Toru Nagashima. All rights reserved. | ||||||
* See LICENSE file in root directory for full license. | ||||||
*/ | ||||||
'use strict' | ||||||
|
||||||
// ------------------------------------------------------------------------------ | ||||||
// Public Interface | ||||||
// ------------------------------------------------------------------------------ | ||||||
|
||||||
module.exports = function bootstrap (name) { | ||||||
export default async function bootstrap (name) { | ||||||
const argv = process.argv.slice(2) | ||||||
|
||||||
switch (argv[0]) { | ||||||
case undefined: | ||||||
case '-h': | ||||||
case '--help': | ||||||
return require(`../${name}/help`)(process.stdout) | ||||||
case '--help': { | ||||||
const help = await import(`../${name}/help.js`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would do this instead:
Suggested change
Makes it more clear that it's only the |
||||||
return help.default(process.stdout) | ||||||
} | ||||||
|
||||||
case '-v': | ||||||
case '--version': | ||||||
return require('./version')(process.stdout) | ||||||
case '--version': { | ||||||
const version = await import('./version.js') | ||||||
return version.default(process.stdout) | ||||||
} | ||||||
|
||||||
default: | ||||||
default: { | ||||||
// https://github.com/mysticatea/npm-run-all/issues/105 | ||||||
// Avoid MaxListenersExceededWarnings. | ||||||
process.stdout.setMaxListeners(0) | ||||||
process.stderr.setMaxListeners(0) | ||||||
process.stdin.setMaxListeners(0) | ||||||
|
||||||
// Main | ||||||
return require(`../${name}/main`)( | ||||||
const main = await import(`../${name}/main.js`) | ||||||
return main.default( | ||||||
argv, | ||||||
process.stdout, | ||||||
process.stderr | ||||||
|
@@ -44,5 +48,6 @@ module.exports = function bootstrap (name) { | |||||
process.exit(1) | ||||||
} | ||||||
) | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,21 +3,30 @@ | |||||
* @copyright 2016 Toru Nagashima. All rights reserved. | ||||||
* See LICENSE file in root directory for full license. | ||||||
*/ | ||||||
'use strict' | ||||||
|
||||||
// ------------------------------------------------------------------------------ | ||||||
// Public Interface | ||||||
// ------------------------------------------------------------------------------ | ||||||
|
||||||
import { readFile } from 'fs/promises' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would do
Suggested change
|
||||||
import { fileURLToPath } from 'url' | ||||||
import { dirname, resolve } from 'path' | ||||||
|
||||||
const __filename = fileURLToPath(import.meta.url) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use |
||||||
const __dirname = dirname(__filename) | ||||||
|
||||||
/** | ||||||
* Print a version text. | ||||||
* | ||||||
* @param {stream.Writable} output - A writable stream to print. | ||||||
* @returns {Promise} Always a fulfilled promise. | ||||||
* @private | ||||||
*/ | ||||||
module.exports = function printVersion (output) { | ||||||
const version = require('../../package.json').version | ||||||
export default async function printVersion (output) { | ||||||
const packageJson = JSON.parse( | ||||||
await readFile(resolve(__dirname, '../../package.json'), 'utf8') | ||||||
) | ||||||
const version = packageJson.version | ||||||
|
||||||
output.write(`v${version}\n`) | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
'use strict' | ||
import neostandard from 'neostandard' | ||
|
||
module.exports = [ | ||
...require('neostandard')({ | ||
env: ['node', 'mocha'], | ||
ignores: require('neostandard').resolveIgnoresFromGitignore(), | ||
export default [ | ||
...neostandard({ | ||
ignores: neostandard.resolveIgnoresFromGitignore(), | ||
ts: true, | ||
}), | ||
] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||
const { default: npmRunAll } = require('./esm.mjs') | ||||||
|
||||||
// Didn't manage to get this ito the last breaking change, so adding a cjs as the primary export | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the spelling of 'ito' to 'into'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
// maintiains a compatible layer for cjs consumers. If we export esm by default, the best cjs can | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the typo 'maintiains' to 'maintains'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
// get is a default exoport field (breaking). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the spelling of 'exoport' to 'export'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
// | ||||||
// TODO: Next breaking change, drop this file in favor of a named ESM export. | ||||||
// | ||||||
// ESM consumers can import 'npm-run-all2/esm.js' directly if they want to bypass this indirect. | ||||||
module.exports = npmRunAll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README states
Node@>=22
, butpackage.json
engines allow^20.5.0
. Update the README to match the supported Node versions (>=20.5.0).Copilot uses AI. Check for mistakes.