@alexaegis/standard-version 0.0.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.
@@ -0,0 +1,10 @@
1
+ export declare const createStandardVersionConfig: () => {
2
+ bumpFiles: {
3
+ filename: string;
4
+ updater: {
5
+ readVersion: (contents: string) => string;
6
+ writeVersion: (contents: string, version: string) => string;
7
+ };
8
+ }[];
9
+ };
10
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B;;;;;;;;CAuBvC,CAAC"}
package/index.cjs ADDED
@@ -0,0 +1,116 @@
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 common = require("@alexaegis/common");
8
+ const collectPackages = () => {
9
+ const workspaceRoot = getWorkspaceRoot();
10
+ if (!workspaceRoot) {
11
+ throw new Error("not in a workspace");
12
+ }
13
+ const pnpmWorkspace = jsYaml.load(
14
+ node_fs.readFileSync(node_path.join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" })
15
+ );
16
+ const workspacePackageJson = JSON.parse(
17
+ node_fs.readFileSync(node_path.join(workspaceRoot, "package.json"), { encoding: "utf8" })
18
+ );
19
+ let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
20
+ if (pnpmWorkspace.packages) {
21
+ workspaces = [...workspaces, ...pnpmWorkspace.packages];
22
+ }
23
+ const packagePaths = glob.globSync(workspaces, {
24
+ ignore: ["node_modules"],
25
+ cwd: workspaceRoot,
26
+ absolute: true
27
+ }).filter((path) => node_fs.statSync(path).isDirectory());
28
+ const workspacePackage = {
29
+ path: workspaceRoot,
30
+ packageJson: workspacePackageJson
31
+ };
32
+ const subPackages = packagePaths.map((packagePath) => ({
33
+ path: packagePath.toString(),
34
+ packageJson: JSON.parse(
35
+ node_fs.readFileSync(node_path.join(packagePath, "package.json"), { encoding: "utf8" })
36
+ )
37
+ }));
38
+ return { workspacePackage, subPackages };
39
+ };
40
+ const getWorkspaceRoot = (cwd = process.cwd()) => {
41
+ return collectPackageJsonPathsUpDirectoryTree(cwd)[0];
42
+ };
43
+ const collectPackageJsonPathsUpDirectoryTree = (cwd = process.cwd()) => {
44
+ return collectPackageJsonPathsUpDirectoryTreeInternal(cwd);
45
+ };
46
+ const collectPackageJsonPathsUpDirectoryTreeInternal = (cwd, collection = []) => {
47
+ const path = node_path.normalize(cwd);
48
+ if (node_fs.existsSync(node_path.join(path, "package.json"))) {
49
+ collection.unshift(path);
50
+ }
51
+ const parentPath = node_path.join(path, "..");
52
+ if (parentPath !== path) {
53
+ return collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);
54
+ }
55
+ return collection;
56
+ };
57
+ const normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
58
+ if (Array.isArray(packageJsonWorkspaces)) {
59
+ return packageJsonWorkspaces;
60
+ } else if (packageJsonWorkspaces) {
61
+ return [
62
+ ...packageJsonWorkspaces.packages ?? [],
63
+ ...packageJsonWorkspaces.nohoist ?? []
64
+ ];
65
+ } else {
66
+ return [];
67
+ }
68
+ };
69
+ const createUpdater = (packages) => {
70
+ return {
71
+ readVersion: (contents) => {
72
+ const results = [...contents.matchAll(/"version": "(.*)"/g)];
73
+ return results[0]?.[1] ?? "0.0.0";
74
+ },
75
+ writeVersion: (contents, version) => {
76
+ return packages.map((localPackage) => localPackage.packageJson.name).filter(common.isNotNullish).reduce(
77
+ (r, localPackageName) => r.replaceAll(
78
+ new RegExp(`"${localPackageName}": ".*"`, "g"),
79
+ `"${localPackageName}": "${version}"`
80
+ ).replaceAll(
81
+ new RegExp(`${localPackageName}@([^s
82
+ \r]+)`, "g"),
83
+ `${localPackageName}@${version}`
84
+ ),
85
+ contents.replace(/"version": ".*"/, `"version": "${version}"`)
86
+ );
87
+ }
88
+ };
89
+ };
90
+ const createStandardVersionConfig = () => {
91
+ const { workspacePackage, subPackages } = collectPackages();
92
+ const updater = createUpdater(subPackages);
93
+ return {
94
+ bumpFiles: [
95
+ {
96
+ filename: node_path.join(workspacePackage.path, "package.json"),
97
+ updater
98
+ },
99
+ {
100
+ filename: node_path.join(workspacePackage.path, "readme.md"),
101
+ updater
102
+ },
103
+ ...subPackages.map((p) => ({
104
+ filename: node_path.join(p.path, "package.json"),
105
+ updater
106
+ })),
107
+ ...subPackages.map((p) => ({
108
+ filename: node_path.join(p.path, "readme.md"),
109
+ updater
110
+ }))
111
+ ]
112
+ };
113
+ };
114
+ exports.collectPackages = collectPackages;
115
+ exports.createStandardVersionConfig = createStandardVersionConfig;
116
+ //# sourceMappingURL=index.cjs.map
package/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/workspace/collect-packages.ts","../src/workspace/local-package-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 { join, normalize } from 'node:path';\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 */\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 workspacePackageJson = JSON.parse(\n\t\treadFileSync(join(workspaceRoot, 'package.json'), { 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\tpath: workspaceRoot,\n\t\tpackageJson: workspacePackageJson,\n\t};\n\tconst subPackages: WorkspacePackage[] = packagePaths.map((packagePath) => ({\n\t\tpath: packagePath.toString(),\n\t\tpackageJson: JSON.parse(\n\t\t\treadFileSync(join(packagePath, 'package.json'), { encoding: 'utf8' })\n\t\t) as PackageJson,\n\t}));\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 { isNotNullish } from '@alexaegis/common';\nimport 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 createUpdater = (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(isNotNullish)\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}\": \".*\"`, '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\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 { join } from 'node:path';\nimport { collectPackages } from '../workspace/collect-packages.js';\nimport { createUpdater } from '../workspace/local-package-updater.js';\n\nexport const createStandardVersionConfig = () => {\n\tconst { workspacePackage, subPackages } = collectPackages();\n\tconst updater = createUpdater(subPackages);\n\treturn {\n\t\tbumpFiles: [\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.path, 'package.json'),\n\t\t\t\tupdater,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.path, 'readme.md'),\n\t\t\t\tupdater,\n\t\t\t},\n\t\t\t...subPackages.map((p) => ({\n\t\t\t\tfilename: join(p.path, 'package.json'),\n\t\t\t\tupdater,\n\t\t\t})),\n\t\t\t...subPackages.map((p) => ({\n\t\t\t\tfilename: join(p.path, 'readme.md'),\n\t\t\t\tupdater,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"names":["load","readFileSync","join","globSync","statSync","normalize","existsSync","isNotNullish"],"mappings":";;;;;;;AAWO,MAAM,kBAAkB,MAG1B;AACJ,QAAM,gBAAgB;AAEtB,MAAI,CAAC,eAAe;AACb,UAAA,IAAI,MAAM,oBAAoB;AAAA,EACrC;AAEA,QAAM,gBAAgBA,OAAA;AAAA,IACrBC,QAAA,aAAaC,eAAK,eAAe,qBAAqB,GAAG,EAAE,UAAU,QAAQ;AAAA,EAAA;AAG9E,QAAM,uBAAuB,KAAK;AAAA,IACjCD,QAAA,aAAaC,eAAK,eAAe,cAAc,GAAG,EAAE,UAAU,QAAQ;AAAA,EAAA;AAGnE,MAAA,aAAa,oCAAoC,qBAAqB,UAAU;AAEpF,MAAI,cAAc,UAAU;AAC3B,iBAAa,CAAC,GAAG,YAAY,GAAG,cAAc,QAAQ;AAAA,EACvD;AAEM,QAAA,eAAeC,cAAS,YAAY;AAAA,IACzC,QAAQ,CAAC,cAAc;AAAA,IACvB,KAAK;AAAA,IACL,UAAU;AAAA,EAAA,CACV,EAAE,OAAO,CAAC,SAASC,QAAS,SAAA,IAAI,EAAE,YAAA,CAAa;AAEhD,QAAM,mBAAqC;AAAA,IAC1C,MAAM;AAAA,IACN,aAAa;AAAA,EAAA;AAEd,QAAM,cAAkC,aAAa,IAAI,CAAC,iBAAiB;AAAA,IAC1E,MAAM,YAAY,SAAS;AAAA,IAC3B,aAAa,KAAK;AAAA,MACjBH,QAAA,aAAaC,eAAK,aAAa,cAAc,GAAG,EAAE,UAAU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B;AAAA,UACA,IAAI,OAAO,GAAG;AAAA,QAAkC,GAAG;AAAA,UACnD,GAAG,oBAAoB;AAAA,QACxB;AAAA,QACF,SAAS,QAAQ,mBAAmB,eAAe,UAAU;AAAA,MAAA;AAAA,IAEhE;AAAA,EAAA;AAEF;AChCO,MAAM,8BAA8B,MAAM;AAChD,QAAM,EAAE,kBAAkB,YAAY,IAAI,gBAAgB;AACpD,QAAA,UAAU,cAAc,WAAW;AAClC,SAAA;AAAA,IACN,WAAW;AAAA,MACV;AAAA,QACC,UAAUL,UAAA,KAAK,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,MACD;AAAA,MACA;AAAA,QACC,UAAUA,UAAA,KAAK,iBAAiB,MAAM,WAAW;AAAA,QACjD;AAAA,MACD;AAAA,MACA,GAAG,YAAY,IAAI,CAAC,OAAO;AAAA,QAC1B,UAAUA,UAAA,KAAK,EAAE,MAAM,cAAc;AAAA,QACrC;AAAA,MAAA,EACC;AAAA,MACF,GAAG,YAAY,IAAI,CAAC,OAAO;AAAA,QAC1B,UAAUA,UAAA,KAAK,EAAE,MAAM,WAAW;AAAA,QAClC;AAAA,MAAA,EACC;AAAA,IACH;AAAA,EAAA;AAEF;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { createStandardVersionConfig } from './config/config.js';
2
+ export { collectPackages } from './workspace/collect-packages.js';
3
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC"}
package/index.js ADDED
@@ -0,0 +1,116 @@
1
+ import { join, normalize } from "node:path";
2
+ import { globSync } from "glob";
3
+ import { load } from "js-yaml";
4
+ import { readFileSync, statSync, existsSync } from "node:fs";
5
+ import { isNotNullish } from "@alexaegis/common";
6
+ const collectPackages = () => {
7
+ const workspaceRoot = getWorkspaceRoot();
8
+ if (!workspaceRoot) {
9
+ throw new Error("not in a workspace");
10
+ }
11
+ const pnpmWorkspace = load(
12
+ readFileSync(join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" })
13
+ );
14
+ const workspacePackageJson = JSON.parse(
15
+ readFileSync(join(workspaceRoot, "package.json"), { encoding: "utf8" })
16
+ );
17
+ let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
18
+ if (pnpmWorkspace.packages) {
19
+ workspaces = [...workspaces, ...pnpmWorkspace.packages];
20
+ }
21
+ const packagePaths = globSync(workspaces, {
22
+ ignore: ["node_modules"],
23
+ cwd: workspaceRoot,
24
+ absolute: true
25
+ }).filter((path) => statSync(path).isDirectory());
26
+ const workspacePackage = {
27
+ path: workspaceRoot,
28
+ packageJson: workspacePackageJson
29
+ };
30
+ const subPackages = packagePaths.map((packagePath) => ({
31
+ path: packagePath.toString(),
32
+ packageJson: JSON.parse(
33
+ readFileSync(join(packagePath, "package.json"), { encoding: "utf8" })
34
+ )
35
+ }));
36
+ return { workspacePackage, subPackages };
37
+ };
38
+ const getWorkspaceRoot = (cwd = process.cwd()) => {
39
+ return collectPackageJsonPathsUpDirectoryTree(cwd)[0];
40
+ };
41
+ const collectPackageJsonPathsUpDirectoryTree = (cwd = process.cwd()) => {
42
+ return collectPackageJsonPathsUpDirectoryTreeInternal(cwd);
43
+ };
44
+ const collectPackageJsonPathsUpDirectoryTreeInternal = (cwd, collection = []) => {
45
+ const path = normalize(cwd);
46
+ if (existsSync(join(path, "package.json"))) {
47
+ collection.unshift(path);
48
+ }
49
+ const parentPath = join(path, "..");
50
+ if (parentPath !== path) {
51
+ return collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);
52
+ }
53
+ return collection;
54
+ };
55
+ const normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
56
+ if (Array.isArray(packageJsonWorkspaces)) {
57
+ return packageJsonWorkspaces;
58
+ } else if (packageJsonWorkspaces) {
59
+ return [
60
+ ...packageJsonWorkspaces.packages ?? [],
61
+ ...packageJsonWorkspaces.nohoist ?? []
62
+ ];
63
+ } else {
64
+ return [];
65
+ }
66
+ };
67
+ const createUpdater = (packages) => {
68
+ return {
69
+ readVersion: (contents) => {
70
+ const results = [...contents.matchAll(/"version": "(.*)"/g)];
71
+ return results[0]?.[1] ?? "0.0.0";
72
+ },
73
+ writeVersion: (contents, version) => {
74
+ return packages.map((localPackage) => localPackage.packageJson.name).filter(isNotNullish).reduce(
75
+ (r, localPackageName) => r.replaceAll(
76
+ new RegExp(`"${localPackageName}": ".*"`, "g"),
77
+ `"${localPackageName}": "${version}"`
78
+ ).replaceAll(
79
+ new RegExp(`${localPackageName}@([^s
80
+ \r]+)`, "g"),
81
+ `${localPackageName}@${version}`
82
+ ),
83
+ contents.replace(/"version": ".*"/, `"version": "${version}"`)
84
+ );
85
+ }
86
+ };
87
+ };
88
+ const createStandardVersionConfig = () => {
89
+ const { workspacePackage, subPackages } = collectPackages();
90
+ const updater = createUpdater(subPackages);
91
+ return {
92
+ bumpFiles: [
93
+ {
94
+ filename: join(workspacePackage.path, "package.json"),
95
+ updater
96
+ },
97
+ {
98
+ filename: join(workspacePackage.path, "readme.md"),
99
+ updater
100
+ },
101
+ ...subPackages.map((p) => ({
102
+ filename: join(p.path, "package.json"),
103
+ updater
104
+ })),
105
+ ...subPackages.map((p) => ({
106
+ filename: join(p.path, "readme.md"),
107
+ updater
108
+ }))
109
+ ]
110
+ };
111
+ };
112
+ export {
113
+ collectPackages,
114
+ createStandardVersionConfig
115
+ };
116
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/workspace/collect-packages.ts","../src/workspace/local-package-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 { join, normalize } from 'node:path';\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 */\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 workspacePackageJson = JSON.parse(\n\t\treadFileSync(join(workspaceRoot, 'package.json'), { 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\tpath: workspaceRoot,\n\t\tpackageJson: workspacePackageJson,\n\t};\n\tconst subPackages: WorkspacePackage[] = packagePaths.map((packagePath) => ({\n\t\tpath: packagePath.toString(),\n\t\tpackageJson: JSON.parse(\n\t\t\treadFileSync(join(packagePath, 'package.json'), { encoding: 'utf8' })\n\t\t) as PackageJson,\n\t}));\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 { isNotNullish } from '@alexaegis/common';\nimport 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 createUpdater = (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(isNotNullish)\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}\": \".*\"`, '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\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 { join } from 'node:path';\nimport { collectPackages } from '../workspace/collect-packages.js';\nimport { createUpdater } from '../workspace/local-package-updater.js';\n\nexport const createStandardVersionConfig = () => {\n\tconst { workspacePackage, subPackages } = collectPackages();\n\tconst updater = createUpdater(subPackages);\n\treturn {\n\t\tbumpFiles: [\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.path, 'package.json'),\n\t\t\t\tupdater,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.path, 'readme.md'),\n\t\t\t\tupdater,\n\t\t\t},\n\t\t\t...subPackages.map((p) => ({\n\t\t\t\tfilename: join(p.path, 'package.json'),\n\t\t\t\tupdater,\n\t\t\t})),\n\t\t\t...subPackages.map((p) => ({\n\t\t\t\tfilename: join(p.path, 'readme.md'),\n\t\t\t\tupdater,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"names":[],"mappings":";;;;;AAWO,MAAM,kBAAkB,MAG1B;AACJ,QAAM,gBAAgB;AAEtB,MAAI,CAAC,eAAe;AACb,UAAA,IAAI,MAAM,oBAAoB;AAAA,EACrC;AAEA,QAAM,gBAAgB;AAAA,IACrB,aAAa,KAAK,eAAe,qBAAqB,GAAG,EAAE,UAAU,QAAQ;AAAA,EAAA;AAG9E,QAAM,uBAAuB,KAAK;AAAA,IACjC,aAAa,KAAK,eAAe,cAAc,GAAG,EAAE,UAAU,QAAQ;AAAA,EAAA;AAGnE,MAAA,aAAa,oCAAoC,qBAAqB,UAAU;AAEpF,MAAI,cAAc,UAAU;AAC3B,iBAAa,CAAC,GAAG,YAAY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,SAAA;AAAA,IACN,aAAa,CAAC,aAA6B;AAC1C,YAAM,UAAU,CAAC,GAAG,SAAS,SAAS,oBAAoB,CAAC;AAC3D,aAAO,QAAQ,CAAC,IAAI,CAAC,KAAK;AAAA,IAC3B;AAAA,IACA,cAAc,CAAC,UAAkB,YAA4B;AACrD,aAAA,SACL,IAAI,CAAC,iBAAiB,aAAa,YAAY,IAAI,EACnD,OAAO,YAAY,EACnB;AAAA,QACA,CAAC,GAAG,qBACH,EACE;AAAA,UACA,IAAI,OAAO,IAAI,2BAA2B,GAAG;AAAA,UAC7C,IAAI,uBAAuB;AAAA,QAAA,EAE3B;AAAA,UACA,IAAI,OAAO,GAAG;AAAA,QAAkC,GAAG;AAAA,UACnD,GAAG,oBAAoB;AAAA,QACxB;AAAA,QACF,SAAS,QAAQ,mBAAmB,eAAe,UAAU;AAAA,MAAA;AAAA,IAEhE;AAAA,EAAA;AAEF;AChCO,MAAM,8BAA8B,MAAM;AAChD,QAAM,EAAE,kBAAkB,YAAY,IAAI,gBAAgB;AACpD,QAAA,UAAU,cAAc,WAAW;AAClC,SAAA;AAAA,IACN,WAAW;AAAA,MACV;AAAA,QACC,UAAU,KAAK,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,MACD;AAAA,MACA;AAAA,QACC,UAAU,KAAK,iBAAiB,MAAM,WAAW;AAAA,QACjD;AAAA,MACD;AAAA,MACA,GAAG,YAAY,IAAI,CAAC,OAAO;AAAA,QAC1B,UAAU,KAAK,EAAE,MAAM,cAAc;AAAA,QACrC;AAAA,MAAA,EACC;AAAA,MACF,GAAG,YAAY,IAAI,CAAC,OAAO;AAAA,QAC1B,UAAU,KAAK,EAAE,MAAM,WAAW;AAAA,QAClC;AAAA,MAAA,EACC;AAAA,IACH;AAAA,EAAA;AAEF;"}
package/license ADDED
@@ -0,0 +1,21 @@
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.
package/manifest.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "src/index.ts": {
3
+ "file": "index.cjs",
4
+ "isEntry": true,
5
+ "src": "src/index.ts"
6
+ }
7
+ }
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@alexaegis/standard-version",
3
+ "description": "Standard version",
4
+ "version": "0.0.1",
5
+ "license": "mit",
6
+ "private": false,
7
+ "author": {
8
+ "email": "alexaegis@gmail.com",
9
+ "name": "Alex Aegis",
10
+ "url": "https://github.com/AlexAegis"
11
+ },
12
+ "homepage": "https://github.com/AlexAegis/js-tooling",
13
+ "bugs": {
14
+ "email": "alexaegis@gmail.com",
15
+ "url": "https://github.com/AlexAegis/js-tooling/issues"
16
+ },
17
+ "keywords": [
18
+ "eslint",
19
+ "javascript",
20
+ "js",
21
+ "ts",
22
+ "tsconfig",
23
+ "turbo",
24
+ "typescript"
25
+ ],
26
+ "type": "module",
27
+ "config": {
28
+ "engine-strict": true
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "engines": {
34
+ "node": ">=18.13.0"
35
+ },
36
+ "exports": {
37
+ ".": {
38
+ "types": "./index.d.ts",
39
+ "import": "./index.js",
40
+ "require": "./index.cjs"
41
+ },
42
+ "./readme": "./readme.md"
43
+ },
44
+ "bin": {
45
+ "lcov-viewer": "node_modules/@lcov-viewer/cli/lib/index.js",
46
+ "merge-workspace-lcov-reports": "node_modules/@alexaegis/coverage-tools/bin/merge-workspace-lcov-reports.mjs"
47
+ },
48
+ "dependencies": {
49
+ "@alexaegis/cli-tools": "0.0.23",
50
+ "@alexaegis/common": "0.0.23",
51
+ "@alexaegis/coverage-tools": "0.0.23",
52
+ "@alexaegis/logging": "0.0.23",
53
+ "@alexaegis/workspace-tools": "0.0.23",
54
+ "@lcov-viewer/cli": "^1.3.0",
55
+ "glob": "^9.2.1",
56
+ "js-yaml": "^4.1.0"
57
+ },
58
+ "devDependencies": {
59
+ "@alexaegis/vite": "0.0.1",
60
+ "@alexaegis/vitest": "0.0.1",
61
+ "@types/js-yaml": "^4.0.5",
62
+ "@types/node": "^18.14.6",
63
+ "typescript": "4.9.5"
64
+ },
65
+ "scripts": {
66
+ "build": "turbo run build-lib_ --concurrency 6 --filter @alexaegis/standard-version",
67
+ "build-lib_": "vite build",
68
+ "lint:es": "turbo run lint:es_ --concurrency 6 --filter @alexaegis/standard-version",
69
+ "lint:es_": "eslint --max-warnings=0 --fix --no-error-on-unmatched-pattern .",
70
+ "lint:format": "turbo run lint:format_ --concurrency 6 --filter @alexaegis/standard-version",
71
+ "lint:format_": "prettier --check .",
72
+ "lint:md": "turbo run lint:md_ --concurrency 6 --filter @alexaegis/standard-version",
73
+ "lint:md_": "remark --frail --no-stdout --silently-ignore *.md docs/**/*.md",
74
+ "lint:tsc": "turbo run lint:tsc_ --concurrency 6 --filter @alexaegis/standard-version",
75
+ "lint:tsc_": "tsc --noEmit",
76
+ "format": "prettier --write .",
77
+ "test": "turbo run test_ --concurrency 6 --filter @alexaegis/standard-version && merge-workspace-lcov-reports && lcov-viewer lcov -o ./coverage ./coverage/lcov.info",
78
+ "test_": "vitest --passWithNoTests --coverage --run",
79
+ "test:watch": "vitest --passWithNoTests --coverage --run"
80
+ }
81
+ }
package/readme.md ADDED
@@ -0,0 +1,24 @@
1
+ # [@alexaegis/standard-version](https://github.com/AlexAegis/js-tooling/tree/master/packages/standard-version)
2
+
3
+ [![npm](https://img.shields.io/npm/v/@alexaegis/standard-version/latest)](https://www.npmjs.com/package/@alexaegis/standard-version)
4
+ [![ci](https://github.com/AlexAegis/js-tooling/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexAegis/js-tooling/actions/workflows/ci.yml)
5
+ [![codacy](https://app.codacy.com/project/badge/Grade/7939332dc9454dc1b0529e720ff902e6)](https://www.codacy.com/gh/AlexAegis/js-tooling/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AlexAegis/js-tooling&utm_campaign=Badge_Grade)
6
+
7
+ This package has some code similar what's in
8
+ [@alexaegis/workspace-tools](https://github.com/AlexAegis/js-core/tree/master/packages/workspace-tools)
9
+ but the config file of `standard-version` has to be sync so the `async`
10
+ functions had to be reimplemented, albeit in a much simpler form.
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ npm i @alexaegis/standard-version@0.0.1
16
+ ```
17
+
18
+ ```json
19
+ {
20
+ "dependencies": {
21
+ "@alexaegis/standard-version": "0.0.1"
22
+ }
23
+ }
24
+ ```
@@ -0,0 +1,11 @@
1
+ import type { WorkspacePackage } from '@alexaegis/workspace-tools';
2
+ /**
3
+ * The functions found in this file are copied from @alexaegis/workspace-tools
4
+ * to be a sync, non-esm (globby is only esm) variant that could be invoked
5
+ * from a CJS based configuration file.
6
+ */
7
+ export declare const collectPackages: () => {
8
+ workspacePackage: WorkspacePackage;
9
+ subPackages: WorkspacePackage[];
10
+ };
11
+ //# sourceMappingURL=collect-packages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect-packages.d.ts","sourceRoot":"","sources":["../../../src/workspace/collect-packages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAMnG;;;;GAIG;AACH,eAAO,MAAM,eAAe;sBACT,gBAAgB;iBACrB,gBAAgB,EAAE;CAwC/B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { WorkspacePackage } from '@alexaegis/workspace-tools';
2
+ /**
3
+ * This updater also updates all local dependencies too that were updated
4
+ * While it's mainly used for packageJson files, it does not assume the file to
5
+ * be valid JSON, so it can be used with any file that contains lines like
6
+ * "version": "0.0.0", like examples in readme files.
7
+ *
8
+ * It also replaces everything that looks like a `packageName@version`
9
+ */
10
+ export declare const createUpdater: (packages: WorkspacePackage[]) => {
11
+ readVersion: (contents: string) => string;
12
+ writeVersion: (contents: string, version: string) => string;
13
+ };
14
+ //# sourceMappingURL=local-package-updater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-package-updater.d.ts","sourceRoot":"","sources":["../../../src/workspace/local-package-updater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,aAAc,gBAAgB,EAAE;4BAEhC,MAAM,KAAG,MAAM;6BAId,MAAM,WAAW,MAAM,KAAG,MAAM;CAmB1D,CAAC"}