update-workspace-root-version 0.1.0 → 0.3.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/README.md +39 -6
- package/dist/bin/update-workspace-root-version.js +6 -0
- package/dist/src/index.js +3 -3
- package/dist/src/steps/create-options.js +2 -1
- package/dist/src/steps/get-new-version.js +12 -0
- package/dist/src/steps/get-package-versions.js +5 -2
- package/dist/src/steps/get-workspace-root-version.js +1 -1
- package/dist/src/steps/index.js +1 -1
- package/dist/src/utils/version/allow.js +6 -0
- package/dist/src/utils/{versions → version}/index.js +1 -0
- package/package.json +1 -1
- package/dist/src/steps/get-highest-version.js +0 -5
- /package/dist/src/utils/{versions → version}/compare.js +0 -0
- /package/dist/src/utils/{versions → version}/increment.js +0 -0
package/README.md
CHANGED
|
@@ -4,21 +4,54 @@
|
|
|
4
4
|
|
|
5
5
|
_Update the workspace root version in a monorepo_
|
|
6
6
|
|
|
7
|
+
1. [Why use it?](#why-use-it)
|
|
8
|
+
1. [Usage](#usage)
|
|
9
|
+
- [Arguments](#arguments)
|
|
10
|
+
- [Limitations](#limitations)
|
|
11
|
+
1. [Compatibility](#compatibility)
|
|
12
|
+
1. [Contributing](#contributing)
|
|
13
|
+
1. [License](#license)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Why use it?
|
|
17
|
+
|
|
18
|
+
A release tag helps us easily see the project at a past point in time. Naming the release tag can be tricky in a monorepo, because we can release many packages at once.
|
|
19
|
+
|
|
20
|
+
We can solve the naming problem if the workspace root version represents the state of the project: We simply set the tag name to be the workspace root version.
|
|
21
|
+
|
|
7
22
|
|
|
8
23
|
## Usage
|
|
9
24
|
|
|
10
|
-
|
|
25
|
+
At the workspace root, install `update-workspace-root-version` as a development dependency. Run the codemod after updating the package versions.
|
|
26
|
+
|
|
27
|
+
For example, with [changesets](https://github.com/changesets/changesets),
|
|
28
|
+
|
|
29
|
+
```json5
|
|
30
|
+
/* package.json */
|
|
31
|
+
{
|
|
32
|
+
"scripts": {
|
|
33
|
+
"release:changelog": "changeset version; update-workspace-root-version",
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@changesets/cli": "...",
|
|
37
|
+
"update-workspace-root-version": "..."
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
11
41
|
|
|
12
|
-
[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.]
|
|
13
42
|
|
|
14
|
-
|
|
43
|
+
### Arguments
|
|
15
44
|
|
|
16
|
-
<
|
|
45
|
+
<details>
|
|
17
46
|
|
|
18
|
-
|
|
47
|
+
<summary>Optional: Specify the algorithm</summary>
|
|
19
48
|
|
|
20
49
|
```sh
|
|
21
|
-
|
|
50
|
+
# Highest version (default)
|
|
51
|
+
update-workspace-root-version --algorithm highest-version
|
|
52
|
+
|
|
53
|
+
# Increment by one
|
|
54
|
+
update-workspace-root-version --algorithm increment-by-one
|
|
22
55
|
```
|
|
23
56
|
|
|
24
57
|
</details>
|
|
@@ -7,12 +7,18 @@ import { runCodemod } from '../src/index.js';
|
|
|
7
7
|
process.title = 'update-workspace-root-version';
|
|
8
8
|
// Set codemod options
|
|
9
9
|
const argv = yargs(hideBin(process.argv))
|
|
10
|
+
.option('algorithm', {
|
|
11
|
+
choices: ['highest-version', 'increment-by-one'],
|
|
12
|
+
describe: 'How to update the workspace root version',
|
|
13
|
+
type: 'string',
|
|
14
|
+
})
|
|
10
15
|
.option('root', {
|
|
11
16
|
describe: 'Where to run the codemod',
|
|
12
17
|
type: 'string',
|
|
13
18
|
})
|
|
14
19
|
.parseSync();
|
|
15
20
|
const codemodOptions = {
|
|
21
|
+
algorithm: argv['algorithm'] ?? 'highest-version',
|
|
16
22
|
projectRoot: argv['root'] ?? process.cwd(),
|
|
17
23
|
};
|
|
18
24
|
runCodemod(codemodOptions);
|
package/dist/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createOptions,
|
|
1
|
+
import { createOptions, getNewVersion, getPackageVersions, getWorkspaceRootVersion, updateWorkspaceRootVersion, } from './steps/index.js';
|
|
2
2
|
export function runCodemod(codemodOptions) {
|
|
3
3
|
const options = createOptions(codemodOptions);
|
|
4
4
|
const packageVersions = getPackageVersions(options);
|
|
5
5
|
const workspaceRootVersion = getWorkspaceRootVersion(options);
|
|
6
|
-
const
|
|
7
|
-
updateWorkspaceRootVersion(
|
|
6
|
+
const version = getNewVersion(packageVersions, workspaceRootVersion, options);
|
|
7
|
+
updateWorkspaceRootVersion(version, options);
|
|
8
8
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { compare, increment } from '../utils/version/index.js';
|
|
2
|
+
export function getNewVersion(packageVersions, workspaceRootVersion, options) {
|
|
3
|
+
switch (options.algorithm) {
|
|
4
|
+
case 'highest-version': {
|
|
5
|
+
const versions = [...packageVersions, increment(workspaceRootVersion)];
|
|
6
|
+
return versions.sort(compare)[0];
|
|
7
|
+
}
|
|
8
|
+
case 'increment-by-one': {
|
|
9
|
+
return increment(workspaceRootVersion);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { findFiles } from '@codemod-utils/files';
|
|
3
3
|
import { readPackageJson } from '@codemod-utils/json';
|
|
4
|
+
import { allow } from '../utils/version/index.js';
|
|
4
5
|
function getPackageRoots(options) {
|
|
5
6
|
const { projectRoot } = options;
|
|
6
7
|
const packageRoots = findFiles('**/package.json', {
|
|
@@ -18,8 +19,10 @@ function getPackageRoots(options) {
|
|
|
18
19
|
}
|
|
19
20
|
export function getPackageVersions(options) {
|
|
20
21
|
const packageRoots = getPackageRoots(options);
|
|
21
|
-
return packageRoots
|
|
22
|
+
return packageRoots
|
|
23
|
+
.map((packageRoot) => {
|
|
22
24
|
const packageJson = readPackageJson({ projectRoot: packageRoot });
|
|
23
25
|
return packageJson['version'];
|
|
24
|
-
})
|
|
26
|
+
})
|
|
27
|
+
.filter(allow);
|
|
25
28
|
}
|
|
@@ -2,5 +2,5 @@ import { readPackageJson } from '@codemod-utils/json';
|
|
|
2
2
|
export function getWorkspaceRootVersion(options) {
|
|
3
3
|
const { projectRoot } = options;
|
|
4
4
|
const packageJson = readPackageJson({ projectRoot });
|
|
5
|
-
return packageJson['version'];
|
|
5
|
+
return packageJson['version'] ?? '0.0.0';
|
|
6
6
|
}
|
package/dist/src/steps/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './create-options.js';
|
|
2
|
-
export * from './get-
|
|
2
|
+
export * from './get-new-version.js';
|
|
3
3
|
export * from './get-package-versions.js';
|
|
4
4
|
export * from './get-workspace-root-version.js';
|
|
5
5
|
export * from './update-workspace-root-version.js';
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|