Skip to content

Commit

Permalink
remove static components, helpers, modifiers settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Feb 2, 2025
1 parent a4178fb commit f872f1c
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 238 deletions.
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 @@ -112,10 +112,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 {
return Object.assign({}, defaults, options);
Expand Down
11 changes: 4 additions & 7 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 @@ -323,15 +320,15 @@ class TemplateResolver implements ASTPlugin {
}

private get staticComponentsEnabled(): boolean {
return this.config.options.staticComponents || Boolean(this.auditHandler);
return this.config.options.staticInvokables || Boolean(this.auditHandler);
}

private get staticHelpersEnabled(): boolean {
return this.config.options.staticHelpers || Boolean(this.auditHandler);
return this.config.options.staticInvokables || Boolean(this.auditHandler);
}

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

private isIgnoredComponent(dasherizedName: string) {
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

0 comments on commit f872f1c

Please sign in to comment.