Skip to content

Commit

Permalink
Merge pull request #2106 from embroider-build/default-macros
Browse files Browse the repository at this point in the history
add macros plugins with default config rather than no plugins at all
  • Loading branch information
ef4 authored Sep 12, 2024
2 parents 94a010f + 9421052 commit ad1534d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 11 additions & 2 deletions packages/compat/src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { join } from 'path';
import type { Transform } from 'babel-plugin-ember-template-compilation';
import type { Options as ResolverTransformOptions } from './resolver-transform';
import type { Options as AdjustImportsOptions } from './babel-plugin-adjust-imports';
import MacrosConfig from '@embroider/macros/src/macros-config';

export interface CompatBabelState {
plugins: PluginItem[];
Expand All @@ -24,11 +25,19 @@ function loadCompatConfig(): CompatBabelState {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(compatFile);
}
let macros = MacrosConfig.for({}, process.cwd());
let { plugins: templateMacros, setConfig } = MacrosConfig.transforms();
setConfig(macros);
if (process.env.NODE_ENV === 'development') {
macros.enablePackageDevelopment(process.cwd());
macros.enableRuntimeMode();
}
macros.finalize();
return {
plugins: [],
templateTransforms: [],
babelMacros: [],
templateMacros: [],
babelMacros: macros.babelPluginConfig(),
templateMacros: templateMacros as any,
};
}

Expand Down
10 changes: 6 additions & 4 deletions tests/scenarios/compat-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2112,10 +2112,11 @@ Scenarios.fromProject(() => new Project())

expectTranspiled('components/my-thing.hbs').equalsCode(`
window.define("my-app/components/alpha", function () {
return importSync("@embroider/virtual/components/alpha");
return esc(_importSync0);
});
import { precompileTemplate } from "@ember/template-compilation";
import { importSync } from "@embroider/macros";
import esc from "../node_modules/@embroider/compat/node_modules/@embroider/macros/src/addon/es-compat2";
import * as _importSync0 from "@embroider/virtual/components/alpha";
export default precompileTemplate("{{component this.which}}", {
moduleName: "my-app/components/my-thing.hbs"
});
Expand All @@ -2141,10 +2142,11 @@ Scenarios.fromProject(() => new Project())

expectTranspiled('templates/index.hbs').equalsCode(`
window.define("my-app/components/alpha", function () {
return importSync("@embroider/virtual/components/alpha");
return esc(_importSync0);
});
import { precompileTemplate } from "@ember/template-compilation";
import { importSync } from "@embroider/macros";
import esc from "../node_modules/@embroider/compat/node_modules/@embroider/macros/src/addon/es-compat2";
import * as _importSync0 from "@embroider/virtual/components/alpha";
export default precompileTemplate("{{component this.which}}", {
moduleName: "my-app/templates/index.hbs"
});
Expand Down

0 comments on commit ad1534d

Please sign in to comment.