Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MessagePort } from 'node:worker_threads';
import path from 'path';
import { pathToFileURL, fileURLToPath } from 'url';
import type {
ResolveFnOutput, ResolveHookContext, LoadHook, GlobalPreloadHook,
ResolveFnOutput, ResolveHookContext, LoadHook, GlobalPreloadHook, InitializeHook,
} from 'module';
import {
transform,
Expand Down Expand Up @@ -48,6 +48,17 @@ export const globalPreload: GlobalPreloadHook = ({ port }) => {
`;
};

/**
* From Node.js v20.6.0, `globalPreload` is deprecarated in favor of `initialize`
* However, it requires the loader to be loaded via `--import` that registers
* the loader instead of directly loading the loader via `--loader`
*
* https://nodejs.org/api/esm.html#initialize
*/
export const initialize: InitializeHook = () => {
console.log('initialize');
};

const extensions = ['.js', '.json', '.ts', '.tsx', '.jsx'] as const;

async function tryExtensions(
Expand Down