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

fix: adjust feature detection for node 18.19 loader changes #422

Merged
merged 3 commits into from
Nov 30, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/esm/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

export const initialize: InitializeHook = async (data) => {
if (!data) {
throw new Error('tsx must be loaded with --import instead of --loader\nThe --loader flag was deprecated in Node v20.6.0');
throw new Error('tsx must be loaded with --import instead of --loader\nThe --loader flag was deprecated in Node v20.6.0 and v18.19.0');
privatenumber marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down Expand Up @@ -133,7 +133,7 @@

const isRelativePathPattern = /^\.{1,2}\//;

export const resolve: resolve = async function (

Check warning on line 136 in src/esm/loaders.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected unnamed async function

Check warning on line 136 in src/esm/loaders.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Async function has a complexity of 22. Maximum allowed is 10
specifier,
context,
defaultResolve,
Expand Down Expand Up @@ -231,7 +231,7 @@

const contextAttributesProperty = importAttributes ? 'importAttributes' : 'importAssertions';

export const load: LoadHook = async function (

Check warning on line 234 in src/esm/loaders.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected unnamed async function
url,
context,
defaultLoad,
Expand Down
19 changes: 11 additions & 8 deletions src/utils/node-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ export const compareNodeVersion = (
|| nodeVersion[2] - version[2]
);

/**
* Node.js loaders are isolated from v20
* https://github.com/nodejs/node/issues/49455#issuecomment-1703812193
* https://github.com/nodejs/node/blob/33710e7e7d39d19449a75911537d630349110a0c/doc/api/module.md#L375-L376
*/
export const isolatedLoader = compareNodeVersion([20, 0, 0]) >= 0;

export const supportsModuleRegister = compareNodeVersion([20, 6, 0]) >= 0;
export const supportsModuleRegister = (
compareNodeVersion([20, 6, 0]) >= 0
|| (
compareNodeVersion([20, 0, 0]) < 0
&& compareNodeVersion([18, 19, 0]) >= 0
)
);

export const importAttributes = (
compareNodeVersion([21, 0, 0]) >= 0
|| compareNodeVersion([20, 10, 0]) >= 0
|| (
compareNodeVersion([20, 0, 0]) < 0
&& compareNodeVersion([18, 19, 0]) >= 0
)
);

// Added in v21.0.0
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/node-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const nodeVersions = [
)
? [
latestMajor('20.10.0'),
latestMajor('18.18.2'),
// TODO:
// '20.0.0',
latestMajor('18.19.0'),
privatenumber marked this conversation as resolved.
Show resolved Hide resolved
'18.0.0',
] as const
: [] as const
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export const createNode = async (

const versionParsed = node.version.split('.').map(Number) as Version;
const supports = {
moduleRegister: compareNodeVersion([20, 6, 0], versionParsed) >= 0,
moduleRegister: (
compareNodeVersion([20, 6, 0], versionParsed) >= 0
|| (
compareNodeVersion([20, 0, 0], versionParsed) < 0
&& compareNodeVersion([18, 19, 0], versionParsed) >= 0
)
),

// https://nodejs.org/docs/latest-v18.x/api/cli.html#--test
cliTestFlag: compareNodeVersion([18, 1, 0], versionParsed) >= 0,
Expand Down
Loading