@staticbolt/core 1.0.0-beta.1 → 1.0.0-beta.11
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/lib/chunk-C7Uep-_p.mjs +20 -0
- package/lib/cli/index.mjs +1 -1
- package/lib/cli/index.mjs.map +1 -1
- package/lib/index.d.mts +299 -292
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +3 -3
- package/lib/index.mjs.map +1 -1
- package/lib/{logger-BuxMGhij.mjs → logger-BfIn1ytK.mjs} +29 -9
- package/lib/logger-BfIn1ytK.mjs.map +1 -0
- package/lib/plugins/index.d.mts +16 -11
- package/lib/plugins/index.d.mts.map +1 -1
- package/lib/plugins/index.mjs +133 -99
- package/lib/plugins/index.mjs.map +1 -1
- package/lib/{dependency-tracker-BuZfopIj.mjs → utilities-CZmLMi93.mjs} +45 -45
- package/lib/utilities-CZmLMi93.mjs.map +1 -0
- package/package.json +40 -40
- package/lib/dependency-tracker-BuZfopIj.mjs.map +0 -1
- package/lib/logger-BuxMGhij.mjs.map +0 -1
package/lib/plugins/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as isHtmlMetadata, C as PrintFormattedError, D as filterScriptMetadata, E as traverse, F as isSvgMetadata, I as isTextAssetMetadata, L as isWebManifestMetadata, M as isPackageMetadata, N as isScriptMetadata, O as filterStyleMetadata, P as isStyleMetadata, R as isScriptType, S as valueOrError, T as generator,
|
|
2
|
-
import { _ as
|
|
1
|
+
import { A as isHtmlMetadata, B as DependencyTracker, C as PrintFormattedError, D as filterScriptMetadata, E as traverse, F as isSvgMetadata, I as isTextAssetMetadata, L as isWebManifestMetadata, M as isPackageMetadata, N as isScriptMetadata, O as filterStyleMetadata, P as isStyleMetadata, R as isScriptType, S as valueOrError, T as generator, _ as mergeMaps, b as safeReadFileSync, c as downloadContent, d as hashContent, f as humanReadableBytes, h as isURL, j as isMarkdownMetadata, k as isBinaryAssetMetadata, l as escapeHtml, n as bytesToKB, s as cloneObject, w as printFmtError, z as METADATA_TYPES } from "../utilities-CZmLMi93.mjs";
|
|
2
|
+
import { _ as CUSTOM_ATTRIBUTES, a as extname, c as join, d as parse$2, g as CONFIG_FILE_NAME, h as resolve, i as dirname, l as matchPath, m as replaceExtension, n as createLog, o as isAbsolute, p as relative, r as basename, s as isSubpath, t as Log, u as normalize } from "../logger-BfIn1ytK.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import nodePath from "node:path";
|
|
5
5
|
import { HTMLElement, NodeType, parse } from "@staticbolt/node-html-parser";
|
|
@@ -1146,6 +1146,7 @@ function parseOptionFromImgPath(imgPath, defaultQuality, defaultPreset) {
|
|
|
1146
1146
|
function copyAssetsPlugin(options = {}) {
|
|
1147
1147
|
const include = options.include ?? ["sources/assets/**/*"];
|
|
1148
1148
|
const ignore = options.exclude ?? [];
|
|
1149
|
+
const publicDirectory = options.publicDirectory ?? "public";
|
|
1149
1150
|
return {
|
|
1150
1151
|
name: "copy-assets",
|
|
1151
1152
|
postBuild() {
|
|
@@ -1157,7 +1158,6 @@ function copyAssetsPlugin(options = {}) {
|
|
|
1157
1158
|
nodir: true,
|
|
1158
1159
|
cwd: this.root
|
|
1159
1160
|
});
|
|
1160
|
-
if (assetsFiles.length === 0) return;
|
|
1161
1161
|
for (const file of assetsFiles) {
|
|
1162
1162
|
const inputFile = join(this.root, file);
|
|
1163
1163
|
if (convertedImages.has(inputFile)) continue;
|
|
@@ -1167,6 +1167,20 @@ function copyAssetsPlugin(options = {}) {
|
|
|
1167
1167
|
mkdirSync(dirname(outputFile), { recursive: true });
|
|
1168
1168
|
copyFileSync(inputFile, outputFile);
|
|
1169
1169
|
}
|
|
1170
|
+
const publicFiles = globSync("**/*", {
|
|
1171
|
+
ignore,
|
|
1172
|
+
nodir: true,
|
|
1173
|
+
cwd: join(this.root, publicDirectory)
|
|
1174
|
+
});
|
|
1175
|
+
for (const file of publicFiles) {
|
|
1176
|
+
const inputFile = join(this.root, publicDirectory, file);
|
|
1177
|
+
if (convertedImages.has(inputFile)) continue;
|
|
1178
|
+
if (optimizedSvgList.has(inputFile)) continue;
|
|
1179
|
+
const outputFile = join(this.outdir, file);
|
|
1180
|
+
if (existsSync(outputFile)) continue;
|
|
1181
|
+
mkdirSync(dirname(outputFile), { recursive: true });
|
|
1182
|
+
copyFileSync(inputFile, outputFile);
|
|
1183
|
+
}
|
|
1170
1184
|
}
|
|
1171
1185
|
};
|
|
1172
1186
|
}
|
|
@@ -2421,7 +2435,7 @@ function loadSourcesPlugin(options) {
|
|
|
2421
2435
|
const ignore = options.exclude ?? [];
|
|
2422
2436
|
return {
|
|
2423
2437
|
name: "load-sources",
|
|
2424
|
-
|
|
2438
|
+
setup() {
|
|
2425
2439
|
const entryFiles = globSync(options.include, {
|
|
2426
2440
|
ignore,
|
|
2427
2441
|
cwd: this.root,
|
|
@@ -2436,16 +2450,6 @@ function loadSourcesPlugin(options) {
|
|
|
2436
2450
|
this.entryPoints.add(normalized);
|
|
2437
2451
|
this.watcher?.add(normalized);
|
|
2438
2452
|
}
|
|
2439
|
-
if (!this.production) return;
|
|
2440
|
-
for (const entryFile of this.entryPoints) {
|
|
2441
|
-
if (this.findMetadata({ id: entryFile })) continue;
|
|
2442
|
-
const metadata = await this.load(entryFile);
|
|
2443
|
-
if (!metadata) {
|
|
2444
|
-
this.log.error(`Could not load "${entryFile}".`);
|
|
2445
|
-
return;
|
|
2446
|
-
}
|
|
2447
|
-
this.addMetadata(metadata);
|
|
2448
|
-
}
|
|
2449
2453
|
},
|
|
2450
2454
|
onFileEvent(event, id) {
|
|
2451
2455
|
if (event === "change") return;
|
|
@@ -3071,29 +3075,24 @@ function htmlBuildTimeScript(options = {}) {
|
|
|
3071
3075
|
//#region src/plugins/html-bundle-script/esbuild-plugin.ts
|
|
3072
3076
|
function loaderPlugin(outFile, checkExternal) {
|
|
3073
3077
|
const root = this.root;
|
|
3074
|
-
const
|
|
3078
|
+
const outFileAbs = join(root, outFile);
|
|
3079
|
+
const app = this;
|
|
3075
3080
|
return {
|
|
3076
3081
|
name: "resolve-loader",
|
|
3077
3082
|
setup(build) {
|
|
3078
3083
|
build.onResolve({ filter: /\.(js|mjs|cjs)$/ }, (arguments_) => {
|
|
3079
3084
|
if (!arguments_.path.startsWith(".")) return;
|
|
3080
|
-
const app = appThis();
|
|
3081
3085
|
const absSource = join(arguments_.resolveDir, arguments_.path);
|
|
3082
3086
|
const source = relative(root, absSource);
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
path: relativeToOutFile,
|
|
3087
|
-
external
|
|
3087
|
+
if (checkExternal(source)) return {
|
|
3088
|
+
path: relative(dirname(outFile), source),
|
|
3089
|
+
external: true
|
|
3088
3090
|
};
|
|
3089
3091
|
if (matchPath(source, {
|
|
3090
3092
|
include: ["**/node_modules/**"],
|
|
3091
3093
|
ignore: [],
|
|
3092
3094
|
root
|
|
3093
|
-
})) return {
|
|
3094
|
-
path: absSource,
|
|
3095
|
-
external
|
|
3096
|
-
};
|
|
3095
|
+
})) return { path: absSource };
|
|
3097
3096
|
const scriptMetadata = app.findMetadata({ filePath: source });
|
|
3098
3097
|
if (!isScriptMetadata(scriptMetadata)) {
|
|
3099
3098
|
Log.error(`[htmlBundleScriptPlugin:onResolve] Script metadata for the path "${source}" not found`);
|
|
@@ -3102,8 +3101,7 @@ function loaderPlugin(outFile, checkExternal) {
|
|
|
3102
3101
|
return {
|
|
3103
3102
|
path: absSource,
|
|
3104
3103
|
namespace: "loader",
|
|
3105
|
-
pluginData: scriptMetadata
|
|
3106
|
-
external
|
|
3104
|
+
pluginData: scriptMetadata
|
|
3107
3105
|
};
|
|
3108
3106
|
});
|
|
3109
3107
|
build.onLoad({
|
|
@@ -3115,9 +3113,11 @@ function loaderPlugin(outFile, checkExternal) {
|
|
|
3115
3113
|
Log.error(`[htmlBundleScriptPlugin:onLoad] Script metadata for the path "${arguments_.path}" not found."`);
|
|
3116
3114
|
return;
|
|
3117
3115
|
}
|
|
3116
|
+
const clone = app.clone(scriptMetadata);
|
|
3117
|
+
await app.rebase(clone, outFileAbs);
|
|
3118
3118
|
return {
|
|
3119
|
-
contents: await
|
|
3120
|
-
resolveDir: dirname(
|
|
3119
|
+
contents: await app.stringify(clone),
|
|
3120
|
+
resolveDir: dirname(outFileAbs),
|
|
3121
3121
|
loader: "js"
|
|
3122
3122
|
};
|
|
3123
3123
|
});
|
|
@@ -3161,22 +3161,21 @@ async function bundleScriptWithEsbuild(options) {
|
|
|
3161
3161
|
//#endregion
|
|
3162
3162
|
//#region src/plugins/html-bundle-script/html-bundle-script-plugin.ts
|
|
3163
3163
|
/**
|
|
3164
|
-
* A plugin that bundles
|
|
3164
|
+
* A plugin that bundles script tags in HTML files using esbuild.
|
|
3165
3165
|
*
|
|
3166
|
-
* Bundling is opt-in per script tag via the
|
|
3166
|
+
* Bundling is opt-in per script tag via the "bundle" attribute (configurable via HtmlBundleScriptOptions.bundleAttribute).
|
|
3167
3167
|
*
|
|
3168
|
-
*
|
|
3168
|
+
* Inlining vs. separate file
|
|
3169
3169
|
*
|
|
3170
|
-
* - Inline script, no
|
|
3171
|
-
* - Inline script,
|
|
3172
|
-
* -
|
|
3173
|
-
* -
|
|
3170
|
+
* - Inline script, no "bundle-out" attribute: bundled output replaces the tag content in place.
|
|
3171
|
+
* - Inline script, "bundle-out" attribute set: tag content is cleared and "src" is set to the output file.
|
|
3172
|
+
* - "src" script, no "bundle-out" attribute: bundle is written to "{filename}.bundle.js" and "src" is updated.
|
|
3173
|
+
* - "src" script, "bundle-out" attribute set: bundle is written to the specified path and "src" is updated.
|
|
3174
3174
|
*
|
|
3175
|
-
*
|
|
3175
|
+
* Externals resolution
|
|
3176
3176
|
*
|
|
3177
|
-
* Glob patterns in
|
|
3178
|
-
*
|
|
3179
|
-
* `externalsExclude`.
|
|
3177
|
+
* Glob patterns in HtmlBundleScriptOptions.externals and HtmlBundleScriptOptions.externalsExclude are matched against each
|
|
3178
|
+
* resolved module path. A module is treated as external if it matches "externals" and does not match "externalsExclude".
|
|
3180
3179
|
*/
|
|
3181
3180
|
function htmlBundleScriptPlugin(options = {}) {
|
|
3182
3181
|
const defaultExternal = options.externals ?? ["**/node_modules/**"];
|
|
@@ -3207,6 +3206,7 @@ function htmlBundleScriptPlugin(options = {}) {
|
|
|
3207
3206
|
}
|
|
3208
3207
|
});
|
|
3209
3208
|
}
|
|
3209
|
+
return sources;
|
|
3210
3210
|
},
|
|
3211
3211
|
async transform(metadata) {
|
|
3212
3212
|
if (!isHtmlMetadata(metadata)) return;
|
|
@@ -3240,28 +3240,42 @@ function htmlBundleScriptPlugin(options = {}) {
|
|
|
3240
3240
|
let entryPoint = "";
|
|
3241
3241
|
let outfile = "";
|
|
3242
3242
|
let contents = "";
|
|
3243
|
-
if (bundleOut) outfile = bundleOut;
|
|
3244
3243
|
if (hasContent) {
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3244
|
+
outfile = bundleOut ?? filePath;
|
|
3245
|
+
if (inline) {
|
|
3246
|
+
entryPoint = metadata.filePath;
|
|
3247
|
+
contents = await this.stringify(scriptMetadata);
|
|
3248
|
+
} else {
|
|
3249
|
+
node.textContent = "";
|
|
3250
|
+
if (this.findMetadata({ filePath: outfile })) {
|
|
3251
|
+
this.log.info(`The entry point "${entryPoint}" is already bundled in "${outfile}", skipping...`);
|
|
3252
|
+
if (scriptMetadataID) metadata.scriptsMetadataList.delete(scriptMetadataID);
|
|
3253
|
+
node.setAttribute("src", relative(dirname(filePath), outfile));
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
entryPoint = outfile;
|
|
3257
|
+
const clone = this.clone(scriptMetadata);
|
|
3258
|
+
await this.rebase(clone, join(this.root, outfile));
|
|
3259
|
+
contents = await this.stringify(clone);
|
|
3260
|
+
}
|
|
3261
|
+
} else if (scriptSource) {
|
|
3262
|
+
outfile = bundleOut ?? normalize(replaceExtension(basename(scriptSource), ".bundle.js"));
|
|
3263
|
+
entryPoint = outfile;
|
|
3264
|
+
if (this.findMetadata({ filePath: outfile })) {
|
|
3265
|
+
this.log.info(`The entry point "${entryPoint}" is already bundled in "${outfile}", skipping...`);
|
|
3266
|
+
continue;
|
|
3255
3267
|
}
|
|
3256
|
-
const
|
|
3257
|
-
if (!isScriptMetadata(
|
|
3268
|
+
const sourceScriptMetadata = this.findMetadata({ filePath: join(dirname(filePath), scriptSource) });
|
|
3269
|
+
if (!isScriptMetadata(sourceScriptMetadata)) {
|
|
3258
3270
|
printFmtError(`Script metadata for the path "${entryPoint}" not found`, {
|
|
3259
3271
|
node,
|
|
3260
3272
|
filePath
|
|
3261
3273
|
});
|
|
3262
3274
|
continue;
|
|
3263
3275
|
}
|
|
3264
|
-
|
|
3276
|
+
const clone = this.clone(sourceScriptMetadata);
|
|
3277
|
+
await this.rebase(clone, join(this.root, outfile));
|
|
3278
|
+
contents = await this.stringify(clone);
|
|
3265
3279
|
}
|
|
3266
3280
|
const checkExternal = (string) => {
|
|
3267
3281
|
return matchPath(string, {
|
|
@@ -3283,7 +3297,7 @@ function htmlBundleScriptPlugin(options = {}) {
|
|
|
3283
3297
|
});
|
|
3284
3298
|
continue;
|
|
3285
3299
|
}
|
|
3286
|
-
const newMetadataPath = normalize(inline ?
|
|
3300
|
+
const newMetadataPath = normalize(inline ? filePath : outfile);
|
|
3287
3301
|
const newScriptMetadata = await this.load(newMetadataPath, {
|
|
3288
3302
|
code: bundleString,
|
|
3289
3303
|
type: "js"
|
|
@@ -3838,11 +3852,11 @@ function htmlInsertPlugin(options = {}) {
|
|
|
3838
3852
|
//#endregion
|
|
3839
3853
|
//#region src/plugins/html-layout/fill-placeholders.ts
|
|
3840
3854
|
/** (any){{any}} */
|
|
3841
|
-
const placeholderRe$
|
|
3855
|
+
const placeholderRe$2 = /(\\)?{{\s*([\s\S]*?)\s*}}/g;
|
|
3842
3856
|
/** `{{ JavaScript expression }}` */
|
|
3843
3857
|
function fillLayoutPlaceholders(html, placeholders) {
|
|
3844
3858
|
const errors = [];
|
|
3845
|
-
const result = html.replace(placeholderRe$
|
|
3859
|
+
const result = html.replace(placeholderRe$2, (match, escape, content) => {
|
|
3846
3860
|
if (escape === "\\") return match.slice(1);
|
|
3847
3861
|
const [expression, executeError] = executeExpression$1(content, placeholders);
|
|
3848
3862
|
if (executeError) {
|
|
@@ -4488,11 +4502,11 @@ function cutLeadingSubpath(pathToCut, leadingSubpath) {
|
|
|
4488
4502
|
//#endregion
|
|
4489
4503
|
//#region src/plugins/html-pages/fill-placeholders.ts
|
|
4490
4504
|
/** (any){{any}} */
|
|
4491
|
-
const placeholderRe = /(\\)?{{\s*([\s\S]*?)\s*}}/g;
|
|
4505
|
+
const placeholderRe$1 = /(\\)?{{\s*([\s\S]*?)\s*}}/g;
|
|
4492
4506
|
/** `{{ JavaScript expression }}` */
|
|
4493
4507
|
function fillPlaceholders(html, routeData) {
|
|
4494
4508
|
const errors = [];
|
|
4495
|
-
const result = html.replace(placeholderRe, (match, escape, content) => {
|
|
4509
|
+
const result = html.replace(placeholderRe$1, (match, escape, content) => {
|
|
4496
4510
|
if (escape === "\\") return match.slice(1);
|
|
4497
4511
|
const [expression, executeError] = executeExpression(content, routeData);
|
|
4498
4512
|
if (executeError) {
|
|
@@ -5054,6 +5068,8 @@ function stringifySrcset(entries) {
|
|
|
5054
5068
|
for (const entry of entries) srcset += entry.descriptor ? `, ${entry.url} ${entry.descriptor}` : `, ${entry.url}`;
|
|
5055
5069
|
return srcset;
|
|
5056
5070
|
}
|
|
5071
|
+
/** Match placeholders [[ has $ ]] or {{ has $ }} */
|
|
5072
|
+
const placeholderRe = /(?:\[\[([^\]]*\$[^\]]*?)\]\]|\{\{([^}]*\$[^}]*?)\}\})/;
|
|
5057
5073
|
function parseHtmlSources(ast) {
|
|
5058
5074
|
const links = [];
|
|
5059
5075
|
for (const node of ast.querySelectorAll(combinedSelector)) {
|
|
@@ -5065,19 +5081,23 @@ function parseHtmlSources(ast) {
|
|
|
5065
5081
|
if (!value) continue;
|
|
5066
5082
|
if (attribute === "srcset") {
|
|
5067
5083
|
const entries = parseSrcset(value);
|
|
5068
|
-
for (const [index, entry] of entries.entries())
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5084
|
+
for (const [index, entry] of entries.entries()) {
|
|
5085
|
+
if (placeholderRe.test(entry.url)) continue;
|
|
5086
|
+
links.push({
|
|
5087
|
+
node,
|
|
5088
|
+
get source() {
|
|
5089
|
+
return decodeURIComponent(entry.url);
|
|
5090
|
+
},
|
|
5091
|
+
set source(newValue) {
|
|
5092
|
+
const current = parseSrcset(node.getAttribute("srcset") || "");
|
|
5093
|
+
current[index].url = newValue;
|
|
5094
|
+
node.setAttribute("srcset", stringifySrcset(current));
|
|
5095
|
+
}
|
|
5096
|
+
});
|
|
5097
|
+
}
|
|
5079
5098
|
continue;
|
|
5080
5099
|
}
|
|
5100
|
+
if (placeholderRe.test(value)) continue;
|
|
5081
5101
|
links.push({
|
|
5082
5102
|
node,
|
|
5083
5103
|
get source() {
|
|
@@ -5095,7 +5115,10 @@ function parseHtmlSources(ast) {
|
|
|
5095
5115
|
//#endregion
|
|
5096
5116
|
//#region src/parsers/html-parser.ts
|
|
5097
5117
|
function parseHtmlUnsafe(html, options = {}) {
|
|
5098
|
-
return parse(html,
|
|
5118
|
+
return parse(html, {
|
|
5119
|
+
comment: true,
|
|
5120
|
+
...options
|
|
5121
|
+
});
|
|
5099
5122
|
}
|
|
5100
5123
|
/** Parse HTML string and return the root node */
|
|
5101
5124
|
const parseHtml = valueOrError(parseHtmlUnsafe);
|
|
@@ -5198,24 +5221,25 @@ function coreHtmlPlugin(options = {}) {
|
|
|
5198
5221
|
const nodeIdMap = /* @__PURE__ */ new Map();
|
|
5199
5222
|
const scriptsAndStyles = metadata.ast.querySelectorAll("script,style");
|
|
5200
5223
|
for (const node of scriptsAndStyles) {
|
|
5201
|
-
const
|
|
5202
|
-
|
|
5203
|
-
const id = node.getAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5204
|
-
if (!id) continue;
|
|
5205
|
-
nodeIdMap.set(node, id);
|
|
5206
|
-
node.removeAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5224
|
+
const hasMinifyAttribute = node.hasAttribute(minifyAttribute);
|
|
5225
|
+
const shouldMinify = minify || hasMinifyAttribute;
|
|
5207
5226
|
const isScript = node.tagName === "SCRIPT";
|
|
5227
|
+
node.removeAttribute(minifyAttribute);
|
|
5208
5228
|
const scriptType = node.getAttribute("type");
|
|
5209
5229
|
if (isScript && !isScriptType(scriptType)) continue;
|
|
5210
|
-
const
|
|
5230
|
+
const metadataID = node.getAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5231
|
+
if (!metadataID) continue;
|
|
5232
|
+
nodeIdMap.set(node, metadataID);
|
|
5233
|
+
node.removeAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5234
|
+
const tagMetadata = metadata[isScript ? "scriptsMetadataList" : "stylesMetadataList"].get(metadataID);
|
|
5211
5235
|
if (!tagMetadata) continue;
|
|
5212
5236
|
const code = await this.stringify(tagMetadata, {
|
|
5213
|
-
format: format && !
|
|
5214
|
-
minify:
|
|
5237
|
+
format: format && !shouldMinify,
|
|
5238
|
+
minify: shouldMinify
|
|
5215
5239
|
});
|
|
5216
5240
|
if (!code) continue;
|
|
5217
5241
|
node.textContent = code;
|
|
5218
|
-
if (format &&
|
|
5242
|
+
if (format && hasMinifyAttribute) node.replaceWith(ignoreFormatComment + node.outerHTML);
|
|
5219
5243
|
}
|
|
5220
5244
|
const code = metadata.ast.toString();
|
|
5221
5245
|
for (const [node, metadataID] of nodeIdMap) node.setAttribute(CUSTOM_ATTRIBUTES.MetadataID, metadataID);
|
|
@@ -5380,12 +5404,8 @@ function coreMarkdownPlugin(options = {}) {
|
|
|
5380
5404
|
|
|
5381
5405
|
//#endregion
|
|
5382
5406
|
//#region src/ast-utilities/babel-utils/parse-script-srouces.ts
|
|
5383
|
-
function parseScriptSources({ ast
|
|
5407
|
+
function parseScriptSources({ ast }) {
|
|
5384
5408
|
const result = [];
|
|
5385
|
-
const printFmtError = PrintFormattedError.create({
|
|
5386
|
-
function: parseScriptSources,
|
|
5387
|
-
filePath
|
|
5388
|
-
});
|
|
5389
5409
|
t.traverseFast(ast, (node) => {
|
|
5390
5410
|
if (t.isImportDeclaration(node)) {
|
|
5391
5411
|
if (!t.isStringLiteral(node.source)) return;
|
|
@@ -5459,10 +5479,7 @@ function parseScriptSources({ ast, filePath }) {
|
|
|
5459
5479
|
if (t.isNewExpression(node)) {
|
|
5460
5480
|
if (!t.isIdentifier(node.callee, { name: "URL" })) return;
|
|
5461
5481
|
const firstArgument = node.arguments[0];
|
|
5462
|
-
if (!t.isStringLiteral(firstArgument))
|
|
5463
|
-
printFmtError("The first argument of `URL` should be a string", { node });
|
|
5464
|
-
return;
|
|
5465
|
-
}
|
|
5482
|
+
if (!t.isStringLiteral(firstArgument)) return;
|
|
5466
5483
|
const setSource = (newValue) => {
|
|
5467
5484
|
node.arguments[0] = t.stringLiteral(newValue);
|
|
5468
5485
|
};
|
|
@@ -6048,6 +6065,7 @@ function developmentServerPlugin(options = {}) {
|
|
|
6048
6065
|
function upgradeWebSocketHandler(request, socket, head) {
|
|
6049
6066
|
websocket.handleUpgrade(request, socket, head, (ws) => {
|
|
6050
6067
|
wsClients.add(ws);
|
|
6068
|
+
websocket.emit("connection", ws, request);
|
|
6051
6069
|
ws.send(JSON.stringify({ data: "connected" }));
|
|
6052
6070
|
ws.on("close", () => {
|
|
6053
6071
|
wsClients.delete(ws);
|
|
@@ -6084,6 +6102,14 @@ function developmentServerPlugin(options = {}) {
|
|
|
6084
6102
|
}
|
|
6085
6103
|
this.log.info(c.bold("Server listening on"), c.green(address + entry));
|
|
6086
6104
|
});
|
|
6105
|
+
websocket.on("connection", () => {
|
|
6106
|
+
const sortedByAge = Array.from(entryPointAgeMap).toSorted((a, b) => a[1] - b[1]).map(([id]) => id);
|
|
6107
|
+
const excess = sortedByAge.length - wsClients.size;
|
|
6108
|
+
if (excess > 0) for (const id of sortedByAge.slice(0, excess)) {
|
|
6109
|
+
entryPointAgeMap.delete(id);
|
|
6110
|
+
removeAndPruneOrphans(this.metadataList, id);
|
|
6111
|
+
}
|
|
6112
|
+
});
|
|
6087
6113
|
},
|
|
6088
6114
|
async onFileEvent(event, changedSource) {
|
|
6089
6115
|
if (event === "unlink") {
|
|
@@ -6101,11 +6127,15 @@ function developmentServerPlugin(options = {}) {
|
|
|
6101
6127
|
if (oldMetadataList.length === 0) continue;
|
|
6102
6128
|
const oldDeps = new Set(oldMetadataList.flatMap((m) => Array.from(m.directDependencies)));
|
|
6103
6129
|
this.removeMetadata(oldMetadataList);
|
|
6104
|
-
await this.process(id)
|
|
6130
|
+
if (!await this.process(id)) {
|
|
6131
|
+
this.addMetadata(oldMetadataList);
|
|
6132
|
+
continue;
|
|
6133
|
+
}
|
|
6105
6134
|
const newMetadataList = this.filterMetadata({ id });
|
|
6106
6135
|
const newDeps = new Set(newMetadataList.flatMap((m) => Array.from(m.directDependencies)));
|
|
6107
6136
|
const removedDeps = Array.from(oldDeps).filter((dep) => !newDeps.has(dep));
|
|
6108
|
-
for (const dep of removedDeps)
|
|
6137
|
+
for (const dep of removedDeps) {
|
|
6138
|
+
if (this.metadataList.some((m) => m.directDependencies && m.directDependencies.has(dep))) continue;
|
|
6109
6139
|
const orphans = this.filterMetadata({ id: dep });
|
|
6110
6140
|
if (orphans && orphans.length > 0) this.removeMetadata(orphans);
|
|
6111
6141
|
}
|
|
@@ -6135,12 +6165,6 @@ function developmentServerPlugin(options = {}) {
|
|
|
6135
6165
|
if (this.entryPoints.has(metadata.id) && isHtmlMetadata(metadata)) {
|
|
6136
6166
|
injectReloadScript(metadata);
|
|
6137
6167
|
entryPointAgeMap.set(metadata.id, Date.now());
|
|
6138
|
-
const sortedByAge = Array.from(entryPointAgeMap).toSorted((a, b) => a[1] - b[1]).map(([id]) => id);
|
|
6139
|
-
const excess = sortedByAge.length - wsClients.size;
|
|
6140
|
-
if (excess > 0) for (const id of sortedByAge.slice(0, excess)) {
|
|
6141
|
-
entryPointAgeMap.delete(id);
|
|
6142
|
-
removeAndPruneOrphans(this.metadataList, id);
|
|
6143
|
-
}
|
|
6144
6168
|
}
|
|
6145
6169
|
const stringified = await this.stringify(metadata);
|
|
6146
6170
|
if (typeof stringified !== "string") return;
|
|
@@ -6555,6 +6579,15 @@ var App = class {
|
|
|
6555
6579
|
this.log.info("Dev mode: on-demand build active, skipping build pipeline");
|
|
6556
6580
|
return;
|
|
6557
6581
|
}
|
|
6582
|
+
for (const entryFile of this.entryPoints) {
|
|
6583
|
+
if (this.findMetadata({ id: entryFile })) continue;
|
|
6584
|
+
const metadata = await this.load(entryFile);
|
|
6585
|
+
if (!metadata) {
|
|
6586
|
+
this.log.error(`Could not load "${entryFile}".`);
|
|
6587
|
+
return;
|
|
6588
|
+
}
|
|
6589
|
+
this.addMetadata(metadata);
|
|
6590
|
+
}
|
|
6558
6591
|
this.log.info(`Resolving ${this.metadataList.length} entry point(s)`);
|
|
6559
6592
|
await this.resolveAndLoad(this.metadataList);
|
|
6560
6593
|
this.log.info(`Transforming ${this.metadataList.length} file(s)`);
|
|
@@ -6572,7 +6605,7 @@ var App = class {
|
|
|
6572
6605
|
const metadata = await this.load(id);
|
|
6573
6606
|
if (!metadata) {
|
|
6574
6607
|
this.log.error(`Could not load "${id}".`);
|
|
6575
|
-
return;
|
|
6608
|
+
return false;
|
|
6576
6609
|
}
|
|
6577
6610
|
const metadataList = await this.resolveAndLoad(metadata);
|
|
6578
6611
|
const previouslyTransformed = new Set(this.metadataList);
|
|
@@ -6580,6 +6613,7 @@ var App = class {
|
|
|
6580
6613
|
for (const plugin of this.plugins) await this.callPluginMethod(plugin, "preTransform");
|
|
6581
6614
|
for (const plugin of this.plugins) for (const metadataItem of this.metadataList) if (!previouslyTransformed.has(metadataItem)) await this.callPluginMethod(plugin, "transform", metadataItem);
|
|
6582
6615
|
for (const plugin of this.plugins) await this.callPluginMethod(plugin, "postTransform");
|
|
6616
|
+
return true;
|
|
6583
6617
|
}
|
|
6584
6618
|
async resolve(metadata) {
|
|
6585
6619
|
if (!this.isPluginInitialized) this.log.warn("[resolve] Plugins are not fully setup yet.");
|