@aws/nx-plugin 1.0.0-rc.92 → 1.0.0-rc.93
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/migrations.json
CHANGED
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
"implementation": "./src/migrations/v1.0.0-rc.89/0001-nx-parallel-default/migration"
|
|
294
294
|
},
|
|
295
295
|
"sync-vended-versions": {
|
|
296
|
-
"version": "1.0.0-rc.
|
|
296
|
+
"version": "1.0.0-rc.93",
|
|
297
297
|
"description": "Sync vended dependency versions and the tracked plugin version to those vended by this release",
|
|
298
298
|
"implementation": "./src/utils/version-upgrade-migration/migration"
|
|
299
299
|
}
|
package/package.json
CHANGED
|
@@ -244,6 +244,17 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
244
244
|
(name)=>`uvx --from ${name}==`,
|
|
245
245
|
(name)=>`--with ${name}==`
|
|
246
246
|
];
|
|
247
|
+
/**
|
|
248
|
+
* The way a `project.json` target command vendors an npm package into a build
|
|
249
|
+
* output, e.g. the AWS Distro for OpenTelemetry a code-packaged AgentCore
|
|
250
|
+
* runtime carries.
|
|
251
|
+
*
|
|
252
|
+
* Reuses the `Dockerfile` install shape: both are shell `npm install` lines, and
|
|
253
|
+
* a command string being JSON only narrows what can terminate the version — which
|
|
254
|
+
* `VERSION_TERMINATORS` already covers. Driven off the owned set like every other
|
|
255
|
+
* pin, so a package a later release vendors this way is covered without a change
|
|
256
|
+
* here.
|
|
257
|
+
*/ const TARGET_NPM_INSTALL_SHAPE = (name)=>`npm (?:install|i|add)[^\\n]*?\\s${name}@([0-9][^${VERSION_TERMINATORS}']*)`;
|
|
247
258
|
/**
|
|
248
259
|
* Sync the pinned tools a `project.json` target command runs: a container image,
|
|
249
260
|
* and the Python versions a `uvx` invocation pins.
|
|
@@ -257,7 +268,7 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
257
268
|
* Unscoped, unlike the file-body pins: a `uvx` invocation installs nothing into
|
|
258
269
|
* the project, so there is no dependency for a generator to own. A version is only
|
|
259
270
|
* rewritten where this release vends that exact package at a higher one.
|
|
260
|
-
*/ const syncTargetToolPins = async (tree)=>{
|
|
271
|
+
*/ const syncTargetToolPins = async (tree, owned)=>{
|
|
261
272
|
const projectJsons = [];
|
|
262
273
|
visitNotIgnoredFiles(tree, '.', (path)=>{
|
|
263
274
|
if (path.endsWith('project.json')) {
|
|
@@ -291,7 +302,23 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
291
302
|
];
|
|
292
303
|
const skipped = [];
|
|
293
304
|
for (const path of projectJsons){
|
|
294
|
-
|
|
305
|
+
// The vendoring pins are ownership-scoped, unlike the tooling ones above: a
|
|
306
|
+
// vendored package is declared by the generator that vendors it, so a
|
|
307
|
+
// package the user pinned in a command of their own is never rewritten.
|
|
308
|
+
const vendoringPins = [];
|
|
309
|
+
for (const name of ownedForFile(owned, path).ts){
|
|
310
|
+
const vended = vendedTsVersion(name);
|
|
311
|
+
if (vended) {
|
|
312
|
+
vendoringPins.push({
|
|
313
|
+
pattern: TARGET_NPM_INSTALL_SHAPE(escapeRegExp(name)),
|
|
314
|
+
vended
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if ((await applyPins(tree, path, [
|
|
319
|
+
...pins,
|
|
320
|
+
...vendoringPins
|
|
321
|
+
])).skipped) {
|
|
295
322
|
skipped.push(path);
|
|
296
323
|
}
|
|
297
324
|
}
|
|
@@ -345,7 +372,7 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
345
372
|
*/ export const syncEmbeddedVersions = async (tree, owned)=>[
|
|
346
373
|
...await syncDockerfiles(tree, owned),
|
|
347
374
|
...await syncTerraformScriptPins(tree, owned),
|
|
348
|
-
...await syncTargetToolPins(tree),
|
|
375
|
+
...await syncTargetToolPins(tree, owned),
|
|
349
376
|
...await syncSmithyMavenPins(tree)
|
|
350
377
|
];
|
|
351
378
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/version-upgrade-migration/sync-embedded-versions.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { ProjectConfiguration, Tree } from '@nx/devkit';\nimport {\n getProjects,\n joinPathFragments,\n visitNotIgnoredFiles,\n} from '@nx/devkit';\nimport { SMITHY_PROJECT_GENERATOR_INFO } from '../../smithy/project/generator.js';\nimport { applyGritQL } from '../ast.js';\nimport {\n BASE_IMAGES,\n CONTAINER_REPOSITORIES,\n CONTAINER_VERSIONS,\n JAVA_ARTIFACTS,\n JAVA_VERSIONS,\n MISE_VERSIONS,\n PY_VERSIONS,\n TS_VERSIONS,\n} from '../versions.js';\nimport { type OwnedDependencies, ownedForFile } from './owned-dependencies.js';\nimport { isVendedUpgrade } from './vended-upgrade.js';\n\n/**\n * Sync the vended versions generators bake into the body of a file rather than\n * into a manifest: the container image pins in a `Dockerfile`, the Python pins\n * in a Terraform inline script, and the tooling images a `project.json` target\n * command runs.\n *\n * Every version here is pinned to clear a known HIGH/CRITICAL vulnerability, or\n * to keep a generated image reproducible, so leaving them behind strands a\n * workspace on exactly the versions most in need of an upgrade.\n *\n * These sit inside shell commands, which GritQL has no grammar for — so instead\n * of pattern-matching the surrounding syntax, each pin is located by an anchored\n * regex whose single capture group is the version, and only that capture is\n * rewritten. The file's own text around it is never reconstructed, so a\n * reformatted or hand-edited file syncs the same way a freshly generated one\n * does.\n */\n\n/** A pin found in a file body, and the version this release vends for it. */\ninterface EmbeddedPin {\n /** Regex matching the pin, with the version as its only capture group. */\n readonly pattern: string;\n readonly vended: string;\n /**\n * Whether the declared value is a version to move forward, or a tag to replace\n * whenever it differs. A tag — `lts-slim`, say — has no ordering to compare, so\n * one that isn't what this release vends is simply out of date.\n */\n readonly kind?: 'version' | 'tag';\n}\n\n/** Escape a package name or image reference for use inside a regex. */\nconst escapeRegExp = (value: string): string =>\n value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/**\n * Characters that end a pinned version: whitespace, the backslash continuing a\n * shell line, and the quote closing the string the pin sits in.\n *\n * The quote is escaped because the pattern is itself a double-quoted GritQL\n * regex literal, which a bare quote would terminate.\n */\nconst VERSION_TERMINATORS = '\\\\s\\\\\\\\\\\\\"';\n\n/**\n * Rewrite the capture group of an anchored regex to the vended version.\n *\n * The leading and trailing `[\\s\\S]*` anchor the match to the whole file, which\n * is what lets a capture group be rewritten on its own: GritQL binds the group\n * to a node it can replace, leaving every other byte untouched. Without the\n * anchors nothing matches.\n */\nconst rewriteCapture = (pattern: string, vended: string): string =>\n `r\"[\\\\s\\\\S]*${pattern}[\\\\s\\\\S]*\"($version) where { $version => \\`${vended}\\` }`;\n\n/**\n * Versions a pin's regex currently matches in the file.\n *\n * Read before rewriting so a version the user raised past what this release\n * vends is left alone, matching how every other surface behaves.\n */\nconst declaredVersions = (contents: string, pattern: string): string[] => {\n const matches = contents.matchAll(new RegExp(pattern, 'g'));\n return [...matches].flatMap((match) => (match[1] ? [match[1]] : []));\n};\n\n/**\n * Occurrences of one pin a single rewrite will handle.\n *\n * GritQL rewrites each match separately, so its cost grows with how many a\n * pattern matches — ~10ms an occurrence, which a hand-authored file with hundreds\n * of `RUN npm install` lines turns into minutes of an unattended `nx migrate`.\n * Past this the file is left alone and reported, since a wrong version the user\n * can see and fix beats an upgrade that appears to hang.\n */\nconst MAX_OCCURRENCES_PER_PIN = 100;\n\n/**\n * Apply the pins whose declared version this release moves forward.\n *\n * A single rewrite covers every occurrence of a pin in the file, so each pin is\n * applied once. Reports whether anything changed, and whether a pin was left\n * alone for exceeding {@link MAX_OCCURRENCES_PER_PIN}.\n */\nconst applyPins = async (\n tree: Tree,\n path: string,\n pins: readonly EmbeddedPin[],\n): Promise<{ changed: boolean; skipped: boolean }> => {\n // Read once and re-read only after a rewrite: a rewrite parses the whole file,\n // and there is a pin per owned package, so re-reading per pin would scale the\n // cost of a large file with the size of the owned set.\n let contents = tree.read(path, 'utf-8') ?? '';\n let changed = false;\n let skipped = false;\n\n for (const { pattern, vended, kind = 'version' } of pins) {\n const declared = declaredVersions(contents, pattern);\n if (declared.length === 0) {\n continue;\n }\n if (declared.length > MAX_OCCURRENCES_PER_PIN) {\n skipped = true;\n continue;\n }\n const outOfDate =\n kind === 'tag'\n ? (tag: string) => tag !== vended\n : (version: string) => isVendedUpgrade(vended, version);\n // A rewrite replaces every occurrence at once, so this must hold for all of\n // them — a pin already at or beyond the vended version is left as it is.\n if (!declared.every(outOfDate)) {\n continue;\n }\n if (await applyGritQL(tree, path, rewriteCapture(pattern, vended))) {\n contents = tree.read(path, 'utf-8') ?? '';\n changed = true;\n }\n }\n\n return { changed, skipped };\n};\n\n/**\n * The version this release vends for a package, or undefined for one it doesn't\n * vend at all.\n *\n * Ownership is applied by the caller, which only ever passes a name drawn from\n * the owned set — so a package the user pinned themselves never reaches here and\n * keeps the version they chose.\n */\nconst vendedTsVersion = (name: string): string | undefined =>\n TS_VERSIONS[name as keyof typeof TS_VERSIONS];\n\n/** `PY_VERSIONS` records the `==` operator; a pin holds the bare version. */\nconst vendedPyVersion = (name: string): string | undefined =>\n PY_VERSIONS[name as keyof typeof PY_VERSIONS]?.replace(/^==/, '');\n\n/**\n * The ways a generated `Dockerfile` pins a TypeScript package's version, as\n * regex fragments taking the escaped package name.\n *\n * The name is required to run to its delimiter, so a package whose name merely\n * ends with another's — `some-npm` against `npm` — cannot match, and an\n * installed version must start with a digit so a `@latest` style tag is left\n * alone.\n */\nconst DOCKERFILE_PIN_SHAPES: readonly ((name: string) => string)[] = [\n // Installed by the image build. `install` and its `i` alias are both used, as\n // are `-g` and several packages in one command, so the name only has to follow\n // an `npm` subcommand rather than sit right after it. The whitespace before it\n // is matched rather than asserted, since GritQL's regex engine has no\n // lookbehind — which also keeps `some-npm` from matching `npm`, and unlike a\n // `\\b` boundary still reaches a `@scope/name`.\n (name) =>\n `npm (?:install|i|add)[^\\\\n]*?\\\\s${name}@([0-9][^${VERSION_TERMINATORS}]*)`,\n // Held at a fixed version through an `npm pkg set` override, to clear a known\n // vulnerability in a transitive dependency.\n (name) => `overrides\\\\.${name}=([^${VERSION_TERMINATORS}]+)`,\n];\n\n/**\n * Every pin a generated `Dockerfile` may carry, for the packages owned where it\n * sits.\n *\n * Driven off the owned packages rather than a list of the ones that happen to be\n * pinned today: a pin added to a template in a later release is then covered\n * without this module changing, which is the whole point — the versions baked\n * into image builds are pinned precisely because they clear a known\n * vulnerability.\n *\n * A package the user pinned themselves is not owned, so it is never matched.\n */\nconst dockerfilePins = (owned: {\n readonly ts: ReadonlySet<string>;\n}): EmbeddedPin[] => {\n const pins: EmbeddedPin[] = [];\n\n for (const name of owned.ts) {\n const vended = vendedTsVersion(name);\n if (!vended) {\n continue;\n }\n for (const shape of DOCKERFILE_PIN_SHAPES) {\n pins.push({ pattern: shape(escapeRegExp(name)), vended });\n }\n }\n\n for (const image of Object.values(BASE_IMAGES)) {\n const [repository, tag] = splitImageReference(image);\n pins.push({\n // Only a `FROM` that is the whole instruction. A build stage names itself\n // — `FROM <repo>:24 AS builder` — and picks its tag for what that stage has\n // to run: the smithy builder needs curl and unzip, which the slim tag this\n // release vends for a runtime image does not carry. Rewriting it would\n // break the build, and the two share a repository, so the instruction\n // ending is what separates them.\n pattern: `FROM ${escapeRegExp(repository)}:([^\\\\s]+)\\\\n`,\n vended: tag,\n kind: 'tag',\n });\n }\n\n return pins;\n};\n\n/**\n * The repository and tag of a pinned image reference. The tag is the part after\n * the last `:`, which a registry port would otherwise be mistaken for — every\n * reference here carries one.\n */\nconst splitImageReference = (image: string): [string, string] => {\n const at = image.lastIndexOf(':');\n return [image.slice(0, at), image.slice(at + 1)];\n};\n\n/**\n * Whether a file is a Dockerfile: exactly `Dockerfile`, or the `<name>.Dockerfile`\n * form the smithy templates vend as `build.Dockerfile`.\n *\n * Deliberately exact rather than a prefix match, which would also claim a\n * `Dockerfile.bak` or a `Dockerfile.md` the user keeps beside a real one.\n */\nexport const isDockerfile = (filePath: string): boolean => {\n const name = filePath.split('/').pop() ?? '';\n return name === 'Dockerfile' || name.endsWith('.Dockerfile');\n};\n\n/**\n * Sync the pins in every generated Dockerfile.\n *\n * Ownership is resolved per file, so a Dockerfile is only rewritten for the\n * packages the project it belongs to owns — a sibling project owning `prisma`\n * does not license rewriting a `prisma` pin here.\n */\nconst syncDockerfiles = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => {\n const dockerfiles: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (isDockerfile(path)) {\n dockerfiles.push(path);\n }\n });\n\n const skipped: string[] = [];\n for (const path of dockerfiles) {\n const result = await applyPins(\n tree,\n path,\n dockerfilePins(ownedForFile(owned, path)),\n );\n if (result.skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/** The `uv run --with` pins to apply, for the Python packages owned where a file sits. */\nconst terraformScriptPins = (owned: {\n readonly py: ReadonlySet<string>;\n}): EmbeddedPin[] =>\n [...owned.py].flatMap((name) => {\n const vended = vendedPyVersion(name);\n return vended\n ? [\n {\n pattern: `--with ${escapeRegExp(name)}==([^${VERSION_TERMINATORS}]+)`,\n vended,\n },\n ]\n : [];\n });\n\n/**\n * Sync the Python pins a generated Terraform inline script runs through\n * `uv run --with <package>==<version>`.\n *\n * These are the plugin's own pins, in a file the Terraform provider sync already\n * visits but only reads `required_providers` from. Driven off the owned Python\n * packages, so a pin added to a template later is covered without a change here.\n *\n * Scoped per file like the Dockerfiles. The modules carrying these live in the\n * shared Terraform project, which no single generator owns — a file there belongs\n * to no project, so it takes the workspace-wide union, which is the set of\n * generators that legitimately write into it.\n */\nconst syncTerraformScriptPins = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => {\n const terraformFiles: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (path.endsWith('.tf')) {\n terraformFiles.push(path);\n }\n });\n\n const skipped: string[] = [];\n for (const path of terraformFiles) {\n const result = await applyPins(\n tree,\n path,\n terraformScriptPins(ownedForFile(owned, path)),\n );\n if (result.skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/**\n * The ways a `uvx` invocation pins a Python version: the tool it runs, and any\n * package it adds to that tool's environment.\n *\n * A command string is JSON here, so a quote ends a version too.\n */\nconst UVX_PIN_SHAPES: readonly ((name: string) => string)[] = [\n (name) => `uvx --from ${name}==`,\n (name) => `--with ${name}==`,\n];\n\n/**\n * Sync the pinned tools a `project.json` target command runs: a container image,\n * and the Python versions a `uvx` invocation pins.\n *\n * Both are built into the command string rather than declared as a dependency, so\n * nothing else reaches them. The images are driven off `CONTAINER_REPOSITORIES`\n * and the Python versions off `PY_VERSIONS`, so a tool pinned in a target command\n * later is covered without a change here — the same property the Dockerfile and\n * Terraform paths get from the owned set.\n *\n * Unscoped, unlike the file-body pins: a `uvx` invocation installs nothing into\n * the project, so there is no dependency for a generator to own. A version is only\n * rewritten where this release vends that exact package at a higher one.\n */\nconst syncTargetToolPins = async (tree: Tree): Promise<string[]> => {\n const projectJsons: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (path.endsWith('project.json')) {\n projectJsons.push(path);\n }\n });\n\n const pins: EmbeddedPin[] = [\n ...Object.entries(CONTAINER_REPOSITORIES).map(([tool, repository]) => ({\n // A command string is JSON here, so a quote ends the reference too.\n pattern: `${escapeRegExp(repository)}:([^${VERSION_TERMINATORS}']+)`,\n vended: CONTAINER_VERSIONS[tool as keyof typeof CONTAINER_VERSIONS],\n })),\n // The Smithy CLI a Smithy project's compile target runs, and the `mise` that\n // resolves it. Neither is installed into the workspace — the target fetches\n // mise with `npx` — so this command is the only place either version sits.\n {\n pattern: `exec smithy@([^${VERSION_TERMINATORS}']+)`,\n vended: MISE_VERSIONS.smithy,\n },\n {\n pattern: `npx -y mise@([^${VERSION_TERMINATORS}']+)`,\n vended: TS_VERSIONS.mise,\n },\n ...Object.keys(PY_VERSIONS).flatMap((name) => {\n const vended = vendedPyVersion(name);\n return vended\n ? UVX_PIN_SHAPES.map((shape) => ({\n pattern: `${shape(escapeRegExp(name))}([^${VERSION_TERMINATORS}']+)`,\n vended,\n }))\n : [];\n }),\n ];\n\n const skipped: string[] = [];\n for (const path of projectJsons) {\n if ((await applyPins(tree, path, pins)).skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/**\n * Sync the Maven coordinates a generated `smithy-build.json` resolves.\n *\n * These are Java artifacts the Smithy CLI downloads, so they appear in no\n * manifest the dependency sync reads — this file is the only place they sit. Each\n * is matched by its `group:artifact` prefix so only the version is rewritten,\n * leaving any coordinate the user added alone.\n *\n * Scoped to the projects `smithy#project` generated: a `smithy-build.json` a user\n * wrote themselves keeps the versions they chose.\n */\nconst syncSmithyMavenPins = async (tree: Tree): Promise<string[]> => {\n const isGeneratedSmithyProject = (project: ProjectConfiguration): boolean =>\n (project.metadata as { generator?: string } | undefined)?.generator ===\n SMITHY_PROJECT_GENERATOR_INFO.id;\n\n const smithyBuilds: string[] = [];\n for (const [, project] of getProjects(tree)) {\n if (!isGeneratedSmithyProject(project)) {\n continue;\n }\n const path = joinPathFragments(project.root, 'smithy-build.json');\n if (tree.exists(path)) {\n smithyBuilds.push(path);\n }\n }\n\n const pins: EmbeddedPin[] = JAVA_ARTIFACTS.map((artifact) => ({\n // A coordinate is a JSON string here, so a quote ends the version.\n pattern: `${escapeRegExp(artifact)}:([^${VERSION_TERMINATORS}']+)`,\n vended: JAVA_VERSIONS[artifact],\n }));\n\n const skipped: string[] = [];\n for (const path of smithyBuilds) {\n if ((await applyPins(tree, path, pins)).skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/**\n * Sync the vended versions baked into generated file bodies: `Dockerfile` pins,\n * the Python pins in Terraform inline scripts, the tooling `project.json` target\n * commands run, and the Maven coordinates a `smithy-build.json` resolves.\n *\n * Reports only the files left for the user: a pin that takes effect the next time\n * the thing holding it runs needs no follow-up, but one this skipped for holding\n * more occurrences than it will rewrite at once does.\n *\n * @returns paths whose pins were left as they were\n */\nexport const syncEmbeddedVersions = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => [\n ...(await syncDockerfiles(tree, owned)),\n ...(await syncTerraformScriptPins(tree, owned)),\n ...(await syncTargetToolPins(tree)),\n ...(await syncSmithyMavenPins(tree)),\n];\n"],"names":["getProjects","joinPathFragments","visitNotIgnoredFiles","SMITHY_PROJECT_GENERATOR_INFO","applyGritQL","BASE_IMAGES","CONTAINER_REPOSITORIES","CONTAINER_VERSIONS","JAVA_ARTIFACTS","JAVA_VERSIONS","MISE_VERSIONS","PY_VERSIONS","TS_VERSIONS","ownedForFile","isVendedUpgrade","escapeRegExp","value","replace","VERSION_TERMINATORS","rewriteCapture","pattern","vended","declaredVersions","contents","matches","matchAll","RegExp","flatMap","match","MAX_OCCURRENCES_PER_PIN","applyPins","tree","path","pins","read","changed","skipped","kind","declared","length","outOfDate","tag","version","every","vendedTsVersion","name","vendedPyVersion","DOCKERFILE_PIN_SHAPES","dockerfilePins","owned","ts","shape","push","image","Object","values","repository","splitImageReference","at","lastIndexOf","slice","isDockerfile","filePath","split","pop","endsWith","syncDockerfiles","dockerfiles","result","terraformScriptPins","py","syncTerraformScriptPins","terraformFiles","UVX_PIN_SHAPES","syncTargetToolPins","projectJsons","entries","map","tool","smithy","mise","keys","syncSmithyMavenPins","isGeneratedSmithyProject","project","metadata","generator","id","smithyBuilds","root","exists","artifact","syncEmbeddedVersions"],"mappings":"AAAA;;;CAGC,GAED,SACEA,WAAW,EACXC,iBAAiB,EACjBC,oBAAoB,QACf,aAAa;AACpB,SAASC,6BAA6B,QAAQ,oCAAoC;AAClF,SAASC,WAAW,QAAQ,YAAY;AACxC,SACEC,WAAW,EACXC,sBAAsB,EACtBC,kBAAkB,EAClBC,cAAc,EACdC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,WAAW,QACN,iBAAiB;AACxB,SAAiCC,YAAY,QAAQ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AAO,MAAMwD,uBAAuB,OAClC7D,MACAkB,QACsB;WAClB,MAAMiB,gBAAgBnC,MAAMkB;WAC5B,MAAMsB,wBAAwBxC,MAAMkB;WACpC,MAAMyB,mBAAmB3C;WACzB,MAAMmD,oBAAoBnD;KAC/B,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/version-upgrade-migration/sync-embedded-versions.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { ProjectConfiguration, Tree } from '@nx/devkit';\nimport {\n getProjects,\n joinPathFragments,\n visitNotIgnoredFiles,\n} from '@nx/devkit';\nimport { SMITHY_PROJECT_GENERATOR_INFO } from '../../smithy/project/generator.js';\nimport { applyGritQL } from '../ast.js';\nimport {\n BASE_IMAGES,\n CONTAINER_REPOSITORIES,\n CONTAINER_VERSIONS,\n JAVA_ARTIFACTS,\n JAVA_VERSIONS,\n MISE_VERSIONS,\n PY_VERSIONS,\n TS_VERSIONS,\n} from '../versions.js';\nimport { type OwnedDependencies, ownedForFile } from './owned-dependencies.js';\nimport { isVendedUpgrade } from './vended-upgrade.js';\n\n/**\n * Sync the vended versions generators bake into the body of a file rather than\n * into a manifest: the container image pins in a `Dockerfile`, the Python pins\n * in a Terraform inline script, and the tooling images a `project.json` target\n * command runs.\n *\n * Every version here is pinned to clear a known HIGH/CRITICAL vulnerability, or\n * to keep a generated image reproducible, so leaving them behind strands a\n * workspace on exactly the versions most in need of an upgrade.\n *\n * These sit inside shell commands, which GritQL has no grammar for — so instead\n * of pattern-matching the surrounding syntax, each pin is located by an anchored\n * regex whose single capture group is the version, and only that capture is\n * rewritten. The file's own text around it is never reconstructed, so a\n * reformatted or hand-edited file syncs the same way a freshly generated one\n * does.\n */\n\n/** A pin found in a file body, and the version this release vends for it. */\ninterface EmbeddedPin {\n /** Regex matching the pin, with the version as its only capture group. */\n readonly pattern: string;\n readonly vended: string;\n /**\n * Whether the declared value is a version to move forward, or a tag to replace\n * whenever it differs. A tag — `lts-slim`, say — has no ordering to compare, so\n * one that isn't what this release vends is simply out of date.\n */\n readonly kind?: 'version' | 'tag';\n}\n\n/** Escape a package name or image reference for use inside a regex. */\nconst escapeRegExp = (value: string): string =>\n value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/**\n * Characters that end a pinned version: whitespace, the backslash continuing a\n * shell line, and the quote closing the string the pin sits in.\n *\n * The quote is escaped because the pattern is itself a double-quoted GritQL\n * regex literal, which a bare quote would terminate.\n */\nconst VERSION_TERMINATORS = '\\\\s\\\\\\\\\\\\\"';\n\n/**\n * Rewrite the capture group of an anchored regex to the vended version.\n *\n * The leading and trailing `[\\s\\S]*` anchor the match to the whole file, which\n * is what lets a capture group be rewritten on its own: GritQL binds the group\n * to a node it can replace, leaving every other byte untouched. Without the\n * anchors nothing matches.\n */\nconst rewriteCapture = (pattern: string, vended: string): string =>\n `r\"[\\\\s\\\\S]*${pattern}[\\\\s\\\\S]*\"($version) where { $version => \\`${vended}\\` }`;\n\n/**\n * Versions a pin's regex currently matches in the file.\n *\n * Read before rewriting so a version the user raised past what this release\n * vends is left alone, matching how every other surface behaves.\n */\nconst declaredVersions = (contents: string, pattern: string): string[] => {\n const matches = contents.matchAll(new RegExp(pattern, 'g'));\n return [...matches].flatMap((match) => (match[1] ? [match[1]] : []));\n};\n\n/**\n * Occurrences of one pin a single rewrite will handle.\n *\n * GritQL rewrites each match separately, so its cost grows with how many a\n * pattern matches — ~10ms an occurrence, which a hand-authored file with hundreds\n * of `RUN npm install` lines turns into minutes of an unattended `nx migrate`.\n * Past this the file is left alone and reported, since a wrong version the user\n * can see and fix beats an upgrade that appears to hang.\n */\nconst MAX_OCCURRENCES_PER_PIN = 100;\n\n/**\n * Apply the pins whose declared version this release moves forward.\n *\n * A single rewrite covers every occurrence of a pin in the file, so each pin is\n * applied once. Reports whether anything changed, and whether a pin was left\n * alone for exceeding {@link MAX_OCCURRENCES_PER_PIN}.\n */\nconst applyPins = async (\n tree: Tree,\n path: string,\n pins: readonly EmbeddedPin[],\n): Promise<{ changed: boolean; skipped: boolean }> => {\n // Read once and re-read only after a rewrite: a rewrite parses the whole file,\n // and there is a pin per owned package, so re-reading per pin would scale the\n // cost of a large file with the size of the owned set.\n let contents = tree.read(path, 'utf-8') ?? '';\n let changed = false;\n let skipped = false;\n\n for (const { pattern, vended, kind = 'version' } of pins) {\n const declared = declaredVersions(contents, pattern);\n if (declared.length === 0) {\n continue;\n }\n if (declared.length > MAX_OCCURRENCES_PER_PIN) {\n skipped = true;\n continue;\n }\n const outOfDate =\n kind === 'tag'\n ? (tag: string) => tag !== vended\n : (version: string) => isVendedUpgrade(vended, version);\n // A rewrite replaces every occurrence at once, so this must hold for all of\n // them — a pin already at or beyond the vended version is left as it is.\n if (!declared.every(outOfDate)) {\n continue;\n }\n if (await applyGritQL(tree, path, rewriteCapture(pattern, vended))) {\n contents = tree.read(path, 'utf-8') ?? '';\n changed = true;\n }\n }\n\n return { changed, skipped };\n};\n\n/**\n * The version this release vends for a package, or undefined for one it doesn't\n * vend at all.\n *\n * Ownership is applied by the caller, which only ever passes a name drawn from\n * the owned set — so a package the user pinned themselves never reaches here and\n * keeps the version they chose.\n */\nconst vendedTsVersion = (name: string): string | undefined =>\n TS_VERSIONS[name as keyof typeof TS_VERSIONS];\n\n/** `PY_VERSIONS` records the `==` operator; a pin holds the bare version. */\nconst vendedPyVersion = (name: string): string | undefined =>\n PY_VERSIONS[name as keyof typeof PY_VERSIONS]?.replace(/^==/, '');\n\n/**\n * The ways a generated `Dockerfile` pins a TypeScript package's version, as\n * regex fragments taking the escaped package name.\n *\n * The name is required to run to its delimiter, so a package whose name merely\n * ends with another's — `some-npm` against `npm` — cannot match, and an\n * installed version must start with a digit so a `@latest` style tag is left\n * alone.\n */\nconst DOCKERFILE_PIN_SHAPES: readonly ((name: string) => string)[] = [\n // Installed by the image build. `install` and its `i` alias are both used, as\n // are `-g` and several packages in one command, so the name only has to follow\n // an `npm` subcommand rather than sit right after it. The whitespace before it\n // is matched rather than asserted, since GritQL's regex engine has no\n // lookbehind — which also keeps `some-npm` from matching `npm`, and unlike a\n // `\\b` boundary still reaches a `@scope/name`.\n (name) =>\n `npm (?:install|i|add)[^\\\\n]*?\\\\s${name}@([0-9][^${VERSION_TERMINATORS}]*)`,\n // Held at a fixed version through an `npm pkg set` override, to clear a known\n // vulnerability in a transitive dependency.\n (name) => `overrides\\\\.${name}=([^${VERSION_TERMINATORS}]+)`,\n];\n\n/**\n * Every pin a generated `Dockerfile` may carry, for the packages owned where it\n * sits.\n *\n * Driven off the owned packages rather than a list of the ones that happen to be\n * pinned today: a pin added to a template in a later release is then covered\n * without this module changing, which is the whole point — the versions baked\n * into image builds are pinned precisely because they clear a known\n * vulnerability.\n *\n * A package the user pinned themselves is not owned, so it is never matched.\n */\nconst dockerfilePins = (owned: {\n readonly ts: ReadonlySet<string>;\n}): EmbeddedPin[] => {\n const pins: EmbeddedPin[] = [];\n\n for (const name of owned.ts) {\n const vended = vendedTsVersion(name);\n if (!vended) {\n continue;\n }\n for (const shape of DOCKERFILE_PIN_SHAPES) {\n pins.push({ pattern: shape(escapeRegExp(name)), vended });\n }\n }\n\n for (const image of Object.values(BASE_IMAGES)) {\n const [repository, tag] = splitImageReference(image);\n pins.push({\n // Only a `FROM` that is the whole instruction. A build stage names itself\n // — `FROM <repo>:24 AS builder` — and picks its tag for what that stage has\n // to run: the smithy builder needs curl and unzip, which the slim tag this\n // release vends for a runtime image does not carry. Rewriting it would\n // break the build, and the two share a repository, so the instruction\n // ending is what separates them.\n pattern: `FROM ${escapeRegExp(repository)}:([^\\\\s]+)\\\\n`,\n vended: tag,\n kind: 'tag',\n });\n }\n\n return pins;\n};\n\n/**\n * The repository and tag of a pinned image reference. The tag is the part after\n * the last `:`, which a registry port would otherwise be mistaken for — every\n * reference here carries one.\n */\nconst splitImageReference = (image: string): [string, string] => {\n const at = image.lastIndexOf(':');\n return [image.slice(0, at), image.slice(at + 1)];\n};\n\n/**\n * Whether a file is a Dockerfile: exactly `Dockerfile`, or the `<name>.Dockerfile`\n * form the smithy templates vend as `build.Dockerfile`.\n *\n * Deliberately exact rather than a prefix match, which would also claim a\n * `Dockerfile.bak` or a `Dockerfile.md` the user keeps beside a real one.\n */\nexport const isDockerfile = (filePath: string): boolean => {\n const name = filePath.split('/').pop() ?? '';\n return name === 'Dockerfile' || name.endsWith('.Dockerfile');\n};\n\n/**\n * Sync the pins in every generated Dockerfile.\n *\n * Ownership is resolved per file, so a Dockerfile is only rewritten for the\n * packages the project it belongs to owns — a sibling project owning `prisma`\n * does not license rewriting a `prisma` pin here.\n */\nconst syncDockerfiles = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => {\n const dockerfiles: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (isDockerfile(path)) {\n dockerfiles.push(path);\n }\n });\n\n const skipped: string[] = [];\n for (const path of dockerfiles) {\n const result = await applyPins(\n tree,\n path,\n dockerfilePins(ownedForFile(owned, path)),\n );\n if (result.skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/** The `uv run --with` pins to apply, for the Python packages owned where a file sits. */\nconst terraformScriptPins = (owned: {\n readonly py: ReadonlySet<string>;\n}): EmbeddedPin[] =>\n [...owned.py].flatMap((name) => {\n const vended = vendedPyVersion(name);\n return vended\n ? [\n {\n pattern: `--with ${escapeRegExp(name)}==([^${VERSION_TERMINATORS}]+)`,\n vended,\n },\n ]\n : [];\n });\n\n/**\n * Sync the Python pins a generated Terraform inline script runs through\n * `uv run --with <package>==<version>`.\n *\n * These are the plugin's own pins, in a file the Terraform provider sync already\n * visits but only reads `required_providers` from. Driven off the owned Python\n * packages, so a pin added to a template later is covered without a change here.\n *\n * Scoped per file like the Dockerfiles. The modules carrying these live in the\n * shared Terraform project, which no single generator owns — a file there belongs\n * to no project, so it takes the workspace-wide union, which is the set of\n * generators that legitimately write into it.\n */\nconst syncTerraformScriptPins = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => {\n const terraformFiles: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (path.endsWith('.tf')) {\n terraformFiles.push(path);\n }\n });\n\n const skipped: string[] = [];\n for (const path of terraformFiles) {\n const result = await applyPins(\n tree,\n path,\n terraformScriptPins(ownedForFile(owned, path)),\n );\n if (result.skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/**\n * The ways a `uvx` invocation pins a Python version: the tool it runs, and any\n * package it adds to that tool's environment.\n *\n * A command string is JSON here, so a quote ends a version too.\n */\nconst UVX_PIN_SHAPES: readonly ((name: string) => string)[] = [\n (name) => `uvx --from ${name}==`,\n (name) => `--with ${name}==`,\n];\n\n/**\n * The way a `project.json` target command vendors an npm package into a build\n * output, e.g. the AWS Distro for OpenTelemetry a code-packaged AgentCore\n * runtime carries.\n *\n * Reuses the `Dockerfile` install shape: both are shell `npm install` lines, and\n * a command string being JSON only narrows what can terminate the version — which\n * `VERSION_TERMINATORS` already covers. Driven off the owned set like every other\n * pin, so a package a later release vendors this way is covered without a change\n * here.\n */\nconst TARGET_NPM_INSTALL_SHAPE = (name: string): string =>\n `npm (?:install|i|add)[^\\\\n]*?\\\\s${name}@([0-9][^${VERSION_TERMINATORS}']*)`;\n\n/**\n * Sync the pinned tools a `project.json` target command runs: a container image,\n * and the Python versions a `uvx` invocation pins.\n *\n * Both are built into the command string rather than declared as a dependency, so\n * nothing else reaches them. The images are driven off `CONTAINER_REPOSITORIES`\n * and the Python versions off `PY_VERSIONS`, so a tool pinned in a target command\n * later is covered without a change here — the same property the Dockerfile and\n * Terraform paths get from the owned set.\n *\n * Unscoped, unlike the file-body pins: a `uvx` invocation installs nothing into\n * the project, so there is no dependency for a generator to own. A version is only\n * rewritten where this release vends that exact package at a higher one.\n */\nconst syncTargetToolPins = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => {\n const projectJsons: string[] = [];\n\n visitNotIgnoredFiles(tree, '.', (path) => {\n if (path.endsWith('project.json')) {\n projectJsons.push(path);\n }\n });\n\n const pins: EmbeddedPin[] = [\n ...Object.entries(CONTAINER_REPOSITORIES).map(([tool, repository]) => ({\n // A command string is JSON here, so a quote ends the reference too.\n pattern: `${escapeRegExp(repository)}:([^${VERSION_TERMINATORS}']+)`,\n vended: CONTAINER_VERSIONS[tool as keyof typeof CONTAINER_VERSIONS],\n })),\n // The Smithy CLI a Smithy project's compile target runs, and the `mise` that\n // resolves it. Neither is installed into the workspace — the target fetches\n // mise with `npx` — so this command is the only place either version sits.\n {\n pattern: `exec smithy@([^${VERSION_TERMINATORS}']+)`,\n vended: MISE_VERSIONS.smithy,\n },\n {\n pattern: `npx -y mise@([^${VERSION_TERMINATORS}']+)`,\n vended: TS_VERSIONS.mise,\n },\n ...Object.keys(PY_VERSIONS).flatMap((name) => {\n const vended = vendedPyVersion(name);\n return vended\n ? UVX_PIN_SHAPES.map((shape) => ({\n pattern: `${shape(escapeRegExp(name))}([^${VERSION_TERMINATORS}']+)`,\n vended,\n }))\n : [];\n }),\n ];\n\n const skipped: string[] = [];\n for (const path of projectJsons) {\n // The vendoring pins are ownership-scoped, unlike the tooling ones above: a\n // vendored package is declared by the generator that vendors it, so a\n // package the user pinned in a command of their own is never rewritten.\n const vendoringPins: EmbeddedPin[] = [];\n for (const name of ownedForFile(owned, path).ts) {\n const vended = vendedTsVersion(name);\n if (vended) {\n vendoringPins.push({\n pattern: TARGET_NPM_INSTALL_SHAPE(escapeRegExp(name)),\n vended,\n });\n }\n }\n\n if ((await applyPins(tree, path, [...pins, ...vendoringPins])).skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/**\n * Sync the Maven coordinates a generated `smithy-build.json` resolves.\n *\n * These are Java artifacts the Smithy CLI downloads, so they appear in no\n * manifest the dependency sync reads — this file is the only place they sit. Each\n * is matched by its `group:artifact` prefix so only the version is rewritten,\n * leaving any coordinate the user added alone.\n *\n * Scoped to the projects `smithy#project` generated: a `smithy-build.json` a user\n * wrote themselves keeps the versions they chose.\n */\nconst syncSmithyMavenPins = async (tree: Tree): Promise<string[]> => {\n const isGeneratedSmithyProject = (project: ProjectConfiguration): boolean =>\n (project.metadata as { generator?: string } | undefined)?.generator ===\n SMITHY_PROJECT_GENERATOR_INFO.id;\n\n const smithyBuilds: string[] = [];\n for (const [, project] of getProjects(tree)) {\n if (!isGeneratedSmithyProject(project)) {\n continue;\n }\n const path = joinPathFragments(project.root, 'smithy-build.json');\n if (tree.exists(path)) {\n smithyBuilds.push(path);\n }\n }\n\n const pins: EmbeddedPin[] = JAVA_ARTIFACTS.map((artifact) => ({\n // A coordinate is a JSON string here, so a quote ends the version.\n pattern: `${escapeRegExp(artifact)}:([^${VERSION_TERMINATORS}']+)`,\n vended: JAVA_VERSIONS[artifact],\n }));\n\n const skipped: string[] = [];\n for (const path of smithyBuilds) {\n if ((await applyPins(tree, path, pins)).skipped) {\n skipped.push(path);\n }\n }\n return skipped;\n};\n\n/**\n * Sync the vended versions baked into generated file bodies: `Dockerfile` pins,\n * the Python pins in Terraform inline scripts, the tooling `project.json` target\n * commands run, and the Maven coordinates a `smithy-build.json` resolves.\n *\n * Reports only the files left for the user: a pin that takes effect the next time\n * the thing holding it runs needs no follow-up, but one this skipped for holding\n * more occurrences than it will rewrite at once does.\n *\n * @returns paths whose pins were left as they were\n */\nexport const syncEmbeddedVersions = async (\n tree: Tree,\n owned: OwnedDependencies,\n): Promise<string[]> => [\n ...(await syncDockerfiles(tree, owned)),\n ...(await syncTerraformScriptPins(tree, owned)),\n ...(await syncTargetToolPins(tree, owned)),\n ...(await syncSmithyMavenPins(tree)),\n];\n"],"names":["getProjects","joinPathFragments","visitNotIgnoredFiles","SMITHY_PROJECT_GENERATOR_INFO","applyGritQL","BASE_IMAGES","CONTAINER_REPOSITORIES","CONTAINER_VERSIONS","JAVA_ARTIFACTS","JAVA_VERSIONS","MISE_VERSIONS","PY_VERSIONS","TS_VERSIONS","ownedForFile","isVendedUpgrade","escapeRegExp","value","replace","VERSION_TERMINATORS","rewriteCapture","pattern","vended","declaredVersions","contents","matches","matchAll","RegExp","flatMap","match","MAX_OCCURRENCES_PER_PIN","applyPins","tree","path","pins","read","changed","skipped","kind","declared","length","outOfDate","tag","version","every","vendedTsVersion","name","vendedPyVersion","DOCKERFILE_PIN_SHAPES","dockerfilePins","owned","ts","shape","push","image","Object","values","repository","splitImageReference","at","lastIndexOf","slice","isDockerfile","filePath","split","pop","endsWith","syncDockerfiles","dockerfiles","result","terraformScriptPins","py","syncTerraformScriptPins","terraformFiles","UVX_PIN_SHAPES","TARGET_NPM_INSTALL_SHAPE","syncTargetToolPins","projectJsons","entries","map","tool","smithy","mise","keys","vendoringPins","syncSmithyMavenPins","isGeneratedSmithyProject","project","metadata","generator","id","smithyBuilds","root","exists","artifact","syncEmbeddedVersions"],"mappings":"AAAA;;;CAGC,GAED,SACEA,WAAW,EACXC,iBAAiB,EACjBC,oBAAoB,QACf,aAAa;AACpB,SAASC,6BAA6B,QAAQ,oCAAoC;AAClF,SAASC,WAAW,QAAQ,YAAY;AACxC,SACEC,WAAW,EACXC,sBAAsB,EACtBC,kBAAkB,EAClBC,cAAc,EACdC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,WAAW,QACN,iBAAiB;AACxB,SAAiCC,YAAY,QAAQ,0BAA0B;AAC/E,SAASC,eAAe,QAAQ,sBAAsB;AAiCtD,qEAAqE,GACrE,MAAMC,eAAe,CAACC,QACpBA,MAAMC,OAAO,CAAC,uBAAuB;AAEvC;;;;;;CAMC,GACD,MAAMC,sBAAsB;AAE5B;;;;;;;CAOC,GACD,MAAMC,iBAAiB,CAACC,SAAiBC,SACvC,CAAC,WAAW,EAAED,QAAQ,2CAA2C,EAAEC,OAAO,IAAI,CAAC;AAEjF;;;;;CAKC,GACD,MAAMC,mBAAmB,CAACC,UAAkBH;IAC1C,MAAMI,UAAUD,SAASE,QAAQ,CAAC,IAAIC,OAAON,SAAS;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