Skip to content

Allow configuring Embroider macros via a configure option#27

Open
rmoodyab wants to merge 1 commit into
ember-tooling:mainfrom
rmoodyab:configure-embroider-macros
Open

Allow configuring Embroider macros via a configure option#27
rmoodyab wants to merge 1 commit into
ember-tooling:mainfrom
rmoodyab:configure-embroider-macros

Conversation

@rmoodyab

Copy link
Copy Markdown

Why

ember-astro calls buildMacros() with no options, so consumers can't supply Embroider macros config. Compiling any Ember app/library gated on getGlobalConfig() then fails.

Concretely: importing a component library that depends on WarpDrive / ember-data — whose published code runs macroCondition(getGlobalConfig().WarpDriveMirror.env.PRODUCTION) — throws during the build:

@warp-drive-mirror/ember/dist/index.js: Cannot read properties of undefined (reading 'env')

because getGlobalConfig().WarpDriveMirror is undefined (no macros config was registered). A normal Ember app build supplies this via ember-cli-build / setConfig; there was no equivalent hook for the Astro integration.

What

Forward a configure callback to buildMacros({ configure }) (one of its documented options), so consumers can register global config:

import { defineConfig } from 'astro/config';
import { ember } from 'ember-astro';
import { setConfig } from '@warp-drive/build-config'; // or your lib's macros setup

export default defineConfig({
  integrations: [ember({ configure: (macros) => setConfig(macros, {}) })],
});

The buildMacros() call also moves into the integration factory so the option is honored per-instantiation.

Backward compatibility

Fully backward-compatible — when configure is omitted, buildMacros({ configure: undefined }) behaves exactly as the previous buildMacros() call.

Notes

Verified end-to-end: this is the only ember-astro change needed to compile a real Ember component library (that transitively pulls in WarpDrive) and render live examples inline in an Astro site. Happy to broaden this to a full macros options passthrough (buildMacros(options.macros) — exposing setOwnConfig/setConfig/configure) if you'd prefer that shape.

ember-astro called buildMacros() with no options, so consumers couldn't supply
macros config. Compiling Ember apps/libraries gated on getGlobalConfig() then
failed — e.g. importing a library that depends on WarpDrive/ember-data, whose
published code runs macroCondition(getGlobalConfig().WarpDriveMirror.env.PRODUCTION),
throws 'Cannot read properties of undefined (reading env)'.

Forward a `configure` callback to buildMacros({ configure }) (a documented
buildMacros option). Backward compatible: omitting it behaves exactly as before.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@NullVoxPopuli NullVoxPopuli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! thanks for your contribution!

I think instead of trying to accommodate every way of configuring babel, we should auto-detect the presence of a babel config (using babel's APIs to d o this), and then specify the path to that babel config -- then the babel config we have inline here should just be "the default" (only used when we don't detect a local babel config)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants