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

Prevent redundant toTree wrapping for macros #1213

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 15 additions & 9 deletions packages/macros/src/ember-addon-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { join } from 'path';
import { BuildPluginParams } from './glimmer/ast-transform';
import { MacrosConfig, isEmbroiderMacrosPlugin } from './node';

let hasWrappedToTree = false;

export = {
name: '@embroider/macros',
included(this: any, parent: any) {
Expand Down Expand Up @@ -48,16 +50,20 @@ export = {

appInstance.import('vendor/embroider-macros-test-support.js', { type: 'test' });

// When we're used inside the traditional ember-cli build pipeline without
// Embroider, we unfortunately need to hook into here uncleanly because we
// need to delineate the point in time after which writing macro config is
// forbidden and consuming it becomes allowed. There's no existing hook with
// that timing.
const originalToTree = appInstance.toTree;
appInstance.toTree = function (...args) {
macrosConfig.finalize();
return originalToTree.apply(appInstance, args);
};

if (!hasWrappedToTree) {
// When we're used inside the traditional ember-cli build pipeline without
// Embroider, we unfortunately need to hook into here uncleanly because we
// need to delineate the point in time after which writing macro config is
// forbidden and consuming it becomes allowed. There's no existing hook with
// that timing.
appInstance.toTree = function (...args) {
macrosConfig.finalize();
return originalToTree.apply(appInstance, args);
};
hasWrappedToTree = true;
}
},

// Other addons are allowed to call this. It's needed if an addon needs to
Expand Down