From 64347d556e5e309e427d704c0e3be83531496c0d Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sat, 21 Dec 2024 10:27:11 +0000 Subject: [PATCH] make an explicit options type and use it everywhere --- packages/compat/src/compat-app-builder.ts | 3 ++- packages/compat/src/compat-app.ts | 3 ++- packages/compat/src/options.ts | 25 ++++++---------------- packages/compat/src/v1-addon.ts | 6 +++--- packages/core/src/options.ts | 26 +++++++++++++++++++---- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/packages/compat/src/compat-app-builder.ts b/packages/compat/src/compat-app-builder.ts index 3af48f8d1..678ca7339 100644 --- a/packages/compat/src/compat-app-builder.ts +++ b/packages/compat/src/compat-app-builder.ts @@ -60,6 +60,7 @@ import escapeRegExp from 'escape-string-regexp'; import type CompatApp from './compat-app'; import { SyncDir } from './sync-dir'; +import { CompatOptionsType } from './options'; // This exists during the actual broccoli build step. As opposed to CompatApp, // which also exists during pipeline-construction time. @@ -75,7 +76,7 @@ export class CompatAppBuilder { private root: string, private origAppPackage: Package, private appPackageWithMovedDeps: Package, - private options: Required, + private options: CompatOptionsType, private compatApp: CompatApp, private configTree: V1Config, private synthVendor: Package, diff --git a/packages/compat/src/compat-app.ts b/packages/compat/src/compat-app.ts index 3146c8c0f..bdf9b4281 100644 --- a/packages/compat/src/compat-app.ts +++ b/packages/compat/src/compat-app.ts @@ -2,6 +2,7 @@ import type { Node as BroccoliNode } from 'broccoli-node-api'; import type { Stage, Package } from '@embroider/core'; import { PackageCache, WaitForTrees, RewrittenPackageCache, locateEmbroiderWorkingDir } from '@embroider/core'; import type Options from './options'; +import type { CompatOptionsType } from './options'; import { optionsWithDefaults } from './options'; import { Memoize } from 'typescript-memoize'; import { sync as pkgUpSync } from 'pkg-up'; @@ -41,7 +42,7 @@ interface Group { export default class CompatApp { private annotation = '@embroider/compat/app'; private active: CompatAppBuilder | undefined; - readonly options: Required; + readonly options: CompatOptionsType; private _publicAssets: { [filePath: string]: string } = Object.create(null); private _implicitScripts: string[] = []; diff --git a/packages/compat/src/options.ts b/packages/compat/src/options.ts index 67517db9e..bc0155d45 100644 --- a/packages/compat/src/options.ts +++ b/packages/compat/src/options.ts @@ -95,22 +95,6 @@ export default interface Options extends CoreOptions { // it on in production. But it can be helpful when testing how much of your // app is able to work with staticComponents enabled. allowUnsafeDynamicComponents?: 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 - * of the build if they are unused i.e. "tree shaking". - * - * Defaults to false which gives you greater compatibility with classic Ember apps at the - * cost of bigger builds. - * - * This setting takes over from `staticHelpers`, `staticModifiers`, and `staticComponents` - * because the Developer Experience was less than ideal if any of these settings did not - * agree i.e. they all needed to be true or they all needed to be false. - * - * Enabling this is a prerequisite for route splitting. - */ - staticInvokables?: boolean; } const defaults = Object.assign(coreWithDefaults(), { @@ -122,10 +106,14 @@ const defaults = Object.assign(coreWithDefaults(), { workspaceDir: null, packageRules: [], allowUnsafeDynamicComponents: false, - staticInvokables: false, }); -export function optionsWithDefaults(options?: Options): Required { +export type CompatOptionsType = Required< + Omit +> & + Pick; + +export function optionsWithDefaults(options?: Options): CompatOptionsType { return Object.assign({}, defaults, options); } @@ -138,7 +126,6 @@ export const recommendedOptions: { [name: string]: Options } = Object.freeze({ optimized: Object.freeze({ staticAddonTrees: true, staticAddonTestSupportTrees: true, - staticInvokables: true, staticEmberSource: true, allowUnsafeDynamicComponents: false, }), diff --git a/packages/compat/src/v1-addon.ts b/packages/compat/src/v1-addon.ts index 6d6bfc472..985860059 100644 --- a/packages/compat/src/v1-addon.ts +++ b/packages/compat/src/v1-addon.ts @@ -14,7 +14,6 @@ import rewriteAddonTree from './rewrite-addon-tree'; import { mergeWithAppend } from './merges'; import type { AddonMeta, PackageCache, AddonInstance, AddonTreePath } from '@embroider/core'; import { debug, findTopmostAddon } from '@embroider/core'; -import type Options from './options'; import walkSync from 'walk-sync'; import ObserveTree from './observe-tree'; import { isEmbroiderMacrosPlugin } from '@embroider/macros/src/node'; @@ -34,6 +33,7 @@ import loadAstPlugins from './prepare-htmlbars-ast-plugins'; import getRealAddon from './get-real-addon'; import type { Options as EtcOptions } from 'babel-plugin-ember-template-compilation'; import type CompatApp from './compat-app'; +import { CompatOptionsType } from './options'; const stockTreeNames: AddonTreePath[] = Object.freeze([ 'addon', @@ -82,7 +82,7 @@ const fastbootPublicationDir = '_fastboot_'; export default class V1Addon { constructor( protected addonInstance: AddonInstance, - protected addonOptions: Required, + protected addonOptions: CompatOptionsType, protected app: CompatApp, private packageCache: PackageCache, private orderIdx: number @@ -1094,7 +1094,7 @@ export default class V1Addon { export interface V1AddonConstructor { new ( addonInstance: any, - options: Required, + options: CompatOptionsType, app: CompatApp, packageCache: PackageCache, orderIdx: number diff --git a/packages/core/src/options.ts b/packages/core/src/options.ts index 6fbcb003a..6502d7e97 100644 --- a/packages/core/src/options.ts +++ b/packages/core/src/options.ts @@ -41,6 +41,22 @@ export default interface Options { */ 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 + * of the build if they are unused i.e. "tree shaking". + * + * Defaults to false which gives you greater compatibility with classic Ember apps at the + * cost of bigger builds. + * + * This setting takes over from `staticHelpers`, `staticModifiers`, and `staticComponents` + * because the Developer Experience was less than ideal if any of these settings did not + * agree i.e. they all needed to be true or they all needed to be false. + * + * Enabling this is a prerequisite for route splitting. + */ + staticInvokables?: boolean; + // Enables per-route code splitting. Any route names that match these patterns // will be split out of the initial app payload. If you use this, you must // also add @embroider/router to your app. See [@embroider/router's @@ -136,11 +152,13 @@ export default interface Options { }; } -export function optionsWithDefaults(options?: Options): Required { +export type CoreOptionsType = Required< + Omit +> & + Pick; + +export function optionsWithDefaults(options?: Options): CoreOptionsType { let defaults = { - staticHelpers: false, - staticModifiers: false, - staticComponents: false, splitAtRoutes: [], staticAppPaths: [], skipBabel: [],