@zntc/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/bin/banner.mjs +131 -0
- package/bin/cli-flags.mjs +473 -0
- package/bin/rn-asset-copy.mjs +151 -0
- package/bin/rn-dev-input.mjs +225 -0
- package/bin/verify.mjs +190 -0
- package/bin/zntc.mjs +2327 -0
- package/dist/core/index.d.cts +1311 -0
- package/dist/core/index.d.ts +1311 -0
- package/dist/core/src/config-loader.d.ts +157 -0
- package/dist/core/src/load-env.d.ts +31 -0
- package/dist/core/src/platforms.d.ts +35 -0
- package/dist/core/src/runtime-polyfills.d.ts +94 -0
- package/dist/core/src/schema-allowlists.d.ts +17 -0
- package/dist/core/src/typo-suggest.d.ts +38 -0
- package/dist/core/src/workspace.d.ts +185 -0
- package/dist/index.cjs +1608 -0
- package/dist/index.js +3637 -0
- package/dist/shared/compat-engines.d.ts +30 -0
- package/dist/shared/index.d.ts +185 -0
- package/package.json +97 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1608 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region platforms.ts
|
|
3
|
+
const PLATFORMS = [{ name: "linux-x64-gnu", npmOs: "linux", npmCpu: "x64", npmLibc: "glibc", zigTarget: "x86_64-linux-gnu", ghaRunner: "ubuntu-latest" }, { name: "linux-arm64-gnu", npmOs: "linux", npmCpu: "arm64", npmLibc: "glibc", zigTarget: "aarch64-linux-gnu", ghaRunner: "ubuntu-24.04-arm" }, { name: "linux-x64-musl", npmOs: "linux", npmCpu: "x64", npmLibc: "musl", zigTarget: "x86_64-linux-musl", ghaRunner: "ubuntu-latest" }, { name: "linux-arm64-musl", npmOs: "linux", npmCpu: "arm64", npmLibc: "musl", zigTarget: "aarch64-linux-musl", ghaRunner: "ubuntu-24.04-arm" }, { name: "darwin-x64", npmOs: "darwin", npmCpu: "x64", zigTarget: "x86_64-macos", ghaRunner: "macos-15-intel" }, { name: "darwin-arm64", npmOs: "darwin", npmCpu: "arm64", zigTarget: "aarch64-macos", ghaRunner: "macos-latest" }, { name: "win32-x64-msvc", npmOs: "win32", npmCpu: "x64", zigTarget: "x86_64-windows-msvc", ghaRunner: "windows-latest" }, { name: "win32-arm64-msvc", npmOs: "win32", npmCpu: "arm64", zigTarget: "aarch64-windows-msvc", ghaRunner: "windows-11-arm" }, { name: "win32-ia32-msvc", npmOs: "win32", npmCpu: "ia32", zigTarget: "x86-windows-msvc", ghaRunner: "windows-latest" }];
|
|
4
|
+
function subPackageName(platform) {
|
|
5
|
+
return `@zntc/core-${platform.name}`;
|
|
6
|
+
}
|
|
7
|
+
function formatSupportedPlatforms() {
|
|
8
|
+
const groups = new Map();
|
|
9
|
+
for (const p of PLATFORMS) {
|
|
10
|
+
const key = `${p.npmOs}-${p.npmCpu}`;
|
|
11
|
+
if (!groups.has(key))groups.set(key, []);
|
|
12
|
+
if (p.npmLibc)groups.get(key).push(p.npmLibc);
|
|
13
|
+
}
|
|
14
|
+
return Array.from(groups, ([key, libcs]) => libcs.length > 0 ? `${key} (${libcs.join("/")})` : key).join(", ");
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region compat-engines.ts
|
|
18
|
+
const FEATURES = ["arrow", "class", "template_literal", "destructuring", "for_of", "spread", "object_extensions", "default_params", "block_scoping", "generator", "new_target", "exponentiation", "async_await", "object_spread", "optional_catch_binding", "nullish_coalescing", "optional_chaining", "logical_assignment", "class_static_block", "class_private_method", "class_private_field", "top_level_await", "hashbang", "using", "regex_sticky", "regex_dotall", "regex_named_groups", "unicode_brace_escape"],SUPPORT = { arrow: { chrome: [45, 0], firefox: [22, 0], safari: [10, 0], edge: [12, 0], node: [4, 0], deno: [1, 0], ios: [10, 0] }, class: { chrome: [49, 0], firefox: [45, 0], safari: [10, 1], edge: [13, 0], node: [6, 0], deno: [1, 0], ios: [10, 3] }, template_literal: { chrome: [41, 0], firefox: [34, 0], safari: [9, 0], edge: [12, 0], node: [4, 0], deno: [1, 0], ios: [9, 0] }, destructuring: { chrome: [49, 0], firefox: [41, 0], safari: [8, 0], edge: [14, 0], node: [6, 0], deno: [1, 0], ios: [8, 0] }, for_of: { chrome: [38, 0], firefox: [13, 0], safari: [7, 0], edge: [12, 0], node: [0, 12], deno: [1, 0], ios: [7, 0], hermes: [0, 7] }, spread: { chrome: [46, 0], firefox: [27, 0], safari: [10, 0], edge: [13, 0], node: [5, 0], deno: [1, 0], ios: [10, 0], hermes: [0, 7] }, object_extensions: { chrome: [43, 0], firefox: [34, 0], safari: [9, 0], edge: [12, 0], node: [4, 0], deno: [1, 0], ios: [9, 0], hermes: [0, 7] }, default_params: { chrome: [49, 0], firefox: [15, 0], safari: [10, 0], edge: [14, 0], node: [6, 0], deno: [1, 0], ios: [10, 0] }, block_scoping: { chrome: [49, 0], firefox: [51, 0], safari: [11, 0], edge: [14, 0], node: [6, 0], deno: [1, 0], ios: [11, 0] }, generator: { chrome: [50, 0], firefox: [53, 0], safari: [10, 0], edge: [13, 0], node: [6, 0], deno: [1, 0], ios: [10, 0] }, new_target: { chrome: [46, 0], firefox: [41, 0], safari: [10, 0], edge: [14, 0], node: [5, 0], deno: [1, 0], ios: [10, 0] }, exponentiation: { chrome: [52, 0], firefox: [52, 0], safari: [10, 1], edge: [14, 0], node: [7, 0], deno: [1, 0], ios: [10, 3], hermes: [0, 7] }, async_await: { chrome: [55, 0], firefox: [52, 0], safari: [11, 0], edge: [15, 0], node: [7, 6], deno: [1, 0], ios: [11, 0] }, object_spread: { chrome: [60, 0], firefox: [55, 0], safari: [11, 1], edge: [79, 0], node: [8, 3], deno: [1, 0], ios: [11, 3], hermes: [0, 7] }, optional_catch_binding: { chrome: [66, 0], firefox: [58, 0], safari: [11, 1], edge: [79, 0], node: [10, 0], deno: [1, 0], ios: [11, 3], hermes: [0, 12] }, nullish_coalescing: { chrome: [80, 0], firefox: [72, 0], safari: [13, 1], edge: [80, 0], node: [14, 0], deno: [1, 0], ios: [13, 4], hermes: [0, 7] }, optional_chaining: { chrome: [91, 0], firefox: [74, 0], safari: [13, 1], edge: [91, 0], node: [16, 9], deno: [1, 9], ios: [13, 4], hermes: [0, 12] }, logical_assignment: { chrome: [85, 0], firefox: [79, 0], safari: [14, 0], edge: [85, 0], node: [15, 0], deno: [1, 2], ios: [14, 0], hermes: [0, 7] }, class_static_block: { chrome: [94, 0], firefox: [93, 0], safari: [16, 4], edge: [94, 0], node: [16, 11], deno: [1, 14], ios: [16, 4] }, class_private_method: { chrome: [84, 0], firefox: [90, 0], safari: [15, 0], edge: [84, 0], node: [14, 6], deno: [1, 0], ios: [15, 0] }, class_private_field: { chrome: [74, 0], firefox: [90, 0], safari: [14, 1], edge: [79, 0], node: [12, 0], deno: [1, 0], ios: [14, 5] }, hashbang: { chrome: [74, 0], firefox: [67, 0], safari: [13, 1], edge: [79, 0], node: [12, 0], deno: [1, 0], ios: [13, 4], hermes: [0, 7] }, using: {} };
|
|
19
|
+
function verGte(a,b) {
|
|
20
|
+
if (a[0] !== b[0])return a[0] > b[0];
|
|
21
|
+
return a[1] >= b[1];
|
|
22
|
+
}
|
|
23
|
+
function isSupported(feature,engine,ver) {
|
|
24
|
+
const min = SUPPORT[feature]?.[engine];
|
|
25
|
+
if (!min)return false;
|
|
26
|
+
return verGte(ver, min);
|
|
27
|
+
}
|
|
28
|
+
function computeUnsupportedFromEngines(engines) {
|
|
29
|
+
let bits = 0;
|
|
30
|
+
for (let i = 0; i < FEATURES.length; i++) {
|
|
31
|
+
const feature = FEATURES[i];
|
|
32
|
+
let anyUnsupported = false;
|
|
33
|
+
for (const ev of engines) {
|
|
34
|
+
if (!isSupported(feature, ev.engine, [ev.major, ev.minor])) {
|
|
35
|
+
anyUnsupported = true;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (anyUnsupported)bits |= 1 << i;
|
|
40
|
+
}
|
|
41
|
+
return bits;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region index.ts
|
|
45
|
+
const ES_TARGET_BITS = { es5: 0x0fffffff, es2015: 0x06fff800, es2016: 0x06fff000, es2017: 0x06ffe000, es2018: 0x00ffc000, es2019: 0x00ff8000, es2020: 0x00fe0000, es2021: 0x00fc0000, es2022: 0x00c00000, es2023: 0x00800000, es2024: 0x00800000, es2025: 0x0, esnext: 0x0 };
|
|
46
|
+
function isPlainObject(value) {
|
|
47
|
+
return value !== null && typeof value == "object" && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
function validateTsConfigRaw(raw) {
|
|
50
|
+
if (raw === undefined)return;
|
|
51
|
+
let config;
|
|
52
|
+
try {
|
|
53
|
+
config = JSON.parse(raw);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
56
|
+
throw new Error(`failed to parse --tsconfig-raw: ${reason}`);
|
|
57
|
+
}
|
|
58
|
+
if (!isPlainObject(config)) {
|
|
59
|
+
throw new Error("failed to parse --tsconfig-raw: expected a JSON object");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function buildOptionsJson(opts={},unsupportedOverride) {
|
|
63
|
+
const payload = {};
|
|
64
|
+
if (opts.target)payload.target = opts.target;
|
|
65
|
+
if (unsupportedOverride !== undefined && unsupportedOverride !== 0)payload.unsupported = unsupportedOverride;
|
|
66
|
+
if (opts.flow)payload.flow = true;
|
|
67
|
+
if (opts.jsxInJs)payload.jsxInJs = true;
|
|
68
|
+
if (opts.reactRefresh)payload.reactRefresh = true;
|
|
69
|
+
if (opts.reactRefreshHookSignatures)payload.reactRefreshHookSignatures = true;
|
|
70
|
+
if (opts.jsx !== undefined) {
|
|
71
|
+
payload.jsx = opts.jsx === "automatic-dev" ? "automatic_dev" : opts.jsx;
|
|
72
|
+
}
|
|
73
|
+
if (opts.jsxFactory)payload.jsxFactory = opts.jsxFactory;
|
|
74
|
+
if (opts.jsxFragment)payload.jsxFragment = opts.jsxFragment;
|
|
75
|
+
if (opts.jsxImportSource)payload.jsxImportSource = opts.jsxImportSource;
|
|
76
|
+
if (opts.dropConsole)payload.dropConsole = true;
|
|
77
|
+
if (opts.dropDebugger)payload.dropDebugger = true;
|
|
78
|
+
if (opts.asciiOnly)payload.asciiOnly = true;
|
|
79
|
+
if (opts.charsetUtf8)payload.charsetUtf8 = true;
|
|
80
|
+
if (opts.experimentalDecorators)payload.experimentalDecorators = true;
|
|
81
|
+
if (opts.emitDecoratorMetadata)payload.emitDecoratorMetadata = true;
|
|
82
|
+
if (opts.useDefineForClassFields === false)payload.useDefineForClassFields = false;
|
|
83
|
+
if (opts.verbatimModuleSyntax !== undefined)payload.verbatimModuleSyntax = opts.verbatimModuleSyntax;
|
|
84
|
+
if (opts.tsconfigPath)payload.tsconfigPath = opts.tsconfigPath;
|
|
85
|
+
if (opts.tsconfigRaw)payload.tsconfigRaw = opts.tsconfigRaw;
|
|
86
|
+
if (opts.format)payload.format = opts.format;
|
|
87
|
+
if (opts.quotes)payload.quotes = opts.quotes;
|
|
88
|
+
if (opts.platform === "react-native")payload.platform = "react_native"; else if (opts.platform)payload.platform = opts.platform;
|
|
89
|
+
if (opts.minifyWhitespace || opts.minify)payload.minifyWhitespace = true;
|
|
90
|
+
if (opts.minifyIdentifiers || opts.minify)payload.minifyIdentifiers = true;
|
|
91
|
+
if (opts.minifySyntax || opts.minify)payload.minifySyntax = true;
|
|
92
|
+
if (opts.sourcemap)payload.sourcemap = true;
|
|
93
|
+
if (opts.sourcemapDebugIds)payload.sourcemapDebugIds = true;
|
|
94
|
+
if (opts.sourcesContent === false)payload.sourcesContent = false;
|
|
95
|
+
if (opts.sourceRoot)payload.sourceRoot = opts.sourceRoot;
|
|
96
|
+
if (opts.define && opts.define.length > 0)payload.define = opts.define;
|
|
97
|
+
if (opts.stopAfter)payload.stopAfter = opts.stopAfter;
|
|
98
|
+
return JSON.stringify(payload);
|
|
99
|
+
}
|
|
100
|
+
function parseBrowserslistEntry(entry) {
|
|
101
|
+
const m = entry.trim().match(/^(\S+)\s+([\d.]+)(?:-[\d.]+)?$/);
|
|
102
|
+
if (!m)return null;
|
|
103
|
+
const name = m[1].toLowerCase();
|
|
104
|
+
;
|
|
105
|
+
const [majStr, minStr="0"] = (m[2]).split("."),major = parseInt(majStr, 10),minor = parseInt(minStr, 10);
|
|
106
|
+
if (Number.isNaN(major))return null;
|
|
107
|
+
;
|
|
108
|
+
const engine = { chrome: "chrome", and_chr: "chrome", firefox: "firefox", and_ff: "firefox", safari: "safari", ios_saf: "ios", edge: "edge", node: "node", deno: "deno", opera: "opera", op_mob: "opera", hermes: "hermes" }[name];
|
|
109
|
+
if (!engine)return null;
|
|
110
|
+
return { engine, major, minor };
|
|
111
|
+
}
|
|
112
|
+
function browserslistToUnsupported(entries) {
|
|
113
|
+
const engines = [];
|
|
114
|
+
for (const e of entries) {
|
|
115
|
+
const parsed = parseBrowserslistEntry(e);
|
|
116
|
+
if (parsed)engines.push(parsed);
|
|
117
|
+
}
|
|
118
|
+
if (engines.length === 0)return 0;
|
|
119
|
+
return computeUnsupportedFromEngines(engines);
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region runtime-polyfills.ts
|
|
123
|
+
var readFileSync = require("node:fs").readFileSync;
|
|
124
|
+
var createRequire = require("node:module").createRequire;
|
|
125
|
+
var dirname = require("node:path").dirname;
|
|
126
|
+
var resolve = require("node:path").resolve;
|
|
127
|
+
let runtimeRequireOverride = null;
|
|
128
|
+
function getRuntimeRequire() {
|
|
129
|
+
return runtimeRequireOverride ?? createRequire(require("url").pathToFileURL(__filename).href);
|
|
130
|
+
}
|
|
131
|
+
const ES_TARGETS = new Set(["es5", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020", "es2021", "es2022", "es2023", "es2024", "es2025", "esnext"]),DEVICE_TARGET_RE = /\b(?:iphone|ipad|ipod|galaxy|pixel|nexus|oneplus|xiaomi|redmi|huawei|motorola|moto)\b/i,RUNTIME_POLYFILL_FEATURE_MODULES = [{ feature: "aggregate_error", module: "es.aggregate-error" }, { feature: "aggregate_error", module: "es.aggregate-error.cause" }, { feature: "array_buffer", module: "es.array-buffer.constructor" }, { feature: "array_buffer_detached", module: "es.array-buffer.detached" }, { feature: "array_buffer_is_view", module: "es.array-buffer.is-view" }, { feature: "array_buffer_slice", module: "es.array-buffer.slice" }, { feature: "array_buffer_transfer", module: "es.array-buffer.transfer" }, { feature: "array_buffer_transfer_to_fixed_length", module: "es.array-buffer.transfer-to-fixed-length" }, { feature: "array_at", module: "es.array.at" }, { feature: "array_concat", module: "es.array.concat" }, { feature: "array_copy_within", module: "es.array.copy-within" }, { feature: "array_every", module: "es.array.every" }, { feature: "array_fill", module: "es.array.fill" }, { feature: "array_filter", module: "es.array.filter" }, { feature: "array_find", module: "es.array.find" }, { feature: "array_find_index", module: "es.array.find-index" }, { feature: "array_find_last", module: "es.array.find-last" }, { feature: "array_find_last_index", module: "es.array.find-last-index" }, { feature: "array_flat", module: "es.array.flat" }, { feature: "array_flat_map", module: "es.array.flat-map" }, { feature: "array_for_each", module: "es.array.for-each" }, { feature: "array_from", module: "es.array.from" }, { feature: "array_from_async", module: "es.array.from-async" }, { feature: "array_includes", module: "es.array.includes" }, { feature: "array_index_of", module: "es.array.index-of" }, { feature: "array_is_array", module: "es.array.is-array" }, { feature: "array_join", module: "es.array.join" }, { feature: "array_last_index_of", module: "es.array.last-index-of" }, { feature: "array_map", module: "es.array.map" }, { feature: "array_of", module: "es.array.of" }, { feature: "array_push", module: "es.array.push" }, { feature: "array_reduce", module: "es.array.reduce" }, { feature: "array_reduce_right", module: "es.array.reduce-right" }, { feature: "array_reverse", module: "es.array.reverse" }, { feature: "array_slice", module: "es.array.slice" }, { feature: "array_some", module: "es.array.some" }, { feature: "array_sort", module: "es.array.sort" }, { feature: "array_splice", module: "es.array.splice" }, { feature: "array_to_reversed", module: "es.array.to-reversed" }, { feature: "array_to_sorted", module: "es.array.to-sorted" }, { feature: "array_to_spliced", module: "es.array.to-spliced" }, { feature: "array_unshift", module: "es.array.unshift" }, { feature: "array_with", module: "es.array.with" }, { feature: "async_disposable_stack", module: "es.async-disposable-stack.constructor" }, { feature: "data_view", module: "es.data-view" }, { feature: "data_view_get_float16", module: "es.data-view.get-float16" }, { feature: "data_view_set_float16", module: "es.data-view.set-float16" }, { feature: "date_now", module: "es.date.now" }, { feature: "date_to_iso_string", module: "es.date.to-iso-string" }, { feature: "disposable_stack", module: "es.disposable-stack.constructor" }, { feature: "error_is_error", module: "es.error.is-error" }, { feature: "escape", module: "es.escape" }, { feature: "function_bind", module: "es.function.bind" }, { feature: "global_this", module: "es.global-this" }, { feature: "iterator", module: "es.iterator.constructor" }, { feature: "iterator_drop", module: "es.iterator.drop" }, { feature: "iterator_every", module: "es.iterator.every" }, { feature: "iterator_filter", module: "es.iterator.filter" }, { feature: "iterator_find", module: "es.iterator.find" }, { feature: "iterator_flat_map", module: "es.iterator.flat-map" }, { feature: "iterator_for_each", module: "es.iterator.for-each" }, { feature: "iterator_from", module: "es.iterator.from" }, { feature: "iterator_map", module: "es.iterator.map" }, { feature: "iterator_reduce", module: "es.iterator.reduce" }, { feature: "iterator_some", module: "es.iterator.some" }, { feature: "iterator_take", module: "es.iterator.take" }, { feature: "iterator_to_array", module: "es.iterator.to-array" }, { feature: "json_is_raw_json", module: "es.json.is-raw-json" }, { feature: "json_parse", module: "es.json.parse" }, { feature: "json_raw_json", module: "es.json.raw-json" }, { feature: "json_stringify", module: "es.json.stringify" }, { feature: "map", module: "es.map" }, { feature: "map_get_or_insert", module: "es.map.get-or-insert" }, { feature: "map_get_or_insert_computed", module: "es.map.get-or-insert-computed" }, { feature: "map_group_by", module: "es.map.group-by" }, { feature: "math_acosh", module: "es.math.acosh" }, { feature: "math_asinh", module: "es.math.asinh" }, { feature: "math_atanh", module: "es.math.atanh" }, { feature: "math_cbrt", module: "es.math.cbrt" }, { feature: "math_clz32", module: "es.math.clz32" }, { feature: "math_cosh", module: "es.math.cosh" }, { feature: "math_expm1", module: "es.math.expm1" }, { feature: "math_f16round", module: "es.math.f16round" }, { feature: "math_fround", module: "es.math.fround" }, { feature: "math_hypot", module: "es.math.hypot" }, { feature: "math_imul", module: "es.math.imul" }, { feature: "math_log10", module: "es.math.log10" }, { feature: "math_log1p", module: "es.math.log1p" }, { feature: "math_log2", module: "es.math.log2" }, { feature: "math_sign", module: "es.math.sign" }, { feature: "math_sinh", module: "es.math.sinh" }, { feature: "math_sum_precise", module: "es.math.sum-precise" }, { feature: "math_tanh", module: "es.math.tanh" }, { feature: "math_trunc", module: "es.math.trunc" }, { feature: "number_constructor", module: "es.number.constructor" }, { feature: "number_epsilon", module: "es.number.epsilon" }, { feature: "number_is_finite", module: "es.number.is-finite" }, { feature: "number_is_integer", module: "es.number.is-integer" }, { feature: "number_is_nan", module: "es.number.is-nan" }, { feature: "number_is_safe_integer", module: "es.number.is-safe-integer" }, { feature: "number_max_safe_integer", module: "es.number.max-safe-integer" }, { feature: "number_min_safe_integer", module: "es.number.min-safe-integer" }, { feature: "number_parse_float", module: "es.number.parse-float" }, { feature: "number_parse_int", module: "es.number.parse-int" }, { feature: "number_to_exponential", module: "es.number.to-exponential" }, { feature: "number_to_fixed", module: "es.number.to-fixed" }, { feature: "number_to_precision", module: "es.number.to-precision" }, { feature: "object_assign", module: "es.object.assign" }, { feature: "object_create", module: "es.object.create" }, { feature: "object_define_getter", module: "es.object.define-getter" }, { feature: "object_define_properties", module: "es.object.define-properties" }, { feature: "object_define_property", module: "es.object.define-property" }, { feature: "object_define_setter", module: "es.object.define-setter" }, { feature: "object_entries", module: "es.object.entries" }, { feature: "object_freeze", module: "es.object.freeze" }, { feature: "object_from_entries", module: "es.object.from-entries" }, { feature: "object_get_own_property_descriptor", module: "es.object.get-own-property-descriptor" }, { feature: "object_get_own_property_descriptors", module: "es.object.get-own-property-descriptors" }, { feature: "object_get_own_property_names", module: "es.object.get-own-property-names" }, { feature: "object_get_prototype_of", module: "es.object.get-prototype-of" }, { feature: "object_group_by", module: "es.object.group-by" }, { feature: "object_has_own", module: "es.object.has-own" }, { feature: "object_is", module: "es.object.is" }, { feature: "object_is_extensible", module: "es.object.is-extensible" }, { feature: "object_is_frozen", module: "es.object.is-frozen" }, { feature: "object_is_sealed", module: "es.object.is-sealed" }, { feature: "object_keys", module: "es.object.keys" }, { feature: "object_lookup_getter", module: "es.object.lookup-getter" }, { feature: "object_lookup_setter", module: "es.object.lookup-setter" }, { feature: "object_prevent_extensions", module: "es.object.prevent-extensions" }, { feature: "object_proto", module: "es.object.proto" }, { feature: "object_seal", module: "es.object.seal" }, { feature: "object_set_prototype_of", module: "es.object.set-prototype-of" }, { feature: "object_values", module: "es.object.values" }, { feature: "parse_float", module: "es.parse-float" }, { feature: "parse_int", module: "es.parse-int" }, { feature: "set", module: "es.set" }, { feature: "set_difference", module: "es.set.difference.v2" }, { feature: "set_intersection", module: "es.set.intersection.v2" }, { feature: "set_is_disjoint_from", module: "es.set.is-disjoint-from.v2" }, { feature: "set_is_subset_of", module: "es.set.is-subset-of.v2" }, { feature: "set_is_superset_of", module: "es.set.is-superset-of.v2" }, { feature: "set_symmetric_difference", module: "es.set.symmetric-difference.v2" }, { feature: "set_union", module: "es.set.union.v2" }, { feature: "promise", module: "es.promise" }, { feature: "promise_all_settled", module: "es.promise.all-settled" }, { feature: "promise_any", module: "es.promise.any" }, { feature: "promise_finally", module: "es.promise.finally" }, { feature: "promise_try", module: "es.promise.try" }, { feature: "promise_with_resolvers", module: "es.promise.with-resolvers" }, { feature: "reflect_apply", module: "es.reflect.apply" }, { feature: "reflect_construct", module: "es.reflect.construct" }, { feature: "reflect_define_property", module: "es.reflect.define-property" }, { feature: "reflect_delete_property", module: "es.reflect.delete-property" }, { feature: "reflect_get", module: "es.reflect.get" }, { feature: "reflect_get_own_property_descriptor", module: "es.reflect.get-own-property-descriptor" }, { feature: "reflect_get_prototype_of", module: "es.reflect.get-prototype-of" }, { feature: "reflect_has", module: "es.reflect.has" }, { feature: "reflect_is_extensible", module: "es.reflect.is-extensible" }, { feature: "reflect_own_keys", module: "es.reflect.own-keys" }, { feature: "reflect_prevent_extensions", module: "es.reflect.prevent-extensions" }, { feature: "reflect_set", module: "es.reflect.set" }, { feature: "reflect_set_prototype_of", module: "es.reflect.set-prototype-of" }, { feature: "regexp_escape", module: "es.regexp.escape" }, { feature: "regexp_flags", module: "es.regexp.flags" }, { feature: "regexp_sticky", module: "es.regexp.sticky" }, { feature: "regexp_dot_all", module: "es.regexp.dot-all" }, { feature: "structured_clone", module: "web.structured-clone" }, { feature: "string_anchor", module: "es.string.anchor" }, { feature: "string_big", module: "es.string.big" }, { feature: "string_blink", module: "es.string.blink" }, { feature: "string_bold", module: "es.string.bold" }, { feature: "string_code_point_at", module: "es.string.code-point-at" }, { feature: "string_ends_with", module: "es.string.ends-with" }, { feature: "string_fixed", module: "es.string.fixed" }, { feature: "string_fontcolor", module: "es.string.fontcolor" }, { feature: "string_fontsize", module: "es.string.fontsize" }, { feature: "string_from_code_point", module: "es.string.from-code-point" }, { feature: "string_includes", module: "es.string.includes" }, { feature: "string_is_well_formed", module: "es.string.is-well-formed" }, { feature: "string_italics", module: "es.string.italics" }, { feature: "string_link", module: "es.string.link" }, { feature: "string_match_all", module: "es.string.match-all" }, { feature: "string_pad_end", module: "es.string.pad-end" }, { feature: "string_pad_start", module: "es.string.pad-start" }, { feature: "string_raw", module: "es.string.raw" }, { feature: "string_repeat", module: "es.string.repeat" }, { feature: "string_replace_all", module: "es.string.replace-all" }, { feature: "string_small", module: "es.string.small" }, { feature: "string_starts_with", module: "es.string.starts-with" }, { feature: "string_strike", module: "es.string.strike" }, { feature: "string_sub", module: "es.string.sub" }, { feature: "string_substr", module: "es.string.substr" }, { feature: "string_sup", module: "es.string.sup" }, { feature: "string_to_well_formed", module: "es.string.to-well-formed" }, { feature: "string_trim", module: "es.string.trim" }, { feature: "string_trim_end", module: "es.string.trim-end" }, { feature: "string_trim_start", module: "es.string.trim-start" }, { feature: "suppressed_error", module: "es.suppressed-error.constructor" }, { feature: "symbol", module: "es.symbol" }, { feature: "symbol_async_dispose", module: "es.symbol.async-dispose" }, { feature: "symbol_async_iterator", module: "es.symbol.async-iterator" }, { feature: "symbol_description", module: "es.symbol.description" }, { feature: "symbol_dispose", module: "es.symbol.dispose" }, { feature: "symbol_has_instance", module: "es.symbol.has-instance" }, { feature: "symbol_is_concat_spreadable", module: "es.symbol.is-concat-spreadable" }, { feature: "symbol_iterator", module: "es.symbol.iterator" }, { feature: "symbol_match", module: "es.symbol.match" }, { feature: "symbol_match_all", module: "es.symbol.match-all" }, { feature: "symbol_replace", module: "es.symbol.replace" }, { feature: "symbol_search", module: "es.symbol.search" }, { feature: "symbol_species", module: "es.symbol.species" }, { feature: "symbol_split", module: "es.symbol.split" }, { feature: "symbol_to_primitive", module: "es.symbol.to-primitive" }, { feature: "symbol_to_string_tag", module: "es.symbol.to-string-tag" }, { feature: "symbol_unscopables", module: "es.symbol.unscopables" }, { feature: "typed_array_float32", module: "es.typed-array.float32-array" }, { feature: "typed_array_float64", module: "es.typed-array.float64-array" }, { feature: "typed_array_int8", module: "es.typed-array.int8-array" }, { feature: "typed_array_int16", module: "es.typed-array.int16-array" }, { feature: "typed_array_int32", module: "es.typed-array.int32-array" }, { feature: "typed_array_uint8", module: "es.typed-array.uint8-array" }, { feature: "typed_array_uint8_clamped", module: "es.typed-array.uint8-clamped-array" }, { feature: "typed_array_uint16", module: "es.typed-array.uint16-array" }, { feature: "typed_array_uint32", module: "es.typed-array.uint32-array" }, { feature: "typed_array_at", module: "es.typed-array.at" }, { feature: "typed_array_copy_within", module: "es.typed-array.copy-within" }, { feature: "typed_array_every", module: "es.typed-array.every" }, { feature: "typed_array_fill", module: "es.typed-array.fill" }, { feature: "typed_array_filter", module: "es.typed-array.filter" }, { feature: "typed_array_find", module: "es.typed-array.find" }, { feature: "typed_array_find_index", module: "es.typed-array.find-index" }, { feature: "typed_array_find_last", module: "es.typed-array.find-last" }, { feature: "typed_array_find_last_index", module: "es.typed-array.find-last-index" }, { feature: "typed_array_for_each", module: "es.typed-array.for-each" }, { feature: "typed_array_from", module: "es.typed-array.from" }, { feature: "typed_array_includes", module: "es.typed-array.includes" }, { feature: "typed_array_index_of", module: "es.typed-array.index-of" }, { feature: "typed_array_join", module: "es.typed-array.join" }, { feature: "typed_array_last_index_of", module: "es.typed-array.last-index-of" }, { feature: "typed_array_map", module: "es.typed-array.map" }, { feature: "typed_array_of", module: "es.typed-array.of" }, { feature: "typed_array_reduce", module: "es.typed-array.reduce" }, { feature: "typed_array_reduce_right", module: "es.typed-array.reduce-right" }, { feature: "typed_array_reverse", module: "es.typed-array.reverse" }, { feature: "typed_array_set", module: "es.typed-array.set" }, { feature: "typed_array_slice", module: "es.typed-array.slice" }, { feature: "typed_array_some", module: "es.typed-array.some" }, { feature: "typed_array_sort", module: "es.typed-array.sort" }, { feature: "typed_array_subarray", module: "es.typed-array.subarray" }, { feature: "typed_array_to_reversed", module: "es.typed-array.to-reversed" }, { feature: "typed_array_to_sorted", module: "es.typed-array.to-sorted" }, { feature: "typed_array_with", module: "es.typed-array.with" }, { feature: "uint8_array_from_base64", module: "es.uint8-array.from-base64" }, { feature: "uint8_array_from_hex", module: "es.uint8-array.from-hex" }, { feature: "uint8_array_set_from_base64", module: "es.uint8-array.set-from-base64" }, { feature: "uint8_array_set_from_hex", module: "es.uint8-array.set-from-hex" }, { feature: "uint8_array_to_base64", module: "es.uint8-array.to-base64" }, { feature: "uint8_array_to_hex", module: "es.uint8-array.to-hex" }, { feature: "unescape", module: "es.unescape" }, { feature: "weak_map", module: "es.weak-map" }, { feature: "weak_map_get_or_insert", module: "es.weak-map.get-or-insert" }, { feature: "weak_map_get_or_insert_computed", module: "es.weak-map.get-or-insert-computed" }, { feature: "weak_set", module: "es.weak-set" }, { feature: "web_atob", module: "web.atob" }, { feature: "web_btoa", module: "web.btoa" }, { feature: "web_dom_collections_for_each", module: "web.dom-collections.for-each" }, { feature: "web_dom_collections_iterator", module: "web.dom-collections.iterator" }, { feature: "web_dom_exception", module: "web.dom-exception.constructor" }, { feature: "web_immediate", module: "web.immediate" }, { feature: "web_queue_microtask", module: "web.queue-microtask" }, { feature: "web_self", module: "web.self" }, { feature: "web_timers", module: "web.timers" }, { feature: "web_url", module: "web.url" }, { feature: "web_url_can_parse", module: "web.url.can-parse" }, { feature: "web_url_parse", module: "web.url.parse" }, { feature: "web_url_to_json", module: "web.url.to-json" }, { feature: "web_url_search_params", module: "web.url-search-params" }, { feature: "web_url_search_params_delete", module: "web.url-search-params.delete" }, { feature: "web_url_search_params_has", module: "web.url-search-params.has" }, { feature: "web_url_search_params_size", module: "web.url-search-params.size" }],RUNTIME_POLYFILL_CANDIDATE_MODULES = RUNTIME_POLYFILL_FEATURE_MODULES.map((item) => item.module);
|
|
132
|
+
let coreJsCompatCache,coreJsVersionCache;
|
|
133
|
+
function isEsTarget(target) {
|
|
134
|
+
return target !== undefined && ES_TARGETS.has(target);
|
|
135
|
+
}
|
|
136
|
+
function loadCoreJsCompat() {
|
|
137
|
+
if (coreJsCompatCache !== undefined) {
|
|
138
|
+
if (coreJsCompatCache)return coreJsCompatCache;
|
|
139
|
+
throwCoreJsCompatMissing();
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
const req = getRuntimeRequire();
|
|
143
|
+
coreJsCompatCache = req("core-js-compat");
|
|
144
|
+
return coreJsCompatCache;
|
|
145
|
+
} catch {
|
|
146
|
+
coreJsCompatCache = null;
|
|
147
|
+
throwCoreJsCompatMissing();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function throwCoreJsCompatMissing() {
|
|
151
|
+
throw new Error("@zntc/core: runtimePolyfills requires the optional 'core-js-compat' package. Install it with `bun add core-js core-js-compat`.");
|
|
152
|
+
}
|
|
153
|
+
function readInstalledCoreJsVersion() {
|
|
154
|
+
if (coreJsVersionCache !== undefined)return coreJsVersionCache ?? undefined;
|
|
155
|
+
try {
|
|
156
|
+
const req = getRuntimeRequire(),pkgPath = req.resolve("core-js/package.json"),pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
157
|
+
coreJsVersionCache = pkg.version ?? null;
|
|
158
|
+
} catch {
|
|
159
|
+
coreJsVersionCache = null;
|
|
160
|
+
}
|
|
161
|
+
return coreJsVersionCache ?? undefined;
|
|
162
|
+
}
|
|
163
|
+
function assertNotPhysicalDeviceTarget(raw) {
|
|
164
|
+
if (!DEVICE_TARGET_RE.test(raw))return;
|
|
165
|
+
throw new Error(`@zntc/core: unsupported runtime target '${raw}'. Physical device names are not supported; use Browserslist targets such as 'ios_saf 12', 'chrome >= 85', or 'node 18'.`);
|
|
166
|
+
}
|
|
167
|
+
function assertNotCompactRuntimeTarget(raw) {
|
|
168
|
+
const compact = raw.match(/^(ios_saf|ios|safari|chrome|android|samsung|hermes|node)v?\d+(?:\.\d+)*$/i);
|
|
169
|
+
if (!compact)return;
|
|
170
|
+
throw new Error(`@zntc/core: unsupported runtime target '${raw}'. Compact runtime target shorthands are not supported; use Browserslist targets such as 'ios_saf 12', 'chrome >= 85', or 'node 18'.`);
|
|
171
|
+
}
|
|
172
|
+
function assertBrowserslistRuntimeTarget(raw) {
|
|
173
|
+
if (!/^(?:hermes|react-native|reactnative)\b/i.test(raw))return;
|
|
174
|
+
throw new Error(`@zntc/core: unsupported runtime target '${raw}'. runtimePolyfills.targets follows Rspack/SWC env.targets and accepts Browserslist queries; use platform: 'react-native' for the default Hermes runtime target.`);
|
|
175
|
+
}
|
|
176
|
+
function normalizeRuntimeTargetString(raw) {
|
|
177
|
+
const value = raw.trim();
|
|
178
|
+
assertNotPhysicalDeviceTarget(value);
|
|
179
|
+
assertNotCompactRuntimeTarget(value);
|
|
180
|
+
assertBrowserslistRuntimeTarget(value);
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
function normalizeRuntimeTargets(targets) {
|
|
184
|
+
if (Array.isArray(targets))return targets.map(normalizeRuntimeTargetString);
|
|
185
|
+
return normalizeRuntimeTargetString(targets);
|
|
186
|
+
}
|
|
187
|
+
function normalizeBuildTargetForRuntime(target) {
|
|
188
|
+
if (!target || isEsTarget(target))return undefined;
|
|
189
|
+
const nodeTarget = target.match(/^node(\d+(?:\.\d+)*)$/i);
|
|
190
|
+
if (nodeTarget)return { node: nodeTarget[1] };
|
|
191
|
+
const hermesTarget = target.match(/^hermes(\d+(?:\.\d+)*)$/i);
|
|
192
|
+
if (hermesTarget)return { hermes: hermesTarget[1] };
|
|
193
|
+
return normalizeRuntimeTargets(target);
|
|
194
|
+
}
|
|
195
|
+
function defaultRuntimeTargets(options) {
|
|
196
|
+
if (options.platform === "node") {
|
|
197
|
+
const [major, minor="0"] = process.versions.node.split(".");
|
|
198
|
+
return { node: `${major}.${minor}` };
|
|
199
|
+
}
|
|
200
|
+
if (options.platform === "react-native")return { hermes: "0.7" };
|
|
201
|
+
return "defaults";
|
|
202
|
+
}
|
|
203
|
+
function chooseRuntimeTargets(options,runtime) {
|
|
204
|
+
const raw = runtime.targets ?? (options.browserslist ? options.browserslist : undefined);
|
|
205
|
+
if (raw !== undefined)return normalizeRuntimeTargets(raw);
|
|
206
|
+
const target = normalizeBuildTargetForRuntime(options.target);
|
|
207
|
+
if (target !== undefined)return target;
|
|
208
|
+
return defaultRuntimeTargets(options);
|
|
209
|
+
}
|
|
210
|
+
function normalizeCoreJsModuleName(raw) {
|
|
211
|
+
let value = raw.trim();
|
|
212
|
+
if (value.startsWith("core-js/modules/"))value = value.slice("core-js/modules/".length);
|
|
213
|
+
if (value.endsWith(".js"))value = value.slice(0, -3);
|
|
214
|
+
if (!/^(?:es|web)\.[a-z0-9.-]+$/i.test(value)) {
|
|
215
|
+
throw new Error(`@zntc/core: invalid core-js module '${raw}'. Expected e.g. 'es.string.replace-all'.`);
|
|
216
|
+
}
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
function normalizeRuntimePolyfillOptions(options) {
|
|
220
|
+
const raw = options.runtimePolyfills;
|
|
221
|
+
if (raw === undefined || raw === "off")return null;
|
|
222
|
+
const runtime = typeof raw == "string" ? { mode: raw } : { ...raw },mode = runtime.mode ?? "auto";
|
|
223
|
+
if (mode !== "auto" && mode !== "usage" && mode !== "entry") {
|
|
224
|
+
throw new Error("@zntc/core: runtimePolyfills.mode must be 'auto', 'usage', or 'entry'.");
|
|
225
|
+
}
|
|
226
|
+
const provider = runtime.provider ?? "core-js";
|
|
227
|
+
if (provider !== "core-js") {
|
|
228
|
+
throw new Error("@zntc/core: runtimePolyfills.provider currently supports only 'core-js'.");
|
|
229
|
+
}
|
|
230
|
+
return { mode, provider, targets: chooseRuntimeTargets(options, runtime), include: (runtime.include ?? []).map(normalizeCoreJsModuleName), exclude: (runtime.exclude ?? []).map(normalizeCoreJsModuleName), proposals: runtime.proposals === true, coreJsVersion: runtime.coreJs ?? options.coreJs ?? readInstalledCoreJsVersion() };
|
|
231
|
+
}
|
|
232
|
+
function computeCoreJsCompatModules(targets,modules,options={}) {
|
|
233
|
+
const compat = loadCoreJsCompat(),result = compat({ targets, modules, version: options.version, proposals: options.proposals });
|
|
234
|
+
return result.list.map(normalizeCoreJsModuleName).sort();
|
|
235
|
+
}
|
|
236
|
+
function buildCoreJsResolver(entryPoints) {
|
|
237
|
+
const override = runtimeRequireOverride,requires = [];
|
|
238
|
+
if (override) {
|
|
239
|
+
requires.push(override);
|
|
240
|
+
} else {
|
|
241
|
+
const entry = entryPoints[0];
|
|
242
|
+
if (entry)requires.push(createRequire(resolve(dirname(resolve(entry)), "package.json")));
|
|
243
|
+
requires.push(createRequire(require("url").pathToFileURL(__filename).href));
|
|
244
|
+
}
|
|
245
|
+
return (moduleName) => {
|
|
246
|
+
const specifier = `core-js/modules/${moduleName}.js`;
|
|
247
|
+
let firstError;
|
|
248
|
+
for (const req of requires) {
|
|
249
|
+
try {
|
|
250
|
+
return req.resolve(specifier);
|
|
251
|
+
} catch (err) {
|
|
252
|
+
firstError ??= err instanceof Error ? err.message : String(err);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
throw new Error(`@zntc/core: runtimePolyfills could not resolve '${specifier}'. Install core-js with \`bun add core-js\`.\n${firstError ?? ""}`);
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function uniqueSorted(values) {
|
|
259
|
+
return [...new Set(values)].sort();
|
|
260
|
+
}
|
|
261
|
+
function resolveRuntimeModules(modules,resolveCoreJs) {
|
|
262
|
+
return uniqueSorted(modules).map((moduleName) => ({ module: moduleName, path: resolveCoreJs(moduleName) }));
|
|
263
|
+
}
|
|
264
|
+
function applyRuntimePolyfillsToNapiOptions(napiOptions,options) {
|
|
265
|
+
delete napiOptions.runtimePolyfills;
|
|
266
|
+
delete napiOptions.coreJs;
|
|
267
|
+
if (options.target && !isEsTarget(options.target))delete napiOptions.target;
|
|
268
|
+
const runtime = normalizeRuntimePolyfillOptions(options);
|
|
269
|
+
if (!runtime)return { cleanup: () => {
|
|
270
|
+
}, modules: [] };
|
|
271
|
+
const exclude = new Set(runtime.exclude),includeModules = runtime.include.filter((moduleName) => !exclude.has(moduleName)),resolveCoreJs = buildCoreJsResolver(options.entryPoints),includeResolved = resolveRuntimeModules(includeModules, resolveCoreJs);
|
|
272
|
+
if (runtime.mode === "entry") {
|
|
273
|
+
const entryModules = computeCoreJsCompatModules(runtime.targets, /^(?:es|web)\./, { version: runtime.coreJsVersion, proposals: runtime.proposals }).filter((moduleName) => !exclude.has(moduleName)),entryResolved = resolveRuntimeModules(entryModules, resolveCoreJs);
|
|
274
|
+
if (entryResolved.length === 0 && includeResolved.length === 0) {
|
|
275
|
+
return { cleanup: () => {
|
|
276
|
+
}, modules: [] };
|
|
277
|
+
}
|
|
278
|
+
napiOptions.runtimePolyfillPlan = { mode: "entry", entry: entryResolved, include: includeResolved, exclude: runtime.exclude };
|
|
279
|
+
return { cleanup: () => {
|
|
280
|
+
}, modules: uniqueSorted([...entryResolved, ...includeResolved].map((item) => item.module)) };
|
|
281
|
+
}
|
|
282
|
+
const targetCandidateSet = new Set(computeCoreJsCompatModules(runtime.targets, RUNTIME_POLYFILL_CANDIDATE_MODULES, { version: runtime.coreJsVersion, proposals: runtime.proposals }).filter((moduleName) => !exclude.has(moduleName))),candidates = [];
|
|
283
|
+
for (const item of RUNTIME_POLYFILL_FEATURE_MODULES) {
|
|
284
|
+
if (!targetCandidateSet.has(item.module))continue;
|
|
285
|
+
candidates.push({ feature: item.feature, module: item.module, path: resolveCoreJs(item.module) });
|
|
286
|
+
}
|
|
287
|
+
if (candidates.length === 0 && includeResolved.length === 0) {
|
|
288
|
+
return { cleanup: () => {
|
|
289
|
+
}, modules: [] };
|
|
290
|
+
}
|
|
291
|
+
napiOptions.runtimePolyfillPlan = { mode: "usage", candidates, include: includeResolved, exclude: runtime.exclude };
|
|
292
|
+
return { cleanup: () => {
|
|
293
|
+
}, modules: uniqueSorted([...candidates, ...includeResolved].map((item) => item.module)) };
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region config-loader.ts
|
|
297
|
+
var randomBytes = require("node:crypto").randomBytes;
|
|
298
|
+
var existsSync = require("node:fs").existsSync;
|
|
299
|
+
var readFileSync$1 = require("node:fs").readFileSync;
|
|
300
|
+
var unlinkSync = require("node:fs").unlinkSync;
|
|
301
|
+
var writeFileSync = require("node:fs").writeFileSync;
|
|
302
|
+
var dirname$1 = require("node:path").dirname;
|
|
303
|
+
var extname = require("node:path").extname;
|
|
304
|
+
var join = require("node:path").join;
|
|
305
|
+
var pathResolve = require("node:path").resolve;
|
|
306
|
+
var pathToFileURL = require("node:url").pathToFileURL;
|
|
307
|
+
var CONFIG_EXT_PRIORITY = [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
|
|
308
|
+
var TS_EXTS = new Set(CONFIG_EXT_PRIORITY.slice(0, 3)),JS_EXTS = new Set(CONFIG_EXT_PRIORITY.slice(3, 6));
|
|
309
|
+
async function loadConfig(filePath,env) {
|
|
310
|
+
const absPath = pathResolve(filePath);
|
|
311
|
+
return loadConfigWithExtends(absPath, env, new Set());
|
|
312
|
+
}
|
|
313
|
+
async function loadConfigWithExtends(absPath,env,visited) {
|
|
314
|
+
if (visited.has(absPath)) {
|
|
315
|
+
throw new Error(`@zntc/core: circular extends detected at ${absPath} (chain: ${[...visited, absPath].join(" → ")})`);
|
|
316
|
+
}
|
|
317
|
+
visited.add(absPath);
|
|
318
|
+
const raw = await loadModuleDefault(absPath, "config"),resolved = await resolveConfigValue(raw, env, absPath),extendsField = resolved.extends;
|
|
319
|
+
if (extendsField === undefined)return resolved;
|
|
320
|
+
const extendsPaths = Array.isArray(extendsField) ? extendsField : [extendsField],baseDir = dirname$1(absPath);
|
|
321
|
+
let merged = {};
|
|
322
|
+
for (const extPath of extendsPaths) {
|
|
323
|
+
const resolvedExt = pathResolve(baseDir, extPath),base = await loadConfigWithExtends(resolvedExt, env, new Set(visited));
|
|
324
|
+
merged = mergeUserConfigs(merged, base);
|
|
325
|
+
}
|
|
326
|
+
const { extends:_extends, ...currentWithoutExtends } = resolved;
|
|
327
|
+
return mergeUserConfigs(merged, currentWithoutExtends);
|
|
328
|
+
}
|
|
329
|
+
function defaultConfigEnv() {
|
|
330
|
+
return { command: "bundle", mode: "production", env: process.env };
|
|
331
|
+
}
|
|
332
|
+
async function resolveConfigValue(raw,env,absPath) {
|
|
333
|
+
if (typeof raw != "function") {
|
|
334
|
+
return raw;
|
|
335
|
+
}
|
|
336
|
+
const result = await raw(env ?? defaultConfigEnv());
|
|
337
|
+
if (!isPlainObject(result)) {
|
|
338
|
+
const got = Array.isArray(result) ? "array" : typeof result;
|
|
339
|
+
throw new Error(`@zntc/core: functional config must return an object (got ${got}) from ${absPath}`);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
async function loadModuleDefault(absPath,kind,options) {
|
|
344
|
+
const allowArray = options?.allowArray === true,ext = extname(absPath).toLowerCase();
|
|
345
|
+
if (ext === ".json") {
|
|
346
|
+
const raw = readFileOrThrowNotFound(absPath);
|
|
347
|
+
try {
|
|
348
|
+
return JSON.parse(raw);
|
|
349
|
+
} catch (err) {
|
|
350
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
351
|
+
throw new Error(`@zntc/core: failed to parse JSON ${kind} ${absPath}: ${reason}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (TS_EXTS.has(ext)) {
|
|
355
|
+
return (await loadTsModule(absPath, kind, allowArray));
|
|
356
|
+
}
|
|
357
|
+
if (JS_EXTS.has(ext)) {
|
|
358
|
+
try {
|
|
359
|
+
return await importAndResolveDefault(absPath, { allowArray });
|
|
360
|
+
} catch (err) {
|
|
361
|
+
if (err instanceof Error) {
|
|
362
|
+
err.message = err.message.replace("module not found", `${kind} file not found`).replace(/module must be an object or function/, `${kind} must export an object or function`);
|
|
363
|
+
}
|
|
364
|
+
throw err;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
throw new Error(`@zntc/core: unsupported ${kind} extension "${ext}" for ${absPath}. Supported: .ts/.mts/.cts/.mjs/.js/.cjs/.json`);
|
|
368
|
+
}
|
|
369
|
+
async function loadTsModule(absPath,kind,allowArray) {
|
|
370
|
+
init();
|
|
371
|
+
const source = readFileOrThrowNotFound(absPath),parseFilename = absPath.endsWith(".cts") ? absPath.slice(0, -4) + ".ts" : absPath,result = transpile(source, { filename: parseFilename, format: "esm" });
|
|
372
|
+
if (result.errors) {
|
|
373
|
+
throw new Error(`@zntc/core: ${kind} compile failed in ${absPath}\n${result.errors}`);
|
|
374
|
+
}
|
|
375
|
+
const tmpName = `.zntc-${kind}.bundled-${randomBytes(6).toString("hex")}.mjs`,tmpPath = join(dirname$1(absPath), tmpName);
|
|
376
|
+
writeFileSync(tmpPath, result.code, "utf8");
|
|
377
|
+
try {
|
|
378
|
+
return await importAndResolveDefault(tmpPath, { allowArray });
|
|
379
|
+
} finally {
|
|
380
|
+
try {
|
|
381
|
+
unlinkSync(tmpPath);
|
|
382
|
+
} catch (err) {
|
|
383
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
384
|
+
console.warn(`@zntc/core: failed to remove tmp ${kind} ${tmpPath}: ${reason}`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function importAndResolveDefault(absPath,options) {
|
|
389
|
+
const allowArray = options?.allowArray === true;
|
|
390
|
+
;
|
|
391
|
+
let mod;
|
|
392
|
+
try {
|
|
393
|
+
mod = await import(url);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
const code = err?.code;
|
|
396
|
+
if (code === "ERR_MODULE_NOT_FOUND" || code === "ENOENT") {
|
|
397
|
+
throw new Error(`@zntc/core: module not found: ${absPath}`);
|
|
398
|
+
}
|
|
399
|
+
throw err;
|
|
400
|
+
}
|
|
401
|
+
const value = mod.default ?? mod,valueType = typeof value,isArray = Array.isArray(value);
|
|
402
|
+
;
|
|
403
|
+
if (valueType !== "function" && !(valueType === "object" && value !== null && (allowArray || !isArray))) {
|
|
404
|
+
;
|
|
405
|
+
throw new Error(`@zntc/core: module must be an object or function (got ${(value === null ? "null" : isArray ? "array" : valueType)}) from ${absPath}`);
|
|
406
|
+
}
|
|
407
|
+
return value;
|
|
408
|
+
}
|
|
409
|
+
function readFileOrThrowNotFound(absPath) {
|
|
410
|
+
try {
|
|
411
|
+
return readFileSync$1(absPath, "utf8");
|
|
412
|
+
} catch (err) {
|
|
413
|
+
if (err.code === "ENOENT") {
|
|
414
|
+
throw new Error(`@zntc/core: config file not found: ${absPath}`);
|
|
415
|
+
}
|
|
416
|
+
throw err;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function readFileIfExists(absPath) {
|
|
420
|
+
try {
|
|
421
|
+
return readFileSync$1(absPath, "utf8");
|
|
422
|
+
} catch (err) {
|
|
423
|
+
const code = err.code;
|
|
424
|
+
if (code === "ENOENT" || code === "ENOTDIR")return null;
|
|
425
|
+
throw err;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function findConfigPath(cwd) {
|
|
429
|
+
for (const ext of CONFIG_EXT_PRIORITY) {
|
|
430
|
+
const candidate = join(cwd, `zntc.config${ext}`);
|
|
431
|
+
if (existsSync(candidate))return candidate;
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
function findModeConfigPath(cwd,mode) {
|
|
436
|
+
if (!mode)return null;
|
|
437
|
+
for (const ext of CONFIG_EXT_PRIORITY) {
|
|
438
|
+
const candidate = join(cwd, `zntc.config.${mode}${ext}`);
|
|
439
|
+
if (existsSync(candidate))return candidate;
|
|
440
|
+
}
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
function mergeUserConfigs(base,mode) {
|
|
444
|
+
const merged = { ...base };
|
|
445
|
+
for (const key of Object.keys(mode)) {
|
|
446
|
+
const modeVal = mode[key];
|
|
447
|
+
if (modeVal === undefined)continue;
|
|
448
|
+
if (key === "plugins" && Array.isArray(modeVal) && Array.isArray(merged.plugins)) {
|
|
449
|
+
merged.plugins = [...merged.plugins, ...modeVal];
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
const baseVal = base[key];
|
|
453
|
+
if (typeof baseVal == "object" && baseVal !== null && !Array.isArray(baseVal) && typeof modeVal == "object" && modeVal !== null && !Array.isArray(modeVal)) {
|
|
454
|
+
merged[key] = { ...baseVal, ...modeVal };
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
merged[key] = modeVal;
|
|
458
|
+
}
|
|
459
|
+
return merged;
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region load-env.ts
|
|
463
|
+
var pathResolve$1 = require("node:path").resolve;
|
|
464
|
+
function parseDotenvLine(line) {
|
|
465
|
+
const trimmed = line.trim();
|
|
466
|
+
if (!trimmed || trimmed.startsWith("#"))return null;
|
|
467
|
+
const eqIdx = trimmed.indexOf("=");
|
|
468
|
+
if (eqIdx <= 0)return null;
|
|
469
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
470
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))return null;
|
|
471
|
+
let value = trimmed.slice(eqIdx + 1).trim();
|
|
472
|
+
const quoted = (value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"));
|
|
473
|
+
if (quoted) {
|
|
474
|
+
value = value.slice(1, -1);
|
|
475
|
+
} else {
|
|
476
|
+
value = value.replace(/\s+#.*$/, "");
|
|
477
|
+
}
|
|
478
|
+
return [key, value];
|
|
479
|
+
}
|
|
480
|
+
function parseDotenvFile(filePath) {
|
|
481
|
+
const content = readFileIfExists(filePath);
|
|
482
|
+
if (content === null)return {};
|
|
483
|
+
const out = {};
|
|
484
|
+
for (const line of content.split(/\r?\n/)) {
|
|
485
|
+
const parsed = parseDotenvLine(line);
|
|
486
|
+
if (parsed)out[parsed[0]] = parsed[1];
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
function loadEnv(mode,envDir,prefixes=["VITE_", "ZNTC_"]) {
|
|
491
|
+
const prefixList = Array.isArray(prefixes) ? prefixes : [prefixes],dir = pathResolve$1(envDir),files = [`.env`, `.env.local`, `.env.${mode}`, `.env.${mode}.local`],merged = {};
|
|
492
|
+
for (const file of files) {
|
|
493
|
+
Object.assign(merged, parseDotenvFile(`${dir}/${file}`));
|
|
494
|
+
}
|
|
495
|
+
const filtered = {};
|
|
496
|
+
for (const [key, value] of Object.entries(merged)) {
|
|
497
|
+
if (prefixList.some((p) => key.startsWith(p))) {
|
|
498
|
+
filtered[key] = value;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return filtered;
|
|
502
|
+
}
|
|
503
|
+
function envToDefine(env,mode,baseUrl="/") {
|
|
504
|
+
const envObject = { MODE: mode, PROD: mode === "production", DEV: mode !== "production", SSR: false, BASE_URL: baseUrl };
|
|
505
|
+
for (const [key, value] of Object.entries(env))envObject[key] = value;
|
|
506
|
+
const define = { "import.meta.env": JSON.stringify(envObject) };
|
|
507
|
+
for (const [key, value] of Object.entries(envObject)) {
|
|
508
|
+
define[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
509
|
+
}
|
|
510
|
+
return define;
|
|
511
|
+
}
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region typo-suggest.ts
|
|
514
|
+
function levenshtein(a,b) {
|
|
515
|
+
if (a.length === 0)return b.length;
|
|
516
|
+
if (b.length === 0)return a.length;
|
|
517
|
+
const [s, l] = a.length <= b.length ? [a, b] : [b, a];
|
|
518
|
+
let prev = Array.from({ length: s.length + 1 }),curr = Array.from({ length: s.length + 1 });
|
|
519
|
+
for (let i = 0; i <= s.length; i++)prev[i] = i;
|
|
520
|
+
for (let i = 1; i <= l.length; i++) {
|
|
521
|
+
curr[0] = i;
|
|
522
|
+
for (let j = 1; j <= s.length; j++) {
|
|
523
|
+
const cost = l.charCodeAt(i - 1) === s.charCodeAt(j - 1) ? 0 : 1;
|
|
524
|
+
curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
|
|
525
|
+
}
|
|
526
|
+
[prev, curr] = [curr, prev];
|
|
527
|
+
}
|
|
528
|
+
return prev[s.length];
|
|
529
|
+
}
|
|
530
|
+
function suggestKey(unknown,known,threshold=2) {
|
|
531
|
+
if (!unknown || known.length === 0)return null;
|
|
532
|
+
const adjusted = Math.min(threshold, Math.max(1, Math.ceil(unknown.length / 3)));
|
|
533
|
+
let best = null,bestDist = adjusted + 1;
|
|
534
|
+
for (const candidate of known) {
|
|
535
|
+
const d = levenshtein(unknown, candidate);
|
|
536
|
+
if (d > adjusted)continue;
|
|
537
|
+
if (d < bestDist || (d === bestDist && best !== null && candidate < best)) {
|
|
538
|
+
best = candidate;
|
|
539
|
+
bestDist = d;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return best;
|
|
543
|
+
}
|
|
544
|
+
function warnUnknownKeys(config,known,options={}) {
|
|
545
|
+
const result = [],knownSet = new Set(known);
|
|
546
|
+
for (const key of Object.keys(config)) {
|
|
547
|
+
if (knownSet.has(key))continue;
|
|
548
|
+
const suggestion = suggestKey(key, known);
|
|
549
|
+
result.push({ unknown: key, suggestion });
|
|
550
|
+
if (!options.silent) {
|
|
551
|
+
const where = options.sourceLabel ? ` (${options.sourceLabel})` : "",hint = suggestion ? ` — did you mean '${suggestion}'?` : "";
|
|
552
|
+
console.warn(`@zntc/core: unknown config key '${key}'${where}${hint}`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
556
|
+
}
|
|
557
|
+
const KNOWN_CONFIG_KEYS = ["entryPoints", "outdir", "outfile", "outbase", "format", "platform", "target", "browserslist", "runtimePolyfills", "coreJs", "jsx", "jsxDev", "jsxFactory", "jsxFragment", "jsxImportSource", "jsxInJs", "jsxSideEffects", "minify", "minifyWhitespace", "minifyIdentifiers", "minifySyntax", "sourcemap", "sourcemapMode", "sourcemapDebugIds", "sourcesContent", "sourceRoot", "external", "alias", "define", "server", "loader", "conditions", "nodePaths", "moduleSpecifierMap", "resolveExtensions", "mainFields", "packagesExternal", "preserveSymlinks", "resolveSymlinkSiblings", "disableHierarchicalLookup", "splitting", "outputExports", "preserveModules", "preserveModulesRoot", "inlineDynamicImports", "manualChunks", "minChunkSize", "metafile", "treeShaking", "shimMissingExports", "keepNames", "drop", "dropConsole", "dropDebugger", "dropLabels", "banner", "footer", "intro", "outro", "inject", "pure", "legalComments", "entryNames", "chunkNames", "assetNames", "experimentalDecorators", "emitDecoratorMetadata", "useDefineForClassFields", "verbatimModuleSyntax", "tsconfigPath", "tsconfigRaw", "globalName", "globals", "publicPath", "charsetUtf8", "asciiOnly", "quotes", "compiler", "mf", "flow", "plugins", "logLevel", "logLimit", "lineLimit", "profile", "profileFormat", "profileLevel", "tokenizeFormat", "stopAfter", "ignoreAnnotations", "watchDelay", "jobs", "codegenTransform", "extends", "root", "projectRoot", "entry", "dev", "outDir", "bundler", "resolver", "transformer", "serializer", "symbolicator", "watchFolders"];
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region workspace.ts
|
|
560
|
+
var existsSync$1 = require("node:fs").existsSync;
|
|
561
|
+
var readdirSync = require("node:fs").readdirSync;
|
|
562
|
+
var readFileSync$2 = require("node:fs").readFileSync;
|
|
563
|
+
var basename = require("node:path").basename;
|
|
564
|
+
var join$1 = require("node:path").join;
|
|
565
|
+
var pathResolve$2 = require("node:path").resolve;
|
|
566
|
+
var CONFIG_EXT_PRIORITY_LOCAL = [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
|
|
567
|
+
function defineWorkspace(input) {
|
|
568
|
+
return input;
|
|
569
|
+
}
|
|
570
|
+
var WORKSPACE_EXT_PRIORITY = CONFIG_EXT_PRIORITY_LOCAL;
|
|
571
|
+
function findWorkspacePath(cwd) {
|
|
572
|
+
for (const ext of WORKSPACE_EXT_PRIORITY) {
|
|
573
|
+
const p = join$1(cwd, `zntc.workspace${ext}`);
|
|
574
|
+
if (existsSync$1(p))return p;
|
|
575
|
+
}
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
async function loadWorkspace(filePath,env) {
|
|
579
|
+
const absPath = pathResolve$2(filePath),raw = await loadModuleDefault(absPath, "workspace", { allowArray: true }),entries = typeof raw == "function" ? await raw(env ?? defaultConfigEnv()) : raw;
|
|
580
|
+
if (!Array.isArray(entries)) {
|
|
581
|
+
;
|
|
582
|
+
throw new Error(`@zntc/core: workspace must export an array (got ${(entries === null ? "null" : typeof entries)}) from ${absPath}`);
|
|
583
|
+
}
|
|
584
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
585
|
+
const e = entries[i];
|
|
586
|
+
if (typeof e == "string") {
|
|
587
|
+
if (!e.length) {
|
|
588
|
+
throw new Error(`@zntc/core: workspace[${i}] is empty string in ${absPath}`);
|
|
589
|
+
}
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (!isPlainObject(e)) {
|
|
593
|
+
throw new Error(`@zntc/core: workspace[${i}] must be a string or object (got ${Array.isArray(e) ? "array" : e === null ? "null" : typeof e}) in ${absPath}`);
|
|
594
|
+
}
|
|
595
|
+
const name = e.name;
|
|
596
|
+
if (typeof name != "string" || !name) {
|
|
597
|
+
throw new Error(`@zntc/core: workspace[${i}] inline entry requires non-empty 'name' in ${absPath}`);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return entries;
|
|
601
|
+
}
|
|
602
|
+
function identifyWorkspaceEntries(entries,rootDir) {
|
|
603
|
+
const seen = new Set(),out = [],push = (w) => {
|
|
604
|
+
if (seen.has(w.cwd))return;
|
|
605
|
+
seen.add(w.cwd);
|
|
606
|
+
out.push(w);
|
|
607
|
+
};
|
|
608
|
+
for (const entry of entries) {
|
|
609
|
+
if (typeof entry == "string") {
|
|
610
|
+
if (entry.includes("*")) {
|
|
611
|
+
for (const dir of expandGlob(entry, rootDir)) {
|
|
612
|
+
push({ name: detectPackageName(dir), cwd: dir, source: "glob", inlineConfig: null });
|
|
613
|
+
}
|
|
614
|
+
} else {
|
|
615
|
+
const abs = pathResolve$2(rootDir, entry);
|
|
616
|
+
push({ name: detectPackageName(abs), cwd: abs, source: "path", inlineConfig: null });
|
|
617
|
+
}
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
const { name:name, ...rest } = entry;
|
|
621
|
+
push({ name, cwd: rootDir, source: "inline", inlineConfig: rest });
|
|
622
|
+
}
|
|
623
|
+
return out;
|
|
624
|
+
}
|
|
625
|
+
async function loadIdentifiedConfig(w,env) {
|
|
626
|
+
if (w.inlineConfig)return w.inlineConfig;
|
|
627
|
+
const configPath = findConfigPath(w.cwd);
|
|
628
|
+
return configPath ? await loadConfig(configPath, env) : {};
|
|
629
|
+
}
|
|
630
|
+
function expandGlob(pattern,rootDir) {
|
|
631
|
+
if (pattern.includes("**")) {
|
|
632
|
+
throw new Error(`@zntc/core: workspace glob '**' is not supported (got '${pattern}'). Use single-level '*' patterns.`);
|
|
633
|
+
}
|
|
634
|
+
const lastSep = pattern.lastIndexOf("/");
|
|
635
|
+
if (lastSep === -1) {
|
|
636
|
+
return enumerateDirs(rootDir, pattern);
|
|
637
|
+
}
|
|
638
|
+
const dirPart = pattern.slice(0, lastSep),namePart = pattern.slice(lastSep + 1);
|
|
639
|
+
if (dirPart.includes("*")) {
|
|
640
|
+
throw new Error(`@zntc/core: workspace glob with '*' in directory part is not supported (got '${pattern}'). Use trailing-only '*'.`);
|
|
641
|
+
}
|
|
642
|
+
if (!namePart.includes("*")) {
|
|
643
|
+
return [pathResolve$2(rootDir, pattern)];
|
|
644
|
+
}
|
|
645
|
+
const baseDir = pathResolve$2(rootDir, dirPart);
|
|
646
|
+
return enumerateDirs(baseDir, namePart);
|
|
647
|
+
}
|
|
648
|
+
function enumerateDirs(baseDir,namePattern) {
|
|
649
|
+
if (!existsSync$1(baseDir))return [];
|
|
650
|
+
const matcher = makeStarMatcher(namePattern),out = [];
|
|
651
|
+
for (const d of readdirSync(baseDir, { withFileTypes: true })) {
|
|
652
|
+
if (!d.isDirectory())continue;
|
|
653
|
+
if (d.name.startsWith("."))continue;
|
|
654
|
+
if (d.name === "node_modules")continue;
|
|
655
|
+
if (matcher(d.name))out.push(join$1(baseDir, d.name));
|
|
656
|
+
}
|
|
657
|
+
out.sort();
|
|
658
|
+
return out;
|
|
659
|
+
}
|
|
660
|
+
function makeStarMatcher(pattern) {
|
|
661
|
+
if (pattern === "*")return () => true;
|
|
662
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*"),re = new RegExp("^" + escaped + "$");
|
|
663
|
+
return (s) => re.test(s);
|
|
664
|
+
}
|
|
665
|
+
function detectPackageName(absDir) {
|
|
666
|
+
const pkgPath = join$1(absDir, "package.json");
|
|
667
|
+
if (existsSync$1(pkgPath)) {
|
|
668
|
+
try {
|
|
669
|
+
const pkg = JSON.parse(readFileSync$2(pkgPath, "utf8"));
|
|
670
|
+
if (typeof pkg.name == "string" && pkg.name)return pkg.name;
|
|
671
|
+
} catch {
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return basename(absDir);
|
|
675
|
+
}
|
|
676
|
+
function filterWorkspaces(workspaces,filter) {
|
|
677
|
+
if (!filter)return workspaces;
|
|
678
|
+
const filtered = workspaces.filter((w) => w.name === filter);
|
|
679
|
+
if (filtered.length === 0) {
|
|
680
|
+
const available = workspaces.map((w) => w.name).join(", ");
|
|
681
|
+
throw new Error(`@zntc/core: --workspace='${filter}' matched 0 entries (available: ${available || "<none>"})`);
|
|
682
|
+
}
|
|
683
|
+
return filtered;
|
|
684
|
+
}
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region index.ts
|
|
687
|
+
var createRequire$1 = require("module").createRequire;
|
|
688
|
+
var existsSync$2 = require("fs").existsSync;
|
|
689
|
+
var mkdirSync = require("fs").mkdirSync;
|
|
690
|
+
var writeFileSync$1 = require("fs").writeFileSync;
|
|
691
|
+
var join$2 = require("path").join;
|
|
692
|
+
var dirname$2 = require("path").dirname;
|
|
693
|
+
var resolve$1 = require("path").resolve;
|
|
694
|
+
var fileURLToPath = require("url").fileURLToPath;
|
|
695
|
+
var UTF8_DECODER = new TextDecoder("utf-8");
|
|
696
|
+
function attachTextGetter(file) {
|
|
697
|
+
let cachedContents,cachedText;
|
|
698
|
+
Object.defineProperty(file, "text", { get() {
|
|
699
|
+
if (cachedContents !== file.contents) {
|
|
700
|
+
cachedContents = file.contents;
|
|
701
|
+
cachedText = UTF8_DECODER.decode(cachedContents);
|
|
702
|
+
}
|
|
703
|
+
return cachedText;
|
|
704
|
+
}, enumerable: false, configurable: true });
|
|
705
|
+
return file;
|
|
706
|
+
}
|
|
707
|
+
function wrapOutputFiles(result) {
|
|
708
|
+
for (const file of result.outputFiles)attachTextGetter(file);
|
|
709
|
+
return result;
|
|
710
|
+
}
|
|
711
|
+
var native = null;
|
|
712
|
+
function detectLinuxLibc() {
|
|
713
|
+
if (process.platform !== "linux")return undefined;
|
|
714
|
+
try {
|
|
715
|
+
const report = process.report?.getReport();
|
|
716
|
+
if (report?.header?.glibcVersionRuntime)return "glibc";
|
|
717
|
+
} catch {
|
|
718
|
+
}
|
|
719
|
+
return "musl";
|
|
720
|
+
}
|
|
721
|
+
function getPlatformPackage() {
|
|
722
|
+
const { platform:platform, arch:arch } = process,libc = detectLinuxLibc(),match = PLATFORMS.find((p) => p.npmOs === platform && p.npmCpu === arch && p.npmLibc === libc);
|
|
723
|
+
return match ? subPackageName(match) : null;
|
|
724
|
+
}
|
|
725
|
+
function findAddon() {
|
|
726
|
+
const __dirname = dirname$2(fileURLToPath(require("url").pathToFileURL(__filename).href)),platformPkg = getPlatformPackage(),zigOut = join$2(__dirname, "../../zig-out/lib/zntc.node");
|
|
727
|
+
if (existsSync$2(zigOut))return zigOut;
|
|
728
|
+
const zigOut2 = join$2(__dirname, "../../../zig-out/lib/zntc.node");
|
|
729
|
+
if (existsSync$2(zigOut2))return zigOut2;
|
|
730
|
+
if (platformPkg) {
|
|
731
|
+
try {
|
|
732
|
+
const nodeRequire = createRequire$1(require("url").pathToFileURL(__filename).href);
|
|
733
|
+
return nodeRequire.resolve(platformPkg);
|
|
734
|
+
} catch {
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
const local = join$2(__dirname, "zntc.node");
|
|
738
|
+
if (existsSync$2(local))return local;
|
|
739
|
+
const parent = join$2(__dirname, "../zntc.node");
|
|
740
|
+
if (existsSync$2(parent))return parent;
|
|
741
|
+
const expected = platformPkg ? ` (expected sub-package: ${platformPkg})` : "";
|
|
742
|
+
throw new Error(`@zntc/core: native binary not found for ${process.platform}-${process.arch}${expected}. ` + `Supported: ${formatSupportedPlatforms()}. ` + "For development run `zig build napi`. " + "If your platform should be supported, please open an issue.");
|
|
743
|
+
}
|
|
744
|
+
function defineConfig(config) {
|
|
745
|
+
return config;
|
|
746
|
+
}
|
|
747
|
+
function init(addonPath) {
|
|
748
|
+
if (native)return;
|
|
749
|
+
const path = addonPath ?? findAddon(),nodeRequire = createRequire$1(require("url").pathToFileURL(__filename).href);
|
|
750
|
+
native = nodeRequire(path);
|
|
751
|
+
}
|
|
752
|
+
function ensureNative() {
|
|
753
|
+
init();
|
|
754
|
+
return native;
|
|
755
|
+
}
|
|
756
|
+
var _browserslist = null,_browserslistResolved = false;
|
|
757
|
+
function loadBrowserslist() {
|
|
758
|
+
if (_browserslistResolved)return _browserslist;
|
|
759
|
+
_browserslistResolved = true;
|
|
760
|
+
try {
|
|
761
|
+
const req = createRequire$1(require("url").pathToFileURL(__filename).href);
|
|
762
|
+
;
|
|
763
|
+
_browserslist = req("browserslist");
|
|
764
|
+
} catch {
|
|
765
|
+
_browserslist = null;
|
|
766
|
+
}
|
|
767
|
+
return _browserslist;
|
|
768
|
+
}
|
|
769
|
+
function resolveUnsupported(options) {
|
|
770
|
+
if (options.browserslist) {
|
|
771
|
+
const bl = loadBrowserslist();
|
|
772
|
+
if (!bl) {
|
|
773
|
+
throw new Error("@zntc/core: 'browserslist' option requires the 'browserslist' package. Install it: bun add browserslist");
|
|
774
|
+
}
|
|
775
|
+
return browserslistToUnsupported(bl(options.browserslist));
|
|
776
|
+
}
|
|
777
|
+
return options.target ? (ES_TARGET_BITS[options.target] ?? 0) : 0;
|
|
778
|
+
}
|
|
779
|
+
var TsconfigCache = class {
|
|
780
|
+
_handle;
|
|
781
|
+
constructor() {
|
|
782
|
+
this._handle = ensureNative().createTsconfigCache();
|
|
783
|
+
}
|
|
784
|
+
clear() {
|
|
785
|
+
this._handle.clear();
|
|
786
|
+
}
|
|
787
|
+
get size() {
|
|
788
|
+
return this._handle.size();
|
|
789
|
+
}
|
|
790
|
+
[Symbol.dispose]() {
|
|
791
|
+
this._handle.clear();
|
|
792
|
+
}
|
|
793
|
+
static _unwrap(c) {
|
|
794
|
+
return c._handle;
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
function transpile(source,options={}) {
|
|
798
|
+
if (!source)throw new Error("@zntc/core: empty source");
|
|
799
|
+
validateTsConfigRaw(options.tsconfigRaw);
|
|
800
|
+
const optionsJson = buildOptionsJson(options, resolveUnsupported(options));
|
|
801
|
+
return ensureNative().transpile(source, options.filename ?? "input.js", optionsJson, options.cache ? TsconfigCache._unwrap(options.cache) : undefined);
|
|
802
|
+
}
|
|
803
|
+
function tokenize(source,options={}) {
|
|
804
|
+
if (!source)throw new Error("@zntc/core: empty source");
|
|
805
|
+
return ensureNative().tokenize(source, options.filename ?? "input.js");
|
|
806
|
+
}
|
|
807
|
+
function configureProfile(profile,level) {
|
|
808
|
+
ensureNative().configureProfile(profile, level);
|
|
809
|
+
}
|
|
810
|
+
function profileReport(format="table") {
|
|
811
|
+
return ensureNative().profileReport(format);
|
|
812
|
+
}
|
|
813
|
+
function normalizePluginFailure(pluginName,hookName,thrown,fallbackFile) {
|
|
814
|
+
let message = "Plugin hook failed",file = fallbackFile ?? undefined,line,column;
|
|
815
|
+
if (typeof thrown == "string") {
|
|
816
|
+
message = thrown;
|
|
817
|
+
} else if (thrown && typeof thrown == "object") {
|
|
818
|
+
const err = thrown;
|
|
819
|
+
if (typeof err.message == "string")message = err.message; else if (typeof err.text == "string")message = err.text; else message = String(thrown);
|
|
820
|
+
const loc = err.loc,fileCandidate = loc?.file ?? err.id ?? err.file ?? err.fileName;
|
|
821
|
+
if (typeof fileCandidate == "string" && fileCandidate.length > 0)file = fileCandidate;
|
|
822
|
+
const lineCandidate = loc?.line ?? err.line ?? err.lineNumber,columnCandidate = loc?.column ?? err.column ?? err.columnNumber;
|
|
823
|
+
if (typeof lineCandidate == "number" && Number.isFinite(lineCandidate))line = lineCandidate;
|
|
824
|
+
if (typeof columnCandidate == "number" && Number.isFinite(columnCandidate)) {
|
|
825
|
+
column = columnCandidate;
|
|
826
|
+
}
|
|
827
|
+
} else if (thrown != null) {
|
|
828
|
+
message = String(thrown);
|
|
829
|
+
}
|
|
830
|
+
return { __zntcPluginFailure: true, pluginName, hookName, message, ...(file ? { file } : {}), ...(line !== undefined ? { line } : {}), ...(column !== undefined ? { column } : {}) };
|
|
831
|
+
}
|
|
832
|
+
function pluginFailureText(failure) {
|
|
833
|
+
const location = failure.file && failure.line !== undefined ? ` (${failure.file}:${failure.line}:${failure.column ?? 0})` : failure.file ? ` (${failure.file})` : "";
|
|
834
|
+
return `Plugin "${failure.pluginName}" failed in ${failure.hookName}: ${failure.message}${location}`;
|
|
835
|
+
}
|
|
836
|
+
function pluginFailureToDiagnostic(failure) {
|
|
837
|
+
return { code: "plugin_error", text: pluginFailureText(failure), ...(failure.file ? { location: { file: failure.file, line: failure.line, column: failure.column } } : {}) };
|
|
838
|
+
}
|
|
839
|
+
function serializePluginSourceMap(map) {
|
|
840
|
+
if (map == null)return null;
|
|
841
|
+
if (typeof map == "string") {
|
|
842
|
+
try {
|
|
843
|
+
JSON.parse(map);
|
|
844
|
+
} catch (err) {
|
|
845
|
+
throw new Error(`Invalid sourcemap: ${err instanceof Error ? err.message : String(err)}`);
|
|
846
|
+
}
|
|
847
|
+
return map;
|
|
848
|
+
}
|
|
849
|
+
if (typeof map != "object") {
|
|
850
|
+
throw new Error(`Invalid sourcemap: expected object, string, null, or undefined`);
|
|
851
|
+
}
|
|
852
|
+
try {
|
|
853
|
+
return JSON.stringify(map);
|
|
854
|
+
} catch (err) {
|
|
855
|
+
throw new Error(`Invalid sourcemap: ${err instanceof Error ? err.message : String(err)}`);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
function isPromiseLike(value) {
|
|
859
|
+
return (value != null && (typeof value == "object" || typeof value == "function") && typeof value.then == "function");
|
|
860
|
+
}
|
|
861
|
+
function silenceUnsupportedSyncPromise(value) {
|
|
862
|
+
Promise.resolve(value).catch(() => {
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
function syncPluginPromiseFailure(pluginName,hookName,file) {
|
|
866
|
+
return normalizePluginFailure(pluginName, hookName, new Error("buildSync() does not support async plugin hooks. Return a synchronous value or use build() instead."), file);
|
|
867
|
+
}
|
|
868
|
+
function isPluginFailureResult(value) {
|
|
869
|
+
return Boolean(value && typeof value == "object" && value.__zntcPluginFailure === true);
|
|
870
|
+
}
|
|
871
|
+
function safeSerializeSourceMap(map) {
|
|
872
|
+
try {
|
|
873
|
+
return { ok: true, map: serializePluginSourceMap(map) };
|
|
874
|
+
} catch (err) {
|
|
875
|
+
return { ok: false, err };
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
function mapMaybePromise(value,mapper) {
|
|
879
|
+
if (isPromiseLike(value))return Promise.resolve(value).then(mapper);
|
|
880
|
+
return mapper(value);
|
|
881
|
+
}
|
|
882
|
+
function collectPluginRegistry(plugins) {
|
|
883
|
+
const registry = { hooks: { resolveId: [], load: [], transform: [], renderChunk: [], resolveContext: [] }, generateBundleCallbacks: [], buildStartCallbacks: [], buildEndCallbacks: [], closeBundleCallbacks: [], astFunctionHooks: [], lifecycleFailures: [] };
|
|
884
|
+
for (const plugin of plugins) {
|
|
885
|
+
const build = { onResolve(opts,cb) {
|
|
886
|
+
registry.hooks.resolveId.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
|
|
887
|
+
}, onLoad(opts,cb) {
|
|
888
|
+
registry.hooks.load.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
|
|
889
|
+
}, onTransform(opts,cb) {
|
|
890
|
+
registry.hooks.transform.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
|
|
891
|
+
}, onRenderChunk(opts,cb) {
|
|
892
|
+
registry.hooks.renderChunk.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
|
|
893
|
+
}, onGenerateBundle(cb) {
|
|
894
|
+
registry.generateBundleCallbacks.push({ pluginName: plugin.name, callback: cb });
|
|
895
|
+
}, onBuildStart(cb) {
|
|
896
|
+
registry.buildStartCallbacks.push({ pluginName: plugin.name, callback: cb });
|
|
897
|
+
}, onBuildEnd(cb) {
|
|
898
|
+
registry.buildEndCallbacks.push({ pluginName: plugin.name, callback: cb });
|
|
899
|
+
}, onCloseBundle(cb) {
|
|
900
|
+
registry.closeBundleCallbacks.push({ pluginName: plugin.name, callback: cb });
|
|
901
|
+
}, onAstFunction(opts,cb) {
|
|
902
|
+
registry.astFunctionHooks.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
|
|
903
|
+
}, onResolveContext(opts,cb) {
|
|
904
|
+
registry.hooks.resolveContext.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
|
|
905
|
+
} };
|
|
906
|
+
plugin.setup(build);
|
|
907
|
+
}
|
|
908
|
+
return registry;
|
|
909
|
+
}
|
|
910
|
+
var pluginArgBuilders = { resolveId: (arg1, arg2) => [arg1, { path: arg1, importer: arg2 }], load: (arg1, _) => [arg1, { path: arg1 }], renderChunk: (arg1, arg2) => [arg2 ?? "", { code: arg1, chunk: arg2 }] };
|
|
911
|
+
function lifecycleHookSpec(reg,hookName,arg1) {
|
|
912
|
+
switch (hookName) {
|
|
913
|
+
case "generateBundle":
|
|
914
|
+
{
|
|
915
|
+
const outputs = arg1;
|
|
916
|
+
for (const file of outputs)attachTextGetter(file);
|
|
917
|
+
return { callbacks: reg.generateBundleCallbacks, arg: outputs, surfaceFailures: false };
|
|
918
|
+
}
|
|
919
|
+
case "buildStart":
|
|
920
|
+
return { callbacks: reg.buildStartCallbacks, arg: undefined, surfaceFailures: false };
|
|
921
|
+
case "buildEnd":
|
|
922
|
+
{
|
|
923
|
+
const msg = arg1;
|
|
924
|
+
return { callbacks: reg.buildEndCallbacks, arg: msg && msg.length > 0 ? new Error(msg) : undefined, surfaceFailures: true };
|
|
925
|
+
}
|
|
926
|
+
case "closeBundle":
|
|
927
|
+
return { callbacks: reg.closeBundleCallbacks, arg: undefined, surfaceFailures: true };
|
|
928
|
+
default:
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function* dispatchHook(reg,hookName,arg1,arg2) {
|
|
933
|
+
if (hookName === "astFunction") {
|
|
934
|
+
if (reg.astFunctionHooks.length === 0)return null;
|
|
935
|
+
let info;
|
|
936
|
+
try {
|
|
937
|
+
info = JSON.parse(arg1);
|
|
938
|
+
} catch {
|
|
939
|
+
return null;
|
|
940
|
+
}
|
|
941
|
+
for (const h of reg.astFunctionHooks) {
|
|
942
|
+
if (!h.filter.test(info.sourcePath))continue;
|
|
943
|
+
const result = yield { callback: () => h.callback(info), pluginName: h.pluginName, hookName: "astFunction", fallbackFile: info.sourcePath };
|
|
944
|
+
if (isPluginFailureResult(result))return result;
|
|
945
|
+
if (result != null)return result;
|
|
946
|
+
}
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
if (hookName === "resolveContext") {
|
|
950
|
+
if (reg.hooks.resolveContext.length === 0)return null;
|
|
951
|
+
let args;
|
|
952
|
+
try {
|
|
953
|
+
args = JSON.parse(arg1);
|
|
954
|
+
} catch {
|
|
955
|
+
return null;
|
|
956
|
+
}
|
|
957
|
+
for (const h of reg.hooks.resolveContext) {
|
|
958
|
+
if (!h.filter.test(args.dir))continue;
|
|
959
|
+
const result = yield { callback: () => h.callback(args), pluginName: h.pluginName, hookName: "resolveContext", fallbackFile: args.importer };
|
|
960
|
+
if (isPluginFailureResult(result))return result;
|
|
961
|
+
if (result != null)return result;
|
|
962
|
+
}
|
|
963
|
+
return null;
|
|
964
|
+
}
|
|
965
|
+
{
|
|
966
|
+
const spec = lifecycleHookSpec(reg, hookName, arg1);
|
|
967
|
+
if (spec) {
|
|
968
|
+
let firstFailure = null;
|
|
969
|
+
for (const { pluginName:pluginName, callback:callback } of spec.callbacks) {
|
|
970
|
+
const result = yield { callback: () => callback(spec.arg), pluginName, hookName };
|
|
971
|
+
if (isPluginFailureResult(result) && firstFailure == null)firstFailure = result;
|
|
972
|
+
}
|
|
973
|
+
if (spec.surfaceFailures) {
|
|
974
|
+
if (firstFailure)reg.lifecycleFailures.push(firstFailure);
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
return firstFailure;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
if (hookName === "transform" || hookName === "renderChunk") {
|
|
981
|
+
const hookList = reg.hooks[hookName];
|
|
982
|
+
if (!hookList)return null;
|
|
983
|
+
let currentCode = arg1,changed = false;
|
|
984
|
+
const sourceMaps = [];
|
|
985
|
+
for (const h of hookList) {
|
|
986
|
+
if (!h.filter.test(arg2 ?? ""))continue;
|
|
987
|
+
const cbArgs = hookName === "transform" ? { code: currentCode, path: arg2 } : { code: currentCode, chunk: arg2 },result = yield { callback: () => h.callback(cbArgs), pluginName: h.pluginName, hookName, fallbackFile: arg2 };
|
|
988
|
+
if (isPluginFailureResult(result))return result;
|
|
989
|
+
if (result != null) {
|
|
990
|
+
const obj = result,newCode = typeof result == "string" ? result : obj.code;
|
|
991
|
+
if (typeof newCode == "string") {
|
|
992
|
+
currentCode = newCode;
|
|
993
|
+
changed = true;
|
|
994
|
+
}
|
|
995
|
+
if (hookName === "transform" && typeof result == "object" && "map" in obj) {
|
|
996
|
+
const r = safeSerializeSourceMap(obj.map);
|
|
997
|
+
if (!r.ok)return normalizePluginFailure(h.pluginName, hookName, r.err, arg2);
|
|
998
|
+
if (r.map != null)sourceMaps.push(r.map);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return changed ? { code: currentCode, ...(sourceMaps.length > 0 ? { maps: sourceMaps } : {}) } : null;
|
|
1003
|
+
}
|
|
1004
|
+
const hookList = reg.hooks[hookName];
|
|
1005
|
+
if (!hookList)return null;
|
|
1006
|
+
const buildArgs = pluginArgBuilders[hookName];
|
|
1007
|
+
if (!buildArgs)return null;
|
|
1008
|
+
const [filterTarget, cbArgs] = buildArgs(arg1, arg2);
|
|
1009
|
+
for (const h of hookList) {
|
|
1010
|
+
if (!h.filter.test(filterTarget))continue;
|
|
1011
|
+
const fallbackFile = hookName === "resolveId" ? arg2 : filterTarget,result = yield { callback: () => h.callback(cbArgs), pluginName: h.pluginName, hookName, fallbackFile };
|
|
1012
|
+
if (isPluginFailureResult(result))return result;
|
|
1013
|
+
if (result != null) {
|
|
1014
|
+
if (hookName === "load" && typeof result == "object" && "map" in result) {
|
|
1015
|
+
const r = safeSerializeSourceMap(result.map);
|
|
1016
|
+
if (!r.ok)return normalizePluginFailure(h.pluginName, hookName, r.err, fallbackFile);
|
|
1017
|
+
return { ...result, ...(r.map != null ? { map: r.map } : { map: undefined }) };
|
|
1018
|
+
}
|
|
1019
|
+
return result;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return null;
|
|
1023
|
+
}
|
|
1024
|
+
async function driveDispatchAsync(gen) {
|
|
1025
|
+
let r = gen.next();
|
|
1026
|
+
while (!r.done) {
|
|
1027
|
+
const call = r.value;
|
|
1028
|
+
let value;
|
|
1029
|
+
try {
|
|
1030
|
+
value = await call.callback();
|
|
1031
|
+
} catch (err) {
|
|
1032
|
+
value = normalizePluginFailure(call.pluginName, call.hookName, err, call.fallbackFile);
|
|
1033
|
+
}
|
|
1034
|
+
r = gen.next(value);
|
|
1035
|
+
}
|
|
1036
|
+
return r.value;
|
|
1037
|
+
}
|
|
1038
|
+
function driveDispatchSync(gen) {
|
|
1039
|
+
let r = gen.next();
|
|
1040
|
+
while (!r.done) {
|
|
1041
|
+
const call = r.value;
|
|
1042
|
+
let value;
|
|
1043
|
+
try {
|
|
1044
|
+
const raw = call.callback();
|
|
1045
|
+
if (isPromiseLike(raw)) {
|
|
1046
|
+
silenceUnsupportedSyncPromise(raw);
|
|
1047
|
+
value = syncPluginPromiseFailure(call.pluginName, call.hookName, call.fallbackFile);
|
|
1048
|
+
} else {
|
|
1049
|
+
value = raw;
|
|
1050
|
+
}
|
|
1051
|
+
} catch (err) {
|
|
1052
|
+
value = normalizePluginFailure(call.pluginName, call.hookName, err, call.fallbackFile);
|
|
1053
|
+
}
|
|
1054
|
+
r = gen.next(value);
|
|
1055
|
+
}
|
|
1056
|
+
return r.value;
|
|
1057
|
+
}
|
|
1058
|
+
function createPluginDispatcher(plugins) {
|
|
1059
|
+
const reg = collectPluginRegistry(plugins),dispatcher = function dispatcher(hookName,arg1,arg2) {
|
|
1060
|
+
return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2));
|
|
1061
|
+
};
|
|
1062
|
+
dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
|
|
1063
|
+
return dispatcher;
|
|
1064
|
+
}
|
|
1065
|
+
function createSyncPluginDispatcher(plugins) {
|
|
1066
|
+
const reg = collectPluginRegistry(plugins),dispatcher = function dispatcher(hookName,arg1,arg2) {
|
|
1067
|
+
return driveDispatchSync(dispatchHook(reg, hookName, arg1, arg2));
|
|
1068
|
+
};
|
|
1069
|
+
dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
|
|
1070
|
+
return dispatcher;
|
|
1071
|
+
}
|
|
1072
|
+
function arrayAliasToPlugin(aliasArray) {
|
|
1073
|
+
return { name: "zntc:array-alias", setup(build) {
|
|
1074
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
1075
|
+
for (const { find:find, replacement:replacement } of aliasArray) {
|
|
1076
|
+
if (find instanceof RegExp) {
|
|
1077
|
+
if (args.path.search(find) !== -1) {
|
|
1078
|
+
return { path: args.path.replace(find, replacement) };
|
|
1079
|
+
}
|
|
1080
|
+
} else if (args.path === find || args.path.startsWith(find + "/")) {
|
|
1081
|
+
return { path: args.path.replace(find, replacement) };
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return null;
|
|
1085
|
+
});
|
|
1086
|
+
} };
|
|
1087
|
+
}
|
|
1088
|
+
function resolveDispatcher(options,mode="async") {
|
|
1089
|
+
const arrayAlias = Array.isArray(options.alias) ? options.alias : null,userPlugins = options.plugins ?? [],allPlugins = arrayAlias ? [arrayAliasToPlugin(arrayAlias), ...userPlugins] : userPlugins;
|
|
1090
|
+
if (allPlugins.length === 0)return null;
|
|
1091
|
+
return mode === "sync" ? createSyncPluginDispatcher(allPlugins) : createPluginDispatcher(allPlugins);
|
|
1092
|
+
}
|
|
1093
|
+
function isBrowserLikeBuildPlatform(platform) {
|
|
1094
|
+
return platform === undefined || platform === "browser" || platform === "react-native";
|
|
1095
|
+
}
|
|
1096
|
+
function withDefaultBuildDefines(options) {
|
|
1097
|
+
const define = { ...options.define },browserLike = isBrowserLikeBuildPlatform(options.platform) || options.minifySyntax === true;
|
|
1098
|
+
if (browserLike && define["process.env.NODE_ENV"] === undefined) {
|
|
1099
|
+
define["process.env.NODE_ENV"] = options.devMode ? "\"development\"" : "\"production\"";
|
|
1100
|
+
}
|
|
1101
|
+
if (options.platform === "react-native" && define.__DEV__ === undefined) {
|
|
1102
|
+
define.__DEV__ = options.devMode ? "true" : "false";
|
|
1103
|
+
}
|
|
1104
|
+
return Object.keys(define).length > 0 ? define : undefined;
|
|
1105
|
+
}
|
|
1106
|
+
function withDefaultAppBuildDefines(options) {
|
|
1107
|
+
const define = { ...options.define };
|
|
1108
|
+
if (define["process.env.NODE_ENV"] === undefined) {
|
|
1109
|
+
define["process.env.NODE_ENV"] = (options.mode ?? "production") === "production" ? "\"production\"" : "\"development\"";
|
|
1110
|
+
}
|
|
1111
|
+
return define;
|
|
1112
|
+
}
|
|
1113
|
+
function prepareNapiOptions(options) {
|
|
1114
|
+
const napiOptions = { ...options },define = withDefaultBuildDefines(options);
|
|
1115
|
+
if (define)napiOptions.define = define;
|
|
1116
|
+
delete napiOptions.write;
|
|
1117
|
+
delete napiOptions.outdir;
|
|
1118
|
+
delete napiOptions.plugins;
|
|
1119
|
+
delete napiOptions.allowOverwrite;
|
|
1120
|
+
if (Array.isArray(napiOptions.alias))delete napiOptions.alias;
|
|
1121
|
+
delete napiOptions.manualChunks;
|
|
1122
|
+
if (options.manualChunks) {
|
|
1123
|
+
napiOptions._manualChunks = options.manualChunks;
|
|
1124
|
+
}
|
|
1125
|
+
delete napiOptions.mf;
|
|
1126
|
+
if (options.mf) {
|
|
1127
|
+
napiOptions.mfRaw = JSON.stringify(options.mf);
|
|
1128
|
+
}
|
|
1129
|
+
if (options.blockList) {
|
|
1130
|
+
napiOptions.blockList = options.blockList.map((p) => {
|
|
1131
|
+
if (p instanceof RegExp)return p.source;
|
|
1132
|
+
if (typeof p == "string")return p;
|
|
1133
|
+
throw new TypeError(`blockList entries must be RegExp or string, got ${typeof p}`);
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
if (options.browserslist) {
|
|
1137
|
+
napiOptions.unsupported = resolveUnsupported({ browserslist: options.browserslist });
|
|
1138
|
+
delete napiOptions.browserslist;
|
|
1139
|
+
}
|
|
1140
|
+
if (options.target && !isEsTarget(options.target)) {
|
|
1141
|
+
delete napiOptions.target;
|
|
1142
|
+
}
|
|
1143
|
+
delete napiOptions.compiler;
|
|
1144
|
+
const sc = options.compiler?.styledComponents;
|
|
1145
|
+
if (sc !== undefined && sc !== false) {
|
|
1146
|
+
napiOptions.styledComponents = true;
|
|
1147
|
+
if (typeof sc == "object") {
|
|
1148
|
+
if (sc.ssr === false)napiOptions.styledComponentsSsr = false;
|
|
1149
|
+
if (sc.minify === true)napiOptions.styledComponentsMinify = true;
|
|
1150
|
+
if (sc.fileName === false)napiOptions.styledComponentsFileName = false;
|
|
1151
|
+
if (sc.pure === true)napiOptions.styledComponentsPure = true;
|
|
1152
|
+
if (typeof sc.namespace == "string" && sc.namespace.length > 0) {
|
|
1153
|
+
napiOptions.styledComponentsNamespace = sc.namespace;
|
|
1154
|
+
}
|
|
1155
|
+
if (Array.isArray(sc.meaninglessFileNames)) {
|
|
1156
|
+
napiOptions.styledComponentsMeaninglessFileNames = sc.meaninglessFileNames;
|
|
1157
|
+
}
|
|
1158
|
+
if (Array.isArray(sc.topLevelImportPaths)) {
|
|
1159
|
+
napiOptions.styledComponentsTopLevelImportPaths = sc.topLevelImportPaths;
|
|
1160
|
+
}
|
|
1161
|
+
if (sc.cssProp === true)napiOptions.styledComponentsCssProp = true;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
const em = options.compiler?.emotion;
|
|
1165
|
+
if (em !== undefined && em !== false) {
|
|
1166
|
+
napiOptions.emotion = true;
|
|
1167
|
+
if (typeof em == "object") {
|
|
1168
|
+
if (em.autoLabel === false) {
|
|
1169
|
+
napiOptions.emotionAutoLabel = "never";
|
|
1170
|
+
} else if (em.autoLabel === true) {
|
|
1171
|
+
napiOptions.emotionAutoLabel = "always";
|
|
1172
|
+
} else if (typeof em.autoLabel == "string") {
|
|
1173
|
+
napiOptions.emotionAutoLabel = em.autoLabel;
|
|
1174
|
+
}
|
|
1175
|
+
if (em.sourceMap === true)napiOptions.emotionSourceMap = true;
|
|
1176
|
+
if (typeof em.labelFormat == "string" && em.labelFormat.length > 0) {
|
|
1177
|
+
napiOptions.emotionLabelFormat = em.labelFormat;
|
|
1178
|
+
}
|
|
1179
|
+
const extras = collectEmotionImportMapExtras(em.importMap);
|
|
1180
|
+
if (extras.css.length > 0)napiOptions.emotionExtraCssSources = extras.css;
|
|
1181
|
+
if (extras.styled.length > 0)napiOptions.emotionExtraStyledSources = extras.styled;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
const runtimePolyfills = applyRuntimePolyfillsToNapiOptions(napiOptions, { entryPoints: options.entryPoints, platform: options.platform, target: options.target, browserslist: options.browserslist, runtimePolyfills: options.runtimePolyfills, coreJs: options.coreJs, runBeforeMain: options.runBeforeMain, resolveExtensions: options.resolveExtensions });
|
|
1185
|
+
return { napiOptions, cleanup: runtimePolyfills.cleanup };
|
|
1186
|
+
}
|
|
1187
|
+
var EMOTION_CSS_CANONICAL_SOURCES = new Set(["@emotion/react", "@emotion/css", "@emotion/core", "@emotion/native", "@emotion/primitives", "@emotion/primitives-core"]);
|
|
1188
|
+
function collectEmotionImportMapExtras(importMap) {
|
|
1189
|
+
const css = new Set(),styled = new Set();
|
|
1190
|
+
if (!importMap)return { css: [], styled: [] };
|
|
1191
|
+
for (const [source, locals] of Object.entries(importMap)) {
|
|
1192
|
+
for (const spec of Object.values(locals)) {
|
|
1193
|
+
const [pkg, exportName] = spec.canonicalImport;
|
|
1194
|
+
if (pkg === "@emotion/styled" && exportName === "default") {
|
|
1195
|
+
styled.add(source);
|
|
1196
|
+
} else if (EMOTION_CSS_CANONICAL_SOURCES.has(pkg)) {
|
|
1197
|
+
css.add(source);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return { css: [...css], styled: [...styled] };
|
|
1202
|
+
}
|
|
1203
|
+
function postProcessCssOutputs(result,options) {
|
|
1204
|
+
if (!options.minify)return;
|
|
1205
|
+
let lcss;
|
|
1206
|
+
try {
|
|
1207
|
+
lcss = require("lightningcss");
|
|
1208
|
+
} catch {
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
for (const file of result.outputFiles) {
|
|
1212
|
+
if (!file.path.endsWith(".css"))continue;
|
|
1213
|
+
try {
|
|
1214
|
+
const transformed = lcss.transform({ code: file.contents, minify: true, filename: file.path });
|
|
1215
|
+
file.contents = transformed.code;
|
|
1216
|
+
} catch {
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function writeOutputFiles(result,options) {
|
|
1221
|
+
const shouldWrite = options.write ?? (options.outdir != null || options.outfile != null);
|
|
1222
|
+
if (!shouldWrite)return;
|
|
1223
|
+
if (!options.allowOverwrite && options.outfile) {
|
|
1224
|
+
const outResolved = resolve$1(options.outfile);
|
|
1225
|
+
for (const entry of options.entryPoints) {
|
|
1226
|
+
if (resolve$1(entry) === outResolved) {
|
|
1227
|
+
throw new Error(`@zntc/core: output file '${options.outfile}' would overwrite input file (set allowOverwrite: true to permit)`);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
const createdDirs = new Set(),outfileResolved = options.outfile ? resolve$1(options.outfile) : null;
|
|
1232
|
+
for (const file of result.outputFiles) {
|
|
1233
|
+
let outPath;
|
|
1234
|
+
if (outfileResolved && file.path === "bundle.js") {
|
|
1235
|
+
outPath = outfileResolved;
|
|
1236
|
+
} else if (outfileResolved && file.path.endsWith(".map")) {
|
|
1237
|
+
outPath = outfileResolved + ".map";
|
|
1238
|
+
} else if (options.outdir) {
|
|
1239
|
+
outPath = join$2(resolve$1(options.outdir), file.path);
|
|
1240
|
+
} else {
|
|
1241
|
+
outPath = resolve$1(file.path);
|
|
1242
|
+
}
|
|
1243
|
+
const dir = dirname$2(outPath);
|
|
1244
|
+
if (!createdDirs.has(dir)) {
|
|
1245
|
+
mkdirSync(dir, { recursive: true });
|
|
1246
|
+
createdDirs.add(dir);
|
|
1247
|
+
}
|
|
1248
|
+
writeFileSync$1(outPath, file.contents);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
async function build(options) {
|
|
1252
|
+
const n = ensureNative();
|
|
1253
|
+
if (!options.entryPoints?.length)throw new Error("@zntc/core: entryPoints is required");
|
|
1254
|
+
validateTsConfigRaw(options.tsconfigRaw);
|
|
1255
|
+
if (options.output && options.output.length >= 2) {
|
|
1256
|
+
return buildMultiFormat(options);
|
|
1257
|
+
}
|
|
1258
|
+
const { napiOptions:napiOptions, cleanup:cleanup } = prepareNapiOptions(options),dispatcher = resolveDispatcher(options);
|
|
1259
|
+
if (dispatcher)napiOptions._pluginDispatcher = dispatcher;
|
|
1260
|
+
try {
|
|
1261
|
+
const result = wrapOutputFiles(await n.build(napiOptions));
|
|
1262
|
+
if (dispatcher) {
|
|
1263
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
1264
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
postProcessCssOutputs(result, options);
|
|
1268
|
+
writeOutputFiles(result, options);
|
|
1269
|
+
if (dispatcher) {
|
|
1270
|
+
await dispatcher("closeBundle", undefined, null);
|
|
1271
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
1272
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
return result;
|
|
1276
|
+
} finally {
|
|
1277
|
+
cleanup();
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
function buildSync(options) {
|
|
1281
|
+
const n = ensureNative();
|
|
1282
|
+
if (!options.entryPoints?.length)throw new Error("@zntc/core: entryPoints is required");
|
|
1283
|
+
validateTsConfigRaw(options.tsconfigRaw);
|
|
1284
|
+
const { napiOptions:napiOptions, cleanup:cleanup } = prepareNapiOptions(options),dispatcher = resolveDispatcher(options, "sync");
|
|
1285
|
+
if (dispatcher)napiOptions._pluginDispatcherSync = dispatcher;
|
|
1286
|
+
try {
|
|
1287
|
+
const result = wrapOutputFiles(n.buildSync(napiOptions));
|
|
1288
|
+
if (dispatcher) {
|
|
1289
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
1290
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
postProcessCssOutputs(result, options);
|
|
1294
|
+
writeOutputFiles(result, options);
|
|
1295
|
+
if (dispatcher) {
|
|
1296
|
+
dispatcher("closeBundle", undefined, null);
|
|
1297
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
1298
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return result;
|
|
1302
|
+
} finally {
|
|
1303
|
+
cleanup();
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
var BuildInstance = class {
|
|
1307
|
+
#base;
|
|
1308
|
+
#closed = false;
|
|
1309
|
+
constructor(base) {
|
|
1310
|
+
this.#base = base;
|
|
1311
|
+
}
|
|
1312
|
+
get closed() {
|
|
1313
|
+
return this.#closed;
|
|
1314
|
+
}
|
|
1315
|
+
async write(output={}) {
|
|
1316
|
+
this.#assertOpen();
|
|
1317
|
+
return build(mergeOutput(this.#base, output));
|
|
1318
|
+
}
|
|
1319
|
+
async generate(output={}) {
|
|
1320
|
+
this.#assertOpen();
|
|
1321
|
+
return build({ ...mergeOutput(this.#base, output), write: false });
|
|
1322
|
+
}
|
|
1323
|
+
async close() {
|
|
1324
|
+
this.#closed = true;
|
|
1325
|
+
}
|
|
1326
|
+
#assertOpen() {
|
|
1327
|
+
if (this.#closed)throw new Error("@zntc/core: BuildInstance is closed");
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
function mergeOutput(base,out) {
|
|
1331
|
+
const merged = { ...base };
|
|
1332
|
+
if (out.format !== undefined)merged.format = out.format;
|
|
1333
|
+
if (out.dir !== undefined)merged.outdir = out.dir;
|
|
1334
|
+
if (out.file !== undefined)merged.outfile = out.file;
|
|
1335
|
+
if (out.globals !== undefined)merged.globals = out.globals;
|
|
1336
|
+
return merged;
|
|
1337
|
+
}
|
|
1338
|
+
async function zntc(options) {
|
|
1339
|
+
if (!options.entryPoints?.length)throw new Error("@zntc/core: entryPoints is required");
|
|
1340
|
+
validateTsConfigRaw(options.tsconfigRaw);
|
|
1341
|
+
return new BuildInstance(options);
|
|
1342
|
+
}
|
|
1343
|
+
async function buildMultiFormat(options) {
|
|
1344
|
+
const outputs = options.output,{ output:_omit, ...baseOpts } = options,aggregated = { outputFiles: [], errors: [], warnings: [], outputsByFormat: [] };
|
|
1345
|
+
for (const cfg of outputs) {
|
|
1346
|
+
const r = await build(mergeOutput(baseOpts, cfg));
|
|
1347
|
+
aggregated.errors.push(...r.errors);
|
|
1348
|
+
aggregated.warnings.push(...r.warnings);
|
|
1349
|
+
aggregated.outputsByFormat.push({ format: cfg.format ?? "esm", outputFiles: r.outputFiles });
|
|
1350
|
+
}
|
|
1351
|
+
if (aggregated.outputsByFormat.length > 0) {
|
|
1352
|
+
aggregated.outputFiles = aggregated.outputsByFormat[0].outputFiles;
|
|
1353
|
+
}
|
|
1354
|
+
return aggregated;
|
|
1355
|
+
}
|
|
1356
|
+
function buildAppSync(options={}) {
|
|
1357
|
+
const n = ensureNative(),{ publicDir:publicDir, compiler:compiler, ...rest } = options;
|
|
1358
|
+
return wrapOutputFiles(n.buildAppSync({ ...rest, define: withDefaultAppBuildDefines(options), ...(publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {}), ...buildCompilerNapiFields(compiler) }));
|
|
1359
|
+
}
|
|
1360
|
+
function buildCompilerNapiFields(compiler) {
|
|
1361
|
+
const out = {},sc = compiler?.styledComponents;
|
|
1362
|
+
if (sc !== undefined && sc !== false)out.styledComponents = true;
|
|
1363
|
+
if (typeof sc == "object") {
|
|
1364
|
+
if (sc.ssr === false)out.styledComponentsSsr = false;
|
|
1365
|
+
if (sc.minify === true)out.styledComponentsMinify = true;
|
|
1366
|
+
if (sc.fileName === false)out.styledComponentsFileName = false;
|
|
1367
|
+
if (sc.pure === true)out.styledComponentsPure = true;
|
|
1368
|
+
if (typeof sc.namespace == "string" && sc.namespace.length > 0) {
|
|
1369
|
+
out.styledComponentsNamespace = sc.namespace;
|
|
1370
|
+
}
|
|
1371
|
+
if (Array.isArray(sc.meaninglessFileNames)) {
|
|
1372
|
+
out.styledComponentsMeaninglessFileNames = sc.meaninglessFileNames;
|
|
1373
|
+
}
|
|
1374
|
+
if (Array.isArray(sc.topLevelImportPaths)) {
|
|
1375
|
+
out.styledComponentsTopLevelImportPaths = sc.topLevelImportPaths;
|
|
1376
|
+
}
|
|
1377
|
+
if (sc.cssProp === true)out.styledComponentsCssProp = true;
|
|
1378
|
+
}
|
|
1379
|
+
const em = compiler?.emotion;
|
|
1380
|
+
if (em !== undefined && em !== false)out.emotion = true;
|
|
1381
|
+
if (typeof em == "object") {
|
|
1382
|
+
if (em.autoLabel === false)out.emotionAutoLabel = "never"; else if (em.autoLabel === true)out.emotionAutoLabel = "always"; else if (typeof em.autoLabel == "string")out.emotionAutoLabel = em.autoLabel;
|
|
1383
|
+
if (em.sourceMap === true)out.emotionSourceMap = true;
|
|
1384
|
+
if (typeof em.labelFormat == "string" && em.labelFormat.length > 0) {
|
|
1385
|
+
out.emotionLabelFormat = em.labelFormat;
|
|
1386
|
+
}
|
|
1387
|
+
const extras = collectEmotionImportMapExtras(em.importMap);
|
|
1388
|
+
if (extras.css.length > 0)out.emotionExtraCssSources = extras.css;
|
|
1389
|
+
if (extras.styled.length > 0)out.emotionExtraStyledSources = extras.styled;
|
|
1390
|
+
}
|
|
1391
|
+
return out;
|
|
1392
|
+
}
|
|
1393
|
+
function prepareAppDevSync(options={}) {
|
|
1394
|
+
const n = ensureNative(),{ publicDir:publicDir, ...rest } = options;
|
|
1395
|
+
return n.prepareAppDevSync({ ...rest, ...(publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {}) });
|
|
1396
|
+
}
|
|
1397
|
+
function close() {
|
|
1398
|
+
native = null;
|
|
1399
|
+
}
|
|
1400
|
+
function benchmark(options) {
|
|
1401
|
+
if (!options.source && !options.file) {
|
|
1402
|
+
throw new Error("@zntc/core.benchmark: 'source' or 'file' is required");
|
|
1403
|
+
}
|
|
1404
|
+
if (!Array.isArray(options.phases) || options.phases.length === 0) {
|
|
1405
|
+
throw new Error("@zntc/core.benchmark: 'phases' must be a non-empty string array");
|
|
1406
|
+
}
|
|
1407
|
+
return ensureNative().benchmark({ source: options.source, file: options.file, filename: options.filename ?? "input.js", phases: options.phases, iterations: options.iterations ?? 100, warmup: options.warmup ?? 10 });
|
|
1408
|
+
}
|
|
1409
|
+
function extractHandler(hook) {
|
|
1410
|
+
if (hook == null)return undefined;
|
|
1411
|
+
if (typeof hook == "function")return hook;
|
|
1412
|
+
if (typeof hook == "object" && typeof hook.handler == "function") {
|
|
1413
|
+
return hook.handler;
|
|
1414
|
+
}
|
|
1415
|
+
return undefined;
|
|
1416
|
+
}
|
|
1417
|
+
function normalizeVitePluginSourceMap(map,onDrop) {
|
|
1418
|
+
if (map == null)return undefined;
|
|
1419
|
+
if (typeof map == "object") {
|
|
1420
|
+
const obj = map,ver = typeof obj.version == "string" ? Number(obj.version) : obj.version;
|
|
1421
|
+
if (ver !== 3) {
|
|
1422
|
+
onDrop(`version=${String(obj.version)} (expected 3)`);
|
|
1423
|
+
return undefined;
|
|
1424
|
+
}
|
|
1425
|
+
if (!Array.isArray(obj.sources)) {
|
|
1426
|
+
onDrop(`missing sources array`);
|
|
1427
|
+
return undefined;
|
|
1428
|
+
}
|
|
1429
|
+
if (typeof obj.mappings != "string") {
|
|
1430
|
+
onDrop(`missing mappings string`);
|
|
1431
|
+
return undefined;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
try {
|
|
1435
|
+
return serializePluginSourceMap(map) ?? undefined;
|
|
1436
|
+
} catch (err) {
|
|
1437
|
+
onDrop(err instanceof Error ? err.message : String(err));
|
|
1438
|
+
return undefined;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
function createRollupPluginContext(pluginName) {
|
|
1442
|
+
return { error(error) {
|
|
1443
|
+
throw error;
|
|
1444
|
+
}, warn(message) {
|
|
1445
|
+
console.warn(`@zntc/core [${pluginName}]: ${typeof message == "string" ? message : String(message)}`);
|
|
1446
|
+
}, addWatchFile(_id) {
|
|
1447
|
+
}, resolve(_source,_importer,_options) {
|
|
1448
|
+
throw new Error(`@zntc/core [${pluginName}]: this.resolve() is not supported by vitePlugin() adapter yet ` + `(graph mutation surface missing). Use alias config or another plugin's resolveId hook.`);
|
|
1449
|
+
}, emitFile(_file) {
|
|
1450
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() is not supported by vitePlugin() adapter yet.`);
|
|
1451
|
+
} };
|
|
1452
|
+
}
|
|
1453
|
+
function createDropWarner(context) {
|
|
1454
|
+
const seen = new Set();
|
|
1455
|
+
return (reason) => {
|
|
1456
|
+
if (seen.has(reason))return;
|
|
1457
|
+
seen.add(reason);
|
|
1458
|
+
context.warn(`sourcemap dropped: ${reason}`);
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
function vitePlugin(rollupPlugin) {
|
|
1462
|
+
return { name: rollupPlugin.name, setup(build) {
|
|
1463
|
+
const context = createRollupPluginContext(rollupPlugin.name),onDropSourceMap = createDropWarner(context),resolveId = extractHandler(rollupPlugin.resolveId);
|
|
1464
|
+
if (resolveId) {
|
|
1465
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
1466
|
+
const result = resolveId.call(context, args.path, args.importer);
|
|
1467
|
+
return mapMaybePromise(result, (result) => {
|
|
1468
|
+
if (result == null)return null;
|
|
1469
|
+
if (typeof result == "string")return { path: result };
|
|
1470
|
+
if (typeof result == "object" && "id" in result) {
|
|
1471
|
+
return { path: result.id, external: result.external };
|
|
1472
|
+
}
|
|
1473
|
+
return null;
|
|
1474
|
+
});
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
const load = extractHandler(rollupPlugin.load);
|
|
1478
|
+
if (load) {
|
|
1479
|
+
build.onLoad({ filter: /.*/ }, (args) => {
|
|
1480
|
+
const result = load.call(context, args.path);
|
|
1481
|
+
return mapMaybePromise(result, (result) => {
|
|
1482
|
+
if (result == null)return null;
|
|
1483
|
+
if (typeof result == "string")return { contents: result };
|
|
1484
|
+
if (typeof result == "object" && "code" in result) {
|
|
1485
|
+
return { contents: result.code, map: normalizeVitePluginSourceMap(result.map, onDropSourceMap) };
|
|
1486
|
+
}
|
|
1487
|
+
return null;
|
|
1488
|
+
});
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
const transform = extractHandler(rollupPlugin.transform);
|
|
1492
|
+
if (transform) {
|
|
1493
|
+
build.onTransform({ filter: /.*/ }, (args) => {
|
|
1494
|
+
const result = transform.call(context, args.code, args.path);
|
|
1495
|
+
return mapMaybePromise(result, (result) => {
|
|
1496
|
+
if (result == null)return null;
|
|
1497
|
+
if (typeof result == "string")return { code: result };
|
|
1498
|
+
if (typeof result == "object" && "code" in result) {
|
|
1499
|
+
return { code: result.code, map: normalizeVitePluginSourceMap(result.map, onDropSourceMap) };
|
|
1500
|
+
}
|
|
1501
|
+
return null;
|
|
1502
|
+
});
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
const renderChunk = extractHandler(rollupPlugin.renderChunk);
|
|
1506
|
+
if (renderChunk) {
|
|
1507
|
+
build.onRenderChunk({ filter: /.*/ }, (args) => {
|
|
1508
|
+
const result = renderChunk.call(context, args.code, args.chunk);
|
|
1509
|
+
return mapMaybePromise(result, (result) => {
|
|
1510
|
+
if (result == null)return null;
|
|
1511
|
+
if (typeof result == "string")return { code: result };
|
|
1512
|
+
if (typeof result == "object" && "code" in result) {
|
|
1513
|
+
return { code: result.code };
|
|
1514
|
+
}
|
|
1515
|
+
return null;
|
|
1516
|
+
});
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
const generateBundle = extractHandler(rollupPlugin.generateBundle);
|
|
1520
|
+
if (generateBundle) {
|
|
1521
|
+
build.onGenerateBundle((outputs) => generateBundle.call(context, outputs));
|
|
1522
|
+
}
|
|
1523
|
+
const buildStart = extractHandler(rollupPlugin.buildStart);
|
|
1524
|
+
if (buildStart) {
|
|
1525
|
+
build.onBuildStart(() => buildStart.call(context));
|
|
1526
|
+
}
|
|
1527
|
+
const buildEnd = extractHandler(rollupPlugin.buildEnd);
|
|
1528
|
+
if (buildEnd) {
|
|
1529
|
+
build.onBuildEnd((err) => buildEnd.call(context, err));
|
|
1530
|
+
}
|
|
1531
|
+
const closeBundle = extractHandler(rollupPlugin.closeBundle);
|
|
1532
|
+
if (closeBundle) {
|
|
1533
|
+
build.onCloseBundle(() => closeBundle.call(context));
|
|
1534
|
+
}
|
|
1535
|
+
} };
|
|
1536
|
+
}
|
|
1537
|
+
function watch(options) {
|
|
1538
|
+
const n = ensureNative(),{ napiOptions:nativeOpts, cleanup:cleanup } = prepareNapiOptions(options),dispatcher = resolveDispatcher(options);
|
|
1539
|
+
if (dispatcher) {
|
|
1540
|
+
nativeOpts._pluginDispatcher = dispatcher;
|
|
1541
|
+
const dispatchCloseBundle = () => {
|
|
1542
|
+
void dispatcher("closeBundle", undefined, null).catch(() => {
|
|
1543
|
+
});
|
|
1544
|
+
},wrapWatchCallback = (callback) => (event) => {
|
|
1545
|
+
void Promise.resolve().then(() => callback?.(event)).finally(dispatchCloseBundle).catch(() => {
|
|
1546
|
+
});
|
|
1547
|
+
};
|
|
1548
|
+
nativeOpts.onReady = wrapWatchCallback(options.onReady);
|
|
1549
|
+
nativeOpts.onRebuild = wrapWatchCallback(options.onRebuild);
|
|
1550
|
+
}
|
|
1551
|
+
let handle;
|
|
1552
|
+
try {
|
|
1553
|
+
handle = n.watch(nativeOpts);
|
|
1554
|
+
} catch (err) {
|
|
1555
|
+
cleanup();
|
|
1556
|
+
throw err;
|
|
1557
|
+
}
|
|
1558
|
+
return { stop() {
|
|
1559
|
+
try {
|
|
1560
|
+
handle.stop();
|
|
1561
|
+
} finally {
|
|
1562
|
+
cleanup();
|
|
1563
|
+
}
|
|
1564
|
+
}, getBundleSourceMap() {
|
|
1565
|
+
return handle.getBundleSourceMap();
|
|
1566
|
+
}, getHmrSourceMap(moduleId) {
|
|
1567
|
+
return handle.getHmrSourceMap(moduleId);
|
|
1568
|
+
} };
|
|
1569
|
+
}
|
|
1570
|
+
exports.isPlainObject = isPlainObject;
|
|
1571
|
+
exports.validateTsConfigRaw = validateTsConfigRaw;
|
|
1572
|
+
exports.defineConfig = defineConfig;
|
|
1573
|
+
exports.defaultConfigEnv = defaultConfigEnv;
|
|
1574
|
+
exports.findConfigPath = findConfigPath;
|
|
1575
|
+
exports.findModeConfigPath = findModeConfigPath;
|
|
1576
|
+
exports.importAndResolveDefault = importAndResolveDefault;
|
|
1577
|
+
exports.loadConfig = loadConfig;
|
|
1578
|
+
exports.loadModuleDefault = loadModuleDefault;
|
|
1579
|
+
exports.mergeUserConfigs = mergeUserConfigs;
|
|
1580
|
+
exports.envToDefine = envToDefine;
|
|
1581
|
+
exports.loadEnv = loadEnv;
|
|
1582
|
+
exports.KNOWN_CONFIG_KEYS = KNOWN_CONFIG_KEYS;
|
|
1583
|
+
exports.suggestKey = suggestKey;
|
|
1584
|
+
exports.warnUnknownKeys = warnUnknownKeys;
|
|
1585
|
+
exports.defineWorkspace = defineWorkspace;
|
|
1586
|
+
exports.filterWorkspaces = filterWorkspaces;
|
|
1587
|
+
exports.findWorkspacePath = findWorkspacePath;
|
|
1588
|
+
exports.identifyWorkspaceEntries = identifyWorkspaceEntries;
|
|
1589
|
+
exports.loadIdentifiedConfig = loadIdentifiedConfig;
|
|
1590
|
+
exports.loadWorkspace = loadWorkspace;
|
|
1591
|
+
exports.WORKSPACE_EXT_PRIORITY = WORKSPACE_EXT_PRIORITY;
|
|
1592
|
+
exports.init = init;
|
|
1593
|
+
exports.TsconfigCache = TsconfigCache;
|
|
1594
|
+
exports.transpile = transpile;
|
|
1595
|
+
exports.tokenize = tokenize;
|
|
1596
|
+
exports.configureProfile = configureProfile;
|
|
1597
|
+
exports.profileReport = profileReport;
|
|
1598
|
+
exports.build = build;
|
|
1599
|
+
exports.buildSync = buildSync;
|
|
1600
|
+
exports.BuildInstance = BuildInstance;
|
|
1601
|
+
exports.zntc = zntc;
|
|
1602
|
+
exports.buildAppSync = buildAppSync;
|
|
1603
|
+
exports.prepareAppDevSync = prepareAppDevSync;
|
|
1604
|
+
exports.close = close;
|
|
1605
|
+
exports.benchmark = benchmark;
|
|
1606
|
+
exports.vitePlugin = vitePlugin;
|
|
1607
|
+
exports.watch = watch;
|
|
1608
|
+
//#endregion
|