Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ jobs:
# too slow and flaky. Perhaps better in v2?
# - host: ubuntu-latest
# browser: firefox
- host: windows-latest
browser: chromium
- host: macos-latest
browser: webkit
# - host: windows-latest
Expand Down
23 changes: 16 additions & 7 deletions packages/qwik-city/src/static/node/node-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import fs from 'node:fs';
import { cpus as nodeCpus } from 'node:os';
import { Worker } from 'node:worker_threads';
import { isAbsolute, resolve } from 'node:path';
import { dirname, extname, isAbsolute, join, resolve } from 'node:path';
import { ensureDir } from './node-system';
import { normalizePath } from '../../utils/fs';
import { createSingleThreadWorker } from '../worker-thread';
Expand Down Expand Up @@ -78,14 +78,23 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt

let workerFilePath: string | URL;

// Launch the worker using the package's index module, which bootstraps the worker thread.
if (typeof __filename === 'string') {
workerFilePath = __filename;
// CommonJS path
const ext = extname(__filename) || '.js';
workerFilePath = join(dirname(__filename), `index${ext}`);
} else {
workerFilePath = import.meta.url;
}
// ESM path (import.meta.url)
const thisUrl = new URL(import.meta.url);
const pathname = thisUrl.pathname || '';
let ext = '.js';
if (pathname.endsWith('.ts')) {
ext = '.ts';
} else if (pathname.endsWith('.mjs')) {
ext = '.mjs';
}

if (typeof workerFilePath === 'string' && workerFilePath.startsWith('file://')) {
workerFilePath = new URL(workerFilePath);
workerFilePath = new URL(`./index${ext}`, thisUrl);
}

const nodeWorker = new Worker(workerFilePath, { workerData: opts });
Expand Down Expand Up @@ -146,7 +155,7 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt
});

nodeWorker.on('exit', (code) => {
if (code !== 1) {
if (code !== 0) {
console.error(`worker exit ${code}`);
}
});
Expand Down