@mxpicture/build-api 0.2.4

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.
Files changed (87) hide show
  1. package/dist/barrel/Barrel.d.ts +15 -0
  2. package/dist/barrel/Barrel.js +136 -0
  3. package/dist/barrel/index.d.ts +1 -0
  4. package/dist/barrel/index.js +2 -0
  5. package/dist/cleanup/Cleanup.d.ts +24 -0
  6. package/dist/cleanup/Cleanup.js +83 -0
  7. package/dist/cleanup/index.d.ts +1 -0
  8. package/dist/cleanup/index.js +2 -0
  9. package/dist/deps/FixWorkspaceDeps.d.ts +30 -0
  10. package/dist/deps/FixWorkspaceDeps.js +121 -0
  11. package/dist/deps/index.d.ts +1 -0
  12. package/dist/deps/index.js +2 -0
  13. package/dist/osInfo/index.d.ts +1 -0
  14. package/dist/osInfo/index.js +2 -0
  15. package/dist/osInfo/osInfo.common.d.ts +4 -0
  16. package/dist/osInfo/osInfo.common.js +56 -0
  17. package/dist/pkg/Pkg.d.ts +7 -0
  18. package/dist/pkg/Pkg.js +13 -0
  19. package/dist/pkg/index.d.ts +2 -0
  20. package/dist/pkg/index.js +3 -0
  21. package/dist/pkg/pkg.common.d.ts +5 -0
  22. package/dist/pkg/pkg.common.js +41 -0
  23. package/dist/scripts/fix-workspace-deps.d.ts +2 -0
  24. package/dist/scripts/fix-workspace-deps.js +16 -0
  25. package/dist/types/index.d.ts +7 -0
  26. package/dist/types/index.js +8 -0
  27. package/dist/types/types.barrel.d.ts +11 -0
  28. package/dist/types/types.barrel.js +1 -0
  29. package/dist/types/types.cleanup.d.ts +8 -0
  30. package/dist/types/types.cleanup.js +1 -0
  31. package/dist/types/types.common.d.ts +25 -0
  32. package/dist/types/types.common.js +1 -0
  33. package/dist/types/types.deps.d.ts +8 -0
  34. package/dist/types/types.deps.js +10 -0
  35. package/dist/types/types.os.d.ts +7 -0
  36. package/dist/types/types.os.js +1 -0
  37. package/dist/types/types.package.d.ts +27 -0
  38. package/dist/types/types.package.js +1 -0
  39. package/dist/types/types.vscode.d.ts +36 -0
  40. package/dist/types/types.vscode.js +1 -0
  41. package/dist/types/types.workspace.d.ts +27 -0
  42. package/dist/types/types.workspace.js +6 -0
  43. package/dist/vscode/OSUser.d.ts +9 -0
  44. package/dist/vscode/OSUser.js +62 -0
  45. package/dist/vscode/VSCodeSettings.d.ts +10 -0
  46. package/dist/vscode/VSCodeSettings.js +41 -0
  47. package/dist/vscode/VSCodeWorkspace.d.ts +9 -0
  48. package/dist/vscode/VSCodeWorkspace.js +29 -0
  49. package/dist/vscode/common.vscode.d.ts +21 -0
  50. package/dist/vscode/common.vscode.js +65 -0
  51. package/dist/vscode/config.vscode.d.ts +2 -0
  52. package/dist/vscode/config.vscode.js +4 -0
  53. package/dist/vscode/index.d.ts +5 -0
  54. package/dist/vscode/index.js +6 -0
  55. package/dist/vscode/profiles.vscode.d.ts +5 -0
  56. package/dist/vscode/profiles.vscode.js +29 -0
  57. package/dist/vscode/storage.vscode.d.ts +3 -0
  58. package/dist/vscode/storage.vscode.js +15 -0
  59. package/dist/vscode/types.vscode.d.ts +37 -0
  60. package/dist/vscode/types.vscode.js +6 -0
  61. package/dist/vscode/vscode.config.d.ts +2 -0
  62. package/dist/vscode/vscode.config.js +4 -0
  63. package/dist/vscode/vscode.profiles.d.ts +5 -0
  64. package/dist/vscode/vscode.profiles.js +30 -0
  65. package/dist/vscode/vscode.settings.d.ts +3 -0
  66. package/dist/vscode/vscode.settings.js +26 -0
  67. package/dist/vscode/vscode.storage.d.ts +3 -0
  68. package/dist/vscode/vscode.storage.js +15 -0
  69. package/dist/vscode/vscode.workspace.d.ts +3 -0
  70. package/dist/vscode/vscode.workspace.js +14 -0
  71. package/dist/vscode/workspace.vscode.d.ts +11 -0
  72. package/dist/vscode/workspace.vscode.js +149 -0
  73. package/dist/workspace/IFixWorkspaceDeps.d.ts +22 -0
  74. package/dist/workspace/IFixWorkspaceDeps.js +118 -0
  75. package/dist/workspace/WorkspacePaths.d.ts +7 -0
  76. package/dist/workspace/WorkspacePaths.js +30 -0
  77. package/dist/workspace/fixWorkspaceDeps.d.ts +22 -0
  78. package/dist/workspace/fixWorkspaceDeps.js +118 -0
  79. package/dist/workspace/index.d.ts +2 -0
  80. package/dist/workspace/index.js +3 -0
  81. package/dist/workspace/workspace.common.d.ts +13 -0
  82. package/dist/workspace/workspace.common.js +152 -0
  83. package/dist/zod/index.d.ts +1 -0
  84. package/dist/zod/index.js +2 -0
  85. package/dist/zod/zod.package.d.ts +9 -0
  86. package/dist/zod/zod.package.js +8 -0
  87. package/package.json +45 -0
@@ -0,0 +1,152 @@
1
+ import { readdir, readFile, writeFile } from "fs/promises";
2
+ import { WorkspaceFileType, } from "../types/types.workspace.js";
3
+ import { join, parse, relative, resolve } from "path";
4
+ import { splitVersion, compareVersions, concatVersion, } from "../pkg/pkg.common.js";
5
+ import pkg from "json5";
6
+ export const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
7
+ export const getFileType = (filename) => filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)
8
+ ? WorkspaceFileType.workspace
9
+ : filename === "package.json"
10
+ ? WorkspaceFileType.package
11
+ : WorkspaceFileType.other;
12
+ let __workspaceRoot = null;
13
+ export const findWorkspaceRoot = async (startPath) => {
14
+ if (__workspaceRoot)
15
+ return __workspaceRoot;
16
+ let path = startPath;
17
+ let level = 0;
18
+ const promises = [];
19
+ while (path.length > 0) {
20
+ promises.push((async () => {
21
+ const l = level;
22
+ const entries = await readdir(path, { withFileTypes: true });
23
+ let pkg = null;
24
+ for (const entry of entries) {
25
+ if (!entry.isFile())
26
+ continue;
27
+ const type = getFileType(entry.name);
28
+ if (type === WorkspaceFileType.workspace)
29
+ return {
30
+ filePath: join(path, entry.name),
31
+ dirPath: path,
32
+ filename: entry.name,
33
+ level: l,
34
+ type,
35
+ };
36
+ if (!pkg && type === WorkspaceFileType.package)
37
+ pkg = {
38
+ filePath: join(path, entry.name),
39
+ dirPath: path,
40
+ filename: entry.name,
41
+ level: l,
42
+ type,
43
+ };
44
+ }
45
+ if (!pkg)
46
+ throw new Error("");
47
+ return pkg;
48
+ })());
49
+ level++;
50
+ path = path.replace(/\/?[^\/]+\/?$/, ""); // remove last dir
51
+ }
52
+ const results = (await Promise.allSettled(promises)).filter((r) => r.status === "fulfilled");
53
+ results.sort((a, b) => a.value.level - b.value.level);
54
+ const result = results.find((r) => r.value.type === WorkspaceFileType.workspace)?.value &&
55
+ results.find((r) => r.value.type === WorkspaceFileType.package)?.value;
56
+ if (!result)
57
+ throw new Error("findWorkspaceRoot: no file found");
58
+ __workspaceRoot = result;
59
+ return result;
60
+ };
61
+ export const readWorkspaceYaml = async (repoRoot) => {
62
+ const workspaceFilePath = resolve(repoRoot, "pnpm-workspace.yaml");
63
+ const fileContent = await readFile(workspaceFilePath, "utf8");
64
+ const parsed = parse(fileContent);
65
+ if (!parsed || !parsed.packages || !Array.isArray(parsed.packages))
66
+ throw new Error("No 'packages' field found in pnpm-workspace.yaml");
67
+ const packageColletions = await Promise.all(parsed.packages.map(async (p) => {
68
+ if (!p.endsWith("/*"))
69
+ return [p];
70
+ const base = p.substring(0, p.length - 2);
71
+ const pkgs = await readdir(join(repoRoot, base));
72
+ return pkgs
73
+ .filter((pkg) => !pkg.startsWith("."))
74
+ .map((pkg) => join(base, pkg));
75
+ }));
76
+ const packages = [];
77
+ for (const packageColletion of packageColletions)
78
+ packages.push(...packageColletion);
79
+ return { packages };
80
+ };
81
+ export const readPackageJson = async (dirOrFilepath) => {
82
+ try {
83
+ return readPackageJsonThrow(dirOrFilepath);
84
+ }
85
+ catch {
86
+ return null;
87
+ }
88
+ };
89
+ export const readPackageJsonThrow = async (dirOrFilepath) => {
90
+ const pkgPath = dirOrFilepath.endsWith("/package.json")
91
+ ? dirOrFilepath
92
+ : join(dirOrFilepath, "package.json");
93
+ return pkg.parse(await readFile(pkgPath, "utf8"));
94
+ };
95
+ export const readPackageJsons = async (repoRoot) => {
96
+ try {
97
+ const pnpmWS = await readWorkspaceYaml(repoRoot);
98
+ return Promise.all(pnpmWS.packages.map(async (repoPath) => {
99
+ const jsonPath = join(repoRoot, repoPath, "package.json");
100
+ const content = await readPackageJsonThrow(jsonPath);
101
+ return {
102
+ jsonPath,
103
+ repoPath,
104
+ content,
105
+ modified: false,
106
+ wsName: repoPath.startsWith("packages/")
107
+ ? repoPath.substring(9)
108
+ : repoPath,
109
+ };
110
+ }));
111
+ }
112
+ catch {
113
+ return [];
114
+ }
115
+ };
116
+ export const writePackageJsons = async (entries) => Promise.all(entries.map(async (entry) => {
117
+ if (entry.modified) {
118
+ await writeFile(entry.jsonPath, JSON.stringify(entry.content, null, 2) + "\n", "utf8");
119
+ console.log(` ✅ Updated ${entry.content.name}\n`);
120
+ }
121
+ else {
122
+ console.log(` ⏭️ No workspace dependencies to fix. ${entry.content.name}\n`);
123
+ }
124
+ }));
125
+ // Build a map of package names to their versions
126
+ export const buildMapEntries = (pkgEntries) => {
127
+ const versionEntries = [];
128
+ for (const fromPkg of pkgEntries)
129
+ for (const toPkg of pkgEntries)
130
+ if (fromPkg.content.name !== toPkg.content.name)
131
+ versionEntries.push({
132
+ fromPkg,
133
+ toPkg,
134
+ relPath: relative(fromPkg.repoPath, toPkg.repoPath),
135
+ });
136
+ return versionEntries;
137
+ };
138
+ export const readPackageVersions = async (rootDir) => {
139
+ const versions = {};
140
+ const packageJsons = await readPackageJsons(rootDir);
141
+ for (const packageJson of packageJsons)
142
+ versions[packageJson.repoPath] = packageJson.content.version;
143
+ return versions;
144
+ };
145
+ export const readMinPackageVersion = async (rootDir) => {
146
+ const versions = await readPackageVersions(rootDir);
147
+ const splitVersions = Object.values(versions).map(splitVersion);
148
+ if (splitVersions.length === 0)
149
+ return null;
150
+ splitVersions.sort(compareVersions);
151
+ return concatVersion(splitVersions[0]);
152
+ };
@@ -0,0 +1 @@
1
+ export * from "./zod.package.js";
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not edit manually.
2
+ export * from "./zod.package.js";
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ import { PackageVersion } from "../types/types.package.js";
3
+ export declare const packageVersionShape: Record<keyof PackageVersion, z.ZodType>;
4
+ export declare const packageVersionSchema: z.ZodObject<{
5
+ major: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
6
+ minor: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
7
+ patch: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
8
+ prefix: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
9
+ }, z.core.$strip>;
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ export const packageVersionShape = {
3
+ major: z.number().min(0),
4
+ minor: z.xor([z.number(), z.null()]),
5
+ patch: z.xor([z.number(), z.null()]),
6
+ prefix: z.xor([z.string(), z.null()]),
7
+ };
8
+ export const packageVersionSchema = z.object(packageVersionShape);
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@mxpicture/build-api",
3
+ "version": "0.2.4",
4
+ "description": "Build utilities API",
5
+ "type": "module",
6
+ "author": "MXPicture",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/MXPicture/npm-build-cli.git"
11
+ },
12
+ "exports": {
13
+ "./barrel": "./dist/barrel/index.js",
14
+ "./cleanup": "./dist/cleanup/index.js",
15
+ "./deps": "./dist/deps/index.js",
16
+ "./osInfo": "./dist/osInfo/index.js",
17
+ "./pkg": "./dist/pkg/index.js",
18
+ "./types": "./dist/types/index.js",
19
+ "./vscode": "./dist/vscode/index.js",
20
+ "./workspace": "./dist/workspace/index.js",
21
+ "./zod": "./dist/zod/index.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "engines": {
28
+ "node": ">=22"
29
+ },
30
+ "scripts": {
31
+ "lint": "eslint \"src/**/*.{ts,tsx}\" --ext .ts,.tsx",
32
+ "build": "tsc -b ."
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "devDependencies": {
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "dependencies": {
41
+ "json5": "^2.2.3",
42
+ "yaml": "^2.8.2",
43
+ "zod": "^4.3.6"
44
+ }
45
+ }