@hyperfrontend/builder 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/_dependencies/@hyperfrontend/project-scope/core/fs/index.cjs.js +10 -3
  3. package/_dependencies/@hyperfrontend/project-scope/core/fs/index.esm.js +10 -3
  4. package/_dependencies/@hyperfrontend/project-scope/core/index.cjs.js +16 -6
  5. package/_dependencies/@hyperfrontend/project-scope/core/index.esm.js +16 -6
  6. package/_dependencies/@hyperfrontend/project-scope/core/path/index.cjs.js +4 -5
  7. package/_dependencies/@hyperfrontend/project-scope/core/path/index.esm.js +5 -4
  8. package/_dependencies/@hyperfrontend/project-scope/project/root/index.cjs.js +5 -1
  9. package/_dependencies/@hyperfrontend/project-scope/project/root/index.esm.js +5 -1
  10. package/bin/hf-build.js +110 -82
  11. package/bin/hf-build.linux-x64 +0 -0
  12. package/bin/index.cjs.js +82 -36
  13. package/bin/index.esm.js +82 -36
  14. package/bin/script/index.cjs.js +91 -45
  15. package/bin/script/index.esm.js +81 -35
  16. package/bundle/declarations/dts-per-entry.d.ts.map +1 -1
  17. package/bundle/declarations/dts-pre-pass.d.ts.map +1 -1
  18. package/bundle/declarations/index.cjs.js +118 -72
  19. package/bundle/declarations/index.esm.js +83 -37
  20. package/bundle/dependencies/index.cjs.js +95 -49
  21. package/bundle/dependencies/index.d.ts +13 -24
  22. package/bundle/dependencies/index.esm.js +79 -33
  23. package/bundle/dependencies/pre-pass.d.ts +13 -24
  24. package/bundle/dependencies/pre-pass.d.ts.map +1 -1
  25. package/bundle/index.cjs.js +203 -175
  26. package/bundle/index.esm.js +107 -79
  27. package/bundle/rollup/dispatch.d.ts +12 -14
  28. package/bundle/rollup/dispatch.d.ts.map +1 -1
  29. package/bundle/rollup/index.cjs.js +75 -29
  30. package/bundle/rollup/index.d.ts +14 -16
  31. package/bundle/rollup/index.esm.js +76 -30
  32. package/bundle/worker-locator.d.ts +47 -0
  33. package/bundle/worker-locator.d.ts.map +1 -0
  34. package/index.cjs.js +112 -84
  35. package/index.esm.js +113 -85
  36. package/package.json +31 -3
@@ -8,7 +8,7 @@ import { setTimeout, clearInterval, setInterval } from '../_dependencies/@hyperf
8
8
  import { createRequire } from 'node:module';
9
9
  import { join as join$1, dirname, isAbsolute, resolve } from 'node:path';
10
10
  import { spawn } from 'node:child_process';
11
- import { rmSync, existsSync, mkdtempSync, readFileSync, cpSync, statSync, unlinkSync, rmdirSync } from 'node:fs';
11
+ import { existsSync, rmSync, mkdtempSync, readFileSync, cpSync, statSync, unlinkSync, rmdirSync } from 'node:fs';
12
12
  import { tmpdir } from 'node:os';
13
13
  import { stringify, parse } from '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.esm.js';
14
14
  import { readJsonFileIfExists, exists as exists$1, readJsonFile } from '../_dependencies/@hyperfrontend/project-scope/core/fs/index.esm.js';
@@ -33,6 +33,70 @@ import { removeEmptyDirs } from '../_shared/bundle/fs/empty-dirs/index.esm.js';
33
33
  import { mergeDemand, classifyNamespaceUse, collectNamespaceUsage } from '../_shared/bundle/dependencies/prune/namespace-usage/index.esm.js';
34
34
  import { resolveEntries } from '../_shared/bundle/entries/resolve-entries/index.esm.js';
35
35
 
