GeezerVison is showing github.com — worker: handle `--input-type` more consistently · nodejs/node@f39ff4d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,6 +53,7 @@ let debug = require('internal/util/debuglog').debuglog('worker', (fn) => { | 53 | 53 | }); | 54 | 54 |
| 55 | 55 | const assert = require('internal/assert'); | | 56 | +const { getOptionValue } = require('internal/options'); | 56 | 57 | const { exitCodes: { kGenericUserError } } = internalBinding('errors'); | 57 | 58 |
| 58 | 59 | prepareWorkerThreadExecution(); | @@ -153,7 +154,7 @@ port.on('message', (message) => { | 153 | 154 | break; | 154 | 155 | } | 155 | 156 |
| 156 | | - case 'classic': { | | 157 | + case 'classic': if (getOptionValue('--input-type') !== 'module') { | 157 | 158 | const { evalScript } = require('internal/process/execution'); | 158 | 159 | const name = '[worker eval]'; | 159 | 160 | // This is necessary for CJS module compilation. | @@ -169,6 +170,7 @@ port.on('message', (message) => { | 169 | 170 | break; | 170 | 171 | } | 171 | 172 |
| | 173 | + // eslint-disable-next-line no-fallthrough | 172 | 174 | case 'module': { | 173 | 175 | const { evalModuleEntryPoint } = require('internal/process/execution'); | 174 | 176 | PromisePrototypeThen(evalModuleEntryPoint(filename), undefined, (e) => { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-worker-cli-options.js +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // Flags: --expose-internals --expose-gc | 2 | 2 | 'use strict'; | 3 | | -require('../common'); | | 3 | +const common = require('../common'); | 4 | 4 | const { Worker } = require('worker_threads'); | 5 | 5 | const assert = require('assert'); | 6 | 6 |
| @@ -29,3 +29,11 @@ new Worker(CODE, { eval: true, env: process.env, execArgv: ['--expose-internals' | 29 | 29 | assert.throws(() => { | 30 | 30 | new Worker(CODE, { eval: true, execArgv: ['--expose-gc'] }); | 31 | 31 | }, /ERR_WORKER_INVALID_EXEC_ARGV/); | | 32 | + | | 33 | +// Test ESM eval | | 34 | +new Worker('export {}', { eval: true, execArgv: ['--input-type=module'] }); | | 35 | +new Worker('export {}', { eval: true, execArgv: ['--input-type=commonjs'] }) | | 36 | + .once('error', common.expectsError({ name: 'SyntaxError' })); | | 37 | +new Worker('export {}', { eval: true, execArgv: ['--experimental-detect-module'] }); | | 38 | +new Worker('export {}', { eval: true, execArgv: ['--no-experimental-detect-module'] }) | | 39 | + .once('error', common.expectsError({ name: 'SyntaxError' })); |
|