yarn-version 8.7.0 → 9.0.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.
- package/CHANGELOG.md +19 -0
- package/README.md +2 -152
- package/package.json +9 -39
- package/yarn-version.mjs +3 -0
- package/dist/index-node.mjs +0 -1251
- package/dist/index-node.mjs.map +0 -1
- package/rollup.config.mjs +0 -12
- package/src/__fixtures__/basic/package.json +0 -4
- package/src/__fixtures__/basic/yarn.lock +0 -12
- package/src/__fixtures__/monorepo/package.json +0 -7
- package/src/__fixtures__/monorepo/packages/package-1/package.json +0 -4
- package/src/__fixtures__/monorepo/packages/package-2/package.json +0 -7
- package/src/__fixtures__/monorepo/packages/package-3/package.json +0 -7
- package/src/__fixtures__/monorepo/packages/package-4/package.json +0 -7
- package/src/__fixtures__/monorepo/packages/package-5/package.json +0 -8
- package/src/__fixtures__/monorepo/yarn.lock +0 -0
- package/src/__fixtures__/no-version/package.json +0 -3
- package/src/__fixtures__/no-version/yarn.lock +0 -0
- package/src/__fixtures__/with-lifecycle/.yarn/install-state.gz +0 -0
- package/src/__fixtures__/with-lifecycle/package.json +0 -7
- package/src/__fixtures__/with-lifecycle/yarn.lock +0 -11
- package/src/commands/version.test.ts +0 -94
- package/src/commands/version.ts +0 -902
- package/src/index.ts +0 -13
- package/src/missing-types.d.ts +0 -11
- package/src/utils/UsageError.ts +0 -6
- package/src/utils/bumpTypeUtils.ts +0 -113
- package/src/utils/conventionalChangelogUtils.test.ts +0 -761
- package/src/utils/conventionalChangelogUtils.ts +0 -104
- package/src/utils/conventionalCommitConfigUtils.ts +0 -20
- package/src/utils/execCommand.ts +0 -189
- package/src/utils/generatorUtils.ts +0 -11
- package/src/utils/gitUtils.ts +0 -193
- package/src/utils/githubUtils.ts +0 -82
- package/src/utils/mapUtils.ts +0 -7
- package/src/utils/packageDependenciesUtils.test.ts +0 -24
- package/src/utils/packageDependenciesUtils.ts +0 -80
- package/src/utils/packageUtils.ts +0 -97
- package/src/utils/updateChangelog.ts +0 -39
- package/src/utils/workspaceUtils.ts +0 -142
- package/tsconfig.json +0 -23
- package/vitest.config.js +0 -9
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Combination of an optional scope and name.
|
|
3
|
-
*
|
|
4
|
-
* eg `@npm/types`
|
|
5
|
-
*/
|
|
6
|
-
export interface PackageDescriptorName {
|
|
7
|
-
scope?: string;
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface DescriptorUtils<Descriptor> {
|
|
12
|
-
parse: (value: string) => Descriptor;
|
|
13
|
-
stringify: (descriptor: Descriptor) => string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const PackageDescriptorNameUtils: DescriptorUtils<PackageDescriptorName> =
|
|
17
|
-
{
|
|
18
|
-
parse: (value) => {
|
|
19
|
-
if (value.startsWith("@")) {
|
|
20
|
-
const [scope, name] = value.slice(1).split("/", 2);
|
|
21
|
-
if (!scope || !name) {
|
|
22
|
-
throw new Error(`Invalid package descriptor name: ${value}`);
|
|
23
|
-
}
|
|
24
|
-
return { scope, name };
|
|
25
|
-
}
|
|
26
|
-
return { name: value };
|
|
27
|
-
},
|
|
28
|
-
stringify: (descriptor) => {
|
|
29
|
-
return descriptor.scope === undefined
|
|
30
|
-
? descriptor.name
|
|
31
|
-
: `@${descriptor.scope}/${descriptor.name}`;
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export interface PackageDependencyDescriptor {
|
|
36
|
-
key: string;
|
|
37
|
-
name: PackageDescriptorName;
|
|
38
|
-
selector: string; // can be npm tag or version or version range or git url or local folder path
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface PackageDependencyDescriptorUtils<
|
|
42
|
-
Descriptor = PackageDependencyDescriptor,
|
|
43
|
-
> {
|
|
44
|
-
make: (descriptor: Descriptor, selector: string) => Descriptor;
|
|
45
|
-
parse: (dependencyKey: string, dependencyValue: string) => Descriptor;
|
|
46
|
-
stringify: (descriptor: Descriptor) => [key: string, value: string];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const PackageDependencyDescriptorUtils: PackageDependencyDescriptorUtils =
|
|
50
|
-
{
|
|
51
|
-
make: (descriptor, selector) => {
|
|
52
|
-
return { key: descriptor.key, name: descriptor.name, selector };
|
|
53
|
-
},
|
|
54
|
-
parse: (dependencyKey, dependencyValue) => {
|
|
55
|
-
const [name, selector] = dependencyValue.startsWith("npm:")
|
|
56
|
-
? (() => {
|
|
57
|
-
const v = dependencyValue.slice("npm:".length);
|
|
58
|
-
if (!v.startsWith("@")) return v.split("@", 2) as [string, string];
|
|
59
|
-
const [packageNameWithoutFirstChar, selector] = v
|
|
60
|
-
.slice(1)
|
|
61
|
-
.split("@", 2);
|
|
62
|
-
if (!packageNameWithoutFirstChar || !selector) {
|
|
63
|
-
throw new Error(`Invalid package descriptor: ${dependencyValue}`);
|
|
64
|
-
}
|
|
65
|
-
return [`@${packageNameWithoutFirstChar}`, selector];
|
|
66
|
-
})()
|
|
67
|
-
: [dependencyKey, dependencyValue];
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
key: dependencyKey,
|
|
71
|
-
name: PackageDescriptorNameUtils.parse(name),
|
|
72
|
-
selector,
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
stringify: (descriptor) => {
|
|
76
|
-
return [descriptor.key, descriptor.selector];
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// export const PackageDependencySelectorUtils;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import mapWorkspaces from "@npmcli/map-workspaces";
|
|
5
|
-
import prettyPkg from "@pob/pretty-pkg";
|
|
6
|
-
import type { PackageJson } from "type-fest";
|
|
7
|
-
|
|
8
|
-
export interface Workspace {
|
|
9
|
-
readonly cwd: string;
|
|
10
|
-
readonly relativeCwd?: string;
|
|
11
|
-
readonly pkg: PackageJson;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface ProjectWorkspace {
|
|
15
|
-
readonly root: Workspace;
|
|
16
|
-
readonly children: Map<string, Workspace>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const createProjectWorkspace = async (
|
|
20
|
-
root: Workspace,
|
|
21
|
-
): Promise<ProjectWorkspace> => {
|
|
22
|
-
const map: Map<string, string> = root.pkg.workspaces
|
|
23
|
-
? await mapWorkspaces({ cwd: root.cwd, pkg: root.pkg })
|
|
24
|
-
: new Map();
|
|
25
|
-
|
|
26
|
-
const children = new Map<string, Workspace>(
|
|
27
|
-
await Promise.all(
|
|
28
|
-
[...map.entries()].map(
|
|
29
|
-
async ([packageName, packagePath]) =>
|
|
30
|
-
[
|
|
31
|
-
packageName,
|
|
32
|
-
{
|
|
33
|
-
...(await createWorkspace(packagePath)),
|
|
34
|
-
relativeCwd: path.relative(root.cwd, packagePath),
|
|
35
|
-
} satisfies Workspace,
|
|
36
|
-
] as const,
|
|
37
|
-
),
|
|
38
|
-
),
|
|
39
|
-
);
|
|
40
|
-
return { root, children };
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const isAccessible = (path: string): Promise<boolean> =>
|
|
44
|
-
fs.access(path).then(
|
|
45
|
-
() => true,
|
|
46
|
-
() => false,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
export const findRootWorkspace = async (
|
|
50
|
-
cwd: string,
|
|
51
|
-
): Promise<Workspace | null> => {
|
|
52
|
-
let currentPath = cwd;
|
|
53
|
-
do {
|
|
54
|
-
const isRootIfOneOfThesePathsExists = await Promise.all([
|
|
55
|
-
isAccessible(path.join(currentPath, ".yarnrc.yml")),
|
|
56
|
-
isAccessible(path.join(currentPath, "yarn.lock")),
|
|
57
|
-
]);
|
|
58
|
-
if (isRootIfOneOfThesePathsExists.some(Boolean)) {
|
|
59
|
-
return createWorkspace(currentPath);
|
|
60
|
-
}
|
|
61
|
-
currentPath = path.dirname(currentPath);
|
|
62
|
-
} while (currentPath && currentPath !== "/");
|
|
63
|
-
return null;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const getPackageJsonPath = (cwd: string): string =>
|
|
67
|
-
path.join(cwd, "package.json");
|
|
68
|
-
|
|
69
|
-
export const createWorkspace = async (path: string): Promise<Workspace> => {
|
|
70
|
-
const pkg = await readPkg(path);
|
|
71
|
-
return { cwd: path, pkg };
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export async function writePkg(
|
|
75
|
-
workspace: Workspace,
|
|
76
|
-
prettierOptions = undefined,
|
|
77
|
-
): Promise<void> {
|
|
78
|
-
const string = await prettyPkg(workspace.pkg, prettierOptions);
|
|
79
|
-
await fs.writeFile(getPackageJsonPath(workspace.cwd), string, "utf8");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function readPkg(cwd: string): Promise<PackageJson> {
|
|
83
|
-
const packagePath = getPackageJsonPath(cwd);
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
|
|
85
|
-
const pkg = await fs.readFile(packagePath, "utf8").catch((error: Error) => {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Failed to read package.json in "${cwd}": ${error instanceof Error ? error.message : String(error)}`,
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
try {
|
|
91
|
-
return JSON.parse(pkg);
|
|
92
|
-
} catch (error: unknown) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Failed to parse package.json in "${cwd}": ${error instanceof Error ? error.message : String(error)}`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
const COMMIT_GUIDELINE =
|
|
4
|
-
"See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.";
|
|
5
|
-
|
|
6
|
-
const CHANGELOG_HEADER = [
|
|
7
|
-
"# Changelog",
|
|
8
|
-
"",
|
|
9
|
-
"All notable changes to this project will be documented in this file.",
|
|
10
|
-
COMMIT_GUIDELINE,
|
|
11
|
-
"",
|
|
12
|
-
].join("\n");
|
|
13
|
-
|
|
14
|
-
export const updateChangelogFile = async (
|
|
15
|
-
versionChangelogContent: string,
|
|
16
|
-
tagPrefix: string,
|
|
17
|
-
file = "CHANGELOG.md",
|
|
18
|
-
): Promise<void> => {
|
|
19
|
-
const START_OF_LAST_RELEASE_PATTERN = new RegExp(
|
|
20
|
-
`(^#+ \\[?(?:${tagPrefix})?\\d+\\.\\d+\\.\\d+|<a name=)`,
|
|
21
|
-
"m",
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
let oldContent = "";
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
oldContent = await fs.readFile(file, "utf8");
|
|
28
|
-
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN);
|
|
29
|
-
// find the position of the last release and remove header:
|
|
30
|
-
if (oldContentStart !== -1) {
|
|
31
|
-
oldContent = oldContent.slice(Math.max(0, oldContentStart));
|
|
32
|
-
}
|
|
33
|
-
} catch {}
|
|
34
|
-
|
|
35
|
-
await fs.writeFile(
|
|
36
|
-
file,
|
|
37
|
-
`${CHANGELOG_HEADER}\n${versionChangelogContent}\n${oldContent}`,
|
|
38
|
-
);
|
|
39
|
-
};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { getMapArrayItemForKey } from "./mapUtils.ts";
|
|
4
|
-
import type { PackageDependencyDescriptor } from "./packageDependenciesUtils.ts";
|
|
5
|
-
import {
|
|
6
|
-
PackageDependencyDescriptorUtils,
|
|
7
|
-
PackageDescriptorNameUtils,
|
|
8
|
-
} from "./packageDependenciesUtils.ts";
|
|
9
|
-
import type { ProjectWorkspace, Workspace } from "./packageUtils.ts";
|
|
10
|
-
|
|
11
|
-
const allDependenciesTypes = [
|
|
12
|
-
"dependencies",
|
|
13
|
-
"devDependencies",
|
|
14
|
-
"peerDependencies",
|
|
15
|
-
] as const;
|
|
16
|
-
export type DependencyType = (typeof allDependenciesTypes)[number];
|
|
17
|
-
|
|
18
|
-
export const getWorkspaceName = (workspace: Workspace): string => {
|
|
19
|
-
return (
|
|
20
|
-
workspace.pkg.name ?? (path.basename(workspace.cwd) || "unnamed-workspace")
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type WorkspacesDependenciesMap = Map<
|
|
25
|
-
Workspace,
|
|
26
|
-
[Workspace, DependencyType, PackageDependencyDescriptor][]
|
|
27
|
-
>;
|
|
28
|
-
|
|
29
|
-
export const buildDependentsMaps = (
|
|
30
|
-
project: ProjectWorkspace,
|
|
31
|
-
): WorkspacesDependenciesMap => {
|
|
32
|
-
const dependentsMap: WorkspacesDependenciesMap = new Map<
|
|
33
|
-
Workspace,
|
|
34
|
-
[Workspace, DependencyType, PackageDependencyDescriptor][]
|
|
35
|
-
>();
|
|
36
|
-
|
|
37
|
-
// Note that we need to do this before applying the new versions,
|
|
38
|
-
// otherwise the `findWorkspacesByDescriptor` calls won't be able to
|
|
39
|
-
// resolve the workspaces anymore (because the workspace versions will
|
|
40
|
-
// have changed and won't match the outdated dependencies).
|
|
41
|
-
|
|
42
|
-
for (const [, dependent] of project.children) {
|
|
43
|
-
for (const set of allDependenciesTypes) {
|
|
44
|
-
for (const [dependencyKey, dependencyValue] of Object.entries(
|
|
45
|
-
dependent.pkg[set] || {},
|
|
46
|
-
)) {
|
|
47
|
-
if (!dependencyValue) continue;
|
|
48
|
-
const descriptor = PackageDependencyDescriptorUtils.parse(
|
|
49
|
-
dependencyKey,
|
|
50
|
-
dependencyValue,
|
|
51
|
-
);
|
|
52
|
-
const workspace = project.children.get(
|
|
53
|
-
PackageDescriptorNameUtils.stringify(descriptor.name),
|
|
54
|
-
);
|
|
55
|
-
if (!workspace) continue;
|
|
56
|
-
|
|
57
|
-
const dependents = getMapArrayItemForKey(dependentsMap, workspace);
|
|
58
|
-
dependents.push([dependent, set, descriptor]);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return dependentsMap;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const buildDependenciesMaps = (
|
|
67
|
-
project: ProjectWorkspace,
|
|
68
|
-
): WorkspacesDependenciesMap => {
|
|
69
|
-
const dependenciesMap: WorkspacesDependenciesMap = new Map<
|
|
70
|
-
Workspace,
|
|
71
|
-
[Workspace, DependencyType, PackageDependencyDescriptor][]
|
|
72
|
-
>();
|
|
73
|
-
|
|
74
|
-
// Note that we need to do this before applying the new versions,
|
|
75
|
-
// otherwise the `findWorkspacesByDescriptor` calls won't be able to
|
|
76
|
-
// resolve the workspaces anymore (because the workspace versions will
|
|
77
|
-
// have changed and won't match the outdated dependencies).
|
|
78
|
-
|
|
79
|
-
for (const dependent of project.children.values()) {
|
|
80
|
-
for (const set of allDependenciesTypes) {
|
|
81
|
-
for (const [dependencyKey, dependencyValue] of Object.entries(
|
|
82
|
-
dependent.pkg[set] || {},
|
|
83
|
-
)) {
|
|
84
|
-
if (!dependencyValue) continue;
|
|
85
|
-
const descriptor = PackageDependencyDescriptorUtils.parse(
|
|
86
|
-
dependencyKey,
|
|
87
|
-
dependencyValue,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const workspace = project.children.get(
|
|
91
|
-
PackageDescriptorNameUtils.stringify(descriptor.name),
|
|
92
|
-
);
|
|
93
|
-
if (!workspace) continue;
|
|
94
|
-
|
|
95
|
-
const dependencies = getMapArrayItemForKey(dependenciesMap, dependent);
|
|
96
|
-
dependencies.push([workspace, set, descriptor]);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return dependenciesMap;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const buildTopologicalOrderBatches = (
|
|
105
|
-
project: ProjectWorkspace,
|
|
106
|
-
dependenciesMap: WorkspacesDependenciesMap,
|
|
107
|
-
): Workspace[][] => {
|
|
108
|
-
const batches: Workspace[][] = [];
|
|
109
|
-
|
|
110
|
-
const added = new Set<Workspace>();
|
|
111
|
-
const toAdd = new Set<Workspace>([
|
|
112
|
-
project.root,
|
|
113
|
-
...project.children.values(),
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
while (toAdd.size > 0) {
|
|
117
|
-
const batch = new Set<Workspace>();
|
|
118
|
-
for (const workspace of toAdd) {
|
|
119
|
-
// make sure top level workspace is always in the last batch
|
|
120
|
-
if (workspace === project.root && toAdd.size > 1) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const dependencies = dependenciesMap.get(workspace);
|
|
125
|
-
if (!dependencies || dependencies.every((w) => added.has(w[0]))) {
|
|
126
|
-
batch.add(workspace);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
for (const workspace of batch) {
|
|
131
|
-
added.add(workspace);
|
|
132
|
-
toAdd.delete(workspace);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (batch.size === 0) {
|
|
136
|
-
throw new Error("Circular dependency detected");
|
|
137
|
-
}
|
|
138
|
-
batches.push([...batch]);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return batches;
|
|
142
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"@pob/root/tsconfigs/strict.json",
|
|
4
|
-
"@pob/root/tsconfigs/targets/rollup-node-22.json"
|
|
5
|
-
],
|
|
6
|
-
"include": ["src/**/*.ts"],
|
|
7
|
-
"compilerOptions": {
|
|
8
|
-
"rootDir": "src",
|
|
9
|
-
"baseUrl": "" /* Base directory to resolve non-absolute module names. */,
|
|
10
|
-
"noEmit": true,
|
|
11
|
-
"tsBuildInfoFile": "node_modules/.cache/tsc/tsbuildinfo",
|
|
12
|
-
"incremental": true,
|
|
13
|
-
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
|
|
16
|
-
"paths": {
|
|
17
|
-
"@pob/rollup-esbuild": ["../../@pob/rollup-esbuild/lib"],
|
|
18
|
-
"@pob/rollup-esbuild/*": ["../../@pob/rollup-esbuild/lib/*"],
|
|
19
|
-
"@pob/pretty-pkg": ["../../@pob/pretty-pkg/lib"],
|
|
20
|
-
"@pob/pretty-pkg/*": ["../../@pob/pretty-pkg/lib/*"]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|