@normed/bundle 4.5.7 → 4.6.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 +8 -0
- package/bundles/bin/cli.js +179 -3
- package/bundles/bin/cli.js.map +3 -3
- package/bundles/esbuild-plugins/load_pug.d.ts +17 -0
- package/bundles/index.js +179 -3
- package/bundles/index.js.map +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ 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.1
|
|
10
|
+
|
|
11
|
+
* 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.
|
|
12
|
+
|
|
13
|
+
# 4.6.0
|
|
14
|
+
|
|
15
|
+
* MINOR: Add `pkg:` prefix for referencing npm package files in pug templates. CSS files from packages (e.g., `pkg:normalize.css/normalize.css`) are processed through esbuild's CSS pipeline to properly handle `url()` references. Non-CSS files (JS, fonts, images) are copied with content hashing.
|
|
16
|
+
|
|
9
17
|
# 4.5.7
|
|
10
18
|
|
|
11
19
|
* PATCH: Fix assets referenced via `url()` in less files (fonts, images) not being output. Previously, only the CSS file was written but referenced assets were missing from the output directory.
|
package/bundles/bin/cli.js
CHANGED
|
@@ -69136,6 +69136,7 @@ var import_pug = __toESM(require_lib14());
|
|
|
69136
69136
|
var import_fs4 = __toESM(require("fs"));
|
|
69137
69137
|
var import_path5 = __toESM(require("path"));
|
|
69138
69138
|
var import_crypto = __toESM(require("crypto"));
|
|
69139
|
+
var import_module = require("module");
|
|
69139
69140
|
function computeContentHash(content) {
|
|
69140
69141
|
const hash = import_crypto.default.createHash("sha256").update(content).digest();
|
|
69141
69142
|
const num = hash.readUInt32BE(0);
|
|
@@ -69171,14 +69172,36 @@ function isPugReference(assetPath) {
|
|
|
69171
69172
|
function isLessReference(assetPath) {
|
|
69172
69173
|
return assetPath.endsWith(".less") && isRelativeAssetPath(assetPath);
|
|
69173
69174
|
}
|
|
69175
|
+
var PKG_PREFIX = "pkg:";
|
|
69176
|
+
function isPackageReference(assetPath) {
|
|
69177
|
+
return assetPath.startsWith(PKG_PREFIX);
|
|
69178
|
+
}
|
|
69179
|
+
function getPackageSpecifier(assetPath) {
|
|
69180
|
+
return assetPath.slice(PKG_PREFIX.length);
|
|
69181
|
+
}
|
|
69182
|
+
function isPackageCssReference(assetPath) {
|
|
69183
|
+
return isPackageReference(assetPath) && assetPath.endsWith(".css");
|
|
69184
|
+
}
|
|
69185
|
+
function resolvePackagePath(packageSpecifier, fromFile) {
|
|
69186
|
+
try {
|
|
69187
|
+
const require2 = (0, import_module.createRequire)(fromFile);
|
|
69188
|
+
return require2.resolve(packageSpecifier);
|
|
69189
|
+
} catch {
|
|
69190
|
+
return null;
|
|
69191
|
+
}
|
|
69192
|
+
}
|
|
69174
69193
|
var discoveredPugReferences = /* @__PURE__ */ new Map();
|
|
69175
69194
|
var discoveredLessReferences = /* @__PURE__ */ new Map();
|
|
69195
|
+
var discoveredPackageCssReferences = /* @__PURE__ */ new Map();
|
|
69176
69196
|
function clearDiscoveredPugReferences() {
|
|
69177
69197
|
discoveredPugReferences.clear();
|
|
69178
69198
|
}
|
|
69179
69199
|
function clearDiscoveredLessReferences() {
|
|
69180
69200
|
discoveredLessReferences.clear();
|
|
69181
69201
|
}
|
|
69202
|
+
function clearDiscoveredPackageCssReferences() {
|
|
69203
|
+
discoveredPackageCssReferences.clear();
|
|
69204
|
+
}
|
|
69182
69205
|
function applyAssetNamesTemplate(template, originalPath, hash, baseDir) {
|
|
69183
69206
|
const ext = import_path5.default.extname(originalPath).slice(1);
|
|
69184
69207
|
const name3 = import_path5.default.basename(originalPath, import_path5.default.extname(originalPath));
|
|
@@ -69190,6 +69213,7 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69190
69213
|
const assets = [];
|
|
69191
69214
|
const pugReferences = [];
|
|
69192
69215
|
const lessReferences = [];
|
|
69216
|
+
const packageCssReferences = [];
|
|
69193
69217
|
const assetNames = options2.assetNames || "[name]-[hash]";
|
|
69194
69218
|
const outdir = options2.outdir || ".";
|
|
69195
69219
|
const outbase = options2.outbase || import_path5.default.dirname(pugFilePath);
|
|
@@ -69216,6 +69240,7 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69216
69240
|
}
|
|
69217
69241
|
const discoveredPugPaths = /* @__PURE__ */ new Set();
|
|
69218
69242
|
const discoveredLessPaths = /* @__PURE__ */ new Set();
|
|
69243
|
+
const discoveredPackageCssPaths = /* @__PURE__ */ new Set();
|
|
69219
69244
|
for (const { fullMatch, attr, value } of matches) {
|
|
69220
69245
|
let newValue = value;
|
|
69221
69246
|
if (attr === "srcset") {
|
|
@@ -69267,6 +69292,32 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69267
69292
|
discoveredLessPaths.add(absolutePath);
|
|
69268
69293
|
lessReferences.push({ originalHref: value, absolutePath });
|
|
69269
69294
|
}
|
|
69295
|
+
} else if (isPackageCssReference(value)) {
|
|
69296
|
+
const packageSpecifier = getPackageSpecifier(value);
|
|
69297
|
+
const absolutePath = resolvePackagePath(packageSpecifier, pugFilePath);
|
|
69298
|
+
if (absolutePath && !discoveredPackageCssPaths.has(absolutePath)) {
|
|
69299
|
+
discoveredPackageCssPaths.add(absolutePath);
|
|
69300
|
+
packageCssReferences.push({ originalHref: value, absolutePath });
|
|
69301
|
+
}
|
|
69302
|
+
} else if (isPackageReference(value)) {
|
|
69303
|
+
const packageSpecifier = getPackageSpecifier(value);
|
|
69304
|
+
const absolutePath = resolvePackagePath(packageSpecifier, pugFilePath);
|
|
69305
|
+
if (absolutePath) {
|
|
69306
|
+
const hashedPath = await processPackageAsset(
|
|
69307
|
+
absolutePath,
|
|
69308
|
+
packageSpecifier,
|
|
69309
|
+
pugFilePath,
|
|
69310
|
+
outdir,
|
|
69311
|
+
outbase,
|
|
69312
|
+
assetNames,
|
|
69313
|
+
publicPath,
|
|
69314
|
+
assets,
|
|
69315
|
+
processedAssets
|
|
69316
|
+
);
|
|
69317
|
+
if (hashedPath) {
|
|
69318
|
+
newValue = hashedPath;
|
|
69319
|
+
}
|
|
69320
|
+
}
|
|
69270
69321
|
} else if (isRelativeAssetPath(value)) {
|
|
69271
69322
|
const hashedPath = await processAsset(
|
|
69272
69323
|
value,
|
|
@@ -69288,7 +69339,13 @@ async function processHtmlAssets(html, pugFilePath, options2) {
|
|
|
69288
69339
|
modifiedHtml = modifiedHtml.replace(fullMatch, newFullMatch);
|
|
69289
69340
|
}
|
|
69290
69341
|
}
|
|
69291
|
-
return {
|
|
69342
|
+
return {
|
|
69343
|
+
html: modifiedHtml,
|
|
69344
|
+
assets,
|
|
69345
|
+
pugReferences,
|
|
69346
|
+
lessReferences,
|
|
69347
|
+
packageCssReferences
|
|
69348
|
+
};
|
|
69292
69349
|
}
|
|
69293
69350
|
async function processAsset(assetPath, pugDir, pugFilePath, outdir, outbase, assetNames, publicPath, assets, processedAssets) {
|
|
69294
69351
|
const absoluteSource = import_path5.default.resolve(pugDir, assetPath);
|
|
@@ -69329,6 +69386,47 @@ async function processAsset(assetPath, pugDir, pugFilePath, outdir, outbase, ass
|
|
|
69329
69386
|
return null;
|
|
69330
69387
|
}
|
|
69331
69388
|
}
|
|
69389
|
+
async function processPackageAsset(absoluteSource, packageSpecifier, pugFilePath, outdir, outbase, assetNames, publicPath, assets, processedAssets) {
|
|
69390
|
+
if (processedAssets.has(absoluteSource)) {
|
|
69391
|
+
return processedAssets.get(absoluteSource);
|
|
69392
|
+
}
|
|
69393
|
+
if (!import_fs4.default.existsSync(absoluteSource)) {
|
|
69394
|
+
return null;
|
|
69395
|
+
}
|
|
69396
|
+
try {
|
|
69397
|
+
const content = await import_fs4.default.promises.readFile(absoluteSource);
|
|
69398
|
+
const hash = computeContentHash(content);
|
|
69399
|
+
const filename = import_path5.default.basename(packageSpecifier);
|
|
69400
|
+
const packageAssetNames = assetNames.replace(/\[dir\]\/?/g, "");
|
|
69401
|
+
const hashedFilename = applyAssetNamesTemplate(
|
|
69402
|
+
packageAssetNames,
|
|
69403
|
+
filename,
|
|
69404
|
+
hash,
|
|
69405
|
+
""
|
|
69406
|
+
// No base dir for package assets
|
|
69407
|
+
);
|
|
69408
|
+
const absoluteOutput = import_path5.default.join(outdir, hashedFilename);
|
|
69409
|
+
const pugRelativeToOutbase = import_path5.default.relative(outbase, pugFilePath);
|
|
69410
|
+
const htmlOutputPath = import_path5.default.join(outdir, pugRelativeToOutbase);
|
|
69411
|
+
const htmlOutputDir = import_path5.default.dirname(htmlOutputPath);
|
|
69412
|
+
let htmlPath;
|
|
69413
|
+
if (publicPath) {
|
|
69414
|
+
htmlPath = publicPath.replace(/\/$/, "") + "/" + hashedFilename;
|
|
69415
|
+
} else {
|
|
69416
|
+
htmlPath = import_path5.default.relative(htmlOutputDir, absoluteOutput);
|
|
69417
|
+
}
|
|
69418
|
+
assets.push({
|
|
69419
|
+
originalPath: packageSpecifier,
|
|
69420
|
+
hashedPath: htmlPath,
|
|
69421
|
+
absoluteSource,
|
|
69422
|
+
absoluteOutput
|
|
69423
|
+
});
|
|
69424
|
+
processedAssets.set(absoluteSource, htmlPath);
|
|
69425
|
+
return htmlPath;
|
|
69426
|
+
} catch {
|
|
69427
|
+
return null;
|
|
69428
|
+
}
|
|
69429
|
+
}
|
|
69332
69430
|
async function copyAssets(assets) {
|
|
69333
69431
|
const written = /* @__PURE__ */ new Set();
|
|
69334
69432
|
for (const asset of assets) {
|
|
@@ -69423,7 +69521,8 @@ async function loadAsEntrypoint(filepath, options2) {
|
|
|
69423
69521
|
html: processedHtml,
|
|
69424
69522
|
assets,
|
|
69425
69523
|
pugReferences,
|
|
69426
|
-
lessReferences
|
|
69524
|
+
lessReferences,
|
|
69525
|
+
packageCssReferences
|
|
69427
69526
|
} = await processHtmlAssets(contents, filepath, options2);
|
|
69428
69527
|
contents = processedHtml;
|
|
69429
69528
|
if (pugReferences.length > 0) {
|
|
@@ -69432,6 +69531,9 @@ async function loadAsEntrypoint(filepath, options2) {
|
|
|
69432
69531
|
if (lessReferences.length > 0) {
|
|
69433
69532
|
discoveredLessReferences.set(filepath, lessReferences);
|
|
69434
69533
|
}
|
|
69534
|
+
if (packageCssReferences.length > 0) {
|
|
69535
|
+
discoveredPackageCssReferences.set(filepath, packageCssReferences);
|
|
69536
|
+
}
|
|
69435
69537
|
if (assets.length > 0) {
|
|
69436
69538
|
await copyAssets(assets);
|
|
69437
69539
|
}
|
|
@@ -69693,6 +69795,18 @@ function rewriteLessReferencesInHtml(html, lessReferences, lessToOutputPath, htm
|
|
|
69693
69795
|
}
|
|
69694
69796
|
return result;
|
|
69695
69797
|
}
|
|
69798
|
+
function rewritePackageCssReferencesInHtml(html, packageCssReferences, packageCssToOutputPath, htmlOutputDir, outdir) {
|
|
69799
|
+
let result = html;
|
|
69800
|
+
for (const ref of packageCssReferences) {
|
|
69801
|
+
const outputPath = packageCssToOutputPath.get(ref.absolutePath);
|
|
69802
|
+
if (outputPath) {
|
|
69803
|
+
const absoluteOutputPath = import_path8.default.join(outdir, outputPath);
|
|
69804
|
+
const relativePath = import_path8.default.relative(htmlOutputDir, absoluteOutputPath);
|
|
69805
|
+
result = result.split(ref.originalHref).join(relativePath);
|
|
69806
|
+
}
|
|
69807
|
+
}
|
|
69808
|
+
return result;
|
|
69809
|
+
}
|
|
69696
69810
|
function outExt(inExt) {
|
|
69697
69811
|
if (inExt.match(/^((c|m)?sx?|tsx?)$/)) {
|
|
69698
69812
|
return "js";
|
|
@@ -69799,13 +69913,17 @@ var esbuilder = {
|
|
|
69799
69913
|
);
|
|
69800
69914
|
clearDiscoveredPugReferences();
|
|
69801
69915
|
clearDiscoveredLessReferences();
|
|
69916
|
+
clearDiscoveredPackageCssReferences();
|
|
69802
69917
|
const pugHtmlOutputs = /* @__PURE__ */ new Map();
|
|
69803
69918
|
const pugToOutputPath = /* @__PURE__ */ new Map();
|
|
69804
69919
|
const lessToOutputPath = /* @__PURE__ */ new Map();
|
|
69920
|
+
const packageCssToOutputPath = /* @__PURE__ */ new Map();
|
|
69805
69921
|
const processedPugFiles = /* @__PURE__ */ new Set();
|
|
69806
69922
|
const processedLessFiles = /* @__PURE__ */ new Set();
|
|
69923
|
+
const processedPackageCssFiles = /* @__PURE__ */ new Set();
|
|
69807
69924
|
const pendingPugFiles = [];
|
|
69808
69925
|
const pendingLessFiles = [];
|
|
69926
|
+
const pendingPackageCssFiles = [];
|
|
69809
69927
|
const processOutputFiles = async (result, currentOutputFilesMap, isDiscoveredBuild) => {
|
|
69810
69928
|
if (result.errors.length || result.warnings.length) {
|
|
69811
69929
|
log_default.info(`Build completed with errors or warnings:`, {
|
|
@@ -69866,6 +69984,7 @@ var esbuilder = {
|
|
|
69866
69984
|
if (isHtmlOutput && sourcePath) {
|
|
69867
69985
|
const pugRefs = discoveredPugReferences.get(sourcePath) || [];
|
|
69868
69986
|
const lessRefs = discoveredLessReferences.get(sourcePath) || [];
|
|
69987
|
+
const packageCssRefs = discoveredPackageCssReferences.get(sourcePath) || [];
|
|
69869
69988
|
pugToOutputPath.set(sourcePath, relativeTarget);
|
|
69870
69989
|
for (const ref of pugRefs) {
|
|
69871
69990
|
if (!processedPugFiles.has(ref.absolutePath) && !pendingPugFiles.includes(ref.absolutePath)) {
|
|
@@ -69895,12 +70014,27 @@ var esbuilder = {
|
|
|
69895
70014
|
}
|
|
69896
70015
|
}
|
|
69897
70016
|
}
|
|
70017
|
+
for (const ref of packageCssRefs) {
|
|
70018
|
+
if (!processedPackageCssFiles.has(ref.absolutePath) && !pendingPackageCssFiles.includes(ref.absolutePath)) {
|
|
70019
|
+
if (import_fs7.default.existsSync(ref.absolutePath)) {
|
|
70020
|
+
pendingPackageCssFiles.push(ref.absolutePath);
|
|
70021
|
+
log_default.debug(
|
|
70022
|
+
`Discovered package CSS reference: ${ref.originalHref} -> ${ref.absolutePath}`
|
|
70023
|
+
);
|
|
70024
|
+
} else {
|
|
70025
|
+
log_default.warn(
|
|
70026
|
+
`Referenced package CSS file not found: ${ref.originalHref} (resolved to ${ref.absolutePath})`
|
|
70027
|
+
);
|
|
70028
|
+
}
|
|
70029
|
+
}
|
|
70030
|
+
}
|
|
69898
70031
|
pugHtmlOutputs.set(sourcePath, {
|
|
69899
70032
|
content: file.text,
|
|
69900
70033
|
sourcePath,
|
|
69901
70034
|
outputPath: import_path8.default.join(outdir, relativeTarget),
|
|
69902
70035
|
pugReferences: pugRefs,
|
|
69903
|
-
lessReferences: lessRefs
|
|
70036
|
+
lessReferences: lessRefs,
|
|
70037
|
+
packageCssReferences: packageCssRefs
|
|
69904
70038
|
});
|
|
69905
70039
|
} else {
|
|
69906
70040
|
if (relativeTarget.endsWith(".css") && oFM_result?.entrypoint?.infile.extension === "less") {
|
|
@@ -70023,6 +70157,39 @@ var esbuilder = {
|
|
|
70023
70157
|
}
|
|
70024
70158
|
}
|
|
70025
70159
|
}
|
|
70160
|
+
while (pendingPackageCssFiles.length > 0) {
|
|
70161
|
+
const batch = pendingPackageCssFiles.splice(0);
|
|
70162
|
+
const newEntryPoints = batch.filter(
|
|
70163
|
+
(f) => !processedPackageCssFiles.has(f)
|
|
70164
|
+
);
|
|
70165
|
+
if (newEntryPoints.length === 0) break;
|
|
70166
|
+
log_default.debug(
|
|
70167
|
+
`Building ${newEntryPoints.length} discovered package CSS file(s):`,
|
|
70168
|
+
newEntryPoints
|
|
70169
|
+
);
|
|
70170
|
+
for (const cssSourcePath of newEntryPoints) {
|
|
70171
|
+
processedPackageCssFiles.add(cssSourcePath);
|
|
70172
|
+
const entryNames = (finalConfig.assetNames?.replace("[ext]", "") || "[name]-[hash]").replace(/\[dir\]\/?/g, "");
|
|
70173
|
+
const cssConfig = {
|
|
70174
|
+
...finalConfig,
|
|
70175
|
+
entryPoints: [cssSourcePath],
|
|
70176
|
+
entryNames
|
|
70177
|
+
};
|
|
70178
|
+
const cssResult = await esbuild.build(cssConfig);
|
|
70179
|
+
for (const file of cssResult.outputFiles) {
|
|
70180
|
+
const relativeFilePath = import_path8.default.relative(outdir, file.path);
|
|
70181
|
+
if (relativeFilePath.endsWith(".css")) {
|
|
70182
|
+
packageCssToOutputPath.set(cssSourcePath, relativeFilePath);
|
|
70183
|
+
log_default.debug(
|
|
70184
|
+
`Built package CSS file: ${cssSourcePath} -> ${relativeFilePath}`
|
|
70185
|
+
);
|
|
70186
|
+
}
|
|
70187
|
+
await fileWriter.writeFile(file.path, file.contents, {
|
|
70188
|
+
encoding: "utf-8"
|
|
70189
|
+
});
|
|
70190
|
+
}
|
|
70191
|
+
}
|
|
70192
|
+
}
|
|
70026
70193
|
log_default.debug(
|
|
70027
70194
|
`Rewriting pug/less references in ${pugHtmlOutputs.size} HTML file(s)`
|
|
70028
70195
|
);
|
|
@@ -70048,6 +70215,15 @@ var esbuilder = {
|
|
|
70048
70215
|
outdir
|
|
70049
70216
|
);
|
|
70050
70217
|
}
|
|
70218
|
+
if (output.packageCssReferences.length > 0) {
|
|
70219
|
+
html = rewritePackageCssReferencesInHtml(
|
|
70220
|
+
html,
|
|
70221
|
+
output.packageCssReferences,
|
|
70222
|
+
packageCssToOutputPath,
|
|
70223
|
+
htmlOutputDir,
|
|
70224
|
+
outdir
|
|
70225
|
+
);
|
|
70226
|
+
}
|
|
70051
70227
|
const promise = fileWriter.writeFile(output.outputPath, html, {
|
|
70052
70228
|
encoding: "utf-8"
|
|
70053
70229
|
});
|