36
+ const SWC_NODE_REGISTER = '@swc-node/register';
37
+ const probeDir = (dir, offset) => {
38
+ const compiled = join$1(dir, ...offset, 'index.cjs.js');
39
+ if (existsSync(compiled))
40
+ return { path: compiled, execArgv: [] };
41
+ const source = join$1(dir, ...offset, 'index.ts');
42
+ if (existsSync(source))
43
+ return { path: source, execArgv: ['--require', SWC_NODE_REGISTER] };
44
+ return undefined;
45
+ };
46
+ /**
47
+ * Directory of the currently-executing builder module, read from `__dirname`.
48
+ * It is present in the shipped CommonJS build, in the `@swc-node/register` source
49
+ * bootstrap, and under the test runner, so callers get their own on-disk location
50
+ * and can find the worker beside them however the builder was packaged.
51
+ *
52
+ * @returns Absolute directory path of the running module.
53
+ *
54
+ * @example Anchoring a lookup beside the running builder
55
+ * ```typescript
56
+ * const invocation = ascendForWorker(['bundle', 'rollup', 'worker'], currentModuleDir())
57
+ * ```
58
+ */
59
+ const currentModuleDir = () => {
60
+ /* istanbul ignore if -- @preserve the ESM build has no __dirname; the shipped CommonJS build and the test runner always define it, so this guard is unreachable under test */
61
+ if (typeof __dirname === 'undefined') {
62
+ throw createError('@hyperfrontend/builder self-location requires the CommonJS build; drive build() from the CommonJS entry point');
63
+ }
64
+ return __dirname;
65
+ };
66
+ /**
67
+ * Locate a builder worker entry by ascending from a start directory toward the
68
+ * filesystem root, returning the first ancestor at which the worker exists at the
69
+ * given in-package offset. The compiled `index.cjs.js` is preferred; an `index.ts`
70
+ * sibling (source-mode bootstrap) resolves with the swc loader attached.
71
+ *
72
+ * The worker ships inside the builder's own package, so resolving relative to the
73
+ * running module finds it wherever the package lives — built dist, an installed
74
+ * `node_modules` copy, or melded into a host bundle under `_dependencies/`.
75
+ *
76
+ * @param offset - In-package path segments to the worker directory (e.g. `['bundle', 'rollup', 'worker']`).
77
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
78
+ * @returns The resolved worker invocation, or `undefined` if no worker exists at the offset under any ancestor.
79
+ *
80
+ * @example Resolving the rollup worker from the running module
81
+ * ```typescript
82
+ * const invocation = ascendForWorker(['bundle', 'rollup', 'worker'])
83
+ * if (!invocation) throw new Error('builder rollup worker not found beside the builder module')
84
+ * ```
85
+ */
86
+ const ascendForWorker = (offset, startDir = currentModuleDir()) => {
87
+ let dir = startDir;
88
+ let parent = dirname(dir);
89
+ // how: probe each level then step up; the final probe covers the filesystem root, where parent === dir
90
+ while (parent !== dir) {
91
+ const found = probeDir(dir, offset);
92
+ if (found)
93
+ return found;
94
+ dir = parent;
95
+ parent = dirname(dir);
96
+ }
97
+ return probeDir(dir, offset);
98
+ };
99
+
36
100
  const log$b = logger.channel('builder:bundle:dependencies:pre-pass');
37
101
  const REPORT_DIR_PREFIX$1 = 'hf-builder-prepass-';
38
102
  const createReportDir$1 = () => mkdtempSync(join$2(tmpdir(), REPORT_DIR_PREFIX$1));
@@ -69,43 +133,25 @@ const readReport$1 = (reportPath, job) => {
69
133
  const data = parse(readFileSync(reportPath, 'utf8'));
70
134
  return { job, outputSize: data.outputSize, endHeapMB: data.endHeapMB, endRssMB: data.endRssMB, durationMs: data.durationMs };
71
135
  };
72
- const SWC_NODE_REGISTER$1 = '@swc-node/register';
73
- const swcNodeAvailable$1 = (workspaceRoot) => existsSync(join$2(workspaceRoot, 'node_modules', '@swc-node', 'register', 'index.js'));
74
136
  /**
75
- * Default worker-path resolution: prefers the built-and-published artifact, falls
76
- * back to the workspace dist path, and finally to the in-source TypeScript file
77
- * via `@swc-node/register` (bootstrap case where builder is building itself for
78
- * the first time and the dist worker doesn't exist yet).
79
- *
80
- * Looks at, in order:
81
- * 1. `<workspaceRoot>/dist/libs/builder/bundle/dependencies/worker/index.cjs.js`
82
- * 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/dependencies/worker/index.cjs.js`
83
- * 3. `<workspaceRoot>/libs/builder/src/bundle/dependencies/worker/index.ts` (with `--require \@swc-node/register`)
84
- *
85
- * @param workspaceRoot - Absolute workspace root.
86
- * @returns Worker invocation descriptor, or `undefined` if no candidate exists.
87
- *
88
- * @example Locating the worker for an in-workspace consumer
137
+ * Resolves the dependency pre-pass worker by self-locating it beside the running
138
+ * builder module: ascends from the module's own directory to the builder package
139
+ * root and returns the worker at `bundle/dependencies/worker`. This works whether
140
+ * the builder runs from its built dist, an installed `node_modules` copy, or
141
+ * melded into a host bundle under `_dependencies/`. The compiled `index.cjs.js`
142
+ * is preferred; an `index.ts` sibling resolves with the `@swc-node/register`
143
+ * loader for source-mode bootstrap.
144
+ *
145
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
146
+ * @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
147
+ *
148
+ * @example Locating the worker beside the builder
89
149
  * ```typescript
90
- * const invocation = resolveDefaultWorkerPath('/abs/repo')
150
+ * const invocation = resolveDefaultWorkerPath()
91
151
  * if (!invocation) throw new Error('builder worker artifact not found')
92
152
  * ```
93
153
  */
