@amaster.ai/cli 1.1.29 → 1.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -54,6 +54,26 @@ amaster addon upgrade crm-pages
54
54
  amaster addon list
55
55
  ```
56
56
 
57
+ Addon 可把市场展示主图和截图放在源码包内,例如:
58
+
59
+ ```text
60
+ marketplace/cover.png
61
+ marketplace/screenshots/preview.png
62
+ ```
63
+
64
+ 并在 `addon.json` 中声明:
65
+
66
+ ```json
67
+ {
68
+ "display": {
69
+ "image": "marketplace/cover.png",
70
+ "screenshots": ["marketplace/screenshots/preview.png"]
71
+ }
72
+ }
73
+ ```
74
+
75
+ 这些文件只用于发布到 Addon Marketplace,不会被 `addon install` 安装到应用工程。
76
+
57
77
  `addon search` 在未显式传 `--application-type` 时,会从当前目录向上查找最近的 `package.json`,读取同级 `app.settings.yml` 的 `type`,并自动按 `web` 或 `mini` 过滤。
58
78
 
59
79
  常用参数:
@@ -88,6 +108,11 @@ Addon 可在 `addon.json` 中声明安装后的运行配置要求:
88
108
  ```json
89
109
  {
90
110
  "install": {
111
+ "npm": {
112
+ "dependencies": {
113
+ "@tanstack/react-query": "^5.66.0"
114
+ }
115
+ },
91
116
  "requirements": {
92
117
  "envs": [
93
118
  {
@@ -109,12 +134,15 @@ Addon 可在 `addon.json` 中声明安装后的运行配置要求:
109
134
  }
110
135
  ```
111
136
 
137
+ `install.npm` 会写入应用根目录 `package.json`。如果目标应用已声明同名包且版本不一致,安装/升级会停止并返回 `package_dependency_conflict`。
138
+ 通过 registry 执行 `addon install` / `addon upgrade` 时,如果 `package.json` 有变更,CLI 会按当前应用自动执行 `bun install`、`pnpm install`、`npm install` 或 `yarn install`。
139
+
112
140
  `install.requirements` 会写入 `meta.json`,并在安装/升级结果中返回 `requirements` 和 `missingRequirements`。`secrets` 只保存键名和说明,不保存密钥值。
113
141
 
114
142
  页面注册方式:
115
143
 
116
- - `web`:生成 `src/amaster/registry/addon-routes.generated.ts`,并 patch `src/routes.tsx`
117
- - `mini`:生成 `src/amaster/registry/addon-pages.generated.ts`,并 patch `src/app.config.ts`
144
+ - `web`:生成 `src/routes-addon.ts`,并 patch `src/routes.tsx`
145
+ - `mini`:生成 `src/app-addon.config.ts`,并 patch `src/app.config.ts`
118
146
 
119
147
  升级策略:
120
148
 
package/dist/cli.cjs CHANGED
@@ -12,6 +12,7 @@ var os = require('os');
12
12
  var tar = require('tar');
13
13
  var http = require('http');
14
14
  var child_process = require('child_process');
15
+ var util = require('util');
15
16
  var YAML2 = require('yaml');
16
17
  var ts = require('typescript');
17
18
 
@@ -563,6 +564,7 @@ async function loadAddonManifestFromDirectory(directory) {
563
564
  const manifestText = await promises$1.readFile(manifestPath, "utf8");
564
565
  const manifest = JSON.parse(manifestText);
565
566
  validateAddonManifest(manifest);
567
+ await assertDisplayAssetPathsExist(directory, manifest);
566
568
  return manifest;
567
569
  }
568
570
  function validateAddonManifest(manifest) {
@@ -581,7 +583,39 @@ function validateAddonManifest(manifest) {
581
583
  if (!Array.isArray(manifest.members)) {
582
584
  throw new Error("addon.json missing members");
583
585
  }
586
+ validateDisplayAssets(manifest);
584
587
  validateInstallRequirements(manifest);
588
+ validateInstallNpm(manifest);
589
+ }
590
+ function validateDisplayAssets(manifest) {
591
+ const image = manifest.display.image;
592
+ if (image !== void 0) {
593
+ if (typeof image !== "string") {
594
+ throw new Error("addon.json display.image must be a string");
595
+ }
596
+ normalizeRelativePath(image, "display.image");
597
+ }
598
+ const screenshots = manifest.display.screenshots;
599
+ if (screenshots !== void 0) {
600
+ if (!Array.isArray(screenshots)) {
601
+ throw new Error("addon.json display.screenshots must be an array");
602
+ }
603
+ screenshots.forEach((item, index) => {
604
+ if (typeof item !== "string") {
605
+ throw new Error(`addon.json display.screenshots[${index}] must be a string`);
606
+ }
607
+ normalizeRelativePath(item, `display.screenshots[${index}]`);
608
+ });
609
+ }
610
+ }
611
+ async function assertDisplayAssetPathsExist(directory, manifest) {
612
+ const paths = [
613
+ ...manifest.display.image ? [manifest.display.image] : [],
614
+ ...manifest.display.screenshots ?? []
615
+ ];
616
+ for (const assetPath of paths) {
617
+ await assertPathExists(directory, normalizeRelativePath(assetPath, "display asset path"));
618
+ }
585
619
  }
586
620
  function validateInstallRequirements(manifest) {
587
621
  const requirements = manifest.install?.requirements;
@@ -622,24 +656,48 @@ function validateRequirementItem(item, kind) {
622
656
  throw new Error(`addon.json install.requirements.${kind}s item defaultValue must be string`);
623
657
  }
624
658
  }
659
+ function validateInstallNpm(manifest) {
660
+ const npm = manifest.install?.npm;
661
+ if (npm === void 0) {
662
+ return;
663
+ }
664
+ if (!npm || typeof npm !== "object" || Array.isArray(npm)) {
665
+ throw new Error("addon.json install.npm must be an object");
666
+ }
667
+ const dependencies = npm.dependencies;
668
+ if (dependencies === void 0) {
669
+ return;
670
+ }
671
+ if (!dependencies || typeof dependencies !== "object" || Array.isArray(dependencies)) {
672
+ throw new Error("addon.json install.npm.dependencies must be an object");
673
+ }
674
+ for (const [name, version] of Object.entries(dependencies)) {
675
+ if (!name.trim()) {
676
+ throw new Error("addon.json install.npm.dependencies contains an empty package name");
677
+ }
678
+ if (typeof version !== "string" || !version.trim()) {
679
+ throw new Error(`addon.json install.npm.dependencies.${name} must be a string`);
680
+ }
681
+ }
682
+ }
625
683
  function resolveMemberSourcePath(member) {
626
684
  const sourcePath = member.source?.path;
627
685
  if (typeof sourcePath === "string" && sourcePath.trim()) {
628
- return normalizeRelativePath(sourcePath);
686
+ return normalizeRelativePath(sourcePath, "member source path");
629
687
  }
630
688
  const fallbackKeys = ["entry", "path", "contentPath"];
631
689
  for (const key of fallbackKeys) {
632
690
  const value = member[key];
633
691
  if (typeof value === "string" && value.trim()) {
634
- return normalizeRelativePath(value);
692
+ return normalizeRelativePath(value, "member source path");
635
693
  }
636
694
  }
637
695
  return null;
638
696
  }
639
- function normalizeRelativePath(value) {
697
+ function normalizeRelativePath(value, fieldName = "path") {
640
698
  const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
641
699
  if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
642
- throw new Error(`Invalid member source path: ${value}`);
700
+ throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
643
701
  }
644
702
  return normalized;
645
703
  }
@@ -706,6 +764,15 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
706
764
  }
707
765
 
708
766
  // src/marketplace/install.ts
767
+ var execFileAsync = util.promisify(child_process.execFile);
768
+ var ADDON_ROUTES_FILE = "src/routes-addon.ts";
769
+ var ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./routes-addon";';
770
+ var LEGACY_ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./amaster/registry/addon-routes.generated";';
771
+ var LEGACY_ADDON_ROUTES_FILE = "src/amaster/registry/addon-routes.generated.ts";
772
+ var ADDON_PAGES_FILE = "src/app-addon.config.ts";
773
+ var ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./app-addon.config";';
774
+ var LEGACY_ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";';
775
+ var LEGACY_ADDON_PAGES_FILE = "src/amaster/registry/addon-pages.generated.ts";
709
776
  var AddonInstallConflictError = class extends Error {
710
777
  constructor(input) {
711
778
  super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
@@ -834,6 +901,18 @@ function resolveInstallRequirements(manifest) {
834
901
  secrets: requirements.secrets?.map((item) => ({ ...item }))
835
902
  };
836
903
  }
904
+ function resolveInstallNpm(manifest) {
905
+ const npm = manifest.install?.npm ?? {};
906
+ return {
907
+ dependencies: npm.dependencies ? { ...npm.dependencies } : void 0
908
+ };
909
+ }
910
+ function listNpmDependencies(npm) {
911
+ return Object.entries(npm.dependencies ?? {}).map(([packageName, version]) => ({
912
+ packageName,
913
+ version
914
+ }));
915
+ }
837
916
  function buildMissingRequirements(requirements) {
838
917
  return {
839
918
  envs: requirements.envs?.filter((item) => item.required !== false).map((item) => ({ ...item })),
@@ -884,6 +963,36 @@ function buildOwnershipMap(metas, excludeAddonName) {
884
963
  }
885
964
  return ownership;
886
965
  }
966
+ async function readPackageJson(targetDir) {
967
+ const packageJsonPath = ensurePathInsideTarget(targetDir, "package.json");
968
+ const parsed = JSON.parse(await promises$1.readFile(packageJsonPath, "utf8"));
969
+ if (!isPlainObject(parsed)) {
970
+ throw new Error("package.json must contain a JSON object");
971
+ }
972
+ return parsed;
973
+ }
974
+ function readDependencies(packageJson) {
975
+ const value = packageJson.dependencies;
976
+ if (value === void 0) {
977
+ return {};
978
+ }
979
+ if (!isPlainObject(value)) {
980
+ throw new Error("package.json dependencies must be an object");
981
+ }
982
+ const dependencies = {};
983
+ for (const [name, version] of Object.entries(value)) {
984
+ if (typeof version === "string") {
985
+ dependencies[name] = version;
986
+ }
987
+ }
988
+ return dependencies;
989
+ }
990
+ function findPackageDependency(packageJson, packageName) {
991
+ return readDependencies(packageJson)[packageName] ?? null;
992
+ }
993
+ function buildNpmDependencyMap(npm) {
994
+ return new Map(listNpmDependencies(npm).map((item) => [item.packageName, item]));
995
+ }
887
996
  async function collectDirectoryFiles(sourceDir) {
888
997
  const entries = await promises$1.readdir(sourceDir, { withFileTypes: true });
889
998
  const files = [];
@@ -1079,6 +1188,7 @@ function buildInstalledAddonMeta(options) {
1079
1188
  },
1080
1189
  installParameters: options.installParameters,
1081
1190
  requirements: resolveInstallRequirements(options.manifest),
1191
+ npm: resolveInstallNpm(options.manifest),
1082
1192
  members: options.members,
1083
1193
  files: options.files
1084
1194
  };
@@ -1262,10 +1372,77 @@ async function removeObsoleteFiles(targetDir, previousMeta, nextPaths) {
1262
1372
  }
1263
1373
  return removed;
1264
1374
  }
1375
+ async function applyNpmDependencies(targetDir, npm) {
1376
+ const dependencies = listNpmDependencies(npm);
1377
+ if (!dependencies.length) {
1378
+ return [];
1379
+ }
1380
+ const packageJsonPath = ensurePathInsideTarget(targetDir, "package.json");
1381
+ const packageJson = await readPackageJson(targetDir);
1382
+ let changed = false;
1383
+ for (const dependency of dependencies) {
1384
+ const section = packageJson.dependencies;
1385
+ const nextSection = isPlainObject(section) ? section : {};
1386
+ if (!isPlainObject(section)) {
1387
+ packageJson.dependencies = nextSection;
1388
+ changed = true;
1389
+ }
1390
+ if (nextSection[dependency.packageName] !== dependency.version) {
1391
+ nextSection[dependency.packageName] = dependency.version;
1392
+ changed = true;
1393
+ }
1394
+ }
1395
+ if (!changed) {
1396
+ return [];
1397
+ }
1398
+ await promises$1.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
1399
+ `);
1400
+ return ["package.json"];
1401
+ }
1402
+ function resolvePackageManagerCommand(targetDir, packageJson) {
1403
+ const packageManager = typeof packageJson.packageManager === "string" ? packageJson.packageManager : "";
1404
+ if (fs.existsSync(path.join(targetDir, "bun.lockb")) || fs.existsSync(path.join(targetDir, "bun.lock")) || packageManager.startsWith("bun@")) {
1405
+ return { command: "bun", args: ["install"] };
1406
+ }
1407
+ if (fs.existsSync(path.join(targetDir, "pnpm-lock.yaml")) || packageManager.startsWith("pnpm@")) {
1408
+ return { command: "pnpm", args: ["install"] };
1409
+ }
1410
+ if (fs.existsSync(path.join(targetDir, "yarn.lock")) || packageManager.startsWith("yarn@")) {
1411
+ return { command: "yarn", args: ["install"] };
1412
+ }
1413
+ return { command: "npm", args: ["install"] };
1414
+ }
1415
+ async function installPackageDependencies(targetDir) {
1416
+ const packageJson = await readPackageJson(targetDir);
1417
+ const { command, args } = resolvePackageManagerCommand(targetDir, packageJson);
1418
+ try {
1419
+ await execFileAsync(command, args, {
1420
+ cwd: targetDir,
1421
+ maxBuffer: 1024 * 1024 * 10
1422
+ });
1423
+ } catch (error) {
1424
+ const message = error instanceof Error ? error.message : String(error);
1425
+ throw new Error(`Failed to install addon npm dependencies with ${command} ${args.join(" ")}: ${message}`);
1426
+ }
1427
+ }
1265
1428
  async function validateInstallConflicts(targetDir, plan, existingMetas) {
1266
1429
  const ownership = buildOwnershipMap(existingMetas);
1267
1430
  const settingsOwnership = buildSettingsOwnershipMap(existingMetas);
1268
1431
  const conflicts = [];
1432
+ const packageJson = await readPackageJson(targetDir);
1433
+ for (const dependency of listNpmDependencies(resolveInstallNpm(plan.manifest))) {
1434
+ const existing = findPackageDependency(packageJson, dependency.packageName);
1435
+ if (existing && existing !== dependency.version) {
1436
+ conflicts.push({
1437
+ kind: "package_dependency_conflict",
1438
+ path: `package.json#dependencies.${dependency.packageName}`,
1439
+ packageName: dependency.packageName,
1440
+ requestedVersion: dependency.version,
1441
+ existingVersion: existing,
1442
+ message: `${dependency.packageName} is already declared as ${existing} in package.json`
1443
+ });
1444
+ }
1445
+ }
1269
1446
  for (const file of plan.files) {
1270
1447
  const owner = ownership.get(file.targetPath);
1271
1448
  if (owner && owner !== plan.manifest.name) {
@@ -1330,6 +1507,35 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
1330
1507
  const nextSettingKeys = new Set(plannedSettings.map((item) => `${item.targetPath}#${item.path}`));
1331
1508
  const plannedSettingsByKey = new Map(plannedSettings.map((item) => [`${item.targetPath}#${item.path}`, item]));
1332
1509
  const conflicts = [];
1510
+ const packageJson = await readPackageJson(targetDir);
1511
+ const previousNpmByName = buildNpmDependencyMap(previousMeta.npm ?? {});
1512
+ for (const dependency of listNpmDependencies(resolveInstallNpm(plan.manifest))) {
1513
+ const existing = findPackageDependency(packageJson, dependency.packageName);
1514
+ const previous = previousNpmByName.get(dependency.packageName);
1515
+ if (!existing) {
1516
+ if (previous) {
1517
+ conflicts.push({
1518
+ kind: "package_dependency_conflict",
1519
+ path: `package.json#dependencies.${dependency.packageName}`,
1520
+ packageName: dependency.packageName,
1521
+ requestedVersion: dependency.version,
1522
+ message: `managed npm package missing from package.json: ${dependency.packageName}`
1523
+ });
1524
+ }
1525
+ continue;
1526
+ }
1527
+ const canUpdateManagedVersion = previous && existing === previous.version;
1528
+ if (existing !== dependency.version && !canUpdateManagedVersion) {
1529
+ conflicts.push({
1530
+ kind: "package_dependency_conflict",
1531
+ path: `package.json#dependencies.${dependency.packageName}`,
1532
+ packageName: dependency.packageName,
1533
+ requestedVersion: dependency.version,
1534
+ existingVersion: existing,
1535
+ message: `${dependency.packageName} is already declared as ${existing} in package.json`
1536
+ });
1537
+ }
1538
+ }
1333
1539
  for (const managedFile of previousMeta.files) {
1334
1540
  const absolutePath = ensurePathInsideTarget(targetDir, managedFile.path);
1335
1541
  if (!fs.existsSync(absolutePath)) {
@@ -1475,10 +1681,14 @@ async function ensureWebRoutesPatched(targetDir) {
1475
1681
  const routesFile = path.join(targetDir, "src", "routes.tsx");
1476
1682
  const original = await promises$1.readFile(routesFile, "utf8");
1477
1683
  let next = original;
1478
- if (!next.includes("./amaster/registry/addon-routes.generated")) {
1684
+ if (next.includes(LEGACY_ADDON_ROUTES_IMPORT)) {
1685
+ next = next.replace(LEGACY_ADDON_ROUTES_IMPORT, ADDON_ROUTES_IMPORT);
1686
+ }
1687
+ if (!next.includes(ADDON_ROUTES_IMPORT)) {
1479
1688
  next = next.replace(
1480
1689
  'import type { ComponentType } from "react";',
1481
- 'import type { ComponentType } from "react";\nimport { addonRoutes } from "./amaster/registry/addon-routes.generated";'
1690
+ `import type { ComponentType } from "react";
1691
+ ${ADDON_ROUTES_IMPORT}`
1482
1692
  );
1483
1693
  }
1484
1694
  if (!next.includes("...addonRoutes")) {
@@ -1502,8 +1712,11 @@ async function ensureMiniAppConfigPatched(targetDir, needsTabBarItems) {
1502
1712
  const configFile = path.join(targetDir, "src", "app.config.ts");
1503
1713
  const original = await promises$1.readFile(configFile, "utf8");
1504
1714
  let next = original;
1505
- if (!next.includes("./amaster/registry/addon-pages.generated")) {
1506
- next = `import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";
1715
+ if (next.includes(LEGACY_ADDON_PAGES_IMPORT)) {
1716
+ next = next.replace(LEGACY_ADDON_PAGES_IMPORT, ADDON_PAGES_IMPORT);
1717
+ }
1718
+ if (!next.includes(ADDON_PAGES_IMPORT)) {
1719
+ next = `${ADDON_PAGES_IMPORT}
1507
1720
  ${next}`;
1508
1721
  }
1509
1722
  if (!next.includes("...addonPages")) {
@@ -1528,8 +1741,6 @@ ${next}`;
1528
1741
  }
1529
1742
  }
1530
1743
  async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1531
- const registryDir = path.join(targetDir, "src", "amaster", "registry");
1532
- await promises$1.mkdir(registryDir, { recursive: true });
1533
1744
  if (applicationType === "web") {
1534
1745
  const pageMembers2 = metas.flatMap(
1535
1746
  (meta) => meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({ addonName: meta.name, member }))
@@ -1539,32 +1750,38 @@ async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1539
1750
  const entry = member.page.web.entry;
1540
1751
  return {
1541
1752
  identifier,
1542
- importPath: `../../${removeFileExtension(entry).replace(/\\/g, "/")}`,
1753
+ importPath: `./${removeFileExtension(entry).replace(/\\/g, "/")}`,
1543
1754
  route: member.page.web.route,
1544
1755
  visible: member.page.web.visible,
1545
1756
  name: member.name
1546
1757
  };
1547
1758
  });
1548
- const fileContent2 = [
1549
- 'import type { ComponentType } from "react";',
1550
- ...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
1551
- "",
1552
- "type AddonRouteConfig = {",
1553
- " name: string;",
1554
- " path: string;",
1555
- " Component: ComponentType<Record<string, unknown>>;",
1556
- " visible?: boolean;",
1557
- "};",
1558
- "",
1559
- "export const addonRoutes: AddonRouteConfig[] = [",
1560
- ...imports.map(
1561
- (item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
1562
- ),
1563
- "];",
1564
- ""
1565
- ].join("\n");
1566
- await promises$1.writeFile(path.join(registryDir, "addon-routes.generated.ts"), fileContent2);
1567
- await ensureWebRoutesPatched(targetDir);
1759
+ const routesFile = path.join(targetDir, "src", "routes.tsx");
1760
+ const routesContent = fs.existsSync(routesFile) ? await promises$1.readFile(routesFile, "utf8") : "";
1761
+ const alreadyPatched2 = routesContent.includes(ADDON_ROUTES_IMPORT) || routesContent.includes(LEGACY_ADDON_ROUTES_IMPORT) || routesContent.includes("...addonRoutes");
1762
+ await promises$1.unlink(path.join(targetDir, LEGACY_ADDON_ROUTES_FILE)).catch(() => void 0);
1763
+ if (imports.length > 0 || alreadyPatched2) {
1764
+ const fileContent = [
1765
+ 'import type { ComponentType } from "react";',
1766
+ ...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
1767
+ "",
1768
+ "type AddonRouteConfig = {",
1769
+ " name: string;",
1770
+ " path: string;",
1771
+ " Component: ComponentType<Record<string, unknown>>;",
1772
+ " visible?: boolean;",
1773
+ "};",
1774
+ "",
1775
+ "export const addonRoutes: AddonRouteConfig[] = [",
1776
+ ...imports.map(
1777
+ (item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
1778
+ ),
1779
+ "];",
1780
+ ""
1781
+ ].join("\n");
1782
+ await promises$1.writeFile(path.join(targetDir, ADDON_ROUTES_FILE), fileContent);
1783
+ await ensureWebRoutesPatched(targetDir);
1784
+ }
1568
1785
  return;
1569
1786
  }
1570
1787
  const pageMembers = metas.flatMap(
@@ -1575,14 +1792,20 @@ async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1575
1792
  pagePath: page.pagePath,
1576
1793
  ...page.tabBar
1577
1794
  }));
1578
- const fileContent = [
1579
- `export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
1580
- "",
1581
- `export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
1582
- ""
1583
- ].join("\n");
1584
- await promises$1.writeFile(path.join(registryDir, "addon-pages.generated.ts"), fileContent);
1585
- await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
1795
+ const appConfigFile = path.join(targetDir, "src", "app.config.ts");
1796
+ const appConfigContent = fs.existsSync(appConfigFile) ? await promises$1.readFile(appConfigFile, "utf8") : "";
1797
+ const alreadyPatched = appConfigContent.includes(ADDON_PAGES_IMPORT) || appConfigContent.includes(LEGACY_ADDON_PAGES_IMPORT) || appConfigContent.includes("...addonPages") || appConfigContent.includes("...addonTabBarItems");
1798
+ await promises$1.unlink(path.join(targetDir, LEGACY_ADDON_PAGES_FILE)).catch(() => void 0);
1799
+ if (addonPages.length > 0 || alreadyPatched) {
1800
+ const fileContent = [
1801
+ `export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
1802
+ "",
1803
+ `export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
1804
+ ""
1805
+ ].join("\n");
1806
+ await promises$1.writeFile(path.join(targetDir, ADDON_PAGES_FILE), fileContent);
1807
+ await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
1808
+ }
1586
1809
  }
1587
1810
  async function materializeAddon(options) {
1588
1811
  const targetDir = path.resolve(options.targetDir);
@@ -1605,6 +1828,8 @@ async function materializeAddon(options) {
1605
1828
  }
1606
1829
  const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
1607
1830
  const restoredSettingsFiles = await restoreObsoleteSettings(targetDir, previousMeta, plan.settings);
1831
+ const npm = resolveInstallNpm(plan.manifest);
1832
+ const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
1608
1833
  await writePlannedFiles(targetDir, plan.files);
1609
1834
  const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
1610
1835
  const installedFiles = [];
@@ -1627,13 +1852,17 @@ async function materializeAddon(options) {
1627
1852
  await promises$1.writeFile(plan.metaPath, JSON.stringify(meta, null, 2));
1628
1853
  const nextMetas = existingMetas.filter((item) => item.name !== meta.name).concat(meta);
1629
1854
  await rebuildRegistryFiles(targetDir, plan.applicationType, nextMetas.filter((item) => item.applicationType === plan.applicationType));
1855
+ if (options.installPackageDependencies && packageJsonFiles.length) {
1856
+ await installPackageDependencies(targetDir);
1857
+ }
1630
1858
  const requirements = resolveInstallRequirements(plan.manifest);
1631
1859
  return {
1632
1860
  meta,
1633
- writtenFiles: installedFiles.map((file) => file.path).concat(restoredSettingsFiles, settingsResult.writtenFiles),
1861
+ writtenFiles: installedFiles.map((file) => file.path).concat(packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
1634
1862
  removedFiles,
1635
1863
  requirements,
1636
- missingRequirements: buildMissingRequirements(requirements)
1864
+ missingRequirements: buildMissingRequirements(requirements),
1865
+ npm
1637
1866
  };
1638
1867
  }
1639
1868
  async function installAddonFromExtractedDirectory(options) {
@@ -1889,7 +2118,8 @@ async function installAddonFromRegistry(options) {
1889
2118
  extractedDir,
1890
2119
  applicationType: options.applicationType,
1891
2120
  organizationCode: options.organizationCode,
1892
- installParameters: options.installParameters
2121
+ installParameters: options.installParameters,
2122
+ installPackageDependencies: true
1893
2123
  });
1894
2124
  } finally {
1895
2125
  await removeTempDirectory(extractedDir).catch(() => void 0);
@@ -1907,7 +2137,8 @@ async function upgradeAddonFromRegistry(options) {
1907
2137
  extractedDir,
1908
2138
  applicationType: options.applicationType,
1909
2139
  organizationCode: options.organizationCode,
1910
- installParameters: options.installParameters
2140
+ installParameters: options.installParameters,
2141
+ installPackageDependencies: true
1911
2142
  });
1912
2143
  } finally {
1913
2144
  await removeTempDirectory(extractedDir).catch(() => void 0);