Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove skipBabel option #1942

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
11 changes: 0 additions & 11 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
explicitRelative,
extensionsPattern,
warn,
jsHandlebarsCompile,
templateColocationPluginPath,
cacheBustingPluginVersion,
cacheBustingPluginPath,
Expand Down Expand Up @@ -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: this.options.skipBabel, appRoot: this.origAppPackage.root }),
'utf8'
);
}

private addResolverConfig(config: CompatResolverOptions) {
Expand Down Expand Up @@ -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: Options['skipBabel']; 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) {
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ export default interface Options {
// route templates, and controllers which are governed by splitAtRoutes).
staticAppPaths?: string[];

// By default, all modules that get imported into the app go through Babel, so
// that all code will conform with your Babel targets. This option allows you
// to turn Babel off for a particular package. You might need this to work
// around a transpiler bug or you might use this as a build-performance
// optimization if you've manually verified that a particular package doesn't
// need transpilation to be safe in your target browsers.
skipBabel?: { package: string; semverRange?: string }[];

// This is a performance optimization that can help you avoid the "Your build
// is slower because some babel plugins are non-serializable" penalty. If you
// provide the locations of known non-serializable objects, we can discover
Expand Down Expand Up @@ -131,7 +123,6 @@ export function optionsWithDefaults(options?: Options): Required<Options> {
staticComponents: false,
splitAtRoutes: [],
staticAppPaths: [],
skipBabel: [],
pluginHints: [],
amdCompatibility: 'cjs' as const,
};
Expand Down
34 changes: 0 additions & 34 deletions packages/shared-internals/src/babel-filter.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/shared-internals/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 0 additions & 11 deletions test-packages/support/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import type { BoundExpectFile } from './file-assertions';
import type { AppMeta } from '../../packages/core/src/index';
import { hbsToJS, locateEmbroiderWorkingDir, RewrittenPackageCache } from '../../packages/core/src/index';
import { Memoize } from 'typescript-memoize';
import { getRewrittenLocation } from './rewritten-path';

export class Transpiler {
private appOutputPath: string;
constructor(private appDir: string) {
let packageCache = RewrittenPackageCache.shared('embroider', appDir);
this.appOutputPath = packageCache.maybeMoved(packageCache.get(appDir)).root;
this.transpile = this.transpile.bind(this);
this.shouldTranspile = this.shouldTranspile.bind(this);
}

transpile(contents: string, fileAssert: BoundExpectFile): string {
Expand All @@ -33,15 +31,6 @@ export class Transpiler {
}
}

shouldTranspile(relativePath: string) {
// Depending on how the app builds, the babel filter is not at the same location
let embroiderLocation = join(locateEmbroiderWorkingDir(this.appDir), '_babel_filter_.js');
let shouldTranspile = existsSync(embroiderLocation)
? require(embroiderLocation)
: require(join(this.appOutputPath, '_babel_filter_'));
return shouldTranspile(join(this.appDir, getRewrittenLocation(this.appDir, relativePath))) as boolean;
}

@Memoize()
private get pkgJSON() {
return readJSONSync(join(this.appOutputPath, 'package.json'));
Expand Down
8 changes: 1 addition & 7 deletions tests/addon-template/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,5 @@ module.exports = function (defaults) {
*/

const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
return maybeEmbroider(app);
};
8 changes: 1 addition & 7 deletions tests/app-template/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,5 @@ const { maybeEmbroider } = require('@embroider/test-setup');
module.exports = function (defaults) {
let app = new EmberApp(defaults, {});

return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
return maybeEmbroider(app);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,5 @@ module.exports = function (defaults) {
},
});

return maybeEmbroider(app, {

skipBabel: [
{
package: 'qunit',
},
],
});
return maybeEmbroider(app);
};
5 changes: 0 additions & 5 deletions tests/fixtures/macro-sample-addon/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@ module.exports = function(defaults) {

return maybeEmbroider(app, {
useAddonAppBoot: false,
skipBabel: [
{
package: 'qunit',
},
],
});
};
5 changes: 0 additions & 5 deletions tests/scenarios/compat-addon-classic-features-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ appScenarios

return maybeEmbroider(app, {
availableContentForTypes: ['custom'],
skipBabel: [
{
package: 'qunit',
},
],
});
};
`,
Expand Down
5 changes: 0 additions & 5 deletions tests/scenarios/compat-exclude-dot-files-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ appScenarios

return maybeEmbroider(app, {
staticAddonTrees: false,
skipBabel: [
{
package: 'qunit',
},
],
});
};
`,
Expand Down
5 changes: 0 additions & 5 deletions tests/scenarios/compat-plugin-hints-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ appScenarios
});

