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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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/@[email protected]_@[email protected]/node_modules/@greenwood/cli/package.json imported from /Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@greenwood/plugin-adapter-vercel/src/index.js
       
  2. Bump GitHub Actions to [20, 22] though seems we can keep engines at >=18.20.5 (overlaps with Upgrade to Node 20.x (latest LTS) #1202 )

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

TODO

  1. (right after merge) Update GitHub Actions version check(s)
  2. (nice to have) self invoke greenwood w/ command
    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?
    "dev": "node --import @greenwood/cli/register ./node_modules/@greenwood/cli/src/index.js develop",

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 Node 20.x (latest LTS)
1 participant