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

remove static components, helpers, modifiers settings #2246

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import type { CompatOptionsType } from './options';
// which also exists during pipeline-construction time.

export class CompatAppBuilder {
private staticComponents = false;
private staticHelpers = false;
private staticModifiers = false;

constructor(
private origAppPackage: Package,
private appPackageWithMovedDeps: Package,
Expand All @@ -37,39 +33,7 @@ export class CompatAppBuilder {
private contentForTree: ContentForConfig,
private synthVendor: Package,
private synthStyles: Package
) {
// staticInvokables always wins when configured
if (typeof options.staticInvokables !== 'undefined') {
if (
typeof options.staticComponents !== 'undefined' ||
typeof options.staticHelpers !== 'undefined' ||
typeof options.staticModifiers !== 'undefined'
) {
throw new Error(
'You cannot set `staticHelpers`, `staticComponents`, or `staticModifiers` if you have set `staticInvokables`. Delete these configs to continue.'
);
}
this.staticComponents = this.staticHelpers = this.staticModifiers = options.staticInvokables;
return;
}

if (typeof options.staticComponents !== 'undefined') {
// TODO it doesn't seem like we have any real deprecation functionality in this package yet.
// do we need it?
console.error(`Setting 'staticComponents' is deprecated. Use 'staticInvokables' instead`);
this.staticComponents = options.staticComponents;
}

if (typeof options.staticHelpers !== 'undefined') {
console.error(`Setting 'staticHelpers' is deprecated. Use 'staticInvokables' instead`);
this.staticHelpers = options.staticHelpers;
}

if (typeof options.staticModifiers !== 'undefined') {
console.error(`Setting 'staticModifiers' is deprecated. Use 'staticInvokables' instead`);
this.staticModifiers = options.staticModifiers;
}
}
) {}

private modulePrefix(): string {
return this.configTree.readConfig().modulePrefix;
Expand All @@ -94,9 +58,7 @@ export class CompatAppBuilder {
...allActiveAddons.filter(p => p.meta['auto-upgraded']),
]);
options.options = {
staticHelpers: this.staticHelpers,
staticModifiers: this.staticModifiers,
staticComponents: this.staticComponents,
staticInvokables: this.options.staticInvokables,
allowUnsafeDynamicComponents: this.options.allowUnsafeDynamicComponents,
};
return options;
Expand Down
5 changes: 1 addition & 4 deletions packages/compat/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ const defaults = Object.assign(coreWithDefaults(), {
useAddonConfigModule: true,
});

export type CompatOptionsType = Required<
Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>
> &
Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;
export type CompatOptionsType = Required<Options>;

export function optionsWithDefaults(options?: Options): CompatOptionsType {
if (!(options as any)?.staticEmberSource) {
Expand Down
52 changes: 10 additions & 42 deletions packages/compat/src/resolver-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ type Env = WithJSUtils<ASTPluginEnvironment> & {
// this is a subset of the full Options. We care about serializability, and we
// only needs parts that are easily serializable, which is why we don't keep the
// whole thing.
type UserConfig = Pick<
Required<CompatOptions>,
'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'allowUnsafeDynamicComponents'
>;
type UserConfig = Pick<Required<CompatOptions>, 'staticInvokables' | 'allowUnsafeDynamicComponents'>;

export interface CompatResolverOptions extends CoreResolverOptions {
activePackageRules: ActivePackageRules[];
Expand Down Expand Up @@ -322,25 +319,11 @@ class TemplateResolver implements ASTPlugin {
}
}

private get staticComponentsEnabled(): boolean {
private get staticInvokablesEnabled(): boolean {
if (!this.config?.options) {
return true;
}
return this.config.options.staticComponents || Boolean(this.auditHandler);
}

private get staticHelpersEnabled(): boolean {
if (!this.config?.options) {
return true;
}
return this.config.options.staticHelpers || Boolean(this.auditHandler);
}

private get staticModifiersEnabled(): boolean {
if (!this.config?.options) {
return true;
}
return this.config.options.staticModifiers || Boolean(this.auditHandler);
return this.config.options.staticInvokables || Boolean(this.auditHandler);
}

private isIgnoredComponent(dasherizedName: string) {
Expand Down Expand Up @@ -425,7 +408,7 @@ class TemplateResolver implements ASTPlugin {
}

private targetComponent(name: string, nameHint: string): ComponentResolution | null {
if (!this.staticComponentsEnabled) {
if (!this.staticInvokablesEnabled) {
return null;
}

Expand Down Expand Up @@ -468,7 +451,7 @@ class TemplateResolver implements ASTPlugin {
loc: Loc,
impliedBecause?: { componentName: string; argumentName: string }
): ComponentResolution | ResolutionFail | null {
if (!this.staticComponentsEnabled) {
if (!this.staticInvokablesEnabled) {
return null;
}

Expand Down Expand Up @@ -503,7 +486,7 @@ class TemplateResolver implements ASTPlugin {
}

private targetHelper(path: string): HelperResolution | null {
if (!this.staticHelpersEnabled) {
if (!this.staticInvokablesEnabled) {
return null;
}

Expand Down Expand Up @@ -592,7 +575,7 @@ class TemplateResolver implements ASTPlugin {
*/

// first, bail out on all the stuff we can obviously ignore
if ((!this.staticHelpersEnabled && !this.staticComponentsEnabled) || this.isIgnoredComponent(path)) {
if (!this.staticInvokablesEnabled || this.isIgnoredComponent(path)) {
return null;
}

Expand Down Expand Up @@ -653,21 +636,6 @@ class TemplateResolver implements ASTPlugin {
return null;
}

// Above we already bailed out if both of these were disabled, so we know at
// least one is turned on. If both aren't turned on, we're stuck, because we
// can't even tell if this *is* a component vs a helper.
if (!this.staticHelpersEnabled || !this.staticComponentsEnabled) {
this.reportError({
type: 'error',
message: 'unsupported ambiguity between helper and component',
detail: `this use of "{{${path}}}" could be helper "{{ (${path}) }}" or component "<${capitalize(
camelCase(path)
)} />", and your settings for staticHelpers and staticComponents do not agree. Either switch to one of the unambiguous forms, or make staticHelpers and staticComponents agree, or use a "disambiguate" packageRule to work around the problem if its in third-party code you cannot easily fix.`,
loc,
});
return null;
}

let componentRules = this.rules.components.get(path);
return {
type: 'component',
Expand All @@ -681,7 +649,7 @@ class TemplateResolver implements ASTPlugin {
}

private targetElementModifier(path: string): ModifierResolution | null {
if (!this.staticModifiersEnabled) {
if (!this.staticInvokablesEnabled) {
return null;
}

Expand Down Expand Up @@ -709,7 +677,7 @@ class TemplateResolver implements ASTPlugin {
}

targetDynamicModifier(modifier: ComponentLocator, loc: Loc): ModifierResolution | ResolutionFail | null {
if (!this.staticModifiersEnabled) {
if (!this.staticInvokablesEnabled) {
return null;
}

Expand All @@ -726,7 +694,7 @@ class TemplateResolver implements ASTPlugin {
}

private targetDynamicHelper(helper: ComponentLocator): HelperResolution | null {
if (!this.staticHelpersEnabled) {
if (!this.staticInvokablesEnabled) {
return null;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/compat/tests/audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ describe('audit', function () {
appRoot: app.baseDir,
modulePrefix: 'audit-this-app',
options: {
staticComponents: true,
staticHelpers: true,
staticModifiers: true,
staticInvokables: true,
allowUnsafeDynamicComponents: false,
},
activePackageRules: [],
Expand Down
66 changes: 20 additions & 46 deletions packages/core/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
export default interface Options {
/**
* When true, we statically resolve all template helpers at build time. This
* causes unused helpers to be left out of the build ("tree shaking" of
* helpers).
*
* Defaults to false, which gives you greater compatibility with classic Ember
* apps at the cost of bigger builds.
*
* Enabling this is a prerequisite for route splitting.
*
* @deprecated use staticInvokables instead
*/
staticHelpers?: boolean;

/**
* When true, we statically resolve all modifiers at build time. This
* causes unused modifiers to be left out of the build ("tree shaking" of
* modifiers).
*
* Defaults to false, which gives you greater compatibility with classic Ember
* apps at the cost of bigger builds.
*
* Enabling this is a prerequisite for route splitting.
*
* @deprecated use staticInvokables instead
*/
staticModifiers?: boolean;

/**
* When true, we statically resolve all components at build time. This causes
* unused components to be left out of the build ("tree shaking" of
* components).
*
* Defaults to false, which gives you greater compatibility with classic Ember
* apps at the cost of bigger builds.
*
* Enabling this is a prerequisite for route splitting.
*
* @deprecated use staticInvokables instead
*/
staticComponents?: boolean;

/**
* When true, we statically resolve all components, modifiers, and helpers (collectively
* knows as Invokables) at build time. This causes any unused Invokables to be left out
Expand Down Expand Up @@ -101,13 +59,29 @@ export default interface Options {
pluginHints?: { resolve: string[]; useMethod?: string }[];
}

export type CoreOptionsType = Required<
Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>
> &
Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;
export type CoreOptionsType = Required<Options>;

export function optionsWithDefaults(options?: Options): CoreOptionsType {
if ((options as any)?.staticHelpers !== undefined) {
throw new Error(
`You have set 'staticHelpers' on your Embroider options. This setting has been removed and replaced with 'staticInvokables'`
);
}

if ((options as any)?.staticComponents !== undefined) {
throw new Error(
`You have set 'staticComponents' on your Embroider options. This setting has been removed and replaced with 'staticInvokables'`
);
}

if ((options as any)?.staticModifiers !== undefined) {
throw new Error(
`You have set 'staticModifiers' on your Embroider options. This setting has been removed and replaced with 'staticInvokables'`
);
}

let defaults = {
staticInvokables: true,
splitAtRoutes: [],
staticAppPaths: [],
pluginHints: [],
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ export function renderEntrypoint(
let options = (resolver.options as CompatResolverOptions).options ?? optionsWithDefaults();

let requiredAppFiles = [appFiles.otherAppFiles];
if (!options.staticComponents) {
if (!options.staticInvokables) {
requiredAppFiles.push(appFiles.components);
}
if (!options.staticHelpers) {
requiredAppFiles.push(appFiles.helpers);
}
if (!options.staticModifiers) {
requiredAppFiles.push(appFiles.modifiers);
}

Expand Down
Loading