@zntc/core 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -25
- package/bin/cli-flags.mjs +16 -0
- package/bin/rn-dev-input.mjs +11 -0
- package/bin/zntc.mjs +816 -48
- package/dist/core/index.d.cts +300 -3
- package/dist/core/index.d.ts +300 -3
- package/dist/core/src/config-loader.d.ts +1 -1
- package/dist/core/src/schema-allowlists.d.ts +2 -2
- package/dist/index.cjs +283 -82
- package/dist/index.js +361 -83
- package/dist/shared/compat-engines.d.ts +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -818,7 +818,7 @@ var require_node = __commonJS((exports, module) => {
|
|
|
818
818
|
// index.ts
|
|
819
819
|
import { createRequire as createRequire3 } from "module";
|
|
820
820
|
import { existsSync as existsSync3, mkdirSync, writeFileSync as writeFileSync2 } from "fs";
|
|
821
|
-
import { join as
|
|
821
|
+
import { join as join4, dirname as dirname3, resolve as resolve2 } from "path";
|
|
822
822
|
import { fileURLToPath } from "url";
|
|
823
823
|
|
|
824
824
|
// src/platforms.ts
|
|
@@ -935,7 +935,10 @@ var FEATURES = [
|
|
|
935
935
|
"regex_sticky",
|
|
936
936
|
"regex_dotall",
|
|
937
937
|
"regex_named_groups",
|
|
938
|
-
"unicode_brace_escape"
|
|
938
|
+
"unicode_brace_escape",
|
|
939
|
+
"regex_duplicate_named_groups",
|
|
940
|
+
"regex_modifiers",
|
|
941
|
+
"regex_lookbehind"
|
|
939
942
|
];
|
|
940
943
|
var SUPPORT = {
|
|
941
944
|
arrow: {
|
|
@@ -1146,7 +1149,34 @@ var SUPPORT = {
|
|
|
1146
1149
|
ios: [13, 4],
|
|
1147
1150
|
hermes: [0, 7]
|
|
1148
1151
|
},
|
|
1149
|
-
using: {}
|
|
1152
|
+
using: {},
|
|
1153
|
+
regex_duplicate_named_groups: {
|
|
1154
|
+
chrome: [125, 0],
|
|
1155
|
+
edge: [125, 0],
|
|
1156
|
+
firefox: [129, 0],
|
|
1157
|
+
safari: [17, 4],
|
|
1158
|
+
ios: [17, 4],
|
|
1159
|
+
node: [23, 0],
|
|
1160
|
+
deno: [1, 44]
|
|
1161
|
+
},
|
|
1162
|
+
regex_modifiers: {
|
|
1163
|
+
chrome: [125, 0],
|
|
1164
|
+
edge: [125, 0],
|
|
1165
|
+
firefox: [132, 0],
|
|
1166
|
+
safari: [26, 0],
|
|
1167
|
+
ios: [26, 0],
|
|
1168
|
+
node: [23, 0],
|
|
1169
|
+
deno: [1, 44]
|
|
1170
|
+
},
|
|
1171
|
+
regex_lookbehind: {
|
|
1172
|
+
chrome: [62, 0],
|
|
1173
|
+
edge: [79, 0],
|
|
1174
|
+
firefox: [78, 0],
|
|
1175
|
+
safari: [16, 4],
|
|
1176
|
+
ios: [16, 4],
|
|
1177
|
+
node: [8, 10],
|
|
1178
|
+
deno: [1, 0]
|
|
1179
|
+
}
|
|
1150
1180
|
};
|
|
1151
1181
|
function verGte(a, b) {
|
|
1152
1182
|
if (a[0] !== b[0])
|
|
@@ -1177,17 +1207,17 @@ function computeUnsupportedFromEngines(engines) {
|
|
|
1177
1207
|
}
|
|
1178
1208
|
// ../shared/index.ts
|
|
1179
1209
|
var ES_TARGET_BITS = {
|
|
1180
|
-
es5:
|
|
1181
|
-
es2015:
|
|
1182
|
-
es2016:
|
|
1183
|
-
es2017:
|
|
1184
|
-
es2018:
|
|
1185
|
-
es2019:
|
|
1186
|
-
es2020:
|
|
1187
|
-
es2021:
|
|
1188
|
-
es2022:
|
|
1189
|
-
es2023:
|
|
1190
|
-
es2024:
|
|
1210
|
+
es5: 2147483647,
|
|
1211
|
+
es2015: 1996486656,
|
|
1212
|
+
es2016: 1996484608,
|
|
1213
|
+
es2017: 1996480512,
|
|
1214
|
+
es2018: 822067200,
|
|
1215
|
+
es2019: 822050816,
|
|
1216
|
+
es2020: 821952512,
|
|
1217
|
+
es2021: 821821440,
|
|
1218
|
+
es2022: 817889280,
|
|
1219
|
+
es2023: 813694976,
|
|
1220
|
+
es2024: 813694976,
|
|
1191
1221
|
es2025: 0,
|
|
1192
1222
|
esnext: 0
|
|
1193
1223
|
};
|
|
@@ -1928,7 +1958,7 @@ async function loadModuleDefault(absPath, kind, options) {
|
|
|
1928
1958
|
const allowArray = options?.allowArray === true;
|
|
1929
1959
|
const ext = extname(absPath).toLowerCase();
|
|
1930
1960
|
if (ext === ".json") {
|
|
1931
|
-
const raw = readFileOrThrowNotFound(absPath);
|
|
1961
|
+
const raw = readFileOrThrowNotFound(absPath, kind);
|
|
1932
1962
|
try {
|
|
1933
1963
|
return JSON.parse(raw);
|
|
1934
1964
|
} catch (err) {
|
|
@@ -1953,7 +1983,7 @@ async function loadModuleDefault(absPath, kind, options) {
|
|
|
1953
1983
|
}
|
|
1954
1984
|
async function loadTsModule(absPath, kind, allowArray) {
|
|
1955
1985
|
init();
|
|
1956
|
-
const source = readFileOrThrowNotFound(absPath);
|
|
1986
|
+
const source = readFileOrThrowNotFound(absPath, kind);
|
|
1957
1987
|
const parseFilename = absPath.endsWith(".cts") ? absPath.slice(0, -4) + ".ts" : absPath;
|
|
1958
1988
|
const result = transpile(source, {
|
|
1959
1989
|
filename: parseFilename,
|
|
@@ -2000,12 +2030,12 @@ async function importAndResolveDefault(absPath, options) {
|
|
|
2000
2030
|
}
|
|
2001
2031
|
return value;
|
|
2002
2032
|
}
|
|
2003
|
-
function readFileOrThrowNotFound(absPath) {
|
|
2033
|
+
function readFileOrThrowNotFound(absPath, kind) {
|
|
2004
2034
|
try {
|
|
2005
2035
|
return readFileSync2(absPath, "utf8");
|
|
2006
2036
|
} catch (err) {
|
|
2007
2037
|
if (err.code === "ENOENT") {
|
|
2008
|
-
throw new Error(`@zntc/core:
|
|
2038
|
+
throw new Error(`@zntc/core: ${kind} file not found: ${absPath}`);
|
|
2009
2039
|
}
|
|
2010
2040
|
throw err;
|
|
2011
2041
|
}
|
|
@@ -2061,7 +2091,7 @@ function mergeUserConfigs(base, mode) {
|
|
|
2061
2091
|
return merged;
|
|
2062
2092
|
}
|
|
2063
2093
|
// src/load-env.ts
|
|
2064
|
-
import { resolve as pathResolve2 } from "node:path";
|
|
2094
|
+
import { join as join2, resolve as pathResolve2 } from "node:path";
|
|
2065
2095
|
function parseDotenvLine(line) {
|
|
2066
2096
|
const trimmed = line.trim();
|
|
2067
2097
|
if (!trimmed || trimmed.startsWith("#"))
|
|
@@ -2099,7 +2129,7 @@ function loadEnv(mode, envDir, prefixes = ["VITE_", "ZNTC_"]) {
|
|
|
2099
2129
|
const files = [`.env`, `.env.local`, `.env.${mode}`, `.env.${mode}.local`];
|
|
2100
2130
|
const merged = {};
|
|
2101
2131
|
for (const file of files) {
|
|
2102
|
-
Object.assign(merged, parseDotenvFile(
|
|
2132
|
+
Object.assign(merged, parseDotenvFile(join2(dir, file)));
|
|
2103
2133
|
}
|
|
2104
2134
|
const filtered = {};
|
|
2105
2135
|
for (const [key, value] of Object.entries(merged)) {
|
|
@@ -2183,12 +2213,16 @@ function warnUnknownKeys(config, known, options = {}) {
|
|
|
2183
2213
|
}
|
|
2184
2214
|
var KNOWN_CONFIG_KEYS = [
|
|
2185
2215
|
"entryPoints",
|
|
2216
|
+
"output",
|
|
2186
2217
|
"outdir",
|
|
2187
2218
|
"outfile",
|
|
2188
2219
|
"outbase",
|
|
2189
2220
|
"format",
|
|
2190
2221
|
"platform",
|
|
2191
2222
|
"target",
|
|
2223
|
+
"rnVersion",
|
|
2224
|
+
"diskCache",
|
|
2225
|
+
"cacheDir",
|
|
2192
2226
|
"browserslist",
|
|
2193
2227
|
"runtimePolyfills",
|
|
2194
2228
|
"coreJs",
|
|
@@ -2210,6 +2244,7 @@ var KNOWN_CONFIG_KEYS = [
|
|
|
2210
2244
|
"sourceRoot",
|
|
2211
2245
|
"external",
|
|
2212
2246
|
"alias",
|
|
2247
|
+
"aliasExact",
|
|
2213
2248
|
"define",
|
|
2214
2249
|
"server",
|
|
2215
2250
|
"loader",
|
|
@@ -2247,6 +2282,8 @@ var KNOWN_CONFIG_KEYS = [
|
|
|
2247
2282
|
"entryNames",
|
|
2248
2283
|
"chunkNames",
|
|
2249
2284
|
"assetNames",
|
|
2285
|
+
"assetInlineLimit",
|
|
2286
|
+
"cssNames",
|
|
2250
2287
|
"experimentalDecorators",
|
|
2251
2288
|
"emitDecoratorMetadata",
|
|
2252
2289
|
"useDefineForClassFields",
|
|
@@ -2275,6 +2312,9 @@ var KNOWN_CONFIG_KEYS = [
|
|
|
2275
2312
|
"watchDelay",
|
|
2276
2313
|
"jobs",
|
|
2277
2314
|
"codegenTransform",
|
|
2315
|
+
"lazyCompilation",
|
|
2316
|
+
"lazyForceParse",
|
|
2317
|
+
"preserveSafePlugins",
|
|
2278
2318
|
"extends",
|
|
2279
2319
|
"root",
|
|
2280
2320
|
"projectRoot",
|
|
@@ -2290,7 +2330,7 @@ var KNOWN_CONFIG_KEYS = [
|
|
|
2290
2330
|
];
|
|
2291
2331
|
// src/workspace.ts
|
|
2292
2332
|
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync3 } from "node:fs";
|
|
2293
|
-
import { basename, join as
|
|
2333
|
+
import { basename, join as join3, resolve as pathResolve3 } from "node:path";
|
|
2294
2334
|
var CONFIG_EXT_PRIORITY_LOCAL = [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
|
|
2295
2335
|
function defineWorkspace(input) {
|
|
2296
2336
|
return input;
|
|
@@ -2298,7 +2338,7 @@ function defineWorkspace(input) {
|
|
|
2298
2338
|
var WORKSPACE_EXT_PRIORITY = CONFIG_EXT_PRIORITY_LOCAL;
|
|
2299
2339
|
function findWorkspacePath(cwd) {
|
|
2300
2340
|
for (const ext of WORKSPACE_EXT_PRIORITY) {
|
|
2301
|
-
const p =
|
|
2341
|
+
const p = join3(cwd, `zntc.workspace${ext}`);
|
|
2302
2342
|
if (existsSync2(p))
|
|
2303
2343
|
return p;
|
|
2304
2344
|
}
|
|
@@ -2334,9 +2374,10 @@ function identifyWorkspaceEntries(entries, rootDir) {
|
|
|
2334
2374
|
const seen = new Set;
|
|
2335
2375
|
const out = [];
|
|
2336
2376
|
const push = (w) => {
|
|
2337
|
-
|
|
2377
|
+
const key = w.source === "inline" ? `inline:${w.name}` : w.cwd;
|
|
2378
|
+
if (seen.has(key))
|
|
2338
2379
|
return;
|
|
2339
|
-
seen.add(
|
|
2380
|
+
seen.add(key);
|
|
2340
2381
|
out.push(w);
|
|
2341
2382
|
};
|
|
2342
2383
|
for (const entry of entries) {
|
|
@@ -2399,7 +2440,7 @@ function enumerateDirs(baseDir, namePattern) {
|
|
|
2399
2440
|
if (d.name === "node_modules")
|
|
2400
2441
|
continue;
|
|
2401
2442
|
if (matcher(d.name))
|
|
2402
|
-
out.push(
|
|
2443
|
+
out.push(join3(baseDir, d.name));
|
|
2403
2444
|
}
|
|
2404
2445
|
out.sort();
|
|
2405
2446
|
return out;
|
|
@@ -2412,7 +2453,7 @@ function makeStarMatcher(pattern) {
|
|
|
2412
2453
|
return (s) => re.test(s);
|
|
2413
2454
|
}
|
|
2414
2455
|
function detectPackageName(absDir) {
|
|
2415
|
-
const pkgPath =
|
|
2456
|
+
const pkgPath = join3(absDir, "package.json");
|
|
2416
2457
|
if (existsSync2(pkgPath)) {
|
|
2417
2458
|
try {
|
|
2418
2459
|
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
@@ -2475,10 +2516,10 @@ function getPlatformPackage() {
|
|
|
2475
2516
|
function findAddon() {
|
|
2476
2517
|
const __dirname2 = dirname3(fileURLToPath(import.meta.url));
|
|
2477
2518
|
const platformPkg = getPlatformPackage();
|
|
2478
|
-
const zigOut =
|
|
2519
|
+
const zigOut = join4(__dirname2, "../../zig-out/lib/zntc.node");
|
|
2479
2520
|
if (existsSync3(zigOut))
|
|
2480
2521
|
return zigOut;
|
|
2481
|
-
const zigOut2 =
|
|
2522
|
+
const zigOut2 = join4(__dirname2, "../../../zig-out/lib/zntc.node");
|
|
2482
2523
|
if (existsSync3(zigOut2))
|
|
2483
2524
|
return zigOut2;
|
|
2484
2525
|
if (platformPkg) {
|
|
@@ -2487,10 +2528,10 @@ function findAddon() {
|
|
|
2487
2528
|
return nodeRequire.resolve(platformPkg);
|
|
2488
2529
|
} catch {}
|
|
2489
2530
|
}
|
|
2490
|
-
const local =
|
|
2531
|
+
const local = join4(__dirname2, "zntc.node");
|
|
2491
2532
|
if (existsSync3(local))
|
|
2492
2533
|
return local;
|
|
2493
|
-
const parent =
|
|
2534
|
+
const parent = join4(__dirname2, "../zntc.node");
|
|
2494
2535
|
if (existsSync3(parent))
|
|
2495
2536
|
return parent;
|
|
2496
2537
|
const expected = platformPkg ? ` (expected sub-package: ${platformPkg})` : "";
|
|
@@ -2555,15 +2596,15 @@ class TsconfigCache {
|
|
|
2555
2596
|
}
|
|
2556
2597
|
}
|
|
2557
2598
|
function transpile(source, options = {}) {
|
|
2558
|
-
if (
|
|
2559
|
-
throw new Error("@zntc/core:
|
|
2599
|
+
if (typeof source !== "string")
|
|
2600
|
+
throw new Error("@zntc/core: source must be a string");
|
|
2560
2601
|
validateTsConfigRaw(options.tsconfigRaw);
|
|
2561
2602
|
const optionsJson = buildOptionsJson(options, resolveUnsupported(options));
|
|
2562
2603
|
return ensureNative().transpile(source, options.filename ?? "input.js", optionsJson, options.cache ? TsconfigCache._unwrap(options.cache) : undefined);
|
|
2563
2604
|
}
|
|
2564
2605
|
function tokenize(source, options = {}) {
|
|
2565
|
-
if (
|
|
2566
|
-
throw new Error("@zntc/core:
|
|
2606
|
+
if (typeof source !== "string")
|
|
2607
|
+
throw new Error("@zntc/core: source must be a string");
|
|
2567
2608
|
return ensureNative().tokenize(source, options.filename ?? "input.js");
|
|
2568
2609
|
}
|
|
2569
2610
|
function configureProfile(profile, level) {
|
|
@@ -2572,6 +2613,18 @@ function configureProfile(profile, level) {
|
|
|
2572
2613
|
function profileReport(format = "table") {
|
|
2573
2614
|
return ensureNative().profileReport(format);
|
|
2574
2615
|
}
|
|
2616
|
+
function tlsSelfCheck(options) {
|
|
2617
|
+
ensureNative().tlsSelfCheck(options);
|
|
2618
|
+
}
|
|
2619
|
+
function startDevServer(options) {
|
|
2620
|
+
return ensureNative().startDevServer(options);
|
|
2621
|
+
}
|
|
2622
|
+
function stopDevServer(handle) {
|
|
2623
|
+
ensureNative().stopDevServer(handle);
|
|
2624
|
+
}
|
|
2625
|
+
function getDevServerPort(handle) {
|
|
2626
|
+
return ensureNative().getDevServerPort(handle);
|
|
2627
|
+
}
|
|
2575
2628
|
function normalizePluginFailure(pluginName, hookName, thrown, fallbackFile) {
|
|
2576
2629
|
let message = "Plugin hook failed";
|
|
2577
2630
|
let file = fallbackFile ?? undefined;
|
|
@@ -2654,6 +2707,21 @@ function syncPluginPromiseFailure(pluginName, hookName, file) {
|
|
|
2654
2707
|
function isPluginFailureResult(value) {
|
|
2655
2708
|
return Boolean(value && typeof value === "object" && value.__zntcPluginFailure === true);
|
|
2656
2709
|
}
|
|
2710
|
+
function deepMergeMeta(target, source) {
|
|
2711
|
+
const out = { ...target };
|
|
2712
|
+
for (const key of Object.keys(source)) {
|
|
2713
|
+
const sv = source[key];
|
|
2714
|
+
const tv = out[key];
|
|
2715
|
+
const merged = sv != null && typeof sv === "object" && !Array.isArray(sv) && tv != null && typeof tv === "object" && !Array.isArray(tv) ? deepMergeMeta(tv, sv) : sv;
|
|
2716
|
+
Object.defineProperty(out, key, {
|
|
2717
|
+
value: merged,
|
|
2718
|
+
writable: true,
|
|
2719
|
+
enumerable: true,
|
|
2720
|
+
configurable: true
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
return out;
|
|
2724
|
+
}
|
|
2657
2725
|
function safeSerializeSourceMap(map) {
|
|
2658
2726
|
try {
|
|
2659
2727
|
return { ok: true, map: serializePluginSourceMap(map) };
|
|
@@ -2680,31 +2748,37 @@ function collectPluginRegistry(plugins) {
|
|
|
2680
2748
|
buildEndCallbacks: [],
|
|
2681
2749
|
closeBundleCallbacks: [],
|
|
2682
2750
|
astFunctionHooks: [],
|
|
2683
|
-
lifecycleFailures: []
|
|
2751
|
+
lifecycleFailures: [],
|
|
2752
|
+
pluginWarnings: [],
|
|
2753
|
+
contexts: new Map
|
|
2684
2754
|
};
|
|
2685
2755
|
for (const plugin of plugins) {
|
|
2686
2756
|
const build = {
|
|
2687
2757
|
onResolve(opts, cb) {
|
|
2688
2758
|
registry.hooks.resolveId.push({
|
|
2689
2759
|
pluginName: plugin.name,
|
|
2690
|
-
filter: opts.filter,
|
|
2760
|
+
filter: stripStatefulFilterFlags(opts.filter),
|
|
2691
2761
|
callback: cb
|
|
2692
2762
|
});
|
|
2693
2763
|
},
|
|
2694
2764
|
onLoad(opts, cb) {
|
|
2695
|
-
registry.hooks.load.push({
|
|
2765
|
+
registry.hooks.load.push({
|
|
2766
|
+
pluginName: plugin.name,
|
|
2767
|
+
filter: stripStatefulFilterFlags(opts.filter),
|
|
2768
|
+
callback: cb
|
|
2769
|
+
});
|
|
2696
2770
|
},
|
|
2697
2771
|
onTransform(opts, cb) {
|
|
2698
2772
|
registry.hooks.transform.push({
|
|
2699
2773
|
pluginName: plugin.name,
|
|
2700
|
-
filter: opts.filter,
|
|
2774
|
+
filter: stripStatefulFilterFlags(opts.filter),
|
|
2701
2775
|
callback: cb
|
|
2702
2776
|
});
|
|
2703
2777
|
},
|
|
2704
2778
|
onRenderChunk(opts, cb) {
|
|
2705
2779
|
registry.hooks.renderChunk.push({
|
|
2706
2780
|
pluginName: plugin.name,
|
|
2707
|
-
filter: opts.filter,
|
|
2781
|
+
filter: stripStatefulFilterFlags(opts.filter),
|
|
2708
2782
|
callback: cb
|
|
2709
2783
|
});
|
|
2710
2784
|
},
|
|
@@ -2723,14 +2797,14 @@ function collectPluginRegistry(plugins) {
|
|
|
2723
2797
|
onAstFunction(opts, cb) {
|
|
2724
2798
|
registry.astFunctionHooks.push({
|
|
2725
2799
|
pluginName: plugin.name,
|
|
2726
|
-
filter: opts.filter,
|
|
2800
|
+
filter: stripStatefulFilterFlags(opts.filter),
|
|
2727
2801
|
callback: cb
|
|
2728
2802
|
});
|
|
2729
2803
|
},
|
|
2730
2804
|
onResolveContext(opts, cb) {
|
|
2731
2805
|
registry.hooks.resolveContext.push({
|
|
2732
2806
|
pluginName: plugin.name,
|
|
2733
|
-
filter: opts.filter,
|
|
2807
|
+
filter: stripStatefulFilterFlags(opts.filter),
|
|
2734
2808
|
callback: cb
|
|
2735
2809
|
});
|
|
2736
2810
|
}
|
|
@@ -2772,7 +2846,25 @@ function lifecycleHookSpec(reg, hookName, arg1) {
|
|
|
2772
2846
|
return null;
|
|
2773
2847
|
}
|
|
2774
2848
|
}
|
|
2775
|
-
function
|
|
2849
|
+
function getPluginContext(reg, pluginName, getModuleInfo, resolve3, emitFile, getFileName) {
|
|
2850
|
+
let ctx = reg.contexts.get(pluginName);
|
|
2851
|
+
if (!ctx) {
|
|
2852
|
+
ctx = createRollupPluginContext(pluginName, (d) => reg.pluginWarnings.push(d));
|
|
2853
|
+
reg.contexts.set(pluginName, ctx);
|
|
2854
|
+
}
|
|
2855
|
+
const slot = ctx;
|
|
2856
|
+
slot.__getModuleInfo = getModuleInfo;
|
|
2857
|
+
slot.__resolve = resolve3;
|
|
2858
|
+
slot.__emitFile = emitFile;
|
|
2859
|
+
slot.__getFileName = getFileName;
|
|
2860
|
+
return ctx;
|
|
2861
|
+
}
|
|
2862
|
+
function stripStatefulFilterFlags(re) {
|
|
2863
|
+
if (!re.global && !re.sticky)
|
|
2864
|
+
return re;
|
|
2865
|
+
return new RegExp(re.source, re.flags.replace(/[gy]/g, ""));
|
|
2866
|
+
}
|
|
2867
|
+
function* dispatchHook(reg, hookName, arg1, arg2, getModuleInfo, resolve3, emitFile, getFileName) {
|
|
2776
2868
|
if (hookName === "astFunction") {
|
|
2777
2869
|
if (reg.astFunctionHooks.length === 0)
|
|
2778
2870
|
return null;
|
|
@@ -2786,7 +2878,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2786
2878
|
if (!h.filter.test(info.sourcePath))
|
|
2787
2879
|
continue;
|
|
2788
2880
|
const result = yield {
|
|
2789
|
-
callback: () => h.callback(info),
|
|
2881
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), info),
|
|
2790
2882
|
pluginName: h.pluginName,
|
|
2791
2883
|
hookName: "astFunction",
|
|
2792
2884
|
fallbackFile: info.sourcePath
|
|
@@ -2811,7 +2903,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2811
2903
|
if (!h.filter.test(args.dir))
|
|
2812
2904
|
continue;
|
|
2813
2905
|
const result = yield {
|
|
2814
|
-
callback: () => h.callback(args),
|
|
2906
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), args),
|
|
2815
2907
|
pluginName: h.pluginName,
|
|
2816
2908
|
hookName: "resolveContext",
|
|
2817
2909
|
fallbackFile: args.importer
|
|
@@ -2829,7 +2921,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2829
2921
|
let firstFailure = null;
|
|
2830
2922
|
for (const { pluginName, callback } of spec.callbacks) {
|
|
2831
2923
|
const result = yield {
|
|
2832
|
-
callback: () => callback(spec.arg),
|
|
2924
|
+
callback: () => callback.call(getPluginContext(reg, pluginName, getModuleInfo, resolve3, emitFile, getFileName), spec.arg),
|
|
2833
2925
|
pluginName,
|
|
2834
2926
|
hookName
|
|
2835
2927
|
};
|
|
@@ -2851,12 +2943,13 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2851
2943
|
let currentCode = arg1;
|
|
2852
2944
|
let changed = false;
|
|
2853
2945
|
const sourceMaps = [];
|
|
2946
|
+
let mergedMeta;
|
|
2854
2947
|
for (const h of hookList2) {
|
|
2855
2948
|
if (!h.filter.test(arg2 ?? ""))
|
|
2856
2949
|
continue;
|
|
2857
2950
|
const cbArgs2 = hookName === "transform" ? { code: currentCode, path: arg2 } : { code: currentCode, chunk: arg2 };
|
|
2858
2951
|
const result = yield {
|
|
2859
|
-
callback: () => h.callback(cbArgs2),
|
|
2952
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), cbArgs2),
|
|
2860
2953
|
pluginName: h.pluginName,
|
|
2861
2954
|
hookName,
|
|
2862
2955
|
fallbackFile: arg2
|
|
@@ -2877,9 +2970,26 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2877
2970
|
if (r.map != null)
|
|
2878
2971
|
sourceMaps.push(r.map);
|
|
2879
2972
|
}
|
|
2973
|
+
if (hookName === "transform" && typeof result === "object" && obj.meta != null) {
|
|
2974
|
+
if (typeof obj.meta !== "object") {} else {
|
|
2975
|
+
mergedMeta = mergedMeta === undefined ? { ...obj.meta } : deepMergeMeta(mergedMeta, obj.meta);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
let metaJson;
|
|
2981
|
+
if (mergedMeta !== undefined) {
|
|
2982
|
+
try {
|
|
2983
|
+
metaJson = JSON.stringify(mergedMeta);
|
|
2984
|
+
} catch (err) {
|
|
2985
|
+
return normalizePluginFailure("transform-chain", hookName, err, arg2);
|
|
2880
2986
|
}
|
|
2881
2987
|
}
|
|
2882
|
-
return changed
|
|
2988
|
+
return changed || metaJson !== undefined ? {
|
|
2989
|
+
...changed ? { code: currentCode } : {},
|
|
2990
|
+
...sourceMaps.length > 0 ? { maps: sourceMaps } : {},
|
|
2991
|
+
...metaJson !== undefined ? { meta: metaJson } : {}
|
|
2992
|
+
} : null;
|
|
2883
2993
|
}
|
|
2884
2994
|
const hookList = reg.hooks[hookName];
|
|
2885
2995
|
if (!hookList)
|
|
@@ -2893,7 +3003,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2893
3003
|
continue;
|
|
2894
3004
|
const fallbackFile = hookName === "resolveId" ? arg2 : filterTarget;
|
|
2895
3005
|
const result = yield {
|
|
2896
|
-
callback: () => h.callback(cbArgs),
|
|
3006
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), cbArgs),
|
|
2897
3007
|
pluginName: h.pluginName,
|
|
2898
3008
|
hookName,
|
|
2899
3009
|
fallbackFile
|
|
@@ -2901,13 +3011,27 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2901
3011
|
if (isPluginFailureResult(result))
|
|
2902
3012
|
return result;
|
|
2903
3013
|
if (result != null) {
|
|
2904
|
-
|
|
2905
|
-
|
|
3014
|
+
let withMeta = result;
|
|
3015
|
+
const rawMeta = typeof result === "object" && result !== null ? result.meta : undefined;
|
|
3016
|
+
if (rawMeta != null && typeof rawMeta === "object") {
|
|
3017
|
+
let metaJson;
|
|
3018
|
+
try {
|
|
3019
|
+
metaJson = JSON.stringify(rawMeta);
|
|
3020
|
+
} catch (err) {
|
|
3021
|
+
return normalizePluginFailure(h.pluginName, hookName, err, fallbackFile);
|
|
3022
|
+
}
|
|
3023
|
+
withMeta = { ...result, meta: metaJson };
|
|
3024
|
+
}
|
|
3025
|
+
if (hookName === "load" && typeof withMeta === "object" && "map" in withMeta) {
|
|
3026
|
+
const r = safeSerializeSourceMap(withMeta.map);
|
|
2906
3027
|
if (!r.ok)
|
|
2907
3028
|
return normalizePluginFailure(h.pluginName, hookName, r.err, fallbackFile);
|
|
2908
|
-
return {
|
|
3029
|
+
return {
|
|
3030
|
+
...withMeta,
|
|
3031
|
+
...r.map != null ? { map: r.map } : { map: undefined }
|
|
3032
|
+
};
|
|
2909
3033
|
}
|
|
2910
|
-
return
|
|
3034
|
+
return withMeta;
|
|
2911
3035
|
}
|
|
2912
3036
|
}
|
|
2913
3037
|
return null;
|
|
@@ -2948,10 +3072,11 @@ function driveDispatchSync(gen) {
|
|
|
2948
3072
|
}
|
|
2949
3073
|
function createPluginDispatcher(plugins) {
|
|
2950
3074
|
const reg = collectPluginRegistry(plugins);
|
|
2951
|
-
const dispatcher = function dispatcher2(hookName, arg1, arg2) {
|
|
2952
|
-
return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2));
|
|
3075
|
+
const dispatcher = function dispatcher2(hookName, arg1, arg2, getModuleInfo, resolve3, emitFile, getFileName) {
|
|
3076
|
+
return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2, getModuleInfo, resolve3, emitFile, getFileName));
|
|
2953
3077
|
};
|
|
2954
3078
|
dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
|
|
3079
|
+
dispatcher.takePluginWarnings = () => reg.pluginWarnings.splice(0);
|
|
2955
3080
|
return dispatcher;
|
|
2956
3081
|
}
|
|
2957
3082
|
function createSyncPluginDispatcher(plugins) {
|
|
@@ -2960,6 +3085,7 @@ function createSyncPluginDispatcher(plugins) {
|
|
|
2960
3085
|
return driveDispatchSync(dispatchHook(reg, hookName, arg1, arg2));
|
|
2961
3086
|
};
|
|
2962
3087
|
dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
|
|
3088
|
+
dispatcher.takePluginWarnings = () => reg.pluginWarnings.splice(0);
|
|
2963
3089
|
return dispatcher;
|
|
2964
3090
|
}
|
|
2965
3091
|
function arrayAliasToPlugin(aliasArray) {
|
|
@@ -3003,6 +3129,11 @@ function withDefaultBuildDefines(options) {
|
|
|
3003
3129
|
}
|
|
3004
3130
|
return Object.keys(define).length > 0 ? define : undefined;
|
|
3005
3131
|
}
|
|
3132
|
+
function warnIfWatchOnlyOption(options, fnName) {
|
|
3133
|
+
if (options.skipInitialOutput) {
|
|
3134
|
+
console.warn(`@zntc/core: ${fnName}() does not honor skipInitialOutput (watch()-only option). It is silently ignored. If you meant to use this with a separate build, call watch() instead.`);
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3006
3137
|
function withDefaultAppBuildDefines(options) {
|
|
3007
3138
|
const define = { ...options.define };
|
|
3008
3139
|
if (define["process.env.NODE_ENV"] === undefined) {
|
|
@@ -3012,6 +3143,15 @@ function withDefaultAppBuildDefines(options) {
|
|
|
3012
3143
|
}
|
|
3013
3144
|
function prepareNapiOptions(options) {
|
|
3014
3145
|
const napiOptions = { ...options };
|
|
3146
|
+
if (typeof options.rnVersion === "string") {
|
|
3147
|
+
const m = /^[ \t]*(?:>=|<=|==|>|<)?[ \t]*(\d+)\.(\d+)(?:\.\d+)*[ \t]*$/.exec(options.rnVersion);
|
|
3148
|
+
if (!m || Number(m[1]) > 65535 || Number(m[2]) > 65535) {
|
|
3149
|
+
throw new Error(`Invalid rnVersion '${options.rnVersion}' (expected e.g. '0.74', '>=0.74', '<=0.84', '==0.76')`);
|
|
3150
|
+
}
|
|
3151
|
+
if (options.platform === "node" || options.platform === "neutral") {
|
|
3152
|
+
throw new Error(`rnVersion conflicts with platform: '${options.platform}' (rnVersion implies react-native)`);
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3015
3155
|
const define = withDefaultBuildDefines(options);
|
|
3016
3156
|
if (define)
|
|
3017
3157
|
napiOptions.define = define;
|
|
@@ -3153,6 +3293,16 @@ function postProcessCssOutputs(result, options) {
|
|
|
3153
3293
|
} catch {}
|
|
3154
3294
|
}
|
|
3155
3295
|
}
|
|
3296
|
+
function resolveOutputPath(filePath, opts) {
|
|
3297
|
+
const { outfileResolved, outdir } = opts;
|
|
3298
|
+
if (outfileResolved && filePath === "bundle.js")
|
|
3299
|
+
return outfileResolved;
|
|
3300
|
+
if (outfileResolved && filePath === "bundle.js.map")
|
|
3301
|
+
return `${outfileResolved}.map`;
|
|
3302
|
+
if (outdir)
|
|
3303
|
+
return join4(resolve2(outdir), filePath);
|
|
3304
|
+
return resolve2(filePath);
|
|
3305
|
+
}
|
|
3156
3306
|
function writeOutputFiles(result, options) {
|
|
3157
3307
|
const shouldWrite = options.write ?? (options.outdir != null || options.outfile != null);
|
|
3158
3308
|
if (!shouldWrite)
|
|
@@ -3168,16 +3318,7 @@ function writeOutputFiles(result, options) {
|
|
|
3168
3318
|
const createdDirs = new Set;
|
|
3169
3319
|
const outfileResolved = options.outfile ? resolve2(options.outfile) : null;
|
|
3170
3320
|
for (const file of result.outputFiles) {
|
|
3171
|
-
|
|
3172
|
-
if (outfileResolved && file.path === "bundle.js") {
|
|
3173
|
-
outPath = outfileResolved;
|
|
3174
|
-
} else if (outfileResolved && file.path.endsWith(".map")) {
|
|
3175
|
-
outPath = outfileResolved + ".map";
|
|
3176
|
-
} else if (options.outdir) {
|
|
3177
|
-
outPath = join3(resolve2(options.outdir), file.path);
|
|
3178
|
-
} else {
|
|
3179
|
-
outPath = resolve2(file.path);
|
|
3180
|
-
}
|
|
3321
|
+
const outPath = resolveOutputPath(file.path, { outfileResolved, outdir: options.outdir });
|
|
3181
3322
|
const dir = dirname3(outPath);
|
|
3182
3323
|
if (!createdDirs.has(dir)) {
|
|
3183
3324
|
mkdirSync(dir, { recursive: true });
|
|
@@ -3191,6 +3332,7 @@ async function build(options) {
|
|
|
3191
3332
|
if (!options.entryPoints?.length)
|
|
3192
3333
|
throw new Error("@zntc/core: entryPoints is required");
|
|
3193
3334
|
validateTsConfigRaw(options.tsconfigRaw);
|
|
3335
|
+
warnIfWatchOnlyOption(options, "build");
|
|
3194
3336
|
if (options.output && options.output.length >= 2) {
|
|
3195
3337
|
return buildMultiFormat(options);
|
|
3196
3338
|
}
|
|
@@ -3204,6 +3346,9 @@ async function build(options) {
|
|
|
3204
3346
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3205
3347
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3206
3348
|
}
|
|
3349
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3350
|
+
result.warnings.push(warning);
|
|
3351
|
+
}
|
|
3207
3352
|
}
|
|
3208
3353
|
postProcessCssOutputs(result, options);
|
|
3209
3354
|
writeOutputFiles(result, options);
|
|
@@ -3212,6 +3357,9 @@ async function build(options) {
|
|
|
3212
3357
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3213
3358
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3214
3359
|
}
|
|
3360
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3361
|
+
result.warnings.push(warning);
|
|
3362
|
+
}
|
|
3215
3363
|
}
|
|
3216
3364
|
return result;
|
|
3217
3365
|
} finally {
|
|
@@ -3223,6 +3371,7 @@ function buildSync(options) {
|
|
|
3223
3371
|
if (!options.entryPoints?.length)
|
|
3224
3372
|
throw new Error("@zntc/core: entryPoints is required");
|
|
3225
3373
|
validateTsConfigRaw(options.tsconfigRaw);
|
|
3374
|
+
warnIfWatchOnlyOption(options, "buildSync");
|
|
3226
3375
|
const { napiOptions, cleanup } = prepareNapiOptions(options);
|
|
3227
3376
|
const dispatcher = resolveDispatcher(options, "sync");
|
|
3228
3377
|
if (dispatcher)
|
|
@@ -3233,6 +3382,9 @@ function buildSync(options) {
|
|
|
3233
3382
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3234
3383
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3235
3384
|
}
|
|
3385
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3386
|
+
result.warnings.push(warning);
|
|
3387
|
+
}
|
|
3236
3388
|
}
|
|
3237
3389
|
postProcessCssOutputs(result, options);
|
|
3238
3390
|
writeOutputFiles(result, options);
|
|
@@ -3241,6 +3393,9 @@ function buildSync(options) {
|
|
|
3241
3393
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3242
3394
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3243
3395
|
}
|
|
3396
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3397
|
+
result.warnings.push(warning);
|
|
3398
|
+
}
|
|
3244
3399
|
}
|
|
3245
3400
|
return result;
|
|
3246
3401
|
} finally {
|
|
@@ -3316,13 +3471,33 @@ async function buildMultiFormat(options) {
|
|
|
3316
3471
|
}
|
|
3317
3472
|
function buildAppSync(options = {}) {
|
|
3318
3473
|
const n = ensureNative();
|
|
3319
|
-
const { publicDir, compiler, ...rest } = options;
|
|
3320
|
-
|
|
3474
|
+
const { publicDir, compiler, plugins: _plugins, ...rest } = options;
|
|
3475
|
+
const dispatcher = resolveDispatcher(options, "sync");
|
|
3476
|
+
const napiOptions = {
|
|
3321
3477
|
...rest,
|
|
3322
3478
|
define: withDefaultAppBuildDefines(options),
|
|
3323
3479
|
...publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {},
|
|
3324
3480
|
...buildCompilerNapiFields(compiler)
|
|
3325
|
-
}
|
|
3481
|
+
};
|
|
3482
|
+
if (dispatcher)
|
|
3483
|
+
napiOptions._pluginDispatcherSync = dispatcher;
|
|
3484
|
+
const result = wrapOutputFiles(n.buildAppSync(napiOptions));
|
|
3485
|
+
if (dispatcher) {
|
|
3486
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3487
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3488
|
+
}
|
|
3489
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3490
|
+
result.warnings.push(warning);
|
|
3491
|
+
}
|
|
3492
|
+
dispatcher("closeBundle", undefined, null);
|
|
3493
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3494
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3495
|
+
}
|
|
3496
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3497
|
+
result.warnings.push(warning);
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
return result;
|
|
3326
3501
|
}
|
|
3327
3502
|
function buildCompilerNapiFields(compiler) {
|
|
3328
3503
|
const out = {};
|
|
@@ -3436,22 +3611,90 @@ function normalizeVitePluginSourceMap(map, onDrop) {
|
|
|
3436
3611
|
return;
|
|
3437
3612
|
}
|
|
3438
3613
|
}
|
|
3439
|
-
function createRollupPluginContext(pluginName) {
|
|
3440
|
-
|
|
3614
|
+
function createRollupPluginContext(pluginName, onWarn) {
|
|
3615
|
+
const ctx = {
|
|
3441
3616
|
error(error) {
|
|
3442
3617
|
throw error;
|
|
3443
3618
|
},
|
|
3444
3619
|
warn(message) {
|
|
3445
|
-
|
|
3620
|
+
const text = `@zntc/core [${pluginName}]: ${typeof message === "string" ? message : String(message)}`;
|
|
3621
|
+
if (onWarn)
|
|
3622
|
+
onWarn({ text });
|
|
3623
|
+
else
|
|
3624
|
+
console.warn(text);
|
|
3446
3625
|
},
|
|
3447
3626
|
addWatchFile(_id) {},
|
|
3448
|
-
resolve(
|
|
3449
|
-
|
|
3627
|
+
resolve(source, importer, _options) {
|
|
3628
|
+
const fn = ctx.__resolve;
|
|
3629
|
+
if (typeof fn !== "function") {
|
|
3630
|
+
throw new Error(`@zntc/core [${pluginName}]: this.resolve() 는 async build() 의 resolveId/load/transform hook 에서만 사용 가능합니다 (#1880 PR4).`);
|
|
3631
|
+
}
|
|
3632
|
+
return Promise.resolve(fn(source, importer));
|
|
3633
|
+
},
|
|
3634
|
+
emitFile(file) {
|
|
3635
|
+
const fn = ctx.__emitFile;
|
|
3636
|
+
if (typeof fn !== "function") {
|
|
3637
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() 는 async build() 의 resolveId/load/transform hook 에서만 사용 가능합니다 (#1880 PR5).`);
|
|
3638
|
+
}
|
|
3639
|
+
if (typeof file !== "object" || file === null) {
|
|
3640
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() 는 객체 인자가 필요합니다.`);
|
|
3641
|
+
}
|
|
3642
|
+
const f = file;
|
|
3643
|
+
if (f.type === "chunk") {
|
|
3644
|
+
if (typeof f.id !== "string" || f.id.length === 0) {
|
|
3645
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk' }) 는 비어있지 않은 id(모듈 specifier)가 필요합니다 (#1880 PR7-2b).`);
|
|
3646
|
+
}
|
|
3647
|
+
if (f.implicitlyLoadedAfterOneOf !== undefined && (!Array.isArray(f.implicitlyLoadedAfterOneOf) || !f.implicitlyLoadedAfterOneOf.every((x) => typeof x === "string"))) {
|
|
3648
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk' }) 의 implicitlyLoadedAfterOneOf 는 문자열 id 배열이어야 합니다 (#3664).`);
|
|
3649
|
+
}
|
|
3650
|
+
const chunkRef = fn({
|
|
3651
|
+
chunkId: f.id,
|
|
3652
|
+
chunkName: typeof f.name === "string" && f.name.length > 0 ? f.name : undefined,
|
|
3653
|
+
chunkFileName: typeof f.fileName === "string" && f.fileName.length > 0 ? f.fileName : undefined,
|
|
3654
|
+
chunkImplicitlyLoadedAfterOneOf: Array.isArray(f.implicitlyLoadedAfterOneOf) && f.implicitlyLoadedAfterOneOf.length > 0 ? f.implicitlyLoadedAfterOneOf : undefined
|
|
3655
|
+
});
|
|
3656
|
+
if (typeof chunkRef !== "string") {
|
|
3657
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk', id: ${JSON.stringify(f.id)} }) 가 reference id 를 반환하지 못했습니다.`);
|
|
3658
|
+
}
|
|
3659
|
+
return chunkRef;
|
|
3660
|
+
}
|
|
3661
|
+
if (f.type !== "asset") {
|
|
3662
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: '${String(f.type)}' }) 는 아직 미지원입니다 — 현재 type:'asset'/'chunk' 만 지원 (#1880 PR7-2b).`);
|
|
3663
|
+
}
|
|
3664
|
+
const hasFileName = typeof f.fileName === "string" && f.fileName.length > 0;
|
|
3665
|
+
const hasName = typeof f.name === "string" && f.name.length > 0;
|
|
3666
|
+
if (!hasFileName && !hasName) {
|
|
3667
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() asset 은 비어있지 않은 fileName 또는 name 이 필요합니다 (#1880 PR6).`);
|
|
3668
|
+
}
|
|
3669
|
+
if (typeof f.source !== "string" && !(f.source instanceof Uint8Array)) {
|
|
3670
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() asset 은 source(string | Uint8Array) 가 필요합니다.`);
|
|
3671
|
+
}
|
|
3672
|
+
const referenceId = hasFileName ? fn({ fileName: f.fileName, source: f.source }) : fn({ name: f.name, source: f.source });
|
|
3673
|
+
if (typeof referenceId !== "string") {
|
|
3674
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile(${JSON.stringify(hasFileName ? f.fileName : f.name)}) 가 reference id 를 반환하지 못했습니다 (asset emit 실패).`);
|
|
3675
|
+
}
|
|
3676
|
+
return referenceId;
|
|
3450
3677
|
},
|
|
3451
|
-
|
|
3452
|
-
|
|
3678
|
+
getFileName(referenceId) {
|
|
3679
|
+
const fn = ctx.__getFileName;
|
|
3680
|
+
if (typeof fn !== "function") {
|
|
3681
|
+
throw new Error(`@zntc/core [${pluginName}]: this.getFileName() 는 resolveId/load/transform/generateBundle hook 에서만 사용 가능합니다 (#1880 PR6/2c).`);
|
|
3682
|
+
}
|
|
3683
|
+
const name = fn(referenceId);
|
|
3684
|
+
if (typeof name !== "string") {
|
|
3685
|
+
throw new Error(`@zntc/core [${pluginName}]: this.getFileName(${JSON.stringify(referenceId)}) — 알 수 없는 reference id (미emit, 또는 chunk 를 청킹 전 hook 에서 조회 — chunk 파일명은 generateBundle 에서 확정).`);
|
|
3686
|
+
}
|
|
3687
|
+
return name;
|
|
3688
|
+
},
|
|
3689
|
+
getModuleInfo(id) {
|
|
3690
|
+
const fn = ctx.__getModuleInfo;
|
|
3691
|
+
if (typeof fn !== "function") {
|
|
3692
|
+
throw new Error(`@zntc/core [${pluginName}]: this.getModuleInfo() 는 async build() 의 transform hook 에서만 사용 가능합니다 (#1880 PR3).`);
|
|
3693
|
+
}
|
|
3694
|
+
return fn(id);
|
|
3453
3695
|
}
|
|
3454
3696
|
};
|
|
3697
|
+
return ctx;
|
|
3455
3698
|
}
|
|
3456
3699
|
function createDropWarner(context) {
|
|
3457
3700
|
const seen = new Set;
|
|
@@ -3462,6 +3705,12 @@ function createDropWarner(context) {
|
|
|
3462
3705
|
context.warn(`sourcemap dropped: ${reason}`);
|
|
3463
3706
|
};
|
|
3464
3707
|
}
|
|
3708
|
+
function forwardEmitContext(nativeThis, viteCtx) {
|
|
3709
|
+
const from = nativeThis;
|
|
3710
|
+
const to = viteCtx;
|
|
3711
|
+
to.__emitFile = from?.__emitFile;
|
|
3712
|
+
to.__getFileName = from?.__getFileName;
|
|
3713
|
+
}
|
|
3465
3714
|
function vitePlugin(rollupPlugin) {
|
|
3466
3715
|
return {
|
|
3467
3716
|
name: rollupPlugin.name,
|
|
@@ -3470,7 +3719,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3470
3719
|
const onDropSourceMap = createDropWarner(context);
|
|
3471
3720
|
const resolveId = extractHandler(rollupPlugin.resolveId);
|
|
3472
3721
|
if (resolveId) {
|
|
3473
|
-
build2.onResolve({ filter: /.*/ }, (args)
|
|
3722
|
+
build2.onResolve({ filter: /.*/ }, function(args) {
|
|
3723
|
+
forwardEmitContext(this, context);
|
|
3474
3724
|
const result = resolveId.call(context, args.path, args.importer);
|
|
3475
3725
|
return mapMaybePromise(result, (result2) => {
|
|
3476
3726
|
if (result2 == null)
|
|
@@ -3486,7 +3736,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3486
3736
|
}
|
|
3487
3737
|
const load = extractHandler(rollupPlugin.load);
|
|
3488
3738
|
if (load) {
|
|
3489
|
-
build2.onLoad({ filter: /.*/ }, (args)
|
|
3739
|
+
build2.onLoad({ filter: /.*/ }, function(args) {
|
|
3740
|
+
forwardEmitContext(this, context);
|
|
3490
3741
|
const result = load.call(context, args.path);
|
|
3491
3742
|
return mapMaybePromise(result, (result2) => {
|
|
3492
3743
|
if (result2 == null)
|
|
@@ -3505,7 +3756,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3505
3756
|
}
|
|
3506
3757
|
const transform = extractHandler(rollupPlugin.transform);
|
|
3507
3758
|
if (transform) {
|
|
3508
|
-
build2.onTransform({ filter: /.*/ }, (args)
|
|
3759
|
+
build2.onTransform({ filter: /.*/ }, function(args) {
|
|
3760
|
+
forwardEmitContext(this, context);
|
|
3509
3761
|
const result = transform.call(context, args.code, args.path);
|
|
3510
3762
|
return mapMaybePromise(result, (result2) => {
|
|
3511
3763
|
if (result2 == null)
|
|
@@ -3524,7 +3776,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3524
3776
|
}
|
|
3525
3777
|
const renderChunk = extractHandler(rollupPlugin.renderChunk);
|
|
3526
3778
|
if (renderChunk) {
|
|
3527
|
-
build2.onRenderChunk({ filter: /.*/ }, (args)
|
|
3779
|
+
build2.onRenderChunk({ filter: /.*/ }, function(args) {
|
|
3780
|
+
forwardEmitContext(this, context);
|
|
3528
3781
|
const result = renderChunk.call(context, args.code, args.chunk);
|
|
3529
3782
|
return mapMaybePromise(result, (result2) => {
|
|
3530
3783
|
if (result2 == null)
|
|
@@ -3540,19 +3793,31 @@ function vitePlugin(rollupPlugin) {
|
|
|
3540
3793
|
}
|
|
3541
3794
|
const generateBundle = extractHandler(rollupPlugin.generateBundle);
|
|
3542
3795
|
if (generateBundle) {
|
|
3543
|
-
build2.onGenerateBundle((outputs)
|
|
3796
|
+
build2.onGenerateBundle(function(outputs) {
|
|
3797
|
+
forwardEmitContext(this, context);
|
|
3798
|
+
return generateBundle.call(context, outputs);
|
|
3799
|
+
});
|
|
3544
3800
|
}
|
|
3545
3801
|
const buildStart = extractHandler(rollupPlugin.buildStart);
|
|
3546
3802
|
if (buildStart) {
|
|
3547
|
-
build2.onBuildStart(()
|
|
3803
|
+
build2.onBuildStart(function() {
|
|
3804
|
+
forwardEmitContext(this, context);
|
|
3805
|
+
return buildStart.call(context);
|
|
3806
|
+
});
|
|
3548
3807
|
}
|
|
3549
3808
|
const buildEnd = extractHandler(rollupPlugin.buildEnd);
|
|
3550
3809
|
if (buildEnd) {
|
|
3551
|
-
build2.onBuildEnd((err)
|
|
3810
|
+
build2.onBuildEnd(function(err) {
|
|
3811
|
+
forwardEmitContext(this, context);
|
|
3812
|
+
return buildEnd.call(context, err);
|
|
3813
|
+
});
|
|
3552
3814
|
}
|
|
3553
3815
|
const closeBundle = extractHandler(rollupPlugin.closeBundle);
|
|
3554
3816
|
if (closeBundle) {
|
|
3555
|
-
build2.onCloseBundle(()
|
|
3817
|
+
build2.onCloseBundle(function() {
|
|
3818
|
+
forwardEmitContext(this, context);
|
|
3819
|
+
return closeBundle.call(context);
|
|
3820
|
+
});
|
|
3556
3821
|
}
|
|
3557
3822
|
}
|
|
3558
3823
|
};
|
|
@@ -3560,11 +3825,16 @@ function vitePlugin(rollupPlugin) {
|
|
|
3560
3825
|
function watch(options) {
|
|
3561
3826
|
const n = ensureNative();
|
|
3562
3827
|
const { napiOptions: nativeOpts, cleanup } = prepareNapiOptions(options);
|
|
3828
|
+
if (options.outdir !== undefined)
|
|
3829
|
+
nativeOpts.outdir = options.outdir;
|
|
3563
3830
|
const dispatcher = resolveDispatcher(options);
|
|
3564
3831
|
if (dispatcher) {
|
|
3565
3832
|
nativeOpts._pluginDispatcher = dispatcher;
|
|
3566
3833
|
const dispatchCloseBundle = () => {
|
|
3567
|
-
dispatcher("closeBundle", undefined, null).catch(() => {})
|
|
3834
|
+
dispatcher("closeBundle", undefined, null).catch(() => {}).finally(() => {
|
|
3835
|
+
for (const w of dispatcher.takePluginWarnings())
|
|
3836
|
+
console.warn(w.text);
|
|
3837
|
+
});
|
|
3568
3838
|
};
|
|
3569
3839
|
const wrapWatchCallback = (callback) => (event) => {
|
|
3570
3840
|
Promise.resolve().then(() => callback?.(event)).finally(dispatchCloseBundle).catch(() => {});
|
|
@@ -3592,6 +3862,9 @@ function watch(options) {
|
|
|
3592
3862
|
},
|
|
3593
3863
|
getHmrSourceMap(moduleId) {
|
|
3594
3864
|
return handle.getHmrSourceMap(moduleId);
|
|
3865
|
+
},
|
|
3866
|
+
requestLazySeed(path) {
|
|
3867
|
+
handle.requestLazySeed(path);
|
|
3595
3868
|
}
|
|
3596
3869
|
};
|
|
3597
3870
|
}
|
|
@@ -3603,7 +3876,11 @@ export {
|
|
|
3603
3876
|
validateTsConfigRaw,
|
|
3604
3877
|
transpile,
|
|
3605
3878
|
tokenize,
|
|
3879
|
+
tlsSelfCheck,
|
|
3606
3880
|
suggestKey,
|
|
3881
|
+
stopDevServer,
|
|
3882
|
+
startDevServer,
|
|
3883
|
+
resolveOutputPath,
|
|
3607
3884
|
profileReport,
|
|
3608
3885
|
prepareAppDevSync,
|
|
3609
3886
|
mergeUserConfigs,
|
|
@@ -3616,6 +3893,7 @@ export {
|
|
|
3616
3893
|
init,
|
|
3617
3894
|
importAndResolveDefault,
|
|
3618
3895
|
identifyWorkspaceEntries,
|
|
3896
|
+
getDevServerPort,
|
|
3619
3897
|
findWorkspacePath,
|
|
3620
3898
|
findModeConfigPath,
|
|
3621
3899
|
findConfigPath,
|