@aws/nx-plugin 1.0.0-rc.58 → 1.0.0-rc.59
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/generators.json +17 -1
- package/migrations.json +12 -7
- package/package.json +1 -1
- package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +273 -0
- package/src/agentcore-gateway/agent-connection/generator.d.ts +19 -0
- package/src/agentcore-gateway/agent-connection/generator.js +90 -0
- package/src/agentcore-gateway/agent-connection/generator.js.map +1 -0
- package/src/agentcore-gateway/agent-connection/schema.d.js +6 -0
- package/src/agentcore-gateway/agent-connection/schema.d.js.map +1 -0
- package/src/agentcore-gateway/agent-connection/schema.d.ts +13 -0
- package/src/agentcore-gateway/agent-connection/schema.json +31 -0
- package/src/agentcore-gateway/attach-upstream.d.ts +16 -0
- package/src/agentcore-gateway/attach-upstream.js +32 -11
- package/src/agentcore-gateway/attach-upstream.js.map +1 -1
- package/src/agentcore-gateway/files/project/http/local-dev.ts.template +77 -0
- package/src/agentcore-gateway/generator.d.ts +1 -0
- package/src/agentcore-gateway/generator.js +22 -10
- package/src/agentcore-gateway/generator.js.map +1 -1
- package/src/agentcore-gateway/react-connection/__snapshots__/generator.spec.ts.snap +68 -0
- package/src/agentcore-gateway/react-connection/generator.d.ts +19 -0
- package/src/agentcore-gateway/react-connection/generator.js +119 -0
- package/src/agentcore-gateway/react-connection/generator.js.map +1 -0
- package/src/agentcore-gateway/react-connection/schema.d.js +6 -0
- package/src/agentcore-gateway/react-connection/schema.d.js.map +1 -0
- package/src/agentcore-gateway/react-connection/schema.d.ts +13 -0
- package/src/agentcore-gateway/react-connection/schema.json +31 -0
- package/src/agentcore-gateway/schema.d.js.map +1 -1
- package/src/agentcore-gateway/schema.d.ts +1 -1
- package/src/agentcore-gateway/schema.json +2 -2
- package/src/connection/agent-local-dev.d.ts +16 -0
- package/src/connection/agent-local-dev.js +44 -2
- package/src/connection/agent-local-dev.js.map +1 -1
- package/src/connection/gateway-runtime-config.d.ts +19 -0
- package/src/connection/gateway-runtime-config.js +47 -0
- package/src/connection/gateway-runtime-config.js.map +1 -0
- package/src/connection/generator.js +5 -0
- package/src/connection/generator.js.map +1 -1
- package/src/connection/scaffold-catalog.d.ts +107 -0
- package/src/connection/scaffold-catalog.js +140 -0
- package/src/connection/scaffold-catalog.js.map +1 -1
- package/src/connection/supported-connections.d.ts +9 -0
- package/src/connection/supported-connections.js +12 -0
- package/src/connection/supported-connections.js.map +1 -1
- package/src/internal/test-matrix/generator.js +39 -1
- package/src/internal/test-matrix/generator.js.map +1 -1
- package/src/migrations/latest/gateway-agent-targets/__snapshots__/migration.spec.ts.snap +223 -0
- package/src/migrations/latest/gateway-agent-targets/metadata.json +3 -0
- package/src/migrations/latest/gateway-agent-targets/migration.d.ts +6 -0
- package/src/migrations/latest/gateway-agent-targets/migration.js +217 -0
- package/src/migrations/latest/gateway-agent-targets/migration.js.map +1 -0
- package/src/migrations/latest/smithy-ssdk-bundle-pins/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.50/modernize-function-props-cast/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.50/restrict-cors-to-custom-domains/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.50/terraform-bootstrap-adopt-existing-bucket/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.52/user-identity-waf-allow-localhost-callback/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.54/order-access-log-delivery-after-bucket-policy/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.55/backfill-generator-metadata/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.56/dynamodb-local-remove-optimize-flag/metadata.json +3 -0
- package/src/migrations/v1.0.0-rc.57/ts-agent-session-management-support/metadata.json +3 -0
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +2 -0
- package/src/py/agent/react-connection/generator.d.ts +4 -1
- package/src/py/agent/react-connection/generator.js +35 -14
- package/src/py/agent/react-connection/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +4 -0
- package/src/ts/agent/react-connection/generator.d.ts +16 -1
- package/src/ts/agent/react-connection/generator.js +21 -8
- package/src/ts/agent/react-connection/generator.js.map +1 -1
- package/src/ts/nx-migration/generator.js +40 -27
- package/src/ts/nx-migration/generator.js.map +1 -1
- package/src/ts/react-website/agui/files/common/src/hooks/useAgui__agentNameClassName__.tsx.template +16 -0
- package/src/ts/react-website/agui/generator.d.ts +11 -0
- package/src/ts/react-website/agui/generator.js +11 -7
- package/src/ts/react-website/agui/generator.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +5 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -0
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +6 -4
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +119 -3
- package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +17 -0
- package/src/utils/config/utils.d.ts +5 -0
- package/src/utils/config/utils.js +7 -1
- package/src/utils/config/utils.js.map +1 -1
- package/src/utils/connection/open-api/files/components/__apiNameClassName__Provider.tsx.template +13 -2
- package/src/utils/connection/open-api/react.d.ts +10 -1
- package/src/utils/connection/open-api/react.js +3 -2
- package/src/utils/connection/open-api/react.js.map +1 -1
- package/src/utils/migration-manifest.d.ts +58 -0
- package/src/utils/migration-manifest.js +76 -0
- package/src/utils/migration-manifest.js.map +1 -0
- package/src/utils/migration-versions.d.ts +2 -0
- package/src/utils/migration-versions.js.map +1 -1
- package/src/utils/version-upgrade-migration/register.d.ts +4 -2
- package/src/utils/version-upgrade-migration/register.js +13 -13
- package/src/utils/version-upgrade-migration/register.js.map +1 -1
- /package/src/agentcore-gateway/files/project/{local-dev.ts.template → mcp/local-dev.ts.template} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/utils/connection/open-api/react.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTargetToLocalDev } from '../../../connection/local-dev';\nimport runtimeConfigGenerator from '../../../ts/react-website/runtime-config/generator';\nimport { addSingleImport, applyGritQL } from '../../ast';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../declared-dependencies';\nimport { addDependenciesToPackageJson } from '../../dependencies';\nimport { updateGitIgnore } from '../../git';\nimport { kebabCase, toClassName } from '../../names';\nimport { sortObjectKeys } from '../../object';\nimport { type ITsDepVersion, withVersions } from '../../versions';\n\n/** Dependencies a caller must declare to add an OpenAPI React client. */\nexport const OPEN_API_REACT_DEPENDENCIES = [\n { name: 'oidc-client-ts' },\n { name: 'react-oidc-context' },\n { name: '@aws-sdk/credential-provider-cognito-identity' },\n { name: 'aws4fetch' },\n { name: '@tanstack/react-query' },\n { name: '@tanstack/react-query-devtools' },\n { name: '@smithy/types' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface AddOpenApiReactClientOptions {\n /**\n * The react project to add the openapi client and build targets to\n */\n frontendProjectConfig: ProjectConfiguration;\n /**\n * The backend project which serves the api\n */\n backendProjectConfig: ProjectConfiguration;\n /**\n * The project which builds/generates the openapi spec\n */\n specBuildProject: ProjectConfiguration;\n /**\n * Name of the api\n */\n apiName: string;\n /**\n * Path to the openapi spec from the workspace root\n */\n specPath: string;\n /**\n * Fully qualified target name for the target that builds/generates the openapi spec\n */\n specBuildTargetName: string;\n /**\n * Authentication method\n */\n auth: 'iam' | 'cognito' | 'custom';\n /**\n * Port on which the backend project's local server listens\n */\n port: number;\n /**\n * When true, the generated provider reads from runtimeConfig.agentRuntimes\n * and converts Bedrock AgentCore Runtime ARNs to HTTP URLs.\n * When false (default), reads from runtimeConfig.apis directly.\n */\n isAgentRuntime?: boolean;\n /**\n * When true, skips the dev target setup. Use this when the caller\n * handles dev target configuration separately (e.g. agent connections\n * that use a component-specific dev target instead of 'serve').\n */\n skipLocalDev?: boolean;\n}\n\n/**\n * Adds an OpenAPI React client to the frontend project along with supporting build targets\n */\nexport const addOpenApiReactClient = async <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n {\n apiName,\n frontendProjectConfig,\n backendProjectConfig,\n specBuildProject,\n specPath,\n specBuildTargetName,\n auth,\n port,\n isAgentRuntime = false,\n skipLocalDev = false,\n }: AddOpenApiReactClientOptions,\n declaration: D & MustDeclare<typeof OPEN_API_REACT_DEPENDENCIES, D>,\n) => {\n const clientGenTarget = `generate:${kebabCase(apiName)}-client`;\n const clientGenWatchTarget = `watch-${clientGenTarget}`;\n\n const generatedClientDir = joinPathFragments('generated', kebabCase(apiName));\n const generatedClientDirFromRoot = joinPathFragments(\n frontendProjectConfig.sourceRoot,\n generatedClientDir,\n );\n\n // Add TypeScript client generation to Frontend project.json\n updateProjectConfiguration(tree, frontendProjectConfig.name, {\n ...frontendProjectConfig,\n targets: sortObjectKeys({\n ...frontendProjectConfig.targets,\n // Generate should run before compile and bundle as the client is created as part of the website src\n ...Object.fromEntries(\n ['compile', 'bundle'].map((target) => [\n target,\n {\n ...frontendProjectConfig.targets?.[target],\n dependsOn: [\n ...(\n frontendProjectConfig.targets?.[target]?.dependsOn ?? []\n ).filter((t) => t !== clientGenTarget),\n clientGenTarget,\n ],\n },\n ]),\n ),\n [clientGenTarget]: {\n cache: true,\n executor: 'nx:run-commands',\n inputs: [\n {\n dependentTasksOutputFiles: '**/*.json',\n },\n ],\n outputs: [\n joinPathFragments('{workspaceRoot}', generatedClientDirFromRoot),\n ],\n options: {\n commands: [\n `nx g @aws/nx-plugin:open-api#ts-hooks --openApiSpecPath=\"${specPath}\" --outputPath=\"${generatedClientDirFromRoot}\" --no-interactive`,\n ],\n },\n dependsOn: [specBuildTargetName],\n },\n // Watch target for regenerating the client\n [clientGenWatchTarget]: {\n executor: 'nx:run-commands',\n options: {\n commands: [\n `nx watch --projects=${specBuildProject.name} --includeDependencies -- nx run ${frontendProjectConfig.name}:\"${clientGenTarget}\"`,\n ],\n },\n continuous: true,\n },\n }),\n });\n\n const relativeSrcDir = frontendProjectConfig.sourceRoot.slice(\n frontendProjectConfig.root.length + 1,\n );\n\n // Ignore the generated client by default\n // Users can safely remove the entry from the .gitignore if they prefer to check it in\n updateGitIgnore(tree, frontendProjectConfig.root, (patterns) => [\n ...patterns,\n joinPathFragments(relativeSrcDir, generatedClientDir),\n ]);\n\n // Ensure that the frontend has runtime config as we'll use the url for creating the client\n await runtimeConfigGenerator(tree, {\n project: frontendProjectConfig.name,\n });\n\n // Add sigv4 fetch\n if (auth === 'iam') {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, '../../files/website/hooks/sigv4'),\n joinPathFragments(frontendProjectConfig.sourceRoot, 'hooks'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Generate the tanstack query provider if it does not exist already\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '../../files/website/components/tanstack-query',\n ),\n joinPathFragments(frontendProjectConfig.sourceRoot, 'components'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n const apiNameClassName = toClassName(apiName);\n\n // Add a hook to instantiate the client\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n frontendProjectConfig.sourceRoot,\n {\n auth,\n apiName,\n apiNameClassName,\n generatedClientDir,\n isAgentRuntime,\n },\n );\n\n // Update main.tsx to add required providers\n const mainTsxPath = joinPathFragments(\n frontendProjectConfig.sourceRoot,\n 'main.tsx',\n );\n\n // Add the query client provider if it doesn't exist already\n await addSingleImport(\n tree,\n mainTsxPath,\n 'QueryClientProvider',\n './components/QueryClientProvider',\n );\n await applyGritQL(\n tree,\n mainTsxPath,\n '`<App />` => `<QueryClientProvider><App /></QueryClientProvider>` where { $program <: not contains `<QueryClientProvider>$_</QueryClientProvider>` }',\n );\n\n // Add the api provider if it does not exist\n const providerName = `${apiNameClassName}Provider`;\n await addSingleImport(\n tree,\n mainTsxPath,\n providerName,\n `./components/${providerName}`,\n );\n await applyGritQL(\n tree,\n mainTsxPath,\n `\\`<App />\\` => \\`<${providerName}><App /></${providerName}>\\` where { $program <: not contains \\`<${providerName}>$_</${providerName}>\\` }`,\n );\n\n // Update the dev target on the website to use our local server.\n // Callers that handle the dev target separately (e.g. agent connections) set skipLocalDev.\n if (!skipLocalDev) {\n await addTargetToLocalDev(\n tree,\n frontendProjectConfig.name,\n backendProjectConfig.name,\n {\n url: `http://localhost:${port}/`,\n apiName,\n // Additionally add a dependency on the generate watch command to ensure that local\n // API changes that affect the client are also reloaded.\n // We include a dependency on the generate target as watch ONLY triggers on a change,\n // and we need to ensure the client is generated the first time if not already present.\n additionalDependencyTargets: [clientGenTarget, clientGenWatchTarget],\n },\n );\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions(\n forDependencies<typeof OPEN_API_REACT_DEPENDENCIES>(declaration),\n [\n ...((auth === 'iam'\n ? [\n 'oidc-client-ts',\n 'react-oidc-context',\n '@aws-sdk/credential-provider-cognito-identity',\n 'aws4fetch',\n ]\n : []) as any),\n ...((auth === 'cognito' ? ['react-oidc-context'] : []) as any),\n '@tanstack/react-query',\n '@tanstack/react-query-devtools',\n ],\n ),\n withVersions(\n forDependencies<typeof OPEN_API_REACT_DEPENDENCIES>(declaration),\n ['@smithy/types'],\n ),\n joinPathFragments(frontendProjectConfig.root, 'package.json'),\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTargetToLocalDev","runtimeConfigGenerator","addSingleImport","applyGritQL","forDependencies","addDependenciesToPackageJson","updateGitIgnore","kebabCase","toClassName","sortObjectKeys","withVersions","OPEN_API_REACT_DEPENDENCIES","name","addOpenApiReactClient","tree","apiName","frontendProjectConfig","backendProjectConfig","specBuildProject","specPath","specBuildTargetName","auth","port","isAgentRuntime","skipLocalDev","declaration","clientGenTarget","clientGenWatchTarget","generatedClientDir","generatedClientDirFromRoot","sourceRoot","targets","Object","fromEntries","map","target","dependsOn","filter","t","cache","executor","inputs","dependentTasksOutputFiles","outputs","options","commands","continuous","relativeSrcDir","slice","root","length","patterns","project","dirname","overwriteStrategy","KeepExisting","apiNameClassName","mainTsxPath","providerName","url","additionalDependencyTargets"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,mBAAmB,QAAQ,mCAAgC;AACpE,OAAOC,4BAA4B,wDAAqD;AACxF,SAASC,eAAe,EAAEC,WAAW,QAAQ,eAAY;AACzD,SAEEC,eAAe,QAEV,iCAA8B;AACrC,SAASC,4BAA4B,QAAQ,wBAAqB;AAClE,SAASC,eAAe,QAAQ,eAAY;AAC5C,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAc;AACrD,SAASC,cAAc,QAAQ,kBAAe;AAC9C,SAA6BC,YAAY,QAAQ,oBAAiB;AAElE,uEAAuE,GACvE,OAAO,MAAMC,8BAA8B;IACzC;QAAEC,MAAM;IAAiB;IACzB;QAAEA,MAAM;IAAqB;IAC7B;QAAEA,MAAM;IAAgD;IACxD;QAAEA,MAAM;IAAY;IACpB;QAAEA,MAAM;IAAwB;IAChC;QAAEA,MAAM;IAAiC;IACzC;QAAEA,MAAM;IAAgB;CACzB,CAAuD;AAiDxD;;CAEC,GACD,OAAO,MAAMC,wBAAwB,OAGnCC,MACA,EACEC,OAAO,EACPC,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,QA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MvD,YACJW,MACA2C,aACA,CAAC,kBAAkB,EAAEC,aAAa,UAAU,EAAEA,aAAa,wCAAwC,EAAEA,aAAa,KAAK,EAAEA,aAAa,KAAK,CAAC;IAG9I,gEAAgE;IAChE,2FAA2F;IAC3F,IAAI,CAAClC,cAAc;QACjB,MAAMxB,oBACJc,MACAE,sBAAsBJ,IAAI,EAC1BK,qBAAqBL,IAAI,EACzB;YACE+C,KAAK,CAAC,iBAAiB,EAAErC,KAAK,CAAC,CAAC;YAChCP;YACA,mFAAmF;YACnF,wDAAwD;YACxD,qFAAqF;YACrF,uFAAuF;YACvF6C,6BAA6B;gBAAClC;gBAAiBC;aAAqB;QACtE;IAEJ;IAEAtB,6BACES,MACAJ,aACEN,gBAAoDqB,cACpD;WACOJ,SAAS,QACV;YACE;YACA;YACA;YACA;SACD,GACD,EAAE;WACDA,SAAS,YAAY;YAAC;SAAqB,GAAG,EAAE;QACrD;QACA;KACD,GAEHX,aACEN,gBAAoDqB,cACpD;QAAC;KAAgB,GAEnB5B,kBAAkBmB,sBAAsBiC,IAAI,EAAE;AAElD,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/utils/connection/open-api/react.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTargetToLocalDev } from '../../../connection/local-dev';\nimport runtimeConfigGenerator from '../../../ts/react-website/runtime-config/generator';\nimport { addSingleImport, applyGritQL } from '../../ast';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../declared-dependencies';\nimport { addDependenciesToPackageJson } from '../../dependencies';\nimport { updateGitIgnore } from '../../git';\nimport { kebabCase, toClassName } from '../../names';\nimport { sortObjectKeys } from '../../object';\nimport { type ITsDepVersion, withVersions } from '../../versions';\n\n/** Dependencies a caller must declare to add an OpenAPI React client. */\nexport const OPEN_API_REACT_DEPENDENCIES = [\n { name: 'oidc-client-ts' },\n { name: 'react-oidc-context' },\n { name: '@aws-sdk/credential-provider-cognito-identity' },\n { name: 'aws4fetch' },\n { name: '@tanstack/react-query' },\n { name: '@tanstack/react-query-devtools' },\n { name: '@smithy/types' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface AddOpenApiReactClientOptions {\n /**\n * The react project to add the openapi client and build targets to\n */\n frontendProjectConfig: ProjectConfiguration;\n /**\n * The backend project which serves the api\n */\n backendProjectConfig: ProjectConfiguration;\n /**\n * The project which builds/generates the openapi spec\n */\n specBuildProject: ProjectConfiguration;\n /**\n * Name of the api\n */\n apiName: string;\n /**\n * Path to the openapi spec from the workspace root\n */\n specPath: string;\n /**\n * Fully qualified target name for the target that builds/generates the openapi spec\n */\n specBuildTargetName: string;\n /**\n * Authentication method\n */\n auth: 'iam' | 'cognito' | 'custom';\n /**\n * Port on which the backend project's local server listens\n */\n port: number;\n /**\n * When true, the generated provider reads from runtimeConfig.agentRuntimes\n * and converts Bedrock AgentCore Runtime ARNs to HTTP URLs.\n * When false (default), reads from runtimeConfig.apis directly.\n */\n isAgentRuntime?: boolean;\n /**\n * When set, the generated provider reads the gateway's URL from\n * runtimeConfig.gateways and routes to the agent via the gateway's\n * path-based `/<targetName>` route instead of invoking the runtime directly.\n */\n gatewayRoute?: {\n gatewayClassName: string;\n targetName: string;\n };\n /**\n * When true, skips the dev target setup. Use this when the caller\n * handles dev target configuration separately (e.g. agent connections\n * that use a component-specific dev target instead of 'serve').\n */\n skipLocalDev?: boolean;\n}\n\n/**\n * Adds an OpenAPI React client to the frontend project along with supporting build targets\n */\nexport const addOpenApiReactClient = async <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n {\n apiName,\n frontendProjectConfig,\n backendProjectConfig,\n specBuildProject,\n specPath,\n specBuildTargetName,\n auth,\n port,\n isAgentRuntime = false,\n gatewayRoute,\n skipLocalDev = false,\n }: AddOpenApiReactClientOptions,\n declaration: D & MustDeclare<typeof OPEN_API_REACT_DEPENDENCIES, D>,\n) => {\n const clientGenTarget = `generate:${kebabCase(apiName)}-client`;\n const clientGenWatchTarget = `watch-${clientGenTarget}`;\n\n const generatedClientDir = joinPathFragments('generated', kebabCase(apiName));\n const generatedClientDirFromRoot = joinPathFragments(\n frontendProjectConfig.sourceRoot,\n generatedClientDir,\n );\n\n // Add TypeScript client generation to Frontend project.json\n updateProjectConfiguration(tree, frontendProjectConfig.name, {\n ...frontendProjectConfig,\n targets: sortObjectKeys({\n ...frontendProjectConfig.targets,\n // Generate should run before compile and bundle as the client is created as part of the website src\n ...Object.fromEntries(\n ['compile', 'bundle'].map((target) => [\n target,\n {\n ...frontendProjectConfig.targets?.[target],\n dependsOn: [\n ...(\n frontendProjectConfig.targets?.[target]?.dependsOn ?? []\n ).filter((t) => t !== clientGenTarget),\n clientGenTarget,\n ],\n },\n ]),\n ),\n [clientGenTarget]: {\n cache: true,\n executor: 'nx:run-commands',\n inputs: [\n {\n dependentTasksOutputFiles: '**/*.json',\n },\n ],\n outputs: [\n joinPathFragments('{workspaceRoot}', generatedClientDirFromRoot),\n ],\n options: {\n commands: [\n `nx g @aws/nx-plugin:open-api#ts-hooks --openApiSpecPath=\"${specPath}\" --outputPath=\"${generatedClientDirFromRoot}\" --no-interactive`,\n ],\n },\n dependsOn: [specBuildTargetName],\n },\n // Watch target for regenerating the client\n [clientGenWatchTarget]: {\n executor: 'nx:run-commands',\n options: {\n commands: [\n `nx watch --projects=${specBuildProject.name} --includeDependencies -- nx run ${frontendProjectConfig.name}:\"${clientGenTarget}\"`,\n ],\n },\n continuous: true,\n },\n }),\n });\n\n const relativeSrcDir = frontendProjectConfig.sourceRoot.slice(\n frontendProjectConfig.root.length + 1,\n );\n\n // Ignore the generated client by default\n // Users can safely remove the entry from the .gitignore if they prefer to check it in\n updateGitIgnore(tree, frontendProjectConfig.root, (patterns) => [\n ...patterns,\n joinPathFragments(relativeSrcDir, generatedClientDir),\n ]);\n\n // Ensure that the frontend has runtime config as we'll use the url for creating the client\n await runtimeConfigGenerator(tree, {\n project: frontendProjectConfig.name,\n });\n\n // Add sigv4 fetch\n if (auth === 'iam') {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, '../../files/website/hooks/sigv4'),\n joinPathFragments(frontendProjectConfig.sourceRoot, 'hooks'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Generate the tanstack query provider if it does not exist already\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '../../files/website/components/tanstack-query',\n ),\n joinPathFragments(frontendProjectConfig.sourceRoot, 'components'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n const apiNameClassName = toClassName(apiName);\n\n // Add a hook to instantiate the client\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n frontendProjectConfig.sourceRoot,\n {\n auth,\n apiName,\n apiNameClassName,\n generatedClientDir,\n isAgentRuntime,\n gatewayRoute,\n },\n );\n\n // Update main.tsx to add required providers\n const mainTsxPath = joinPathFragments(\n frontendProjectConfig.sourceRoot,\n 'main.tsx',\n );\n\n // Add the query client provider if it doesn't exist already\n await addSingleImport(\n tree,\n mainTsxPath,\n 'QueryClientProvider',\n './components/QueryClientProvider',\n );\n await applyGritQL(\n tree,\n mainTsxPath,\n '`<App />` => `<QueryClientProvider><App /></QueryClientProvider>` where { $program <: not contains `<QueryClientProvider>$_</QueryClientProvider>` }',\n );\n\n // Add the api provider if it does not exist\n const providerName = `${apiNameClassName}Provider`;\n await addSingleImport(\n tree,\n mainTsxPath,\n providerName,\n `./components/${providerName}`,\n );\n await applyGritQL(\n tree,\n mainTsxPath,\n `\\`<App />\\` => \\`<${providerName}><App /></${providerName}>\\` where { $program <: not contains \\`<${providerName}>$_</${providerName}>\\` }`,\n );\n\n // Update the dev target on the website to use our local server.\n // Callers that handle the dev target separately (e.g. agent connections) set skipLocalDev.\n if (!skipLocalDev) {\n await addTargetToLocalDev(\n tree,\n frontendProjectConfig.name,\n backendProjectConfig.name,\n {\n url: `http://localhost:${port}/`,\n apiName,\n // Additionally add a dependency on the generate watch command to ensure that local\n // API changes that affect the client are also reloaded.\n // We include a dependency on the generate target as watch ONLY triggers on a change,\n // and we need to ensure the client is generated the first time if not already present.\n additionalDependencyTargets: [clientGenTarget, clientGenWatchTarget],\n },\n );\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions(\n forDependencies<typeof OPEN_API_REACT_DEPENDENCIES>(declaration),\n [\n ...((auth === 'iam'\n ? [\n 'oidc-client-ts',\n 'react-oidc-context',\n '@aws-sdk/credential-provider-cognito-identity',\n 'aws4fetch',\n ]\n : []) as any),\n ...((auth === 'cognito' ? ['react-oidc-context'] : []) as any),\n '@tanstack/react-query',\n '@tanstack/react-query-devtools',\n ],\n ),\n withVersions(\n forDependencies<typeof OPEN_API_REACT_DEPENDENCIES>(declaration),\n ['@smithy/types'],\n ),\n joinPathFragments(frontendProjectConfig.root, 'package.json'),\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTargetToLocalDev","runtimeConfigGenerator","addSingleImport","applyGritQL","forDependencies","addDependenciesToPackageJson","updateGitIgnore","kebabCase","toClassName","sortObjectKeys","withVersions","OPEN_API_REACT_DEPENDENCIES","name","addOpenApiReactClient","tree","apiName","frontendProjectConfig","backendProjectConfig","specBuildProject","specPath","specBuildTargetName","auth","port","isAgentRuntime","gatewayRoute","skipLocalDev","declaration","clientGenTarget","clientGenWatchTarget","generatedClientDir","generatedClientDirFromRoot","sourceRoot","targets","Object","fromEntries","map","target","dependsOn","filter","t","cache","executor","inputs","dependentTasksOutputFiles","outputs","options","commands","continuous","relativeSrcDir","slice","root","length","patterns","project","dirname","overwriteStrategy","KeepExisting","apiNameClassName","mainTsxPath","providerName","url","additionalDependencyTargets"],"mappings":"AAAA;;;CAGC,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BACES,MACAJ,aACEN,gBAAoDsB,cACpD;WACOL,SAAS,QACV;YACE;YACA;YACA;YACA;SACD,GACD,EAAE;WACDA,SAAS,YAAY;YAAC;SAAqB,GAAG,EAAE;QACrD;QACA;KACD,GAEHX,aACEN,gBAAoDsB,cACpD;QAAC;KAAgB,GAEnB7B,kBAAkBmB,sBAAsBkC,IAAI,EAAE;AAElD,EAAE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { MigrationsJson } from './migration-versions';
|
|
6
|
+
/**
|
|
7
|
+
* `migrations.json` is assembled from the plugin's source rather than committed,
|
|
8
|
+
* so two PRs each adding a migration touch disjoint files and never conflict on
|
|
9
|
+
* a shared manifest.
|
|
10
|
+
*
|
|
11
|
+
* The pieces it is assembled from:
|
|
12
|
+
* - one folder per migration under `src/migrations/<dir>/<name>/`, where `<dir>`
|
|
13
|
+
* is `latest` until a release claims it and `v<version>` after — the folder
|
|
14
|
+
* carries a `metadata.json` (its description) beside the code, and its files
|
|
15
|
+
* discriminate the kind: a `migration.ts` makes it deterministic, a `prompt.md`
|
|
16
|
+
* agentic, both hybrid;
|
|
17
|
+
* - `packageJsonUpdates.json`, the nx bumps the weekly update maintains, kept in
|
|
18
|
+
* its own file so that churn never shares an edit with a migration PR;
|
|
19
|
+
* - the version sync entry, a fixed `everyMigration` codemod that runs on every
|
|
20
|
+
* upgrade and so has no folder.
|
|
21
|
+
*
|
|
22
|
+
* The assembled manifest is unversioned — release-time stamping resolves versions
|
|
23
|
+
* (see `migration-versions.ts`).
|
|
24
|
+
*/
|
|
25
|
+
/** JSON schema the manifest declares, matching what nx expects. */
|
|
26
|
+
export declare const MIGRATIONS_JSON_SCHEMA = "http://json-schema.org/schema";
|
|
27
|
+
/** Key the version sync migration is registered under. */
|
|
28
|
+
export declare const SYNC_VENDED_MIGRATION_KEY = "sync-vended-versions";
|
|
29
|
+
/**
|
|
30
|
+
* The version sync migration entry. Committed as code rather than a folder: it
|
|
31
|
+
* carries no release-specific registration and must run on every upgrade, so it
|
|
32
|
+
* is fixed and can't conflict.
|
|
33
|
+
*/
|
|
34
|
+
export declare const syncVendedMigrationEntry: () => NonNullable<MigrationsJson["generators"]>[string];
|
|
35
|
+
/** A migration folder discovered under `src/migrations`. */
|
|
36
|
+
export interface DiscoveredMigration {
|
|
37
|
+
/** Folder grouping the migration by release: `latest` or `v<version>`. */
|
|
38
|
+
dir: string;
|
|
39
|
+
/** Migration folder name. */
|
|
40
|
+
name: string;
|
|
41
|
+
/** Description read from the folder's `metadata.json`. */
|
|
42
|
+
description: string;
|
|
43
|
+
/** A `migration.ts` is present, so the migration has a codemod. */
|
|
44
|
+
hasImplementation: boolean;
|
|
45
|
+
/** A `prompt.md` is present, so the migration hands off to an agent. */
|
|
46
|
+
hasPrompt: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Assemble the plugin's `migrations.json` from its source pieces: the discovered
|
|
50
|
+
* migration folders, the version sync entry, and the nx `packageJsonUpdates`.
|
|
51
|
+
*
|
|
52
|
+
* Deterministic — keys are sorted — so regenerating always yields the same file.
|
|
53
|
+
*
|
|
54
|
+
* @param pluginName the plugin package name the manifest is for
|
|
55
|
+
* @param migrations migration folders discovered under `src/migrations`
|
|
56
|
+
* @param packageJsonUpdates parsed `packageJsonUpdates.json`, if present
|
|
57
|
+
*/
|
|
58
|
+
export declare const assembleMigrations: (pluginName: string, migrations: DiscoveredMigration[], packageJsonUpdates?: MigrationsJson["packageJsonUpdates"]) => MigrationsJson;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { isValidVersion, LATEST_MIGRATIONS_DIR, migrationKey } from "./migration-versions.js";
|
|
5
|
+
import { sortObjectKeys } from "./object.js";
|
|
6
|
+
/**
|
|
7
|
+
* `migrations.json` is assembled from the plugin's source rather than committed,
|
|
8
|
+
* so two PRs each adding a migration touch disjoint files and never conflict on
|
|
9
|
+
* a shared manifest.
|
|
10
|
+
*
|
|
11
|
+
* The pieces it is assembled from:
|
|
12
|
+
* - one folder per migration under `src/migrations/<dir>/<name>/`, where `<dir>`
|
|
13
|
+
* is `latest` until a release claims it and `v<version>` after — the folder
|
|
14
|
+
* carries a `metadata.json` (its description) beside the code, and its files
|
|
15
|
+
* discriminate the kind: a `migration.ts` makes it deterministic, a `prompt.md`
|
|
16
|
+
* agentic, both hybrid;
|
|
17
|
+
* - `packageJsonUpdates.json`, the nx bumps the weekly update maintains, kept in
|
|
18
|
+
* its own file so that churn never shares an edit with a migration PR;
|
|
19
|
+
* - the version sync entry, a fixed `everyMigration` codemod that runs on every
|
|
20
|
+
* upgrade and so has no folder.
|
|
21
|
+
*
|
|
22
|
+
* The assembled manifest is unversioned — release-time stamping resolves versions
|
|
23
|
+
* (see `migration-versions.ts`).
|
|
24
|
+
*/ /** JSON schema the manifest declares, matching what nx expects. */ export const MIGRATIONS_JSON_SCHEMA = 'http://json-schema.org/schema';
|
|
25
|
+
/** Key the version sync migration is registered under. */ export const SYNC_VENDED_MIGRATION_KEY = 'sync-vended-versions';
|
|
26
|
+
/**
|
|
27
|
+
* The version sync migration entry. Committed as code rather than a folder: it
|
|
28
|
+
* carries no release-specific registration and must run on every upgrade, so it
|
|
29
|
+
* is fixed and can't conflict.
|
|
30
|
+
*/ export const syncVendedMigrationEntry = ()=>({
|
|
31
|
+
description: 'Sync vended dependency versions and the tracked plugin version to those vended by this release',
|
|
32
|
+
implementation: './src/utils/version-upgrade-migration/migration',
|
|
33
|
+
everyMigration: true
|
|
34
|
+
});
|
|
35
|
+
/** Registration for a single discovered migration folder. */ const migrationEntry = (migration)=>{
|
|
36
|
+
const path = `./src/migrations/${migration.dir}/${migration.name}`;
|
|
37
|
+
return {
|
|
38
|
+
// A migration in a `v<version>` folder has already been claimed by that
|
|
39
|
+
// release; its version is the folder. One in `latest` is left for stamping.
|
|
40
|
+
...migration.dir !== LATEST_MIGRATIONS_DIR && isValidVersion(migration.dir.replace(/^v/, '')) ? {
|
|
41
|
+
version: migration.dir.replace(/^v/, '')
|
|
42
|
+
} : {},
|
|
43
|
+
description: migration.description,
|
|
44
|
+
...migration.hasImplementation ? {
|
|
45
|
+
implementation: `${path}/migration`
|
|
46
|
+
} : {},
|
|
47
|
+
...migration.hasPrompt ? {
|
|
48
|
+
prompt: `${path}/prompt.md`
|
|
49
|
+
} : {}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Assemble the plugin's `migrations.json` from its source pieces: the discovered
|
|
54
|
+
* migration folders, the version sync entry, and the nx `packageJsonUpdates`.
|
|
55
|
+
*
|
|
56
|
+
* Deterministic — keys are sorted — so regenerating always yields the same file.
|
|
57
|
+
*
|
|
58
|
+
* @param pluginName the plugin package name the manifest is for
|
|
59
|
+
* @param migrations migration folders discovered under `src/migrations`
|
|
60
|
+
* @param packageJsonUpdates parsed `packageJsonUpdates.json`, if present
|
|
61
|
+
*/ export const assembleMigrations = (pluginName, migrations, packageJsonUpdates)=>({
|
|
62
|
+
$schema: MIGRATIONS_JSON_SCHEMA,
|
|
63
|
+
name: pluginName,
|
|
64
|
+
generators: sortObjectKeys({
|
|
65
|
+
[SYNC_VENDED_MIGRATION_KEY]: syncVendedMigrationEntry(),
|
|
66
|
+
...Object.fromEntries(migrations.map((migration)=>[
|
|
67
|
+
migrationKey(migration.dir, migration.name),
|
|
68
|
+
migrationEntry(migration)
|
|
69
|
+
]))
|
|
70
|
+
}),
|
|
71
|
+
...packageJsonUpdates && Object.keys(packageJsonUpdates).length > 0 ? {
|
|
72
|
+
packageJsonUpdates
|
|
73
|
+
} : {}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=migration-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/migration-manifest.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { MigrationsJson } from './migration-versions';\nimport {\n isValidVersion,\n LATEST_MIGRATIONS_DIR,\n migrationKey,\n} from './migration-versions';\nimport { sortObjectKeys } from './object';\n\n/**\n * `migrations.json` is assembled from the plugin's source rather than committed,\n * so two PRs each adding a migration touch disjoint files and never conflict on\n * a shared manifest.\n *\n * The pieces it is assembled from:\n * - one folder per migration under `src/migrations/<dir>/<name>/`, where `<dir>`\n * is `latest` until a release claims it and `v<version>` after — the folder\n * carries a `metadata.json` (its description) beside the code, and its files\n * discriminate the kind: a `migration.ts` makes it deterministic, a `prompt.md`\n * agentic, both hybrid;\n * - `packageJsonUpdates.json`, the nx bumps the weekly update maintains, kept in\n * its own file so that churn never shares an edit with a migration PR;\n * - the version sync entry, a fixed `everyMigration` codemod that runs on every\n * upgrade and so has no folder.\n *\n * The assembled manifest is unversioned — release-time stamping resolves versions\n * (see `migration-versions.ts`).\n */\n\n/** JSON schema the manifest declares, matching what nx expects. */\nexport const MIGRATIONS_JSON_SCHEMA = 'http://json-schema.org/schema';\n\n/** Key the version sync migration is registered under. */\nexport const SYNC_VENDED_MIGRATION_KEY = 'sync-vended-versions';\n\n/**\n * The version sync migration entry. Committed as code rather than a folder: it\n * carries no release-specific registration and must run on every upgrade, so it\n * is fixed and can't conflict.\n */\nexport const syncVendedMigrationEntry = (): NonNullable<\n MigrationsJson['generators']\n>[string] => ({\n description:\n 'Sync vended dependency versions and the tracked plugin version to those vended by this release',\n implementation: './src/utils/version-upgrade-migration/migration',\n everyMigration: true,\n});\n\n/** A migration folder discovered under `src/migrations`. */\nexport interface DiscoveredMigration {\n /** Folder grouping the migration by release: `latest` or `v<version>`. */\n dir: string;\n /** Migration folder name. */\n name: string;\n /** Description read from the folder's `metadata.json`. */\n description: string;\n /** A `migration.ts` is present, so the migration has a codemod. */\n hasImplementation: boolean;\n /** A `prompt.md` is present, so the migration hands off to an agent. */\n hasPrompt: boolean;\n}\n\n/** Registration for a single discovered migration folder. */\nconst migrationEntry = (\n migration: DiscoveredMigration,\n): NonNullable<MigrationsJson['generators']>[string] => {\n const path = `./src/migrations/${migration.dir}/${migration.name}`;\n return {\n // A migration in a `v<version>` folder has already been claimed by that\n // release; its version is the folder. One in `latest` is left for stamping.\n ...(migration.dir !== LATEST_MIGRATIONS_DIR &&\n isValidVersion(migration.dir.replace(/^v/, ''))\n ? { version: migration.dir.replace(/^v/, '') }\n : {}),\n description: migration.description,\n ...(migration.hasImplementation\n ? { implementation: `${path}/migration` }\n : {}),\n ...(migration.hasPrompt ? { prompt: `${path}/prompt.md` } : {}),\n };\n};\n\n/**\n * Assemble the plugin's `migrations.json` from its source pieces: the discovered\n * migration folders, the version sync entry, and the nx `packageJsonUpdates`.\n *\n * Deterministic — keys are sorted — so regenerating always yields the same file.\n *\n * @param pluginName the plugin package name the manifest is for\n * @param migrations migration folders discovered under `src/migrations`\n * @param packageJsonUpdates parsed `packageJsonUpdates.json`, if present\n */\nexport const assembleMigrations = (\n pluginName: string,\n migrations: DiscoveredMigration[],\n packageJsonUpdates?: MigrationsJson['packageJsonUpdates'],\n): MigrationsJson => ({\n $schema: MIGRATIONS_JSON_SCHEMA,\n name: pluginName,\n generators: sortObjectKeys({\n [SYNC_VENDED_MIGRATION_KEY]: syncVendedMigrationEntry(),\n ...Object.fromEntries(\n migrations.map((migration) => [\n migrationKey(migration.dir, migration.name),\n migrationEntry(migration),\n ]),\n ),\n }),\n ...(packageJsonUpdates && Object.keys(packageJsonUpdates).length > 0\n ? { packageJsonUpdates }\n : {}),\n});\n"],"names":["isValidVersion","LATEST_MIGRATIONS_DIR","migrationKey","sortObjectKeys","MIGRATIONS_JSON_SCHEMA","SYNC_VENDED_MIGRATION_KEY","syncVendedMigrationEntry","description","implementation","everyMigration","migrationEntry","migration","path","dir","name","replace","version","hasImplementation","hasPrompt","prompt","assembleMigrations","pluginName","migrations","packageJsonUpdates","$schema","generators","Object","fromEntries","map","keys","length"],"mappings":"AAAA;;;CAGC,GAED,SACEA,cAAc,EACdC,qBAAqB,EACrBC,YAAY,QACP,0BAAuB;AAC9B,SAASC,cAAc,QAAQ,cAAW;AAE1C;;;;;;;;;;;;;;;;;;CAkBC,GAED,iEAAiE,GACjE,OAAO,MAAMC,yBAAyB,gCAAgC;AAEtE,wDAAwD,GACxD,OAAO,MAAMC,4BAA4B,uBAAuB;AAEhE;;;;CAIC,GACD,OAAO,MAAMC,2BAA2B,IAE1B,CAAA;QACZC,aACE;QACFC,gBAAgB;QAChBC,gBAAgB;IAClB,CAAA,EAAG;AAgBH,2DAA2D,GAC3D,MAAMC,iBAAiB,CACrBC;IAEA,MAAMC,OAAO,CAAC,iBAAiB,EAAED,UAAUE,GAAG,CAAC,CAAC,EAAEF,UAAUG,IAAI,EAAE;IAClE,OAAO;QACL,wEAAwE;QACxE,4EAA4E;QAC5E,GAAIH,UAAUE,GAAG,KAAKZ,yBACtBD,eAAeW,UAAUE,GAAG,CAACE,OAAO,CAAC,MAAM,OACvC;YAAEC,SAASL,UAAUE,GAAG,CAACE,OAAO,CAAC,MAAM;QAAI,IAC3C,CAAC,CAAC;QACNR,aAAaI,UAAUJ,WAAW;QAClC,GAAII,UAAUM,iBAAiB,GAC3B;YAAET,gBAAgB,GAAGI,KAAK,UAAU,CAAC;QAAC,IACtC,CAAC,CAAC;QACN,GAAID,UAAUO,SAAS,GAAG;YAAEC,QAAQ,GAAGP,KAAK,UAAU,CAAC;QAAC,IAAI,CAAC,CAAC;IAChE;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,MAAMQ,qBAAqB,CAChCC,YACAC,YACAC,qBACoB,CAAA;QACpBC,SAASpB;QACTU,MAAMO;QACNI,YAAYtB,eAAe;YACzB,CAACE,0BAA0B,EAAEC;YAC7B,GAAGoB,OAAOC,WAAW,CACnBL,WAAWM,GAAG,CAAC,CAACjB,YAAc;oBAC5BT,aAAaS,UAAUE,GAAG,EAAEF,UAAUG,IAAI;oBAC1CJ,eAAeC;iBAChB,EACF;QACH;QACA,GAAIY,sBAAsBG,OAAOG,IAAI,CAACN,oBAAoBO,MAAM,GAAG,IAC/D;YAAEP;QAAmB,IACrB,CAAC,CAAC;IACR,CAAA,EAAG"}
|
|
@@ -27,6 +27,8 @@ import { compare } from 'semver';
|
|
|
27
27
|
* re-stamped with each pending version, so it runs on every upgrade.
|
|
28
28
|
*/
|
|
29
29
|
export interface MigrationsJson {
|
|
30
|
+
$schema?: string;
|
|
31
|
+
name?: string;
|
|
30
32
|
generators?: Record<string, {
|
|
31
33
|
version?: string;
|
|
32
34
|
everyMigration?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/migration-versions.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { compare, valid } from 'semver';\n\n/**\n * Version stamping for migrations.\n *\n * A new migration is committed with no `version` — releases are calculated from\n * conventional commits and written only to `dist/` and a git tag, so versions\n * reach the published `migrations.json` two ways:\n *\n * - At release time (`scripts/stamp-migrations.ts`) entries still missing a\n * version are stamped into the compiled `migrations.json`: an already shipped\n * one gets the earliest release tag registering it, and a net-new one gets the\n * version the release is about to publish, which the release job passes in\n * after `nx release version` writes it to the dist manifests.\n * - The weekly `update-versions` PR backfills the version of the release that\n * shipped each migration, moving and re-keying it accordingly\n * (`scripts/backfill-migration-versions.ts`), so source converges on the\n * versions of everything already released. `packageJsonUpdates` entries are\n * dated in place there too, since their keys never change.\n *\n * A version already in source always wins, so backfilled entries are stable.\n *\n * An entry marked `everyMigration: true` is never backfilled or pinned, and is\n * re-stamped with each pending version, so it runs on every upgrade.\n */\n\nexport interface MigrationsJson {\n generators?: Record<\n string,\n { version?: string; everyMigration?: boolean } & Record<string, unknown>\n >;\n /**\n * Declarative dependency bumps `nx migrate` applies to the root manifest.\n * Keyed by what the bump targets rather than the release that ships it, so an\n * entry is unique from the moment it is written and one release's bump can sit\n * beside the next; nx itself gates on the entry's `version`.\n */\n packageJsonUpdates?: Record<\n string,\n { version: string } & Record<string, unknown>\n >;\n}\n\n/** Ascending semver comparator for `Array.prototype.sort`. */\nexport const compareVersions = compare;\n\n/** Whether a string is an exact semver version. */\nexport const isValidVersion = (version: string): boolean =>\n valid(version) !== null;\n\n/**\n * Map of entry key -> version of the earliest release that registers it, across\n * both `generators` and `packageJsonUpdates`. Resolved only for the entries still\n * missing a version (one already recorded in source wins, so its history doesn't\n * need reading). An entry that hasn't been released is absent.\n *\n * Walks releases newest first and stops as soon as every entry is resolved: an\n * entry that has disappeared from a release's `migrations.json` was first\n * registered by the release after it, which is the one that shipped it.\n *\n * Both sections resolve the same way and share the walk, so the release doesn't\n * read tag history twice. Keys can't collide: a migration is keyed by its own\n * name, an nx bump by the nx version it moves to.\n *\n * @param migrations parsed source migrations.json\n * @param versions released versions in descending semver order\n * @param readReleasedMigrations reads the `migrations.json` published by a given\n * version, or undefined if it predates the manifest\n */\nexport const readShippedMigrationVersions = (\n migrations: MigrationsJson,\n versions: string[],\n readReleasedMigrations: (version: string) => MigrationsJson | undefined,\n): Record<string, string> => {\n const shippedVersions: Record<string, string> = {};\n // A `packageJsonUpdates` entry records `latest` rather than omitting its\n // version, since nx requires the field.\n let unresolved = [\n ...Object.entries(migrations.generators ?? {})\n .filter(([, entry]) => !entry.version)\n .map(([key]) => key),\n ...Object.entries(migrations.packageJsonUpdates ?? {})\n .filter(([, entry]) => entry.version === LATEST_MIGRATIONS_DIR)\n .map(([key]) => key),\n ];\n\n for (const version of versions) {\n if (unresolved.length === 0) {\n break;\n }\n const released = readReleasedMigrations(version);\n const registered = new Set([\n ...Object.keys(released?.generators ?? {}),\n ...Object.keys(released?.packageJsonUpdates ?? {}),\n ]);\n // Entries gone at this release keep the version recorded from the release\n // after it (if any) and stop being looked up.\n unresolved = unresolved.filter((key) => registered.has(key));\n for (const key of unresolved) {\n shippedVersions[key] = version;\n }\n }\n\n return shippedVersions;\n};\n\n/**\n * Return a copy of the migrations collection with a `version` stamped onto\n * every generator entry, preserving any already present, and the pending version\n * recorded on any `packageJsonUpdates` entry still holding `latest`.\n *\n * @param migrations parsed migrations.json to stamp\n * @param shippedVersions migration key -> version of the earliest release\n * tag that registers it (absent for migrations that haven't shipped)\n * @param pendingVersion version the release is about to publish, stamped onto\n * unshipped migrations so their version is one that really shipped\n */\nexport const stampMigrationVersions = (\n migrations: MigrationsJson,\n shippedVersions: Record<string, string>,\n pendingVersion: string,\n): MigrationsJson => ({\n ...migrations,\n generators: Object.fromEntries(\n // `nx migrate` sorts the run ascending by version and preserves the\n // manifest's order among equal versions, so emitting the every-migration\n // entries last is what makes them run after the release's own migrations.\n Object.entries(migrations.generators ?? {})\n .sort(\n ([, a], [, b]) =>\n Number(a.everyMigration ?? false) - Number(b.everyMigration ?? false),\n )\n .map(([name, entry]) => {\n // Source-only marker, stripped from what nx reads.\n const { everyMigration, version: sourceVersion, ...published } = entry;\n // Overrides any source version so it stays ahead of what is installed.\n const version = everyMigration\n ? pendingVersion\n : (sourceVersion ?? shippedVersions[name] ?? pendingVersion);\n return [name, { version, ...published }];\n }),\n ),\n ...(migrations.packageJsonUpdates && {\n packageJsonUpdates: stampPackageJsonUpdates(\n migrations.packageJsonUpdates,\n pendingVersion,\n ),\n }),\n});\n\n/**\n * Version any `packageJsonUpdates` entry still holding `latest` with the release\n * about to publish it, so the nx bump ships under a version `nx migrate` gates on.\n */\nconst stampPackageJsonUpdates = (\n packageJsonUpdates: NonNullable<MigrationsJson['packageJsonUpdates']>,\n pendingVersion: string,\n): NonNullable<MigrationsJson['packageJsonUpdates']> =>\n resolvePackageJsonUpdateVersions(packageJsonUpdates, () => pendingVersion);\n\n/** Directory a newly scaffolded migration lands in, before a release claims it. */\nexport const LATEST_MIGRATIONS_DIR = 'latest';\n\n/** Directory holding the migrations shipped by a given release. */\nexport const versionMigrationsDir = (version: string) => `v${version}`;\n\n/**\n * Key a migration is registered under in `migrations.json`. Prefixed with its\n * directory so reusing a name in a later release can't silently overwrite the\n * one that already shipped.\n */\nexport const migrationKey = (dir: string, name: string) => `${dir}-${name}`;\n\nconst LATEST_KEY_PREFIX = `${LATEST_MIGRATIONS_DIR}-`;\n\n/** A migration directory move the caller needs to make on disk. */\nexport interface MigrationDirMove {\n name: string;\n version: string;\n from: string;\n to: string;\n}\n\n/**\n * Record the release that shipped each migration on entries without a version,\n * re-keying them and re-pointing their paths at that release's folder, and\n * return the collection alongside the keys that changed and the directory moves\n * to make on disk.\n *\n * Unlike `stampMigrationVersions` this only records already-released versions,\n * leaving the release to decide what a net-new migration gets.\n *\n * @param migrations parsed migrations.json to backfill\n * @param shippedVersions migration key -> version of the earliest release tag\n * that registers it (absent for migrations that haven't shipped)\n */\nexport const backfillMigrationVersions = (\n migrations: MigrationsJson,\n shippedVersions: Record<string, string>,\n): {\n migrations: MigrationsJson;\n backfilled: string[];\n moves: MigrationDirMove[];\n} => {\n const generators: NonNullable<MigrationsJson['generators']> = {};\n const backfilled: string[] = [];\n const moves: MigrationDirMove[] = [];\n // Reported alongside the migrations so the update's PR says an nx bump was\n // dated, and so the caller knows there is something to commit.\n const backfilledUpdates = Object.entries(migrations.packageJsonUpdates ?? {})\n .filter(\n ([key, entry]) =>\n entry.version === LATEST_MIGRATIONS_DIR && shippedVersions[key],\n )\n .map(([key]) => key);\n\n for (const [key, entry] of Object.entries(migrations.generators ?? {})) {\n const version = shippedVersions[key];\n // Pinning an every-migration entry would stop it running on later upgrades.\n if (entry.version || !version || entry.everyMigration) {\n generators[key] = entry;\n continue;\n }\n\n const name = key.startsWith(LATEST_KEY_PREFIX)\n ? key.slice(LATEST_KEY_PREFIX.length)\n : key;\n const versionDir = versionMigrationsDir(version);\n const latestSegment = `/${LATEST_MIGRATIONS_DIR}/${name}/`;\n const versionSegment = `/${versionDir}/${name}/`;\n\n // Re-point each path field at the version folder, recording the move the\n // caller needs to make on disk the first time one is found.\n const repointed: Record<string, unknown> = {};\n let moved = false;\n for (const [field, value] of Object.entries(entry)) {\n if (typeof value !== 'string' || !value.includes(latestSegment)) {\n repointed[field] = value;\n continue;\n }\n repointed[field] = value.replace(latestSegment, versionSegment);\n if (!moved) {\n moved = true;\n const dir = value.slice(0, value.indexOf(latestSegment));\n moves.push({\n name,\n version,\n from: `${dir}${latestSegment}`.replace(/^\\.\\/|\\/$/g, ''),\n to: `${dir}${versionSegment}`.replace(/^\\.\\/|\\/$/g, ''),\n });\n }\n }\n\n generators[migrationKey(versionDir, name)] = { version, ...repointed };\n backfilled.push(key);\n }\n\n return {\n migrations: {\n ...migrations,\n generators,\n ...(migrations.packageJsonUpdates && {\n packageJsonUpdates: resolvePackageJsonUpdateVersions(\n migrations.packageJsonUpdates,\n (key) => shippedVersions[key],\n ),\n }),\n },\n backfilled: [...backfilled, ...backfilledUpdates],\n moves,\n };\n};\n\n/**\n * Record the version each `packageJsonUpdates` entry ships under, for those still\n * holding `latest`.\n *\n * The key already identifies the entry — an nx bump is named for the nx version\n * it moves to — so only the `version` field changes. Nothing is re-keyed, which\n * is what lets one release's bump sit alongside the next without either being\n * overwritten before it ships.\n */\nconst resolvePackageJsonUpdateVersions = (\n packageJsonUpdates: NonNullable<MigrationsJson['packageJsonUpdates']>,\n resolve: (key: string) => string | undefined,\n): NonNullable<MigrationsJson['packageJsonUpdates']> =>\n Object.fromEntries(\n Object.entries(packageJsonUpdates).map(([key, entry]) => {\n const version =\n entry.version === LATEST_MIGRATIONS_DIR ? resolve(key) : undefined;\n return [key, version ? { ...entry, version } : entry];\n }),\n );\n"],"names":["compare","valid","compareVersions","isValidVersion","version","readShippedMigrationVersions","migrations","versions","readReleasedMigrations","shippedVersions","unresolved","Object","entries","generators","filter","entry","map","key","packageJsonUpdates","LATEST_MIGRATIONS_DIR","length","released","registered","Set","keys","has","stampMigrationVersions","pendingVersion","fromEntries","sort","a","b","Number","everyMigration","name","sourceVersion","published","stampPackageJsonUpdates","resolvePackageJsonUpdateVersions","versionMigrationsDir","migrationKey","dir","LATEST_KEY_PREFIX","backfillMigrationVersions","backfilled","moves","backfilledUpdates","startsWith","slice","versionDir","latestSegment","versionSegment","repointed","moved","field","value","includes","replace","indexOf","push","from","to","resolve","undefined"],"mappings":"AAAA;;;CAGC,GACD,SAASA,OAAO,EAAEC,KAAK,QAAQ,SAAS;AA2CxC,4DAA4D,GAC5D,OAAO,MAAMC,kBAAkBF,QAAQ;AAEvC,iDAAiD,GACjD,OAAO,MAAMG,iBAAiB,CAACC,UAC7BH,MAAMG,aAAa,KAAK;AAE1B;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,MAAMC,+BAA+B,CAC1CC,YACAC,UACAC;IAEA,MAAMC,kBAA0C,CAAC;IACjD,yEAAyE;IACzE,wCAAwC;IACxC,IAAIC,aAAa;WACZC,OAAOC,OAAO,CAACN,WAAWO,UAAU,IAAI,CAAC,GACzCC,MAAM,CAAC,CAAC,GAAGC,MAAM,GAAK,CAACA,MAAMX,OAAO,EACpCY,GAAG,CAAC,CAAC,CAACC,IAAI,GAAKA;WACfN,OAAOC,OAAO,CAACN,WAAWY,kBAAkB,IAAI,CAAC,GACjDJ,MAAM,CAAC,CAAC,GAAGC,MAAM,GAAKA,MAAMX,OAAO,KAAKe,uBACxCH,GAAG,CAAC,CAAC,CAACC,IAAI,GAAKA;KACnB;IAED,KAAK,MAAMb,WAAWG,SAAU;QAC9B,IAAIG,WAAWU,MAAM,KAAK,GAAG;YAC3B;QACF;QACA,MAAMC,WAAWb,uBAAuBJ;QACxC,MAAMkB,aAAa,IAAIC,IAAI;eACtBZ,OAAOa,IAAI,CAACH,UAAUR,cAAc,CAAC;eACrCF,OAAOa,IAAI,CAACH,UAAUH,sBAAsB,CAAC;SACjD;QACD,0EAA0E;QAC1E,8CA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UAAU,YAAY,CAACA,MAAMC,QAAQ,CAACN,gBAAgB;gBAC/DE,SAAS,CAACE,MAAM,GAAGC;gBACnB;YACF;YACAH,SAAS,CAACE,MAAM,GAAGC,MAAME,OAAO,CAACP,eAAeC;YAChD,IAAI,CAACE,OAAO;gBACVA,QAAQ;gBACR,MAAMZ,MAAMc,MAAMP,KAAK,CAAC,GAAGO,MAAMG,OAAO,CAACR;gBACzCL,MAAMc,IAAI,CAAC;oBACTzB;oBACA9B;oBACAwD,MAAM,GAAGnB,MAAMS,eAAe,CAACO,OAAO,CAAC,cAAc;oBACrDI,IAAI,GAAGpB,MAAMU,gBAAgB,CAACM,OAAO,CAAC,cAAc;gBACtD;YACF;QACF;QAEA5C,UAAU,CAAC2B,aAAaS,YAAYf,MAAM,GAAG;YAAE9B;YAAS,GAAGgD,SAAS;QAAC;QACrER,WAAWe,IAAI,CAAC1C;IAClB;IAEA,OAAO;QACLX,YAAY;YACV,GAAGA,UAAU;YACbO;YACA,GAAIP,WAAWY,kBAAkB,IAAI;gBACnCA,oBAAoBoB,iCAClBhC,WAAWY,kBAAkB,EAC7B,CAACD,MAAQR,eAAe,CAACQ,IAAI;YAEjC,CAAC;QACH;QACA2B,YAAY;eAAIA;eAAeE;SAAkB;QACjDD;IACF;AACF,EAAE;AAEF;;;;;;;;CAQC,GACD,MAAMP,mCAAmC,CACvCpB,oBACA4C,UAEAnD,OAAOiB,WAAW,CAChBjB,OAAOC,OAAO,CAACM,oBAAoBF,GAAG,CAAC,CAAC,CAACC,KAAKF,MAAM;QAClD,MAAMX,UACJW,MAAMX,OAAO,KAAKe,wBAAwB2C,QAAQ7C,OAAO8C;QAC3D,OAAO;YAAC9C;YAAKb,UAAU;gBAAE,GAAGW,KAAK;gBAAEX;YAAQ,IAAIW;SAAM;IACvD"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/migration-versions.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { compare, valid } from 'semver';\n\n/**\n * Version stamping for migrations.\n *\n * A new migration is committed with no `version` — releases are calculated from\n * conventional commits and written only to `dist/` and a git tag, so versions\n * reach the published `migrations.json` two ways:\n *\n * - At release time (`scripts/stamp-migrations.ts`) entries still missing a\n * version are stamped into the compiled `migrations.json`: an already shipped\n * one gets the earliest release tag registering it, and a net-new one gets the\n * version the release is about to publish, which the release job passes in\n * after `nx release version` writes it to the dist manifests.\n * - The weekly `update-versions` PR backfills the version of the release that\n * shipped each migration, moving and re-keying it accordingly\n * (`scripts/backfill-migration-versions.ts`), so source converges on the\n * versions of everything already released. `packageJsonUpdates` entries are\n * dated in place there too, since their keys never change.\n *\n * A version already in source always wins, so backfilled entries are stable.\n *\n * An entry marked `everyMigration: true` is never backfilled or pinned, and is\n * re-stamped with each pending version, so it runs on every upgrade.\n */\n\nexport interface MigrationsJson {\n $schema?: string;\n name?: string;\n generators?: Record<\n string,\n { version?: string; everyMigration?: boolean } & Record<string, unknown>\n >;\n /**\n * Declarative dependency bumps `nx migrate` applies to the root manifest.\n * Keyed by what the bump targets rather than the release that ships it, so an\n * entry is unique from the moment it is written and one release's bump can sit\n * beside the next; nx itself gates on the entry's `version`.\n */\n packageJsonUpdates?: Record<\n string,\n { version: string } & Record<string, unknown>\n >;\n}\n\n/** Ascending semver comparator for `Array.prototype.sort`. */\nexport const compareVersions = compare;\n\n/** Whether a string is an exact semver version. */\nexport const isValidVersion = (version: string): boolean =>\n valid(version) !== null;\n\n/**\n * Map of entry key -> version of the earliest release that registers it, across\n * both `generators` and `packageJsonUpdates`. Resolved only for the entries still\n * missing a version (one already recorded in source wins, so its history doesn't\n * need reading). An entry that hasn't been released is absent.\n *\n * Walks releases newest first and stops as soon as every entry is resolved: an\n * entry that has disappeared from a release's `migrations.json` was first\n * registered by the release after it, which is the one that shipped it.\n *\n * Both sections resolve the same way and share the walk, so the release doesn't\n * read tag history twice. Keys can't collide: a migration is keyed by its own\n * name, an nx bump by the nx version it moves to.\n *\n * @param migrations parsed source migrations.json\n * @param versions released versions in descending semver order\n * @param readReleasedMigrations reads the `migrations.json` published by a given\n * version, or undefined if it predates the manifest\n */\nexport const readShippedMigrationVersions = (\n migrations: MigrationsJson,\n versions: string[],\n readReleasedMigrations: (version: string) => MigrationsJson | undefined,\n): Record<string, string> => {\n const shippedVersions: Record<string, string> = {};\n // A `packageJsonUpdates` entry records `latest` rather than omitting its\n // version, since nx requires the field.\n let unresolved = [\n ...Object.entries(migrations.generators ?? {})\n .filter(([, entry]) => !entry.version)\n .map(([key]) => key),\n ...Object.entries(migrations.packageJsonUpdates ?? {})\n .filter(([, entry]) => entry.version === LATEST_MIGRATIONS_DIR)\n .map(([key]) => key),\n ];\n\n for (const version of versions) {\n if (unresolved.length === 0) {\n break;\n }\n const released = readReleasedMigrations(version);\n const registered = new Set([\n ...Object.keys(released?.generators ?? {}),\n ...Object.keys(released?.packageJsonUpdates ?? {}),\n ]);\n // Entries gone at this release keep the version recorded from the release\n // after it (if any) and stop being looked up.\n unresolved = unresolved.filter((key) => registered.has(key));\n for (const key of unresolved) {\n shippedVersions[key] = version;\n }\n }\n\n return shippedVersions;\n};\n\n/**\n * Return a copy of the migrations collection with a `version` stamped onto\n * every generator entry, preserving any already present, and the pending version\n * recorded on any `packageJsonUpdates` entry still holding `latest`.\n *\n * @param migrations parsed migrations.json to stamp\n * @param shippedVersions migration key -> version of the earliest release\n * tag that registers it (absent for migrations that haven't shipped)\n * @param pendingVersion version the release is about to publish, stamped onto\n * unshipped migrations so their version is one that really shipped\n */\nexport const stampMigrationVersions = (\n migrations: MigrationsJson,\n shippedVersions: Record<string, string>,\n pendingVersion: string,\n): MigrationsJson => ({\n ...migrations,\n generators: Object.fromEntries(\n // `nx migrate` sorts the run ascending by version and preserves the\n // manifest's order among equal versions, so emitting the every-migration\n // entries last is what makes them run after the release's own migrations.\n Object.entries(migrations.generators ?? {})\n .sort(\n ([, a], [, b]) =>\n Number(a.everyMigration ?? false) - Number(b.everyMigration ?? false),\n )\n .map(([name, entry]) => {\n // Source-only marker, stripped from what nx reads.\n const { everyMigration, version: sourceVersion, ...published } = entry;\n // Overrides any source version so it stays ahead of what is installed.\n const version = everyMigration\n ? pendingVersion\n : (sourceVersion ?? shippedVersions[name] ?? pendingVersion);\n return [name, { version, ...published }];\n }),\n ),\n ...(migrations.packageJsonUpdates && {\n packageJsonUpdates: stampPackageJsonUpdates(\n migrations.packageJsonUpdates,\n pendingVersion,\n ),\n }),\n});\n\n/**\n * Version any `packageJsonUpdates` entry still holding `latest` with the release\n * about to publish it, so the nx bump ships under a version `nx migrate` gates on.\n */\nconst stampPackageJsonUpdates = (\n packageJsonUpdates: NonNullable<MigrationsJson['packageJsonUpdates']>,\n pendingVersion: string,\n): NonNullable<MigrationsJson['packageJsonUpdates']> =>\n resolvePackageJsonUpdateVersions(packageJsonUpdates, () => pendingVersion);\n\n/** Directory a newly scaffolded migration lands in, before a release claims it. */\nexport const LATEST_MIGRATIONS_DIR = 'latest';\n\n/** Directory holding the migrations shipped by a given release. */\nexport const versionMigrationsDir = (version: string) => `v${version}`;\n\n/**\n * Key a migration is registered under in `migrations.json`. Prefixed with its\n * directory so reusing a name in a later release can't silently overwrite the\n * one that already shipped.\n */\nexport const migrationKey = (dir: string, name: string) => `${dir}-${name}`;\n\nconst LATEST_KEY_PREFIX = `${LATEST_MIGRATIONS_DIR}-`;\n\n/** A migration directory move the caller needs to make on disk. */\nexport interface MigrationDirMove {\n name: string;\n version: string;\n from: string;\n to: string;\n}\n\n/**\n * Record the release that shipped each migration on entries without a version,\n * re-keying them and re-pointing their paths at that release's folder, and\n * return the collection alongside the keys that changed and the directory moves\n * to make on disk.\n *\n * Unlike `stampMigrationVersions` this only records already-released versions,\n * leaving the release to decide what a net-new migration gets.\n *\n * @param migrations parsed migrations.json to backfill\n * @param shippedVersions migration key -> version of the earliest release tag\n * that registers it (absent for migrations that haven't shipped)\n */\nexport const backfillMigrationVersions = (\n migrations: MigrationsJson,\n shippedVersions: Record<string, string>,\n): {\n migrations: MigrationsJson;\n backfilled: string[];\n moves: MigrationDirMove[];\n} => {\n const generators: NonNullable<MigrationsJson['generators']> = {};\n const backfilled: string[] = [];\n const moves: MigrationDirMove[] = [];\n // Reported alongside the migrations so the update's PR says an nx bump was\n // dated, and so the caller knows there is something to commit.\n const backfilledUpdates = Object.entries(migrations.packageJsonUpdates ?? {})\n .filter(\n ([key, entry]) =>\n entry.version === LATEST_MIGRATIONS_DIR && shippedVersions[key],\n )\n .map(([key]) => key);\n\n for (const [key, entry] of Object.entries(migrations.generators ?? {})) {\n const version = shippedVersions[key];\n // Pinning an every-migration entry would stop it running on later upgrades.\n if (entry.version || !version || entry.everyMigration) {\n generators[key] = entry;\n continue;\n }\n\n const name = key.startsWith(LATEST_KEY_PREFIX)\n ? key.slice(LATEST_KEY_PREFIX.length)\n : key;\n const versionDir = versionMigrationsDir(version);\n const latestSegment = `/${LATEST_MIGRATIONS_DIR}/${name}/`;\n const versionSegment = `/${versionDir}/${name}/`;\n\n // Re-point each path field at the version folder, recording the move the\n // caller needs to make on disk the first time one is found.\n const repointed: Record<string, unknown> = {};\n let moved = false;\n for (const [field, value] of Object.entries(entry)) {\n if (typeof value !== 'string' || !value.includes(latestSegment)) {\n repointed[field] = value;\n continue;\n }\n repointed[field] = value.replace(latestSegment, versionSegment);\n if (!moved) {\n moved = true;\n const dir = value.slice(0, value.indexOf(latestSegment));\n moves.push({\n name,\n version,\n from: `${dir}${latestSegment}`.replace(/^\\.\\/|\\/$/g, ''),\n to: `${dir}${versionSegment}`.replace(/^\\.\\/|\\/$/g, ''),\n });\n }\n }\n\n generators[migrationKey(versionDir, name)] = { version, ...repointed };\n backfilled.push(key);\n }\n\n return {\n migrations: {\n ...migrations,\n generators,\n ...(migrations.packageJsonUpdates && {\n packageJsonUpdates: resolvePackageJsonUpdateVersions(\n migrations.packageJsonUpdates,\n (key) => shippedVersions[key],\n ),\n }),\n },\n backfilled: [...backfilled, ...backfilledUpdates],\n moves,\n };\n};\n\n/**\n * Record the version each `packageJsonUpdates` entry ships under, for those still\n * holding `latest`.\n *\n * The key already identifies the entry — an nx bump is named for the nx version\n * it moves to — so only the `version` field changes. Nothing is re-keyed, which\n * is what lets one release's bump sit alongside the next without either being\n * overwritten before it ships.\n */\nconst resolvePackageJsonUpdateVersions = (\n packageJsonUpdates: NonNullable<MigrationsJson['packageJsonUpdates']>,\n resolve: (key: string) => string | undefined,\n): NonNullable<MigrationsJson['packageJsonUpdates']> =>\n Object.fromEntries(\n Object.entries(packageJsonUpdates).map(([key, entry]) => {\n const version =\n entry.version === LATEST_MIGRATIONS_DIR ? resolve(key) : undefined;\n return [key, version ? { ...entry, version } : entry];\n }),\n );\n"],"names":["compare","valid","compareVersions","isValidVersion","version","readShippedMigrationVersions","migrations","versions","readReleasedMigrations","shippedVersions","unresolved","Object","entries","generators","filter","entry","map","key","packageJsonUpdates","LATEST_MIGRATIONS_DIR","length","released","registered","Set","keys","has","stampMigrationVersions","pendingVersion","fromEntries","sort","a","b","Number","everyMigration","name","sourceVersion","published","stampPackageJsonUpdates","resolvePackageJsonUpdateVersions","versionMigrationsDir","migrationKey","dir","LATEST_KEY_PREFIX","backfillMigrationVersions","backfilled","moves","backfilledUpdates","startsWith","slice","versionDir","latestSegment","versionSegment","repointed","moved","field","value","includes","replace","indexOf","push","from","to","resolve","undefined"],"mappings":"AAAA;;;CAGC,GACD,SAASA,OAAO,EAAEC,KAAK,QAAQ,SAAS;AA6CxC,4DAA4D,GAC5D,OAAO,MAAMC,kBAAkBF,QAAQ;AAEvC,iDAAiD,GACjD,OAAO,MAAMG,iBAAiB,CAACC,UAC7BH,MAAMG,aAAa,KAAK;AAE1B;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,MAAMC,+BAA+B,CAC1CC,YACAC,UACAC;IAEA,MAAMC,kBAA0C,CAAC;IACjD,yEAAyE;IACzE,wCAAwC;IACxC,IAAIC,aAAa;WACZC,OAAO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gBACnCA,oBAAoBoB,iCAClBhC,WAAWY,kBAAkB,EAC7B,CAACD,MAAQR,eAAe,CAACQ,IAAI;YAEjC,CAAC;QACH;QACA2B,YAAY;eAAIA;eAAeE;SAAkB;QACjDD;IACF;AACF,EAAE;AAEF;;;;;;;;CAQC,GACD,MAAMP,mCAAmC,CACvCpB,oBACA4C,UAEAnD,OAAOiB,WAAW,CAChBjB,OAAOC,OAAO,CAACM,oBAAoBF,GAAG,CAAC,CAAC,CAACC,KAAKF,MAAM;QAClD,MAAMX,UACJW,MAAMX,OAAO,KAAKe,wBAAwB2C,QAAQ7C,OAAO8C;QAC3D,OAAO;YAAC9C;YAAKb,UAAU;gBAAE,GAAGW,KAAK;gBAAEX;YAAQ,IAAIW;SAAM;IACvD"}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type Tree } from '@nx/devkit';
|
|
6
6
|
/**
|
|
7
|
-
* Register the nx bump a version update needs, in `
|
|
8
|
-
* when an nx package actually moved.
|
|
7
|
+
* Register the nx bump a version update needs, in `packageJsonUpdates.json`. Call
|
|
8
|
+
* only when an nx package actually moved.
|
|
9
9
|
*
|
|
10
|
+
* The bumps live in their own committed file, assembled into `migrations.json`
|
|
11
|
+
* at build time, so this weekly-bot edit never conflicts with a migration PR.
|
|
10
12
|
* The version sync migration itself is a committed `everyMigration` entry, so
|
|
11
13
|
* only the nx packages need registering per update: they go through
|
|
12
14
|
* `packageJsonUpdates` rather than a migration (see `nx-package-updates.ts`).
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/ import {
|
|
4
|
+
*/ import { writeJson } from "@nx/devkit";
|
|
5
5
|
import { LATEST_MIGRATIONS_DIR } from "../migration-versions.js";
|
|
6
6
|
import { nxPackageJsonUpdates } from "./nx-package-updates.js";
|
|
7
|
-
const
|
|
7
|
+
const PACKAGE_JSON_UPDATES_PATH = 'packages/nx-plugin/packageJsonUpdates.json';
|
|
8
8
|
/**
|
|
9
|
-
* Register the nx bump a version update needs, in `
|
|
10
|
-
* when an nx package actually moved.
|
|
9
|
+
* Register the nx bump a version update needs, in `packageJsonUpdates.json`. Call
|
|
10
|
+
* only when an nx package actually moved.
|
|
11
11
|
*
|
|
12
|
+
* The bumps live in their own committed file, assembled into `migrations.json`
|
|
13
|
+
* at build time, so this weekly-bot edit never conflicts with a migration PR.
|
|
12
14
|
* The version sync migration itself is a committed `everyMigration` entry, so
|
|
13
15
|
* only the nx packages need registering per update: they go through
|
|
14
16
|
* `packageJsonUpdates` rather than a migration (see `nx-package-updates.ts`).
|
|
@@ -26,16 +28,14 @@ const MIGRATIONS_JSON_PATH = 'packages/nx-plugin/migrations.json';
|
|
|
26
28
|
* entry would record the one being replaced.
|
|
27
29
|
* @returns paths written, for the update report
|
|
28
30
|
*/ export const registerNxPackageUpdates = (tree, nxVersion)=>{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}));
|
|
31
|
+
const existing = tree.exists(PACKAGE_JSON_UPDATES_PATH) ? JSON.parse(tree.read(PACKAGE_JSON_UPDATES_PATH, 'utf-8')) : {};
|
|
32
|
+
writeJson(tree, PACKAGE_JSON_UPDATES_PATH, {
|
|
33
|
+
// Recorded under `latest` until stamping resolves the version it ships with.
|
|
34
|
+
...Object.fromEntries(Object.entries(existing).filter(([, entry])=>entry.version !== LATEST_MIGRATIONS_DIR)),
|
|
35
|
+
...nxPackageJsonUpdates(LATEST_MIGRATIONS_DIR, nxVersion)
|
|
36
|
+
});
|
|
37
37
|
return [
|
|
38
|
-
|
|
38
|
+
PACKAGE_JSON_UPDATES_PATH
|
|
39
39
|
];
|
|
40
40
|
};
|
|
41
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/version-upgrade-migration/register.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { type Tree,
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/version-upgrade-migration/register.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { type Tree, writeJson } from '@nx/devkit';\nimport { LATEST_MIGRATIONS_DIR } from '../migration-versions';\nimport {\n nxPackageJsonUpdates,\n type PackageJsonUpdates,\n} from './nx-package-updates';\n\nconst PACKAGE_JSON_UPDATES_PATH = 'packages/nx-plugin/packageJsonUpdates.json';\n\n/**\n * Register the nx bump a version update needs, in `packageJsonUpdates.json`. Call\n * only when an nx package actually moved.\n *\n * The bumps live in their own committed file, assembled into `migrations.json`\n * at build time, so this weekly-bot edit never conflicts with a migration PR.\n * The version sync migration itself is a committed `everyMigration` entry, so\n * only the nx packages need registering per update: they go through\n * `packageJsonUpdates` rather than a migration (see `nx-package-updates.ts`).\n *\n * A bump already dated by a release stays — a workspace several releases behind\n * needs each hop in turn. One still waiting for a release is dropped: this bump\n * supersedes it, and both would otherwise ship under the same version, leaving\n * which nx a workspace lands on down to the order nx happens to apply them in.\n *\n * Idempotent: re-running before a release replaces the pending entry with itself.\n *\n * @param nxVersion nx version being moved to. The update script rewrites\n * `versions.ts` on the tree, which cannot change the `NX_VERSION` this process\n * imported at load — so the caller passes the version it just wrote, or the\n * entry would record the one being replaced.\n * @returns paths written, for the update report\n */\nexport const registerNxPackageUpdates = (\n tree: Tree,\n nxVersion?: string,\n): string[] => {\n const existing: PackageJsonUpdates = tree.exists(PACKAGE_JSON_UPDATES_PATH)\n ? JSON.parse(tree.read(PACKAGE_JSON_UPDATES_PATH, 'utf-8'))\n : {};\n\n writeJson(tree, PACKAGE_JSON_UPDATES_PATH, {\n // Recorded under `latest` until stamping resolves the version it ships with.\n ...Object.fromEntries(\n Object.entries(existing).filter(\n ([, entry]) => entry.version !== LATEST_MIGRATIONS_DIR,\n ),\n ),\n ...nxPackageJsonUpdates(LATEST_MIGRATIONS_DIR, nxVersion),\n });\n\n return [PACKAGE_JSON_UPDATES_PATH];\n};\n"],"names":["writeJson","LATEST_MIGRATIONS_DIR","nxPackageJsonUpdates","PACKAGE_JSON_UPDATES_PATH","registerNxPackageUpdates","tree","nxVersion","existing","exists","JSON","parse","read","Object","fromEntries","entries","filter","entry","version"],"mappings":"AAAA;;;CAGC,GACD,SAAoBA,SAAS,QAAQ,aAAa;AAClD,SAASC,qBAAqB,QAAQ,2BAAwB;AAC9D,SACEC,oBAAoB,QAEf,0BAAuB;AAE9B,MAAMC,4BAA4B;AAElC;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,MAAMC,2BAA2B,CACtCC,MACAC;IAEA,MAAMC,WAA+BF,KAAKG,MAAM,CAACL,6BAC7CM,KAAKC,KAAK,CAACL,KAAKM,IAAI,CAACR,2BAA2B,YAChD,CAAC;IAELH,UAAUK,MAAMF,2BAA2B;QACzC,6EAA6E;QAC7E,GAAGS,OAAOC,WAAW,CACnBD,OAAOE,OAAO,CAACP,UAAUQ,MAAM,CAC7B,CAAC,GAAGC,MAAM,GAAKA,MAAMC,OAAO,KAAKhB,uBAEpC;QACD,GAAGC,qBAAqBD,uBAAuBK,UAAU;IAC3D;IAEA,OAAO;QAACH;KAA0B;AACpC,EAAE"}
|
/package/src/agentcore-gateway/files/project/{local-dev.ts.template → mcp/local-dev.ts.template}
RENAMED
|
File without changes
|