From 9902031f44ad434bc9ca2f38833188d8ab57c31d Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Wed, 22 May 2024 17:03:59 +0200 Subject: [PATCH] remove the babelFilter function and the output of _babel_filter_.js file --- packages/compat/src/compat-app-builder.ts | 11 ------ packages/shared-internals/src/babel-filter.ts | 34 ------------------- packages/shared-internals/src/index.ts | 1 - tests/scenarios/compat-resolver-test.ts | 3 -- tests/scenarios/core-resolver-test.ts | 3 -- 5 files changed, 52 deletions(-) delete mode 100644 packages/shared-internals/src/babel-filter.ts diff --git a/packages/compat/src/compat-app-builder.ts b/packages/compat/src/compat-app-builder.ts index 66b9dafeb..fc8b9de2e 100644 --- a/packages/compat/src/compat-app-builder.ts +++ b/packages/compat/src/compat-app-builder.ts @@ -4,7 +4,6 @@ import { explicitRelative, extensionsPattern, warn, - jsHandlebarsCompile, templateColocationPluginPath, cacheBustingPluginVersion, cacheBustingPluginPath, @@ -581,11 +580,6 @@ export class CompatAppBuilder { `module.exports = ${JSON.stringify(pconfig.config, null, 2)}`, 'utf8' ); - writeFileSync( - join(locateEmbroiderWorkingDir(this.compatApp.root), '_babel_filter_.js'), - babelFilterTemplate({ skipBabel: [], appRoot: this.origAppPackage.root }), - 'utf8' - ); } private addResolverConfig(config: CompatResolverOptions) { @@ -656,11 +650,6 @@ function defaultAddonPackageRules(): PackageRules[] { .reduce((a, b) => a.concat(b), []); } -const babelFilterTemplate = jsHandlebarsCompile(` -const { babelFilter } = require(${JSON.stringify(require.resolve('@embroider/core'))}); -module.exports = babelFilter({{json-stringify skipBabel}}, "{{js-string-escape appRoot}}"); -`) as (params: { skipBabel: string[]; appRoot: string }) => string; - function combinePackageJSON(...layers: object[]) { function custom(objValue: any, srcValue: any, key: string, _object: any, _source: any, stack: { size: number }) { if (key === 'keywords' && stack.size === 0) { diff --git a/packages/shared-internals/src/babel-filter.ts b/packages/shared-internals/src/babel-filter.ts deleted file mode 100644 index 96cebe448..000000000 --- a/packages/shared-internals/src/babel-filter.ts +++ /dev/null @@ -1,34 +0,0 @@ -import PackageCache from './package-cache'; -import semver from 'semver'; - -export default function babelFilter(skipBabel: { package: string; semverRange?: string }[], appRoot: string) { - return function shouldTranspileFile(filename: string) { - if (!babelCanHandle(filename)) { - // quick exit for non JS extensions - return false; - } - - let owner = PackageCache.shared('embroider', appRoot).ownerOfFile(filename); - if (owner) { - for (let { package: pkg, semverRange } of skipBabel) { - if (owner.name === pkg && (semverRange == null || semver.satisfies(owner.version, semverRange))) { - if (owner.isEmberAddon()) { - throw new Error( - `You can't use skipBabel to disable transpilation of Ember addons, it only works for non-Ember third-party packages` - ); - } - return false; - } - } - } - return true; - }; -} - -function babelCanHandle(filename: string) { - // we can handle .mjs, .js and .ts files with babel. If typescript is enabled, - // .ts files become resolvable and stage3 will be asking us if they should get - // transpiled and the answer is yes. If typescript is not enbled, they will - // not be resolvable, so stage3 won't ask us about them. - return /\.m?[jt]s$/i.test(filename); -} diff --git a/packages/shared-internals/src/index.ts b/packages/shared-internals/src/index.ts index 47a8ea4cf..bd88319a7 100644 --- a/packages/shared-internals/src/index.ts +++ b/packages/shared-internals/src/index.ts @@ -12,7 +12,6 @@ export { default as Package, V2AddonPackage as AddonPackage, V2AppPackage as App export { default as PackageCache } from './package-cache'; export type { RewrittenPackageIndex } from './rewritten-package-cache'; export { RewrittenPackageCache } from './rewritten-package-cache'; -export { default as babelFilter } from './babel-filter'; export { default as packageName } from './package-name'; export { default as tmpdir } from './tmpdir'; export * from './ember-cli-models'; diff --git a/tests/scenarios/compat-resolver-test.ts b/tests/scenarios/compat-resolver-test.ts index 33504039d..f13639f8d 100644 --- a/tests/scenarios/compat-resolver-test.ts +++ b/tests/scenarios/compat-resolver-test.ts @@ -120,9 +120,6 @@ Scenarios.fromProject(() => new Project()) [require.resolve('@embroider/compat/src/babel-plugin-adjust-imports'), { appRoot: app.dir }], ])} }`, - 'node_modules/.embroider/_babel_filter.js': ` - module.exports = function(filename) { return true } - `, 'node_modules/.embroider/resolver.json': JSON.stringify(resolverOptions), }); }; diff --git a/tests/scenarios/core-resolver-test.ts b/tests/scenarios/core-resolver-test.ts index 0f1eba66d..0b3020d7f 100644 --- a/tests/scenarios/core-resolver-test.ts +++ b/tests/scenarios/core-resolver-test.ts @@ -142,9 +142,6 @@ Scenarios.fromProject(() => new Project()) plugins: [] } `, - 'node_modules/.embroider/_babel_filter.js': ` - module.exports = function(filename) { return true } - `, 'node_modules/.embroider/resolver.json': JSON.stringify(resolverOptions), 'node_modules/my-addon/package.json': addonPackageJSON('my-addon', opts?.addonMeta), });