-
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.
- Loading branch information
Showing
6 changed files
with
24 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const sayHi = (name: string) => { | ||
return `Hi ${name}`; | ||
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import * as iitm from "../../hook.mjs"; | ||
import * as tsNode from "ts-node/esm.mjs"; | ||
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); | ||
}; | ||
}; | ||
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); | ||
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); | ||
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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import assert from "node:assert/strict"; | ||
import test from "node:test"; | ||
import { addHook } from "../../index.js"; | ||
import { sayHi } from "./say-hi.mjs"; | ||
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"; | ||
if (url.toLowerCase().endsWith('say-hi.mts')) { | ||
exported.sayHi = () => 'Hooked' | ||
} | ||
}); | ||
}) | ||
|
||
test("Hook a module", async () => { | ||
assert.equal(sayHi("test"), "Hooked"); | ||
}); | ||
assert.equal(sayHi('test'), 'Hooked') |