@mxpicture/build-api 0.2.4 → 0.2.5
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/scripts/fix-workspace-deps.js +15 -9
- package/package.json +1 -1
- package/dist/types/types.common.d.ts +0 -25
- package/dist/types/types.common.js +0 -1
- package/dist/vscode/OSUser.d.ts +0 -9
- package/dist/vscode/OSUser.js +0 -62
- package/dist/vscode/VSCodeSettings.d.ts +0 -10
- package/dist/vscode/VSCodeSettings.js +0 -41
- package/dist/vscode/VSCodeWorkspace.d.ts +0 -9
- package/dist/vscode/VSCodeWorkspace.js +0 -29
- package/dist/vscode/common.vscode.d.ts +0 -21
- package/dist/vscode/common.vscode.js +0 -65
- package/dist/vscode/config.vscode.d.ts +0 -2
- package/dist/vscode/config.vscode.js +0 -4
- package/dist/vscode/profiles.vscode.d.ts +0 -5
- package/dist/vscode/profiles.vscode.js +0 -29
- package/dist/vscode/storage.vscode.d.ts +0 -3
- package/dist/vscode/storage.vscode.js +0 -15
- package/dist/vscode/types.vscode.d.ts +0 -37
- package/dist/vscode/types.vscode.js +0 -6
- package/dist/vscode/workspace.vscode.d.ts +0 -11
- package/dist/vscode/workspace.vscode.js +0 -149
- package/dist/workspace/IFixWorkspaceDeps.d.ts +0 -22
- package/dist/workspace/IFixWorkspaceDeps.js +0 -118
- package/dist/workspace/fixWorkspaceDeps.d.ts +0 -22
- package/dist/workspace/fixWorkspaceDeps.js +0 -118
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
2
|
import { Argument, program } from "@commander-js/extra-typings";
|
|
3
|
-
import { argv
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { argv } from "node:process";
|
|
4
|
+
import { findWorkspaceRoot } from "../workspace/workspace.common.js";
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { runFixDeps } from "../deps/FixWorkspaceDeps.js";
|
|
8
|
+
import { DepsProcessMode, DepsReplacementMode } from "../types/types.deps.js";
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
10
|
program
|
|
8
11
|
.version("1.0.0")
|
|
9
12
|
.description("Fix/restore workspace dependencies CLI")
|
|
10
|
-
.addArgument(new Argument("<mode>", "fix / restore").choices(
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
.addArgument(new Argument("<mode>", "fix / restore").choices(Object.values(DepsProcessMode)))
|
|
14
|
+
.action(async (mode) => {
|
|
15
|
+
const repoRoot = (await findWorkspaceRoot(__dirname)).dirPath;
|
|
16
|
+
await runFixDeps({
|
|
17
|
+
repoRoot,
|
|
18
|
+
mode,
|
|
19
|
+
replacement: DepsReplacementMode.version,
|
|
20
|
+
});
|
|
15
21
|
});
|
|
16
22
|
program.parse(argv);
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type Logger = (...data: any[]) => void;
|
|
2
|
-
export interface PnpmWorkspace {
|
|
3
|
-
packages: string[];
|
|
4
|
-
}
|
|
5
|
-
export interface PackageJson {
|
|
6
|
-
name: string;
|
|
7
|
-
version: string;
|
|
8
|
-
exports?: Record<string, string>;
|
|
9
|
-
dependencies?: Record<string, string>;
|
|
10
|
-
devDependencies?: Record<string, string>;
|
|
11
|
-
peerDependencies?: Record<string, string>;
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
}
|
|
14
|
-
export interface PackageEntry {
|
|
15
|
-
jsonPath: string;
|
|
16
|
-
repoPath: string;
|
|
17
|
-
wsName: string;
|
|
18
|
-
content: PackageJson;
|
|
19
|
-
modified: boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface MapEntry {
|
|
22
|
-
fromPkg: PackageEntry;
|
|
23
|
-
toPkg: PackageEntry;
|
|
24
|
-
relPath: string;
|
|
25
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/vscode/OSUser.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { OSInfo } from "../types/types.os.js";
|
|
2
|
-
export declare class OSUser {
|
|
3
|
-
protected static info?: OSInfo;
|
|
4
|
-
static getInfo(): OSInfo;
|
|
5
|
-
protected constructor();
|
|
6
|
-
protected static load(): void;
|
|
7
|
-
protected static getWSL(): OSInfo;
|
|
8
|
-
protected static getDefault(): OSInfo;
|
|
9
|
-
}
|
package/dist/vscode/OSUser.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import * as os from "os";
|
|
3
|
-
import { join, sep } from "path";
|
|
4
|
-
export class OSUser {
|
|
5
|
-
static info;
|
|
6
|
-
static getInfo() {
|
|
7
|
-
this.load();
|
|
8
|
-
if (!this.info)
|
|
9
|
-
throw new Error("Load OS info failed");
|
|
10
|
-
return this.info;
|
|
11
|
-
}
|
|
12
|
-
constructor() { }
|
|
13
|
-
static load() {
|
|
14
|
-
if (this.info)
|
|
15
|
-
return;
|
|
16
|
-
const isWSL = os.release().toLowerCase().includes("microsoft");
|
|
17
|
-
this.info = isWSL ? this.getWSL() : this.getDefault();
|
|
18
|
-
}
|
|
19
|
-
static getWSL() {
|
|
20
|
-
const whoamiParts = execSync("whoami.exe").toString().split(sep);
|
|
21
|
-
if (whoamiParts.length === 0)
|
|
22
|
-
throw new Error("Windows user could not be determined");
|
|
23
|
-
// const winUser = process.env["WINUSER"] || process.env["USER"];
|
|
24
|
-
const platform = process.platform;
|
|
25
|
-
let username = whoamiParts[whoamiParts.length - 1];
|
|
26
|
-
// remove AD group
|
|
27
|
-
const userParts = username.split("\\");
|
|
28
|
-
username = userParts[userParts.length - 1];
|
|
29
|
-
username = username.replace("\r", "").replace("\n", "");
|
|
30
|
-
const parts = ["/mnt", "c", "Users", username];
|
|
31
|
-
const homedir = join(...parts);
|
|
32
|
-
const configDir = join(homedir, "AppData", "Roaming");
|
|
33
|
-
return {
|
|
34
|
-
username,
|
|
35
|
-
homedir,
|
|
36
|
-
configDir,
|
|
37
|
-
platform,
|
|
38
|
-
isWSL: true,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
static getDefault() {
|
|
42
|
-
const platform = process.platform;
|
|
43
|
-
const homedir = os.homedir();
|
|
44
|
-
const configDirParts = [];
|
|
45
|
-
if (platform === "win32") {
|
|
46
|
-
if (process.env.APPDATA)
|
|
47
|
-
configDirParts.push(process.env.APPDATA);
|
|
48
|
-
}
|
|
49
|
-
else if (platform === "darwin") {
|
|
50
|
-
configDirParts.push(homedir, "Library", "Application Support");
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
configDirParts.push(homedir, ".config");
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
username: os.userInfo().username,
|
|
57
|
-
homedir,
|
|
58
|
-
platform,
|
|
59
|
-
configDir: join(...configDirParts),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { VSCodeSettingsContent } from "../types/types.vscode.js";
|
|
2
|
-
export declare class VSCodeSettings {
|
|
3
|
-
protected static instance: VSCodeSettings | undefined;
|
|
4
|
-
protected content: VSCodeSettingsContent;
|
|
5
|
-
static load(): Promise<VSCodeSettings>;
|
|
6
|
-
protected constructor(content: VSCodeSettingsContent);
|
|
7
|
-
getProperty(name: string): unknown;
|
|
8
|
-
getContent(): VSCodeSettingsContent;
|
|
9
|
-
getClangFormatStyle(): string | undefined;
|
|
10
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import pkg from "json5";
|
|
3
|
-
import { activeProfile, defaultSettingsPath } from "./profiles.vscode.js";
|
|
4
|
-
export class VSCodeSettings {
|
|
5
|
-
static instance;
|
|
6
|
-
content;
|
|
7
|
-
static async load() {
|
|
8
|
-
if (this.instance)
|
|
9
|
-
return this.instance;
|
|
10
|
-
let settingsPath;
|
|
11
|
-
try {
|
|
12
|
-
// check profile
|
|
13
|
-
settingsPath = (await activeProfile()).settingsPath;
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
// check default
|
|
18
|
-
settingsPath = defaultSettingsPath();
|
|
19
|
-
}
|
|
20
|
-
if (!settingsPath)
|
|
21
|
-
throw new Error("No settings path found");
|
|
22
|
-
const raw = fs.readFileSync(settingsPath, "utf-8");
|
|
23
|
-
this.instance = new VSCodeSettings(pkg.parse(raw));
|
|
24
|
-
return this.instance;
|
|
25
|
-
}
|
|
26
|
-
constructor(content) {
|
|
27
|
-
this.content = content;
|
|
28
|
-
}
|
|
29
|
-
getProperty(name) {
|
|
30
|
-
return this.getContent()[name];
|
|
31
|
-
}
|
|
32
|
-
getContent() {
|
|
33
|
-
return { ...this.content };
|
|
34
|
-
}
|
|
35
|
-
getClangFormatStyle() {
|
|
36
|
-
const value = this.getProperty("C_Cpp.clang_format_style");
|
|
37
|
-
if (typeof value !== "string")
|
|
38
|
-
throw new Error("C_Cpp.clang_format_style not found in settings.json");
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { VSCodeWorkspaceContent } from "../types/types.vscode.js";
|
|
2
|
-
export declare class VSCodeWorkspace {
|
|
3
|
-
readonly workspaceFile: string;
|
|
4
|
-
readonly content: VSCodeWorkspaceContent;
|
|
5
|
-
protected static instances: VSCodeWorkspace[];
|
|
6
|
-
static load(workspaceFile?: string): Promise<VSCodeWorkspace>;
|
|
7
|
-
protected constructor(workspaceFile: string, content: VSCodeWorkspaceContent);
|
|
8
|
-
get root(): string;
|
|
9
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { dirname } from "path";
|
|
2
|
-
import pkg from "json5";
|
|
3
|
-
import { readFile } from "fs/promises";
|
|
4
|
-
import { findWorkspaceRoot } from "../workspace/workspace.common.js";
|
|
5
|
-
export class VSCodeWorkspace {
|
|
6
|
-
workspaceFile;
|
|
7
|
-
content;
|
|
8
|
-
static instances = [];
|
|
9
|
-
static async load(workspaceFile) {
|
|
10
|
-
if (!workspaceFile) {
|
|
11
|
-
const foundWorkspaceFile = await findWorkspaceRoot();
|
|
12
|
-
workspaceFile = foundWorkspaceFile.filePath;
|
|
13
|
-
}
|
|
14
|
-
let found = this.instances.find((inst) => inst.workspaceFile === workspaceFile);
|
|
15
|
-
if (!found) {
|
|
16
|
-
const workspaceContent = await readFile(workspaceFile, "utf-8");
|
|
17
|
-
found = new VSCodeWorkspace(workspaceFile, pkg.parse(workspaceContent));
|
|
18
|
-
this.instances.push(found);
|
|
19
|
-
}
|
|
20
|
-
return found;
|
|
21
|
-
}
|
|
22
|
-
constructor(workspaceFile, content) {
|
|
23
|
-
this.workspaceFile = workspaceFile;
|
|
24
|
-
this.content = content;
|
|
25
|
-
}
|
|
26
|
-
get root() {
|
|
27
|
-
return dirname(this.workspaceFile);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { WorkspaceFileType } from "./types.vscode.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
export declare const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
4
|
-
export declare const removeLastPathElement: (path: string) => string | undefined;
|
|
5
|
-
export declare const getFileType: (filename: string) => WorkspaceFileType;
|
|
6
|
-
export interface PackageVersion {
|
|
7
|
-
major: number;
|
|
8
|
-
minor: number | null;
|
|
9
|
-
patch: number | null;
|
|
10
|
-
prefix: string | null;
|
|
11
|
-
}
|
|
12
|
-
export declare const packageVersionSchema: z.ZodObject<{
|
|
13
|
-
major: z.ZodNumber;
|
|
14
|
-
minor: z.ZodXor<readonly [z.ZodNumber, z.ZodNull]>;
|
|
15
|
-
patch: z.ZodXor<readonly [z.ZodNumber, z.ZodNull]>;
|
|
16
|
-
prefix: z.ZodXor<readonly [z.ZodString, z.ZodNull]>;
|
|
17
|
-
}, z.core.$strip>;
|
|
18
|
-
export declare const splitVersion: (version: string) => PackageVersion;
|
|
19
|
-
export declare const concatVersion: (version: PackageVersion) => string;
|
|
20
|
-
export declare const compareVersions: (a: PackageVersion | string, b: PackageVersion | string) => number;
|
|
21
|
-
export declare const compareVersionsGT: (a: PackageVersion | string, b: PackageVersion | string) => boolean;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { join, sep } from "path";
|
|
2
|
-
import { WorkspaceFileType } from "./types.vscode.js";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
export const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
5
|
-
export const removeLastPathElement = (path) => {
|
|
6
|
-
const parts = path.split(sep);
|
|
7
|
-
parts.pop();
|
|
8
|
-
if (parts.length <= 1)
|
|
9
|
-
return;
|
|
10
|
-
if (parts[0] === "")
|
|
11
|
-
parts[0] = "/";
|
|
12
|
-
return join(...parts);
|
|
13
|
-
};
|
|
14
|
-
export const getFileType = (filename) => filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)
|
|
15
|
-
? WorkspaceFileType.workspace
|
|
16
|
-
: filename === "package.json"
|
|
17
|
-
? WorkspaceFileType.package
|
|
18
|
-
: WorkspaceFileType.other;
|
|
19
|
-
export const packageVersionSchema = z.object({
|
|
20
|
-
major: z.number().min(0),
|
|
21
|
-
minor: z.xor([z.number(), z.null()]),
|
|
22
|
-
patch: z.xor([z.number(), z.null()]),
|
|
23
|
-
prefix: z.xor([z.string(), z.null()]),
|
|
24
|
-
});
|
|
25
|
-
export const splitVersion = (version) => {
|
|
26
|
-
const parts = version.split(".");
|
|
27
|
-
let major = parts.shift();
|
|
28
|
-
const prefix = major.startsWith("v") ? "v" : null;
|
|
29
|
-
if (major.startsWith("v"))
|
|
30
|
-
major = major.substring(1);
|
|
31
|
-
const minor = parts.shift();
|
|
32
|
-
const patch = parts.shift();
|
|
33
|
-
return {
|
|
34
|
-
major: Number(major),
|
|
35
|
-
minor: minor ? Number(minor) : null,
|
|
36
|
-
patch: patch ? Number(patch) : null,
|
|
37
|
-
prefix,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
export const concatVersion = (version) => {
|
|
41
|
-
let result = version.major.toString();
|
|
42
|
-
if (version.prefix)
|
|
43
|
-
result = version.prefix + result;
|
|
44
|
-
if (version.minor)
|
|
45
|
-
result += "." + version.minor.toString();
|
|
46
|
-
if (version.patch)
|
|
47
|
-
result += "." + version.patch.toString();
|
|
48
|
-
return result;
|
|
49
|
-
};
|
|
50
|
-
export const compareVersions = (a, b) => {
|
|
51
|
-
a = typeof a === "string" ? splitVersion(a) : a;
|
|
52
|
-
b = typeof b === "string" ? splitVersion(b) : b;
|
|
53
|
-
if (a.major !== b.major)
|
|
54
|
-
return a.major - b.major;
|
|
55
|
-
if (a.minor === null || b.minor === null)
|
|
56
|
-
return 0;
|
|
57
|
-
if (a.minor !== b.minor)
|
|
58
|
-
return a.minor - b.minor;
|
|
59
|
-
if (a.patch === null || b.patch === null)
|
|
60
|
-
return 0;
|
|
61
|
-
if (a.patch !== b.patch)
|
|
62
|
-
return a.patch - b.patch;
|
|
63
|
-
return 0;
|
|
64
|
-
};
|
|
65
|
-
export const compareVersionsGT = (a, b) => compareVersions(a, b) > 0;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { VSCodeProfile } from "../types/types.vscode.js";
|
|
2
|
-
export declare const profiles: () => VSCodeProfile[];
|
|
3
|
-
export declare const activeProfile: () => Promise<VSCodeProfile>;
|
|
4
|
-
export declare const profileSettingsPath: (profile: string) => string;
|
|
5
|
-
export declare const defaultSettingsPath: () => string;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { join } from "path";
|
|
2
|
-
import { storage } from "./storage.vscode.js";
|
|
3
|
-
import { configUserPath } from "./config.vscode.js";
|
|
4
|
-
import { findWorkspaceRoot } from "./workspace.vscode.js";
|
|
5
|
-
export const profiles = () => storage().userDataProfiles.map((prof) => ({
|
|
6
|
-
name: prof.name,
|
|
7
|
-
location: prof.location,
|
|
8
|
-
settingsPath: profileSettingsPath(prof.location),
|
|
9
|
-
}));
|
|
10
|
-
export const activeProfile = async () => {
|
|
11
|
-
const foundWS = await findWorkspaceRoot();
|
|
12
|
-
const storageContent = storage();
|
|
13
|
-
const profs = profiles();
|
|
14
|
-
let foundProfile;
|
|
15
|
-
// eslint-disable-next-line prefer-const
|
|
16
|
-
for (let [path, profile] of Object.entries(storageContent.profileAssociations.workspaces)) {
|
|
17
|
-
path = path.replace("file://", "");
|
|
18
|
-
if (foundWS.filePath !== path)
|
|
19
|
-
continue;
|
|
20
|
-
foundProfile = profs.find((prof) => prof.location === profile);
|
|
21
|
-
if (foundProfile)
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (!foundProfile)
|
|
25
|
-
throw new Error("No active profile found");
|
|
26
|
-
return foundProfile;
|
|
27
|
-
};
|
|
28
|
-
export const profileSettingsPath = (profile) => join(configUserPath(), "profiles", profile, "settings.json");
|
|
29
|
-
export const defaultSettingsPath = () => join(configUserPath(), "settings.json");
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import pkg from "json5";
|
|
4
|
-
import { configUserPath } from "./config.vscode.js";
|
|
5
|
-
export const storagePath = () => join(configUserPath(), "globalStorage", "storage.json");
|
|
6
|
-
let __storage;
|
|
7
|
-
export const storage = () => {
|
|
8
|
-
if (__storage)
|
|
9
|
-
return __storage;
|
|
10
|
-
const content = fs.readFileSync(storagePath()).toString();
|
|
11
|
-
__storage = pkg.parse(content);
|
|
12
|
-
if (!__storage)
|
|
13
|
-
throw new Error("VS Code storage.json could not be loaded");
|
|
14
|
-
return __storage;
|
|
15
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export interface VSCodeProfile {
|
|
2
|
-
location: string;
|
|
3
|
-
name: string;
|
|
4
|
-
settingsPath: string;
|
|
5
|
-
}
|
|
6
|
-
export interface VSCodeStorage {
|
|
7
|
-
userDataProfiles: {
|
|
8
|
-
location: string;
|
|
9
|
-
name: string;
|
|
10
|
-
icon: string;
|
|
11
|
-
useDefaultFlags?: {
|
|
12
|
-
settings?: boolean;
|
|
13
|
-
keybindings?: boolean;
|
|
14
|
-
snippets?: boolean;
|
|
15
|
-
tasks?: boolean;
|
|
16
|
-
extensions?: boolean;
|
|
17
|
-
};
|
|
18
|
-
}[];
|
|
19
|
-
profileAssociations: {
|
|
20
|
-
workspaces: {
|
|
21
|
-
[key: string]: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export declare enum WorkspaceFileType {
|
|
26
|
-
package = "package",
|
|
27
|
-
workspace = "workspace",
|
|
28
|
-
other = "other"
|
|
29
|
-
}
|
|
30
|
-
export interface WorkspaceFile {
|
|
31
|
-
filePath: string;
|
|
32
|
-
dirPath: string;
|
|
33
|
-
filename: string;
|
|
34
|
-
level: number;
|
|
35
|
-
type: WorkspaceFileType;
|
|
36
|
-
}
|
|
37
|
-
export type ProcessMode = "fix" | "restore";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { WorkspaceFile } from "./types.vscode.js";
|
|
2
|
-
import { MapEntry, PackageEntry, PackageJson, PnpmWorkspace } from "../types/types.common.js";
|
|
3
|
-
export declare const findWorkspaceRoot: (startPath?: string) => Promise<WorkspaceFile>;
|
|
4
|
-
export declare const readWorkspaceYaml: (repoRoot: string) => Promise<PnpmWorkspace>;
|
|
5
|
-
export declare const readPackageJson: (dirOrFilepath: string) => Promise<PackageJson | null>;
|
|
6
|
-
export declare const readPackageJsonThrow: (dirOrFilepath: string) => Promise<PackageJson>;
|
|
7
|
-
export declare const readPackageJsons: (repoRoot: string) => Promise<PackageEntry[]>;
|
|
8
|
-
export declare const writePackageJsons: (entries: PackageEntry[]) => Promise<void[]>;
|
|
9
|
-
export declare const buildMapEntries: (pkgEntries: PackageEntry[]) => MapEntry[];
|
|
10
|
-
export declare const readPackageVersions: (rootDir: string) => Promise<Record<string, string>>;
|
|
11
|
-
export declare const readMinPackageVersion: (rootDir: string) => Promise<string | null>;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { dirname, join, relative, resolve } from "path";
|
|
2
|
-
import { parse } from "yaml";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import pkg from "json5";
|
|
5
|
-
import { WorkspaceFileType } from "./types.vscode.js";
|
|
6
|
-
import { compareVersions, concatVersion, getFileType, splitVersion, } from "./common.vscode.js";
|
|
7
|
-
import { readdir, readFile, writeFile } from "fs/promises";
|
|
8
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
let __workspaceRoot = null;
|
|
10
|
-
export const findWorkspaceRoot = async (startPath) => {
|
|
11
|
-
if (__workspaceRoot)
|
|
12
|
-
return __workspaceRoot;
|
|
13
|
-
let path = startPath ?? __dirname;
|
|
14
|
-
let level = 0;
|
|
15
|
-
const promises = [];
|
|
16
|
-
while (path.length > 0) {
|
|
17
|
-
promises.push((async () => {
|
|
18
|
-
const l = level;
|
|
19
|
-
const entries = await readdir(path, { withFileTypes: true });
|
|
20
|
-
let pkg = null;
|
|
21
|
-
for (const entry of entries) {
|
|
22
|
-
if (!entry.isFile())
|
|
23
|
-
continue;
|
|
24
|
-
const type = getFileType(entry.name);
|
|
25
|
-
if (type === WorkspaceFileType.workspace)
|
|
26
|
-
return {
|
|
27
|
-
filePath: join(path, entry.name),
|
|
28
|
-
dirPath: path,
|
|
29
|
-
filename: entry.name,
|
|
30
|
-
level: l,
|
|
31
|
-
type,
|
|
32
|
-
};
|
|
33
|
-
if (!pkg && type === WorkspaceFileType.package)
|
|
34
|
-
pkg = {
|
|
35
|
-
filePath: join(path, entry.name),
|
|
36
|
-
dirPath: path,
|
|
37
|
-
filename: entry.name,
|
|
38
|
-
level: l,
|
|
39
|
-
type,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (!pkg)
|
|
43
|
-
throw new Error("");
|
|
44
|
-
return pkg;
|
|
45
|
-
})());
|
|
46
|
-
level++;
|
|
47
|
-
path = path.replace(/\/?[^\/]+\/?$/, ""); // remove last dir
|
|
48
|
-
}
|
|
49
|
-
const results = (await Promise.allSettled(promises)).filter((r) => r.status === "fulfilled");
|
|
50
|
-
results.sort((a, b) => a.value.level - b.value.level);
|
|
51
|
-
const result = results.find((r) => r.value.type === WorkspaceFileType.workspace)?.value &&
|
|
52
|
-
results.find((r) => r.value.type === WorkspaceFileType.package)?.value;
|
|
53
|
-
if (!result)
|
|
54
|
-
throw new Error("findWorkspaceRoot: no file found");
|
|
55
|
-
__workspaceRoot = result;
|
|
56
|
-
return result;
|
|
57
|
-
};
|
|
58
|
-
export const readWorkspaceYaml = async (repoRoot) => {
|
|
59
|
-
const workspaceFilePath = resolve(repoRoot, "pnpm-workspace.yaml");
|
|
60
|
-
const fileContent = await readFile(workspaceFilePath, "utf8");
|
|
61
|
-
const parsed = parse(fileContent);
|
|
62
|
-
if (!parsed || !parsed.packages || !Array.isArray(parsed.packages))
|
|
63
|
-
throw new Error("No 'packages' field found in pnpm-workspace.yaml");
|
|
64
|
-
const packageColletions = await Promise.all(parsed.packages.map(async (p) => {
|
|
65
|
-
if (!p.endsWith("/*"))
|
|
66
|
-
return [p];
|
|
67
|
-
const base = p.substring(0, p.length - 2);
|
|
68
|
-
const pkgs = await readdir(join(repoRoot, base));
|
|
69
|
-
return pkgs
|
|
70
|
-
.filter((pkg) => !pkg.startsWith("."))
|
|
71
|
-
.map((pkg) => join(base, pkg));
|
|
72
|
-
}));
|
|
73
|
-
const packages = [];
|
|
74
|
-
for (const packageColletion of packageColletions)
|
|
75
|
-
packages.push(...packageColletion);
|
|
76
|
-
return { packages };
|
|
77
|
-
};
|
|
78
|
-
export const readPackageJson = async (dirOrFilepath) => {
|
|
79
|
-
try {
|
|
80
|
-
return readPackageJsonThrow(dirOrFilepath);
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
export const readPackageJsonThrow = async (dirOrFilepath) => {
|
|
87
|
-
const pkgPath = dirOrFilepath.endsWith("/package.json")
|
|
88
|
-
? dirOrFilepath
|
|
89
|
-
: join(dirOrFilepath, "package.json");
|
|
90
|
-
return pkg.parse(await readFile(pkgPath, "utf8"));
|
|
91
|
-
};
|
|
92
|
-
export const readPackageJsons = async (repoRoot) => {
|
|
93
|
-
try {
|
|
94
|
-
const pnpmWS = await readWorkspaceYaml(repoRoot);
|
|
95
|
-
return Promise.all(pnpmWS.packages.map(async (repoPath) => {
|
|
96
|
-
const jsonPath = join(repoRoot, repoPath, "package.json");
|
|
97
|
-
const content = await readPackageJsonThrow(jsonPath);
|
|
98
|
-
return {
|
|
99
|
-
jsonPath,
|
|
100
|
-
repoPath,
|
|
101
|
-
content,
|
|
102
|
-
modified: false,
|
|
103
|
-
wsName: repoPath.startsWith("packages/")
|
|
104
|
-
? repoPath.substring(9)
|
|
105
|
-
: repoPath,
|
|
106
|
-
};
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
return [];
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
export const writePackageJsons = async (entries) => Promise.all(entries.map(async (entry) => {
|
|
114
|
-
if (entry.modified) {
|
|
115
|
-
await writeFile(entry.jsonPath, JSON.stringify(entry.content, null, 2) + "\n", "utf8");
|
|
116
|
-
console.log(` ✅ Updated ${entry.content.name}\n`);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
console.log(` ⏭️ No workspace dependencies to fix. ${entry.content.name}\n`);
|
|
120
|
-
}
|
|
121
|
-
}));
|
|
122
|
-
// Build a map of package names to their versions
|
|
123
|
-
export const buildMapEntries = (pkgEntries) => {
|
|
124
|
-
const versionEntries = [];
|
|
125
|
-
for (const fromPkg of pkgEntries)
|
|
126
|
-
for (const toPkg of pkgEntries)
|
|
127
|
-
if (fromPkg.content.name !== toPkg.content.name)
|
|
128
|
-
versionEntries.push({
|
|
129
|
-
fromPkg,
|
|
130
|
-
toPkg,
|
|
131
|
-
relPath: relative(fromPkg.repoPath, toPkg.repoPath),
|
|
132
|
-
});
|
|
133
|
-
return versionEntries;
|
|
134
|
-
};
|
|
135
|
-
export const readPackageVersions = async (rootDir) => {
|
|
136
|
-
const versions = {};
|
|
137
|
-
const packageJsons = await readPackageJsons(rootDir);
|
|
138
|
-
for (const packageJson of packageJsons)
|
|
139
|
-
versions[packageJson.repoPath] = packageJson.content.version;
|
|
140
|
-
return versions;
|
|
141
|
-
};
|
|
142
|
-
export const readMinPackageVersion = async (rootDir) => {
|
|
143
|
-
const versions = await readPackageVersions(rootDir);
|
|
144
|
-
const splitVersions = Object.values(versions).map(splitVersion);
|
|
145
|
-
if (splitVersions.length === 0)
|
|
146
|
-
return null;
|
|
147
|
-
splitVersions.sort(compareVersions);
|
|
148
|
-
return concatVersion(splitVersions[0]);
|
|
149
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ProcessMode } from "../types/types.vscode.js";
|
|
2
|
-
import { FixWorkspaceDepsMain, FixWorkspaceDepsParams } from "../types/types.workspace.js";
|
|
3
|
-
export declare const runFixDepsByVersion: (repoRoot: string, mode: ProcessMode) => Promise<void>;
|
|
4
|
-
export declare const runFixDepsByFile: (repoRoot: string, mode: ProcessMode) => Promise<void>;
|
|
5
|
-
export declare abstract class IFixWorkspaceDeps {
|
|
6
|
-
readonly repoRoot: string;
|
|
7
|
-
readonly mode: ProcessMode;
|
|
8
|
-
constructor(repoRoot: string, mode: ProcessMode);
|
|
9
|
-
protected abstract fixVersion(p: FixWorkspaceDepsParams): string | null;
|
|
10
|
-
protected abstract restoreVersion(p: FixWorkspaceDepsParams): string | null;
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
protected handleDependencies(deps: Record<string, string> | undefined, p: FixWorkspaceDepsMain): boolean;
|
|
13
|
-
protected runSingle(p: FixWorkspaceDepsMain): boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
16
|
-
protected fixVersion(p: FixWorkspaceDepsParams): string | null;
|
|
17
|
-
protected restoreVersion(p: FixWorkspaceDepsParams): string | null;
|
|
18
|
-
}
|
|
19
|
-
export declare class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
20
|
-
protected fixVersion(p: FixWorkspaceDepsParams): string | null;
|
|
21
|
-
protected restoreVersion(p: FixWorkspaceDepsParams): string | null;
|
|
22
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { buildMapEntries, readPackageJsons, writePackageJsons, } from "./workspace.common.js";
|
|
2
|
-
export const runFixDepsByVersion = async (repoRoot, mode) => new FixWorkspaceDepsVersion(repoRoot, mode).run();
|
|
3
|
-
export const runFixDepsByFile = async (repoRoot, mode) => new FixWorkspaceDepsFile(repoRoot, mode).run();
|
|
4
|
-
export class IFixWorkspaceDeps {
|
|
5
|
-
repoRoot;
|
|
6
|
-
mode;
|
|
7
|
-
constructor(repoRoot, mode) {
|
|
8
|
-
this.repoRoot = repoRoot;
|
|
9
|
-
this.mode = mode;
|
|
10
|
-
}
|
|
11
|
-
async run() {
|
|
12
|
-
if (this.mode === "fix")
|
|
13
|
-
console.log("🔧 Fixing workspace dependencies...\n");
|
|
14
|
-
else
|
|
15
|
-
console.log("🔧 Restoring workspace dependencies...\n");
|
|
16
|
-
const pkgs = await readPackageJsons(this.repoRoot);
|
|
17
|
-
const mapEntries = buildMapEntries(pkgs);
|
|
18
|
-
const versionMap = new Map();
|
|
19
|
-
const workspacePackages = new Set();
|
|
20
|
-
for (const pkg of pkgs) {
|
|
21
|
-
versionMap.set(pkg.content.name, pkg.content.version);
|
|
22
|
-
workspacePackages.add(pkg.content.name);
|
|
23
|
-
}
|
|
24
|
-
console.log("📋 Version map:");
|
|
25
|
-
for (const map of mapEntries)
|
|
26
|
-
console.log(` ${map.fromPkg.content.name} --> ${map.toPkg.content.name}: ${map.relPath}`);
|
|
27
|
-
console.log();
|
|
28
|
-
for (const consumingPkg of pkgs) {
|
|
29
|
-
console.log(`📦 Processing ${consumingPkg.content.name}...`);
|
|
30
|
-
try {
|
|
31
|
-
consumingPkg.modified = this.runSingle({
|
|
32
|
-
consumingPkg,
|
|
33
|
-
mapEntries,
|
|
34
|
-
versionMap,
|
|
35
|
-
workspacePackages,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
console.error(`\nError processing ${consumingPkg.content.name}:`, err);
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
await writePackageJsons(pkgs);
|
|
44
|
-
if (this.mode === "fix")
|
|
45
|
-
console.log("✅ Done fixing workspace dependencies!");
|
|
46
|
-
else
|
|
47
|
-
console.log("✅ Done restoring workspace dependencies!");
|
|
48
|
-
}
|
|
49
|
-
// Replace workspace:* with file:...
|
|
50
|
-
handleDependencies(deps, p) {
|
|
51
|
-
if (!deps)
|
|
52
|
-
return false;
|
|
53
|
-
const handler = this.mode === "fix" ? this.fixVersion : this.restoreVersion;
|
|
54
|
-
let modified = false;
|
|
55
|
-
for (const [name, version] of Object.entries(deps)) {
|
|
56
|
-
const newVersion = handler({ ...p, pkg: name, version });
|
|
57
|
-
if (!newVersion)
|
|
58
|
-
continue;
|
|
59
|
-
console.log(` ✓ Replaced ${name}: ${version} → ${newVersion}`);
|
|
60
|
-
deps[name] = newVersion;
|
|
61
|
-
modified = true;
|
|
62
|
-
}
|
|
63
|
-
return modified;
|
|
64
|
-
}
|
|
65
|
-
runSingle(p) {
|
|
66
|
-
let modified = false;
|
|
67
|
-
modified =
|
|
68
|
-
this.handleDependencies(p.consumingPkg.content.dependencies, p) ||
|
|
69
|
-
modified;
|
|
70
|
-
modified =
|
|
71
|
-
this.handleDependencies(p.consumingPkg.content.devDependencies, p) ||
|
|
72
|
-
modified;
|
|
73
|
-
modified =
|
|
74
|
-
this.handleDependencies(p.consumingPkg.content.peerDependencies, p) ||
|
|
75
|
-
modified;
|
|
76
|
-
return modified;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
80
|
-
fixVersion(p) {
|
|
81
|
-
if (p.version !== "workspace:*")
|
|
82
|
-
return null;
|
|
83
|
-
const actualVersion = p.versionMap.get(p.pkg);
|
|
84
|
-
if (!actualVersion) {
|
|
85
|
-
console.error(` ERROR: Could not find version for workspace dependency ${p.pkg}`);
|
|
86
|
-
throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);
|
|
87
|
-
}
|
|
88
|
-
return `^${actualVersion}`;
|
|
89
|
-
}
|
|
90
|
-
restoreVersion(p) {
|
|
91
|
-
if (p.workspacePackages.has(p.pkg) && p.version.startsWith("^")) {
|
|
92
|
-
// Verify the version matches what fix script would have created
|
|
93
|
-
const actualVersion = p.versionMap.get(p.pkg);
|
|
94
|
-
if (actualVersion && p.version === `^${actualVersion}`) {
|
|
95
|
-
return "workspace:*";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
102
|
-
fixVersion(p) {
|
|
103
|
-
if (p.version !== "workspace:*")
|
|
104
|
-
return null;
|
|
105
|
-
const mapEntry = p.mapEntries.find((mapEntry) => mapEntry.fromPkg.content.name === p.consumingPkg.content.name &&
|
|
106
|
-
mapEntry.toPkg.content.name === p.pkg);
|
|
107
|
-
if (!mapEntry) {
|
|
108
|
-
console.error(` ERROR: Could not find version for workspace dependency ${p.pkg}`);
|
|
109
|
-
throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);
|
|
110
|
-
}
|
|
111
|
-
return `file:${mapEntry.relPath}`;
|
|
112
|
-
}
|
|
113
|
-
restoreVersion(p) {
|
|
114
|
-
if (!p.version.startsWith("file:"))
|
|
115
|
-
return null;
|
|
116
|
-
return "workspace:*";
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { FixWorkspaceDepsMain, FixWorkspaceDepsParams } from "../types/types.workspace.js";
|
|
2
|
-
export type ProcessMode = "fix" | "restore";
|
|
3
|
-
export declare const runFixDepsByVersion: (repoRoot: string, mode: ProcessMode) => Promise<void>;
|
|
4
|
-
export declare const runFixDepsByFile: (repoRoot: string, mode: ProcessMode) => Promise<void>;
|
|
5
|
-
export declare abstract class IFixWorkspaceDeps {
|
|
6
|
-
readonly repoRoot: string;
|
|
7
|
-
readonly mode: ProcessMode;
|
|
8
|
-
constructor(repoRoot: string, mode: ProcessMode);
|
|
9
|
-
protected abstract fixVersion(p: FixWorkspaceDepsParams): string | null;
|
|
10
|
-
protected abstract restoreVersion(p: FixWorkspaceDepsParams): string | null;
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
protected handleDependencies(deps: Record<string, string> | undefined, p: FixWorkspaceDepsMain): boolean;
|
|
13
|
-
protected runSingle(p: FixWorkspaceDepsMain): boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
16
|
-
protected fixVersion(p: FixWorkspaceDepsParams): string | null;
|
|
17
|
-
protected restoreVersion(p: FixWorkspaceDepsParams): string | null;
|
|
18
|
-
}
|
|
19
|
-
export declare class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
20
|
-
protected fixVersion(p: FixWorkspaceDepsParams): string | null;
|
|
21
|
-
protected restoreVersion(p: FixWorkspaceDepsParams): string | null;
|
|
22
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { buildMapEntries, readPackageJsons, writePackageJsons, } from "./workspace.common.js";
|
|
2
|
-
export const runFixDepsByVersion = async (repoRoot, mode) => new FixWorkspaceDepsVersion(repoRoot, mode).run();
|
|
3
|
-
export const runFixDepsByFile = async (repoRoot, mode) => new FixWorkspaceDepsFile(repoRoot, mode).run();
|
|
4
|
-
export class IFixWorkspaceDeps {
|
|
5
|
-
repoRoot;
|
|
6
|
-
mode;
|
|
7
|
-
constructor(repoRoot, mode) {
|
|
8
|
-
this.repoRoot = repoRoot;
|
|
9
|
-
this.mode = mode;
|
|
10
|
-
}
|
|
11
|
-
async run() {
|
|
12
|
-
if (this.mode === "fix")
|
|
13
|
-
console.log("🔧 Fixing workspace dependencies...\n");
|
|
14
|
-
else
|
|
15
|
-
console.log("🔧 Restoring workspace dependencies...\n");
|
|
16
|
-
const pkgs = await readPackageJsons(this.repoRoot);
|
|
17
|
-
const mapEntries = buildMapEntries(pkgs);
|
|
18
|
-
const versionMap = new Map();
|
|
19
|
-
const workspacePackages = new Set();
|
|
20
|
-
for (const pkg of pkgs) {
|
|
21
|
-
versionMap.set(pkg.content.name, pkg.content.version);
|
|
22
|
-
workspacePackages.add(pkg.content.name);
|
|
23
|
-
}
|
|
24
|
-
console.log("📋 Version map:");
|
|
25
|
-
for (const map of mapEntries)
|
|
26
|
-
console.log(` ${map.fromPkg.content.name} --> ${map.toPkg.content.name}: ${map.relPath}`);
|
|
27
|
-
console.log();
|
|
28
|
-
for (const consumingPkg of pkgs) {
|
|
29
|
-
console.log(`📦 Processing ${consumingPkg.content.name}...`);
|
|
30
|
-
try {
|
|
31
|
-
consumingPkg.modified = this.runSingle({
|
|
32
|
-
consumingPkg,
|
|
33
|
-
mapEntries,
|
|
34
|
-
versionMap,
|
|
35
|
-
workspacePackages,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
console.error(`\nError processing ${consumingPkg.content.name}:`, err);
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
await writePackageJsons(pkgs);
|
|
44
|
-
if (this.mode === "fix")
|
|
45
|
-
console.log("✅ Done fixing workspace dependencies!");
|
|
46
|
-
else
|
|
47
|
-
console.log("✅ Done restoring workspace dependencies!");
|
|
48
|
-
}
|
|
49
|
-
// Replace workspace:* with file:...
|
|
50
|
-
handleDependencies(deps, p) {
|
|
51
|
-
if (!deps)
|
|
52
|
-
return false;
|
|
53
|
-
const handler = this.mode === "fix" ? this.fixVersion : this.restoreVersion;
|
|
54
|
-
let modified = false;
|
|
55
|
-
for (const [name, version] of Object.entries(deps)) {
|
|
56
|
-
const newVersion = handler({ ...p, pkg: name, version });
|
|
57
|
-
if (!newVersion)
|
|
58
|
-
continue;
|
|
59
|
-
console.log(` ✓ Replaced ${name}: ${version} → ${newVersion}`);
|
|
60
|
-
deps[name] = newVersion;
|
|
61
|
-
modified = true;
|
|
62
|
-
}
|
|
63
|
-
return modified;
|
|
64
|
-
}
|
|
65
|
-
runSingle(p) {
|
|
66
|
-
let modified = false;
|
|
67
|
-
modified =
|
|
68
|
-
this.handleDependencies(p.consumingPkg.content.dependencies, p) ||
|
|
69
|
-
modified;
|
|
70
|
-
modified =
|
|
71
|
-
this.handleDependencies(p.consumingPkg.content.devDependencies, p) ||
|
|
72
|
-
modified;
|
|
73
|
-
modified =
|
|
74
|
-
this.handleDependencies(p.consumingPkg.content.peerDependencies, p) ||
|
|
75
|
-
modified;
|
|
76
|
-
return modified;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
80
|
-
fixVersion(p) {
|
|
81
|
-
if (p.version !== "workspace:*")
|
|
82
|
-
return null;
|
|
83
|
-
const actualVersion = p.versionMap.get(p.pkg);
|
|
84
|
-
if (!actualVersion) {
|
|
85
|
-
console.error(` ERROR: Could not find version for workspace dependency ${p.pkg}`);
|
|
86
|
-
throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);
|
|
87
|
-
}
|
|
88
|
-
return `^${actualVersion}`;
|
|
89
|
-
}
|
|
90
|
-
restoreVersion(p) {
|
|
91
|
-
if (p.workspacePackages.has(p.pkg) && p.version.startsWith("^")) {
|
|
92
|
-
// Verify the version matches what fix script would have created
|
|
93
|
-
const actualVersion = p.versionMap.get(p.pkg);
|
|
94
|
-
if (actualVersion && p.version === `^${actualVersion}`) {
|
|
95
|
-
return "workspace:*";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
102
|
-
fixVersion(p) {
|
|
103
|
-
if (p.version !== "workspace:*")
|
|
104
|
-
return null;
|
|
105
|
-
const mapEntry = p.mapEntries.find((mapEntry) => mapEntry.fromPkg.content.name === p.consumingPkg.content.name &&
|
|
106
|
-
mapEntry.toPkg.content.name === p.pkg);
|
|
107
|
-
if (!mapEntry) {
|
|
108
|
-
console.error(` ERROR: Could not find version for workspace dependency ${p.pkg}`);
|
|
109
|
-
throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);
|
|
110
|
-
}
|
|
111
|
-
return `file:${mapEntry.relPath}`;
|
|
112
|
-
}
|
|
113
|
-
restoreVersion(p) {
|
|
114
|
-
if (!p.version.startsWith("file:"))
|
|
115
|
-
return null;
|
|
116
|
-
return "workspace:*";
|
|
117
|
-
}
|
|
118
|
-
}
|