update-workspace-root-version 0.2.0 → 0.3.1

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 CHANGED
@@ -15,9 +15,11 @@ _Update the workspace root version in a monorepo_
15
15
 
16
16
  ## Why use it?
17
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.
18
+ Git tags mark a specific point in a repo's history and are usually created before release. Thanks to these tags, we can easily send people links and point to specific code. We can also compare tags to see how files have changed.
19
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.
20
+ Creating tags can be tricky in monorepos, because we can release many packages at once: How do we create just 1 tag (no matter how many packages) and give it a name that resembles a [semantic version](https://semver.org/)?
21
+
22
+ Solution: We let the workspace root's version indicate the state of the whole project, then set the tag name to be this version. `update-workspace-root-version` helps you update the version automatically.
21
23
 
22
24
 
23
25
  ## Usage
@@ -59,19 +61,7 @@ update-workspace-root-version --algorithm increment-by-one
59
61
 
60
62
  ### Limitations
61
63
 
62
- The codemod is designed to cover typical cases. It is not designed to cover one-off cases.
63
-
64
- To better meet your needs, consider cloning the repo and running the codemod locally.
65
-
66
- ```sh
67
- cd <path/to/cloned/repo>
68
-
69
- # Compile TypeScript
70
- pnpm build
71
-
72
- # Run codemod
73
- ./dist/bin/update-workspace-root-version.js --root <path/to/your/project>
74
- ```
64
+ The codemod assumes that every package follows semantic versioning. It is designed to cover typical cases.
75
65
 
76
66
 
77
67
  ## Compatibility
@@ -1,4 +1,4 @@
1
- import { compare, increment } from '../utils/versions/index.js';
1
+ import { compare, increment } from '../utils/version/index.js';
2
2
  export function getNewVersion(packageVersions, workspaceRootVersion, options) {
3
3
  switch (options.algorithm) {
4
4
  case 'highest-version': {
@@ -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.map((packageRoot) => {
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
  }
@@ -0,0 +1,6 @@
1
+ export function allow(version) {
2
+ if (!version) {
3
+ return false;
4
+ }
5
+ return new RegExp(/^\d+\.\d+\.\d+$/).test(version);
6
+ }
@@ -1,2 +1,3 @@
1
+ export * from './allow.js';
1
2
  export * from './compare.js';
2
3
  export * from './increment.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "update-workspace-root-version",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Update the workspace root version in a monorepo",
5
5
  "keywords": [
6
6
  "codemod",
@@ -35,15 +35,15 @@
35
35
  "@sondr3/minitest": "^0.1.2",
36
36
  "@tsconfig/node18": "^18.2.4",
37
37
  "@tsconfig/strictest": "^2.0.5",
38
- "@types/node": "^18.19.47",
38
+ "@types/node": "^18.19.49",
39
39
  "@types/yargs": "^17.0.33",
40
- "@typescript-eslint/eslint-plugin": "^8.3.0",
41
- "@typescript-eslint/parser": "^8.3.0",
40
+ "@typescript-eslint/eslint-plugin": "^8.4.0",
41
+ "@typescript-eslint/parser": "^8.4.0",
42
42
  "concurrently": "^8.2.2",
43
43
  "eslint": "^8.57.0",
44
44
  "eslint-config-prettier": "^9.1.0",
45
45
  "eslint-import-resolver-typescript": "^3.6.3",
46
- "eslint-plugin-import": "^2.29.1",
46
+ "eslint-plugin-import": "^2.30.0",
47
47
  "eslint-plugin-n": "^17.10.2",
48
48
  "eslint-plugin-prettier": "^5.2.1",
49
49
  "eslint-plugin-simple-import-sort": "^12.1.1",
File without changes