MCPcopy
hub / github.com/QwikDev/qwik / createNodeMainProcess

Function createNodeMainProcess

packages/qwik-city/src/static/node/node-main.ts:17–238  ·  view source on GitHub ↗
(sys: System, opts: StaticGenerateOptions)

Source from the content-addressed store, hash-verified

15import { normalizePath } from '../../utils/fs';
16
17export async function createNodeMainProcess(sys: System, opts: StaticGenerateOptions) {
18 const ssgWorkers: StaticGeneratorWorker[] = [];
19 const sitemapBuffer: string[] = [];
20 let sitemapStream: fs.WriteStream | null = null;
21
22 opts = { ...opts };
23
24 let outDir = opts.outDir;
25 if (typeof outDir !== 'string') {
26 throw new Error(`Missing "outDir" option`);
27 }
28 if (!isAbsolute(outDir)) {
29 throw new Error(`"outDir" must be an absolute file path, received: ${outDir}`);
30 }
31 outDir = normalizePath(outDir);
32
33 let maxWorkers = nodeCpus().length;
34 if (typeof opts.maxWorkers === 'number') {
35 maxWorkers = Math.max(1, Math.min(opts.maxWorkers, maxWorkers));
36 }
37
38 let maxTasksPerWorker = 20;
39 if (typeof opts.maxTasksPerWorker === 'number') {
40 maxTasksPerWorker = Math.max(1, Math.min(opts.maxTasksPerWorker, 50));
41 }
42
43 let sitemapOutFile = opts.sitemapOutFile;
44 if (sitemapOutFile !== null) {
45 if (typeof sitemapOutFile !== 'string') {
46 sitemapOutFile = 'sitemap.xml';
47 }
48 if (!isAbsolute(sitemapOutFile)) {
49 sitemapOutFile = resolve(outDir, sitemapOutFile);
50 }
51 }
52 const createWorker = () => {
53 let terminateResolve: (() => void) | null = null;
54 const mainTasks = new Map<string, WorkerMainTask>();
55
56 let workerFilePath: string | URL;
57 let terminateTimeout: number | null = null;
58
59 // Launch the worker using the package's index module, which bootstraps the worker thread.
60 if (typeof __filename === 'string') {
61 workerFilePath = __filename;
62 } else {
63 workerFilePath = import.meta.url;
64 }
65
66 if (typeof workerFilePath === 'string' && workerFilePath.startsWith('file://')) {
67 workerFilePath = new URL(workerFilePath);
68 }
69
70 const nodeWorker = new Worker(workerFilePath, { workerData: opts });
71 nodeWorker.unref();
72
73 const ssgWorker: StaticGeneratorWorker = {
74 activeTasks: 0,

Callers 1

createSystemFunction · 0.90

Calls 5

normalizePathFunction · 0.90
ensureDirFunction · 0.90
isAbsoluteFunction · 0.85
createWorkerFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…