From 36a6c1d3bf28a9eeda5fc0a22fd342d3ac111d88 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Wed, 11 Sep 2024 16:51:20 +0100 Subject: [PATCH] stay compatible with default core options --- packages/compat/src/babel-plugin-adjust-imports.ts | 4 ++-- packages/core/src/resolver-loader.ts | 11 ++++++++--- packages/core/src/virtual-entrypoint.ts | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/compat/src/babel-plugin-adjust-imports.ts b/packages/compat/src/babel-plugin-adjust-imports.ts index f3eaaa66e..9fe846aa3 100644 --- a/packages/compat/src/babel-plugin-adjust-imports.ts +++ b/packages/compat/src/babel-plugin-adjust-imports.ts @@ -136,7 +136,7 @@ function amdDefine(t: BabelTypes, adder: ImportUtil, path: NodePath, function preprocessExtraImports(loader: ResolverLoader): ExtraImports { let extraImports: ExtraImports = {}; let config = loader.resolver.options as CompatResolverOptions; - for (let rule of config.activePackageRules) { + for (let rule of config.activePackageRules ?? []) { if (rule.addonModules) { for (let [filename, moduleRules] of Object.entries(rule.addonModules)) { for (let root of rule.roots) { @@ -200,7 +200,7 @@ function lazyPackageLookup(config: InternalConfig, filename: string) { function preprocessComponentExtraImports(loader: ResolverLoader): ExtraImports { let extraImports: ExtraImports = {}; let config = loader.resolver.options as CompatResolverOptions; - for (let rule of config.activePackageRules) { + for (let rule of config.activePackageRules ?? []) { if (rule.components) { for (let [componentName, rules] of Object.entries(rule.components)) { if (rules.invokes) { diff --git a/packages/core/src/resolver-loader.ts b/packages/core/src/resolver-loader.ts index 4a6aebfb6..c7d7fe460 100644 --- a/packages/core/src/resolver-loader.ts +++ b/packages/core/src/resolver-loader.ts @@ -1,5 +1,5 @@ -import { readJSONSync } from 'fs-extra'; -import type { Options } from './module-resolver-options'; +import { existsSync, readJSONSync } from 'fs-extra'; +import { buildResolverOptions, type Options } from './module-resolver-options'; import { Resolver } from './module-resolver'; import { locateEmbroiderWorkingDir } from '@embroider/shared-internals'; import { join } from 'path'; @@ -26,7 +26,12 @@ export class ResolverLoader { get resolver(): Resolver { if (!this.#resolver) { - let config: Options = readJSONSync(join(locateEmbroiderWorkingDir(this.appRoot), 'resolver.json')); + let config: Options; + if (existsSync(this.#configFile)) { + config = readJSONSync(this.#configFile); + } else { + config = buildResolverOptions({}); + } this.#resolver = new Resolver(config); } return this.#resolver; diff --git a/packages/core/src/virtual-entrypoint.ts b/packages/core/src/virtual-entrypoint.ts index a74c5648a..da5d4716a 100644 --- a/packages/core/src/virtual-entrypoint.ts +++ b/packages/core/src/virtual-entrypoint.ts @@ -9,6 +9,7 @@ import walkSync from 'walk-sync'; import type { V2AddonPackage } from '@embroider/shared-internals/src/package'; import { encodePublicRouteEntrypoint } from './virtual-route-entrypoint'; import escapeRegExp from 'escape-string-regexp'; +import { optionsWithDefaults } from './options'; const entrypointPattern = /(?.*)[\\/]-embroider-entrypoint.js/; @@ -68,7 +69,7 @@ export function renderEntrypoint( resolver.options.podModulePrefix ); - let options = (resolver.options as CompatResolverOptions).options; + let options = (resolver.options as CompatResolverOptions).options ?? optionsWithDefaults(); let requiredAppFiles = [appFiles.otherAppFiles]; if (!options.staticComponents) {