@jskit-ai/kernel 0.1.81 → 0.1.83

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.
@@ -3,6 +3,26 @@ import { pathToFileURL } from "node:url";
3
3
  import { normalizeObject } from "../../shared/support/normalize.js";
4
4
  import { fileExists } from "./fileSystem.js";
5
5
 
6
+ function resolveNodeModulesDescriptorCandidatePaths({ appRoot, packageId }) {
7
+ const packageDescriptorPath = path.join(packageId, "package.descriptor.mjs");
8
+ const candidatePaths = [];
9
+ let currentRoot = path.resolve(appRoot);
10
+
11
+ while (true) {
12
+ const nodeModulesRoot =
13
+ path.basename(currentRoot) === "node_modules" ? currentRoot : path.join(currentRoot, "node_modules");
14
+ candidatePaths.push(path.join(nodeModulesRoot, packageDescriptorPath));
15
+
16
+ const parentRoot = path.dirname(currentRoot);
17
+ if (parentRoot === currentRoot) {
18
+ break;
19
+ }
20
+ currentRoot = parentRoot;
21
+ }
22
+
23
+ return candidatePaths;
24
+ }
25
+
6
26
  function resolveDescriptorCandidatePaths({ appRoot, packageId, installedPackageState }) {
7
27
  const normalizedAppRoot = String(appRoot || "").trim();
8
28
  if (!normalizedAppRoot) {
@@ -19,9 +39,10 @@ function resolveDescriptorCandidatePaths({ appRoot, packageId, installedPackageS
19
39
  const packagePathFromSource = String(source.packagePath || "").trim();
20
40
  const jskitRoot = path.join(normalizedAppRoot, "node_modules", "@jskit-ai", "jskit-cli");
21
41
 
22
- const candidatePaths = [
23
- path.resolve(normalizedAppRoot, "node_modules", normalizedPackageId, "package.descriptor.mjs")
24
- ];
42
+ const candidatePaths = resolveNodeModulesDescriptorCandidatePaths({
43
+ appRoot: normalizedAppRoot,
44
+ packageId: normalizedPackageId
45
+ });
25
46
  if (packagePathFromSource) {
26
47
  candidatePaths.push(path.resolve(normalizedAppRoot, packagePathFromSource, "package.descriptor.mjs"));
27
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/kernel",
3
- "version": "0.1.81",
3
+ "version": "0.1.83",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "json-rest-schema": "1.x.x"
@@ -70,6 +70,32 @@ test("resolveDescriptorPathForInstalledPackage resolves descriptor using source.
70
70
  }
71
71
  });
72
72
 
73
+ test("resolveDescriptorPathForInstalledPackage resolves descriptor from ancestor node_modules", async () => {
74
+ const installRoot = await createFixtureRoot("kernel-package-descriptor-hoisted-");
75
+ try {
76
+ const appRoot = path.join(installRoot, "node_modules", "@example", "app");
77
+ const descriptorPath = path.join(
78
+ installRoot,
79
+ "node_modules",
80
+ "@jskit-ai",
81
+ "shell-web",
82
+ "package.descriptor.mjs"
83
+ );
84
+ await mkdir(appRoot, { recursive: true });
85
+ await writeDescriptorFile(descriptorPath, "export default { packageId: \"@jskit-ai/shell-web\" };\n");
86
+
87
+ const resolvedDescriptorPath = await resolveDescriptorPathForInstalledPackage({
88
+ appRoot,
89
+ packageId: "@jskit-ai/shell-web",
90
+ installedPackageState: {},
91
+ required: true
92
+ });
93
+ assert.equal(resolvedDescriptorPath, descriptorPath);
94
+ } finally {
95
+ await rm(installRoot, { recursive: true, force: true });
96
+ }
97
+ });
98
+
73
99
  test("resolveDescriptorPathForInstalledPackage resolves descriptor using jskit-cli descriptorPath fallback", async () => {
74
100
  const appRoot = await createFixtureRoot("kernel-package-descriptor-jskit-root-");
75
101
  try {