@aws/nx-plugin 1.0.0-rc.93 → 1.0.0-rc.95
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 +36 -1
- package/package.json +1 -1
- package/src/agentcore-harness/generator.d.ts +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +5 -5
- package/src/infra/app/generator.d.ts +1 -1
- package/src/infra/app/generator.js +5 -3
- package/src/infra/app/generator.js.map +1 -1
- package/src/init/generator.d.ts +1 -1
- package/src/migrations/latest/agent-connection-pin-strands-peers/metadata.json +3 -0
- package/src/migrations/latest/agent-connection-pin-strands-peers/migration.d.ts +18 -0
- package/src/migrations/latest/agent-connection-pin-strands-peers/migration.js +38 -0
- package/src/migrations/latest/agent-connection-pin-strands-peers/migration.js.map +1 -0
- package/src/migrations/latest/agent-core-vendor-target/metadata.json +3 -0
- package/src/migrations/latest/agent-core-vendor-target/migration.d.ts +6 -0
- package/src/migrations/latest/agent-core-vendor-target/migration.js +98 -0
- package/src/migrations/latest/agent-core-vendor-target/migration.js.map +1 -0
- package/src/migrations/latest/ignore-package-manager-temp-files/metadata.json +3 -0
- package/src/migrations/latest/ignore-package-manager-temp-files/migration.d.ts +12 -0
- package/src/migrations/latest/ignore-package-manager-temp-files/migration.js +25 -0
- package/src/migrations/latest/ignore-package-manager-temp-files/migration.js.map +1 -0
- package/src/migrations/latest/infra-deploy-express-mode/metadata.json +3 -0
- package/src/migrations/latest/infra-deploy-express-mode/migration.d.ts +6 -0
- package/src/migrations/latest/infra-deploy-express-mode/migration.js +83 -0
- package/src/migrations/latest/infra-deploy-express-mode/migration.js.map +1 -0
- package/src/migrations/latest/rolldown-config-bundle-transient/metadata.json +3 -0
- package/src/migrations/latest/rolldown-config-bundle-transient/migration.d.ts +6 -0
- package/src/migrations/latest/rolldown-config-bundle-transient/migration.js +80 -0
- package/src/migrations/latest/rolldown-config-bundle-transient/migration.js.map +1 -0
- package/src/migrations/latest/shadcn-package-imports-exports/metadata.json +3 -0
- package/src/migrations/latest/shadcn-package-imports-exports/migration.d.ts +6 -0
- package/src/migrations/latest/shadcn-package-imports-exports/migration.js +184 -0
- package/src/migrations/latest/shadcn-package-imports-exports/migration.js.map +1 -0
- package/src/migrations/latest/shx-fs-commands/metadata.json +3 -0
- package/src/migrations/latest/shx-fs-commands/migration.d.ts +6 -0
- package/src/migrations/latest/shx-fs-commands/migration.js +216 -0
- package/src/migrations/latest/shx-fs-commands/migration.js.map +1 -0
- package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +18 -12
- package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +5 -2
- package/src/open-api/utils/codegen-data/types.d.ts +6 -0
- package/src/open-api/utils/codegen-data/types.js.map +1 -1
- package/src/open-api/utils/codegen-data.js +32 -7
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/open-api/utils/normalise.js +39 -14
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/open-api/utils/parser.js +51 -5
- package/src/open-api/utils/parser.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +5 -1
- package/src/preset/generator.d.ts +1 -1
- package/src/py/agent/a2a-connection/generator.d.ts +1 -1
- package/src/py/agent/gateway-connection/generator.d.ts +1 -1
- package/src/py/agent/generator.d.ts +2 -26
- package/src/py/agent/generator.js +2 -2
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/agent/mcp-connection/generator.d.ts +1 -1
- package/src/py/agent/react-connection/generator.d.ts +1 -1
- package/src/py/fast-api/generator.d.ts +1 -13
- package/src/py/fast-api/generator.js +1 -1
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/generator.d.ts +1 -1
- package/src/py/mcp-server/generator.d.ts +2 -26
- package/src/py/mcp-server/generator.js +2 -2
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/rdb/generator.d.ts +2 -26
- package/src/py/rdb/generator.js +6 -6
- package/src/py/rdb/generator.js.map +1 -1
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +24 -20
- package/src/smithy/project/generator.d.ts +2 -14
- package/src/smithy/project/generator.js +2 -1
- package/src/smithy/project/generator.js.map +1 -1
- package/src/smithy/react-connection/generator.d.ts +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +12 -8
- package/src/smithy/ts/api/generator.d.ts +1 -13
- package/src/smithy/ts/api/generator.js +1 -1
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/terraform/project/generator.d.ts +2 -2
- package/src/terraform/project/generator.js +4 -4
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/react/generator.d.ts +1 -1
- package/src/ts/agent/a2a-connection/generator.d.ts +5 -1
- package/src/ts/agent/gateway-connection/generator.d.ts +5 -1
- package/src/ts/agent/generator.d.ts +5 -37
- package/src/ts/agent/generator.js +1 -1
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/generator.d.ts +5 -1
- package/src/ts/agent/react-connection/generator.d.ts +1 -1
- package/src/ts/astro-docs/generator.d.ts +1 -1
- package/src/ts/dcr-proxy/generator.d.ts +1 -1
- package/src/ts/dynamodb/generator.d.ts +1 -1
- package/src/ts/lambda-function/generator.d.ts +1 -1
- package/src/ts/lib/generator.d.ts +1 -1
- package/src/ts/mcp-server/generator.d.ts +3 -39
- package/src/ts/mcp-server/generator.js +1 -1
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/generator.d.ts +1 -1
- package/src/ts/nx-migration/generator.d.ts +1 -1
- package/src/ts/nx-plugin/generator.d.ts +1 -1
- package/src/ts/rdb/generator.d.ts +3 -27
- package/src/ts/rdb/generator.js +3 -3
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/agui/generator.d.ts +1 -1
- package/src/ts/react-website/agui/generator.js +2 -1
- package/src/ts/react-website/agui/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/ts/react-website/app/generator.js +2 -1
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/utils/agent-connection/agent-connection.d.ts +2 -0
- package/src/utils/agent-connection/agent-connection.js +11 -4
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-core-packaging.d.ts +25 -12
- package/src/utils/agent-core-packaging.js +47 -11
- package/src/utils/agent-core-packaging.js.map +1 -1
- package/src/utils/bundle/bundle.js +10 -0
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/docker.d.ts +1 -7
- package/src/utils/docker.js +1 -1
- package/src/utils/docker.js.map +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/alert.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/avatar.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/breadcrumb.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/button.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/card.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/input.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/separator.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/sheet.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/sidebar.tsx.template +8 -8
- package/src/utils/files/common/shadcn/src/components/ui/skeleton.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/spinner.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/textarea.tsx.template +1 -1
- package/src/utils/files/common/shadcn/src/components/ui/tooltip.tsx.template +1 -1
- package/src/utils/files/shadcn/components.json.template +5 -5
- package/src/utils/format.d.ts +21 -0
- package/src/utils/format.js +20 -0
- package/src/utils/format.js.map +1 -1
- package/src/utils/fs.d.ts +21 -11
- package/src/utils/fs.js +30 -22
- package/src/utils/fs.js.map +1 -1
- package/src/utils/init.js +11 -4
- package/src/utils/init.js.map +1 -1
- package/src/utils/pnpm-workspace.d.ts +5 -5
- package/src/utils/pnpm-workspace.js +5 -5
- package/src/utils/pnpm-workspace.js.map +1 -1
- package/src/utils/shared-shadcn.d.ts +9 -0
- package/src/utils/shared-shadcn.js +36 -26
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/version-lockstep/lockstep.d.ts +27 -0
- package/src/utils/version-lockstep/lockstep.js +46 -0
- package/src/utils/version-lockstep/lockstep.js.map +1 -0
- package/src/utils/versions.d.ts +9 -4
- package/src/utils/versions.js +24 -4
- package/src/utils/versions.js.map +1 -1
|
@@ -37,6 +37,18 @@ import { agentCoreRuntime, TS_VERSIONS } from "./versions.js";
|
|
|
37
37
|
name: '@aws/aws-distro-opentelemetry-node-autoinstrumentation'
|
|
38
38
|
}
|
|
39
39
|
];
|
|
40
|
+
/**
|
|
41
|
+
* Name of the target that installs ADOT for the project's code packages. Every
|
|
42
|
+
* code package in a project vendors the same thing, so they share one.
|
|
43
|
+
*/ export const ADOT_VENDOR_TARGET_NAME = 'agent-core-vendor';
|
|
44
|
+
/**
|
|
45
|
+
* Directory the vendor target installs into, relative to the workspace root.
|
|
46
|
+
*
|
|
47
|
+
* A sibling of the `package` directory rather than a path inside it: Nx replaces
|
|
48
|
+
* a cached target's whole declared output directory on restore, so an output
|
|
49
|
+
* nested inside another target's output would have each wipe the other's work on
|
|
50
|
+
* a cache hit.
|
|
51
|
+
*/ export const adotVendorDir = (projectRoot)=>joinPathFragments('dist', projectRoot, 'agent-core-vendor');
|
|
40
52
|
/**
|
|
41
53
|
* Add a target assembling the deployable code package for a TypeScript
|
|
42
54
|
* AgentCore Runtime.
|
|
@@ -48,16 +60,39 @@ import { agentCoreRuntime, TS_VERSIONS } from "./versions.js";
|
|
|
48
60
|
* being installed at runtime — the `opentelemetry-instrument` entry point
|
|
49
61
|
* prefix resolves it from there.
|
|
50
62
|
*
|
|
51
|
-
* The install is scoped to
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
63
|
+
* The install is scoped to its own directory with `--prefix` and `--no-save`, so
|
|
64
|
+
* it never touches the project's own manifest. `--omit=dev` keeps the package to
|
|
65
|
+
* what the runtime loads. ADOT is pure JavaScript with no native binaries, so the
|
|
66
|
+
* package is architecture independent even though AgentCore only runs arm64.
|
|
67
|
+
*
|
|
68
|
+
* Vendoring is a separate target so Nx caches it independently of the source. It
|
|
69
|
+
* depends on nothing but the pinned ADOT version, which the install command
|
|
70
|
+
* carries and Nx hashes as part of the target's configuration, so it declares no
|
|
71
|
+
* `inputs`: editing an agent replays a directory copy rather than re-running the
|
|
72
|
+
* install, while bumping the version still invalidates it.
|
|
56
73
|
*/ export const addTypeScriptCodePackageTarget = (tree, options, declaration)=>{
|
|
57
74
|
const { project, targetName, bundleTargetName, bundleOutputDir, packageOutputDir } = options;
|
|
58
75
|
const fs = new FsCommands(tree, forDependencies(declaration));
|
|
59
76
|
const adotVersion = TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'];
|
|
77
|
+
const vendorDir = adotVendorDir(project.root);
|
|
60
78
|
project.targets ??= {};
|
|
79
|
+
// Shared by every code package in the project, so only added once.
|
|
80
|
+
project.targets[ADOT_VENDOR_TARGET_NAME] ??= {
|
|
81
|
+
cache: true,
|
|
82
|
+
inputs: [],
|
|
83
|
+
outputs: [
|
|
84
|
+
`{workspaceRoot}/${vendorDir}`
|
|
85
|
+
],
|
|
86
|
+
executor: 'nx:run-commands',
|
|
87
|
+
options: {
|
|
88
|
+
commands: [
|
|
89
|
+
fs.rm(vendorDir),
|
|
90
|
+
fs.mkdir(vendorDir),
|
|
91
|
+
`npm install --prefix ${vendorDir} --no-save --no-audit --no-fund --omit=dev @aws/aws-distro-opentelemetry-node-autoinstrumentation@${adotVersion}`
|
|
92
|
+
],
|
|
93
|
+
parallel: false
|
|
94
|
+
}
|
|
95
|
+
};
|
|
61
96
|
project.targets[targetName] = {
|
|
62
97
|
cache: true,
|
|
63
98
|
inputs: [
|
|
@@ -71,13 +106,14 @@ import { agentCoreRuntime, TS_VERSIONS } from "./versions.js";
|
|
|
71
106
|
commands: [
|
|
72
107
|
fs.rm(packageOutputDir),
|
|
73
108
|
fs.mkdir(packageOutputDir),
|
|
74
|
-
fs.
|
|
75
|
-
|
|
109
|
+
fs.cpFile(joinPathFragments(bundleOutputDir, 'index.js'), joinPathFragments(packageOutputDir, 'index.js')),
|
|
110
|
+
fs.cpDir(joinPathFragments(vendorDir, 'node_modules'), joinPathFragments(packageOutputDir, 'node_modules'))
|
|
76
111
|
],
|
|
77
112
|
parallel: false
|
|
78
113
|
},
|
|
79
114
|
dependsOn: [
|
|
80
|
-
bundleTargetName
|
|
115
|
+
bundleTargetName,
|
|
116
|
+
ADOT_VENDOR_TARGET_NAME
|
|
81
117
|
]
|
|
82
118
|
};
|
|
83
119
|
addArtifactDependencyToTargets(project, targetName);
|
|
@@ -115,9 +151,9 @@ import { agentCoreRuntime, TS_VERSIONS } from "./versions.js";
|
|
|
115
151
|
commands: [
|
|
116
152
|
fs.rm(packageOutputDir),
|
|
117
153
|
fs.mkdir(packageOutputDir),
|
|
118
|
-
fs.
|
|
119
|
-
fs.
|
|
120
|
-
fs.
|
|
154
|
+
fs.cpDir(bundleOutputDir, packageOutputDir),
|
|
155
|
+
fs.cpDir(sourceRoot, joinPathFragments(packageOutputDir, moduleName)),
|
|
156
|
+
fs.cpFile(entryPointPath, joinPathFragments(packageOutputDir, entryPointFileName))
|
|
121
157
|
],
|
|
122
158
|
parallel: false
|
|
123
159
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/agent-core-packaging.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport { FS_DEPENDENCIES, FsCommands } from './fs.js';\nimport { addArtifactDependencyToTargets } from './nx.js';\nimport {\n agentCoreRuntime,\n type ITsDepVersion,\n TS_VERSIONS,\n} from './versions.js';\n\n/**\n * How an AgentCore Runtime's artifact is packaged and hosted.\n *\n * `agentcore` uploads a `.zip` of the built code to S3 and runs it on an\n * AgentCore managed language runtime, which skips the container build, ECR\n * repository and image push entirely — the fastest build and deploy cycle.\n * `agentcore-ecr` builds an arm64 container image and hosts it from ECR, for\n * workloads needing OS-level control (e.g. native system libraries) or an\n * established container pipeline.\n */\nexport const AGENT_CORE_INFRA = ['agentcore', 'agentcore-ecr', 'none'] as const;\n\nexport type AgentCoreInfra = (typeof AGENT_CORE_INFRA)[number];\n\n/** Whether the given infra option hosts on AgentCore Runtime at all. */\nexport const isAgentCoreHosted = (infra: AgentCoreInfra): boolean =>\n infra === 'agentcore' || infra === 'agentcore-ecr';\n\n/** Whether the given infra option builds and hosts a container image. */\nexport const isContainerHosted = (infra: AgentCoreInfra): boolean =>\n infra === 'agentcore-ecr';\n\n/** The AgentCore managed runtime a TypeScript component targets. */\nexport const agentCoreNodeRuntime = (): string => agentCoreRuntime('node');\n\n/** The AgentCore managed runtime a Python component targets. */\nexport const agentCorePythonRuntime = (): string => agentCoreRuntime('python');\n\n/**\n * Dependencies a caller must declare to add a code (`.zip`) packaging target.\n *\n * The TypeScript package target vendors the AWS Distro for OpenTelemetry into\n * the package directory, so its version is declared here (spread through\n * `ownedElsewhere` by callers, since the install targets the built package\n * rather than any workspace manifest).\n */\nexport const CODE_PACKAGE_DEPENDENCIES = [\n ...FS_DEPENDENCIES,\n { name: '@aws/aws-distro-opentelemetry-node-autoinstrumentation' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface AddTypeScriptCodePackageTargetOptions {\n /** Project configuration to add the target to (mutated in place). */\n readonly project: ProjectConfiguration;\n /** Name of the packaging target to add, e.g. `agent-package`. */\n readonly targetName: string;\n /** Name of the target producing the bundled `index.js`, depended on here. */\n readonly bundleTargetName: string;\n /** Directory holding the bundled `index.js`, relative to the workspace root. */\n readonly bundleOutputDir: string;\n /** Directory to assemble the deployable package in, relative to the workspace root. */\n readonly packageOutputDir: string;\n}\n\n/**\n * Add a target assembling the deployable code package for a TypeScript\n * AgentCore Runtime.\n *\n * The package is the rolldown bundle plus a vendored AWS Distro for\n * OpenTelemetry install. AgentCore rejects a code package with no OpenTelemetry\n * dependencies present (`CREATE_FAILED`: \"OpenTelemetry instrumentation\n * executable not found\"), so ADOT must ship inside the package rather than\n * being installed at runtime — the `opentelemetry-instrument` entry point\n * prefix resolves it from there.\n *\n * The install is scoped to the package directory with `--prefix` and\n * `--no-save`, so it never touches the project's own manifest. `--omit=dev`\n * keeps the package to what the runtime loads. ADOT is pure JavaScript with no\n * native binaries, so the package is architecture independent even though\n * AgentCore only runs arm64.\n */\nexport const addTypeScriptCodePackageTarget = <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n options: AddTypeScriptCodePackageTargetOptions,\n declaration: D & MustDeclare<typeof CODE_PACKAGE_DEPENDENCIES, D>,\n): void => {\n const {\n project,\n targetName,\n bundleTargetName,\n bundleOutputDir,\n packageOutputDir,\n } = options;\n\n const fs = new FsCommands(\n tree,\n forDependencies<typeof FS_DEPENDENCIES>(declaration),\n );\n const adotVersion =\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'];\n\n project.targets ??= {};\n project.targets[targetName] = {\n cache: true,\n inputs: ['default'],\n outputs: [`{workspaceRoot}/${packageOutputDir}`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(packageOutputDir),\n fs.mkdir(packageOutputDir),\n fs.cp(\n joinPathFragments(bundleOutputDir, 'index.js'),\n joinPathFragments(packageOutputDir, 'index.js'),\n ),\n `npm install --prefix ${packageOutputDir} --no-save --no-audit --no-fund --omit=dev @aws/aws-distro-opentelemetry-node-autoinstrumentation@${adotVersion}`,\n ],\n parallel: false,\n },\n dependsOn: [bundleTargetName],\n };\n\n addArtifactDependencyToTargets(project, targetName);\n};\n\nexport interface AddPythonCodePackageTargetOptions {\n /** Project configuration to add the target to (mutated in place). */\n readonly project: ProjectConfiguration;\n /** Name of the packaging target to add, e.g. `agent-package`. */\n readonly targetName: string;\n /** Name of the arm64 bundle target, depended on here. */\n readonly bundleTargetName: string;\n /** Directory holding the arm64 bundle, relative to the workspace root. */\n readonly bundleOutputDir: string;\n /** Directory to assemble the deployable package in, relative to the workspace root. */\n readonly packageOutputDir: string;\n /**\n * The project's source root, which is itself the module directory — copied\n * into the package under {@link moduleName} so the agent's imports resolve.\n */\n readonly sourceRoot: string;\n /** Python module name (the source root's last segment). */\n readonly moduleName: string;\n /**\n * Path to the entry point script, relative to the workspace root. Copied to\n * the package root, where AgentCore's `entryPoint` runs it.\n */\n readonly entryPointPath: string;\n /** File name the entry point takes at the package root. */\n readonly entryPointFileName: string;\n}\n\n/**\n * Add a target assembling the deployable code package for a Python AgentCore\n * Runtime.\n *\n * The package is the arm64 dependency bundle (which already carries\n * `bin/opentelemetry-instrument` from `aws-opentelemetry-distro`, satisfying\n * AgentCore's requirement that OpenTelemetry be present), the project's own\n * module tree, and a root entry point script.\n *\n * The entry point sits at the package root rather than inside the module:\n * AgentCore runs it as a file path, and Python gives a script run that way no\n * parent package, so the agent's own `from .init import app` would raise\n * `ImportError: attempted relative import with no known parent package`. The\n * root script imports the module absolutely instead, which resolves those\n * relative imports normally.\n */\nexport const addPythonCodePackageTarget = <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n options: AddPythonCodePackageTargetOptions,\n declaration: D & MustDeclare<typeof FS_DEPENDENCIES, D>,\n): void => {\n const {\n project,\n targetName,\n bundleTargetName,\n bundleOutputDir,\n packageOutputDir,\n sourceRoot,\n moduleName,\n entryPointPath,\n entryPointFileName,\n } = options;\n\n const fs = new FsCommands(\n tree,\n forDependencies<typeof FS_DEPENDENCIES>(declaration),\n );\n\n project.targets ??= {};\n project.targets[targetName] = {\n cache: true,\n inputs: ['production', '^production'],\n outputs: [`{workspaceRoot}/${packageOutputDir}`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(packageOutputDir),\n fs.mkdir(packageOutputDir),\n fs.cp(bundleOutputDir, packageOutputDir),\n fs.cp(sourceRoot, joinPathFragments(packageOutputDir, moduleName)),\n fs.cp(\n entryPointPath,\n joinPathFragments(packageOutputDir, entryPointFileName),\n ),\n ],\n parallel: false,\n },\n dependsOn: [bundleTargetName],\n };\n\n addArtifactDependencyToTargets(project, targetName);\n};\n"],"names":["joinPathFragments","forDependencies","FS_DEPENDENCIES","FsCommands","addArtifactDependencyToTargets","agentCoreRuntime","TS_VERSIONS","AGENT_CORE_INFRA","isAgentCoreHosted","infra","isContainerHosted","agentCoreNodeRuntime","agentCorePythonRuntime","CODE_PACKAGE_DEPENDENCIES","name","addTypeScriptCodePackageTarget","tree","options","declaration","project","targetName","bundleTargetName","bundleOutputDir","packageOutputDir","fs","adotVersion","targets","cache","inputs","outputs","executor","commands","rm","mkdir","cp","parallel","dependsOn","addPythonCodePackageTarget","sourceRoot","moduleName","entryPointPath","entryPointFileName"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAEEC,eAAe,QAEV,6BAA6B;AACpC,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,8BAA8B,QAAQ,UAAU;AACzD,SACEC,gBAAgB,EAEhBC,WAAW,QACN,gBAAgB;AAEvB;;;;;;;;;CASC,GACD,OAAO,MAAMC,mBAAmB;IAAC;IAAa;IAAiB;CAAO,CAAU;AAIhF,sEAAsE,GACtE,OAAO,MAAMC,oBAAoB,CAACC,QAChCA,UAAU,eAAeA,UAAU,gBAAgB;AAErD,uEAAuE,GACvE,OAAO,MAAMC,oBAAoB,CAACD,QAChCA,UAAU,gBAAgB;AAE5B,kEAAkE,GAClE,OAAO,MAAME,uBAAuB,IAAcN,iBAAiB,QAAQ;AAE3E,8DAA8D,GAC9D,OAAO,MAAMO,yBAAyB,IAAcP,i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YAAC;YAAc;SAAc;QACrCC,SAAS;YAAC,CAAC,gBAAgB,EAAEN,kBAAkB;SAAC;QAChDO,UAAU;QACVb,SAAS;YACPc,UAAU;gBACRP,GAAGQ,EAAE,CAACT;gBACNC,GAAGS,KAAK,CAACV;gBACTC,GAAGU,EAAE,CAACZ,iBAAiBC;gBACvBC,GAAGU,EAAE,CAACI,YAAYtC,kBAAkBuB,kBAAkBgB;gBACtDf,GAAGU,EAAE,CACHM,gBACAxC,kBAAkBuB,kBAAkBkB;aAEvC;YACDN,UAAU;QACZ;QACAC,WAAW;YAACf;SAAiB;IAC/B;IAEAjB,+BAA+Be,SAASC;AAC1C,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/agent-core-packaging.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport { FS_DEPENDENCIES, FsCommands } from './fs.js';\nimport { addArtifactDependencyToTargets } from './nx.js';\nimport {\n agentCoreRuntime,\n type ITsDepVersion,\n TS_VERSIONS,\n} from './versions.js';\n\n/**\n * How an AgentCore Runtime's artifact is packaged and hosted.\n *\n * `agentcore` uploads a `.zip` of the built code to S3 and runs it on an\n * AgentCore managed language runtime, which skips the container build, ECR\n * repository and image push entirely — the fastest build and deploy cycle.\n * `agentcore-ecr` builds an arm64 container image and hosts it from ECR, for\n * workloads needing OS-level control (e.g. native system libraries) or an\n * established container pipeline.\n */\nexport const AGENT_CORE_INFRA = ['agentcore', 'agentcore-ecr', 'none'] as const;\n\nexport type AgentCoreInfra = (typeof AGENT_CORE_INFRA)[number];\n\n/** Whether the given infra option hosts on AgentCore Runtime at all. */\nexport const isAgentCoreHosted = (infra: AgentCoreInfra): boolean =>\n infra === 'agentcore' || infra === 'agentcore-ecr';\n\n/** Whether the given infra option builds and hosts a container image. */\nexport const isContainerHosted = (infra: AgentCoreInfra): boolean =>\n infra === 'agentcore-ecr';\n\n/** The AgentCore managed runtime a TypeScript component targets. */\nexport const agentCoreNodeRuntime = (): string => agentCoreRuntime('node');\n\n/** The AgentCore managed runtime a Python component targets. */\nexport const agentCorePythonRuntime = (): string => agentCoreRuntime('python');\n\n/**\n * Dependencies a caller must declare to add a code (`.zip`) packaging target.\n *\n * The TypeScript package target vendors the AWS Distro for OpenTelemetry into\n * the package directory, so its version is declared here (spread through\n * `ownedElsewhere` by callers, since the install targets the built package\n * rather than any workspace manifest).\n */\nexport const CODE_PACKAGE_DEPENDENCIES = [\n ...FS_DEPENDENCIES,\n { name: '@aws/aws-distro-opentelemetry-node-autoinstrumentation' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface AddTypeScriptCodePackageTargetOptions {\n /** Project configuration to add the target to (mutated in place). */\n readonly project: ProjectConfiguration;\n /** Name of the packaging target to add, e.g. `agent-package`. */\n readonly targetName: string;\n /** Name of the target producing the bundled `index.js`, depended on here. */\n readonly bundleTargetName: string;\n /** Directory holding the bundled `index.js`, relative to the workspace root. */\n readonly bundleOutputDir: string;\n /** Directory to assemble the deployable package in, relative to the workspace root. */\n readonly packageOutputDir: string;\n}\n\n/**\n * Name of the target that installs ADOT for the project's code packages. Every\n * code package in a project vendors the same thing, so they share one.\n */\nexport const ADOT_VENDOR_TARGET_NAME = 'agent-core-vendor';\n\n/**\n * Directory the vendor target installs into, relative to the workspace root.\n *\n * A sibling of the `package` directory rather than a path inside it: Nx replaces\n * a cached target's whole declared output directory on restore, so an output\n * nested inside another target's output would have each wipe the other's work on\n * a cache hit.\n */\nexport const adotVendorDir = (projectRoot: string): string =>\n joinPathFragments('dist', projectRoot, 'agent-core-vendor');\n\n/**\n * Add a target assembling the deployable code package for a TypeScript\n * AgentCore Runtime.\n *\n * The package is the rolldown bundle plus a vendored AWS Distro for\n * OpenTelemetry install. AgentCore rejects a code package with no OpenTelemetry\n * dependencies present (`CREATE_FAILED`: \"OpenTelemetry instrumentation\n * executable not found\"), so ADOT must ship inside the package rather than\n * being installed at runtime — the `opentelemetry-instrument` entry point\n * prefix resolves it from there.\n *\n * The install is scoped to its own directory with `--prefix` and `--no-save`, so\n * it never touches the project's own manifest. `--omit=dev` keeps the package to\n * what the runtime loads. ADOT is pure JavaScript with no native binaries, so the\n * package is architecture independent even though AgentCore only runs arm64.\n *\n * Vendoring is a separate target so Nx caches it independently of the source. It\n * depends on nothing but the pinned ADOT version, which the install command\n * carries and Nx hashes as part of the target's configuration, so it declares no\n * `inputs`: editing an agent replays a directory copy rather than re-running the\n * install, while bumping the version still invalidates it.\n */\nexport const addTypeScriptCodePackageTarget = <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n options: AddTypeScriptCodePackageTargetOptions,\n declaration: D & MustDeclare<typeof CODE_PACKAGE_DEPENDENCIES, D>,\n): void => {\n const {\n project,\n targetName,\n bundleTargetName,\n bundleOutputDir,\n packageOutputDir,\n } = options;\n\n const fs = new FsCommands(\n tree,\n forDependencies<typeof FS_DEPENDENCIES>(declaration),\n );\n const adotVersion =\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'];\n const vendorDir = adotVendorDir(project.root);\n\n project.targets ??= {};\n\n // Shared by every code package in the project, so only added once.\n project.targets[ADOT_VENDOR_TARGET_NAME] ??= {\n cache: true,\n inputs: [],\n outputs: [`{workspaceRoot}/${vendorDir}`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(vendorDir),\n fs.mkdir(vendorDir),\n `npm install --prefix ${vendorDir} --no-save --no-audit --no-fund --omit=dev @aws/aws-distro-opentelemetry-node-autoinstrumentation@${adotVersion}`,\n ],\n parallel: false,\n },\n };\n\n project.targets[targetName] = {\n cache: true,\n inputs: ['default'],\n outputs: [`{workspaceRoot}/${packageOutputDir}`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(packageOutputDir),\n fs.mkdir(packageOutputDir),\n fs.cpFile(\n joinPathFragments(bundleOutputDir, 'index.js'),\n joinPathFragments(packageOutputDir, 'index.js'),\n ),\n fs.cpDir(\n joinPathFragments(vendorDir, 'node_modules'),\n joinPathFragments(packageOutputDir, 'node_modules'),\n ),\n ],\n parallel: false,\n },\n dependsOn: [bundleTargetName, ADOT_VENDOR_TARGET_NAME],\n };\n\n addArtifactDependencyToTargets(project, targetName);\n};\n\nexport interface AddPythonCodePackageTargetOptions {\n /** Project configuration to add the target to (mutated in place). */\n readonly project: ProjectConfiguration;\n /** Name of the packaging target to add, e.g. `agent-package`. */\n readonly targetName: string;\n /** Name of the arm64 bundle target, depended on here. */\n readonly bundleTargetName: string;\n /** Directory holding the arm64 bundle, relative to the workspace root. */\n readonly bundleOutputDir: string;\n /** Directory to assemble the deployable package in, relative to the workspace root. */\n readonly packageOutputDir: string;\n /**\n * The project's source root, which is itself the module directory — copied\n * into the package under {@link moduleName} so the agent's imports resolve.\n */\n readonly sourceRoot: string;\n /** Python module name (the source root's last segment). */\n readonly moduleName: string;\n /**\n * Path to the entry point script, relative to the workspace root. Copied to\n * the package root, where AgentCore's `entryPoint` runs it.\n */\n readonly entryPointPath: string;\n /** File name the entry point takes at the package root. */\n readonly entryPointFileName: string;\n}\n\n/**\n * Add a target assembling the deployable code package for a Python AgentCore\n * Runtime.\n *\n * The package is the arm64 dependency bundle (which already carries\n * `bin/opentelemetry-instrument` from `aws-opentelemetry-distro`, satisfying\n * AgentCore's requirement that OpenTelemetry be present), the project's own\n * module tree, and a root entry point script.\n *\n * The entry point sits at the package root rather than inside the module:\n * AgentCore runs it as a file path, and Python gives a script run that way no\n * parent package, so the agent's own `from .init import app` would raise\n * `ImportError: attempted relative import with no known parent package`. The\n * root script imports the module absolutely instead, which resolves those\n * relative imports normally.\n */\nexport const addPythonCodePackageTarget = <\n const D extends DependencyDeclaration,\n>(\n tree: Tree,\n options: AddPythonCodePackageTargetOptions,\n declaration: D & MustDeclare<typeof FS_DEPENDENCIES, D>,\n): void => {\n const {\n project,\n targetName,\n bundleTargetName,\n bundleOutputDir,\n packageOutputDir,\n sourceRoot,\n moduleName,\n entryPointPath,\n entryPointFileName,\n } = options;\n\n const fs = new FsCommands(\n tree,\n forDependencies<typeof FS_DEPENDENCIES>(declaration),\n );\n\n project.targets ??= {};\n project.targets[targetName] = {\n cache: true,\n inputs: ['production', '^production'],\n outputs: [`{workspaceRoot}/${packageOutputDir}`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(packageOutputDir),\n fs.mkdir(packageOutputDir),\n fs.cpDir(bundleOutputDir, packageOutputDir),\n fs.cpDir(sourceRoot, joinPathFragments(packageOutputDir, moduleName)),\n fs.cpFile(\n entryPointPath,\n joinPathFragments(packageOutputDir, entryPointFileName),\n ),\n ],\n parallel: false,\n },\n dependsOn: [bundleTargetName],\n };\n\n addArtifactDependencyToTargets(project, targetName);\n};\n"],"names":["joinPathFragments","forDependencies","FS_DEPENDENCIES","FsCommands","addArtifactDependencyToTargets","agentCoreRuntime","TS_VERSIONS","AGENT_CORE_INFRA","isAgentCoreHosted","infra","isContainerHosted","agentCoreNodeRuntime","agentCorePythonRuntime","CODE_PACKAGE_DEPENDENCIES","name","ADOT_VENDOR_TARGET_NAME","adotVendorDir","projectRoot","addTypeScriptCodePackageTarget","tree","options","declaration","project","targetName","bundleTargetName","bundleOutputDir","packageOutputDir","fs","adotVersion","vendorDir","root","targets","cache","inputs","outputs","executor","commands","rm","mkdir","parallel","cpFile","cpDir","dependsOn","addPythonCodePackageTarget","sourceRoot","moduleName","entryPointPath","entryPointFileName"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAEEC,eAAe,QAEV,6BAA6B;AACpC,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,8BAA8B,QAAQ,UAAU;AACzD,SACEC,gBAAgB,EAEhBC,WAAW,QACN,gBAAgB;AAEv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ACZ;QACAG,WAAW;YAAClB;SAAiB;IAC/B;IAEApB,+BAA+BkB,SAASC;AAC1C,EAAE"}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import { applyGritQL } from "../ast.js";
|
|
6
6
|
import { forDependencies } from "../declared-dependencies.js";
|
|
7
7
|
import { addDependenciesToPackageJson } from "../dependencies.js";
|
|
8
|
+
import { ROLLDOWN_CONFIG_BUNDLE_GLOB } from "../format.js";
|
|
9
|
+
import { updateGitIgnore } from "../git.js";
|
|
8
10
|
import { addArtifactDependencyToTargets, addDependencyToTargetIfNotPresent, normalizeTargetKeyOrder } from "../nx.js";
|
|
9
11
|
import { getRelativePathToRoot } from "../paths.js";
|
|
10
12
|
import { LAMBDA_RUNTIME_VERSIONS, withVersions } from "../versions.js";
|
|
@@ -76,6 +78,14 @@ import { LAMBDA_RUNTIME_VERSIONS, withVersions } from "../versions.js";
|
|
|
76
78
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'ts'), project.root, {}, {
|
|
77
79
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
78
80
|
});
|
|
81
|
+
// Loading a TypeScript config bundles it to `rolldown.config.<hash>.js` beside
|
|
82
|
+
// itself, imports it, then unlinks it. Kept out of git so the transient file
|
|
83
|
+
// can never be committed, nor picked up by `license#sync`, which builds its
|
|
84
|
+
// candidate set from git-visible files.
|
|
85
|
+
updateGitIgnore(tree, project.root, (patterns)=>patterns.includes(ROLLDOWN_CONFIG_BUNDLE_GLOB) ? patterns : [
|
|
86
|
+
...patterns,
|
|
87
|
+
ROLLDOWN_CONFIG_BUNDLE_GLOB
|
|
88
|
+
]);
|
|
79
89
|
// Add the bundle target
|
|
80
90
|
if (!project.targets.bundle) {
|
|
81
91
|
project.targets.bundle = normalizeTargetKeyOrder({
|
|
@@ -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.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../declared-dependencies.js';\nimport { addDependenciesToPackageJson } from '../dependencies.js';\nimport {\n addArtifactDependencyToTargets,\n addDependencyToTargetIfNotPresent,\n normalizeTargetKeyOrder,\n} from '../nx.js';\nimport { getRelativePathToRoot } from '../paths.js';\nimport {\n type ITsDepVersion,\n LAMBDA_RUNTIME_VERSIONS,\n withVersions,\n} from '../versions.js';\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 // The bundle holds exported dependencies and the entrypoint script, never\n // test files, so tests are excluded via `production`.\n inputs: ['production', '^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 // `--python-version` pins wheel resolution to the Lambda Python runtime,\n // so the bundle cannot be built against whichever interpreter happens to\n // be on the build machine.\n `uv pip install -n --no-deps --no-installer-metadata --no-compile-bytecode --python-platform ${pythonPlatform} --python-version ${LAMBDA_RUNTIME_VERSIONS.python} --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 addArtifactDependencyToTargets(project, '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 // Declared rather than left to Nx's implicit `[\"default\", \"^default\"]`,\n // which reads a dependency's whole project directory: rolldown resolves\n // dependencies through the build artifacts `default` already tracks, so\n // `^default` only adds files no bundle can contain.\n inputs: ['default'],\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 addArtifactDependencyToTargets(project, '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', codeSplitting: false },\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","addArtifactDependencyToTargets","addDependencyToTargetIfNotPresent","normalizeTargetKeyOrder","getRelativePathToRoot","LAMBDA_RUNTIME_VERSIONS","withVersions","BUNDLE_DEPENDENCIES","name","createPythonBundleTarget","packageName","pythonPlatform","bundleTargetName","cache","inputs","executor","outputs","options","commands","python","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,YAAY;AACxC,SAEEC,eAAe,QAEV,8BAA8B;AACrC,SAASC,4BAA4B,QAAQ,qBAAqB;AAClE,SACEC,8BAA8B,EAC9BC,iCAAiC,EACjCC,uBAAuB,QAClB,WAAW;AAClB,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAEEC,uBAAuB,EACvBC,YAAY,QACP,iBAAiB;AAExB,0EAA0E,GAC1E,OAAO,MAAMC,sBAAsB;IACjC;QAAEC,MAAM;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ACnE,yEAAyE;IACzE,+EAA+E;IAC/E,MAAMS,WAAW,MAAMlD,YACrB+B,MACAQ,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,MAAMnD,YACrB+B,MACAQ,oBACA,CAAC,2DAA2D,CAAC;QAE/D,IAAIY,UAAU;YACZ,MAAMnD,YACJ+B,MACAQ,oBACA,CAAC,kFAAkF,EAAEQ,MAAM,GAAG,CAAC;QAEnG;IACF;IAEA7C,6BACE6B,MACA,CAAC,GACDvB,aAAaP,gBAA4C+B,cAAc;QACrE;KACD;AAEL,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.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../declared-dependencies.js';\nimport { addDependenciesToPackageJson } from '../dependencies.js';\nimport { ROLLDOWN_CONFIG_BUNDLE_GLOB } from '../format.js';\nimport { updateGitIgnore } from '../git.js';\nimport {\n addArtifactDependencyToTargets,\n addDependencyToTargetIfNotPresent,\n normalizeTargetKeyOrder,\n} from '../nx.js';\nimport { getRelativePathToRoot } from '../paths.js';\nimport {\n type ITsDepVersion,\n LAMBDA_RUNTIME_VERSIONS,\n withVersions,\n} from '../versions.js';\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 // The bundle holds exported dependencies and the entrypoint script, never\n // test files, so tests are excluded via `production`.\n inputs: ['production', '^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 // `--python-version` pins wheel resolution to the Lambda Python runtime,\n // so the bundle cannot be built against whichever interpreter happens to\n // be on the build machine.\n `uv pip install -n --no-deps --no-installer-metadata --no-compile-bytecode --python-platform ${pythonPlatform} --python-version ${LAMBDA_RUNTIME_VERSIONS.python} --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 addArtifactDependencyToTargets(project, '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 // Loading a TypeScript config bundles it to `rolldown.config.<hash>.js` beside\n // itself, imports it, then unlinks it. Kept out of git so the transient file\n // can never be committed, nor picked up by `license#sync`, which builds its\n // candidate set from git-visible files.\n updateGitIgnore(tree, project.root, (patterns) =>\n patterns.includes(ROLLDOWN_CONFIG_BUNDLE_GLOB)\n ? patterns\n : [...patterns, ROLLDOWN_CONFIG_BUNDLE_GLOB],\n );\n\n // Add the bundle target\n if (!project.targets.bundle) {\n project.targets.bundle = normalizeTargetKeyOrder({\n cache: true,\n // Declared rather than left to Nx's implicit `[\"default\", \"^default\"]`,\n // which reads a dependency's whole project directory: rolldown resolves\n // dependencies through the build artifacts `default` already tracks, so\n // `^default` only adds files no bundle can contain.\n inputs: ['default'],\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 addArtifactDependencyToTargets(project, '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', codeSplitting: false },\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","ROLLDOWN_CONFIG_BUNDLE_GLOB","updateGitIgnore","addArtifactDependencyToTargets","addDependencyToTargetIfNotPresent","normalizeTargetKeyOrder","getRelativePathToRoot","LAMBDA_RUNTIME_VERSIONS","withVersions","BUNDLE_DEPENDENCIES","name","createPythonBundleTarget","packageName","pythonPlatform","bundleTargetName","cache","inputs","executor","outputs","options","commands","python","parallel","addPythonBundleTarget","project","opts","targets","dependsOn","bundleOutputDir","root","addTypeScriptBundleTarget","tree","declaration","dirname","overwriteStrategy","KeepExisting","patterns","includes","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,YAAY;AACxC,SAEEC,eAAe,QAEV,8BAA8B;AACrC,SAASC,4BAA4B,QAAQ,qBAAqB;AAClE,SAASC,2BAA2B,QAAQ,eAAe;AAC3D,SAASC,eAAe,QAAQ,YAAY;AAC5C,SACEC,8BAA8B,EAC9BC,iCAAiC,EACjCC,uBAAuB,QAClB,WAAW;AAClB,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAEEC,uBAAuB,EACvBC,YAAY,QACP,iBAAiB;AAExB,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;QACP,0EAA0E;QAC1E,sDAAsD;QACtDC,QAAQ;YAAC;YAAc;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AAyE;IACzE,+EAA+E;IAC/E,MAAMS,WAAW,MAAMtD,YACrBiC,MACAU,oBACA,CAAC,6DAA6D,EAAEhB,KAAKyB,cAAc,CAAC,kBAAkB,EAAED,MAAM,GAAG,CAAC;IAGpH,IAAI,CAACG,UAAU;QACb,wEAAwE;QACxE,uEAAuE;QACvE,kEAAkE;QAClE,8DAA8D;QAC9D,MAAMC,WAAW,MAAMvD,YACrBiC,MACAU,oBACA,CAAC,2DAA2D,CAAC;QAE/D,IAAIY,UAAU;YACZ,MAAMvD,YACJiC,MACAU,oBACA,CAAC,kFAAkF,EAAEQ,MAAM,GAAG,CAAC;QAEnG;IACF;IAEAjD,6BACE+B,MACA,CAAC,GACDvB,aAAaT,gBAA4CiC,cAAc;QACrE;KACD;AAEL,EAAE"}
|
package/src/utils/docker.d.ts
CHANGED
|
@@ -6,13 +6,7 @@ import { type ProjectConfiguration, type Tree } from '@nx/devkit';
|
|
|
6
6
|
import { type DependencyDeclaration, type MustDeclare } from './declared-dependencies.js';
|
|
7
7
|
/** Dependencies a caller must declare to add a Docker scan target. */
|
|
8
8
|
export declare const DOCKER_DEPENDENCIES: readonly [{
|
|
9
|
-
readonly name: "
|
|
10
|
-
}, {
|
|
11
|
-
readonly name: "rimraf";
|
|
12
|
-
}, {
|
|
13
|
-
readonly name: "make-dir-cli";
|
|
14
|
-
}, {
|
|
15
|
-
readonly name: "cpy-cli";
|
|
9
|
+
readonly name: "shx";
|
|
16
10
|
}];
|
|
17
11
|
/**
|
|
18
12
|
* The `cache` setting every target that builds a container image must use.
|
package/src/utils/docker.js
CHANGED
|
@@ -95,7 +95,7 @@ const TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.
|
|
|
95
95
|
const commands = [
|
|
96
96
|
fs.rm(scanDir),
|
|
97
97
|
fs.mkdir(scanDir),
|
|
98
|
-
fs.
|
|
98
|
+
fs.cpFile(ignoreFilePath, joinPathFragments(scanDir, TRIVY_IGNORE_FILE))
|
|
99
99
|
];
|
|
100
100
|
imageTags.forEach((imageTag, index)=>{
|
|
101
101
|
const tarName = `image-${index}.tar`;
|
package/src/utils/docker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/docker.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport { FS_DEPENDENCIES, FsCommands } from './fs.js';\nimport { addDependencyToTargetIfNotPresent } from './nx.js';\nimport { containerImage, type ITsDepVersion, TS_VERSIONS } from './versions.js';\n\n/** Dependencies a caller must declare to add a Docker scan target. */\nexport const DOCKER_DEPENDENCIES = [...FS_DEPENDENCIES] as const;\n\n/**\n * The `cache` setting every target that builds a container image must use.\n *\n * A built image lives in the container engine's own store, not under any\n * `outputs` path, so Nx has nothing to restore a cache hit from: it would\n * report the build complete while the image is missing, and the `trivy` scan\n * that depends on it would report a cached pass against an image that isn't\n * there. The container engine's layer cache is the sound cache here — it is\n * keyed on the build context and lives alongside the image, so an unchanged\n * context rebuilds in well under a second and always leaves the image present.\n */\nexport const IMAGE_BUILD_CACHE = false;\n\nconst TRIVY_IGNORE_FILE = '.trivyignore';\n\nconst TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.g. CVE-2021-12345) per line to\n# suppress it during the image scan (\\`nx run-many --target trivy\\`).\n# https://trivy.dev/latest/docs/configuration/filtering/#by-finding-ids\n`;\n\n/**\n * Substitution variables for the vended Node `Dockerfile` templates: the npm\n * version to install globally, and the versions its dependency overrides pin.\n */\nexport const nodeImageVersions = () => ({\n npmVersion: TS_VERSIONS.npm,\n minimatchVersion: TS_VERSIONS.minimatch,\n});\n\n/**\n * Packages a vended Node `Dockerfile` pins, which every generator writing one\n * must declare so the version sync keeps those pins current.\n *\n * Spread through `ownedElsewhere`: the pin lives in the image build rather than\n * in any manifest, so nothing is installed into the workspace. Left undeclared\n * these would be the only vended versions never upgraded — and they are\n * precisely the ones held at a version clear of a known HIGH/CRITICAL\n * vulnerability.\n */\nexport const NODE_IMAGE_DEPENDENCIES = [\n { name: 'npm' },\n { name: 'minimatch' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\n/**\n * Packages the AWS Distro for OpenTelemetry install in a vended `Dockerfile`\n * pins, for the images that auto-instrument with it. Spread through\n * `ownedElsewhere` for the same reason as {@link NODE_IMAGE_DEPENDENCIES}.\n */\nexport const ADOT_IMAGE_DEPENDENCIES = [\n { name: '@aws/aws-distro-opentelemetry-node-autoinstrumentation' },\n { name: '@opentelemetry/propagator-jaeger' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface DockerScanTargetOptions {\n /**\n * Project configuration to add the scan target to (mutated in place).\n */\n readonly project: ProjectConfiguration;\n /**\n * Container engine command to invoke (\\`docker\\` or \\`finch\\`).\n */\n readonly containerEngine: string;\n /**\n * Name of the scan target to add, e.g. \\`my-agent-trivy\\`.\n */\n readonly trivyTargetName: string;\n /**\n * Name of the docker target that builds the image(s) to scan. The scan\n * target depends on it.\n */\n readonly dockerTargetName: string;\n /**\n * Tags of the images built by the docker target which should be scanned.\n */\n readonly imageTags: string[];\n}\n\n/**\n * Add a Trivy scan target for the images built by a docker target and wire it\n * under the aggregate \\`trivy\\` target. The scan is not part of \\`build\\` — run\n * \\`nx run-many --target trivy\\` (the root \\`trivy\\` script) in CI.\n *\n * The scan target depends on the docker target and is not cacheable, because\n * what it scans lives in the container engine rather than under its \\`outputs\\`.\n * Each image is saved to a tarball under \\`dist/<projectRoot>/trivy/<scan-key>\\`\n * (kept out of any Docker build context) and scanned with the pinned ECR-hosted\n * Trivy image via a workspace-relative bind mount, so the same commands work\n * under both docker and finch. The scan exits non-zero (exit code 1) on\n * HIGH/CRITICAL vulnerabilities.\n *\n * A \\`.trivyignore\\` is vended at the project root (kept if it already exists)\n * for suppressing findings.\n */\nexport const addDockerScanTarget = <const D extends DependencyDeclaration>(\n tree: Tree,\n options: DockerScanTargetOptions,\n declaration: D & MustDeclare<typeof DOCKER_DEPENDENCIES, D>,\n): void => {\n const { project, containerEngine, trivyTargetName, dockerTargetName } =\n options;\n const { imageTags } = options;\n const projectRoot = project.root;\n\n const ignoreFilePath = joinPathFragments(projectRoot, TRIVY_IGNORE_FILE);\n if (!tree.exists(ignoreFilePath)) {\n tree.write(ignoreFilePath, TRIVY_IGNORE_CONTENTS);\n }\n\n // Stage scan artifacts in a directory unique to this scan target so that\n // sibling targets in the same project (e.g. multiple agents) don't clobber\n // each other's tarballs when run in parallel. The first image tag is unique\n // per target, so it makes a stable, collision-free key.\n const scanKey = imageTags[0].replace(/[^a-zA-Z0-9-]/g, '-');\n const scanDir = joinPathFragments('dist', projectRoot, 'trivy', scanKey);\n const trivyImage = containerImage('trivy');\n\n const fs = new FsCommands(\n tree,\n forDependencies<typeof DOCKER_DEPENDENCIES>(declaration),\n );\n const commands = [\n fs.rm(scanDir),\n fs.mkdir(scanDir),\n fs.cp(ignoreFilePath, joinPathFragments(scanDir, TRIVY_IGNORE_FILE)),\n ];\n\n imageTags.forEach((imageTag, index) => {\n const tarName = `image-${index}.tar`;\n commands.push(\n `${containerEngine} save -o ${joinPathFragments(scanDir, tarName)} ${imageTag}`,\n `${containerEngine} run --rm -v \"./${scanDir}\":/scan ${trivyImage} image --input /scan/${tarName} --ignorefile /scan/${TRIVY_IGNORE_FILE} --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 --no-progress -q`,\n );\n });\n\n project.targets ??= {};\n project.targets[trivyTargetName] = {\n // The image being scanned is only reachable through the container engine,\n // so a restored cache entry would report a pass for an image that may no\n // longer exist. The scan re-runs and either scans the real image or fails.\n // Nx only hashes a cacheable task, so declaring `inputs` here would have no\n // effect.\n cache: false,\n outputs: [`{workspaceRoot}/${scanDir}`],\n executor: 'nx:run-commands',\n options: {\n commands,\n parallel: false,\n },\n dependsOn: [dockerTargetName],\n };\n\n // Aggregate per-component scan targets under a single `trivy` target. The\n // scan is intentionally NOT wired into `build`: image scanning is slow and\n // its result depends on the ever-changing vulnerability database (a scan\n // that passes today can fail tomorrow when a new CVE is published), so\n // coupling it to `build` would make local and CI builds non-deterministic.\n // Run `nx run-many --target trivy` (the root `trivy` script) in CI instead.\n if (trivyTargetName !== 'trivy') {\n addDependencyToTargetIfNotPresent(project, 'trivy', trivyTargetName);\n }\n};\n"],"names":["joinPathFragments","forDependencies","FS_DEPENDENCIES","FsCommands","addDependencyToTargetIfNotPresent","containerImage","TS_VERSIONS","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","TRIVY_IGNORE_FILE","TRIVY_IGNORE_CONTENTS","nodeImageVersions","npmVersion","npm","minimatchVersion","minimatch","NODE_IMAGE_DEPENDENCIES","name","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","tree","options","declaration","project","containerEngine","trivyTargetName","dockerTargetName","imageTags","projectRoot","root","ignoreFilePath","exists","write","scanKey","replace","scanDir","trivyImage","fs","commands","rm","mkdir","cp","forEach","imageTag","index","tarName","push","targets","cache","outputs","executor","parallel","dependsOn"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAEEC,eAAe,QAEV,6BAA6B;AACpC,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,iCAAiC,QAAQ,UAAU;AAC5D,SAASC,cAAc,EAAsBC,WAAW,QAAQ,gBAAgB;AAEhF,oEAAoE,GACpE,OAAO,MAAMC,sBAAsB;OAAIL;CAAgB,CAAU;AAEjE;;;;;;;;;;CAUC,GACD,OAAO,MAAMM,oBAAoB,MAAM;AAEvC,MAAMC,oBAAoB;AAE1B,MAAMC,wBAAwB,CAAC;;;AAG/B,CAAC;AAED;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,IAAO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,CAAC,EAAEF,UAAU,EAC/E,GAAGnB,gBAAgB,gBAAgB,EAAEW,QAAQ,QAAQ,EAAEC,WAAW,qBAAqB,EAAES,QAAQ,oBAAoB,EAAEpC,kBAAkB,yFAAyF,CAAC;IAEvO;IAEAc,QAAQwB,OAAO,KAAK,CAAC;IACrBxB,QAAQwB,OAAO,CAACtB,gBAAgB,GAAG;QACjC,0EAA0E;QAC1E,yEAAyE;QACzE,2EAA2E;QAC3E,4EAA4E;QAC5E,UAAU;QACVuB,OAAO;QACPC,SAAS;YAAC,CAAC,gBAAgB,EAAEd,SAAS;SAAC;QACvCe,UAAU;QACV7B,SAAS;YACPiB;YACAa,UAAU;QACZ;QACAC,WAAW;YAAC1B;SAAiB;IAC/B;IAEA,0EAA0E;IAC1E,2EAA2E;IAC3E,yEAAyE;IACzE,uEAAuE;IACvE,2EAA2E;IAC3E,4EAA4E;IAC5E,IAAID,oBAAoB,SAAS;QAC/BrB,kCAAkCmB,SAAS,SAASE;IACtD;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/docker.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport { FS_DEPENDENCIES, FsCommands } from './fs.js';\nimport { addDependencyToTargetIfNotPresent } from './nx.js';\nimport { containerImage, type ITsDepVersion, TS_VERSIONS } from './versions.js';\n\n/** Dependencies a caller must declare to add a Docker scan target. */\nexport const DOCKER_DEPENDENCIES = [...FS_DEPENDENCIES] as const;\n\n/**\n * The `cache` setting every target that builds a container image must use.\n *\n * A built image lives in the container engine's own store, not under any\n * `outputs` path, so Nx has nothing to restore a cache hit from: it would\n * report the build complete while the image is missing, and the `trivy` scan\n * that depends on it would report a cached pass against an image that isn't\n * there. The container engine's layer cache is the sound cache here — it is\n * keyed on the build context and lives alongside the image, so an unchanged\n * context rebuilds in well under a second and always leaves the image present.\n */\nexport const IMAGE_BUILD_CACHE = false;\n\nconst TRIVY_IGNORE_FILE = '.trivyignore';\n\nconst TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.g. CVE-2021-12345) per line to\n# suppress it during the image scan (\\`nx run-many --target trivy\\`).\n# https://trivy.dev/latest/docs/configuration/filtering/#by-finding-ids\n`;\n\n/**\n * Substitution variables for the vended Node `Dockerfile` templates: the npm\n * version to install globally, and the versions its dependency overrides pin.\n */\nexport const nodeImageVersions = () => ({\n npmVersion: TS_VERSIONS.npm,\n minimatchVersion: TS_VERSIONS.minimatch,\n});\n\n/**\n * Packages a vended Node `Dockerfile` pins, which every generator writing one\n * must declare so the version sync keeps those pins current.\n *\n * Spread through `ownedElsewhere`: the pin lives in the image build rather than\n * in any manifest, so nothing is installed into the workspace. Left undeclared\n * these would be the only vended versions never upgraded — and they are\n * precisely the ones held at a version clear of a known HIGH/CRITICAL\n * vulnerability.\n */\nexport const NODE_IMAGE_DEPENDENCIES = [\n { name: 'npm' },\n { name: 'minimatch' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\n/**\n * Packages the AWS Distro for OpenTelemetry install in a vended `Dockerfile`\n * pins, for the images that auto-instrument with it. Spread through\n * `ownedElsewhere` for the same reason as {@link NODE_IMAGE_DEPENDENCIES}.\n */\nexport const ADOT_IMAGE_DEPENDENCIES = [\n { name: '@aws/aws-distro-opentelemetry-node-autoinstrumentation' },\n { name: '@opentelemetry/propagator-jaeger' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport interface DockerScanTargetOptions {\n /**\n * Project configuration to add the scan target to (mutated in place).\n */\n readonly project: ProjectConfiguration;\n /**\n * Container engine command to invoke (\\`docker\\` or \\`finch\\`).\n */\n readonly containerEngine: string;\n /**\n * Name of the scan target to add, e.g. \\`my-agent-trivy\\`.\n */\n readonly trivyTargetName: string;\n /**\n * Name of the docker target that builds the image(s) to scan. The scan\n * target depends on it.\n */\n readonly dockerTargetName: string;\n /**\n * Tags of the images built by the docker target which should be scanned.\n */\n readonly imageTags: string[];\n}\n\n/**\n * Add a Trivy scan target for the images built by a docker target and wire it\n * under the aggregate \\`trivy\\` target. The scan is not part of \\`build\\` — run\n * \\`nx run-many --target trivy\\` (the root \\`trivy\\` script) in CI.\n *\n * The scan target depends on the docker target and is not cacheable, because\n * what it scans lives in the container engine rather than under its \\`outputs\\`.\n * Each image is saved to a tarball under \\`dist/<projectRoot>/trivy/<scan-key>\\`\n * (kept out of any Docker build context) and scanned with the pinned ECR-hosted\n * Trivy image via a workspace-relative bind mount, so the same commands work\n * under both docker and finch. The scan exits non-zero (exit code 1) on\n * HIGH/CRITICAL vulnerabilities.\n *\n * A \\`.trivyignore\\` is vended at the project root (kept if it already exists)\n * for suppressing findings.\n */\nexport const addDockerScanTarget = <const D extends DependencyDeclaration>(\n tree: Tree,\n options: DockerScanTargetOptions,\n declaration: D & MustDeclare<typeof DOCKER_DEPENDENCIES, D>,\n): void => {\n const { project, containerEngine, trivyTargetName, dockerTargetName } =\n options;\n const { imageTags } = options;\n const projectRoot = project.root;\n\n const ignoreFilePath = joinPathFragments(projectRoot, TRIVY_IGNORE_FILE);\n if (!tree.exists(ignoreFilePath)) {\n tree.write(ignoreFilePath, TRIVY_IGNORE_CONTENTS);\n }\n\n // Stage scan artifacts in a directory unique to this scan target so that\n // sibling targets in the same project (e.g. multiple agents) don't clobber\n // each other's tarballs when run in parallel. The first image tag is unique\n // per target, so it makes a stable, collision-free key.\n const scanKey = imageTags[0].replace(/[^a-zA-Z0-9-]/g, '-');\n const scanDir = joinPathFragments('dist', projectRoot, 'trivy', scanKey);\n const trivyImage = containerImage('trivy');\n\n const fs = new FsCommands(\n tree,\n forDependencies<typeof DOCKER_DEPENDENCIES>(declaration),\n );\n const commands = [\n fs.rm(scanDir),\n fs.mkdir(scanDir),\n fs.cpFile(ignoreFilePath, joinPathFragments(scanDir, TRIVY_IGNORE_FILE)),\n ];\n\n imageTags.forEach((imageTag, index) => {\n const tarName = `image-${index}.tar`;\n commands.push(\n `${containerEngine} save -o ${joinPathFragments(scanDir, tarName)} ${imageTag}`,\n `${containerEngine} run --rm -v \"./${scanDir}\":/scan ${trivyImage} image --input /scan/${tarName} --ignorefile /scan/${TRIVY_IGNORE_FILE} --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 --no-progress -q`,\n );\n });\n\n project.targets ??= {};\n project.targets[trivyTargetName] = {\n // The image being scanned is only reachable through the container engine,\n // so a restored cache entry would report a pass for an image that may no\n // longer exist. The scan re-runs and either scans the real image or fails.\n // Nx only hashes a cacheable task, so declaring `inputs` here would have no\n // effect.\n cache: false,\n outputs: [`{workspaceRoot}/${scanDir}`],\n executor: 'nx:run-commands',\n options: {\n commands,\n parallel: false,\n },\n dependsOn: [dockerTargetName],\n };\n\n // Aggregate per-component scan targets under a single `trivy` target. The\n // scan is intentionally NOT wired into `build`: image scanning is slow and\n // its result depends on the ever-changing vulnerability database (a scan\n // that passes today can fail tomorrow when a new CVE is published), so\n // coupling it to `build` would make local and CI builds non-deterministic.\n // Run `nx run-many --target trivy` (the root `trivy` script) in CI instead.\n if (trivyTargetName !== 'trivy') {\n addDependencyToTargetIfNotPresent(project, 'trivy', trivyTargetName);\n }\n};\n"],"names":["joinPathFragments","forDependencies","FS_DEPENDENCIES","FsCommands","addDependencyToTargetIfNotPresent","containerImage","TS_VERSIONS","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","TRIVY_IGNORE_FILE","TRIVY_IGNORE_CONTENTS","nodeImageVersions","npmVersion","npm","minimatchVersion","minimatch","NODE_IMAGE_DEPENDENCIES","name","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","tree","options","declaration","project","containerEngine","trivyTargetName","dockerTargetName","imageTags","projectRoot","root","ignoreFilePath","exists","write","scanKey","replace","scanDir","trivyImage","fs","commands","rm","mkdir","cpFile","forEach","imageTag","index","tarName","push","targets","cache","outputs","executor","parallel","dependsOn"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAEEC,eAAe,QAEV,6BAA6B;AACpC,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,iCAAiC,QAAQ,UAAU;AAC5D,SAASC,cAAc,EAAsBC,WAAW,QAAQ,gBAAgB;AAEhF,oEAAoE,GACpE,OAAO,MAAMC,sBAAsB;OAAIL;CAAgB,CAAU;AAEjE;;;;;;;;;;CAUC,GACD,OAAO,MAAMM,oBAAoB,MAAM;AAEvC,MAAMC,oBAAoB;AAE1B,MAAMC,wBAAwB,CAAC;;;AAG/B,CAAC;AAED;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,IAAO,CAAA;QACtCC,YAAYN,YAAYO,GAAG;QAC3BC,kBAAkBR,YAAYS,SAAS;IACzC,CAAA,EAAG;AAEH;;;;;;;;;CASC,GACD,OAAO,MAAMC,0BAA0B;IACrC;QAAEC,MAAM;IAAM;IACd;QAAEA,MAAM;IAAY;CACrB,CAAuD;AAExD;;;;CAIC,GACD,OAAO,MAAMC,0BAA0B;IACrC;QAAED,MAAM;IAAyD;IACjE;QAAEA,MAAM;IAAmC;CAC5C,CAAuD;AA0BxD;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAME,sBAAsB,CACjCC,MACAC,SACAC;IAEA,MAAM,EAAEC,OAAO,EAAEC,eAAe,EAAEC,eAAe,EAAEC,gBAAgB,EAAE,GACnEL;IACF,MAAM,EAAEM,SAAS,EAAE,GAAGN;IACtB,MAAMO,cAAcL,QAAQM,IAAI;IAEhC,MAAMC,iBAAiB9B,kBAAkB4B,aAAanB;IACtD,IAAI,CAACW,KAAKW,MAAM,CAACD,iBAAiB;QAChCV,KAAKY,KAAK,CAACF,gBAAgBpB;IAC7B;IAEA,yEAAyE;IACzE,2EAA2E;IAC3E,4EAA4E;IAC5E,wDA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|
|
3
3
|
|
|
4
|
-
import { cn } from "
|
|
4
|
+
import { cn } from "#lib/utils"
|
|
5
5
|
|
|
6
6
|
const alertVariants = cva(
|
|
7
7
|
"relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
|
@@ -2,7 +2,7 @@ import * as React from "react"
|
|
|
2
2
|
import { ChevronRight, MoreHorizontal } from "lucide-react"
|
|
3
3
|
import { Slot } from "radix-ui"
|
|
4
4
|
|
|
5
|
-
import { cn } from "
|
|
5
|
+
import { cn } from "#lib/utils"
|
|
6
6
|
|
|
7
7
|
function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
|
|
8
8
|
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />
|
|
@@ -2,7 +2,7 @@ import * as React from "react"
|
|
|
2
2
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
3
|
import { Slot } from "radix-ui"
|
|
4
4
|
|
|
5
|
-
import { cn } from "
|
|
5
|
+
import { cn } from "#lib/utils"
|
|
6
6
|
|
|
7
7
|
const buttonVariants = cva(
|
|
8
8
|
"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
@@ -4,7 +4,7 @@ import * as React from "react"
|
|
|
4
4
|
import { XIcon } from "lucide-react"
|
|
5
5
|
import { Dialog as SheetPrimitive } from "radix-ui"
|
|
6
6
|
|
|
7
|
-
import { cn } from "
|
|
7
|
+
import { cn } from "#lib/utils"
|
|
8
8
|
|
|
9
9
|
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
|
10
10
|
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
|
@@ -5,25 +5,25 @@ import { cva, type VariantProps } from "class-variance-authority"
|
|
|
5
5
|
import { PanelLeftIcon } from "lucide-react"
|
|
6
6
|
import { Slot } from "radix-ui"
|
|
7
7
|
|
|
8
|
-
import { useIsMobile } from "
|
|
9
|
-
import { cn } from "
|
|
10
|
-
import { Button } from "
|
|
11
|
-
import { Input } from "
|
|
12
|
-
import { Separator } from "
|
|
8
|
+
import { useIsMobile } from "#hooks/use-mobile"
|
|
9
|
+
import { cn } from "#lib/utils"
|
|
10
|
+
import { Button } from "#components/ui/button"
|
|
11
|
+
import { Input } from "#components/ui/input"
|
|
12
|
+
import { Separator } from "#components/ui/separator"
|
|
13
13
|
import {
|
|
14
14
|
Sheet,
|
|
15
15
|
SheetContent,
|
|
16
16
|
SheetDescription,
|
|
17
17
|
SheetHeader,
|
|
18
18
|
SheetTitle,
|
|
19
|
-
} from "
|
|
20
|
-
import { Skeleton } from "
|
|
19
|
+
} from "#components/ui/sheet"
|
|
20
|
+
import { Skeleton } from "#components/ui/skeleton"
|
|
21
21
|
import {
|
|
22
22
|
Tooltip,
|
|
23
23
|
TooltipContent,
|
|
24
24
|
TooltipProvider,
|
|
25
25
|
TooltipTrigger,
|
|
26
|
-
} from "
|
|
26
|
+
} from "#components/ui/tooltip"
|
|
27
27
|
|
|
28
28
|
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
|
29
29
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
},
|
|
12
12
|
"iconLibrary": "lucide",
|
|
13
13
|
"aliases": {
|
|
14
|
-
"components": "
|
|
15
|
-
"utils": "
|
|
16
|
-
"hooks": "
|
|
17
|
-
"lib": "
|
|
18
|
-
"ui": "
|
|
14
|
+
"components": "#components",
|
|
15
|
+
"utils": "#lib/utils",
|
|
16
|
+
"hooks": "#hooks",
|
|
17
|
+
"lib": "#lib",
|
|
18
|
+
"ui": "#components/ui"
|
|
19
19
|
}
|
|
20
20
|
}
|
package/src/utils/format.d.ts
CHANGED
|
@@ -3,11 +3,32 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { type Tree } from '@nx/devkit';
|
|
6
|
+
/**
|
|
7
|
+
* The Biome release the wasm bindings are built from. Must match
|
|
8
|
+
* `TS_VERSIONS['@biomejs/biome']`, the CLI the vended targets run.
|
|
9
|
+
*/
|
|
10
|
+
export declare const BIOME_WASM_VERSION: string;
|
|
6
11
|
/**
|
|
7
12
|
* Excludes test reports — including the vendored scripts vitest's coverage HTML
|
|
8
13
|
* reporter writes — from formatting and linting.
|
|
9
14
|
*/
|
|
10
15
|
export declare const BIOME_TEST_OUTPUT_EXCLUDE = "!**/test-output";
|
|
16
|
+
/**
|
|
17
|
+
* The transient bundle rolldown writes beside a `rolldown.config.ts` while
|
|
18
|
+
* loading it.
|
|
19
|
+
*
|
|
20
|
+
* Loading a TypeScript config bundles it to `rolldown.config.<hash>.js` in the
|
|
21
|
+
* config's own directory, imports it, then unlinks it. That file exists for as
|
|
22
|
+
* long as the bundle takes, so a `format` or `lint` target running concurrently
|
|
23
|
+
* in the same project sees a machine-generated file — reported unformatted,
|
|
24
|
+
* failing the target for no fault of the source.
|
|
25
|
+
*
|
|
26
|
+
* `.*js` rather than `.js`, since the extension follows the config's own: a
|
|
27
|
+
* `.mts` config bundles to `.mjs`, a `.cts` one to `.cjs`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ROLLDOWN_CONFIG_BUNDLE_GLOB = "**/rolldown.config.*.*js";
|
|
30
|
+
/** Keeps rolldown's transient config bundle out of formatting and linting. */
|
|
31
|
+
export declare const BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE = "!**/rolldown.config.*.*js";
|
|
11
32
|
/**
|
|
12
33
|
* The biome.json vended into a new workspace. The pnpm catalog resolver is only
|
|
13
34
|
* included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only
|
package/src/utils/format.js
CHANGED
|
@@ -3,14 +3,33 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { Biome } from "@biomejs/js-api/nodejs";
|
|
5
5
|
import { getProjects } from "@nx/devkit";
|
|
6
|
+
import { createRequire } from "module";
|
|
6
7
|
import path from "path";
|
|
7
8
|
import { ruffFixAndFormat } from "./ruff.js";
|
|
8
9
|
import { tryReadToml } from "./toml.js";
|
|
9
10
|
import { TS_VERSIONS } from "./versions.js";
|
|
11
|
+
/**
|
|
12
|
+
* The Biome release the wasm bindings are built from. Must match
|
|
13
|
+
* `TS_VERSIONS['@biomejs/biome']`, the CLI the vended targets run.
|
|
14
|
+
*/ export const BIOME_WASM_VERSION = createRequire(import.meta.url)('@biomejs/wasm-nodejs/package.json').version;
|
|
10
15
|
/**
|
|
11
16
|
* Excludes test reports — including the vendored scripts vitest's coverage HTML
|
|
12
17
|
* reporter writes — from formatting and linting.
|
|
13
18
|
*/ export const BIOME_TEST_OUTPUT_EXCLUDE = '!**/test-output';
|
|
19
|
+
/**
|
|
20
|
+
* The transient bundle rolldown writes beside a `rolldown.config.ts` while
|
|
21
|
+
* loading it.
|
|
22
|
+
*
|
|
23
|
+
* Loading a TypeScript config bundles it to `rolldown.config.<hash>.js` in the
|
|
24
|
+
* config's own directory, imports it, then unlinks it. That file exists for as
|
|
25
|
+
* long as the bundle takes, so a `format` or `lint` target running concurrently
|
|
26
|
+
* in the same project sees a machine-generated file — reported unformatted,
|
|
27
|
+
* failing the target for no fault of the source.
|
|
28
|
+
*
|
|
29
|
+
* `.*js` rather than `.js`, since the extension follows the config's own: a
|
|
30
|
+
* `.mts` config bundles to `.mjs`, a `.cts` one to `.cjs`.
|
|
31
|
+
*/ export const ROLLDOWN_CONFIG_BUNDLE_GLOB = '**/rolldown.config.*.*js';
|
|
32
|
+
/** Keeps rolldown's transient config bundle out of formatting and linting. */ export const BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE = `!${ROLLDOWN_CONFIG_BUNDLE_GLOB}`;
|
|
14
33
|
/**
|
|
15
34
|
* The biome.json vended into a new workspace. The pnpm catalog resolver is only
|
|
16
35
|
* included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only
|
|
@@ -69,6 +88,7 @@ import { TS_VERSIONS } from "./versions.js";
|
|
|
69
88
|
'!**/dist',
|
|
70
89
|
'!**/out-tsc',
|
|
71
90
|
BIOME_TEST_OUTPUT_EXCLUDE,
|
|
91
|
+
BIOME_ROLLDOWN_CONFIG_BUNDLE_EXCLUDE,
|
|
72
92
|
'!**/node_modules',
|
|
73
93
|
'!**/.nx',
|
|
74
94
|
'!**/.venv',
|