Skip to content

Commit 0d0a961

Browse files
committed
work on plugin
1 parent 6984650 commit 0d0a961

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"lint": "run-s prepare lint-raw",
3737
"lint-raw": "run-s test-eslint test-type-definitions bundle-package test-publint",
3838
"test": "run-s prepare test-raw",
39-
"test-raw": "run-s lint-raw bundle-tests test-unit test-promises test-entries test-compat-data test-compat-tools test-builder check",
39+
"test-raw": "run-s lint-raw bundle-tests test-unit test-promises test-entries test-compat-data test-compat-tools test-builder test-babel-plugin check",
4040
"test-eslint": "npm run zxi time tests/eslint/runner.mjs",
4141
"test-publint": "npm run zxi time tests/publint/runner.mjs",
4242
"test-unit": "run-s test-unit-karma test-unit-node test-unit-bun",

packages/core-js-babel-plugin/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module.exports = defineProvider(({
3333
const modulesListForTargetVersion = getModulesListForTargetVersion(version);
3434
const injectedModules = new Set();
3535

36+
if (!Object.keys(targets).length) targets = null;
37+
3638
const resolve = createMetaResolver({
3739
global: Globals,
3840
static: StaticProperties,
@@ -52,15 +54,14 @@ module.exports = defineProvider(({
5254
}
5355

5456
function getModulesForCoreJSEntry(entry) {
55-
return compat({ modules: entries[entry], targets }).list;
57+
return compat({ modules: entries[entry], targets, version }).list;
5658
}
5759

5860
function injectCoreJSModulesForEntry(entry, utils) {
5961
for (const moduleName of getModulesForCoreJSEntry(entry)) {
60-
if (injectedModules.has(moduleName)) continue;
61-
injectedModules.add(moduleName);
62-
const modulePath = `${ pkg }/modules/${ moduleName }`;
63-
utils.injectGlobalImport(modulePath, moduleName);
62+
const moduleEntry = `modules/${ moduleName }`;
63+
utils.injectGlobalImport(`${ pkg }/${ moduleEntry }`, moduleName);
64+
injectedModules.add(moduleEntry);
6465
debug(moduleName);
6566
}
6667
}
@@ -70,7 +71,7 @@ module.exports = defineProvider(({
7071
polyfills: modulesListForTargetVersion,
7172
entryGlobal({ source }, utils, path) {
7273
const entry = getCoreJSEntry(source);
73-
if (entry === null) return;
74+
if (entry === null || injectedModules.has(entry)) return;
7475
injectCoreJSModulesForEntry(entry, utils);
7576
path.remove();
7677
},

tests/babel-plugin/index.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const { transformAsync } = require('@babel/core');
22
const { strictEqual } = require('node:assert');
33

4+
const { _: args } = argv;
45
const { access, readdir, readFile, readJson, stat, writeFile } = fs;
56
const { join } = path;
6-
const { cyan, green, yellow } = chalk;
7+
const { cyan, green, red, yellow } = chalk;
78

89
const { OVERWRITE } = process.env;
910
const UTF8 = { encoding: 'utf8' };
@@ -30,8 +31,8 @@ async function handleDirectory(directory) {
3031
return echo`${ cyan(expected) } ${ yellow('created') }`;
3132
}
3233

33-
strictEqual(String(await readFile(expected, UTF8)), result);
34+
strictEqual(String(await readFile(expected, UTF8)), result, red(directory));
3435
echo`${ cyan(directory) } ${ green('passed') }`;
3536
}
3637

37-
await handleDirectory('./fixtures');
38+
await handleDirectory(args.length ? `./fixtures/${ args[0] }` : './fixtures');

0 commit comments

Comments
 (0)