yarn-version 1.0.0-pre

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,39 @@
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
+ };
@@ -0,0 +1,142 @@
1
+ /* eslint-disable complexity */
2
+ import path from "node:path";
3
+ import { getMapArrayItemForKey } from "./mapUtils";
4
+ import type { PackageDependencyDescriptor } from "./packageDependenciesUtils";
5
+ import {
6
+ PackageDependencyDescriptorUtils,
7
+ PackageDescriptorNameUtils,
8
+ } from "./packageDependenciesUtils";
9
+ import type { ProjectWorkspace, Workspace } from "./packageUtils";
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 ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "extends": [
3
+ "@pob/root/tsconfigs/strict.json",
4
+ "@pob/root/tsconfigs/targets/rollup-node-20.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
+ "composite": true,
14
+
15
+ "resolveJsonModule": true,
16
+
17
+ "paths": {
18
+ "@pob/rollup-esbuild": ["../../@pob/rollup-esbuild/lib"],
19
+ "@pob/rollup-esbuild/*": ["../../@pob/rollup-esbuild/lib/*"],
20
+ "@pob/pretty-pkg": ["../../@pob/pretty-pkg/lib"],
21
+ "@pob/pretty-pkg/*": ["../../@pob/pretty-pkg/lib/*"]
22
+ }
23
+ }
24
+ }