-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into add-loader-tests
- Loading branch information
Showing
11 changed files
with
149 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
import { isMainThread } from 'node:worker_threads'; | ||
import { supportsModuleRegister } from '../utils/node-features'; | ||
import { registerLoader } from './register'; | ||
|
||
// Loaded via --import flag | ||
if ( | ||
supportsModuleRegister | ||
&& isMainThread | ||
) { | ||
registerLoader(); | ||
} | ||
|
||
export * from './loaders.js'; | ||
export * from './loaders-deprecated.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import module from 'node:module'; | ||
import { MessageChannel } from 'node:worker_threads'; | ||
import { installSourceMapSupport } from '../source-map'; | ||
|
||
export const registerLoader = () => { | ||
const { port1, port2 } = new MessageChannel(); | ||
|
||
installSourceMapSupport(port1); | ||
if (process.send) { | ||
port1.addListener('message', (message) => { | ||
if (message.type === 'dependency') { | ||
process.send!(message); | ||
} | ||
}); | ||
} | ||
|
||
// Allows process to exit without waiting for port to close | ||
port1.unref(); | ||
|
||
module.register( | ||
'./index.mjs', | ||
{ | ||
parentURL: import.meta.url, | ||
data: { | ||
port: port2, | ||
}, | ||
transferList: [port2], | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
type Version = [number, number, number]; | ||
|
||
const nodeVersion = process.versions.node.split('.').map(Number) as Version; | ||
|
||
const compareNodeVersion = (version: Version) => ( | ||
nodeVersion[0] - version[0] | ||
|| nodeVersion[1] - version[1] | ||
|| nodeVersion[2] - version[2] | ||
); | ||
|
||
export const nodeSupportsImport = ( | ||
// v13.2.0 and higher | ||
compareNodeVersion([13, 2, 0]) >= 0 | ||
|
||
// 12.20.0 ~ 13.0.0 | ||
|| ( | ||
compareNodeVersion([12, 20, 0]) >= 0 | ||
&& compareNodeVersion([13, 0, 0]) < 0 | ||
) | ||
); | ||
|
||
export const supportsNodePrefix = ( | ||
compareNodeVersion([16, 0, 0]) >= 0 | ||
|| compareNodeVersion([14, 18, 0]) >= 0 | ||
); | ||
|
||
export const nodeSupportsDeprecatedLoaders = compareNodeVersion([16, 12, 0]) < 0; | ||
|
||
/** | ||
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters