@openspecui/core 1.2.0 → 1.6.0

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.
@@ -0,0 +1,63 @@
1
+ //#region src/opsx-display-path.ts
2
+ const VIRTUAL_PROJECT_DIRNAME = "project";
3
+ const WINDOWS_DRIVE_PREFIX = /^[A-Za-z]:\//;
4
+ function normalizeFsPath(path) {
5
+ return path.replace(/\\/g, "/").replace(/\/+$/g, "");
6
+ }
7
+ function isAbsolutePath(path) {
8
+ return path.startsWith("/") || WINDOWS_DRIVE_PREFIX.test(path);
9
+ }
10
+ function stripRelativePrefix(path) {
11
+ return path.replace(/^\.?\//, "");
12
+ }
13
+ function splitSegments(path) {
14
+ return normalizeFsPath(path).split("/").filter(Boolean);
15
+ }
16
+ function toNpmSpecifier(path) {
17
+ const normalized = normalizeFsPath(path);
18
+ const match = /(?:^|\/)node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?(@[^/]+\/[^/]+|[^/]+)(\/.*)?/.exec(normalized);
19
+ const pkgName = match?.[1];
20
+ if (!pkgName) return null;
21
+ return `npm:${pkgName}${match[2] ?? ""}`;
22
+ }
23
+ function toVirtualProjectPath(path) {
24
+ return `${VIRTUAL_PROJECT_DIRNAME}:${stripRelativePrefix(path)}`;
25
+ }
26
+ function isPathInside(root, target) {
27
+ const normalizedRoot = normalizeFsPath(root);
28
+ const normalizedTarget = normalizeFsPath(target);
29
+ const rootLower = normalizedRoot.toLowerCase();
30
+ const targetLower = normalizedTarget.toLowerCase();
31
+ return targetLower === rootLower || targetLower.startsWith(`${rootLower}/`);
32
+ }
33
+ function toRelativeFromRoot(root, target) {
34
+ const rootSegments = splitSegments(root);
35
+ const targetSegments = splitSegments(target);
36
+ let index = 0;
37
+ while (index < rootSegments.length && index < targetSegments.length) {
38
+ if (rootSegments[index]?.toLowerCase() !== targetSegments[index]?.toLowerCase()) break;
39
+ index += 1;
40
+ }
41
+ return targetSegments.slice(index).join("/");
42
+ }
43
+ function findOpspecSlice(path) {
44
+ const segments = splitSegments(path);
45
+ const idx = segments.lastIndexOf("openspec");
46
+ if (idx < 0) return null;
47
+ return segments.slice(idx).join("/");
48
+ }
49
+ function toOpsxDisplayPath(absoluteOrRelativePath, options) {
50
+ const normalized = normalizeFsPath(absoluteOrRelativePath);
51
+ const npmSpecifier = toNpmSpecifier(normalized);
52
+ if (options?.source === "package" || npmSpecifier) {
53
+ if (npmSpecifier) return npmSpecifier;
54
+ }
55
+ if (!isAbsolutePath(normalized)) return toVirtualProjectPath(normalized);
56
+ if (options?.projectDir && isPathInside(options.projectDir, normalized)) return toVirtualProjectPath(toRelativeFromRoot(options.projectDir, normalized));
57
+ const openspecSlice = findOpspecSlice(normalized);
58
+ if (openspecSlice) return toVirtualProjectPath(openspecSlice);
59
+ return toVirtualProjectPath(splitSegments(normalized).slice(-4).join("/"));
60
+ }
61
+
62
+ //#endregion
63
+ export { toOpsxDisplayPath as n, VIRTUAL_PROJECT_DIRNAME as t };
@@ -0,0 +1,8 @@
1
+ //#region src/opsx-display-path.d.ts
2
+ declare const VIRTUAL_PROJECT_DIRNAME = "project";
3
+ declare function toOpsxDisplayPath(absoluteOrRelativePath: string, options?: {
4
+ source?: 'project' | 'user' | 'package';
5
+ projectDir?: string;
6
+ }): string;
7
+ //#endregion
8
+ export { toOpsxDisplayPath as n, VIRTUAL_PROJECT_DIRNAME as t };
@@ -0,0 +1,2 @@
1
+ import { n as toOpsxDisplayPath, t as VIRTUAL_PROJECT_DIRNAME } from "./opsx-display-path-RBULE8_G.mjs";
2
+ export { VIRTUAL_PROJECT_DIRNAME, toOpsxDisplayPath };
@@ -0,0 +1,3 @@
1
+ import { n as toOpsxDisplayPath, t as VIRTUAL_PROJECT_DIRNAME } from "./opsx-display-path-DYIjMsbM.mjs";
2
+
3
+ export { VIRTUAL_PROJECT_DIRNAME, toOpsxDisplayPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openspecui/core",
3
- "version": "1.2.0",
3
+ "version": "1.6.0",
4
4
  "description": "Core OpenSpec adapter and parser",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -9,6 +9,10 @@
9
9
  ".": {
10
10
  "import": "./dist/index.mjs",
11
11
  "types": "./dist/index.d.mts"
12
+ },
13
+ "./opsx-display-path": {
14
+ "import": "./dist/opsx-display-path.mjs",
15
+ "types": "./dist/opsx-display-path.d.mts"
12
16
  }
13
17
  },
14
18
  "files": [
@@ -29,8 +33,8 @@
29
33
  "typescript": "^5.0.0"
30
34
  },
31
35
  "scripts": {
32
- "build": "tsdown src/index.ts --format esm --dts",
33
- "dev": "tsdown src/index.ts --format esm --dts --watch",
36
+ "build": "tsdown src/index.ts src/opsx-display-path.ts --format esm --dts",
37
+ "dev": "tsdown src/index.ts src/opsx-display-path.ts --format esm --dts --watch",
34
38
  "test": "vitest run",
35
39
  "test:watch": "vitest",
36
40
  "typecheck": "tsc --noEmit"