@normed/bundle 4.5.7 → 4.6.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 +4 -0
- package/bundles/bin/cli.js +178 -3
- package/bundles/bin/cli.js.map +3 -3
- package/bundles/esbuild-plugins/load_pug.d.ts +17 -0
- package/bundles/index.js +178 -3
- package/bundles/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -23,6 +23,19 @@ export declare const discoveredPugReferences: Map<string, DiscoveredPugReference
|
|
|
23
23
|
* This is populated during build and used by the builder to trigger sub-builds.
|
|
24
24
|
*/
|
|
25
25
|
export declare const discoveredLessReferences: Map<string, DiscoveredLessReference[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Discovered package CSS reference from HTML.
|
|
28
|
+
* Package CSS files need to go through esbuild's CSS pipeline to handle url() references.
|
|
29
|
+
*/
|
|
30
|
+
export interface DiscoveredPackageCssReference {
|
|
31
|
+
originalHref: string;
|
|
32
|
+
absolutePath: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Map of source pug file path to discovered package CSS references.
|
|
36
|
+
* This is populated during build and used by the builder to trigger CSS processing.
|
|
37
|
+
*/
|
|
38
|
+
export declare const discoveredPackageCssReferences: Map<string, DiscoveredPackageCssReference[]>;
|
|
26
39
|
/**
|
|
27
40
|
* Clear discovered pug references. Should be called before a new build.
|
|
28
41
|
*/
|
|
@@ -31,5 +44,9 @@ export declare function clearDiscoveredPugReferences(): void;
|
|
|
31
44
|
* Clear discovered less references. Should be called before a new build.
|
|
32
45
|
*/
|
|
33
46
|
export declare function clearDiscoveredLessReferences(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Clear discovered package CSS references. Should be called before a new build.
|
|
49
|
+
*/
|
|
50
|
+
export declare function clearDiscoveredPackageCssReferences(): void;
|
|
34
51
|
declare const plugin: esbuild.Plugin;
|
|
35
52
|
export default plugin;
|
package/bundles/index.js
CHANGED
|
@@ -69150,6 +69150,7 @@ var import_pug = __toESM(require_lib14());
|
|
|
69150
69150
|
var import_fs4 = __toESM(require("fs"));
|
|
69151
69151
|
var import_path5 = __toESM(require("path"));
|
|
69152
69152
|
var import_crypto = __toESM(require("crypto"));
|
|
69153
|
+
var import_module = require("module");
|
|
69153
69154
|
function computeContentHash(content) {
|
|
69154
69155
|
const hash = import_crypto.default.createHash("sha256").update(content).digest();
|
|
69155
69156
|
const num = hash.readUInt32BE(0);
|
|
@@ -69185,14 +69186,36 @@ function isPugReference(assetPath) {
|
|
|
69185
69186
|
function isLessReference(assetPath) {
|
|
69186
69187
|
return assetPath.endsWith(".less") && isRelativeAssetPath(assetPath);
|
|
69187
69188
|
}
|
|
69189
|
+
var PKG_PREFIX = "pkg:";
|
|
69190
|
+
function isPackageReference(assetPath) {
|
|
69191
|
+
return assetPath.startsWith(PKG_PREFIX);
|
|
69192
|
+
}
|
|
69193
|
+
function getPackageSpecifier(assetPath) {
|
|
69194
|
+
return assetPath.slice(PKG_PREFIX.length);
|
|
69195
|
+
}
|
|
69196
|
+
function isPackageCssReference(assetPath) {
|
|
69197
|
+
return isPackageReference(assetPath) && assetPath.endsWith(".css");
|
|
69198
|
+
}
|
|
69199
|
+
function resolvePackagePath(packageSpecifier, fromFile) {
|
|
69200
|
+
try {
|
|
69201
|
+
const require2 = (0, import_module.createRequire)(fromFile);
|
|
69202
|
+
return require2.resolve(packageSpecifier);
|
|
69203
|
+
} catch {
|
|
69204
|
+
return null;
|
|
69205
|
+
}
|
|
69206
|
+
}
|
|
69188
69207
|
var discoveredPugReferences = /* @__PURE__ */ new Map();
|
|
69189
69208
|
var discoveredLessReferences = /* @__PURE__ */ new Map();
|
|
69209
|
+
var discoveredPackageCssReferences = /* @__PURE__ */ new Map();
|
|
69190
69210
|
function clearDiscoveredPugReferences() {
|
|
69191
69211
|
discoveredPugReferences.clear();
|
|
69192
69212
|
}
|
|
69193
69213
|
function clearDiscoveredLessReferences() {
|
|
69194
69214
|
discoveredLessReferences.clear();
|
|
69195
69215
|
}
|
|
69216
|
+
function clearDiscoveredPackageCssReferences() {
|
|
69217
|
+
discoveredPackageCssReferences.clear();
|
|
69218
|
+
}
|
|
69196
69219
|
function applyAssetNamesTemplate(template, originalPath, hash, baseDir) {
|
|
69197
69220
|
const ext = import_path5.default.extname(originalPath).slice(1);
|
|
69198
69221
|
const name3 = import_path5.default.basename(originalPath, import_path5.default.extname(originalPath));
|
|
@@ -69204,6 +69227,7 @@ async function processHtmlAssets(html, pugFilePath, options) {
|
|
|
69204
69227
|
const assets = [];
|
|
69205
69228
|
const pugReferences = [];
|
|
69206
69229
|
const lessReferences = [];
|
|
69230
|
+
const packageCssReferences = [];
|
|
69207
69231
|
const assetNames = options.assetNames || "[name]-[hash]";
|
|
69208
69232
|
const outdir = options.outdir || ".";
|
|
69209
69233
|
const outbase = options.outbase || import_path5.default.dirname(pugFilePath);
|
|
@@ -69230,6 +69254,7 @@ async function processHtmlAssets(html, pugFilePath, options) {
|
|
|
69230
69254
|
}
|
|
69231
69255
|
const discoveredPugPaths = /* @__PURE__ */ new Set();
|
|
69232
69256
|
const discoveredLessPaths = /* @__PURE__ */ new Set();
|
|
69257
|
+
const discoveredPackageCssPaths = /* @__PURE__ */ new Set();
|
|
69233
69258
|
for (const { fullMatch, attr, value } of matches) {
|
|
69234
69259
|
let newValue = value;
|
|
69235
69260
|
if (attr === "srcset") {
|
|
@@ -69281,6 +69306,32 @@ async function processHtmlAssets(html, pugFilePath, options) {
|
|
|
69281
69306
|
discoveredLessPaths.add(absolutePath);
|
|
69282
69307
|
lessReferences.push({ originalHref: value, absolutePath });
|
|
69283
69308
|
}
|
|
69309
|
+
} else if (isPackageCssReference(value)) {
|
|
69310
|
+
const packageSpecifier = getPackageSpecifier(value);
|
|
69311
|
+
const absolutePath = resolvePackagePath(packageSpecifier, pugFilePath);
|
|
69312
|
+
if (absolutePath && !discoveredPackageCssPaths.has(absolutePath)) {
|
|
69313
|
+
discoveredPackageCssPaths.add(absolutePath);
|
|
69314
|
+
packageCssReferences.push({ originalHref: value, absolutePath });
|
|
69315
|
+
}
|
|
69316
|
+
} else if (isPackageReference(value)) {
|
|
69317
|
+
const packageSpecifier = getPackageSpecifier(value);
|
|
69318
|
+
const absolutePath = resolvePackagePath(packageSpecifier, pugFilePath);
|
|
69319
|
+
if (absolutePath) {
|
|
69320
|
+
const hashedPath = await processPackageAsset(
|
|
69321
|
+
absolutePath,
|
|
69322
|
+
packageSpecifier,
|
|
69323
|
+
pugFilePath,
|
|
69324
|
+
outdir,
|
|
69325
|
+
outbase,
|
|
69326
|
+
assetNames,
|
|
69327
|
+
publicPath,
|
|
69328
|
+
assets,
|
|
69329
|
+
processedAssets
|
|
69330
|
+
);
|
|
69331
|
+
if (hashedPath) {
|
|
69332
|
+
newValue = hashedPath;
|
|
69333
|
+
}
|
|
69334
|
+
}
|
|
69284
69335
|
} else if (isRelativeAssetPath(value)) {
|
|
69285
69336
|
const hashedPath = await processAsset(
|
|
69286
69337
|
value,
|
|
@@ -69302,7 +69353,13 @@ async function processHtmlAssets(html, pugFilePath, options) {
|
|
|
69302
69353
|
modifiedHtml = modifiedHtml.replace(fullMatch, newFullMatch);
|
|
69303
69354
|
}
|
|
69304
69355
|
}
|
|
69305
|
-
return {
|
|
69356
|
+
return {
|
|
69357
|
+
html: modifiedHtml,
|
|
69358
|
+
assets,
|
|
69359
|
+
pugReferences,
|
|
69360
|
+
lessReferences,
|
|
69361
|
+
packageCssReferences
|
|
69362
|
+
};
|
|
69306
69363
|
}
|
|
69307
69364
|
async function processAsset(assetPath, pugDir, pugFilePath, outdir, outbase, assetNames, publicPath, assets, processedAssets) {
|
|
69308
69365
|
const absoluteSource = import_path5.default.resolve(pugDir, assetPath);
|
|
@@ -69343,6 +69400,46 @@ async function processAsset(assetPath, pugDir, pugFilePath, outdir, outbase, ass
|
|
|
69343
69400
|
return null;
|
|
69344
69401
|
}
|
|
69345
69402
|
}
|
|
69403
|
+
async function processPackageAsset(absoluteSource, packageSpecifier, pugFilePath, outdir, outbase, assetNames, publicPath, assets, processedAssets) {
|
|
69404
|
+
if (processedAssets.has(absoluteSource)) {
|
|
69405
|
+
return processedAssets.get(absoluteSource);
|
|
69406
|
+
}
|
|
69407
|
+
if (!import_fs4.default.existsSync(absoluteSource)) {
|
|
69408
|
+
return null;
|
|
69409
|
+
}
|
|
69410
|
+
try {
|
|
69411
|
+
const content = await import_fs4.default.promises.readFile(absoluteSource);
|
|
69412
|
+
const hash = computeContentHash(content);
|
|
69413
|
+
const filename = import_path5.default.basename(packageSpecifier);
|
|
69414
|
+
const hashedFilename = applyAssetNamesTemplate(
|
|
69415
|
+
assetNames,
|
|
69416
|
+
filename,
|
|
69417
|
+
hash,
|
|
69418
|
+
""
|
|
69419
|
+
// No base dir for package assets
|
|
69420
|
+
);
|
|
69421
|
+
const absoluteOutput = import_path5.default.join(outdir, hashedFilename);
|
|
69422
|
+
const pugRelativeToOutbase = import_path5.default.relative(outbase, pugFilePath);
|
|
69423
|
+
const htmlOutputPath = import_path5.default.join(outdir, pugRelativeToOutbase);
|
|
69424
|
+
const htmlOutputDir = import_path5.default.dirname(htmlOutputPath);
|
|
69425
|
+
let htmlPath;
|
|
69426
|
+
if (publicPath) {
|
|
69427
|
+
htmlPath = publicPath.replace(/\/$/, "") + "/" + hashedFilename;
|
|
69428
|
+
} else {
|
|
69429
|
+
htmlPath = import_path5.default.relative(htmlOutputDir, absoluteOutput);
|
|
69430
|
+
}
|
|
69431
|
+
assets.push({
|
|
69432
|
+
originalPath: packageSpecifier,
|
|
69433
|
+
hashedPath: htmlPath,
|
|
69434
|
+
absoluteSource,
|
|
69435
|
+
absoluteOutput
|
|
69436
|
+
});
|
|
69437
|
+
processedAssets.set(absoluteSource, htmlPath);
|
|
69438
|
+
return htmlPath;
|
|
69439
|
+
} catch {
|
|
69440
|
+
return null;
|
|
69441
|
+
}
|
|
69442
|
+
}
|
|
69346
69443
|
async function copyAssets(assets) {
|
|
69347
69444
|
const written = /* @__PURE__ */ new Set();
|
|
69348
69445
|
for (const asset of assets) {
|
|
@@ -69437,7 +69534,8 @@ async function loadAsEntrypoint(filepath, options) {
|
|
|
69437
69534
|
html: processedHtml,
|
|
69438
69535
|
assets,
|
|
69439
69536
|
pugReferences,
|
|
69440
|
-
lessReferences
|
|
69537
|
+
lessReferences,
|
|
69538
|
+
packageCssReferences
|
|
69441
69539
|
} = await processHtmlAssets(contents, filepath, options);
|
|
69442
69540
|
contents = processedHtml;
|
|
69443
69541
|
if (pugReferences.length > 0) {
|
|
@@ -69446,6 +69544,9 @@ async function loadAsEntrypoint(filepath, options) {
|
|
|
69446
69544
|
if (lessReferences.length > 0) {
|
|
69447
69545
|
discoveredLessReferences.set(filepath, lessReferences);
|
|
69448
69546
|
}
|
|
69547
|
+
if (packageCssReferences.length > 0) {
|
|
69548
|
+
discoveredPackageCssReferences.set(filepath, packageCssReferences);
|
|
69549
|
+
}
|
|
69449
69550
|
if (assets.length > 0) {
|
|
69450
69551
|
await copyAssets(assets);
|
|
69451
69552
|
}
|
|
@@ -69707,6 +69808,18 @@ function rewriteLessReferencesInHtml(html, lessReferences, lessToOutputPath, htm
|
|
|
69707
69808
|
}
|
|
69708
69809
|
return result;
|
|
69709
69810
|
}
|
|
69811
|
+
function rewritePackageCssReferencesInHtml(html, packageCssReferences, packageCssToOutputPath, htmlOutputDir, outdir) {
|
|
69812
|
+
let result = html;
|
|
69813
|
+
for (const ref of packageCssReferences) {
|
|
69814
|
+
const outputPath = packageCssToOutputPath.get(ref.absolutePath);
|
|
69815
|
+
if (outputPath) {
|
|
69816
|
+
const absoluteOutputPath = import_path8.default.join(outdir, outputPath);
|
|
69817
|
+
const relativePath = import_path8.default.relative(htmlOutputDir, absoluteOutputPath);
|
|
69818
|
+
result = result.split(ref.originalHref).join(relativePath);
|
|
69819
|
+
}
|
|
69820
|
+
}
|
|
69821
|
+
return result;
|
|
69822
|
+
}
|
|
69710
69823
|
function outExt(inExt) {
|
|
69711
69824
|
if (inExt.match(/^((c|m)?sx?|tsx?)$/)) {
|
|
69712
69825
|
return "js";
|
|
@@ -69813,13 +69926,17 @@ var esbuilder = {
|
|
|
69813
69926
|
);
|
|
69814
69927
|
clearDiscoveredPugReferences();
|
|
69815
69928
|
clearDiscoveredLessReferences();
|
|
69929
|
+
clearDiscoveredPackageCssReferences();
|
|
69816
69930
|
const pugHtmlOutputs = /* @__PURE__ */ new Map();
|
|
69817
69931
|
const pugToOutputPath = /* @__PURE__ */ new Map();
|
|
69818
69932
|
const lessToOutputPath = /* @__PURE__ */ new Map();
|
|
69933
|
+
const packageCssToOutputPath = /* @__PURE__ */ new Map();
|
|
69819
69934
|
const processedPugFiles = /* @__PURE__ */ new Set();
|
|
69820
69935
|
const processedLessFiles = /* @__PURE__ */ new Set();
|
|
69936
|
+
const processedPackageCssFiles = /* @__PURE__ */ new Set();
|
|
69821
69937
|
const pendingPugFiles = [];
|
|
69822
69938
|
const pendingLessFiles = [];
|
|
69939
|
+
const pendingPackageCssFiles = [];
|
|
69823
69940
|
const processOutputFiles = async (result, currentOutputFilesMap, isDiscoveredBuild) => {
|
|
69824
69941
|
if (result.errors.length || result.warnings.length) {
|
|
69825
69942
|
log_default.info(`Build completed with errors or warnings:`, {
|
|
@@ -69880,6 +69997,7 @@ var esbuilder = {
|
|
|
69880
69997
|
if (isHtmlOutput && sourcePath) {
|
|
69881
69998
|
const pugRefs = discoveredPugReferences.get(sourcePath) || [];
|
|
69882
69999
|
const lessRefs = discoveredLessReferences.get(sourcePath) || [];
|
|
70000
|
+
const packageCssRefs = discoveredPackageCssReferences.get(sourcePath) || [];
|
|
69883
70001
|
pugToOutputPath.set(sourcePath, relativeTarget);
|
|
69884
70002
|
for (const ref of pugRefs) {
|
|
69885
70003
|
if (!processedPugFiles.has(ref.absolutePath) && !pendingPugFiles.includes(ref.absolutePath)) {
|
|
@@ -69909,12 +70027,27 @@ var esbuilder = {
|
|
|
69909
70027
|
}
|
|
69910
70028
|
}
|
|
69911
70029
|
}
|
|
70030
|
+
for (const ref of packageCssRefs) {
|
|
70031
|
+
if (!processedPackageCssFiles.has(ref.absolutePath) && !pendingPackageCssFiles.includes(ref.absolutePath)) {
|
|
70032
|
+
if (import_fs7.default.existsSync(ref.absolutePath)) {
|
|
70033
|
+
pendingPackageCssFiles.push(ref.absolutePath);
|
|
70034
|
+
log_default.debug(
|
|
70035
|
+
`Discovered package CSS reference: ${ref.originalHref} -> ${ref.absolutePath}`
|
|
70036
|
+
);
|
|
70037
|
+
} else {
|
|
70038
|
+
log_default.warn(
|
|
70039
|
+
`Referenced package CSS file not found: ${ref.originalHref} (resolved to ${ref.absolutePath})`
|
|
70040
|
+
);
|
|
70041
|
+
}
|
|
70042
|
+
}
|
|
70043
|
+
}
|
|
69912
70044
|
pugHtmlOutputs.set(sourcePath, {
|
|
69913
70045
|
content: file.text,
|
|
69914
70046
|
sourcePath,
|
|
69915
70047
|
outputPath: import_path8.default.join(outdir, relativeTarget),
|
|
69916
70048
|
pugReferences: pugRefs,
|
|
69917
|
-
lessReferences: lessRefs
|
|
70049
|
+
lessReferences: lessRefs,
|
|
70050
|
+
packageCssReferences: packageCssRefs
|
|
69918
70051
|
});
|
|
69919
70052
|
} else {
|
|
69920
70053
|
if (relativeTarget.endsWith(".css") && oFM_result?.entrypoint?.infile.extension === "less") {
|
|
@@ -70037,6 +70170,39 @@ var esbuilder = {
|
|
|
70037
70170
|
}
|
|
70038
70171
|
}
|
|
70039
70172
|
}
|
|
70173
|
+
while (pendingPackageCssFiles.length > 0) {
|
|
70174
|
+
const batch = pendingPackageCssFiles.splice(0);
|
|
70175
|
+
const newEntryPoints = batch.filter(
|
|
70176
|
+
(f) => !processedPackageCssFiles.has(f)
|
|
70177
|
+
);
|
|
70178
|
+
if (newEntryPoints.length === 0) break;
|
|
70179
|
+
log_default.debug(
|
|
70180
|
+
`Building ${newEntryPoints.length} discovered package CSS file(s):`,
|
|
70181
|
+
newEntryPoints
|
|
70182
|
+
);
|
|
70183
|
+
for (const cssSourcePath of newEntryPoints) {
|
|
70184
|
+
processedPackageCssFiles.add(cssSourcePath);
|
|
70185
|
+
const entryNames = "[name]-[hash]";
|
|
70186
|
+
const cssConfig = {
|
|
70187
|
+
...finalConfig,
|
|
70188
|
+
entryPoints: [cssSourcePath],
|
|
70189
|
+
entryNames
|
|
70190
|
+
};
|
|
70191
|
+
const cssResult = await esbuild.build(cssConfig);
|
|
70192
|
+
for (const file of cssResult.outputFiles) {
|
|
70193
|
+
const relativeFilePath = import_path8.default.relative(outdir, file.path);
|
|
70194
|
+
if (relativeFilePath.endsWith(".css")) {
|
|
70195
|
+
packageCssToOutputPath.set(cssSourcePath, relativeFilePath);
|
|
70196
|
+
log_default.debug(
|
|
70197
|
+
`Built package CSS file: ${cssSourcePath} -> ${relativeFilePath}`
|
|
70198
|
+
);
|
|
70199
|
+
}
|
|
70200
|
+
await fileWriter.writeFile(file.path, file.contents, {
|
|
70201
|
+
encoding: "utf-8"
|
|
70202
|
+
});
|
|
70203
|
+
}
|
|
70204
|
+
}
|
|
70205
|
+
}
|
|
70040
70206
|
log_default.debug(
|
|
70041
70207
|
`Rewriting pug/less references in ${pugHtmlOutputs.size} HTML file(s)`
|
|
70042
70208
|
);
|
|
@@ -70062,6 +70228,15 @@ var esbuilder = {
|
|
|
70062
70228
|
outdir
|
|
70063
70229
|
);
|
|
70064
70230
|
}
|
|
70231
|
+
if (output.packageCssReferences.length > 0) {
|
|
70232
|
+
html = rewritePackageCssReferencesInHtml(
|
|
70233
|
+
html,
|
|
70234
|
+
output.packageCssReferences,
|
|
70235
|
+
packageCssToOutputPath,
|
|
70236
|
+
htmlOutputDir,
|
|
70237
|
+
outdir
|
|
70238
|
+
);
|
|
70239
|
+
}
|
|
70065
70240
|
const promise = fileWriter.writeFile(output.outputPath, html, {
|
|
70066
70241
|
encoding: "utf-8"
|
|
70067
70242
|
});
|