94
- const resolveDefaultWorkerPath = (workspaceRoot) => {
95
- const distCandidates = [
96
- join$2(workspaceRoot, 'dist', 'libs', 'builder', 'bundle', 'dependencies', 'worker', 'index.cjs.js'),
97
- join$2(workspaceRoot, 'node_modules', '@hyperfrontend', 'builder', 'bundle', 'dependencies', 'worker', 'index.cjs.js'),
98
- ];
99
- for (const path of distCandidates) {
100
- if (existsSync(path))
101
- return { path, execArgv: [] };
102
- }
103
- const sourcePath = join$2(workspaceRoot, 'libs', 'builder', 'src', 'bundle', 'dependencies', 'worker', 'index.ts');
104
- if (existsSync(sourcePath) && swcNodeAvailable$1(workspaceRoot)) {
105
- return { path: sourcePath, execArgv: ['--require', SWC_NODE_REGISTER$1] };
106
- }
107
- return undefined;
108
- };
154
+ const resolveDefaultWorkerPath = (startDir) => ascendForWorker(['bundle', 'dependencies', 'worker'], startDir);
109
155
  /**
110
156
  * Sequentially runs the supplied pre-pass jobs by forking a fresh Node child
111
157
  * per invocation. Strict sequential execution is mandatory — concurrent
@@ -234,9 +280,9 @@ const buildJobs$1 = (entries, context) => {
234
280
  const runDtsPerEntry = async (context, monitor) => {
235
281
  if (context.bundledDeps.length === 0 && context.workspaceBundledDeps.length === 0)
236
282
  return;
237
- const invocation = resolveDefaultWorkerPath(context.workspaceRoot);
283
+ const invocation = resolveDefaultWorkerPath();
238
284
  if (!invocation) {
239
- throw createError('bundleAllDeps is enabled but the pre-pass worker artifact was not found for the per-entry d.ts pass.');
285
+ throw createError('bundleAllDeps is enabled but the pre-pass worker could not be located beside the builder module for the per-entry d.ts pass.');
240
286
  }
241
287
  const jobs = buildJobs$1(context.entryPointDiscovery.entryPoints, context);
242
288
  if (jobs.length === 0) {
@@ -419,9 +465,9 @@ const buildWorkspaceJobs = (context, npmDeps) => {
419
465
  const runDtsPrePass = async (context, monitor) => {
420
466
  if (context.bundledDeps.length === 0 && context.workspaceBundledDeps.length === 0)
421
467
  return;
422
- const invocation = resolveDefaultWorkerPath(context.workspaceRoot);
468
+ const invocation = resolveDefaultWorkerPath();
423
469
  if (!invocation) {
424
- throw createError('bundleAllDeps is enabled but the pre-pass worker artifact was not found for the d.ts pre-pass.');
470
+ throw createError('bundleAllDeps is enabled but the pre-pass worker could not be located beside the builder module for the d.ts pre-pass.');
425
471
  }
426
472
  const npmJobs = buildJobs(context.bundledDeps, context);
427
473
  const workspaceJobs = buildWorkspaceJobs(context, context.bundledDeps);
@@ -3339,43 +3385,25 @@ const toUmdBuildDescriptor = (entry, config, context, reportPath) => {
3339
3385
 
3340
3386
  const log$1 = logger.channel('builder:bundle:rollup:dispatch');
3341
3387
  const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
3342
- const SWC_NODE_REGISTER = '@swc-node/register';
3343
- const swcNodeAvailable = (workspaceRoot) => existsSync(join$2(workspaceRoot, 'node_modules', '@swc-node', 'register', 'index.js'));
3344
3388
  /**
3345
- * Default worker-path resolution: prefers the built-and-published artifact, falls
3346
- * back to the workspace dist path, and finally to the in-source TypeScript file
3347
- * via `@swc-node/register` (bootstrap case where builder is building itself for
3348
- * the first time and the dist worker doesn't exist yet).
3349
- *
3350
- * Looks at, in order:
3351
- * 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
3352
- * 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
3353
- * 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
3354
- *
3355
- * @param workspaceRoot - Absolute workspace root.
3356
- * @returns Worker invocation descriptor, or `undefined` if no candidate exists.
3357
- *
3358
- * @example Locating the worker for an in-workspace consumer
3389
+ * Resolves the rollup worker by self-locating it beside the running builder
3390
+ * module: ascends from the module's own directory to the builder package root
3391
+ * and returns the worker at `bundle/rollup/worker`. This works whether the
3392
+ * builder runs from its built dist, an installed `node_modules` copy, or melded
3393
+ * into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
3394
+ * preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
3395
+ * for source-mode bootstrap.
3396
+ *
3397
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
3398
+ * @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
3399
+ *
3400
+ * @example Locating the worker beside the builder
3359
3401
  * ```typescript
3360
- * const invocation = resolveDefaultRollupWorkerPath('/abs/repo')
3402
+ * const invocation = resolveDefaultRollupWorkerPath()
3361
3403
  * if (!invocation) throw new Error('builder rollup worker artifact not found')
3362
3404
  * ```
3363
3405
  */
