@staticbolt/core 1.0.0-beta.30 → 1.0.0-beta.31
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/README.md +2 -1
- package/lib/cli/index.mjs +31 -8
- package/lib/cli/index.mjs.map +1 -1
- package/lib/{common-DUFKS3lW.mjs → common-D1QTZ8ra.mjs} +2 -2
- package/lib/{common-DUFKS3lW.mjs.map → common-D1QTZ8ra.mjs.map} +1 -1
- package/lib/index.d.mts +151 -3
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +3 -3
- package/lib/index.mjs.map +1 -1
- package/lib/{load-config-D-FtbUws.mjs → load-config-CsbiJ01A.mjs} +2 -2
- package/lib/{load-config-D-FtbUws.mjs.map → load-config-CsbiJ01A.mjs.map} +1 -1
- package/lib/plugins/index.d.mts +16 -7
- package/lib/plugins/index.d.mts.map +1 -1
- package/lib/plugins/index.mjs +739 -206
- package/lib/plugins/index.mjs.map +1 -1
- package/lib/{utilities-D0KXIZ-B.mjs → utilities-jK4uUZBV.mjs} +85 -26
- package/lib/utilities-jK4uUZBV.mjs.map +1 -0
- package/package.json +8 -4
- package/lib/utilities-D0KXIZ-B.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as replaceExtension, c as isAbsolute, d as join, f as normalize, n as CUSTOM_ATTRIBUTES, o as dirname, r as Log, s as extname } from "./common-
|
|
1
|
+
import { _ as replaceExtension, c as isAbsolute, d as join, f as normalize, n as CUSTOM_ATTRIBUTES, o as dirname, r as Log, s as extname } from "./common-D1QTZ8ra.mjs";
|
|
2
2
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { ResolverFactory } from "oxc-resolver";
|
|
4
4
|
import chalk from "chalk";
|
|
@@ -86,6 +86,75 @@ function splitHtmlLink(url) {
|
|
|
86
86
|
return [url, ""];
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/helpers/is-script-type.ts
|
|
91
|
+
/**
|
|
92
|
+
* The `type` that marks a script as TypeScript for the editor: Prettier formats it as such, the editor's own script support
|
|
93
|
+
* leaves it alone, and the build drops it from the output.
|
|
94
|
+
*/
|
|
95
|
+
const TYPESCRIPT_TYPE = "application/x-typescript";
|
|
96
|
+
const allowedTypes = /* @__PURE__ */ new Set([
|
|
97
|
+
"module",
|
|
98
|
+
TYPESCRIPT_TYPE,
|
|
99
|
+
"text/javascript",
|
|
100
|
+
"application/javascript",
|
|
101
|
+
"text/ecmascript",
|
|
102
|
+
"application/ecmascript",
|
|
103
|
+
"application/x-javascript"
|
|
104
|
+
]);
|
|
105
|
+
function isScriptType(type) {
|
|
106
|
+
return !type || allowedTypes.has(type.toLowerCase());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/helpers/lsp-checks.ts
|
|
111
|
+
/** The placeholder syntaxes a plugin or a runtime may fill in: `{{ }}`, `[[ ]]`, `${ }`, `<% %>`, `{% %}` and `%name%`. */
|
|
112
|
+
const PLACEHOLDER = /\{\{[\s\S]*?\}\}|\[\[[\s\S]*?\]\]|\$\{[\s\S]*?\}|<%[\s\S]*?%>|\{%[\s\S]*?%\}|%[\w.-]+%/;
|
|
113
|
+
/** Whether an attribute value is only known later: it holds a placeholder something else fills in. */
|
|
114
|
+
function isDynamic(value) {
|
|
115
|
+
return PLACEHOLDER.test(value);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Reports an attribute whose value is a path to a file that is not there. A URL, an absolute link or a value with a placeholder
|
|
119
|
+
* is left alone.
|
|
120
|
+
*/
|
|
121
|
+
function checkFileExists(attribute, document, report) {
|
|
122
|
+
if (!attribute.value) return;
|
|
123
|
+
if (isDynamic(attribute.value)) return;
|
|
124
|
+
if (!isValidRelativePath(attribute.value)) return;
|
|
125
|
+
if (document.resolve(attribute.value)?.exists) return;
|
|
126
|
+
report.error(attribute, `"${attribute.value}" does not exist`);
|
|
127
|
+
}
|
|
128
|
+
/** Reports an attribute whose value is not the JSON of an object. A value with a placeholder is left alone. */
|
|
129
|
+
function checkJsonObject(attribute, report) {
|
|
130
|
+
if (!attribute.value) return;
|
|
131
|
+
if (isDynamic(attribute.value)) return;
|
|
132
|
+
if (isJsonObject(attribute.value)) return;
|
|
133
|
+
report.error(attribute, `"${attribute.name}" must be a JSON object`);
|
|
134
|
+
}
|
|
135
|
+
/** Whether a string is the JSON of an object. */
|
|
136
|
+
function isJsonObject(text) {
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(text);
|
|
139
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed);
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Whether a script element holds JavaScript, going by its `type`: the build leaves any other kind of script alone. */
|
|
145
|
+
function isJavaScript(script) {
|
|
146
|
+
return isScriptType(script.attribute("type")?.value ?? null);
|
|
147
|
+
}
|
|
148
|
+
/** Whether a `<script>` is marked as TypeScript for the editor, which also keeps the editor's own script support out. */
|
|
149
|
+
function isTypeScriptScript(script) {
|
|
150
|
+
return script.attribute("type")?.value?.toLowerCase() === TYPESCRIPT_TYPE;
|
|
151
|
+
}
|
|
152
|
+
/** Whether an element has nothing but whitespace between its tags. */
|
|
153
|
+
function isEmptyElement(element, document) {
|
|
154
|
+
if (!element.contentRange) return true;
|
|
155
|
+
return document.textOf(element.contentRange).trim() === "";
|
|
156
|
+
}
|
|
157
|
+
|
|
89
158
|
//#endregion
|
|
90
159
|
//#region src/utilities/value-or-error.ts
|
|
91
160
|
function errorsWrapper(function_) {
|
|
@@ -194,6 +263,8 @@ var Resolver = class Resolver {
|
|
|
194
263
|
files = /* @__PURE__ */ new Set();
|
|
195
264
|
directories = /* @__PURE__ */ new Set();
|
|
196
265
|
misses = /* @__PURE__ */ new Set();
|
|
266
|
+
/** Whether a source that resolves to a missing file is logged, once. The result says so either way. */
|
|
267
|
+
shouldWarnOnMissing;
|
|
197
268
|
static JS_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
198
269
|
".js",
|
|
199
270
|
".mjs",
|
|
@@ -205,9 +276,10 @@ var Resolver = class Resolver {
|
|
|
205
276
|
".tsx"
|
|
206
277
|
]);
|
|
207
278
|
static HTML_EXTENSIONS = /* @__PURE__ */ new Set([".html", ".md"]);
|
|
208
|
-
constructor(root, isProduction = false, configAliases = {}) {
|
|
279
|
+
constructor(root, isProduction = false, configAliases = {}, shouldWarnOnMissing = true) {
|
|
209
280
|
this.root = root;
|
|
210
281
|
this.isProduction = isProduction;
|
|
282
|
+
this.shouldWarnOnMissing = shouldWarnOnMissing;
|
|
211
283
|
const [aliases] = getPathAliases(root);
|
|
212
284
|
this.aliases = {
|
|
213
285
|
...aliases,
|
|
@@ -233,10 +305,7 @@ var Resolver = class Resolver {
|
|
|
233
305
|
const absSource = join(this.root, resolvedPathAlias);
|
|
234
306
|
const foundFile = this.findFile(absSource, isDirectory);
|
|
235
307
|
const isFileAlias = Object.hasOwn(this.aliases, sourceForAlias) && !sourceForAlias.endsWith("/");
|
|
236
|
-
if (!foundFile
|
|
237
|
-
this.notFound.add(absSource.replace(/\/$/, ""));
|
|
238
|
-
Log.warn(`[resolver] Source "${sourceOrLink}" found in "${filePath}" was resolved to "${resolvedPathAlias}", but the file is missing.`);
|
|
239
|
-
}
|
|
308
|
+
if (!foundFile) this.#warnMissing(absSource.replace(/\/$/, ""), `[resolver] Source "${sourceOrLink}" found in "${filePath}" was resolved to "${resolvedPathAlias}", but the file is missing.`);
|
|
240
309
|
return {
|
|
241
310
|
path: foundFile ?? absSource,
|
|
242
311
|
exists: !!foundFile,
|
|
@@ -255,10 +324,7 @@ var Resolver = class Resolver {
|
|
|
255
324
|
};
|
|
256
325
|
}
|
|
257
326
|
if (source.startsWith("./") || source.startsWith("../")) {
|
|
258
|
-
|
|
259
|
-
this.notFound.add(absSource);
|
|
260
|
-
Log.warn(`[resolver] Source "${sourceOrLink}" found in "${filePath}" points to a non-existent file.`);
|
|
261
|
-
}
|
|
327
|
+
this.#warnMissing(absSource, `[resolver] Source "${sourceOrLink}" found in "${filePath}" points to a non-existent file.`);
|
|
262
328
|
return {
|
|
263
329
|
path: absSource,
|
|
264
330
|
suffix,
|
|
@@ -266,6 +332,13 @@ var Resolver = class Resolver {
|
|
|
266
332
|
};
|
|
267
333
|
}
|
|
268
334
|
}
|
|
335
|
+
/** Logs a missing file the first time it is resolved to, when the resolver is set to. */
|
|
336
|
+
#warnMissing(absSource, message) {
|
|
337
|
+
if (!this.shouldWarnOnMissing) return;
|
|
338
|
+
if (this.notFound.has(absSource)) return;
|
|
339
|
+
this.notFound.add(absSource);
|
|
340
|
+
Log.warn(message);
|
|
341
|
+
}
|
|
269
342
|
resolveAlias(source) {
|
|
270
343
|
return Resolver.resolvePathAlias(source, this.aliases);
|
|
271
344
|
}
|
|
@@ -377,20 +450,6 @@ const METADATA_TYPES = Object.freeze({
|
|
|
377
450
|
WebAppManifest: "WebAppManifest"
|
|
378
451
|
});
|
|
379
452
|
|
|
380
|
-
//#endregion
|
|
381
|
-
//#region src/helpers/is-script-type.ts
|
|
382
|
-
const allowedTypes = /* @__PURE__ */ new Set([
|
|
383
|
-
"module",
|
|
384
|
-
"text/javascript",
|
|
385
|
-
"application/javascript",
|
|
386
|
-
"text/ecmascript",
|
|
387
|
-
"application/ecmascript",
|
|
388
|
-
"application/x-javascript"
|
|
389
|
-
]);
|
|
390
|
-
function isScriptType(type) {
|
|
391
|
-
return !type || allowedTypes.has(type.toLowerCase());
|
|
392
|
-
}
|
|
393
|
-
|
|
394
453
|
//#endregion
|
|
395
454
|
//#region src/utilities/metadata-utilities.ts
|
|
396
455
|
function isScriptMetadata(metadata) {
|
|
@@ -741,5 +800,5 @@ function escapeHtml(input) {
|
|
|
741
800
|
}
|
|
742
801
|
|
|
743
802
|
//#endregion
|
|
744
|
-
export { isTextAssetMetadata as A,
|
|
745
|
-
//# sourceMappingURL=utilities-
|
|
803
|
+
export { isTextAssetMetadata as A, checkJsonObject as B, isBinaryAssetMetadata as C, isScriptMetadata as D, isPackageMetadata as E, safeReadFile as F, isTypeScriptScript as G, isEmptyElement as H, safeReadFileSync as I, isHtmlLink as J, TYPESCRIPT_TYPE as K, handleError as L, METADATA_TYPES as M, Resolver as N, isStyleMetadata as O, readJsonFile as P, valueOrError as R, filterStyleMetadata as S, isMarkdownMetadata as T, isJavaScript as U, isDynamic as V, isJsonObject as W, splitHtmlLink as X, isValidRelativePath as Y, DependencyTracker as Z, mergeMaps as _, clamp as a, printFmtError as b, downloadContent as c, hashContent as d, humanReadableBytes as f, kebabToCamelCase as g, isURL as h, capitalize as i, isWebManifestMetadata as j, isSvgMetadata as k, escapeHtml as l, isObject as m, bytesToKB as n, clearLn as o, isDefined as p, isScriptType as q, camelCaseToKebabCase as r, cloneObject as s, assign as t, getLineColumn as u, print as v, isHtmlMetadata as w, filterScriptMetadata as x, PrintFormattedError as y, checkFileExists as z };
|
|
804
|
+
//# sourceMappingURL=utilities-jK4uUZBV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities-jK4uUZBV.mjs","names":["#sourcesToImporters","#importerToSources","#warnMissing","#findFileUncached","c","PostcssNode"],"sources":["../src/helpers/dependency-tracker.ts","../src/utilities/html-links.ts","../src/helpers/is-script-type.ts","../src/helpers/lsp-checks.ts","../src/utilities/value-or-error.ts","../src/utilities/read-file.ts","../src/utilities/read-json-file.ts","../src/resolver/get-aliases.ts","../src/resolver/resolver.ts","../src/types/metadata.ts","../src/utilities/metadata-utilities.ts","../src/utilities/highlight-code.ts","../src/utilities/print-formatted-error.ts","../src/utilities/utilities.ts"],"sourcesContent":["/**\n * Tracks bidirectional dependencies between importers and their sources.\\\n * Handles reconciliation when dependencies change, so stale entries are automatically removed when an importer stops referencing\n * a source.\n */\nexport class DependencyTracker {\n /** Source → Set of importers that depend on it */\n readonly #sourcesToImporters = new Map<string, Set<string>>();\n\n /** Importer → Set of sources it depends on */\n readonly #importerToSources = new Map<string, Set<string>>();\n\n /** Updates the full set of sources for a given importer, reconciling any stale entries from previous calls. */\n update(importer: string, sources: Iterable<string>): void {\n const nextSources = new Set(sources);\n const previousSources = this.#importerToSources.get(importer) ?? new Set();\n\n // Remove importer from sources it no longer uses\n for (const source of previousSources) {\n if (!nextSources.has(source)) {\n this.#sourcesToImporters.get(source)?.delete(importer);\n }\n }\n\n // Add importer to newly referenced sources\n for (const source of nextSources) {\n if (!this.#sourcesToImporters.has(source)) {\n this.#sourcesToImporters.set(source, new Set());\n }\n\n this.#sourcesToImporters.get(source)!.add(importer);\n }\n\n this.#importerToSources.set(importer, nextSources);\n }\n\n /** Deletes all dependency data for a given id, whether it's acting as an importer, a source, or both (e.g. on file unlink). */\n delete(id: string): void {\n // id was a source — drop it entirely\n this.#sourcesToImporters.delete(id);\n\n // id was an importer — remove it from all sources it referenced\n const sources = this.#importerToSources.get(id);\n if (sources) {\n for (const source of sources) {\n this.#sourcesToImporters.get(source)?.delete(id);\n }\n\n this.#importerToSources.delete(id);\n }\n }\n\n /** Returns all importers that depend on a given source, or an empty set. */\n getImporters(source: string): ReadonlySet<string> {\n return this.#sourcesToImporters.get(source) ?? new Set();\n }\n\n /** Returns all sources that a given importer depends on, or an empty set. */\n getSources(importer: string): ReadonlySet<string> {\n return this.#importerToSources.get(importer) ?? new Set();\n }\n}\n","import { isAbsolute } from \"./path.ts\";\n\n/**\n * Checks if the link is an HTML link (not a file link)\n *\n * @param source - The link\n * @returns\n */\nexport function isHtmlLink(source: string): boolean {\n return /^(?:#|https?|mailto:|tel:|url\\(|ftp:|data:|javascript:)/i.test(source);\n}\n\nexport function isValidRelativePath(source: string): boolean {\n if (!source) return false;\n // if (source.includes(\" \")) return false;\n if (isAbsolute(source)) return false;\n return !isHtmlLink(source);\n}\n\nexport function splitHtmlLink(url: string): [string, string] {\n const qIndex = url.indexOf(\"?\");\n const hIndex = url.indexOf(\"#\");\n\n // Find the earliest query/hash delimiter\n let delimIndex = -1;\n\n if (qIndex !== -1 && hIndex !== -1) {\n delimIndex = Math.min(qIndex, hIndex);\n }\n //\n else if (qIndex !== -1) {\n delimIndex = qIndex;\n }\n //\n else if (hIndex !== -1) {\n delimIndex = hIndex;\n }\n\n if (delimIndex !== -1) {\n // If a '/' immediately precedes the delimiter, include it in the suffix\n const pathEnd = url[delimIndex - 1] === \"/\" ? delimIndex - 1 : delimIndex;\n return [url.slice(0, pathEnd), url.slice(pathEnd)];\n }\n\n // No query or hash — handle trailing slash\n if (url.endsWith(\"/\")) {\n // Bare \"/\" or \"./\" are kept whole\n if (url === \"/\" || url === \"./\") {\n return [url, \"\"];\n }\n\n return [url.slice(0, -1), \"/\"];\n }\n\n return [url, \"\"];\n}\n","/**\n * The `type` that marks a script as TypeScript for the editor: Prettier formats it as such, the editor's own script support\n * leaves it alone, and the build drops it from the output.\n */\nexport const TYPESCRIPT_TYPE = \"application/x-typescript\";\n\nconst allowedTypes = new Set([\n \"module\",\n TYPESCRIPT_TYPE,\n \"text/javascript\",\n \"application/javascript\",\n \"text/ecmascript\",\n \"application/ecmascript\",\n \"application/x-javascript\",\n]);\n\nexport function isScriptType(type: string | null) {\n return !type || allowedTypes.has(type.toLowerCase());\n}\n","import { isValidRelativePath } from \"../utilities/html-links.ts\";\nimport { isScriptType, TYPESCRIPT_TYPE } from \"./is-script-type.ts\";\n\nimport type { AttributeInfo, DocumentInfo, ElementInfo, ProblemReporter } from \"../types/lsp.ts\";\n\n/** The placeholder syntaxes a plugin or a runtime may fill in: `{{ }}`, `[[ ]]`, `${ }`, `<% %>`, `{% %}` and `%name%`. */\nconst PLACEHOLDER = /\\{\\{[\\s\\S]*?\\}\\}|\\[\\[[\\s\\S]*?\\]\\]|\\$\\{[\\s\\S]*?\\}|<%[\\s\\S]*?%>|\\{%[\\s\\S]*?%\\}|%[\\w.-]+%/;\n\n/** Whether an attribute value is only known later: it holds a placeholder something else fills in. */\nexport function isDynamic(value: string): boolean {\n return PLACEHOLDER.test(value);\n}\n\n/**\n * Reports an attribute whose value is a path to a file that is not there. A URL, an absolute link or a value with a placeholder\n * is left alone.\n */\nexport function checkFileExists(attribute: AttributeInfo, document: DocumentInfo, report: ProblemReporter): void {\n if (!attribute.value) return;\n if (isDynamic(attribute.value)) return;\n if (!isValidRelativePath(attribute.value)) return;\n if (document.resolve(attribute.value)?.exists) return;\n\n report.error(attribute, `\"${attribute.value}\" does not exist`);\n}\n\n/** Reports an attribute whose value is not the JSON of an object. A value with a placeholder is left alone. */\nexport function checkJsonObject(attribute: AttributeInfo, report: ProblemReporter): void {\n if (!attribute.value) return;\n if (isDynamic(attribute.value)) return;\n if (isJsonObject(attribute.value)) return;\n\n report.error(attribute, `\"${attribute.name}\" must be a JSON object`);\n}\n\n/** Whether a string is the JSON of an object. */\nexport function isJsonObject(text: string): boolean {\n try {\n const parsed: unknown = JSON.parse(text);\n\n return typeof parsed === \"object\" && parsed !== null && !Array.isArray(parsed);\n } catch {\n return false;\n }\n}\n\n/** Whether a script element holds JavaScript, going by its `type`: the build leaves any other kind of script alone. */\nexport function isJavaScript(script: ElementInfo): boolean {\n return isScriptType(script.attribute(\"type\")?.value ?? null);\n}\n\n/** Whether a `<script>` is marked as TypeScript for the editor, which also keeps the editor's own script support out. */\nexport function isTypeScriptScript(script: ElementInfo): boolean {\n return script.attribute(\"type\")?.value?.toLowerCase() === TYPESCRIPT_TYPE;\n}\n\n/** Whether an element has nothing but whitespace between its tags. */\nexport function isEmptyElement(element: ElementInfo, document: DocumentInfo): boolean {\n if (!element.contentRange) {\n return true;\n }\n\n return document.textOf(element.contentRange).trim() === \"\";\n}\n","export type ValueOrError<T> = [T, null] | [null, Error];\n\nfunction errorsWrapper<T, A extends unknown[]>(function_: (...arguments_: A) => T | Promise<T>) {\n return (...arguments_: A) => {\n try {\n const promiseOrValue = function_(...arguments_);\n if (isPromise<T>(promiseOrValue)) {\n return new Promise(resolve => {\n promiseOrValue\n .then(value => {\n resolve([value, null]);\n })\n .catch((error: unknown) => {\n resolve(handleError(error, function_.name));\n });\n });\n }\n return [promiseOrValue, null];\n } catch (error) {\n return handleError(error, function_.name);\n }\n };\n}\n\nfunction isPromise<T>(value: T | Promise<T>): value is Promise<T> {\n return (\n value &&\n typeof value === \"object\" &&\n \"then\" in value &&\n typeof value.then === \"function\" &&\n \"catch\" in value &&\n typeof value.catch === \"function\"\n );\n}\n\nexport function handleError<T>(error: unknown, functionName = \"\"): ValueOrError<T> {\n if (!error) {\n return [null, new Error(`[${functionName}] Unexpected error`)];\n }\n\n if (typeof error === \"string\") {\n return [null, new Error(error)];\n }\n\n if (error instanceof Error) {\n return [null, error];\n }\n\n // in some cases the error is not an instance of Error but an object\n if (typeof error === \"object\" && \"message\" in error && typeof error.message === \"string\") {\n return [null, new Error(error.message)];\n }\n\n return [null, new Error(`[${functionName}] Unexpected error`)];\n}\n\ninterface goErrorsI {\n <T, A extends unknown[]>(function_: (...arguments_: A) => Promise<T>): (...arguments_: A) => Promise<ValueOrError<T>>;\n <T, A extends unknown[]>(function_: (...arguments_: A) => T): (...arguments_: A) => ValueOrError<T>;\n}\n\nexport const valueOrError = errorsWrapper as unknown as goErrorsI;\n","import type { Abortable } from \"node:events\";\nimport { readFileSync } from \"node:fs\";\nimport type { ObjectEncodingOptions, OpenMode, PathLike, PathOrFileDescriptor } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport type { FileHandle } from \"node:fs/promises\";\n\nimport { handleError } from \"./value-or-error.ts\";\n\nimport type { ValueOrError } from \"./value-or-error.ts\";\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options?:\n | ({\n encoding?: null | undefined;\n flag?: OpenMode | undefined;\n } & Abortable)\n | null\n): Promise<ValueOrError<Buffer>>;\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options:\n | ({\n encoding: BufferEncoding;\n flag?: OpenMode | undefined;\n } & Abortable)\n | BufferEncoding\n): Promise<ValueOrError<string>>;\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options?:\n | (ObjectEncodingOptions &\n Abortable & {\n flag?: OpenMode | undefined;\n })\n | BufferEncoding\n | null\n): Promise<ValueOrError<string | Buffer>>;\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options?:\n | (ObjectEncodingOptions &\n Abortable & {\n flag?: OpenMode | undefined;\n })\n | BufferEncoding\n | null\n): Promise<ValueOrError<string | Buffer>> {\n try {\n const string_ = await readFile(path, options);\n return [string_, null];\n } catch (error) {\n return handleError(error, \"readFile\");\n }\n}\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options?: {\n encoding?: null | undefined;\n flag?: string | undefined;\n } | null\n): ValueOrError<NonSharedBuffer>;\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options:\n | BufferEncoding\n | {\n encoding: BufferEncoding;\n flag?: string | undefined;\n }\n): ValueOrError<string>;\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options?:\n | (ObjectEncodingOptions & {\n flag?: string | undefined;\n })\n | BufferEncoding\n | null\n): ValueOrError<string | NonSharedBuffer>;\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options?:\n | (ObjectEncodingOptions & {\n flag?: string | undefined;\n })\n | BufferEncoding\n | null\n): ValueOrError<string | NonSharedBuffer> {\n try {\n const string_ = readFileSync(path, options);\n return [string_, null];\n } catch (error) {\n return handleError(error, \"readFileSync\");\n }\n}\n","import json5 from \"json5\";\n\nimport { safeReadFileSync } from \"./read-file.ts\";\nimport { valueOrError } from \"./value-or-error.ts\";\n\nimport type { ValueOrError } from \"./value-or-error.ts\";\n\n/** Read a file and parse it as JSON safely. */\nexport function readJsonFile<T>(path: string, code?: string): ValueOrError<T> {\n if (!code) {\n const [fileString, readError] = safeReadFileSync(path, \"utf8\");\n if (readError) {\n return [null, readError];\n }\n\n code = fileString;\n }\n\n const [parsed, parseError] = valueOrError(json5.parse<T>)(code);\n if (parseError !== null) {\n return [null, parseError];\n }\n\n return [parsed, null];\n}\n","import { join } from \"../utilities/path.ts\";\nimport { readJsonFile } from \"../utilities/read-json-file.ts\";\n\nimport type { ValueOrError } from \"../utilities/value-or-error.ts\";\nimport type { CompilerOptions } from \"typescript\";\n\n/** Gets path aliases from `tsconfig.json` */\nexport function getPathAliases(root: string): ValueOrError<Record<string, string>> {\n const [tsconfig, tsconfigParseError] = readTsconfig(root);\n if (tsconfigParseError !== null) {\n return [null, tsconfigParseError];\n }\n\n const paths = tsconfig.paths ?? {};\n const alias: Record<string, string> = {};\n\n for (const key in paths) {\n const aliasName = key.replace(/\\*$/, \"\");\n const aliasPath = paths[key][0].replace(/\\*$/, \"\");\n alias[aliasName] = aliasPath;\n }\n\n return [alias, null];\n}\n\nfunction readTsconfig(root: string): ValueOrError<CompilerOptions> {\n const tsconfigPath = join(root, \"tsconfig.json\");\n\n const [tsconfig, tsconfigParseError] = readJsonFile<{ compilerOptions: CompilerOptions }>(tsconfigPath);\n if (tsconfigParseError !== null) {\n return [null, tsconfigParseError];\n }\n\n if (!tsconfig.compilerOptions) {\n return [null, new Error(\"[readTsconfig] No compilerOptions found in tsconfig.json\")];\n }\n\n return [tsconfig.compilerOptions, null];\n}\n","import { existsSync, statSync } from \"node:fs\";\nimport { ResolverFactory } from \"oxc-resolver\";\n\nimport { isValidRelativePath, splitHtmlLink } from \"../utilities/html-links.ts\";\nimport { Log } from \"../utilities/logger.ts\";\nimport { dirname, extname, isAbsolute, join, normalize, replaceExtension } from \"../utilities/path.ts\";\nimport { getPathAliases } from \"./get-aliases.ts\";\n\nconst nodeModulesResolver = new ResolverFactory({\n conditionNames: [\"browser\", \"import\", \"default\"],\n extensions: [\".js\", \".json\", \".node\", \".css\"],\n symlinks: false,\n});\n\ntype ResolveResult = {\n path: string;\n suffix: string;\n isDirAlias?: boolean;\n isFileAlias?: boolean;\n isPackage?: boolean;\n exists: boolean;\n};\n\nexport class Resolver {\n root: string;\n isProduction: boolean;\n aliases: Record<string, string> = {};\n notFound: Set<string> = new Set();\n files: Set<string> = new Set();\n directories: Set<string> = new Set();\n misses: Set<string> = new Set();\n\n /** Whether a source that resolves to a missing file is logged, once. The result says so either way. */\n shouldWarnOnMissing: boolean;\n\n static JS_EXTENSIONS = new Set([\".js\", \".mjs\", \".cjs\", \".jsx\", \".ts\", \".mts\", \".cts\", \".tsx\"]);\n static HTML_EXTENSIONS = new Set([\".html\", \".md\"]);\n\n constructor(root: string, isProduction = false, configAliases: Record<string, string> = {}, shouldWarnOnMissing = true) {\n this.root = root;\n this.isProduction = isProduction;\n this.shouldWarnOnMissing = shouldWarnOnMissing;\n\n const [aliases] = getPathAliases(root);\n this.aliases = { ...aliases, ...configAliases };\n }\n\n resolve(sourceOrLink: string, filePath: string): ResolveResult | undefined {\n if (!isValidRelativePath(sourceOrLink)) return;\n\n const absFilePath = isAbsolute(filePath) ? filePath : join(this.root, filePath);\n const [source, suffix] = splitHtmlLink(sourceOrLink);\n\n // HTML links can be absolute E.g. /index.html\n if (isAbsolute(source)) {\n return;\n }\n\n const isDirectory = suffix === \"/\";\n\n // file or directory\n const absSource = join(dirname(absFilePath), source);\n const foundFile = this.findFile(absSource, isDirectory);\n if (foundFile) {\n return { path: foundFile, exists: true, suffix };\n }\n\n // path alias — restore the stripped trailing slash so \"~/\" aliases match\n const sourceForAlias = suffix === \"/\" ? source + \"/\" : source;\n const resolvedPathAlias = Resolver.resolvePathAlias(sourceForAlias, this.aliases);\n if (resolvedPathAlias) {\n const absSource = join(this.root, resolvedPathAlias);\n const foundFile = this.findFile(absSource, isDirectory);\n\n const isFileAlias = Object.hasOwn(this.aliases, sourceForAlias) && !sourceForAlias.endsWith(\"/\");\n\n if (!foundFile) {\n this.#warnMissing(\n absSource.replace(/\\/$/, \"\"),\n `[resolver] Source \"${sourceOrLink}\" found in \"${filePath}\" was resolved to \"${resolvedPathAlias}\", but the file is missing.`\n );\n }\n\n return { path: foundFile ?? absSource, exists: !!foundFile, suffix, isFileAlias, isDirAlias: !isFileAlias };\n }\n\n // node module package\n if (!source.startsWith(\".\")) {\n const resolverResult = nodeModulesResolver.sync(this.root, source);\n if (resolverResult.path) {\n return { path: resolverResult.path, suffix, exists: true, isPackage: true };\n }\n }\n\n // Not found, but its already a file path\n if (source.startsWith(\"./\") || source.startsWith(\"../\")) {\n this.#warnMissing(absSource, `[resolver] Source \"${sourceOrLink}\" found in \"${filePath}\" points to a non-existent file.`);\n\n return { path: absSource, suffix, exists: false };\n }\n }\n\n /** Logs a missing file the first time it is resolved to, when the resolver is set to. */\n #warnMissing(absSource: string, message: string): void {\n if (!this.shouldWarnOnMissing) return;\n if (this.notFound.has(absSource)) return;\n\n this.notFound.add(absSource);\n Log.warn(message);\n }\n\n resolveAlias(source: string): string | undefined {\n return Resolver.resolvePathAlias(source, this.aliases);\n }\n\n normalize(filePath: string): string {\n return normalize(filePath);\n }\n\n static isFile(filePath: string): boolean {\n try {\n return statSync(filePath).isFile();\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"ENOENT\" || code === \"ENOTDIR\") {\n return false;\n }\n\n throw error;\n }\n }\n\n /** Aliased path to path */\n static resolvePathAlias(filePath: string, aliases: Record<string, string>): string | undefined {\n for (const [key, value] of Object.entries(aliases)) {\n // directory path alias\n if (key.endsWith(\"/\")) {\n if (!filePath.startsWith(key)) {\n continue;\n }\n\n return filePath.replace(key, () => value);\n }\n\n // file path alias\n if (filePath === key) {\n return value;\n }\n }\n }\n\n /** Path to aliased path */\n static resolveAliasPath(filePath: string, aliases: Record<string, string>): string {\n let shortest: string | undefined;\n\n for (const [key, value] of Object.entries(aliases)) {\n // directory path alias\n if (key.endsWith(\"/\")) {\n if (!filePath.startsWith(value)) {\n continue;\n }\n\n const aliased = filePath.replace(value, () => key);\n if (!shortest || aliased.length < shortest.length) {\n shortest = aliased;\n }\n continue;\n }\n\n // file path alias\n if (filePath === value && (!shortest || key.length < shortest.length)) {\n shortest = key;\n }\n }\n\n return shortest ?? filePath;\n }\n\n /** Path to aliased path */\n aliasPath(filePath: string): string {\n return Resolver.resolveAliasPath(filePath, this.aliases);\n }\n\n findFile(filePath: string, shouldCheckDirectory = false): string | undefined {\n const missKey = (shouldCheckDirectory ? \"d:\" : \"f:\") + filePath;\n\n if (this.isProduction && this.misses.has(missKey)) {\n return;\n }\n\n const found = this.#findFileUncached(filePath, shouldCheckDirectory);\n\n if (found === undefined && this.isProduction) {\n this.misses.add(missKey);\n }\n\n return found;\n }\n\n #findFileUncached(filePath: string, shouldCheckDirectory: boolean): string | undefined {\n // From cache\n if (this.files.has(filePath)) {\n return filePath;\n }\n\n // Exact match\n if (Resolver.isFile(filePath)) {\n this.files.add(filePath);\n return filePath;\n }\n\n const extension = extname(filePath);\n\n // No extension\n if (!extension) {\n // it might be a js file, html file, markdown file or just a directory\n for (const candidateExtension of [...Resolver.JS_EXTENSIONS, ...Resolver.HTML_EXTENSIONS]) {\n const candidate = replaceExtension(filePath, candidateExtension);\n\n if (this.files.has(candidate)) {\n return candidate;\n }\n\n if (Resolver.isFile(candidate)) {\n this.files.add(candidate);\n return candidate;\n }\n }\n\n // it might be index.html or index.md\n const withIndex = join(filePath, \"index\");\n\n for (const candidateExtension of Resolver.HTML_EXTENSIONS) {\n const candidate = replaceExtension(withIndex, candidateExtension);\n\n if (this.files.has(candidate)) {\n return candidate;\n }\n\n if (Resolver.isFile(candidate)) {\n this.files.add(candidate);\n return candidate;\n }\n }\n\n // directory\n if (shouldCheckDirectory) {\n if (this.directories.has(filePath)) {\n return filePath;\n }\n\n if (existsSync(filePath)) {\n this.directories.add(filePath);\n return filePath;\n }\n }\n\n return;\n }\n\n // main.js does not exist but main{.jsx, .ts, .tsx} may exist\n if (Resolver.JS_EXTENSIONS.has(extension)) {\n for (const jsExtension of Resolver.JS_EXTENSIONS) {\n const candidate = replaceExtension(filePath, jsExtension);\n\n if (Resolver.isFile(candidate)) {\n this.files.add(candidate);\n return candidate;\n }\n }\n\n return;\n }\n }\n}\n","import type { BabelAst, PostcssAst, Document, MarkdownAst } from \"@staticbolt/core\";\nimport type { WebAppManifest } from \"web-app-manifest\";\n\nexport const METADATA_TYPES = Object.freeze({\n Script: \"Script\",\n HTML: \"Html\",\n Markdown: \"Markdown\",\n CSS: \"Style\",\n SVG: \"Svg\",\n Package: \"Package\",\n TextAsset: \"TextAsset\",\n BinaryAsset: \"BinaryAsset\",\n WebAppManifest: \"WebAppManifest\",\n});\n\nexport type MetadataTypes = (typeof METADATA_TYPES)[keyof typeof METADATA_TYPES];\n\nexport interface MetadataBase {\n readonly type: `${Capitalize<string>}${string}`;\n\n /**\n * Relative path of the source file.\n *\n * Initially identical to `originalSource` when the metadata is created. During the build process, this value may change (e.g.,\n * if the file is moved to a different location and its links are rebased).\n */\n filePath: string;\n\n /**\n * Original relative path of the source file.\n *\n * Set when the metadata is created and never modified.\n */\n readonly id: string;\n\n readonly directDependencies: Set<string>;\n}\n\nexport interface ScriptMetadata extends MetadataBase {\n readonly type: (typeof METADATA_TYPES)[\"Script\"];\n\n /**\n * The Babel AST for the script.\n *\n * Mutated during the build process and always represents the file's current transformed state.\n */\n ast: BabelAst;\n\n /** Whether the script is a module or global */\n module: boolean;\n}\n\nexport interface StyleMetadata extends MetadataBase {\n readonly type: (typeof METADATA_TYPES)[\"CSS\"];\n\n /**\n * The PostCSS root after transformation\n *\n * Mutated during the build process and always represents the file's current transformed state.\n */\n ast: PostcssAst;\n}\n\nexport interface HtmlMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"HTML\"];\n\n /**\n * The HTML AST (root element).\n *\n * Mutated during the build process and always represents the file's current transformed state\n */\n ast: Document;\n\n /** The transformed ASTs from script tags. The key is the UUID */\n scriptsMetadataList: Map<string, ScriptMetadata>;\n\n /** The transformed ASTs from script tags. The key is the UUID */\n stylesMetadataList: Map<string, StyleMetadata>;\n}\n\nexport interface SvgMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"SVG\"];\n\n /**\n * The HTML AST (root element).\n *\n * Mutated during the build process and always represents the file's current transformed state\n */\n ast: Document;\n\n /** The transformed ASTs from script tags. The key is the UUID */\n stylesMetadataList: Map<string, StyleMetadata>;\n}\n\nexport interface MarkdownMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"Markdown\"];\n\n /**\n * Markdown tokens and frontmatter.\n *\n * Mutated during the build process and always represents the file's current transformed state\n */\n ast: MarkdownAst;\n}\n\nexport interface WebManifestMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"WebAppManifest\"];\n ast: WebAppManifest;\n}\n\nexport interface PackageMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"Package\"];\n\n /** Metadata code */\n code: string;\n\n packageName: string;\n}\n\nexport interface TextAssetMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"TextAsset\"];\n\n /** Metadata code */\n code: string;\n}\n\nexport interface BinaryAssetMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"BinaryAsset\"];\n\n /** Raw binary content — images, fonts, wasm, etc. */\n data?: Uint8Array;\n}\n","import { isScriptType } from \"../helpers/is-script-type.ts\";\nimport { CUSTOM_ATTRIBUTES } from \"../types/common.ts\";\nimport { METADATA_TYPES } from \"../types/metadata.ts\";\n\nimport type {\n TextAssetMetadata,\n HtmlMetadata,\n MarkdownMetadata,\n MetadataBase,\n ScriptMetadata,\n StyleMetadata,\n SvgMetadata,\n WebManifestMetadata,\n BinaryAssetMetadata,\n PackageMetadata,\n HTMLElement,\n} from \"@staticbolt/core\";\n\nexport function isScriptMetadata(metadata: MetadataBase | undefined): metadata is ScriptMetadata {\n return metadata?.type === METADATA_TYPES.Script;\n}\n\nexport function isPackageMetadata(metadata: MetadataBase | undefined): metadata is PackageMetadata {\n return metadata?.type === METADATA_TYPES.Package;\n}\n\nexport function isHtmlMetadata(metadata: MetadataBase | undefined): metadata is HtmlMetadata {\n return metadata?.type === METADATA_TYPES.HTML;\n}\n\nexport function isStyleMetadata(metadata: MetadataBase | undefined): metadata is StyleMetadata {\n return metadata?.type === METADATA_TYPES.CSS;\n}\n\nexport function isSvgMetadata(metadata: MetadataBase | undefined): metadata is SvgMetadata {\n return metadata?.type === METADATA_TYPES.SVG;\n}\n\nexport function isMarkdownMetadata(metadata: MetadataBase | undefined): metadata is MarkdownMetadata {\n return metadata?.type === METADATA_TYPES.Markdown;\n}\n\nexport function isTextAssetMetadata(metadata: MetadataBase | undefined): metadata is TextAssetMetadata {\n return metadata?.type === METADATA_TYPES.TextAsset;\n}\n\nexport function isBinaryAssetMetadata(metadata: MetadataBase | undefined): metadata is BinaryAssetMetadata {\n return metadata?.type === METADATA_TYPES.BinaryAsset;\n}\n\nexport function isWebManifestMetadata(metadata: MetadataBase): metadata is WebManifestMetadata {\n return metadata.type === METADATA_TYPES.WebAppManifest;\n}\n\n/**\n * Returns script-related metadata entries.\n *\n * - If the input is ScriptMetadata, it returns it directly.\n * - If the input is HtmlMetadata, it scans <script> tags in the AST and resolves their associated ScriptMetadata using the metadata\n * ID attribute.\n */\nexport function filterScriptMetadata(metadata: MetadataBase) {\n const result: { metadata: ScriptMetadata; tag?: HTMLElement; htmlMetadata?: HtmlMetadata }[] = [];\n\n if (isScriptMetadata(metadata)) {\n result.push({ metadata });\n return result;\n }\n\n if (isHtmlMetadata(metadata)) {\n const scriptTags = metadata.ast.querySelectorAll(\"script\");\n\n for (const scriptTag of scriptTags) {\n const scriptId = scriptTag.getAttribute(CUSTOM_ATTRIBUTES.MetadataID);\n if (!scriptId) continue;\n\n const scriptType = scriptTag.getAttribute(\"type\");\n if (!isScriptType(scriptType)) {\n continue;\n }\n\n const scriptMetadata = metadata.scriptsMetadataList.get(scriptId);\n if (!scriptMetadata) continue;\n\n result.push({ metadata: scriptMetadata, htmlMetadata: metadata, tag: scriptTag });\n }\n }\n\n return result;\n}\n\n/**\n * Returns style-related metadata entries.\n *\n * - If the input is StyleMetadata, it returns it directly.\n * - If the input is HtmlMetadata, it scans <style> tags in the AST and resolves their associated StyleMetadata using the metadata\n * ID attribute.\n */\nexport function filterStyleMetadata(metadata: MetadataBase) {\n const result: { metadata: StyleMetadata; tag?: HTMLElement; htmlMetadata?: HtmlMetadata }[] = [];\n\n if (isStyleMetadata(metadata)) {\n result.push({ metadata });\n return result;\n }\n\n if (isHtmlMetadata(metadata)) {\n const styleTags = metadata.ast.querySelectorAll(\"style\");\n\n for (const styleTag of styleTags) {\n const styleId = styleTag.getAttribute(CUSTOM_ATTRIBUTES.MetadataID) || \"\";\n const styleMetadata = metadata.stylesMetadataList.get(styleId);\n if (!styleMetadata) continue;\n\n result.push({\n metadata: styleMetadata,\n htmlMetadata: metadata,\n tag: styleTag,\n });\n }\n }\n\n return result;\n}\n","import boxen from \"boxen\";\nimport chalk from \"chalk\";\nimport { common, createEmphasize } from \"emphasize\";\n\n/** - Highlight code string for terminal */\nexport function highlightCode(code: string, { lang = \"ts\", maxCodeLength = 170, maxLineLength = 110, boxed = true } = {}) {\n // Limit code length\n const isTruncated = code.length > maxCodeLength;\n if (isTruncated) code = code.slice(0, Math.max(0, maxCodeLength));\n\n // Limit line length and break on words\n const lines = code.split(\"\\n\");\n let withNewLines = \"\";\n for (const line of lines) {\n if (line.length <= maxLineLength) {\n withNewLines += line + \"\\n\";\n continue;\n }\n\n const words = line.split(\" \");\n let currentLine = \"\";\n for (const word of words) {\n if (currentLine.length + word.length <= maxLineLength) {\n currentLine += word + \" \";\n continue;\n }\n withNewLines += currentLine + \"\\n\";\n currentLine = word + \" \";\n }\n withNewLines += currentLine + \"\\n\";\n }\n\n // Highlight\n let highlighted = createEmphasize(common).highlight(lang, withNewLines.trim()).value;\n if (isTruncated) highlighted += \"\\n\" + chalk.inverse(\" ... \");\n\n if (!boxed) return highlighted;\n\n return boxen(highlighted, {\n padding: 0.5,\n borderStyle: \"round\",\n borderColor: \"white\",\n dimBorder: true,\n });\n}\n","import _generator from \"@babel/generator\";\nimport { NodeType } from \"@staticbolt/node-html-parser\";\nimport c from \"chalk\";\nimport { Node as PostcssNode } from \"postcss\";\n\nimport { CUSTOM_ATTRIBUTES } from \"../types/common.ts\";\nimport { highlightCode } from \"./highlight-code.ts\";\nimport { Log } from \"./logger.ts\";\n\nimport type { Node as BabelNode } from \"@babel/types\";\nimport type { Node as HtmlNode } from \"@staticbolt/node-html-parser\";\n\nconst generator = typeof _generator === \"function\" ? _generator : _generator.default;\n\ntype Node = BabelNode | PostcssNode | HtmlNode;\n\ninterface FormatErrorOptions {\n /** AST node (e.g., from Babel, PostCSS, or HTML) to convert and highlight */\n node?: Node;\n\n /** Source code to highlight (use instead of `node`) */\n code?: string;\n\n /** Language of the provided source code (required if `code` is set) */\n lang?: string;\n\n /** Path of the file where the error occurred */\n filePath?: string;\n\n /** Name of the function where the error originated */\n functionName?: string;\n\n level?: \"error\" | \"warning\";\n\n /** Function reference used to extract the function name */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function?: (...arguments_: any[]) => any;\n}\n\ntype MessageAndError = (string | Error)[];\n\nexport class PrintFormattedError {\n options: FormatErrorOptions = {};\n\n constructor(options: FormatErrorOptions = {}) {\n Object.assign(this.options, options);\n }\n\n static create(options: FormatErrorOptions = {}) {\n return new PrintFormattedError(options).print;\n }\n\n print = (...messageAndErrorWithOptions: [...MessageAndError] | [...MessageAndError, FormatErrorOptions]) => {\n const options: FormatErrorOptions = { ...this.options };\n\n const messagesArray: string[] = [];\n for (const item of messageAndErrorWithOptions) {\n // Msg\n if (typeof item === \"string\") {\n messagesArray.push(item);\n continue;\n }\n\n // Error\n if (item instanceof Error) {\n messagesArray.push(`\\n${item.message}`);\n continue;\n }\n\n // Options\n Object.assign(options, item);\n }\n\n let message = \"\";\n\n // First file path in one line without anything else to enable vscode link parsing\n if (options.filePath) {\n message += c.italic(options.filePath) + \"\\n\";\n }\n\n // Then the function name before the messages\n const functionName = options.function?.name ?? options.functionName;\n if (functionName) {\n message += c.dim(`[${functionName}] `);\n }\n\n // Then the messages (spaced)\n message += messagesArray.join(\" \");\n\n // Now the code\n const codeFromNode = options.node && nodeToString(options.node);\n const code = options.code ?? codeFromNode?.code;\n const lang = options.lang ?? codeFromNode?.lang;\n const codeBox = code && lang ? highlightCode(code, { lang }) : \"\";\n if (codeBox) {\n message += \"\\n\" + codeBox;\n }\n\n if (options.level === \"warning\") {\n Log.warn(message);\n return;\n }\n\n Log.error(message);\n };\n}\n\nexport const printFmtError = PrintFormattedError.create();\n\nfunction isHtmlNode(node: Node): node is HtmlNode {\n return \"nodeType\" in node && typeof node.nodeType === \"number\";\n}\n\nfunction isPostcssNode(node: Node): node is PostcssNode {\n return node instanceof PostcssNode;\n}\n\nfunction nodeToString(node: Node): { code: string; lang: string } {\n if (isHtmlNode(node)) {\n const clone = node.clone();\n if (clone.nodeType === NodeType.ELEMENT_NODE) {\n clone.removeAttribute(CUSTOM_ATTRIBUTES.MetadataID);\n }\n\n return { code: clone.toString(), lang: \"html\" };\n }\n\n if (isPostcssNode(node)) {\n return { code: node.toString(), lang: \"css\" };\n }\n\n return { code: generator(node, { jsescOption: { minimal: true } }).code, lang: \"js\" };\n}\n","import { createHash } from \"node:crypto\";\n\nimport { Log } from \"./logger.ts\";\n\nimport type { ValueOrError } from \"./value-or-error.ts\";\n\n/** `process.stdout.write` */\nexport function print(...input: string[]) {\n process.stdout.write(input.join(\" \"));\n}\n\n/** - Clear the line in the terminal */\nexport function clearLn() {\n if (!(\"clearLine\" in process.stdout && typeof process.stdout.clearLine === \"function\")) {\n return;\n }\n\n process.stdout.clearLine(0);\n process.stdout.cursorTo(0);\n}\n\n/** Used to assign a computed value to a variable */\nexport function assign<T>(function_: () => T): T {\n return function_();\n}\n\n/** Check if the value is an object */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && !Array.isArray(value) && value !== null;\n}\n\nexport function kebabToCamelCase(string_: string): string {\n return string_.replace(/-([a-z])/g, (_, char) => (char as string).toUpperCase());\n}\n\nexport function camelCaseToKebabCase(string_: string): string {\n return string_.replace(/([a-z])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\nexport function capitalize(string_: string): string {\n return string_.charAt(0).toUpperCase() + string_.slice(1);\n}\n\n/**\n * - Get line and column number from first match index\n *\n * @param code - Code string\n * @param matchIndex - Matching index\n * @returns - `[line, column]`\n */\nexport function getLineColumn(code: string, matchIndex: number): [number, number] {\n let lineNumber = 1;\n let columnNumber = 1;\n\n for (let index = 0; index < matchIndex; index++) {\n if (code[index] === \"\\n\") {\n lineNumber++;\n columnNumber = 1; // Reset column at each new line\n continue;\n }\n\n columnNumber++;\n }\n\n return [lineNumber, columnNumber];\n}\n\n/** - Human readable bytes, E.g: `1024 => 1KB` */\nexport function humanReadableBytes(bytes: number): string {\n const units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n let unitIndex = 0;\n while (bytes >= 1024 && unitIndex < units.length - 1) {\n bytes /= 1024;\n unitIndex++;\n }\n return `${bytes.toFixed(2)} ${units[unitIndex]}`;\n}\n\nexport function bytesToKB(bytes: number): number {\n return bytes / 1024;\n}\n\n/** - Clamp a numeric value between min and max values. */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nexport function isDefined<T>(value: T | undefined): value is T {\n return value !== undefined;\n}\n\n/**\n * Merges all entries from `source` into `target`, mutating `target` in place.\n *\n * - Existing keys in `target` are overwritten by `source` values.\n * - Values are **not** cloned — object references are shared between both maps after the merge.\n *\n * @param target - The map to be mutated with new/updated entries.\n * @param source - The map whose entries are read and applied to `target`.\n * @returns The mutated `target` map.\n */\nexport function mergeMaps<K, V>(target: Map<K, V>, source: Map<K, V>): Map<K, V> {\n for (const [key, value] of source) {\n target.set(key, value);\n }\n return target;\n}\n\nconst cached = new Map<string, string>();\n\n/** - Download from CDN */\nexport async function downloadContent(url: string): Promise<ValueOrError<string>> {\n if (cached.has(url)) {\n return [cached.get(url)!, null];\n }\n\n const headers = {\n \"User-Agent\":\n \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36\",\n Accept: \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\",\n Referer: url,\n };\n\n try {\n Log.info(`Downloading content from \"${url}\"`);\n const response = await fetch(url, { headers });\n const text = await response.text();\n cached.set(url, text);\n return [text, null];\n } catch {\n return [null, new Error(\"Error downloading q: \" + url)];\n }\n}\n\nexport function isURL(url: string): boolean {\n return url.startsWith(\"http://\") || url.startsWith(\"https://\");\n}\n\n/** Creates a shallow clone of an object while preserving its prototype and property descriptors. */\nexport function cloneObject<T extends object>(object: T): T {\n return Object.create(Object.getPrototypeOf(object) as T, Object.getOwnPropertyDescriptors(object)) as T;\n}\n\nexport function hashContent(content: string) {\n return createHash(\"sha1\").update(content).digest(\"hex\"); // full 40 chars\n}\n\nconst matchHtmlRegExp = /[\"'&<>]/;\n\nexport function escapeHtml(input: string) {\n const string = input;\n const match = matchHtmlRegExp.exec(string);\n\n if (!match) {\n return string;\n }\n\n let escape;\n let html = \"\";\n // eslint-disable-next-line no-useless-assignment\n let index = 0;\n let lastIndex = 0;\n\n for (index = match.index; index < string.length; index++) {\n switch (string.codePointAt(index)) {\n case 34: {\n // \"\n escape = \""\";\n break;\n }\n case 38: {\n // &\n escape = \"&\";\n break;\n }\n case 39: {\n // '\n escape = \"'\";\n break;\n }\n case 60: {\n // <\n escape = \"<\";\n break;\n }\n case 62: {\n // >\n escape = \">\";\n break;\n }\n default: {\n continue;\n }\n }\n\n if (lastIndex !== index) {\n html += string.slice(lastIndex, index);\n }\n\n lastIndex = index + 1;\n html += escape;\n }\n\n return lastIndex === index ? html : html + string.slice(lastIndex, index);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,IAAa,oBAAb,MAA+B;;CAE7B,AAASA,sCAAsB,IAAI,IAAyB;;CAG5D,AAASC,qCAAqB,IAAI,IAAyB;;CAG3D,OAAO,UAAkB,SAAiC;EACxD,MAAM,cAAc,IAAI,IAAI,OAAO;EACnC,MAAM,kBAAkB,KAAKA,mBAAmB,IAAI,Q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
|
5
5
|
"author": "Ahmed ALABSI",
|
|
6
6
|
"bin": {
|
|
7
7
|
"staticbolt": "lib/cli/index.mjs"
|
|
@@ -76,21 +76,25 @@
|
|
|
76
76
|
".": {
|
|
77
77
|
"types": "./lib/index.d.mts",
|
|
78
78
|
"node": "./lib/index.mjs",
|
|
79
|
+
"source": "./src/index.ts",
|
|
79
80
|
"default": "./lib/index.mjs"
|
|
80
81
|
},
|
|
81
82
|
"./plugins": {
|
|
82
83
|
"types": "./lib/plugins/index.d.mts",
|
|
83
84
|
"node": "./lib/plugins/index.mjs",
|
|
85
|
+
"source": "./src/plugins/index.ts",
|
|
84
86
|
"default": "./lib/plugins/index.mjs"
|
|
85
87
|
},
|
|
86
88
|
"./deferred": {
|
|
87
89
|
"types": "./lib/deferred.d.mts",
|
|
88
90
|
"node": "./lib/deferred.mjs",
|
|
91
|
+
"source": "./src/deferred.ts",
|
|
89
92
|
"default": "./lib/deferred.mjs"
|
|
90
93
|
},
|
|
91
94
|
"./deferred-worker": {
|
|
92
95
|
"types": "./lib/plugins/write-files/deferred-worker.d.mts",
|
|
93
96
|
"node": "./lib/plugins/write-files/deferred-worker.mjs",
|
|
97
|
+
"source": "./src/plugins/write-files/deferred-worker.ts",
|
|
94
98
|
"default": "./lib/plugins/write-files/deferred-worker.mjs"
|
|
95
99
|
}
|
|
96
100
|
},
|
|
@@ -102,13 +106,13 @@
|
|
|
102
106
|
],
|
|
103
107
|
"license": "MIT",
|
|
104
108
|
"peerDependencies": {
|
|
105
|
-
"@staticbolt/args-parser": "1.0.0-beta.
|
|
106
|
-
"@staticbolt/node-html-parser": "1.0.0-beta.
|
|
109
|
+
"@staticbolt/args-parser": "1.0.0-beta.31",
|
|
110
|
+
"@staticbolt/node-html-parser": "1.0.0-beta.31"
|
|
107
111
|
},
|
|
108
112
|
"private": false,
|
|
109
113
|
"scripts": {
|
|
110
114
|
"build": "tsdown && npm run generate-cli-documentation",
|
|
111
|
-
"fix-lint": "
|
|
115
|
+
"fix-lint": "cd ../.. && eslint --fix packages/core",
|
|
112
116
|
"generate-cli-documentation": "node scripts/generate-cli-docs.js",
|
|
113
117
|
"prepack": "npm run build",
|
|
114
118
|
"ts-check": "tsc --noEmit",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utilities-D0KXIZ-B.mjs","names":["#sourcesToImporters","#importerToSources","#findFileUncached","c","PostcssNode"],"sources":["../src/helpers/dependency-tracker.ts","../src/utilities/html-links.ts","../src/utilities/value-or-error.ts","../src/utilities/read-file.ts","../src/utilities/read-json-file.ts","../src/resolver/get-aliases.ts","../src/resolver/resolver.ts","../src/types/metadata.ts","../src/helpers/is-script-type.ts","../src/utilities/metadata-utilities.ts","../src/utilities/highlight-code.ts","../src/utilities/print-formatted-error.ts","../src/utilities/utilities.ts"],"sourcesContent":["/**\n * Tracks bidirectional dependencies between importers and their sources.\\\n * Handles reconciliation when dependencies change, so stale entries are automatically removed when an importer stops referencing\n * a source.\n */\nexport class DependencyTracker {\n /** Source → Set of importers that depend on it */\n readonly #sourcesToImporters = new Map<string, Set<string>>();\n\n /** Importer → Set of sources it depends on */\n readonly #importerToSources = new Map<string, Set<string>>();\n\n /** Updates the full set of sources for a given importer, reconciling any stale entries from previous calls. */\n update(importer: string, sources: Iterable<string>): void {\n const nextSources = new Set(sources);\n const previousSources = this.#importerToSources.get(importer) ?? new Set();\n\n // Remove importer from sources it no longer uses\n for (const source of previousSources) {\n if (!nextSources.has(source)) {\n this.#sourcesToImporters.get(source)?.delete(importer);\n }\n }\n\n // Add importer to newly referenced sources\n for (const source of nextSources) {\n if (!this.#sourcesToImporters.has(source)) {\n this.#sourcesToImporters.set(source, new Set());\n }\n\n this.#sourcesToImporters.get(source)!.add(importer);\n }\n\n this.#importerToSources.set(importer, nextSources);\n }\n\n /** Deletes all dependency data for a given id, whether it's acting as an importer, a source, or both (e.g. on file unlink). */\n delete(id: string): void {\n // id was a source — drop it entirely\n this.#sourcesToImporters.delete(id);\n\n // id was an importer — remove it from all sources it referenced\n const sources = this.#importerToSources.get(id);\n if (sources) {\n for (const source of sources) {\n this.#sourcesToImporters.get(source)?.delete(id);\n }\n\n this.#importerToSources.delete(id);\n }\n }\n\n /** Returns all importers that depend on a given source, or an empty set. */\n getImporters(source: string): ReadonlySet<string> {\n return this.#sourcesToImporters.get(source) ?? new Set();\n }\n\n /** Returns all sources that a given importer depends on, or an empty set. */\n getSources(importer: string): ReadonlySet<string> {\n return this.#importerToSources.get(importer) ?? new Set();\n }\n}\n","import { isAbsolute } from \"./path.ts\";\n\n/**\n * Checks if the link is an HTML link (not a file link)\n *\n * @param source - The link\n * @returns\n */\nexport function isHtmlLink(source: string): boolean {\n return /^(?:#|https?|mailto:|tel:|url\\(|ftp:|data:|javascript:)/i.test(source);\n}\n\nexport function isValidRelativePath(source: string): boolean {\n if (!source) return false;\n // if (source.includes(\" \")) return false;\n if (isAbsolute(source)) return false;\n return !isHtmlLink(source);\n}\n\nexport function splitHtmlLink(url: string): [string, string] {\n const qIndex = url.indexOf(\"?\");\n const hIndex = url.indexOf(\"#\");\n\n // Find the earliest query/hash delimiter\n let delimIndex = -1;\n\n if (qIndex !== -1 && hIndex !== -1) {\n delimIndex = Math.min(qIndex, hIndex);\n }\n //\n else if (qIndex !== -1) {\n delimIndex = qIndex;\n }\n //\n else if (hIndex !== -1) {\n delimIndex = hIndex;\n }\n\n if (delimIndex !== -1) {\n // If a '/' immediately precedes the delimiter, include it in the suffix\n const pathEnd = url[delimIndex - 1] === \"/\" ? delimIndex - 1 : delimIndex;\n return [url.slice(0, pathEnd), url.slice(pathEnd)];\n }\n\n // No query or hash — handle trailing slash\n if (url.endsWith(\"/\")) {\n // Bare \"/\" or \"./\" are kept whole\n if (url === \"/\" || url === \"./\") {\n return [url, \"\"];\n }\n\n return [url.slice(0, -1), \"/\"];\n }\n\n return [url, \"\"];\n}\n","export type ValueOrError<T> = [T, null] | [null, Error];\n\nfunction errorsWrapper<T, A extends unknown[]>(function_: (...arguments_: A) => T | Promise<T>) {\n return (...arguments_: A) => {\n try {\n const promiseOrValue = function_(...arguments_);\n if (isPromise<T>(promiseOrValue)) {\n return new Promise(resolve => {\n promiseOrValue\n .then(value => {\n resolve([value, null]);\n })\n .catch((error: unknown) => {\n resolve(handleError(error, function_.name));\n });\n });\n }\n return [promiseOrValue, null];\n } catch (error) {\n return handleError(error, function_.name);\n }\n };\n}\n\nfunction isPromise<T>(value: T | Promise<T>): value is Promise<T> {\n return (\n value &&\n typeof value === \"object\" &&\n \"then\" in value &&\n typeof value.then === \"function\" &&\n \"catch\" in value &&\n typeof value.catch === \"function\"\n );\n}\n\nexport function handleError<T>(error: unknown, functionName = \"\"): ValueOrError<T> {\n if (!error) {\n return [null, new Error(`[${functionName}] Unexpected error`)];\n }\n\n if (typeof error === \"string\") {\n return [null, new Error(error)];\n }\n\n if (error instanceof Error) {\n return [null, error];\n }\n\n // in some cases the error is not an instance of Error but an object\n if (typeof error === \"object\" && \"message\" in error && typeof error.message === \"string\") {\n return [null, new Error(error.message)];\n }\n\n return [null, new Error(`[${functionName}] Unexpected error`)];\n}\n\ninterface goErrorsI {\n <T, A extends unknown[]>(function_: (...arguments_: A) => Promise<T>): (...arguments_: A) => Promise<ValueOrError<T>>;\n <T, A extends unknown[]>(function_: (...arguments_: A) => T): (...arguments_: A) => ValueOrError<T>;\n}\n\nexport const valueOrError = errorsWrapper as unknown as goErrorsI;\n","import type { Abortable } from \"node:events\";\nimport { readFileSync } from \"node:fs\";\nimport type { ObjectEncodingOptions, OpenMode, PathLike, PathOrFileDescriptor } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport type { FileHandle } from \"node:fs/promises\";\n\nimport { handleError } from \"./value-or-error.ts\";\n\nimport type { ValueOrError } from \"./value-or-error.ts\";\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options?:\n | ({\n encoding?: null | undefined;\n flag?: OpenMode | undefined;\n } & Abortable)\n | null\n): Promise<ValueOrError<Buffer>>;\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options:\n | ({\n encoding: BufferEncoding;\n flag?: OpenMode | undefined;\n } & Abortable)\n | BufferEncoding\n): Promise<ValueOrError<string>>;\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options?:\n | (ObjectEncodingOptions &\n Abortable & {\n flag?: OpenMode | undefined;\n })\n | BufferEncoding\n | null\n): Promise<ValueOrError<string | Buffer>>;\n\nexport async function safeReadFile(\n path: PathLike | FileHandle,\n options?:\n | (ObjectEncodingOptions &\n Abortable & {\n flag?: OpenMode | undefined;\n })\n | BufferEncoding\n | null\n): Promise<ValueOrError<string | Buffer>> {\n try {\n const string_ = await readFile(path, options);\n return [string_, null];\n } catch (error) {\n return handleError(error, \"readFile\");\n }\n}\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options?: {\n encoding?: null | undefined;\n flag?: string | undefined;\n } | null\n): ValueOrError<NonSharedBuffer>;\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options:\n | BufferEncoding\n | {\n encoding: BufferEncoding;\n flag?: string | undefined;\n }\n): ValueOrError<string>;\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options?:\n | (ObjectEncodingOptions & {\n flag?: string | undefined;\n })\n | BufferEncoding\n | null\n): ValueOrError<string | NonSharedBuffer>;\n\nexport function safeReadFileSync(\n path: PathOrFileDescriptor,\n options?:\n | (ObjectEncodingOptions & {\n flag?: string | undefined;\n })\n | BufferEncoding\n | null\n): ValueOrError<string | NonSharedBuffer> {\n try {\n const string_ = readFileSync(path, options);\n return [string_, null];\n } catch (error) {\n return handleError(error, \"readFileSync\");\n }\n}\n","import json5 from \"json5\";\n\nimport { safeReadFileSync } from \"./read-file.ts\";\nimport { valueOrError } from \"./value-or-error.ts\";\n\nimport type { ValueOrError } from \"./value-or-error.ts\";\n\n/** Read a file and parse it as JSON safely. */\nexport function readJsonFile<T>(path: string, code?: string): ValueOrError<T> {\n if (!code) {\n const [fileString, readError] = safeReadFileSync(path, \"utf8\");\n if (readError) {\n return [null, readError];\n }\n\n code = fileString;\n }\n\n const [parsed, parseError] = valueOrError(json5.parse<T>)(code);\n if (parseError !== null) {\n return [null, parseError];\n }\n\n return [parsed, null];\n}\n","import { join } from \"../utilities/path.ts\";\nimport { readJsonFile } from \"../utilities/read-json-file.ts\";\n\nimport type { ValueOrError } from \"../utilities/value-or-error.ts\";\nimport type { CompilerOptions } from \"typescript\";\n\n/** Gets path aliases from `tsconfig.json` */\nexport function getPathAliases(root: string): ValueOrError<Record<string, string>> {\n const [tsconfig, tsconfigParseError] = readTsconfig(root);\n if (tsconfigParseError !== null) {\n return [null, tsconfigParseError];\n }\n\n const paths = tsconfig.paths ?? {};\n const alias: Record<string, string> = {};\n\n for (const key in paths) {\n const aliasName = key.replace(/\\*$/, \"\");\n const aliasPath = paths[key][0].replace(/\\*$/, \"\");\n alias[aliasName] = aliasPath;\n }\n\n return [alias, null];\n}\n\nfunction readTsconfig(root: string): ValueOrError<CompilerOptions> {\n const tsconfigPath = join(root, \"tsconfig.json\");\n\n const [tsconfig, tsconfigParseError] = readJsonFile<{ compilerOptions: CompilerOptions }>(tsconfigPath);\n if (tsconfigParseError !== null) {\n return [null, tsconfigParseError];\n }\n\n if (!tsconfig.compilerOptions) {\n return [null, new Error(\"[readTsconfig] No compilerOptions found in tsconfig.json\")];\n }\n\n return [tsconfig.compilerOptions, null];\n}\n","import { existsSync, statSync } from \"node:fs\";\nimport { ResolverFactory } from \"oxc-resolver\";\n\nimport { isValidRelativePath, splitHtmlLink } from \"../utilities/html-links.ts\";\nimport { Log } from \"../utilities/logger.ts\";\nimport { dirname, extname, isAbsolute, join, normalize, replaceExtension } from \"../utilities/path.ts\";\nimport { getPathAliases } from \"./get-aliases.ts\";\n\nconst nodeModulesResolver = new ResolverFactory({\n conditionNames: [\"browser\", \"import\", \"default\"],\n extensions: [\".js\", \".json\", \".node\", \".css\"],\n symlinks: false,\n});\n\ntype ResolveResult = {\n path: string;\n suffix: string;\n isDirAlias?: boolean;\n isFileAlias?: boolean;\n isPackage?: boolean;\n exists: boolean;\n};\n\nexport class Resolver {\n root: string;\n isProduction: boolean;\n aliases: Record<string, string> = {};\n notFound: Set<string> = new Set();\n files: Set<string> = new Set();\n directories: Set<string> = new Set();\n misses: Set<string> = new Set();\n\n static JS_EXTENSIONS = new Set([\".js\", \".mjs\", \".cjs\", \".jsx\", \".ts\", \".mts\", \".cts\", \".tsx\"]);\n static HTML_EXTENSIONS = new Set([\".html\", \".md\"]);\n\n constructor(root: string, isProduction = false, configAliases: Record<string, string> = {}) {\n this.root = root;\n this.isProduction = isProduction;\n\n const [aliases] = getPathAliases(root);\n this.aliases = { ...aliases, ...configAliases };\n }\n\n resolve(sourceOrLink: string, filePath: string): ResolveResult | undefined {\n if (!isValidRelativePath(sourceOrLink)) return;\n\n const absFilePath = isAbsolute(filePath) ? filePath : join(this.root, filePath);\n const [source, suffix] = splitHtmlLink(sourceOrLink);\n\n // HTML links can be absolute E.g. /index.html\n if (isAbsolute(source)) {\n return;\n }\n\n const isDirectory = suffix === \"/\";\n\n // file or directory\n const absSource = join(dirname(absFilePath), source);\n const foundFile = this.findFile(absSource, isDirectory);\n if (foundFile) {\n return { path: foundFile, exists: true, suffix };\n }\n\n // path alias — restore the stripped trailing slash so \"~/\" aliases match\n const sourceForAlias = suffix === \"/\" ? source + \"/\" : source;\n const resolvedPathAlias = Resolver.resolvePathAlias(sourceForAlias, this.aliases);\n if (resolvedPathAlias) {\n const absSource = join(this.root, resolvedPathAlias);\n const foundFile = this.findFile(absSource, isDirectory);\n\n const isFileAlias = Object.hasOwn(this.aliases, sourceForAlias) && !sourceForAlias.endsWith(\"/\");\n\n // Warn once when a resolved source cannot be found on disk.\n if (!foundFile && !this.notFound.has(absSource.replace(/\\/$/, \"\"))) {\n this.notFound.add(absSource.replace(/\\/$/, \"\"));\n Log.warn(\n `[resolver] Source \"${sourceOrLink}\" found in \"${filePath}\" was resolved to \"${resolvedPathAlias}\", but the file is missing.`\n );\n }\n\n return { path: foundFile ?? absSource, exists: !!foundFile, suffix, isFileAlias, isDirAlias: !isFileAlias };\n }\n\n // node module package\n if (!source.startsWith(\".\")) {\n const resolverResult = nodeModulesResolver.sync(this.root, source);\n if (resolverResult.path) {\n return { path: resolverResult.path, suffix, exists: true, isPackage: true };\n }\n }\n\n // Not found, but its already a file path\n if (source.startsWith(\"./\") || source.startsWith(\"../\")) {\n // Warn once per missing source: it was resolved previously but the file cannot be found anymore.\n if (!this.notFound.has(absSource)) {\n this.notFound.add(absSource);\n Log.warn(`[resolver] Source \"${sourceOrLink}\" found in \"${filePath}\" points to a non-existent file.`);\n }\n\n return { path: absSource, suffix, exists: false };\n }\n }\n\n resolveAlias(source: string): string | undefined {\n return Resolver.resolvePathAlias(source, this.aliases);\n }\n\n normalize(filePath: string): string {\n return normalize(filePath);\n }\n\n static isFile(filePath: string): boolean {\n try {\n return statSync(filePath).isFile();\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"ENOENT\" || code === \"ENOTDIR\") {\n return false;\n }\n\n throw error;\n }\n }\n\n /** Aliased path to path */\n static resolvePathAlias(filePath: string, aliases: Record<string, string>): string | undefined {\n for (const [key, value] of Object.entries(aliases)) {\n // directory path alias\n if (key.endsWith(\"/\")) {\n if (!filePath.startsWith(key)) {\n continue;\n }\n\n return filePath.replace(key, () => value);\n }\n\n // file path alias\n if (filePath === key) {\n return value;\n }\n }\n }\n\n /** Path to aliased path */\n static resolveAliasPath(filePath: string, aliases: Record<string, string>): string {\n let shortest: string | undefined;\n\n for (const [key, value] of Object.entries(aliases)) {\n // directory path alias\n if (key.endsWith(\"/\")) {\n if (!filePath.startsWith(value)) {\n continue;\n }\n\n const aliased = filePath.replace(value, () => key);\n if (!shortest || aliased.length < shortest.length) {\n shortest = aliased;\n }\n continue;\n }\n\n // file path alias\n if (filePath === value && (!shortest || key.length < shortest.length)) {\n shortest = key;\n }\n }\n\n return shortest ?? filePath;\n }\n\n /** Path to aliased path */\n aliasPath(filePath: string): string {\n return Resolver.resolveAliasPath(filePath, this.aliases);\n }\n\n findFile(filePath: string, shouldCheckDirectory = false): string | undefined {\n const missKey = (shouldCheckDirectory ? \"d:\" : \"f:\") + filePath;\n\n if (this.isProduction && this.misses.has(missKey)) {\n return;\n }\n\n const found = this.#findFileUncached(filePath, shouldCheckDirectory);\n\n if (found === undefined && this.isProduction) {\n this.misses.add(missKey);\n }\n\n return found;\n }\n\n #findFileUncached(filePath: string, shouldCheckDirectory: boolean): string | undefined {\n // From cache\n if (this.files.has(filePath)) {\n return filePath;\n }\n\n // Exact match\n if (Resolver.isFile(filePath)) {\n this.files.add(filePath);\n return filePath;\n }\n\n const extension = extname(filePath);\n\n // No extension\n if (!extension) {\n // it might be a js file, html file, markdown file or just a directory\n for (const candidateExtension of [...Resolver.JS_EXTENSIONS, ...Resolver.HTML_EXTENSIONS]) {\n const candidate = replaceExtension(filePath, candidateExtension);\n\n if (this.files.has(candidate)) {\n return candidate;\n }\n\n if (Resolver.isFile(candidate)) {\n this.files.add(candidate);\n return candidate;\n }\n }\n\n // it might be index.html or index.md\n const withIndex = join(filePath, \"index\");\n\n for (const candidateExtension of Resolver.HTML_EXTENSIONS) {\n const candidate = replaceExtension(withIndex, candidateExtension);\n\n if (this.files.has(candidate)) {\n return candidate;\n }\n\n if (Resolver.isFile(candidate)) {\n this.files.add(candidate);\n return candidate;\n }\n }\n\n // directory\n if (shouldCheckDirectory) {\n if (this.directories.has(filePath)) {\n return filePath;\n }\n\n if (existsSync(filePath)) {\n this.directories.add(filePath);\n return filePath;\n }\n }\n\n return;\n }\n\n // main.js does not exist but main{.jsx, .ts, .tsx} may exist\n if (Resolver.JS_EXTENSIONS.has(extension)) {\n for (const jsExtension of Resolver.JS_EXTENSIONS) {\n const candidate = replaceExtension(filePath, jsExtension);\n\n if (Resolver.isFile(candidate)) {\n this.files.add(candidate);\n return candidate;\n }\n }\n\n return;\n }\n }\n}\n","import type { BabelAst, PostcssAst, Document, MarkdownAst } from \"@staticbolt/core\";\nimport type { WebAppManifest } from \"web-app-manifest\";\n\nexport const METADATA_TYPES = Object.freeze({\n Script: \"Script\",\n HTML: \"Html\",\n Markdown: \"Markdown\",\n CSS: \"Style\",\n SVG: \"Svg\",\n Package: \"Package\",\n TextAsset: \"TextAsset\",\n BinaryAsset: \"BinaryAsset\",\n WebAppManifest: \"WebAppManifest\",\n});\n\nexport type MetadataTypes = (typeof METADATA_TYPES)[keyof typeof METADATA_TYPES];\n\nexport interface MetadataBase {\n readonly type: `${Capitalize<string>}${string}`;\n\n /**\n * Relative path of the source file.\n *\n * Initially identical to `originalSource` when the metadata is created. During the build process, this value may change (e.g.,\n * if the file is moved to a different location and its links are rebased).\n */\n filePath: string;\n\n /**\n * Original relative path of the source file.\n *\n * Set when the metadata is created and never modified.\n */\n readonly id: string;\n\n readonly directDependencies: Set<string>;\n}\n\nexport interface ScriptMetadata extends MetadataBase {\n readonly type: (typeof METADATA_TYPES)[\"Script\"];\n\n /**\n * The Babel AST for the script.\n *\n * Mutated during the build process and always represents the file's current transformed state.\n */\n ast: BabelAst;\n\n /** Whether the script is a module or global */\n module: boolean;\n}\n\nexport interface StyleMetadata extends MetadataBase {\n readonly type: (typeof METADATA_TYPES)[\"CSS\"];\n\n /**\n * The PostCSS root after transformation\n *\n * Mutated during the build process and always represents the file's current transformed state.\n */\n ast: PostcssAst;\n}\n\nexport interface HtmlMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"HTML\"];\n\n /**\n * The HTML AST (root element).\n *\n * Mutated during the build process and always represents the file's current transformed state\n */\n ast: Document;\n\n /** The transformed ASTs from script tags. The key is the UUID */\n scriptsMetadataList: Map<string, ScriptMetadata>;\n\n /** The transformed ASTs from script tags. The key is the UUID */\n stylesMetadataList: Map<string, StyleMetadata>;\n}\n\nexport interface SvgMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"SVG\"];\n\n /**\n * The HTML AST (root element).\n *\n * Mutated during the build process and always represents the file's current transformed state\n */\n ast: Document;\n\n /** The transformed ASTs from script tags. The key is the UUID */\n stylesMetadataList: Map<string, StyleMetadata>;\n}\n\nexport interface MarkdownMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"Markdown\"];\n\n /**\n * Markdown tokens and frontmatter.\n *\n * Mutated during the build process and always represents the file's current transformed state\n */\n ast: MarkdownAst;\n}\n\nexport interface WebManifestMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"WebAppManifest\"];\n ast: WebAppManifest;\n}\n\nexport interface PackageMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"Package\"];\n\n /** Metadata code */\n code: string;\n\n packageName: string;\n}\n\nexport interface TextAssetMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"TextAsset\"];\n\n /** Metadata code */\n code: string;\n}\n\nexport interface BinaryAssetMetadata extends MetadataBase {\n type: (typeof METADATA_TYPES)[\"BinaryAsset\"];\n\n /** Raw binary content — images, fonts, wasm, etc. */\n data?: Uint8Array;\n}\n","const allowedTypes = new Set([\n \"module\",\n \"text/javascript\",\n \"application/javascript\",\n \"text/ecmascript\",\n \"application/ecmascript\",\n \"application/x-javascript\",\n]);\n\nexport function isScriptType(type: string | null) {\n return !type || allowedTypes.has(type.toLowerCase());\n}\n","import { isScriptType } from \"../helpers/is-script-type.ts\";\nimport { CUSTOM_ATTRIBUTES } from \"../types/common.ts\";\nimport { METADATA_TYPES } from \"../types/metadata.ts\";\n\nimport type {\n TextAssetMetadata,\n HtmlMetadata,\n MarkdownMetadata,\n MetadataBase,\n ScriptMetadata,\n StyleMetadata,\n SvgMetadata,\n WebManifestMetadata,\n BinaryAssetMetadata,\n PackageMetadata,\n HTMLElement,\n} from \"@staticbolt/core\";\n\nexport function isScriptMetadata(metadata: MetadataBase | undefined): metadata is ScriptMetadata {\n return metadata?.type === METADATA_TYPES.Script;\n}\n\nexport function isPackageMetadata(metadata: MetadataBase | undefined): metadata is PackageMetadata {\n return metadata?.type === METADATA_TYPES.Package;\n}\n\nexport function isHtmlMetadata(metadata: MetadataBase | undefined): metadata is HtmlMetadata {\n return metadata?.type === METADATA_TYPES.HTML;\n}\n\nexport function isStyleMetadata(metadata: MetadataBase | undefined): metadata is StyleMetadata {\n return metadata?.type === METADATA_TYPES.CSS;\n}\n\nexport function isSvgMetadata(metadata: MetadataBase | undefined): metadata is SvgMetadata {\n return metadata?.type === METADATA_TYPES.SVG;\n}\n\nexport function isMarkdownMetadata(metadata: MetadataBase | undefined): metadata is MarkdownMetadata {\n return metadata?.type === METADATA_TYPES.Markdown;\n}\n\nexport function isTextAssetMetadata(metadata: MetadataBase | undefined): metadata is TextAssetMetadata {\n return metadata?.type === METADATA_TYPES.TextAsset;\n}\n\nexport function isBinaryAssetMetadata(metadata: MetadataBase | undefined): metadata is BinaryAssetMetadata {\n return metadata?.type === METADATA_TYPES.BinaryAsset;\n}\n\nexport function isWebManifestMetadata(metadata: MetadataBase): metadata is WebManifestMetadata {\n return metadata.type === METADATA_TYPES.WebAppManifest;\n}\n\n/**\n * Returns script-related metadata entries.\n *\n * - If the input is ScriptMetadata, it returns it directly.\n * - If the input is HtmlMetadata, it scans <script> tags in the AST and resolves their associated ScriptMetadata using the metadata\n * ID attribute.\n */\nexport function filterScriptMetadata(metadata: MetadataBase) {\n const result: { metadata: ScriptMetadata; tag?: HTMLElement; htmlMetadata?: HtmlMetadata }[] = [];\n\n if (isScriptMetadata(metadata)) {\n result.push({ metadata });\n return result;\n }\n\n if (isHtmlMetadata(metadata)) {\n const scriptTags = metadata.ast.querySelectorAll(\"script\");\n\n for (const scriptTag of scriptTags) {\n const scriptId = scriptTag.getAttribute(CUSTOM_ATTRIBUTES.MetadataID);\n if (!scriptId) continue;\n\n const scriptType = scriptTag.getAttribute(\"type\");\n if (!isScriptType(scriptType)) {\n continue;\n }\n\n const scriptMetadata = metadata.scriptsMetadataList.get(scriptId);\n if (!scriptMetadata) continue;\n\n result.push({ metadata: scriptMetadata, htmlMetadata: metadata, tag: scriptTag });\n }\n }\n\n return result;\n}\n\n/**\n * Returns style-related metadata entries.\n *\n * - If the input is StyleMetadata, it returns it directly.\n * - If the input is HtmlMetadata, it scans <style> tags in the AST and resolves their associated StyleMetadata using the metadata\n * ID attribute.\n */\nexport function filterStyleMetadata(metadata: MetadataBase) {\n const result: { metadata: StyleMetadata; tag?: HTMLElement; htmlMetadata?: HtmlMetadata }[] = [];\n\n if (isStyleMetadata(metadata)) {\n result.push({ metadata });\n return result;\n }\n\n if (isHtmlMetadata(metadata)) {\n const styleTags = metadata.ast.querySelectorAll(\"style\");\n\n for (const styleTag of styleTags) {\n const styleId = styleTag.getAttribute(CUSTOM_ATTRIBUTES.MetadataID) || \"\";\n const styleMetadata = metadata.stylesMetadataList.get(styleId);\n if (!styleMetadata) continue;\n\n result.push({\n metadata: styleMetadata,\n htmlMetadata: metadata,\n tag: styleTag,\n });\n }\n }\n\n return result;\n}\n","import boxen from \"boxen\";\nimport chalk from \"chalk\";\nimport { common, createEmphasize } from \"emphasize\";\n\n/** - Highlight code string for terminal */\nexport function highlightCode(code: string, { lang = \"ts\", maxCodeLength = 170, maxLineLength = 110, boxed = true } = {}) {\n // Limit code length\n const isTruncated = code.length > maxCodeLength;\n if (isTruncated) code = code.slice(0, Math.max(0, maxCodeLength));\n\n // Limit line length and break on words\n const lines = code.split(\"\\n\");\n let withNewLines = \"\";\n for (const line of lines) {\n if (line.length <= maxLineLength) {\n withNewLines += line + \"\\n\";\n continue;\n }\n\n const words = line.split(\" \");\n let currentLine = \"\";\n for (const word of words) {\n if (currentLine.length + word.length <= maxLineLength) {\n currentLine += word + \" \";\n continue;\n }\n withNewLines += currentLine + \"\\n\";\n currentLine = word + \" \";\n }\n withNewLines += currentLine + \"\\n\";\n }\n\n // Highlight\n let highlighted = createEmphasize(common).highlight(lang, withNewLines.trim()).value;\n if (isTruncated) highlighted += \"\\n\" + chalk.inverse(\" ... \");\n\n if (!boxed) return highlighted;\n\n return boxen(highlighted, {\n padding: 0.5,\n borderStyle: \"round\",\n borderColor: \"white\",\n dimBorder: true,\n });\n}\n","import _generator from \"@babel/generator\";\nimport { NodeType } from \"@staticbolt/node-html-parser\";\nimport c from \"chalk\";\nimport { Node as PostcssNode } from \"postcss\";\n\nimport { CUSTOM_ATTRIBUTES } from \"../types/common.ts\";\nimport { highlightCode } from \"./highlight-code.ts\";\nimport { Log } from \"./logger.ts\";\n\nimport type { Node as BabelNode } from \"@babel/types\";\nimport type { Node as HtmlNode } from \"@staticbolt/node-html-parser\";\n\nconst generator = typeof _generator === \"function\" ? _generator : _generator.default;\n\ntype Node = BabelNode | PostcssNode | HtmlNode;\n\ninterface FormatErrorOptions {\n /** AST node (e.g., from Babel, PostCSS, or HTML) to convert and highlight */\n node?: Node;\n\n /** Source code to highlight (use instead of `node`) */\n code?: string;\n\n /** Language of the provided source code (required if `code` is set) */\n lang?: string;\n\n /** Path of the file where the error occurred */\n filePath?: string;\n\n /** Name of the function where the error originated */\n functionName?: string;\n\n level?: \"error\" | \"warning\";\n\n /** Function reference used to extract the function name */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function?: (...arguments_: any[]) => any;\n}\n\ntype MessageAndError = (string | Error)[];\n\nexport class PrintFormattedError {\n options: FormatErrorOptions = {};\n\n constructor(options: FormatErrorOptions = {}) {\n Object.assign(this.options, options);\n }\n\n static create(options: FormatErrorOptions = {}) {\n return new PrintFormattedError(options).print;\n }\n\n print = (...messageAndErrorWithOptions: [...MessageAndError] | [...MessageAndError, FormatErrorOptions]) => {\n const options: FormatErrorOptions = { ...this.options };\n\n const messagesArray: string[] = [];\n for (const item of messageAndErrorWithOptions) {\n // Msg\n if (typeof item === \"string\") {\n messagesArray.push(item);\n continue;\n }\n\n // Error\n if (item instanceof Error) {\n messagesArray.push(`\\n${item.message}`);\n continue;\n }\n\n // Options\n Object.assign(options, item);\n }\n\n let message = \"\";\n\n // First file path in one line without anything else to enable vscode link parsing\n if (options.filePath) {\n message += c.italic(options.filePath) + \"\\n\";\n }\n\n // Then the function name before the messages\n const functionName = options.function?.name ?? options.functionName;\n if (functionName) {\n message += c.dim(`[${functionName}] `);\n }\n\n // Then the messages (spaced)\n message += messagesArray.join(\" \");\n\n // Now the code\n const codeFromNode = options.node && nodeToString(options.node);\n const code = options.code ?? codeFromNode?.code;\n const lang = options.lang ?? codeFromNode?.lang;\n const codeBox = code && lang ? highlightCode(code, { lang }) : \"\";\n if (codeBox) {\n message += \"\\n\" + codeBox;\n }\n\n if (options.level === \"warning\") {\n Log.warn(message);\n return;\n }\n\n Log.error(message);\n };\n}\n\nexport const printFmtError = PrintFormattedError.create();\n\nfunction isHtmlNode(node: Node): node is HtmlNode {\n return \"nodeType\" in node && typeof node.nodeType === \"number\";\n}\n\nfunction isPostcssNode(node: Node): node is PostcssNode {\n return node instanceof PostcssNode;\n}\n\nfunction nodeToString(node: Node): { code: string; lang: string } {\n if (isHtmlNode(node)) {\n const clone = node.clone();\n if (clone.nodeType === NodeType.ELEMENT_NODE) {\n clone.removeAttribute(CUSTOM_ATTRIBUTES.MetadataID);\n }\n\n return { code: clone.toString(), lang: \"html\" };\n }\n\n if (isPostcssNode(node)) {\n return { code: node.toString(), lang: \"css\" };\n }\n\n return { code: generator(node, { jsescOption: { minimal: true } }).code, lang: \"js\" };\n}\n","import { createHash } from \"node:crypto\";\n\nimport { Log } from \"./logger.ts\";\n\nimport type { ValueOrError } from \"./value-or-error.ts\";\n\n/** `process.stdout.write` */\nexport function print(...input: string[]) {\n process.stdout.write(input.join(\" \"));\n}\n\n/** - Clear the line in the terminal */\nexport function clearLn() {\n if (!(\"clearLine\" in process.stdout && typeof process.stdout.clearLine === \"function\")) {\n return;\n }\n\n process.stdout.clearLine(0);\n process.stdout.cursorTo(0);\n}\n\n/** Used to assign a computed value to a variable */\nexport function assign<T>(function_: () => T): T {\n return function_();\n}\n\n/** Check if the value is an object */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && !Array.isArray(value) && value !== null;\n}\n\nexport function kebabToCamelCase(string_: string): string {\n return string_.replace(/-([a-z])/g, (_, char) => (char as string).toUpperCase());\n}\n\nexport function camelCaseToKebabCase(string_: string): string {\n return string_.replace(/([a-z])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\nexport function capitalize(string_: string): string {\n return string_.charAt(0).toUpperCase() + string_.slice(1);\n}\n\n/**\n * - Get line and column number from first match index\n *\n * @param code - Code string\n * @param matchIndex - Matching index\n * @returns - `[line, column]`\n */\nexport function getLineColumn(code: string, matchIndex: number): [number, number] {\n let lineNumber = 1;\n let columnNumber = 1;\n\n for (let index = 0; index < matchIndex; index++) {\n if (code[index] === \"\\n\") {\n lineNumber++;\n columnNumber = 1; // Reset column at each new line\n continue;\n }\n\n columnNumber++;\n }\n\n return [lineNumber, columnNumber];\n}\n\n/** - Human readable bytes, E.g: `1024 => 1KB` */\nexport function humanReadableBytes(bytes: number): string {\n const units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n let unitIndex = 0;\n while (bytes >= 1024 && unitIndex < units.length - 1) {\n bytes /= 1024;\n unitIndex++;\n }\n return `${bytes.toFixed(2)} ${units[unitIndex]}`;\n}\n\nexport function bytesToKB(bytes: number): number {\n return bytes / 1024;\n}\n\n/** - Clamp a numeric value between min and max values. */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nexport function isDefined<T>(value: T | undefined): value is T {\n return value !== undefined;\n}\n\n/**\n * Merges all entries from `source` into `target`, mutating `target` in place.\n *\n * - Existing keys in `target` are overwritten by `source` values.\n * - Values are **not** cloned — object references are shared between both maps after the merge.\n *\n * @param target - The map to be mutated with new/updated entries.\n * @param source - The map whose entries are read and applied to `target`.\n * @returns The mutated `target` map.\n */\nexport function mergeMaps<K, V>(target: Map<K, V>, source: Map<K, V>): Map<K, V> {\n for (const [key, value] of source) {\n target.set(key, value);\n }\n return target;\n}\n\nconst cached = new Map<string, string>();\n\n/** - Download from CDN */\nexport async function downloadContent(url: string): Promise<ValueOrError<string>> {\n if (cached.has(url)) {\n return [cached.get(url)!, null];\n }\n\n const headers = {\n \"User-Agent\":\n \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36\",\n Accept: \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\",\n Referer: url,\n };\n\n try {\n Log.info(`Downloading content from \"${url}\"`);\n const response = await fetch(url, { headers });\n const text = await response.text();\n cached.set(url, text);\n return [text, null];\n } catch {\n return [null, new Error(\"Error downloading q: \" + url)];\n }\n}\n\nexport function isURL(url: string): boolean {\n return url.startsWith(\"http://\") || url.startsWith(\"https://\");\n}\n\n/** Creates a shallow clone of an object while preserving its prototype and property descriptors. */\nexport function cloneObject<T extends object>(object: T): T {\n return Object.create(Object.getPrototypeOf(object) as T, Object.getOwnPropertyDescriptors(object)) as T;\n}\n\nexport function hashContent(content: string) {\n return createHash(\"sha1\").update(content).digest(\"hex\"); // full 40 chars\n}\n\nconst matchHtmlRegExp = /[\"'&<>]/;\n\nexport function escapeHtml(input: string) {\n const string = input;\n const match = matchHtmlRegExp.exec(string);\n\n if (!match) {\n return string;\n }\n\n let escape;\n let html = \"\";\n // eslint-disable-next-line no-useless-assignment\n let index = 0;\n let lastIndex = 0;\n\n for (index = match.index; index < string.length; index++) {\n switch (string.codePointAt(index)) {\n case 34: {\n // \"\n escape = \""\";\n break;\n }\n case 38: {\n // &\n escape = \"&\";\n break;\n }\n case 39: {\n // '\n escape = \"'\";\n break;\n }\n case 60: {\n // <\n escape = \"<\";\n break;\n }\n case 62: {\n // >\n escape = \">\";\n break;\n }\n default: {\n continue;\n }\n }\n\n if (lastIndex !== index) {\n html += string.slice(lastIndex, index);\n }\n\n lastIndex = index + 1;\n html += escape;\n }\n\n return lastIndex === index ? html : html + string.slice(lastIndex, index);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,IAAa,oBAAb,MAA+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