Skip to content

Commit

Permalink
stay compatible with default core options
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Sep 11, 2024
1 parent be6f781 commit 36a6c1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/compat/src/babel-plugin-adjust-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function amdDefine(t: BabelTypes, adder: ImportUtil, path: NodePath<t.Program>,
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) {
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/resolver-loader.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?<filename>.*)[\\/]-embroider-entrypoint.js/;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 36a6c1d

Please sign in to comment.