agent-package-manager 0.4.1 → 0.4.3

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/index.js CHANGED
@@ -4790,6 +4790,7 @@ async function runSync(input, projectDir) {
4790
4790
  import { existsSync as existsSync6 } from "fs";
4791
4791
  import { mkdir as mkdir5, rm as rm4 } from "fs/promises";
4792
4792
  import { join as join8 } from "path";
4793
+ import semver3 from "semver";
4793
4794
  async function runUpdate(input, projectDir) {
4794
4795
  const config = await readProjectConfig(projectDir);
4795
4796
  const lock = await readLockFile(projectDir);
@@ -4850,11 +4851,6 @@ async function runUpdate(input, projectDir) {
4850
4851
  hasBreakingChanges: hasBreaking
4851
4852
  });
4852
4853
  }
4853
- if (updates.length === 0) {
4854
- log.info("All packages are up to date");
4855
- console.log(JSON.stringify({ updates: [], dryRun: input.dryRun }, null, 2));
4856
- return;
4857
- }
4858
4854
  for (const u of updates) {
4859
4855
  const breaking = u.hasBreakingChanges ? " (BREAKING)" : "";
4860
4856
  log.info(`${u.package}: ${u.fromVersion} \u2192 ${u.toVersion}${breaking}`);
@@ -4863,6 +4859,7 @@ async function runUpdate(input, projectDir) {
4863
4859
  console.log(JSON.stringify({ updates, dryRun: true }, null, 2));
4864
4860
  return;
4865
4861
  }
4862
+ const installedDeps = [];
4866
4863
  for (const u of updates) {
4867
4864
  const pkg = config.packages[u.package];
4868
4865
  const registryName = pkg.registry || "default";
@@ -4877,20 +4874,146 @@ async function runUpdate(input, projectDir) {
4877
4874
  await mkdir5(installDir, { recursive: true });
4878
4875
  await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
4879
4876
  const contentHash = await hashDirectory(installDir);
4877
+ const pkgManifest = await readPackageManifest(installDir);
4878
+ const entrypoint = pkgManifest?.entrypoint ?? DEFAULT_ENTRYPOINT;
4880
4879
  config.packages[u.package].version = u.toVersion;
4881
4880
  lock.packages[u.package] = {
4882
4881
  ...lock.packages[u.package],
4883
4882
  version: u.toVersion,
4884
4883
  tag: `${u.package}/v${u.toVersion}`,
4885
4884
  commit: resolved.commit,
4886
- contentHash
4885
+ contentHash,
4886
+ entrypoint: `${config.install.modulesDir}/${u.package}/${entrypoint}`
4887
4887
  };
4888
4888
  log.success(`Updated ${u.package} to ${u.toVersion}`);
4889
+ if (pkgManifest?.dependencies) {
4890
+ const deps = await installDependencies2(
4891
+ projectDir,
4892
+ config,
4893
+ lock,
4894
+ registry,
4895
+ registryName,
4896
+ repoDir,
4897
+ manifest,
4898
+ pkgManifest.dependencies,
4899
+ /* @__PURE__ */ new Set([u.package])
4900
+ );
4901
+ installedDeps.push(...deps);
4902
+ }
4903
+ }
4904
+ const upToDatePackages = targetPackages.filter(
4905
+ (name) => !updates.some((u) => u.package === name)
4906
+ );
4907
+ for (const name of upToDatePackages) {
4908
+ const pkg = config.packages[name];
4909
+ const registryName = pkg.registry || "default";
4910
+ const registry = config.registries[registryName];
4911
+ if (!registry) continue;
4912
+ const installDir = join8(projectDir, config.install.modulesDir, name);
4913
+ if (!existsSync6(installDir)) continue;
4914
+ const pkgManifest = await readPackageManifest(installDir);
4915
+ if (!pkgManifest?.dependencies) continue;
4916
+ const missingDeps = Object.entries(pkgManifest.dependencies).filter(
4917
+ ([depId, range]) => {
4918
+ const existing = config.packages[depId];
4919
+ if (!existing) return true;
4920
+ const depDir = join8(projectDir, config.install.modulesDir, depId);
4921
+ if (!existsSync6(depDir)) return true;
4922
+ return !semver3.satisfies(existing.version, range);
4923
+ }
4924
+ );
4925
+ if (missingDeps.length === 0) continue;
4926
+ log.info(`${name}@${pkg.version} \u2014 resolving missing dependencies`);
4927
+ const repoDir = await ensureCloned(registry.owner, registry.repo);
4928
+ const manifest = await readManifestFromRepo(repoDir);
4929
+ const deps = await installDependencies2(
4930
+ projectDir,
4931
+ config,
4932
+ lock,
4933
+ registry,
4934
+ registryName,
4935
+ repoDir,
4936
+ manifest,
4937
+ Object.fromEntries(missingDeps),
4938
+ /* @__PURE__ */ new Set([name])
4939
+ );
4940
+ installedDeps.push(...deps);
4941
+ }
4942
+ if (updates.length === 0 && installedDeps.length === 0) {
4943
+ log.info("All packages are up to date");
4944
+ console.log(JSON.stringify({ updates: [], installedDeps: [], dryRun: false }, null, 2));
4945
+ return;
4889
4946
  }
4890
4947
  lock.generatedAt = (/* @__PURE__ */ new Date()).toISOString();
4891
4948
  await writeProjectConfig(projectDir, config);
4892
4949
  await writeLockFile(projectDir, lock);
4893
- console.log(JSON.stringify({ updates, dryRun: false }, null, 2));
4950
+ console.log(JSON.stringify({ updates, installedDeps, dryRun: false }, null, 2));
4951
+ }
4952
+ async function installDependencies2(projectDir, config, lock, registry, registryName, repoDir, manifest, dependencies, resolving) {
4953
+ const installed = [];
4954
+ for (const [depId, range] of Object.entries(dependencies)) {
4955
+ if (resolving.has(depId)) {
4956
+ const chain = [...resolving, depId].join(" \u2192 ");
4957
+ throw new Error(`Circular dependency detected: ${chain}`);
4958
+ }
4959
+ const existing = config.packages[depId];
4960
+ const depDir = join8(projectDir, config.install.modulesDir, depId);
4961
+ if (existing && existsSync6(depDir) && semver3.satisfies(existing.version, range)) {
4962
+ log.debug(`Dependency ${depId}@${existing.version} already satisfies ${range}`);
4963
+ continue;
4964
+ }
4965
+ const resolvedVersion = resolveVersionRange(manifest, depId, range);
4966
+ if (!resolvedVersion) {
4967
+ throw new Error(
4968
+ `No version of "${depId}" satisfies range "${range}". Available: ${Object.keys(manifest.packages[depId]?.versions ?? {}).join(", ") || "(none)"}`
4969
+ );
4970
+ }
4971
+ log.step(`Dependency: ${depId}@${resolvedVersion} (required: ${range})`);
4972
+ resolving.add(depId);
4973
+ const resolved = resolveVersionFromManifest(manifest, depId, resolvedVersion);
4974
+ const installDir = join8(projectDir, config.install.modulesDir, depId);
4975
+ if (existsSync6(installDir)) {
4976
+ await rm4(installDir, { recursive: true, force: true });
4977
+ }
4978
+ await mkdir5(installDir, { recursive: true });
4979
+ await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
4980
+ const contentHash = await hashDirectory(installDir);
4981
+ const pkgManifest = await readPackageManifest(installDir);
4982
+ const entrypoint = pkgManifest?.entrypoint ?? DEFAULT_ENTRYPOINT;
4983
+ config.packages[depId] = {
4984
+ registry: registryName,
4985
+ path: resolved.path,
4986
+ version: resolvedVersion
4987
+ };
4988
+ lock.packages[depId] = {
4989
+ registry: registryName,
4990
+ path: resolved.path,
4991
+ version: resolvedVersion,
4992
+ tag: `${depId}/v${resolvedVersion}`,
4993
+ commit: resolved.commit,
4994
+ contentHash,
4995
+ installedTo: `${config.install.modulesDir}/${depId}`,
4996
+ entrypoint: `${config.install.modulesDir}/${depId}/${entrypoint}`
4997
+ };
4998
+ log.success(`Installed dependency ${depId}@${resolvedVersion}`);
4999
+ installed.push(depId);
5000
+ if (pkgManifest?.dependencies) {
5001
+ const transitive = await installDependencies2(
5002
+ projectDir,
5003
+ config,
5004
+ lock,
5005
+ registry,
5006
+ registryName,
5007
+ repoDir,
5008
+ manifest,
5009
+ pkgManifest.dependencies,
5010
+ resolving
5011
+ );
5012
+ installed.push(...transitive);
5013
+ }
5014
+ resolving.delete(depId);
5015
+ }
5016
+ return installed;
4894
5017
  }
4895
5018
  function parseSemver(v) {
4896
5019
  const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);