mbler 0.2.7-rc.6 → 0.2.8-rc.1

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/build.d.ts CHANGED
@@ -29,12 +29,13 @@ interface MblerBuildConfig {
29
29
  }
30
30
  interface MblerConfigData {
31
31
  name: string;
32
+ displayName?: string;
32
33
  outdir?: MblerConfigOutdir;
33
34
  description: string;
34
35
  version: string;
35
36
  mcVersion: string | string[];
36
37
  script?: MblerConfigScript;
37
- minify?: boolean;
38
+ minify?: 'oxc' | 'terser' | 'esbuild';
38
39
  build?: Partial<MblerBuildConfig>;
39
40
  }
40
41
  interface CliParam {
@@ -43,10 +44,6 @@ interface CliParam {
43
44
  }
44
45
  //#endregion
45
46
  //#region src/build/sapi.d.ts
46
- /**
47
- * Compare two dotted version strings ("major.minor.patch").
48
- * Returns negative if a < b, positive if a > b, zero if equal.
49
- */
50
47
  declare const Sapi: () => {
51
48
  refresh: () => Promise<void>;
52
49
  generateVersion: (module: "@minecraft/server-ui" | "@minecraft/server", mcVersion: string, isBeta: boolean, withFull: boolean) => Promise<string>;
@@ -1,6 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
2
  import * as mcxDef from "@mbler/mcx-core";
3
- import minifyPlugin from "@rollup/plugin-terser";
4
3
  import { watch as watch$1 } from "chokidar";
5
4
  import * as fs$3 from "node:fs/promises";
6
5
  import fs from "node:fs/promises";
@@ -11,9 +10,10 @@ import * as readline from "readline";
11
10
  import * as fs$2 from "node:fs";
12
11
  import fs$1 from "node:fs";
13
12
  import os, { homedir, tmpdir } from "node:os";
14
- import crypto from "node:crypto";
15
13
  import { env } from "node:process";
16
14
  import { styleText } from "node:util";
15
+ import { pathToFileURL } from "node:url";
16
+ import crypto from "node:crypto";
17
17
  import { createMCXLanguagePlugin } from "@mbler/mcx-server";
18
18
  import { runTsc } from "@volar/typescript/lib/quickstart/runTsc.js";
19
19
  //#region \0rolldown/runtime.js
@@ -44,11 +44,12 @@ const cmdList = [
44
44
  ];
45
45
  const templateMblerConfig = {
46
46
  name: "demo",
47
+ displayName: "",
47
48
  description: "demo",
48
49
  version: "0.0.0",
49
50
  mcVersion: "1.21.100",
51
+ minify: "oxc",
50
52
  script: { main: "" },
51
- minify: false,
52
53
  outdir: {
53
54
  behavior: "",
54
55
  resources: "",
@@ -68,19 +69,13 @@ const templateMblerConfig = {
68
69
  //#endregion
69
70
  //#region src/version.ts
70
71
  var version_default = {
71
- commit: `commit 85f665dae2e6951b64fd1f021a8bb151c5776b15
72
+ commit: `commit fd62af9738d7c40c81852464f6b10c32921396ed
72
73
  Author: ruanhor <3915264929@qq.com>
73
- Date: Sat Jun 13 22:04:15 2026 +0800
74
+ Date: Mon Jun 22 18:20:50 2026 +0800
74
75
 
75
- refactor(cli): add declarative command framework with typed params
76
-
77
- - Add src/cli/command.ts with CommandDef, parseArgs, parseRawParams
78
- - Refactor CLI dispatcher to use CommandDef-based dispatch
79
- - Convert all 11 command handlers to declarative CommandDef format
80
- - Fix parseParam to handle -flag=value correctly
81
- - Add 63 new tests for CLI framework and publisher modules
76
+ fix: improve error message clarity in build process
82
77
  `,
83
- version: "0.2.7-rc.4"
78
+ version: "0.2.8"
84
79
  };
85
80
  //#endregion
86
81
  //#region src/i18n/zh.ts
@@ -159,6 +154,7 @@ git https://github.com/RuanhoR/mbler/`,
159
154
  readmeNotFound: "未找到 README 文件",
160
155
  metadataInvalid: "元数据无效",
161
156
  packageNameInvalid: "包名格式必须是 @scope/name",
157
+ nameMismatch: "mbler.config.js 与 package.json 中的 name 必须一致",
162
158
  notLoginError: "未登录",
163
159
  tokenMissing: "获取 token 失败",
164
160
  unpublishReqFailed: "取消发布请求失败",
@@ -274,6 +270,7 @@ var en_default = {
274
270
  readmeNotFound: "README file not found",
275
271
  metadataInvalid: "Invalid metadata",
276
272
  packageNameInvalid: "Package name must be in the format of @scope/name",
273
+ nameMismatch: "Package name in mbler.config.js and package.json must match",
277
274
  notLoginError: "Not logged in",
278
275
  tokenMissing: "Failed to get token",
279
276
  unpublishReqFailed: "Failed to unpublish package",
@@ -579,6 +576,11 @@ const BuildConfig = {
579
576
  items: "directory",
580
577
  loot_tables: "directory",
581
578
  recipes: "directory",
579
+ /**
580
+ * Skipped from the default copy flow; handled separately by the build:
581
+ * - bundle: true → bundled via rollup
582
+ * - bundle: false → copied as-is into the output
583
+ */
582
584
  scripts: "skip",
583
585
  spawn_rules: "directory",
584
586
  structures: "directory",
@@ -614,6 +616,7 @@ async function ReadProjectMblerConfig(project) {
614
616
  try {
615
617
  const pkgRaw = await fs$3.readFile(path$1.join(project, "package.json"), "utf-8");
616
618
  const pkg = JSON.parse(pkgRaw);
619
+ if (file.name && pkg.name && file.name !== pkg.name) throw new Error(`Package name mismatch: mbler.config.js ("${file.name}") != package.json ("${pkg.name}"). They must match.`);
617
620
  if (pkg.name) config.name = pkg.name;
618
621
  if (pkg.version) config.version = pkg.version;
619
622
  } catch {}
@@ -621,6 +624,11 @@ async function ReadProjectMblerConfig(project) {
621
624
  if (!config.version) config.version = "0.0.0";
622
625
  return config;
623
626
  }
627
+ function sleep(time) {
628
+ return new Promise((resolve) => {
629
+ setTimeout(resolve, time);
630
+ });
631
+ }
624
632
  /**
625
633
  * Print a single-line message to stdout with a trailing newline.
626
634
  * Exported here so other modules (for example `build`) do not need
@@ -733,6 +741,96 @@ var BuildCacheManager = class {
733
741
  }
734
742
  };
735
743
  //#endregion
744
+ //#region src/build/release.ts
745
+ function Release() {
746
+ const AdmZip = __require("adm-zip");
747
+ function createFullZip(dir) {
748
+ const zip = new AdmZip();
749
+ zip.addLocalFolder(dir);
750
+ return zip;
751
+ }
752
+ function createZipWithMoreFolder(dir) {
753
+ const zip = new AdmZip();
754
+ for (const folder of dir) zip.addLocalFolder(folder[0], folder[1]);
755
+ return zip;
756
+ }
757
+ return async function generateRelease(build) {
758
+ if (!build.outdirs) throw new Error("invalid Build");
759
+ if (env.BUILD_MODULE !== "release") return;
760
+ let zip;
761
+ if (build.module == "all") zip = createZipWithMoreFolder([[build.outdirs?.behavior, "behavior"], [build.outdirs?.resources, "resources"]]);
762
+ else if (build.module == "behavior") zip = createFullZip(build.outdirs?.behavior);
763
+ else zip = createFullZip(build.outdirs?.resources);
764
+ await zip.writeZipPromise(build.outdirs?.dist);
765
+ };
766
+ }
767
+ let releaseEmul = null;
768
+ const generateRelease = (...argv) => {
769
+ if (!releaseEmul) releaseEmul = Release();
770
+ return releaseEmul(...argv);
771
+ };
772
+ //#endregion
773
+ //#region src/build/postgress.ts
774
+ var Postgress = class {
775
+ max;
776
+ constructor(max) {
777
+ this.max = max;
778
+ }
779
+ update(current) {
780
+ const percentage = Math.min(current, this.max) / this.max;
781
+ const barWidth = 30;
782
+ const filledWidth = Math.round(barWidth * percentage);
783
+ const emptyWidth = barWidth - filledWidth;
784
+ showText(`\n\u001B[1A\r[${`${styleText("green", "█".repeat(filledWidth))}${styleText("white", "█".repeat(emptyWidth))}`}] ${styleText("blue", `${Math.round(percentage * 100)}%`)} (${current}/${this.max})`, false);
785
+ if (current == this.max) showText("", true);
786
+ }
787
+ };
788
+ //#endregion
789
+ //#region src/build/minify.ts
790
+ function resolvePackage(name, baseBuildDir) {
791
+ const require = createRequire(path.join(baseBuildDir, "noop.js"));
792
+ try {
793
+ return require.resolve(name, { paths: [baseBuildDir] });
794
+ } catch {
795
+ throw new Error(`\`${name}\` is required for minification. Install it in your project:\n npm i -D ${name}\n pnpm add -D ${name}\n yarn add -D ${name}`);
796
+ }
797
+ }
798
+ function terserPlugin(baseBuildDir) {
799
+ return {
800
+ name: "mbler:terser",
801
+ async generateBundle(_, bundle) {
802
+ const terser = await import(pathToFileURL(resolvePackage("terser", baseBuildDir)).href);
803
+ for (const [, chunk] of Object.entries(bundle)) {
804
+ if (chunk.type !== "chunk") continue;
805
+ const res = await terser.minify(chunk.code, {
806
+ format: { comments: false },
807
+ compress: {
808
+ unused: true,
809
+ dead_code: true,
810
+ if_return: true
811
+ }
812
+ });
813
+ if (res.code) chunk.code = res.code;
814
+ }
815
+ }
816
+ };
817
+ }
818
+ function esbuildPlugin(baseBuildDir) {
819
+ return {
820
+ name: "mbler:esbuild",
821
+ async generateBundle(_, bundle) {
822
+ const esbuild = await import(pathToFileURL(resolvePackage("esbuild", baseBuildDir)).href);
823
+ for (const [, chunk] of Object.entries(bundle)) {
824
+ if (chunk.type !== "chunk") continue;
825
+ chunk.code = (await esbuild.transform(chunk.code, {
826
+ minify: true,
827
+ loader: "js"
828
+ })).code;
829
+ }
830
+ }
831
+ };
832
+ }
833
+ //#endregion
736
834
  //#region src/uuid/index.ts
737
835
  /**
738
836
  * @description To generate uuid
@@ -756,21 +854,18 @@ const config = {
756
854
  };
757
855
  //#endregion
758
856
  //#region src/build/sapi.ts
759
- /**
760
- * Compare two dotted version strings ("major.minor.patch").
761
- * Returns negative if a < b, positive if a > b, zero if equal.
762
- */
763
857
  const Sapi = function() {
764
- async function json(path) {
765
- return await (await fetch("https://registry.npmjs.com" + path)).json();
858
+ const MAX_RETRIES = 3;
859
+ async function json(path, attempt = 1) {
860
+ const r = await fetch("https://registry.npmjs.com" + path);
861
+ if (!r.ok && attempt < MAX_RETRIES) {
862
+ await sleep(1e3 * attempt);
863
+ return json(path, attempt + 1);
864
+ }
865
+ return await r.json();
766
866
  }
767
867
  const cacheFile = path$1.join(config.tmpdir, "_sapi_version.json");
768
868
  let cacheData = null;
769
- /**
770
- * Pull every published version for a package and reduce it to a mapping
771
- * from the embedded Minecraft version (e.g. "1.21.60") to the most
772
- * recent formal/beta release we were able to parse.
773
- */
774
869
  async function fetchData(pkgName) {
775
870
  const data = await json(`/${pkgName}`);
776
871
  const pkgVersions = Object.keys(data.versions);
@@ -787,18 +882,13 @@ const Sapi = function() {
787
882
  if (!entry) {
788
883
  entry = {
789
884
  formal: "",
790
- beta: "",
791
- _v: -1
885
+ beta: ""
792
886
  };
793
887
  reValue[mcVersion] = entry;
794
888
  }
795
889
  if (isStable) {
796
- if (!entry.formal || v > entry.formal) entry.formal = v;
797
- entry._v = Infinity;
798
- } else {
799
- if (!entry.beta || v > entry.beta) entry.beta = v;
800
- if (entry._v !== Infinity) entry._v = 1;
801
- }
890
+ if (!entry.formal || compareVersion(v, entry.formal) > 0) entry.formal = v;
891
+ } else if (!entry.beta || compareVersion(v, entry.beta) > 0) entry.beta = v;
802
892
  }
803
893
  return reValue;
804
894
  }
@@ -807,26 +897,20 @@ const Sapi = function() {
807
897
  const uiMap = await fetchData("@minecraft/server-ui");
808
898
  const versions = new Set([...Object.keys(serverMap), ...Object.keys(uiMap)]);
809
899
  const arr = [];
810
- for (const ver of Array.from(versions)) arr.push({
900
+ for (const ver of versions) arr.push({
811
901
  version: ver,
812
- server: serverMap[ver] ? {
813
- formal: serverMap[ver].formal,
814
- beta: serverMap[ver].beta
815
- } : {
902
+ server: serverMap[ver] ?? {
816
903
  formal: "",
817
904
  beta: ""
818
905
  },
819
- "server-ui": uiMap[ver] ? {
820
- formal: uiMap[ver].formal,
821
- beta: uiMap[ver].beta
822
- } : {
906
+ "server-ui": uiMap[ver] ?? {
823
907
  formal: "",
824
908
  beta: ""
825
909
  }
826
910
  });
827
911
  arr.sort((a, b) => compareVersion(a.version, b.version));
828
912
  cacheData = arr;
829
- await fs$2.promises.mkdir(config.tmpdir, { recursive: true }).catch(() => void 0);
913
+ await fs$2.promises.mkdir(config.tmpdir, { recursive: true }).catch(() => {});
830
914
  await fs$2.promises.writeFile(cacheFile, JSON.stringify(arr, null, 2), "utf-8");
831
915
  }
832
916
  async function generateVersion(module, mcVersion, isBeta, withFull = false) {
@@ -836,26 +920,20 @@ const Sapi = function() {
836
920
  } catch {
837
921
  await refresh();
838
922
  }
839
- if (!cacheData) throw new Error("unable to load sapi cache data");
923
+ if (!cacheData) throw new Error("unable to load SAPI version data. Check network connectivity or delete ~/.mbler/_sapi_version.json and try again.");
840
924
  let entry = cacheData.find((e) => e.version === mcVersion);
841
925
  if (!entry) {
842
- const sorted = cacheData.slice();
843
926
  let candidate = null;
844
- for (const e of sorted) if (compareVersion(e.version, mcVersion) <= 0) candidate = e;
927
+ for (const e of cacheData) if (compareVersion(e.version, mcVersion) <= 0) candidate = e;
845
928
  else break;
846
- if (!candidate) candidate = sorted[0];
847
- entry = candidate;
929
+ entry = candidate ?? cacheData[0];
848
930
  }
931
+ if (!entry) throw new Error(`no SAPI version data found for Minecraft version ${mcVersion}`);
849
932
  const entryModule = entry[module === "@minecraft/server" ? "server" : "server-ui"];
850
933
  let result = isBeta ? entryModule.beta : entryModule.formal;
851
934
  if (!result) result = entryModule.formal || entryModule.beta;
852
935
  if (withFull) return result || "";
853
- else {
854
- const tmp = result.split("-").slice(0, 2);
855
- tmp[1] = tmp[1].split(".")[0];
856
- result = tmp.join("-");
857
- return result || "error";
858
- }
936
+ return evalVersion(result || "error");
859
937
  }
860
938
  return {
861
939
  refresh,
@@ -877,8 +955,7 @@ var sapi_default = new Proxy({}, {
877
955
  function evalVersion(result) {
878
956
  const tmp = result.split("-").slice(0, 2);
879
957
  tmp[1] = tmp[1].split(".")[0];
880
- result = tmp.join("-");
881
- return result;
958
+ return tmp.join("-");
882
959
  }
883
960
  //#endregion
884
961
  //#region src/build/manifest.ts
@@ -887,7 +964,7 @@ async function generateManifest(config, type) {
887
964
  const manifest = {
888
965
  format_version: 2,
889
966
  header: {
890
- name: config.name,
967
+ name: config.displayName || config.name,
891
968
  description: config.description,
892
969
  uuid: fromString(hashRaw, BuildConfig.salt.header),
893
970
  version: stringToNumberArray(config.version),
@@ -939,51 +1016,6 @@ async function generateManifest(config, type) {
939
1016
  return manifest;
940
1017
  }
941
1018
  //#endregion
942
- //#region src/build/release.ts
943
- function Release() {
944
- const AdmZip = __require("adm-zip");
945
- function createFullZip(dir) {
946
- const zip = new AdmZip();
947
- zip.addLocalFolder(dir);
948
- return zip;
949
- }
950
- function createZipWithMoreFolder(dir) {
951
- const zip = new AdmZip();
952
- for (const folder of dir) zip.addLocalFolder(folder[0], folder[1]);
953
- return zip;
954
- }
955
- return async function generateRelease(build) {
956
- if (!build.outdirs) throw new Error("invalid Build");
957
- if (env.BUILD_MODULE !== "release") return;
958
- let zip;
959
- if (build.module == "all") zip = createZipWithMoreFolder([[build.outdirs?.behavior, "behavior"], [build.outdirs?.resources, "resources"]]);
960
- else if (build.module == "behavior") zip = createFullZip(build.outdirs?.behavior);
961
- else zip = createFullZip(build.outdirs?.resources);
962
- await zip.writeZipPromise(build.outdirs?.dist);
963
- };
964
- }
965
- let releaseEmul = null;
966
- const generateRelease = (...argv) => {
967
- if (!releaseEmul) releaseEmul = Release();
968
- return releaseEmul(...argv);
969
- };
970
- //#endregion
971
- //#region src/build/postgress.ts
972
- var Postgress = class {
973
- max;
974
- constructor(max) {
975
- this.max = max;
976
- }
977
- update(current) {
978
- const percentage = Math.min(current, this.max) / this.max;
979
- const barWidth = 30;
980
- const filledWidth = Math.round(barWidth * percentage);
981
- const emptyWidth = barWidth - filledWidth;
982
- showText(`\n\u001B[1A\r[${`${styleText("green", "█".repeat(filledWidth))}${styleText("white", "█".repeat(emptyWidth))}`}] ${styleText("blue", `${Math.round(percentage * 100)}%`)} (${current}/${this.max})`, false);
983
- if (current == this.max) showText("", true);
984
- }
985
- };
986
- //#endregion
987
1019
  //#region src/build/plugin-mcx-tsc.ts
988
1020
  /**
989
1021
  * 运行 MCX TypeScript 编译器
@@ -1147,18 +1179,20 @@ var Build = class {
1147
1179
  const isBundle = this.currentConfig.build?.bundle !== false;
1148
1180
  if (this.currentConfig.script) if (isBundle) {
1149
1181
  const rBuild = await this.createRollup();
1150
- if (!this.rollupPlugin || !this.outdirs) throw new Error(`[build addon]: can't resolve rollup instance`);
1182
+ if (!this.rollupPlugin || !this.outdirs) throw new Error(`[build addon]: rollup instance not available`);
1151
1183
  if (!this.isWatch) progress.update(50);
1152
1184
  let output = this.currentConfig.script?.main;
1153
1185
  if (!output) output = "index.js";
1154
1186
  if (path.extname(output) !== "js") output = output.slice(0, output.length - path.extname(output).length) + ".js";
1155
1187
  if (this.buildConfig?.outputFilename) output = this.buildConfig.outputFilename;
1156
1188
  const outputDir = this.buildConfig?.outputDir || "scripts";
1157
- await rBuild.write({
1189
+ const writeOptions = {
1158
1190
  file: join(path.join(this.outdirs.behavior, outputDir), output),
1159
1191
  format: "esm",
1160
1192
  sourcemap: false
1161
- });
1193
+ };
1194
+ if (this.currentConfig.minify === "oxc") writeOptions.minify = true;
1195
+ await rBuild.write(writeOptions);
1162
1196
  } else {
1163
1197
  const srcScriptDir = path.join(this.srcDirs.behavior, "scripts");
1164
1198
  const outputDir = this.buildConfig?.outputDir || "scripts";
@@ -1169,7 +1203,7 @@ var Build = class {
1169
1203
  });
1170
1204
  }
1171
1205
  if (!this.isWatch) progress.update(70);
1172
- if (!this.outdirs || !this.module) throw new Error(`[build addon]: can't resolve outdirs`);
1206
+ if (!this.outdirs || !this.module) throw new Error(`[build addon]: output directories not initialized`);
1173
1207
  await generateRelease({
1174
1208
  outdirs: this.outdirs,
1175
1209
  module: this.module
@@ -1191,21 +1225,21 @@ var Build = class {
1191
1225
  * (in which case nothing needs to be bundled).
1192
1226
  */
1193
1227
  async createRollup() {
1194
- if (!this.currentConfig || !this.srcDirs || !this.outdirs) throw new Error(`[build addon]: can't first can this method`);
1228
+ if (!this.currentConfig || !this.srcDirs || !this.outdirs) throw new Error(`[build addon]: internal error: called before initialization`);
1195
1229
  if (!this.currentConfig.script) return;
1196
1230
  const main = path.join(this.srcDirs.behavior, "scripts", this.currentConfig.script.main);
1197
- if (!await FileExist(main)) throw new Error(`[build addon]: main script ${main} is not exist: can't resolve entry`);
1231
+ if (!await FileExist(main)) throw new Error(`[build addon]: main script not found: ${main}`);
1198
1232
  const plugin = [];
1199
1233
  const moduleDir = path.join(this.baseBuildDir, "node_modules");
1200
- if (!await FileExist(moduleDir)) throw new Error(`[build addon]: node_modules is not exist in project root: can't resolve node_modules for rollup: ${moduleDir}`);
1201
- if (this.currentConfig.minify) plugin.push(minifyPlugin({
1202
- format: { comments: false },
1203
- compress: { unused: true }
1204
- }));
1234
+ if (!await FileExist(moduleDir)) throw new Error(`[build addon]: node_modules not found: ${moduleDir}`);
1235
+ if (this.currentConfig.minify) {
1236
+ if (this.currentConfig.minify === "terser") plugin.push(terserPlugin(this.baseBuildDir));
1237
+ else if (this.currentConfig.minify === "esbuild") plugin.push(esbuildPlugin(this.baseBuildDir));
1238
+ }
1205
1239
  if (this.buildConfig?.rollupPlugins) plugin.push(...this.buildConfig.rollupPlugins);
1206
1240
  if (this.currentConfig.script?.lang == "mcx") try {
1207
1241
  const tsconfigPath = path.join(this.baseBuildDir, "tsconfig.json");
1208
- if (!await FileExist(tsconfigPath)) throw new Error(`[build addon]: ts-lang: tsconfig.json is not exist in project root: can't resolve tsconfig for rollup: ${tsconfigPath}`);
1242
+ if (!await FileExist(tsconfigPath)) throw new Error(`[build addon]: tsconfig.json not found: ${tsconfigPath}`);
1209
1243
  const pluginConfig = {
1210
1244
  moduleDir,
1211
1245
  tsconfigPath,
@@ -1262,12 +1296,18 @@ var Build = class {
1262
1296
  return false;
1263
1297
  }
1264
1298
  async createRollupWatcher() {
1265
- if (!this.srcDirs || !this.outdirs || !this.currentConfig || !this.rollupPlugin) throw new Error(`[build addon]: can't first can this method`);
1299
+ if (!this.srcDirs || !this.outdirs || !this.currentConfig || !this.rollupPlugin) throw new Error(`[build addon]: internal error: called before initialization`);
1266
1300
  let output = this.currentConfig.script?.main;
1267
1301
  if (!output) output = "index.js";
1268
1302
  if (path.extname(output) !== "js") output = output.slice(0, output.length - path.extname(output).length) + ".js";
1269
1303
  if (this.buildConfig?.outputFilename) output = this.buildConfig.outputFilename;
1270
1304
  const outputDir = this.buildConfig?.outputDir || "scripts";
1305
+ const outputOptions = {
1306
+ file: join(path.join(this.outdirs.behavior, outputDir), output),
1307
+ format: "esm",
1308
+ sourcemap: false
1309
+ };
1310
+ if (this.currentConfig.minify === "oxc") outputOptions.minify = true;
1271
1311
  const rollupWatcher = watch$2({
1272
1312
  input: path.join(this.srcDirs.behavior, "scripts", this.currentConfig?.script?.main || ""),
1273
1313
  external: [
@@ -1277,11 +1317,7 @@ var Build = class {
1277
1317
  ],
1278
1318
  plugins: this.rollupPlugin,
1279
1319
  experimental: { ...this.cacheManager?.shouldUseIncrementalBuild() ? { incrementalBuild: true } : {} },
1280
- output: {
1281
- file: join(path.join(this.outdirs.behavior, outputDir), output),
1282
- format: "esm",
1283
- sourcemap: false
1284
- },
1320
+ output: outputOptions,
1285
1321
  watch: {
1286
1322
  clearScreen: false,
1287
1323
  include: path.join(this.srcDirs.behavior, "scripts/**/*"),
@@ -1307,7 +1343,7 @@ var Build = class {
1307
1343
  }
1308
1344
  async onChange(filePath) {
1309
1345
  const isBundle = this.currentConfig?.build?.bundle !== false;
1310
- if (!this.srcDirs || !this.outdirs || !this.currentConfig || isBundle && !this.rollupPlugin || !this.watchers) throw new Error(`[build addon]: can't first can this method`);
1346
+ if (!this.srcDirs || !this.outdirs || !this.currentConfig || isBundle && !this.rollupPlugin || !this.watchers) throw new Error(`[build addon]: internal error: called before initialization`);
1311
1347
  const isConfigChange = path.relative(path.join(this.baseBuildDir, BuildConfig.ConfigFile), filePath) === "";
1312
1348
  const isPkgChange = path.relative(path.join(this.baseBuildDir, "package.json"), filePath) === "";
1313
1349
  const isScriptsChange = !isBundle && this.isParent(path.join(this.srcDirs.behavior, "scripts"), filePath);
@@ -1355,7 +1391,7 @@ var Build = class {
1355
1391
  }
1356
1392
  if (isBehaviorChange || isResourcesChange) {
1357
1393
  const handlerBP = async () => {
1358
- if (!this.srcDirs || !this.outdirs) throw new Error(`[build addon]: can't first can this method`);
1394
+ if (!this.srcDirs || !this.outdirs) throw new Error(`[build addon]: internal error: called before initialization`);
1359
1395
  const relativePath = path.relative(this.srcDirs.behavior, filePath);
1360
1396
  await fs$3.cp(path.join(this.srcDirs.behavior, relativePath), path.join(this.outdirs.behavior, relativePath), {
1361
1397
  recursive: true,
@@ -1363,7 +1399,7 @@ var Build = class {
1363
1399
  });
1364
1400
  };
1365
1401
  const handlerRP = async () => {
1366
- if (!this.srcDirs || !this.outdirs) throw new Error(`[build addon]: can't first can this method`);
1402
+ if (!this.srcDirs || !this.outdirs) throw new Error(`[build addon]: internal error: called before initialization`);
1367
1403
  const relativePath = path.relative(this.srcDirs.resources, filePath);
1368
1404
  await fs$3.cp(path.join(this.srcDirs.resources, relativePath), path.join(this.outdirs.resources, relativePath), {
1369
1405
  recursive: true,
@@ -1377,7 +1413,7 @@ var Build = class {
1377
1413
  }
1378
1414
  async createWatcher() {
1379
1415
  const isBundle = this.currentConfig?.build?.bundle !== false;
1380
- if (!this.srcDirs || !this.outdirs || isBundle && !this.rollupPlugin) throw new Error(`[build addon]: can't first can this method`);
1416
+ if (!this.srcDirs || !this.outdirs || isBundle && !this.rollupPlugin) throw new Error(`[build addon]: internal error: called before initialization`);
1381
1417
  const chokidar = watch$1(this.baseBuildDir, {
1382
1418
  ignored: [
1383
1419
  this.outdirs.behavior,
@@ -1404,13 +1440,13 @@ var Build = class {
1404
1440
  };
1405
1441
  }
1406
1442
  async handlerManifest() {
1407
- if (!this.currentConfig || !this.outdirs || !this.srcDirs || !this.module) throw new Error(`[build addon]: can't first can this method`);
1443
+ if (!this.currentConfig || !this.outdirs || !this.srcDirs || !this.module) throw new Error(`[build addon]: internal error: called before initialization`);
1408
1444
  const otherManifestOption = {
1409
1445
  behavior: {},
1410
1446
  resources: {}
1411
1447
  };
1412
1448
  const handlerBP = async () => {
1413
- if (!this.outdirs || !this.currentConfig) throw new Error(`[build addon]: can't first can this method`);
1449
+ if (!this.outdirs || !this.currentConfig) throw new Error(`[build addon]: internal error: called before initialization`);
1414
1450
  const manifest = await generateManifest(this.currentConfig, "data");
1415
1451
  await writeJSON(path.join(this.outdirs.behavior, "manifest.json"), {
1416
1452
  ...manifest,
@@ -1418,7 +1454,7 @@ var Build = class {
1418
1454
  });
1419
1455
  };
1420
1456
  const handlerRP = async () => {
1421
- if (!this.outdirs || !this.currentConfig) throw new Error(`[build addon]: can't first can this method`);
1457
+ if (!this.outdirs || !this.currentConfig) throw new Error(`[build addon]: internal error: called before initialization`);
1422
1458
  const manifest = await generateManifest(this.currentConfig, "resources");
1423
1459
  await writeJSON(path.join(this.outdirs.resources, "manifest.json"), {
1424
1460
  ...manifest,
@@ -1447,7 +1483,7 @@ var Build = class {
1447
1483
  }
1448
1484
  }
1449
1485
  loadData() {
1450
- if (!this.currentConfig || !this.baseBuildDir) throw new Error("[build data]: can't resolve again");
1486
+ if (!this.currentConfig || !this.baseBuildDir) throw new Error("[build data]: already initialized");
1451
1487
  this.srcDirs = {
1452
1488
  behavior: path.join(this.baseBuildDir, BuildConfig.behavior),
1453
1489
  resources: path.join(this.baseBuildDir, BuildConfig.resources)
@@ -1464,10 +1500,10 @@ var Build = class {
1464
1500
  * by inspecting the source directories.
1465
1501
  */
1466
1502
  async handlerOtherAddon() {
1467
- if (!this.srcDirs) throw new Error("[build addon]: can't first can this method");
1468
- if (!await FileExist(this.srcDirs.behavior)) throw new Error("[build addon]: can't resolve behavior");
1503
+ if (!this.srcDirs) throw new Error("[build addon]: internal error: called before initialization");
1504
+ if (!await FileExist(this.srcDirs.behavior)) throw new Error("[build addon]: behavior source directory not found");
1469
1505
  const handlerBP = async () => {
1470
- if (!this.srcDirs || !this.outdirs) throw new Error("[build addon]: can't first can this method");
1506
+ if (!this.srcDirs || !this.outdirs) throw new Error("[build addon]: internal error: called before initialization");
1471
1507
  for (const f of await fs$3.readdir(this.srcDirs.behavior)) {
1472
1508
  const fType = await this.fileType(path.join(this.srcDirs.behavior, f));
1473
1509
  const includeType = BuildConfig.includes.behavior[f] || BuildConfig.includes.public[f];
@@ -1480,7 +1516,7 @@ var Build = class {
1480
1516
  }
1481
1517
  };
1482
1518
  const handlerRP = async () => {
1483
- if (!this.srcDirs || !this.outdirs) throw new Error("[build addon]: can't first can this method");
1519
+ if (!this.srcDirs || !this.outdirs) throw new Error("[build addon]: internal error: called before initialization");
1484
1520
  for (const f of await fs$3.readdir(this.srcDirs.resources)) {
1485
1521
  const fType = await this.fileType(path.join(this.srcDirs.resources, f));
1486
1522
  const includeType = BuildConfig.includes.resources[f] || BuildConfig.includes.public[f];