Skip to content

Commit

Permalink
feat(remove rewritten-app): output _babel_config_.js in the .embroide…
Browse files Browse the repository at this point in the history
…r folder so it's separated from the rewritten-app
  • Loading branch information
BlueCutOfficial committed May 22, 2024
1 parent 22786e3 commit 187f072
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
12 changes: 9 additions & 3 deletions packages/compat/src/audit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, readJSONSync } from 'fs-extra';
import { existsSync, readFileSync, readJSONSync } from 'fs-extra';
import { join, resolve as resolvePath, dirname } from 'path';
import type { AppMeta, ResolverOptions } from '@embroider/core';
import { explicitRelative, hbsToJS, locateEmbroiderWorkingDir, Resolver, RewrittenPackageCache } from '@embroider/core';
Expand Down Expand Up @@ -153,8 +153,14 @@ export class Audit {

@Memoize()
private get babelConfig() {
// eslint-disable-next-line @typescript-eslint/no-require-imports
let config = require(join(this.movedAppRoot, this.meta.babel.filename));
// Depending on how the app builds, the babel config is not at the same location
let embroiderLocation = join(locateEmbroiderWorkingDir(this.originAppRoot), '_babel_config_.js');
let config = existsSync(embroiderLocation)
? // eslint-disable-next-line @typescript-eslint/no-require-imports
require(embroiderLocation)
: // eslint-disable-next-line @typescript-eslint/no-require-imports
require(join(this.movedAppRoot, this.meta.babel.filename));

config = Object.assign({}, config);
config.plugins = config.plugins.filter((p: any) => !isMacrosPlugin(p));

Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class CompatAppBuilder {
warn('Your build is slower because some babel plugins are non-serializable');
}
writeFileSync(
join(this.root, '_babel_config_.js'),
join(locateEmbroiderWorkingDir(this.compatApp.root), '_babel_config_.js'),
`module.exports = ${JSON.stringify(pconfig.config, null, 2)}`,
'utf8'
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function shouldSplitRoute(routeName: string, splitAtRoutes: (RegExp | string)[]

export function getAppFiles(appRoot: string): Set<string> {
const files: string[] = walkSync(appRoot, {
ignore: ['_babel_config_.js', '_babel_filter_.js', 'app.js', 'assets', 'testem.js', 'node_modules'],
ignore: ['_babel_filter_.js', 'app.js', 'assets', 'testem.js', 'node_modules'],
});
return new Set(files);
}
Expand Down
10 changes: 7 additions & 3 deletions test-packages/support/transpiler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readJSONSync } from 'fs-extra';
import { readJSONSync, existsSync } from 'fs-extra';
import { join } from 'path';
import type { TransformOptions } from '@babel/core';
import { transform } from '@babel/core';
import type { BoundExpectFile } from './file-assertions';
import type { AppMeta } from '../../packages/core/src/index';
import { hbsToJS, RewrittenPackageCache } from '../../packages/core/src/index';
import { hbsToJS, locateEmbroiderWorkingDir, RewrittenPackageCache } from '../../packages/core/src/index';
import { Memoize } from 'typescript-memoize';
import { getRewrittenLocation } from './rewritten-path';

Expand Down Expand Up @@ -53,6 +53,10 @@ export class Transpiler {
throw new Error(`@embroider/test-support only suports babel 7`);
}

return require(join(this.appOutputPath, this.emberMeta['babel'].filename)) as TransformOptions;
// Depending on how the app builds, the babel config is not at the same location
let embroiderLocation = join(locateEmbroiderWorkingDir(this.appDir), '_babel_config_.js');
return existsSync(embroiderLocation)
? (require(embroiderLocation) as TransformOptions)
: (require(join(this.appDir, this.emberMeta['babel'].filename)) as TransformOptions);
}
}
2 changes: 1 addition & 1 deletion tests/addon-template/babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (
) {
config = {};
} else {
config = require("./node_modules/.embroider/rewritten-app/_babel_config_");
config = require("./node_modules/.embroider/_babel_config_");
}

module.exports = config;
2 changes: 1 addition & 1 deletion tests/app-template/babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (
) {
config = {};
} else {
config = require("./node_modules/.embroider/rewritten-app/_babel_config_");
config = require("./node_modules/.embroider/_babel_config_");
}

module.exports = config;
2 changes: 1 addition & 1 deletion tests/ts-app-template-classic/babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let config;
if (process.env.EMBROIDER_PREBUILD || process.env.EMBROIDER_TEST_SETUP_FORCE === 'classic') {
config = {};
} else {
config = require('./node_modules/.embroider/rewritten-app/_babel_config_');
config = require('./node_modules/.embroider/_babel_config_');
}

module.exports = config;
2 changes: 1 addition & 1 deletion tests/ts-app-template/babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let config;
if (process.env.EMBROIDER_PREBUILD || process.env.EMBROIDER_TEST_SETUP_FORCE === 'classic') {
config = {};
} else {
config = require('./node_modules/.embroider/rewritten-app/_babel_config_');
config = require('./node_modules/.embroider/_babel_config_');
}

module.exports = config;

0 comments on commit 187f072

Please sign in to comment.