-
Notifications
You must be signed in to change notification settings - Fork 18
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
add support for initialize hook #240
Conversation
The newer initialize hook will really simplify many things and allow us to remove global variables and other things. For now though, things will get complicated. |
This PR has a few major issues but is almost working. Observe current issues with esmock.node.global.test.js ./tests/tests-node/ npm run test-one esmock.node.global.test.js
npm run test-one-no--loader esmock.node.global.test.js Main problem: currently, loader hooks engage three times and process files three times. This happens when "initialized" loader exports hooks used by "--loader" loader. If we did not need backward-compatibility, places needed by "--loader" could be removed and we would be done,
|
yikes node v20's globalPreload mechanism esmock uses to message the loader was removed this morning! nodejs/node#49144 |
cautiously, this branch is mostly working... other things to consider adding here before this branch will be ready,
|
…shing (ci-tests run before publishing)
…of node, without --loader=esmock
package.json scripts in the test folders are updated with patterns like this one used by the mocha folder "scripts": {
"isnodelt20_6": "node -e \"(([mj, mn]) => (+mj < 20 || (+mj === 20 && +mn < 6)))(process.versions.node.split('.')) || process.exit(1)\"",
"test:loader": "mocha --loader=esmock",
"test:current": "mocha",
"test": "npm run test:loader && npm run isnodelt20_6 || npm run test:current"
} This is kind of noisy however works well with windows and npm and, for newer versions of node, runs tests without --loader=esmock. When support for node18 is dropped, a lot of noise can be removed from the sources and the script pattern can simplified to just this, "scripts": {
"test": "mocha"
} please review :) |
Planning to merge and publish this soon so changes will be available for the workspace PR #243 |
this PR adds support for the initialize hook: https://nodejs.org/api/esm.html#initialize
Essentially, with node v20.6
esmock
does not need to be called with "--loader" and insteadesmock
creates its own message channel and script-registers the loader to the channel itself.