@normed/bundle 4.6.1 → 4.6.3
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 +129 -2
- package/bundles/bin/cli.js.map +2 -2
- package/bundles/esbuild-plugins/load_pug.d.ts +16 -0
- package/bundles/index.js +129 -2
- package/bundles/index.js.map +2 -2
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@ 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.6.3
|
|
10
|
+
|
|
11
|
+
* PATCH: Fix JavaScript and TypeScript files referenced from `.static.pug` templates being copied verbatim instead of being bundled. Script files (`.js`, `.jsx`, `.mjs`, `.cjs`, `.ts`, `.tsx`) are now properly processed through esbuild, bundling imports and transpiling TypeScript, producing `.js` output with correct paths in the generated HTML.
|
|
12
|
+
|
|
9
13
|
# 4.6.1
|
|
10
14
|
|
|
11
15
|
* PATCH: Fix `pkg:` prefix to respect `assetNames` configuration. Package CSS files now correctly follow the configured output path (e.g., `assets/[name]-[hash]`) instead of being placed at the root.
|
package/bundles/bin/cli.js
CHANGED
|
@@ -69172,6 +69172,12 @@ function isPugReference(assetPath) {
|
|
|
69172
69172
|
function isLessReference(assetPath) {
|
|
69173
69173
|
return assetPath.endsWith(".less") && isRelativeAssetPath(assetPath);
|
|
69174
69174
|
}
|
|
69175
|
+
function isScriptReference(assetPath) {
|
|
69176
|
+
const scriptExtensions = [".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx"];
|
|
69177
|
+
const isScript = scriptExtensions.some((ext) => assetPath.endsWith(ext));
|
|
69178
|
+
const isDeclaration = assetPath.endsWith(".d.ts");
|
|
69179
|
+
return isScript && !isDeclaration && isRelativeAssetPath(assetPath);
|
|
69180
|
+
}
|
|
69175
69181
|
var PKG_PREFIX = "pkg:";
|
|
69176
69182
|
function isPackageReference(assetPath) {
|
|
69177
69183
|
return assetPath.startsWith(PKG_PREFIX);
|
|
@@ -69192,6 +69198,7 @@ function resolvePackagePath(packageSpecifier, fromFile) {
|
|
|
69192
69198
|
}
|
|
69193
69199
|
var discoveredPugReferences = /* @__PURE__ */ new Map();
|
|
69194
69200
|
var discoveredLessReferences = /* @__PURE__ */ new Map();
|
|
69201
|
+
var discoveredScriptReferences = /* @__PURE__ */ new Map();
|
|
69195
69202
|
var discoveredPackageCssReferences = /* @__PURE__ */ new Map();
|
|
69196
69203
|
function clearDiscoveredPugReferences() {
|
|
69197
69204
|
discoveredPugReferences.clear();
|
|
@@ -69199,6 +69206,9 @@ function clearDiscoveredPugReferences() {
|
|
|
69199
69206
|
function clearDiscoveredLessReferences() {
|
|
69200
69207
|
discoveredLessReferences.clear();
|
|
69201
69208
|
}
|
|
69209
|
+
function clearDiscoveredScriptReferences() {
|
|
69210
|
+
discoveredScriptReferences.clear();
|
|
69211
|
+
}
|
|
69202
69212
|
function clearDiscoveredPackageCssReferences() {
|
|
69203
69213
|
discoveredPackageCssReferences.clear();
|
|
69204
69214
|
}
|
|
@@ -69213,6 +69223,7 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69213
69223
|
const assets = [];
|
|
69214
69224
|
const pugReferences = [];
|
|
69215
69225
|
const lessReferences = [];
|
|
69226
|
+
const scriptReferences = [];
|
|
69216
69227
|
const packageCssReferences = [];
|
|
69217
69228
|
const assetNames = options2.assetNames || "[name]-[hash]";
|
|
69218
69229
|
const outdir = options2.outdir || ".";
|
|
@@ -69240,6 +69251,7 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69240
69251
|
}
|
|
69241
69252
|
const discoveredPugPaths = /* @__PURE__ */ new Set();
|
|
69242
69253
|
const discoveredLessPaths = /* @__PURE__ */ new Set();
|
|
69254
|
+
const discoveredScriptPaths = /* @__PURE__ */ new Set();
|
|
69243
69255
|
const discoveredPackageCssPaths = /* @__PURE__ */ new Set();
|
|
69244
69256
|
for (const { fullMatch, attr, value } of matches) {
|
|
69245
69257
|
let newValue = value;
|
|
@@ -69292,6 +69304,12 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69292
69304
|
discoveredLessPaths.add(absolutePath);
|
|
69293
69305
|
lessReferences.push({ originalHref: value, absolutePath });
|
|
69294
69306
|
}
|
|
69307
|
+
} else if (isScriptReference(value)) {
|
|
69308
|
+
const absolutePath = import_path5.default.resolve(pugDir, value);
|
|
69309
|
+
if (!discoveredScriptPaths.has(absolutePath)) {
|
|
69310
|
+
discoveredScriptPaths.add(absolutePath);
|
|
69311
|
+
scriptReferences.push({ originalHref: value, absolutePath });
|
|
69312
|
+
}
|
|
69295
69313
|
} else if (isPackageCssReference(value)) {
|
|
69296
69314
|
const packageSpecifier = getPackageSpecifier(value);
|
|
69297
69315
|
const absolutePath = resolvePackagePath(packageSpecifier, pugFilePath);
|
|
@@ -69344,6 +69362,7 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69344
69362
|
assets,
|
|
69345
69363
|
pugReferences,
|
|
69346
69364
|
lessReferences,
|
|
69365
|
+
scriptReferences,
|
|
69347
69366
|
packageCssReferences
|
|
69348
69367
|
};
|
|
69349
69368
|
}
|
|
@@ -69522,6 +69541,7 @@ async function loadAsEntrypoint(filepath, options2) {
|
|
|
69522
69541
|
assets,
|
|
69523
69542
|
pugReferences,
|
|
69524
69543
|
lessReferences,
|
|
69544
|
+
scriptReferences,
|
|
69525
69545
|
packageCssReferences
|
|
69526
69546
|
} = await processHtmlAssets(contents, filepath, options2);
|
|
69527
69547
|
contents = processedHtml;
|
|
@@ -69531,6 +69551,9 @@ async function loadAsEntrypoint(filepath, options2) {
|
|
|
69531
69551
|
if (lessReferences.length > 0) {
|
|
69532
69552
|
discoveredLessReferences.set(filepath, lessReferences);
|
|
69533
69553
|
}
|
|
69554
|
+
if (scriptReferences.length > 0) {
|
|
69555
|
+
discoveredScriptReferences.set(filepath, scriptReferences);
|
|
69556
|
+
}
|
|
69534
69557
|
if (packageCssReferences.length > 0) {
|
|
69535
69558
|
discoveredPackageCssReferences.set(filepath, packageCssReferences);
|
|
69536
69559
|
}
|
|
@@ -69807,6 +69830,18 @@ function rewritePackageCssReferencesInHtml(html, packageCssReferences, packageCs
|
|
|
69807
69830
|
}
|
|
69808
69831
|
return result;
|
|
69809
69832
|
}
|
|
69833
|
+
function rewriteScriptReferencesInHtml(html, scriptReferences, scriptToOutputPath, htmlOutputDir, outdir) {
|
|
69834
|
+
let result = html;
|
|
69835
|
+
for (const ref of scriptReferences) {
|
|
69836
|
+
const outputPath = scriptToOutputPath.get(ref.absolutePath);
|
|
69837
|
+
if (outputPath) {
|
|
69838
|
+
const absoluteOutputPath = import_path8.default.join(outdir, outputPath);
|
|
69839
|
+
const relativePath = import_path8.default.relative(htmlOutputDir, absoluteOutputPath);
|
|
69840
|
+
result = result.split(ref.originalHref).join(relativePath);
|
|
69841
|
+
}
|
|
69842
|
+
}
|
|
69843
|
+
return result;
|
|
69844
|
+
}
|
|
69810
69845
|
function outExt(inExt) {
|
|
69811
69846
|
if (inExt.match(/^((c|m)?sx?|tsx?)$/)) {
|
|
69812
69847
|
return "js";
|
|
@@ -69842,6 +69877,9 @@ var esbuilder = {
|
|
|
69842
69877
|
return "css";
|
|
69843
69878
|
}
|
|
69844
69879
|
return ext;
|
|
69880
|
+
}, isCssGeneratedAsset = function(filePath) {
|
|
69881
|
+
const ext = import_path8.default.extname(filePath).toLowerCase();
|
|
69882
|
+
return cssAssetExtensions.has(ext);
|
|
69845
69883
|
};
|
|
69846
69884
|
const exampleFile = build2[0];
|
|
69847
69885
|
if (!exampleFile) {
|
|
@@ -69913,17 +69951,43 @@ var esbuilder = {
|
|
|
69913
69951
|
);
|
|
69914
69952
|
clearDiscoveredPugReferences();
|
|
69915
69953
|
clearDiscoveredLessReferences();
|
|
69954
|
+
clearDiscoveredScriptReferences();
|
|
69916
69955
|
clearDiscoveredPackageCssReferences();
|
|
69917
69956
|
const pugHtmlOutputs = /* @__PURE__ */ new Map();
|
|
69918
69957
|
const pugToOutputPath = /* @__PURE__ */ new Map();
|
|
69919
69958
|
const lessToOutputPath = /* @__PURE__ */ new Map();
|
|
69959
|
+
const scriptToOutputPath = /* @__PURE__ */ new Map();
|
|
69920
69960
|
const packageCssToOutputPath = /* @__PURE__ */ new Map();
|
|
69921
69961
|
const processedPugFiles = /* @__PURE__ */ new Set();
|
|
69922
69962
|
const processedLessFiles = /* @__PURE__ */ new Set();
|
|
69963
|
+
const processedScriptFiles = /* @__PURE__ */ new Set();
|
|
69923
69964
|
const processedPackageCssFiles = /* @__PURE__ */ new Set();
|
|
69924
69965
|
const pendingPugFiles = [];
|
|
69925
69966
|
const pendingLessFiles = [];
|
|
69967
|
+
const pendingScriptFiles = [];
|
|
69926
69968
|
const pendingPackageCssFiles = [];
|
|
69969
|
+
const cssAssetExtensions = /* @__PURE__ */ new Set([
|
|
69970
|
+
".png",
|
|
69971
|
+
".jpg",
|
|
69972
|
+
".jpeg",
|
|
69973
|
+
".gif",
|
|
69974
|
+
".webp",
|
|
69975
|
+
".svg",
|
|
69976
|
+
".ico",
|
|
69977
|
+
".woff",
|
|
69978
|
+
".woff2",
|
|
69979
|
+
".ttf",
|
|
69980
|
+
".eot",
|
|
69981
|
+
".otf",
|
|
69982
|
+
".mp4",
|
|
69983
|
+
".webm",
|
|
69984
|
+
".ogg",
|
|
69985
|
+
".mp3",
|
|
69986
|
+
".wav",
|
|
69987
|
+
".flac",
|
|
69988
|
+
".aac",
|
|
69989
|
+
".avif"
|
|
69990
|
+
]);
|
|
69927
69991
|
const processOutputFiles = async (result, currentOutputFilesMap, isDiscoveredBuild) => {
|
|
69928
69992
|
if (result.errors.length || result.warnings.length) {
|
|
69929
69993
|
log_default.info(`Build completed with errors or warnings:`, {
|
|
@@ -69969,7 +70033,7 @@ var esbuilder = {
|
|
|
69969
70033
|
`Build artefact "${relativeFilePath}" was created but not expected.`
|
|
69970
70034
|
);
|
|
69971
70035
|
}
|
|
69972
|
-
} else if (!isDiscoveredBuild) {
|
|
70036
|
+
} else if (!isDiscoveredBuild && !isCssGeneratedAsset(relativeFilePath)) {
|
|
69973
70037
|
log_default.warn(
|
|
69974
70038
|
`Build artefact "${relativeFilePath}" was created but not expected.`
|
|
69975
70039
|
);
|
|
@@ -69984,6 +70048,7 @@ var esbuilder = {
|
|
|
69984
70048
|
if (isHtmlOutput && sourcePath) {
|
|
69985
70049
|
const pugRefs = discoveredPugReferences.get(sourcePath) || [];
|
|
69986
70050
|
const lessRefs = discoveredLessReferences.get(sourcePath) || [];
|
|
70051
|
+
const scriptRefs = discoveredScriptReferences.get(sourcePath) || [];
|
|
69987
70052
|
const packageCssRefs = discoveredPackageCssReferences.get(sourcePath) || [];
|
|
69988
70053
|
pugToOutputPath.set(sourcePath, relativeTarget);
|
|
69989
70054
|
for (const ref of pugRefs) {
|
|
@@ -70014,6 +70079,20 @@ var esbuilder = {
|
|
|
70014
70079
|
}
|
|
70015
70080
|
}
|
|
70016
70081
|
}
|
|
70082
|
+
for (const ref of scriptRefs) {
|
|
70083
|
+
if (!processedScriptFiles.has(ref.absolutePath) && !pendingScriptFiles.includes(ref.absolutePath)) {
|
|
70084
|
+
if (import_fs7.default.existsSync(ref.absolutePath)) {
|
|
70085
|
+
pendingScriptFiles.push(ref.absolutePath);
|
|
70086
|
+
log_default.debug(
|
|
70087
|
+
`Discovered script reference: ${ref.originalHref} -> ${ref.absolutePath}`
|
|
70088
|
+
);
|
|
70089
|
+
} else {
|
|
70090
|
+
log_default.warn(
|
|
70091
|
+
`Referenced script file not found: ${ref.originalHref} (resolved to ${ref.absolutePath})`
|
|
70092
|
+
);
|
|
70093
|
+
}
|
|
70094
|
+
}
|
|
70095
|
+
}
|
|
70017
70096
|
for (const ref of packageCssRefs) {
|
|
70018
70097
|
if (!processedPackageCssFiles.has(ref.absolutePath) && !pendingPackageCssFiles.includes(ref.absolutePath)) {
|
|
70019
70098
|
if (import_fs7.default.existsSync(ref.absolutePath)) {
|
|
@@ -70034,6 +70113,7 @@ var esbuilder = {
|
|
|
70034
70113
|
outputPath: import_path8.default.join(outdir, relativeTarget),
|
|
70035
70114
|
pugReferences: pugRefs,
|
|
70036
70115
|
lessReferences: lessRefs,
|
|
70116
|
+
scriptReferences: scriptRefs,
|
|
70037
70117
|
packageCssReferences: packageCssRefs
|
|
70038
70118
|
});
|
|
70039
70119
|
} else {
|
|
@@ -70157,6 +70237,44 @@ var esbuilder = {
|
|
|
70157
70237
|
}
|
|
70158
70238
|
}
|
|
70159
70239
|
}
|
|
70240
|
+
while (pendingScriptFiles.length > 0) {
|
|
70241
|
+
const batch = pendingScriptFiles.splice(0);
|
|
70242
|
+
const newEntryPoints = batch.filter(
|
|
70243
|
+
(f) => !processedScriptFiles.has(f)
|
|
70244
|
+
);
|
|
70245
|
+
if (newEntryPoints.length === 0) break;
|
|
70246
|
+
log_default.debug(
|
|
70247
|
+
`Building ${newEntryPoints.length} discovered script file(s):`,
|
|
70248
|
+
newEntryPoints
|
|
70249
|
+
);
|
|
70250
|
+
for (const scriptSourcePath of newEntryPoints) {
|
|
70251
|
+
processedScriptFiles.add(scriptSourcePath);
|
|
70252
|
+
const entryNames = finalConfig.assetNames?.replace("[ext]", "") || "[dir]/[name]-[hash]";
|
|
70253
|
+
const scriptConfig = {
|
|
70254
|
+
...finalConfig,
|
|
70255
|
+
entryPoints: [scriptSourcePath],
|
|
70256
|
+
entryNames,
|
|
70257
|
+
// Use minifyWhitespace to remove module boundary comments (// path/to/file.js)
|
|
70258
|
+
// These comments contain absolute paths that differ between machines,
|
|
70259
|
+
// causing non-deterministic content hashes. minifyWhitespace removes them
|
|
70260
|
+
// while preserving variable names for debugging.
|
|
70261
|
+
minifyWhitespace: true
|
|
70262
|
+
};
|
|
70263
|
+
const scriptResult = await esbuild.build(scriptConfig);
|
|
70264
|
+
for (const file of scriptResult.outputFiles) {
|
|
70265
|
+
const relativeFilePath = import_path8.default.relative(outdir, file.path);
|
|
70266
|
+
if (relativeFilePath.endsWith(".js")) {
|
|
70267
|
+
scriptToOutputPath.set(scriptSourcePath, relativeFilePath);
|
|
70268
|
+
log_default.debug(
|
|
70269
|
+
`Built script file: ${import_path8.default.relative(indir, scriptSourcePath)} -> ${relativeFilePath}`
|
|
70270
|
+
);
|
|
70271
|
+
}
|
|
70272
|
+
await fileWriter.writeFile(file.path, file.contents, {
|
|
70273
|
+
encoding: "utf-8"
|
|
70274
|
+
});
|
|
70275
|
+
}
|
|
70276
|
+
}
|
|
70277
|
+
}
|
|
70160
70278
|
while (pendingPackageCssFiles.length > 0) {
|
|
70161
70279
|
const batch = pendingPackageCssFiles.splice(0);
|
|
70162
70280
|
const newEntryPoints = batch.filter(
|
|
@@ -70191,7 +70309,7 @@ var esbuilder = {
|
|
|
70191
70309
|
}
|
|
70192
70310
|
}
|
|
70193
70311
|
log_default.debug(
|
|
70194
|
-
`Rewriting pug/less references in ${pugHtmlOutputs.size} HTML file(s)`
|
|
70312
|
+
`Rewriting pug/less/script references in ${pugHtmlOutputs.size} HTML file(s)`
|
|
70195
70313
|
);
|
|
70196
70314
|
const htmlWriters = [];
|
|
70197
70315
|
for (const [_sourcePath, output] of pugHtmlOutputs.entries()) {
|
|
@@ -70215,6 +70333,15 @@ var esbuilder = {
|
|
|
70215
70333
|
outdir
|
|
70216
70334
|
);
|
|
70217
70335
|
}
|
|
70336
|
+
if (output.scriptReferences.length > 0) {
|
|
70337
|
+
html = rewriteScriptReferencesInHtml(
|
|
70338
|
+
html,
|
|
70339
|
+
output.scriptReferences,
|
|
70340
|
+
scriptToOutputPath,
|
|
70341
|
+
htmlOutputDir,
|
|
70342
|
+
outdir
|
|
70343
|
+
);
|
|
70344
|
+
}
|
|
70218
70345
|
if (output.packageCssReferences.length > 0) {
|
|
70219
70346
|
html = rewritePackageCssReferencesInHtml(
|
|
70220
70347
|
html,
|