return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
pluginHints: [
{
resolve: ["${__filename.replace(/\\/g, '/').replace(/\.ts$/, '.js')}"],
Expand Down
5 changes: 0 additions & 5 deletions tests/scenarios/compat-renaming-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ appScenarios
return maybeEmbroider(app, {
staticAddonTrees: false,
staticComponents: false,
skipBabel: [
{
package: 'qunit',
},
],
// TODO remove this when we virtualise the entrypoint
amdCompatibility: {
es: [
Expand Down
3 changes: 0 additions & 3 deletions tests/scenarios/compat-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
};
Expand Down
38 changes: 0 additions & 38 deletions tests/scenarios/compat-stage2-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,6 @@ stage2Scenarios
amdCompatibility: {
es: [['not-a-resolvable-package', ['default']]],
},
skipBabel: [
{
package: 'babel-filter-test1',
},
{
package: 'babel-filter-test2',
semverRange: '^4.0.0',
},
{
package: 'babel-filter-test3',
semverRange: '^2.0.0',
},
],
staticAppPaths: ['static-dir', 'top-level-static.js'],
packageRules: [
{
Expand Down Expand Up @@ -404,11 +391,6 @@ stage2Scenarios
});

return prebuild(app, {
skipBabel: [
{
package: 'qunit',
},
],
...opts
});
};
Expand Down Expand Up @@ -780,26 +762,6 @@ stage2Scenarios
assertFile.matches(/return require\(['"]some-package['"]\)/, 'should find plain cjs require');
});

test('transpilation runs for ember addons', async function (assert) {
assert.ok(build.shouldTranspile('node_modules/my-addon/components/has-relative-template.js'));
});

test('transpilation is skipped when package matches skipBabel', async function (assert) {
assert.ok(!build.shouldTranspile('node_modules/babel-filter-test1/index.js'));
});

test('transpilation is skipped when package and version match skipBabel', async function (assert) {
assert.ok(!build.shouldTranspile('node_modules/babel-filter-test2/index.js'));
});

test('transpilation runs when package version does not match skipBabel', async function (assert) {
assert.ok(build.shouldTranspile('node_modules/babel-filter-test3/index.js'));
});

test('transpilation runs for non-ember package that is not explicitly skipped', async function (assert) {
assert.ok(build.shouldTranspile('node_modules/babel-filter-test4/index.js'));
});

test(`app's babel plugins ran`, async function () {
let assertFile = expectFile('custom-babel-needed.js').transform(build.transpile);
assertFile.matches(/console\.log\(['"]embroider-sample-transforms-result['"]\)/);
Expand Down
3 changes: 0 additions & 3 deletions tests/scenarios/core-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand Down
5 changes: 0 additions & 5 deletions tests/scenarios/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ function setupScenario(project: Project) {
staticHelpers: true,
staticModifiers: true,
splitAtRoutes: ['split-me'],
skipBabel: [
{
package: 'qunit',
},
],
});
};
`,
Expand Down
5 changes: 0 additions & 5 deletions tests/scenarios/stage1-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ appScenarios
staticComponents: false,
staticHelpers: false,
staticModifiers: false,
skipBabel: [
{
package: 'qunit',
},
],
});
};
`,
Expand Down
4 changes: 0 additions & 4 deletions tests/scenarios/static-app-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,6 @@ appScenarios
},
},
],
skipBabel: [
{ package: 'qunit' },
{ package: 'macro-decorators' },
],
});
};
`,
Expand Down
8 changes: 1 addition & 7 deletions tests/ts-app-template-classic/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,5 @@ module.exports = function (defaults) {
'ember-cli-babel': { enableTypeScriptTransform: true },
});

return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
return maybeEmbroider(app);
};
8 changes: 1 addition & 7 deletions tests/ts-app-template/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,5 @@ module.exports = function (defaults) {
'ember-cli-babel': { enableTypeScriptTransform: true },
});

return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
return maybeEmbroider(app);
};