@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
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.0
|
|
10
|
+
|
|
11
|
+
* 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.
|
|
12
|
+
|
|
9
13
|
# 4.5.7
|
|
10
14
|
|
|
11
15
|
* 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,46 @@ 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 hashedFilename = applyAssetNamesTemplate(
|
|
69401
|
+
assetNames,
|
|
69402
|
+
filename,
|
|
69403
|
+
hash,
|
|
69404
|
+
""
|
|
69405
|
+
// No base dir for package assets
|
|
69406
|
+
);
|
|
69407
|
+
const absoluteOutput = import_path5.default.join(outdir, hashedFilename);
|
|
69408
|
+
const pugRelativeToOutbase = import_path5.default.relative(outbase, pugFilePath);
|
|
69409
|
+
const htmlOutputPath = import_path5.default.join(outdir, pugRelativeToOutbase);
|
|
69410
|
+
const htmlOutputDir = import_path5.default.dirname(htmlOutputPath);
|
|
69411
|
+
let htmlPath;
|
|
69412
|
+
if (publicPath) {
|
|
69413
|
+
htmlPath = publicPath.replace(/\/$/, "") + "/" + hashedFilename;
|
|
69414
|
+
} else {
|
|
69415
|
+
htmlPath = import_path5.default.relative(htmlOutputDir, absoluteOutput);
|
|
69416
|
+
}
|
|
69417
|
+
assets.push({
|
|
69418
|
+
originalPath: packageSpecifier,
|
|
69419
|
+
hashedPath: htmlPath,
|
|
69420
|
+
absoluteSource,
|
|
69421
|
+
absoluteOutput
|
|
69422
|
+
});
|
|
69423
|
+
processedAssets.set(absoluteSource, htmlPath);
|
|
69424
|
+
return htmlPath;
|
|
69425
|
+
} catch {
|
|
69426
|
+
return null;
|
|
69427
|
+
}
|
|
69428
|
+
}
|
|
69332
69429
|
async function copyAssets(assets) {
|
|
69333
69430
|
const written = /* @__PURE__ */ new Set();
|
|
69334
69431
|
for (const asset of assets) {
|
|
@@ -69423,7 +69520,8 @@ async function loadAsEntrypoint(filepath, options2) {
|
|
|
69423
69520
|
html: processedHtml,
|
|
69424
69521
|
assets,
|
|
69425
69522
|
pugReferences,
|
|
69426
|
-
lessReferences
|
|
69523
|
+
lessReferences,
|
|
69524
|
+
packageCssReferences
|
|
69427
69525
|
} = await processHtmlAssets(contents, filepath, options2);
|
|
69428
69526
|
contents = processedHtml;
|
|
69429
69527
|
if (pugReferences.length > 0) {
|
|
@@ -69432,6 +69530,9 @@ async function loadAsEntrypoint(filepath, options2) {
|
|
|
69432
69530
|
if (lessReferences.length > 0) {
|
|
69433
69531
|
discoveredLessReferences.set(filepath, lessReferences);
|
|
69434
69532
|
}
|
|
69533
|
+
if (packageCssReferences.length > 0) {
|
|
69534
|
+
discoveredPackageCssReferences.set(filepath, packageCssReferences);
|
|
69535
|
+
}
|
|
69435
69536
|
if (assets.length > 0) {
|
|
69436
69537
|
await copyAssets(assets);
|
|
69437
69538
|
}
|
|
@@ -69693,6 +69794,18 @@ function rewriteLessReferencesInHtml(html, lessReferences, lessToOutputPath, htm
|
|
|
69693
69794
|
}
|
|
69694
69795
|
return result;
|
|
69695
69796
|
}
|
|
69797
|
+
function rewritePackageCssReferencesInHtml(html, packageCssReferences, packageCssToOutputPath, htmlOutputDir, outdir) {
|
|
69798
|
+
let result = html;
|
|
69799
|
+
for (const ref of packageCssReferences) {
|
|
69800
|
+
const outputPath = packageCssToOutputPath.get(ref.absolutePath);
|
|
69801
|
+
if (outputPath) {
|
|
69802
|
+
const absoluteOutputPath = import_path8.default.join(outdir, outputPath);
|
|
69803
|
+
const relativePath = import_path8.default.relative(htmlOutputDir, absoluteOutputPath);
|
|
69804
|
+
result = result.split(ref.originalHref).join(relativePath);
|
|
69805
|
+
}
|
|
69806
|
+
}
|
|
69807
|
+
return result;
|
|
69808
|
+
}
|
|
69696
69809
|
function outExt(inExt) {
|
|
69697
69810
|
if (inExt.match(/^((c|m)?sx?|tsx?)$/)) {
|
|
69698
69811
|
return "js";
|
|
@@ -69799,13 +69912,17 @@ var esbuilder = {
|
|
|
69799
69912
|
);
|
|
69800
69913
|
clearDiscoveredPugReferences();
|
|
69801
69914
|
clearDiscoveredLessReferences();
|
|
69915
|
+
clearDiscoveredPackageCssReferences();
|
|
69802
69916
|
const pugHtmlOutputs = /* @__PURE__ */ new Map();
|
|
69803
69917
|
const pugToOutputPath = /* @__PURE__ */ new Map();
|
|
69804
69918
|
const lessToOutputPath = /* @__PURE__ */ new Map();
|
|
69919
|
+
const packageCssToOutputPath = /* @__PURE__ */ new Map();
|
|
69805
69920
|
const processedPugFiles = /* @__PURE__ */ new Set();
|
|
69806
69921
|
const processedLessFiles = /* @__PURE__ */ new Set();
|
|
69922
|
+
const processedPackageCssFiles = /* @__PURE__ */ new Set();
|
|
69807
69923
|
const pendingPugFiles = [];
|
|
69808
69924
|
const pendingLessFiles = [];
|
|
69925
|
+
const pendingPackageCssFiles = [];
|
|
69809
69926
|
const processOutputFiles = async (result, currentOutputFilesMap, isDiscoveredBuild) => {
|
|
69810
69927
|
if (result.errors.length || result.warnings.length) {
|
|
69811
69928
|
log_default.info(`Build completed with errors or warnings:`, {
|
|
@@ -69866,6 +69983,7 @@ var esbuilder = {
|
|
|
69866
69983
|
if (isHtmlOutput && sourcePath) {
|
|
69867
69984
|
const pugRefs = discoveredPugReferences.get(sourcePath) || [];
|
|
69868
69985
|
const lessRefs = discoveredLessReferences.get(sourcePath) || [];
|
|
69986
|
+
const packageCssRefs = discoveredPackageCssReferences.get(sourcePath) || [];
|
|
69869
69987
|
pugToOutputPath.set(sourcePath, relativeTarget);
|
|
69870
69988
|
for (const ref of pugRefs) {
|
|
69871
69989
|
if (!processedPugFiles.has(ref.absolutePath) && !pendingPugFiles.includes(ref.absolutePath)) {
|
|
@@ -69895,12 +70013,27 @@ var esbuilder = {
|
|
|
69895
70013
|
}
|
|
69896
70014
|
}
|
|
69897
70015
|
}
|
|
70016
|
+
for (const ref of packageCssRefs) {
|
|
70017
|
+
if (!processedPackageCssFiles.has(ref.absolutePath) && !pendingPackageCssFiles.includes(ref.absolutePath)) {
|
|
70018
|
+
if (import_fs7.default.existsSync(ref.absolutePath)) {
|
|
70019
|
+
pendingPackageCssFiles.push(ref.absolutePath);
|
|
70020
|
+
log_default.debug(
|
|
70021
|
+
`Discovered package CSS reference: ${ref.originalHref} -> ${ref.absolutePath}`
|
|
70022
|
+
);
|
|
70023
|
+
} else {
|
|
70024
|
+
log_default.warn(
|
|
70025
|
+
`Referenced package CSS file not found: ${ref.originalHref} (resolved to ${ref.absolutePath})`
|
|
70026
|
+
);
|
|
70027
|
+
}
|
|
70028
|
+
}
|
|
70029
|
+
}
|
|
69898
70030
|
pugHtmlOutputs.set(sourcePath, {
|
|
69899
70031
|
content: file.text,
|
|
69900
70032
|
sourcePath,
|
|
69901
70033
|
outputPath: import_path8.default.join(outdir, relativeTarget),
|
|
69902
70034
|
pugReferences: pugRefs,
|
|
69903
|
-
lessReferences: lessRefs
|
|
70035
|
+
lessReferences: lessRefs,
|
|
70036
|
+
packageCssReferences: packageCssRefs
|
|
69904
70037
|
});
|
|
69905
70038
|
} else {
|
|
69906
70039
|
if (relativeTarget.endsWith(".css") && oFM_result?.entrypoint?.infile.extension === "less") {
|
|
@@ -70023,6 +70156,39 @@ var esbuilder = {
|
|
|
70023
70156
|
}
|
|
70024
70157
|
}
|
|
70025
70158
|
}
|
|
70159
|
+
while (pendingPackageCssFiles.length > 0) {
|
|
70160
|
+
const batch = pendingPackageCssFiles.splice(0);
|
|
70161
|
+
const newEntryPoints = batch.filter(
|
|
70162
|
+
(f) => !processedPackageCssFiles.has(f)
|
|
70163
|
+
);
|
|
70164
|
+
if (newEntryPoints.length === 0) break;
|
|
70165
|
+
log_default.debug(
|
|
70166
|
+
`Building ${newEntryPoints.length} discovered package CSS file(s):`,
|
|
70167
|
+
newEntryPoints
|
|
70168
|
+
);
|
|
70169
|
+
for (const cssSourcePath of newEntryPoints) {
|
|
70170
|
+
processedPackageCssFiles.add(cssSourcePath);
|
|
70171
|
+
const entryNames = "[name]-[hash]";
|
|
70172
|
+
const cssConfig = {
|
|
70173
|
+
...finalConfig,
|
|
70174
|
+
entryPoints: [cssSourcePath],
|
|
70175
|
+
entryNames
|
|
70176
|
+
};
|
|
70177
|
+
const cssResult = await esbuild.build(cssConfig);
|
|
70178
|
+
for (const file of cssResult.outputFiles) {
|
|
70179
|
+
const relativeFilePath = import_path8.default.relative(outdir, file.path);
|
|
70180
|
+
if (relativeFilePath.endsWith(".css")) {
|
|
70181
|
+
packageCssToOutputPath.set(cssSourcePath, relativeFilePath);
|
|
70182
|
+
log_default.debug(
|
|
70183
|
+
`Built package CSS file: ${cssSourcePath} -> ${relativeFilePath}`
|
|
70184
|
+
);
|
|
70185
|
+
}
|
|
70186
|
+
await fileWriter.writeFile(file.path, file.contents, {
|
|
70187
|
+
encoding: "utf-8"
|
|
70188
|
+
});
|
|
70189
|
+
}
|
|
70190
|
+
}
|
|
70191
|
+
}
|
|
70026
70192
|
log_default.debug(
|
|
70027
70193
|
`Rewriting pug/less references in ${pugHtmlOutputs.size} HTML file(s)`
|
|
70028
70194
|
);
|
|
@@ -70048,6 +70214,15 @@ var esbuilder = {
|
|
|
70048
70214
|
outdir
|
|
70049
70215
|
);
|
|
70050
70216
|
}
|
|
70217
|
+
if (output.packageCssReferences.length > 0) {
|
|
70218
|
+
html = rewritePackageCssReferencesInHtml(
|
|
70219
|
+
html,
|
|
70220
|
+
output.packageCssReferences,
|
|
70221
|
+
packageCssToOutputPath,
|
|
70222
|
+
htmlOutputDir,
|
|
70223
|
+
outdir
|
|
70224
|
+
);
|
|
70225
|
+
}
|
|
70051
70226
|
const promise = fileWriter.writeFile(output.outputPath, html, {
|
|
70052
70227
|
encoding: "utf-8"
|
|
70053
70228
|
});
|