Skip to content

Commit 9875cdb

Browse files
committed
fix: cjs wrap
1 parent f845ced commit 9875cdb

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default (script: string, scriptArgs: string[], nodeArgs: string[], {
8989

9090
const args = nodeArgs.slice()
9191

92-
args.push(`--require=${resolveMain(localPath('wrap'))}`)
92+
args.push(`--require=${resolveMain(localPath('wrap.cjs'))}`)
9393

9494
if (!semver.satisfies(process.version, '>=21.0.0')) {
9595
const loaderURL = pathToFileURL(resolveMain(localPath(join('loaders', 'load.js'))))

src/wrap.ts renamed to src/wrap.cts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import childProcess from 'child_process'
2-
import { createRequire, register } from 'node:module'
2+
import { register } from 'node:module'
33
import { pathToFileURL } from 'node:url'
44
import { MessageChannel } from 'node:worker_threads'
55
import { dirname, extname } from 'path'
6-
import { isMainThread } from 'worker_threads'
76
import resolve from 'resolve'
87
import semver from 'semver'
8+
import { isMainThread } from 'worker_threads'
99
import { getConfig } from './cfg.js'
1010
import hook from './hook.js'
1111
import { relay, send } from './ipc.js'
1212
import resolveMain from './resolve-main.js'
1313
import suppressExperimentalWarnings from './suppress-experimental-warnings.js'
1414

15-
const require = createRequire(import.meta.url)
16-
1715
// Experimental warnings need to be suppressed in worker threads as well, since
1816
// their process inherits the Node arguments from the main thread.
1917
suppressExperimentalWarnings(process)
@@ -92,7 +90,7 @@ if (isMainThread) {
9290
.unref()
9391

9492
register('./loaders/load.js', {
95-
parentURL: pathToFileURL(import.meta.filename),
93+
parentURL: pathToFileURL(__filename),
9694
data: { port: port2 },
9795
transferList: [port2]
9896
})

0 commit comments

Comments
 (0)