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

migrate to register function for NodeJS custom imports (no more flag!) #1220

Open
thescientist13 opened this issue Apr 20, 2024 · 1 comment
Labels
breaking documentation Greenwood specific docs feature New feature or request SSR v0.31.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Apr 20, 2024

Summary

Although currently in RC, NodeJS implementation of custom loaders / imports / hooks is changing (in the better for Greenwood I think) moving from having to be be invoked with a flag (which is very clunky for downstream users

$ c8 node --experimental-loader ./test-exp-loader.js ./node_modules/mocha/bin/mocha "./test/**/**/*.spec.js"
(node:30066) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("./test-exp-loader.js", pathToFileURL("./"));'

To something like this in our index.js instead
https://nodejs.org/api/module.html#customization-hooks

const { register } = require('node:module');
const { pathToFileURL } = require('node:url');

register('http-to-https', pathToFileURL(__filename));

// Because this is a dynamic `import()`, the `http-to-https` hooks will run
// to handle `./my-app.js` and any other files it imports or requires.
import('./my-app.js');

Details

Hopefully this lands as stable in a version of NodeJS soon, though I expect it to require a minimum NodeJS version given the release timeline, but hopefully in time for a 1.0 release on the Greenwood side.

This also means we should be able to remove all mentions of any pre-requisite configuration from our docs and would resolve #1217!
https://www.greenwoodjs.io/docs/server-rendering/#custom-imports

@thescientist13 thescientist13 added documentation Greenwood specific docs breaking SSR feature New feature or request labels Apr 20, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone Apr 20, 2024
@thescientist13
Copy link
Member Author

Looks like this entered RC in Node starting with version 20.x
https://nodejs.org/docs/latest-v20.x/api/module.html#customization-hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking documentation Greenwood specific docs feature New feature or request SSR v0.31.0
Projects
Development

No branches or pull requests

1 participant