@aws/nx-plugin 1.0.0-rc.46 → 1.0.0-rc.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-THIRD-PARTY +3 -60
- package/generators.json +1 -1
- package/package.json +7 -6
- package/src/agentcore-gateway/generator.js +12 -2
- package/src/agentcore-gateway/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +25 -31
- package/src/infra/app/generator.js +9 -6
- package/src/infra/app/generator.js.map +1 -1
- package/src/license/config.js +1 -1
- package/src/license/config.js.map +1 -1
- package/src/mcp-server/dev-server.d.ts +1 -0
- package/src/mcp-server/dev-server.js +18 -0
- package/src/mcp-server/dev-server.js.map +1 -0
- package/src/mcp-server/schema.d.ts +1 -1
- package/src/mcp-server/tools/general-guidance.js +5 -6
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +42 -7
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +4 -2
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.js.map +1 -1
- package/src/preset/schema.d.ts +1 -0
- package/src/preset/schema.json +5 -0
- package/src/py/agent/generator.js +2 -1
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/mcp-server/generator.js +2 -1
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/project/generator.js +2 -1
- package/src/py/project/generator.js.map +1 -1
- package/src/py/rdb/generator.js +2 -1
- package/src/py/rdb/generator.js.map +1 -1
- package/src/smithy/ts/api/generator.js +5 -2
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/terraform/project/generator.js +4 -1
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +6 -6
- package/src/trpc/backend/generator.js +7 -5
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/react/generator.js +4 -4
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +9 -5
- package/src/ts/agent/a2a-connection/generator.js +3 -2
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/deploy/Dockerfile.template +7 -3
- package/src/ts/agent/gateway-connection/generator.js +4 -3
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +10 -7
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/agent/mcp-connection/generator.js +4 -3
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/agent/react-connection/generator.js +10 -19
- package/src/ts/agent/react-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/generator.js +12 -3
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dcr-proxy/generator.js +5 -5
- package/src/ts/dcr-proxy/generator.js.map +1 -1
- package/src/ts/dynamodb/generator.js +5 -2
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +4 -2
- package/src/ts/lambda-function/files/handler/__lambdaFunctionKebabCase__.ts.template +2 -1
- package/src/ts/lambda-function/generator.js +3 -2
- package/src/ts/lambda-function/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +17 -10
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.js +2 -1
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/files/Dockerfile.template +7 -3
- package/src/ts/mcp-server/generator.js +13 -13
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/generator.js +5 -0
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +5 -6
- package/src/ts/nx-plugin/files/mcp-server/resources/GENERAL_GUIDANCE.md.template +5 -6
- package/src/ts/nx-plugin/utils.js +8 -10
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +11 -3
- package/src/ts/rdb/agent-connection/generator.js +1 -2
- package/src/ts/rdb/agent-connection/generator.js.map +1 -1
- package/src/ts/rdb/files/Dockerfile.template +5 -1
- package/src/ts/rdb/files/src/migration-handler.ts.template +3 -1
- package/src/ts/rdb/generator.js +12 -8
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/rdb/mcp-server-connection/generator.js +1 -2
- package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -1
- package/src/ts/rdb/smithy-connection/generator.js +1 -2
- package/src/ts/rdb/smithy-connection/generator.js.map +1 -1
- package/src/ts/rdb/trpc-connection/generator.js +1 -2
- package/src/ts/rdb/trpc-connection/generator.js.map +1 -1
- package/src/ts/react-website/agui/generator.js +5 -4
- package/src/ts/react-website/agui/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +210 -79
- package/src/ts/react-website/app/generator.js +34 -14
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/react-website/cognito-auth/generator.js +3 -2
- package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
- package/src/ts/react-website/runtime-config/generator.js +2 -2
- package/src/ts/react-website/runtime-config/generator.js.map +1 -1
- package/src/ts/sync/generator.js +81 -3
- package/src/ts/sync/generator.js.map +1 -1
- package/src/utils/agent-connection/agent-connection.d.ts +1 -1
- package/src/utils/agent-connection/agent-connection.js +50 -1
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +19 -1
- package/src/utils/api-constructs/api-constructs.js +15 -1
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/bundle/bundle.js +2 -1
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/commands.d.ts +5 -3
- package/src/utils/commands.js +24 -3
- package/src/utils/commands.js.map +1 -1
- package/src/utils/config/index.d.ts +16 -0
- package/src/utils/config/index.js.map +1 -1
- package/src/utils/config/utils.d.ts +3 -2
- package/src/utils/config/utils.js +4 -3
- package/src/utils/config/utils.js.map +1 -1
- package/src/utils/connection/open-api/react.js +3 -2
- package/src/utils/connection/open-api/react.js.map +1 -1
- package/src/utils/containers.js +1 -1
- package/src/utils/containers.js.map +1 -1
- package/src/utils/dependencies.d.ts +18 -0
- package/src/utils/dependencies.js +206 -0
- package/src/utils/dependencies.js.map +1 -0
- package/src/utils/docker.d.ts +8 -0
- package/src/utils/docker.js +8 -1
- package/src/utils/docker.js.map +1 -1
- package/src/utils/files/common/shadcn/readme/README.md.template +3 -3
- package/src/utils/files/shadcn/components.json.template +1 -1
- package/src/utils/format.d.ts +20 -1
- package/src/utils/format.js +137 -74
- package/src/utils/format.js.map +1 -1
- package/src/utils/fs.d.ts +1 -1
- package/src/utils/fs.js +1 -1
- package/src/utils/fs.js.map +1 -1
- package/src/utils/iac.js +1 -1
- package/src/utils/iac.js.map +1 -1
- package/src/utils/init.d.ts +7 -1
- package/src/utils/init.js +45 -19
- package/src/utils/init.js.map +1 -1
- package/src/utils/install.js +3 -1
- package/src/utils/install.js.map +1 -1
- package/src/utils/mcp.d.ts +9 -0
- package/src/utils/mcp.js +9 -1
- package/src/utils/mcp.js.map +1 -1
- package/src/utils/module-format.d.ts +5 -8
- package/src/utils/module-format.js +29 -12
- package/src/utils/module-format.js.map +1 -1
- package/src/utils/npm-scope.d.ts +0 -4
- package/src/utils/npm-scope.js +0 -5
- package/src/utils/npm-scope.js.map +1 -1
- package/src/utils/nx.d.ts +13 -0
- package/src/utils/nx.js +24 -1
- package/src/utils/nx.js.map +1 -1
- package/src/utils/pnpm-workspace.d.ts +1 -12
- package/src/utils/pnpm-workspace.js +3 -30
- package/src/utils/pnpm-workspace.js.map +1 -1
- package/src/utils/project-package-json.d.ts +39 -0
- package/src/utils/project-package-json.js +119 -0
- package/src/utils/project-package-json.js.map +1 -0
- package/src/utils/shared-constructs.js +6 -5
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-dynamodb-scripts.js +4 -2
- package/src/utils/shared-dynamodb-scripts.js.map +1 -1
- package/src/utils/shared-infra-scripts.js +5 -4
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-rdb-scripts.js +14 -1
- package/src/utils/shared-rdb-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.js +11 -8
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test-git.d.ts +39 -0
- package/src/utils/test-git.js +117 -0
- package/src/utils/test-git.js.map +1 -0
- package/src/utils/test.js +8 -3
- package/src/utils/test.js.map +1 -1
- package/src/utils/versions.d.ts +7 -1
- package/src/utils/versions.js +13 -2
- package/src/utils/versions.js.map +1 -1
- package/src/bin/aws-nx-mcp.d.ts +0 -2
- package/src/bin/aws-nx-mcp.js +0 -14
- package/src/bin/aws-nx-mcp.js.map +0 -1
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 { FsCommands } from './fs';\nimport { addDependencyToTargetIfNotPresent } from './nx';\nimport { CONTAINER_VERSIONS } from './versions';\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\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 cacheable Trivy scan target for the images built by a docker target\n * and wire it under the aggregate \\`trivy\\` target. The scan is not part of\n * \\`build\\` — run \\`nx run-many --target trivy\\` (the root \\`trivy\\` script) in CI.\n *\n * The scan target depends on the docker target and declares the project source\n * as its inputs, so an unchanged image is never re-scanned (a cache hit skips\n * the scan entirely). Each image is saved to a tarball under\n * \\`dist/<projectRoot>/trivy/<scan-key>\\` (kept out of any Docker build context)\n * and scanned with the pinned ECR-hosted Trivy image via a workspace-relative\n * bind mount, so the same commands work under both docker and finch. The scan\n * exits non-zero (exit code 1) on 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 = (\n tree: Tree,\n options: DockerScanTargetOptions,\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 = `public.ecr.aws/aquasecurity/trivy:${CONTAINER_VERSIONS.trivy}`;\n\n const fs = new FsCommands(tree);\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 cache: true,\n // The scanned image is fully determined by the project source, so caching\n // on the source ensures an unchanged image is never re-scanned.\n inputs: ['default', '^production'],\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","FsCommands","addDependencyToTargetIfNotPresent","CONTAINER_VERSIONS","TRIVY_IGNORE_FILE","TRIVY_IGNORE_CONTENTS","addDockerScanTarget","tree","options","project","containerEngine","trivyTargetName","dockerTargetName","imageTags","projectRoot","root","ignoreFilePath","exists","write","scanKey","replace","scanDir","trivyImage","trivy","fs","commands","rm","mkdir","cp","forEach","imageTag","index","tarName","push","targets","cache","inputs","outputs","executor","parallel","dependsOn"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAASC,UAAU,QAAQ,UAAO;AAClC,SAASC,iCAAiC,QAAQ,UAAO;AACzD,SAASC,kBAAkB,QAAQ,gBAAa;
|
|
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 { FsCommands } from './fs';\nimport { addDependencyToTargetIfNotPresent } from './nx';\nimport { CONTAINER_VERSIONS, TS_VERSIONS } from './versions';\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\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 cacheable Trivy scan target for the images built by a docker target\n * and wire it under the aggregate \\`trivy\\` target. The scan is not part of\n * \\`build\\` — run \\`nx run-many --target trivy\\` (the root \\`trivy\\` script) in CI.\n *\n * The scan target depends on the docker target and declares the project source\n * as its inputs, so an unchanged image is never re-scanned (a cache hit skips\n * the scan entirely). Each image is saved to a tarball under\n * \\`dist/<projectRoot>/trivy/<scan-key>\\` (kept out of any Docker build context)\n * and scanned with the pinned ECR-hosted Trivy image via a workspace-relative\n * bind mount, so the same commands work under both docker and finch. The scan\n * exits non-zero (exit code 1) on 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 = (\n tree: Tree,\n options: DockerScanTargetOptions,\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 = `public.ecr.aws/aquasecurity/trivy:${CONTAINER_VERSIONS.trivy}`;\n\n const fs = new FsCommands(tree);\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 cache: true,\n // The scanned image is fully determined by the project source, so caching\n // on the source ensures an unchanged image is never re-scanned.\n inputs: ['default', '^production'],\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","FsCommands","addDependencyToTargetIfNotPresent","CONTAINER_VERSIONS","TS_VERSIONS","TRIVY_IGNORE_FILE","TRIVY_IGNORE_CONTENTS","nodeImageVersions","npmVersion","npm","minimatchVersion","minimatch","addDockerScanTarget","tree","options","project","containerEngine","trivyTargetName","dockerTargetName","imageTags","projectRoot","root","ignoreFilePath","exists","write","scanKey","replace","scanDir","trivyImage","trivy","fs","commands","rm","mkdir","cp","forEach","imageTag","index","tarName","push","targets","cache","inputs","outputs","executor","parallel","dependsOn"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAASC,UAAU,QAAQ,UAAO;AAClC,SAASC,iCAAiC,QAAQ,UAAO;AACzD,SAASC,kBAAkB,EAAEC,WAAW,QAAQ,gBAAa;AAE7D,MAAMC,oBAAoB;AAE1B,MAAMC,wBAAwB,CAAC;;;AAG/B,CAAC;AAED;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,IAAO,CAAA;QACtCC,YAAYJ,YAAYK,GAAG;QAC3BC,kBAAkBN,YAAYO,SAAS;IACzC,CAAA,EAAG;AA0BH;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,sBAAsB,CACjCC,MACAC;IAEA,MAAM,EAAEC,OAAO,EAAEC,eAAe,E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B;YACAc,UAAU;QACZ;QACAC,WAAW;YAAC5B;SAAiB;IAC/B;IAEA,0EAA0E;IAC1E,2EAA2E;IAC3E,yEAAyE;IACzE,uEAAuE;IACvE,2EAA2E;IAC3E,4EAA4E;IAC5E,IAAID,oBAAoB,SAAS;QAC/Bf,kCAAkCa,SAAS,SAASE;IACtD;AACF,EAAE"}
|
|
@@ -5,9 +5,9 @@ This package centralises Shadcn UI components that are shared between your React
|
|
|
5
5
|
- Components live under `packages/common/shadcn/src/components`
|
|
6
6
|
- Utilities live under `packages/common/shadcn/src/lib`
|
|
7
7
|
- Hooks live under `packages/common/shadcn/src/hooks`
|
|
8
|
-
- Global styles are defined in `packages/common/shadcn/src/styles.css`
|
|
8
|
+
- Global styles are defined in `packages/common/shadcn/src/styles/globals.css`
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
This package contains a `components.json`, so you can add new components by running the following from `packages/common/shadcn`:
|
|
11
11
|
|
|
12
12
|
With npm:
|
|
13
13
|
```bash
|
|
@@ -29,4 +29,4 @@ With bun:
|
|
|
29
29
|
bunx --bun shadcn@latest add <component>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Running from this directory means any dependencies a component needs are installed into this package's `package.json`.
|
package/src/utils/format.d.ts
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { type Tree } from '@nx/devkit';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The biome.json vended into a new workspace. The pnpm catalog resolver is only
|
|
8
|
+
* included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only
|
|
9
|
+
* catalog resolver and reads `pnpm-workspace.yaml` exclusively — it does nothing
|
|
10
|
+
* for yarn or bun catalogs, so vending it there would be misleading.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDefaultBiomeConfig: (tree: Tree) => {
|
|
7
13
|
$schema: string;
|
|
8
14
|
root: boolean;
|
|
9
15
|
formatter: {
|
|
@@ -13,6 +19,9 @@ export declare const DEFAULT_BIOME_CONFIG: {
|
|
|
13
19
|
lineWidth: number;
|
|
14
20
|
};
|
|
15
21
|
javascript: {
|
|
22
|
+
resolver?: {
|
|
23
|
+
experimentalPnpmCatalogs: boolean;
|
|
24
|
+
};
|
|
16
25
|
formatter: {
|
|
17
26
|
quoteStyle: string;
|
|
18
27
|
trailingCommas: string;
|
|
@@ -45,6 +54,16 @@ export declare const DEFAULT_BIOME_CONFIG: {
|
|
|
45
54
|
files: {
|
|
46
55
|
includes: string[];
|
|
47
56
|
};
|
|
57
|
+
overrides: {
|
|
58
|
+
includes: string[];
|
|
59
|
+
linter: {
|
|
60
|
+
rules: {
|
|
61
|
+
correctness: {
|
|
62
|
+
noUndeclaredDependencies: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}[];
|
|
48
67
|
};
|
|
49
68
|
/**
|
|
50
69
|
* Format files in the given directory within the tree.
|
package/src/utils/format.js
CHANGED
|
@@ -11,60 +11,94 @@ import { uvxCommand } from "./py.js";
|
|
|
11
11
|
import { readToml } from "./toml.js";
|
|
12
12
|
import { TS_VERSIONS } from "./versions.js";
|
|
13
13
|
const require = createRequire(import.meta.url);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
javascript: {
|
|
24
|
-
formatter: {
|
|
25
|
-
quoteStyle: 'single',
|
|
26
|
-
trailingCommas: 'all'
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
css: {
|
|
14
|
+
/**
|
|
15
|
+
* The biome.json vended into a new workspace. The pnpm catalog resolver is only
|
|
16
|
+
* included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only
|
|
17
|
+
* catalog resolver and reads `pnpm-workspace.yaml` exclusively — it does nothing
|
|
18
|
+
* for yarn or bun catalogs, so vending it there would be misleading.
|
|
19
|
+
*/ export const getDefaultBiomeConfig = (tree)=>({
|
|
20
|
+
$schema: `https://biomejs.dev/schemas/${TS_VERSIONS['@biomejs/biome']}/schema.json`,
|
|
21
|
+
root: true,
|
|
30
22
|
formatter: {
|
|
31
|
-
|
|
23
|
+
enabled: true,
|
|
24
|
+
indentStyle: 'space',
|
|
25
|
+
indentWidth: 2,
|
|
26
|
+
lineWidth: 80
|
|
27
|
+
},
|
|
28
|
+
javascript: {
|
|
29
|
+
formatter: {
|
|
30
|
+
quoteStyle: 'single',
|
|
31
|
+
trailingCommas: 'all'
|
|
32
|
+
},
|
|
33
|
+
// Resolve `catalog:` versions from pnpm-workspace.yaml (pnpm workspaces only).
|
|
34
|
+
...tree.exists('pnpm-workspace.yaml') ? {
|
|
35
|
+
resolver: {
|
|
36
|
+
experimentalPnpmCatalogs: true
|
|
37
|
+
}
|
|
38
|
+
} : {}
|
|
39
|
+
},
|
|
40
|
+
css: {
|
|
41
|
+
formatter: {
|
|
42
|
+
quoteStyle: 'single'
|
|
43
|
+
},
|
|
44
|
+
linter: {
|
|
45
|
+
enabled: false
|
|
46
|
+
}
|
|
32
47
|
},
|
|
33
48
|
linter: {
|
|
34
|
-
enabled:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
noUndeclaredDependencies: 'warn'
|
|
49
|
+
enabled: true,
|
|
50
|
+
rules: {
|
|
51
|
+
preset: 'none',
|
|
52
|
+
correctness: {
|
|
53
|
+
// Every project must declare the third-party dependencies its source
|
|
54
|
+
// code imports in its own package.json.
|
|
55
|
+
noUndeclaredDependencies: 'error'
|
|
56
|
+
}
|
|
43
57
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
},
|
|
59
|
+
assist: {
|
|
60
|
+
actions: {
|
|
61
|
+
source: {
|
|
62
|
+
organizeImports: 'on'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
files: {
|
|
67
|
+
includes: [
|
|
68
|
+
'**',
|
|
69
|
+
'!**/dist',
|
|
70
|
+
'!**/out-tsc',
|
|
71
|
+
'!**/node_modules',
|
|
72
|
+
'!**/.nx',
|
|
73
|
+
'!**/.venv',
|
|
74
|
+
// GritQL codemod cache written by generators — its sample sources
|
|
75
|
+
// otherwise pollute a bare `biome check .` with parse errors.
|
|
76
|
+
'!**/.grit',
|
|
77
|
+
'!**/*.css',
|
|
78
|
+
'!**/*.gen.*',
|
|
79
|
+
'!**/generated/**',
|
|
80
|
+
'!**/tsconfig*.json'
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
// Config files, build scripts and tests use root tooling rather than
|
|
84
|
+
// declaring it per-project, so the undeclared-dependency rule is off for them.
|
|
85
|
+
overrides: [
|
|
86
|
+
{
|
|
87
|
+
includes: [
|
|
88
|
+
'**/*.config.{ts,mts,cts,js,mjs,cjs}',
|
|
89
|
+
'**/*.{spec,test}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}',
|
|
90
|
+
'**/*.stories.{ts,tsx}'
|
|
91
|
+
],
|
|
92
|
+
linter: {
|
|
93
|
+
rules: {
|
|
94
|
+
correctness: {
|
|
95
|
+
noUndeclaredDependencies: 'off'
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
50
99
|
}
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
files: {
|
|
54
|
-
includes: [
|
|
55
|
-
'**',
|
|
56
|
-
'!**/dist',
|
|
57
|
-
'!**/out-tsc',
|
|
58
|
-
'!**/node_modules',
|
|
59
|
-
'!**/.nx',
|
|
60
|
-
'!**/.venv',
|
|
61
|
-
'!**/*.css',
|
|
62
|
-
'!**/*.gen.*',
|
|
63
|
-
'!**/generated/**',
|
|
64
|
-
'!**/tsconfig*.json'
|
|
65
100
|
]
|
|
66
|
-
}
|
|
67
|
-
};
|
|
101
|
+
});
|
|
68
102
|
const BIOME_FORMATTABLE_EXTENSIONS = new Set([
|
|
69
103
|
'.ts',
|
|
70
104
|
'.tsx',
|
|
@@ -95,10 +129,14 @@ const BIOME_FORMATTABLE_EXTENSIONS = new Set([
|
|
|
95
129
|
// Resolve each project's ruff settings (module names, line-length) so files
|
|
96
130
|
// are formatted to match the on-disk build (see getPythonProjectRuffConfigs).
|
|
97
131
|
const pythonProjectConfigs = pyFiles.length ? getPythonProjectRuffConfigs(tree) : [];
|
|
132
|
+
// Run ruff from the workspace root so it resolves the same on-disk config
|
|
133
|
+
// hasRuffConfigOnDisk probed for. An in-memory tree has no root on disk, in
|
|
134
|
+
// which case there is no config to find and the process cwd is left alone.
|
|
135
|
+
const ruffCwd = pyFiles.length && existsSync(tree.root) ? tree.root : undefined;
|
|
98
136
|
// Format Python files with ruff (lint fixes + formatting)
|
|
99
137
|
for (const file of pyFiles){
|
|
100
138
|
try {
|
|
101
|
-
const content = ruffFixAndFormat(file.content.toString('utf-8'), file.path, hasRuffConfigOnDisk(tree, file.path), getOwningProjectRuffConfig(file.path, pythonProjectConfigs));
|
|
139
|
+
const content = ruffFixAndFormat(file.content.toString('utf-8'), file.path, hasRuffConfigOnDisk(tree, file.path), ruffCwd, getOwningProjectRuffConfig(file.path, pythonProjectConfigs));
|
|
102
140
|
tree.write(file.path, content);
|
|
103
141
|
} catch {
|
|
104
142
|
// Silently skip ruff formatting failures
|
|
@@ -155,7 +193,7 @@ const BIOME_FORMATTABLE_EXTENSIONS = new Set([
|
|
|
155
193
|
const { projectKey } = biome.openProject();
|
|
156
194
|
// Apply the workspace biome.json if it exists in the tree, otherwise the defaults.
|
|
157
195
|
const treeConfig = tree.read('biome.json', 'utf-8');
|
|
158
|
-
biome.applyConfiguration(projectKey, treeConfig ? JSON.parse(treeConfig) :
|
|
196
|
+
biome.applyConfiguration(projectKey, treeConfig ? JSON.parse(treeConfig) : getDefaultBiomeConfig(tree));
|
|
159
197
|
for (const file of files){
|
|
160
198
|
try {
|
|
161
199
|
const { content } = biome.formatContent(projectKey, file.content?.toString('utf-8') ?? '', {
|
|
@@ -277,6 +315,19 @@ function getRuffCommand() {
|
|
|
277
315
|
dir = parent;
|
|
278
316
|
}
|
|
279
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* The `[tool.ruff.lint].select` generated Python projects vend. Generation
|
|
320
|
+
* formats before that config lands on disk, so it is pinned here to keep
|
|
321
|
+
* generated files clean under the project's own `lint` target rather than under
|
|
322
|
+
* whatever ruff's defaults happen to be for the pinned release.
|
|
323
|
+
*/ const DEFAULT_RUFF_SELECT = [
|
|
324
|
+
'E',
|
|
325
|
+
'F',
|
|
326
|
+
'UP',
|
|
327
|
+
'B',
|
|
328
|
+
'SIM',
|
|
329
|
+
'I'
|
|
330
|
+
];
|
|
280
331
|
/**
|
|
281
332
|
* Derive ruff's `target-version` (eg `py314`) from a PEP 508
|
|
282
333
|
* `requires-python` specifier (eg `>=3.14`). Ruff targets the minimum
|
|
@@ -301,7 +352,8 @@ function getRuffCommand() {
|
|
|
301
352
|
/**
|
|
302
353
|
* Map each Nx project with a `pyproject.toml` to the ruff settings the on-disk
|
|
303
354
|
* build enforces for it: its top-level module names (from
|
|
304
|
-
* `[tool.hatch.build.targets.wheel].packages`)
|
|
355
|
+
* `[tool.hatch.build.targets.wheel].packages`), its `[tool.ruff].line-length`
|
|
356
|
+
* and its `[tool.ruff.lint].select`.
|
|
305
357
|
*/ function getPythonProjectRuffConfigs(tree) {
|
|
306
358
|
const configs = [];
|
|
307
359
|
for (const project of getProjects(tree).values()){
|
|
@@ -315,12 +367,15 @@ function getRuffCommand() {
|
|
|
315
367
|
const modules = Array.isArray(wheelPackages) ? wheelPackages.filter((pkg)=>typeof pkg === 'string' && !!pkg).map((pkg)=>pkg.split('/')[0]) : [];
|
|
316
368
|
const lineLength = pyproject?.tool?.ruff?.['line-length'];
|
|
317
369
|
const targetVersion = requiresPythonToRuffTarget(pyproject?.project?.['requires-python']);
|
|
318
|
-
|
|
370
|
+
const selected = pyproject?.tool?.ruff?.lint?.select;
|
|
371
|
+
const select = Array.isArray(selected) ? selected.filter((rule)=>typeof rule === 'string' && !!rule) : undefined;
|
|
372
|
+
if (modules.length || typeof lineLength === 'number' || targetVersion || select?.length) {
|
|
319
373
|
configs.push({
|
|
320
374
|
root: project.root.split(path.sep).join('/'),
|
|
321
375
|
modules,
|
|
322
376
|
lineLength: typeof lineLength === 'number' ? lineLength : undefined,
|
|
323
|
-
targetVersion
|
|
377
|
+
targetVersion,
|
|
378
|
+
select: select?.length ? select : undefined
|
|
324
379
|
});
|
|
325
380
|
}
|
|
326
381
|
} catch {
|
|
@@ -350,11 +405,16 @@ function getRuffCommand() {
|
|
|
350
405
|
* Run ruff check --fix and ruff format on Python file content via stdin.
|
|
351
406
|
* Applies all configured lint fixes (including import sorting) and formatting.
|
|
352
407
|
*
|
|
353
|
-
* When no ruff config exists on disk (`hasConfig` false) ruff
|
|
354
|
-
* defaults, which
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
408
|
+
* When no ruff config exists on disk (`hasConfig` false) ruff would fall back to
|
|
409
|
+
* its own defaults, which change between releases — 0.16 widened them from `E`
|
|
410
|
+
* and `F` to 36 rule prefixes — so generation would apply fixes the project's
|
|
411
|
+
* build never asks for (eg `RUF022` reordering `__all__`). Instead run
|
|
412
|
+
* `--isolated` with the project's own `lint.select` pinned, so generation
|
|
413
|
+
* enforces exactly what `lint` does and nothing more. `--isolated` also stops
|
|
414
|
+
* ruff walking above the workspace to a stray config on the host.
|
|
415
|
+
*
|
|
416
|
+
* When a config does exist we defer to it entirely, honouring the user's rule
|
|
417
|
+
* selection, and run from `tree.root` so ruff discovers it.
|
|
358
418
|
*
|
|
359
419
|
* `projectConfig` carries the owning project's ruff settings, which ruff cannot
|
|
360
420
|
* detect from the filesystem during generation because the project lives only
|
|
@@ -363,11 +423,16 @@ function getRuffCommand() {
|
|
|
363
423
|
* imports in their own group, and `line-length` keeps wrapping consistent (the
|
|
364
424
|
* generated config raises it above ruff's default of 88). These are additive to
|
|
365
425
|
* any on-disk config, so they are safe to pass regardless of `hasConfig`.
|
|
366
|
-
*/ function ruffFixAndFormat(content, filePath, hasConfig, projectConfig) {
|
|
426
|
+
*/ function ruffFixAndFormat(content, filePath, hasConfig, cwd, projectConfig) {
|
|
367
427
|
const ruff = getRuffCommand();
|
|
368
428
|
if (!ruff) return content;
|
|
369
|
-
const extendSelect = hasConfig ? '' : ' --extend-select I';
|
|
370
429
|
const configArgs = [];
|
|
430
|
+
// Pin the rule selection only when deferring to ruff's defaults would
|
|
431
|
+
// otherwise apply rules the project's build does not enforce.
|
|
432
|
+
const isolated = !hasConfig;
|
|
433
|
+
if (isolated) {
|
|
434
|
+
configArgs.push(`lint.select = ${JSON.stringify(projectConfig?.select ?? DEFAULT_RUFF_SELECT)}`);
|
|
435
|
+
}
|
|
371
436
|
if (projectConfig?.modules.length) {
|
|
372
437
|
configArgs.push(`lint.isort.known-first-party = ${JSON.stringify(projectConfig.modules)}`);
|
|
373
438
|
}
|
|
@@ -378,17 +443,23 @@ function getRuffCommand() {
|
|
|
378
443
|
configArgs.push(`target-version = "${projectConfig.targetVersion}"`);
|
|
379
444
|
}
|
|
380
445
|
const config = configArgs.map((arg)=>` --config ${JSON.stringify(arg)}`).join('');
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
input
|
|
446
|
+
const flags = `${isolated ? ' --isolated' : ''}${config}`;
|
|
447
|
+
// Built per invocation: `input` carries the content the previous step emitted.
|
|
448
|
+
const options = (input)=>({
|
|
449
|
+
input,
|
|
385
450
|
encoding: 'utf-8',
|
|
386
451
|
stdio: [
|
|
387
452
|
'pipe',
|
|
388
453
|
'pipe',
|
|
389
454
|
'pipe'
|
|
390
|
-
]
|
|
455
|
+
],
|
|
456
|
+
...cwd ? {
|
|
457
|
+
cwd
|
|
458
|
+
} : {}
|
|
391
459
|
});
|
|
460
|
+
// First apply lint fixes (import sorting, unused imports, etc.)
|
|
461
|
+
try {
|
|
462
|
+
const result = execSync(`${ruff} check --fix${flags} --stdin-filename ${filePath} -`, options(content));
|
|
392
463
|
content = result;
|
|
393
464
|
} catch (e) {
|
|
394
465
|
// ruff check exits non-zero when it finds unfixable issues,
|
|
@@ -399,15 +470,7 @@ function getRuffCommand() {
|
|
|
399
470
|
}
|
|
400
471
|
// Then apply formatting
|
|
401
472
|
try {
|
|
402
|
-
content = execSync(`${ruff} format${
|
|
403
|
-
input: content,
|
|
404
|
-
encoding: 'utf-8',
|
|
405
|
-
stdio: [
|
|
406
|
-
'pipe',
|
|
407
|
-
'pipe',
|
|
408
|
-
'pipe'
|
|
409
|
-
]
|
|
410
|
-
});
|
|
473
|
+
content = execSync(`${ruff} format${flags} --stdin-filename ${filePath} -`, options(content));
|
|
411
474
|
} catch {
|
|
412
475
|
// Fall through with whatever content we have
|
|
413
476
|
}
|
package/src/utils/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/format.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Biome } from '@biomejs/js-api/nodejs';\nimport { getProjects, type Tree } from '@nx/devkit';\nimport { execFileSync, execSync } from 'child_process';\nimport { existsSync, readFileSync } from 'fs';\nimport { createRequire } from 'module';\nimport path from 'path';\nimport { uvxCommand } from './py';\nimport { readToml } from './toml';\nimport { TS_VERSIONS } from './versions';\n\nconst require = createRequire(import.meta.url);\n\nexport const DEFAULT_BIOME_CONFIG = {\n $schema: `https://biomejs.dev/schemas/${TS_VERSIONS['@biomejs/biome']}/schema.json`,\n root: true,\n formatter: {\n enabled: true,\n indentStyle: 'space',\n indentWidth: 2,\n lineWidth: 80,\n },\n javascript: {\n formatter: {\n quoteStyle: 'single',\n trailingCommas: 'all',\n },\n },\n css: {\n formatter: {\n quoteStyle: 'single',\n },\n linter: {\n enabled: false,\n },\n },\n linter: {\n enabled: true,\n rules: {\n preset: 'none',\n correctness: {\n noUndeclaredDependencies: 'warn',\n },\n },\n },\n assist: {\n actions: {\n source: {\n organizeImports: 'on',\n },\n },\n },\n files: {\n includes: [\n '**',\n '!**/dist',\n '!**/out-tsc',\n '!**/node_modules',\n '!**/.nx',\n '!**/.venv',\n '!**/*.css',\n '!**/*.gen.*',\n '!**/generated/**',\n '!**/tsconfig*.json',\n ],\n },\n};\n\nconst BIOME_FORMATTABLE_EXTENSIONS = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.mts',\n '.cts',\n '.json',\n '.jsonc',\n '.css',\n]);\n\n/** Matches `tsconfig.json` and variants like `tsconfig.lib.json`. */\nconst isTsConfig = (filePath: string): boolean =>\n /(^|\\/)tsconfig[^/]*\\.json$/.test(filePath);\n\n/**\n * Format files in the given directory within the tree.\n * Handles both TypeScript/JavaScript/JSON (via biome) and Python (via ruff) files.\n * See https://github.com/nrwl/nx/blob/4cd640a9187954505d12de5b6d76a90d8ce4c2eb/packages/devkit/src/generators/format-files.ts#L11\n */\nexport async function formatFilesInSubtree(\n tree: Tree,\n dir?: string,\n): Promise<void> {\n const changedFiles = tree\n .listChanges()\n .filter((file) => file.type !== 'DELETE')\n .filter((file) => (dir ? file.path.startsWith(dir) : true));\n\n const pyFiles = changedFiles.filter((file) => file.path.endsWith('.py'));\n const otherFiles = changedFiles.filter(\n (file) =>\n BIOME_FORMATTABLE_EXTENSIONS.has(path.extname(file.path)) &&\n // tsconfigs are not biome-managed: they're excluded from the vended\n // format target (Nx's typescript-sync rewrites them without formatting),\n // so formatting them at generation would only diverge from the form\n // written on later runs. Leave them as updateJson/writeJson emit them so\n // repeated generation stays idempotent.\n !isTsConfig(file.path),\n );\n\n // Resolve each project's ruff settings (module names, line-length) so files\n // are formatted to match the on-disk build (see getPythonProjectRuffConfigs).\n const pythonProjectConfigs = pyFiles.length\n ? getPythonProjectRuffConfigs(tree)\n : [];\n\n // Format Python files with ruff (lint fixes + formatting)\n for (const file of pyFiles) {\n try {\n const content = ruffFixAndFormat(\n file.content.toString('utf-8'),\n file.path,\n hasRuffConfigOnDisk(tree, file.path),\n getOwningProjectRuffConfig(file.path, pythonProjectConfigs),\n );\n tree.write(file.path, content);\n } catch {\n // Silently skip ruff formatting failures\n }\n }\n\n if (otherFiles.length === 0) return;\n\n // Use the workspace's own Biome CLI (its version and config) when biome.json\n // exists on disk; otherwise format via the bundled library API with the\n // in-memory tree config. The CLI path does not see in-tree config changes.\n if (existsSync(path.join(tree.root, 'biome.json'))) {\n formatWithBiomeCli(tree, otherFiles);\n } else {\n formatWithBiomeApi(tree, otherFiles);\n }\n}\n\n/**\n * Format files via the workspace's Biome CLI, run from the workspace root so it\n * discovers the on-disk biome.json.\n */\nfunction formatWithBiomeCli(\n tree: Tree,\n files: { path: string; content: Buffer | null }[],\n): void {\n const biome = getBiomeCommand(tree.root);\n if (!biome) {\n // Fall back to the library API if the CLI cannot be resolved\n formatWithBiomeApi(tree, files);\n return;\n }\n\n for (const file of files) {\n try {\n const content = execFileSync(\n biome.command,\n [...biome.args, 'format', `--stdin-file-path=${file.path}`],\n {\n input: file.content?.toString('utf-8') ?? '',\n encoding: 'utf-8',\n cwd: tree.root,\n stdio: ['pipe', 'pipe', 'pipe'],\n },\n );\n tree.write(file.path, content);\n } catch {\n // Leave individual files that fail to format untouched\n }\n }\n}\n\n/**\n * Format files via the bundled Biome library API, applying the in-memory tree\n * config.\n */\nfunction formatWithBiomeApi(\n tree: Tree,\n files: { path: string; content: Buffer | null }[],\n): void {\n try {\n const biome = new Biome();\n const { projectKey } = biome.openProject();\n // Apply the workspace biome.json if it exists in the tree, otherwise the defaults.\n const treeConfig = tree.read('biome.json', 'utf-8');\n biome.applyConfiguration(\n projectKey,\n treeConfig ? JSON.parse(treeConfig) : DEFAULT_BIOME_CONFIG,\n );\n\n for (const file of files) {\n try {\n const { content } = biome.formatContent(\n projectKey,\n file.content?.toString('utf-8') ?? '',\n { filePath: file.path },\n );\n tree.write(file.path, content);\n } catch {\n // Leave individual files that fail to format untouched\n }\n }\n } catch {\n // Silently skip formatting failures\n }\n}\n\ninterface BiomeCommand {\n command: string;\n args: string[];\n}\n\n/**\n * Resolve the `@biomejs/biome` CLI from the user's workspace, falling back to a\n * `biome` binary on the PATH.\n */\nconst _biomeCommands = new Map<string, BiomeCommand | null>();\nfunction getBiomeCommand(root: string): BiomeCommand | undefined {\n if (_biomeCommands.has(root)) {\n return _biomeCommands.get(root) ?? undefined;\n }\n\n // Run via node for cross-platform execution of the bin shim.\n try {\n const pkgJsonPath = require.resolve('@biomejs/biome/package.json', {\n paths: [root, import.meta.dirname],\n });\n const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));\n const binRelative =\n typeof pkgJson.bin === 'string' ? pkgJson.bin : pkgJson.bin?.biome;\n if (binRelative) {\n const binPath = path.join(path.dirname(pkgJsonPath), binRelative);\n const command = { command: process.execPath, args: [binPath] };\n _biomeCommands.set(root, command);\n return command;\n }\n } catch {\n // Fall back to a biome binary on the PATH\n }\n\n try {\n execSync('biome --version', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const command = { command: 'biome', args: [] };\n _biomeCommands.set(root, command);\n return command;\n } catch {\n _biomeCommands.set(root, null);\n return undefined;\n }\n}\n\n/**\n * Find the ruff command: `uvx --from ruff==<version> ruff`. uvx works\n * regardless of workspace resolution state (unlike `uv run ruff`, which fails\n * while installs are deferred), and the version pin matches the project's\n * `format` target (PY_VERSIONS) so generation and check format identically.\n * Only a successful probe is cached — ruff can become available mid-run in the\n * long-lived Nx daemon, so a cached failure would skip formatting thereafter.\n */\nlet _ruffCommand: string | undefined;\nfunction getRuffCommand(): string | undefined {\n if (_ruffCommand) {\n return _ruffCommand;\n }\n const cmd = uvxCommand('ruff');\n try {\n execSync(`${cmd} --version`, {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n _ruffCommand = cmd;\n return cmd;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Whether ruff would discover a config on disk for a file, by walking from its\n * directory up to the workspace root looking for `.ruff.toml`, `ruff.toml`, or a\n * `pyproject.toml` with a `[tool.ruff]` section — the same files ruff itself\n * resolves. The walk stops at `tree.root` so a stray config in a parent of the\n * workspace (or the home directory) is never treated as the project's. Used to\n * decide whether to nudge ruff towards import sorting (see\n * {@link ruffFixAndFormat}).\n */\nfunction hasRuffConfigOnDisk(tree: Tree, filePath: string): boolean {\n const root = path.resolve(tree.root);\n let dir = path.resolve(root, path.dirname(filePath));\n while (true) {\n if (\n existsSync(path.join(dir, '.ruff.toml')) ||\n existsSync(path.join(dir, 'ruff.toml'))\n ) {\n return true;\n }\n const pyproject = path.join(dir, 'pyproject.toml');\n if (\n existsSync(pyproject) &&\n readFileSync(pyproject, 'utf-8').includes('[tool.ruff')\n ) {\n return true;\n }\n const parent = path.dirname(dir);\n // Stop once the workspace root has been checked (or we hit the FS root).\n if (dir === root || parent === dir) {\n return false;\n }\n dir = parent;\n }\n}\n\ninterface PythonProjectRuffConfig {\n /** Project root, normalised to use forward slashes. */\n readonly root: string;\n /** Top-level importable module names declared by the project. */\n readonly modules: string[];\n /** The project's `[tool.ruff].line-length`, if set. */\n readonly lineLength?: number;\n /**\n * Ruff `target-version` (eg `py314`) derived from `[project].requires-python`.\n * Generation formats via stdin with no pyproject, so it must be passed\n * explicitly — ruff's formatting differs by target.\n */\n readonly targetVersion?: string;\n}\n\n/**\n * Derive ruff's `target-version` (eg `py314`) from a PEP 508\n * `requires-python` specifier (eg `>=3.14`). Ruff targets the minimum\n * supported version, so take the lowest `major.minor` mentioned.\n */\nexport const requiresPythonToRuffTarget = (\n requiresPython: unknown,\n): string | undefined => {\n if (typeof requiresPython !== 'string') {\n return undefined;\n }\n let min: { major: number; minor: number } | undefined;\n for (const match of requiresPython.matchAll(/(\\d+)\\.(\\d+)/g)) {\n const major = Number(match[1]);\n const minor = Number(match[2]);\n if (\n !min ||\n major < min.major ||\n (major === min.major && minor < min.minor)\n ) {\n min = { major, minor };\n }\n }\n return min ? `py${min.major}${min.minor}` : undefined;\n};\n\n/**\n * Map each Nx project with a `pyproject.toml` to the ruff settings the on-disk\n * build enforces for it: its top-level module names (from\n * `[tool.hatch.build.targets.wheel].packages`) and its `[tool.ruff].line-length`.\n */\nfunction getPythonProjectRuffConfigs(tree: Tree): PythonProjectRuffConfig[] {\n const configs: PythonProjectRuffConfig[] = [];\n\n for (const project of getProjects(tree).values()) {\n const pyprojectPath = path.join(project.root, 'pyproject.toml');\n if (tree.exists(pyprojectPath)) {\n try {\n const pyproject = readToml(tree, pyprojectPath) as any;\n const wheelPackages: unknown =\n pyproject?.tool?.hatch?.build?.targets?.wheel?.packages;\n // Record the top-level module segment (`pkg/sub` -> `pkg`), which is\n // all `known-first-party` keys off.\n const modules = Array.isArray(wheelPackages)\n ? wheelPackages\n .filter((pkg): pkg is string => typeof pkg === 'string' && !!pkg)\n .map((pkg) => pkg.split('/')[0])\n : [];\n const lineLength: unknown = pyproject?.tool?.ruff?.['line-length'];\n const targetVersion = requiresPythonToRuffTarget(\n pyproject?.project?.['requires-python'],\n );\n if (modules.length || typeof lineLength === 'number' || targetVersion) {\n configs.push({\n root: project.root.split(path.sep).join('/'),\n modules,\n lineLength: typeof lineLength === 'number' ? lineLength : undefined,\n targetVersion,\n });\n }\n } catch {\n // Skip projects whose pyproject.toml cannot be parsed\n }\n }\n }\n\n return configs;\n}\n\n/**\n * Resolve the ruff config for the project that owns a file (the project with\n * the longest root that is a prefix of the file path). Ruff runs per-project on\n * disk, so a file's settings come from its own project — only its own module is\n * first-party (sibling workspace packages are third-party) and its own\n * line-length applies — and scoping this way keeps in-tree formatting\n * consistent with the on-disk build.\n */\nfunction getOwningProjectRuffConfig(\n filePath: string,\n configs: PythonProjectRuffConfig[],\n): PythonProjectRuffConfig | undefined {\n let owner: PythonProjectRuffConfig | undefined;\n for (const config of configs) {\n if (\n (filePath === config.root || filePath.startsWith(`${config.root}/`)) &&\n (!owner || config.root.length > owner.root.length)\n ) {\n owner = config;\n }\n }\n return owner;\n}\n\n/**\n * Run ruff check --fix and ruff format on Python file content via stdin.\n * Applies all configured lint fixes (including import sorting) and formatting.\n *\n * When no ruff config exists on disk (`hasConfig` false) ruff falls back to its\n * defaults, which omit isort — but generated projects enable rule `I` and their\n * build fails on unsorted imports (I001). In that case we add `--extend-select\n * I` so import sorting matches what the build enforces. When a config does\n * exist we defer to it entirely, honouring the user's rule selection.\n *\n * `projectConfig` carries the owning project's ruff settings, which ruff cannot\n * detect from the filesystem during generation because the project lives only\n * in the tree. We pass them via `--config` so in-tree formatting matches the\n * on-disk build: `known-first-party` (the project's own modules) keeps its\n * imports in their own group, and `line-length` keeps wrapping consistent (the\n * generated config raises it above ruff's default of 88). These are additive to\n * any on-disk config, so they are safe to pass regardless of `hasConfig`.\n */\nfunction ruffFixAndFormat(\n content: string,\n filePath: string,\n hasConfig: boolean,\n projectConfig?: PythonProjectRuffConfig,\n): string {\n const ruff = getRuffCommand();\n if (!ruff) return content;\n\n const extendSelect = hasConfig ? '' : ' --extend-select I';\n const configArgs: string[] = [];\n if (projectConfig?.modules.length) {\n configArgs.push(\n `lint.isort.known-first-party = ${JSON.stringify(projectConfig.modules)}`,\n );\n }\n if (typeof projectConfig?.lineLength === 'number') {\n configArgs.push(`line-length = ${projectConfig.lineLength}`);\n }\n if (projectConfig?.targetVersion) {\n configArgs.push(`target-version = \"${projectConfig.targetVersion}\"`);\n }\n const config = configArgs\n .map((arg) => ` --config ${JSON.stringify(arg)}`)\n .join('');\n\n // First apply lint fixes (import sorting, unused imports, etc.)\n try {\n const result = execSync(\n `${ruff} check --fix${extendSelect}${config} --stdin-filename ${filePath} -`,\n { input: content, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] },\n );\n content = result;\n } catch (e: any) {\n // ruff check exits non-zero when it finds unfixable issues,\n // but stdout still contains the fixed content\n if (e.stdout) {\n content = e.stdout;\n }\n }\n\n // Then apply formatting\n try {\n content = execSync(\n `${ruff} format${config} --stdin-filename ${filePath} -`,\n {\n input: content,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n },\n );\n } catch {\n // Fall through with whatever content we have\n }\n\n return content;\n}\n"],"names":["Biome","getProjects","execFileSync","execSync","existsSync","readFileSync","createRequire","path","uvxCommand","readToml","TS_VERSIONS","require","url","DEFAULT_BIOME_CONFIG","$schema","root","formatter","enabled","indentStyle","indentWidth","lineWidth","javascript","quoteStyle","trailingCommas","css","linter","rules","preset","correctness","noUndeclaredDependencies","assist","actions","source","organizeImports","files","includes","BIOME_FORMATTABLE_EXTENSIONS","Set","isTsConfig","filePath","test","formatFilesInSubtree","tree","dir","changedFiles","listChanges","filter","file","type","startsWith","pyFiles","endsWith","otherFiles","has","extname","pythonProjectConfigs","length","getPythonProjectRuffConfigs","content","ruffFixAndFormat","toString","hasRuffConfigOnDisk","getOwningProjectRuffConfig","write","join","formatWithBiomeCli","formatWithBiomeApi","biome","getBiomeCommand","command","args","input","encoding","cwd","stdio","projectKey","openProject","treeConfig","read","applyConfiguration","JSON","parse","formatContent","_biomeCommands","Map","get","undefined","pkgJsonPath","resolve","paths","dirname","pkgJson","binRelative","bin","binPath","process","execPath","set","_ruffCommand","getRuffCommand","cmd","pyproject","parent","requiresPythonToRuffTarget","requiresPython","min","match","matchAll","major","Number","minor","configs","project","values","pyprojectPath","exists","wheelPackages","tool","hatch","build","targets","wheel","packages","modules","Array","isArray","pkg","map","split","lineLength","ruff","targetVersion","push","sep","owner","config","hasConfig","projectConfig","extendSelect","configArgs","stringify","arg","result","e","stdout"],"mappings":"AAAA;;;CAGC,GAED,SAASA,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,QAAmB,aAAa;AACpD,SAASC,YAAY,EAAEC,QAAQ,QAAQ,gBAAgB;AACvD,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAK;AAC9C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AQnE,QAAQ;QACjCmF,WAAWP,IAAI,CACb,CAAC,+BAA+B,EAAEpD,KAAK4D,SAAS,CAACH,cAAcd,OAAO,GAAG;IAE7E;IACA,IAAI,OAAOc,eAAeR,eAAe,UAAU;QACjDU,WAAWP,IAAI,CAAC,CAAC,cAAc,EAAEK,cAAcR,UAAU,EAAE;IAC7D;IACA,IAAIQ,eAAeN,eAAe;QAChCQ,WAAWP,IAAI,CAAC,CAAC,kBAAkB,EAAEK,cAAcN,aAAa,CAAC,CAAC,CAAC;IACrE;IACA,MAAMI,SAASI,WACZZ,GAAG,CAAC,CAACc,MAAQ,CAAC,UAAU,EAAE7D,KAAK4D,SAAS,CAACC,MAAM,EAC/C7E,IAAI,CAAC;IAER,gEAAgE;IAChE,IAAI;QACF,MAAM8E,SAAS3I,SACb,GAAG+H,KAAK,YAAY,EAAEQ,eAAeH,OAAO,kBAAkB,EAAEhG,SAAS,EAAE,CAAC,EAC5E;YAAEgC,OAAOb;YAASc,UAAU;YAASE,OAAO;gBAAC;gBAAQ;gBAAQ;aAAO;QAAC;QAEvEhB,UAAUoF;IACZ,EAAE,OAAOC,GAAQ;QACf,4DAA4D;QAC5D,8CAA8C;QAC9C,IAAIA,EAAEC,MAAM,EAAE;YACZtF,UAAUqF,EAAEC,MAAM;QACpB;IACF;IAEA,wBAAwB;IACxB,IAAI;QACFtF,UAAUvD,SACR,GAAG+H,KAAK,OAAO,EAAEK,OAAO,kBAAkB,EAAEhG,SAAS,EAAE,CAAC,EACxD;YACEgC,OAAOb;YACPc,UAAU;YACVE,OAAO;gBAAC;gBAAQ;gBAAQ;aAAO;QACjC;IAEJ,EAAE,OAAM;IACN,6CAA6C;IAC/C;IAEA,OAAOhB;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/format.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Biome } from '@biomejs/js-api/nodejs';\nimport { getProjects, type Tree } from '@nx/devkit';\nimport {\n type ExecSyncOptionsWithStringEncoding,\n execFileSync,\n execSync,\n} from 'child_process';\nimport { existsSync, readFileSync } from 'fs';\nimport { createRequire } from 'module';\nimport path from 'path';\nimport { uvxCommand } from './py';\nimport { readToml } from './toml';\nimport { TS_VERSIONS } from './versions';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * The biome.json vended into a new workspace. The pnpm catalog resolver is only\n * included on pnpm workspaces, since `experimentalPnpmCatalogs` is Biome's only\n * catalog resolver and reads `pnpm-workspace.yaml` exclusively — it does nothing\n * for yarn or bun catalogs, so vending it there would be misleading.\n */\nexport const getDefaultBiomeConfig = (tree: Tree) => ({\n $schema: `https://biomejs.dev/schemas/${TS_VERSIONS['@biomejs/biome']}/schema.json`,\n root: true,\n formatter: {\n enabled: true,\n indentStyle: 'space',\n indentWidth: 2,\n lineWidth: 80,\n },\n javascript: {\n formatter: {\n quoteStyle: 'single',\n trailingCommas: 'all',\n },\n // Resolve `catalog:` versions from pnpm-workspace.yaml (pnpm workspaces only).\n ...(tree.exists('pnpm-workspace.yaml')\n ? { resolver: { experimentalPnpmCatalogs: true } }\n : {}),\n },\n css: {\n formatter: {\n quoteStyle: 'single',\n },\n linter: {\n enabled: false,\n },\n },\n linter: {\n enabled: true,\n rules: {\n preset: 'none',\n correctness: {\n // Every project must declare the third-party dependencies its source\n // code imports in its own package.json.\n noUndeclaredDependencies: 'error',\n },\n },\n },\n assist: {\n actions: {\n source: {\n organizeImports: 'on',\n },\n },\n },\n files: {\n includes: [\n '**',\n '!**/dist',\n '!**/out-tsc',\n '!**/node_modules',\n '!**/.nx',\n '!**/.venv',\n // GritQL codemod cache written by generators — its sample sources\n // otherwise pollute a bare `biome check .` with parse errors.\n '!**/.grit',\n '!**/*.css',\n '!**/*.gen.*',\n '!**/generated/**',\n '!**/tsconfig*.json',\n ],\n },\n // Config files, build scripts and tests use root tooling rather than\n // declaring it per-project, so the undeclared-dependency rule is off for them.\n overrides: [\n {\n includes: [\n '**/*.config.{ts,mts,cts,js,mjs,cjs}',\n '**/*.{spec,test}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}',\n '**/*.stories.{ts,tsx}',\n ],\n linter: {\n rules: {\n correctness: {\n noUndeclaredDependencies: 'off',\n },\n },\n },\n },\n ],\n});\n\nconst BIOME_FORMATTABLE_EXTENSIONS = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.mts',\n '.cts',\n '.json',\n '.jsonc',\n '.css',\n]);\n\n/** Matches `tsconfig.json` and variants like `tsconfig.lib.json`. */\nconst isTsConfig = (filePath: string): boolean =>\n /(^|\\/)tsconfig[^/]*\\.json$/.test(filePath);\n\n/**\n * Format files in the given directory within the tree.\n * Handles both TypeScript/JavaScript/JSON (via biome) and Python (via ruff) files.\n * See https://github.com/nrwl/nx/blob/4cd640a9187954505d12de5b6d76a90d8ce4c2eb/packages/devkit/src/generators/format-files.ts#L11\n */\nexport async function formatFilesInSubtree(\n tree: Tree,\n dir?: string,\n): Promise<void> {\n const changedFiles = tree\n .listChanges()\n .filter((file) => file.type !== 'DELETE')\n .filter((file) => (dir ? file.path.startsWith(dir) : true));\n\n const pyFiles = changedFiles.filter((file) => file.path.endsWith('.py'));\n const otherFiles = changedFiles.filter(\n (file) =>\n BIOME_FORMATTABLE_EXTENSIONS.has(path.extname(file.path)) &&\n // tsconfigs are not biome-managed: they're excluded from the vended\n // format target (Nx's typescript-sync rewrites them without formatting),\n // so formatting them at generation would only diverge from the form\n // written on later runs. Leave them as updateJson/writeJson emit them so\n // repeated generation stays idempotent.\n !isTsConfig(file.path),\n );\n\n // Resolve each project's ruff settings (module names, line-length) so files\n // are formatted to match the on-disk build (see getPythonProjectRuffConfigs).\n const pythonProjectConfigs = pyFiles.length\n ? getPythonProjectRuffConfigs(tree)\n : [];\n\n // Run ruff from the workspace root so it resolves the same on-disk config\n // hasRuffConfigOnDisk probed for. An in-memory tree has no root on disk, in\n // which case there is no config to find and the process cwd is left alone.\n const ruffCwd =\n pyFiles.length && existsSync(tree.root) ? tree.root : undefined;\n\n // Format Python files with ruff (lint fixes + formatting)\n for (const file of pyFiles) {\n try {\n const content = ruffFixAndFormat(\n file.content.toString('utf-8'),\n file.path,\n hasRuffConfigOnDisk(tree, file.path),\n ruffCwd,\n getOwningProjectRuffConfig(file.path, pythonProjectConfigs),\n );\n tree.write(file.path, content);\n } catch {\n // Silently skip ruff formatting failures\n }\n }\n\n if (otherFiles.length === 0) return;\n\n // Use the workspace's own Biome CLI (its version and config) when biome.json\n // exists on disk; otherwise format via the bundled library API with the\n // in-memory tree config. The CLI path does not see in-tree config changes.\n if (existsSync(path.join(tree.root, 'biome.json'))) {\n formatWithBiomeCli(tree, otherFiles);\n } else {\n formatWithBiomeApi(tree, otherFiles);\n }\n}\n\n/**\n * Format files via the workspace's Biome CLI, run from the workspace root so it\n * discovers the on-disk biome.json.\n */\nfunction formatWithBiomeCli(\n tree: Tree,\n files: { path: string; content: Buffer | null }[],\n): void {\n const biome = getBiomeCommand(tree.root);\n if (!biome) {\n // Fall back to the library API if the CLI cannot be resolved\n formatWithBiomeApi(tree, files);\n return;\n }\n\n for (const file of files) {\n try {\n const content = execFileSync(\n biome.command,\n [...biome.args, 'format', `--stdin-file-path=${file.path}`],\n {\n input: file.content?.toString('utf-8') ?? '',\n encoding: 'utf-8',\n cwd: tree.root,\n stdio: ['pipe', 'pipe', 'pipe'],\n },\n );\n tree.write(file.path, content);\n } catch {\n // Leave individual files that fail to format untouched\n }\n }\n}\n\n/**\n * Format files via the bundled Biome library API, applying the in-memory tree\n * config.\n */\nfunction formatWithBiomeApi(\n tree: Tree,\n files: { path: string; content: Buffer | null }[],\n): void {\n try {\n const biome = new Biome();\n const { projectKey } = biome.openProject();\n // Apply the workspace biome.json if it exists in the tree, otherwise the defaults.\n const treeConfig = tree.read('biome.json', 'utf-8');\n biome.applyConfiguration(\n projectKey,\n treeConfig ? JSON.parse(treeConfig) : getDefaultBiomeConfig(tree),\n );\n\n for (const file of files) {\n try {\n const { content } = biome.formatContent(\n projectKey,\n file.content?.toString('utf-8') ?? '',\n { filePath: file.path },\n );\n tree.write(file.path, content);\n } catch {\n // Leave individual files that fail to format untouched\n }\n }\n } catch {\n // Silently skip formatting failures\n }\n}\n\ninterface BiomeCommand {\n command: string;\n args: string[];\n}\n\n/**\n * Resolve the `@biomejs/biome` CLI from the user's workspace, falling back to a\n * `biome` binary on the PATH.\n */\nconst _biomeCommands = new Map<string, BiomeCommand | null>();\nfunction getBiomeCommand(root: string): BiomeCommand | undefined {\n if (_biomeCommands.has(root)) {\n return _biomeCommands.get(root) ?? undefined;\n }\n\n // Run via node for cross-platform execution of the bin shim.\n try {\n const pkgJsonPath = require.resolve('@biomejs/biome/package.json', {\n paths: [root, import.meta.dirname],\n });\n const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));\n const binRelative =\n typeof pkgJson.bin === 'string' ? pkgJson.bin : pkgJson.bin?.biome;\n if (binRelative) {\n const binPath = path.join(path.dirname(pkgJsonPath), binRelative);\n const command = { command: process.execPath, args: [binPath] };\n _biomeCommands.set(root, command);\n return command;\n }\n } catch {\n // Fall back to a biome binary on the PATH\n }\n\n try {\n execSync('biome --version', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const command = { command: 'biome', args: [] };\n _biomeCommands.set(root, command);\n return command;\n } catch {\n _biomeCommands.set(root, null);\n return undefined;\n }\n}\n\n/**\n * Find the ruff command: `uvx --from ruff==<version> ruff`. uvx works\n * regardless of workspace resolution state (unlike `uv run ruff`, which fails\n * while installs are deferred), and the version pin matches the project's\n * `format` target (PY_VERSIONS) so generation and check format identically.\n * Only a successful probe is cached — ruff can become available mid-run in the\n * long-lived Nx daemon, so a cached failure would skip formatting thereafter.\n */\nlet _ruffCommand: string | undefined;\nfunction getRuffCommand(): string | undefined {\n if (_ruffCommand) {\n return _ruffCommand;\n }\n const cmd = uvxCommand('ruff');\n try {\n execSync(`${cmd} --version`, {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n _ruffCommand = cmd;\n return cmd;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Whether ruff would discover a config on disk for a file, by walking from its\n * directory up to the workspace root looking for `.ruff.toml`, `ruff.toml`, or a\n * `pyproject.toml` with a `[tool.ruff]` section — the same files ruff itself\n * resolves. The walk stops at `tree.root` so a stray config in a parent of the\n * workspace (or the home directory) is never treated as the project's. Used to\n * decide whether to nudge ruff towards import sorting (see\n * {@link ruffFixAndFormat}).\n */\nfunction hasRuffConfigOnDisk(tree: Tree, filePath: string): boolean {\n const root = path.resolve(tree.root);\n let dir = path.resolve(root, path.dirname(filePath));\n while (true) {\n if (\n existsSync(path.join(dir, '.ruff.toml')) ||\n existsSync(path.join(dir, 'ruff.toml'))\n ) {\n return true;\n }\n const pyproject = path.join(dir, 'pyproject.toml');\n if (\n existsSync(pyproject) &&\n readFileSync(pyproject, 'utf-8').includes('[tool.ruff')\n ) {\n return true;\n }\n const parent = path.dirname(dir);\n // Stop once the workspace root has been checked (or we hit the FS root).\n if (dir === root || parent === dir) {\n return false;\n }\n dir = parent;\n }\n}\n\n/**\n * The `[tool.ruff.lint].select` generated Python projects vend. Generation\n * formats before that config lands on disk, so it is pinned here to keep\n * generated files clean under the project's own `lint` target rather than under\n * whatever ruff's defaults happen to be for the pinned release.\n */\nconst DEFAULT_RUFF_SELECT = ['E', 'F', 'UP', 'B', 'SIM', 'I'];\n\ninterface PythonProjectRuffConfig {\n /** Project root, normalised to use forward slashes. */\n readonly root: string;\n /** Top-level importable module names declared by the project. */\n readonly modules: string[];\n /** The project's `[tool.ruff].line-length`, if set. */\n readonly lineLength?: number;\n /**\n * Ruff `target-version` (eg `py314`) derived from `[project].requires-python`.\n * Generation formats via stdin with no pyproject, so it must be passed\n * explicitly — ruff's formatting differs by target.\n */\n readonly targetVersion?: string;\n /** The project's `[tool.ruff.lint].select`, if set. */\n readonly select?: string[];\n}\n\n/**\n * Derive ruff's `target-version` (eg `py314`) from a PEP 508\n * `requires-python` specifier (eg `>=3.14`). Ruff targets the minimum\n * supported version, so take the lowest `major.minor` mentioned.\n */\nexport const requiresPythonToRuffTarget = (\n requiresPython: unknown,\n): string | undefined => {\n if (typeof requiresPython !== 'string') {\n return undefined;\n }\n let min: { major: number; minor: number } | undefined;\n for (const match of requiresPython.matchAll(/(\\d+)\\.(\\d+)/g)) {\n const major = Number(match[1]);\n const minor = Number(match[2]);\n if (\n !min ||\n major < min.major ||\n (major === min.major && minor < min.minor)\n ) {\n min = { major, minor };\n }\n }\n return min ? `py${min.major}${min.minor}` : undefined;\n};\n\n/**\n * Map each Nx project with a `pyproject.toml` to the ruff settings the on-disk\n * build enforces for it: its top-level module names (from\n * `[tool.hatch.build.targets.wheel].packages`), its `[tool.ruff].line-length`\n * and its `[tool.ruff.lint].select`.\n */\nfunction getPythonProjectRuffConfigs(tree: Tree): PythonProjectRuffConfig[] {\n const configs: PythonProjectRuffConfig[] = [];\n\n for (const project of getProjects(tree).values()) {\n const pyprojectPath = path.join(project.root, 'pyproject.toml');\n if (tree.exists(pyprojectPath)) {\n try {\n const pyproject = readToml(tree, pyprojectPath) as any;\n const wheelPackages: unknown =\n pyproject?.tool?.hatch?.build?.targets?.wheel?.packages;\n // Record the top-level module segment (`pkg/sub` -> `pkg`), which is\n // all `known-first-party` keys off.\n const modules = Array.isArray(wheelPackages)\n ? wheelPackages\n .filter((pkg): pkg is string => typeof pkg === 'string' && !!pkg)\n .map((pkg) => pkg.split('/')[0])\n : [];\n const lineLength: unknown = pyproject?.tool?.ruff?.['line-length'];\n const targetVersion = requiresPythonToRuffTarget(\n pyproject?.project?.['requires-python'],\n );\n const selected: unknown = pyproject?.tool?.ruff?.lint?.select;\n const select = Array.isArray(selected)\n ? selected.filter(\n (rule): rule is string => typeof rule === 'string' && !!rule,\n )\n : undefined;\n if (\n modules.length ||\n typeof lineLength === 'number' ||\n targetVersion ||\n select?.length\n ) {\n configs.push({\n root: project.root.split(path.sep).join('/'),\n modules,\n lineLength: typeof lineLength === 'number' ? lineLength : undefined,\n targetVersion,\n select: select?.length ? select : undefined,\n });\n }\n } catch {\n // Skip projects whose pyproject.toml cannot be parsed\n }\n }\n }\n\n return configs;\n}\n\n/**\n * Resolve the ruff config for the project that owns a file (the project with\n * the longest root that is a prefix of the file path). Ruff runs per-project on\n * disk, so a file's settings come from its own project — only its own module is\n * first-party (sibling workspace packages are third-party) and its own\n * line-length applies — and scoping this way keeps in-tree formatting\n * consistent with the on-disk build.\n */\nfunction getOwningProjectRuffConfig(\n filePath: string,\n configs: PythonProjectRuffConfig[],\n): PythonProjectRuffConfig | undefined {\n let owner: PythonProjectRuffConfig | undefined;\n for (const config of configs) {\n if (\n (filePath === config.root || filePath.startsWith(`${config.root}/`)) &&\n (!owner || config.root.length > owner.root.length)\n ) {\n owner = config;\n }\n }\n return owner;\n}\n\n/**\n * Run ruff check --fix and ruff format on Python file content via stdin.\n * Applies all configured lint fixes (including import sorting) and formatting.\n *\n * When no ruff config exists on disk (`hasConfig` false) ruff would fall back to\n * its own defaults, which change between releases — 0.16 widened them from `E`\n * and `F` to 36 rule prefixes — so generation would apply fixes the project's\n * build never asks for (eg `RUF022` reordering `__all__`). Instead run\n * `--isolated` with the project's own `lint.select` pinned, so generation\n * enforces exactly what `lint` does and nothing more. `--isolated` also stops\n * ruff walking above the workspace to a stray config on the host.\n *\n * When a config does exist we defer to it entirely, honouring the user's rule\n * selection, and run from `tree.root` so ruff discovers it.\n *\n * `projectConfig` carries the owning project's ruff settings, which ruff cannot\n * detect from the filesystem during generation because the project lives only\n * in the tree. We pass them via `--config` so in-tree formatting matches the\n * on-disk build: `known-first-party` (the project's own modules) keeps its\n * imports in their own group, and `line-length` keeps wrapping consistent (the\n * generated config raises it above ruff's default of 88). These are additive to\n * any on-disk config, so they are safe to pass regardless of `hasConfig`.\n */\nfunction ruffFixAndFormat(\n content: string,\n filePath: string,\n hasConfig: boolean,\n cwd: string | undefined,\n projectConfig?: PythonProjectRuffConfig,\n): string {\n const ruff = getRuffCommand();\n if (!ruff) return content;\n\n const configArgs: string[] = [];\n // Pin the rule selection only when deferring to ruff's defaults would\n // otherwise apply rules the project's build does not enforce.\n const isolated = !hasConfig;\n if (isolated) {\n configArgs.push(\n `lint.select = ${JSON.stringify(projectConfig?.select ?? DEFAULT_RUFF_SELECT)}`,\n );\n }\n if (projectConfig?.modules.length) {\n configArgs.push(\n `lint.isort.known-first-party = ${JSON.stringify(projectConfig.modules)}`,\n );\n }\n if (typeof projectConfig?.lineLength === 'number') {\n configArgs.push(`line-length = ${projectConfig.lineLength}`);\n }\n if (projectConfig?.targetVersion) {\n configArgs.push(`target-version = \"${projectConfig.targetVersion}\"`);\n }\n const config = configArgs\n .map((arg) => ` --config ${JSON.stringify(arg)}`)\n .join('');\n const flags = `${isolated ? ' --isolated' : ''}${config}`;\n // Built per invocation: `input` carries the content the previous step emitted.\n const options = (input: string): ExecSyncOptionsWithStringEncoding => ({\n input,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n ...(cwd ? { cwd } : {}),\n });\n\n // First apply lint fixes (import sorting, unused imports, etc.)\n try {\n const result = execSync(\n `${ruff} check --fix${flags} --stdin-filename ${filePath} -`,\n options(content),\n );\n content = result;\n } catch (e: any) {\n // ruff check exits non-zero when it finds unfixable issues,\n // but stdout still contains the fixed content\n if (e.stdout) {\n content = e.stdout;\n }\n }\n\n // Then apply formatting\n try {\n content = execSync(\n `${ruff} format${flags} --stdin-filename ${filePath} -`,\n options(content),\n );\n } catch {\n // Fall through with whatever content we have\n }\n\n return content;\n}\n"],"names":["Biome","getProjects","execFileSync","execSync","existsSync","readFileSync","createRequire","path","uvxCommand","readToml","TS_VERSIONS","require","url","getDefaultBiomeConfig","tree","$schema","root","formatter","enabled","indentStyle","indentWidth","lineWidth","javascript","quoteStyle","trailingCommas","exists","resolver","experimentalPnpmCatalogs","css","linter","rules","preset","correctness","noUndeclaredDependencies","assist","actions","source","organizeImports","files","includes","overrides","BIOME_FORMATTABLE_EXTENSIONS","Set","isTsConfig","filePath","test","formatFilesInSubtree","dir","changedFiles","listChanges","filter","file","type","startsWith","pyFiles","endsWith","otherFiles","has","extname","pythonProjectConfigs","length","getPythonProjectRuffConfigs","ruffCwd","undefined","content","ruffFixAndFormat","toString","hasRuffConfigOnDisk","getOwningProjectRuffConfig","write","join","formatWithBiomeCli","formatWithBiomeApi","biome","getBiomeCommand","command","args","input","encoding","cwd","stdio","projectKey","openProject","treeConfig","read","applyConfiguration","JSON","parse","formatContent","_biomeCommands","Map","get","pkgJsonPath","resolve","paths","dirname","pkgJson","binRelative","bin","binPath","process","execPath","set","_ruffCommand","getRuffCommand","cmd","pyproject","parent","DEFAULT_RUFF_SELECT","requiresPythonToRuffTarget","requiresPython","min","match","matchAll","major","Number","minor","configs","project","values","pyprojectPath","wheelPackages","tool","hatch","build","targets","wheel","packages","modules","Array","isArray","pkg","map","split","lineLength","ruff","targetVersion","selected","lint","select","rule","push","sep","owner","config","hasConfig","projectConfig","configArgs","isolated","stringify","arg","flags","options","result","e","stdout"],"mappings":"AAAA;;;CAGC,GAED,SAASA,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,QAAmB,aAAa;AACpD,SAEEC,YAAY,EACZC,QAAQ,QACH,gBAAgB;AACvB,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAK;AAC9C,SAASC,aAAa,QAAQ,SAAS;AACvC,OAAOC,UAAU,OAAO;AACxB,SAASC,UAAU,QAAQ,UAAO;AAClC,SAASC,QAAQ,QAAQ,YAAS;AAClC,SAASC,WAAW,QAAQ,gBAAa;AAEzC,MAAMC,UAAUL,cAAc,YAAYM,GAAG;AAE7C;;;;;CAKC,GACD,OAAO,MAAMC,wBAAwB,CAACC,OAAgB,CAAA;QACpDC,SAAS,CAAC,4BAA4B,EAAEL,WAAW,CAAC,iBAAiB,CAAC,YAAY,CAAC;QACnFM,MAAM;Q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+EAA+E;IAC/E,MAAMQ,UAAU,CAAC3E,QAAsD,CAAA;YACrEA;YACAC,UAAU;YACVE,OAAO;gBAAC;gBAAQ;gBAAQ;aAAO;YAC/B,GAAID,MAAM;gBAAEA;YAAI,IAAI,CAAC,CAAC;QACxB,CAAA;IAEA,gEAAgE;IAChE,IAAI;QACF,MAAM0E,SAAStJ,SACb,GAAGoI,KAAK,YAAY,EAAEgB,MAAM,kBAAkB,EAAE3G,SAAS,EAAE,CAAC,EAC5D4G,QAAQxF;QAEVA,UAAUyF;IACZ,EAAE,OAAOC,GAAQ;QACf,4DAA4D;QAC5D,8CAA8C;QAC9C,IAAIA,EAAEC,MAAM,EAAE;YACZ3F,UAAU0F,EAAEC,MAAM;QACpB;IACF;IAEA,wBAAwB;IACxB,IAAI;QACF3F,UAAU7D,SACR,GAAGoI,KAAK,OAAO,EAAEgB,MAAM,kBAAkB,EAAE3G,SAAS,EAAE,CAAC,EACvD4G,QAAQxF;IAEZ,EAAE,OAAM;IACN,6CAA6C;IAC/C;IAEA,OAAOA;AACT"}
|
package/src/utils/fs.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { Tree } from '@nx/devkit';
|
|
6
6
|
/**
|
|
7
7
|
* Utility class for creating platform agnostic commands for filesystem operations.
|
|
8
8
|
* Adds the required dependencies to the root package json
|
package/src/utils/fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/ import { addDependenciesToPackageJson } from "
|
|
4
|
+
*/ import { addDependenciesToPackageJson } from "./dependencies.js";
|
|
5
5
|
import { withVersions } from "./versions.js";
|
|
6
6
|
/**
|
|
7
7
|
* Utility class for creating platform agnostic commands for filesystem operations.
|
package/src/utils/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/fs.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/fs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { Tree } from '@nx/devkit';\nimport { addDependenciesToPackageJson } from './dependencies';\nimport { withVersions } from './versions';\n\n/**\n * Utility class for creating platform agnostic commands for filesystem operations.\n * Adds the required dependencies to the root package json\n */\nexport class FsCommands {\n private tree: Tree;\n\n constructor(tree: Tree) {\n this.tree = tree;\n }\n\n public cp(src: string, dst: string) {\n addDependenciesToPackageJson(this.tree, {}, withVersions(['ncp']));\n return `ncp ${src} ${dst}`;\n }\n\n public rm(dir: string) {\n addDependenciesToPackageJson(this.tree, {}, withVersions(['rimraf']));\n return `rimraf ${dir}`;\n }\n\n public mkdir(dir: string) {\n addDependenciesToPackageJson(this.tree, {}, withVersions(['make-dir-cli']));\n return `make-dir ${dir}`;\n }\n}\n"],"names":["addDependenciesToPackageJson","withVersions","FsCommands","tree","cp","src","dst","rm","dir","mkdir"],"mappings":"AAAA;;;CAGC,GAED,SAASA,4BAA4B,QAAQ,oBAAiB;AAC9D,SAASC,YAAY,QAAQ,gBAAa;AAE1C;;;CAGC,GACD,OAAO,MAAMC;IACHC,KAAW;IAEnB,YAAYA,IAAU,CAAE;QACtB,IAAI,CAACA,IAAI,GAAGA;IACd;IAEOC,GAAGC,GAAW,EAAEC,GAAW,EAAE;QAClCN,6BAA6B,IAAI,CAACG,IAAI,EAAE,CAAC,GAAGF,aAAa;YAAC;SAAM;QAChE,OAAO,CAAC,IAAI,EAAEI,IAAI,CAAC,EAAEC,KAAK;IAC5B;IAEOC,GAAGC,GAAW,EAAE;QACrBR,6BAA6B,IAAI,CAACG,IAAI,EAAE,CAAC,GAAGF,aAAa;YAAC;SAAS;QACnE,OAAO,CAAC,OAAO,EAAEO,KAAK;IACxB;IAEOC,MAAMD,GAAW,EAAE;QACxBR,6BAA6B,IAAI,CAACG,IAAI,EAAE,CAAC,GAAGF,aAAa;YAAC;SAAe;QACzE,OAAO,CAAC,SAAS,EAAEO,KAAK;IAC1B;AACF"}
|
package/src/utils/iac.js
CHANGED
|
@@ -8,7 +8,7 @@ import { IAC_PROVIDERS } from "./iac-providers.js";
|
|
|
8
8
|
* Given an iac provider option, resolve the actual iac provider to use
|
|
9
9
|
*/ export const resolveIac = async (tree, iacOption)=>{
|
|
10
10
|
if (iacOption === 'inherit') {
|
|
11
|
-
const pluginConfig =
|
|
11
|
+
const pluginConfig = readAwsNxPluginConfig(tree);
|
|
12
12
|
if (!pluginConfig?.iac?.provider) {
|
|
13
13
|
throw new Error(`IaC provider "inherit" requires iac.provider to be set in ${AWS_NX_PLUGIN_CONFIG_FILE_NAME}`);
|
|
14
14
|
}
|
package/src/utils/iac.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/iac.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { Tree } from '@nx/devkit';\nimport {\n AWS_NX_PLUGIN_CONFIG_FILE_NAME,\n readAwsNxPluginConfig,\n} from './config/utils';\n\nexport { IAC_PROVIDERS, type Iac, type IacOption } from './iac-providers';\n\nimport { IAC_PROVIDERS } from './iac-providers';\n\n/**\n * Configuration for infrastructure as code\n */\nexport interface IacConfig {\n /**\n * Default provider for infrastructure as code\n */\n provider: (typeof IAC_PROVIDERS)[number];\n}\n\n/**\n * Given an iac provider option, resolve the actual iac provider to use\n */\nexport const resolveIac = async (\n tree: Tree,\n iacOption: 'cdk' | 'terraform' | 'inherit',\n): Promise<(typeof IAC_PROVIDERS)[number]> => {\n if (iacOption === 'inherit') {\n const pluginConfig =
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/iac.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { Tree } from '@nx/devkit';\nimport {\n AWS_NX_PLUGIN_CONFIG_FILE_NAME,\n readAwsNxPluginConfig,\n} from './config/utils';\n\nexport { IAC_PROVIDERS, type Iac, type IacOption } from './iac-providers';\n\nimport { IAC_PROVIDERS } from './iac-providers';\n\n/**\n * Configuration for infrastructure as code\n */\nexport interface IacConfig {\n /**\n * Default provider for infrastructure as code\n */\n provider: (typeof IAC_PROVIDERS)[number];\n}\n\n/**\n * Given an iac provider option, resolve the actual iac provider to use\n */\nexport const resolveIac = async (\n tree: Tree,\n iacOption: 'cdk' | 'terraform' | 'inherit',\n): Promise<(typeof IAC_PROVIDERS)[number]> => {\n if (iacOption === 'inherit') {\n const pluginConfig = readAwsNxPluginConfig(tree);\n\n if (!pluginConfig?.iac?.provider) {\n throw new Error(\n `IaC provider \"inherit\" requires iac.provider to be set in ${AWS_NX_PLUGIN_CONFIG_FILE_NAME}`,\n );\n }\n if (!IAC_PROVIDERS.includes(pluginConfig.iac.provider)) {\n throw new Error(\n `iac.provider in ${AWS_NX_PLUGIN_CONFIG_FILE_NAME} must be one of ${IAC_PROVIDERS.join(', ')}`,\n );\n }\n\n return pluginConfig.iac.provider;\n }\n return iacOption;\n};\n"],"names":["AWS_NX_PLUGIN_CONFIG_FILE_NAME","readAwsNxPluginConfig","IAC_PROVIDERS","resolveIac","tree","iacOption","pluginConfig","iac","provider","Error","includes","join"],"mappings":"AAAA;;;CAGC,GAED,SACEA,8BAA8B,EAC9BC,qBAAqB,QAChB,oBAAiB;AAExB,SAASC,aAAa,QAAkC,qBAAkB;AAE1E,SAASA,aAAa,QAAQ,qBAAkB;AAYhD;;CAEC,GACD,OAAO,MAAMC,aAAa,OACxBC,MACAC;IAEA,IAAIA,cAAc,WAAW;QAC3B,MAAMC,eAAeL,sBAAsBG;QAE3C,IAAI,CAACE,cAAcC,KAAKC,UAAU;YAChC,MAAM,IAAIC,MACR,CAAC,0DAA0D,EAAET,gCAAgC;QAEjG;QACA,IAAI,CAACE,cAAcQ,QAAQ,CAACJ,aAAaC,GAAG,CAACC,QAAQ,GAAG;YACtD,MAAM,IAAIC,MACR,CAAC,gBAAgB,EAAET,+BAA+B,gBAAgB,EAAEE,cAAcS,IAAI,CAAC,OAAO;QAElG;QAEA,OAAOL,aAAaC,GAAG,CAACC,QAAQ;IAClC;IACA,OAAOH;AACT,EAAE"}
|