@mxpicture/build-api 0.2.18 → 0.2.20
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/deps/FixWorkspaceDeps.js +4 -4
- package/dist/npmPublish/NpmPublisher.js +2 -2
- package/dist/pkg/UpdatePackages.d.ts +19 -0
- package/dist/pkg/UpdatePackages.js +148 -0
- package/dist/pkg/index.d.ts +1 -0
- package/dist/pkg/index.js +1 -0
- package/dist/types/types.package.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logInfo, logSuccess } from "../logger/Logger.js";
|
|
1
|
+
import { logError, logInfo, logSuccess } from "../logger/Logger.js";
|
|
2
2
|
import { DepsReplacementMode, } from "../types/types.deps.js";
|
|
3
3
|
import { buildMapEntries, readPackageEntries, writePackageEntries, } from "../workspace/workspace.pkg.js";
|
|
4
4
|
export const runFixDeps = async (p) => instanceFixDeps(p).run();
|
|
@@ -40,7 +40,7 @@ export class IFixWorkspaceDeps {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
catch (err) {
|
|
43
|
-
|
|
43
|
+
logError(`\nError processing ${consumingPkg.content.name}:`, err);
|
|
44
44
|
throw err;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -86,7 +86,7 @@ export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
|
86
86
|
return null;
|
|
87
87
|
const actualVersion = p.versionMap.get(p.pkg);
|
|
88
88
|
if (!actualVersion) {
|
|
89
|
-
|
|
89
|
+
logError(` ERROR: Could not find version for workspace dependency ${p.pkg}`);
|
|
90
90
|
throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);
|
|
91
91
|
}
|
|
92
92
|
return `^${actualVersion}`;
|
|
@@ -109,7 +109,7 @@ export class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
|
109
109
|
const mapEntry = p.mapEntries.find((mapEntry) => mapEntry.fromPkg.content.name === p.consumingPkg.content.name &&
|
|
110
110
|
mapEntry.toPkg.content.name === p.pkg);
|
|
111
111
|
if (!mapEntry) {
|
|
112
|
-
|
|
112
|
+
logError(` ERROR: Could not find version for workspace dependency ${p.pkg}`);
|
|
113
113
|
throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);
|
|
114
114
|
}
|
|
115
115
|
return `file:${mapEntry.relPath}`;
|
|
@@ -16,9 +16,9 @@ export class NpmPublisher {
|
|
|
16
16
|
const results = await Promise.allSettled(packageDirs.map((d) => this.runPackage(d)));
|
|
17
17
|
const failures = results.filter((r) => r.status === "rejected");
|
|
18
18
|
if (failures.length > 0) {
|
|
19
|
-
|
|
19
|
+
logError(`\n❌ ${failures.length} package(s) failed to publish:`);
|
|
20
20
|
failures.forEach((failure) => {
|
|
21
|
-
|
|
21
|
+
logError(failure.reason);
|
|
22
22
|
});
|
|
23
23
|
process.exit(1);
|
|
24
24
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
|
|
2
|
+
import { PackageEntry, UpdatePackagesParams } from "../types/types.package.js";
|
|
3
|
+
export declare const runUpdatePackages: (params: UpdatePackagesParams) => Promise<void>;
|
|
4
|
+
export declare class UpdatePackages {
|
|
5
|
+
protected readonly paths: WorkspacePaths;
|
|
6
|
+
protected readonly pattern: string;
|
|
7
|
+
protected patternWoSlash: string;
|
|
8
|
+
constructor(paths: WorkspacePaths, pattern: string);
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
protected exec(command: string): Promise<string>;
|
|
11
|
+
protected getPackages(): Promise<Set<string>>;
|
|
12
|
+
protected filterPackages(wsPackages: PackageEntry[], results: Set<string>): void;
|
|
13
|
+
protected filterPackage(wsPackage: PackageEntry, results: Set<string>): void;
|
|
14
|
+
protected filterPackageDep(deps: Record<string, string> | undefined, results: Set<string>): void;
|
|
15
|
+
protected updatePackages(packages: Set<string>): Promise<void>;
|
|
16
|
+
protected deduplicate(): Promise<void>;
|
|
17
|
+
protected rmOldVersions(): Promise<void>;
|
|
18
|
+
protected verifyPackages(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
|
|
2
|
+
import { readPackageEntries } from "../workspace/workspace.pkg.js";
|
|
3
|
+
import { logInfo, logSuccess } from "../logger/Logger.js";
|
|
4
|
+
import { execAsync } from "../common/common.fs.js";
|
|
5
|
+
import micromatch from "micromatch";
|
|
6
|
+
export const runUpdatePackages = async (params) => new UpdatePackages(WorkspacePaths.instance(params.repoRoot, params.workspacesName), params.pattern).run();
|
|
7
|
+
export class UpdatePackages {
|
|
8
|
+
paths;
|
|
9
|
+
pattern;
|
|
10
|
+
patternWoSlash;
|
|
11
|
+
constructor(paths, pattern) {
|
|
12
|
+
this.paths = paths;
|
|
13
|
+
this.pattern = pattern;
|
|
14
|
+
this.patternWoSlash = pattern.replaceAll("/", "+");
|
|
15
|
+
}
|
|
16
|
+
async run() {
|
|
17
|
+
logInfo(`🚀 Starting ${this.pattern} packages update process...\n`);
|
|
18
|
+
// Step 1: Find all packages
|
|
19
|
+
const packages = await this.getPackages();
|
|
20
|
+
logInfo(`📦 Found ${this.pattern} packages:`);
|
|
21
|
+
for (const pkg of packages)
|
|
22
|
+
logInfo(` - ${pkg}`);
|
|
23
|
+
if (packages.size === 0)
|
|
24
|
+
return logSuccess(`✅ No ${this.pattern} packages found.`);
|
|
25
|
+
// Step 2: Update packages in all workspaces recursively
|
|
26
|
+
await this.updatePackages(packages);
|
|
27
|
+
// Step 3: Deduplicate dependencies
|
|
28
|
+
await this.deduplicate();
|
|
29
|
+
// Step 4: Remove old versions from node_modules
|
|
30
|
+
await this.rmOldVersions();
|
|
31
|
+
// Step 5: Verify all packages are at the same version
|
|
32
|
+
await this.verifyPackages();
|
|
33
|
+
}
|
|
34
|
+
async exec(command) {
|
|
35
|
+
console.log(`\n▶ ${command}`);
|
|
36
|
+
try {
|
|
37
|
+
return (await execAsync(command, {
|
|
38
|
+
cwd: this.paths.repoRoot,
|
|
39
|
+
encoding: "utf-8",
|
|
40
|
+
})).stdout;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(`Error executing: ${command}`);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async getPackages() {
|
|
48
|
+
const wsPackages = await readPackageEntries(this.paths.repoRoot);
|
|
49
|
+
const packageNames = new Set();
|
|
50
|
+
this.filterPackages(wsPackages, packageNames);
|
|
51
|
+
return packageNames;
|
|
52
|
+
}
|
|
53
|
+
filterPackages(wsPackages, results) {
|
|
54
|
+
for (const wsPackage of wsPackages)
|
|
55
|
+
this.filterPackage(wsPackage, results);
|
|
56
|
+
}
|
|
57
|
+
filterPackage(wsPackage, results) {
|
|
58
|
+
this.filterPackageDep(wsPackage.content.dependencies, results);
|
|
59
|
+
this.filterPackageDep(wsPackage.content.devDependencies, results);
|
|
60
|
+
}
|
|
61
|
+
filterPackageDep(deps, results) {
|
|
62
|
+
if (!deps)
|
|
63
|
+
return;
|
|
64
|
+
for (const depName of Object.keys(deps))
|
|
65
|
+
if (micromatch.isMatch(depName, this.pattern))
|
|
66
|
+
results.add(depName);
|
|
67
|
+
}
|
|
68
|
+
async updatePackages(packages) {
|
|
69
|
+
logInfo("\n📥 Updating packages across all workspaces...");
|
|
70
|
+
const packageList = Array.from(packages).join(" ");
|
|
71
|
+
await this.exec(`pnpm update -r --latest ${packageList}`);
|
|
72
|
+
}
|
|
73
|
+
async deduplicate() {
|
|
74
|
+
logInfo("\n🔧 Deduplicating dependencies...");
|
|
75
|
+
await this.exec("pnpm dedupe");
|
|
76
|
+
}
|
|
77
|
+
async rmOldVersions() {
|
|
78
|
+
logInfo("\n🧹 Checking for old versions...");
|
|
79
|
+
const oldVersions = await this.exec(`find node_modules/.pnpm -type d -name "${this.patternWoSlash}" -depth 1 2>/dev/null || true`);
|
|
80
|
+
const versionDirs = oldVersions.trim().split("\n").filter(Boolean);
|
|
81
|
+
// Group by package name to identify duplicates
|
|
82
|
+
const packageVersions = new Map();
|
|
83
|
+
for (const dir of versionDirs) {
|
|
84
|
+
const match = dir.match(/@mxpicture\+([^@]+)@(.+)/);
|
|
85
|
+
if (!match)
|
|
86
|
+
continue;
|
|
87
|
+
const [, pkgName, version] = match;
|
|
88
|
+
const key = `@mxpicture/${pkgName.replace(/\+/g, "/")}`;
|
|
89
|
+
if (!packageVersions.has(key))
|
|
90
|
+
packageVersions.set(key, []);
|
|
91
|
+
packageVersions.get(key).push(version.split("_")[0]); // Remove peer dep suffixes
|
|
92
|
+
}
|
|
93
|
+
// Check for duplicates
|
|
94
|
+
let hasDuplicates = false;
|
|
95
|
+
for (const [pkg, versions] of packageVersions) {
|
|
96
|
+
const uniqueVersions = [...new Set(versions)];
|
|
97
|
+
if (uniqueVersions.length <= 1)
|
|
98
|
+
continue;
|
|
99
|
+
logInfo(`⚠️ Multiple versions found for ${pkg}:`, uniqueVersions.join(", "));
|
|
100
|
+
hasDuplicates = true;
|
|
101
|
+
}
|
|
102
|
+
if (hasDuplicates) {
|
|
103
|
+
logInfo("\n🔨 Reinstalling to remove duplicate versions...");
|
|
104
|
+
logInfo(" This ensures TypeScript loads the correct types.");
|
|
105
|
+
await this.exec("mv node_modules node_modules_tmp");
|
|
106
|
+
await Promise.all([
|
|
107
|
+
this.exec("rm -rf node_modules_tmp"),
|
|
108
|
+
this.exec("pnpm install"),
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async verifyPackages() {
|
|
113
|
+
logSuccess("\n✅ Verifying package versions...");
|
|
114
|
+
const listOutput = await this.exec(`pnpm list ${this.pattern} --depth=0 -r --json`);
|
|
115
|
+
const workspaces = JSON.parse(listOutput);
|
|
116
|
+
const versionMap = new Map();
|
|
117
|
+
for (const workspace of workspaces) {
|
|
118
|
+
const deps = workspace.dependencies || {};
|
|
119
|
+
for (const [pkg, info] of Object.entries(deps)) {
|
|
120
|
+
if (micromatch.isMatch(pkg, this.pattern)) {
|
|
121
|
+
if (!versionMap.has(pkg))
|
|
122
|
+
versionMap.set(pkg, new Map());
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
+
versionMap.get(pkg).set(workspace.name, info.version);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
let allConsistent = true;
|
|
129
|
+
for (const [pkg, versions] of versionMap) {
|
|
130
|
+
const uniqueVersions = new Set(versions.values());
|
|
131
|
+
if (uniqueVersions.size <= 1) {
|
|
132
|
+
logSuccess(`✅ ${pkg}: ${[...uniqueVersions][0]}`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
logInfo(`❌ Inconsistent versions for ${pkg}:`);
|
|
136
|
+
for (const [workspace, version] of versions)
|
|
137
|
+
logInfo(` - ${workspace}: ${version}`);
|
|
138
|
+
allConsistent = false;
|
|
139
|
+
}
|
|
140
|
+
if (!allConsistent) {
|
|
141
|
+
console.error("\n❌ Version inconsistencies detected! Please review and fix manually.");
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
logInfo(`\n🎉 All ${this.pattern} packages updated successfully!`);
|
|
145
|
+
logInfo("\n💡 Tip: Restart your TypeScript server in VS Code to pick up the new types.");
|
|
146
|
+
logInfo(' - Cmd+Shift+P → "TypeScript: Restart TS Server"');
|
|
147
|
+
}
|
|
148
|
+
}
|
package/dist/pkg/index.d.ts
CHANGED
package/dist/pkg/index.js
CHANGED