@zntc/core 0.1.0 → 0.1.2
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/bin/cli-flags.mjs +8 -0
- package/bin/rn-dev-input.mjs +6 -0
- package/bin/zntc.mjs +789 -45
- package/dist/core/index.d.cts +260 -3
- package/dist/core/index.d.ts +260 -3
- package/dist/core/src/schema-allowlists.d.ts +1 -1
- package/dist/index.cjs +231 -44
- package/dist/index.js +252 -33
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -2183,6 +2183,7 @@ function warnUnknownKeys(config, known, options = {}) {
|
|
|
2183
2183
|
}
|
|
2184
2184
|
var KNOWN_CONFIG_KEYS = [
|
|
2185
2185
|
"entryPoints",
|
|
2186
|
+
"output",
|
|
2186
2187
|
"outdir",
|
|
2187
2188
|
"outfile",
|
|
2188
2189
|
"outbase",
|
|
@@ -2247,6 +2248,7 @@ var KNOWN_CONFIG_KEYS = [
|
|
|
2247
2248
|
"entryNames",
|
|
2248
2249
|
"chunkNames",
|
|
2249
2250
|
"assetNames",
|
|
2251
|
+
"cssNames",
|
|
2250
2252
|
"experimentalDecorators",
|
|
2251
2253
|
"emitDecoratorMetadata",
|
|
2252
2254
|
"useDefineForClassFields",
|
|
@@ -2572,6 +2574,18 @@ function configureProfile(profile, level) {
|
|
|
2572
2574
|
function profileReport(format = "table") {
|
|
2573
2575
|
return ensureNative().profileReport(format);
|
|
2574
2576
|
}
|
|
2577
|
+
function tlsSelfCheck(options) {
|
|
2578
|
+
ensureNative().tlsSelfCheck(options);
|
|
2579
|
+
}
|
|
2580
|
+
function startDevServer(options) {
|
|
2581
|
+
return ensureNative().startDevServer(options);
|
|
2582
|
+
}
|
|
2583
|
+
function stopDevServer(handle) {
|
|
2584
|
+
ensureNative().stopDevServer(handle);
|
|
2585
|
+
}
|
|
2586
|
+
function getDevServerPort(handle) {
|
|
2587
|
+
return ensureNative().getDevServerPort(handle);
|
|
2588
|
+
}
|
|
2575
2589
|
function normalizePluginFailure(pluginName, hookName, thrown, fallbackFile) {
|
|
2576
2590
|
let message = "Plugin hook failed";
|
|
2577
2591
|
let file = fallbackFile ?? undefined;
|
|
@@ -2654,6 +2668,21 @@ function syncPluginPromiseFailure(pluginName, hookName, file) {
|
|
|
2654
2668
|
function isPluginFailureResult(value) {
|
|
2655
2669
|
return Boolean(value && typeof value === "object" && value.__zntcPluginFailure === true);
|
|
2656
2670
|
}
|
|
2671
|
+
function deepMergeMeta(target, source) {
|
|
2672
|
+
const out = { ...target };
|
|
2673
|
+
for (const key of Object.keys(source)) {
|
|
2674
|
+
const sv = source[key];
|
|
2675
|
+
const tv = out[key];
|
|
2676
|
+
const merged = sv != null && typeof sv === "object" && !Array.isArray(sv) && tv != null && typeof tv === "object" && !Array.isArray(tv) ? deepMergeMeta(tv, sv) : sv;
|
|
2677
|
+
Object.defineProperty(out, key, {
|
|
2678
|
+
value: merged,
|
|
2679
|
+
writable: true,
|
|
2680
|
+
enumerable: true,
|
|
2681
|
+
configurable: true
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
return out;
|
|
2685
|
+
}
|
|
2657
2686
|
function safeSerializeSourceMap(map) {
|
|
2658
2687
|
try {
|
|
2659
2688
|
return { ok: true, map: serializePluginSourceMap(map) };
|
|
@@ -2680,7 +2709,9 @@ function collectPluginRegistry(plugins) {
|
|
|
2680
2709
|
buildEndCallbacks: [],
|
|
2681
2710
|
closeBundleCallbacks: [],
|
|
2682
2711
|
astFunctionHooks: [],
|
|
2683
|
-
lifecycleFailures: []
|
|
2712
|
+
lifecycleFailures: [],
|
|
2713
|
+
pluginWarnings: [],
|
|
2714
|
+
contexts: new Map
|
|
2684
2715
|
};
|
|
2685
2716
|
for (const plugin of plugins) {
|
|
2686
2717
|
const build = {
|
|
@@ -2772,7 +2803,20 @@ function lifecycleHookSpec(reg, hookName, arg1) {
|
|
|
2772
2803
|
return null;
|
|
2773
2804
|
}
|
|
2774
2805
|
}
|
|
2775
|
-
function
|
|
2806
|
+
function getPluginContext(reg, pluginName, getModuleInfo, resolve3, emitFile, getFileName) {
|
|
2807
|
+
let ctx = reg.contexts.get(pluginName);
|
|
2808
|
+
if (!ctx) {
|
|
2809
|
+
ctx = createRollupPluginContext(pluginName, (d) => reg.pluginWarnings.push(d));
|
|
2810
|
+
reg.contexts.set(pluginName, ctx);
|
|
2811
|
+
}
|
|
2812
|
+
const slot = ctx;
|
|
2813
|
+
slot.__getModuleInfo = getModuleInfo;
|
|
2814
|
+
slot.__resolve = resolve3;
|
|
2815
|
+
slot.__emitFile = emitFile;
|
|
2816
|
+
slot.__getFileName = getFileName;
|
|
2817
|
+
return ctx;
|
|
2818
|
+
}
|
|
2819
|
+
function* dispatchHook(reg, hookName, arg1, arg2, getModuleInfo, resolve3, emitFile, getFileName) {
|
|
2776
2820
|
if (hookName === "astFunction") {
|
|
2777
2821
|
if (reg.astFunctionHooks.length === 0)
|
|
2778
2822
|
return null;
|
|
@@ -2786,7 +2830,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2786
2830
|
if (!h.filter.test(info.sourcePath))
|
|
2787
2831
|
continue;
|
|
2788
2832
|
const result = yield {
|
|
2789
|
-
callback: () => h.callback(info),
|
|
2833
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), info),
|
|
2790
2834
|
pluginName: h.pluginName,
|
|
2791
2835
|
hookName: "astFunction",
|
|
2792
2836
|
fallbackFile: info.sourcePath
|
|
@@ -2811,7 +2855,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2811
2855
|
if (!h.filter.test(args.dir))
|
|
2812
2856
|
continue;
|
|
2813
2857
|
const result = yield {
|
|
2814
|
-
callback: () => h.callback(args),
|
|
2858
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), args),
|
|
2815
2859
|
pluginName: h.pluginName,
|
|
2816
2860
|
hookName: "resolveContext",
|
|
2817
2861
|
fallbackFile: args.importer
|
|
@@ -2829,7 +2873,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2829
2873
|
let firstFailure = null;
|
|
2830
2874
|
for (const { pluginName, callback } of spec.callbacks) {
|
|
2831
2875
|
const result = yield {
|
|
2832
|
-
callback: () => callback(spec.arg),
|
|
2876
|
+
callback: () => callback.call(getPluginContext(reg, pluginName, getModuleInfo, resolve3, emitFile, getFileName), spec.arg),
|
|
2833
2877
|
pluginName,
|
|
2834
2878
|
hookName
|
|
2835
2879
|
};
|
|
@@ -2851,12 +2895,13 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2851
2895
|
let currentCode = arg1;
|
|
2852
2896
|
let changed = false;
|
|
2853
2897
|
const sourceMaps = [];
|
|
2898
|
+
let mergedMeta;
|
|
2854
2899
|
for (const h of hookList2) {
|
|
2855
2900
|
if (!h.filter.test(arg2 ?? ""))
|
|
2856
2901
|
continue;
|
|
2857
2902
|
const cbArgs2 = hookName === "transform" ? { code: currentCode, path: arg2 } : { code: currentCode, chunk: arg2 };
|
|
2858
2903
|
const result = yield {
|
|
2859
|
-
callback: () => h.callback(cbArgs2),
|
|
2904
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), cbArgs2),
|
|
2860
2905
|
pluginName: h.pluginName,
|
|
2861
2906
|
hookName,
|
|
2862
2907
|
fallbackFile: arg2
|
|
@@ -2877,9 +2922,26 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2877
2922
|
if (r.map != null)
|
|
2878
2923
|
sourceMaps.push(r.map);
|
|
2879
2924
|
}
|
|
2925
|
+
if (hookName === "transform" && typeof result === "object" && obj.meta != null) {
|
|
2926
|
+
if (typeof obj.meta !== "object") {} else {
|
|
2927
|
+
mergedMeta = mergedMeta === undefined ? { ...obj.meta } : deepMergeMeta(mergedMeta, obj.meta);
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
let metaJson;
|
|
2933
|
+
if (mergedMeta !== undefined) {
|
|
2934
|
+
try {
|
|
2935
|
+
metaJson = JSON.stringify(mergedMeta);
|
|
2936
|
+
} catch (err) {
|
|
2937
|
+
return normalizePluginFailure("transform-chain", hookName, err, arg2);
|
|
2880
2938
|
}
|
|
2881
2939
|
}
|
|
2882
|
-
return changed
|
|
2940
|
+
return changed || metaJson !== undefined ? {
|
|
2941
|
+
...changed ? { code: currentCode } : {},
|
|
2942
|
+
...sourceMaps.length > 0 ? { maps: sourceMaps } : {},
|
|
2943
|
+
...metaJson !== undefined ? { meta: metaJson } : {}
|
|
2944
|
+
} : null;
|
|
2883
2945
|
}
|
|
2884
2946
|
const hookList = reg.hooks[hookName];
|
|
2885
2947
|
if (!hookList)
|
|
@@ -2893,7 +2955,7 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2893
2955
|
continue;
|
|
2894
2956
|
const fallbackFile = hookName === "resolveId" ? arg2 : filterTarget;
|
|
2895
2957
|
const result = yield {
|
|
2896
|
-
callback: () => h.callback(cbArgs),
|
|
2958
|
+
callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve3, emitFile, getFileName), cbArgs),
|
|
2897
2959
|
pluginName: h.pluginName,
|
|
2898
2960
|
hookName,
|
|
2899
2961
|
fallbackFile
|
|
@@ -2901,13 +2963,27 @@ function* dispatchHook(reg, hookName, arg1, arg2) {
|
|
|
2901
2963
|
if (isPluginFailureResult(result))
|
|
2902
2964
|
return result;
|
|
2903
2965
|
if (result != null) {
|
|
2904
|
-
|
|
2905
|
-
|
|
2966
|
+
let withMeta = result;
|
|
2967
|
+
const rawMeta = typeof result === "object" && result !== null ? result.meta : undefined;
|
|
2968
|
+
if (rawMeta != null && typeof rawMeta === "object") {
|
|
2969
|
+
let metaJson;
|
|
2970
|
+
try {
|
|
2971
|
+
metaJson = JSON.stringify(rawMeta);
|
|
2972
|
+
} catch (err) {
|
|
2973
|
+
return normalizePluginFailure(h.pluginName, hookName, err, fallbackFile);
|
|
2974
|
+
}
|
|
2975
|
+
withMeta = { ...result, meta: metaJson };
|
|
2976
|
+
}
|
|
2977
|
+
if (hookName === "load" && typeof withMeta === "object" && "map" in withMeta) {
|
|
2978
|
+
const r = safeSerializeSourceMap(withMeta.map);
|
|
2906
2979
|
if (!r.ok)
|
|
2907
2980
|
return normalizePluginFailure(h.pluginName, hookName, r.err, fallbackFile);
|
|
2908
|
-
return {
|
|
2981
|
+
return {
|
|
2982
|
+
...withMeta,
|
|
2983
|
+
...r.map != null ? { map: r.map } : { map: undefined }
|
|
2984
|
+
};
|
|
2909
2985
|
}
|
|
2910
|
-
return
|
|
2986
|
+
return withMeta;
|
|
2911
2987
|
}
|
|
2912
2988
|
}
|
|
2913
2989
|
return null;
|
|
@@ -2948,10 +3024,11 @@ function driveDispatchSync(gen) {
|
|
|
2948
3024
|
}
|
|
2949
3025
|
function createPluginDispatcher(plugins) {
|
|
2950
3026
|
const reg = collectPluginRegistry(plugins);
|
|
2951
|
-
const dispatcher = function dispatcher2(hookName, arg1, arg2) {
|
|
2952
|
-
return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2));
|
|
3027
|
+
const dispatcher = function dispatcher2(hookName, arg1, arg2, getModuleInfo, resolve3, emitFile, getFileName) {
|
|
3028
|
+
return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2, getModuleInfo, resolve3, emitFile, getFileName));
|
|
2953
3029
|
};
|
|
2954
3030
|
dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
|
|
3031
|
+
dispatcher.takePluginWarnings = () => reg.pluginWarnings.splice(0);
|
|
2955
3032
|
return dispatcher;
|
|
2956
3033
|
}
|
|
2957
3034
|
function createSyncPluginDispatcher(plugins) {
|
|
@@ -2960,6 +3037,7 @@ function createSyncPluginDispatcher(plugins) {
|
|
|
2960
3037
|
return driveDispatchSync(dispatchHook(reg, hookName, arg1, arg2));
|
|
2961
3038
|
};
|
|
2962
3039
|
dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
|
|
3040
|
+
dispatcher.takePluginWarnings = () => reg.pluginWarnings.splice(0);
|
|
2963
3041
|
return dispatcher;
|
|
2964
3042
|
}
|
|
2965
3043
|
function arrayAliasToPlugin(aliasArray) {
|
|
@@ -3003,6 +3081,11 @@ function withDefaultBuildDefines(options) {
|
|
|
3003
3081
|
}
|
|
3004
3082
|
return Object.keys(define).length > 0 ? define : undefined;
|
|
3005
3083
|
}
|
|
3084
|
+
function warnIfWatchOnlyOption(options, fnName) {
|
|
3085
|
+
if (options.skipInitialOutput) {
|
|
3086
|
+
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.`);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3006
3089
|
function withDefaultAppBuildDefines(options) {
|
|
3007
3090
|
const define = { ...options.define };
|
|
3008
3091
|
if (define["process.env.NODE_ENV"] === undefined) {
|
|
@@ -3191,6 +3274,7 @@ async function build(options) {
|
|
|
3191
3274
|
if (!options.entryPoints?.length)
|
|
3192
3275
|
throw new Error("@zntc/core: entryPoints is required");
|
|
3193
3276
|
validateTsConfigRaw(options.tsconfigRaw);
|
|
3277
|
+
warnIfWatchOnlyOption(options, "build");
|
|
3194
3278
|
if (options.output && options.output.length >= 2) {
|
|
3195
3279
|
return buildMultiFormat(options);
|
|
3196
3280
|
}
|
|
@@ -3204,6 +3288,9 @@ async function build(options) {
|
|
|
3204
3288
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3205
3289
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3206
3290
|
}
|
|
3291
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3292
|
+
result.warnings.push(warning);
|
|
3293
|
+
}
|
|
3207
3294
|
}
|
|
3208
3295
|
postProcessCssOutputs(result, options);
|
|
3209
3296
|
writeOutputFiles(result, options);
|
|
@@ -3212,6 +3299,9 @@ async function build(options) {
|
|
|
3212
3299
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3213
3300
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3214
3301
|
}
|
|
3302
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3303
|
+
result.warnings.push(warning);
|
|
3304
|
+
}
|
|
3215
3305
|
}
|
|
3216
3306
|
return result;
|
|
3217
3307
|
} finally {
|
|
@@ -3223,6 +3313,7 @@ function buildSync(options) {
|
|
|
3223
3313
|
if (!options.entryPoints?.length)
|
|
3224
3314
|
throw new Error("@zntc/core: entryPoints is required");
|
|
3225
3315
|
validateTsConfigRaw(options.tsconfigRaw);
|
|
3316
|
+
warnIfWatchOnlyOption(options, "buildSync");
|
|
3226
3317
|
const { napiOptions, cleanup } = prepareNapiOptions(options);
|
|
3227
3318
|
const dispatcher = resolveDispatcher(options, "sync");
|
|
3228
3319
|
if (dispatcher)
|
|
@@ -3233,6 +3324,9 @@ function buildSync(options) {
|
|
|
3233
3324
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3234
3325
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3235
3326
|
}
|
|
3327
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3328
|
+
result.warnings.push(warning);
|
|
3329
|
+
}
|
|
3236
3330
|
}
|
|
3237
3331
|
postProcessCssOutputs(result, options);
|
|
3238
3332
|
writeOutputFiles(result, options);
|
|
@@ -3241,6 +3335,9 @@ function buildSync(options) {
|
|
|
3241
3335
|
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3242
3336
|
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3243
3337
|
}
|
|
3338
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3339
|
+
result.warnings.push(warning);
|
|
3340
|
+
}
|
|
3244
3341
|
}
|
|
3245
3342
|
return result;
|
|
3246
3343
|
} finally {
|
|
@@ -3316,13 +3413,33 @@ async function buildMultiFormat(options) {
|
|
|
3316
3413
|
}
|
|
3317
3414
|
function buildAppSync(options = {}) {
|
|
3318
3415
|
const n = ensureNative();
|
|
3319
|
-
const { publicDir, compiler, ...rest } = options;
|
|
3320
|
-
|
|
3416
|
+
const { publicDir, compiler, plugins: _plugins, ...rest } = options;
|
|
3417
|
+
const dispatcher = resolveDispatcher(options, "sync");
|
|
3418
|
+
const napiOptions = {
|
|
3321
3419
|
...rest,
|
|
3322
3420
|
define: withDefaultAppBuildDefines(options),
|
|
3323
3421
|
...publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {},
|
|
3324
3422
|
...buildCompilerNapiFields(compiler)
|
|
3325
|
-
}
|
|
3423
|
+
};
|
|
3424
|
+
if (dispatcher)
|
|
3425
|
+
napiOptions._pluginDispatcherSync = dispatcher;
|
|
3426
|
+
const result = wrapOutputFiles(n.buildAppSync(napiOptions));
|
|
3427
|
+
if (dispatcher) {
|
|
3428
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3429
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3430
|
+
}
|
|
3431
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3432
|
+
result.warnings.push(warning);
|
|
3433
|
+
}
|
|
3434
|
+
dispatcher("closeBundle", undefined, null);
|
|
3435
|
+
for (const failure of dispatcher.takeLifecycleFailures()) {
|
|
3436
|
+
result.errors.push(pluginFailureToDiagnostic(failure));
|
|
3437
|
+
}
|
|
3438
|
+
for (const warning of dispatcher.takePluginWarnings()) {
|
|
3439
|
+
result.warnings.push(warning);
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
return result;
|
|
3326
3443
|
}
|
|
3327
3444
|
function buildCompilerNapiFields(compiler) {
|
|
3328
3445
|
const out = {};
|
|
@@ -3436,22 +3553,90 @@ function normalizeVitePluginSourceMap(map, onDrop) {
|
|
|
3436
3553
|
return;
|
|
3437
3554
|
}
|
|
3438
3555
|
}
|
|
3439
|
-
function createRollupPluginContext(pluginName) {
|
|
3440
|
-
|
|
3556
|
+
function createRollupPluginContext(pluginName, onWarn) {
|
|
3557
|
+
const ctx = {
|
|
3441
3558
|
error(error) {
|
|
3442
3559
|
throw error;
|
|
3443
3560
|
},
|
|
3444
3561
|
warn(message) {
|
|
3445
|
-
|
|
3562
|
+
const text = `@zntc/core [${pluginName}]: ${typeof message === "string" ? message : String(message)}`;
|
|
3563
|
+
if (onWarn)
|
|
3564
|
+
onWarn({ text });
|
|
3565
|
+
else
|
|
3566
|
+
console.warn(text);
|
|
3446
3567
|
},
|
|
3447
3568
|
addWatchFile(_id) {},
|
|
3448
|
-
resolve(
|
|
3449
|
-
|
|
3569
|
+
resolve(source, importer, _options) {
|
|
3570
|
+
const fn = ctx.__resolve;
|
|
3571
|
+
if (typeof fn !== "function") {
|
|
3572
|
+
throw new Error(`@zntc/core [${pluginName}]: this.resolve() 는 async build() 의 resolveId/load/transform hook 에서만 사용 가능합니다 (#1880 PR4).`);
|
|
3573
|
+
}
|
|
3574
|
+
return Promise.resolve(fn(source, importer));
|
|
3450
3575
|
},
|
|
3451
|
-
emitFile(
|
|
3452
|
-
|
|
3576
|
+
emitFile(file) {
|
|
3577
|
+
const fn = ctx.__emitFile;
|
|
3578
|
+
if (typeof fn !== "function") {
|
|
3579
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() 는 async build() 의 resolveId/load/transform hook 에서만 사용 가능합니다 (#1880 PR5).`);
|
|
3580
|
+
}
|
|
3581
|
+
if (typeof file !== "object" || file === null) {
|
|
3582
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() 는 객체 인자가 필요합니다.`);
|
|
3583
|
+
}
|
|
3584
|
+
const f = file;
|
|
3585
|
+
if (f.type === "chunk") {
|
|
3586
|
+
if (typeof f.id !== "string" || f.id.length === 0) {
|
|
3587
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk' }) 는 비어있지 않은 id(모듈 specifier)가 필요합니다 (#1880 PR7-2b).`);
|
|
3588
|
+
}
|
|
3589
|
+
if (f.implicitlyLoadedAfterOneOf !== undefined && (!Array.isArray(f.implicitlyLoadedAfterOneOf) || !f.implicitlyLoadedAfterOneOf.every((x) => typeof x === "string"))) {
|
|
3590
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk' }) 의 implicitlyLoadedAfterOneOf 는 문자열 id 배열이어야 합니다 (#3664).`);
|
|
3591
|
+
}
|
|
3592
|
+
const chunkRef = fn({
|
|
3593
|
+
chunkId: f.id,
|
|
3594
|
+
chunkName: typeof f.name === "string" && f.name.length > 0 ? f.name : undefined,
|
|
3595
|
+
chunkFileName: typeof f.fileName === "string" && f.fileName.length > 0 ? f.fileName : undefined,
|
|
3596
|
+
chunkImplicitlyLoadedAfterOneOf: Array.isArray(f.implicitlyLoadedAfterOneOf) && f.implicitlyLoadedAfterOneOf.length > 0 ? f.implicitlyLoadedAfterOneOf : undefined
|
|
3597
|
+
});
|
|
3598
|
+
if (typeof chunkRef !== "string") {
|
|
3599
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk', id: ${JSON.stringify(f.id)} }) 가 reference id 를 반환하지 못했습니다.`);
|
|
3600
|
+
}
|
|
3601
|
+
return chunkRef;
|
|
3602
|
+
}
|
|
3603
|
+
if (f.type !== "asset") {
|
|
3604
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: '${String(f.type)}' }) 는 아직 미지원입니다 — 현재 type:'asset'/'chunk' 만 지원 (#1880 PR7-2b).`);
|
|
3605
|
+
}
|
|
3606
|
+
const hasFileName = typeof f.fileName === "string" && f.fileName.length > 0;
|
|
3607
|
+
const hasName = typeof f.name === "string" && f.name.length > 0;
|
|
3608
|
+
if (!hasFileName && !hasName) {
|
|
3609
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() asset 은 비어있지 않은 fileName 또는 name 이 필요합니다 (#1880 PR6).`);
|
|
3610
|
+
}
|
|
3611
|
+
if (typeof f.source !== "string" && !(f.source instanceof Uint8Array)) {
|
|
3612
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile() asset 은 source(string | Uint8Array) 가 필요합니다.`);
|
|
3613
|
+
}
|
|
3614
|
+
const referenceId = hasFileName ? fn({ fileName: f.fileName, source: f.source }) : fn({ name: f.name, source: f.source });
|
|
3615
|
+
if (typeof referenceId !== "string") {
|
|
3616
|
+
throw new Error(`@zntc/core [${pluginName}]: this.emitFile(${JSON.stringify(hasFileName ? f.fileName : f.name)}) 가 reference id 를 반환하지 못했습니다 (asset emit 실패).`);
|
|
3617
|
+
}
|
|
3618
|
+
return referenceId;
|
|
3619
|
+
},
|
|
3620
|
+
getFileName(referenceId) {
|
|
3621
|
+
const fn = ctx.__getFileName;
|
|
3622
|
+
if (typeof fn !== "function") {
|
|
3623
|
+
throw new Error(`@zntc/core [${pluginName}]: this.getFileName() 는 resolveId/load/transform/generateBundle hook 에서만 사용 가능합니다 (#1880 PR6/2c).`);
|
|
3624
|
+
}
|
|
3625
|
+
const name = fn(referenceId);
|
|
3626
|
+
if (typeof name !== "string") {
|
|
3627
|
+
throw new Error(`@zntc/core [${pluginName}]: this.getFileName(${JSON.stringify(referenceId)}) — 알 수 없는 reference id (미emit, 또는 chunk 를 청킹 전 hook 에서 조회 — chunk 파일명은 generateBundle 에서 확정).`);
|
|
3628
|
+
}
|
|
3629
|
+
return name;
|
|
3630
|
+
},
|
|
3631
|
+
getModuleInfo(id) {
|
|
3632
|
+
const fn = ctx.__getModuleInfo;
|
|
3633
|
+
if (typeof fn !== "function") {
|
|
3634
|
+
throw new Error(`@zntc/core [${pluginName}]: this.getModuleInfo() 는 async build() 의 transform hook 에서만 사용 가능합니다 (#1880 PR3).`);
|
|
3635
|
+
}
|
|
3636
|
+
return fn(id);
|
|
3453
3637
|
}
|
|
3454
3638
|
};
|
|
3639
|
+
return ctx;
|
|
3455
3640
|
}
|
|
3456
3641
|
function createDropWarner(context) {
|
|
3457
3642
|
const seen = new Set;
|
|
@@ -3462,6 +3647,12 @@ function createDropWarner(context) {
|
|
|
3462
3647
|
context.warn(`sourcemap dropped: ${reason}`);
|
|
3463
3648
|
};
|
|
3464
3649
|
}
|
|
3650
|
+
function forwardEmitContext(nativeThis, viteCtx) {
|
|
3651
|
+
const from = nativeThis;
|
|
3652
|
+
const to = viteCtx;
|
|
3653
|
+
to.__emitFile = from?.__emitFile;
|
|
3654
|
+
to.__getFileName = from?.__getFileName;
|
|
3655
|
+
}
|
|
3465
3656
|
function vitePlugin(rollupPlugin) {
|
|
3466
3657
|
return {
|
|
3467
3658
|
name: rollupPlugin.name,
|
|
@@ -3470,7 +3661,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3470
3661
|
const onDropSourceMap = createDropWarner(context);
|
|
3471
3662
|
const resolveId = extractHandler(rollupPlugin.resolveId);
|
|
3472
3663
|
if (resolveId) {
|
|
3473
|
-
build2.onResolve({ filter: /.*/ }, (args)
|
|
3664
|
+
build2.onResolve({ filter: /.*/ }, function(args) {
|
|
3665
|
+
forwardEmitContext(this, context);
|
|
3474
3666
|
const result = resolveId.call(context, args.path, args.importer);
|
|
3475
3667
|
return mapMaybePromise(result, (result2) => {
|
|
3476
3668
|
if (result2 == null)
|
|
@@ -3486,7 +3678,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3486
3678
|
}
|
|
3487
3679
|
const load = extractHandler(rollupPlugin.load);
|
|
3488
3680
|
if (load) {
|
|
3489
|
-
build2.onLoad({ filter: /.*/ }, (args)
|
|
3681
|
+
build2.onLoad({ filter: /.*/ }, function(args) {
|
|
3682
|
+
forwardEmitContext(this, context);
|
|
3490
3683
|
const result = load.call(context, args.path);
|
|
3491
3684
|
return mapMaybePromise(result, (result2) => {
|
|
3492
3685
|
if (result2 == null)
|
|
@@ -3505,7 +3698,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3505
3698
|
}
|
|
3506
3699
|
const transform = extractHandler(rollupPlugin.transform);
|
|
3507
3700
|
if (transform) {
|
|
3508
|
-
build2.onTransform({ filter: /.*/ }, (args)
|
|
3701
|
+
build2.onTransform({ filter: /.*/ }, function(args) {
|
|
3702
|
+
forwardEmitContext(this, context);
|
|
3509
3703
|
const result = transform.call(context, args.code, args.path);
|
|
3510
3704
|
return mapMaybePromise(result, (result2) => {
|
|
3511
3705
|
if (result2 == null)
|
|
@@ -3524,7 +3718,8 @@ function vitePlugin(rollupPlugin) {
|
|
|
3524
3718
|
}
|
|
3525
3719
|
const renderChunk = extractHandler(rollupPlugin.renderChunk);
|
|
3526
3720
|
if (renderChunk) {
|
|
3527
|
-
build2.onRenderChunk({ filter: /.*/ }, (args)
|
|
3721
|
+
build2.onRenderChunk({ filter: /.*/ }, function(args) {
|
|
3722
|
+
forwardEmitContext(this, context);
|
|
3528
3723
|
const result = renderChunk.call(context, args.code, args.chunk);
|
|
3529
3724
|
return mapMaybePromise(result, (result2) => {
|
|
3530
3725
|
if (result2 == null)
|
|
@@ -3540,19 +3735,31 @@ function vitePlugin(rollupPlugin) {
|
|
|
3540
3735
|
}
|
|
3541
3736
|
const generateBundle = extractHandler(rollupPlugin.generateBundle);
|
|
3542
3737
|
if (generateBundle) {
|
|
3543
|
-
build2.onGenerateBundle((outputs)
|
|
3738
|
+
build2.onGenerateBundle(function(outputs) {
|
|
3739
|
+
forwardEmitContext(this, context);
|
|
3740
|
+
return generateBundle.call(context, outputs);
|
|
3741
|
+
});
|
|
3544
3742
|
}
|
|
3545
3743
|
const buildStart = extractHandler(rollupPlugin.buildStart);
|
|
3546
3744
|
if (buildStart) {
|
|
3547
|
-
build2.onBuildStart(()
|
|
3745
|
+
build2.onBuildStart(function() {
|
|
3746
|
+
forwardEmitContext(this, context);
|
|
3747
|
+
return buildStart.call(context);
|
|
3748
|
+
});
|
|
3548
3749
|
}
|
|
3549
3750
|
const buildEnd = extractHandler(rollupPlugin.buildEnd);
|
|
3550
3751
|
if (buildEnd) {
|
|
3551
|
-
build2.onBuildEnd((err)
|
|
3752
|
+
build2.onBuildEnd(function(err) {
|
|
3753
|
+
forwardEmitContext(this, context);
|
|
3754
|
+
return buildEnd.call(context, err);
|
|
3755
|
+
});
|
|
3552
3756
|
}
|
|
3553
3757
|
const closeBundle = extractHandler(rollupPlugin.closeBundle);
|
|
3554
3758
|
if (closeBundle) {
|
|
3555
|
-
build2.onCloseBundle(()
|
|
3759
|
+
build2.onCloseBundle(function() {
|
|
3760
|
+
forwardEmitContext(this, context);
|
|
3761
|
+
return closeBundle.call(context);
|
|
3762
|
+
});
|
|
3556
3763
|
}
|
|
3557
3764
|
}
|
|
3558
3765
|
};
|
|
@@ -3560,11 +3767,16 @@ function vitePlugin(rollupPlugin) {
|
|
|
3560
3767
|
function watch(options) {
|
|
3561
3768
|
const n = ensureNative();
|
|
3562
3769
|
const { napiOptions: nativeOpts, cleanup } = prepareNapiOptions(options);
|
|
3770
|
+
if (options.outdir !== undefined)
|
|
3771
|
+
nativeOpts.outdir = options.outdir;
|
|
3563
3772
|
const dispatcher = resolveDispatcher(options);
|
|
3564
3773
|
if (dispatcher) {
|
|
3565
3774
|
nativeOpts._pluginDispatcher = dispatcher;
|
|
3566
3775
|
const dispatchCloseBundle = () => {
|
|
3567
|
-
dispatcher("closeBundle", undefined, null).catch(() => {})
|
|
3776
|
+
dispatcher("closeBundle", undefined, null).catch(() => {}).finally(() => {
|
|
3777
|
+
for (const w of dispatcher.takePluginWarnings())
|
|
3778
|
+
console.warn(w.text);
|
|
3779
|
+
});
|
|
3568
3780
|
};
|
|
3569
3781
|
const wrapWatchCallback = (callback) => (event) => {
|
|
3570
3782
|
Promise.resolve().then(() => callback?.(event)).finally(dispatchCloseBundle).catch(() => {});
|
|
@@ -3592,6 +3804,9 @@ function watch(options) {
|
|
|
3592
3804
|
},
|
|
3593
3805
|
getHmrSourceMap(moduleId) {
|
|
3594
3806
|
return handle.getHmrSourceMap(moduleId);
|
|
3807
|
+
},
|
|
3808
|
+
requestLazySeed(path) {
|
|
3809
|
+
handle.requestLazySeed(path);
|
|
3595
3810
|
}
|
|
3596
3811
|
};
|
|
3597
3812
|
}
|
|
@@ -3603,7 +3818,10 @@ export {
|
|
|
3603
3818
|
validateTsConfigRaw,
|
|
3604
3819
|
transpile,
|
|
3605
3820
|
tokenize,
|
|
3821
|
+
tlsSelfCheck,
|
|
3606
3822
|
suggestKey,
|
|
3823
|
+
stopDevServer,
|
|
3824
|
+
startDevServer,
|
|
3607
3825
|
profileReport,
|
|
3608
3826
|
prepareAppDevSync,
|
|
3609
3827
|
mergeUserConfigs,
|
|
@@ -3616,6 +3834,7 @@ export {
|
|
|
3616
3834
|
init,
|
|
3617
3835
|
importAndResolveDefault,
|
|
3618
3836
|
identifyWorkspaceEntries,
|
|
3837
|
+
getDevServerPort,
|
|
3619
3838
|
findWorkspacePath,
|
|
3620
3839
|
findModeConfigPath,
|
|
3621
3840
|
findConfigPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zntc/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "ZNTC native transpiler & compiler binding",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bundler",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
|
-
"build:napi": "cd ../.. && zig build napi",
|
|
62
|
+
"build:napi": "cd ../.. && zig build napi --cache-dir .zig-cache-napi",
|
|
63
63
|
"build:js:esm": "bun build index.ts --outdir dist --format esm --target node",
|
|
64
64
|
"build:js:cjs": "node bin/zntc.mjs --bundle index.ts --outfile dist/index.cjs --format=cjs --platform=node --packages=external",
|
|
65
65
|
"build:js": "bun run build:js:esm && bun run build:js:cjs",
|
|
@@ -73,18 +73,18 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/node": "^25.5.2",
|
|
76
|
-
"@zntc/test-helpers": "
|
|
76
|
+
"@zntc/test-helpers": "0.0.0"
|
|
77
77
|
},
|
|
78
78
|
"optionalDependencies": {
|
|
79
|
-
"@zntc/core-darwin-arm64": "0.1.
|
|
80
|
-
"@zntc/core-darwin-x64": "0.1.
|
|
81
|
-
"@zntc/core-linux-arm64-gnu": "0.1.
|
|
82
|
-
"@zntc/core-linux-arm64-musl": "0.1.
|
|
83
|
-
"@zntc/core-linux-x64-gnu": "0.1.
|
|
84
|
-
"@zntc/core-linux-x64-musl": "0.1.
|
|
85
|
-
"@zntc/core-win32-arm64-msvc": "0.1.
|
|
86
|
-
"@zntc/core-win32-ia32-msvc": "0.1.
|
|
87
|
-
"@zntc/core-win32-x64-msvc": "0.1.
|
|
79
|
+
"@zntc/core-darwin-arm64": "0.1.2",
|
|
80
|
+
"@zntc/core-darwin-x64": "0.1.2",
|
|
81
|
+
"@zntc/core-linux-arm64-gnu": "0.1.2",
|
|
82
|
+
"@zntc/core-linux-arm64-musl": "0.1.2",
|
|
83
|
+
"@zntc/core-linux-x64-gnu": "0.1.2",
|
|
84
|
+
"@zntc/core-linux-x64-musl": "0.1.2",
|
|
85
|
+
"@zntc/core-win32-arm64-msvc": "0.1.2",
|
|
86
|
+
"@zntc/core-win32-ia32-msvc": "0.1.2",
|
|
87
|
+
"@zntc/core-win32-x64-msvc": "0.1.2",
|
|
88
88
|
"browserslist": "^4.24.0",
|
|
89
89
|
"core-js": "^3.49.0",
|
|
90
90
|
"core-js-compat": "^3.49.0",
|