Skip to content
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

worker: add no-worker-extension-check option #39785

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ added: v6.0.0

Silence all process warnings (including deprecations).

### `--no-worker-extension-check`

<!-- YAML
added: REPLACEME
-->

Disable runtime file extension check for worker.

### `--node-memory-debug`
<!-- YAML
added: v15.0.0
Expand Down
3 changes: 3 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ These will still be enabled dynamically when `async_hooks` is enabled.
.It Fl -no-warnings
Silence all process warnings (including deprecations).
.
It Fl -no-worker-extension-check
Disable runtime file extension check for worker.
.
.It Fl -node-memory-debug
Enable extra debug checks for memory leaks in Node.js internals. This is
usually only useful for developers debugging Node.js itself.
Expand Down
5 changes: 4 additions & 1 deletion lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ class Worker extends EventEmitter {
}

const ext = path.extname(filename);
if (ext !== '.js' && ext !== '.mjs' && ext !== '.cjs') {
if (!getOptionValue('--no-worker-extension-check') &&
ext !== '.js' &&
ext !== '.mjs' &&
ext !== '.cjs') {
throw new ERR_WORKER_UNSUPPORTED_EXTENSION(ext);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"set default TLS maximum to TLSv1.3 (default: TLSv1.3)",
&EnvironmentOptions::tls_max_v1_3,
kAllowedInEnvironment);
AddOption("--worker-extension-check",
"disable file extension check for worker thread",
&EnvironmentOptions::worker_extension_check,
kAllowedInEnvironment,
true);
}

PerIsolateOptionsParser::PerIsolateOptionsParser(
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class EnvironmentOptions : public Options {
bool preserve_symlinks = false;
bool preserve_symlinks_main = false;
bool prof_process = false;
bool worker_extension_check = true;
#if HAVE_INSPECTOR
std::string cpu_prof_dir;
static const uint64_t kDefaultCpuProfInterval = 1000;
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-worker-disable-extension-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Flags: --no-worker-extension-check

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');

const { Worker } = require('worker_threads');

(common.mustCall(() => { new Worker(fixtures.path('foo')); }))();