Skip to content

Commit 4cac78e

Browse files
authored
[ESM] support new experimental-loader format (#270)
* [ESM] getSource has been renamed load * [ESM] It seems load was just introduced in 16.12.0 so we need to keep getSource for 14
1 parent a14b1b6 commit 4cac78e

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ module.exports = function (
9999
const resolveLoader = resolveMain(localPath('resolve-loader.mjs'));
100100
cmd.unshift('--experimental-modules', `--loader=${resolveLoader}`);
101101
} else if (semver.satisfies(process.version, '>=12.11.1')) {
102-
const getSourceLoader = resolveMain(localPath('get-source-loader.mjs'));
103-
cmd.unshift(`--experimental-loader=${getSourceLoader}`);
102+
const loaderPath = semver.satisfies(process.version, '>=16.12.0')
103+
? 'load-loader.mjs'
104+
: 'get-source-loader.mjs';
105+
const experimentalLoader = resolveMain(localPath(loaderPath));
106+
cmd.unshift(`--experimental-loader=${experimentalLoader}`);
104107
}
105108
}
106109

lib/load-loader.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { send } from './ipc.js';
2+
3+
export async function load(url, context, defaultLoad) {
4+
send({ required: new URL(url).pathname });
5+
return defaultLoad(url, context, defaultLoad);
6+
}

0 commit comments

Comments
 (0)