@alexaegis/standard-version 0.3.1 → 0.3.3
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/config/config.d.ts.map +1 -1
- package/index.cjs +53 -10
- package/index.cjs.map +1 -1
- package/index.js +53 -10
- package/index.js.map +1 -1
- package/package.json +19 -23
- package/readme.md +2 -2
- package/workspace/collect-packages.d.ts +1 -0
- package/workspace/collect-packages.d.ts.map +1 -1
- package/workspace/{local-package-updater.d.ts → generic-updater.d.ts} +2 -2
- package/workspace/generic-updater.d.ts.map +1 -0
- package/workspace/package-json-updater.d.ts +14 -0
- package/workspace/package-json-updater.d.ts.map +1 -0
- package/manifest.json +0 -7
- package/workspace/local-package-updater.d.ts.map +0 -1
package/config/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,2BAA2B;;;;;;;;;;;;CA6BvC,CAAC"}
|
package/index.cjs
CHANGED
|
@@ -6,6 +6,12 @@ const glob = require("glob");
|
|
|
6
6
|
const jsYaml = require("js-yaml");
|
|
7
7
|
const node_fs = require("node:fs");
|
|
8
8
|
const PACKAGE_JSON_NAME = "package.json";
|
|
9
|
+
const PACKAGE_JSON_DEPENDENCY_FIELDS = [
|
|
10
|
+
"dependencies",
|
|
11
|
+
"devDependencies",
|
|
12
|
+
"optionalDependencies",
|
|
13
|
+
"peerDependencies"
|
|
14
|
+
];
|
|
9
15
|
const collectPackages = () => {
|
|
10
16
|
const workspaceRoot = getWorkspaceRoot();
|
|
11
17
|
if (!workspaceRoot) {
|
|
@@ -82,17 +88,22 @@ const normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
|
|
|
82
88
|
return [];
|
|
83
89
|
}
|
|
84
90
|
};
|
|
85
|
-
const
|
|
91
|
+
const createGenericUpdater = (packages) => {
|
|
86
92
|
return {
|
|
87
93
|
readVersion: (contents) => {
|
|
94
|
+
var _a;
|
|
88
95
|
const results = [...contents.matchAll(/"version": "(.*)"/g)];
|
|
89
|
-
return results[0]
|
|
96
|
+
return ((_a = results[0]) == null ? void 0 : _a[1]) ?? "0.0.0";
|
|
90
97
|
},
|
|
91
98
|
writeVersion: (contents, version) => {
|
|
92
99
|
return packages.map((localPackage) => localPackage.packageJson.name).filter(common.isNotNullish).reduce(
|
|
93
100
|
(r, localPackageName) => r.replaceAll(
|
|
94
|
-
new RegExp(`"${localPackageName}": "(
|
|
95
|
-
`"${localPackageName}": "$1
|
|
101
|
+
new RegExp(`"${localPackageName}": "(workspace:)([~^])?.*"`, "g"),
|
|
102
|
+
`"${localPackageName}": "$1$2"`
|
|
103
|
+
// the workspace protocol does not include versions but keeps the specifier. This is how pnpm leaves them on install.
|
|
104
|
+
).replaceAll(
|
|
105
|
+
new RegExp(`"${localPackageName}": "(?!workspace:)([~^])?.*"`, "g"),
|
|
106
|
+
`"${localPackageName}": "$1${version}"`
|
|
96
107
|
).replaceAll(
|
|
97
108
|
new RegExp(`${localPackageName}@([^s
|
|
98
109
|
\r]+)`, "g"),
|
|
@@ -103,9 +114,41 @@ const createUpdater = (packages) => {
|
|
|
103
114
|
}
|
|
104
115
|
};
|
|
105
116
|
};
|
|
117
|
+
const workspaceDependencyVersionRegexp = /^(workspace:)([\^~])?.*$/g;
|
|
118
|
+
const nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\^~])?.*$/g;
|
|
119
|
+
const createPackageJsonUpdater = (packages) => {
|
|
120
|
+
return {
|
|
121
|
+
readVersion: (contents) => {
|
|
122
|
+
var _a;
|
|
123
|
+
const results = [...contents.matchAll(/"version": "(.*)"/g)];
|
|
124
|
+
return ((_a = results[0]) == null ? void 0 : _a[1]) ?? "0.0.0";
|
|
125
|
+
},
|
|
126
|
+
writeVersion: (contents, version) => {
|
|
127
|
+
const packageJson = JSON.parse(contents);
|
|
128
|
+
const indent = " ";
|
|
129
|
+
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
130
|
+
packageJson.version = version;
|
|
131
|
+
for (const localPackageName of packages.map((localPackage) => localPackage.packageJson.name).filter(common.isNotNullish)) {
|
|
132
|
+
for (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {
|
|
133
|
+
const dependencies = packageJson[dependencyField];
|
|
134
|
+
const localDependency = dependencies == null ? void 0 : dependencies[localPackageName];
|
|
135
|
+
if (dependencies && localDependency) {
|
|
136
|
+
dependencies[localPackageName] = localDependency.replaceAll(workspaceDependencyVersionRegexp, "$1$2").replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const json = JSON.stringify(packageJson, void 0, indent);
|
|
141
|
+
if (newline === "\r\n") {
|
|
142
|
+
return json.replaceAll("\n", "\r\n") + "\r\n";
|
|
143
|
+
}
|
|
144
|
+
return json + "\n";
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
};
|
|
106
148
|
const createStandardVersionConfig = () => {
|
|
107
149
|
const { workspacePackage, subPackages } = collectPackages();
|
|
108
|
-
const
|
|
150
|
+
const packageJsonUpdater = createPackageJsonUpdater(subPackages);
|
|
151
|
+
const genericUpdater = createGenericUpdater(subPackages);
|
|
109
152
|
return {
|
|
110
153
|
scripts: {
|
|
111
154
|
postbump: "pnpm install",
|
|
@@ -114,19 +157,19 @@ const createStandardVersionConfig = () => {
|
|
|
114
157
|
bumpFiles: [
|
|
115
158
|
{
|
|
116
159
|
filename: workspacePackage.packageJsonPath,
|
|
117
|
-
updater
|
|
160
|
+
updater: packageJsonUpdater
|
|
118
161
|
},
|
|
119
162
|
{
|
|
120
163
|
filename: node_path.join(workspacePackage.packagePath, "readme.md"),
|
|
121
|
-
updater
|
|
164
|
+
updater: genericUpdater
|
|
122
165
|
},
|
|
123
166
|
...subPackages.map((pkg) => ({
|
|
124
|
-
filename:
|
|
125
|
-
updater
|
|
167
|
+
filename: pkg.packageJsonPath,
|
|
168
|
+
updater: packageJsonUpdater
|
|
126
169
|
})),
|
|
127
170
|
...subPackages.map((pkg) => ({
|
|
128
171
|
filename: node_path.join(pkg.packagePath, "readme.md"),
|
|
129
|
-
updater
|
|
172
|
+
updater: genericUpdater
|
|
130
173
|
}))
|
|
131
174
|
]
|
|
132
175
|
};
|
package/index.cjs.map
CHANGED
|
@@ -1 +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 { isNotNullish } from '@alexaegis/common';\nimport 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\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(isNotNullish);\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}\": \"$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 { 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\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,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.packagePath, 'readme.md'),\n\t\t\t\tupdater,\n\t\t\t},\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: join(pkg.packagePath, 'package.json'),\n\t\t\t\tupdater,\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,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"names":["load","readFileSync","join","globSync","statSync","relative","dirname","isNotNullish","normalize","existsSync"],"mappings":";;;;;;;AAOA,MAAM,oBAAoB;AASnB,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;AAGxE,QAAA,2BAA2BA,UAAAA,KAAK,eAAe,iBAAiB;AACtE,QAAM,uBAAuB,KAAK;AAAA,IACjCD,QAAAA,aAAa,0BAA0B,EAAE,UAAU,QAAQ;AAAA,EAAA;A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AU,iBAAiB;AAAA,QAC3B;AAAA,MACD;AAAA,MACA;AAAA,QACC,UAAUL,UAAA,KAAK,iBAAiB,aAAa,WAAW;AAAA,QACxD;AAAA,MACD;AAAA,MACA,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAUA,UAAA,KAAK,IAAI,aAAa,cAAc;AAAA,QAC9C;AAAA,MAAA,EACC;AAAA,MACF,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAUA,UAAA,KAAK,IAAI,aAAa,WAAW;AAAA,QAC3C;AAAA,MAAA,EACC;AAAA,IACH;AAAA,EAAA;AAEF;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/workspace/collect-packages.ts","../src/workspace/generic-updater.ts","../src/workspace/package-json-updater.ts","../src/config/config.ts"],"sourcesContent":["import { isNotNullish } from '@alexaegis/common';\nimport 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(isNotNullish);\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 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(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}\": \"(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 { isNotNullish } from '@alexaegis/common';\nimport 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(isNotNullish)) {\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"],"names":["load","readFileSync","join","globSync","statSync","relative","dirname","isNotNullish","normalize","existsSync"],"mappings":";;;;;;;AAOA,MAAM,oBAAoB;AAEnB,MAAM,iCAAiC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AASO,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;AAGxE,QAAA,2BAA2BA,UAAAA,KAAK,eAAe,iBAAiB;AACtE,QAAM,uBAAuB,KAAK;AAAA,IACjCD,QAAAA,aAAa,0BAA0B,EAAE,UAAU,QAAQ;AAAA,EAAA;AAGxD,MAAA,aAAa,oCAAoC,qBAAqB,UAAU;AAEpF,MAAI,cAAc,UAAU;AAC3B,iBAAa,CAAC,GAAG,YAAY,GAAG,cAAc,QAAQ;AAAA,EACvD;AAEM,QAAA,eAAeE,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,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,0BAA0B;AAAA,IAC1B,4BAA4B;AAAA,EAAA;AAE7B,QAAM,cAAkC,aACtC,IAAI,CAAC,gBAAgB;AACf,UAAA,kBAAkBF,UA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B,WAAW,kCAAkC,MAAM,EACnD,WAAW,qCAAqC,KAAK,SAAS;AAAA,UACjE;AAAA,QACD;AAAA,MACD;AAEA,YAAM,OAAO,KAAK,UAAU,aAAa,QAAW,MAAM;AAE1D,UAAI,YAAY,QAAQ;AACvB,eAAO,KAAK,WAAW,MAAM,MAAM,IAAI;AAAA,MACxC;AAEA,aAAO,OAAO;AAAA,IACf;AAAA,EAAA;AAEF;AChDO,MAAM,8BAA8B,MAAM;AAChD,QAAM,EAAE,kBAAkB,YAAY,IAAI,gBAAgB;AACpD,QAAA,qBAAqB,yBAAyB,WAAW;AACzD,QAAA,iBAAiB,qBAAqB,WAAW;AAEhD,SAAA;AAAA,IACN,SAAS;AAAA,MACR,UAAU;AAAA,MACV,cAAc;AAAA,IACf;AAAA,IACA,WAAW;AAAA,MACV;AAAA,QACC,UAAU,iBAAiB;AAAA,QAC3B,SAAS;AAAA,MACV;AAAA,MACA;AAAA,QACC,UAAUL,UAAA,KAAK,iBAAiB,aAAa,WAAW;AAAA,QACxD,SAAS;AAAA,MACV;AAAA,MACA,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAU,IAAI;AAAA,QACd,SAAS;AAAA,MAAA,EACR;AAAA,MACF,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAUA,UAAA,KAAK,IAAI,aAAa,WAAW;AAAA,QAC3C,SAAS;AAAA,MAAA,EACR;AAAA,IACH;AAAA,EAAA;AAEF;;;"}
|
package/index.js
CHANGED
|
@@ -4,6 +4,12 @@ import { globSync } from "glob";
|
|
|
4
4
|
import { load } from "js-yaml";
|
|
5
5
|
import { readFileSync, statSync, existsSync } from "node:fs";
|
|
6
6
|
const PACKAGE_JSON_NAME = "package.json";
|
|
7
|
+
const PACKAGE_JSON_DEPENDENCY_FIELDS = [
|
|
8
|
+
"dependencies",
|
|
9
|
+
"devDependencies",
|
|
10
|
+
"optionalDependencies",
|
|
11
|
+
"peerDependencies"
|
|
12
|
+
];
|
|
7
13
|
const collectPackages = () => {
|
|
8
14
|
const workspaceRoot = getWorkspaceRoot();
|
|
9
15
|
if (!workspaceRoot) {
|
|
@@ -80,17 +86,22 @@ const normalizePackageJsonWorkspacesField = (packageJsonWorkspaces) => {
|
|
|
80
86
|
return [];
|
|
81
87
|
}
|
|
82
88
|
};
|
|
83
|
-
const
|
|
89
|
+
const createGenericUpdater = (packages) => {
|
|
84
90
|
return {
|
|
85
91
|
readVersion: (contents) => {
|
|
92
|
+
var _a;
|
|
86
93
|
const results = [...contents.matchAll(/"version": "(.*)"/g)];
|
|
87
|
-
return results[0]
|
|
94
|
+
return ((_a = results[0]) == null ? void 0 : _a[1]) ?? "0.0.0";
|
|
88
95
|
},
|
|
89
96
|
writeVersion: (contents, version) => {
|
|
90
97
|
return packages.map((localPackage) => localPackage.packageJson.name).filter(isNotNullish).reduce(
|
|
91
98
|
(r, localPackageName) => r.replaceAll(
|
|
92
|
-
new RegExp(`"${localPackageName}": "(
|
|
93
|
-
`"${localPackageName}": "$1
|
|
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}"`
|
|
94
105
|
).replaceAll(
|
|
95
106
|
new RegExp(`${localPackageName}@([^s
|
|
96
107
|
\r]+)`, "g"),
|
|
@@ -101,9 +112,41 @@ const createUpdater = (packages) => {
|
|
|
101
112
|
}
|
|
102
113
|
};
|
|
103
114
|
};
|
|
115
|
+
const workspaceDependencyVersionRegexp = /^(workspace:)([\^~])?.*$/g;
|
|
116
|
+
const nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\^~])?.*$/g;
|
|
117
|
+
const createPackageJsonUpdater = (packages) => {
|
|
118
|
+
return {
|
|
119
|
+
readVersion: (contents) => {
|
|
120
|
+
var _a;
|
|
121
|
+
const results = [...contents.matchAll(/"version": "(.*)"/g)];
|
|
122
|
+
return ((_a = results[0]) == null ? void 0 : _a[1]) ?? "0.0.0";
|
|
123
|
+
},
|
|
124
|
+
writeVersion: (contents, version) => {
|
|
125
|
+
const packageJson = JSON.parse(contents);
|
|
126
|
+
const indent = " ";
|
|
127
|
+
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
128
|
+
packageJson.version = version;
|
|
129
|
+
for (const localPackageName of packages.map((localPackage) => localPackage.packageJson.name).filter(isNotNullish)) {
|
|
130
|
+
for (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {
|
|
131
|
+
const dependencies = packageJson[dependencyField];
|
|
132
|
+
const localDependency = dependencies == null ? void 0 : dependencies[localPackageName];
|
|
133
|
+
if (dependencies && localDependency) {
|
|
134
|
+
dependencies[localPackageName] = localDependency.replaceAll(workspaceDependencyVersionRegexp, "$1$2").replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const json = JSON.stringify(packageJson, void 0, indent);
|
|
139
|
+
if (newline === "\r\n") {
|
|
140
|
+
return json.replaceAll("\n", "\r\n") + "\r\n";
|
|
141
|
+
}
|
|
142
|
+
return json + "\n";
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
104
146
|
const createStandardVersionConfig = () => {
|
|
105
147
|
const { workspacePackage, subPackages } = collectPackages();
|
|
106
|
-
const
|
|
148
|
+
const packageJsonUpdater = createPackageJsonUpdater(subPackages);
|
|
149
|
+
const genericUpdater = createGenericUpdater(subPackages);
|
|
107
150
|
return {
|
|
108
151
|
scripts: {
|
|
109
152
|
postbump: "pnpm install",
|
|
@@ -112,19 +155,19 @@ const createStandardVersionConfig = () => {
|
|
|
112
155
|
bumpFiles: [
|
|
113
156
|
{
|
|
114
157
|
filename: workspacePackage.packageJsonPath,
|
|
115
|
-
updater
|
|
158
|
+
updater: packageJsonUpdater
|
|
116
159
|
},
|
|
117
160
|
{
|
|
118
161
|
filename: join(workspacePackage.packagePath, "readme.md"),
|
|
119
|
-
updater
|
|
162
|
+
updater: genericUpdater
|
|
120
163
|
},
|
|
121
164
|
...subPackages.map((pkg) => ({
|
|
122
|
-
filename:
|
|
123
|
-
updater
|
|
165
|
+
filename: pkg.packageJsonPath,
|
|
166
|
+
updater: packageJsonUpdater
|
|
124
167
|
})),
|
|
125
168
|
...subPackages.map((pkg) => ({
|
|
126
169
|
filename: join(pkg.packagePath, "readme.md"),
|
|
127
|
-
updater
|
|
170
|
+
updater: genericUpdater
|
|
128
171
|
}))
|
|
129
172
|
]
|
|
130
173
|
};
|
package/index.js.map
CHANGED
|
@@ -1 +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 { isNotNullish } from '@alexaegis/common';\nimport 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\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(isNotNullish);\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}\": \"$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 { 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\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,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.packagePath, 'readme.md'),\n\t\t\t\tupdater,\n\t\t\t},\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: join(pkg.packagePath, 'package.json'),\n\t\t\t\tupdater,\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,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"names":[],"mappings":";;;;;AAOA,MAAM,oBAAoB;AASnB,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;AAGxE,QAAA,2BAA2B,KAAK,eAAe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;AAAA,QACC,UAAU,iBAAiB;AAAA,QAC3B;AAAA,MACD;AAAA,MACA;AAAA,QACC,UAAU,KAAK,iBAAiB,aAAa,WAAW;AAAA,QACxD;AAAA,MACD;AAAA,MACA,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAU,KAAK,IAAI,aAAa,cAAc;AAAA,QAC9C;AAAA,MAAA,EACC;AAAA,MACF,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAU,KAAK,IAAI,aAAa,WAAW;AAAA,QAC3C;AAAA,MAAA,EACC;AAAA,IACH;AAAA,EAAA;AAEF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/workspace/collect-packages.ts","../src/workspace/generic-updater.ts","../src/workspace/package-json-updater.ts","../src/config/config.ts"],"sourcesContent":["import { isNotNullish } from '@alexaegis/common';\nimport 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(isNotNullish);\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 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(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}\": \"(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 { isNotNullish } from '@alexaegis/common';\nimport 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(isNotNullish)) {\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"],"names":[],"mappings":";;;;;AAOA,MAAM,oBAAoB;AAEnB,MAAM,iCAAiC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AASO,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;AAGxE,QAAA,2BAA2B,KAAK,eAAe,iBAAiB;AACtE,QAAM,uBAAuB,KAAK;AAAA,IACjC,aAAa,0BAA0B,EAAE,UAAU,QAAQ;AAAA,EAAA;AAGxD,MAAA,aAAa,oCAAoC,qBAAqB,UAAU;AAEpF,MAAI,cAAc,UAAU;AAC3B,iBAAa,CAAC,GAAG,YAAY,GAAG,cAAc,QAAQ;AAAA,EACvD;AAEM,QAAA,eAAe,SAAS,YAAY;AAAA,IACzC,QAAQ,CAAC,cAAc;AAAA,IACvB,KAAK;AAAA,IACL,UAAU;AAAA,EAAA,CACV,EAAE,OAAO,CAAC,SAAS,SAAS,IAAI,EAAE,YAAA,CAAa;AAEhD,QAAM,mBAAqC;AAAA,IAC1C,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,0BAA0B;AAAA,IAC1B,4BAA4B;AAAA,EAAA;AAE7B,QAAM,cAAkC,aACtC,IAAI,CAAC,gBAAgB;AACf,UAAA,kBAAkB,KAAK,aAAa,iBAAiB;AACvD,QAAA;AACI,aAAA;AAAA,QACN,aAAa;AAAA,QACb,aAAa,YAAY,SAAS;AAAA,QAClC;AAAA,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AW,MAAM,MAAM,IAAI;AAAA,MACxC;AAEA,aAAO,OAAO;AAAA,IACf;AAAA,EAAA;AAEF;AChDO,MAAM,8BAA8B,MAAM;AAChD,QAAM,EAAE,kBAAkB,YAAY,IAAI,gBAAgB;AACpD,QAAA,qBAAqB,yBAAyB,WAAW;AACzD,QAAA,iBAAiB,qBAAqB,WAAW;AAEhD,SAAA;AAAA,IACN,SAAS;AAAA,MACR,UAAU;AAAA,MACV,cAAc;AAAA,IACf;AAAA,IACA,WAAW;AAAA,MACV;AAAA,QACC,UAAU,iBAAiB;AAAA,QAC3B,SAAS;AAAA,MACV;AAAA,MACA;AAAA,QACC,UAAU,KAAK,iBAAiB,aAAa,WAAW;AAAA,QACxD,SAAS;AAAA,MACV;AAAA,MACA,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAU,IAAI;AAAA,QACd,SAAS;AAAA,MAAA,EACR;AAAA,MACF,GAAG,YAAY,IAAI,CAAC,SAAS;AAAA,QAC5B,UAAU,KAAK,IAAI,aAAa,WAAW;AAAA,QAC3C,SAAS;AAAA,MAAA,EACR;AAAA,IACH;AAAA,EAAA;AAEF;"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexaegis/standard-version",
|
|
3
3
|
"description": "Standard version",
|
|
4
|
-
"version": "0.3.
|
|
5
|
-
"license": "
|
|
4
|
+
"version": "0.3.3",
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"archetype": {
|
|
8
8
|
"platform": "node",
|
|
@@ -11,14 +11,9 @@
|
|
|
11
11
|
"kind": "lib"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
|
-
"
|
|
15
|
-
"javascript",
|
|
16
|
-
"js",
|
|
14
|
+
"commit-and-tag-version",
|
|
17
15
|
"managed-by-autotool",
|
|
18
|
-
"
|
|
19
|
-
"tsconfig",
|
|
20
|
-
"turbo",
|
|
21
|
-
"typescript"
|
|
16
|
+
"standard-version"
|
|
22
17
|
],
|
|
23
18
|
"author": {
|
|
24
19
|
"email": "alexaegis@gmail.com",
|
|
@@ -27,9 +22,9 @@
|
|
|
27
22
|
},
|
|
28
23
|
"homepage": "https://github.com/AlexAegis/js-tooling",
|
|
29
24
|
"repository": {
|
|
30
|
-
"
|
|
25
|
+
"url": "git+https://github.com/AlexAegis/js-tooling",
|
|
31
26
|
"type": "git",
|
|
32
|
-
"
|
|
27
|
+
"directory": "packages/standard-version"
|
|
33
28
|
},
|
|
34
29
|
"bugs": {
|
|
35
30
|
"email": "alexaegis@gmail.com",
|
|
@@ -50,28 +45,29 @@
|
|
|
50
45
|
".": {
|
|
51
46
|
"types": "./index.d.ts",
|
|
52
47
|
"import": "./index.js",
|
|
53
|
-
"require": "./index.cjs"
|
|
48
|
+
"require": "./index.cjs",
|
|
49
|
+
"default": "./index.js"
|
|
54
50
|
},
|
|
55
51
|
"./readme": "./readme.md"
|
|
56
52
|
},
|
|
57
53
|
"dependencies": {
|
|
58
|
-
"@alexaegis/common": "^0.2.
|
|
59
|
-
"@alexaegis/coverage-tools": "^0.2.
|
|
60
|
-
"@alexaegis/workspace-tools": "^0.2.
|
|
61
|
-
"glob": "^10.
|
|
54
|
+
"@alexaegis/common": "^0.2.3",
|
|
55
|
+
"@alexaegis/coverage-tools": "^0.2.3",
|
|
56
|
+
"@alexaegis/workspace-tools": "^0.2.3",
|
|
57
|
+
"glob": "^10.3.0",
|
|
62
58
|
"js-yaml": "^4.1.0"
|
|
63
59
|
},
|
|
64
60
|
"devDependencies": {
|
|
65
|
-
"@alexaegis/eslint-config-vitest": "^0.3.
|
|
66
|
-
"@alexaegis/ts": "^0.3.
|
|
67
|
-
"@alexaegis/vite": "^0.3.
|
|
68
|
-
"@alexaegis/vitest": "^0.3.
|
|
61
|
+
"@alexaegis/eslint-config-vitest": "^0.3.3",
|
|
62
|
+
"@alexaegis/ts": "^0.3.3",
|
|
63
|
+
"@alexaegis/vite": "^0.3.3",
|
|
64
|
+
"@alexaegis/vitest": "^0.3.3",
|
|
69
65
|
"@types/js-yaml": "^4.0.5",
|
|
70
|
-
"@types/node": "^20.2
|
|
66
|
+
"@types/node": "^20.3.2",
|
|
71
67
|
"publint": "^0.1.12",
|
|
72
|
-
"typescript": "^5.
|
|
68
|
+
"typescript": "^5.1.3",
|
|
73
69
|
"vite": "^4.3.9",
|
|
74
|
-
"vitest": "^0.
|
|
70
|
+
"vitest": "^0.32.2"
|
|
75
71
|
},
|
|
76
72
|
"scripts": {
|
|
77
73
|
"build": "turbo run build-lib_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
|
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.3.
|
|
15
|
+
npm i @alexaegis/standard-version@0.3.3
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
```json
|
|
19
19
|
{
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@alexaegis/standard-version": "^0.3.
|
|
21
|
+
"@alexaegis/standard-version": "^0.3.3"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WorkspacePackage } from '@alexaegis/workspace-tools';
|
|
2
|
+
export declare const PACKAGE_JSON_DEPENDENCY_FIELDS: readonly ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
2
3
|
/**
|
|
3
4
|
* The functions found in this file are copied from @alexaegis/workspace-tools
|
|
4
5
|
* to be a sync, non-esm (globby is only esm) variant that could be invoked
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-packages.d.ts","sourceRoot":"","sources":["../../../src/workspace/collect-packages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkC,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAQnG;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;sBACT,gBAAgB;iBACrB,gBAAgB,EAAE;CAyD/B,CAAC"}
|
|
1
|
+
{"version":3,"file":"collect-packages.d.ts","sourceRoot":"","sources":["../../../src/workspace/collect-packages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkC,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAQnG,eAAO,MAAM,8BAA8B,0FAKjC,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;sBACT,gBAAgB;iBACrB,gBAAgB,EAAE;CAyD/B,CAAC"}
|
|
@@ -7,8 +7,8 @@ import type { WorkspacePackage } from '@alexaegis/workspace-tools';
|
|
|
7
7
|
*
|
|
8
8
|
* It also replaces everything that looks like a `packageName@version`
|
|
9
9
|
*/
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const createGenericUpdater: (packages: WorkspacePackage[]) => {
|
|
11
11
|
readVersion: (contents: string) => string;
|
|
12
12
|
writeVersion: (contents: string, version: string) => string;
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=generic-updater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-updater.d.ts","sourceRoot":"","sources":["../../../src/workspace/generic-updater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,aAAc,gBAAgB,EAAE;4BAEvC,MAAM,KAAG,MAAM;6BAId,MAAM,WAAW,MAAM,KAAG,MAAM;CAuB1D,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 createPackageJsonUpdater: (packages: WorkspacePackage[]) => {
|
|
11
|
+
readVersion: (contents: string) => string;
|
|
12
|
+
writeVersion: (contents: string, version: string) => string;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=package-json-updater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json-updater.d.ts","sourceRoot":"","sources":["../../../src/workspace/package-json-updater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAOhF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,aAAc,gBAAgB,EAAE;4BAE3C,MAAM,KAAG,MAAM;6BAId,MAAM,WAAW,MAAM,KAAG,MAAM;CA+B1D,CAAC"}
|
package/manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|