@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/bundles/bundle.d.ts
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
import "@normed/json-types";
|
|
2
|
-
import { APIOptions_Bundle } from "./types";
|
|
3
|
-
|
|
2
|
+
import { Entrypoint, APIOptions_Bundle } from "./types";
|
|
3
|
+
import { WrappedErrors } from "./errors";
|
|
4
|
+
import { BundlePlugins } from "./plugins";
|
|
5
|
+
export default function bundle(options?: APIOptions_Bundle, plugins?: BundlePlugins): Promise<WrappedErrors | {
|
|
6
|
+
completed: boolean;
|
|
7
|
+
errors: Error[];
|
|
8
|
+
warnings: Error[];
|
|
9
|
+
watchFiles: import("./File").FileInfo[];
|
|
10
|
+
watchDirs: {
|
|
11
|
+
path: string;
|
|
12
|
+
}[];
|
|
13
|
+
producedFiles: import("./File").FileInfo[];
|
|
14
|
+
entrypoints: Entrypoint[];
|
|
15
|
+
duration_ms: number;
|
|
16
|
+
children: ({
|
|
17
|
+
completed: boolean;
|
|
18
|
+
watchFiles: import("./File").FileInfo[];
|
|
19
|
+
watchDirs: {
|
|
20
|
+
path: string;
|
|
21
|
+
}[];
|
|
22
|
+
producedFiles: import("./File").FileInfo[];
|
|
23
|
+
} & import("./errors").ErrorLog & {
|
|
24
|
+
entrypoints: Entrypoint[];
|
|
25
|
+
builder: import("./types").Builder;
|
|
26
|
+
duration_ms: number;
|
|
27
|
+
})[];
|
|
28
|
+
}>;
|
package/bundles/entrypoints.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "@normed/json-types";
|
|
2
2
|
import { Entrypoint, BuildConfig } from "./types";
|
|
3
3
|
import { NoMatchingBuilder } from "./errors";
|
|
4
|
-
export default function getEntrypoints(buildConfig: BuildConfig, manuallySpecified?: string[]): Promise<(
|
|
4
|
+
export default function getEntrypoints(buildConfig: BuildConfig, manuallySpecified?: string[]): Promise<(NoMatchingBuilder | Entrypoint)[]>;
|
package/bundles/errors.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
export interface MetaField {
|
|
2
|
+
meta?: JSONishObject | undefined;
|
|
3
|
+
}
|
|
4
|
+
export type WithMeta<V> = V & MetaField;
|
|
5
|
+
export interface ErrorLog {
|
|
6
|
+
errors?: Error[];
|
|
7
|
+
warnings?: Error[];
|
|
8
|
+
}
|
|
9
|
+
export declare function combineErrorLogs(...logs: ErrorLog[]): ErrorLog;
|
|
10
|
+
export declare class WrappedErrors extends AggregateError implements MetaField, ErrorLog {
|
|
11
|
+
meta?: JSONishObject | undefined;
|
|
12
|
+
warnings?: Error[];
|
|
13
|
+
constructor(errors: Error[] | ErrorLog, message: string, meta?: JSONishObject | undefined);
|
|
14
|
+
static fromErrorLog(errorLog: ErrorLog, message: string, meta?: JSONishObject): WrappedErrors;
|
|
15
|
+
static fromError(error: Error, message: string, meta?: JSONishObject): WrappedErrors;
|
|
16
|
+
static fromErrors(errors: Error[], message: string, meta?: JSONishObject): WrappedErrors;
|
|
17
|
+
static fromValue(value: unknown, message: string, meta?: JSONishObject): WrappedErrors;
|
|
18
|
+
static fromValues(values: unknown[], message: string, meta?: JSONishObject): WrappedErrors;
|
|
19
|
+
}
|
|
20
|
+
export declare function asError(value: unknown): Error;
|
|
21
|
+
export declare function asError(value: unknown, meta: JSONishObject): WithMeta<Error>;
|
|
1
22
|
export declare class NoMatchingBuilder extends Error {
|
|
2
23
|
readonly file: string;
|
|
3
24
|
readonly ext: string;
|
package/bundles/index.js
CHANGED
|
@@ -68594,6 +68594,34 @@ function groupBy(objs, extractSubgroupFuncs) {
|
|
|
68594
68594
|
}
|
|
68595
68595
|
return groups;
|
|
68596
68596
|
}
|
|
68597
|
+
function keyBy(objs, extractKeyFuncs) {
|
|
68598
|
+
const result = /* @__PURE__ */ new Map();
|
|
68599
|
+
const knownKeys = [];
|
|
68600
|
+
for (const obj of objs) {
|
|
68601
|
+
const key = {};
|
|
68602
|
+
for (const [keyName, extractKeyFunc] of Object.entries(extractKeyFuncs)) {
|
|
68603
|
+
key[keyName] = extractKeyFunc(obj);
|
|
68604
|
+
}
|
|
68605
|
+
let knownKey = knownKeys.find(
|
|
68606
|
+
(knownKey2) => Object.keys(knownKey2).length === Object.keys(key).length && Object.keys(knownKey2).every(
|
|
68607
|
+
(k) => knownKey2[k] === key[k]
|
|
68608
|
+
)
|
|
68609
|
+
);
|
|
68610
|
+
if (!knownKey) {
|
|
68611
|
+
knownKey = key;
|
|
68612
|
+
knownKeys.push(key);
|
|
68613
|
+
result.set(knownKey, [obj]);
|
|
68614
|
+
} else {
|
|
68615
|
+
const group = result.get(knownKey);
|
|
68616
|
+
if (group) {
|
|
68617
|
+
group.push(obj);
|
|
68618
|
+
} else {
|
|
68619
|
+
throw new Error(`Keying failed in keyBy`);
|
|
68620
|
+
}
|
|
68621
|
+
}
|
|
68622
|
+
}
|
|
68623
|
+
return result;
|
|
68624
|
+
}
|
|
68597
68625
|
function divide(list, divider) {
|
|
68598
68626
|
const a = [];
|
|
68599
68627
|
const b = [];
|
|
@@ -68890,6 +68918,68 @@ function mergeDeep(into, from) {
|
|
|
68890
68918
|
}
|
|
68891
68919
|
|
|
68892
68920
|
// pnp:/builds/normed/bundle/packages/bundle/src/errors.ts
|
|
68921
|
+
function combineErrorLogs(...logs) {
|
|
68922
|
+
const combined = {
|
|
68923
|
+
errors: [],
|
|
68924
|
+
warnings: []
|
|
68925
|
+
};
|
|
68926
|
+
for (const log of logs) {
|
|
68927
|
+
if (log.errors) {
|
|
68928
|
+
combined.errors.push(...log.errors);
|
|
68929
|
+
}
|
|
68930
|
+
if (log.warnings) {
|
|
68931
|
+
combined.warnings.push(...log.warnings);
|
|
68932
|
+
}
|
|
68933
|
+
}
|
|
68934
|
+
return combined;
|
|
68935
|
+
}
|
|
68936
|
+
var WrappedErrors = class _WrappedErrors extends AggregateError {
|
|
68937
|
+
constructor(errors, message, meta) {
|
|
68938
|
+
var __super = (...args) => {
|
|
68939
|
+
super(...args);
|
|
68940
|
+
this.meta = meta;
|
|
68941
|
+
return this;
|
|
68942
|
+
};
|
|
68943
|
+
if (Array.isArray(errors)) {
|
|
68944
|
+
__super(errors, message);
|
|
68945
|
+
} else {
|
|
68946
|
+
__super(errors.errors ?? [], message);
|
|
68947
|
+
this.warnings = errors.warnings ?? [];
|
|
68948
|
+
}
|
|
68949
|
+
this.name = "WrappedError";
|
|
68950
|
+
}
|
|
68951
|
+
warnings;
|
|
68952
|
+
static fromErrorLog(errorLog, message, meta) {
|
|
68953
|
+
return new _WrappedErrors(errorLog, message, meta);
|
|
68954
|
+
}
|
|
68955
|
+
static fromError(error, message, meta) {
|
|
68956
|
+
return new _WrappedErrors([error], message, meta);
|
|
68957
|
+
}
|
|
68958
|
+
static fromErrors(errors, message, meta) {
|
|
68959
|
+
return new _WrappedErrors(errors, message, meta);
|
|
68960
|
+
}
|
|
68961
|
+
static fromValue(value, message, meta) {
|
|
68962
|
+
const error = asError(value);
|
|
68963
|
+
return new _WrappedErrors([error], message, meta);
|
|
68964
|
+
}
|
|
68965
|
+
static fromValues(values, message, meta) {
|
|
68966
|
+
const errors = values.map(asError);
|
|
68967
|
+
return new _WrappedErrors(errors, message, meta);
|
|
68968
|
+
}
|
|
68969
|
+
};
|
|
68970
|
+
function asError(value, meta) {
|
|
68971
|
+
let error;
|
|
68972
|
+
if (!(value instanceof Error)) {
|
|
68973
|
+
error = new Error(String(value));
|
|
68974
|
+
} else {
|
|
68975
|
+
error = value;
|
|
68976
|
+
}
|
|
68977
|
+
if (meta) {
|
|
68978
|
+
let existingMeta = error.meta ?? {};
|
|
68979
|
+
error.meta = { ...existingMeta, ...meta };
|
|
68980
|
+
}
|
|
68981
|
+
return error;
|
|
68982
|
+
}
|
|
68893
68983
|
var NoMatchingBuilder = class extends Error {
|
|
68894
68984
|
file;
|
|
68895
68985
|
ext;
|
|
@@ -68914,6 +69004,14 @@ var copyBuilder = {
|
|
|
68914
69004
|
copy(infile.absolute, outfile.absolute);
|
|
68915
69005
|
})
|
|
68916
69006
|
);
|
|
69007
|
+
return {
|
|
69008
|
+
warnings: [],
|
|
69009
|
+
errors: [],
|
|
69010
|
+
watchFiles: entrypoints.map((e) => e.infile),
|
|
69011
|
+
watchDirs: [],
|
|
69012
|
+
producedFiles: entrypoints.map((e) => e.outfile),
|
|
69013
|
+
completed: true
|
|
69014
|
+
};
|
|
68917
69015
|
}
|
|
68918
69016
|
};
|
|
68919
69017
|
|
|
@@ -69042,6 +69140,30 @@ var load_less_default = plugin;
|
|
|
69042
69140
|
var import_pug = __toESM(require_lib14());
|
|
69043
69141
|
var import_fs4 = __toESM(require("fs"));
|
|
69044
69142
|
var import_path5 = __toESM(require("path"));
|
|
69143
|
+
function pugTransformer(test, onFound) {
|
|
69144
|
+
return {
|
|
69145
|
+
preCodeGen(ast) {
|
|
69146
|
+
const pending = [...ast?.nodes || []];
|
|
69147
|
+
const found = [];
|
|
69148
|
+
while (pending.length > 0) {
|
|
69149
|
+
const node = pending.shift();
|
|
69150
|
+
if (!node) continue;
|
|
69151
|
+
if (node.block?.nodes) {
|
|
69152
|
+
pending.push(...node.block.nodes);
|
|
69153
|
+
}
|
|
69154
|
+
if (!test(node)) continue;
|
|
69155
|
+
found.push(node);
|
|
69156
|
+
}
|
|
69157
|
+
if (found.length) {
|
|
69158
|
+
onFound(found);
|
|
69159
|
+
}
|
|
69160
|
+
return ast;
|
|
69161
|
+
}
|
|
69162
|
+
};
|
|
69163
|
+
}
|
|
69164
|
+
function isScriptNodeWithSrcAttr(node) {
|
|
69165
|
+
return node.name === "script" && node.attrs.some((attr) => attr.name === "src");
|
|
69166
|
+
}
|
|
69045
69167
|
async function loadAsText2(_filepath) {
|
|
69046
69168
|
return {
|
|
69047
69169
|
loader: "text"
|
|
@@ -69049,33 +69171,59 @@ async function loadAsText2(_filepath) {
|
|
|
69049
69171
|
// as well - its probably faster than us doing it in JS.
|
|
69050
69172
|
};
|
|
69051
69173
|
}
|
|
69052
|
-
async function loadAsJS2(filepath) {
|
|
69174
|
+
async function loadAsJS2(filepath, options) {
|
|
69053
69175
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69054
|
-
const contents = "export default " + import_pug.default.compileClient(fileData, {
|
|
69176
|
+
const contents = "export default " + import_pug.default.compileClient(fileData, {
|
|
69177
|
+
name: "render",
|
|
69178
|
+
filename: filepath,
|
|
69179
|
+
basedir: options.outbase
|
|
69180
|
+
});
|
|
69055
69181
|
return {
|
|
69056
69182
|
contents,
|
|
69057
69183
|
loader: "js"
|
|
69058
69184
|
};
|
|
69059
69185
|
}
|
|
69060
|
-
async function loadAsHtml(filepath) {
|
|
69186
|
+
async function loadAsHtml(filepath, options) {
|
|
69061
69187
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69062
|
-
const contents = import_pug.default.render(fileData, {
|
|
69188
|
+
const contents = import_pug.default.render(fileData, {
|
|
69189
|
+
name: "render",
|
|
69190
|
+
filename: filepath,
|
|
69191
|
+
basedir: options.outbase,
|
|
69192
|
+
plugins: [
|
|
69193
|
+
pugTransformer(isScriptNodeWithSrcAttr, (nodes) => {
|
|
69194
|
+
nodes;
|
|
69195
|
+
})
|
|
69196
|
+
]
|
|
69197
|
+
});
|
|
69063
69198
|
return {
|
|
69064
69199
|
contents,
|
|
69065
69200
|
loader: "js"
|
|
69066
69201
|
};
|
|
69067
69202
|
}
|
|
69068
|
-
async function
|
|
69203
|
+
async function loadAsEntrypoint(filepath, options) {
|
|
69069
69204
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69070
|
-
const contents = import_pug.default.render(fileData, {
|
|
69205
|
+
const contents = import_pug.default.render(fileData, {
|
|
69206
|
+
filename: filepath,
|
|
69207
|
+
basedir: options.outbase,
|
|
69208
|
+
name: "render",
|
|
69209
|
+
plugins: [
|
|
69210
|
+
pugTransformer(isScriptNodeWithSrcAttr, (nodes) => {
|
|
69211
|
+
nodes;
|
|
69212
|
+
})
|
|
69213
|
+
]
|
|
69214
|
+
});
|
|
69071
69215
|
return {
|
|
69072
69216
|
contents,
|
|
69073
69217
|
loader: "copy"
|
|
69074
69218
|
};
|
|
69075
69219
|
}
|
|
69076
|
-
async function loadAsFile(filepath) {
|
|
69220
|
+
async function loadAsFile(filepath, options) {
|
|
69077
69221
|
const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
|
|
69078
|
-
const contents = import_pug.default.render(fileData, {
|
|
69222
|
+
const contents = import_pug.default.render(fileData, {
|
|
69223
|
+
name: "render",
|
|
69224
|
+
filename: filepath,
|
|
69225
|
+
basedir: options.outbase
|
|
69226
|
+
});
|
|
69079
69227
|
return {
|
|
69080
69228
|
contents,
|
|
69081
69229
|
loader: "file"
|
|
@@ -69114,7 +69262,7 @@ var plugin2 = {
|
|
|
69114
69262
|
}) => {
|
|
69115
69263
|
const isEntryPoint = pluginData?.[name2]?.entrypoint;
|
|
69116
69264
|
if (isEntryPoint) {
|
|
69117
|
-
return
|
|
69265
|
+
return loadAsEntrypoint(filepath, build2.initialOptions);
|
|
69118
69266
|
}
|
|
69119
69267
|
const type = withArg?.["type"] ?? "js";
|
|
69120
69268
|
switch (type) {
|
|
@@ -69122,7 +69270,7 @@ var plugin2 = {
|
|
|
69122
69270
|
// This gives a string of the pug already rendered to html
|
|
69123
69271
|
// TODO: could support passing options to pug.render via the with clause
|
|
69124
69272
|
case "html":
|
|
69125
|
-
return loadAsHtml(filepath);
|
|
69273
|
+
return loadAsHtml(filepath, build2.initialOptions);
|
|
69126
69274
|
// Load pug as a text file by doing "import template from './file.pug' with { type: 'text' }"
|
|
69127
69275
|
// This gives a string of the raw pug file, which can be used as pug - e.g. as a template string
|
|
69128
69276
|
case "pug":
|
|
@@ -69131,12 +69279,12 @@ var plugin2 = {
|
|
|
69131
69279
|
// Load pug as a render function by doing "import render from './file.pug' with { type: 'js' }"
|
|
69132
69280
|
// This is the default behaviour if no with clause is used, or no type is specified.
|
|
69133
69281
|
case "js":
|
|
69134
|
-
return loadAsJS2(filepath);
|
|
69282
|
+
return loadAsJS2(filepath, build2.initialOptions);
|
|
69135
69283
|
// Load pug as a file by doing "import template from './file.pug' with { type: 'file' }"
|
|
69136
69284
|
// This will render the pug file to a file, and return the path to that file.
|
|
69137
69285
|
// The path is going to contain a hash, so it is not going to be the same as the original file.
|
|
69138
69286
|
case "file":
|
|
69139
|
-
return loadAsFile(filepath);
|
|
69287
|
+
return loadAsFile(filepath, build2.initialOptions);
|
|
69140
69288
|
// In the case that the type is not recognised, throw an error
|
|
69141
69289
|
default:
|
|
69142
69290
|
throw new Error(`Unsupported type: ${type}`);
|
|
@@ -69304,7 +69452,9 @@ var esbuilder = {
|
|
|
69304
69452
|
entryPoints: build2.map(({ infile }) => infile.absolute),
|
|
69305
69453
|
outdir,
|
|
69306
69454
|
outbase: indir,
|
|
69307
|
-
write: false
|
|
69455
|
+
write: false,
|
|
69456
|
+
logLevel: "silent"
|
|
69457
|
+
// TODO: add a specific variable for this
|
|
69308
69458
|
};
|
|
69309
69459
|
log_default.debug(
|
|
69310
69460
|
`Final config:`,
|
|
@@ -69315,6 +69465,13 @@ var esbuilder = {
|
|
|
69315
69465
|
)
|
|
69316
69466
|
);
|
|
69317
69467
|
const codeBuild = esbuild.build(finalConfig).then(async (result) => {
|
|
69468
|
+
if (result.errors.length || result.warnings.length) {
|
|
69469
|
+
log_default.info(`Build completed with errors or warnings:`, {
|
|
69470
|
+
errors: result.errors.length,
|
|
69471
|
+
warnings: result.warnings.length
|
|
69472
|
+
});
|
|
69473
|
+
throw result;
|
|
69474
|
+
}
|
|
69318
69475
|
log_default.debug(
|
|
69319
69476
|
`Got output files:`,
|
|
69320
69477
|
result.outputFiles.map((f) => import_path7.default.relative(outdir, f.path))
|
|
@@ -69383,6 +69540,20 @@ var esbuilder = {
|
|
|
69383
69540
|
}
|
|
69384
69541
|
}
|
|
69385
69542
|
await Promise.all(writers);
|
|
69543
|
+
}).catch((err) => {
|
|
69544
|
+
const errors = err.errors || [];
|
|
69545
|
+
const warnings = err.warnings || [];
|
|
69546
|
+
if (!errors.length && !warnings.length) {
|
|
69547
|
+
log_default.error(
|
|
69548
|
+
`Build failed with no errors or warnings, but an unknown error occurred.`
|
|
69549
|
+
);
|
|
69550
|
+
throw err;
|
|
69551
|
+
} else {
|
|
69552
|
+
log_default.error(
|
|
69553
|
+
`Build failed with ${errors.length} errors and ${warnings.length} warnings.`
|
|
69554
|
+
);
|
|
69555
|
+
throw [...errors, ...warnings];
|
|
69556
|
+
}
|
|
69386
69557
|
});
|
|
69387
69558
|
promises.push(codeBuild);
|
|
69388
69559
|
if (exampleFile.entryconfig.declarations) {
|
|
@@ -69409,6 +69580,18 @@ var esbuilder = {
|
|
|
69409
69580
|
}
|
|
69410
69581
|
await Promise.all(promises);
|
|
69411
69582
|
}
|
|
69583
|
+
return {
|
|
69584
|
+
// TODO: rewrite to return warnings
|
|
69585
|
+
warnings: [],
|
|
69586
|
+
// TODO: rewrite to return errors
|
|
69587
|
+
errors: [],
|
|
69588
|
+
watchFiles: entrypoints.map((e) => e.infile),
|
|
69589
|
+
watchDirs: [],
|
|
69590
|
+
// TODO: these are not the correct files
|
|
69591
|
+
producedFiles: entrypoints.map((e) => e.outfile),
|
|
69592
|
+
// TODO: rewrite to only return true if all builds were successful
|
|
69593
|
+
completed: true
|
|
69594
|
+
};
|
|
69412
69595
|
}
|
|
69413
69596
|
};
|
|
69414
69597
|
async function compileToTypeDeclarations(fileNames, options) {
|
|
@@ -70282,7 +70465,7 @@ async function getEntrypoints(buildConfig, manuallySpecified) {
|
|
|
70282
70465
|
}
|
|
70283
70466
|
|
|
70284
70467
|
// pnp:/builds/normed/bundle/packages/bundle/src/bundle.ts
|
|
70285
|
-
async function
|
|
70468
|
+
async function getBuildConfig(options) {
|
|
70286
70469
|
const buildConfig = {
|
|
70287
70470
|
dir: {
|
|
70288
70471
|
in: getInDir(options),
|
|
@@ -70396,125 +70579,116 @@ async function bundle(options = {}) {
|
|
|
70396
70579
|
"Build Config - post reading package.json",
|
|
70397
70580
|
JSON.stringify(buildConfig.baseConfig, null, 2)
|
|
70398
70581
|
);
|
|
70399
|
-
|
|
70400
|
-
|
|
70401
|
-
|
|
70402
|
-
|
|
70403
|
-
|
|
70404
|
-
|
|
70405
|
-
|
|
70406
|
-
|
|
70407
|
-
(e) => e.origin === "discovered" && e.infile.modifiers.includes("context")
|
|
70582
|
+
return buildConfig;
|
|
70583
|
+
}
|
|
70584
|
+
async function discoverEntrypoints(buildConfig, entrypoints, plugins = {}) {
|
|
70585
|
+
let initialEntrypoints = await getEntrypoints(buildConfig, entrypoints);
|
|
70586
|
+
initialEntrypoints = await plugins.initialEntrypoints?.(initialEntrypoints) ?? initialEntrypoints;
|
|
70587
|
+
const [missing, found] = divide(
|
|
70588
|
+
initialEntrypoints,
|
|
70589
|
+
(e) => e instanceof NoMatchingBuilder
|
|
70408
70590
|
);
|
|
70409
|
-
|
|
70410
|
-
|
|
70411
|
-
|
|
70412
|
-
|
|
70413
|
-
|
|
70414
|
-
|
|
70415
|
-
|
|
70416
|
-
|
|
70417
|
-
log_default.warn(` - skipping ${contextEntrypoint.infile.relative}`);
|
|
70418
|
-
return;
|
|
70419
|
-
}
|
|
70420
|
-
skippedContextFile = false;
|
|
70421
|
-
const matchingEntrypoints = entrypoints.filter(
|
|
70422
|
-
(e) => e.infile.bare === contextEntrypoint.infile.bare
|
|
70423
|
-
);
|
|
70424
|
-
if (!matchingEntrypoints.length) {
|
|
70425
|
-
log_default.warn(
|
|
70426
|
-
`Context file ${contextEntrypoint.infile.bare} is not used by any entrypoint`
|
|
70427
|
-
);
|
|
70428
|
-
return;
|
|
70429
|
-
}
|
|
70430
|
-
log_default.verbose(
|
|
70431
|
-
`Context file ${contextEntrypoint.infile.bare} is used by ${matchingEntrypoints.length} entrypoints`
|
|
70432
|
-
);
|
|
70433
|
-
async function compile(_v) {
|
|
70434
|
-
throw new Error("Function not implemented.");
|
|
70435
|
-
}
|
|
70436
|
-
const compiled = await compile(contextEntrypoint);
|
|
70437
|
-
const { context } = await compiled.run();
|
|
70438
|
-
if (!context) {
|
|
70439
|
-
log_default.warn(
|
|
70440
|
-
`Context file ${contextEntrypoint.infile.bare} did not export a context function`
|
|
70441
|
-
);
|
|
70442
|
-
return;
|
|
70443
|
-
}
|
|
70444
|
-
const contextResult = await context();
|
|
70445
|
-
if (!contextResult) {
|
|
70446
|
-
log_default.warn(
|
|
70447
|
-
`Context file ${contextEntrypoint.infile.bare} did not return a context object`
|
|
70448
|
-
);
|
|
70449
|
-
return;
|
|
70450
|
-
}
|
|
70451
|
-
const builderNames = matchingEntrypoints.map((e) => e.builder.name).filter((v, i, a) => a.indexOf(v) === i);
|
|
70452
|
-
const builderNamesWithContexts = builderNames.filter(
|
|
70453
|
-
(name3) => contextResult[name3]
|
|
70454
|
-
);
|
|
70455
|
-
if (!builderNamesWithContexts.length) {
|
|
70456
|
-
log_default.warn(
|
|
70457
|
-
`Context file ${contextEntrypoint.infile.bare} did not return any context for any of the builders: ${builderNames.join(", ")}`
|
|
70458
|
-
);
|
|
70459
|
-
return;
|
|
70460
|
-
}
|
|
70461
|
-
for (const builderName of builderNamesWithContexts) {
|
|
70462
|
-
await Promise.all(
|
|
70463
|
-
matchingEntrypoints.filter((e) => e.builder.name === builderName).map(async (entrypoint) => {
|
|
70464
|
-
const func = contextResult[builderName];
|
|
70465
|
-
if (!func) {
|
|
70466
|
-
log_default.warn(
|
|
70467
|
-
`Context file ${contextEntrypoint.infile.bare} did not return a context for builder ${builderName}`
|
|
70468
|
-
);
|
|
70469
|
-
return;
|
|
70470
|
-
}
|
|
70471
|
-
entrypoint.context = await func();
|
|
70472
|
-
})
|
|
70473
|
-
);
|
|
70591
|
+
if (missing.length) {
|
|
70592
|
+
const missingBuilders = missing.filter((v, i, a) => a.indexOf(v) === i);
|
|
70593
|
+
return WrappedErrors.fromErrors(
|
|
70594
|
+
missing,
|
|
70595
|
+
"Missing builders for entrypoints",
|
|
70596
|
+
{
|
|
70597
|
+
missingBuilders: missingBuilders.map((b) => b.name),
|
|
70598
|
+
missingBuilders_count: missingBuilders.length
|
|
70474
70599
|
}
|
|
70475
|
-
|
|
70600
|
+
);
|
|
70601
|
+
}
|
|
70602
|
+
return plugins.discoveredEntrypoints?.(found) ?? found;
|
|
70603
|
+
}
|
|
70604
|
+
async function bundle(options = {}, plugins = {}) {
|
|
70605
|
+
const start = Date.now();
|
|
70606
|
+
const buildConfig = await getBuildConfig(options);
|
|
70607
|
+
const entrypoints = await discoverEntrypoints(
|
|
70608
|
+
buildConfig,
|
|
70609
|
+
options.entrypoints,
|
|
70610
|
+
plugins
|
|
70476
70611
|
);
|
|
70477
|
-
|
|
70478
|
-
|
|
70479
|
-
|
|
70480
|
-
|
|
70481
|
-
if (!acc[index]) {
|
|
70482
|
-
acc[index] = [];
|
|
70483
|
-
}
|
|
70484
|
-
acc[index]?.push(entryPoint);
|
|
70485
|
-
return acc;
|
|
70486
|
-
}, []);
|
|
70487
|
-
for (const index in grouped) {
|
|
70488
|
-
const group = grouped[index];
|
|
70489
|
-
const builder = buildConfig.builders[index];
|
|
70490
|
-
if (!builder) {
|
|
70491
|
-
continue;
|
|
70492
|
-
}
|
|
70493
|
-
log_default.info(
|
|
70494
|
-
builder.color(
|
|
70495
|
-
`${builder.name}:
|
|
70496
|
-
${group?.map((i) => `${i.infile.relative} => ${i.outfile.relative}`).join("\n ")}`
|
|
70497
|
-
)
|
|
70612
|
+
if (entrypoints instanceof WrappedErrors) {
|
|
70613
|
+
return WrappedErrors.fromError(
|
|
70614
|
+
entrypoints,
|
|
70615
|
+
"Failed to discover entrypoints"
|
|
70498
70616
|
);
|
|
70499
70617
|
}
|
|
70500
|
-
|
|
70501
|
-
|
|
70502
|
-
|
|
70503
|
-
|
|
70504
|
-
|
|
70505
|
-
|
|
70506
|
-
|
|
70507
|
-
|
|
70508
|
-
|
|
70509
|
-
|
|
70510
|
-
|
|
70618
|
+
let grouped = keyBy(entrypoints, {
|
|
70619
|
+
builder: (entrypoint) => entrypoint.builder
|
|
70620
|
+
});
|
|
70621
|
+
grouped = await plugins.preBuild?.(grouped) ?? grouped;
|
|
70622
|
+
const results = await Promise.allSettled(
|
|
70623
|
+
Array.from(grouped.entries()).map(
|
|
70624
|
+
async ([
|
|
70625
|
+
{ builder },
|
|
70626
|
+
entrypoints2
|
|
70627
|
+
]) => {
|
|
70628
|
+
const start2 = Date.now();
|
|
70629
|
+
const annotations = {
|
|
70630
|
+
entrypoints: entrypoints2,
|
|
70631
|
+
builder,
|
|
70632
|
+
duration_ms: -1
|
|
70633
|
+
};
|
|
70634
|
+
let result;
|
|
70635
|
+
try {
|
|
70636
|
+
result = await builder.build(entrypoints2);
|
|
70637
|
+
} catch (e) {
|
|
70638
|
+
result = {
|
|
70639
|
+
warnings: [],
|
|
70640
|
+
errors: [WrappedErrors.fromValue(e, "Builder failed to build")],
|
|
70641
|
+
watchFiles: entrypoints2.map((e2) => e2.infile),
|
|
70642
|
+
watchDirs: [],
|
|
70643
|
+
producedFiles: [],
|
|
70644
|
+
completed: false
|
|
70645
|
+
};
|
|
70646
|
+
} finally {
|
|
70647
|
+
annotations.duration_ms = Date.now() - start2;
|
|
70511
70648
|
}
|
|
70512
|
-
|
|
70649
|
+
result = await plugins.postBuild?.(result, annotations) ?? result;
|
|
70650
|
+
return {
|
|
70651
|
+
...result,
|
|
70652
|
+
...annotations
|
|
70653
|
+
};
|
|
70654
|
+
}
|
|
70513
70655
|
)
|
|
70514
70656
|
);
|
|
70515
|
-
const
|
|
70516
|
-
|
|
70517
|
-
|
|
70657
|
+
const [rejected, fulfilled] = divide(
|
|
70658
|
+
results,
|
|
70659
|
+
(r) => r.status === "rejected"
|
|
70660
|
+
);
|
|
70661
|
+
const [uncompleted, completed] = divide(fulfilled, (r) => r.value.completed);
|
|
70662
|
+
const errorLogs = combineErrorLogs(
|
|
70663
|
+
...uncompleted.map((r) => r.value),
|
|
70664
|
+
...completed.map((r) => r.value)
|
|
70665
|
+
);
|
|
70666
|
+
const errors = [
|
|
70667
|
+
rejected.length ? WrappedErrors.fromValues(
|
|
70668
|
+
rejected.map((r) => r.reason),
|
|
70669
|
+
"Some builders encountered errors when running",
|
|
70670
|
+
{
|
|
70671
|
+
rejected_count: rejected.length,
|
|
70672
|
+
entrypoints: entrypoints.map((e) => e.infile.relative),
|
|
70673
|
+
builders: Array.from(grouped.keys()).map(
|
|
70674
|
+
({ builder }) => builder.name
|
|
70675
|
+
)
|
|
70676
|
+
}
|
|
70677
|
+
) : void 0,
|
|
70678
|
+
...errorLogs.errors ?? []
|
|
70679
|
+
];
|
|
70680
|
+
const warnings = errorLogs.warnings ?? [];
|
|
70681
|
+
return {
|
|
70682
|
+
completed: rejected.length === 0 && uncompleted.length === 0,
|
|
70683
|
+
errors: errors.filter(isNot.undefined),
|
|
70684
|
+
warnings,
|
|
70685
|
+
watchFiles: fulfilled.flatMap((r) => r.value.watchFiles),
|
|
70686
|
+
watchDirs: fulfilled.flatMap((r) => r.value.watchDirs),
|
|
70687
|
+
producedFiles: fulfilled.flatMap((r) => r.value.producedFiles),
|
|
70688
|
+
entrypoints,
|
|
70689
|
+
duration_ms: Date.now() - start,
|
|
70690
|
+
children: fulfilled.map((r) => r.value)
|
|
70691
|
+
};
|
|
70518
70692
|
}
|
|
70519
70693
|
|
|
70520
70694
|
// pnp:/builds/normed/bundle/packages/bundle/src/index.ts
|