@alexaegis/standard-version 0.2.0 → 0.3.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/index.cjs CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const node_path = require("node:path");
4
+ const common = require("@alexaegis/common");
4
5
  const glob = require("glob");
5
6
  const jsYaml = require("js-yaml");
6
7
  const node_fs = require("node:fs");
7
- const common = require("@alexaegis/common");
8
+ const PACKAGE_JSON_NAME = "package.json";
8
9
  const collectPackages = () => {
9
10
  const workspaceRoot = getWorkspaceRoot();
10
11
  if (!workspaceRoot) {
@@ -13,8 +14,9 @@ const collectPackages = () => {
13
14
  const pnpmWorkspace = jsYaml.load(
14
15
  node_fs.readFileSync(node_path.join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" })
15
16
  );
17
+ const workspacePackageJsonPath = node_path.join(workspaceRoot, PACKAGE_JSON_NAME);
16
18
  const workspacePackageJson = JSON.parse(
17
- node_fs.readFileSync(node_path.join(workspaceRoot, "package.json"), { encoding: "utf8" })
19
+ node_fs.readFileSync(workspacePackageJsonPath, { encoding: "utf8" })
18
20
  );
19
21
  let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
20
22
  if (pnpmWorkspace.packages) {
@@ -26,15 +28,29 @@ const collectPackages = () => {
26
28
  absolute: true
27
29
  }).filter((path) => node_fs.statSync(path).isDirectory());
28
30
  const workspacePackage = {
29
- path: workspaceRoot,
30
- packageJson: workspacePackageJson
31
+ packageKind: "root",
32
+ packagePath: workspaceRoot,
33
+ packageJson: workspacePackageJson,
34
+ packageJsonPath: workspacePackageJsonPath,
35
+ workspacePackagePatterns: workspaces,
36
+ packagePathFromRootPackage: "."
31
37
  };
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
+ const subPackages = packagePaths.map((packagePath) => {
39
+ const packageJsonPath = node_path.join(packagePath, PACKAGE_JSON_NAME);
40
+ try {
41
+ return {
42
+ packageKind: "regular",
43
+ packagePath: packagePath.toString(),
44
+ packageJsonPath,
45
+ packageJson: JSON.parse(
46
+ node_fs.readFileSync(packageJsonPath, { encoding: "utf8" })
47
+ ),
48
+ packagePathFromRootPackage: node_path.relative(workspaceRoot, node_path.dirname(packageJsonPath))
49
+ };
50
+ } catch {
51
+ return void 0;
52
+ }
53
+ }).filter(common.isNotNullish);
38
54
  return { workspacePackage, subPackages };
39
55
  };
40
56
  const getWorkspaceRoot = (cwd = process.cwd()) => {
@@ -97,19 +113,19 @@ const createStandardVersionConfig = () => {
97
113
  },
98
114
  bumpFiles: [
99
115
  {
100
- filename: node_path.join(workspacePackage.path, "package.json"),
116
+ filename: workspacePackage.packageJsonPath,
101
117
  updater
102
118
  },
103
119
  {
104
- filename: node_path.join(workspacePackage.path, "readme.md"),
120
+ filename: node_path.join(workspacePackage.packagePath, "readme.md"),
105
121
  updater
106
122
  },
107
- ...subPackages.map((p) => ({
108
- filename: node_path.join(p.path, "package.json"),
123
+ ...subPackages.map((pkg) => ({
124
+ filename: node_path.join(pkg.packagePath, "package.json"),
109
125
  updater
110
126
  })),
111
- ...subPackages.map((p) => ({
112
- filename: node_path.join(p.path, "readme.md"),
127
+ ...subPackages.map((pkg) => ({
128
+ filename: node_path.join(pkg.packagePath, "readme.md"),
113
129
  updater
114
130
  }))
115
131
  ]
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}\": \"(.*:)?[~^]?.*\"`, '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\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;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OAAO;AAAA,QAC1B,UAAUA,UAAA,KAAK,EAAE,MAAM,WAAW;AAAA,QAClC;AAAA,MAAA,EACC;AAAA,IACH;AAAA,EAAA;AAEF;;;"}
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;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;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AA,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;;;"}
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
- import { join, normalize } from "node:path";
1
+ import { join, relative, dirname, normalize } from "node:path";
2
+ import { isNotNullish } from "@alexaegis/common";
2
3
  import { globSync } from "glob";
3
4
  import { load } from "js-yaml";
4
5
  import { readFileSync, statSync, existsSync } from "node:fs";
5
- import { isNotNullish } from "@alexaegis/common";
6
+ const PACKAGE_JSON_NAME = "package.json";
6
7
  const collectPackages = () => {
7
8
  const workspaceRoot = getWorkspaceRoot();
8
9
  if (!workspaceRoot) {
@@ -11,8 +12,9 @@ const collectPackages = () => {
11
12
  const pnpmWorkspace = load(
12
13
  readFileSync(join(workspaceRoot, "pnpm-workspace.yaml"), { encoding: "utf8" })
13
14
  );
15
+ const workspacePackageJsonPath = join(workspaceRoot, PACKAGE_JSON_NAME);
14
16
  const workspacePackageJson = JSON.parse(
15
- readFileSync(join(workspaceRoot, "package.json"), { encoding: "utf8" })
17
+ readFileSync(workspacePackageJsonPath, { encoding: "utf8" })
16
18
  );
17
19
  let workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);
18
20
  if (pnpmWorkspace.packages) {
@@ -24,15 +26,29 @@ const collectPackages = () => {
24
26
  absolute: true
25
27
  }).filter((path) => statSync(path).isDirectory());
26
28
  const workspacePackage = {
27
- path: workspaceRoot,
28
- packageJson: workspacePackageJson
29
+ packageKind: "root",
30
+ packagePath: workspaceRoot,
31
+ packageJson: workspacePackageJson,
32
+ packageJsonPath: workspacePackageJsonPath,
33
+ workspacePackagePatterns: workspaces,
34
+ packagePathFromRootPackage: "."
29
35
  };
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
+ const subPackages = packagePaths.map((packagePath) => {
37
+ const packageJsonPath = join(packagePath, PACKAGE_JSON_NAME);
38
+ try {
39
+ return {
40
+ packageKind: "regular",
41
+ packagePath: packagePath.toString(),
42
+ packageJsonPath,
43
+ packageJson: JSON.parse(
44
+ readFileSync(packageJsonPath, { encoding: "utf8" })
45
+ ),
46
+ packagePathFromRootPackage: relative(workspaceRoot, dirname(packageJsonPath))
47
+ };
48
+ } catch {
49
+ return void 0;
50
+ }
51
+ }).filter(isNotNullish);
36
52
  return { workspacePackage, subPackages };
37
53
  };
38
54
  const getWorkspaceRoot = (cwd = process.cwd()) => {
@@ -95,19 +111,19 @@ const createStandardVersionConfig = () => {
95
111
  },
96
112
  bumpFiles: [
97
113
  {
98
- filename: join(workspacePackage.path, "package.json"),
114
+ filename: workspacePackage.packageJsonPath,
99
115
  updater
100
116
  },
101
117
  {
102
- filename: join(workspacePackage.path, "readme.md"),
118
+ filename: join(workspacePackage.packagePath, "readme.md"),
103
119
  updater
104
120
  },
105
- ...subPackages.map((p) => ({
106
- filename: join(p.path, "package.json"),
121
+ ...subPackages.map((pkg) => ({
122
+ filename: join(pkg.packagePath, "package.json"),
107
123
  updater
108
124
  })),
109
- ...subPackages.map((p) => ({
110
- filename: join(p.path, "readme.md"),
125
+ ...subPackages.map((pkg) => ({
126
+ filename: join(pkg.packagePath, "readme.md"),
111
127
  updater
112
128
  }))
113
129
  ]
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}\": \"(.*:)?[~^]?.*\"`, '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\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,GAAG,cAAc,QAAQ;AAAA,EACvD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AA6B;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,sCAAsC,GAAG;AAAA,UACxD,IAAI,0BAA0B;AAAA,QAAA,EAE9B;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,SAAS;AAAA,MACR,UAAU;AAAA,MACV,cAAc;AAAA,IACf;AAAA,IACA,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;"}
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,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,i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,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,sCAAsC,GAAG;AAAA,UACxD,IAAI,0BAA0B;AAAA,QAAA,EAE9B;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,SAAS;AAAA,MACR,UAAU;AAAA,MACV,cAAc;AAAA,IACf;AAAA,IACA,WAAW;AAAA,MACV;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;"}
package/package.json CHANGED
@@ -1,28 +1,35 @@
1
1
  {
2
2
  "name": "@alexaegis/standard-version",
3
3
  "description": "Standard version",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "license": "mit",
6
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"
7
+ "archetype": {
8
+ "platform": "node",
9
+ "framework": "autotool",
10
+ "language": "ts",
11
+ "kind": "lib"
16
12
  },
17
13
  "keywords": [
18
14
  "eslint",
19
15
  "javascript",
20
16
  "js",
17
+ "managed-by-autotool",
21
18
  "ts",
22
19
  "tsconfig",
23
20
  "turbo",
24
21
  "typescript"
25
22
  ],
23
+ "author": {
24
+ "email": "alexaegis@gmail.com",
25
+ "name": "Alex Aegis",
26
+ "url": "https://github.com/AlexAegis"
27
+ },
28
+ "homepage": "https://github.com/AlexAegis/js-tooling",
29
+ "bugs": {
30
+ "email": "alexaegis@gmail.com",
31
+ "url": "https://github.com/AlexAegis/js-tooling/issues"
32
+ },
26
33
  "type": "module",
27
34
  "config": {
28
35
  "engine-strict": true
@@ -42,39 +49,42 @@
42
49
  "./readme": "./readme.md"
43
50
  },
44
51
  "dependencies": {
45
- "@alexaegis/common": "^0.1.4",
46
- "@alexaegis/coverage-tools": "^0.1.4",
47
- "@alexaegis/workspace-tools": "^0.1.4",
48
- "@lcov-viewer/cli": "^1.3.0",
49
- "glob": "^10.2.1",
52
+ "@alexaegis/common": "^0.1.8",
53
+ "@alexaegis/coverage-tools": "^0.1.8",
54
+ "@alexaegis/workspace-tools": "^0.1.8",
55
+ "glob": "^10.2.5",
50
56
  "js-yaml": "^4.1.0"
51
57
  },
52
58
  "devDependencies": {
53
- "@alexaegis/eslint-config-vitest": "^0.2.0",
54
- "@alexaegis/ts": "^0.2.0",
55
- "@alexaegis/vite": "^0.2.0",
56
- "@alexaegis/vitest": "^0.2.0",
59
+ "@alexaegis/eslint-config-vitest": "^0.3.0",
60
+ "@alexaegis/ts": "^0.3.0",
61
+ "@alexaegis/vite": "^0.3.0",
62
+ "@alexaegis/vitest": "^0.3.0",
57
63
  "@types/js-yaml": "^4.0.5",
58
- "@types/node": "^18.15.13",
64
+ "@types/node": "^20.2.1",
65
+ "publint": "^0.1.11",
59
66
  "typescript": "^5.0.4",
60
- "vite": "^4.3.1"
67
+ "vite": "^4.3.8",
68
+ "vitest": "^0.31.1"
61
69
  },
62
70
  "scripts": {
63
- "build": "turbo run build-lib_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
71
+ "build": "turbo run build-lib_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
64
72
  "build-lib_": "vite build",
65
- "lint:depcheck": "turbo run lint:depcheck_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
73
+ "lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
66
74
  "lint:depcheck_": "depcheck",
67
- "lint:es": "turbo run lint:es_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
75
+ "lint:es": "turbo run lint:es_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
68
76
  "lint:es_": "eslint --max-warnings=0 --fix --no-error-on-unmatched-pattern .",
69
- "lint:format": "turbo run lint:format_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
77
+ "lint:format": "turbo run lint:format_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
70
78
  "lint:format_": "prettier --check .",
71
- "lint:md": "turbo run lint:md_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
79
+ "lint:md": "turbo run lint:md_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
72
80
  "lint:md_": "remark --frail --no-stdout --silently-ignore *.md docs/**/*.md",
73
- "lint:tsc": "turbo run lint:tsc_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
81
+ "lint:tsc": "turbo run lint:tsc_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
74
82
  "lint:tsc_": "tsc --noEmit",
83
+ "publint": "turbo run publint_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
84
+ "publint_": "publint dist",
75
85
  "format": "prettier --write .",
76
- "test": "turbo run test_ --concurrency 6 --cache-dir .cache/turbo --filter @alexaegis/standard-version && merge-workspace-lcov-reports && lcov-viewer lcov -o ./coverage ./coverage/lcov.info",
86
+ "test": "turbo run test_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/standard-version",
77
87
  "test_": "vitest --passWithNoTests --coverage --run",
78
- "test:watch": "vitest --passWithNoTests --coverage --run"
88
+ "test:watch": "vitest --passWithNoTests --coverage"
79
89
  }
80
90
  }
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.2.0
15
+ npm i @alexaegis/standard-version@0.3.0
16
16
  ```
17
17
 
18
18
  ```json
19
19
  {
20
20
  "dependencies": {
21
- "@alexaegis/standard-version": "^0.2.0"
21
+ "@alexaegis/standard-version": "^0.3.0"
22
22
  }
23
23
  }
24
24
  ```
@@ -3,6 +3,8 @@ import type { WorkspacePackage } from '@alexaegis/workspace-tools';
3
3
  * The functions found in this file are copied from @alexaegis/workspace-tools
4
4
  * to be a sync, non-esm (globby is only esm) variant that could be invoked
5
5
  * from a CJS based configuration file.
6
+ *
7
+ * ? Once standard-version/commit-and-version is migrated to ESM, this can be removed
6
8
  */
7
9
  export declare const collectPackages: () => {
8
10
  workspacePackage: WorkspacePackage;
@@ -1 +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"}
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"}