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

enhancement/issue 1220 adopt NodeJS register API for custom loaders #1373

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Dec 31, 2024

Related Issue

resolves #1220

Documentation

  1. Need to document new custom loaders API usage and NodeJS 20.10.0 as minimum version with JSON Import Attributes + register function support (not just 20.6.0) - document latest usage and minimum NodeJS version for custom loaders usage www.greenwoodjs.dev#158
       Error building up import map TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/lit/package.json" needs an import assertion of type "json"
         at new NodeError (node:internal/errors:405:5)
         at validateAssertions (node:internal/modules/esm/assert:94:15)
         at defaultLoad (node:internal/modules/esm/load:117:3)
         at ModuleLoader.load (node:internal/modules/esm/loader:388:13)
         at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:270:56)
         at new ModuleJob (node:internal/modules/esm/module_job:65:26)
         at #createModuleJob (node:internal/modules/esm/loader:282:17)
         at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:240:34)
         at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:221:17)
         at async ModuleLoader.import (node:internal/modules/esm/loader:307:23) {
       code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING'
       }
       

Summary of Changes

  1. Create a register function and adopted for an export alias (and thus had to create an exports map for Greenwood as needed)
         node:internal/process/esm_loader:48
         internalBinding('errors').triggerUncaughtException(
                                   ^
       Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './src/lib/resource-utils.js' is not defined by "exports" in /Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/@greenwood+plugin-adapter-vercel@0.31.0-alpha.2_@greenwood+cli@0.31.0-alpha.2/node_modules/@greenwood/cli/package.json imported from /Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/@greenwood+plugin-adapter-vercel@0.31.0-alpha.2_@greenwood+cli@0.31.0-alpha.2/node_modules/@greenwood/plugin-adapter-vercel/src/index.js
       

Example repo - thescientist13/greenwood-lit-ssr#28

TODO

  1. Windows Loaders CI is flaking hard post rebase (but not against loaders test cases???) 😭 - enhancement/issue 1220 adopt NodeJS register API for custom loaders #1373 (comment)
  2. (nice to have) self invoke greenwood w/ command - Tracked here - Self Invoking Custom Import Loader(s) #1217 (comment)
    import { register } from 'node:module';
    
    register('./loader.js', import.meta.url);
    
    // TODO can we do this for the user?
    // await import('./index.js');
  3. (nice to have) can we clean up the invocation / no userland flag? - Tracked here - Self Invoking Custom Import Loader(s) #1217 (comment)
    "dev": "node --import @greenwood/cli/register ./node_modules/@greenwood/cli/src/index.js develop",

@thescientist13 thescientist13 force-pushed the enhancement/issue-1220-adopt-nodejs-register-API-for-custom-loaders branch from 1c94ba4 to 3603ab4 Compare January 11, 2025 18:59
@thescientist13
Copy link
Member Author

thescientist13 commented Jan 11, 2025

Windows Loaders test cases are failing intermittently, but seemed to be working prior to the rebase after #1372

working - https://github.com/ProjectEvergreen/greenwood/actions/runs/12734825121/job/35492838978
Screenshot 2025-01-12 at 10 51 02 AM

not working - https://github.com/ProjectEvergreen/greenwood/actions/runs/12734825121/job/35492838978
Screenshot 2025-01-12 at 10 50 51 AM

Tried with windows-2025 and that didn't work either, I guess could try windows-2022 but I think latest is already aliased to this anyway?

The intermittent Windows tests all run fine locally on Windows in Paralles at least

  3393 passing (13m)
  61 pending

Done in 781.57s.

owenbuckley@OWENBUCKLEY5945 MINGW64 ~/Workspace/greenwood (master)
$ node -v
v20.18.1

Examples

@thescientist13 thescientist13 mentioned this pull request Jan 12, 2025
40 tasks
@thescientist13 thescientist13 merged commit 33da5e2 into master Jan 12, 2025
9 of 10 checks passed
@thescientist13 thescientist13 deleted the enhancement/issue-1220-adopt-nodejs-register-API-for-custom-loaders branch January 12, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking CLI documentation Greenwood specific docs enhancement Improve something existing (e.g. no docs, new APIs, etc) SSR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

migrate to register function for NodeJS custom imports (no more flag?) Upgrade to latest Node LTS(s)
1 participant