Skip to content

Commit

Permalink
fix(cli): remove configLoadingMode and use import-fresh (#2629)
Browse files Browse the repository at this point in the history
fix initialization of import-fresh's Worker
  • Loading branch information
AviVahl authored Jan 13, 2025
1 parent b409cb9 commit 5c09c8c
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 299 deletions.
13 changes: 0 additions & 13 deletions packages/engine-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ async function engine() {
description: 'Enable config build via config loaders',
default: false,
},
configLoadingMode: {
type: (value: string) => {
if (value === 'fresh' || value === 'watch' || value === 'require') {
return value;
} else {
throw new Error(`Invalid config loading mode: ${value}`);
}
},
description: 'Config loading mode (fresh, watch, require)',
default: undefined,
},
verbose: {
type: Boolean,
description: 'Verbose output',
Expand Down Expand Up @@ -195,7 +184,6 @@ async function engine() {
} else {
const dev = argv.flags.dev ?? argv.flags.watch;
const run = argv.flags.run ?? dev;
const configLoadingMode = argv.flags.configLoadingMode ?? (argv.flags.watch ? 'watch' : 'require');
const runtimeArgs = argv.flags.runtimeArgs;
addRuntimeArgsFlagsFromEngineConfig(engineConfig, argv.flags, runtimeArgs);

Expand All @@ -205,7 +193,6 @@ async function engine() {
runtimeArgs,
dev,
run,
configLoadingMode,
engineConfig,
});
}
Expand Down
7 changes: 1 addition & 6 deletions packages/engine-cli/src/engine-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createBuildEndPluginHook } from './esbuild-build-end-plugin.js';
import { loadConfigFile } from './load-config-file.js';
import { writeWatchSignal } from './watch-signal.js';
import { resolveBuildEntryPoints } from './resolve-build-configurations.js';
import { ConfigLoadingMode, launchDashboardServer } from './launch-dashboard-server.js';
import { launchDashboardServer } from './launch-dashboard-server.js';
import { createBuildConfiguration } from './create-environments-build-configuration.js';
import { readEntryPoints, writeEntryPoints } from './entrypoint-files.js';
import { EntryPoints, EntryPointsPaths } from './create-entrypoints.js';
Expand Down Expand Up @@ -40,7 +40,6 @@ export interface RunEngineOptions {
writeMetadataFiles?: boolean;
publicPath?: string;
publicConfigsRoute?: string;
configLoadingMode?: ConfigLoadingMode;
staticBuild?: boolean;
title?: string;
}
Expand All @@ -64,7 +63,6 @@ export async function runEngine({
runtimeArgs = {},
writeMetadataFiles = !watch,
publicConfigsRoute = 'configs',
configLoadingMode = 'require',
staticBuild = false,
title,
}: RunEngineOptions = {}): Promise<{
Expand Down Expand Up @@ -249,11 +247,8 @@ export async function runEngine({
configMapping,
runtimeOptions,
outputPath,
configLoadingMode,
analyze,
waitForWebRebuild,
buildConditions,
extensions,
);
if (watch) {
writeWatchSignal(outputPath, { isAliveUrl: `http://localhost:${devServer.port}/is_alive` });
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-cli/src/import-fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Worker, isMainThread, parentPort, workerData } from 'node:worker_thread
export async function importFresh(filePath: string[], exportSymbolName?: string): Promise<unknown[]>;
export async function importFresh(filePath: string, exportSymbolName?: string): Promise<unknown>;
export async function importFresh(filePath: string | string[], exportSymbolName = 'default'): Promise<unknown> {
const worker = new Worker(import.meta.url, {
const worker = new Worker(new URL(import.meta.url), {
workerData: { filePath, exportSymbolName } satisfies ImportFreshWorkerData,
// doesn't seem to inherit two levels deep (Worker from Worker)
execArgv: [...process.execArgv],
Expand Down
1 change: 0 additions & 1 deletion packages/engine-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export { ENGINE_CONFIG_FILE_NAME } from './find-features/build-constants.js';
export { loadFeatureDirectory } from './find-features/load-feature-directory.js';
export * from './find-features/merge.js';
export { extractModuleRequests } from './find-features/resolve-module-graph.js';
export { NodeConfigManager } from './node-config-manager.js';
export { resolveRuntimeOptions, type RunNodeManagerOptions } from './resolve-runtime-options.js';
export { RunningFeatureOptions, getRunningFeature } from './run-environment.js';
export { runLocalNodeManager } from './run-local-mode-manager.js';
Expand Down
22 changes: 0 additions & 22 deletions packages/engine-cli/src/launch-dashboard-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import { ConfigurationEnvironmentMapping, FeatureEnvironmentMapping } from '@wix
import express from 'express';
import { LaunchOptions, RouteMiddleware, launchServer } from './start-dev-server.js';
import { runLocalNodeManager } from './run-local-mode-manager.js';
import { NodeConfigManager } from './node-config-manager.js';
import type { StaticConfig } from './types.js';

export type ConfigLoadingMode = 'fresh' | 'watch' | 'require';

export async function launchDashboardServer(
rootDir: string,
serveStatic: StaticConfig[],
Expand All @@ -18,11 +15,8 @@ export async function launchDashboardServer(
configMapping: ConfigurationEnvironmentMapping,
runtimeOptions: Map<string, string | boolean | undefined>,
outputPath: string,
configLoadingMode: ConfigLoadingMode,
analyzeForBuild: () => Promise<unknown>,
waitForBuildReady?: (cb: () => void) => boolean,
buildConditions?: string[],
extensions?: string[],
): Promise<ReturnType<typeof launchServer>> {
const staticMiddlewares = serveStatic.map(({ route, directoryPath }) => ({
path: route,
Expand All @@ -35,10 +29,7 @@ export async function launchDashboardServer(
featureEnvironmentsMapping,
configMapping,
outputPath,
configLoadingMode,
waitForBuildReady,
buildConditions,
extensions,
);
const autoRunFeatureName = runtimeOptions.get('feature') as string | undefined;
if (autoRunFeatureName) {
Expand Down Expand Up @@ -104,21 +95,10 @@ function runOnDemandSingleEnvironment(
featureEnvironmentsMapping: FeatureEnvironmentMapping,
configMapping: ConfigurationEnvironmentMapping,
outputPath: string,
configLoadingMode: 'fresh' | 'watch' | 'require',
waitForBuildReady?: (cb: () => void) => boolean,
buildConditions?: string[],
extensions?: string[],
) {
let currentlyDisposing: Promise<unknown> | undefined;
const openManagers = new Map<string, Awaited<ReturnType<typeof runLocalNodeManager>>>();
const configManager =
configLoadingMode === 'fresh' || configLoadingMode === 'watch'
? new NodeConfigManager(configLoadingMode, {
absWorkingDir: rootDir,
conditions: buildConditions,
resolveExtensions: extensions,
})
: undefined;

async function run(featureName: string, configName: string, runtimeArgs: string) {
try {
Expand All @@ -142,7 +122,6 @@ function runOnDemandSingleEnvironment(
configMapping,
runOptions,
outputPath,
configManager,
{
routeMiddlewares: [
{
Expand All @@ -159,7 +138,6 @@ function runOnDemandSingleEnvironment(
async function disposeOpenManagers() {
await currentlyDisposing;
if (openManagers.size > 0) {
await configManager?.disposeAll();
const toDispose = [];
for (const { manager } of openManagers.values()) {
toDispose.push(manager.dispose());
Expand Down
166 changes: 0 additions & 166 deletions packages/engine-cli/src/node-config-manager.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/engine-cli/src/run-local-mode-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ import {
} from '@wixc3/engine-runtime-node';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { NodeConfigManager } from './node-config-manager.js';
import { importFresh } from './import-fresh.js';

export async function runLocalNodeManager(
featureEnvironmentsMapping: FeatureEnvironmentMapping,
configMapping: ConfigurationEnvironmentMapping,
execRuntimeOptions: Map<string, string | boolean | undefined>,
outputPath: string = 'dist-engine',
configManager?: NodeConfigManager,
serverOptions?: ILaunchHttpServerOptions,
) {
const manager = new NodeEnvManager(
{ url: pathToFileURL(join(outputPath, 'node/')).href },
featureEnvironmentsMapping,
configMapping,
configManager?.loadConfigs,
(entryPoints: string[]) => importFresh(entryPoints, 'default'),
);
const { port } = await manager.autoLaunch(execRuntimeOptions, serverOptions);
return { port, manager };
Expand Down
Loading

0 comments on commit 5c09c8c

Please sign in to comment.