Код: Выделить всё
"./my-hook.mjs 'load'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include `shortCircuit: true` in the hook's return.
Код: Выделить всё
// my-hook.mjs
export async function load(url, context, nextLoad) {
if (url.endsWith(".js")) {
let source = await readFile(fileURLToPath(url), "utf-8");
source = source.replace("hello", "123");
return {
source: source,
shortCircuit: true, // cannot be false
format: "module",
};
}
return nextLoad(url);
}
< /code>
// register-hooks.mjs
import { register } from "node:module";
register("./my-hook.mjs", import.meta.url);
< /code>
node --import ./register-hooks.mjs a.jsЯ хочу добавить новый синтаксис в типографию.
Моя идея - написать нагрузку крючок, который обрабатывает .ts files и конвертирует мой синтаксис в стандартный Typescript Syntax. Затем я бы передал конвертированный код TSX .
нравится это: node-import my-hook-import tsx a.ts
Это возможно? Если нет, не могли бы вы порекомендовать другие методы?
Подробнее здесь: https://stackoverflow.com/questions/797 ... tion-hooks
Мобильная версия