Skip to content

Commit 6ccb355

Browse files
committed
Convert codebase to mostly ESM
1 parent af75f95 commit 6ccb355

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+274
-293
lines changed

.knip.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"$schema": "https://unpkg.com/knip@5/schema.json",
3-
"entry": ["lib/index.js", "bin/*/*.js", "test-workspace/tasks/*.js"],
3+
"entry": ["lib/index.js", "bin/*/*.js", "test-workspace/tasks/*.cjs"],
44
"ignoreDependencies": ["yarn", "spec"]
55
}

bin/common/bootstrap.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Public Interface
109
// ------------------------------------------------------------------------------
1110

12-
module.exports = function bootstrap (name) {
11+
export default async function bootstrap (name) {
1312
const argv = process.argv.slice(2)
1413

1514
switch (argv[0]) {
1615
case undefined:
1716
case '-h':
18-
case '--help':
19-
return require(`../${name}/help`)(process.stdout)
17+
case '--help': {
18+
const help = await import(`../${name}/help.js`)
19+
return help.default(process.stdout)
20+
}
2021

2122
case '-v':
22-
case '--version':
23-
return require('./version')(process.stdout)
23+
case '--version': {
24+
const version = await import('./version.js')
25+
return version.default(process.stdout)
26+
}
2427

25-
default:
28+
default: {
2629
// https://github.com/mysticatea/npm-run-all/issues/105
2730
// Avoid MaxListenersExceededWarnings.
2831
process.stdout.setMaxListeners(0)
2932
process.stderr.setMaxListeners(0)
3033
process.stdin.setMaxListeners(0)
3134

3235
// Main
33-
return require(`../${name}/main`)(
36+
const main = await import(`../${name}/main.js`)
37+
return main.default(
3438
argv,
3539
process.stdout,
3640
process.stderr
@@ -44,5 +48,6 @@ module.exports = function bootstrap (name) {
4448
process.exit(1)
4549
}
4650
)
51+
}
4752
}
4853
}

bin/common/parse-cli-args.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Helpers
@@ -238,6 +237,6 @@ function parseCLIArgsCore (set, args) {
238237
* @param {boolean} options.singleMode - The flag to be single group mode.
239238
* @returns {ArgumentSet} The parsed CLI arguments.
240239
*/
241-
module.exports = function parseCLIArgs (args, initialValues, options) {
240+
export default function parseCLIArgs (args, initialValues, options) {
242241
return parseCLIArgsCore(new ArgumentSet(initialValues, options), args)
243242
}

bin/common/version.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Public Interface
109
// ------------------------------------------------------------------------------
1110

11+
import { readFile } from 'fs/promises'
12+
import { fileURLToPath } from 'url'
13+
import { dirname, resolve } from 'path'
14+
15+
const __filename = fileURLToPath(import.meta.url)
16+
const __dirname = dirname(__filename)
17+
1218
/**
1319
* Print a version text.
1420
*
1521
* @param {stream.Writable} output - A writable stream to print.
1622
* @returns {Promise} Always a fulfilled promise.
1723
* @private
1824
*/
19-
module.exports = function printVersion (output) {
20-
const version = require('../../package.json').version
25+
export default async function printVersion (output) {
26+
const packageJson = JSON.parse(
27+
await readFile(resolve(__dirname, '../../package.json'), 'utf8')
28+
)
29+
const version = packageJson.version
2130

2231
output.write(`v${version}\n`)
2332

bin/npm-run-all/help.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @copyright 2015 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Public Interface
@@ -16,7 +15,7 @@
1615
* @returns {Promise} Always a fulfilled promise.
1716
* @private
1817
*/
19-
module.exports = function printHelp (output) {
18+
export default function printHelp (output) {
2019
output.write(`
2120
Usage:
2221
$ npm-run-all [--help | -h | --version | -v]

bin/npm-run-all/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* @copyright 2015 Toru Nagashima. All rights reserved.
55
* See LICENSE file in root directory for full license.
66
*/
7-
'use strict'
87

98
// ------------------------------------------------------------------------------
109
// Main
1110
// ------------------------------------------------------------------------------
1211

13-
require('../common/bootstrap')('npm-run-all')
12+
import bootstrap from '../common/bootstrap.js'
13+
14+
bootstrap('npm-run-all')

bin/npm-run-all/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* @copyright 2015 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Requirements
109
// ------------------------------------------------------------------------------
1110

12-
const runAll = require('../../lib')
13-
const parseCLIArgs = require('../common/parse-cli-args')
11+
import runAll from '../../lib/index.js'
12+
import parseCLIArgs from '../common/parse-cli-args.js'
1413

1514
// ------------------------------------------------------------------------------
1615
// Public Interface
@@ -25,7 +24,7 @@ const parseCLIArgs = require('../common/parse-cli-args')
2524
* @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed.
2625
* @private
2726
*/
28-
module.exports = function npmRunAll (args, stdout, stderr) {
27+
export default function npmRunAll (args, stdout, stderr) {
2928
try {
3029
const stdin = process.stdin
3130
const argv = parseCLIArgs(args)

bin/run-p/help.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Public Interface
@@ -16,7 +15,7 @@
1615
* @returns {Promise} Always a fulfilled promise.
1716
* @private
1817
*/
19-
module.exports = function printHelp (output) {
18+
export default function printHelp (output) {
2019
output.write(`
2120
Usage:
2221
$ run-p [--help | -h | --version | -v]

bin/run-p/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* @copyright 2015 Toru Nagashima. All rights reserved.
55
* See LICENSE file in root directory for full license.
66
*/
7-
'use strict'
87

98
// ------------------------------------------------------------------------------
109
// Main
1110
// ------------------------------------------------------------------------------
1211

13-
require('../common/bootstrap')('run-p')
12+
import bootstrap from '../common/bootstrap.js'
13+
14+
bootstrap('run-p')

bin/run-p/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Requirements
109
// ------------------------------------------------------------------------------
1110

12-
const runAll = require('../../lib')
13-
const parseCLIArgs = require('../common/parse-cli-args')
11+
import runAll from '../../lib/index.js'
12+
import parseCLIArgs from '../common/parse-cli-args.js'
1413

1514
// ------------------------------------------------------------------------------
1615
// Public Interface
@@ -25,7 +24,7 @@ const parseCLIArgs = require('../common/parse-cli-args')
2524
* @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed.
2625
* @private
2726
*/
28-
module.exports = function npmRunAll (args, stdout, stderr) {
27+
export default function npmRunAll (args, stdout, stderr) {
2928
try {
3029
const stdin = process.stdin
3130
const argv = parseCLIArgs(args, { parallel: true }, { singleMode: true })

bin/run-s/help.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Public Interface
@@ -16,7 +15,7 @@
1615
* @returns {Promise} Always a fulfilled promise.
1716
* @private
1817
*/
19-
module.exports = function printHelp (output) {
18+
export default function printHelp (output) {
2019
output.write(`
2120
Usage:
2221
$ run-s [--help | -h | --version | -v]

bin/run-s/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* @copyright 2015 Toru Nagashima. All rights reserved.
55
* See LICENSE file in root directory for full license.
66
*/
7-
'use strict'
87

98
// ------------------------------------------------------------------------------
109
// Main
1110
// ------------------------------------------------------------------------------
1211

13-
require('../common/bootstrap')('run-s')
12+
import bootstrap from '../common/bootstrap.js'
13+
14+
bootstrap('run-s')

bin/run-s/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* @copyright 2016 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
'use strict'
76

87
// ------------------------------------------------------------------------------
98
// Requirements
109
// ------------------------------------------------------------------------------
1110

12-
const runAll = require('../../lib')
13-
const parseCLIArgs = require('../common/parse-cli-args')
11+
import runAll from '../../lib/index.js'
12+
import parseCLIArgs from '../common/parse-cli-args.js'
1413

1514
// ------------------------------------------------------------------------------
1615
// Public Interface
@@ -25,7 +24,7 @@ const parseCLIArgs = require('../common/parse-cli-args')
2524
* @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed.
2625
* @private
2726
*/
28-
module.exports = function npmRunAll (args, stdout, stderr) {
27+
export default function npmRunAll (args, stdout, stderr) {
2928
try {
3029
const stdin = process.stdin
3130
const argv = parseCLIArgs(args, { parallel: false }, { singleMode: true })

eslint.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
'use strict'
1+
import neostandard from 'neostandard'
22

3-
module.exports = [
4-
...require('neostandard')({
3+
export default [
4+
...neostandard({
55
env: ['node', 'mocha'],
6-
ignores: require('neostandard').resolveIgnoresFromGitignore(),
6+
ignores: neostandard.resolveIgnoresFromGitignore(),
77
ts: true,
88
}),
99
]

lib/create-header.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @copyright 2016 Toru Nagashima. All rights reserved.
55
* See LICENSE file in root directory for full license.
66
*/
7-
'use strict'
87

98
// ------------------------------------------------------------------------------
109
// Public Interface
@@ -20,7 +19,7 @@
2019
* @param {boolean} isTTY - The flag to color the header.
2120
* @returns {string} The header of a given task.
2221
*/
23-
module.exports = function createHeader (nameAndArgs, packageInfo, isTTY, ansiStyles) {
22+
export default function createHeader (nameAndArgs, packageInfo, isTTY, ansiStyles) {
2423
if (!packageInfo) {
2524
return `\n> ${nameAndArgs}\n\n`
2625
}

lib/create-prefix-transform-stream.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
* @copyright 2016 Toru Nagashima. All rights reserved.
55
* See LICENSE file in root directory for full license.
66
*/
7-
'use strict'
87

98
// ------------------------------------------------------------------------------
109
// Requirements
1110
// ------------------------------------------------------------------------------
1211

13-
const stream = require('stream')
12+
import stream from 'stream'
1413

1514
// ------------------------------------------------------------------------------
1615
// Helpers
@@ -86,6 +85,6 @@ class PrefixTransform extends stream.Transform {
8685
* @param {boolean} state.lastIsLinebreak -The flag to check whether the last output is a line break or not.
8786
* @returns {stream.Transform} The created transform stream.
8887
*/
89-
module.exports = function createPrefixTransform (prefix, state) {
88+
export default function createPrefixTransform (prefix, state) {
9089
return new PrefixTransform(prefix, state)
9190
}

0 commit comments

Comments
 (0)