{"version":3,"file":"index.cjs","names":[],"sources":["../src/workspace/collect-packages.ts","../src/workspace/generic-updater.ts","../src/workspace/package-json-updater.ts","../src/config/config.ts"],"sourcesContent":["import type { PackageJson, PnpmWorkspaceYaml, WorkspacePackage } from '@alexaegis/workspace-tools';\nimport { globSync } from 'glob';\nimport { load } from 'js-yaml';\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join, normalize, relative } from 'node:path';\n\nconst PACKAGE_JSON_NAME = 'package.json';\n\nexport const PACKAGE_JSON_DEPENDENCY_FIELDS = [\n\t'dependencies',\n\t'devDependencies',\n\t'optionalDependencies',\n\t'peerDependencies',\n] as const;\n\n/**\n * The functions found in this file are copied from @alexaegis/workspace-tools\n * to be a sync, non-esm (globby is only esm) variant that could be invoked\n * from a CJS based configuration file.\n *\n * ? Once standard-version/commit-and-version is migrated to ESM, this can be removed\n */\nexport const collectPackages = (): {\n\tworkspacePackage: WorkspacePackage;\n\tsubPackages: WorkspacePackage[];\n} => {\n\tconst workspaceRoot = getWorkspaceRoot();\n\n\tif (!workspaceRoot) {\n\t\tthrow new Error('not in a workspace');\n\t}\n\n\tconst pnpmWorkspace = load(\n\t\treadFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), { encoding: 'utf8' }),\n\t) as PnpmWorkspaceYaml;\n\n\tconst workspacePackageJsonPath = join(workspaceRoot, PACKAGE_JSON_NAME);\n\tconst workspacePackageJson = JSON.parse(\n\t\treadFileSync(workspacePackageJsonPath, { encoding: 'utf8' }),\n\t) as PackageJson;\n\n\tlet workspaces = normalizePackageJsonWorkspacesField(workspacePackageJson.workspaces);\n\n\tif (pnpmWorkspace.packages) {\n\t\tworkspaces = [...workspaces, ...pnpmWorkspace.packages];\n\t}\n\n\tconst packagePaths = globSync(workspaces, {\n\t\tignore: ['node_modules'],\n\t\tcwd: workspaceRoot,\n\t\tabsolute: true,\n\t}).filter((path) => statSync(path).isDirectory());\n\n\tconst workspacePackage: WorkspacePackage = {\n\t\tpackageKind: 'root',\n\t\tpackagePath: workspaceRoot,\n\t\tpackageJson: workspacePackageJson,\n\t\tpackageJsonPath: workspacePackageJsonPath,\n\t\tworkspacePackagePatterns: workspaces,\n\t\tpackagePathFromRootPackage: '.',\n\t};\n\tconst subPackages: WorkspacePackage[] = packagePaths\n\t\t.map((packagePath) => {\n\t\t\tconst packageJsonPath = join(packagePath, PACKAGE_JSON_NAME);\n\t\t\ttry {\n\t\t\t\treturn {\n\t\t\t\t\tpackageKind: 'regular',\n\t\t\t\t\tpackagePath: packagePath.toString(),\n\t\t\t\t\tpackageJsonPath,\n\t\t\t\t\tpackageJson: JSON.parse(\n\t\t\t\t\t\treadFileSync(packageJsonPath, { encoding: 'utf8' }),\n\t\t\t\t\t) as PackageJson,\n\t\t\t\t\tpackagePathFromRootPackage: relative(workspaceRoot, dirname(packageJsonPath)),\n\t\t\t\t} as WorkspacePackage;\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((pkg): pkg is WorkspacePackage => !!pkg);\n\n\treturn { workspacePackage, subPackages };\n};\n\nconst getWorkspaceRoot = (cwd: string = process.cwd()): string | undefined => {\n\treturn collectPackageJsonPathsUpDirectoryTree(cwd)[0];\n};\n\nconst collectPackageJsonPathsUpDirectoryTree = (cwd: string = process.cwd()): string[] => {\n\treturn collectPackageJsonPathsUpDirectoryTreeInternal(cwd);\n};\n\nconst collectPackageJsonPathsUpDirectoryTreeInternal = (\n\tcwd: string,\n\tcollection: string[] = [],\n): string[] => {\n\tconst path = normalize(cwd);\n\n\tif (existsSync(join(path, 'package.json'))) {\n\t\tcollection.unshift(path);\n\t}\n\n\tconst parentPath = join(path, '..');\n\tif (parentPath !== path) {\n\t\treturn collectPackageJsonPathsUpDirectoryTreeInternal(parentPath, collection);\n\t}\n\n\treturn collection;\n};\n\nconst normalizePackageJsonWorkspacesField = (\n\tpackageJsonWorkspaces?: PackageJson['workspaces'],\n): string[] => {\n\tif (Array.isArray(packageJsonWorkspaces)) {\n\t\treturn packageJsonWorkspaces;\n\t} else if (packageJsonWorkspaces) {\n\t\treturn [\n\t\t\t...(packageJsonWorkspaces.packages ?? []),\n\t\t\t...(packageJsonWorkspaces.nohoist ?? []),\n\t\t];\n\t} else {\n\t\treturn [];\n\t}\n};\n","import type { WorkspacePackage } from '@alexaegis/workspace-tools';\n\n/**\n * This updater also updates all local dependencies too that were updated\n * While it's mainly used for packageJson files, it does not assume the file to\n * be valid JSON, so it can be used with any file that contains lines like\n * \"version\": \"0.0.0\", like examples in readme files.\n *\n * It also replaces everything that looks like a `packageName@version`\n */\nexport const createGenericUpdater = (packages: WorkspacePackage[]) => {\n\treturn {\n\t\treadVersion: (contents: string): string => {\n\t\t\tconst results = [...contents.matchAll(/\"version\": \"(.*)\"/g)];\n\t\t\treturn results[0]?.[1] ?? '0.0.0';\n\t\t},\n\t\twriteVersion: (contents: string, version: string): string => {\n\t\t\treturn packages\n\t\t\t\t.map((localPackage) => localPackage.packageJson.name)\n\t\t\t\t.filter((name): name is string => !!name)\n\t\t\t\t.reduce(\n\t\t\t\t\t(r, localPackageName) =>\n\t\t\t\t\t\tr\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`\"${localPackageName}\": \"(workspace:)([~^])?.*\"`, 'g'),\n\t\t\t\t\t\t\t\t`\"${localPackageName}\": \"$1$2\"`, // the workspace protocol does not include versions but keeps the specifier. This is how pnpm leaves them on install.\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`\"${localPackageName}\": \"(?!workspace:)([~^])?.*\"`, 'g'),\n\t\t\t\t\t\t\t\t`\"${localPackageName}\": \"$1${version}\"`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.replaceAll(\n\t\t\t\t\t\t\t\tnew RegExp(`${localPackageName}@([^s\\t\\n\\r]+)`, 'g'),\n\t\t\t\t\t\t\t\t`${localPackageName}@${version}`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\tcontents.replace(/\"version\": \".*\"/, `\"version\": \"${version}\"`),\n\t\t\t\t);\n\t\t},\n\t};\n};\n","import type { PackageJson, WorkspacePackage } from '@alexaegis/workspace-tools';\n\nimport { PACKAGE_JSON_DEPENDENCY_FIELDS } from './collect-packages.js';\n\nconst workspaceDependencyVersionRegexp = /^(workspace:)([\\^~])?.*$/g;\nconst nonWorkspaceDependencyVersionRegexp = /^(?!workspace:)([\\^~])?.*$/g;\n\n/**\n * This updater also updates all local dependencies too that were updated\n * While it's mainly used for packageJson files, it does not assume the file to\n * be valid JSON, so it can be used with any file that contains lines like\n * \"version\": \"0.0.0\", like examples in readme files.\n *\n * It also replaces everything that looks like a `packageName@version`\n */\nexport const createPackageJsonUpdater = (packages: WorkspacePackage[]) => {\n\treturn {\n\t\treadVersion: (contents: string): string => {\n\t\t\tconst results = [...contents.matchAll(/\"version\": \"(.*)\"/g)];\n\t\t\treturn results[0]?.[1] ?? '0.0.0';\n\t\t},\n\t\twriteVersion: (contents: string, version: string): string => {\n\t\t\tconst packageJson: PackageJson = JSON.parse(contents) as PackageJson;\n\t\t\tconst indent = '\\t';\n\t\t\tconst newline = contents.includes('\\r\\n') ? '\\r\\n' : '\\n';\n\t\t\tpackageJson.version = version;\n\n\t\t\tfor (const localPackageName of packages\n\t\t\t\t.map((localPackage) => localPackage.packageJson.name)\n\t\t\t\t.filter((name): name is string => !!name)) {\n\t\t\t\tfor (const dependencyField of PACKAGE_JSON_DEPENDENCY_FIELDS) {\n\t\t\t\t\tconst dependencies = packageJson[dependencyField];\n\n\t\t\t\t\tconst localDependency: string | undefined = dependencies?.[localPackageName];\n\n\t\t\t\t\tif (dependencies && localDependency) {\n\t\t\t\t\t\tdependencies[localPackageName] = localDependency\n\t\t\t\t\t\t\t.replaceAll(workspaceDependencyVersionRegexp, '$1$2')\n\t\t\t\t\t\t\t.replaceAll(nonWorkspaceDependencyVersionRegexp, `$1${version}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst json = JSON.stringify(packageJson, undefined, indent);\n\n\t\t\tif (newline === '\\r\\n') {\n\t\t\t\treturn json.replaceAll('\\n', '\\r\\n') + '\\r\\n';\n\t\t\t}\n\n\t\t\treturn json + '\\n';\n\t\t},\n\t};\n};\n","import { join } from 'node:path';\nimport { collectPackages } from '../workspace/collect-packages.js';\nimport { createGenericUpdater } from '../workspace/generic-updater.js';\nimport { createPackageJsonUpdater } from '../workspace/package-json-updater.js';\n\nexport const createStandardVersionConfig = () => {\n\tconst { workspacePackage, subPackages } = collectPackages();\n\tconst packageJsonUpdater = createPackageJsonUpdater(subPackages);\n\tconst genericUpdater = createGenericUpdater(subPackages);\n\n\treturn {\n\t\tscripts: {\n\t\t\tpostbump: 'pnpm install',\n\t\t\tprechangelog: 'git add pnpm-lock.yaml',\n\t\t},\n\t\tbumpFiles: [\n\t\t\t{\n\t\t\t\tfilename: workspacePackage.packageJsonPath,\n\t\t\t\tupdater: packageJsonUpdater,\n\t\t\t},\n\t\t\t{\n\t\t\t\tfilename: join(workspacePackage.packagePath, 'readme.md'),\n\t\t\t\tupdater: genericUpdater,\n\t\t\t},\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: pkg.packageJsonPath,\n\t\t\t\tupdater: packageJsonUpdater,\n\t\t\t})),\n\t\t\t...subPackages.map((pkg) => ({\n\t\t\t\tfilename: join(pkg.packagePath, 'readme.md'),\n\t\t\t\tupdater: genericUpdater,\n\t\t\t})),\n\t\t],\n\t};\n};\n"],"mappings":";;;;;;AAMA,IAAM,oBAAoB;AAE1B,IAAa,iCAAiC;CAC7C;CACA;CACA;CACA;AACD;;;;;;;;AASA,IAAa,wBAGR;CACJ,MAAM,gBAAgB,iBAAiB;CAEvC,IAAI,CAAC,eACJ,MAAM,IAAI,MAAM,oBAAoB;CAGrC,MAAM,iBAAA,GAAA,QAAA,KAAA,EAAA,GAAA,QAAA,aAAA,EAAA,GAAA,UAAA,KAAA,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