@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/dist/cli.js CHANGED
@@ -3,13 +3,14 @@ import { readFileSync, existsSync, writeFileSync, readdirSync, statSync, rmSync,
3
3
  import { createInterface } from 'readline/promises';
4
4
  import { stdin, stdout } from 'process';
5
5
  import { Command, Option } from 'commander';
6
- import { readFile, mkdtemp, stat, rm, writeFile, readdir, unlink, copyFile, mkdir, access } from 'fs/promises';
6
+ import { readFile, mkdtemp, stat, rm, writeFile, readdir, access, unlink, copyFile, mkdir } from 'fs/promises';
7
7
  import { join, resolve, basename, dirname, relative, parse, extname } from 'path';
8
8
  import { randomBytes, createHash, randomUUID } from 'crypto';
9
9
  import { tmpdir, homedir } from 'os';
10
10
  import * as tar from 'tar';
11
11
  import { createServer } from 'http';
12
- import { spawn, spawnSync } from 'child_process';
12
+ import { execFile, spawn, spawnSync } from 'child_process';
13
+ import { promisify } from 'util';
13
14
  import YAML2 from 'yaml';
14
15
  import ts from 'typescript';
15
16
 
@@ -536,6 +537,7 @@ async function loadAddonManifestFromDirectory(directory) {
536
537
  const manifestText = await readFile(manifestPath, "utf8");
537
538
  const manifest = JSON.parse(manifestText);
538
539
  validateAddonManifest(manifest);
540
+ await assertDisplayAssetPathsExist(directory, manifest);
539
541
  return manifest;
540
542
  }
541
543
  function validateAddonManifest(manifest) {
@@ -554,7 +556,39 @@ function validateAddonManifest(manifest) {
554
556
  if (!Array.isArray(manifest.members)) {
555
557
  throw new Error("addon.json missing members");
556
558
  }
559
+ validateDisplayAssets(manifest);
557
560
  validateInstallRequirements(manifest);
561
+ validateInstallNpm(manifest);
562
+ }
563
+ function validateDisplayAssets(manifest) {
564
+ const image = manifest.display.image;
565
+ if (image !== void 0) {
566
+ if (typeof image !== "string") {
567
+ throw new Error("addon.json display.image must be a string");
568
+ }
569
+ normalizeRelativePath(image, "display.image");
570
+ }
571
+ const screenshots = manifest.display.screenshots;
572
+ if (screenshots !== void 0) {
573
+ if (!Array.isArray(screenshots)) {
574
+ throw new Error("addon.json display.screenshots must be an array");
575
+ }
576
+ screenshots.forEach((item, index) => {
577
+ if (typeof item !== "string") {
578
+ throw new Error(`addon.json display.screenshots[${index}] must be a string`);
579
+ }
580
+ normalizeRelativePath(item, `display.screenshots[${index}]`);
581
+ });
582
+ }
583
+ }
584
+ async function assertDisplayAssetPathsExist(directory, manifest) {
585
+ const paths = [
586
+ ...manifest.display.image ? [manifest.display.image] : [],
587
+ ...manifest.display.screenshots ?? []
588
+ ];
589
+ for (const assetPath of paths) {
590
+ await assertPathExists(directory, normalizeRelativePath(assetPath, "display asset path"));
591
+ }
558
592
  }
559
593
  function validateInstallRequirements(manifest) {
560
594
  const requirements = manifest.install?.requirements;
@@ -595,24 +629,48 @@ function validateRequirementItem(item, kind) {
595
629
  throw new Error(`addon.json install.requirements.${kind}s item defaultValue must be string`);
596
630
  }
597
631
  }
632
+ function validateInstallNpm(manifest) {
633
+ const npm = manifest.install?.npm;
634
+ if (npm === void 0) {
635
+ return;
636
+ }
637
+ if (!npm || typeof npm !== "object" || Array.isArray(npm)) {
638
+ throw new Error("addon.json install.npm must be an object");
639
+ }
640
+ const dependencies = npm.dependencies;
641
+ if (dependencies === void 0) {
642
+ return;
643
+ }
644
+ if (!dependencies || typeof dependencies !== "object" || Array.isArray(dependencies)) {
645
+ throw new Error("addon.json install.npm.dependencies must be an object");
646
+ }
647
+ for (const [name, version] of Object.entries(dependencies)) {
648
+ if (!name.trim()) {
649
+ throw new Error("addon.json install.npm.dependencies contains an empty package name");
650
+ }
651
+ if (typeof version !== "string" || !version.trim()) {
652
+ throw new Error(`addon.json install.npm.dependencies.${name} must be a string`);
653
+ }
654
+ }
655
+ }
598
656
  function resolveMemberSourcePath(member) {
599
657
  const sourcePath = member.source?.path;
600
658
  if (typeof sourcePath === "string" && sourcePath.trim()) {
601
- return normalizeRelativePath(sourcePath);
659
+ return normalizeRelativePath(sourcePath, "member source path");
602
660
  }
603
661
  const fallbackKeys = ["entry", "path", "contentPath"];
604
662
  for (const key of fallbackKeys) {
605
663
  const value = member[key];
606
664
  if (typeof value === "string" && value.trim()) {
607
- return normalizeRelativePath(value);
665
+ return normalizeRelativePath(value, "member source path");
608
666
  }
609
667
  }
610
668
  return null;
611
669
  }
612
- function normalizeRelativePath(value) {
670
+ function normalizeRelativePath(value, fieldName = "path") {
613
671
  const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
614
672
  if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
615
- throw new Error(`Invalid member source path: ${value}`);
673
+ throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
616
674
  }
617
675
  return normalized;
618
676
  }
@@ -679,6 +737,15 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
679
737
  }
680
738
 
681
739
  // src/marketplace/install.ts
740
+ var execFileAsync = promisify(execFile);
741
+ var ADDON_ROUTES_FILE = "src/routes-addon.ts";
742
+ var ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./routes-addon";';
743
+ var LEGACY_ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./amaster/registry/addon-routes.generated";';
744
+ var LEGACY_ADDON_ROUTES_FILE = "src/amaster/registry/addon-routes.generated.ts";
745
+ var ADDON_PAGES_FILE = "src/app-addon.config.ts";
746
+ var ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./app-addon.config";';
747
+ var LEGACY_ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";';
748
+ var LEGACY_ADDON_PAGES_FILE = "src/amaster/registry/addon-pages.generated.ts";
682
749
  var AddonInstallConflictError = class extends Error {
683
750
  constructor(input) {
684
751
  super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
@@ -807,6 +874,18 @@ function resolveInstallRequirements(manifest) {
807
874
  secrets: requirements.secrets?.map((item) => ({ ...item }))
808
875
  };
809
876
  }
877
+ function resolveInstallNpm(manifest) {
878
+ const npm = manifest.install?.npm ?? {};
879
+ return {
880
+ dependencies: npm.dependencies ? { ...npm.dependencies } : void 0
881
+ };
882
+ }
883
+ function listNpmDependencies(npm) {
884
+ return Object.entries(npm.dependencies ?? {}).map(([packageName, version]) => ({
885
+ packageName,
886
+ version
887
+ }));
888
+ }
810
889
  function buildMissingRequirements(requirements) {
811
890
  return {
812
891
  envs: requirements.envs?.filter((item) => item.required !== false).map((item) => ({ ...item })),
@@ -857,6 +936,36 @@ function buildOwnershipMap(metas, excludeAddonName) {
857
936
  }
858
937
  return ownership;
859
938
  }
939
+ async function readPackageJson(targetDir) {
940
+ const packageJsonPath = ensurePathInsideTarget(targetDir, "package.json");
941
+ const parsed = JSON.parse(await readFile(packageJsonPath, "utf8"));
942
+ if (!isPlainObject(parsed)) {
943
+ throw new Error("package.json must contain a JSON object");
944
+ }
945
+ return parsed;
946
+ }
947
+ function readDependencies(packageJson) {
948
+ const value = packageJson.dependencies;
949
+ if (value === void 0) {
950
+ return {};
951
+ }
952
+ if (!isPlainObject(value)) {
953
+ throw new Error("package.json dependencies must be an object");
954
+ }
955
+ const dependencies = {};
956
+ for (const [name, version] of Object.entries(value)) {
957
+ if (typeof version === "string") {
958
+ dependencies[name] = version;
959
+ }
960
+ }
961
+ return dependencies;
962
+ }
963
+ function findPackageDependency(packageJson, packageName) {
964
+ return readDependencies(packageJson)[packageName] ?? null;
965
+ }
966
+ function buildNpmDependencyMap(npm) {
967
+ return new Map(listNpmDependencies(npm).map((item) => [item.packageName, item]));
968
+ }
860
969
  async function collectDirectoryFiles(sourceDir) {
861
970
  const entries = await readdir(sourceDir, { withFileTypes: true });
862
971
  const files = [];
@@ -1052,6 +1161,7 @@ function buildInstalledAddonMeta(options) {
1052
1161
  },
1053
1162
  installParameters: options.installParameters,
1054
1163
  requirements: resolveInstallRequirements(options.manifest),
1164
+ npm: resolveInstallNpm(options.manifest),
1055
1165
  members: options.members,
1056
1166
  files: options.files
1057
1167
  };
@@ -1235,10 +1345,77 @@ async function removeObsoleteFiles(targetDir, previousMeta, nextPaths) {
1235
1345
  }
1236
1346
  return removed;
1237
1347
  }
1348
+ async function applyNpmDependencies(targetDir, npm) {
1349
+ const dependencies = listNpmDependencies(npm);
1350
+ if (!dependencies.length) {
1351
+ return [];
1352
+ }
1353
+ const packageJsonPath = ensurePathInsideTarget(targetDir, "package.json");
1354
+ const packageJson = await readPackageJson(targetDir);
1355
+ let changed = false;
1356
+ for (const dependency of dependencies) {
1357
+ const section = packageJson.dependencies;
1358
+ const nextSection = isPlainObject(section) ? section : {};
1359
+ if (!isPlainObject(section)) {
1360
+ packageJson.dependencies = nextSection;
1361
+ changed = true;
1362
+ }
1363
+ if (nextSection[dependency.packageName] !== dependency.version) {
1364
+ nextSection[dependency.packageName] = dependency.version;
1365
+ changed = true;
1366
+ }
1367
+ }
1368
+ if (!changed) {
1369
+ return [];
1370
+ }
1371
+ await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
1372
+ `);
1373
+ return ["package.json"];
1374
+ }
1375
+ function resolvePackageManagerCommand(targetDir, packageJson) {
1376
+ const packageManager = typeof packageJson.packageManager === "string" ? packageJson.packageManager : "";
1377
+ if (existsSync(join(targetDir, "bun.lockb")) || existsSync(join(targetDir, "bun.lock")) || packageManager.startsWith("bun@")) {
1378
+ return { command: "bun", args: ["install"] };
1379
+ }
1380
+ if (existsSync(join(targetDir, "pnpm-lock.yaml")) || packageManager.startsWith("pnpm@")) {
1381
+ return { command: "pnpm", args: ["install"] };
1382
+ }
1383
+ if (existsSync(join(targetDir, "yarn.lock")) || packageManager.startsWith("yarn@")) {
1384
+ return { command: "yarn", args: ["install"] };
1385
+ }
1386
+ return { command: "npm", args: ["install"] };
1387
+ }
1388
+ async function installPackageDependencies(targetDir) {
1389
+ const packageJson = await readPackageJson(targetDir);
1390
+ const { command, args } = resolvePackageManagerCommand(targetDir, packageJson);
1391
+ try {
1392
+ await execFileAsync(command, args, {
1393
+ cwd: targetDir,
1394
+ maxBuffer: 1024 * 1024 * 10
1395
+ });
1396
+ } catch (error) {
1397
+ const message = error instanceof Error ? error.message : String(error);
1398
+ throw new Error(`Failed to install addon npm dependencies with ${command} ${args.join(" ")}: ${message}`);
1399
+ }
1400
+ }
1238
1401
  async function validateInstallConflicts(targetDir, plan, existingMetas) {
1239
1402
  const ownership = buildOwnershipMap(existingMetas);
1240
1403
  const settingsOwnership = buildSettingsOwnershipMap(existingMetas);
1241
1404
  const conflicts = [];
1405
+ const packageJson = await readPackageJson(targetDir);
1406
+ for (const dependency of listNpmDependencies(resolveInstallNpm(plan.manifest))) {
1407
+ const existing = findPackageDependency(packageJson, dependency.packageName);
1408
+ if (existing && existing !== dependency.version) {
1409
+ conflicts.push({
1410
+ kind: "package_dependency_conflict",
1411
+ path: `package.json#dependencies.${dependency.packageName}`,
1412
+ packageName: dependency.packageName,
1413
+ requestedVersion: dependency.version,
1414
+ existingVersion: existing,
1415
+ message: `${dependency.packageName} is already declared as ${existing} in package.json`
1416
+ });
1417
+ }
1418
+ }
1242
1419
  for (const file of plan.files) {
1243
1420
  const owner = ownership.get(file.targetPath);
1244
1421
  if (owner && owner !== plan.manifest.name) {
@@ -1303,6 +1480,35 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
1303
1480
  const nextSettingKeys = new Set(plannedSettings.map((item) => `${item.targetPath}#${item.path}`));
1304
1481
  const plannedSettingsByKey = new Map(plannedSettings.map((item) => [`${item.targetPath}#${item.path}`, item]));
1305
1482
  const conflicts = [];
1483
+ const packageJson = await readPackageJson(targetDir);
1484
+ const previousNpmByName = buildNpmDependencyMap(previousMeta.npm ?? {});
1485
+ for (const dependency of listNpmDependencies(resolveInstallNpm(plan.manifest))) {
1486
+ const existing = findPackageDependency(packageJson, dependency.packageName);
1487
+ const previous = previousNpmByName.get(dependency.packageName);
1488
+ if (!existing) {
1489
+ if (previous) {
1490
+ conflicts.push({
1491
+ kind: "package_dependency_conflict",
1492
+ path: `package.json#dependencies.${dependency.packageName}`,
1493
+ packageName: dependency.packageName,
1494
+ requestedVersion: dependency.version,
1495
+ message: `managed npm package missing from package.json: ${dependency.packageName}`
1496
+ });
1497
+ }
1498
+ continue;
1499
+ }
1500
+ const canUpdateManagedVersion = previous && existing === previous.version;
1501
+ if (existing !== dependency.version && !canUpdateManagedVersion) {
1502
+ conflicts.push({
1503
+ kind: "package_dependency_conflict",
1504
+ path: `package.json#dependencies.${dependency.packageName}`,
1505
+ packageName: dependency.packageName,
1506
+ requestedVersion: dependency.version,
1507
+ existingVersion: existing,
1508
+ message: `${dependency.packageName} is already declared as ${existing} in package.json`
1509
+ });
1510
+ }
1511
+ }
1306
1512
  for (const managedFile of previousMeta.files) {
1307
1513
  const absolutePath = ensurePathInsideTarget(targetDir, managedFile.path);
1308
1514
  if (!existsSync(absolutePath)) {
@@ -1448,10 +1654,14 @@ async function ensureWebRoutesPatched(targetDir) {
1448
1654
  const routesFile = join(targetDir, "src", "routes.tsx");
1449
1655
  const original = await readFile(routesFile, "utf8");
1450
1656
  let next = original;
1451
- if (!next.includes("./amaster/registry/addon-routes.generated")) {
1657
+ if (next.includes(LEGACY_ADDON_ROUTES_IMPORT)) {
1658
+ next = next.replace(LEGACY_ADDON_ROUTES_IMPORT, ADDON_ROUTES_IMPORT);
1659
+ }
1660
+ if (!next.includes(ADDON_ROUTES_IMPORT)) {
1452
1661
  next = next.replace(
1453
1662
  'import type { ComponentType } from "react";',
1454
- 'import type { ComponentType } from "react";\nimport { addonRoutes } from "./amaster/registry/addon-routes.generated";'
1663
+ `import type { ComponentType } from "react";
1664
+ ${ADDON_ROUTES_IMPORT}`
1455
1665
  );
1456
1666
  }
1457
1667
  if (!next.includes("...addonRoutes")) {
@@ -1475,8 +1685,11 @@ async function ensureMiniAppConfigPatched(targetDir, needsTabBarItems) {
1475
1685
  const configFile = join(targetDir, "src", "app.config.ts");
1476
1686
  const original = await readFile(configFile, "utf8");
1477
1687
  let next = original;
1478
- if (!next.includes("./amaster/registry/addon-pages.generated")) {
1479
- next = `import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";
1688
+ if (next.includes(LEGACY_ADDON_PAGES_IMPORT)) {
1689
+ next = next.replace(LEGACY_ADDON_PAGES_IMPORT, ADDON_PAGES_IMPORT);
1690
+ }
1691
+ if (!next.includes(ADDON_PAGES_IMPORT)) {
1692
+ next = `${ADDON_PAGES_IMPORT}
1480
1693
  ${next}`;
1481
1694
  }
1482
1695
  if (!next.includes("...addonPages")) {
@@ -1501,8 +1714,6 @@ ${next}`;
1501
1714
  }
1502
1715
  }
1503
1716
  async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1504
- const registryDir = join(targetDir, "src", "amaster", "registry");
1505
- await mkdir(registryDir, { recursive: true });
1506
1717
  if (applicationType === "web") {
1507
1718
  const pageMembers2 = metas.flatMap(
1508
1719
  (meta) => meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({ addonName: meta.name, member }))
@@ -1512,32 +1723,38 @@ async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1512
1723
  const entry = member.page.web.entry;
1513
1724
  return {
1514
1725
  identifier,
1515
- importPath: `../../${removeFileExtension(entry).replace(/\\/g, "/")}`,
1726
+ importPath: `./${removeFileExtension(entry).replace(/\\/g, "/")}`,
1516
1727
  route: member.page.web.route,
1517
1728
  visible: member.page.web.visible,
1518
1729
  name: member.name
1519
1730
  };
1520
1731
  });
1521
- const fileContent2 = [
1522
- 'import type { ComponentType } from "react";',
1523
- ...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
1524
- "",
1525
- "type AddonRouteConfig = {",
1526
- " name: string;",
1527
- " path: string;",
1528
- " Component: ComponentType<Record<string, unknown>>;",
1529
- " visible?: boolean;",
1530
- "};",
1531
- "",
1532
- "export const addonRoutes: AddonRouteConfig[] = [",
1533
- ...imports.map(
1534
- (item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
1535
- ),
1536
- "];",
1537
- ""
1538
- ].join("\n");
1539
- await writeFile(join(registryDir, "addon-routes.generated.ts"), fileContent2);
1540
- await ensureWebRoutesPatched(targetDir);
1732
+ const routesFile = join(targetDir, "src", "routes.tsx");
1733
+ const routesContent = existsSync(routesFile) ? await readFile(routesFile, "utf8") : "";
1734
+ const alreadyPatched2 = routesContent.includes(ADDON_ROUTES_IMPORT) || routesContent.includes(LEGACY_ADDON_ROUTES_IMPORT) || routesContent.includes("...addonRoutes");
1735
+ await unlink(join(targetDir, LEGACY_ADDON_ROUTES_FILE)).catch(() => void 0);
1736
+ if (imports.length > 0 || alreadyPatched2) {
1737
+ const fileContent = [
1738
+ 'import type { ComponentType } from "react";',
1739
+ ...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
1740
+ "",
1741
+ "type AddonRouteConfig = {",
1742
+ " name: string;",
1743
+ " path: string;",
1744
+ " Component: ComponentType<Record<string, unknown>>;",
1745
+ " visible?: boolean;",
1746
+ "};",
1747
+ "",
1748
+ "export const addonRoutes: AddonRouteConfig[] = [",
1749
+ ...imports.map(
1750
+ (item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
1751
+ ),
1752
+ "];",
1753
+ ""
1754
+ ].join("\n");
1755
+ await writeFile(join(targetDir, ADDON_ROUTES_FILE), fileContent);
1756
+ await ensureWebRoutesPatched(targetDir);
1757
+ }
1541
1758
  return;
1542
1759
  }
1543
1760
  const pageMembers = metas.flatMap(
@@ -1548,14 +1765,20 @@ async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1548
1765
  pagePath: page.pagePath,
1549
1766
  ...page.tabBar
1550
1767
  }));
1551
- const fileContent = [
1552
- `export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
1553
- "",
1554
- `export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
1555
- ""
1556
- ].join("\n");
1557
- await writeFile(join(registryDir, "addon-pages.generated.ts"), fileContent);
1558
- await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
1768
+ const appConfigFile = join(targetDir, "src", "app.config.ts");
1769
+ const appConfigContent = existsSync(appConfigFile) ? await readFile(appConfigFile, "utf8") : "";
1770
+ const alreadyPatched = appConfigContent.includes(ADDON_PAGES_IMPORT) || appConfigContent.includes(LEGACY_ADDON_PAGES_IMPORT) || appConfigContent.includes("...addonPages") || appConfigContent.includes("...addonTabBarItems");
1771
+ await unlink(join(targetDir, LEGACY_ADDON_PAGES_FILE)).catch(() => void 0);
1772
+ if (addonPages.length > 0 || alreadyPatched) {
1773
+ const fileContent = [
1774
+ `export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
1775
+ "",
1776
+ `export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
1777
+ ""
1778
+ ].join("\n");
1779
+ await writeFile(join(targetDir, ADDON_PAGES_FILE), fileContent);
1780
+ await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
1781
+ }
1559
1782
  }
1560
1783
  async function materializeAddon(options) {
1561
1784
  const targetDir = resolve(options.targetDir);
@@ -1578,6 +1801,8 @@ async function materializeAddon(options) {
1578
1801
  }
1579
1802
  const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
1580
1803
  const restoredSettingsFiles = await restoreObsoleteSettings(targetDir, previousMeta, plan.settings);
1804
+ const npm = resolveInstallNpm(plan.manifest);
1805
+ const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
1581
1806
  await writePlannedFiles(targetDir, plan.files);
1582
1807
  const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
1583
1808
  const installedFiles = [];
@@ -1600,13 +1825,17 @@ async function materializeAddon(options) {
1600
1825
  await writeFile(plan.metaPath, JSON.stringify(meta, null, 2));
1601
1826
  const nextMetas = existingMetas.filter((item) => item.name !== meta.name).concat(meta);
1602
1827
  await rebuildRegistryFiles(targetDir, plan.applicationType, nextMetas.filter((item) => item.applicationType === plan.applicationType));
1828
+ if (options.installPackageDependencies && packageJsonFiles.length) {
1829
+ await installPackageDependencies(targetDir);
1830
+ }
1603
1831
  const requirements = resolveInstallRequirements(plan.manifest);
1604
1832
  return {
1605
1833
  meta,
1606
- writtenFiles: installedFiles.map((file) => file.path).concat(restoredSettingsFiles, settingsResult.writtenFiles),
1834
+ writtenFiles: installedFiles.map((file) => file.path).concat(packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
1607
1835
  removedFiles,
1608
1836
  requirements,
1609
- missingRequirements: buildMissingRequirements(requirements)
1837
+ missingRequirements: buildMissingRequirements(requirements),
1838
+ npm
1610
1839
  };
1611
1840
  }
1612
1841
  async function installAddonFromExtractedDirectory(options) {
@@ -1862,7 +2091,8 @@ async function installAddonFromRegistry(options) {
1862
2091
  extractedDir,
1863
2092
  applicationType: options.applicationType,
1864
2093
  organizationCode: options.organizationCode,
1865
- installParameters: options.installParameters
2094
+ installParameters: options.installParameters,
2095
+ installPackageDependencies: true
1866
2096
  });
1867
2097
  } finally {
1868
2098
  await removeTempDirectory(extractedDir).catch(() => void 0);
@@ -1880,7 +2110,8 @@ async function upgradeAddonFromRegistry(options) {
1880
2110
  extractedDir,
1881
2111
  applicationType: options.applicationType,
1882
2112
  organizationCode: options.organizationCode,
1883
- installParameters: options.installParameters
2113
+ installParameters: options.installParameters,
2114
+ installPackageDependencies: true
1884
2115
  });
1885
2116
  } finally {
1886
2117
  await removeTempDirectory(extractedDir).catch(() => void 0);