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

Update esm loader hooks API #1457

Merged
merged 36 commits into from Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2108b58
Initial commit
jonaskello Sep 12, 2021
f8ef837
Merge branch 'main' into resolver-hooks-update
jonaskello Sep 12, 2021
073bbfc
Update hooks
jonaskello Sep 12, 2021
765932f
Merge branch 'resolver-hooks-update' of github.com:jonaskello/ts-node…
jonaskello Sep 12, 2021
786ec34
wip impl of load
jonaskello Sep 12, 2021
14220ac
Expose old hooks for backward compat
jonaskello Sep 12, 2021
cd44ef3
Some logging
jonaskello Sep 13, 2021
245242b
Add raw copy of default get format
jonaskello Sep 17, 2021
0b0d50c
Adapt defaultGetFormat() from node source
jonaskello Sep 17, 2021
5534722
Fix defaultTransformSource
jonaskello Sep 17, 2021
1030783
Add missing newline
jonaskello Sep 17, 2021
9f28485
Fix require
jonaskello Sep 17, 2021
662b4b8
Check node version to avoid deprecation warning
jonaskello Sep 17, 2021
469437b
Remove load from old hooks
jonaskello Sep 17, 2021
b102ee6
Add some comments
jonaskello Sep 18, 2021
2044208
Use versionGte
jonaskello Sep 18, 2021
b2fffe7
Remove logging
jonaskello Sep 18, 2021
d41204c
Refine comments
jonaskello Sep 18, 2021
da34bf7
Wording
jonaskello Sep 18, 2021
a7e3475
Use format hint if available
jonaskello Sep 18, 2021
e228e08
One more comment
jonaskello Sep 18, 2021
f4dee40
Nitpicky changes to comments
cspotcode Sep 18, 2021
0025586
Update index.ts
cspotcode Sep 18, 2021
6ffe9ea
lint-fix
cspotcode Sep 18, 2021
521a1e2
attempt at downloading node nightly in tests
cspotcode Sep 18, 2021
8b94f1b
fix
cspotcode Sep 18, 2021
10e5580
fix
cspotcode Sep 18, 2021
77acae6
Windows install of node nightly
cspotcode Sep 18, 2021
8e40254
update version checks to be ready for node backporting
cspotcode Sep 23, 2021
d3ed4a1
Add guards for undefined source
jonaskello Sep 25, 2021
544584a
More error info
jonaskello Sep 25, 2021
a23bc47
Skip source transform for builtin and commonjs
jonaskello Sep 25, 2021
63c0618
Update transpile-only.mjs
cspotcode Oct 6, 2021
ca9cde9
Merge remote-tracking branch 'origin/main' into resolver-hooks-update
cspotcode Oct 10, 2021
e576772
Tweak `createEsmHooks` type
cspotcode Oct 10, 2021
8b328d3
fix test to accomodate new api
cspotcode Oct 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -69,7 +69,8 @@
"test-local": "npm run lint-fix && npm run build-tsc && npm run build-pack && npm run test-spec --",
"coverage-report": "nyc report --reporter=lcov",
"prepare": "npm run clean && npm run build-nopack",
"api-extractor": "api-extractor run --local --verbose"
"api-extractor": "api-extractor run --local --verbose",
"esm-usage-example": "npm run build-tsc && cd esm-usage-example && node --experimental-specifier-resolution node --loader ../esm.mjs ./index"
},
"engines": {
"node": ">=12.0.0"
Expand Down
17 changes: 15 additions & 2 deletions src/esm.ts
Expand Up @@ -28,7 +28,8 @@ export function registerAndCreateEsmHooks(opts?: RegisterOptions) {
preferTsExts: tsNodeInstance.options.preferTsExts,
});

return { resolve, getFormat, transformSource };
// return { resolve, getFormat, transformSource };
return { resolve, load };
jonaskello marked this conversation as resolved.
Show resolved Hide resolved

function isFileUrlOrNodeStyleSpecifier(parsed: UrlWithStringQuery) {
// We only understand file:// URLs, but in node, the specifier can be a node-style `./foo` or `foo`
Expand Down Expand Up @@ -65,11 +66,23 @@ export function registerAndCreateEsmHooks(opts?: RegisterOptions) {

// pathname is the path to be resolved

return nodeResolveImplementation.defaultResolve(
console.log('got here');

const x = nodeResolveImplementation.defaultResolve(
specifier,
context,
defaultResolve
);
console.log('x', x);
return x;
}

async function load(
url: string,
context: {},
defaultLoad: typeof load
): Promise<{ format: Format }> {
throw new Error('load');
jonaskello marked this conversation as resolved.
Show resolved Hide resolved
}

type Format = 'builtin' | 'commonjs' | 'dynamic' | 'json' | 'module' | 'wasm';
Expand Down