|
1 | 1 | const { fork } = require('child_process'); |
2 | 2 | const filewatcher = require('filewatcher'); |
3 | | -const { extname } = require('path'); |
4 | 3 | const semver = require('semver'); |
5 | | -const getPackageType = require('get-package-type'); |
| 4 | +const { pathToFileURL } = require('url'); |
6 | 5 |
|
7 | 6 | const { clearFactory } = require('./clear'); |
8 | 7 | const { configureDeps, configureIgnore } = require('./ignore'); |
@@ -55,8 +54,6 @@ module.exports = function ( |
55 | 54 | const isIgnored = configureIgnore(ignore); |
56 | 55 | const isTooDeep = configureDeps(deps); |
57 | 56 |
|
58 | | - const wrapper = resolveMain(localPath('wrap.js')); |
59 | | - |
60 | 57 | // Run ./dedupe.js as preload script |
61 | 58 | if (dedupe) process.env.NODE_DEV_PRELOAD = localPath('dedupe'); |
62 | 59 |
|
@@ -96,27 +93,24 @@ module.exports = function ( |
96 | 93 |
|
97 | 94 | const args = nodeArgs.slice(); |
98 | 95 |
|
99 | | - if (extname(script) === '.mjs' || getPackageType.sync(script) === 'module') { |
100 | | - if (semver.satisfies(process.version, '>=10 <12.11.1')) { |
101 | | - const resolveLoader = resolveMain(localPath('resolve-loader.mjs')); |
102 | | - args.push('--experimental-modules', `--loader=${resolveLoader}`); |
103 | | - } else if (semver.satisfies(process.version, '>=12.11.1')) { |
104 | | - if (semver.satisfies(process.version, '<12.17.0')) { |
105 | | - args.push('--experimental-modules'); |
106 | | - } |
107 | | - const loaderPath = semver.satisfies(process.version, '>=16.12.0') |
108 | | - ? 'load-loader.mjs' |
109 | | - : 'get-source-loader.mjs'; |
110 | | - const experimentalLoader = resolveMain(localPath(loaderPath)); |
111 | | - args.push(`--experimental-loader=${experimentalLoader}`); |
112 | | - } |
| 96 | + args.push(`--require=${resolveMain(localPath('wrap'))}`); |
| 97 | + const loaderPath = semver.satisfies(process.version, '<16.12.0') |
| 98 | + ? 'loader-legacy.mjs' |
| 99 | + : 'loader.mjs'; |
| 100 | + const loader = pathToFileURL(resolveMain(localPath(loaderPath))); |
| 101 | + if (semver.satisfies(process.version, '<12.17.0')) { |
| 102 | + args.push('--experimental-modules'); |
| 103 | + } |
| 104 | + if (semver.satisfies(process.version, '<12.11.1')) { |
| 105 | + args.push(`--loader=${loader.href}`); |
| 106 | + } else { |
| 107 | + args.push(`--experimental-loader=${loader.href}`); |
113 | 108 | } |
114 | 109 |
|
115 | | - const cmd = args.concat(wrapper, script, scriptArgs); |
116 | | - |
117 | | - child = fork(cmd[0], cmd.slice(1), { |
| 110 | + child = fork(script, scriptArgs, { |
118 | 111 | cwd: process.cwd(), |
119 | | - env: process.env |
| 112 | + env: process.env, |
| 113 | + execArgv: args |
120 | 114 | }); |
121 | 115 |
|
122 | 116 | if (respawn) { |
|
0 commit comments