@jskit-ai/jskit-cli 0.2.26 → 0.2.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/jskit-cli",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "description": "Bundle and package orchestration CLI for JSKIT apps.",
5
5
  "type": "module",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "test": "node --test"
21
21
  },
22
22
  "dependencies": {
23
- "@jskit-ai/jskit-catalog": "0.1.26"
23
+ "@jskit-ai/jskit-catalog": "0.1.27"
24
24
  },
25
25
  "engines": {
26
26
  "node": "20.x"
@@ -60,6 +60,8 @@ const WORKSPACE_VISIBILITY_LEVELS = Object.freeze(["workspace", "workspace_user"
60
60
  const WORKSPACE_VISIBILITY_SET = new Set(WORKSPACE_VISIBILITY_LEVELS);
61
61
  const MATERIALIZED_PACKAGE_ROOTS = new Map();
62
62
  const MATERIALIZED_PACKAGE_TEMP_DIRECTORIES = new Set();
63
+ const LOCAL_WORKSPACE_PACKAGE_ROOTS = new Map();
64
+ let LOCAL_WORKSPACE_PACKAGE_ID_INDEX = null;
63
65
  const BUILTIN_CAPABILITY_PROVIDERS = Object.freeze({
64
66
  "runtime.actions": Object.freeze(["@jskit-ai/kernel"])
65
67
  });
@@ -3483,11 +3485,110 @@ async function materializePackageRootFromRegistry({ packageEntry, appRoot }) {
3483
3485
  return packageRoot;
3484
3486
  }
3485
3487
 
3488
+ async function resolvePackageRootFromNodeModules({ appRoot, packageId }) {
3489
+ const normalizedAppRoot = path.resolve(String(appRoot || "").trim());
3490
+ const normalizedPackageId = String(packageId || "").trim();
3491
+ if (!normalizedAppRoot || !normalizedPackageId) {
3492
+ return "";
3493
+ }
3494
+
3495
+ const candidateRoot = path.resolve(normalizedAppRoot, "node_modules", ...normalizedPackageId.split("/"));
3496
+ const candidateDescriptorPath = path.join(candidateRoot, "package.descriptor.mjs");
3497
+ if (!(await fileExists(candidateDescriptorPath))) {
3498
+ return "";
3499
+ }
3500
+
3501
+ return candidateRoot;
3502
+ }
3503
+
3504
+ async function loadLocalWorkspacePackageIdIndex() {
3505
+ if (LOCAL_WORKSPACE_PACKAGE_ID_INDEX instanceof Map) {
3506
+ return LOCAL_WORKSPACE_PACKAGE_ID_INDEX;
3507
+ }
3508
+
3509
+ const repoRoot = path.resolve(CLI_PACKAGE_ROOT, "..", "..");
3510
+ const parentDirectories = [
3511
+ path.join(repoRoot, "packages"),
3512
+ path.join(repoRoot, "tooling")
3513
+ ];
3514
+ const packageIdIndex = new Map();
3515
+
3516
+ for (const parentDirectory of parentDirectories) {
3517
+ if (!(await fileExists(parentDirectory))) {
3518
+ continue;
3519
+ }
3520
+
3521
+ const entries = await readdir(parentDirectory, { withFileTypes: true });
3522
+ for (const entry of entries) {
3523
+ if (!entry.isDirectory() || entry.name.startsWith(".")) {
3524
+ continue;
3525
+ }
3526
+
3527
+ const candidateRoot = path.join(parentDirectory, entry.name);
3528
+ const packageJsonPath = path.join(candidateRoot, "package.json");
3529
+ const descriptorPath = path.join(candidateRoot, "package.descriptor.mjs");
3530
+ if (!(await fileExists(packageJsonPath)) || !(await fileExists(descriptorPath))) {
3531
+ continue;
3532
+ }
3533
+
3534
+ let packageJson = {};
3535
+ try {
3536
+ packageJson = await readJsonFile(packageJsonPath);
3537
+ } catch {
3538
+ continue;
3539
+ }
3540
+
3541
+ const packageId = String(packageJson?.name || "").trim();
3542
+ if (!packageId.startsWith("@jskit-ai/")) {
3543
+ continue;
3544
+ }
3545
+ if (packageIdIndex.has(packageId)) {
3546
+ continue;
3547
+ }
3548
+ packageIdIndex.set(packageId, candidateRoot);
3549
+ }
3550
+ }
3551
+
3552
+ LOCAL_WORKSPACE_PACKAGE_ID_INDEX = packageIdIndex;
3553
+ return packageIdIndex;
3554
+ }
3555
+
3556
+ async function resolvePackageRootFromLocalWorkspace({ packageId }) {
3557
+ const normalizedPackageId = String(packageId || "").trim();
3558
+ if (!normalizedPackageId.startsWith("@jskit-ai/")) {
3559
+ return "";
3560
+ }
3561
+ if (LOCAL_WORKSPACE_PACKAGE_ROOTS.has(normalizedPackageId)) {
3562
+ return LOCAL_WORKSPACE_PACKAGE_ROOTS.get(normalizedPackageId);
3563
+ }
3564
+
3565
+ const packageIdIndex = await loadLocalWorkspacePackageIdIndex();
3566
+ const packageRoot = String(packageIdIndex.get(normalizedPackageId) || "").trim();
3567
+ LOCAL_WORKSPACE_PACKAGE_ROOTS.set(normalizedPackageId, packageRoot);
3568
+ return packageRoot;
3569
+ }
3570
+
3486
3571
  async function resolvePackageTemplateRoot({ packageEntry, appRoot }) {
3487
3572
  const packageRoot = String(packageEntry?.rootDir || "").trim();
3488
3573
  if (packageRoot) {
3489
3574
  return packageRoot;
3490
3575
  }
3576
+
3577
+ const installedPackageRoot = await resolvePackageRootFromNodeModules({
3578
+ appRoot,
3579
+ packageId: packageEntry?.packageId
3580
+ });
3581
+ if (installedPackageRoot) {
3582
+ return installedPackageRoot;
3583
+ }
3584
+
3585
+ const localWorkspacePackageRoot = await resolvePackageRootFromLocalWorkspace({
3586
+ packageId: packageEntry?.packageId
3587
+ });
3588
+ if (localWorkspacePackageRoot) {
3589
+ return localWorkspacePackageRoot;
3590
+ }
3591
+
3491
3592
  return await materializePackageRootFromRegistry({ packageEntry, appRoot });
3492
3593
  }
3493
3594
 
@@ -3497,6 +3598,8 @@ async function cleanupMaterializedPackageRoots() {
3497
3598
  }
3498
3599
  MATERIALIZED_PACKAGE_TEMP_DIRECTORIES.clear();
3499
3600
  MATERIALIZED_PACKAGE_ROOTS.clear();
3601
+ LOCAL_WORKSPACE_PACKAGE_ROOTS.clear();
3602
+ LOCAL_WORKSPACE_PACKAGE_ID_INDEX = null;
3500
3603
  }
3501
3604
 
3502
3605
  function interpolateFileMutationRecord(mutation, options, packageId) {