@aws/nx-plugin 1.0.0-rc.54 → 1.0.0-rc.55
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 +45 -0
- package/package.json +1 -1
- package/src/agentcore-gateway/gateway-connection/generator.js +3 -1
- package/src/agentcore-gateway/gateway-connection/generator.js.map +1 -1
- package/src/agentcore-gateway/generator.d.ts +49 -1
- package/src/agentcore-gateway/generator.js +55 -22
- package/src/agentcore-gateway/generator.js.map +1 -1
- package/src/agentcore-gateway/mcp-connection/generator.js +3 -1
- package/src/agentcore-gateway/mcp-connection/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/infra/app/generator.d.ts +43 -0
- package/src/infra/app/generator.js +47 -18
- package/src/infra/app/generator.js.map +1 -1
- package/src/init/generator.d.ts +13 -0
- package/src/init/generator.js +14 -3
- package/src/init/generator.js.map +1 -1
- package/src/migrations/latest/backfill-generator-metadata/migration.d.ts +96 -0
- package/src/migrations/latest/backfill-generator-metadata/migration.js +670 -0
- package/src/migrations/latest/backfill-generator-metadata/migration.js.map +1 -0
- package/src/preset/generator.d.ts +13 -0
- package/src/preset/generator.js +12 -3
- package/src/preset/generator.js.map +1 -1
- package/src/py/agent/a2a-connection/generator.d.ts +24 -0
- package/src/py/agent/a2a-connection/generator.js +49 -20
- package/src/py/agent/a2a-connection/generator.js.map +1 -1
- package/src/py/agent/gateway-connection/generator.d.ts +23 -0
- package/src/py/agent/gateway-connection/generator.js +45 -11
- package/src/py/agent/gateway-connection/generator.js.map +1 -1
- package/src/py/agent/generator.d.ts +146 -1
- package/src/py/agent/generator.js +173 -76
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/agent/mcp-connection/generator.d.ts +23 -0
- package/src/py/agent/mcp-connection/generator.js +45 -11
- package/src/py/agent/mcp-connection/generator.js.map +1 -1
- package/src/py/agent/react-connection/generator.d.ts +146 -0
- package/src/py/agent/react-connection/generator.js +27 -4
- package/src/py/agent/react-connection/generator.js.map +1 -1
- package/src/py/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/py/dynamodb/agent-connection/generator.js +7 -1
- package/src/py/dynamodb/agent-connection/generator.js.map +1 -1
- package/src/py/dynamodb/fast-api-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/py/dynamodb/fast-api-connection/generator.js +3 -1
- package/src/py/dynamodb/fast-api-connection/generator.js.map +1 -1
- package/src/py/dynamodb/generator.d.ts +29 -0
- package/src/py/dynamodb/generator.js +32 -12
- package/src/py/dynamodb/generator.js.map +1 -1
- package/src/py/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/py/dynamodb/mcp-server-connection/generator.js +7 -1
- package/src/py/dynamodb/mcp-server-connection/generator.js.map +1 -1
- package/src/py/fast-api/generator.d.ts +63 -0
- package/src/py/fast-api/generator.js +58 -23
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/generator.d.ts +16 -1
- package/src/py/fast-api/react/generator.js +15 -3
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/lambda-function/generator.d.ts +21 -0
- package/src/py/lambda-function/generator.js +29 -10
- package/src/py/lambda-function/generator.js.map +1 -1
- package/src/py/mcp-server/generator.d.ts +60 -0
- package/src/py/mcp-server/generator.js +62 -25
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/project/generator.d.ts +13 -0
- package/src/py/project/generator.js +29 -10
- package/src/py/project/generator.js.map +1 -1
- package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +19 -0
- package/src/py/rdb/agent-connection/generator.js +7 -1
- package/src/py/rdb/agent-connection/generator.js.map +1 -1
- package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +7 -0
- package/src/py/rdb/fast-api-connection/generator.js +3 -1
- package/src/py/rdb/fast-api-connection/generator.js.map +1 -1
- package/src/py/rdb/generator.d.ts +89 -0
- package/src/py/rdb/generator.js +88 -40
- package/src/py/rdb/generator.js.map +1 -1
- package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/py/rdb/mcp-server-connection/generator.js +7 -1
- package/src/py/rdb/mcp-server-connection/generator.js.map +1 -1
- package/src/smithy/project/generator.d.ts +7 -0
- package/src/smithy/project/generator.js +8 -2
- package/src/smithy/project/generator.js.map +1 -1
- package/src/smithy/react-connection/generator.d.ts +15 -0
- package/src/smithy/react-connection/generator.js +17 -3
- package/src/smithy/react-connection/generator.js.map +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/smithy/ts/api/generator.d.ts +79 -0
- package/src/smithy/ts/api/generator.js +77 -33
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/terraform/project/generator.d.ts +50 -0
- package/src/terraform/project/generator.js +63 -17
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/generator.d.ts +84 -0
- package/src/trpc/backend/generator.js +98 -38
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/react/generator.d.ts +37 -0
- package/src/trpc/react/generator.js +63 -26
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/agent/a2a-connection/generator.d.ts +46 -0
- package/src/ts/agent/a2a-connection/generator.js +53 -16
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/gateway-connection/generator.d.ts +37 -0
- package/src/ts/agent/gateway-connection/generator.js +41 -14
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.d.ts +162 -0
- package/src/ts/agent/generator.js +166 -75
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/generator.d.ts +37 -0
- package/src/ts/agent/mcp-connection/generator.js +41 -14
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/agent/react-connection/generator.d.ts +186 -0
- package/src/ts/agent/react-connection/generator.js +70 -21
- package/src/ts/agent/react-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/generator.d.ts +38 -0
- package/src/ts/astro-docs/generator.js +58 -19
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dcr-proxy/generator.d.ts +24 -0
- package/src/ts/dcr-proxy/generator.js +31 -14
- package/src/ts/dcr-proxy/generator.js.map +1 -1
- package/src/ts/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/ts/dynamodb/agent-connection/generator.js +7 -1
- package/src/ts/dynamodb/agent-connection/generator.js.map +1 -1
- package/src/ts/dynamodb/generator.d.ts +41 -0
- package/src/ts/dynamodb/generator.js +47 -20
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/ts/dynamodb/mcp-server-connection/generator.js +7 -1
- package/src/ts/dynamodb/mcp-server-connection/generator.js.map +1 -1
- package/src/ts/dynamodb/smithy-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/dynamodb/smithy-connection/generator.js +3 -1
- package/src/ts/dynamodb/smithy-connection/generator.js.map +1 -1
- package/src/ts/dynamodb/trpc-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/dynamodb/trpc-connection/generator.js +3 -1
- package/src/ts/dynamodb/trpc-connection/generator.js.map +1 -1
- package/src/ts/lambda-function/generator.d.ts +38 -0
- package/src/ts/lambda-function/generator.js +49 -20
- package/src/ts/lambda-function/generator.js.map +1 -1
- package/src/ts/lib/generator.d.ts +7 -0
- package/src/ts/lib/generator.js +8 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.d.ts +3 -1
- package/src/ts/lib/ts-project-utils.js +3 -2
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.d.ts +10 -1
- package/src/ts/lib/vitest.js +14 -2
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/generator.d.ts +71 -0
- package/src/ts/mcp-server/generator.js +73 -36
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/generator.d.ts +3 -0
- package/src/ts/nx-generator/generator.js +8 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-migration/generator.d.ts +3 -0
- package/src/ts/nx-migration/generator.js +8 -2
- package/src/ts/nx-migration/generator.js.map +1 -1
- package/src/ts/nx-plugin/generator.d.ts +3 -0
- package/src/ts/nx-plugin/generator.js +8 -2
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/ts/nx-plugin/utils.d.ts +7 -2
- package/src/ts/nx-plugin/utils.js +10 -4
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +10 -0
- package/src/ts/rdb/agent-connection/generator.js +8 -1
- package/src/ts/rdb/agent-connection/generator.js.map +1 -1
- package/src/ts/rdb/generator.d.ts +101 -0
- package/src/ts/rdb/generator.js +93 -41
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +10 -0
- package/src/ts/rdb/mcp-server-connection/generator.js +8 -1
- package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -1
- package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/rdb/smithy-connection/generator.js +4 -1
- package/src/ts/rdb/smithy-connection/generator.js.map +1 -1
- package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/rdb/trpc-connection/generator.js +3 -1
- package/src/ts/rdb/trpc-connection/generator.js.map +1 -1
- package/src/ts/react-website/agui/generator.d.ts +86 -0
- package/src/ts/react-website/agui/generator.js +63 -28
- package/src/ts/react-website/agui/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +8 -2
- package/src/ts/react-website/app/generator.d.ts +136 -1
- package/src/ts/react-website/app/generator.js +109 -40
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/react-website/cognito-auth/generator.d.ts +19 -0
- package/src/ts/react-website/cognito-auth/generator.js +21 -9
- package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
- package/src/utils/add-dependencies.d.ts +38 -0
- package/src/utils/add-dependencies.js +83 -0
- package/src/utils/add-dependencies.js.map +1 -0
- package/src/utils/agent-connection/agent-connection.d.ts +27 -6
- package/src/utils/agent-connection/agent-connection.js +47 -18
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +19 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +26 -6
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/api-constructs/api-constructs.d.ts +21 -2
- package/src/utils/api-constructs/api-constructs.js +26 -5
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/bundle/bundle.d.ts +6 -1
- package/src/utils/bundle/bundle.js +8 -2
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/commands.d.ts +5 -4
- package/src/utils/commands.js +2 -6
- package/src/utils/commands.js.map +1 -1
- package/src/utils/connection/open-api/react.d.ts +18 -1
- package/src/utils/connection/open-api/react.js +27 -3
- package/src/utils/connection/open-api/react.js.map +1 -1
- package/src/utils/declared-dependencies.d.ts +140 -0
- package/src/utils/declared-dependencies.js +64 -0
- package/src/utils/declared-dependencies.js.map +1 -0
- package/src/utils/docker.d.ts +10 -1
- package/src/utils/docker.js +7 -3
- package/src/utils/docker.js.map +1 -1
- package/src/utils/fs.d.ts +15 -4
- package/src/utils/fs.js +26 -13
- package/src/utils/fs.js.map +1 -1
- package/src/utils/init.d.ts +14 -1
- package/src/utils/init.js +25 -7
- package/src/utils/init.js.map +1 -1
- package/src/utils/migration-versions.d.ts +15 -1
- package/src/utils/migration-versions.js +53 -7
- package/src/utils/migration-versions.js.map +1 -1
- package/src/utils/nx.d.ts +18 -0
- package/src/utils/nx.js +4 -0
- package/src/utils/nx.js.map +1 -1
- package/src/utils/py.d.ts +3 -2
- package/src/utils/py.js +10 -10
- package/src/utils/py.js.map +1 -1
- package/src/utils/shared-constructs-constants.d.ts +39 -4
- package/src/utils/shared-constructs-constants.js +29 -0
- package/src/utils/shared-constructs-constants.js.map +1 -1
- package/src/utils/shared-constructs.d.ts +4 -1
- package/src/utils/shared-constructs.js +5 -4
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-dynamodb-scripts.d.ts +8 -1
- package/src/utils/shared-dynamodb-scripts.js +11 -3
- package/src/utils/shared-dynamodb-scripts.js.map +1 -1
- package/src/utils/shared-infra-scripts.d.ts +16 -1
- package/src/utils/shared-infra-scripts.js +18 -3
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-rdb-scripts.d.ts +12 -1
- package/src/utils/shared-rdb-scripts.js +17 -3
- package/src/utils/shared-rdb-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.d.ts +26 -1
- package/src/utils/shared-shadcn.js +31 -14
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/version-upgrade-migration/migration.d.ts +14 -0
- package/src/utils/version-upgrade-migration/migration.js +16 -0
- package/src/utils/version-upgrade-migration/migration.js.map +1 -0
- package/src/utils/version-upgrade-migration/nx-package-updates.d.ts +35 -0
- package/src/utils/version-upgrade-migration/nx-package-updates.js +42 -0
- package/src/utils/version-upgrade-migration/nx-package-updates.js.map +1 -0
- package/src/utils/version-upgrade-migration/owned-dependencies.d.ts +50 -0
- package/src/utils/version-upgrade-migration/owned-dependencies.js +98 -0
- package/src/utils/version-upgrade-migration/owned-dependencies.js.map +1 -0
- package/src/utils/version-upgrade-migration/register.d.ts +18 -0
- package/src/utils/version-upgrade-migration/register.js +33 -0
- package/src/utils/version-upgrade-migration/register.js.map +1 -0
- package/src/utils/version-upgrade-migration/sync-metrics-version.d.ts +13 -0
- package/src/utils/version-upgrade-migration/sync-metrics-version.js +33 -0
- package/src/utils/version-upgrade-migration/sync-metrics-version.js.map +1 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.d.ts +10 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.js +504 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -0
- package/src/utils/version-upgrade-migration/vended-upgrade.d.ts +14 -0
- package/src/utils/version-upgrade-migration/vended-upgrade.js +40 -0
- package/src/utils/version-upgrade-migration/vended-upgrade.js.map +1 -0
- package/src/utils/versions.d.ts +25 -5
- package/src/utils/versions.js +46 -4
- package/src/utils/versions.js.map +1 -1
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { generateFiles, joinPathFragments, OverwriteStrategy } from "@nx/devkit";
|
|
5
5
|
import { applyGritQL } from "../ast.js";
|
|
6
|
+
import { forDependencies } from "../declared-dependencies.js";
|
|
6
7
|
import { addDependenciesToPackageJson } from "../dependencies.js";
|
|
7
8
|
import { addDependencyToTargetIfNotPresent, normalizeTargetKeyOrder } from "../nx.js";
|
|
8
9
|
import { getRelativePathToRoot } from "../paths.js";
|
|
9
10
|
import { withVersions } from "../versions.js";
|
|
11
|
+
/** Dependencies a caller must declare to add a TypeScript bundle target. */ export const BUNDLE_DEPENDENCIES = [
|
|
12
|
+
{
|
|
13
|
+
name: 'rolldown'
|
|
14
|
+
}
|
|
15
|
+
];
|
|
10
16
|
/**
|
|
11
17
|
* Create a target for bundling a python project
|
|
12
18
|
*/ const createPythonBundleTarget = ({ packageName, pythonPlatform, bundleTargetName })=>{
|
|
@@ -59,7 +65,7 @@ import { withVersions } from "../versions.js";
|
|
|
59
65
|
};
|
|
60
66
|
/**
|
|
61
67
|
* Add a TypeScript bundle target using rolldown
|
|
62
|
-
*/ export const addTypeScriptBundleTarget = async (tree, project, opts)=>{
|
|
68
|
+
*/ export const addTypeScriptBundleTarget = async (tree, project, opts, declaration)=>{
|
|
63
69
|
project.targets ??= {};
|
|
64
70
|
// Generate empty rolldown config if it doesn't exist
|
|
65
71
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'ts'), project.root, {}, {
|
|
@@ -108,7 +114,7 @@ import { withVersions } from "../versions.js";
|
|
|
108
114
|
await applyGritQL(tree, rolldownConfigPath, `\`defineConfig([$items])\` where { $items <: \`__PLACEHOLDER__\` => ., $items += "${entry}" }`);
|
|
109
115
|
}
|
|
110
116
|
}
|
|
111
|
-
addDependenciesToPackageJson(tree, {}, withVersions([
|
|
117
|
+
addDependenciesToPackageJson(tree, {}, withVersions(forDependencies(declaration), [
|
|
112
118
|
'rolldown'
|
|
113
119
|
]));
|
|
114
120
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/bundle/bundle.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type TargetConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { applyGritQL } from '../ast';\nimport { addDependenciesToPackageJson } from '../dependencies';\nimport {\n addDependencyToTargetIfNotPresent,\n normalizeTargetKeyOrder,\n} from '../nx';\nimport { getRelativePathToRoot } from '../paths';\nimport { withVersions } from '../versions';\n\nexport interface AddPythonBundleTargetOptions {\n /**\n * Python platform\n * @default x86_64-manylinux_2_28\n */\n pythonPlatform?: 'x86_64-manylinux_2_28' | 'aarch64-manylinux_2_28';\n}\n\ninterface CreatePythonBundleTargetOptions\n extends Required<AddPythonBundleTargetOptions> {\n /**\n * Python package name\n */\n packageName: string;\n\n /**\n * Name of the bundle target, used for the outdir for the bundle\n */\n bundleTargetName: string;\n}\n\n/**\n * Create a target for bundling a python project\n */\nconst createPythonBundleTarget = ({\n packageName,\n pythonPlatform,\n bundleTargetName,\n}: CreatePythonBundleTargetOptions): TargetConfiguration => {\n return {\n cache: true,\n inputs: ['default', '^production'],\n executor: 'nx:run-commands',\n outputs: [`{workspaceRoot}/dist/{projectRoot}/${bundleTargetName}`],\n options: {\n commands: [\n `uv export --frozen --no-dev --no-editable --project {projectRoot} --package ${packageName} -o dist/{projectRoot}/${bundleTargetName}/requirements.txt`,\n `uv pip install -n --no-deps --no-installer-metadata --no-compile-bytecode --python-platform ${pythonPlatform} --target dist/{projectRoot}/${bundleTargetName} -r dist/{projectRoot}/${bundleTargetName}/requirements.txt`,\n ],\n parallel: false,\n },\n };\n};\n\n/**\n * Adds a bundle target to the given project if it does not exist, and updates the build target to depend on it\n */\nexport const addPythonBundleTarget = (\n project: ProjectConfiguration,\n opts?: AddPythonBundleTargetOptions,\n) => {\n if (!project.targets) {\n project.targets = {};\n }\n\n const pythonPlatform = opts?.pythonPlatform ?? 'x86_64-manylinux_2_28';\n const bundleTargetName =\n pythonPlatform === 'aarch64-manylinux_2_28' ? 'bundle-arm' : 'bundle-x86';\n\n if (!project.targets?.[bundleTargetName]) {\n project.targets[bundleTargetName] = normalizeTargetKeyOrder({\n ...createPythonBundleTarget({\n packageName: project.name,\n pythonPlatform,\n bundleTargetName,\n }),\n dependsOn: ['compile'],\n });\n }\n\n // Add a \"bundle\" target which depends on either bundle-arm or bundle-x86 (or both)\n addDependencyToTargetIfNotPresent(project, 'bundle', bundleTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'bundle');\n\n return {\n bundleTargetName,\n bundleOutputDir: joinPathFragments('dist', project.root, bundleTargetName),\n };\n};\n\nexport interface AddTypeScriptBundleTargetOptions {\n /**\n * Path to the target file relative to the project dir\n */\n targetFilePath: string;\n\n /**\n * Sub directory to write bundled index.js file to (if any)\n * Outputs to dist/{projectRoot}/bundle/{bundleOutputDir}/index.js\n */\n bundleOutputDir?: string;\n\n /**\n * Modules to omit from the bundle and treat as external\n */\n external?: (string | RegExp)[];\n\n /**\n * Target platform for the bundle\n * @default 'node'\n */\n platform?: 'node' | 'browser' | 'neutral';\n}\n\n/**\n * Add a TypeScript bundle target using rolldown\n */\nexport const addTypeScriptBundleTarget = async (\n tree: Tree,\n project: ProjectConfiguration,\n opts: AddTypeScriptBundleTargetOptions,\n) => {\n project.targets ??= {};\n\n // Generate empty rolldown config if it doesn't exist\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'ts'),\n project.root,\n {},\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add the bundle target\n if (!project.targets.bundle) {\n project.targets.bundle = normalizeTargetKeyOrder({\n cache: true,\n outputs: [`{workspaceRoot}/dist/{projectRoot}/bundle`],\n executor: 'nx:run-commands',\n options: {\n command: 'rolldown -c rolldown.config.ts',\n cwd: '{projectRoot}',\n },\n dependsOn: ['compile'],\n });\n }\n\n // Add bundle to the build target\n addDependencyToTargetIfNotPresent(project, 'build', 'bundle');\n\n const rolldownConfigPath = joinPathFragments(\n project.root,\n 'rolldown.config.ts',\n );\n\n const outputFile = joinPathFragments(\n getRelativePathToRoot(tree, project.name),\n 'dist',\n project.root,\n 'bundle',\n opts.bundleOutputDir ?? '.',\n 'index.js',\n );\n\n const external = opts.external?.length\n ? opts.external\n .map((ext) =>\n typeof ext === 'string' ? `'${ext}'` : `/${ext.source}/`,\n )\n .join(', ')\n : '';\n\n const entry = `{\n tsconfig: 'tsconfig.lib.json',\n input: '${opts.targetFilePath}',\n output: { file: '${outputFile}', format: 'cjs', inlineDynamicImports: true },\n platform: '${opts.platform ?? 'node'}',\n ${external ? `external: [${external}],` : ''}\n }`;\n\n // Use GritQL to append the config entry to the defineConfig array.\n // First try the non-empty array case using the accumulate (+=) operator,\n // with an idempotency guard that checks the input path is not already present.\n const appended = await applyGritQL(\n tree,\n rolldownConfigPath,\n `\\`defineConfig([$items])\\` where { $items <: not contains \\`'${opts.targetFilePath}'\\`, $items += \", ${entry}\" }`,\n );\n\n if (!appended) {\n // Empty array — GritQL's += cannot accumulate into an empty list, so we\n // first insert a placeholder to make the array non-empty, then replace\n // the placeholder with the real entry via += (which handles regex\n // literals that are invalid inside GritQL backtick snippets).\n const inserted = await applyGritQL(\n tree,\n rolldownConfigPath,\n `\\`defineConfig([])\\` => \\`defineConfig([__PLACEHOLDER__])\\``,\n );\n if (inserted) {\n await applyGritQL(\n tree,\n rolldownConfigPath,\n `\\`defineConfig([$items])\\` where { $items <: \\`__PLACEHOLDER__\\` => ., $items += \"${entry}\" }`,\n );\n }\n }\n\n addDependenciesToPackageJson(tree, {}, withVersions(['rolldown']));\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","applyGritQL","addDependenciesToPackageJson","addDependencyToTargetIfNotPresent","normalizeTargetKeyOrder","getRelativePathToRoot","withVersions","createPythonBundleTarget","packageName","pythonPlatform","bundleTargetName","cache","inputs","executor","outputs","options","commands","parallel","addPythonBundleTarget","project","opts","targets","name","dependsOn","bundleOutputDir","root","addTypeScriptBundleTarget","tree","dirname","overwriteStrategy","KeepExisting","bundle","command","cwd","rolldownConfigPath","outputFile","external","length","map","ext","source","join","entry","targetFilePath","platform","appended","inserted"],"mappings":"AAAA;;;CAGC,GAED,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAIZ,aAAa;AACpB,SAASC,WAAW,QAAQ,YAAS;AACrC,SAASC,4BAA4B,QAAQ,qBAAkB;AAC/D,SACEC,iCAAiC,EACjCC,uBAAuB,QAClB,WAAQ;AACf,SAASC,qBAAqB,QAAQ,cAAW;AACjD,SAASC,YAAY,QAAQ,iBAAc;AAuB3C;;CAEC,GACD,MAAMC,2BAA2B,CAAC,EAChCC,WAAW,EACXC,cAAc,EACdC,gBAAgB,EACgB;IAChC,OAAO;QACLC,OAAO;QACPC,QAAQ;YAAC;YAAW;SAAc;QAClCC,UAAU;QACVC,SAAS;YAAC,CAAC,mCAAmC,EAAEJ,kBAAkB;SAAC;QACnEK,SAAS;YACPC,UAAU;gBACR,CAAC,4EAA4E,EAAER,YAAY,uBAAuB,EAAEE,iBAAiB,iBAAiB,CAAC;gBACvJ,CAAC,4FAA4F,EAAED,eAAe,6BAA6B,EAAEC,iBAAiB,uB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SAAS;IAEpD,MAAMe,qBAAqBnC,kBACzBoB,QAAQM,IAAI,EACZ;IAGF,MAAMU,aAAapC,kBACjBM,sBAAsBsB,MAAMR,QAAQG,IAAI,GACxC,QACAH,QAAQM,IAAI,EACZ,UACAL,KAAKI,eAAe,IAAI,KACxB;IAGF,MAAMY,WAAWhB,KAAKgB,QAAQ,EAAEC,SAC5BjB,KAAKgB,QAAQ,CACVE,GAAG,CAAC,CAACC,MACJ,OAAOA,QAAQ,WAAW,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAEA,IAAIC,MAAM,CAAC,CAAC,CAAC,EAEzDC,IAAI,CAAC,QACR;IAEJ,MAAMC,QAAQ,CAAC;;YAEL,EAAEtB,KAAKuB,cAAc,CAAC;qBACb,EAAER,WAAW;eACnB,EAAEf,KAAKwB,QAAQ,IAAI,OAAO;IACrC,EAAER,WAAW,CAAC,WAAW,EAAEA,SAAS,EAAE,CAAC,GAAG,GAAG;GAC9C,CAAC;IAEF,mEAAmE;IACnE,yEAAyE;IACzE,+EAA+E;IAC/E,MAAMS,WAAW,MAAM5C,YACrB0B,MACAO,oBACA,CAAC,6DAA6D,EAAEd,KAAKuB,cAAc,CAAC,kBAAkB,EAAED,MAAM,GAAG,CAAC;IAGpH,IAAI,CAACG,UAAU;QACb,wEAAwE;QACxE,uEAAuE;QACvE,kEAAkE;QAClE,8DAA8D;QAC9D,MAAMC,WAAW,MAAM7C,YACrB0B,MACAO,oBACA,CAAC,2DAA2D,CAAC;QAE/D,IAAIY,UAAU;YACZ,MAAM7C,YACJ0B,MACAO,oBACA,CAAC,kFAAkF,EAAEQ,MAAM,GAAG,CAAC;QAEnG;IACF;IAEAxC,6BAA6ByB,MAAM,CAAC,GAAGrB,aAAa;QAAC;KAAW;AAClE,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/bundle/bundle.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type TargetConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { applyGritQL } from '../ast';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../declared-dependencies';\nimport { addDependenciesToPackageJson } from '../dependencies';\nimport {\n addDependencyToTargetIfNotPresent,\n normalizeTargetKeyOrder,\n} from '../nx';\nimport { getRelativePathToRoot } from '../paths';\nimport { type ITsDepVersion, withVersions } from '../versions';\n\n/** Dependencies a caller must declare to add a TypeScript bundle target. */\nexport const BUNDLE_DEPENDENCIES = [\n { name: 'rolldown' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface AddPythonBundleTargetOptions {\n /**\n * Python platform\n * @default x86_64-manylinux_2_28\n */\n pythonPlatform?: 'x86_64-manylinux_2_28' | 'aarch64-manylinux_2_28';\n}\n\ninterface CreatePythonBundleTargetOptions\n extends Required<AddPythonBundleTargetOptions> {\n /**\n * Python package name\n */\n packageName: string;\n\n /**\n * Name of the bundle target, used for the outdir for the bundle\n */\n bundleTargetName: string;\n}\n\n/**\n * Create a target for bundling a python project\n */\nconst createPythonBundleTarget = ({\n packageName,\n pythonPlatform,\n bundleTargetName,\n}: CreatePythonBundleTargetOptions): TargetConfiguration => {\n return {\n cache: true,\n inputs: ['default', '^production'],\n executor: 'nx:run-commands',\n outputs: [`{workspaceRoot}/dist/{projectRoot}/${bundleTargetName}`],\n options: {\n commands: [\n `uv export --frozen --no-dev --no-editable --project {projectRoot} --package ${packageName} -o dist/{projectRoot}/${bundleTargetName}/requirements.txt`,\n `uv pip install -n --no-deps --no-installer-metadata --no-compile-bytecode --python-platform ${pythonPlatform} --target dist/{projectRoot}/${bundleTargetName} -r dist/{projectRoot}/${bundleTargetName}/requirements.txt`,\n ],\n parallel: false,\n },\n };\n};\n\n/**\n * Adds a bundle target to the given project if it does not exist, and updates the build target to depend on it\n */\nexport const addPythonBundleTarget = (\n project: ProjectConfiguration,\n opts?: AddPythonBundleTargetOptions,\n) => {\n if (!project.targets) {\n project.targets = {};\n }\n\n const pythonPlatform = opts?.pythonPlatform ?? 'x86_64-manylinux_2_28';\n const bundleTargetName =\n pythonPlatform === 'aarch64-manylinux_2_28' ? 'bundle-arm' : 'bundle-x86';\n\n if (!project.targets?.[bundleTargetName]) {\n project.targets[bundleTargetName] = normalizeTargetKeyOrder({\n ...createPythonBundleTarget({\n packageName: project.name,\n pythonPlatform,\n bundleTargetName,\n }),\n dependsOn: ['compile'],\n });\n }\n\n // Add a \"bundle\" target which depends on either bundle-arm or bundle-x86 (or both)\n addDependencyToTargetIfNotPresent(project, 'bundle', bundleTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'bundle');\n\n return {\n bundleTargetName,\n bundleOutputDir: joinPathFragments('dist', project.root, bundleTargetName),\n };\n};\n\nexport interface AddTypeScriptBundleTargetOptions {\n /**\n * Path to the target file relative to the project dir\n */\n targetFilePath: string;\n\n /**\n * Sub directory to write bundled index.js file to (if any)\n * Outputs to dist/{projectRoot}/bundle/{bundleOutputDir}/index.js\n */\n bundleOutputDir?: string;\n\n /**\n * Modules to omit from the bundle and treat as external\n */\n external?: (string | RegExp)[];\n\n /**\n * Target platform for the bundle\n * @default 'node'\n */\n platform?: 'node' | 'browser' | 'neutral';\n}\n\n/**\n * Add a TypeScript bundle target using rolldown\n */\nexport const addTypeScriptBundleTarget = async <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n project: ProjectConfiguration,\n opts: AddTypeScriptBundleTargetOptions,\n declaration: D & MustDeclare<typeof BUNDLE_DEPENDENCIES, D>,\n) => {\n project.targets ??= {};\n\n // Generate empty rolldown config if it doesn't exist\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'ts'),\n project.root,\n {},\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add the bundle target\n if (!project.targets.bundle) {\n project.targets.bundle = normalizeTargetKeyOrder({\n cache: true,\n outputs: [`{workspaceRoot}/dist/{projectRoot}/bundle`],\n executor: 'nx:run-commands',\n options: {\n command: 'rolldown -c rolldown.config.ts',\n cwd: '{projectRoot}',\n },\n dependsOn: ['compile'],\n });\n }\n\n // Add bundle to the build target\n addDependencyToTargetIfNotPresent(project, 'build', 'bundle');\n\n const rolldownConfigPath = joinPathFragments(\n project.root,\n 'rolldown.config.ts',\n );\n\n const outputFile = joinPathFragments(\n getRelativePathToRoot(tree, project.name),\n 'dist',\n project.root,\n 'bundle',\n opts.bundleOutputDir ?? '.',\n 'index.js',\n );\n\n const external = opts.external?.length\n ? opts.external\n .map((ext) =>\n typeof ext === 'string' ? `'${ext}'` : `/${ext.source}/`,\n )\n .join(', ')\n : '';\n\n const entry = `{\n tsconfig: 'tsconfig.lib.json',\n input: '${opts.targetFilePath}',\n output: { file: '${outputFile}', format: 'cjs', inlineDynamicImports: true },\n platform: '${opts.platform ?? 'node'}',\n ${external ? `external: [${external}],` : ''}\n }`;\n\n // Use GritQL to append the config entry to the defineConfig array.\n // First try the non-empty array case using the accumulate (+=) operator,\n // with an idempotency guard that checks the input path is not already present.\n const appended = await applyGritQL(\n tree,\n rolldownConfigPath,\n `\\`defineConfig([$items])\\` where { $items <: not contains \\`'${opts.targetFilePath}'\\`, $items += \", ${entry}\" }`,\n );\n\n if (!appended) {\n // Empty array — GritQL's += cannot accumulate into an empty list, so we\n // first insert a placeholder to make the array non-empty, then replace\n // the placeholder with the real entry via += (which handles regex\n // literals that are invalid inside GritQL backtick snippets).\n const inserted = await applyGritQL(\n tree,\n rolldownConfigPath,\n `\\`defineConfig([])\\` => \\`defineConfig([__PLACEHOLDER__])\\``,\n );\n if (inserted) {\n await applyGritQL(\n tree,\n rolldownConfigPath,\n `\\`defineConfig([$items])\\` where { $items <: \\`__PLACEHOLDER__\\` => ., $items += \"${entry}\" }`,\n );\n }\n }\n\n addDependenciesToPackageJson(\n tree,\n {},\n withVersions(forDependencies<typeof BUNDLE_DEPENDENCIES>(declaration), [\n 'rolldown',\n ]),\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","applyGritQL","forDependencies","addDependenciesToPackageJson","addDependencyToTargetIfNotPresent","normalizeTargetKeyOrder","getRelativePathToRoot","withVersions","BUNDLE_DEPENDENCIES","name","createPythonBundleTarget","packageName","pythonPlatform","bundleTargetName","cache","inputs","executor","outputs","options","commands","parallel","addPythonBundleTarget","project","opts","targets","dependsOn","bundleOutputDir","root","addTypeScriptBundleTarget","tree","declaration","dirname","overwriteStrategy","KeepExisting","bundle","command","cwd","rolldownConfigPath","outputFile","external","length","map","ext","source","join","entry","targetFilePath","platform","appended","inserted"],"mappings":"AAAA;;;CAGC,GAED,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAIZ,aAAa;AACpB,SAASC,WAAW,QAAQ,YAAS;AACrC,SAEEC,eAAe,QAEV,8BAA2B;AAClC,SAASC,4BAA4B,QAAQ,qBAAkB;AAC/D,SACEC,iCAAiC,EACjCC,uBAAuB,QAClB,WAAQ;AACf,SAASC,qBAAqB,QAAQ,cAAW;AACjD,SAA6BC,YAAY,QAAQ,iBAAc;AAE/D,0EAA0E,GAC1E,OAAO,MAAMC,sBAAsB;IACjC;QAAEC,MAAM;IAAW;CACpB,CAAuD;AAuBxD;;CAEC,GACD,MAAMC,2BAA2B,CAAC,EAChCC,WAAW,EACXC,cAAc,EACdC,gBAAgB,EACgB;IAChC,OAAO;QACLC,OAAO;QACPC,QAAQ;YAAC;YAAW;SAAc;QAClCC,UAAU;QACVC,SAAS;YAAC,CAAC,mCAAmC,EAAEJ,kBAAkB;SAAC;QACnEK,SAAS;YACPC,UAAU;gBACR,CAAC,4EAA4E,EAAER,YAAY,uBAAuB,EAAEE,iBAAiB,iBAAiB,CAAC;gBACvJ,CAAC,4FAA4F,EAAED,eAAe,6BAA6B,EAAEC,iBAAiB,uBAAuB,EAAEA,iBAAiB,iBAAiB,CAAC;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*` packages — a mismatch deadlocks `nx sync`.
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
*/
|
|
6
|
-
|
|
5
|
+
import { NX_VERSION } from './versions';
|
|
6
|
+
/** Re-exported for callers that already import it from here. */
|
|
7
|
+
export { NX_VERSION };
|
|
7
8
|
/**
|
|
8
9
|
* Display-friendly command prefixes for each package manager.
|
|
9
10
|
*
|
package/src/utils/commands.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/ import {
|
|
5
|
-
/**
|
|
6
|
-
* The nx version the plugin is built against. Commands that download nx
|
|
7
|
-
* (e.g. `nx init`) pin to this version so the workspace's nx matches the
|
|
8
|
-
* plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.
|
|
9
|
-
*/ export const NX_VERSION = TS_VERSIONS['@nx/devkit'];
|
|
4
|
+
*/ import { NX_VERSION } from "./versions.js";
|
|
5
|
+
/** Re-exported for callers that already import it from here. */ export { NX_VERSION };
|
|
10
6
|
export const PACKAGE_MANAGER_COMMANDS = {
|
|
11
7
|
npm: {
|
|
12
8
|
exec: 'npx',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { NX_VERSION } from './versions';\n\n/** Re-exported for callers that already import it from here. */\nexport { NX_VERSION };\n\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command. Without `pkg`, installs the workspace's existing\n * dependencies. With `project`, targets that project's manifest (pnpm\n * `--filter` by unscoped name, npm/bun by `projectDir` defaulting to\n * `packages/<name>`, yarn by fully-qualified name); otherwise the root.\n */\nexport const buildInstallCommand = (\n pm: string,\n pkg?: string,\n dev?: boolean,\n project?: string,\n projectDir?: string,\n) => {\n if (!pkg) {\n return pm === 'yarn' ? 'yarn' : `${pm} install`;\n }\n if (project) {\n const shortName = project.split('/').pop();\n const dir = projectDir ?? `packages/${shortName}`;\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D ' : ''}${pkg} --filter ${shortName}`;\n case 'yarn':\n return `yarn workspace ${project} add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg} -w ${dir}`;\n case 'bun':\n return `bun add ${dev ? '-D ' : ''}${pkg} --cwd ${dir}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n }\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun add ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build the command that adds Nx to a non-Nx project, pinned to the nx\n * version the plugin is built against.\n */\nexport const buildNxInitCommand = (pm: string) => {\n const dlxPrefix =\n { npm: 'npx', pnpm: 'pnpm dlx', yarn: 'yarn dlx', bun: 'bunx' }[pm] ??\n 'npx';\n return `${dlxPrefix} nx@${NX_VERSION} init`;\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n module?: 'esm' | 'cjs',\n extraArgs?: string,\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ...(module ? [`--module=${module}`] : []),\n ...(extraArgs ? [extraArgs] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["NX_VERSION","PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","project","projectDir","shortName","split","pop","dir","buildNxInitCommand","dlxPrefix","buildCreateNxWorkspaceCommand","workspace","iac","tag","module","extraArgs","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD,SAASA,UAAU,QAAQ,gBAAa;AAExC,8DAA8D,GAC9D,SAASA,UAAU,GAAG;AAoBtB,OAAO,MAAMC,2BAGT;IACFC,KAAK;QAAEC,MAAM;QAAOC,KAAK;QAAWC,QAAQ;IAAa;IACzDC,MAAM;QAAEH,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDE,MAAM;QAAEJ,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDG,KAAK;QAAEL,MAAM;QAAQC,KAAK;QAAOC,QAAQ;IAAa;AACxD,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMI,iCAAiC,CAACC,IAAYC;IACzD,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEP,QAAQO;IACrD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAME,kCAAkC,CAC7CH,IACAC;IAEA,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEN,OAAOM;IACpD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;;;;CAKC,GACD,OAAO,MAAMG,sBAAsB,CACjCJ,IACAK,KACAC,KACAC,SACAC;IAEA,IAAI,CAACH,KA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,CAAC;AAC7C,EAAE;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAMyB,gCAAgC,CAC3Cf,IACAgB,WACAC,KACAC,KACAC,QACAC;IAEA,MAAMC,eAAe9B,wBAAwB,CAACS,GAAG,EAAEL,UAAU,GAAGK,GAAG,OAAO,CAAC;IAC3E,MAAMsB,UAAUJ,MAAM,CAAC,kBAAkB,EAAEA,KAAK,GAAG;IACnD,MAAMK,QAAQ;QACZF;QACAC;QACA,wEAAwE;WACpEtB,OAAO,QAAQ;YAAC;SAAK,GAAG,EAAE;QAC9BgB;WACIC,MAAM;YAAC,CAAC,MAAM,EAAEA,KAAK;SAAC,GAAG,EAAE;WAC3BE,SAAS;YAAC,CAAC,SAAS,EAAEA,QAAQ;SAAC,GAAG,EAAE;WACpCC,YAAY;YAACA;SAAU,GAAG,EAAE;KACjC;IACD,OAAOG,MAAMC,IAAI,CAAC;AACpB,EAAE"}
|
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { type ProjectConfiguration, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type DependencyDeclaration, type MustDeclare } from '../../declared-dependencies';
|
|
7
|
+
/** Dependencies a caller must declare to add an OpenAPI React client. */
|
|
8
|
+
export declare const OPEN_API_REACT_DEPENDENCIES: readonly [{
|
|
9
|
+
readonly name: "oidc-client-ts";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "react-oidc-context";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "@aws-sdk/credential-provider-cognito-identity";
|
|
14
|
+
}, {
|
|
15
|
+
readonly name: "aws4fetch";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "@tanstack/react-query";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "@tanstack/react-query-devtools";
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "@smithy/types";
|
|
22
|
+
}];
|
|
6
23
|
export interface AddOpenApiReactClientOptions {
|
|
7
24
|
/**
|
|
8
25
|
* The react project to add the openapi client and build targets to
|
|
@@ -52,4 +69,4 @@ export interface AddOpenApiReactClientOptions {
|
|
|
52
69
|
/**
|
|
53
70
|
* Adds an OpenAPI React client to the frontend project along with supporting build targets
|
|
54
71
|
*/
|
|
55
|
-
export declare const addOpenApiReactClient: (tree: Tree, { apiName, frontendProjectConfig, backendProjectConfig, specBuildProject, specPath, specBuildTargetName, auth, port, isAgentRuntime, skipLocalDev, }: AddOpenApiReactClientOptions) => Promise<void>;
|
|
72
|
+
export declare const addOpenApiReactClient: <const D extends DependencyDeclaration>(tree: Tree, { apiName, frontendProjectConfig, backendProjectConfig, specBuildProject, specPath, specBuildTargetName, auth, port, isAgentRuntime, skipLocalDev, }: AddOpenApiReactClientOptions, declaration: D & MustDeclare<typeof OPEN_API_REACT_DEPENDENCIES, D>) => Promise<void>;
|
|
@@ -5,14 +5,38 @@
|
|
|
5
5
|
import { addTargetToLocalDev } from "../../../connection/local-dev.js";
|
|
6
6
|
import runtimeConfigGenerator from "../../../ts/react-website/runtime-config/generator.js";
|
|
7
7
|
import { addSingleImport, applyGritQL } from "../../ast.js";
|
|
8
|
+
import { forDependencies } from "../../declared-dependencies.js";
|
|
8
9
|
import { addDependenciesToPackageJson } from "../../dependencies.js";
|
|
9
10
|
import { updateGitIgnore } from "../../git.js";
|
|
10
11
|
import { kebabCase, toClassName } from "../../names.js";
|
|
11
12
|
import { sortObjectKeys } from "../../object.js";
|
|
12
13
|
import { withVersions } from "../../versions.js";
|
|
14
|
+
/** Dependencies a caller must declare to add an OpenAPI React client. */ export const OPEN_API_REACT_DEPENDENCIES = [
|
|
15
|
+
{
|
|
16
|
+
name: 'oidc-client-ts'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'react-oidc-context'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: '@aws-sdk/credential-provider-cognito-identity'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'aws4fetch'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: '@tanstack/react-query'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: '@tanstack/react-query-devtools'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: '@smithy/types'
|
|
35
|
+
}
|
|
36
|
+
];
|
|
13
37
|
/**
|
|
14
38
|
* Adds an OpenAPI React client to the frontend project along with supporting build targets
|
|
15
|
-
*/ export const addOpenApiReactClient = async (tree, { apiName, frontendProjectConfig, backendProjectConfig, specBuildProject, specPath, specBuildTargetName, auth, port, isAgentRuntime = false, skipLocalDev = false })=>{
|
|
39
|
+
*/ export const addOpenApiReactClient = async (tree, { apiName, frontendProjectConfig, backendProjectConfig, specBuildProject, specPath, specBuildTargetName, auth, port, isAgentRuntime = false, skipLocalDev = false }, declaration)=>{
|
|
16
40
|
const clientGenTarget = `generate:${kebabCase(apiName)}-client`;
|
|
17
41
|
const clientGenWatchTarget = `watch-${clientGenTarget}`;
|
|
18
42
|
const generatedClientDir = joinPathFragments('generated', kebabCase(apiName));
|
|
@@ -123,7 +147,7 @@ import { withVersions } from "../../versions.js";
|
|
|
123
147
|
]
|
|
124
148
|
});
|
|
125
149
|
}
|
|
126
|
-
addDependenciesToPackageJson(tree, withVersions([
|
|
150
|
+
addDependenciesToPackageJson(tree, withVersions(forDependencies(declaration), [
|
|
127
151
|
...auth === 'iam' ? [
|
|
128
152
|
'oidc-client-ts',
|
|
129
153
|
'react-oidc-context',
|
|
@@ -135,7 +159,7 @@ import { withVersions } from "../../versions.js";
|
|
|
135
159
|
] : [],
|
|
136
160
|
'@tanstack/react-query',
|
|
137
161
|
'@tanstack/react-query-devtools'
|
|
138
|
-
]), withVersions([
|
|
162
|
+
]), withVersions(forDependencies(declaration), [
|
|
139
163
|
'@smithy/types'
|
|
140
164
|
]), joinPathFragments(frontendProjectConfig.root, 'package.json'));
|
|
141
165
|
};
|
|
@@ -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 { addDependenciesToPackageJson } from '../../dependencies';\nimport { updateGitIgnore } from '../../git';\nimport { kebabCase, toClassName } from '../../names';\nimport { sortObjectKeys } from '../../object';\nimport { withVersions } from '../../versions';\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 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) => {\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 ...((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 withVersions(['@smithy/types']),\n joinPathFragments(frontendProjectConfig.root, 'package.json'),\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTargetToLocalDev","runtimeConfigGenerator","addSingleImport","applyGritQL","addDependenciesToPackageJson","updateGitIgnore","kebabCase","toClassName","sortObjectKeys","withVersions","addOpenApiReactClient","tree","apiName","frontendProjectConfig","backendProjectConfig","specBuildProject","specPath","specBuildTargetName","auth","port","isAgentRuntime","skipLocalDev","clientGenTarget","clientGenWatchTarget","generatedClientDir","generatedClientDirFromRoot","sourceRoot","name","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,e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A4C;IAC5C,MAAMkC,cAAczD,kBAClBgB,sBAAsBa,UAAU,EAChC;IAGF,4DAA4D;IAC5D,MAAMxB,gBACJS,MACA2C,aACA,uBACA;IAEF,MAAMnD,YACJQ,MACA2C,aACA;IAGF,4CAA4C;IAC5C,MAAMC,eAAe,GAAGF,iBAAiB,QAAQ,CAAC;IAClD,MAAMnD,gBACJS,MACA2C,aACAC,cACA,CAAC,aAAa,EAAEA,cAAc;IAEhC,MAAMpD,YACJQ,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,MAAMrB,oBACJW,MACAE,sBAAsBc,IAAI,EAC1Bb,qBAAqBa,IAAI,EACzB;YACE6B,KAAK,CAAC,iBAAiB,EAAErC,KAAK,CAAC,CAAC;YAChCP;YACA,mFAAmF;YACnF,wDAAwD;YACxD,qFAAqF;YACrF,uFAAuF;YACvF6C,6BAA6B;gBAACnC;gBAAiBC;aAAqB;QACtE;IAEJ;IAEAnB,6BACEO,MACAF,aAAa;WACNS,SAAS,QACV;YACE;YACA;YACA;YACA;SACD,GACD,EAAE;WACDA,SAAS,YAAY;YAAC;SAAqB,GAAG,EAAE;QACrD;QACA;KACD,GACDT,aAAa;QAAC;KAAgB,GAC9BZ,kBAAkBgB,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 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,QAAQ,EACRC,mBAAmB,EACnBC,IAAI,EACJC,IAAI,EACJC,iBAAiB,KAAK,EACtBC,eAAe,KAAK,EACS,EAC/BC;IAEA,MAAMC,kBAAkB,CAAC,SAAS,EAAEnB,UAAUQ,SAAS,OAAO,CAAC;IAC/D,MAAMY,uBAAuB,CAAC,MAAM,EAAED,iBAAiB;IAEvD,MAAME,qBAAqB/B,kBAAkB,aAAaU,UAAUQ;IACpE,MAAMc,6BAA6BhC,kBACjCmB,sBAAsBc,UAAU,EAChCF;IAGF,4DAA4D;IAC5D7B,2BAA2Be,MAAME,sBAAsBJ,IAAI,EAAE;QAC3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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"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { IPyDepVersion, ITsDepVersion } from './versions';
|
|
6
|
+
/**
|
|
7
|
+
* Which vended dependencies each generator is responsible for, and when each
|
|
8
|
+
* applies.
|
|
9
|
+
*
|
|
10
|
+
* A generator declares every dependency it may add — including those added on
|
|
11
|
+
* its behalf by helpers it calls — once, and `addTsDependencies` /
|
|
12
|
+
* `addPyDependencies` add the subset whose `when` predicate the generator's
|
|
13
|
+
* metadata satisfies. The declaration is the only place packages are listed.
|
|
14
|
+
*
|
|
15
|
+
* The same declaration drives the version sync migration, which replays the
|
|
16
|
+
* predicates against the metadata recorded on each project. Pass the very object
|
|
17
|
+
* you record as metadata, so what a generator added and what the migration owns
|
|
18
|
+
* cannot drift.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The metadata a generator records, which its predicates read. Deliberately
|
|
22
|
+
* `object` rather than an index signature, so a generator can type its
|
|
23
|
+
* declaration against a plain interface.
|
|
24
|
+
*/
|
|
25
|
+
export type DependencyMetadata = object;
|
|
26
|
+
/** What every declared dependency carries, whichever language it belongs to. */
|
|
27
|
+
export interface DeclaredDependency<Name, M extends DependencyMetadata> {
|
|
28
|
+
readonly name: Name;
|
|
29
|
+
/**
|
|
30
|
+
* Whether this dependency applies. Reads the metadata the generator records,
|
|
31
|
+
* so the migration can evaluate the same predicate later. Any truthy return
|
|
32
|
+
* counts, so a predicate can hand back the value it read.
|
|
33
|
+
*/
|
|
34
|
+
readonly when?: (metadata: M) => unknown;
|
|
35
|
+
/** Added to the workspace root manifest rather than the project's. */
|
|
36
|
+
readonly root?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Declared only so the version sync keeps its pinned version current — an
|
|
39
|
+
* `overrides` entry, say. Never installed as a dependency.
|
|
40
|
+
*/
|
|
41
|
+
readonly versionOnly?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A TypeScript dependency, which may be a dev dependency.
|
|
45
|
+
*
|
|
46
|
+
* `group` is typed as never-present rather than left off, so putting a Python
|
|
47
|
+
* flag on a TypeScript entry is a type error instead of an ignored property.
|
|
48
|
+
*/
|
|
49
|
+
export interface DeclaredTsDependency<Name, M extends DependencyMetadata> extends DeclaredDependency<Name, M> {
|
|
50
|
+
/** Added as a dev dependency rather than a runtime one. */
|
|
51
|
+
readonly dev?: boolean;
|
|
52
|
+
readonly group?: never;
|
|
53
|
+
}
|
|
54
|
+
/** A Python dependency, which may belong to a pyproject dependency group. */
|
|
55
|
+
export interface DeclaredPyDependency<Name, M extends DependencyMetadata> extends DeclaredDependency<Name, M> {
|
|
56
|
+
/** Added to this pyproject dependency group rather than the main list. */
|
|
57
|
+
readonly group?: string;
|
|
58
|
+
readonly dev?: never;
|
|
59
|
+
}
|
|
60
|
+
export interface DependencyDeclaration<Ts extends readonly DeclaredTsDependency<ITsDepVersion, never>[] = readonly DeclaredTsDependency<ITsDepVersion, never>[], Py extends readonly DeclaredPyDependency<IPyDepVersion, never>[] = readonly DeclaredPyDependency<IPyDepVersion, never>[]> {
|
|
61
|
+
readonly ts: Ts;
|
|
62
|
+
readonly py: Py;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Declare the dependencies a generator owns, typed against the metadata it
|
|
66
|
+
* records. Spread the `*_DEPENDENCIES` of any helper called, so the declaration
|
|
67
|
+
* covers what those helpers add too.
|
|
68
|
+
*/
|
|
69
|
+
export declare const declareDependencies: <M extends DependencyMetadata = Record<string, never>>() => <const Ts extends readonly DeclaredTsDependency<ITsDepVersion, M>[], const Py extends readonly DeclaredPyDependency<IPyDepVersion, M>[]>(declaration: {
|
|
70
|
+
ts?: Ts;
|
|
71
|
+
py?: Py;
|
|
72
|
+
}) => DependencyDeclaration<Ts, Py>;
|
|
73
|
+
/**
|
|
74
|
+
* Narrow entries to a further condition, keeping the one each already carries.
|
|
75
|
+
*
|
|
76
|
+
* For a helper's constant spread into a generator that calls it down one branch:
|
|
77
|
+
* the branch gates the whole set, and each entry's own predicate still gates it
|
|
78
|
+
* within that branch. Replacing `when` outright would widen ownership to the
|
|
79
|
+
* helper's every branch.
|
|
80
|
+
*/
|
|
81
|
+
export declare const onlyWhen: <M extends DependencyMetadata, const Entries extends readonly {
|
|
82
|
+
readonly name: unknown;
|
|
83
|
+
}[]>(entries: Entries, condition: (metadata: M) => unknown) => { readonly [K in keyof Entries]: Omit<Entries[K], "when"> & {
|
|
84
|
+
when: (m: M) => boolean;
|
|
85
|
+
}; };
|
|
86
|
+
/**
|
|
87
|
+
* Mark entries as declared for ownership but never installed here — a helper's
|
|
88
|
+
* constant spread into a generator that doesn't own the project the helper adds
|
|
89
|
+
* them to.
|
|
90
|
+
*/
|
|
91
|
+
export declare const ownedElsewhere: <const Entries extends readonly unknown[]>(entries: Entries) => { readonly [K in keyof Entries]: Entries[K] & {
|
|
92
|
+
versionOnly: true;
|
|
93
|
+
}; };
|
|
94
|
+
/** Every package a declaration names, whatever its predicate. */
|
|
95
|
+
export declare const declaredNames: <Name>(entries: readonly {
|
|
96
|
+
readonly name: Name;
|
|
97
|
+
}[]) => Name[];
|
|
98
|
+
/**
|
|
99
|
+
* The entries of a declaration whose condition the given metadata satisfies —
|
|
100
|
+
* everything this occurrence is responsible for, installed here or not.
|
|
101
|
+
*
|
|
102
|
+
* A predicate that throws — reading a field the metadata doesn't carry, say —
|
|
103
|
+
* counts as not applying. The migration evaluates these against whatever a
|
|
104
|
+
* project happened to record, and must not claim a branch it cannot confirm.
|
|
105
|
+
*/
|
|
106
|
+
export declare const ownedDependencyEntries: <Name, M extends DependencyMetadata, Entry extends DeclaredDependency<Name, M>>(entries: readonly Entry[], metadata: M) => Entry[];
|
|
107
|
+
/**
|
|
108
|
+
* The entries to install for the given metadata: those it owns, less the ones
|
|
109
|
+
* declared for their version alone. A `versionOnly` entry is still owned — the
|
|
110
|
+
* sync keeps its pin current wherever it already sits.
|
|
111
|
+
*/
|
|
112
|
+
export declare const applicableDependencies: <Name, M extends DependencyMetadata, Entry extends DeclaredDependency<Name, M>>(entries: readonly Entry[], metadata: M) => Entry[];
|
|
113
|
+
/**
|
|
114
|
+
* Requires a caller's declaration to cover `Needed`, naming whatever is missing
|
|
115
|
+
* in the type error. Helpers that add dependencies take this alongside the
|
|
116
|
+
* declaration so a forgotten spread can't compile.
|
|
117
|
+
*/
|
|
118
|
+
export type MustDeclare<Needed extends readonly {
|
|
119
|
+
readonly name: ITsDepVersion;
|
|
120
|
+
}[], D extends DependencyDeclaration> = [Exclude<Needed[number]['name'], D['ts'][number]['name']>] extends [never] ? unknown : {
|
|
121
|
+
__missingDeclaredDependencies: Exclude<Needed[number]['name'], D['ts'][number]['name']>;
|
|
122
|
+
};
|
|
123
|
+
/** `MustDeclare` for Python dependencies. */
|
|
124
|
+
export type MustDeclarePy<Needed extends readonly {
|
|
125
|
+
readonly name: IPyDepVersion;
|
|
126
|
+
}[], D extends DependencyDeclaration> = [Exclude<Needed[number]['name'], D['py'][number]['name']>] extends [never] ? unknown : {
|
|
127
|
+
__missingDeclaredPyDependencies: Exclude<Needed[number]['name'], D['py'][number]['name']>;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* The dependencies a declaration covers, for typing a conditional list without
|
|
131
|
+
* widening it to every vended package.
|
|
132
|
+
*/
|
|
133
|
+
export type DeclaredTs<D extends DependencyDeclaration> = D['ts'][number]['name'];
|
|
134
|
+
/** `DeclaredTs` for Python dependencies. */
|
|
135
|
+
export type DeclaredPy<D extends DependencyDeclaration> = D['py'][number]['name'];
|
|
136
|
+
/**
|
|
137
|
+
* Narrows a caller's declaration to the subset a helper adds, which
|
|
138
|
+
* `MustDeclare` has already proven the caller covers.
|
|
139
|
+
*/
|
|
140
|
+
export declare const forDependencies: <const Ts extends readonly DeclaredDependency<ITsDepVersion, never>[] = [], const Py extends readonly DeclaredDependency<IPyDepVersion, never>[] = []>(declaration: DependencyDeclaration) => DependencyDeclaration<Ts, Py>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ /**
|
|
5
|
+
* Declare the dependencies a generator owns, typed against the metadata it
|
|
6
|
+
* records. Spread the `*_DEPENDENCIES` of any helper called, so the declaration
|
|
7
|
+
* covers what those helpers add too.
|
|
8
|
+
*/ export const declareDependencies = ()=>(declaration)=>({
|
|
9
|
+
ts: declaration.ts ?? [],
|
|
10
|
+
py: declaration.py ?? []
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Narrow entries to a further condition, keeping the one each already carries.
|
|
14
|
+
*
|
|
15
|
+
* For a helper's constant spread into a generator that calls it down one branch:
|
|
16
|
+
* the branch gates the whole set, and each entry's own predicate still gates it
|
|
17
|
+
* within that branch. Replacing `when` outright would widen ownership to the
|
|
18
|
+
* helper's every branch.
|
|
19
|
+
*/ export const onlyWhen = (entries, condition)=>entries.map((entry)=>{
|
|
20
|
+
// A declaration erases the metadata its predicates read, so calling one back
|
|
21
|
+
// requires naming the type the caller narrows to.
|
|
22
|
+
const own = entry.when;
|
|
23
|
+
return {
|
|
24
|
+
...entry,
|
|
25
|
+
when: (metadata)=>Boolean(condition(metadata)) && Boolean(own?.(metadata) ?? true)
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Mark entries as declared for ownership but never installed here — a helper's
|
|
30
|
+
* constant spread into a generator that doesn't own the project the helper adds
|
|
31
|
+
* them to.
|
|
32
|
+
*/ export const ownedElsewhere = (entries)=>entries.map((entry)=>({
|
|
33
|
+
...entry,
|
|
34
|
+
versionOnly: true
|
|
35
|
+
}));
|
|
36
|
+
/** Every package a declaration names, whatever its predicate. */ export const declaredNames = (entries)=>entries.map((entry)=>entry.name);
|
|
37
|
+
/**
|
|
38
|
+
* The entries of a declaration whose condition the given metadata satisfies —
|
|
39
|
+
* everything this occurrence is responsible for, installed here or not.
|
|
40
|
+
*
|
|
41
|
+
* A predicate that throws — reading a field the metadata doesn't carry, say —
|
|
42
|
+
* counts as not applying. The migration evaluates these against whatever a
|
|
43
|
+
* project happened to record, and must not claim a branch it cannot confirm.
|
|
44
|
+
*/ export const ownedDependencyEntries = (entries, metadata)=>entries.filter((entry)=>{
|
|
45
|
+
if (!entry.when) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return Boolean(entry.when(metadata));
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* The entries to install for the given metadata: those it owns, less the ones
|
|
56
|
+
* declared for their version alone. A `versionOnly` entry is still owned — the
|
|
57
|
+
* sync keeps its pin current wherever it already sits.
|
|
58
|
+
*/ export const applicableDependencies = (entries, metadata)=>ownedDependencyEntries(entries, metadata).filter((entry)=>!entry.versionOnly);
|
|
59
|
+
/**
|
|
60
|
+
* Narrows a caller's declaration to the subset a helper adds, which
|
|
61
|
+
* `MustDeclare` has already proven the caller covers.
|
|
62
|
+
*/ export const forDependencies = (declaration)=>declaration;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=declared-dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/declared-dependencies.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { IPyDepVersion, ITsDepVersion } from './versions';\n\n/**\n * Which vended dependencies each generator is responsible for, and when each\n * applies.\n *\n * A generator declares every dependency it may add — including those added on\n * its behalf by helpers it calls — once, and `addTsDependencies` /\n * `addPyDependencies` add the subset whose `when` predicate the generator's\n * metadata satisfies. The declaration is the only place packages are listed.\n *\n * The same declaration drives the version sync migration, which replays the\n * predicates against the metadata recorded on each project. Pass the very object\n * you record as metadata, so what a generator added and what the migration owns\n * cannot drift.\n */\n\n/**\n * The metadata a generator records, which its predicates read. Deliberately\n * `object` rather than an index signature, so a generator can type its\n * declaration against a plain interface.\n */\nexport type DependencyMetadata = object;\n\n/** What every declared dependency carries, whichever language it belongs to. */\nexport interface DeclaredDependency<Name, M extends DependencyMetadata> {\n readonly name: Name;\n /**\n * Whether this dependency applies. Reads the metadata the generator records,\n * so the migration can evaluate the same predicate later. Any truthy return\n * counts, so a predicate can hand back the value it read.\n */\n readonly when?: (metadata: M) => unknown;\n /** Added to the workspace root manifest rather than the project's. */\n readonly root?: boolean;\n /**\n * Declared only so the version sync keeps its pinned version current — an\n * `overrides` entry, say. Never installed as a dependency.\n */\n readonly versionOnly?: boolean;\n}\n\n/**\n * A TypeScript dependency, which may be a dev dependency.\n *\n * `group` is typed as never-present rather than left off, so putting a Python\n * flag on a TypeScript entry is a type error instead of an ignored property.\n */\nexport interface DeclaredTsDependency<Name, M extends DependencyMetadata>\n extends DeclaredDependency<Name, M> {\n /** Added as a dev dependency rather than a runtime one. */\n readonly dev?: boolean;\n readonly group?: never;\n}\n\n/** A Python dependency, which may belong to a pyproject dependency group. */\nexport interface DeclaredPyDependency<Name, M extends DependencyMetadata>\n extends DeclaredDependency<Name, M> {\n /** Added to this pyproject dependency group rather than the main list. */\n readonly group?: string;\n readonly dev?: never;\n}\n\nexport interface DependencyDeclaration<\n Ts extends readonly DeclaredTsDependency<\n ITsDepVersion,\n never\n >[] = readonly DeclaredTsDependency<ITsDepVersion, never>[],\n Py extends readonly DeclaredPyDependency<\n IPyDepVersion,\n never\n >[] = readonly DeclaredPyDependency<IPyDepVersion, never>[],\n> {\n readonly ts: Ts;\n readonly py: Py;\n}\n\n/**\n * Declare the dependencies a generator owns, typed against the metadata it\n * records. Spread the `*_DEPENDENCIES` of any helper called, so the declaration\n * covers what those helpers add too.\n */\nexport const declareDependencies =\n <M extends DependencyMetadata = Record<string, never>>() =>\n <\n const Ts extends readonly DeclaredTsDependency<ITsDepVersion, M>[],\n const Py extends readonly DeclaredPyDependency<IPyDepVersion, M>[],\n >(declaration: {\n ts?: Ts;\n py?: Py;\n }): DependencyDeclaration<Ts, Py> =>\n ({\n ts: declaration.ts ?? [],\n py: declaration.py ?? [],\n }) as unknown as DependencyDeclaration<Ts, Py>;\n\n/**\n * Narrow entries to a further condition, keeping the one each already carries.\n *\n * For a helper's constant spread into a generator that calls it down one branch:\n * the branch gates the whole set, and each entry's own predicate still gates it\n * within that branch. Replacing `when` outright would widen ownership to the\n * helper's every branch.\n */\nexport const onlyWhen = <\n M extends DependencyMetadata,\n const Entries extends readonly { readonly name: unknown }[],\n>(\n entries: Entries,\n condition: (metadata: M) => unknown,\n): {\n readonly [K in keyof Entries]: Omit<Entries[K], 'when'> & {\n when: (m: M) => boolean;\n };\n} =>\n entries.map((entry) => {\n // A declaration erases the metadata its predicates read, so calling one back\n // requires naming the type the caller narrows to.\n const own = (entry as { when?: (m: M) => unknown }).when;\n return {\n ...entry,\n when: (metadata: M) =>\n Boolean(condition(metadata)) && Boolean(own?.(metadata) ?? true),\n };\n }) as never;\n\n/**\n * Mark entries as declared for ownership but never installed here — a helper's\n * constant spread into a generator that doesn't own the project the helper adds\n * them to.\n */\nexport const ownedElsewhere = <const Entries extends readonly unknown[]>(\n entries: Entries,\n): { readonly [K in keyof Entries]: Entries[K] & { versionOnly: true } } =>\n entries.map((entry) => ({\n ...(entry as object),\n versionOnly: true,\n })) as never;\n\n/** Every package a declaration names, whatever its predicate. */\nexport const declaredNames = <Name>(\n entries: readonly { readonly name: Name }[],\n): Name[] => entries.map((entry) => entry.name);\n\n/**\n * The entries of a declaration whose condition the given metadata satisfies —\n * everything this occurrence is responsible for, installed here or not.\n *\n * A predicate that throws — reading a field the metadata doesn't carry, say —\n * counts as not applying. The migration evaluates these against whatever a\n * project happened to record, and must not claim a branch it cannot confirm.\n */\nexport const ownedDependencyEntries = <\n Name,\n M extends DependencyMetadata,\n Entry extends DeclaredDependency<Name, M>,\n>(\n entries: readonly Entry[],\n metadata: M,\n): Entry[] =>\n entries.filter((entry) => {\n if (!entry.when) {\n return true;\n }\n try {\n return Boolean(entry.when(metadata));\n } catch {\n return false;\n }\n });\n\n/**\n * The entries to install for the given metadata: those it owns, less the ones\n * declared for their version alone. A `versionOnly` entry is still owned — the\n * sync keeps its pin current wherever it already sits.\n */\nexport const applicableDependencies = <\n Name,\n M extends DependencyMetadata,\n Entry extends DeclaredDependency<Name, M>,\n>(\n entries: readonly Entry[],\n metadata: M,\n): Entry[] =>\n ownedDependencyEntries(entries, metadata).filter(\n (entry) => !entry.versionOnly,\n );\n\n/**\n * Requires a caller's declaration to cover `Needed`, naming whatever is missing\n * in the type error. Helpers that add dependencies take this alongside the\n * declaration so a forgotten spread can't compile.\n */\nexport type MustDeclare<\n Needed extends readonly { readonly name: ITsDepVersion }[],\n D extends DependencyDeclaration,\n> = [Exclude<Needed[number]['name'], D['ts'][number]['name']>] extends [never]\n ? unknown\n : {\n __missingDeclaredDependencies: Exclude<\n Needed[number]['name'],\n D['ts'][number]['name']\n >;\n };\n\n/** `MustDeclare` for Python dependencies. */\nexport type MustDeclarePy<\n Needed extends readonly { readonly name: IPyDepVersion }[],\n D extends DependencyDeclaration,\n> = [Exclude<Needed[number]['name'], D['py'][number]['name']>] extends [never]\n ? unknown\n : {\n __missingDeclaredPyDependencies: Exclude<\n Needed[number]['name'],\n D['py'][number]['name']\n >;\n };\n\n/**\n * The dependencies a declaration covers, for typing a conditional list without\n * widening it to every vended package.\n */\nexport type DeclaredTs<D extends DependencyDeclaration> =\n D['ts'][number]['name'];\n\n/** `DeclaredTs` for Python dependencies. */\nexport type DeclaredPy<D extends DependencyDeclaration> =\n D['py'][number]['name'];\n\n/**\n * Narrows a caller's declaration to the subset a helper adds, which\n * `MustDeclare` has already proven the caller covers.\n */\nexport const forDependencies = <\n const Ts extends readonly DeclaredDependency<ITsDepVersion, never>[] = [],\n const Py extends readonly DeclaredDependency<IPyDepVersion, never>[] = [],\n>(\n declaration: DependencyDeclaration,\n): DependencyDeclaration<Ts, Py> =>\n declaration as unknown as DependencyDeclaration<Ts, Py>;\n"],"names":["declareDependencies","declaration","ts","py","onlyWhen","entries","condition","map","entry","own","when","metadata","Boolean","ownedElsewhere","versionOnly","declaredNames","name","ownedDependencyEntries","filter","applicableDependencies","forDependencies"],"mappings":"AAAA;;;CAGC,GA8ED;;;;CAIC,GACD,OAAO,MAAMA,sBACX,IACA,CAGEC,cAIC,CAAA;YACCC,IAAID,YAAYC,EAAE,IAAI,EAAE;YACxBC,IAAIF,YAAYE,EAAE,IAAI,EAAE;QAC1B,CAAA,EAA+C;AAEnD;;;;;;;CAOC,GACD,OAAO,MAAMC,WAAW,CAItBC,SACAC,YAMAD,QAAQE,GAAG,CAAC,CAACC;QACX,6EAA6E;QAC7E,kDAAkD;QAClD,MAAMC,MAAM,AAACD,MAAuCE,IAAI;QACxD,OAAO;YACL,GAAGF,KAAK;YACRE,MAAM,CAACC,WACLC,QAAQN,UAAUK,cAAcC,QAAQH,MAAME,aAAa;QAC/D;IACF,GAAY;AAEd;;;;CAIC,GACD,OAAO,MAAME,iBAAiB,CAC5BR,UAEAA,QAAQE,GAAG,CAAC,CAACC,QAAW,CAAA;YACtB,GAAIA,KAAK;YACTM,aAAa;QACf,CAAA,GAAa;AAEf,+DAA+D,GAC/D,OAAO,MAAMC,gBAAgB,CAC3BV,UACWA,QAAQE,GAAG,CAAC,CAACC,QAAUA,MAAMQ,IAAI,EAAE;AAEhD;;;;;;;CAOC,GACD,OAAO,MAAMC,yBAAyB,CAKpCZ,SACAM,WAEAN,QAAQa,MAAM,CAAC,CAACV;QACd,IAAI,CAACA,MAAME,IAAI,EAAE;YACf,OAAO;QACT;QACA,IAAI;YACF,OAAOE,QAAQJ,MAAME,IAAI,CAACC;QAC5B,EAAE,OAAM;YACN,OAAO;QACT;IACF,GAAG;AAEL;;;;CAIC,GACD,OAAO,MAAMQ,yBAAyB,CAKpCd,SACAM,WAEAM,uBAAuBZ,SAASM,UAAUO,MAAM,CAC9C,CAACV,QAAU,CAACA,MAAMM,WAAW,EAC7B;AA2CJ;;;CAGC,GACD,OAAO,MAAMM,kBAAkB,CAI7BnB,cAEAA,YAAwD"}
|
package/src/utils/docker.d.ts
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { type ProjectConfiguration, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type DependencyDeclaration, type MustDeclare } from './declared-dependencies';
|
|
7
|
+
/** Dependencies a caller must declare to add a Docker scan target. */
|
|
8
|
+
export declare const DOCKER_DEPENDENCIES: readonly [{
|
|
9
|
+
readonly name: "ncp";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "rimraf";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "make-dir-cli";
|
|
14
|
+
}];
|
|
6
15
|
/**
|
|
7
16
|
* Substitution variables for the vended Node `Dockerfile` templates: the npm
|
|
8
17
|
* version to install globally, and the versions its dependency overrides pin.
|
|
@@ -50,4 +59,4 @@ export interface DockerScanTargetOptions {
|
|
|
50
59
|
* A \`.trivyignore\` is vended at the project root (kept if it already exists)
|
|
51
60
|
* for suppressing findings.
|
|
52
61
|
*/
|
|
53
|
-
export declare const addDockerScanTarget: (tree: Tree, options: DockerScanTargetOptions) => void;
|
|
62
|
+
export declare const addDockerScanTarget: <const D extends DependencyDeclaration>(tree: Tree, options: DockerScanTargetOptions, declaration: D & MustDeclare<typeof DOCKER_DEPENDENCIES, D>) => void;
|
package/src/utils/docker.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { joinPathFragments } from "@nx/devkit";
|
|
5
|
-
import {
|
|
5
|
+
import { forDependencies } from "./declared-dependencies.js";
|
|
6
|
+
import { FS_DEPENDENCIES, FsCommands } from "./fs.js";
|
|
6
7
|
import { addDependencyToTargetIfNotPresent } from "./nx.js";
|
|
7
8
|
import { CONTAINER_VERSIONS, TS_VERSIONS } from "./versions.js";
|
|
9
|
+
/** Dependencies a caller must declare to add a Docker scan target. */ export const DOCKER_DEPENDENCIES = [
|
|
10
|
+
...FS_DEPENDENCIES
|
|
11
|
+
];
|
|
8
12
|
const TRIVY_IGNORE_FILE = '.trivyignore';
|
|
9
13
|
const TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.g. CVE-2021-12345) per line to
|
|
10
14
|
# suppress it during the image scan (\`nx run-many --target trivy\`).
|
|
@@ -32,7 +36,7 @@ const TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.
|
|
|
32
36
|
*
|
|
33
37
|
* A \`.trivyignore\` is vended at the project root (kept if it already exists)
|
|
34
38
|
* for suppressing findings.
|
|
35
|
-
*/ export const addDockerScanTarget = (tree, options)=>{
|
|
39
|
+
*/ export const addDockerScanTarget = (tree, options, declaration)=>{
|
|
36
40
|
const { project, containerEngine, trivyTargetName, dockerTargetName } = options;
|
|
37
41
|
const { imageTags } = options;
|
|
38
42
|
const projectRoot = project.root;
|
|
@@ -47,7 +51,7 @@ const TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.
|
|
|
47
51
|
const scanKey = imageTags[0].replace(/[^a-zA-Z0-9-]/g, '-');
|
|
48
52
|
const scanDir = joinPathFragments('dist', projectRoot, 'trivy', scanKey);
|
|
49
53
|
const trivyImage = `public.ecr.aws/aquasecurity/trivy:${CONTAINER_VERSIONS.trivy}`;
|
|
50
|
-
const fs = new FsCommands(tree);
|
|
54
|
+
const fs = new FsCommands(tree, forDependencies(declaration));
|
|
51
55
|
const commands = [
|
|
52
56
|
fs.rm(scanDir),
|
|
53
57
|
fs.mkdir(scanDir),
|