@alexaegis/standard-version 0.0.5 → 0.1.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/config/config.d.ts +4 -0
- package/config/config.d.ts.map +1 -1
- package/index.cjs +6 -2
- package/index.cjs.map +1 -1
- package/index.js +6 -2
- package/index.js.map +1 -1
- package/package.json +13 -10
- package/readme.md +2 -2
package/config/config.d.ts
CHANGED
package/config/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B;;;;;;;;;;;;CA2BvC,CAAC"}
|
package/index.cjs
CHANGED
|
@@ -75,8 +75,8 @@ const createUpdater = (packages) => {
|
|
|
75
75
|
writeVersion: (contents, version) => {
|
|
76
76
|
return packages.map((localPackage) => localPackage.packageJson.name).filter(common.isNotNullish).reduce(
|
|
77
77
|
(r, localPackageName) => r.replaceAll(
|
|
78
|
-
new RegExp(`"${localPackageName}": "
|
|
79
|
-
`"${localPackageName}": "${version}"`
|
|
78
|
+
new RegExp(`"${localPackageName}": "(.*:)?[~^]?.*"`, "g"),
|
|
79
|
+
`"${localPackageName}": "$1^${version}"`
|
|
80
80
|
).replaceAll(
|
|
81
81
|
new RegExp(`${localPackageName}@([^s
|
|
82
82
|
\r]+)`, "g"),
|
|
@@ -91,6 +91,10 @@ const createStandardVersionConfig = () => {
|
|
|
91
91
|
const { workspacePackage, subPackages } = collectPackages();
|
|
92
92
|
const updater = createUpdater(subPackages);
|
|
93
93
|
return {
|
|
94
|
+
scripts: {
|
|
95
|
+
postbump: "pnpm install",
|
|
96
|
+
prechangelog: "git add pnpm-lock.yaml"
|
|
97
|
+
},
|
|
94
98
|
bumpFiles: [
|
|
95
99
|
{
|
|
96
100
|
filename: node_path.join(workspacePackage.path, "package.json"),
|
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 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}\": \"
|
|
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}\": \"$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: 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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AACpD,QAAA,UAAU,cAAc,WAAW;AAClC,SAAA;AAAA,IACN,SAAS;AAAA,MACR,UAAU;AAAA,MACV,cAAc;AAAA,IACf;AAAA,IACA,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.js
CHANGED
|
@@ -73,8 +73,8 @@ const createUpdater = (packages) => {
|
|
|
73
73
|
writeVersion: (contents, version) => {
|
|
74
74
|
return packages.map((localPackage) => localPackage.packageJson.name).filter(isNotNullish).reduce(
|
|
75
75
|
(r, localPackageName) => r.replaceAll(
|
|
76
|
-
new RegExp(`"${localPackageName}": "
|
|
77
|
-
`"${localPackageName}": "${version}"`
|
|
76
|
+
new RegExp(`"${localPackageName}": "(.*:)?[~^]?.*"`, "g"),
|
|
77
|
+
`"${localPackageName}": "$1^${version}"`
|
|
78
78
|
).replaceAll(
|
|
79
79
|
new RegExp(`${localPackageName}@([^s
|
|
80
80
|
\r]+)`, "g"),
|
|
@@ -89,6 +89,10 @@ const createStandardVersionConfig = () => {
|
|
|
89
89
|
const { workspacePackage, subPackages } = collectPackages();
|
|
90
90
|
const updater = createUpdater(subPackages);
|
|
91
91
|
return {
|
|
92
|
+
scripts: {
|
|
93
|
+
postbump: "pnpm install",
|
|
94
|
+
prechangelog: "git add pnpm-lock.yaml"
|
|
95
|
+
},
|
|
92
96
|
bumpFiles: [
|
|
93
97
|
{
|
|
94
98
|
filename: join(workspacePackage.path, "package.json"),
|
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 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}\": \"
|
|
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}\": \"$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: 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\tupd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A,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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexaegis/standard-version",
|
|
3
3
|
"description": "Standard version",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"license": "mit",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": {
|
|
@@ -42,26 +42,29 @@
|
|
|
42
42
|
"./readme": "./readme.md"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@alexaegis/cli-tools": "0.0.
|
|
46
|
-
"@alexaegis/common": "0.0.
|
|
47
|
-
"@alexaegis/coverage-tools": "0.0.
|
|
48
|
-
"@alexaegis/logging": "0.0.
|
|
49
|
-
"@alexaegis/workspace-tools": "0.0.
|
|
45
|
+
"@alexaegis/cli-tools": "^0.0.24",
|
|
46
|
+
"@alexaegis/common": "^0.0.24",
|
|
47
|
+
"@alexaegis/coverage-tools": "^0.0.24",
|
|
48
|
+
"@alexaegis/logging": "^0.0.24",
|
|
49
|
+
"@alexaegis/workspace-tools": "^0.0.24",
|
|
50
50
|
"@lcov-viewer/cli": "^1.3.0",
|
|
51
51
|
"glob": "^9.3.4",
|
|
52
52
|
"js-yaml": "^4.1.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@alexaegis/
|
|
56
|
-
"@alexaegis/
|
|
55
|
+
"@alexaegis/eslint-config-vitest": "^0.1.0",
|
|
56
|
+
"@alexaegis/vite": "^0.1.0",
|
|
57
|
+
"@alexaegis/vitest": "^0.1.0",
|
|
57
58
|
"@types/js-yaml": "^4.0.5",
|
|
58
59
|
"@types/node": "^18.15.11",
|
|
59
|
-
"typescript": "5.0.
|
|
60
|
-
"vite": "4.2.1"
|
|
60
|
+
"typescript": "^5.0.4",
|
|
61
|
+
"vite": "^4.2.1"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|
|
63
64
|
"build": "turbo run build-lib_ --concurrency 6 --filter @alexaegis/standard-version",
|
|
64
65
|
"build-lib_": "vite build",
|
|
66
|
+
"lint:depcheck": "turbo run lint:depcheck_ --concurrency 6 --filter @alexaegis/standard-version",
|
|
67
|
+
"lint:depcheck_": "depcheck",
|
|
65
68
|
"lint:es": "turbo run lint:es_ --concurrency 6 --filter @alexaegis/standard-version",
|
|
66
69
|
"lint:es_": "eslint --max-warnings=0 --fix --no-error-on-unmatched-pattern .",
|
|
67
70
|
"lint:format": "turbo run lint:format_ --concurrency 6 --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.0
|
|
15
|
+
npm i @alexaegis/standard-version@0.1.0
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
```json
|
|
19
19
|
{
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@alexaegis/standard-version": "0.0
|
|
21
|
+
"@alexaegis/standard-version": "^0.1.0"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
```
|