@zntc/core 0.1.1 → 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/dist/index.cjs CHANGED
@@ -102,7 +102,7 @@ function parseBrowserslistEntry(entry) {
102
102
  if (!m)return null;
103
103
  const name = m[1].toLowerCase();
104
104
  ;
105
- const [majStr, minStr="0"] = (m[2]).split("."),major = parseInt(majStr, 10),minor = parseInt(minStr, 10);
105
+ const [majStr, minStr="0"] = m[2].split("."),major = parseInt(majStr, 10),minor = parseInt(minStr, 10);
106
106
  if (Number.isNaN(major))return null;
107
107
  ;
108
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];
@@ -352,7 +352,7 @@ async function loadModuleDefault(absPath,kind,options) {
352
352
  }
353
353
  }
354
354
  if (TS_EXTS.has(ext)) {
355
- return (await loadTsModule(absPath, kind, allowArray));
355
+ return await loadTsModule(absPath, kind, allowArray);
356
356
  }
357
357
  if (JS_EXTS.has(ext)) {
358
358
  try {
@@ -402,7 +402,7 @@ async function importAndResolveDefault(absPath,options) {
402
402
  ;
403
403
  if (valueType !== "function" && !(valueType === "object" && value !== null && (allowArray || !isArray))) {
404
404
  ;
405
- throw new Error(`@zntc/core: module must be an object or function (got ${(value === null ? "null" : isArray ? "array" : valueType)}) from ${absPath}`);
405
+ throw new Error(`@zntc/core: module must be an object or function (got ${value === null ? "null" : isArray ? "array" : valueType}) from ${absPath}`);
406
406
  }
407
407
  return value;
408
408
  }
@@ -469,7 +469,7 @@ function parseDotenvLine(line) {
469
469
  const key = trimmed.slice(0, eqIdx).trim();
470
470
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))return null;
471
471
  let value = trimmed.slice(eqIdx + 1).trim();
472
- const quoted = (value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"));
472
+ const quoted = value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'");
473
473
  if (quoted) {
474
474
  value = value.slice(1, -1);
475
475
  } else {
@@ -534,7 +534,7 @@ function suggestKey(unknown,known,threshold=2) {
534
534
  for (const candidate of known) {
535
535
  const d = levenshtein(unknown, candidate);
536
536
  if (d > adjusted)continue;
537
- if (d < bestDist || (d === bestDist && best !== null && candidate < best)) {
537
+ if (d < bestDist || d === bestDist && best !== null && candidate < best) {
538
538
  best = candidate;
539
539
  bestDist = d;
540
540
  }
@@ -554,7 +554,7 @@ function warnUnknownKeys(config,known,options={}) {
554
554
  }
555
555
  return result;
556
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"];
557
+ const KNOWN_CONFIG_KEYS = ["entryPoints", "output", "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", "cssNames", "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
558
  //#endregion
559
559
  //#region workspace.ts
560
560
  var existsSync$1 = require("node:fs").existsSync;
@@ -579,7 +579,7 @@ async function loadWorkspace(filePath,env) {
579
579
  const absPath = pathResolve$2(filePath),raw = await loadModuleDefault(absPath, "workspace", { allowArray: true }),entries = typeof raw == "function" ? await raw(env ?? defaultConfigEnv()) : raw;
580
580
  if (!Array.isArray(entries)) {
581
581
  ;
582
- throw new Error(`@zntc/core: workspace must export an array (got ${(entries === null ? "null" : typeof entries)}) from ${absPath}`);
582
+ throw new Error(`@zntc/core: workspace must export an array (got ${entries === null ? "null" : typeof entries}) from ${absPath}`);
583
583
  }
584
584
  for (let i = 0; i < entries.length; i += 1) {
585
585
  const e = entries[i];
@@ -774,7 +774,7 @@ function resolveUnsupported(options) {
774
774
  }
775
775
  return browserslistToUnsupported(bl(options.browserslist));
776
776
  }
777
- return options.target ? (ES_TARGET_BITS[options.target] ?? 0) : 0;
777
+ return options.target ? ES_TARGET_BITS[options.target] ?? 0 : 0;
778
778
  }
779
779
  var TsconfigCache = class {
780
780
  _handle;
@@ -810,6 +810,18 @@ function configureProfile(profile,level) {
810
810
  function profileReport(format="table") {
811
811
  return ensureNative().profileReport(format);
812
812
  }
813
+ function tlsSelfCheck(options) {
814
+ ensureNative().tlsSelfCheck(options);
815
+ }
816
+ function startDevServer(options) {
817
+ return ensureNative().startDevServer(options);
818
+ }
819
+ function stopDevServer(handle) {
820
+ ensureNative().stopDevServer(handle);
821
+ }
822
+ function getDevServerPort(handle) {
823
+ return ensureNative().getDevServerPort(handle);
824
+ }
813
825
  function normalizePluginFailure(pluginName,hookName,thrown,fallbackFile) {
814
826
  let message = "Plugin hook failed",file = fallbackFile ?? undefined,line,column;
815
827
  if (typeof thrown == "string") {
@@ -827,14 +839,14 @@ function normalizePluginFailure(pluginName,hookName,thrown,fallbackFile) {
827
839
  } else if (thrown != null) {
828
840
  message = String(thrown);
829
841
  }
830
- return { __zntcPluginFailure: true, pluginName, hookName, message, ...(file ? { file } : {}), ...(line !== undefined ? { line } : {}), ...(column !== undefined ? { column } : {}) };
842
+ return { __zntcPluginFailure: true, pluginName, hookName, message, ...file ? { file } : {}, ...line !== undefined ? { line } : {}, ...column !== undefined ? { column } : {} };
831
843
  }
832
844
  function pluginFailureText(failure) {
833
845
  const location = failure.file && failure.line !== undefined ? ` (${failure.file}:${failure.line}:${failure.column ?? 0})` : failure.file ? ` (${failure.file})` : "";
834
846
  return `Plugin "${failure.pluginName}" failed in ${failure.hookName}: ${failure.message}${location}`;
835
847
  }
836
848
  function pluginFailureToDiagnostic(failure) {
837
- return { code: "plugin_error", text: pluginFailureText(failure), ...(failure.file ? { location: { file: failure.file, line: failure.line, column: failure.column } } : {}) };
849
+ return { code: "plugin_error", text: pluginFailureText(failure), ...failure.file ? { location: { file: failure.file, line: failure.line, column: failure.column } } : {} };
838
850
  }
839
851
  function serializePluginSourceMap(map) {
840
852
  if (map == null)return null;
@@ -856,7 +868,7 @@ function serializePluginSourceMap(map) {
856
868
  }
857
869
  }
858
870
  function isPromiseLike(value) {
859
- return (value != null && (typeof value == "object" || typeof value == "function") && typeof value.then == "function");
871
+ return value != null && (typeof value == "object" || typeof value == "function") && typeof value.then == "function";
860
872
  }
861
873
  function silenceUnsupportedSyncPromise(value) {
862
874
  Promise.resolve(value).catch(() => {
@@ -868,6 +880,14 @@ function syncPluginPromiseFailure(pluginName,hookName,file) {
868
880
  function isPluginFailureResult(value) {
869
881
  return Boolean(value && typeof value == "object" && value.__zntcPluginFailure === true);
870
882
  }
883
+ function deepMergeMeta(target,source) {
884
+ const out = { ...target };
885
+ for (const key of Object.keys(source)) {
886
+ const sv = source[key],tv = out[key],merged = sv != null && typeof sv == "object" && !Array.isArray(sv) && tv != null && typeof tv == "object" && !Array.isArray(tv) ? deepMergeMeta(tv, sv) : sv;
887
+ Object.defineProperty(out, key, { value: merged, writable: true, enumerable: true, configurable: true });
888
+ }
889
+ return out;
890
+ }
871
891
  function safeSerializeSourceMap(map) {
872
892
  try {
873
893
  return { ok: true, map: serializePluginSourceMap(map) };
@@ -880,7 +900,7 @@ function mapMaybePromise(value,mapper) {
880
900
  return mapper(value);
881
901
  }
882
902
  function collectPluginRegistry(plugins) {
883
- const registry = { hooks: { resolveId: [], load: [], transform: [], renderChunk: [], resolveContext: [] }, generateBundleCallbacks: [], buildStartCallbacks: [], buildEndCallbacks: [], closeBundleCallbacks: [], astFunctionHooks: [], lifecycleFailures: [] };
903
+ const registry = { hooks: { resolveId: [], load: [], transform: [], renderChunk: [], resolveContext: [] }, generateBundleCallbacks: [], buildStartCallbacks: [], buildEndCallbacks: [], closeBundleCallbacks: [], astFunctionHooks: [], lifecycleFailures: [], pluginWarnings: [], contexts: new Map() };
884
904
  for (const plugin of plugins) {
885
905
  const build = { onResolve(opts,cb) {
886
906
  registry.hooks.resolveId.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
@@ -929,7 +949,20 @@ function lifecycleHookSpec(reg,hookName,arg1) {
929
949
  return null;
930
950
  }
931
951
  }
932
- function* dispatchHook(reg,hookName,arg1,arg2) {
952
+ function getPluginContext(reg,pluginName,getModuleInfo,resolve,emitFile,getFileName) {
953
+ let ctx = reg.contexts.get(pluginName);
954
+ if (!ctx) {
955
+ ctx = createRollupPluginContext(pluginName, (d) => reg.pluginWarnings.push(d));
956
+ reg.contexts.set(pluginName, ctx);
957
+ }
958
+ const slot = ctx;
959
+ slot.__getModuleInfo = getModuleInfo;
960
+ slot.__resolve = resolve;
961
+ slot.__emitFile = emitFile;
962
+ slot.__getFileName = getFileName;
963
+ return ctx;
964
+ }
965
+ function* dispatchHook(reg,hookName,arg1,arg2,getModuleInfo,resolve,emitFile,getFileName) {
933
966
  if (hookName === "astFunction") {
934
967
  if (reg.astFunctionHooks.length === 0)return null;
935
968
  let info;
@@ -940,7 +973,7 @@ function* dispatchHook(reg,hookName,arg1,arg2) {
940
973
  }
941
974
  for (const h of reg.astFunctionHooks) {
942
975
  if (!h.filter.test(info.sourcePath))continue;
943
- const result = yield { callback: () => h.callback(info), pluginName: h.pluginName, hookName: "astFunction", fallbackFile: info.sourcePath };
976
+ const result = yield { callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve, emitFile, getFileName), info), pluginName: h.pluginName, hookName: "astFunction", fallbackFile: info.sourcePath };
944
977
  if (isPluginFailureResult(result))return result;
945
978
  if (result != null)return result;
946
979
  }
@@ -956,7 +989,7 @@ function* dispatchHook(reg,hookName,arg1,arg2) {
956
989
  }
957
990
  for (const h of reg.hooks.resolveContext) {
958
991
  if (!h.filter.test(args.dir))continue;
959
- const result = yield { callback: () => h.callback(args), pluginName: h.pluginName, hookName: "resolveContext", fallbackFile: args.importer };
992
+ const result = yield { callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve, emitFile, getFileName), args), pluginName: h.pluginName, hookName: "resolveContext", fallbackFile: args.importer };
960
993
  if (isPluginFailureResult(result))return result;
961
994
  if (result != null)return result;
962
995
  }
@@ -967,7 +1000,7 @@ function* dispatchHook(reg,hookName,arg1,arg2) {
967
1000
  if (spec) {
968
1001
  let firstFailure = null;
969
1002
  for (const { pluginName:pluginName, callback:callback } of spec.callbacks) {
970
- const result = yield { callback: () => callback(spec.arg), pluginName, hookName };
1003
+ const result = yield { callback: () => callback.call(getPluginContext(reg, pluginName, getModuleInfo, resolve, emitFile, getFileName), spec.arg), pluginName, hookName };
971
1004
  if (isPluginFailureResult(result) && firstFailure == null)firstFailure = result;
972
1005
  }
973
1006
  if (spec.surfaceFailures) {
@@ -982,9 +1015,10 @@ function* dispatchHook(reg,hookName,arg1,arg2) {
982
1015
  if (!hookList)return null;
983
1016
  let currentCode = arg1,changed = false;
984
1017
  const sourceMaps = [];
1018
+ let mergedMeta;
985
1019
  for (const h of hookList) {
986
1020
  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 };
1021
+ const cbArgs = hookName === "transform" ? { code: currentCode, path: arg2 } : { code: currentCode, chunk: arg2 },result = yield { callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve, emitFile, getFileName), cbArgs), pluginName: h.pluginName, hookName, fallbackFile: arg2 };
988
1022
  if (isPluginFailureResult(result))return result;
989
1023
  if (result != null) {
990
1024
  const obj = result,newCode = typeof result == "string" ? result : obj.code;
@@ -997,9 +1031,23 @@ function* dispatchHook(reg,hookName,arg1,arg2) {
997
1031
  if (!r.ok)return normalizePluginFailure(h.pluginName, hookName, r.err, arg2);
998
1032
  if (r.map != null)sourceMaps.push(r.map);
999
1033
  }
1034
+ if (hookName === "transform" && typeof result == "object" && obj.meta != null) {
1035
+ if (typeof obj.meta != "object") {
1036
+ } else {
1037
+ mergedMeta = mergedMeta === undefined ? { ...obj.meta } : deepMergeMeta(mergedMeta, obj.meta);
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ let metaJson;
1043
+ if (mergedMeta !== undefined) {
1044
+ try {
1045
+ metaJson = JSON.stringify(mergedMeta);
1046
+ } catch (err) {
1047
+ return normalizePluginFailure("transform-chain", hookName, err, arg2);
1000
1048
  }
1001
1049
  }
1002
- return changed ? { code: currentCode, ...(sourceMaps.length > 0 ? { maps: sourceMaps } : {}) } : null;
1050
+ return changed || metaJson !== undefined ? { ...changed ? { code: currentCode } : {}, ...sourceMaps.length > 0 ? { maps: sourceMaps } : {}, ...metaJson !== undefined ? { meta: metaJson } : {} } : null;
1003
1051
  }
1004
1052
  const hookList = reg.hooks[hookName];
1005
1053
  if (!hookList)return null;
@@ -1008,15 +1056,26 @@ function* dispatchHook(reg,hookName,arg1,arg2) {
1008
1056
  const [filterTarget, cbArgs] = buildArgs(arg1, arg2);
1009
1057
  for (const h of hookList) {
1010
1058
  if (!h.filter.test(filterTarget))continue;
1011
- const fallbackFile = hookName === "resolveId" ? arg2 : filterTarget,result = yield { callback: () => h.callback(cbArgs), pluginName: h.pluginName, hookName, fallbackFile };
1059
+ const fallbackFile = hookName === "resolveId" ? arg2 : filterTarget,result = yield { callback: () => h.callback.call(getPluginContext(reg, h.pluginName, getModuleInfo, resolve, emitFile, getFileName), cbArgs), pluginName: h.pluginName, hookName, fallbackFile };
1012
1060
  if (isPluginFailureResult(result))return result;
1013
1061
  if (result != null) {
1014
- if (hookName === "load" && typeof result == "object" && "map" in result) {
1015
- const r = safeSerializeSourceMap(result.map);
1062
+ let withMeta = result;
1063
+ const rawMeta = typeof result == "object" && result !== null ? result.meta : undefined;
1064
+ if (rawMeta != null && typeof rawMeta == "object") {
1065
+ let metaJson;
1066
+ try {
1067
+ metaJson = JSON.stringify(rawMeta);
1068
+ } catch (err) {
1069
+ return normalizePluginFailure(h.pluginName, hookName, err, fallbackFile);
1070
+ }
1071
+ withMeta = { ...result, meta: metaJson };
1072
+ }
1073
+ if (hookName === "load" && typeof withMeta == "object" && "map" in withMeta) {
1074
+ const r = safeSerializeSourceMap(withMeta.map);
1016
1075
  if (!r.ok)return normalizePluginFailure(h.pluginName, hookName, r.err, fallbackFile);
1017
- return { ...result, ...(r.map != null ? { map: r.map } : { map: undefined }) };
1076
+ return { ...withMeta, ...r.map != null ? { map: r.map } : { map: undefined } };
1018
1077
  }
1019
- return result;
1078
+ return withMeta;
1020
1079
  }
1021
1080
  }
1022
1081
  return null;
@@ -1056,10 +1115,11 @@ function driveDispatchSync(gen) {
1056
1115
  return r.value;
1057
1116
  }
1058
1117
  function createPluginDispatcher(plugins) {
1059
- const reg = collectPluginRegistry(plugins),dispatcher = function dispatcher(hookName,arg1,arg2) {
1060
- return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2));
1118
+ const reg = collectPluginRegistry(plugins),dispatcher = function dispatcher(hookName,arg1,arg2,getModuleInfo,resolve,emitFile,getFileName) {
1119
+ return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2, getModuleInfo, resolve, emitFile, getFileName));
1061
1120
  };
1062
1121
  dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
1122
+ dispatcher.takePluginWarnings = () => reg.pluginWarnings.splice(0);
1063
1123
  return dispatcher;
1064
1124
  }
1065
1125
  function createSyncPluginDispatcher(plugins) {
@@ -1067,6 +1127,7 @@ function createSyncPluginDispatcher(plugins) {
1067
1127
  return driveDispatchSync(dispatchHook(reg, hookName, arg1, arg2));
1068
1128
  };
1069
1129
  dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
1130
+ dispatcher.takePluginWarnings = () => reg.pluginWarnings.splice(0);
1070
1131
  return dispatcher;
1071
1132
  }
1072
1133
  function arrayAliasToPlugin(aliasArray) {
@@ -1103,6 +1164,11 @@ function withDefaultBuildDefines(options) {
1103
1164
  }
1104
1165
  return Object.keys(define).length > 0 ? define : undefined;
1105
1166
  }
1167
+ function warnIfWatchOnlyOption(options,fnName) {
1168
+ if (options.skipInitialOutput) {
1169
+ 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.`);
1170
+ }
1171
+ }
1106
1172
  function withDefaultAppBuildDefines(options) {
1107
1173
  const define = { ...options.define };
1108
1174
  if (define["process.env.NODE_ENV"] === undefined) {
@@ -1252,6 +1318,7 @@ async function build(options) {
1252
1318
  const n = ensureNative();
1253
1319
  if (!options.entryPoints?.length)throw new Error("@zntc/core: entryPoints is required");
1254
1320
  validateTsConfigRaw(options.tsconfigRaw);
1321
+ warnIfWatchOnlyOption(options, "build");
1255
1322
  if (options.output && options.output.length >= 2) {
1256
1323
  return buildMultiFormat(options);
1257
1324
  }
@@ -1263,6 +1330,9 @@ async function build(options) {
1263
1330
  for (const failure of dispatcher.takeLifecycleFailures()) {
1264
1331
  result.errors.push(pluginFailureToDiagnostic(failure));
1265
1332
  }
1333
+ for (const warning of dispatcher.takePluginWarnings()) {
1334
+ result.warnings.push(warning);
1335
+ }
1266
1336
  }
1267
1337
  postProcessCssOutputs(result, options);
1268
1338
  writeOutputFiles(result, options);
@@ -1271,6 +1341,9 @@ async function build(options) {
1271
1341
  for (const failure of dispatcher.takeLifecycleFailures()) {
1272
1342
  result.errors.push(pluginFailureToDiagnostic(failure));
1273
1343
  }
1344
+ for (const warning of dispatcher.takePluginWarnings()) {
1345
+ result.warnings.push(warning);
1346
+ }
1274
1347
  }
1275
1348
  return result;
1276
1349
  } finally {
@@ -1281,6 +1354,7 @@ function buildSync(options) {
1281
1354
  const n = ensureNative();
1282
1355
  if (!options.entryPoints?.length)throw new Error("@zntc/core: entryPoints is required");
1283
1356
  validateTsConfigRaw(options.tsconfigRaw);
1357
+ warnIfWatchOnlyOption(options, "buildSync");
1284
1358
  const { napiOptions:napiOptions, cleanup:cleanup } = prepareNapiOptions(options),dispatcher = resolveDispatcher(options, "sync");
1285
1359
  if (dispatcher)napiOptions._pluginDispatcherSync = dispatcher;
1286
1360
  try {
@@ -1289,6 +1363,9 @@ function buildSync(options) {
1289
1363
  for (const failure of dispatcher.takeLifecycleFailures()) {
1290
1364
  result.errors.push(pluginFailureToDiagnostic(failure));
1291
1365
  }
1366
+ for (const warning of dispatcher.takePluginWarnings()) {
1367
+ result.warnings.push(warning);
1368
+ }
1292
1369
  }
1293
1370
  postProcessCssOutputs(result, options);
1294
1371
  writeOutputFiles(result, options);
@@ -1297,6 +1374,9 @@ function buildSync(options) {
1297
1374
  for (const failure of dispatcher.takeLifecycleFailures()) {
1298
1375
  result.errors.push(pluginFailureToDiagnostic(failure));
1299
1376
  }
1377
+ for (const warning of dispatcher.takePluginWarnings()) {
1378
+ result.warnings.push(warning);
1379
+ }
1300
1380
  }
1301
1381
  return result;
1302
1382
  } finally {
@@ -1354,8 +1434,27 @@ async function buildMultiFormat(options) {
1354
1434
  return aggregated;
1355
1435
  }
1356
1436
  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) }));
1437
+ const n = ensureNative(),{ publicDir:publicDir, compiler:compiler, plugins:_plugins, ...rest } = options;
1438
+ ;
1439
+ const dispatcher = resolveDispatcher(options, "sync"),napiOptions = { ...rest, define: withDefaultAppBuildDefines(options), ...publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {}, ...buildCompilerNapiFields(compiler) };
1440
+ if (dispatcher)napiOptions._pluginDispatcherSync = dispatcher;
1441
+ const result = wrapOutputFiles(n.buildAppSync(napiOptions));
1442
+ if (dispatcher) {
1443
+ for (const failure of dispatcher.takeLifecycleFailures()) {
1444
+ result.errors.push(pluginFailureToDiagnostic(failure));
1445
+ }
1446
+ for (const warning of dispatcher.takePluginWarnings()) {
1447
+ result.warnings.push(warning);
1448
+ }
1449
+ dispatcher("closeBundle", undefined, null);
1450
+ for (const failure of dispatcher.takeLifecycleFailures()) {
1451
+ result.errors.push(pluginFailureToDiagnostic(failure));
1452
+ }
1453
+ for (const warning of dispatcher.takePluginWarnings()) {
1454
+ result.warnings.push(warning);
1455
+ }
1456
+ }
1457
+ return result;
1359
1458
  }
1360
1459
  function buildCompilerNapiFields(compiler) {
1361
1460
  const out = {},sc = compiler?.styledComponents;
@@ -1392,7 +1491,7 @@ function buildCompilerNapiFields(compiler) {
1392
1491
  }
1393
1492
  function prepareAppDevSync(options={}) {
1394
1493
  const n = ensureNative(),{ publicDir:publicDir, ...rest } = options;
1395
- return n.prepareAppDevSync({ ...rest, ...(publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {}) });
1494
+ return n.prepareAppDevSync({ ...rest, ...publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {} });
1396
1495
  }
1397
1496
  function close() {
1398
1497
  native = null;
@@ -1438,17 +1537,74 @@ function normalizeVitePluginSourceMap(map,onDrop) {
1438
1537
  return undefined;
1439
1538
  }
1440
1539
  }
1441
- function createRollupPluginContext(pluginName) {
1442
- return { error(error) {
1540
+ function createRollupPluginContext(pluginName,onWarn) {
1541
+ const ctx = { error(error) {
1443
1542
  throw error;
1444
1543
  }, warn(message) {
1445
- console.warn(`@zntc/core [${pluginName}]: ${typeof message == "string" ? message : String(message)}`);
1544
+ const text = `@zntc/core [${pluginName}]: ${typeof message == "string" ? message : String(message)}`;
1545
+ if (onWarn)onWarn({ text }); else console.warn(text);
1446
1546
  }, 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.`);
1547
+ }, resolve(source,importer,_options) {
1548
+ const fn = ctx.__resolve;
1549
+ if (typeof fn != "function") {
1550
+ throw new Error(`@zntc/core [${pluginName}]: this.resolve() async build() resolveId/load/transform hook 에서만 사용 가능합니다 (#1880 PR4).`);
1551
+ }
1552
+ return Promise.resolve(fn(source, importer));
1553
+ }, emitFile(file) {
1554
+ const fn = ctx.__emitFile;
1555
+ if (typeof fn != "function") {
1556
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile() 는 async build() 의 resolveId/load/transform hook 에서만 사용 가능합니다 (#1880 PR5).`);
1557
+ }
1558
+ if (typeof file != "object" || file === null) {
1559
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile() 는 객체 인자가 필요합니다.`);
1560
+ }
1561
+ const f = file;
1562
+ if (f.type === "chunk") {
1563
+ if (typeof f.id != "string" || f.id.length === 0) {
1564
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk' }) 는 비어있지 않은 id(모듈 specifier)가 필요합니다 (#1880 PR7-2b).`);
1565
+ }
1566
+ if (f.implicitlyLoadedAfterOneOf !== undefined && (!Array.isArray(f.implicitlyLoadedAfterOneOf) || !f.implicitlyLoadedAfterOneOf.every((x) => typeof x == "string"))) {
1567
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk' }) 의 implicitlyLoadedAfterOneOf 는 문자열 id 배열이어야 합니다 (#3664).`);
1568
+ }
1569
+ const chunkRef = fn({ chunkId: f.id, chunkName: typeof f.name == "string" && f.name.length > 0 ? f.name : undefined, chunkFileName: typeof f.fileName == "string" && f.fileName.length > 0 ? f.fileName : undefined, chunkImplicitlyLoadedAfterOneOf: Array.isArray(f.implicitlyLoadedAfterOneOf) && f.implicitlyLoadedAfterOneOf.length > 0 ? f.implicitlyLoadedAfterOneOf : undefined });
1570
+ if (typeof chunkRef != "string") {
1571
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: 'chunk', id: ${JSON.stringify(f.id)} }) 가 reference id 를 반환하지 못했습니다.`);
1572
+ }
1573
+ return chunkRef;
1574
+ }
1575
+ if (f.type !== "asset") {
1576
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile({ type: '${String(f.type)}' }) 는 아직 미지원입니다 — 현재 type:'asset'/'chunk' 만 지원 (#1880 PR7-2b).`);
1577
+ }
1578
+ const hasFileName = typeof f.fileName == "string" && f.fileName.length > 0,hasName = typeof f.name == "string" && f.name.length > 0;
1579
+ if (!hasFileName && !hasName) {
1580
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile() asset 은 비어있지 않은 fileName 또는 name 이 필요합니다 (#1880 PR6).`);
1581
+ }
1582
+ if (typeof f.source != "string" && !(f.source instanceof Uint8Array)) {
1583
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile() asset 은 source(string | Uint8Array) 가 필요합니다.`);
1584
+ }
1585
+ const referenceId = hasFileName ? fn({ fileName: f.fileName, source: f.source }) : fn({ name: f.name, source: f.source });
1586
+ if (typeof referenceId != "string") {
1587
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile(${JSON.stringify(hasFileName ? f.fileName : f.name)}) 가 reference id 를 반환하지 못했습니다 (asset emit 실패).`);
1588
+ }
1589
+ return referenceId;
1590
+ }, getFileName(referenceId) {
1591
+ const fn = ctx.__getFileName;
1592
+ if (typeof fn != "function") {
1593
+ throw new Error(`@zntc/core [${pluginName}]: this.getFileName() 는 resolveId/load/transform/generateBundle hook 에서만 사용 가능합니다 (#1880 PR6/2c).`);
1594
+ }
1595
+ const name = fn(referenceId);
1596
+ if (typeof name != "string") {
1597
+ throw new Error(`@zntc/core [${pluginName}]: this.getFileName(${JSON.stringify(referenceId)}) — 알 수 없는 reference id (미emit, 또는 chunk 를 청킹 전 hook 에서 조회 — chunk 파일명은 generateBundle 에서 확정).`);
1598
+ }
1599
+ return name;
1600
+ }, getModuleInfo(id) {
1601
+ const fn = ctx.__getModuleInfo;
1602
+ if (typeof fn != "function") {
1603
+ throw new Error(`@zntc/core [${pluginName}]: this.getModuleInfo() 는 async build() 의 transform hook 에서만 사용 가능합니다 (#1880 PR3).`);
1604
+ }
1605
+ return fn(id);
1451
1606
  } };
1607
+ return ctx;
1452
1608
  }
1453
1609
  function createDropWarner(context) {
1454
1610
  const seen = new Set();
@@ -1458,11 +1614,17 @@ function createDropWarner(context) {
1458
1614
  context.warn(`sourcemap dropped: ${reason}`);
1459
1615
  };
1460
1616
  }
1617
+ function forwardEmitContext(nativeThis,viteCtx) {
1618
+ const from = nativeThis,to = viteCtx;
1619
+ to.__emitFile = from?.__emitFile;
1620
+ to.__getFileName = from?.__getFileName;
1621
+ }
1461
1622
  function vitePlugin(rollupPlugin) {
1462
1623
  return { name: rollupPlugin.name, setup(build) {
1463
1624
  const context = createRollupPluginContext(rollupPlugin.name),onDropSourceMap = createDropWarner(context),resolveId = extractHandler(rollupPlugin.resolveId);
1464
1625
  if (resolveId) {
1465
- build.onResolve({ filter: /.*/ }, (args) => {
1626
+ build.onResolve({ filter: /.*/ }, function(args) {
1627
+ forwardEmitContext(this, context);
1466
1628
  const result = resolveId.call(context, args.path, args.importer);
1467
1629
  return mapMaybePromise(result, (result) => {
1468
1630
  if (result == null)return null;
@@ -1476,7 +1638,8 @@ function vitePlugin(rollupPlugin) {
1476
1638
  }
1477
1639
  const load = extractHandler(rollupPlugin.load);
1478
1640
  if (load) {
1479
- build.onLoad({ filter: /.*/ }, (args) => {
1641
+ build.onLoad({ filter: /.*/ }, function(args) {
1642
+ forwardEmitContext(this, context);
1480
1643
  const result = load.call(context, args.path);
1481
1644
  return mapMaybePromise(result, (result) => {
1482
1645
  if (result == null)return null;
@@ -1490,7 +1653,8 @@ function vitePlugin(rollupPlugin) {
1490
1653
  }
1491
1654
  const transform = extractHandler(rollupPlugin.transform);
1492
1655
  if (transform) {
1493
- build.onTransform({ filter: /.*/ }, (args) => {
1656
+ build.onTransform({ filter: /.*/ }, function(args) {
1657
+ forwardEmitContext(this, context);
1494
1658
  const result = transform.call(context, args.code, args.path);
1495
1659
  return mapMaybePromise(result, (result) => {
1496
1660
  if (result == null)return null;
@@ -1504,7 +1668,8 @@ function vitePlugin(rollupPlugin) {
1504
1668
  }
1505
1669
  const renderChunk = extractHandler(rollupPlugin.renderChunk);
1506
1670
  if (renderChunk) {
1507
- build.onRenderChunk({ filter: /.*/ }, (args) => {
1671
+ build.onRenderChunk({ filter: /.*/ }, function(args) {
1672
+ forwardEmitContext(this, context);
1508
1673
  const result = renderChunk.call(context, args.code, args.chunk);
1509
1674
  return mapMaybePromise(result, (result) => {
1510
1675
  if (result == null)return null;
@@ -1518,28 +1683,44 @@ function vitePlugin(rollupPlugin) {
1518
1683
  }
1519
1684
  const generateBundle = extractHandler(rollupPlugin.generateBundle);
1520
1685
  if (generateBundle) {
1521
- build.onGenerateBundle((outputs) => generateBundle.call(context, outputs));
1686
+ build.onGenerateBundle(function(outputs) {
1687
+ forwardEmitContext(this, context);
1688
+ return generateBundle.call(context, outputs);
1689
+ });
1522
1690
  }
1523
1691
  const buildStart = extractHandler(rollupPlugin.buildStart);
1524
1692
  if (buildStart) {
1525
- build.onBuildStart(() => buildStart.call(context));
1693
+ build.onBuildStart(function() {
1694
+ forwardEmitContext(this, context);
1695
+ return buildStart.call(context);
1696
+ });
1526
1697
  }
1527
1698
  const buildEnd = extractHandler(rollupPlugin.buildEnd);
1528
1699
  if (buildEnd) {
1529
- build.onBuildEnd((err) => buildEnd.call(context, err));
1700
+ build.onBuildEnd(function(err) {
1701
+ forwardEmitContext(this, context);
1702
+ return buildEnd.call(context, err);
1703
+ });
1530
1704
  }
1531
1705
  const closeBundle = extractHandler(rollupPlugin.closeBundle);
1532
1706
  if (closeBundle) {
1533
- build.onCloseBundle(() => closeBundle.call(context));
1707
+ build.onCloseBundle(function() {
1708
+ forwardEmitContext(this, context);
1709
+ return closeBundle.call(context);
1710
+ });
1534
1711
  }
1535
1712
  } };
1536
1713
  }
1537
1714
  function watch(options) {
1538
- const n = ensureNative(),{ napiOptions:nativeOpts, cleanup:cleanup } = prepareNapiOptions(options),dispatcher = resolveDispatcher(options);
1715
+ const n = ensureNative(),{ napiOptions:nativeOpts, cleanup:cleanup } = prepareNapiOptions(options);
1716
+ if (options.outdir !== undefined)nativeOpts.outdir = options.outdir;
1717
+ const dispatcher = resolveDispatcher(options);
1539
1718
  if (dispatcher) {
1540
1719
  nativeOpts._pluginDispatcher = dispatcher;
1541
1720
  const dispatchCloseBundle = () => {
1542
1721
  void dispatcher("closeBundle", undefined, null).catch(() => {
1722
+ }).finally(() => {
1723
+ for (const w of dispatcher.takePluginWarnings())console.warn(w.text);
1543
1724
  });
1544
1725
  },wrapWatchCallback = (callback) => (event) => {
1545
1726
  void Promise.resolve().then(() => callback?.(event)).finally(dispatchCloseBundle).catch(() => {
@@ -1565,6 +1746,8 @@ function watch(options) {
1565
1746
  return handle.getBundleSourceMap();
1566
1747
  }, getHmrSourceMap(moduleId) {
1567
1748
  return handle.getHmrSourceMap(moduleId);
1749
+ }, requestLazySeed(path) {
1750
+ handle.requestLazySeed(path);
1568
1751
  } };
1569
1752
  }
1570
1753
  exports.isPlainObject = isPlainObject;
@@ -1595,6 +1778,10 @@ exports.transpile = transpile;
1595
1778
  exports.tokenize = tokenize;
1596
1779
  exports.configureProfile = configureProfile;
1597
1780
  exports.profileReport = profileReport;
1781
+ exports.tlsSelfCheck = tlsSelfCheck;
1782
+ exports.startDevServer = startDevServer;
1783
+ exports.stopDevServer = stopDevServer;
1784
+ exports.getDevServerPort = getDevServerPort;
1598
1785
  exports.build = build;
1599
1786
  exports.buildSync = buildSync;
1600
1787
  exports.BuildInstance = BuildInstance;