3364
- const resolveDefaultRollupWorkerPath = (workspaceRoot) => {
3365
- const distCandidates = [
3366
- join$2(workspaceRoot, 'dist', 'libs', 'builder', 'bundle', 'rollup', 'worker', 'index.cjs.js'),
3367
- join$2(workspaceRoot, 'node_modules', '@hyperfrontend', 'builder', 'bundle', 'rollup', 'worker', 'index.cjs.js'),
3368
- ];
3369
- for (const path of distCandidates) {
3370
- if (existsSync(path))
3371
- return { path, execArgv: [] };
3372
- }
3373
- const sourcePath = join$2(workspaceRoot, 'libs', 'builder', 'src', 'bundle', 'rollup', 'worker', 'index.ts');
3374
- if (existsSync(sourcePath) && swcNodeAvailable(workspaceRoot)) {
3375
- return { path: sourcePath, execArgv: ['--require', SWC_NODE_REGISTER] };
3376
- }
3377
- return undefined;
3378
- };
3406
+ const resolveDefaultRollupWorkerPath = (startDir) => ascendForWorker(['bundle', 'rollup', 'worker'], startDir);
3379
3407
  const createReportDir = () => mkdtempSync(join$2(tmpdir(), REPORT_DIR_PREFIX));
3380
3408
  const reportPathFor = (reportDir, descriptor) => {
3381
3409
  const safeLabel = descriptor.inputFile.replace(/[^a-zA-Z0-9_-]+/g, '_');
@@ -3527,25 +3555,25 @@ const buildWorkspaceJsPrePassJobs = (npmDeps, formats, context) => {
3527
3555
  }
3528
3556
  return jobs;
3529
3557
  };
