diff --git a/packages/compat/src/babel.ts b/packages/compat/src/babel.ts index 407bbdc9d..a744519f9 100644 --- a/packages/compat/src/babel.ts +++ b/packages/compat/src/babel.ts @@ -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[]; @@ -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, }; } diff --git a/tests/scenarios/compat-resolver-test.ts b/tests/scenarios/compat-resolver-test.ts index f3c0d53f7..edda45fe1 100644 --- a/tests/scenarios/compat-resolver-test.ts +++ b/tests/scenarios/compat-resolver-test.ts @@ -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" }); @@ -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" });