@alexaegis/standard-version 0.14.0 → 0.15.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/dist/index.cjs ADDED
@@ -0,0 +1,165 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_path = require("node:path");
3
+ let glob = require("glob");
4
+ let js_yaml = require("js-yaml");
5
+ let node_fs = require("node:fs");
6
+ //#region src/workspace/collect-packages.ts
7
+ var PACKAGE_JSON_NAME = "package.json";
8
+ var PACKAGE_JSON_DEPENDENCY_FIELDS = [
9
+ "dependencies",
10
+ "devDependencies",
11
+ "optionalDependencies",
12
+ "peerDependencies"
13
+ ];
14
+ /**
15
+ * The functions found in this file are copied from @alexaegis/workspace-tools
16
+ * to be a sync, non-esm (globby is only esm) variant that could be invoked
17
+ * from a CJS based configuration file.
18
+ *
19
+ * ? Once standard-version/commit-and-version is migrated to ESM, this can be removed
20
+ */
21
+ var collectPackages = () => {
22
+ const workspaceRoot = getWorkspaceRoot();
23
+ if (!workspaceRoot) throw new Error("not in a workspace");
24
+ const pnpmWorkspace = (0, js_yaml.load)((0, node_fs.readFileSync)((0, node_path.join)(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" }));
25
+ const workspacePackageJsonPath = (0, node_path.join)(workspaceRoot, PACKAGE_JSON_NAME);
26
+ const workspacePackageJson = JSON.parse((0, node_fs.readFileSync)(workspacePackageJsonPath, { encoding: "utf8" }));
27
+ let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
28
+ if (pnpmWorkspace.packages) workspaces = [...workspaces, ...pnpmWorkspace.packages];
29
+ const packagePaths = (0, glob.globSync)(workspaces, {
30
+ ignore: ["node_modules"],
31
+ cwd: workspaceRoot,
32
+ absolute: true
33
+ }).filter((path) => (0, node_fs.statSync)(path).isDirectory());
34
+ return {
35
+ workspacePackage: {
36
+ packageKind: "root",
37
+ packagePath: workspaceRoot,
38
+ packageJson: workspacePackageJson,
39
+ packageJsonPath: workspacePackageJsonPath,
40
+ workspacePackagePatterns: workspaces,
41
+ packagePathFromRootPackage: "."
42
+ },
43
+ subPackages: packagePaths.map((packagePath) => {
44
+ const packageJsonPath = (0, node_path.join)(packagePath, PACKAGE_JSON_NAME);
45
+ try {
46
+ return {
47
+ packageKind: "regular",
48
+ packagePath: packagePath.toString(),
49
+ packageJsonPath,
50
+ packageJson: JSON.parse((0, node_fs.readFileSync)(packageJsonPath, { encoding: "utf8" })),
51
+ packagePathFromRootPackage: (0, node_path.relative)(workspaceRoot, (0, node_path.dirname)(packageJsonPath))
52
+ };
53
+ } catch {
54
+ return;
55
+ }
56
+ }).filter((pkg) => !!pkg)
57
+ };
58
+ };
59
+ var getWorkspaceRoot = (cwd = process.cwd()) => {
60
+ return collectPackageJsonPathsUpDirectoryTree(cwd)[0];
61
+ };
62
+ var collectPackageJsonPathsUpDirectoryTree = (cwd = process.cwd()) => {
63
+ return collectPackageJsonPathsUpDirectoryTreeInternal(cwd);
64
+ };
65
+ var collectPackageJsonPathsUpDirectoryTreeInternal = (cwd, collection = []) => {
66
+ const path = (0, node_path.normalize)(cwd);
67
+ if ((0, node_fs.existsSync)((0, node_path.join)(path, "package.json"))) collection.unshift(path);
68
+ const parentPath = (0, node_path.join)(path, "..");
69
+ if (parentPath !== path) return collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);
70
+ return collection;
71
+ };
72
+ var normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
73
+ if (Array.isArray(packageJsonWorkspaces)) return packageJsonWorkspaces;
74
+ else if (packageJsonWorkspaces) return [...packageJsonWorkspaces.packages ?? [], ...packageJsonWorkspaces.nohoist ?? []];
75
+ else return [];
76
+ };
77
+ //#endregion
78
+ //#region src/workspace/generic-updater.ts
79
+ /**
80
+ * This updater also updates all local dependencies too that were updated
81
+ * While it's mainly used for packageJson files, it does not assume the file to
82
+ * be valid JSON, so it can be used with any file that contains lines like
83
+ * "version": "0.0.0", like examples in readme files.
84
+ *
85
+ * It also replaces everything that looks like a `packageName@version`
86
+ */
87
+ var createGenericUpdater = (packages) => {
88
+ return {
89
+ readVersion: (contents) => {
90
+ return [...contents.matchAll(/"version": "(.*)"/g)][0]?.[1] ?? "0.0.0";
91
+ },
92
+ writeVersion: (contents, version) => {
93
+ return packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name).reduce((r, localPackageName) => r.replaceAll(new RegExp(`"${localPackageName}": "(workspace:)([~^])?.*"`, "g"), `"${localPackageName}": "$1$2"`).replaceAll(new RegExp(`"${localPackageName}": "(?!workspace:)([~^])?.*"`, "g"), `"${localPackageName}": "$1${version}"`).replaceAll(new RegExp(`${localPackageName}@([^s\t\n\r]+)`, "g"), `${localPackageName}@${version}`), contents.replace(/"version": ".*"/, `"version": "${version}"`));
94
+ }
95
+ };
96
+ };
97
+ //#endregion
98
+ //#region src/workspace/package-json-updater.ts
99
+ var workspaceDependencyVersionRegexp = /^(workspace:)([\^~])?.*$/g;
100
+ var nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\^~])?.*$/g;
101
+ /**
102
+ * This updater also updates all local dependencies too that were updated
103
+ * While it's mainly used for packageJson files, it does not assume the file to
104
+ * be valid JSON, so it can be used with any file that contains lines like
105
+ * "version": "0.0.0", like examples in readme files.
106
+ *
107
+ * It also replaces everything that looks like a `packageName@version`
108
+ */
109
+ var createPackageJsonUpdater = (packages) => {
110
+ return {
111
+ readVersion: (contents) => {
112
+ return [...contents.matchAll(/"version": "(.*)"/g)][0]?.[1] ?? "0.0.0";
113
+ },
114
+ writeVersion: (contents, version) => {
115
+ const packageJson = JSON.parse(contents);
116
+ const indent = " ";
117
+ const newline = contents.includes("\r\n") ? "\r\n" : "\n";
118
+ packageJson.version = version;
119
+ for (const localPackageName of packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name)) for (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {
120
+ const dependencies = packageJson[dependencyField];
121
+ const localDependency = dependencies?.[localPackageName];
122
+ if (dependencies && localDependency) dependencies[localPackageName] = localDependency.replaceAll(workspaceDependencyVersionRegexp, "$1$2").replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);
123
+ }
124
+ const json = JSON.stringify(packageJson, void 0, indent);
125
+ if (newline === "\r\n") return json.replaceAll("\n", "\r\n") + "\r\n";
126
+ return json + "\n";
127
+ }
128
+ };
129
+ };
130
+ //#endregion
131
+ //#region src/config/config.ts
132
+ var createStandardVersionConfig = () => {
133
+ const { workspacePackage, subPackages } = collectPackages();
134
+ const packageJsonUpdater = createPackageJsonUpdater(subPackages);
135
+ const genericUpdater = createGenericUpdater(subPackages);
136
+ return {
137
+ scripts: {
138
+ postbump: "pnpm install",
139
+ prechangelog: "git add pnpm-lock.yaml"
140
+ },
141
+ bumpFiles: [
142
+ {
143
+ filename: workspacePackage.packageJsonPath,
144
+ updater: packageJsonUpdater
145
+ },
146
+ {
147
+ filename: (0, node_path.join)(workspacePackage.packagePath, "readme.md"),
148
+ updater: genericUpdater
149
+ },
150
+ ...subPackages.map((pkg) => ({
151
+ filename: pkg.packageJsonPath,
152
+ updater: packageJsonUpdater
153
+ })),
154
+ ...subPackages.map((pkg) => ({
155
+ filename: (0, node_path.join)(pkg.packagePath, "readme.md"),
156
+ updater: genericUpdater
157
+ }))
158
+ ]
159
+ };
160
+ };
161
+ //#endregion
162
+ exports.collectPackages = collectPackages;
163
+ exports.createStandardVersionConfig = createStandardVersionConfig;
164
+
165
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/workspace/collect-packages.ts","../src/workspace/generic-updater.ts","../src/workspace/package-json-updater.ts","../src/config/config.ts"],"sourcesContent":["import type { PackageJson, PnpmWorkspaceYaml, WorkspacePackage } from '@alexaegis/workspace-tools';\nimport { globSync } from 'glob';\nimport { load } from 'js-yaml';\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join, normalize, relative } from 'node:path';\n\nconst PACKAGE_JSON_NAME = 'package.json';\n\nexport const PACKAGE_JSON_DEPENDENCY_FIELDS = [\n\t'dependencies',\n\t'devDependencies',\n\t'optionalDependencies',\n\t'peerDependencies',\n] as const;\n\n/**\n * The functions found in this file are copied from @alexaegis/workspace-tools\n * to be a sync, non-esm (globby is only esm) variant that could be invoked\n * from a CJS based configuration file.\n *\n * ? Once standard-version/commit-and-version is migrated to ESM, this can be removed\n */\nexport const collectPackages = (): {\n\tworkspacePackage: WorkspacePackage;\n\tsubPackages: WorkspacePackage[];\n} => {\n\tconst workspaceRoot = getWorkspaceRoot();\n\n\tif (!workspaceRoot) {\n\t\tthrow new Error('not in a workspace');\n\t}\n\n\tconst pnpmWorkspace = load(\n\t\treadFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), { encoding: 'utf8' }),\n\t) as PnpmWorkspaceYaml;\n\n\tconst workspacePackageJsonPath = join(workspaceRoot, PACKAGE_JSON_NAME);\n\tconst workspacePackageJson = JSON.parse(\n\t\treadFileSync(workspacePackageJsonPath, { encoding: 'utf8' }),\n\t) as PackageJson;\n\n\tlet workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);\n\n\tif (pnpmWorkspace.packages) {\n\t\tworkspaces = [...workspaces, ...pnpmWorkspace.packages];\n\t}\n\n\tconst packagePaths = globSync(workspaces, {\n\t\tignore: ['node_modules'],\n\t\tcwd: workspaceRoot,\n\t\tabsolute: true,\n\t}).filter((path) => statSync(path).isDirectory());\n\n\tconst workspacePackage: WorkspacePackage = {\n\t\tpackageKind: 'root',\n\t\tpackagePath: workspaceRoot,\n\t\tpackageJson: workspacePackageJson,\n\t\tpackageJsonPath: workspacePackageJsonPath,\n\t\tworkspacePackagePatterns: workspaces,\n\t\tpackagePathFromRootPackage: '.',\n\t};\n\tconst subPackages: WorkspacePackage[] = packagePaths\n\t\t.map((packagePath) => {\n\t\t\tconst packageJsonPath = join(packagePath, PACKAGE_JSON_NAME);\n\t\t\ttry {\n\t\t\t\treturn {\n\t\t\t\t\tpackageKind: 'regular',\n\t\t\t\t\tpackagePath: packagePath.toString(),\n\t\t\t\t\tpackageJsonPath,\n\t\t\t\t\tpackageJson: JSON.parse(\n\t\t\t\t\t\treadFileSync(packageJsonPath, { encoding: 'utf8' }),\n\t\t\t\t\t) as PackageJson,\n\t\t\t\t\tpackagePathFromRootPackage: relative(workspaceRoot, dirname(packageJsonPath)),\n\t\t\t\t} as WorkspacePackage;\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((pkg): pkg is WorkspacePackage => !!pkg);\n\n\treturn { workspacePackage, subPackages };\n};\n\nconst getWorkspaceRoot = (cwd: string = process.cwd()): string | undefined => {\n\treturn collectPackageJsonPathsUpDirectoryTree(cwd)[0];\n};\n\nconst collectPackageJsonPathsUpDirectoryTree = (cwd: string = process.cwd()): string[] => {\n\treturn collectPackageJsonPathsUpDirectoryTreeInternal(cwd);\n};\n\nconst collectPackageJsonPathsUpDirectoryTreeInternal = (\n\tcwd: string,\n\tcollection: string[] = [],\n): string[] => {\n\tconst path = normalize(cwd);\n\n\tif (existsSync(join(path, 'package.json'))) {\n\t\tcollection.unshift(path);\n\t}\n\n\tconst parentPath = join(path, '..');\n\tif (parentPath !== path) {\n\t\treturn collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);\n\t}\n\n\treturn collection;\n};\n\nconst normalizePackageJsonWorkspacesField = (\n\tpackageJsonWorkspaces?: PackageJson['workspaces'],\n): string[] => {\n\tif (Array.isArray(packageJsonWorkspaces)) {\n\t\treturn packageJsonWorkspaces;\n\t} else if (packageJsonWorkspaces) {\n\t\treturn [\n\t\t\t...(packageJsonWorkspaces.packages ?? []),\n\t\t\t...(packageJsonWorkspaces.nohoist ?? []),\n\t\t];\n\t} else {\n\t\treturn [];\n\t}\n};\n","import type { WorkspacePackage } from '@alexaegis/workspace-tools';\n\n/**\n * This updater also updates all local dependencies too that were updated\n * While it's mainly used for packageJson files, it does not assume the file to\n * be valid JSON, so it can be used with any file that contains lines like\n * \"version\": \"0.0.0\", like examples in readme files.\n *\n * It also replaces everything that looks like a `packageName@version`\n */\nexport const createGenericUpdater = (packages: WorkspacePackage[]) => {\n\treturn {\n\t\treadVersion: (contents: string): string => {\n\t\t\tconst results = [...contents.matchAll(/\"version\": \"(.*)\"/g)];\n\t\t\treturn results[0]?.[1] ?? '0.0.0';\n\t\t},\n\t\twriteVersion: (contents: string, version: string): string => {\n\t\t\treturn packages\n\t\t\t\t.map((localPackage) => localPackage.packageJson.name)\n\t\t\t\t.filter((name): name is string => !!name)\n\t\t\t\t.reduce(\n\t\t\t\t\t(r, localPackageName) =>\n\t\t\t\t\t\tr\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`\"${localPackageName}\": \"(workspace:)([~^])?.*\"`, 'g'),\n\t\t\t\t\t\t\t\t`\"${localPackageName}\": \"$1$2\"`, // the workspace protocol does not include versions but keeps the specifier. This is how pnpm leaves them on install.\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`\"${localPackageName}\": \"(?!workspace:)([~^])?.*\"`, 'g'),\n\t\t\t\t\t\t\t\t`\"${localPackageName}\": \"$1${version}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`${localPackageName}@([^s\\t\\n\\r]+)`, 'g'),\n\t\t\t\t\t\t\t\t`${localPackageName}@${version}`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\tcontents.replace(/\"version\": \".*\"/, `\"version\": \"${version}\"`),\n\t\t\t\t);\n\t\t},\n\t};\n};\n","import type { PackageJson, WorkspacePackage } from '@alexaegis/workspace-tools';\n\nimport { PACKAGE_JSON_DEPENDENCY_FIELDS } from './collect-packages.js';\n\nconst workspaceDependencyVersionRegexp = /^(workspace:)([\\^~])?.*$/g;\nconst nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\\^~])?.*$/g;\n\n/**\n * This updater also updates all local dependencies too that were updated\n * While it's mainly used for packageJson files, it does not assume the file to\n * be valid JSON, so it can be used with any file that contains lines like\n * \"version\": \"0.0.0\", like examples in readme files.\n *\n * It also replaces everything that looks like a `packageName@version`\n */\nexport const createPackageJsonUpdater = (packages: WorkspacePackage[]) => {\n\treturn {\n\t\treadVersion: (contents: string): string => {\n\t\t\tconst results = [...contents.matchAll(/\"version\": \"(.*)\"/g)];\n\t\t\treturn results[0]?.[1] ?? '0.0.0';\n\t\t},\n\t\twriteVersion: (contents: string, version: string): string => {\n\t\t\tconst packageJson: PackageJson = JSON.parse(contents) as PackageJson;\n\t\t\tconst indent = '\\t';\n\t\t\tconst newline = contents.includes('\\r\\n') ? '\\r\\n' : '\\n';\n\t\t\tpackageJson.version = version;\n\n\t\t\tfor (const localPackageName of packages\n\t\t\t\t.map((localPackage) => localPackage.packageJson.name)\n\t\t\t\t.filter((name): name is string => !!name)) {\n\t\t\t\tfor (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {\n\t\t\t\t\tconst dependencies = packageJson[dependencyField];\n\n\t\t\t\t\tconst localDependency: string | undefined = dependencies?.[localPackageName];\n\n\t\t\t\t\tif (dependencies && localDependency) {\n\t\t\t\t\t\tdependencies[localPackageName] = localDependency\n\t\t\t\t\t\t\t.replaceAll(workspaceDependencyVersionRegexp, '$1$2')\n\t\t\t\t\t\t\t.replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst json = JSON.stringify(packageJson, undefined, indent);\n\n\t\t\tif (newline === '\\r\\n') {\n\t\t\t\treturn json.replaceAll('\\n', '\\r\\n') + '\\r\\n';\n\t\t\t}\n\n\t\t\treturn json + '\\n';\n\t\t},\n\t};\n};\n","import { join } from 'node:path';\nimport { collectPackages } from '../workspace/collect-packages.js';\nimport { createGenericUpdater } from '../workspace/generic-updater.js';\nimport { createPackageJsonUpdater } from '../workspace/package-json-updater.js';\n\nexport const createStandardVersionConfig = () => {\n\tconst { workspacePackage, subPackages } = collectPackages();\n\tconst packageJsonUpdater = createPackageJsonUpdater(subPackages);\n\tconst genericUpdater = createGenericUpdater(subPackages);\n\n\treturn {\n\t\tscripts: {\n\t\t\tpostbump: 'pnpm install',\n\t\t\tprechangelog: 'git add pnpm-lock.yaml',\n\t\t},\n\t\tbumpFiles: [\n\t\t\t{\n\t\t\t\tfilename: workspacePackage.packageJsonPath,\n\t\t\t\tupdater: packageJsonUpdater,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.packagePath, 'readme.md'),\n\t\t\t\tupdater: genericUpdater,\n\t\t\t},\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: pkg.packageJsonPath,\n\t\t\t\tupdater: packageJsonUpdater,\n\t\t\t})),\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: join(pkg.packagePath, 'readme.md'),\n\t\t\t\tupdater: genericUpdater,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"mappings":";;;;;;AAMA,IAAM,oBAAoB;AAE1B,IAAa,iCAAiC;CAC7C;CACA;CACA;CACA;CACA;;;;;;;;AASD,IAAa,wBAGR;CACJ,MAAM,gBAAgB,kBAAkB;AAExC,KAAI,CAAC,cACJ,OAAM,IAAI,MAAM,qBAAqB;CAGtC,MAAM,iBAAA,GAAA,QAAA,OAAA,GAAA,QAAA,eAAA,GAAA,UAAA,MACa,eAAe,sBAAsB,EAAE,EAAE,UAAU,QAAQ,CAAC,CAC9E;CAED,MAAM,4BAAA,GAAA,UAAA,MAAgC,eAAe,kBAAkB;CACvE,MAAM,uBAAuB,KAAK,OAAA,GAAA,QAAA,cACpB,0BAA0B,EAAE,UAAU,QAAQ,CAAC,CAC5D;CAED,IAAI,aAAa,oCAAoC,qBAAqB,WAAW;AAErF,KAAI,cAAc,SACjB,cAAa,CAAC,GAAG,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AAoB,gBAC/B,WAAW,kCAAkC,OAAO,CACpD,WAAW,qCAAqC,KAAK,UAAU;;GAKpE,MAAM,OAAO,KAAK,UAAU,aAAa,KAAA,GAAW,OAAO;AAE3D,OAAI,YAAY,OACf,QAAO,KAAK,WAAW,MAAM,OAAO,GAAG;AAGxC,UAAO,OAAO;;EAEf;;;;AC9CF,IAAa,oCAAoC;CAChD,MAAM,EAAE,kBAAkB,gBAAgB,iBAAiB;CAC3D,MAAM,qBAAqB,yBAAyB,YAAY;CAChE,MAAM,iBAAiB,qBAAqB,YAAY;AAExD,QAAO;EACN,SAAS;GACR,UAAU;GACV,cAAc;GACd;EACD,WAAW;GACV;IACC,UAAU,iBAAiB;IAC3B,SAAS;IACT;GACD;IACC,WAAA,GAAA,UAAA,MAAe,iBAAiB,aAAa,YAAY;IACzD,SAAS;IACT;GACD,GAAG,YAAY,KAAK,SAAS;IAC5B,UAAU,IAAI;IACd,SAAS;IACT,EAAE;GACH,GAAG,YAAY,KAAK,SAAS;IAC5B,WAAA,GAAA,UAAA,MAAe,IAAI,aAAa,YAAY;IAC5C,SAAS;IACT,EAAE;GACH;EACD"}
package/dist/index.js ADDED
@@ -0,0 +1,163 @@
1
+ import { dirname, join, normalize, relative } from "node:path";
2
+ import { globSync } from "glob";
3
+ import { load } from "js-yaml";
4
+ import { existsSync, readFileSync, statSync } from "node:fs";
5
+ //#region src/workspace/collect-packages.ts
6
+ var PACKAGE_JSON_NAME = "package.json";
7
+ var PACKAGE_JSON_DEPENDENCY_FIELDS = [
8
+ "dependencies",
9
+ "devDependencies",
10
+ "optionalDependencies",
11
+ "peerDependencies"
12
+ ];
13
+ /**
14
+ * The functions found in this file are copied from @alexaegis/workspace-tools
15
+ * to be a sync, non-esm (globby is only esm) variant that could be invoked
16
+ * from a CJS based configuration file.
17
+ *
18
+ * ? Once standard-version/commit-and-version is migrated to ESM, this can be removed
19
+ */
20
+ var collectPackages = () => {
21
+ const workspaceRoot = getWorkspaceRoot();
22
+ if (!workspaceRoot) throw new Error("not in a workspace");
23
+ const pnpmWorkspace = load(readFileSync(join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" }));
24
+ const workspacePackageJsonPath = join(workspaceRoot, PACKAGE_JSON_NAME);
25
+ const workspacePackageJson = JSON.parse(readFileSync(workspacePackageJsonPath, { encoding: "utf8" }));
26
+ let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
27
+ if (pnpmWorkspace.packages) workspaces = [...workspaces, ...pnpmWorkspace.packages];
28
+ const packagePaths = globSync(workspaces, {
29
+ ignore: ["node_modules"],
30
+ cwd: workspaceRoot,
31
+ absolute: true
32
+ }).filter((path) => statSync(path).isDirectory());
33
+ return {
34
+ workspacePackage: {
35
+ packageKind: "root",
36
+ packagePath: workspaceRoot,
37
+ packageJson: workspacePackageJson,
38
+ packageJsonPath: workspacePackageJsonPath,
39
+ workspacePackagePatterns: workspaces,
40
+ packagePathFromRootPackage: "."
41
+ },
42
+ subPackages: packagePaths.map((packagePath) => {
43
+ const packageJsonPath = join(packagePath, PACKAGE_JSON_NAME);
44
+ try {
45
+ return {
46
+ packageKind: "regular",
47
+ packagePath: packagePath.toString(),
48
+ packageJsonPath,
49
+ packageJson: JSON.parse(readFileSync(packageJsonPath, { encoding: "utf8" })),
50
+ packagePathFromRootPackage: relative(workspaceRoot, dirname(packageJsonPath))
51
+ };
52
+ } catch {
53
+ return;
54
+ }
55
+ }).filter((pkg) => !!pkg)
56
+ };
57
+ };
58
+ var getWorkspaceRoot = (cwd = process.cwd()) => {
59
+ return collectPackageJsonPathsUpDirectoryTree(cwd)[0];
60
+ };
61
+ var collectPackageJsonPathsUpDirectoryTree = (cwd = process.cwd()) => {
62
+ return collectPackageJsonPathsUpDirectoryTreeInternal(cwd);
63
+ };
64
+ var collectPackageJsonPathsUpDirectoryTreeInternal = (cwd, collection = []) => {
65
+ const path = normalize(cwd);
66
+ if (existsSync(join(path, "package.json"))) collection.unshift(path);
67
+ const parentPath = join(path, "..");
68
+ if (parentPath !== path) return collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);
69
+ return collection;
70
+ };
71
+ var normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
72
+ if (Array.isArray(packageJsonWorkspaces)) return packageJsonWorkspaces;
73
+ else if (packageJsonWorkspaces) return [...packageJsonWorkspaces.packages ?? [], ...packageJsonWorkspaces.nohoist ?? []];
74
+ else return [];
75
+ };
76
+ //#endregion
77
+ //#region src/workspace/generic-updater.ts
78
+ /**
79
+ * This updater also updates all local dependencies too that were updated
80
+ * While it's mainly used for packageJson files, it does not assume the file to
81
+ * be valid JSON, so it can be used with any file that contains lines like
82
+ * "version": "0.0.0", like examples in readme files.
83
+ *
84
+ * It also replaces everything that looks like a `packageName@version`
85
+ */
86
+ var createGenericUpdater = (packages) => {
87
+ return {
88
+ readVersion: (contents) => {
89
+ return [...contents.matchAll(/"version": "(.*)"/g)][0]?.[1] ?? "0.0.0";
90
+ },
91
+ writeVersion: (contents, version) => {
92
+ return packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name).reduce((r, localPackageName) => r.replaceAll(new RegExp(`"${localPackageName}": "(workspace:)([~^])?.*"`, "g"), `"${localPackageName}": "$1$2"`).replaceAll(new RegExp(`"${localPackageName}": "(?!workspace:)([~^])?.*"`, "g"), `"${localPackageName}": "$1${version}"`).replaceAll(new RegExp(`${localPackageName}@([^s\t\n\r]+)`, "g"), `${localPackageName}@${version}`), contents.replace(/"version": ".*"/, `"version": "${version}"`));
93
+ }
94
+ };
95
+ };
96
+ //#endregion
97
+ //#region src/workspace/package-json-updater.ts
98
+ var workspaceDependencyVersionRegexp = /^(workspace:)([\^~])?.*$/g;
99
+ var nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\^~])?.*$/g;
100
+ /**
101
+ * This updater also updates all local dependencies too that were updated
102
+ * While it's mainly used for packageJson files, it does not assume the file to
103
+ * be valid JSON, so it can be used with any file that contains lines like
104
+ * "version": "0.0.0", like examples in readme files.
105
+ *
106
+ * It also replaces everything that looks like a `packageName@version`
107
+ */
108
+ var createPackageJsonUpdater = (packages) => {
109
+ return {
110
+ readVersion: (contents) => {
111
+ return [...contents.matchAll(/"version": "(.*)"/g)][0]?.[1] ?? "0.0.0";
112
+ },
113
+ writeVersion: (contents, version) => {
114
+ const packageJson = JSON.parse(contents);
115
+ const indent = " ";
116
+ const newline = contents.includes("\r\n") ? "\r\n" : "\n";
117
+ packageJson.version = version;
118
+ for (const localPackageName of packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name)) for (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {
119
+ const dependencies = packageJson[dependencyField];
120
+ const localDependency = dependencies?.[localPackageName];
121
+ if (dependencies && localDependency) dependencies[localPackageName] = localDependency.replaceAll(workspaceDependencyVersionRegexp, "$1$2").replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);
122
+ }
123
+ const json = JSON.stringify(packageJson, void 0, indent);
124
+ if (newline === "\r\n") return json.replaceAll("\n", "\r\n") + "\r\n";
125
+ return json + "\n";
126
+ }
127
+ };
128
+ };
129
+ //#endregion
130
+ //#region src/config/config.ts
131
+ var createStandardVersionConfig = () => {
132
+ const { workspacePackage, subPackages } = collectPackages();
133
+ const packageJsonUpdater = createPackageJsonUpdater(subPackages);
134
+ const genericUpdater = createGenericUpdater(subPackages);
135
+ return {
136
+ scripts: {
137
+ postbump: "pnpm install",
138
+ prechangelog: "git add pnpm-lock.yaml"
139
+ },
140
+ bumpFiles: [
141
+ {
142
+ filename: workspacePackage.packageJsonPath,
143
+ updater: packageJsonUpdater
144
+ },
145
+ {
146
+ filename: join(workspacePackage.packagePath, "readme.md"),
147
+ updater: genericUpdater
148
+ },
149
+ ...subPackages.map((pkg) => ({
150
+ filename: pkg.packageJsonPath,
151
+ updater: packageJsonUpdater
152
+ })),
153
+ ...subPackages.map((pkg) => ({
154
+ filename: join(pkg.packagePath, "readme.md"),
155
+ updater: genericUpdater
156
+ }))
157
+ ]
158
+ };
159
+ };
160
+ //#endregion
161
+ export { collectPackages, createStandardVersionConfig };
162
+
163
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/workspace/collect-packages.ts","../src/workspace/generic-updater.ts","../src/workspace/package-json-updater.ts","../src/config/config.ts"],"sourcesContent":["import type { PackageJson, PnpmWorkspaceYaml, WorkspacePackage } from '@alexaegis/workspace-tools';\nimport { globSync } from 'glob';\nimport { load } from 'js-yaml';\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join, normalize, relative } from 'node:path';\n\nconst PACKAGE_JSON_NAME = 'package.json';\n\nexport const PACKAGE_JSON_DEPENDENCY_FIELDS = [\n\t'dependencies',\n\t'devDependencies',\n\t'optionalDependencies',\n\t'peerDependencies',\n] as const;\n\n/**\n * The functions found in this file are copied from @alexaegis/workspace-tools\n * to be a sync, non-esm (globby is only esm) variant that could be invoked\n * from a CJS based configuration file.\n *\n * ? Once standard-version/commit-and-version is migrated to ESM, this can be removed\n */\nexport const collectPackages = (): {\n\tworkspacePackage: WorkspacePackage;\n\tsubPackages: WorkspacePackage[];\n} => {\n\tconst workspaceRoot = getWorkspaceRoot();\n\n\tif (!workspaceRoot) {\n\t\tthrow new Error('not in a workspace');\n\t}\n\n\tconst pnpmWorkspace = load(\n\t\treadFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), { encoding: 'utf8' }),\n\t) as PnpmWorkspaceYaml;\n\n\tconst workspacePackageJsonPath = join(workspaceRoot, PACKAGE_JSON_NAME);\n\tconst workspacePackageJson = JSON.parse(\n\t\treadFileSync(workspacePackageJsonPath, { encoding: 'utf8' }),\n\t) as PackageJson;\n\n\tlet workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);\n\n\tif (pnpmWorkspace.packages) {\n\t\tworkspaces = [...workspaces, ...pnpmWorkspace.packages];\n\t}\n\n\tconst packagePaths = globSync(workspaces, {\n\t\tignore: ['node_modules'],\n\t\tcwd: workspaceRoot,\n\t\tabsolute: true,\n\t}).filter((path) => statSync(path).isDirectory());\n\n\tconst workspacePackage: WorkspacePackage = {\n\t\tpackageKind: 'root',\n\t\tpackagePath: workspaceRoot,\n\t\tpackageJson: workspacePackageJson,\n\t\tpackageJsonPath: workspacePackageJsonPath,\n\t\tworkspacePackagePatterns: workspaces,\n\t\tpackagePathFromRootPackage: '.',\n\t};\n\tconst subPackages: WorkspacePackage[] = packagePaths\n\t\t.map((packagePath) => {\n\t\t\tconst packageJsonPath = join(packagePath, PACKAGE_JSON_NAME);\n\t\t\ttry {\n\t\t\t\treturn {\n\t\t\t\t\tpackageKind: 'regular',\n\t\t\t\t\tpackagePath: packagePath.toString(),\n\t\t\t\t\tpackageJsonPath,\n\t\t\t\t\tpackageJson: JSON.parse(\n\t\t\t\t\t\treadFileSync(packageJsonPath, { encoding: 'utf8' }),\n\t\t\t\t\t) as PackageJson,\n\t\t\t\t\tpackagePathFromRootPackage: relative(workspaceRoot, dirname(packageJsonPath)),\n\t\t\t\t} as WorkspacePackage;\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((pkg): pkg is WorkspacePackage => !!pkg);\n\n\treturn { workspacePackage, subPackages };\n};\n\nconst getWorkspaceRoot = (cwd: string = process.cwd()): string | undefined => {\n\treturn collectPackageJsonPathsUpDirectoryTree(cwd)[0];\n};\n\nconst collectPackageJsonPathsUpDirectoryTree = (cwd: string = process.cwd()): string[] => {\n\treturn collectPackageJsonPathsUpDirectoryTreeInternal(cwd);\n};\n\nconst collectPackageJsonPathsUpDirectoryTreeInternal = (\n\tcwd: string,\n\tcollection: string[] = [],\n): string[] => {\n\tconst path = normalize(cwd);\n\n\tif (existsSync(join(path, 'package.json'))) {\n\t\tcollection.unshift(path);\n\t}\n\n\tconst parentPath = join(path, '..');\n\tif (parentPath !== path) {\n\t\treturn collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);\n\t}\n\n\treturn collection;\n};\n\nconst normalizePackageJsonWorkspacesField = (\n\tpackageJsonWorkspaces?: PackageJson['workspaces'],\n): string[] => {\n\tif (Array.isArray(packageJsonWorkspaces)) {\n\t\treturn packageJsonWorkspaces;\n\t} else if (packageJsonWorkspaces) {\n\t\treturn [\n\t\t\t...(packageJsonWorkspaces.packages ?? []),\n\t\t\t...(packageJsonWorkspaces.nohoist ?? []),\n\t\t];\n\t} else {\n\t\treturn [];\n\t}\n};\n","import type { WorkspacePackage } from '@alexaegis/workspace-tools';\n\n/**\n * This updater also updates all local dependencies too that were updated\n * While it's mainly used for packageJson files, it does not assume the file to\n * be valid JSON, so it can be used with any file that contains lines like\n * \"version\": \"0.0.0\", like examples in readme files.\n *\n * It also replaces everything that looks like a `packageName@version`\n */\nexport const createGenericUpdater = (packages: WorkspacePackage[]) => {\n\treturn {\n\t\treadVersion: (contents: string): string => {\n\t\t\tconst results = [...contents.matchAll(/\"version\": \"(.*)\"/g)];\n\t\t\treturn results[0]?.[1] ?? '0.0.0';\n\t\t},\n\t\twriteVersion: (contents: string, version: string): string => {\n\t\t\treturn packages\n\t\t\t\t.map((localPackage) => localPackage.packageJson.name)\n\t\t\t\t.filter((name): name is string => !!name)\n\t\t\t\t.reduce(\n\t\t\t\t\t(r, localPackageName) =>\n\t\t\t\t\t\tr\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`\"${localPackageName}\": \"(workspace:)([~^])?.*\"`, 'g'),\n\t\t\t\t\t\t\t\t`\"${localPackageName}\": \"$1$2\"`, // the workspace protocol does not include versions but keeps the specifier. This is how pnpm leaves them on install.\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`\"${localPackageName}\": \"(?!workspace:)([~^])?.*\"`, 'g'),\n\t\t\t\t\t\t\t\t`\"${localPackageName}\": \"$1${version}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`${localPackageName}@([^s\\t\\n\\r]+)`, 'g'),\n\t\t\t\t\t\t\t\t`${localPackageName}@${version}`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\tcontents.replace(/\"version\": \".*\"/, `\"version\": \"${version}\"`),\n\t\t\t\t);\n\t\t},\n\t};\n};\n","import type { PackageJson, WorkspacePackage } from '@alexaegis/workspace-tools';\n\nimport { PACKAGE_JSON_DEPENDENCY_FIELDS } from './collect-packages.js';\n\nconst workspaceDependencyVersionRegexp = /^(workspace:)([\\^~])?.*$/g;\nconst nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\\^~])?.*$/g;\n\n/**\n * This updater also updates all local dependencies too that were updated\n * While it's mainly used for packageJson files, it does not assume the file to\n * be valid JSON, so it can be used with any file that contains lines like\n * \"version\": \"0.0.0\", like examples in readme files.\n *\n * It also replaces everything that looks like a `packageName@version`\n */\nexport const createPackageJsonUpdater = (packages: WorkspacePackage[]) => {\n\treturn {\n\t\treadVersion: (contents: string): string => {\n\t\t\tconst results = [...contents.matchAll(/\"version\": \"(.*)\"/g)];\n\t\t\treturn results[0]?.[1] ?? '0.0.0';\n\t\t},\n\t\twriteVersion: (contents: string, version: string): string => {\n\t\t\tconst packageJson: PackageJson = JSON.parse(contents) as PackageJson;\n\t\t\tconst indent = '\\t';\n\t\t\tconst newline = contents.includes('\\r\\n') ? '\\r\\n' : '\\n';\n\t\t\tpackageJson.version = version;\n\n\t\t\tfor (const localPackageName of packages\n\t\t\t\t.map((localPackage) => localPackage.packageJson.name)\n\t\t\t\t.filter((name): name is string => !!name)) {\n\t\t\t\tfor (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {\n\t\t\t\t\tconst dependencies = packageJson[dependencyField];\n\n\t\t\t\t\tconst localDependency: string | undefined = dependencies?.[localPackageName];\n\n\t\t\t\t\tif (dependencies && localDependency) {\n\t\t\t\t\t\tdependencies[localPackageName] = localDependency\n\t\t\t\t\t\t\t.replaceAll(workspaceDependencyVersionRegexp, '$1$2')\n\t\t\t\t\t\t\t.replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst json = JSON.stringify(packageJson, undefined, indent);\n\n\t\t\tif (newline === '\\r\\n') {\n\t\t\t\treturn json.replaceAll('\\n', '\\r\\n') + '\\r\\n';\n\t\t\t}\n\n\t\t\treturn json + '\\n';\n\t\t},\n\t};\n};\n","import { join } from 'node:path';\nimport { collectPackages } from '../workspace/collect-packages.js';\nimport { createGenericUpdater } from '../workspace/generic-updater.js';\nimport { createPackageJsonUpdater } from '../workspace/package-json-updater.js';\n\nexport const createStandardVersionConfig = () => {\n\tconst { workspacePackage, subPackages } = collectPackages();\n\tconst packageJsonUpdater = createPackageJsonUpdater(subPackages);\n\tconst genericUpdater = createGenericUpdater(subPackages);\n\n\treturn {\n\t\tscripts: {\n\t\t\tpostbump: 'pnpm install',\n\t\t\tprechangelog: 'git add pnpm-lock.yaml',\n\t\t},\n\t\tbumpFiles: [\n\t\t\t{\n\t\t\t\tfilename: workspacePackage.packageJsonPath,\n\t\t\t\tupdater: packageJsonUpdater,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.packagePath, 'readme.md'),\n\t\t\t\tupdater: genericUpdater,\n\t\t\t},\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: pkg.packageJsonPath,\n\t\t\t\tupdater: packageJsonUpdater,\n\t\t\t})),\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: join(pkg.packagePath, 'readme.md'),\n\t\t\t\tupdater: genericUpdater,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"mappings":";;;;;AAMA,IAAM,oBAAoB;AAE1B,IAAa,iCAAiC;CAC7C;CACA;CACA;CACA;CACA;;;;;;;;AASD,IAAa,wBAGR;CACJ,MAAM,gBAAgB,kBAAkB;AAExC,KAAI,CAAC,cACJ,OAAM,IA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,aAAa,YAAY,KAAK,CACpD,QAAQ,SAAyB,CAAC,CAAC,KAAK,CACzC,MAAK,MAAM,mBAAmB,gCAAgC;IAC7D,MAAM,eAAe,YAAY;IAEjC,MAAM,kBAAsC,eAAe;AAE3D,QAAI,gBAAgB,gBACnB,cAAa,oBAAoB,gBAC/B,WAAW,kCAAkC,OAAO,CACpD,WAAW,qCAAqC,KAAK,UAAU;;GAKpE,MAAM,OAAO,KAAK,UAAU,aAAa,KAAA,GAAW,OAAO;AAE3D,OAAI,YAAY,OACf,QAAO,KAAK,WAAW,MAAM,OAAO,GAAG;AAGxC,UAAO,OAAO;;EAEf;;;;AC9CF,IAAa,oCAAoC;CAChD,MAAM,EAAE,kBAAkB,gBAAgB,iBAAiB;CAC3D,MAAM,qBAAqB,yBAAyB,YAAY;CAChE,MAAM,iBAAiB,qBAAqB,YAAY;AAExD,QAAO;EACN,SAAS;GACR,UAAU;GACV,cAAc;GACd;EACD,WAAW;GACV;IACC,UAAU,iBAAiB;IAC3B,SAAS;IACT;GACD;IACC,UAAU,KAAK,iBAAiB,aAAa,YAAY;IACzD,SAAS;IACT;GACD,GAAG,YAAY,KAAK,SAAS;IAC5B,UAAU,IAAI;IACd,SAAS;IACT,EAAE;GACH,GAAG,YAAY,KAAK,SAAS;IAC5B,UAAU,KAAK,IAAI,aAAa,YAAY;IAC5C,SAAS;IACT,EAAE;GACH;EACD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alexaegis/standard-version",
3
3
  "description": "Standard version",
4
- "version": "0.14.0",
4
+ "version": "0.15.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "archetype": {
@@ -15,59 +15,45 @@
15
15
  "managed-by-autotool",
16
16
  "standard-version"
17
17
  ],
18
- "author": {
19
- "email": "alexaegis@pm.me",
20
- "name": "Alex Aegis",
21
- "url": "https://github.com/AlexAegis"
22
- },
23
- "homepage": "https://github.com/AlexAegis/js-tooling",
24
18
  "repository": {
25
19
  "url": "git+https://github.com/AlexAegis/js-tooling",
26
- "type": "git",
27
- "directory": "packages/standard-version"
28
- },
29
- "bugs": {
30
- "email": "alexaegis@pm.me",
31
- "url": "https://github.com/AlexAegis/js-tooling/issues"
20
+ "type": "git"
32
21
  },
33
22
  "type": "module",
34
- "config": {
35
- "engine-strict": true
36
- },
37
23
  "publishConfig": {
38
24
  "access": "public"
39
25
  },
40
- "engines": {
41
- "node": ">=20",
42
- "pnpm": ">=9"
43
- },
26
+ "files": [
27
+ "dist"
28
+ ],
44
29
  "exports": {
45
30
  ".": {
46
- "types": "./index.d.ts",
47
- "import": "./index.js",
48
- "require": "./index.cjs",
49
- "default": "./index.js"
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/index.cjs",
34
+ "default": "./dist/index.js"
50
35
  },
51
36
  "./package.json": "./package.json",
52
37
  "./readme": "./readme.md"
53
38
  },
54
39
  "dependencies": {
55
- "@alexaegis/coverage-tools": "^0.11.0",
56
- "@alexaegis/workspace-tools": "^0.11.0",
57
- "glob": "^11.0.1",
58
- "js-yaml": "^4.1.0"
40
+ "glob": "^13.0.6",
41
+ "js-yaml": "^4.1.1",
42
+ "@alexaegis/coverage-tools": "^0.15.0",
43
+ "@alexaegis/workspace-tools": "^0.15.0"
59
44
  },
60
45
  "devDependencies": {
61
- "@alexaegis/eslint-config-vitest": "^0.14.0",
62
- "@alexaegis/ts": "^0.14.0",
63
- "@alexaegis/vite": "^0.14.0",
64
- "@alexaegis/vitest": "^0.14.0",
65
46
  "@types/js-yaml": "^4.0.9",
66
- "@types/node": "^22.14.1",
67
- "publint": "^0.3.12",
68
- "typescript": "^5.8.3",
69
- "vite": "^6.3.2",
70
- "vitest": "^3.1.1"
47
+ "@types/node": "^25.5.0",
48
+ "publint": "^0.3.18",
49
+ "typescript": "^5.9.3",
50
+ "vite": "^8.0.1",
51
+ "vite-plugin-dts": "^4.5.4",
52
+ "vitest": "^4.1.0",
53
+ "@alexaegis/vite": "^0.15.0",
54
+ "@alexaegis/eslint-config-vitest": "^0.15.0",
55
+ "@alexaegis/ts": "^0.15.0",
56
+ "@alexaegis/vitest": "^0.15.0"
71
57
  },
72
58
  "scripts": {
73
59
  "lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --filter @alexaegis/standard-version",
@@ -81,7 +67,7 @@
81
67
  "lint:tsc": "turbo run lint:tsc_ --concurrency 16 --filter @alexaegis/standard-version",
82
68
  "lint:tsc_": "tsc --noEmit",
83
69
  "publint": "BUILD_REASON='publish' turbo run publint_ --concurrency 16 --filter @alexaegis/standard-version",
84
- "publint_": "publint dist",
70
+ "publint_": "publint",
85
71
  "test": "turbo run test_ --concurrency 16 --filter @alexaegis/standard-version",
86
72
  "test_": "vitest --passWithNoTests --coverage --run",
87
73
  "test:watch": "vitest --passWithNoTests --coverage",
package/readme.md CHANGED
@@ -12,13 +12,13 @@ functions had to be reimplemented, albeit in a much simpler form.
12
12
  ## Installation
13
13
 
14
14
  ```sh
15
- npm i @alexaegis/standard-version@0.14.0
15
+ npm i @alexaegis/standard-version@0.15.0
16
16
  ```
17
17
 
18
18
  ```json
19
19
  {
20
20
  "dependencies": {
21
- "@alexaegis/standard-version": "^0.14.0"
21
+ "@alexaegis/standard-version": "^0.15.0"
22
22
  }
23
23
  }
24
24
  ```
package/index.cjs DELETED
@@ -1,175 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_path = require("node:path");
4
- const glob = require("glob");
5
- const jsYaml = require("js-yaml");
6
- const node_fs = require("node:fs");
7
- const PACKAGE_JSON_NAME = "package.json";
8
- const PACKAGE_JSON_DEPENDENCY_FIELDS = [
9
- "dependencies",
10
- "devDependencies",
11
- "optionalDependencies",
12
- "peerDependencies"
13
- ];
14
- const collectPackages = () => {
15
- const workspaceRoot = getWorkspaceRoot();
16
- if (!workspaceRoot) {
17
- throw new Error("not in a workspace");
18
- }
19
- const pnpmWorkspace = jsYaml.load(
20
- node_fs.readFileSync(node_path.join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" })
21
- );
22
- const workspacePackageJsonPath = node_path.join(workspaceRoot, PACKAGE_JSON_NAME);
23
- const workspacePackageJson = JSON.parse(
24
- node_fs.readFileSync(workspacePackageJsonPath, { encoding: "utf8" })
25
- );
26
- let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
27
- if (pnpmWorkspace.packages) {
28
- workspaces = [...workspaces, ...pnpmWorkspace.packages];
29
- }
30
- const packagePaths = glob.globSync(workspaces, {
31
- ignore: ["node_modules"],
32
- cwd: workspaceRoot,
33
- absolute: true
34
- }).filter((path) => node_fs.statSync(path).isDirectory());
35
- const workspacePackage = {
36
- packageKind: "root",
37
- packagePath: workspaceRoot,
38
- packageJson: workspacePackageJson,
39
- packageJsonPath: workspacePackageJsonPath,
40
- workspacePackagePatterns: workspaces,
41
- packagePathFromRootPackage: "."
42
- };
43
- const subPackages = packagePaths.map((packagePath) => {
44
- const packageJsonPath = node_path.join(packagePath, PACKAGE_JSON_NAME);
45
- try {
46
- return {
47
- packageKind: "regular",
48
- packagePath: packagePath.toString(),
49
- packageJsonPath,
50
- packageJson: JSON.parse(
51
- node_fs.readFileSync(packageJsonPath, { encoding: "utf8" })
52
- ),
53
- packagePathFromRootPackage: node_path.relative(workspaceRoot, node_path.dirname(packageJsonPath))
54
- };
55
- } catch {
56
- return void 0;
57
- }
58
- }).filter((pkg) => !!pkg);
59
- return { workspacePackage, subPackages };
60
- };
61
- const getWorkspaceRoot = (cwd = process.cwd()) => {
62
- return collectPackageJsonPathsUpDirectoryTree(cwd)[0];
63
- };
64
- const collectPackageJsonPathsUpDirectoryTree = (cwd = process.cwd()) => {
65
- return collectPackageJsonPathsUpDirectoryTreeInternal(cwd);
66
- };
67
- const collectPackageJsonPathsUpDirectoryTreeInternal = (cwd, collection = []) => {
68
- const path = node_path.normalize(cwd);
69
- if (node_fs.existsSync(node_path.join(path, "package.json"))) {
70
- collection.unshift(path);
71
- }
72
- const parentPath = node_path.join(path, "..");
73
- if (parentPath !== path) {
74
- return collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);
75
- }
76
- return collection;
77
- };
78
- const normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
79
- if (Array.isArray(packageJsonWorkspaces)) {
80
- return packageJsonWorkspaces;
81
- } else if (packageJsonWorkspaces) {
82
- return [
83
- ...packageJsonWorkspaces.packages ?? [],
84
- ...packageJsonWorkspaces.nohoist ?? []
85
- ];
86
- } else {
87
- return [];
88
- }
89
- };
90
- const createGenericUpdater = (packages) => {
91
- return {
92
- readVersion: (contents) => {
93
- const results = [...contents.matchAll(/"version": "(.*)"/g)];
94
- return results[0]?.[1] ?? "0.0.0";
95
- },
96
- writeVersion: (contents, version) => {
97
- return packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name).reduce(
98
- (r, localPackageName) => r.replaceAll(
99
- new RegExp(`"${localPackageName}": "(workspace:)([~^])?.*"`, "g"),
100
- `"${localPackageName}": "$1$2"`
101
- // the workspace protocol does not include versions but keeps the specifier. This is how pnpm leaves them on install.
102
- ).replaceAll(
103
- new RegExp(`"${localPackageName}": "(?!workspace:)([~^])?.*"`, "g"),
104
- `"${localPackageName}": "$1${version}"`
105
- ).replaceAll(
106
- new RegExp(`${localPackageName}@([^s
107
- \r]+)`, "g"),
108
- `${localPackageName}@${version}`
109
- ),
110
- contents.replace(/"version": ".*"/, `"version": "${version}"`)
111
- );
112
- }
113
- };
114
- };
115
- const workspaceDependencyVersionRegexp = /^(workspace:)([\^~])?.*$/g;
116
- const nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\^~])?.*$/g;
117
- const createPackageJsonUpdater = (packages) => {
118
- return {
119
- readVersion: (contents) => {
120
- const results = [...contents.matchAll(/"version": "(.*)"/g)];
121
- return results[0]?.[1] ?? "0.0.0";
122
- },
123
- writeVersion: (contents, version) => {
124
- const packageJson = JSON.parse(contents);
125
- const indent = " ";
126
- const newline = contents.includes("\r\n") ? "\r\n" : "\n";
127
- packageJson.version = version;
128
- for (const localPackageName of packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name)) {
129
- for (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {
130
- const dependencies = packageJson[dependencyField];
131
- const localDependency = dependencies?.[localPackageName];
132
- if (dependencies && localDependency) {
133
- dependencies[localPackageName] = localDependency.replaceAll(workspaceDependencyVersionRegexp, "$1$2").replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);
134
- }
135
- }
136
- }
137
- const json = JSON.stringify(packageJson, void 0, indent);
138
- if (newline === "\r\n") {
139
- return json.replaceAll("\n", "\r\n") + "\r\n";
140
- }
141
- return json + "\n";
142
- }
143
- };
144
- };
145
- const createStandardVersionConfig = () => {
146
- const { workspacePackage, subPackages } = collectPackages();
147
- const packageJsonUpdater = createPackageJsonUpdater(subPackages);
148
- const genericUpdater = createGenericUpdater(subPackages);
149
- return {
150
- scripts: {
151
- postbump: "pnpm install",
152
- prechangelog: "git add pnpm-lock.yaml"
153
- },
154
- bumpFiles: [
155
- {
156
- filename: workspacePackage.packageJsonPath,
157
- updater: packageJsonUpdater
158
- },
159
- {
160
- filename: node_path.join(workspacePackage.packagePath, "readme.md"),
161
- updater: genericUpdater
162
- },
163
- ...subPackages.map((pkg) => ({
164
- filename: pkg.packageJsonPath,
165
- updater: packageJsonUpdater
166
- })),
167
- ...subPackages.map((pkg) => ({
168
- filename: node_path.join(pkg.packagePath, "readme.md"),
169
- updater: genericUpdater
170
- }))
171
- ]
172
- };
173
- };
174
- exports.collectPackages = collectPackages;
175
- exports.createStandardVersionConfig = createStandardVersionConfig;
package/index.js DELETED
@@ -1,175 +0,0 @@
1
- import { join, relative, dirname, normalize } from "node:path";
2
- import { globSync } from "glob";
3
- import { load } from "js-yaml";
4
- import { readFileSync, statSync, existsSync } from "node:fs";
5
- const PACKAGE_JSON_NAME = "package.json";
6
- const PACKAGE_JSON_DEPENDENCY_FIELDS = [
7
- "dependencies",
8
- "devDependencies",
9
- "optionalDependencies",
10
- "peerDependencies"
11
- ];
12
- const collectPackages = () => {
13
- const workspaceRoot = getWorkspaceRoot();
14
- if (!workspaceRoot) {
15
- throw new Error("not in a workspace");
16
- }
17
- const pnpmWorkspace = load(
18
- readFileSync(join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" })
19
- );
20
- const workspacePackageJsonPath = join(workspaceRoot, PACKAGE_JSON_NAME);
21
- const workspacePackageJson = JSON.parse(
22
- readFileSync(workspacePackageJsonPath, { encoding: "utf8" })
23
- );
24
- let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
25
- if (pnpmWorkspace.packages) {
26
- workspaces = [...workspaces, ...pnpmWorkspace.packages];
27
- }
28
- const packagePaths = globSync(workspaces, {
29
- ignore: ["node_modules"],
30
- cwd: workspaceRoot,
31
- absolute: true
32
- }).filter((path) => statSync(path).isDirectory());
33
- const workspacePackage = {
34
- packageKind: "root",
35
- packagePath: workspaceRoot,
36
- packageJson: workspacePackageJson,
37
- packageJsonPath: workspacePackageJsonPath,
38
- workspacePackagePatterns: workspaces,
39
- packagePathFromRootPackage: "."
40
- };
41
- const subPackages = packagePaths.map((packagePath) => {
42
- const packageJsonPath = join(packagePath, PACKAGE_JSON_NAME);
43
- try {
44
- return {
45
- packageKind: "regular",
46
- packagePath: packagePath.toString(),
47
- packageJsonPath,
48
- packageJson: JSON.parse(
49
- readFileSync(packageJsonPath, { encoding: "utf8" })
50
- ),
51
- packagePathFromRootPackage: relative(workspaceRoot, dirname(packageJsonPath))
52
- };
53
- } catch {
54
- return void 0;
55
- }
56
- }).filter((pkg) => !!pkg);
57
- return { workspacePackage, subPackages };
58
- };
59
- const getWorkspaceRoot = (cwd = process.cwd()) => {
60
- return collectPackageJsonPathsUpDirectoryTree(cwd)[0];
61
- };
62
- const collectPackageJsonPathsUpDirectoryTree = (cwd = process.cwd()) => {
63
- return collectPackageJsonPathsUpDirectoryTreeInternal(cwd);
64
- };
65
- const collectPackageJsonPathsUpDirectoryTreeInternal = (cwd, collection = []) => {
66
- const path = normalize(cwd);
67
- if (existsSync(join(path, "package.json"))) {
68
- collection.unshift(path);
69
- }
70
- const parentPath = join(path, "..");
71
- if (parentPath !== path) {
72
- return collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);
73
- }
74
- return collection;
75
- };
76
- const normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
77
- if (Array.isArray(packageJsonWorkspaces)) {
78
- return packageJsonWorkspaces;
79
- } else if (packageJsonWorkspaces) {
80
- return [
81
- ...packageJsonWorkspaces.packages ?? [],
82
- ...packageJsonWorkspaces.nohoist ?? []
83
- ];
84
- } else {
85
- return [];
86
- }
87
- };
88
- const createGenericUpdater = (packages) => {
89
- return {
90
- readVersion: (contents) => {
91
- const results = [...contents.matchAll(/"version": "(.*)"/g)];
92
- return results[0]?.[1] ?? "0.0.0";
93
- },
94
- writeVersion: (contents, version) => {
95
- return packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name).reduce(
96
- (r, localPackageName) => r.replaceAll(
97
- new RegExp(`"${localPackageName}": "(workspace:)([~^])?.*"`, "g"),
98
- `"${localPackageName}": "$1$2"`
99
- // the workspace protocol does not include versions but keeps the specifier. This is how pnpm leaves them on install.
100
- ).replaceAll(
101
- new RegExp(`"${localPackageName}": "(?!workspace:)([~^])?.*"`, "g"),
102
- `"${localPackageName}": "$1${version}"`
103
- ).replaceAll(
104
- new RegExp(`${localPackageName}@([^s
105
- \r]+)`, "g"),
106
- `${localPackageName}@${version}`
107
- ),
108
- contents.replace(/"version": ".*"/, `"version": "${version}"`)
109
- );
110
- }
111
- };
112
- };
113
- const workspaceDependencyVersionRegexp = /^(workspace:)([\^~])?.*$/g;
114
- const nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\^~])?.*$/g;
115
- const createPackageJsonUpdater = (packages) => {
116
- return {
117
- readVersion: (contents) => {
118
- const results = [...contents.matchAll(/"version": "(.*)"/g)];
119
- return results[0]?.[1] ?? "0.0.0";
120
- },
121
- writeVersion: (contents, version) => {
122
- const packageJson = JSON.parse(contents);
123
- const indent = " ";
124
- const newline = contents.includes("\r\n") ? "\r\n" : "\n";
125
- packageJson.version = version;
126
- for (const localPackageName of packages.map((localPackage) => localPackage.packageJson.name).filter((name) => !!name)) {
127
- for (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {
128
- const dependencies = packageJson[dependencyField];
129
- const localDependency = dependencies?.[localPackageName];
130
- if (dependencies && localDependency) {
131
- dependencies[localPackageName] = localDependency.replaceAll(workspaceDependencyVersionRegexp, "$1$2").replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);
132
- }
133
- }
134
- }
135
- const json = JSON.stringify(packageJson, void 0, indent);
136
- if (newline === "\r\n") {
137
- return json.replaceAll("\n", "\r\n") + "\r\n";
138
- }
139
- return json + "\n";
140
- }
141
- };
142
- };
143
- const createStandardVersionConfig = () => {
144
- const { workspacePackage, subPackages } = collectPackages();
145
- const packageJsonUpdater = createPackageJsonUpdater(subPackages);
146
- const genericUpdater = createGenericUpdater(subPackages);
147
- return {
148
- scripts: {
149
- postbump: "pnpm install",
150
- prechangelog: "git add pnpm-lock.yaml"
151
- },
152
- bumpFiles: [
153
- {
154
- filename: workspacePackage.packageJsonPath,
155
- updater: packageJsonUpdater
156
- },
157
- {
158
- filename: join(workspacePackage.packagePath, "readme.md"),
159
- updater: genericUpdater
160
- },
161
- ...subPackages.map((pkg) => ({
162
- filename: pkg.packageJsonPath,
163
- updater: packageJsonUpdater
164
- })),
165
- ...subPackages.map((pkg) => ({
166
- filename: join(pkg.packagePath, "readme.md"),
167
- updater: genericUpdater
168
- }))
169
- ]
170
- };
171
- };
172
- export {
173
- collectPackages,
174
- createStandardVersionConfig
175
- };
package/license DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Győri Sándor
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
File without changes
File without changes
File without changes
File without changes
File without changes