Skip to content

Commit 7340421

Browse files
committed
perf(smoke): spawn node dist/index.mjs directly + fix cli.ts hook for --import safety
- smoke.mjs spawns node with --import @esmx/core/cli + dist/index.mjs (no more pnpm filter overhead, ~3000ms vs ~25min on CI) - core/cli.ts: optional-chain parentURL.endsWith so the loader hook is safe when --import installs it before any module has a parentURL
1 parent 8a037a2 commit 7340421

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

packages/core/src/cli/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function resolve(
111111
nextResolve: Function
112112
) {
113113
if (
114-
context?.parentURL.endsWith('.ts') &&
114+
context?.parentURL?.endsWith('.ts') &&
115115
specifier.startsWith('.') &&
116116
!specifier.endsWith('.ts')
117117
) {

scripts/smoke.mjs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,27 @@ function assertHydratable(html, name) {
150150
}
151151

152152
function spawnServer(target) {
153-
const child = spawn('pnpm', ['--filter', `./${target.dir}`, 'start'], {
154-
stdio: ['ignore', 'pipe', 'pipe'],
155-
env: {
156-
...process.env,
157-
PORT: String(target.port),
158-
NODE_ENV: 'production'
153+
// Bypass `pnpm --filter X start` (workspace resolution + npm-script overhead
154+
// is ~5-10s per spawn on CI). Run dist/index.mjs directly with cwd set so
155+
// esmx can find its dist/server/manifest.json. Each example's dist is
156+
// already self-contained from `pnpm build:examples`.
157+
// --import @esmx/core/cli installs the Node ESM loader hook esmx uses for
158+
// bundler-handled assets (.css side-effect imports → no-op SyntheticModule)
159+
// and entry.node.ts extension resolution. Without it federation-style
160+
// imports crash at startup with ERR_UNKNOWN_FILE_EXTENSION.
161+
const child = spawn(
162+
process.execPath,
163+
['--import', '@esmx/core/cli', 'dist/index.mjs'],
164+
{
165+
cwd: target.dir,
166+
stdio: ['ignore', 'pipe', 'pipe'],
167+
env: {
168+
...process.env,
169+
PORT: String(target.port),
170+
NODE_ENV: 'production'
171+
}
159172
}
160-
});
173+
);
161174
child._stderr = '';
162175
child.stderr.on('data', (b) => {
163176
child._stderr += b.toString();

0 commit comments

Comments
 (0)