-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Programmatic options passed to register
are always ignored.
#716
Comments
Thank you so much. This patch allows me to update past 1.5.4 |
eliellis
changed the title
Programatic options passed to
Programmatic options passed to Aug 17, 2023
register
are always ignored.register
are always ignored.
With the recent updates to diff --git a/node_modules/@swc-node/register/lib/read-default-tsconfig.js b/node_modules/@swc-node/register/lib/read-default-tsconfig.js
index fb48a43..de18175 100644
--- a/node_modules/@swc-node/register/lib/read-default-tsconfig.js
+++ b/node_modules/@swc-node/register/lib/read-default-tsconfig.js
@@ -139,6 +139,7 @@ function tsCompilerOptionsToSwcConfig(options, filename) {
useBuiltins: true,
}
: undefined,
+ baseUrl: path_1.resolve(options.baseUrl ?? './'),
paths: Object.fromEntries(Object.entries((_h = options.paths) !== null && _h !== void 0 ? _h : {}).map(([aliasKey, aliasPaths]) => {
var _a;
return [
diff --git a/node_modules/@swc-node/register/lib/register.js b/node_modules/@swc-node/register/lib/register.js
index 7d4cfd8..51adf8a 100644
--- a/node_modules/@swc-node/register/lib/register.js
+++ b/node_modules/@swc-node/register/lib/register.js
@@ -88,7 +88,7 @@ function compile(sourcecode, filename, options, async = false) {
exports.compile = compile;
function register(options = {}, hookOpts = {}) {
if (!process.env.SWCRC) {
- options = (0, read_default_tsconfig_1.readDefaultTsConfig)();
+ options = Object.keys(options).length ? options : (0, read_default_tsconfig_1.readDefaultTsConfig)();
}
options.module = ts.ModuleKind.CommonJS;
(0, sourcemap_support_1.installSourceMapSupport)(); |
Merged
I have opened #725 to address this issue. @Brooooooklyn please take a look when you can. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Due to the below
if
condition, introduced in #694, ifoptions
are passed toregister
programmatically (e.g.register({ ...customOptions })
), they will be ignored in favor of either the results fromreadDefaultTsConfig
or options gathered directly byswc
from a nearby.swcrc
file whenprocess.env.SWCRC = 'true'
.swc-node/packages/register/register.ts
Lines 108 to 110 in ba8f60d
In cases where
SWCRC
is nottrue
(unset, etc.), the configuration returned fromreadDefaultTsConfig
is taken even ifoptions
are passed toregister
, meaning the passedoptions
are altogether ignored.I believe in this specific circumstance, the intuition would be for$iif$ they were given
options
passed toregister
to be used&& !process.env.SWCRC
.Unless I am totally off-base here, I think the body of the
if
can be changed to (or something similar):Where when
process.env.SWCRC
is falsy, we prefer any programmatically specified options before trying to read atsconfig.json
file. With this, I think the scenario above should be accounted for appropriately, while also not breaking what was fixed in #694.For anyone running into this currently, using
patch-package
with the below diff, I was able to quickly fix this for1.6.6
A more detailed and interactive reproduction can be seen here.
The text was updated successfully, but these errors were encountered: