@aws/nx-plugin 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-THIRD-PARTY +107 -259
- package/migrations.json +53 -15
- package/package.json +14 -14
- package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/greengrass/component/python/__snapshots__/generator.spec.ts.snap +8 -8
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/migrations/latest/biome-markdown-yaml-formatter-off/metadata.json +3 -0
- package/src/migrations/latest/biome-markdown-yaml-formatter-off/migration.js +113 -0
- package/src/migrations/latest/biome-markdown-yaml-formatter-off/migration.js.map +1 -0
- package/src/migrations/v1.0.15/0001-py-agent-pillow-override/migration.js.map +1 -0
- package/src/migrations/v1.1.1/0001-ts-agent-guardrails-synth-input/migration.js.map +1 -0
- package/src/migrations/v1.3.0/0001-ts-agent-guardrails-terraform-version-retention/migration.d.ts +6 -0
- package/src/migrations/v1.3.0/0001-ts-agent-guardrails-terraform-version-retention/migration.js.map +1 -0
- package/src/preset/__snapshots__/generator.spec.ts.snap +15 -5
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +7 -7
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +4 -4
- package/src/py/agent/guardrails/__snapshots__/generator.spec.ts.snap +6 -6
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/py/rdb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +5 -5
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +8 -8
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/ts/agent/guardrails/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/ts/dcr-proxy/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +53 -33
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
- package/src/utils/format.d.ts +10 -0
- package/src/utils/format.js +11 -0
- package/src/utils/format.js.map +1 -1
- package/src/utils/version-upgrade-migration/sync-vended-versions.d.ts +8 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.js +11 -2
- package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -1
- package/src/utils/versions.d.ts +71 -71
- package/src/utils/versions.js +68 -68
- package/src/utils/versions.js.map +1 -1
- package/src/migrations/latest/py-agent-pillow-override/migration.js.map +0 -1
- package/src/migrations/latest/ts-agent-guardrails-synth-input/migration.js.map +0 -1
- package/src/migrations/latest/ts-agent-guardrails-terraform-version-retention/migration.js.map +0 -1
- /package/src/migrations/latest/{ts-agent-guardrails-terraform-version-retention → biome-markdown-yaml-formatter-off}/migration.d.ts +0 -0
- /package/src/migrations/{latest/py-agent-pillow-override → v1.0.15/0001-py-agent-pillow-override}/metadata.json +0 -0
- /package/src/migrations/{latest/py-agent-pillow-override → v1.0.15/0001-py-agent-pillow-override}/migration.d.ts +0 -0
- /package/src/migrations/{latest/py-agent-pillow-override → v1.0.15/0001-py-agent-pillow-override}/migration.js +0 -0
- /package/src/migrations/{latest/ts-agent-guardrails-synth-input → v1.1.1/0001-ts-agent-guardrails-synth-input}/metadata.json +0 -0
- /package/src/migrations/{latest/ts-agent-guardrails-synth-input → v1.1.1/0001-ts-agent-guardrails-synth-input}/migration.d.ts +0 -0
- /package/src/migrations/{latest/ts-agent-guardrails-synth-input → v1.1.1/0001-ts-agent-guardrails-synth-input}/migration.js +0 -0
- /package/src/migrations/{latest/ts-agent-guardrails-terraform-version-retention → v1.3.0/0001-ts-agent-guardrails-terraform-version-retention}/metadata.json +0 -0
- /package/src/migrations/{latest/ts-agent-guardrails-terraform-version-retention → v1.3.0/0001-ts-agent-guardrails-terraform-version-retention}/migration.js +0 -0
package/src/utils/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/format.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Biome } from '@biomejs/js-api/nodejs';\nimport { getProjects, type Tree } from '@nx/devkit';\nimport { createRequire } from 'module';\nimport path from 'path';\nimport { type RuffOptions, ruffFixAndFormat } from './ruff.js';\nimport { tryReadToml } from './toml.js';\nimport { TS_VERSIONS } from './versions.js';\n\n/**\n * The Biome release the wasm bindings are built from. Must match\n * `TS_VERSIONS['@biomejs/biome']`, the CLI the vended targets run.\n */\nexport const BIOME_WASM_VERSION: string = createRequire(import.meta.url)(\n '@biomejs/wasm-nodejs/package.json',\n).version;\n\n/**\n * Excludes test reports — including the vendored scripts vitest's coverage HTML\n * reporter writes — from formatting and linting.\n */\nexport const BIOME_TEST_OUTPUT_EXCLUDE = '!**/test-output';\n\n/**\n * The transient bundle rolldown writes beside a `rolldown.config.ts` while\n * loading it.\n *\n * Loading a TypeScript config bundles it to `rolldown.config.<hash>.js` in the\n * config's own directory, imports it, then unlinks it. That file exists for as\n * long as the bundle takes, so a `format` or `lint` target running concurrently\n * in the same project sees a machine-generated file — reported unformatted,\n * failing the target for no fault of the source.\n *\n * `.*js` rather than `.js`, since the extension follows the config's own: a\n * `.mts` config bundles to `.mjs`, a `.cts` one to `.cjs`.\n */\nexport const ROLLDOWN_CONFIG_BUNDLE_GLOB = '**/rolldown.config.*.*js';\n\n/** Keeps rolldown's transient config bundle out of formatting and linting. */\nexport const BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE = `!${ROLLDOWN_CONFIG_BUNDLE_GLOB}`;\n\n/**\n * The biome.json vended into a new workspace. The pnpm catalog resolver is only\n * included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only\n * catalog resolver and reads `pnpm-workspace.yaml` exclusively — it does nothing\n * for yarn or bun catalogs, so vending it there would be misleading.\n */\nexport const getDefaultBiomeConfig = (tree: Tree) => ({\n $schema: `https://biomejs.dev/schemas/${TS_VERSIONS['@biomejs/biome']}/schema.json`,\n root: true,\n formatter: {\n enabled: true,\n indentStyle: 'space',\n indentWidth: 2,\n lineWidth: 80,\n },\n javascript: {\n formatter: {\n quoteStyle: 'single',\n trailingCommas: 'all',\n },\n // Resolve `catalog:` versions from pnpm-workspace.yaml (pnpm workspaces only).\n ...(tree.exists('pnpm-workspace.yaml')\n ? { resolver: { experimentalPnpmCatalogs: true } }\n : {}),\n },\n css: {\n formatter: {\n quoteStyle: 'single',\n },\n linter: {\n enabled: false,\n },\n },\n linter: {\n enabled: true,\n rules: {\n preset: 'none',\n correctness: {\n // Every project must declare the third-party dependencies its source\n // code imports in its own package.json.\n noUndeclaredDependencies: 'error',\n },\n },\n },\n assist: {\n actions: {\n source: {\n organizeImports: 'on',\n },\n },\n },\n files: {\n includes: [\n '**',\n '!**/dist',\n '!**/out-tsc',\n BIOME_TEST_OUTPUT_EXCLUDE,\n BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE,\n '!**/node_modules',\n '!**/.nx',\n '!**/.venv',\n // GritQL codemod cache written by generators — its sample sources\n // otherwise pollute a bare `biome check .` with parse errors.\n '!**/.grit',\n '!**/*.css',\n '!**/*.gen.*',\n '!**/generated/**',\n '!**/tsconfig*.json',\n ],\n },\n // Config files, build scripts and tests use root tooling rather than\n // declaring it per-project, so the undeclared-dependency rule is off for them.\n overrides: [\n {\n includes: [\n '**/*.config.{ts,mts,cts,js,mjs,cjs}',\n '**/*.{spec,test}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}',\n '**/*.stories.{ts,tsx}',\n ],\n linter: {\n rules: {\n correctness: {\n noUndeclaredDependencies: 'off',\n },\n },\n },\n },\n ],\n});\n\nconst BIOME_FORMATTABLE_EXTENSIONS = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.mts',\n '.cts',\n '.json',\n '.jsonc',\n '.css',\n]);\n\n/** Matches `tsconfig.json` and variants like `tsconfig.lib.json`. */\nconst isTsConfig = (filePath: string): boolean =>\n /(^|\\/)tsconfig[^/]*\\.json$/.test(filePath);\n\nexport interface FormatFilesInSubtreeOptions {\n /**\n * Paths, relative to the workspace root, to leave untouched.\n *\n * For files another tool owns the formatting of: formatting them here makes\n * generation non-idempotent, since the tool rewrites them in its own shape on\n * the next run and the workspace flips between the two forms.\n */\n readonly ignore?: readonly string[];\n}\n\n/**\n * Paths declared ignored for a tree, which stay ignored for every later call.\n *\n * A call formats every change pending in the tree, not only the ones its caller\n * made, so the list cannot be scoped to the call that passes it: generators\n * composing on one tree would reformat a file an earlier generator had excluded.\n * Once the generator that owns a file declares it ignored, it stays ignored for\n * the rest of the run.\n */\nconst treeIgnoredPaths = new WeakMap<Tree, Set<string>>();\n\n/**\n * Tree paths are workspace-relative and forward-slash separated. Normalise so a\n * caller building a path with `path.join` on Windows still matches.\n */\nconst normalizeTreePath = (filePath: string): string =>\n filePath.split(path.sep).join('/').replace(/^\\.\\//, '');\n\n/**\n * Format files in the given directory within the tree.\n * Handles both TypeScript/JavaScript/JSON (via biome) and Python (via ruff) files.\n * See https://github.com/nrwl/nx/blob/4cd640a9187954505d12de5b6d76a90d8ce4c2eb/packages/devkit/src/generators/format-files.ts#L11\n */\nexport async function formatFilesInSubtree(\n tree: Tree,\n dir?: string,\n options?: FormatFilesInSubtreeOptions,\n): Promise<void> {\n let ignored = treeIgnoredPaths.get(tree);\n if (options?.ignore?.length) {\n if (!ignored) {\n ignored = new Set();\n treeIgnoredPaths.set(tree, ignored);\n }\n for (const filePath of options.ignore) {\n ignored.add(normalizeTreePath(filePath));\n }\n }\n const changedFiles = tree\n .listChanges()\n .filter((file) => file.type !== 'DELETE')\n .filter((file) => (dir ? file.path.startsWith(dir) : true))\n .filter((file) => !ignored?.has(normalizeTreePath(file.path)));\n\n const pyFiles = changedFiles.filter((file) => file.path.endsWith('.py'));\n const otherFiles = changedFiles.filter(\n (file) =>\n BIOME_FORMATTABLE_EXTENSIONS.has(path.extname(file.path)) &&\n // tsconfigs are not biome-managed: they're excluded from the vended\n // format target (Nx's typescript-sync rewrites them without formatting),\n // so formatting them at generation would only diverge from the form\n // written on later runs. Leave them as updateJson/writeJson emit them so\n // repeated generation stays idempotent.\n !isTsConfig(file.path),\n );\n\n // Resolve each project's ruff settings (module names, line-length) so files\n // are formatted to match the on-disk build (see getPythonProjectRuffConfigs).\n const pythonProjectConfigs = pyFiles.length\n ? getPythonProjectRuffConfigs(tree)\n : [];\n\n // Format Python files with ruff (lint fixes + formatting)\n for (const file of pyFiles) {\n try {\n const content = ruffFixAndFormat(\n file.content.toString('utf-8'),\n file.path,\n resolveRuffOptions(\n readRuffConfig(tree, file.path),\n getOwningProjectRuffConfig(file.path, pythonProjectConfigs),\n ),\n );\n tree.write(file.path, content);\n } catch {\n // Silently skip ruff formatting failures\n }\n }\n\n if (otherFiles.length === 0) return;\n\n formatWithBiome(tree, otherFiles);\n}\n\n/**\n * The Biome configuration to format with: the workspace's own `biome.json`, else\n * the config we vend.\n *\n * Read through the tree, which falls back to disk for a file it doesn't hold. So\n * this resolves the most current config either way — the workspace's on-disk one,\n * or the version a generator has just written to the tree and not yet flushed,\n * which shelling out to the CLI could never see.\n */\nfunction readBiomeConfig(tree: Tree): unknown {\n const config = tree.read('biome.json', 'utf-8');\n if (config) {\n try {\n return JSON.parse(config);\n } catch {\n // Malformed config — fall through to the config we vend\n }\n }\n return getDefaultBiomeConfig(tree);\n}\n\n/**\n * Format files with Biome in-process, reusing one instance across the batch.\n *\n * Replaces one `biome format --stdin-file-path` process per file, which\n * dominated generation at ~70ms each: `formatFilesInSubtree` formats every\n * change accumulated in the tree, not only the ones its caller made, so\n * generators sharing a tree reformat the same files once per call. In-process is\n * ~0.5ms per file. Output was verified byte-identical across the plugin's whole\n * source tree, except that the CLI corrupts control characters passed through\n * stdin (a NUL in a template literal) where formatting in-process preserves them.\n */\nfunction formatWithBiome(\n tree: Tree,\n files: { path: string; content: Buffer | null }[],\n): void {\n try {\n const biome = new Biome();\n const { projectKey } = biome.openProject();\n biome.applyConfiguration(projectKey, readBiomeConfig(tree));\n\n for (const file of files) {\n try {\n const { content } = biome.formatContent(\n projectKey,\n file.content?.toString('utf-8') ?? '',\n { filePath: file.path },\n );\n tree.write(file.path, content);\n } catch {\n // Leave individual files that fail to format untouched\n }\n }\n } catch {\n // Silently skip formatting failures\n }\n}\n\n/**\n * Read the ruff config for a file, by walking from its directory up to the\n * workspace root looking for `.ruff.toml`, `ruff.toml`, or a `pyproject.toml`\n * with a `[tool.ruff]` section — the same files, in the same order, that ruff\n * itself resolves. The walk stops at the workspace root so a stray config in a\n * parent of the workspace (or the home directory) is never treated as the\n * project's.\n *\n * The settings are read rather than merely detected because formatting runs\n * in-process against tree content, so ruff never sees the file's location and\n * cannot resolve the config itself (see {@link resolveRuffOptions}).\n *\n * Reads go through the tree, which falls through to disk for files this run has\n * not touched, so a config the generator has just written in memory is picked up\n * as well as one already on disk.\n */\nfunction readRuffConfig(tree: Tree, filePath: string): RuffOptions | undefined {\n let dir = path.dirname(filePath);\n while (true) {\n for (const name of ['.ruff.toml', 'ruff.toml']) {\n const config = tryReadToml(tree, path.join(dir, name));\n if (config) {\n return config as RuffOptions;\n }\n }\n const ruff = (tryReadToml(tree, path.join(dir, 'pyproject.toml')) as any)\n ?.tool?.ruff;\n if (ruff) {\n return ruff as RuffOptions;\n }\n // Stop once the workspace root ('.') has been checked.\n if (dir === '.' || dir === '' || dir === path.dirname(dir)) {\n return undefined;\n }\n dir = path.dirname(dir);\n }\n}\n\n/**\n * The `[tool.ruff.lint].select` generated Python projects vend. Generation\n * formats before that config lands on disk, so it is pinned here to keep\n * generated files clean under the project's own `lint` target rather than under\n * whatever ruff's defaults happen to be for the pinned release.\n */\nconst DEFAULT_RUFF_SELECT = ['E', 'F', 'UP', 'B', 'SIM', 'I'];\n\ninterface PythonProjectRuffConfig {\n /** Project root, normalised to use forward slashes. */\n readonly root: string;\n /** Top-level importable module names declared by the project. */\n readonly modules: string[];\n /** The project's `[tool.ruff].line-length`, if set. */\n readonly lineLength?: number;\n /**\n * Ruff `target-version` (eg `py314`) derived from `[project].requires-python`.\n * Generation formats via stdin with no pyproject, so it must be passed\n * explicitly — ruff's formatting differs by target.\n */\n readonly targetVersion?: string;\n /** The project's `[tool.ruff.lint].select`, if set. */\n readonly select?: string[];\n}\n\n/**\n * Derive ruff's `target-version` (eg `py314`) from a PEP 508\n * `requires-python` specifier (eg `>=3.14`). Ruff targets the minimum\n * supported version, so take the lowest `major.minor` mentioned.\n */\nexport const requiresPythonToRuffTarget = (\n requiresPython: unknown,\n): string | undefined => {\n if (typeof requiresPython !== 'string') {\n return undefined;\n }\n let min: { major: number; minor: number } | undefined;\n for (const match of requiresPython.matchAll(/(\\d+)\\.(\\d+)/g)) {\n const major = Number(match[1]);\n const minor = Number(match[2]);\n if (\n !min ||\n major < min.major ||\n (major === min.major && minor < min.minor)\n ) {\n min = { major, minor };\n }\n }\n return min ? `py${min.major}${min.minor}` : undefined;\n};\n\n/**\n * Map each Nx project with a `pyproject.toml` to the ruff settings the on-disk\n * build enforces for it: its top-level module names (from\n * `[tool.hatch.build.targets.wheel].packages`), its `[tool.ruff].line-length`\n * and its `[tool.ruff.lint].select`.\n */\nfunction getPythonProjectRuffConfigs(tree: Tree): PythonProjectRuffConfig[] {\n const configs: PythonProjectRuffConfig[] = [];\n\n for (const project of getProjects(tree).values()) {\n // Projects without a pyproject.toml, or whose one cannot be parsed, have no\n // ruff settings to contribute.\n const pyproject = tryReadToml(\n tree,\n path.join(project.root, 'pyproject.toml'),\n ) as any;\n if (!pyproject) {\n continue;\n }\n const wheelPackages: unknown =\n pyproject?.tool?.hatch?.build?.targets?.wheel?.packages;\n // Record the top-level module segment (`pkg/sub` -> `pkg`), which is\n // all `known-first-party` keys off.\n const modules = Array.isArray(wheelPackages)\n ? wheelPackages\n .filter((pkg): pkg is string => typeof pkg === 'string' && !!pkg)\n .map((pkg) => pkg.split('/')[0])\n : [];\n const lineLength: unknown = pyproject?.tool?.ruff?.['line-length'];\n const targetVersion = requiresPythonToRuffTarget(\n pyproject?.project?.['requires-python'],\n );\n const selected: unknown = pyproject?.tool?.ruff?.lint?.select;\n const select = Array.isArray(selected)\n ? selected.filter(\n (rule): rule is string => typeof rule === 'string' && !!rule,\n )\n : undefined;\n if (\n modules.length ||\n typeof lineLength === 'number' ||\n targetVersion ||\n select?.length\n ) {\n configs.push({\n root: project.root.split(path.sep).join('/'),\n modules,\n lineLength: typeof lineLength === 'number' ? lineLength : undefined,\n targetVersion,\n select: select?.length ? select : undefined,\n });\n }\n }\n\n return configs;\n}\n\n/**\n * Resolve the ruff config for the project that owns a file (the project with\n * the longest root that is a prefix of the file path). Ruff runs per-project on\n * disk, so a file's settings come from its own project — only its own module is\n * first-party (sibling workspace packages are third-party) and its own\n * line-length applies — and scoping this way keeps in-tree formatting\n * consistent with the on-disk build.\n */\nfunction getOwningProjectRuffConfig(\n filePath: string,\n configs: PythonProjectRuffConfig[],\n): PythonProjectRuffConfig | undefined {\n let owner: PythonProjectRuffConfig | undefined;\n for (const config of configs) {\n if (\n (filePath === config.root || filePath.startsWith(`${config.root}/`)) &&\n (!owner || config.root.length > owner.root.length)\n ) {\n owner = config;\n }\n }\n return owner;\n}\n\n/**\n * Resolve the ruff settings to format a Python file with, mirroring what the\n * file's build enforces.\n *\n * Ruff's own config discovery never runs: settings are passed to the linter\n * directly rather than resolved from the file's location, which it never sees.\n * That also means a stray config above the workspace (or in the home directory)\n * can never be picked up.\n *\n * `config` is the file's nearest ruff config, whose rule selection is honoured\n * as-is. Without one, ruff would fall back to its own defaults, which change\n * between releases — 0.16 widened them from `E` and `F` to 36 rule prefixes — so\n * generation would apply fixes the project's build never asks for (eg `RUF022`\n * reordering `__all__`). Instead the project's own `lint.select` is pinned, so\n * generation enforces exactly what `lint` does and nothing more.\n *\n * `projectConfig` layers on the settings derived from the owning project rather\n * than declared under `[tool.ruff]`: `known-first-party` (the project's own\n * modules, from its wheel packages) keeps its imports in their own group, and\n * `target-version` (from its `requires-python`) matches the formatting the build\n * produces.\n */\nfunction resolveRuffOptions(\n config: RuffOptions | undefined,\n projectConfig?: PythonProjectRuffConfig,\n): RuffOptions {\n const lint: Record<string, unknown> = { ...config?.lint };\n // Pin the rule selection only when deferring to ruff's defaults would\n // otherwise apply rules the project's build does not enforce.\n if (!config) {\n lint.select = projectConfig?.select ?? DEFAULT_RUFF_SELECT;\n }\n if (projectConfig?.modules.length) {\n lint.isort = {\n ...(lint.isort as object | undefined),\n 'known-first-party': projectConfig.modules,\n };\n }\n return {\n ...config,\n ...(typeof projectConfig?.lineLength === 'number'\n ? { 'line-length': projectConfig.lineLength }\n : {}),\n ...(projectConfig?.targetVersion\n ? { 'target-version': projectConfig.targetVersion }\n : {}),\n lint,\n };\n}\n"],"names":["Biome","getProjects","createRequire","path","ruffFixAndFormat","tryReadToml","TS_VERSIONS","BIOME_WASM_VERSION","url","version","BIOME_TEST_OUTPUT_EXCLUDE","ROLLDOWN_CONFIG_BUNDLE_GLOB","BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE","getDefaultBiomeConfig","tree","$schema","root","formatter","enabled","indentStyle","indentWidth","lineWidth","javascript","quoteStyle","trailingCommas","exists","resolver","experimentalPnpmCatalogs","css","linter","rules","preset","correctness","noUndeclaredDependencies","assist","actions","source","organizeImports","files","includes","overrides","BIOME_FORMATTABLE_EXTENSIONS","Set","isTsConfig","filePath","test","treeIgnoredPaths","WeakMap","normalizeTreePath","split","sep","join","replace","formatFilesInSubtree","dir","options","ignored","get","ignore","length","set","add","changedFiles","listChanges","filter","file","type","startsWith","has","pyFiles","endsWith","otherFiles","extname","pythonProjectConfigs","getPythonProjectRuffConfigs","content","toString","resolveRuffOptions","readRuffConfig","getOwningProjectRuffConfig","write","formatWithBiome","readBiomeConfig","config","read","JSON","parse","biome","projectKey","openProject","applyConfiguration","formatContent","dirname","name","ruff","tool","undefined","DEFAULT_RUFF_SELECT","requiresPythonToRuffTarget","requiresPython","min","match","matchAll","major","Number","minor","configs","project","values","pyproject","wheelPackages","hatch","build","targets","wheel","packages","modules","Array","isArray","pkg","map","lineLength","targetVersion","selected","lint","select","rule","push","owner","projectConfig","isort"],"mappings":"AAAA;;;CAGC,GAED,SAASA,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,QAAmB,aAAa;AACpD,SAASC,aAAa,QAAQ,SAAS;AACvC,OAAOC,UAAU,OAAO;AACxB,SAA2BC,gBAAgB,QAAQ,YAAY;AAC/D,SAASC,WAAW,QAAQ,YAAY;AACxC,SAASC,WAAW,QAAQ,gBAAgB;AAE5C;;;CAGC,GACD,OAAO,MAAMC,qBAA6BL,cAAc,YAAYM,GAAG,EACrE,qCACAC,OAAO,CAAC;AAEV;;;CAGC,GACD,OAAO,MAAMC,4BAA4B,kBAAkB;AAE3D;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,8BAA8B,2BAA2B;AAEtE,4EAA4E,GAC5E,OAAO,MAAMC,uCAAuC,CAAC,CAAC,EAAED,6BAA6B,CAAC;AAEtF;;;;;CAKC,GACD,OAAO,MAAME,wBAAwB,CAACC,OAAgB,CAAA;QACpDC,SAAS,CAAC,4BAA4B,EAAET,WAAW,CAAC,iBAAiB,CAAC,YAAY,CAAC;QACnFU,MAAM;QACNC,WAA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uC;IAEvC,MAAML,OAAgC;QAAE,GAAGzC,QAAQyC,IAAI;IAAC;IACxD,sEAAsE;IACtE,8DAA8D;IAC9D,IAAI,CAACzC,QAAQ;QACXyC,KAAKC,MAAM,GAAGI,eAAeJ,UAAU5B;IACzC;IACA,IAAIgC,eAAeb,QAAQzD,QAAQ;QACjCiE,KAAKM,KAAK,GAAG;YACX,GAAIN,KAAKM,KAAK;YACd,qBAAqBD,cAAcb,OAAO;QAC5C;IACF;IACA,OAAO;QACL,GAAGjC,MAAM;QACT,GAAI,OAAO8C,eAAeR,eAAe,WACrC;YAAE,eAAeQ,cAAcR,UAAU;QAAC,IAC1C,CAAC,CAAC;QACN,GAAIQ,eAAeP,gBACf;YAAE,kBAAkBO,cAAcP,aAAa;QAAC,IAChD,CAAC,CAAC;QACNE;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/format.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Biome } from '@biomejs/js-api/nodejs';\nimport { getProjects, type Tree } from '@nx/devkit';\nimport { createRequire } from 'module';\nimport path from 'path';\nimport { type RuffOptions, ruffFixAndFormat } from './ruff.js';\nimport { tryReadToml } from './toml.js';\nimport { TS_VERSIONS } from './versions.js';\n\n/**\n * The Biome release the wasm bindings are built from. Must match\n * `TS_VERSIONS['@biomejs/biome']`, the CLI the vended targets run.\n */\nexport const BIOME_WASM_VERSION: string = createRequire(import.meta.url)(\n '@biomejs/wasm-nodejs/package.json',\n).version;\n\n/**\n * Excludes test reports — including the vendored scripts vitest's coverage HTML\n * reporter writes — from formatting and linting.\n */\nexport const BIOME_TEST_OUTPUT_EXCLUDE = '!**/test-output';\n\n/**\n * The transient bundle rolldown writes beside a `rolldown.config.ts` while\n * loading it.\n *\n * Loading a TypeScript config bundles it to `rolldown.config.<hash>.js` in the\n * config's own directory, imports it, then unlinks it. That file exists for as\n * long as the bundle takes, so a `format` or `lint` target running concurrently\n * in the same project sees a machine-generated file — reported unformatted,\n * failing the target for no fault of the source.\n *\n * `.*js` rather than `.js`, since the extension follows the config's own: a\n * `.mts` config bundles to `.mjs`, a `.cts` one to `.cjs`.\n */\nexport const ROLLDOWN_CONFIG_BUNDLE_GLOB = '**/rolldown.config.*.*js';\n\n/** Keeps rolldown's transient config bundle out of formatting and linting. */\nexport const BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE = `!${ROLLDOWN_CONFIG_BUNDLE_GLOB}`;\n\n/**\n * The biome.json vended into a new workspace. The pnpm catalog resolver is only\n * included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only\n * catalog resolver and reads `pnpm-workspace.yaml` exclusively — it does nothing\n * for yarn or bun catalogs, so vending it there would be misleading.\n */\nexport const getDefaultBiomeConfig = (tree: Tree) => ({\n $schema: `https://biomejs.dev/schemas/${TS_VERSIONS['@biomejs/biome']}/schema.json`,\n root: true,\n formatter: {\n enabled: true,\n indentStyle: 'space',\n indentWidth: 2,\n lineWidth: 80,\n },\n javascript: {\n formatter: {\n quoteStyle: 'single',\n trailingCommas: 'all',\n },\n // Resolve `catalog:` versions from pnpm-workspace.yaml (pnpm workspaces only).\n ...(tree.exists('pnpm-workspace.yaml')\n ? { resolver: { experimentalPnpmCatalogs: true } }\n : {}),\n },\n css: {\n formatter: {\n quoteStyle: 'single',\n },\n linter: {\n enabled: false,\n },\n },\n // Markdown and YAML files are left as written.\n markdown: { formatter: { enabled: false } },\n yaml: { formatter: { enabled: false } },\n linter: {\n enabled: true,\n rules: {\n preset: 'none',\n correctness: {\n // Every project must declare the third-party dependencies its source\n // code imports in its own package.json.\n noUndeclaredDependencies: 'error',\n },\n },\n },\n assist: {\n actions: {\n source: {\n organizeImports: 'on',\n },\n },\n },\n files: {\n includes: [\n '**',\n '!**/dist',\n '!**/out-tsc',\n BIOME_TEST_OUTPUT_EXCLUDE,\n BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE,\n '!**/node_modules',\n '!**/.nx',\n '!**/.venv',\n // GritQL codemod cache written by generators — its sample sources\n // otherwise pollute a bare `biome check .` with parse errors.\n '!**/.grit',\n '!**/*.css',\n '!**/*.gen.*',\n '!**/generated/**',\n '!**/tsconfig*.json',\n ],\n },\n // Config files, build scripts and tests use root tooling rather than\n // declaring it per-project, so the undeclared-dependency rule is off for them.\n overrides: [\n {\n includes: [\n '**/*.config.{ts,mts,cts,js,mjs,cjs}',\n '**/*.{spec,test}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}',\n '**/*.stories.{ts,tsx}',\n ],\n linter: {\n rules: {\n correctness: {\n noUndeclaredDependencies: 'off',\n },\n },\n },\n },\n ],\n});\n\nconst BIOME_FORMATTABLE_EXTENSIONS = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.mts',\n '.cts',\n '.json',\n '.jsonc',\n '.css',\n]);\n\n/** Matches `tsconfig.json` and variants like `tsconfig.lib.json`. */\nconst isTsConfig = (filePath: string): boolean =>\n /(^|\\/)tsconfig[^/]*\\.json$/.test(filePath);\n\nexport interface FormatFilesInSubtreeOptions {\n /**\n * Paths, relative to the workspace root, to leave untouched.\n *\n * For files another tool owns the formatting of: formatting them here makes\n * generation non-idempotent, since the tool rewrites them in its own shape on\n * the next run and the workspace flips between the two forms.\n */\n readonly ignore?: readonly string[];\n}\n\n/**\n * Paths declared ignored for a tree, which stay ignored for every later call.\n *\n * A call formats every change pending in the tree, not only the ones its caller\n * made, so the list cannot be scoped to the call that passes it: generators\n * composing on one tree would reformat a file an earlier generator had excluded.\n * Once the generator that owns a file declares it ignored, it stays ignored for\n * the rest of the run.\n */\nconst treeIgnoredPaths = new WeakMap<Tree, Set<string>>();\n\n/**\n * Tree paths are workspace-relative and forward-slash separated. Normalise so a\n * caller building a path with `path.join` on Windows still matches.\n */\nconst normalizeTreePath = (filePath: string): string =>\n filePath.split(path.sep).join('/').replace(/^\\.\\//, '');\n\n/**\n * Format files in the given directory within the tree.\n * Handles both TypeScript/JavaScript/JSON (via biome) and Python (via ruff) files.\n * See https://github.com/nrwl/nx/blob/4cd640a9187954505d12de5b6d76a90d8ce4c2eb/packages/devkit/src/generators/format-files.ts#L11\n */\nexport async function formatFilesInSubtree(\n tree: Tree,\n dir?: string,\n options?: FormatFilesInSubtreeOptions,\n): Promise<void> {\n let ignored = treeIgnoredPaths.get(tree);\n if (options?.ignore?.length) {\n if (!ignored) {\n ignored = new Set();\n treeIgnoredPaths.set(tree, ignored);\n }\n for (const filePath of options.ignore) {\n ignored.add(normalizeTreePath(filePath));\n }\n }\n const changedFiles = tree\n .listChanges()\n .filter((file) => file.type !== 'DELETE')\n .filter((file) => (dir ? file.path.startsWith(dir) : true))\n .filter((file) => !ignored?.has(normalizeTreePath(file.path)));\n\n const pyFiles = changedFiles.filter((file) => file.path.endsWith('.py'));\n const otherFiles = changedFiles.filter(\n (file) =>\n BIOME_FORMATTABLE_EXTENSIONS.has(path.extname(file.path)) &&\n // tsconfigs are not biome-managed: they're excluded from the vended\n // format target (Nx's typescript-sync rewrites them without formatting),\n // so formatting them at generation would only diverge from the form\n // written on later runs. Leave them as updateJson/writeJson emit them so\n // repeated generation stays idempotent.\n !isTsConfig(file.path),\n );\n\n // Resolve each project's ruff settings (module names, line-length) so files\n // are formatted to match the on-disk build (see getPythonProjectRuffConfigs).\n const pythonProjectConfigs = pyFiles.length\n ? getPythonProjectRuffConfigs(tree)\n : [];\n\n // Format Python files with ruff (lint fixes + formatting)\n for (const file of pyFiles) {\n try {\n const content = ruffFixAndFormat(\n file.content.toString('utf-8'),\n file.path,\n resolveRuffOptions(\n readRuffConfig(tree, file.path),\n getOwningProjectRuffConfig(file.path, pythonProjectConfigs),\n ),\n );\n tree.write(file.path, content);\n } catch {\n // Silently skip ruff formatting failures\n }\n }\n\n if (otherFiles.length === 0) return;\n\n formatWithBiome(tree, otherFiles);\n}\n\n/**\n * The Biome configuration to format with: the workspace's own `biome.json`, else\n * the config we vend.\n *\n * Read through the tree, which falls back to disk for a file it doesn't hold. So\n * this resolves the most current config either way — the workspace's on-disk one,\n * or the version a generator has just written to the tree and not yet flushed,\n * which shelling out to the CLI could never see.\n */\nfunction readBiomeConfig(tree: Tree): unknown {\n const config = tree.read('biome.json', 'utf-8');\n if (config) {\n try {\n return JSON.parse(config);\n } catch {\n // Malformed config — fall through to the config we vend\n }\n }\n return getDefaultBiomeConfig(tree);\n}\n\n/**\n * Format files with Biome in-process, reusing one instance across the batch.\n *\n * Replaces one `biome format --stdin-file-path` process per file, which\n * dominated generation at ~70ms each: `formatFilesInSubtree` formats every\n * change accumulated in the tree, not only the ones its caller made, so\n * generators sharing a tree reformat the same files once per call. In-process is\n * ~0.5ms per file. Output was verified byte-identical across the plugin's whole\n * source tree, except that the CLI corrupts control characters passed through\n * stdin (a NUL in a template literal) where formatting in-process preserves them.\n */\nfunction formatWithBiome(\n tree: Tree,\n files: { path: string; content: Buffer | null }[],\n): void {\n try {\n const biome = new Biome();\n const { projectKey } = biome.openProject();\n biome.applyConfiguration(projectKey, readBiomeConfig(tree));\n\n for (const file of files) {\n try {\n const { content } = biome.formatContent(\n projectKey,\n file.content?.toString('utf-8') ?? '',\n { filePath: file.path },\n );\n tree.write(file.path, content);\n } catch {\n // Leave individual files that fail to format untouched\n }\n }\n } catch {\n // Silently skip formatting failures\n }\n}\n\n/**\n * Read the ruff config for a file, by walking from its directory up to the\n * workspace root looking for `.ruff.toml`, `ruff.toml`, or a `pyproject.toml`\n * with a `[tool.ruff]` section — the same files, in the same order, that ruff\n * itself resolves. The walk stops at the workspace root so a stray config in a\n * parent of the workspace (or the home directory) is never treated as the\n * project's.\n *\n * The settings are read rather than merely detected because formatting runs\n * in-process against tree content, so ruff never sees the file's location and\n * cannot resolve the config itself (see {@link resolveRuffOptions}).\n *\n * Reads go through the tree, which falls through to disk for files this run has\n * not touched, so a config the generator has just written in memory is picked up\n * as well as one already on disk.\n */\nfunction readRuffConfig(tree: Tree, filePath: string): RuffOptions | undefined {\n let dir = path.dirname(filePath);\n while (true) {\n for (const name of ['.ruff.toml', 'ruff.toml']) {\n const config = tryReadToml(tree, path.join(dir, name));\n if (config) {\n return config as RuffOptions;\n }\n }\n const ruff = (tryReadToml(tree, path.join(dir, 'pyproject.toml')) as any)\n ?.tool?.ruff;\n if (ruff) {\n return ruff as RuffOptions;\n }\n // Stop once the workspace root ('.') has been checked.\n if (dir === '.' || dir === '' || dir === path.dirname(dir)) {\n return undefined;\n }\n dir = path.dirname(dir);\n }\n}\n\n/**\n * The `[tool.ruff.lint].select` generated Python projects vend. Generation\n * formats before that config lands on disk, so it is pinned here to keep\n * generated files clean under the project's own `lint` target rather than under\n * whatever ruff's defaults happen to be for the pinned release.\n */\nconst DEFAULT_RUFF_SELECT = ['E', 'F', 'UP', 'B', 'SIM', 'I'];\n\ninterface PythonProjectRuffConfig {\n /** Project root, normalised to use forward slashes. */\n readonly root: string;\n /** Top-level importable module names declared by the project. */\n readonly modules: string[];\n /** The project's `[tool.ruff].line-length`, if set. */\n readonly lineLength?: number;\n /**\n * Ruff `target-version` (eg `py314`) derived from `[project].requires-python`.\n * Generation formats via stdin with no pyproject, so it must be passed\n * explicitly — ruff's formatting differs by target.\n */\n readonly targetVersion?: string;\n /** The project's `[tool.ruff.lint].select`, if set. */\n readonly select?: string[];\n}\n\n/**\n * Derive ruff's `target-version` (eg `py314`) from a PEP 508\n * `requires-python` specifier (eg `>=3.14`). Ruff targets the minimum\n * supported version, so take the lowest `major.minor` mentioned.\n */\nexport const requiresPythonToRuffTarget = (\n requiresPython: unknown,\n): string | undefined => {\n if (typeof requiresPython !== 'string') {\n return undefined;\n }\n let min: { major: number; minor: number } | undefined;\n for (const match of requiresPython.matchAll(/(\\d+)\\.(\\d+)/g)) {\n const major = Number(match[1]);\n const minor = Number(match[2]);\n if (\n !min ||\n major < min.major ||\n (major === min.major && minor < min.minor)\n ) {\n min = { major, minor };\n }\n }\n return min ? `py${min.major}${min.minor}` : undefined;\n};\n\n/**\n * Map each Nx project with a `pyproject.toml` to the ruff settings the on-disk\n * build enforces for it: its top-level module names (from\n * `[tool.hatch.build.targets.wheel].packages`), its `[tool.ruff].line-length`\n * and its `[tool.ruff.lint].select`.\n */\nfunction getPythonProjectRuffConfigs(tree: Tree): PythonProjectRuffConfig[] {\n const configs: PythonProjectRuffConfig[] = [];\n\n for (const project of getProjects(tree).values()) {\n // Projects without a pyproject.toml, or whose one cannot be parsed, have no\n // ruff settings to contribute.\n const pyproject = tryReadToml(\n tree,\n path.join(project.root, 'pyproject.toml'),\n ) as any;\n if (!pyproject) {\n continue;\n }\n const wheelPackages: unknown =\n pyproject?.tool?.hatch?.build?.targets?.wheel?.packages;\n // Record the top-level module segment (`pkg/sub` -> `pkg`), which is\n // all `known-first-party` keys off.\n const modules = Array.isArray(wheelPackages)\n ? wheelPackages\n .filter((pkg): pkg is string => typeof pkg === 'string' && !!pkg)\n .map((pkg) => pkg.split('/')[0])\n : [];\n const lineLength: unknown = pyproject?.tool?.ruff?.['line-length'];\n const targetVersion = requiresPythonToRuffTarget(\n pyproject?.project?.['requires-python'],\n );\n const selected: unknown = pyproject?.tool?.ruff?.lint?.select;\n const select = Array.isArray(selected)\n ? selected.filter(\n (rule): rule is string => typeof rule === 'string' && !!rule,\n )\n : undefined;\n if (\n modules.length ||\n typeof lineLength === 'number' ||\n targetVersion ||\n select?.length\n ) {\n configs.push({\n root: project.root.split(path.sep).join('/'),\n modules,\n lineLength: typeof lineLength === 'number' ? lineLength : undefined,\n targetVersion,\n select: select?.length ? select : undefined,\n });\n }\n }\n\n return configs;\n}\n\n/**\n * Resolve the ruff config for the project that owns a file (the project with\n * the longest root that is a prefix of the file path). Ruff runs per-project on\n * disk, so a file's settings come from its own project — only its own module is\n * first-party (sibling workspace packages are third-party) and its own\n * line-length applies — and scoping this way keeps in-tree formatting\n * consistent with the on-disk build.\n */\nfunction getOwningProjectRuffConfig(\n filePath: string,\n configs: PythonProjectRuffConfig[],\n): PythonProjectRuffConfig | undefined {\n let owner: PythonProjectRuffConfig | undefined;\n for (const config of configs) {\n if (\n (filePath === config.root || filePath.startsWith(`${config.root}/`)) &&\n (!owner || config.root.length > owner.root.length)\n ) {\n owner = config;\n }\n }\n return owner;\n}\n\n/**\n * Resolve the ruff settings to format a Python file with, mirroring what the\n * file's build enforces.\n *\n * Ruff's own config discovery never runs: settings are passed to the linter\n * directly rather than resolved from the file's location, which it never sees.\n * That also means a stray config above the workspace (or in the home directory)\n * can never be picked up.\n *\n * `config` is the file's nearest ruff config, whose rule selection is honoured\n * as-is. Without one, ruff would fall back to its own defaults, which change\n * between releases — 0.16 widened them from `E` and `F` to 36 rule prefixes — so\n * generation would apply fixes the project's build never asks for (eg `RUF022`\n * reordering `__all__`). Instead the project's own `lint.select` is pinned, so\n * generation enforces exactly what `lint` does and nothing more.\n *\n * `projectConfig` layers on the settings derived from the owning project rather\n * than declared under `[tool.ruff]`: `known-first-party` (the project's own\n * modules, from its wheel packages) keeps its imports in their own group, and\n * `target-version` (from its `requires-python`) matches the formatting the build\n * produces.\n */\nfunction resolveRuffOptions(\n config: RuffOptions | undefined,\n projectConfig?: PythonProjectRuffConfig,\n): RuffOptions {\n const lint: Record<string, unknown> = { ...config?.lint };\n // Pin the rule selection only when deferring to ruff's defaults would\n // otherwise apply rules the project's build does not enforce.\n if (!config) {\n lint.select = projectConfig?.select ?? DEFAULT_RUFF_SELECT;\n }\n if (projectConfig?.modules.length) {\n lint.isort = {\n ...(lint.isort as object | undefined),\n 'known-first-party': projectConfig.modules,\n };\n }\n return {\n ...config,\n ...(typeof projectConfig?.lineLength === 'number'\n ? { 'line-length': projectConfig.lineLength }\n : {}),\n ...(projectConfig?.targetVersion\n ? { 'target-version': projectConfig.targetVersion }\n : {}),\n lint,\n };\n}\n"],"names":["Biome","getProjects","createRequire","path","ruffFixAndFormat","tryReadToml","TS_VERSIONS","BIOME_WASM_VERSION","url","version","BIOME_TEST_OUTPUT_EXCLUDE","ROLLDOWN_CONFIG_BUNDLE_GLOB","BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE","getDefaultBiomeConfig","tree","$schema","root","formatter","enabled","indentStyle","indentWidth","lineWidth","javascript","quoteStyle","trailingCommas","exists","resolver","experimentalPnpmCatalogs","css","linter","markdown","yaml","rules","preset","correctness","noUndeclaredDependencies","assist","actions","source","organizeImports","files","includes","overrides","BIOME_FORMATTABLE_EXTENSIONS","Set","isTsConfig","filePath","test","treeIgnoredPaths","WeakMap","normalizeTreePath","split","sep","join","replace","formatFilesInSubtree","dir","options","ignored","get","ignore","length","set","add","changedFiles","listChanges","filter","file","type","startsWith","has","pyFiles","endsWith","otherFiles","extname","pythonProjectConfigs","getPythonProjectRuffConfigs","content","toString","resolveRuffOptions","readRuffConfig","getOwningProjectRuffConfig","write","formatWithBiome","readBiomeConfig","config","read","JSON","parse","biome","projectKey","openProject","applyConfiguration","formatContent","dirname","name","ruff","tool","undefined","DEFAULT_RUFF_SELECT","requiresPythonToRuffTarget","requiresPython","min","match","matchAll","major","Number","minor","configs","project","values","pyproject","wheelPackages","hatch","build","targets","wheel","packages","modules","Array","isArray","pkg","map","lineLength","targetVersion","selected","lint","select","rule","push","owner","projectConfig","isort"],"mappings":"AAAA;;;CAGC,GAED,SAASA,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,QAAmB,aAAa;AACpD,SAASC,aAAa,QAAQ,SAAS;AACvC,OAAOC,UAAU,OAAO;AACxB,SAA2BC,gBAAgB,QAAQ,YAAY;AAC/D,SAASC,WAAW,QAAQ,YAAY;AACxC,SAASC,WAAW,QAAQ,gBAAgB;AAE5C;;;CAGC,GACD,OAAO,MAAMC,qBAA6BL,cAAc,YAAYM,GAAG,EACrE,qCACAC,OAAO,CAAC;AAEV;;;CAGC,GACD,OAAO,MAAMC,4BAA4B,kBAAkB;AAE3D;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,8BAA8B,2BAA2B;AAEtE,4EAA4E,GAC5E,OAAO,MA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A,aAAauC,OAAOrE,IAAI,IAAI8B,SAASuB,UAAU,CAAC,GAAGgB,OAAOrE,IAAI,CAAC,CAAC,CAAC,CAAA,KACjE,CAAA,CAACkH,SAAS7C,OAAOrE,IAAI,CAAC6C,MAAM,GAAGqE,MAAMlH,IAAI,CAAC6C,MAAM,AAAD,GAChD;YACAqE,QAAQ7C;QACV;IACF;IACA,OAAO6C;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,SAASnD,mBACPM,MAA+B,EAC/B8C,aAAuC;IAEvC,MAAML,OAAgC;QAAE,GAAGzC,QAAQyC,IAAI;IAAC;IACxD,sEAAsE;IACtE,8DAA8D;IAC9D,IAAI,CAACzC,QAAQ;QACXyC,KAAKC,MAAM,GAAGI,eAAeJ,UAAU5B;IACzC;IACA,IAAIgC,eAAeb,QAAQzD,QAAQ;QACjCiE,KAAKM,KAAK,GAAG;YACX,GAAIN,KAAKM,KAAK;YACd,qBAAqBD,cAAcb,OAAO;QAC5C;IACF;IACA,OAAO;QACL,GAAGjC,MAAM;QACT,GAAI,OAAO8C,eAAeR,eAAe,WACrC;YAAE,eAAeQ,cAAcR,UAAU;QAAC,IAC1C,CAAC,CAAC;QACN,GAAIQ,eAAeP,gBACf;YAAE,kBAAkBO,cAAcP,aAAa;QAAC,IAChD,CAAC,CAAC;QACNE;IACF;AACF"}
|
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { type MigrationReturnObject, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type OwnedDependencies } from './owned-dependencies.js';
|
|
7
|
+
/**
|
|
8
|
+
* Version the sync moves a declared TypeScript dependency to, or undefined when
|
|
9
|
+
* it leaves the declaration as it is.
|
|
10
|
+
*
|
|
11
|
+
* Devkit then writes it only when it is higher than the declared version.
|
|
12
|
+
*/
|
|
13
|
+
export declare const syncedTsVersion: (tree: Tree, owned: OwnedDependencies, name: string, declared: unknown) => string | undefined;
|
|
6
14
|
/**
|
|
7
15
|
* Sync the versions this release vends, for the dependencies the workspace's
|
|
8
16
|
* generators own.
|
|
@@ -76,6 +76,15 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
76
76
|
}
|
|
77
77
|
return satisfies(vended, range);
|
|
78
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Version the sync moves a declared TypeScript dependency to, or undefined when
|
|
81
|
+
* it leaves the declaration as it is.
|
|
82
|
+
*
|
|
83
|
+
* Devkit then writes it only when it is higher than the declared version.
|
|
84
|
+
*/ export const syncedTsVersion = (tree, owned, name, declared)=>{
|
|
85
|
+
const vended = vendedTsVersion(owned, name);
|
|
86
|
+
return vended && isSyncableSpecifier(tree, declared) && !alreadyPermitsVended(tree, name, declared, vended) ? vended : undefined;
|
|
87
|
+
};
|
|
79
88
|
/**
|
|
80
89
|
* Vended packages a manifest already declares, and the version to move each to.
|
|
81
90
|
*
|
|
@@ -84,8 +93,8 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
84
93
|
*/ const declaredVendedPackages = (tree, owned, packageJsonPath)=>{
|
|
85
94
|
const json = readJson(tree, packageJsonPath);
|
|
86
95
|
const pick = (field)=>Object.fromEntries(Object.entries(json[field] ?? {}).flatMap(([name, declared])=>{
|
|
87
|
-
const vended =
|
|
88
|
-
return vended
|
|
96
|
+
const vended = syncedTsVersion(tree, owned, name, declared);
|
|
97
|
+
return vended ? [
|
|
89
98
|
[
|
|
90
99
|
name,
|
|
91
100
|
vended
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/version-upgrade-migration/sync-vended-versions.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n detectPackageManager,\n type MigrationReturnObject,\n readJson,\n type Tree,\n updateJson,\n visitNotIgnoredFiles,\n} from '@nx/devkit';\nimport yaml from 'js-yaml';\nimport { getCatalogManager } from 'nx/src/utils/catalog';\nimport { parsePipRequirementsLine } from 'pip-requirements-js';\nimport { coerce, parse, satisfies, validRange } from 'semver';\nimport { applyGritQL, captureAllGritQLVariable } from '../ast.js';\nimport { buildInstallCommand } from '../commands.js';\nimport { formatFilesInSubtree } from '../format.js';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants.js';\nimport { updateToml } from '../toml.js';\nimport {\n cdkLambdaRuntime,\n PY_VERSIONS,\n TERRAFORM_VERSIONS,\n TS_VERSIONS,\n terraformLambdaRuntime,\n} from '../versions.js';\nimport { isNxPackage } from './nx-package-updates.js';\nimport {\n type OwnedDependencies,\n ownedDependencies,\n} from './owned-dependencies.js';\nimport { syncEmbeddedVersions } from './sync-embedded-versions.js';\nimport { syncLambdaRuntimes, type VendedIac } from './sync-lambda-runtimes.js';\nimport { syncMetricsVersion } from './sync-metrics-version.js';\nimport {\n syncProjectPythonVersion,\n syncPythonBundleVersion,\n} from './sync-python-language-version.js';\nimport { isVendedUpgrade } from './vended-upgrade.js';\n\n/**\n * Syncs the versions a generated workspace pins to those this release vends:\n * TypeScript dependencies (including those pinned only by an override), Python\n * pins, Terraform providers, and the plugin version the metrics files report.\n *\n * nx and `@nx/*` are excluded — `packageJsonUpdates` owns them so `nx migrate`\n * collects Nx's own migrations (see `nx-package-updates.ts`).\n */\n\n/** Workspace files holding catalog definitions, and pnpm 11's overrides. */\nconst YAML_WORKSPACE_FILES = ['pnpm-workspace.yaml', '.yarnrc.yml'];\n\n/**\n * Vended version for a dependency this workspace's generators own, or undefined\n * for one the user added themselves.\n */\nconst vendedTsVersion = (\n owned: OwnedDependencies,\n name: string,\n): string | undefined =>\n isNxPackage(name) || !owned.ts.has(name)\n ? undefined\n : TS_VERSIONS[name as keyof typeof TS_VERSIONS];\n\n/** PY_VERSIONS records the `==` operator; the pin holds the bare version. */\nconst vendedPyVersion = (\n owned: OwnedDependencies,\n name: string,\n): string | undefined =>\n owned.py.has(name)\n ? PY_VERSIONS[name as keyof typeof PY_VERSIONS]?.replace(/^==/, '')\n : undefined;\n\n/** Protocols whose version lives elsewhere, and is synced there instead. */\nconst REFERENCE_PROTOCOL =\n /^(?:workspace|file|link|npm|git|git\\+|github|portal|patch|exec):/;\n\n/**\n * Whether devkit may be handed this specifier.\n *\n * `catalog:` is only safe where devkit has a catalog manager (pnpm, yarn, bun).\n * Without one it rewrites the reference to a literal version, severing the\n * catalog — so those references are synced directly instead.\n */\nconst isSyncableSpecifier = (tree: Tree, declared: unknown): boolean => {\n // A manifest is the user's file and may hold anything. A version that isn't a\n // string is not one this can reason about, and throwing here would abort the\n // whole `nx migrate` over a file the sync only meant to skip.\n if (typeof declared !== 'string') {\n return false;\n }\n if (REFERENCE_PROTOCOL.test(declared)) {\n return false;\n }\n return (\n !declared.startsWith('catalog:') || getCatalogManager(tree.root) !== null\n );\n};\n\n/**\n * Whether the declared range already permits the vended version, following a\n * `catalog:` reference to the range it points at.\n *\n * Devkit would narrow such a range to an exact pin, discarding a user's widened\n * specifier without changing what resolves, so it is left alone.\n */\nconst alreadyPermitsVended = (\n tree: Tree,\n packageName: string,\n declared: string,\n vended: string,\n): boolean => {\n let range = declared;\n if (declared.startsWith('catalog:')) {\n const resolved = getCatalogManager(tree.root)?.resolveCatalogReference(\n tree,\n packageName,\n declared,\n );\n if (!resolved) {\n return false;\n }\n range = resolved;\n }\n range = range.trim();\n // An exact pin is the case to upgrade, not a range to preserve.\n if (parse(range) !== null || validRange(range) === null) {\n return false;\n }\n return satisfies(vended, range);\n};\n\n/**\n * Vended packages a manifest already declares, and the version to move each to.\n *\n * Only packages already present are named: devkit adds whatever it is given, so\n * passing the full vended list would inject all of it into every manifest.\n */\nconst declaredVendedPackages = (\n tree: Tree,\n owned: OwnedDependencies,\n packageJsonPath: string,\n): {\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n} => {\n const json = readJson(tree, packageJsonPath);\n const pick = (field: 'dependencies' | 'devDependencies') =>\n Object.fromEntries(\n Object.entries((json[field] ?? {}) as Record<string, string>).flatMap(\n ([name, declared]) => {\n const vended = vendedTsVersion(owned, name);\n return vended &&\n isSyncableSpecifier(tree, declared) &&\n !alreadyPermitsVended(tree, name, declared, vended)\n ? [[name, vended] as const]\n : [];\n },\n ),\n );\n return {\n dependencies: pick('dependencies'),\n devDependencies: pick('devDependencies'),\n };\n};\n\n/**\n * Sync the TypeScript dependencies every `package.json` declares.\n *\n * Devkit does the writing: it moves a version wherever the workspace keeps it —\n * through a `catalog:` reference or directly — and refuses anything that isn't a\n * strict upgrade on what is installed.\n *\n * Called directly rather than through this plugin's wrapper, which *migrates*\n * declarations into the catalog; right when generating, wrong for a version bump.\n */\nconst syncPackageJsons = (tree: Tree, owned: OwnedDependencies): string[] => {\n const updated: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (!path.endsWith('package.json')) {\n return;\n }\n const { dependencies, devDependencies } = declaredVendedPackages(\n tree,\n owned,\n path,\n );\n if (\n Object.keys(dependencies).length === 0 &&\n Object.keys(devDependencies).length === 0\n ) {\n return;\n }\n\n const before = tree.read(path, 'utf-8');\n const catalogsBefore = readCatalogFiles(tree);\n // Install callback dropped: `nx migrate` runs install itself.\n addDependenciesToPackageJson(tree, dependencies, devDependencies, path);\n if (\n tree.read(path, 'utf-8') !== before ||\n readCatalogFiles(tree) !== catalogsBefore\n ) {\n updated.push(path);\n }\n });\n\n return updated;\n};\n\n/** Snapshot of every catalog definition file, for change detection. */\nconst readCatalogFiles = (tree: Tree): string =>\n [...YAML_WORKSPACE_FILES, 'package.json']\n .map((path) => (tree.exists(path) ? tree.read(path, 'utf-8') : ''))\n .join('\\0');\n\n/**\n * Upgrade vended catalog entries devkit cannot reach: those no manifest\n * references.\n */\nconst syncOrphanCatalogEntries = (\n tree: Tree,\n owned: OwnedDependencies,\n): string[] => {\n const referenced = referencedCatalogPackages(tree);\n const updated: string[] = [];\n\n const syncCatalog = (\n catalog: Record<string, string> | undefined,\n ): boolean => {\n let changed = false;\n for (const [name, declared] of Object.entries(catalog ?? {})) {\n const vended = vendedTsVersion(owned, name);\n if (!vended || referenced.has(name)) {\n continue;\n }\n if (isVendedUpgrade(vended, String(declared))) {\n catalog![name] = vended;\n changed = true;\n }\n }\n return changed;\n };\n\n for (const path of YAML_WORKSPACE_FILES) {\n if (!tree.exists(path)) {\n continue;\n }\n const catalogFile = (yaml.load(tree.read(path, 'utf-8') ?? '') ?? {}) as {\n catalog?: Record<string, string>;\n catalogs?: Record<string, Record<string, string>>;\n };\n const changed = [\n syncCatalog(catalogFile.catalog),\n ...Object.values(catalogFile.catalogs ?? {}).map(syncCatalog),\n ].some(Boolean);\n if (changed) {\n tree.write(path, yaml.dump(catalogFile, { quotingType: \"'\" }));\n updated.push(path);\n }\n }\n\n // Bun keeps its catalogs in the root manifest.\n if (tree.exists('package.json')) {\n let changed = false;\n updateJson(tree, 'package.json', (json) => {\n changed = [\n syncCatalog(json.catalog),\n ...Object.values(\n (json.catalogs ?? {}) as Record<string, Record<string, string>>,\n ).map(syncCatalog),\n ].some(Boolean);\n return json;\n });\n if (changed) {\n updated.push('package.json');\n }\n }\n\n return updated;\n};\n\n/**\n * The package an override key pins, or undefined when the key names none.\n *\n * A key is a package name, optionally preceded by the path it is scoped to and\n * followed by the parent range it applies at:\n *\n * zod -> zod\n * zod@^3 -> zod\n * **/@modelcontextprotocol/sdk/zod -> zod\n * @prisma/adapter-pg/@types/pg -> @types/pg\n *\n * The last segment is the package, since every earlier one is a parent it is\n * scoped under — except that a scope and the name after it are one segment.\n */\nconst overriddenPackage = (key: string): string | undefined => {\n const segments = key.split('/').reduce<string[]>((acc, part) => {\n // A bare `@scope` is only half a name; join it to what follows.\n const previous = acc[acc.length - 1];\n if (previous?.startsWith('@') && !previous.includes('/')) {\n acc[acc.length - 1] = `${previous}/${part}`;\n return acc;\n }\n acc.push(part);\n return acc;\n }, []);\n\n const name = segments[segments.length - 1];\n if (!name || name === '.') {\n return undefined;\n }\n // A trailing `@range` scopes the override to a parent version.\n const at = name.lastIndexOf('@');\n return at > 0 ? name.slice(0, at) : name;\n};\n\n/**\n * Sync the owned packages an override pins, wherever the workspace keeps them:\n * npm's `overrides`, yarn and bun's `resolutions`, and pnpm's `pnpm.overrides`\n * (10) or `pnpm-workspace.yaml` `overrides` (11).\n *\n * Devkit does not manage these fields, so an owned package pinned only here\n * would otherwise stay on the version it was generated with. Values are compared\n * with `isVendedUpgrade`, so a range the user widened is left alone.\n */\n/**\n * Where the workspace's package manager reads overrides from.\n *\n * Only the root manifest is considered: every package manager resolves overrides\n * from the workspace root, so a nested `overrides` block is inert and rewriting\n * it would imply an effect it doesn't have.\n *\n * pnpm moved the block between majors — 10 reads `pnpm.overrides` in the\n * manifest, 11 reads `overrides` in `pnpm-workspace.yaml` — so both are covered\n * rather than detecting the minor.\n */\nconst overrideLocations = (\n tree: Tree,\n): {\n manifestFields: readonly ('overrides' | 'resolutions' | 'pnpm.overrides')[];\n workspaceFile?: string;\n} => {\n switch (detectPackageManager(tree.root)) {\n case 'npm':\n return { manifestFields: ['overrides'] };\n case 'yarn':\n return { manifestFields: ['resolutions'] };\n case 'bun':\n // Bun reads npm's `overrides` and yarn's `resolutions` alike.\n return { manifestFields: ['overrides', 'resolutions'] };\n default:\n return {\n manifestFields: ['pnpm.overrides'],\n workspaceFile: 'pnpm-workspace.yaml',\n };\n }\n};\n\nconst syncOverrides = (tree: Tree, owned: OwnedDependencies): string[] => {\n const updated: string[] = [];\n\n // Nested npm overrides carry the pin under `.`, with sibling keys scoping\n // deeper, so a value may be a string or another override object.\n const syncOverrideTree = (overrides: unknown): boolean => {\n if (typeof overrides !== 'object' || overrides === null) {\n return false;\n }\n let changed = false;\n for (const [key, value] of Object.entries(\n overrides as Record<string, unknown>,\n )) {\n if (typeof value === 'object' && value !== null) {\n changed = syncOverrideTree(value) || changed;\n continue;\n }\n if (typeof value !== 'string') {\n continue;\n }\n // `.` pins the package its parent key names.\n const name =\n key === '.' ? undefined : (overriddenPackage(key) ?? undefined);\n const vended = name ? vendedTsVersion(owned, name) : undefined;\n if (vended && isVendedUpgrade(vended, value)) {\n (overrides as Record<string, unknown>)[key] = vended;\n changed = true;\n }\n }\n return changed;\n };\n\n const { manifestFields, workspaceFile } = overrideLocations(tree);\n\n if (manifestFields.length > 0) {\n let changed = false;\n updateJson(tree, 'package.json', (json) => {\n changed = manifestFields\n .map((field) =>\n syncOverrideTree(\n field === 'pnpm.overrides' ? json.pnpm?.overrides : json[field],\n ),\n )\n .some(Boolean);\n return json;\n });\n if (changed) {\n updated.push('package.json');\n }\n }\n\n if (workspaceFile && tree.exists(workspaceFile)) {\n const contents = (yaml.load(tree.read(workspaceFile, 'utf-8') ?? '') ??\n {}) as Record<string, unknown>;\n if (syncOverrideTree(contents.overrides)) {\n tree.write(workspaceFile, yaml.dump(contents, { quotingType: \"'\" }));\n updated.push(workspaceFile);\n }\n }\n\n return updated;\n};\n\n/**\n * Packages devkit already maintains through a `catalog:` reference. Empty\n * without a catalog manager, where no reference resolves.\n */\nconst referencedCatalogPackages = (tree: Tree): Set<string> => {\n const referenced = new Set<string>();\n if (getCatalogManager(tree.root) === null) {\n return referenced;\n }\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (!path.endsWith('package.json')) {\n return;\n }\n const json = readJson(tree, path);\n for (const field of ['dependencies', 'devDependencies'] as const) {\n for (const [name, declared] of Object.entries(\n (json[field] ?? {}) as Record<string, string>,\n )) {\n if (String(declared).startsWith('catalog:')) {\n referenced.add(name);\n }\n }\n }\n });\n return referenced;\n};\n\n/** Pip specifier as `pip-requirements-js` reports it. */\ninterface PyVersionSpec {\n readonly operator: string;\n readonly version: string;\n}\n\n/**\n * Whether the declared specifiers already permit the vended version, so\n * rewriting them would discard the user's range without changing what resolves.\n *\n * This mirrors the TypeScript side: an exact pin is the case to upgrade, a range\n * that already reaches the vended version is left alone, and a range that falls\n * short is moved up.\n *\n * A `*` wildcard or a specifier semver can't read counts as already permitting,\n * so anything not understood is left as the user wrote it.\n */\nconst pyRangePermitsVended = (\n specs: readonly PyVersionSpec[],\n vended: string,\n): boolean =>\n specs.every((spec) => {\n if (spec.version.includes('*')) {\n return true;\n }\n const bound = coerce(spec.version, { includePrerelease: true });\n if (!bound) {\n return true;\n }\n switch (spec.operator) {\n // An exact pin permits only itself, so a differing vended version is an\n // upgrade to apply.\n case '==':\n case '===':\n return satisfies(vended, `=${bound.version}`, {\n includePrerelease: true,\n });\n // `~=1.2.3` allows the patch series; `~=1.2` the minor series.\n case '~=':\n return satisfies(\n vended,\n spec.version.split('.').length > 2\n ? `~${bound.version}`\n : `^${bound.version}`,\n { includePrerelease: true },\n );\n case '>=':\n case '>':\n case '<=':\n case '<':\n return satisfies(vended, `${spec.operator}${bound.version}`, {\n includePrerelease: true,\n });\n // `!=` only excludes, so it never blocks the vended version by itself.\n case '!=':\n return true;\n default:\n return true;\n }\n });\n\n/**\n * Upgrade a pip requirement to the vended version, or return it unchanged.\n *\n * Parsed rather than pattern-matched so extras and operators are read the way\n * `uv` reads them. A requirement whose specifiers already permit the vended\n * version keeps them; one that falls short is replaced with an exact pin, which\n * is what the generators write.\n */\nconst syncPyRequirement = (\n owned: OwnedDependencies,\n requirement: string,\n): string => {\n const parsed = parsePipRequirementsLine(requirement);\n if (parsed?.type !== 'ProjectName' || !parsed.versionSpec?.length) {\n return requirement;\n }\n\n const name = parsed.extras?.length\n ? `${parsed.name}[${parsed.extras.join(',')}]`\n : parsed.name;\n const vended = vendedPyVersion(owned, name);\n if (!vended) {\n return requirement;\n }\n\n const specs = parsed.versionSpec as readonly PyVersionSpec[];\n // Never move a version backwards: a pin above what this release vends is the\n // user's, and a range already reaching it is theirs to keep.\n const [first] = specs;\n const isExactPin =\n specs.length === 1 && (first.operator === '==' || first.operator === '===');\n if (isExactPin && !isVendedUpgrade(vended, first.version)) {\n return requirement;\n }\n if (!isExactPin && pyRangePermitsVended(specs, vended)) {\n return requirement;\n }\n return `${name}==${vended}`;\n};\n\n/** Sync pins in every `pyproject.toml`, dependencies and groups alike. */\nconst syncPyProjects = (tree: Tree, owned: OwnedDependencies): string[] => {\n const updated: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (!path.endsWith('pyproject.toml')) {\n return;\n }\n\n let changed = false;\n const syncRequirements = (requirements: unknown): unknown =>\n Array.isArray(requirements)\n ? requirements.map((requirement) => {\n if (typeof requirement !== 'string') {\n return requirement;\n }\n const synced = syncPyRequirement(owned, requirement);\n changed ||= synced !== requirement;\n return synced;\n })\n : requirements;\n\n updateToml(tree, path, (toml) => {\n const project = toml.project as Record<string, unknown> | undefined;\n if (project?.dependencies) {\n project.dependencies = syncRequirements(project.dependencies) as never;\n }\n const groups = toml['dependency-groups'] as\n | Record<string, unknown>\n | undefined;\n for (const group of Object.keys(groups ?? {})) {\n groups![group] = syncRequirements(groups![group]) as never;\n }\n return toml;\n });\n\n if (changed) {\n updated.push(path);\n }\n });\n\n return updated;\n};\n\n/**\n * GritQL matching one provider's `version` in `required_providers`, scoped by\n * the sibling `source` so an alias or another provider's version can't match.\n *\n * `language hcl` is required — without it the pattern silently matches nothing.\n */\nconst providerVersionPattern = (provider: string, rewrite = ''): string =>\n `language hcl\\n\\`version = $version\\`${rewrite} where {` +\n ` $version <: within \\`{ source = \"hashicorp/${provider}\" $... }\\` }`;\n\n/** Version a provider currently declares, if it declares one. */\nconst declaredProviderVersion = async (\n tree: Tree,\n path: string,\n provider: string,\n): Promise<string | undefined> => {\n const [bound] =\n (await captureAllGritQLVariable(\n tree,\n path,\n providerVersionPattern(provider),\n 'version',\n )) ?? [];\n // The binding is the quoted version, e.g. `\"6.40.0\"`.\n return bound?.replace(/^\"|\"$/g, '');\n};\n\n/** Sync vended provider versions in every `.tf` file. */\nconst syncTerraformProviders = async (tree: Tree): Promise<string[]> => {\n const updated: string[] = [];\n const terraformFiles: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (path.endsWith('.tf')) {\n terraformFiles.push(path);\n }\n });\n\n for (const path of terraformFiles) {\n let changed = false;\n for (const [provider, vended] of Object.entries(TERRAFORM_VERSIONS)) {\n const declared = await declaredProviderVersion(tree, path, provider);\n if (!declared || !isVendedUpgrade(vended, declared)) {\n continue;\n }\n changed =\n (await applyGritQL(\n tree,\n path,\n providerVersionPattern(provider, ` => \\`version = \"${vended}\"\\``),\n )) || changed;\n }\n if (changed) {\n updated.push(path);\n }\n }\n\n return updated;\n};\n\n/**\n * The projects this plugin generates infrastructure into, per provider.\n *\n * A runtime is not a dependency, so there is no per-package ownership to consult —\n * these directories are the scope. A Lambda a user defined in their own project\n * keeps whatever runtime they chose, even though it is the same shape.\n */\nconst OWNED_INFRA_DIRS: Readonly<Record<VendedIac, string>> = {\n cdk: `${PACKAGES_DIR}/${SHARED_CONSTRUCTS_DIR}`,\n terraform: `${PACKAGES_DIR}/${SHARED_TERRAFORM_DIR}`,\n};\n\n/**\n * Sync the versions this release vends, for the dependencies the workspace's\n * generators own.\n */\nexport const syncVendedVersions = async (\n tree: Tree,\n): Promise<MigrationReturnObject> => {\n const nextSteps: string[] = [];\n const owned = await ownedDependencies(tree);\n\n const packageJsons = syncPackageJsons(tree, owned);\n const catalogs = syncOrphanCatalogEntries(tree, owned);\n const overrides = syncOverrides(tree, owned);\n const pyProjects = syncPyProjects(tree, owned);\n const terraformFiles = await syncTerraformProviders(tree);\n const lambdaRuntimes = await syncLambdaRuntimes(tree, OWNED_INFRA_DIRS);\n const projectPython = syncProjectPythonVersion(tree);\n const pythonBundles = syncPythonBundleVersion(tree);\n const skippedEmbedded = await syncEmbeddedVersions(tree, owned);\n await syncMetricsVersion(tree);\n\n // Lock files are left to the user: `nx migrate` only installs when the root\n // manifest changes, and never runs `uv` or `terraform`.\n if (catalogs.length > 0 || packageJsons.length > 0 || overrides.length > 0) {\n nextSteps.push(\n `TypeScript dependency versions were updated. Run \\`${buildInstallCommand(\n detectPackageManager(tree.root),\n )}\\` to update the lock file.`,\n );\n }\n if (\n pyProjects.length > 0 ||\n projectPython.length > 0 ||\n pythonBundles.length > 0\n ) {\n nextSteps.push(\n `Python dependency versions were updated in ${[...new Set([...pyProjects, ...projectPython, ...pythonBundles])].join(', ')}. Run \\`uv sync\\` to update uv.lock.`,\n );\n }\n // A runtime the sync recognised is simply moved; one it doesn't recognise is\n // the user's choice, so it is reported rather than rewritten.\n if (lambdaRuntimes.diverged.length > 0) {\n nextSteps.push(\n `Lambda runtimes in ${[...new Set(lambdaRuntimes.diverged)].join(', ')} have diverged from the generated shape and were left untouched. Set them to \\`${cdkLambdaRuntime('node')}\\` (CDK) or \\`\"${terraformLambdaRuntime('node')}\"\\` (Terraform) if you want them on the runtime this release vends.`,\n );\n }\n if (terraformFiles.length > 0) {\n nextSteps.push(\n `Terraform provider versions were updated in ${terraformFiles.length} file(s). Run \\`terraform init -upgrade\\` in each Terraform project to update its lock file.`,\n );\n }\n // A synced embedded pin needs no next step — it is read the next time the thing\n // holding it runs. A file the sync left alone does: its versions are still the\n // old ones, and only the user can reconcile that.\n if (skippedEmbedded.length > 0) {\n nextSteps.push(\n `Version pins were left as they are in ${skippedEmbedded.join(', ')}, which repeat a pin more times than this migration rewrites at once. Update them by hand.`,\n );\n }\n\n // Without this the workspace's own format check fails on the migrated files.\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n};\n"],"names":["addDependenciesToPackageJson","detectPackageManager","readJson","updateJson","visitNotIgnoredFiles","yaml","getCatalogManager","parsePipRequirementsLine","coerce","parse","satisfies","validRange","applyGritQL","captureAllGritQLVariable","buildInstallCommand","formatFilesInSubtree","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","updateToml","cdkLambdaRuntime","PY_VERSIONS","TERRAFORM_VERSIONS","TS_VERSIONS","terraformLambdaRuntime","isNxPackage","ownedDependencies","syncEmbeddedVersions","syncLambdaRuntimes","syncMetricsVersion","syncProjectPythonVersion","syncPythonBundleVersion","isVendedUpgrade","YAML_WORKSPACE_FILES","vendedTsVersion","owned","name","ts","has","undefined","vendedPyVersion","py","replace","REFERENCE_PROTOCOL","isSyncableSpecifier","tree","declared","test","startsWith","root","alreadyPermitsVended","packageName","vended","range","resolved","resolveCatalogReference","trim","declaredVendedPackages","packageJsonPath","json","pick","field","Object","fromEntries","entries","flatMap","dependencies","devDependencies","syncPackageJsons","updated","path","endsWith","keys","length","before","read","catalogsBefore","readCatalogFiles","push","map","exists","join","syncOrphanCatalogEntries","referenced","referencedCatalogPackages","syncCatalog","catalog","changed","String","catalogFile","load","values","catalogs","some","Boolean","write","dump","quotingType","overriddenPackage","key","segments","split","reduce","acc","part","previous","includes","at","lastIndexOf","slice","overrideLocations","manifestFields","workspaceFile","syncOverrides","syncOverrideTree","overrides","value","pnpm","contents","Set","add","pyRangePermitsVended","specs","every","spec","version","bound","includePrerelease","operator","syncPyRequirement","requirement","parsed","type","versionSpec","extras","first","isExactPin","syncPyProjects","syncRequirements","requirements","Array","isArray","synced","toml","project","groups","group","providerVersionPattern","provider","rewrite","declaredProviderVersion","syncTerraformProviders","terraformFiles","OWNED_INFRA_DIRS","cdk","terraform","syncVendedVersions","nextSteps","packageJsons","pyProjects","lambdaRuntimes","projectPython","pythonBundles","skippedEmbedded","diverged"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,QAAQ,EAERC,UAAU,EACVC,oBAAoB,QACf,aAAa;AACpB,OAAOC,UAAU,UAAU;AAC3B,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,wBAAwB,QAAQ,sBAAsB;AAC/D,SAASC,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,SAAS;AAC9D,SAASC,WAAW,EAAEC,wBAAwB,QAAQ,YAAY;AAClE,SAASC,mBAAmB,QAAQ,iBAAiB;AACrD,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SACEC,YAAY,EACZC,qBAAqB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4CAA4C,EAAE0E,eAAe/E,MAAM,CAAC,4FAA4F,CAAC;IAEtK;IACA,gFAAgF;IAChF,+EAA+E;IAC/E,kDAAkD;IAClD,IAAI0F,gBAAgB1F,MAAM,GAAG,GAAG;QAC9BoF,UAAU/E,IAAI,CACZ,CAAC,sCAAsC,EAAEqF,gBAAgBlF,IAAI,CAAC,MAAM,0FAA0F,CAAC;IAEnK;IAEA,6EAA6E;IAC7E,MAAMlE,qBAAqB8B;IAE3B,OAAO;QAAEgH;IAAU;AACrB,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/version-upgrade-migration/sync-vended-versions.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n detectPackageManager,\n type MigrationReturnObject,\n readJson,\n type Tree,\n updateJson,\n visitNotIgnoredFiles,\n} from '@nx/devkit';\nimport yaml from 'js-yaml';\nimport { getCatalogManager } from 'nx/src/utils/catalog';\nimport { parsePipRequirementsLine } from 'pip-requirements-js';\nimport { coerce, parse, satisfies, validRange } from 'semver';\nimport { applyGritQL, captureAllGritQLVariable } from '../ast.js';\nimport { buildInstallCommand } from '../commands.js';\nimport { formatFilesInSubtree } from '../format.js';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants.js';\nimport { updateToml } from '../toml.js';\nimport {\n cdkLambdaRuntime,\n PY_VERSIONS,\n TERRAFORM_VERSIONS,\n TS_VERSIONS,\n terraformLambdaRuntime,\n} from '../versions.js';\nimport { isNxPackage } from './nx-package-updates.js';\nimport {\n type OwnedDependencies,\n ownedDependencies,\n} from './owned-dependencies.js';\nimport { syncEmbeddedVersions } from './sync-embedded-versions.js';\nimport { syncLambdaRuntimes, type VendedIac } from './sync-lambda-runtimes.js';\nimport { syncMetricsVersion } from './sync-metrics-version.js';\nimport {\n syncProjectPythonVersion,\n syncPythonBundleVersion,\n} from './sync-python-language-version.js';\nimport { isVendedUpgrade } from './vended-upgrade.js';\n\n/**\n * Syncs the versions a generated workspace pins to those this release vends:\n * TypeScript dependencies (including those pinned only by an override), Python\n * pins, Terraform providers, and the plugin version the metrics files report.\n *\n * nx and `@nx/*` are excluded — `packageJsonUpdates` owns them so `nx migrate`\n * collects Nx's own migrations (see `nx-package-updates.ts`).\n */\n\n/** Workspace files holding catalog definitions, and pnpm 11's overrides. */\nconst YAML_WORKSPACE_FILES = ['pnpm-workspace.yaml', '.yarnrc.yml'];\n\n/**\n * Vended version for a dependency this workspace's generators own, or undefined\n * for one the user added themselves.\n */\nconst vendedTsVersion = (\n owned: OwnedDependencies,\n name: string,\n): string | undefined =>\n isNxPackage(name) || !owned.ts.has(name)\n ? undefined\n : TS_VERSIONS[name as keyof typeof TS_VERSIONS];\n\n/** PY_VERSIONS records the `==` operator; the pin holds the bare version. */\nconst vendedPyVersion = (\n owned: OwnedDependencies,\n name: string,\n): string | undefined =>\n owned.py.has(name)\n ? PY_VERSIONS[name as keyof typeof PY_VERSIONS]?.replace(/^==/, '')\n : undefined;\n\n/** Protocols whose version lives elsewhere, and is synced there instead. */\nconst REFERENCE_PROTOCOL =\n /^(?:workspace|file|link|npm|git|git\\+|github|portal|patch|exec):/;\n\n/**\n * Whether devkit may be handed this specifier.\n *\n * `catalog:` is only safe where devkit has a catalog manager (pnpm, yarn, bun).\n * Without one it rewrites the reference to a literal version, severing the\n * catalog — so those references are synced directly instead.\n */\nconst isSyncableSpecifier = (\n tree: Tree,\n declared: unknown,\n): declared is string => {\n // A manifest is the user's file and may hold anything. A version that isn't a\n // string is not one this can reason about, and throwing here would abort the\n // whole `nx migrate` over a file the sync only meant to skip.\n if (typeof declared !== 'string') {\n return false;\n }\n if (REFERENCE_PROTOCOL.test(declared)) {\n return false;\n }\n return (\n !declared.startsWith('catalog:') || getCatalogManager(tree.root) !== null\n );\n};\n\n/**\n * Whether the declared range already permits the vended version, following a\n * `catalog:` reference to the range it points at.\n *\n * Devkit would narrow such a range to an exact pin, discarding a user's widened\n * specifier without changing what resolves, so it is left alone.\n */\nconst alreadyPermitsVended = (\n tree: Tree,\n packageName: string,\n declared: string,\n vended: string,\n): boolean => {\n let range = declared;\n if (declared.startsWith('catalog:')) {\n const resolved = getCatalogManager(tree.root)?.resolveCatalogReference(\n tree,\n packageName,\n declared,\n );\n if (!resolved) {\n return false;\n }\n range = resolved;\n }\n range = range.trim();\n // An exact pin is the case to upgrade, not a range to preserve.\n if (parse(range) !== null || validRange(range) === null) {\n return false;\n }\n return satisfies(vended, range);\n};\n\n/**\n * Version the sync moves a declared TypeScript dependency to, or undefined when\n * it leaves the declaration as it is.\n *\n * Devkit then writes it only when it is higher than the declared version.\n */\nexport const syncedTsVersion = (\n tree: Tree,\n owned: OwnedDependencies,\n name: string,\n declared: unknown,\n): string | undefined => {\n const vended = vendedTsVersion(owned, name);\n return vended &&\n isSyncableSpecifier(tree, declared) &&\n !alreadyPermitsVended(tree, name, declared, vended)\n ? vended\n : undefined;\n};\n\n/**\n * Vended packages a manifest already declares, and the version to move each to.\n *\n * Only packages already present are named: devkit adds whatever it is given, so\n * passing the full vended list would inject all of it into every manifest.\n */\nconst declaredVendedPackages = (\n tree: Tree,\n owned: OwnedDependencies,\n packageJsonPath: string,\n): {\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n} => {\n const json = readJson(tree, packageJsonPath);\n const pick = (field: 'dependencies' | 'devDependencies') =>\n Object.fromEntries(\n Object.entries((json[field] ?? {}) as Record<string, string>).flatMap(\n ([name, declared]) => {\n const vended = syncedTsVersion(tree, owned, name, declared);\n return vended ? [[name, vended] as const] : [];\n },\n ),\n );\n return {\n dependencies: pick('dependencies'),\n devDependencies: pick('devDependencies'),\n };\n};\n\n/**\n * Sync the TypeScript dependencies every `package.json` declares.\n *\n * Devkit does the writing: it moves a version wherever the workspace keeps it —\n * through a `catalog:` reference or directly — and refuses anything that isn't a\n * strict upgrade on what is installed.\n *\n * Called directly rather than through this plugin's wrapper, which *migrates*\n * declarations into the catalog; right when generating, wrong for a version bump.\n */\nconst syncPackageJsons = (tree: Tree, owned: OwnedDependencies): string[] => {\n const updated: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (!path.endsWith('package.json')) {\n return;\n }\n const { dependencies, devDependencies } = declaredVendedPackages(\n tree,\n owned,\n path,\n );\n if (\n Object.keys(dependencies).length === 0 &&\n Object.keys(devDependencies).length === 0\n ) {\n return;\n }\n\n const before = tree.read(path, 'utf-8');\n const catalogsBefore = readCatalogFiles(tree);\n // Install callback dropped: `nx migrate` runs install itself.\n addDependenciesToPackageJson(tree, dependencies, devDependencies, path);\n if (\n tree.read(path, 'utf-8') !== before ||\n readCatalogFiles(tree) !== catalogsBefore\n ) {\n updated.push(path);\n }\n });\n\n return updated;\n};\n\n/** Snapshot of every catalog definition file, for change detection. */\nconst readCatalogFiles = (tree: Tree): string =>\n [...YAML_WORKSPACE_FILES, 'package.json']\n .map((path) => (tree.exists(path) ? tree.read(path, 'utf-8') : ''))\n .join('\\0');\n\n/**\n * Upgrade vended catalog entries devkit cannot reach: those no manifest\n * references.\n */\nconst syncOrphanCatalogEntries = (\n tree: Tree,\n owned: OwnedDependencies,\n): string[] => {\n const referenced = referencedCatalogPackages(tree);\n const updated: string[] = [];\n\n const syncCatalog = (\n catalog: Record<string, string> | undefined,\n ): boolean => {\n let changed = false;\n for (const [name, declared] of Object.entries(catalog ?? {})) {\n const vended = vendedTsVersion(owned, name);\n if (!vended || referenced.has(name)) {\n continue;\n }\n if (isVendedUpgrade(vended, String(declared))) {\n catalog![name] = vended;\n changed = true;\n }\n }\n return changed;\n };\n\n for (const path of YAML_WORKSPACE_FILES) {\n if (!tree.exists(path)) {\n continue;\n }\n const catalogFile = (yaml.load(tree.read(path, 'utf-8') ?? '') ?? {}) as {\n catalog?: Record<string, string>;\n catalogs?: Record<string, Record<string, string>>;\n };\n const changed = [\n syncCatalog(catalogFile.catalog),\n ...Object.values(catalogFile.catalogs ?? {}).map(syncCatalog),\n ].some(Boolean);\n if (changed) {\n tree.write(path, yaml.dump(catalogFile, { quotingType: \"'\" }));\n updated.push(path);\n }\n }\n\n // Bun keeps its catalogs in the root manifest.\n if (tree.exists('package.json')) {\n let changed = false;\n updateJson(tree, 'package.json', (json) => {\n changed = [\n syncCatalog(json.catalog),\n ...Object.values(\n (json.catalogs ?? {}) as Record<string, Record<string, string>>,\n ).map(syncCatalog),\n ].some(Boolean);\n return json;\n });\n if (changed) {\n updated.push('package.json');\n }\n }\n\n return updated;\n};\n\n/**\n * The package an override key pins, or undefined when the key names none.\n *\n * A key is a package name, optionally preceded by the path it is scoped to and\n * followed by the parent range it applies at:\n *\n * zod -> zod\n * zod@^3 -> zod\n * **/@modelcontextprotocol/sdk/zod -> zod\n * @prisma/adapter-pg/@types/pg -> @types/pg\n *\n * The last segment is the package, since every earlier one is a parent it is\n * scoped under — except that a scope and the name after it are one segment.\n */\nconst overriddenPackage = (key: string): string | undefined => {\n const segments = key.split('/').reduce<string[]>((acc, part) => {\n // A bare `@scope` is only half a name; join it to what follows.\n const previous = acc[acc.length - 1];\n if (previous?.startsWith('@') && !previous.includes('/')) {\n acc[acc.length - 1] = `${previous}/${part}`;\n return acc;\n }\n acc.push(part);\n return acc;\n }, []);\n\n const name = segments[segments.length - 1];\n if (!name || name === '.') {\n return undefined;\n }\n // A trailing `@range` scopes the override to a parent version.\n const at = name.lastIndexOf('@');\n return at > 0 ? name.slice(0, at) : name;\n};\n\n/**\n * Sync the owned packages an override pins, wherever the workspace keeps them:\n * npm's `overrides`, yarn and bun's `resolutions`, and pnpm's `pnpm.overrides`\n * (10) or `pnpm-workspace.yaml` `overrides` (11).\n *\n * Devkit does not manage these fields, so an owned package pinned only here\n * would otherwise stay on the version it was generated with. Values are compared\n * with `isVendedUpgrade`, so a range the user widened is left alone.\n */\n/**\n * Where the workspace's package manager reads overrides from.\n *\n * Only the root manifest is considered: every package manager resolves overrides\n * from the workspace root, so a nested `overrides` block is inert and rewriting\n * it would imply an effect it doesn't have.\n *\n * pnpm moved the block between majors — 10 reads `pnpm.overrides` in the\n * manifest, 11 reads `overrides` in `pnpm-workspace.yaml` — so both are covered\n * rather than detecting the minor.\n */\nconst overrideLocations = (\n tree: Tree,\n): {\n manifestFields: readonly ('overrides' | 'resolutions' | 'pnpm.overrides')[];\n workspaceFile?: string;\n} => {\n switch (detectPackageManager(tree.root)) {\n case 'npm':\n return { manifestFields: ['overrides'] };\n case 'yarn':\n return { manifestFields: ['resolutions'] };\n case 'bun':\n // Bun reads npm's `overrides` and yarn's `resolutions` alike.\n return { manifestFields: ['overrides', 'resolutions'] };\n default:\n return {\n manifestFields: ['pnpm.overrides'],\n workspaceFile: 'pnpm-workspace.yaml',\n };\n }\n};\n\nconst syncOverrides = (tree: Tree, owned: OwnedDependencies): string[] => {\n const updated: string[] = [];\n\n // Nested npm overrides carry the pin under `.`, with sibling keys scoping\n // deeper, so a value may be a string or another override object.\n const syncOverrideTree = (overrides: unknown): boolean => {\n if (typeof overrides !== 'object' || overrides === null) {\n return false;\n }\n let changed = false;\n for (const [key, value] of Object.entries(\n overrides as Record<string, unknown>,\n )) {\n if (typeof value === 'object' && value !== null) {\n changed = syncOverrideTree(value) || changed;\n continue;\n }\n if (typeof value !== 'string') {\n continue;\n }\n // `.` pins the package its parent key names.\n const name =\n key === '.' ? undefined : (overriddenPackage(key) ?? undefined);\n const vended = name ? vendedTsVersion(owned, name) : undefined;\n if (vended && isVendedUpgrade(vended, value)) {\n (overrides as Record<string, unknown>)[key] = vended;\n changed = true;\n }\n }\n return changed;\n };\n\n const { manifestFields, workspaceFile } = overrideLocations(tree);\n\n if (manifestFields.length > 0) {\n let changed = false;\n updateJson(tree, 'package.json', (json) => {\n changed = manifestFields\n .map((field) =>\n syncOverrideTree(\n field === 'pnpm.overrides' ? json.pnpm?.overrides : json[field],\n ),\n )\n .some(Boolean);\n return json;\n });\n if (changed) {\n updated.push('package.json');\n }\n }\n\n if (workspaceFile && tree.exists(workspaceFile)) {\n const contents = (yaml.load(tree.read(workspaceFile, 'utf-8') ?? '') ??\n {}) as Record<string, unknown>;\n if (syncOverrideTree(contents.overrides)) {\n tree.write(workspaceFile, yaml.dump(contents, { quotingType: \"'\" }));\n updated.push(workspaceFile);\n }\n }\n\n return updated;\n};\n\n/**\n * Packages devkit already maintains through a `catalog:` reference. Empty\n * without a catalog manager, where no reference resolves.\n */\nconst referencedCatalogPackages = (tree: Tree): Set<string> => {\n const referenced = new Set<string>();\n if (getCatalogManager(tree.root) === null) {\n return referenced;\n }\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (!path.endsWith('package.json')) {\n return;\n }\n const json = readJson(tree, path);\n for (const field of ['dependencies', 'devDependencies'] as const) {\n for (const [name, declared] of Object.entries(\n (json[field] ?? {}) as Record<string, string>,\n )) {\n if (String(declared).startsWith('catalog:')) {\n referenced.add(name);\n }\n }\n }\n });\n return referenced;\n};\n\n/** Pip specifier as `pip-requirements-js` reports it. */\ninterface PyVersionSpec {\n readonly operator: string;\n readonly version: string;\n}\n\n/**\n * Whether the declared specifiers already permit the vended version, so\n * rewriting them would discard the user's range without changing what resolves.\n *\n * This mirrors the TypeScript side: an exact pin is the case to upgrade, a range\n * that already reaches the vended version is left alone, and a range that falls\n * short is moved up.\n *\n * A `*` wildcard or a specifier semver can't read counts as already permitting,\n * so anything not understood is left as the user wrote it.\n */\nconst pyRangePermitsVended = (\n specs: readonly PyVersionSpec[],\n vended: string,\n): boolean =>\n specs.every((spec) => {\n if (spec.version.includes('*')) {\n return true;\n }\n const bound = coerce(spec.version, { includePrerelease: true });\n if (!bound) {\n return true;\n }\n switch (spec.operator) {\n // An exact pin permits only itself, so a differing vended version is an\n // upgrade to apply.\n case '==':\n case '===':\n return satisfies(vended, `=${bound.version}`, {\n includePrerelease: true,\n });\n // `~=1.2.3` allows the patch series; `~=1.2` the minor series.\n case '~=':\n return satisfies(\n vended,\n spec.version.split('.').length > 2\n ? `~${bound.version}`\n : `^${bound.version}`,\n { includePrerelease: true },\n );\n case '>=':\n case '>':\n case '<=':\n case '<':\n return satisfies(vended, `${spec.operator}${bound.version}`, {\n includePrerelease: true,\n });\n // `!=` only excludes, so it never blocks the vended version by itself.\n case '!=':\n return true;\n default:\n return true;\n }\n });\n\n/**\n * Upgrade a pip requirement to the vended version, or return it unchanged.\n *\n * Parsed rather than pattern-matched so extras and operators are read the way\n * `uv` reads them. A requirement whose specifiers already permit the vended\n * version keeps them; one that falls short is replaced with an exact pin, which\n * is what the generators write.\n */\nconst syncPyRequirement = (\n owned: OwnedDependencies,\n requirement: string,\n): string => {\n const parsed = parsePipRequirementsLine(requirement);\n if (parsed?.type !== 'ProjectName' || !parsed.versionSpec?.length) {\n return requirement;\n }\n\n const name = parsed.extras?.length\n ? `${parsed.name}[${parsed.extras.join(',')}]`\n : parsed.name;\n const vended = vendedPyVersion(owned, name);\n if (!vended) {\n return requirement;\n }\n\n const specs = parsed.versionSpec as readonly PyVersionSpec[];\n // Never move a version backwards: a pin above what this release vends is the\n // user's, and a range already reaching it is theirs to keep.\n const [first] = specs;\n const isExactPin =\n specs.length === 1 && (first.operator === '==' || first.operator === '===');\n if (isExactPin && !isVendedUpgrade(vended, first.version)) {\n return requirement;\n }\n if (!isExactPin && pyRangePermitsVended(specs, vended)) {\n return requirement;\n }\n return `${name}==${vended}`;\n};\n\n/** Sync pins in every `pyproject.toml`, dependencies and groups alike. */\nconst syncPyProjects = (tree: Tree, owned: OwnedDependencies): string[] => {\n const updated: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (!path.endsWith('pyproject.toml')) {\n return;\n }\n\n let changed = false;\n const syncRequirements = (requirements: unknown): unknown =>\n Array.isArray(requirements)\n ? requirements.map((requirement) => {\n if (typeof requirement !== 'string') {\n return requirement;\n }\n const synced = syncPyRequirement(owned, requirement);\n changed ||= synced !== requirement;\n return synced;\n })\n : requirements;\n\n updateToml(tree, path, (toml) => {\n const project = toml.project as Record<string, unknown> | undefined;\n if (project?.dependencies) {\n project.dependencies = syncRequirements(project.dependencies) as never;\n }\n const groups = toml['dependency-groups'] as\n | Record<string, unknown>\n | undefined;\n for (const group of Object.keys(groups ?? {})) {\n groups![group] = syncRequirements(groups![group]) as never;\n }\n return toml;\n });\n\n if (changed) {\n updated.push(path);\n }\n });\n\n return updated;\n};\n\n/**\n * GritQL matching one provider's `version` in `required_providers`, scoped by\n * the sibling `source` so an alias or another provider's version can't match.\n *\n * `language hcl` is required — without it the pattern silently matches nothing.\n */\nconst providerVersionPattern = (provider: string, rewrite = ''): string =>\n `language hcl\\n\\`version = $version\\`${rewrite} where {` +\n ` $version <: within \\`{ source = \"hashicorp/${provider}\" $... }\\` }`;\n\n/** Version a provider currently declares, if it declares one. */\nconst declaredProviderVersion = async (\n tree: Tree,\n path: string,\n provider: string,\n): Promise<string | undefined> => {\n const [bound] =\n (await captureAllGritQLVariable(\n tree,\n path,\n providerVersionPattern(provider),\n 'version',\n )) ?? [];\n // The binding is the quoted version, e.g. `\"6.40.0\"`.\n return bound?.replace(/^\"|\"$/g, '');\n};\n\n/** Sync vended provider versions in every `.tf` file. */\nconst syncTerraformProviders = async (tree: Tree): Promise<string[]> => {\n const updated: string[] = [];\n const terraformFiles: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (path.endsWith('.tf')) {\n terraformFiles.push(path);\n }\n });\n\n for (const path of terraformFiles) {\n let changed = false;\n for (const [provider, vended] of Object.entries(TERRAFORM_VERSIONS)) {\n const declared = await declaredProviderVersion(tree, path, provider);\n if (!declared || !isVendedUpgrade(vended, declared)) {\n continue;\n }\n changed =\n (await applyGritQL(\n tree,\n path,\n providerVersionPattern(provider, ` => \\`version = \"${vended}\"\\``),\n )) || changed;\n }\n if (changed) {\n updated.push(path);\n }\n }\n\n return updated;\n};\n\n/**\n * The projects this plugin generates infrastructure into, per provider.\n *\n * A runtime is not a dependency, so there is no per-package ownership to consult —\n * these directories are the scope. A Lambda a user defined in their own project\n * keeps whatever runtime they chose, even though it is the same shape.\n */\nconst OWNED_INFRA_DIRS: Readonly<Record<VendedIac, string>> = {\n cdk: `${PACKAGES_DIR}/${SHARED_CONSTRUCTS_DIR}`,\n terraform: `${PACKAGES_DIR}/${SHARED_TERRAFORM_DIR}`,\n};\n\n/**\n * Sync the versions this release vends, for the dependencies the workspace's\n * generators own.\n */\nexport const syncVendedVersions = async (\n tree: Tree,\n): Promise<MigrationReturnObject> => {\n const nextSteps: string[] = [];\n const owned = await ownedDependencies(tree);\n\n const packageJsons = syncPackageJsons(tree, owned);\n const catalogs = syncOrphanCatalogEntries(tree, owned);\n const overrides = syncOverrides(tree, owned);\n const pyProjects = syncPyProjects(tree, owned);\n const terraformFiles = await syncTerraformProviders(tree);\n const lambdaRuntimes = await syncLambdaRuntimes(tree, OWNED_INFRA_DIRS);\n const projectPython = syncProjectPythonVersion(tree);\n const pythonBundles = syncPythonBundleVersion(tree);\n const skippedEmbedded = await syncEmbeddedVersions(tree, owned);\n await syncMetricsVersion(tree);\n\n // Lock files are left to the user: `nx migrate` only installs when the root\n // manifest changes, and never runs `uv` or `terraform`.\n if (catalogs.length > 0 || packageJsons.length > 0 || overrides.length > 0) {\n nextSteps.push(\n `TypeScript dependency versions were updated. Run \\`${buildInstallCommand(\n detectPackageManager(tree.root),\n )}\\` to update the lock file.`,\n );\n }\n if (\n pyProjects.length > 0 ||\n projectPython.length > 0 ||\n pythonBundles.length > 0\n ) {\n nextSteps.push(\n `Python dependency versions were updated in ${[...new Set([...pyProjects, ...projectPython, ...pythonBundles])].join(', ')}. Run \\`uv sync\\` to update uv.lock.`,\n );\n }\n // A runtime the sync recognised is simply moved; one it doesn't recognise is\n // the user's choice, so it is reported rather than rewritten.\n if (lambdaRuntimes.diverged.length > 0) {\n nextSteps.push(\n `Lambda runtimes in ${[...new Set(lambdaRuntimes.diverged)].join(', ')} have diverged from the generated shape and were left untouched. Set them to \\`${cdkLambdaRuntime('node')}\\` (CDK) or \\`\"${terraformLambdaRuntime('node')}\"\\` (Terraform) if you want them on the runtime this release vends.`,\n );\n }\n if (terraformFiles.length > 0) {\n nextSteps.push(\n `Terraform provider versions were updated in ${terraformFiles.length} file(s). Run \\`terraform init -upgrade\\` in each Terraform project to update its lock file.`,\n );\n }\n // A synced embedded pin needs no next step — it is read the next time the thing\n // holding it runs. A file the sync left alone does: its versions are still the\n // old ones, and only the user can reconcile that.\n if (skippedEmbedded.length > 0) {\n nextSteps.push(\n `Version pins were left as they are in ${skippedEmbedded.join(', ')}, which repeat a pin more times than this migration rewrites at once. Update them by hand.`,\n );\n }\n\n // Without this the workspace's own format check fails on the migrated files.\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n};\n"],"names":["addDependenciesToPackageJson","detectPackageManager","readJson","updateJson","visitNotIgnoredFiles","yaml","getCatalogManager","parsePipRequirementsLine","coerce","parse","satisfies","validRange","applyGritQL","captureAllGritQLVariable","buildInstallCommand","formatFilesInSubtree","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","updateToml","cdkLambdaRuntime","PY_VERSIONS","TERRAFORM_VERSIONS","TS_VERSIONS","terraformLambdaRuntime","isNxPackage","ownedDependencies","syncEmbeddedVersions","syncLambdaRuntimes","syncMetricsVersion","syncProjectPythonVersion","syncPythonBundleVersion","isVendedUpgrade","YAML_WORKSPACE_FILES","vendedTsVersion","owned","name","ts","has","undefined","vendedPyVersion","py","replace","REFERENCE_PROTOCOL","isSyncableSpecifier","tree","declared","test","startsWith","root","alreadyPermitsVended","packageName","vended","range","resolved","resolveCatalogReference","trim","syncedTsVersion","declaredVendedPackages","packageJsonPath","json","pick","field","Object","fromEntries","entries","flatMap","dependencies","devDependencies","syncPackageJsons","updated","path","endsWith","keys","length","before","read","catalogsBefore","readCatalogFiles","push","map","exists","join","syncOrphanCatalogEntries","referenced","referencedCatalogPackages","syncCatalog","catalog","changed","String","catalogFile","load","values","catalogs","some","Boolean","write","dump","quotingType","overriddenPackage","key","segments","split","reduce","acc","part","previous","includes","at","lastIndexOf","slice","overrideLocations","manifestFields","workspaceFile","syncOverrides","syncOverrideTree","overrides","value","pnpm","contents","Set","add","pyRangePermitsVended","specs","every","spec","version","bound","includePrerelease","operator","syncPyRequirement","requirement","parsed","type","versionSpec","extras","first","isExactPin","syncPyProjects","syncRequirements","requirements","Array","isArray","synced","toml","project","groups","group","providerVersionPattern","provider","rewrite","declaredProviderVersion","syncTerraformProviders","terraformFiles","OWNED_INFRA_DIRS","cdk","terraform","syncVendedVersions","nextSteps","packageJsons","pyProjects","lambdaRuntimes","projectPython","pythonBundles","skippedEmbedded","diverged"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,QAAQ,EAERC,UAAU,EACVC,oBAAoB,QACf,aAAa;AACpB,OAAOC,UAAU,UAAU;AAC3B,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,wBAAwB,QAAQ,sBAAsB;AAC/D,SAASC,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,SAAS;AAC9D,SAASC,WAAW,EAAEC,wBAAwB,QAAQ,YAAY;AAClE,SAASC,mBAAmB,QAAQ,iBAAiB;AACrD,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SACEC,YAAY,EACZC,qBAAqB,EACrBC,oBAAoB,QACf,oCAAoC;AAC3C,SAASC,UAAU,QAAQ,aAAa;AACxC,SACEC,gBAAgB,EAChBC,WAAW,EACXC,kBAAkB,EAClBC,WAAW,EACXC,sBAAsB,QACjB,iBAAiB;AACxB,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAEEC,iBAAiB,QACZ,0BAA0B;AACjC,SAASC,oBAAoB,QAAQ,8BAA8B;AACnE,SAASC,kBAAkB,QAAwB,4BAA4B;AAC/E,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SACEC,wBAAwB,EACxBC,uBAAuB,QAClB,oCAAoC;AAC3C,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