3530
- const resolvePrePassWorkerOrThrow = (workspaceRoot) => {
3531
- const invocation = resolveDefaultWorkerPath(workspaceRoot);
3558
+ const resolvePrePassWorkerOrThrow = () => {
3559
+ const invocation = resolveDefaultWorkerPath();
3532
3560
  if (!invocation) {
3533
- throw createError('bundleAllDeps is enabled but the pre-pass worker could not be resolved. Build @hyperfrontend/builder once with bundleAllDeps disabled, or ensure @swc-node/register is installed for source-mode bootstrap.');
3561
+ throw createError('bundleAllDeps is enabled but the pre-pass worker could not be located beside the builder module. The @hyperfrontend/builder package appears incomplete, or @swc-node/register is missing for source-mode bootstrap.');
3534
3562
  }
3535
3563
  return invocation;
3536
3564
  };
3537
- const resolveRollupWorkerOrThrow = (workspaceRoot) => {
3538
- const invocation = resolveDefaultRollupWorkerPath(workspaceRoot);
3565
+ const resolveRollupWorkerOrThrow = () => {
3566
+ const invocation = resolveDefaultRollupWorkerPath();
3539
3567
  if (!invocation) {
3540
- throw createError('rollup worker could not be resolved. Build @hyperfrontend/builder at least once before invoking the bundle phase, or ensure @swc-node/register is installed for source-mode bootstrap.');
3568
+ throw createError('rollup worker could not be located beside the builder module. The @hyperfrontend/builder package appears incomplete, or @swc-node/register is missing for source-mode bootstrap.');
3541
3569
  }
3542
3570
  return invocation;
3543
3571
  };
3544
- const createLazyDispatchResolver = (workspaceRoot) => {
3572
+ const createLazyDispatchResolver = () => {
3545
3573
  let cached = null;
3546
3574
  return () => {
3547
3575
  if (!cached) {
3548
- const invocation = resolveRollupWorkerOrThrow(workspaceRoot);
3576
+ const invocation = resolveRollupWorkerOrThrow();
3549
3577
  cached = { workerPath: invocation.path, execArgv: invocation.execArgv };
3550
3578
  }
3551
3579
  return cached;
@@ -3639,7 +3667,7 @@ const runBundlePhase = async (context, config, monitor) => {
3639
3667
  const outputs = { esm: [], cjs: [], iife: [], umd: [] };
3640
3668
  const requestedPrePassFormats = collectFormatsRequestingPrePass(config);
3641
3669
  if (requestedPrePassFormats.length > 0 && (context.bundledDeps.length > 0 || context.workspaceBundledDeps.length > 0)) {
3642
- const invocation = resolvePrePassWorkerOrThrow(context.workspaceRoot);
3670
+ const invocation = resolvePrePassWorkerOrThrow();
3643
3671
  const npmJobs = buildJsPrePassJobs(context.bundledDeps, requestedPrePassFormats, context);
3644
3672
  const workspaceJobs = buildWorkspaceJsPrePassJobs(context.bundledDeps, requestedPrePassFormats, context);
3645
3673
  const jobs = [...npmJobs, ...workspaceJobs];
@@ -3648,7 +3676,7 @@ const runBundlePhase = async (context, config, monitor) => {
3648
3676
  await runPrePass(jobs, { workerPath: invocation.path, execArgv: invocation.execArgv, monitor });
3649
3677
  monitor?.check('bundle:dependencies:prepass:end');
3650
3678
  }
3651
- const resolveDispatch = createLazyDispatchResolver(context.workspaceRoot);
3679
+ const resolveDispatch = createLazyDispatchResolver();
3652
3680
  await runEsmFormats(config, context, outputs, resolveDispatch, monitor);
3653
3681
  await recover();
3654
3682
  monitor?.check('bundle:esm:end:post-recover');
@@ -26,26 +26,24 @@ export interface RollupWorkerInvocation {
26
26
  execArgv: string[];
27
27
  }
28
28
  /**
29
- * Default worker-path resolution: prefers the built-and-published artifact, falls
30
- * back to the workspace dist path, and finally to the in-source TypeScript file
31
- * via `@swc-node/register` (bootstrap case where builder is building itself for
32
- * the first time and the dist worker doesn't exist yet).
29
+ * Resolves the rollup worker by self-locating it beside the running builder
30
+ * module: ascends from the module's own directory to the builder package root
31
+ * and returns the worker at `bundle/rollup/worker`. This works whether the
32
+ * builder runs from its built dist, an installed `node_modules` copy, or melded
33
+ * into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
34
+ * preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
35
+ * for source-mode bootstrap.
33
36
  *
34
- * Looks at, in order:
35
- * 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
36
- * 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
37
- * 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
37
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
38
+ * @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
38
39
  *
39
- * @param workspaceRoot - Absolute workspace root.
40
- * @returns Worker invocation descriptor, or `undefined` if no candidate exists.
41
- *
42
- * @example Locating the worker for an in-workspace consumer
40
+ * @example Locating the worker beside the builder
43
41
  * ```typescript
44
- * const invocation = resolveDefaultRollupWorkerPath('/abs/repo')
42
+ * const invocation = resolveDefaultRollupWorkerPath()
45
43
  * if (!invocation) throw new Error('builder rollup worker artifact not found')
46
44
  * ```
47
45
  */
48
- export declare const resolveDefaultRollupWorkerPath: (workspaceRoot: string) => RollupWorkerInvocation | undefined;
46
+ export declare const resolveDefaultRollupWorkerPath: (startDir?: string) => RollupWorkerInvocation | undefined;
49
47
  /**
50
48
  * Forks a single rollup worker for the supplied descriptor and waits for it
51
49
  * to exit. The caller-provided descriptor's `reportPath` is overwritten with
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/builder/src/bundle/rollup/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAY/E;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,iGAAiG;IACjG,UAAU,EAAE,MAAM,CAAA;IAClB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uGAAuG;IACvG,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAQD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,8BAA8B,GAAI,eAAe,MAAM,KAAG,sBAAsB,GAAG,SAa/F,CAAA;AA4CD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,qBAAqB,EACjC,SAAS,2BAA2B,KACnC,OAAO,CAAC,kBAAkB,CAkB5B,CAAA"}
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/builder/src/bundle/rollup/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAa/E;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,iGAAiG;IACjG,UAAU,EAAE,MAAM,CAAA;IAClB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uGAAuG;IACvG,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAID;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,8BAA8B,GAAI,WAAW,MAAM,KAAG,sBAAsB,GAAG,SACjC,CAAA;AA4C3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,qBAAqB,EACjC,SAAS,2BAA2B,KACnC,OAAO,CAAC,kBAAkB,CAkB5B,CAAA"}
@@ -321,45 +321,91 @@ const toUmdBuildDescriptor = (entry, config, context, reportPath) => {
321
321
  };
322
322
  };
323
323
 
324
- const log = index_cjs_js$7.logger.channel('builder:bundle:rollup:dispatch');
325
- const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
326
324
  const SWC_NODE_REGISTER = '@swc-node/register';
327
- const swcNodeAvailable = (workspaceRoot) => node_fs.existsSync(index_cjs_js$5.join(workspaceRoot, 'node_modules', '@swc-node', 'register', 'index.js'));
325
+ const probeDir = (dir, offset) => {
326
+ const compiled = node_path.join(dir, ...offset, 'index.cjs.js');
327
+ if (node_fs.existsSync(compiled))
328
+ return { path: compiled, execArgv: [] };
329
+ const source = node_path.join(dir, ...offset, 'index.ts');
330
+ if (node_fs.existsSync(source))
331
+ return { path: source, execArgv: ['--require', SWC_NODE_REGISTER] };
332
+ return undefined;
333
+ };
328
334
  /**
329
- * Default worker-path resolution: prefers the built-and-published artifact, falls
330
- * back to the workspace dist path, and finally to the in-source TypeScript file
331
- * via `@swc-node/register` (bootstrap case where builder is building itself for
332
- * the first time and the dist worker doesn't exist yet).
335
+ * Directory of the currently-executing builder module, read from `__dirname`.
336
+ * It is present in the shipped CommonJS build, in the `@swc-node/register` source
337
+ * bootstrap, and under the test runner, so callers get their own on-disk location
338
+ * and can find the worker beside them however the builder was packaged.
333
339
  *
334
- * Looks at, in order:
335
- * 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
336
- * 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
337
- * 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
340
+ * @returns Absolute directory path of the running module.
338
341
  *
339
- * @param workspaceRoot - Absolute workspace root.
340
- * @returns Worker invocation descriptor, or `undefined` if no candidate exists.
341
- *
342
- * @example Locating the worker for an in-workspace consumer
342
+ * @example Anchoring a lookup beside the running builder
343
343
  * ```typescript
344
- * const invocation = resolveDefaultRollupWorkerPath('/abs/repo')
345
- * if (!invocation) throw new Error('builder rollup worker artifact not found')
344
+ * const invocation = ascendForWorker(['bundle', 'rollup', 'worker'], currentModuleDir())
346
345
  * ```
347
346
  */
348
- const resolveDefaultRollupWorkerPath = (workspaceRoot) => {
349
- const distCandidates = [
350
- index_cjs_js$5.join(workspaceRoot, 'dist', 'libs', 'builder', 'bundle', 'rollup', 'worker', 'index.cjs.js'),
351
- index_cjs_js$5.join(workspaceRoot, 'node_modules', '@hyperfrontend', 'builder', 'bundle', 'rollup', 'worker', 'index.cjs.js'),
352
- ];
353
- for (const path of distCandidates) {
354
- if (node_fs.existsSync(path))
355
- return { path, execArgv: [] };
347
+ const currentModuleDir = () => {
348
+ /* istanbul ignore if -- @preserve the ESM build has no __dirname; the shipped CommonJS build and the test runner always define it, so this guard is unreachable under test */
349
+ if (typeof __dirname === 'undefined') {
350
+ throw index_cjs_js$4.createError('@hyperfrontend/builder self-location requires the CommonJS build; drive build() from the CommonJS entry point');
356
351
  }
357
- const sourcePath = index_cjs_js$5.join(workspaceRoot, 'libs', 'builder', 'src', 'bundle', 'rollup', 'worker', 'index.ts');
358
- if (node_fs.existsSync(sourcePath) && swcNodeAvailable(workspaceRoot)) {
359
- return { path: sourcePath, execArgv: ['--require', SWC_NODE_REGISTER] };
352
+ return __dirname;
353
+ };
354
+ /**
355
+ * Locate a builder worker entry by ascending from a start directory toward the
356
+ * filesystem root, returning the first ancestor at which the worker exists at the
357
+ * given in-package offset. The compiled `index.cjs.js` is preferred; an `index.ts`
358
+ * sibling (source-mode bootstrap) resolves with the swc loader attached.
359
+ *
360
+ * The worker ships inside the builder's own package, so resolving relative to the
361
+ * running module finds it wherever the package lives — built dist, an installed
362
+ * `node_modules` copy, or melded into a host bundle under `_dependencies/`.
363
+ *
364
+ * @param offset - In-package path segments to the worker directory (e.g. `['bundle', 'rollup', 'worker']`).
365
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
366
+ * @returns The resolved worker invocation, or `undefined` if no worker exists at the offset under any ancestor.
367
+ *
368
+ * @example Resolving the rollup worker from the running module
369
+ * ```typescript
370
+ * const invocation = ascendForWorker(['bundle', 'rollup', 'worker'])
371
+ * if (!invocation) throw new Error('builder rollup worker not found beside the builder module')
372
+ * ```
373
+ */
374
+ const ascendForWorker = (offset, startDir = currentModuleDir()) => {
375
+ let dir = startDir;
376
+ let parent = node_path.dirname(dir);
377
+ // how: probe each level then step up; the final probe covers the filesystem root, where parent === dir
378
+ while (parent !== dir) {
379
+ const found = probeDir(dir, offset);
380
+ if (found)
381
+ return found;
382
+ dir = parent;
383
+ parent = node_path.dirname(dir);
360
384
  }
361
- return undefined;
385
+ return probeDir(dir, offset);
362
386
  };
387
+
388
+ const log = index_cjs_js$7.logger.channel('builder:bundle:rollup:dispatch');
389
+ const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
390
+ /**
391
+ * Resolves the rollup worker by self-locating it beside the running builder
392
+ * module: ascends from the module's own directory to the builder package root
393
+ * and returns the worker at `bundle/rollup/worker`. This works whether the
394
+ * builder runs from its built dist, an installed `node_modules` copy, or melded
395
+ * into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
396
+ * preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
397
+ * for source-mode bootstrap.
398
+ *
399
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
400
+ * @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
401
+ *
402
+ * @example Locating the worker beside the builder
403
+ * ```typescript
404
+ * const invocation = resolveDefaultRollupWorkerPath()
405
+ * if (!invocation) throw new Error('builder rollup worker artifact not found')
406
+ * ```
407
+ */
408
+ const resolveDefaultRollupWorkerPath = (startDir) => ascendForWorker(['bundle', 'rollup', 'worker'], startDir);
363
409
  const createReportDir = () => node_fs.mkdtempSync(index_cjs_js$5.join(node_os.tmpdir(), REPORT_DIR_PREFIX));
364
410
  const reportPathFor = (reportDir, descriptor) => {
365
411
  const safeLabel = descriptor.inputFile.replace(/[^a-zA-Z0-9_-]+/g, '_');
@@ -29,26 +29,24 @@ interface RollupWorkerInvocation {
29
29
  execArgv: string[];
30
30
  }
31
31
  /**
32
- * Default worker-path resolution: prefers the built-and-published artifact, falls
33
- * back to the workspace dist path, and finally to the in-source TypeScript file
34
- * via `@swc-node/register` (bootstrap case where builder is building itself for
35
- * the first time and the dist worker doesn't exist yet).
36
- *
37
- * Looks at, in order:
38
- * 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
39
- * 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
40
- * 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
41
- *
42
- * @param workspaceRoot - Absolute workspace root.
43
- * @returns Worker invocation descriptor, or `undefined` if no candidate exists.
44
- *
45
- * @example Locating the worker for an in-workspace consumer
32
+ * Resolves the rollup worker by self-locating it beside the running builder
33
+ * module: ascends from the module's own directory to the builder package root
34
+ * and returns the worker at `bundle/rollup/worker`. This works whether the
35
+ * builder runs from its built dist, an installed `node_modules` copy, or melded
36
+ * into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
37
+ * preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
38
+ * for source-mode bootstrap.
39
+ *
40
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
41
+ * @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
42
+ *
43
+ * @example Locating the worker beside the builder
46
44
  * ```typescript
47
- * const invocation = resolveDefaultRollupWorkerPath('/abs/repo')
45
+ * const invocation = resolveDefaultRollupWorkerPath()
48
46
  * if (!invocation) throw new Error('builder rollup worker artifact not found')
49
47
  * ```
50
48
  */
51
- declare const resolveDefaultRollupWorkerPath: (workspaceRoot: string) => RollupWorkerInvocation | undefined;
49
+ declare const resolveDefaultRollupWorkerPath: (startDir?: string) => RollupWorkerInvocation | undefined;
52
50
  /**
53
51
  * Forks a single rollup worker for the supplied descriptor and waits for it
54
52
  * to exit. The caller-provided descriptor's `reportPath` is overwritten with
@@ -8,7 +8,7 @@ import { exists, readJsonFile } from '../../_dependencies/@hyperfrontend/project
8
8
  import { createError } from '../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js';
9
9
  import { join as join$2 } from '../../_dependencies/@hyperfrontend/project-scope/core/index.esm.js';
10
10
  import { spawn } from 'node:child_process';
11
- import { rmSync, existsSync, mkdtempSync, readFileSync, chmodSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
11
+ import { existsSync, rmSync, mkdtempSync, readFileSync, chmodSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
12
12
  import { tmpdir } from 'node:os';
13
13
  import { stringify, parse } from '../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.esm.js';
14
14
  import { createPromise } from '../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/promise/index.esm.js';
@@ -311,45 +311,91 @@ const toUmdBuildDescriptor = (entry, config, context, reportPath) => {
311
311
  };
312
312
  };
313
313
 
314
- const log = logger.channel('builder:bundle:rollup:dispatch');
315
- const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
316
314
  const SWC_NODE_REGISTER = '@swc-node/register';
317
- const swcNodeAvailable = (workspaceRoot) => existsSync(join$2(workspaceRoot, 'node_modules', '@swc-node', 'register', 'index.js'));
315
+ const probeDir = (dir, offset) => {
316
+ const compiled = join$1(dir, ...offset, 'index.cjs.js');
317
+ if (existsSync(compiled))
318
+ return { path: compiled, execArgv: [] };
319
+ const source = join$1(dir, ...offset, 'index.ts');
320
+ if (existsSync(source))
321
+ return { path: source, execArgv: ['--require', SWC_NODE_REGISTER] };
322
+ return undefined;
323
+ };
318
324
  /**
319
- * Default worker-path resolution: prefers the built-and-published artifact, falls
320
- * back to the workspace dist path, and finally to the in-source TypeScript file
321
- * via `@swc-node/register` (bootstrap case where builder is building itself for
322
- * the first time and the dist worker doesn't exist yet).
325
+ * Directory of the currently-executing builder module, read from `__dirname`.
326
+ * It is present in the shipped CommonJS build, in the `@swc-node/register` source
327
+ * bootstrap, and under the test runner, so callers get their own on-disk location
328
+ * and can find the worker beside them however the builder was packaged.
323
329
  *
324
- * Looks at, in order:
325
- * 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
326
- * 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
327
- * 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
330
+ * @returns Absolute directory path of the running module.
328
331
  *
329
- * @param workspaceRoot - Absolute workspace root.
330
- * @returns Worker invocation descriptor, or `undefined` if no candidate exists.
331
- *
332
- * @example Locating the worker for an in-workspace consumer
332
+ * @example Anchoring a lookup beside the running builder
333
333
  * ```typescript
334
- * const invocation = resolveDefaultRollupWorkerPath('/abs/repo')
335
- * if (!invocation) throw new Error('builder rollup worker artifact not found')
334
+ * const invocation = ascendForWorker(['bundle', 'rollup', 'worker'], currentModuleDir())
336
335
  * ```
337
336
  */
338
- const resolveDefaultRollupWorkerPath = (workspaceRoot) => {
339
- const distCandidates = [
340
- join$2(workspaceRoot, 'dist', 'libs', 'builder', 'bundle', 'rollup', 'worker', 'index.cjs.js'),
341
- join$2(workspaceRoot, 'node_modules', '@hyperfrontend', 'builder', 'bundle', 'rollup', 'worker', 'index.cjs.js'),
342
- ];
343
- for (const path of distCandidates) {
344
- if (existsSync(path))
345
- return { path, execArgv: [] };
337
+ const currentModuleDir = () => {
338
+ /* istanbul ignore if -- @preserve the ESM build has no __dirname; the shipped CommonJS build and the test runner always define it, so this guard is unreachable under test */
339
+ if (typeof __dirname === 'undefined') {
340
+ throw createError('@hyperfrontend/builder self-location requires the CommonJS build; drive build() from the CommonJS entry point');
346
341
  }
347
- const sourcePath = join$2(workspaceRoot, 'libs', 'builder', 'src', 'bundle', 'rollup', 'worker', 'index.ts');
348
- if (existsSync(sourcePath) && swcNodeAvailable(workspaceRoot)) {
349
- return { path: sourcePath, execArgv: ['--require', SWC_NODE_REGISTER] };
342
+ return __dirname;
343
+ };
344
+ /**
345
+ * Locate a builder worker entry by ascending from a start directory toward the
346
+ * filesystem root, returning the first ancestor at which the worker exists at the
347
+ * given in-package offset. The compiled `index.cjs.js` is preferred; an `index.ts`
348
+ * sibling (source-mode bootstrap) resolves with the swc loader attached.
349
+ *
350
+ * The worker ships inside the builder's own package, so resolving relative to the
351
+ * running module finds it wherever the package lives — built dist, an installed
352
+ * `node_modules` copy, or melded into a host bundle under `_dependencies/`.
353
+ *
354
+ * @param offset - In-package path segments to the worker directory (e.g. `['bundle', 'rollup', 'worker']`).
355
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
356
+ * @returns The resolved worker invocation, or `undefined` if no worker exists at the offset under any ancestor.
357
+ *
358
+ * @example Resolving the rollup worker from the running module
359
+ * ```typescript
360
+ * const invocation = ascendForWorker(['bundle', 'rollup', 'worker'])
361
+ * if (!invocation) throw new Error('builder rollup worker not found beside the builder module')
362
+ * ```
363
+ */
364
+ const ascendForWorker = (offset, startDir = currentModuleDir()) => {
365
+ let dir = startDir;
366
+ let parent = dirname(dir);
367
+ // how: probe each level then step up; the final probe covers the filesystem root, where parent === dir
368
+ while (parent !== dir) {
369
+ const found = probeDir(dir, offset);
370
+ if (found)
371
+ return found;
372
+ dir = parent;
373
+ parent = dirname(dir);
350
374
  }
351
- return undefined;
375
+ return probeDir(dir, offset);
352
376
  };
377
+
378
+ const log = logger.channel('builder:bundle:rollup:dispatch');
379
+ const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
380
+ /**
381
+ * Resolves the rollup worker by self-locating it beside the running builder
382
+ * module: ascends from the module's own directory to the builder package root
383
+ * and returns the worker at `bundle/rollup/worker`. This works whether the
384
+ * builder runs from its built dist, an installed `node_modules` copy, or melded
385
+ * into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
386
+ * preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
387
+ * for source-mode bootstrap.
388
+ *
389
+ * @param startDir - Directory to begin the ascent from. Defaults to the running module's directory; pass an explicit value to resolve from another anchor or under test.
390
+ * @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
391
+ *
392
+ * @example Locating the worker beside the builder
393
+ * ```typescript
394
+ * const invocation = resolveDefaultRollupWorkerPath()
395
+ * if (!invocation) throw new Error('builder rollup worker artifact not found')
396
+ * ```
397
+ */
398
+ const resolveDefaultRollupWorkerPath = (startDir) => ascendForWorker(['bundle', 'rollup', 'worker'], startDir);
353
399
  const createReportDir = () => mkdtempSync(join$2(tmpdir(), REPORT_DIR_PREFIX));
354
400
  const reportPathFor = (reportDir, descriptor) => {
355
401
  const safeLabel = descriptor.inputFile.replace(/[^a-zA-Z0-9_-]+/g, '_');