-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeScript extensions to EXTENSION_RE (#14)
* add compatibility with typescript when using ts-node * add missing newline * fix typescript tests * run typescript tests with imhotap * separate js tests from ts tests * do not run test:ts with node 16.10.0 * add a FIXME comment for EXTENSION_RE changes The addition of TS extensions to EXTENSION_RE should be temporary until we find a better way of supporting arbitrary extensions Co-authored-by: rochdev <roch.devost@gmail.com>
- Loading branch information
Showing
8 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 @@ | ||
export const sayHi = (name: string) => { | ||
return `Hi ${name}` | ||
}; |
This file contains 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 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,18 @@ | ||
import * as iitm from '../../hook.mjs' | ||
import * as tsNode from 'ts-node/esm.mjs' | ||
|
||
const makeNext = (loader, fnName, parentResolveOrLoad) => { | ||
return (specifierOrUrl, context) => { | ||
return loader[fnName](specifierOrUrl, context, parentResolveOrLoad) | ||
} | ||
} | ||
|
||
export async function resolve(specifier, context, defaultResolve) { | ||
const next = makeNext(tsNode, 'resolve', defaultResolve) | ||
return iitm.resolve(specifier, context, next) | ||
} | ||
|
||
export async function load(url, context, defaultLoad) { | ||
let next = makeNext(tsNode, 'load', defaultLoad) | ||
return iitm.load(url, context, next) | ||
} |
This file contains 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,11 @@ | ||
import assert from 'node:assert/strict' | ||
import { addHook } from '../../index.js' | ||
import { sayHi } from '../fixtures/say-hi.mjs' | ||
|
||
addHook((url, exported) => { | ||
if (url.toLowerCase().endsWith('say-hi.mts')) { | ||
exported.sayHi = () => 'Hooked' | ||
} | ||
}) | ||
|
||
assert.equal(sayHi('test'), 'Hooked') |
This file contains 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,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"allowSyntheticDefaultImports": true, | ||
"noEmit": true | ||
}, | ||
"ts-node": { | ||
"esm": true | ||
} | ||
} |