@normed/bundle 4.0.0 → 4.2.0
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 +10 -0
- package/bundles/bin/cli.js +372 -132
- package/bundles/bin/cli.js.map +3 -3
- package/bundles/bundle.d.ts +27 -2
- package/bundles/entrypoints.d.ts +1 -1
- package/bundles/errors.d.ts +21 -0
- package/bundles/esbuild-plugins/log_esbuild.d.ts +3 -0
- package/bundles/index.js +299 -125
- package/bundles/index.js.map +3 -3
- package/bundles/log.d.ts +1 -1
- package/bundles/plugins.d.ts +27 -0
- package/bundles/types.d.ts +23 -1
- package/bundles/utils.d.ts +86 -3
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,16 @@ Given a version number MAJOR.MINOR.PATCH, increment the:
|
|
|
6
6
|
2. MINOR version when you add functionality in a backwards compatible manner, and
|
|
7
7
|
3. PATCH version when you make backwards compatible bug fixes.
|
|
8
8
|
|
|
9
|
+
# 4.2.0
|
|
10
|
+
|
|
11
|
+
* MINOR: supports a range of plugins, but these are undocumented.
|
|
12
|
+
* MINOR: supports slightly better error returning, but this is not implemented across the board.
|
|
13
|
+
|
|
14
|
+
# 4.1.0
|
|
15
|
+
|
|
16
|
+
* MINOR: fixes building of entypoint pug files.
|
|
17
|
+
* MINOR: updates error formatting to print less information, better.
|
|
18
|
+
|
|
9
19
|
# 4.0.0
|
|
10
20
|
|
|
11
21
|
* MAJOR: moves to a new package.json format
|
package/bundles/bin/cli.js
CHANGED
|
@@ -68580,6 +68580,34 @@ function groupBy(objs, extractSubgroupFuncs) {
|
|
|
68580
68580
|
}
|
|
68581
68581
|
return groups;
|
|
68582
68582
|
}
|
|
68583
|
+
function keyBy(objs, extractKeyFuncs) {
|
|
68584
|
+
const result = /* @__PURE__ */ new Map();
|
|
68585
|
+
const knownKeys = [];
|
|
68586
|
+
for (const obj of objs) {
|
|
68587
|
+
const key = {};
|
|
68588
|
+
for (const [keyName, extractKeyFunc] of Object.entries(extractKeyFuncs)) {
|
|
68589
|
+
key[keyName] = extractKeyFunc(obj);
|
|
68590
|
+
}
|
|
68591
|
+
let knownKey = knownKeys.find(
|
|
68592
|
+
(knownKey2) => Object.keys(knownKey2).length === Object.keys(key).length && Object.keys(knownKey2).every(
|
|
68593
|
+
(k) => knownKey2[k] === key[k]
|
|
68594
|
+
)
|
|
68595
|
+
);
|
|
68596
|
+
if (!knownKey) {
|
|
68597
|
+
knownKey = key;
|
|
68598
|
+
knownKeys.push(key);
|
|
68599
|
+
result.set(knownKey, [obj]);
|
|
68600
|
+
} else {
|
|
68601
|
+
const group = result.get(knownKey);
|
|
68602
|
+
if (group) {
|
|
68603
|
+
group.push(obj);
|
|
68604
|
+
} else {
|
|
68605
|
+
throw new Error(`Keying failed in keyBy`);
|
|
68606
|
+
}
|
|
68607
|
+
}
|
|
68608
|
+
}
|
|
68609
|
+
return result;
|
|
68610
|
+
}
|
|
68583
68611
|
function divide(list, divider) {
|
|
68584
68612
|
const a = [];
|
|
68585
68613
|
const b = [];
|
|
@@ -68876,6 +68904,68 @@ function mergeDeep(into, from) {
|
|
|
68876
68904
|
}
|
|
68877
68905
|
|
|
68878
68906
|
// pnp:/builds/normed/bundle/packages/bundle/src/errors.ts
|
|
68907
|
+
function combineErrorLogs(...logs) {
|
|
68908
|
+
const combined = {
|
|
68909
|
+
errors: [],
|
|
68910
|
+
warnings: []
|
|
68911
|
+
};
|
|
68912
|
+
for (const log of logs) {
|
|
68913
|
+
if (log.errors) {
|
|
68914
|
+
combined.errors.push(...log.errors);
|
|
68915
|
+
}
|
|
68916
|
+
if (log.warnings) {
|
|
68917
|
+
combined.warnings.push(...log.warnings);
|
|
68918
|
+
}
|
|
68919
|
+
}
|
|
68920
|
+
return combined;
|
|
68921
|
+
}
|
|
68922
|
+
var WrappedErrors = class _WrappedErrors extends AggregateError {
|
|
68923
|
+
constructor(errors, message, meta) {
|
|
68924
|
+
var __super = (...args) => {
|
|
68925
|
+
super(...args);
|
|
68926
|
+
this.meta = meta;
|
|
68927
|
+
return this;
|
|
68928
|
+
};
|
|
68929
|
+
if (Array.isArray(errors)) {
|
|
68930
|
+
__super(errors, message);
|
|
68931
|
+
} else {
|
|
68932
|
+
__super(errors.errors ?? [], message);
|
|
68933
|
+
this.warnings = errors.warnings ?? [];
|
|
68934
|
+
}
|
|
68935
|
+
this.name = "WrappedError";
|
|
68936
|
+
}
|
|
68937
|
+
warnings;
|
|
68938
|
+
static fromErrorLog(errorLog, message, meta) {
|
|
68939
|
+
return new _WrappedErrors(errorLog, message, meta);
|
|
68940
|
+
}
|
|
68941
|
+
static fromError(error, message, meta) {
|
|
68942
|
+
return new _WrappedErrors([error], message, meta);
|
|
68943
|
+
}
|
|
68944
|
+
static fromErrors(errors, message, meta) {
|
|
68945
|
+
return new _WrappedErrors(errors, message, meta);
|
|
68946
|
+
}
|
|
68947
|
+
static fromValue(value, message, meta) {
|
|
68948
|
+
const error = asError(value);
|
|
68949
|
+
return new _WrappedErrors([error], message, meta);
|
|
68950
|
+
}
|
|
68951
|
+
static fromValues(values, message, meta) {
|
|
68952
|
+
const errors = values.map(asError);
|
|
68953
|
+
return new _WrappedErrors(errors, message, meta);
|
|
68954
|
+
}
|
|
68955
|
+
};
|
|
68956
|
+
function asError(value, meta) {
|
|
68957
|
+
let error;
|
|
68958
|
+
if (!(value instanceof Error)) {
|
|
68959
|
+
error = new Error(String(value));
|
|
68960
|
+
} else {
|
|
68961
|
+
error = value;
|
|
68962
|
+
}
|
|
68963
|
+
if (meta) {
|
|
68964
|
+
let existingMeta = error.meta ?? {};
|
|
68965
|
+
error.meta = { ...existingMeta, ...meta };
|
|
68966
|
+
}
|
|
68967
|
+
return error;
|
|
68968
|
+
}
|
|
68879
68969
|
var NoMatchingBuilder = class extends Error {
|
|
68880
68970
|
file;
|
|
68881
68971
|
ext;
|
|
@@ -68900,6 +68990,14 @@ var copyBuilder = {
|
|
|
68900
68990
|
copy(infile.absolute, outfile.absolute);
|
|
68901
68991
|
})
|
|
68902
68992
|
);
|
|
68993
|
+
return {
|
|
68994
|
+
warnings: [],
|
|
68995
|
+
errors: [],
|
|
68996
|
+
watchFiles: entrypoints.map((e) => e.infile),
|
|
68997
|
+
watchDirs: [],
|
|
68998
|
+
producedFiles: entrypoints.map((e) => e.outfile),
|
|
68999
|
+
completed: true
|
|
69000
|
+
};
|
|
68903
69001
|
}
|
|
68904
69002
|
};
|
|
68905
69003
|
|
|
@@ -69028,6 +69126,30 @@ var load_less_default = plugin;
|
|
|
69028
69126
|
var import_pug = __toESM(require_lib14());
|
|
69029
69127
|
var import_fs4 = __toESM(require("fs"));
|
|
69030
69128
|
var import_path5 = __toESM(require("path"));
|
|
69129
|
+
function pugTransformer(test, onFound) {
|
|
69130
|
+
return {
|
|
69131
|
+
preCodeGen(ast) {
|
|
69132
|
+
const pending = [...ast?.nodes || []];
|
|
69133
|
+
const found = [];
|
|
69134
|
+
while (pending.length > 0) {
|
|
69135
|
+
const node = pending.shift();
|
|
69136
|
+
if (!node) continue;
|
|
69137
|
+
if (node.block?.nodes) {
|
|
69138
|
+
pending.push(...node.block.nodes);
|
|
69139
|
+
}
|
|
69140
|
+
if (!test(node)) continue;
|
|
69141
|
+
found.push(node);
|
|
69142
|
+
}
|
|
69143
|
+
if (found.length) {
|
|
69144
|
+
onFound(found);
|
|
69145
|
+
}
|
|
69146
|
+
return ast;
|
|
69147
|
+
}
|
|
69148
|
+
};
|
|
69149
|
+
}
|
|
69150
|
+
function isScriptNodeWithSrcAttr(node) {
|
|
69151
|
+
return node.name === "script" && node.attrs.some((attr) => attr.name === "src");
|
|
69152
|
+
}
|
|
69031
69153
|
async function loadAsText2(_filepath) {
|
|
69032
69154
|
return {
|
|
69033
69155
|
loader: "text"
|
|
@@ -69035,33 +69157,59 @@ async function loadAsText2(_filepath) {
|
|
|
69035
69157
|
// as well - its probably faster than us doing it in JS.
|
|
69036
69158
|
};
|
|
69037
69159
|
}
|
|
69038
|
-
async function loadAsJS2(filepath) {
|
|
69160
|
+
async function loadAsJS2(filepath, options2) {
|
|
69039
69161
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69040
|
-
const contents = "export default " + import_pug.default.compileClient(fileData, {
|
|
69162
|
+
const contents = "export default " + import_pug.default.compileClient(fileData, {
|
|
69163
|
+
name: "render",
|
|
69164
|
+
filename: filepath,
|
|
69165
|
+
basedir: options2.outbase
|
|
69166
|
+
});
|
|
69041
69167
|
return {
|
|
69042
69168
|
contents,
|
|
69043
69169
|
loader: "js"
|
|
69044
69170
|
};
|
|
69045
69171
|
}
|
|
69046
|
-
async function loadAsHtml(filepath) {
|
|
69172
|
+
async function loadAsHtml(filepath, options2) {
|
|
69047
69173
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69048
|
-
const contents = import_pug.default.render(fileData, {
|
|
69174
|
+
const contents = import_pug.default.render(fileData, {
|
|
69175
|
+
name: "render",
|
|
69176
|
+
filename: filepath,
|
|
69177
|
+
basedir: options2.outbase,
|
|
69178
|
+
plugins: [
|
|
69179
|
+
pugTransformer(isScriptNodeWithSrcAttr, (nodes) => {
|
|
69180
|
+
nodes;
|
|
69181
|
+
})
|
|
69182
|
+
]
|
|
69183
|
+
});
|
|
69049
69184
|
return {
|
|
69050
69185
|
contents,
|
|
69051
69186
|
loader: "js"
|
|
69052
69187
|
};
|
|
69053
69188
|
}
|
|
69054
|
-
async function
|
|
69189
|
+
async function loadAsEntrypoint(filepath, options2) {
|
|
69055
69190
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69056
|
-
const contents = import_pug.default.render(fileData, {
|
|
69191
|
+
const contents = import_pug.default.render(fileData, {
|
|
69192
|
+
filename: filepath,
|
|
69193
|
+
basedir: options2.outbase,
|
|
69194
|
+
name: "render",
|
|
69195
|
+
plugins: [
|
|
69196
|
+
pugTransformer(isScriptNodeWithSrcAttr, (nodes) => {
|
|
69197
|
+
nodes;
|
|
69198
|
+
})
|
|
69199
|
+
]
|
|
69200
|
+
});
|
|
69057
69201
|
return {
|
|
69058
69202
|
contents,
|
|
69059
69203
|
loader: "copy"
|
|
69060
69204
|
};
|
|
69061
69205
|
}
|
|
69062
|
-
async function loadAsFile(filepath) {
|
|
69206
|
+
async function loadAsFile(filepath, options2) {
|
|
69063
69207
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69064
|
-
const contents = import_pug.default.render(fileData, {
|
|
69208
|
+
const contents = import_pug.default.render(fileData, {
|
|
69209
|
+
name: "render",
|
|
69210
|
+
filename: filepath,
|
|
69211
|
+
basedir: options2.outbase
|
|
69212
|
+
});
|
|
69065
69213
|
return {
|
|
69066
69214
|
contents,
|
|
69067
69215
|
loader: "file"
|
|
@@ -69100,7 +69248,7 @@ var plugin2 = {
|
|
|
69100
69248
|
}) => {
|
|
69101
69249
|
const isEntryPoint = pluginData?.[name2]?.entrypoint;
|
|
69102
69250
|
if (isEntryPoint) {
|
|
69103
|
-
return
|
|
69251
|
+
return loadAsEntrypoint(filepath, build2.initialOptions);
|
|
69104
69252
|
}
|
|
69105
69253
|
const type = withArg?.["type"] ?? "js";
|
|
69106
69254
|
switch (type) {
|
|
@@ -69108,7 +69256,7 @@ var plugin2 = {
|
|
|
69108
69256
|
// This gives a string of the pug already rendered to html
|
|
69109
69257
|
// TODO: could support passing options to pug.render via the with clause
|
|
69110
69258
|
case "html":
|
|
69111
|
-
return loadAsHtml(filepath);
|
|
69259
|
+
return loadAsHtml(filepath, build2.initialOptions);
|
|
69112
69260
|
// Load pug as a text file by doing "import template from './file.pug' with { type: 'text' }"
|
|
69113
69261
|
// This gives a string of the raw pug file, which can be used as pug - e.g. as a template string
|
|
69114
69262
|
case "pug":
|
|
@@ -69117,12 +69265,12 @@ var plugin2 = {
|
|
|
69117
69265
|
// Load pug as a render function by doing "import render from './file.pug' with { type: 'js' }"
|
|
69118
69266
|
// This is the default behaviour if no with clause is used, or no type is specified.
|
|
69119
69267
|
case "js":
|
|
69120
|
-
return loadAsJS2(filepath);
|
|
69268
|
+
return loadAsJS2(filepath, build2.initialOptions);
|
|
69121
69269
|
// Load pug as a file by doing "import template from './file.pug' with { type: 'file' }"
|
|
69122
69270
|
// This will render the pug file to a file, and return the path to that file.
|
|
69123
69271
|
// The path is going to contain a hash, so it is not going to be the same as the original file.
|
|
69124
69272
|
case "file":
|
|
69125
|
-
return loadAsFile(filepath);
|
|
69273
|
+
return loadAsFile(filepath, build2.initialOptions);
|
|
69126
69274
|
// In the case that the type is not recognised, throw an error
|
|
69127
69275
|
default:
|
|
69128
69276
|
throw new Error(`Unsupported type: ${type}`);
|
|
@@ -69290,7 +69438,9 @@ var esbuilder = {
|
|
|
69290
69438
|
entryPoints: build2.map(({ infile }) => infile.absolute),
|
|
69291
69439
|
outdir,
|
|
69292
69440
|
outbase: indir,
|
|
69293
|
-
write: false
|
|
69441
|
+
write: false,
|
|
69442
|
+
logLevel: "silent"
|
|
69443
|
+
// TODO: add a specific variable for this
|
|
69294
69444
|
};
|
|
69295
69445
|
log_default.debug(
|
|
69296
69446
|
`Final config:`,
|
|
@@ -69301,6 +69451,13 @@ var esbuilder = {
|
|
|
69301
69451
|
)
|
|
69302
69452
|
);
|
|
69303
69453
|
const codeBuild = esbuild.build(finalConfig).then(async (result) => {
|
|
69454
|
+
if (result.errors.length || result.warnings.length) {
|
|
69455
|
+
log_default.info(`Build completed with errors or warnings:`, {
|
|
69456
|
+
errors: result.errors.length,
|
|
69457
|
+
warnings: result.warnings.length
|
|
69458
|
+
});
|
|
69459
|
+
throw result;
|
|
69460
|
+
}
|
|
69304
69461
|
log_default.debug(
|
|
69305
69462
|
`Got output files:`,
|
|
69306
69463
|
result.outputFiles.map((f) => import_path7.default.relative(outdir, f.path))
|
|
@@ -69369,6 +69526,20 @@ var esbuilder = {
|
|
|
69369
69526
|
}
|
|
69370
69527
|
}
|
|
69371
69528
|
await Promise.all(writers);
|
|
69529
|
+
}).catch((err) => {
|
|
69530
|
+
const errors = err.errors || [];
|
|
69531
|
+
const warnings = err.warnings || [];
|
|
69532
|
+
if (!errors.length && !warnings.length) {
|
|
69533
|
+
log_default.error(
|
|
69534
|
+
`Build failed with no errors or warnings, but an unknown error occurred.`
|
|
69535
|
+
);
|
|
69536
|
+
throw err;
|
|
69537
|
+
} else {
|
|
69538
|
+
log_default.error(
|
|
69539
|
+
`Build failed with ${errors.length} errors and ${warnings.length} warnings.`
|
|
69540
|
+
);
|
|
69541
|
+
throw [...errors, ...warnings];
|
|
69542
|
+
}
|
|
69372
69543
|
});
|
|
69373
69544
|
promises.push(codeBuild);
|
|
69374
69545
|
if (exampleFile.entryconfig.declarations) {
|
|
@@ -69395,6 +69566,18 @@ var esbuilder = {
|
|
|
69395
69566
|
}
|
|
69396
69567
|
await Promise.all(promises);
|
|
69397
69568
|
}
|
|
69569
|
+
return {
|
|
69570
|
+
// TODO: rewrite to return warnings
|
|
69571
|
+
warnings: [],
|
|
69572
|
+
// TODO: rewrite to return errors
|
|
69573
|
+
errors: [],
|
|
69574
|
+
watchFiles: entrypoints.map((e) => e.infile),
|
|
69575
|
+
watchDirs: [],
|
|
69576
|
+
// TODO: these are not the correct files
|
|
69577
|
+
producedFiles: entrypoints.map((e) => e.outfile),
|
|
69578
|
+
// TODO: rewrite to only return true if all builds were successful
|
|
69579
|
+
completed: true
|
|
69580
|
+
};
|
|
69398
69581
|
}
|
|
69399
69582
|
};
|
|
69400
69583
|
async function compileToTypeDeclarations(fileNames, options2) {
|
|
@@ -70244,7 +70427,7 @@ async function getEntrypoints(buildConfig, manuallySpecified) {
|
|
|
70244
70427
|
}
|
|
70245
70428
|
|
|
70246
70429
|
// pnp:/builds/normed/bundle/packages/bundle/src/bundle.ts
|
|
70247
|
-
async function
|
|
70430
|
+
async function getBuildConfig(options2) {
|
|
70248
70431
|
const buildConfig = {
|
|
70249
70432
|
dir: {
|
|
70250
70433
|
in: getInDir(options2),
|
|
@@ -70358,125 +70541,116 @@ async function bundle(options2 = {}) {
|
|
|
70358
70541
|
"Build Config - post reading package.json",
|
|
70359
70542
|
JSON.stringify(buildConfig.baseConfig, null, 2)
|
|
70360
70543
|
);
|
|
70361
|
-
|
|
70362
|
-
|
|
70363
|
-
|
|
70364
|
-
|
|
70365
|
-
|
|
70366
|
-
|
|
70367
|
-
|
|
70368
|
-
|
|
70369
|
-
(e) => e.origin === "discovered" && e.infile.modifiers.includes("context")
|
|
70544
|
+
return buildConfig;
|
|
70545
|
+
}
|
|
70546
|
+
async function discoverEntrypoints(buildConfig, entrypoints, plugins = {}) {
|
|
70547
|
+
let initialEntrypoints = await getEntrypoints(buildConfig, entrypoints);
|
|
70548
|
+
initialEntrypoints = await plugins.initialEntrypoints?.(initialEntrypoints) ?? initialEntrypoints;
|
|
70549
|
+
const [missing, found] = divide(
|
|
70550
|
+
initialEntrypoints,
|
|
70551
|
+
(e) => e instanceof NoMatchingBuilder
|
|
70370
70552
|
);
|
|
70371
|
-
|
|
70372
|
-
|
|
70373
|
-
|
|
70374
|
-
|
|
70375
|
-
|
|
70376
|
-
|
|
70377
|
-
|
|
70378
|
-
|
|
70379
|
-
log_default.warn(` - skipping ${contextEntrypoint.infile.relative}`);
|
|
70380
|
-
return;
|
|
70381
|
-
}
|
|
70382
|
-
skippedContextFile = false;
|
|
70383
|
-
const matchingEntrypoints = entrypoints.filter(
|
|
70384
|
-
(e) => e.infile.bare === contextEntrypoint.infile.bare
|
|
70385
|
-
);
|
|
70386
|
-
if (!matchingEntrypoints.length) {
|
|
70387
|
-
log_default.warn(
|
|
70388
|
-
`Context file ${contextEntrypoint.infile.bare} is not used by any entrypoint`
|
|
70389
|
-
);
|
|
70390
|
-
return;
|
|
70391
|
-
}
|
|
70392
|
-
log_default.verbose(
|
|
70393
|
-
`Context file ${contextEntrypoint.infile.bare} is used by ${matchingEntrypoints.length} entrypoints`
|
|
70394
|
-
);
|
|
70395
|
-
async function compile(_v) {
|
|
70396
|
-
throw new Error("Function not implemented.");
|
|
70397
|
-
}
|
|
70398
|
-
const compiled = await compile(contextEntrypoint);
|
|
70399
|
-
const { context } = await compiled.run();
|
|
70400
|
-
if (!context) {
|
|
70401
|
-
log_default.warn(
|
|
70402
|
-
`Context file ${contextEntrypoint.infile.bare} did not export a context function`
|
|
70403
|
-
);
|
|
70404
|
-
return;
|
|
70405
|
-
}
|
|
70406
|
-
const contextResult = await context();
|
|
70407
|
-
if (!contextResult) {
|
|
70408
|
-
log_default.warn(
|
|
70409
|
-
`Context file ${contextEntrypoint.infile.bare} did not return a context object`
|
|
70410
|
-
);
|
|
70411
|
-
return;
|
|
70412
|
-
}
|
|
70413
|
-
const builderNames = matchingEntrypoints.map((e) => e.builder.name).filter((v, i, a) => a.indexOf(v) === i);
|
|
70414
|
-
const builderNamesWithContexts = builderNames.filter(
|
|
70415
|
-
(name3) => contextResult[name3]
|
|
70416
|
-
);
|
|
70417
|
-
if (!builderNamesWithContexts.length) {
|
|
70418
|
-
log_default.warn(
|
|
70419
|
-
`Context file ${contextEntrypoint.infile.bare} did not return any context for any of the builders: ${builderNames.join(", ")}`
|
|
70420
|
-
);
|
|
70421
|
-
return;
|
|
70422
|
-
}
|
|
70423
|
-
for (const builderName of builderNamesWithContexts) {
|
|
70424
|
-
await Promise.all(
|
|
70425
|
-
matchingEntrypoints.filter((e) => e.builder.name === builderName).map(async (entrypoint) => {
|
|
70426
|
-
const func = contextResult[builderName];
|
|
70427
|
-
if (!func) {
|
|
70428
|
-
log_default.warn(
|
|
70429
|
-
`Context file ${contextEntrypoint.infile.bare} did not return a context for builder ${builderName}`
|
|
70430
|
-
);
|
|
70431
|
-
return;
|
|
70432
|
-
}
|
|
70433
|
-
entrypoint.context = await func();
|
|
70434
|
-
})
|
|
70435
|
-
);
|
|
70553
|
+
if (missing.length) {
|
|
70554
|
+
const missingBuilders = missing.filter((v, i, a) => a.indexOf(v) === i);
|
|
70555
|
+
return WrappedErrors.fromErrors(
|
|
70556
|
+
missing,
|
|
70557
|
+
"Missing builders for entrypoints",
|
|
70558
|
+
{
|
|
70559
|
+
missingBuilders: missingBuilders.map((b) => b.name),
|
|
70560
|
+
missingBuilders_count: missingBuilders.length
|
|
70436
70561
|
}
|
|
70437
|
-
|
|
70562
|
+
);
|
|
70563
|
+
}
|
|
70564
|
+
return plugins.discoveredEntrypoints?.(found) ?? found;
|
|
70565
|
+
}
|
|
70566
|
+
async function bundle(options2 = {}, plugins = {}) {
|
|
70567
|
+
const start = Date.now();
|
|
70568
|
+
const buildConfig = await getBuildConfig(options2);
|
|
70569
|
+
const entrypoints = await discoverEntrypoints(
|
|
70570
|
+
buildConfig,
|
|
70571
|
+
options2.entrypoints,
|
|
70572
|
+
plugins
|
|
70438
70573
|
);
|
|
70439
|
-
|
|
70440
|
-
|
|
70441
|
-
|
|
70442
|
-
|
|
70443
|
-
if (!acc[index]) {
|
|
70444
|
-
acc[index] = [];
|
|
70445
|
-
}
|
|
70446
|
-
acc[index]?.push(entryPoint);
|
|
70447
|
-
return acc;
|
|
70448
|
-
}, []);
|
|
70449
|
-
for (const index in grouped) {
|
|
70450
|
-
const group = grouped[index];
|
|
70451
|
-
const builder = buildConfig.builders[index];
|
|
70452
|
-
if (!builder) {
|
|
70453
|
-
continue;
|
|
70454
|
-
}
|
|
70455
|
-
log_default.info(
|
|
70456
|
-
builder.color(
|
|
70457
|
-
`${builder.name}:
|
|
70458
|
-
${group?.map((i) => `${i.infile.relative} => ${i.outfile.relative}`).join("\n ")}`
|
|
70459
|
-
)
|
|
70574
|
+
if (entrypoints instanceof WrappedErrors) {
|
|
70575
|
+
return WrappedErrors.fromError(
|
|
70576
|
+
entrypoints,
|
|
70577
|
+
"Failed to discover entrypoints"
|
|
70460
70578
|
);
|
|
70461
70579
|
}
|
|
70462
|
-
|
|
70463
|
-
|
|
70464
|
-
|
|
70465
|
-
|
|
70466
|
-
|
|
70467
|
-
|
|
70468
|
-
|
|
70469
|
-
|
|
70470
|
-
|
|
70471
|
-
|
|
70472
|
-
|
|
70580
|
+
let grouped = keyBy(entrypoints, {
|
|
70581
|
+
builder: (entrypoint) => entrypoint.builder
|
|
70582
|
+
});
|
|
70583
|
+
grouped = await plugins.preBuild?.(grouped) ?? grouped;
|
|
70584
|
+
const results = await Promise.allSettled(
|
|
70585
|
+
Array.from(grouped.entries()).map(
|
|
70586
|
+
async ([
|
|
70587
|
+
{ builder },
|
|
70588
|
+
entrypoints2
|
|
70589
|
+
]) => {
|
|
70590
|
+
const start2 = Date.now();
|
|
70591
|
+
const annotations = {
|
|
70592
|
+
entrypoints: entrypoints2,
|
|
70593
|
+
builder,
|
|
70594
|
+
duration_ms: -1
|
|
70595
|
+
};
|
|
70596
|
+
let result;
|
|
70597
|
+
try {
|
|
70598
|
+
result = await builder.build(entrypoints2);
|
|
70599
|
+
} catch (e) {
|
|
70600
|
+
result = {
|
|
70601
|
+
warnings: [],
|
|
70602
|
+
errors: [WrappedErrors.fromValue(e, "Builder failed to build")],
|
|
70603
|
+
watchFiles: entrypoints2.map((e2) => e2.infile),
|
|
70604
|
+
watchDirs: [],
|
|
70605
|
+
producedFiles: [],
|
|
70606
|
+
completed: false
|
|
70607
|
+
};
|
|
70608
|
+
} finally {
|
|
70609
|
+
annotations.duration_ms = Date.now() - start2;
|
|
70473
70610
|
}
|
|
70474
|
-
|
|
70611
|
+
result = await plugins.postBuild?.(result, annotations) ?? result;
|
|
70612
|
+
return {
|
|
70613
|
+
...result,
|
|
70614
|
+
...annotations
|
|
70615
|
+
};
|
|
70616
|
+
}
|
|
70475
70617
|
)
|
|
70476
70618
|
);
|
|
70477
|
-
const
|
|
70478
|
-
|
|
70479
|
-
|
|
70619
|
+
const [rejected, fulfilled] = divide(
|
|
70620
|
+
results,
|
|
70621
|
+
(r) => r.status === "rejected"
|
|
70622
|
+
);
|
|
70623
|
+
const [uncompleted, completed] = divide(fulfilled, (r) => r.value.completed);
|
|
70624
|
+
const errorLogs = combineErrorLogs(
|
|
70625
|
+
...uncompleted.map((r) => r.value),
|
|
70626
|
+
...completed.map((r) => r.value)
|
|
70627
|
+
);
|
|
70628
|
+
const errors = [
|
|
70629
|
+
rejected.length ? WrappedErrors.fromValues(
|
|
70630
|
+
rejected.map((r) => r.reason),
|
|
70631
|
+
"Some builders encountered errors when running",
|
|
70632
|
+
{
|
|
70633
|
+
rejected_count: rejected.length,
|
|
70634
|
+
entrypoints: entrypoints.map((e) => e.infile.relative),
|
|
70635
|
+
builders: Array.from(grouped.keys()).map(
|
|
70636
|
+
({ builder }) => builder.name
|
|
70637
|
+
)
|
|
70638
|
+
}
|
|
70639
|
+
) : void 0,
|
|
70640
|
+
...errorLogs.errors ?? []
|
|
70641
|
+
];
|
|
70642
|
+
const warnings = errorLogs.warnings ?? [];
|
|
70643
|
+
return {
|
|
70644
|
+
completed: rejected.length === 0 && uncompleted.length === 0,
|
|
70645
|
+
errors: errors.filter(isNot.undefined),
|
|
70646
|
+
warnings,
|
|
70647
|
+
watchFiles: fulfilled.flatMap((r) => r.value.watchFiles),
|
|
70648
|
+
watchDirs: fulfilled.flatMap((r) => r.value.watchDirs),
|
|
70649
|
+
producedFiles: fulfilled.flatMap((r) => r.value.producedFiles),
|
|
70650
|
+
entrypoints,
|
|
70651
|
+
duration_ms: Date.now() - start,
|
|
70652
|
+
children: fulfilled.map((r) => r.value)
|
|
70653
|
+
};
|
|
70480
70654
|
}
|
|
70481
70655
|
|
|
70482
70656
|
// pnp:/builds/normed/bundle/packages/bundle/src/index.ts
|
|
@@ -70610,17 +70784,83 @@ if (optClean) {
|
|
|
70610
70784
|
}
|
|
70611
70785
|
if (optBuild) {
|
|
70612
70786
|
log_default.info(`Building`);
|
|
70613
|
-
tasks.push(
|
|
70787
|
+
tasks.push(
|
|
70788
|
+
bundle2(options, {
|
|
70789
|
+
preBuild(builderMap) {
|
|
70790
|
+
const builders2 = [...builderMap.entries()].sort(
|
|
70791
|
+
([
|
|
70792
|
+
{
|
|
70793
|
+
builder: { name: a }
|
|
70794
|
+
}
|
|
70795
|
+
], [
|
|
70796
|
+
{
|
|
70797
|
+
builder: { name: b }
|
|
70798
|
+
}
|
|
70799
|
+
]) => {
|
|
70800
|
+
return a.localeCompare(b);
|
|
70801
|
+
}
|
|
70802
|
+
);
|
|
70803
|
+
for (const [{ builder }, entrypoints] of builders2) {
|
|
70804
|
+
log_default.info(
|
|
70805
|
+
builder.color(
|
|
70806
|
+
`${builder.name}:
|
|
70807
|
+
${entrypoints.map((i) => i.infile.relative).join("\n ")}`
|
|
70808
|
+
)
|
|
70809
|
+
);
|
|
70810
|
+
}
|
|
70811
|
+
return builderMap;
|
|
70812
|
+
},
|
|
70813
|
+
postBuild(success, { builder, duration_ms }) {
|
|
70814
|
+
const duration = Math.floor(duration_ms / 10) / 100;
|
|
70815
|
+
if (success) {
|
|
70816
|
+
log_default.info(builder.color(`${builder.name}: ${duration} seconds`));
|
|
70817
|
+
} else {
|
|
70818
|
+
log_default.error(
|
|
70819
|
+
builder.color(`${builder.name}: Failed after ${duration} seconds`)
|
|
70820
|
+
);
|
|
70821
|
+
exitCode = 1;
|
|
70822
|
+
}
|
|
70823
|
+
return success;
|
|
70824
|
+
}
|
|
70825
|
+
}).then(() => {
|
|
70826
|
+
})
|
|
70827
|
+
);
|
|
70614
70828
|
}
|
|
70615
|
-
|
|
70616
|
-
|
|
70617
|
-
|
|
70618
|
-
|
|
70619
|
-
|
|
70829
|
+
function errorPrinter(error, index) {
|
|
70830
|
+
if (Array.isArray(error)) {
|
|
70831
|
+
for (const err of error) {
|
|
70832
|
+
index = errorPrinter(err, index);
|
|
70833
|
+
}
|
|
70834
|
+
return index;
|
|
70835
|
+
}
|
|
70836
|
+
if (error instanceof Error) {
|
|
70837
|
+
log_default.error(`(${index}) Error:`, error.message);
|
|
70838
|
+
log_default.debug(error.stack);
|
|
70839
|
+
index++;
|
|
70840
|
+
} else {
|
|
70841
|
+
if (error && typeof error === "object") {
|
|
70842
|
+
if (error.text && error.notes && error.detail) {
|
|
70843
|
+
log_default.error(`(${index}) Error: ${error.text}`);
|
|
70844
|
+
for (const note of error.notes) {
|
|
70845
|
+
log_default.verbose(`Note: ${note.text}`);
|
|
70846
|
+
if (note.location) {
|
|
70847
|
+
log_default.verbose(
|
|
70848
|
+
`Location: ${note.location.file}:${note.location.line}:${note.location.column}`
|
|
70849
|
+
);
|
|
70850
|
+
}
|
|
70851
|
+
}
|
|
70852
|
+
} else {
|
|
70853
|
+
log_default.error(`(${index}) Error:`, error);
|
|
70854
|
+
}
|
|
70620
70855
|
} else {
|
|
70621
|
-
log_default.error(
|
|
70856
|
+
log_default.error(`(${index}) Error:`, String(error));
|
|
70622
70857
|
}
|
|
70623
70858
|
}
|
|
70859
|
+
return index;
|
|
70860
|
+
}
|
|
70861
|
+
Promise.all(tasks).catch((_errors) => {
|
|
70862
|
+
let errors = Array.isArray(_errors) ? _errors : [_errors];
|
|
70863
|
+
errorPrinter(errors, 1);
|
|
70624
70864
|
exitCode = 1;
|
|
70625
70865
|
}).finally(() => {
|
|
70626
70866
|
const endTime = Date.now();
|