@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.
- package/CHANGELOG.md +6 -0
- package/_dependencies/@hyperfrontend/project-scope/core/fs/index.cjs.js +10 -3
- package/_dependencies/@hyperfrontend/project-scope/core/fs/index.esm.js +10 -3
- package/_dependencies/@hyperfrontend/project-scope/core/index.cjs.js +16 -6
- package/_dependencies/@hyperfrontend/project-scope/core/index.esm.js +16 -6
- package/_dependencies/@hyperfrontend/project-scope/core/path/index.cjs.js +4 -5
- package/_dependencies/@hyperfrontend/project-scope/core/path/index.esm.js +5 -4
- package/_dependencies/@hyperfrontend/project-scope/project/root/index.cjs.js +5 -1
- package/_dependencies/@hyperfrontend/project-scope/project/root/index.esm.js +5 -1
- package/bin/hf-build.js +110 -82
- package/bin/hf-build.linux-x64 +0 -0
- package/bin/index.cjs.js +82 -36
- package/bin/index.esm.js +82 -36
- package/bin/script/index.cjs.js +91 -45
- package/bin/script/index.esm.js +81 -35
- package/bundle/declarations/dts-per-entry.d.ts.map +1 -1
- package/bundle/declarations/dts-pre-pass.d.ts.map +1 -1
- package/bundle/declarations/index.cjs.js +118 -72
- package/bundle/declarations/index.esm.js +83 -37
- package/bundle/dependencies/index.cjs.js +95 -49
- package/bundle/dependencies/index.d.ts +13 -24
- package/bundle/dependencies/index.esm.js +79 -33
- package/bundle/dependencies/pre-pass.d.ts +13 -24
- package/bundle/dependencies/pre-pass.d.ts.map +1 -1
- package/bundle/index.cjs.js +203 -175
- package/bundle/index.esm.js +107 -79
- package/bundle/rollup/dispatch.d.ts +12 -14
- package/bundle/rollup/dispatch.d.ts.map +1 -1
- package/bundle/rollup/index.cjs.js +75 -29
- package/bundle/rollup/index.d.ts +14 -16
- package/bundle/rollup/index.esm.js +76 -30
- package/bundle/worker-locator.d.ts +47 -0
- package/bundle/worker-locator.d.ts.map +1 -0
- package/index.cjs.js +112 -84
- package/index.esm.js +113 -85
- package/package.json +31 -3
package/bin/index.cjs.js
CHANGED
|
@@ -25,7 +25,7 @@ const { depsRootOf } = require('../_shared/bundle/fs/deps-root/index.cjs.js');
|
|
|
25
25
|
require('../_dependencies/postject/index.cjs.js');
|
|
26
26
|
const index_cjs_js$8 = require('../_dependencies/@hyperfrontend/project-scope/core/path/index.cjs.js');
|
|
27
27
|
require('node:module');
|
|
28
|
-
require('node:path');
|
|
28
|
+
const node_path = require('node:path');
|
|
29
29
|
require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js');
|
|
30
30
|
require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js');
|
|
31
31
|
require('../_dependencies/@hyperfrontend/project-scope/core/fs/index.cjs.js');
|
|
@@ -33,7 +33,7 @@ require('../_dependencies/@hyperfrontend/project-scope/core/fs/index.cjs.js');
|
|
|
33
33
|
const log$3 = index_cjs_js$3.logger.channel('builder:bin:native:dispatch');
|
|
34
34
|
const REPORT_DIR_PREFIX$1 = 'hf-builder-inject-';
|
|
35
35
|
const SWC_NODE_REGISTER$1 = '@swc-node/register';
|
|
36
|
-
const swcNodeAvailable
|
|
36
|
+
const swcNodeAvailable = (workspaceRoot) => node_fs.existsSync(index_cjs_js$4.join(workspaceRoot, 'node_modules', '@swc-node', 'register', 'index.js'));
|
|
37
37
|
/**
|
|
38
38
|
* Default worker-path resolution: prefers the built-and-published artifact, falls
|
|
39
39
|
* back to the workspace dist path, and finally to the in-source TypeScript file
|
|
@@ -64,7 +64,7 @@ const resolveDefaultInjectWorkerPath = (workspaceRoot) => {
|
|
|
64
64
|
return { path, execArgv: [] };
|
|
65
65
|
}
|
|
66
66
|
const sourcePath = index_cjs_js$4.join(workspaceRoot, 'libs', 'builder', 'src', 'bin', 'native', 'worker', 'index.ts');
|
|
67
|
-
if (node_fs.existsSync(sourcePath) && swcNodeAvailable
|
|
67
|
+
if (node_fs.existsSync(sourcePath) && swcNodeAvailable(workspaceRoot)) {
|
|
68
68
|
return { path: sourcePath, execArgv: ['--require', SWC_NODE_REGISTER$1] };
|
|
69
69
|
}
|
|
70
70
|
return undefined;
|
|
@@ -323,45 +323,91 @@ const toBinBuildDescriptor = (bin, context, format, formats, reportPath) => {
|
|
|
323
323
|
};
|
|
324
324
|
};
|
|
325
325
|
|
|
326
|
-
const log$1 = index_cjs_js$3.logger.channel('builder:bundle:rollup:dispatch');
|
|
327
|
-
const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
|
|
328
326
|
const SWC_NODE_REGISTER = '@swc-node/register';
|
|
329
|
-
const
|
|
327
|
+
const probeDir = (dir, offset) => {
|
|
328
|
+
const compiled = node_path.join(dir, ...offset, 'index.cjs.js');
|
|
329
|
+
if (node_fs.existsSync(compiled))
|
|
330
|
+
return { path: compiled, execArgv: [] };
|
|
331
|
+
const source = node_path.join(dir, ...offset, 'index.ts');
|
|
332
|
+
if (node_fs.existsSync(source))
|
|
333
|
+
return { path: source, execArgv: ['--require', SWC_NODE_REGISTER] };
|
|
334
|
+
return undefined;
|
|
335
|
+
};
|
|
330
336
|
/**
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* the
|
|
337
|
+
* Directory of the currently-executing builder module, read from `__dirname`.
|
|
338
|
+
* It is present in the shipped CommonJS build, in the `@swc-node/register` source
|
|
339
|
+
* bootstrap, and under the test runner, so callers get their own on-disk location
|
|
340
|
+
* and can find the worker beside them however the builder was packaged.
|
|
335
341
|
*
|
|
336
|
-
*
|
|
337
|
-
* 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
|
|
338
|
-
* 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
|
|
339
|
-
* 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
|
|
342
|
+
* @returns Absolute directory path of the running module.
|
|
340
343
|
*
|
|
341
|
-
* @
|
|
342
|
-
* @returns Worker invocation descriptor, or `undefined` if no candidate exists.
|
|
343
|
-
*
|
|
344
|
-
* @example Locating the worker for an in-workspace consumer
|
|
344
|
+
* @example Anchoring a lookup beside the running builder
|
|
345
345
|
* ```typescript
|
|
346
|
-
* const invocation =
|
|
347
|
-
* if (!invocation) throw new Error('builder rollup worker artifact not found')
|
|
346
|
+
* const invocation = ascendForWorker(['bundle', 'rollup', 'worker'], currentModuleDir())
|
|
348
347
|
* ```
|
|
349
348
|
*/
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
index_cjs_js$
|
|
354
|
-
];
|
|
355
|
-
for (const path of distCandidates) {
|
|
356
|
-
if (node_fs.existsSync(path))
|
|
357
|
-
return { path, execArgv: [] };
|
|
349
|
+
const currentModuleDir = () => {
|
|
350
|
+
/* 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 */
|
|
351
|
+
if (typeof __dirname === 'undefined') {
|
|
352
|
+
throw index_cjs_js$6.createError('@hyperfrontend/builder self-location requires the CommonJS build; drive build() from the CommonJS entry point');
|
|
358
353
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
354
|
+
return __dirname;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Locate a builder worker entry by ascending from a start directory toward the
|
|
358
|
+
* filesystem root, returning the first ancestor at which the worker exists at the
|
|
359
|
+
* given in-package offset. The compiled `index.cjs.js` is preferred; an `index.ts`
|
|
360
|
+
* sibling (source-mode bootstrap) resolves with the swc loader attached.
|
|
361
|
+
*
|
|
362
|
+
* The worker ships inside the builder's own package, so resolving relative to the
|
|
363
|
+
* running module finds it wherever the package lives — built dist, an installed
|
|
364
|
+
* `node_modules` copy, or melded into a host bundle under `_dependencies/`.
|
|
365
|
+
*
|
|
366
|
+
* @param offset - In-package path segments to the worker directory (e.g. `['bundle', 'rollup', 'worker']`).
|
|
367
|
+
* @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.
|
|
368
|
+
* @returns The resolved worker invocation, or `undefined` if no worker exists at the offset under any ancestor.
|
|
369
|
+
*
|
|
370
|
+
* @example Resolving the rollup worker from the running module
|
|
371
|
+
* ```typescript
|
|
372
|
+
* const invocation = ascendForWorker(['bundle', 'rollup', 'worker'])
|
|
373
|
+
* if (!invocation) throw new Error('builder rollup worker not found beside the builder module')
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
const ascendForWorker = (offset, startDir = currentModuleDir()) => {
|
|
377
|
+
let dir = startDir;
|
|
378
|
+
let parent = node_path.dirname(dir);
|
|
379
|
+
// how: probe each level then step up; the final probe covers the filesystem root, where parent === dir
|
|
380
|
+
while (parent !== dir) {
|
|
381
|
+
const found = probeDir(dir, offset);
|
|
382
|
+
if (found)
|
|
383
|
+
return found;
|
|
384
|
+
dir = parent;
|
|
385
|
+
parent = node_path.dirname(dir);
|
|
362
386
|
}
|
|
363
|
-
return
|
|
387
|
+
return probeDir(dir, offset);
|
|
364
388
|
};
|
|
389
|
+
|
|
390
|
+
const log$1 = index_cjs_js$3.logger.channel('builder:bundle:rollup:dispatch');
|
|
391
|
+
const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
|
|
392
|
+
/**
|
|
393
|
+
* Resolves the rollup worker by self-locating it beside the running builder
|
|
394
|
+
* module: ascends from the module's own directory to the builder package root
|
|
395
|
+
* and returns the worker at `bundle/rollup/worker`. This works whether the
|
|
396
|
+
* builder runs from its built dist, an installed `node_modules` copy, or melded
|
|
397
|
+
* into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
|
|
398
|
+
* preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
|
|
399
|
+
* for source-mode bootstrap.
|
|
400
|
+
*
|
|
401
|
+
* @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.
|
|
402
|
+
* @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
|
|
403
|
+
*
|
|
404
|
+
* @example Locating the worker beside the builder
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const invocation = resolveDefaultRollupWorkerPath()
|
|
407
|
+
* if (!invocation) throw new Error('builder rollup worker artifact not found')
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
const resolveDefaultRollupWorkerPath = (startDir) => ascendForWorker(['bundle', 'rollup', 'worker'], startDir);
|
|
365
411
|
const createReportDir = () => node_fs.mkdtempSync(index_cjs_js$4.join(node_os.tmpdir(), REPORT_DIR_PREFIX));
|
|
366
412
|
const reportPathFor = (reportDir, descriptor) => {
|
|
367
413
|
const safeLabel = descriptor.inputFile.replace(/[^a-zA-Z0-9_-]+/g, '_');
|
|
@@ -441,10 +487,10 @@ const dispatchRollupWorker = async (descriptor, options) => {
|
|
|
441
487
|
};
|
|
442
488
|
|
|
443
489
|
const log = index_cjs_js$3.logger.channel('builder:bin:script');
|
|
444
|
-
const resolveWorkerOrThrow = (
|
|
445
|
-
const invocation = resolveDefaultRollupWorkerPath(
|
|
490
|
+
const resolveWorkerOrThrow = () => {
|
|
491
|
+
const invocation = resolveDefaultRollupWorkerPath();
|
|
446
492
|
if (!invocation) {
|
|
447
|
-
throw index_cjs_js$6.createError('rollup worker could not be
|
|
493
|
+
throw index_cjs_js$6.createError('rollup worker could not be located beside the builder module for bin script bundling. The @hyperfrontend/builder package appears incomplete, or @swc-node/register is missing for source-mode bootstrap.');
|
|
448
494
|
}
|
|
449
495
|
return invocation;
|
|
450
496
|
};
|
|
@@ -485,7 +531,7 @@ const buildJsBin = async (bin, ctx) => {
|
|
|
485
531
|
const formats = normalizeFormats(bin.format);
|
|
486
532
|
const binDir = index_cjs_js$4.join(ctx.outputPath, 'bin');
|
|
487
533
|
index_cjs_js$4.ensureDir(binDir);
|
|
488
|
-
const worker = resolveWorkerOrThrow(
|
|
534
|
+
const worker = resolveWorkerOrThrow();
|
|
489
535
|
const outputs = [];
|
|
490
536
|
for (const format of formats) {
|
|
491
537
|
const descriptor = toBinBuildDescriptor(bin, ctx, format, formats, '');
|
package/bin/index.esm.js
CHANGED
|
@@ -12,7 +12,7 @@ import { stringify, parse } from '../_dependencies/@hyperfrontend/immutable-api-
|
|
|
12
12
|
import '../_dependencies/postject/index.esm.js';
|
|
13
13
|
import { join as join$1, getDirname } from '../_dependencies/@hyperfrontend/project-scope/core/path/index.esm.js';
|
|
14
14
|
import 'node:module';
|
|
15
|
-
import 'node:path';
|
|
15
|
+
import { dirname, join as join$2 } from 'node:path';
|
|
16
16
|
import '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js';
|
|
17
17
|
import '../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js';
|
|
18
18
|
import '../_dependencies/@hyperfrontend/project-scope/core/fs/index.esm.js';
|
|
@@ -31,7 +31,7 @@ import { depsRootOf } from '../_shared/bundle/fs/deps-root/index.esm.js';
|
|
|
31
31
|
const log$3 = logger.channel('builder:bin:native:dispatch');
|
|
32
32
|
const REPORT_DIR_PREFIX$1 = 'hf-builder-inject-';
|
|
33
33
|
const SWC_NODE_REGISTER$1 = '@swc-node/register';
|
|
34
|
-
const swcNodeAvailable
|
|
34
|
+
const swcNodeAvailable = (workspaceRoot) => existsSync(join(workspaceRoot, 'node_modules', '@swc-node', 'register', 'index.js'));
|
|
35
35
|
/**
|
|
36
36
|
* Default worker-path resolution: prefers the built-and-published artifact, falls
|
|
37
37
|
* back to the workspace dist path, and finally to the in-source TypeScript file
|
|
@@ -62,7 +62,7 @@ const resolveDefaultInjectWorkerPath = (workspaceRoot) => {
|
|
|
62
62
|
return { path, execArgv: [] };
|
|
63
63
|
}
|
|
64
64
|
const sourcePath = join(workspaceRoot, 'libs', 'builder', 'src', 'bin', 'native', 'worker', 'index.ts');
|
|
65
|
-
if (existsSync(sourcePath) && swcNodeAvailable
|
|
65
|
+
if (existsSync(sourcePath) && swcNodeAvailable(workspaceRoot)) {
|
|
66
66
|
return { path: sourcePath, execArgv: ['--require', SWC_NODE_REGISTER$1] };
|
|
67
67
|
}
|
|
68
68
|
return undefined;
|
|
@@ -321,45 +321,91 @@ const toBinBuildDescriptor = (bin, context, format, formats, reportPath) => {
|
|
|
321
321
|
};
|
|
322
322
|
};
|
|
323
323
|
|
|
324
|
-
const log$1 = 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
|
|
325
|
+
const probeDir = (dir, offset) => {
|
|
326
|
+
const compiled = join$2(dir, ...offset, 'index.cjs.js');
|
|
327
|
+
if (existsSync(compiled))
|
|
328
|
+
return { path: compiled, execArgv: [] };
|
|
329
|
+
const source = join$2(dir, ...offset, 'index.ts');
|
|
330
|
+
if (existsSync(source))
|
|
331
|
+
return { path: source, execArgv: ['--require', SWC_NODE_REGISTER] };
|
|
332
|
+
return undefined;
|
|
333
|
+
};
|
|
328
334
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* the
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
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 =
|
|
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
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
];
|
|
353
|
-
for (const path of distCandidates) {
|
|
354
|
-
if (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 createError('@hyperfrontend/builder self-location requires the CommonJS build; drive build() from the CommonJS entry point');
|
|
356
351
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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 = 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 = dirname(dir);
|
|
360
384
|
}
|
|
361
|
-
return
|
|
385
|
+
return probeDir(dir, offset);
|
|
362
386
|
};
|
|
387
|
+
|
|
388
|
+
const log$1 = 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 = () => mkdtempSync(join(tmpdir(), REPORT_DIR_PREFIX));
|
|
364
410
|
const reportPathFor = (reportDir, descriptor) => {
|
|
365
411
|
const safeLabel = descriptor.inputFile.replace(/[^a-zA-Z0-9_-]+/g, '_');
|
|
@@ -439,10 +485,10 @@ const dispatchRollupWorker = async (descriptor, options) => {
|
|
|
439
485
|
};
|
|
440
486
|
|
|
441
487
|
const log = logger.channel('builder:bin:script');
|
|
442
|
-
const resolveWorkerOrThrow = (
|
|
443
|
-
const invocation = resolveDefaultRollupWorkerPath(
|
|
488
|
+
const resolveWorkerOrThrow = () => {
|
|
489
|
+
const invocation = resolveDefaultRollupWorkerPath();
|
|
444
490
|
if (!invocation) {
|
|
445
|
-
throw createError('rollup worker could not be
|
|
491
|
+
throw createError('rollup worker could not be located beside the builder module for bin script bundling. The @hyperfrontend/builder package appears incomplete, or @swc-node/register is missing for source-mode bootstrap.');
|
|
446
492
|
}
|
|
447
493
|
return invocation;
|
|
448
494
|
};
|
|
@@ -483,7 +529,7 @@ const buildJsBin = async (bin, ctx) => {
|
|
|
483
529
|
const formats = normalizeFormats(bin.format);
|
|
484
530
|
const binDir = join(ctx.outputPath, 'bin');
|
|
485
531
|
ensureDir(binDir);
|
|
486
|
-
const worker = resolveWorkerOrThrow(
|
|
532
|
+
const worker = resolveWorkerOrThrow();
|
|
487
533
|
const outputs = [];
|
|
488
534
|
for (const format of formats) {
|
|
489
535
|
const descriptor = toBinBuildDescriptor(bin, ctx, format, formats, '');
|
package/bin/script/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const index_cjs_js$
|
|
4
|
-
const index_cjs_js$
|
|
3
|
+
const index_cjs_js$2 = require('../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js');
|
|
4
|
+
const index_cjs_js$3 = require('../../_dependencies/@hyperfrontend/logging/index.cjs.js');
|
|
5
5
|
const index_cjs_js = require('../../_dependencies/@hyperfrontend/project-scope/core/index.cjs.js');
|
|
6
6
|
const index_cjs_js$1 = require('../../_dependencies/@hyperfrontend/project-scope/core/path/index.cjs.js');
|
|
7
7
|
const { normalizeFormats } = require('../../_shared/bin/format/index.cjs.js');
|
|
@@ -9,7 +9,7 @@ const { defaultBootstrap } = require('../../_shared/bin/script/bootstrap-footer/
|
|
|
9
9
|
const { buildWorkspaceRoutes } = require('../../_shared/bundle/dependencies/externalize-plugin/index.cjs.js');
|
|
10
10
|
const { depsRootOf } = require('../../_shared/bundle/fs/deps-root/index.cjs.js');
|
|
11
11
|
require('node:module');
|
|
12
|
-
require('node:path');
|
|
12
|
+
const node_path = require('node:path');
|
|
13
13
|
const index_cjs_js$6 = require('../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js');
|
|
14
14
|
require('../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js');
|
|
15
15
|
require('../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js');
|
|
@@ -17,8 +17,8 @@ require('../../_dependencies/@hyperfrontend/project-scope/core/fs/index.cjs.js')
|
|
|
17
17
|
const node_child_process = require('node:child_process');
|
|
18
18
|
const node_fs = require('node:fs');
|
|
19
19
|
const node_os = require('node:os');
|
|
20
|
-
const index_cjs_js$
|
|
21
|
-
const index_cjs_js$
|
|
20
|
+
const index_cjs_js$5 = require('../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.cjs.js');
|
|
21
|
+
const index_cjs_js$4 = require('../../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/promise/index.cjs.js');
|
|
22
22
|
|
|
23
23
|
const SHEBANG = '#!/usr/bin/env node';
|
|
24
24
|
const BIN_FILE_MODE = 0o755;
|
|
@@ -84,53 +84,99 @@ const toBinBuildDescriptor = (bin, context, format, formats, reportPath) => {
|
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
const log$1 = index_cjs_js$2.logger.channel('builder:bundle:rollup:dispatch');
|
|
88
|
-
const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
|
|
89
87
|
const SWC_NODE_REGISTER = '@swc-node/register';
|
|
90
|
-
const
|
|
88
|
+
const probeDir = (dir, offset) => {
|
|
89
|
+
const compiled = node_path.join(dir, ...offset, 'index.cjs.js');
|
|
90
|
+
if (node_fs.existsSync(compiled))
|
|
91
|
+
return { path: compiled, execArgv: [] };
|
|
92
|
+
const source = node_path.join(dir, ...offset, 'index.ts');
|
|
93
|
+
if (node_fs.existsSync(source))
|
|
94
|
+
return { path: source, execArgv: ['--require', SWC_NODE_REGISTER] };
|
|
95
|
+
return undefined;
|
|
96
|
+
};
|
|
91
97
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* the
|
|
98
|
+
* Directory of the currently-executing builder module, read from `__dirname`.
|
|
99
|
+
* It is present in the shipped CommonJS build, in the `@swc-node/register` source
|
|
100
|
+
* bootstrap, and under the test runner, so callers get their own on-disk location
|
|
101
|
+
* and can find the worker beside them however the builder was packaged.
|
|
96
102
|
*
|
|
97
|
-
*
|
|
98
|
-
* 1. `<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js`
|
|
99
|
-
* 2. `<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js`
|
|
100
|
-
* 3. `<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts` (with `--require \@swc-node/register`)
|
|
103
|
+
* @returns Absolute directory path of the running module.
|
|
101
104
|
*
|
|
102
|
-
* @
|
|
103
|
-
* @returns Worker invocation descriptor, or `undefined` if no candidate exists.
|
|
104
|
-
*
|
|
105
|
-
* @example Locating the worker for an in-workspace consumer
|
|
105
|
+
* @example Anchoring a lookup beside the running builder
|
|
106
106
|
* ```typescript
|
|
107
|
-
* const invocation =
|
|
108
|
-
* if (!invocation) throw new Error('builder rollup worker artifact not found')
|
|
107
|
+
* const invocation = ascendForWorker(['bundle', 'rollup', 'worker'], currentModuleDir())
|
|
109
108
|
* ```
|
|
110
109
|
*/
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
index_cjs_js.
|
|
115
|
-
];
|
|
116
|
-
for (const path of distCandidates) {
|
|
117
|
-
if (node_fs.existsSync(path))
|
|
118
|
-
return { path, execArgv: [] };
|
|
110
|
+
const currentModuleDir = () => {
|
|
111
|
+
/* 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 */
|
|
112
|
+
if (typeof __dirname === 'undefined') {
|
|
113
|
+
throw index_cjs_js$2.createError('@hyperfrontend/builder self-location requires the CommonJS build; drive build() from the CommonJS entry point');
|
|
119
114
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
return __dirname;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Locate a builder worker entry by ascending from a start directory toward the
|
|
119
|
+
* filesystem root, returning the first ancestor at which the worker exists at the
|
|
120
|
+
* given in-package offset. The compiled `index.cjs.js` is preferred; an `index.ts`
|
|
121
|
+
* sibling (source-mode bootstrap) resolves with the swc loader attached.
|
|
122
|
+
*
|
|
123
|
+
* The worker ships inside the builder's own package, so resolving relative to the
|
|
124
|
+
* running module finds it wherever the package lives — built dist, an installed
|
|
125
|
+
* `node_modules` copy, or melded into a host bundle under `_dependencies/`.
|
|
126
|
+
*
|
|
127
|
+
* @param offset - In-package path segments to the worker directory (e.g. `['bundle', 'rollup', 'worker']`).
|
|
128
|
+
* @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.
|
|
129
|
+
* @returns The resolved worker invocation, or `undefined` if no worker exists at the offset under any ancestor.
|
|
130
|
+
*
|
|
131
|
+
* @example Resolving the rollup worker from the running module
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const invocation = ascendForWorker(['bundle', 'rollup', 'worker'])
|
|
134
|
+
* if (!invocation) throw new Error('builder rollup worker not found beside the builder module')
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
const ascendForWorker = (offset, startDir = currentModuleDir()) => {
|
|
138
|
+
let dir = startDir;
|
|
139
|
+
let parent = node_path.dirname(dir);
|
|
140
|
+
// how: probe each level then step up; the final probe covers the filesystem root, where parent === dir
|
|
141
|
+
while (parent !== dir) {
|
|
142
|
+
const found = probeDir(dir, offset);
|
|
143
|
+
if (found)
|
|
144
|
+
return found;
|
|
145
|
+
dir = parent;
|
|
146
|
+
parent = node_path.dirname(dir);
|
|
123
147
|
}
|
|
124
|
-
return
|
|
148
|
+
return probeDir(dir, offset);
|
|
125
149
|
};
|
|
150
|
+
|
|
151
|
+
const log$1 = index_cjs_js$3.logger.channel('builder:bundle:rollup:dispatch');
|
|
152
|
+
const REPORT_DIR_PREFIX = 'hf-builder-rollup-';
|
|
153
|
+
/**
|
|
154
|
+
* Resolves the rollup worker by self-locating it beside the running builder
|
|
155
|
+
* module: ascends from the module's own directory to the builder package root
|
|
156
|
+
* and returns the worker at `bundle/rollup/worker`. This works whether the
|
|
157
|
+
* builder runs from its built dist, an installed `node_modules` copy, or melded
|
|
158
|
+
* into a host bundle under `_dependencies/`. The compiled `index.cjs.js` is
|
|
159
|
+
* preferred; an `index.ts` sibling resolves with the `@swc-node/register` loader
|
|
160
|
+
* for source-mode bootstrap.
|
|
161
|
+
*
|
|
162
|
+
* @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.
|
|
163
|
+
* @returns Worker invocation descriptor, or `undefined` if no worker is found under any ancestor.
|
|
164
|
+
*
|
|
165
|
+
* @example Locating the worker beside the builder
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const invocation = resolveDefaultRollupWorkerPath()
|
|
168
|
+
* if (!invocation) throw new Error('builder rollup worker artifact not found')
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
const resolveDefaultRollupWorkerPath = (startDir) => ascendForWorker(['bundle', 'rollup', 'worker'], startDir);
|
|
126
172
|
const createReportDir = () => node_fs.mkdtempSync(index_cjs_js.join(node_os.tmpdir(), REPORT_DIR_PREFIX));
|
|
127
173
|
const reportPathFor = (reportDir, descriptor) => {
|
|
128
174
|
const safeLabel = descriptor.inputFile.replace(/[^a-zA-Z0-9_-]+/g, '_');
|
|
129
175
|
return index_cjs_js.join(reportDir, `${descriptor.format}-${safeLabel}.json`);
|
|
130
176
|
};
|
|
131
|
-
const runOne = (descriptor, options, label) => index_cjs_js$
|
|
177
|
+
const runOne = (descriptor, options, label) => index_cjs_js$4.createPromise((resolve, reject) => {
|
|
132
178
|
const execPath = options.execPath ?? process.execPath;
|
|
133
|
-
const argv = [...(options.execArgv ?? []), options.workerPath, index_cjs_js$
|
|
179
|
+
const argv = [...(options.execArgv ?? []), options.workerPath, index_cjs_js$5.stringify(descriptor)];
|
|
134
180
|
const child = node_child_process.spawn(execPath, argv, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
135
181
|
let capturedStderr = '';
|
|
136
182
|
child.stdout?.on('data', (chunk) => {
|
|
@@ -142,12 +188,12 @@ const runOne = (descriptor, options, label) => index_cjs_js$3.createPromise((res
|
|
|
142
188
|
process.stderr.write(text);
|
|
143
189
|
});
|
|
144
190
|
child.on('error', (error) => {
|
|
145
|
-
reject(index_cjs_js$
|
|
191
|
+
reject(index_cjs_js$2.createError(`rollup worker for ${label} failed to spawn: ${error.message}`));
|
|
146
192
|
});
|
|
147
193
|
child.on('exit', (code) => {
|
|
148
194
|
if (code !== 0) {
|
|
149
195
|
const tail = capturedStderr.trim().split('\n').slice(-10).join('\n');
|
|
150
|
-
reject(index_cjs_js$
|
|
196
|
+
reject(index_cjs_js$2.createError(`rollup worker for ${label} exited with code ${code}\n${tail}`));
|
|
151
197
|
return;
|
|
152
198
|
}
|
|
153
199
|
resolve();
|
|
@@ -155,9 +201,9 @@ const runOne = (descriptor, options, label) => index_cjs_js$3.createPromise((res
|
|
|
155
201
|
});
|
|
156
202
|
const readReport = (reportPath, label) => {
|
|
157
203
|
if (!node_fs.existsSync(reportPath)) {
|
|
158
|
-
throw index_cjs_js$
|
|
204
|
+
throw index_cjs_js$2.createError(`rollup worker for ${label} did not write a report at ${reportPath}`);
|
|
159
205
|
}
|
|
160
|
-
const data = index_cjs_js$
|
|
206
|
+
const data = index_cjs_js$5.parse(node_fs.readFileSync(reportPath, 'utf8'));
|
|
161
207
|
return data;
|
|
162
208
|
};
|
|
163
209
|
/**
|
|
@@ -201,11 +247,11 @@ const dispatchRollupWorker = async (descriptor, options) => {
|
|
|
201
247
|
}
|
|
202
248
|
};
|
|
203
249
|
|
|
204
|
-
const log = index_cjs_js$
|
|
205
|
-
const resolveWorkerOrThrow = (
|
|
206
|
-
const invocation = resolveDefaultRollupWorkerPath(
|
|
250
|
+
const log = index_cjs_js$3.logger.channel('builder:bin:script');
|
|
251
|
+
const resolveWorkerOrThrow = () => {
|
|
252
|
+
const invocation = resolveDefaultRollupWorkerPath();
|
|
207
253
|
if (!invocation) {
|
|
208
|
-
throw index_cjs_js$
|
|
254
|
+
throw index_cjs_js$2.createError('rollup worker could not be located beside the builder module for bin script bundling. The @hyperfrontend/builder package appears incomplete, or @swc-node/register is missing for source-mode bootstrap.');
|
|
209
255
|
}
|
|
210
256
|
return invocation;
|
|
211
257
|
};
|
|
@@ -246,7 +292,7 @@ const buildJsBin = async (bin, ctx) => {
|
|
|
246
292
|
const formats = normalizeFormats(bin.format);
|
|
247
293
|
const binDir = index_cjs_js.join(ctx.outputPath, 'bin');
|
|
248
294
|
index_cjs_js.ensureDir(binDir);
|
|
249
|
-
const worker = resolveWorkerOrThrow(
|
|
295
|
+
const worker = resolveWorkerOrThrow();
|
|
250
296
|
const outputs = [];
|
|
251
297
|
for (const format of formats) {
|
|
252
298
|
const descriptor = toBinBuildDescriptor(bin, ctx, format, formats, '');
|