-
-
Couldn't load subscription status.
- Fork 544
Feature: Expose esm hooks factory to public API #1439
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f53ac63
Add esm to project exports
nonara b1fb154
Convert internal `registerAndCreateEsmHooks` to `createEsmHooks` API
nonara 896f622
Revert "Add esm to project exports"
nonara 7c26ee5
Revert esm loaders + add `registerAndCreateEsmHooks`
nonara e992240
Add tests for `createEsmHooks`
nonara 0784e3f
refactor experimentalEsmLoader into an @internal method on the Servic…
cspotcode fa1162b
lint-fix
cspotcode 12f739b
Make test case more robust
cspotcode d63572e
Merge remote-tracking branch 'origin/main' into expose-esm-hooks-fact…
cspotcode 8a27b42
fix
cspotcode 99863cc
Fix version check; we do not support ESM loader on less than node 12.16
cspotcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // ESM loader hook tests | ||
| // TODO: at the time of writing, other ESM loader hook tests have not been moved into this file. | ||
| // Should consolidate them here. | ||
|
|
||
| import { context } from './testlib'; | ||
| import semver = require('semver'); | ||
| import { | ||
| contextTsNodeUnderTest, | ||
| EXPERIMENTAL_MODULES_FLAG, | ||
| TEST_DIR, | ||
| } from './helpers'; | ||
| import { createExec } from './exec-helpers'; | ||
| import { join } from 'path'; | ||
| import * as expect from 'expect'; | ||
|
|
||
| const test = context(contextTsNodeUnderTest); | ||
|
|
||
| const exec = createExec({ | ||
| cwd: TEST_DIR, | ||
| }); | ||
|
|
||
| test.suite('createEsmHooks', (test) => { | ||
| if (semver.gte(process.version, '12.16.0')) { | ||
| test('should create proper hooks with provided instance', async () => { | ||
| const { err } = await exec( | ||
| `node ${EXPERIMENTAL_MODULES_FLAG} --loader ./loader.mjs index.ts`, | ||
| { | ||
| cwd: join(TEST_DIR, './esm-custom-loader'), | ||
| } | ||
| ); | ||
|
|
||
| if (err === null) { | ||
| throw new Error('Command was expected to fail, but it succeeded.'); | ||
| } | ||
|
|
||
| expect(err.message).toMatch(/TS6133:\s+'unusedVar'/); | ||
| }); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export function abc() { | ||
| let unusedVar: string; | ||
| return true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { fileURLToPath } from 'url'; | ||
| import { createRequire } from 'module'; | ||
| const require = createRequire(fileURLToPath(import.meta.url)); | ||
|
|
||
| /** @type {import('../../dist')} **/ | ||
| const { createEsmHooks, register } = require('ts-node'); | ||
|
|
||
| const tsNodeInstance = register({ | ||
| compilerOptions: { | ||
| noUnusedLocals: true, | ||
| }, | ||
| }); | ||
|
|
||
| export const { resolve, getFormat, transformSource } = createEsmHooks( | ||
| tsNodeInstance | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "ESNext", | ||
| "moduleResolution": "node", | ||
| "noUnusedLocals": false | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.