@aws/nx-plugin 1.0.0-rc.94 → 1.0.0-rc.96
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 +234 -38
- package/migrations.json +54 -1
- package/package.json +6 -6
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +4 -10
- 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/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/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/preset/__snapshots__/generator.spec.ts.snap +8 -6
- 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/mcp-connection/generator.d.ts +1 -1
- package/src/py/agent/react-connection/generator.d.ts +29 -0
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +4 -1
- package/src/ts/agent/a2a-connection/generator.d.ts +4 -0
- package/src/ts/agent/gateway-connection/generator.d.ts +4 -0
- package/src/ts/agent/generator.d.ts +4 -0
- package/src/ts/agent/mcp-connection/generator.d.ts +4 -0
- package/src/ts/agent/react-connection/generator.d.ts +37 -0
- package/src/ts/lib/generator.d.ts +13 -0
- package/src/ts/lib/generator.js +3 -2
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.d.ts +17 -1
- package/src/ts/lib/ts-project-utils.js +29 -0
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.d.ts +6 -0
- package/src/ts/lib/vitest.js +16 -1
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/react-website/agui/generator.d.ts +21 -0
- 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 +28 -22
- package/src/ts/react-website/app/generator.d.ts +42 -0
- package/src/ts/react-website/app/generator.js +4 -2
- 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/bundle/bundle.js +10 -0
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/dependencies.js +1 -10
- package/src/utils/dependencies.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 +16 -0
- package/src/utils/format.js +15 -0
- package/src/utils/format.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 +22 -0
- package/src/utils/shared-shadcn.js +39 -28
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test.js +15 -0
- package/src/utils/test.js.map +1 -1
- package/src/utils/version-upgrade-migration/sync-vended-versions.js +4 -4
- package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -1
- package/src/utils/versions.d.ts +10 -9
- package/src/utils/versions.js +10 -8
- package/src/utils/versions.js.map +1 -1
package/src/utils/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/init.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readNxJson,\n type Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\nimport { initGenerator } from '@nx/js';\nimport { readFileSync } from 'fs';\nimport yaml from 'js-yaml';\nimport { SYNC_GENERATOR_NAME as TS_SYNC_GENERATOR_NAME } from '../ts/sync/generator.js';\nimport { BASE_TSCONFIG_COMPILER_OPTIONS } from './base-tsconfig.js';\nimport {\n ensureAwsNxPluginConfig,\n updateAwsNxPluginConfig,\n} from './config/utils.js';\nimport { type Containers, inferContainers } from './containers.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport {\n addDependenciesToPackageJson,\n detectWorkspacePackageManager,\n} from './dependencies.js';\nimport { getDefaultBiomeConfig } from './format.js';\nimport {\n describeGeneratorForCatalogue,\n generatorsJsonEntries,\n} from './generators.js';\nimport type { Iac } from './iac.js';\nimport { configureMcpServers } from './mcp.js';\nimport { getNpmScope } from './npm-scope.js';\nimport {\n mergeTargetDefault,\n nxPluginMcpDependency,\n nxPluginSelfDependency,\n} from './nx.js';\nimport { getPackageManagerDisplayCommands } from './pkg-manager.js';\nimport { workspaceGlobs } from './project-package-json.js';\nimport { type ITsDepVersion, withVersions } from './versions.js';\n\nconst WORKSPACES = ['packages/*'];\nconst NX_TYPESCRIPT_SYNC_GENERATOR = '@nx/js:typescript-sync';\n\nexport const DEFAULT_PARALLEL = 8;\n\n/** Dependencies a caller must declare to apply the workspace init. */\nexport const INIT_DEPENDENCIES = [\n { name: 'nx' },\n { name: '@nx/js' },\n { name: '@nx/workspace' },\n { name: 'typescript' },\n { name: '@biomejs/biome' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\n// Built dependencies whose install scripts the generated workspace trusts.\n// `onlyBuiltDependencies` is the pnpm 10 key (silently ignored by pnpm 11);\n// pnpm 11 reads `allowBuilds` instead. Any dep NOT in this allowlist will\n// have its install scripts skipped with a warning — matching pnpm 10's\n// default behaviour. The user can opt-in later via `pnpm approve-builds`.\nexport const PNPM_BUILT_DEPENDENCIES = ['@swc/core', 'esbuild', 'nx', 'sharp'];\n\n/**\n * Options controlling how the workspace is initialised. These mirror the\n * preset schema so a workspace created via the preset and one initialised via\n * the `init` generator end up in the same shape.\n */\nexport interface ApplyWorkspaceInitOptions {\n /** The IaC provider to record in the plugin config. */\n readonly iac: Iac;\n /**\n * The container engine to record. `undefined`/`'infer'` picks docker when\n * installed, else finch.\n */\n readonly containers?: Containers | 'infer';\n /** Whether to configure MCP servers for coding agents. Defaults to true. */\n readonly mcp?: boolean;\n /**\n * How to treat the generated workspace README. The preset owns the README of\n * a greenfield workspace (`Overwrite`); the `init` generator must not clobber\n * an existing workspace's README (`KeepExisting`, the default).\n */\n readonly readmeOverwriteStrategy?: OverwriteStrategy;\n /**\n * Whether to overwrite root package.json scripts that already exist. The\n * preset owns a greenfield workspace's scripts (`true`); the `init`\n * generator must not clobber an existing workspace's scripts (`false`,\n * the default) — it only adds the convenience scripts that are absent.\n */\n readonly overwriteScripts?: boolean;\n /**\n * Whether generators use the package manager's dependency catalog. On pnpm\n * this also sets `catalogMode: strict` so `pnpm add` records new deps in the\n * catalog. Defaults to true.\n */\n readonly catalogs?: boolean;\n}\n\n/**\n * Add or repair the pnpm `allowBuilds` / `onlyBuiltDependencies` allowlist for\n * the workspace's `packages` globs, without clobbering any packages the user\n * has already declared.\n *\n * A workspace not created by the preset commonly has either no\n * `pnpm-workspace.yaml`, one missing the `packages` globs, or one carrying the\n * broken `set this to true or false` placeholder pnpm writes when it skips a\n * build script. This makes the file self-consistent so the first generator's\n * install doesn't fail with `ERR_PNPM_IGNORED_BUILDS`.\n */\nconst setUpPnpmWorkspace = (tree: Tree, catalogs: boolean) => {\n const existing = tree.exists('pnpm-workspace.yaml')\n ? ((yaml.load(tree.read('pnpm-workspace.yaml', 'utf-8') ?? '') as Record<\n string,\n unknown\n >) ?? {})\n : {};\n\n // Preserve any packages globs the user already has, ensuring ours are present.\n const packages = Array.from(\n new Set([...((existing.packages as string[]) ?? []), ...WORKSPACES]),\n );\n\n const allowBuilds = {\n ...(typeof existing.allowBuilds === 'object' && existing.allowBuilds\n ? (existing.allowBuilds as Record<string, unknown>)\n : {}),\n // Overwrite any non-boolean (e.g. the \"set this to true or false\"\n // placeholder) with an explicit true for the deps we trust.\n ...Object.fromEntries(PNPM_BUILT_DEPENDENCIES.map((dep) => [dep, true])),\n };\n\n // `strict` makes `pnpm add` record new deps in the catalog; it only gates\n // that flow, so pre-declared direct ranges (e.g. tslib) still install.\n // Preserve an explicit user choice.\n const catalogMode = catalogs\n ? (existing.catalogMode ?? 'strict')\n : existing.catalogMode;\n\n tree.write(\n 'pnpm-workspace.yaml',\n yaml.dump(\n {\n ...existing,\n packages,\n allowBuilds,\n onlyBuiltDependencies: PNPM_BUILT_DEPENDENCIES,\n ...(catalogMode ? { catalogMode } : {}),\n },\n { quotingType: \"'\" },\n ),\n );\n};\n\n/**\n * Configure the workspace's package manager for a monorepo layout.\n *\n * pnpm workspaces are declared in `pnpm-workspace.yaml`; every other package\n * manager reads the `workspaces` field of the root `package.json`.\n */\nconst setUpWorkspaces = (tree: Tree, catalogs: boolean) => {\n if (detectWorkspacePackageManager(tree) === 'pnpm') {\n setUpPnpmWorkspace(tree, catalogs);\n } else {\n updateJson(tree, 'package.json', (json) => {\n // The `workspaces` field may be the object form ({ \"packages\": [...] })\n // accepted by yarn and bun — extend the globs while preserving the form.\n const globs = Array.from(\n new Set([...workspaceGlobs(json.workspaces), ...WORKSPACES]),\n );\n return {\n ...json,\n workspaces:\n json.workspaces !== undefined && !Array.isArray(json.workspaces)\n ? { ...json.workspaces, packages: globs }\n : globs,\n };\n });\n }\n};\n\n/**\n * Ensure the workspace has a `tsconfig.base.json`.\n *\n * `@nx/js` `initGenerator` (with `addTsPlugin`) normally creates this, but it\n * short-circuits when the workspace already has a root `tsconfig.json` — in\n * which case no base file is written and the next project generator fails with\n * `Cannot find tsconfig.base.json`. So we create a compatible one when it's\n * absent. An existing base is left untouched: the user may have tuned it, and\n * rewriting shared compiler options can break other projects (see the\n * \"add to an existing workspace\" guide).\n */\nconst ensureBaseTsConfig = (tree: Tree) => {\n if (tree.exists('tsconfig.base.json')) {\n return;\n }\n tree.write(\n 'tsconfig.base.json',\n JSON.stringify(\n {\n compilerOptions: {\n ...BASE_TSCONFIG_COMPILER_OPTIONS,\n customConditions: [getNpmScope(tree)],\n },\n },\n null,\n 2,\n ),\n );\n};\n\n/**\n * Ensure the workspace has a root `tsconfig.json`.\n *\n * Nx's `@nx/js:typescript-sync` generator hard-fails with\n * `Missing root \"tsconfig.json\"` when it's absent. The plugin's TypeScript\n * projects reference each other via this file, so we guarantee a minimal one\n * exists (sync populates its `references`).\n */\nconst ensureRootTsConfig = (tree: Tree) => {\n if (tree.exists('tsconfig.json')) {\n return;\n }\n tree.write(\n 'tsconfig.json',\n JSON.stringify(\n {\n extends: './tsconfig.base.json',\n files: [],\n references: [],\n },\n null,\n 2,\n ),\n );\n};\n\n/**\n * Transform an Nx workspace into one ready to run `@aws/nx-plugin` generators.\n *\n * This is the deterministic core shared by the workspace preset and the `init`\n * generator. It is safe to re-run: every step is idempotent (config merges,\n * keyed nx.json / package.json entries, create-if-missing files), so running\n * it against an already-initialised workspace is a no-op.\n *\n * It preserves the workspace's module format: the root package.json `type`\n * field is owned by the preset (written from its `--module` option) and left\n * untouched here. It does NOT rewrite an existing `tsconfig.base.json`'s\n * compiler options, migrate a workspace's package manager, or restructure\n * existing projects — those are decisions for the user (see the \"add to an\n * existing workspace\" guide).\n */\nexport const applyWorkspaceInit = async <const D extends DependencyDeclaration>(\n tree: Tree,\n {\n iac,\n containers,\n mcp,\n readmeOverwriteStrategy = OverwriteStrategy.KeepExisting,\n overwriteScripts = false,\n catalogs = true,\n }: ApplyWorkspaceInitOptions,\n declaration: D & MustDeclare<typeof INIT_DEPENDENCIES, D>,\n) => {\n const resolvedContainers =\n !containers || containers === 'infer' ? inferContainers() : containers;\n\n // The catalogs flag is written explicitly (even when true) so the workspace\n // records its dependency-management choice.\n await ensureAwsNxPluginConfig(tree);\n await updateAwsNxPluginConfig(tree, {\n iac: { provider: iac },\n containers: { engine: resolvedContainers },\n packageManager: { catalogs },\n });\n\n // Set up the TypeScript plugin, base tsconfig, formatter etc. `@nx/js`\n // creates `tsconfig.base.json` when absent, but skips it when a root\n // `tsconfig.json` already exists — so we ensure both explicitly below.\n await initGenerator(tree, {\n formatter: 'none',\n addTsPlugin: true,\n });\n\n ensureBaseTsConfig(tree);\n ensureRootTsConfig(tree);\n\n setUpWorkspaces(tree, catalogs);\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n // Preserve an explicit analytics choice in an existing workspace.\n analytics: (nxJson as { analytics?: boolean }).analytics ?? false,\n parallel: nxJson.parallel ?? DEFAULT_PARALLEL,\n targetDefaults: {\n ...nxJson.targetDefaults,\n compile: mergeTargetDefault(nxJson.targetDefaults?.compile, (base) => ({\n ...base,\n syncGenerators: [\n ...(base.syncGenerators ?? []).filter(\n (g) =>\n ![TS_SYNC_GENERATOR_NAME, NX_TYPESCRIPT_SYNC_GENERATOR].includes(\n g,\n ),\n ),\n NX_TYPESCRIPT_SYNC_GENERATOR,\n TS_SYNC_GENERATOR_NAME,\n ],\n })),\n },\n });\n\n const CONVENIENCE_SCRIPTS = {\n dev: 'nx run-many --target dev',\n build: 'nx run-many --target build',\n lint: 'nx run-many --target lint --configuration=fix',\n test: 'nx run-many --target test --all',\n // Trivy container image scanning is not part of `build` (its result\n // depends on the ever-changing vulnerability database); run it explicitly,\n // e.g. in CI.\n trivy: 'nx run-many --target trivy --all',\n 'build:skip-lint': 'nx run-many --target build --configuration=skip-lint',\n 'build:all': 'nx run-many --target build --all',\n 'affected:all': 'nx affected --target build',\n };\n updateJson(tree, 'package.json', (packageJson) => ({\n ...packageJson,\n // The root `type` field is owned by the preset (written explicitly from\n // its `--module` option). `init` preserves an existing workspace's field\n // as-is: an ESM workspace already carries `type: \"module\"` (that is how\n // the format is inferred), and introducing a `type` into a CommonJS\n // workspace that lacks one changes behaviour for frameworks that parse it\n // (e.g. Next.js starts treating the app's ESM source as CJS).\n scripts: overwriteScripts\n ? { ...packageJson.scripts, ...CONVENIENCE_SCRIPTS }\n : { ...CONVENIENCE_SCRIPTS, ...packageJson.scripts },\n }));\n\n // Pin the workspace's `nx` to the version the plugin's @nx/* packages are\n // built against. A mismatched workspace nx (even a patch apart) hoists a\n // second nested nx under @nx/js, and the two instances deadlock `nx sync`.\n // `@nx/js` must be a root dependency for the `@nx/js:typescript-sync`\n // generator registered in nx.json to resolve (npm doesn't hoist the\n // plugin's own copy reliably).\n addDependenciesToPackageJson(\n tree,\n {},\n {\n ...withVersions(forDependencies<typeof INIT_DEPENDENCIES>(declaration), [\n 'nx',\n '@nx/js',\n '@nx/workspace',\n ]),\n ...withVersions(forDependencies<typeof INIT_DEPENDENCIES>(declaration), [\n 'typescript',\n '@biomejs/biome',\n ]),\n // Declare the plugin the generators are running from, plus the MCP server\n // package the vended config runs, so both are pinned in the workspace's\n // lockfile and upgrading them upgrades what the agents use.\n ...nxPluginSelfDependency(tree),\n ...nxPluginMcpDependency(tree),\n },\n );\n\n // Write biome.json for formatting and linting\n if (!tree.exists('biome.json')) {\n tree.write(\n 'biome.json',\n JSON.stringify(getDefaultBiomeConfig(tree), null, 2),\n );\n }\n\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, '..', 'preset', 'files'),\n '.',\n {\n projectName: getNpmScope(tree),\n generators: Object.entries(generatorsJsonEntries)\n .filter(([, info]) => !info.hidden)\n .map(([id, info]) => ({\n name: id,\n description: describeGeneratorForCatalogue(info),\n })),\n ...(() => {\n const cmds = getPackageManagerDisplayCommands();\n return {\n pkgMgrCmd: cmds.exec,\n buildCmd: `${cmds.run} build`,\n lintCmd: `${cmds.run} lint`,\n };\n })(),\n },\n {\n overwriteStrategy: readmeOverwriteStrategy,\n },\n );\n\n if (mcp !== false) {\n configureMcpServers(tree);\n }\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readNxJson","updateJson","updateNxJson","initGenerator","yaml","SYNC_GENERATOR_NAME","TS_SYNC_GENERATOR_NAME","BASE_TSCONFIG_COMPILER_OPTIONS","ensureAwsNxPluginConfig","updateAwsNxPluginConfig","inferContainers","forDependencies","addDependenciesToPackageJson","detectWorkspacePackageManager","getDefaultBiomeConfig","describeGeneratorForCatalogue","generatorsJsonEntries","configureMcpServers","getNpmScope","mergeTargetDefault","nxPluginMcpDependency","nxPluginSelfDependency","getPackageManagerDisplayCommands","workspaceGlobs","withVersions","WORKSPACES","NX_TYPESCRIPT_SYNC_GENERATOR","DEFAULT_PARALLEL","INIT_DEPENDENCIES","name","PNPM_BUILT_DEPENDENCIES","setUpPnpmWorkspace","tree","catalogs","existing","exists","load","read","packages","Array","from","Set","allowBuilds","Object","fromEntries","map","dep","catalogMode","write","dump","onlyBuiltDependencies","quotingType","setUpWorkspaces","json","globs","workspaces","undefined","isArray","ensureBaseTsConfig","JSON","stringify","compilerOptions","customConditions","ensureRootTsConfig","extends","files","references","applyWorkspaceInit","iac","containers","mcp","readmeOverwriteStrategy","KeepExisting","overwriteScripts","declaration","resolvedContainers","provider","engine","packageManager","formatter","addTsPlugin","nxJson","analytics","parallel","targetDefaults","compile","base","syncGenerators","filter","g","includes","CONVENIENCE_SCRIPTS","dev","build","lint","test","trivy","packageJson","scripts","dirname","projectName","generators","entries","info","hidden","id","description","cmds","pkgMgrCmd","exec","buildCmd","run","lintCmd","overwriteStrategy"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,UAAU,EAEVC,UAAU,EACVC,YAAY,QACP,aAAa;AACpB,SAASC,aAAa,QAAQ,SAAS;AAEvC,OAAOC,UAAU,UAAU;AAC3B,SAASC,uBAAuBC,sBAAsB,QAAQ,0BAA0B;AACxF,SAASC,8BAA8B,QAAQ,qBAAqB;AACpE,SACEC,uBAAuB,EACvBC,uBAAuB,QAClB,oBAAoB;AAC3B,SAA0BC,eAAe,QAAQ,kBAAkB;AACnE,SAEEC,eAAe,QAEV,6BAA6B;AACpC,SACEC,4BAA4B,EAC5BC,6BAA6B,QACxB,oBAAoB;AAC3B,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SACEC,6BAA6B,EAC7BC,qBAAqB,QAChB,kBAAkB;AAEzB,SAASC,mBAAmB,QAAQ,WAAW;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC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BACpBC,UAAU,GAAGH,KAAKI,GAAG,CAAC,MAAM,CAAC;gBAC7BC,SAAS,GAAGL,KAAKI,GAAG,CAAC,KAAK,CAAC;YAC7B;QACF,CAAA,GAAI;IACN,GACA;QACEE,mBAAmB1C;IACrB;IAGF,IAAID,QAAQ,OAAO;QACjBrD,oBAAoBe;IACtB;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/init.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readNxJson,\n type Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\nimport { initGenerator } from '@nx/js';\nimport { readFileSync } from 'fs';\nimport yaml from 'js-yaml';\nimport { SYNC_GENERATOR_NAME as TS_SYNC_GENERATOR_NAME } from '../ts/sync/generator.js';\nimport { BASE_TSCONFIG_COMPILER_OPTIONS } from './base-tsconfig.js';\nimport {\n ensureAwsNxPluginConfig,\n updateAwsNxPluginConfig,\n} from './config/utils.js';\nimport { type Containers, inferContainers } from './containers.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport {\n addDependenciesToPackageJson,\n detectWorkspacePackageManager,\n} from './dependencies.js';\nimport { getDefaultBiomeConfig } from './format.js';\nimport {\n describeGeneratorForCatalogue,\n generatorsJsonEntries,\n} from './generators.js';\nimport { updateGitIgnore } from './git.js';\nimport type { Iac } from './iac.js';\nimport { configureMcpServers } from './mcp.js';\nimport { getNpmScope } from './npm-scope.js';\nimport {\n mergeTargetDefault,\n nxPluginMcpDependency,\n nxPluginSelfDependency,\n} from './nx.js';\nimport { getPackageManagerDisplayCommands } from './pkg-manager.js';\nimport { workspaceGlobs } from './project-package-json.js';\nimport { type ITsDepVersion, withVersions } from './versions.js';\n\nconst WORKSPACES = ['packages/*'];\nconst NX_TYPESCRIPT_SYNC_GENERATOR = '@nx/js:typescript-sync';\n\nexport const DEFAULT_PARALLEL = 8;\n\n/** Dependencies a caller must declare to apply the workspace init. */\nexport const INIT_DEPENDENCIES = [\n { name: 'nx' },\n { name: '@nx/js' },\n { name: '@nx/workspace' },\n { name: 'typescript' },\n { name: '@biomejs/biome' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\n// Built dependencies whose install scripts the generated workspace trusts.\n// `onlyBuiltDependencies` is the pnpm 10 key (silently ignored from pnpm 11\n// onwards); pnpm 11 and above read `allowBuilds` instead. Any dep NOT in this\n// allowlist will have its install scripts skipped with a warning — matching\n// pnpm 10's default behaviour. The user can opt-in later via\n// `pnpm approve-builds`.\nexport const PNPM_BUILT_DEPENDENCIES = ['@swc/core', 'esbuild', 'nx', 'sharp'];\n\n/**\n * Options controlling how the workspace is initialised. These mirror the\n * preset schema so a workspace created via the preset and one initialised via\n * the `init` generator end up in the same shape.\n */\nexport interface ApplyWorkspaceInitOptions {\n /** The IaC provider to record in the plugin config. */\n readonly iac: Iac;\n /**\n * The container engine to record. `undefined`/`'infer'` picks docker when\n * installed, else finch.\n */\n readonly containers?: Containers | 'infer';\n /** Whether to configure MCP servers for coding agents. Defaults to true. */\n readonly mcp?: boolean;\n /**\n * How to treat the generated workspace README. The preset owns the README of\n * a greenfield workspace (`Overwrite`); the `init` generator must not clobber\n * an existing workspace's README (`KeepExisting`, the default).\n */\n readonly readmeOverwriteStrategy?: OverwriteStrategy;\n /**\n * Whether to overwrite root package.json scripts that already exist. The\n * preset owns a greenfield workspace's scripts (`true`); the `init`\n * generator must not clobber an existing workspace's scripts (`false`,\n * the default) — it only adds the convenience scripts that are absent.\n */\n readonly overwriteScripts?: boolean;\n /**\n * Whether generators use the package manager's dependency catalog. On pnpm\n * this also sets `catalogMode: strict` so `pnpm add` records new deps in the\n * catalog. Defaults to true.\n */\n readonly catalogs?: boolean;\n}\n\n/**\n * Add or repair the pnpm `allowBuilds` / `onlyBuiltDependencies` allowlist for\n * the workspace's `packages` globs, without clobbering any packages the user\n * has already declared.\n *\n * A workspace not created by the preset commonly has either no\n * `pnpm-workspace.yaml`, one missing the `packages` globs, or one carrying the\n * broken `set this to true or false` placeholder pnpm writes when it skips a\n * build script. This makes the file self-consistent so the first generator's\n * install doesn't fail with `ERR_PNPM_IGNORED_BUILDS`.\n */\nconst setUpPnpmWorkspace = (tree: Tree, catalogs: boolean) => {\n const existing = tree.exists('pnpm-workspace.yaml')\n ? ((yaml.load(tree.read('pnpm-workspace.yaml', 'utf-8') ?? '') as Record<\n string,\n unknown\n >) ?? {})\n : {};\n\n // Preserve any packages globs the user already has, ensuring ours are present.\n const packages = Array.from(\n new Set([...((existing.packages as string[]) ?? []), ...WORKSPACES]),\n );\n\n const allowBuilds = {\n ...(typeof existing.allowBuilds === 'object' && existing.allowBuilds\n ? (existing.allowBuilds as Record<string, unknown>)\n : {}),\n // Overwrite any non-boolean (e.g. the \"set this to true or false\"\n // placeholder) with an explicit true for the deps we trust.\n ...Object.fromEntries(PNPM_BUILT_DEPENDENCIES.map((dep) => [dep, true])),\n };\n\n // `strict` makes `pnpm add` record new deps in the catalog; it only gates\n // that flow, so pre-declared direct ranges (e.g. tslib) still install.\n // Preserve an explicit user choice.\n const catalogMode = catalogs\n ? (existing.catalogMode ?? 'strict')\n : existing.catalogMode;\n\n tree.write(\n 'pnpm-workspace.yaml',\n yaml.dump(\n {\n ...existing,\n packages,\n allowBuilds,\n onlyBuiltDependencies: PNPM_BUILT_DEPENDENCIES,\n ...(catalogMode ? { catalogMode } : {}),\n },\n { quotingType: \"'\" },\n ),\n );\n};\n\n/**\n * Configure the workspace's package manager for a monorepo layout.\n *\n * pnpm workspaces are declared in `pnpm-workspace.yaml`; every other package\n * manager reads the `workspaces` field of the root `package.json`.\n */\nconst setUpWorkspaces = (tree: Tree, catalogs: boolean) => {\n if (detectWorkspacePackageManager(tree) === 'pnpm') {\n setUpPnpmWorkspace(tree, catalogs);\n // pnpm creates these at the workspace root while it materialises packages.\n updateGitIgnore(tree, '.', (patterns) => [...patterns, '_tmp_*']);\n } else {\n updateJson(tree, 'package.json', (json) => {\n // The `workspaces` field may be the object form ({ \"packages\": [...] })\n // accepted by yarn and bun — extend the globs while preserving the form.\n const globs = Array.from(\n new Set([...workspaceGlobs(json.workspaces), ...WORKSPACES]),\n );\n return {\n ...json,\n workspaces:\n json.workspaces !== undefined && !Array.isArray(json.workspaces)\n ? { ...json.workspaces, packages: globs }\n : globs,\n };\n });\n }\n};\n\n/**\n * Ensure the workspace has a `tsconfig.base.json`.\n *\n * `@nx/js` `initGenerator` (with `addTsPlugin`) normally creates this, but it\n * short-circuits when the workspace already has a root `tsconfig.json` — in\n * which case no base file is written and the next project generator fails with\n * `Cannot find tsconfig.base.json`. So we create a compatible one when it's\n * absent. An existing base is left untouched: the user may have tuned it, and\n * rewriting shared compiler options can break other projects (see the\n * \"add to an existing workspace\" guide).\n */\nconst ensureBaseTsConfig = (tree: Tree) => {\n if (tree.exists('tsconfig.base.json')) {\n return;\n }\n tree.write(\n 'tsconfig.base.json',\n JSON.stringify(\n {\n compilerOptions: {\n ...BASE_TSCONFIG_COMPILER_OPTIONS,\n customConditions: [getNpmScope(tree)],\n },\n },\n null,\n 2,\n ),\n );\n};\n\n/**\n * Ensure the workspace has a root `tsconfig.json`.\n *\n * Nx's `@nx/js:typescript-sync` generator hard-fails with\n * `Missing root \"tsconfig.json\"` when it's absent. The plugin's TypeScript\n * projects reference each other via this file, so we guarantee a minimal one\n * exists (sync populates its `references`).\n */\nconst ensureRootTsConfig = (tree: Tree) => {\n if (tree.exists('tsconfig.json')) {\n return;\n }\n tree.write(\n 'tsconfig.json',\n JSON.stringify(\n {\n extends: './tsconfig.base.json',\n files: [],\n references: [],\n },\n null,\n 2,\n ),\n );\n};\n\n/**\n * Transform an Nx workspace into one ready to run `@aws/nx-plugin` generators.\n *\n * This is the deterministic core shared by the workspace preset and the `init`\n * generator. It is safe to re-run: every step is idempotent (config merges,\n * keyed nx.json / package.json entries, create-if-missing files), so running\n * it against an already-initialised workspace is a no-op.\n *\n * It preserves the workspace's module format: the root package.json `type`\n * field is owned by the preset (written from its `--module` option) and left\n * untouched here. It does NOT rewrite an existing `tsconfig.base.json`'s\n * compiler options, migrate a workspace's package manager, or restructure\n * existing projects — those are decisions for the user (see the \"add to an\n * existing workspace\" guide).\n */\nexport const applyWorkspaceInit = async <const D extends DependencyDeclaration>(\n tree: Tree,\n {\n iac,\n containers,\n mcp,\n readmeOverwriteStrategy = OverwriteStrategy.KeepExisting,\n overwriteScripts = false,\n catalogs = true,\n }: ApplyWorkspaceInitOptions,\n declaration: D & MustDeclare<typeof INIT_DEPENDENCIES, D>,\n) => {\n const resolvedContainers =\n !containers || containers === 'infer' ? inferContainers() : containers;\n\n // The catalogs flag is written explicitly (even when true) so the workspace\n // records its dependency-management choice.\n await ensureAwsNxPluginConfig(tree);\n await updateAwsNxPluginConfig(tree, {\n iac: { provider: iac },\n containers: { engine: resolvedContainers },\n packageManager: { catalogs },\n });\n\n // Set up the TypeScript plugin, base tsconfig, formatter etc. `@nx/js`\n // creates `tsconfig.base.json` when absent, but skips it when a root\n // `tsconfig.json` already exists — so we ensure both explicitly below.\n await initGenerator(tree, {\n formatter: 'none',\n addTsPlugin: true,\n });\n\n ensureBaseTsConfig(tree);\n ensureRootTsConfig(tree);\n\n setUpWorkspaces(tree, catalogs);\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n // Preserve an explicit analytics choice in an existing workspace.\n analytics: (nxJson as { analytics?: boolean }).analytics ?? false,\n parallel: nxJson.parallel ?? DEFAULT_PARALLEL,\n targetDefaults: {\n ...nxJson.targetDefaults,\n compile: mergeTargetDefault(nxJson.targetDefaults?.compile, (base) => ({\n ...base,\n syncGenerators: [\n ...(base.syncGenerators ?? []).filter(\n (g) =>\n ![TS_SYNC_GENERATOR_NAME, NX_TYPESCRIPT_SYNC_GENERATOR].includes(\n g,\n ),\n ),\n NX_TYPESCRIPT_SYNC_GENERATOR,\n TS_SYNC_GENERATOR_NAME,\n ],\n })),\n },\n });\n\n const CONVENIENCE_SCRIPTS = {\n dev: 'nx run-many --target dev',\n build: 'nx run-many --target build',\n lint: 'nx run-many --target lint --configuration=fix',\n test: 'nx run-many --target test --all',\n // Trivy container image scanning is not part of `build` (its result\n // depends on the ever-changing vulnerability database); run it explicitly,\n // e.g. in CI.\n trivy: 'nx run-many --target trivy --all',\n 'build:skip-lint': 'nx run-many --target build --configuration=skip-lint',\n 'build:all': 'nx run-many --target build --all',\n 'affected:all': 'nx affected --target build',\n };\n updateJson(tree, 'package.json', (packageJson) => ({\n ...packageJson,\n // The root `type` field is owned by the preset (written explicitly from\n // its `--module` option). `init` preserves an existing workspace's field\n // as-is: an ESM workspace already carries `type: \"module\"` (that is how\n // the format is inferred), and introducing a `type` into a CommonJS\n // workspace that lacks one changes behaviour for frameworks that parse it\n // (e.g. Next.js starts treating the app's ESM source as CJS).\n scripts: overwriteScripts\n ? { ...packageJson.scripts, ...CONVENIENCE_SCRIPTS }\n : { ...CONVENIENCE_SCRIPTS, ...packageJson.scripts },\n }));\n\n // Pin the workspace's `nx` to the version the plugin's @nx/* packages are\n // built against. A mismatched workspace nx (even a patch apart) hoists a\n // second nested nx under @nx/js, and the two instances deadlock `nx sync`.\n // `@nx/js` must be a root dependency for the `@nx/js:typescript-sync`\n // generator registered in nx.json to resolve (npm doesn't hoist the\n // plugin's own copy reliably).\n addDependenciesToPackageJson(\n tree,\n {},\n {\n ...withVersions(forDependencies<typeof INIT_DEPENDENCIES>(declaration), [\n 'nx',\n '@nx/js',\n '@nx/workspace',\n ]),\n ...withVersions(forDependencies<typeof INIT_DEPENDENCIES>(declaration), [\n 'typescript',\n '@biomejs/biome',\n ]),\n // Declare the plugin the generators are running from, plus the MCP server\n // package the vended config runs, so both are pinned in the workspace's\n // lockfile and upgrading them upgrades what the agents use.\n ...nxPluginSelfDependency(tree),\n ...nxPluginMcpDependency(tree),\n },\n );\n\n // Write biome.json for formatting and linting\n if (!tree.exists('biome.json')) {\n tree.write(\n 'biome.json',\n JSON.stringify(getDefaultBiomeConfig(tree), null, 2),\n );\n }\n\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, '..', 'preset', 'files'),\n '.',\n {\n projectName: getNpmScope(tree),\n generators: Object.entries(generatorsJsonEntries)\n .filter(([, info]) => !info.hidden)\n .map(([id, info]) => ({\n name: id,\n description: describeGeneratorForCatalogue(info),\n })),\n ...(() => {\n const cmds = getPackageManagerDisplayCommands();\n return {\n pkgMgrCmd: cmds.exec,\n buildCmd: `${cmds.run} build`,\n lintCmd: `${cmds.run} lint`,\n };\n })(),\n },\n {\n overwriteStrategy: readmeOverwriteStrategy,\n },\n );\n\n if (mcp !== false) {\n configureMcpServers(tree);\n }\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readNxJson","updateJson","updateNxJson","initGenerator","yaml","SYNC_GENERATOR_NAME","TS_SYNC_GENERATOR_NAME","BASE_TSCONFIG_COMPILER_OPTIONS","ensureAwsNxPluginConfig","updateAwsNxPluginConfig","inferContainers","forDependencies","addDependenciesToPackageJson","detectWorkspacePackageManager","getDefaultBiomeConfig","describeGeneratorForCatalogue","generatorsJsonEntries","updateGitIgnore","configureMcpServers","getNpmScope","mergeTargetDefault","nxPluginMcpDependency","nxPluginSelfDependency","getPackageManagerDisplayCommands","workspaceGlobs","withVersions","WORKSPACES","NX_TYPESCRIPT_SYNC_GENERATOR","DEFAULT_PARALLEL","INIT_DEPENDENCIES","name","PNPM_BUILT_DEPENDENCIES","setUpPnpmWorkspace","tree","catalogs","existing","exists","load","read","packages","Array","from","Set","allowBuilds","Object","fromEntries","map","dep","catalogMode","write","dump","onlyBuiltDependencies","quotingType","setUpWorkspaces","patterns","json","globs","workspaces","undefined","isArray","ensureBaseTsConfig","JSON","stringify","compilerOptions","customConditions","ensureRootTsConfig","extends","files","references","applyWorkspaceInit","iac","containers","mcp","readmeOverwriteStrategy","KeepExisting","overwriteScripts","declaration","resolvedContainers","provider","engine","packageManager","formatter","addTsPlugin","nxJson","analytics","parallel","targetDefaults","compile","base","syncGenerators","filter","g","includes","CONVENIENCE_SCRIPTS","dev","build","lint","test","trivy","packageJson","scripts","dirname","projectName","generators","entries","info","hidden","id","description","cmds","pkgMgrCmd","exec","buildCmd","run","lintCmd","overwriteStrategy"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,UAAU,EAEVC,UAAU,EACVC,YAAY,QACP,aAAa;AACpB,SAASC,aAAa,QAAQ,SAAS;AAEvC,OAAOC,UAAU,UAAU;AAC3B,SAASC,uBAAuBC,sBAAsB,QAAQ,0BAA0B;AACxF,SAASC,8BAA8B,QAAQ,qBAAqB;AACpE,SACEC,uBAAuB,EACvBC,uBAAuB,QAClB,oBAAoB;AAC3B,SAA0BC,eAAe,QAAQ,kBAAkB;AACnE,SAEEC,eAAe,QAEV,6BAA6B;AACpC,SACEC,4BAA4B,EAC5BC,6BAA6B,QACxB,oBAAoB;AAC3B,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SACEC,6BAA6B,EAC7BC,qBAAqB,QAChB,kBAAkB;AACzB,SAASC,eAAe,QAAQ,WAAW;AAE3C,SAASC,mBAAmB,QAAQ,WAAW;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SACEC,kBAAkB,EAClBC,qBAAqB,EACrBC,sBAAsB,QACjB,UAAU;AACjB,SAASC,gCAAgC,QAAQ,mBAAmB;AACpE,SAASC,cAAc,QAAQ,4BAA4B;AAC3D,SAA6BC,YAAY,QAAQ,gBAAgB;AAEjE,MAAMC,aAAa;IAAC;CAAa;AACjC,MAAMC,+BAA+B;AAErC,OAAO,MAAMC,mBAAmB,EAAE;AAElC,oEAAoE,GACpE,OAAO,MAAMC,oBAAoB;IAC/B;QAAEC,MAAM;IAAK;IACb;QAAEA,MAAM;IAAS;IACjB;QAAEA,MAAM;IAAgB;IACxB;QAAEA,MAA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|
|
6
6
|
/**
|
|
7
|
-
* Merge `allowBuilds` (pnpm 11) / `onlyBuiltDependencies` (pnpm 10)
|
|
8
|
-
* into the generated workspace's `pnpm-workspace.yaml`. No-op for
|
|
9
|
-
* workspaces.
|
|
7
|
+
* Merge `allowBuilds` (pnpm 11 and above) / `onlyBuiltDependencies` (pnpm 10)
|
|
8
|
+
* entries into the generated workspace's `pnpm-workspace.yaml`. No-op for
|
|
9
|
+
* non-pnpm workspaces.
|
|
10
10
|
*
|
|
11
11
|
* Generators call this when they introduce a dependency whose install
|
|
12
|
-
* script pnpm would otherwise reject under
|
|
12
|
+
* script pnpm would otherwise reject under the default
|
|
13
13
|
* `strictDepBuilds=true`. Keeping the allowlist explicit — rather than
|
|
14
|
-
* globally disabling strictness — preserves the supply-chain audit pnpm
|
|
14
|
+
* globally disabling strictness — preserves the supply-chain audit pnpm
|
|
15
15
|
* intends: each build-script dep is reviewed by the generator author and
|
|
16
16
|
* entered as either `true` (run the script) or `false` (known dep we
|
|
17
17
|
* don't want to run but have seen).
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
import { detectWorkspacePackageManager } from "./dependencies.js";
|
|
6
6
|
const WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
7
7
|
/**
|
|
8
|
-
* Merge `allowBuilds` (pnpm 11) / `onlyBuiltDependencies` (pnpm 10)
|
|
9
|
-
* into the generated workspace's `pnpm-workspace.yaml`. No-op for
|
|
10
|
-
* workspaces.
|
|
8
|
+
* Merge `allowBuilds` (pnpm 11 and above) / `onlyBuiltDependencies` (pnpm 10)
|
|
9
|
+
* entries into the generated workspace's `pnpm-workspace.yaml`. No-op for
|
|
10
|
+
* non-pnpm workspaces.
|
|
11
11
|
*
|
|
12
12
|
* Generators call this when they introduce a dependency whose install
|
|
13
|
-
* script pnpm would otherwise reject under
|
|
13
|
+
* script pnpm would otherwise reject under the default
|
|
14
14
|
* `strictDepBuilds=true`. Keeping the allowlist explicit — rather than
|
|
15
|
-
* globally disabling strictness — preserves the supply-chain audit pnpm
|
|
15
|
+
* globally disabling strictness — preserves the supply-chain audit pnpm
|
|
16
16
|
* intends: each build-script dep is reviewed by the generator author and
|
|
17
17
|
* entered as either `true` (run the script) or `false` (known dep we
|
|
18
18
|
* don't want to run but have seen).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/pnpm-workspace.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 yaml from 'js-yaml';\nimport { detectWorkspacePackageManager } from './dependencies.js';\n\nconst WORKSPACE_FILE = 'pnpm-workspace.yaml';\n\ninterface PnpmWorkspaceYaml {\n allowBuilds?: Record<string, boolean>;\n onlyBuiltDependencies?: string[];\n [key: string]: unknown;\n}\n\n/**\n * Merge `allowBuilds` (pnpm 11) / `onlyBuiltDependencies` (pnpm 10)
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/pnpm-workspace.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 yaml from 'js-yaml';\nimport { detectWorkspacePackageManager } from './dependencies.js';\n\nconst WORKSPACE_FILE = 'pnpm-workspace.yaml';\n\ninterface PnpmWorkspaceYaml {\n allowBuilds?: Record<string, boolean>;\n onlyBuiltDependencies?: string[];\n [key: string]: unknown;\n}\n\n/**\n * Merge `allowBuilds` (pnpm 11 and above) / `onlyBuiltDependencies` (pnpm 10)\n * entries into the generated workspace's `pnpm-workspace.yaml`. No-op for\n * non-pnpm workspaces.\n *\n * Generators call this when they introduce a dependency whose install\n * script pnpm would otherwise reject under the default\n * `strictDepBuilds=true`. Keeping the allowlist explicit — rather than\n * globally disabling strictness — preserves the supply-chain audit pnpm\n * intends: each build-script dep is reviewed by the generator author and\n * entered as either `true` (run the script) or `false` (known dep we\n * don't want to run but have seen).\n *\n * Only `true` entries are also added to `onlyBuiltDependencies` (pnpm 10's\n * allowlist has no equivalent of the `false` decision).\n */\nexport const registerPnpmBuiltDependencies = (\n tree: Tree,\n entries: Record<string, boolean>,\n): void => {\n if (detectWorkspacePackageManager(tree) !== 'pnpm') {\n return;\n }\n if (!tree.exists(WORKSPACE_FILE)) {\n return;\n }\n\n const original = tree.read(WORKSPACE_FILE, 'utf-8') ?? '';\n const parsed = (yaml.load(original) as PnpmWorkspaceYaml | null) ?? {};\n\n const allowBuilds = { ...(parsed.allowBuilds ?? {}) };\n const onlyBuiltDependencies = new Set(parsed.onlyBuiltDependencies ?? []);\n let changed = false;\n\n for (const [pkg, decision] of Object.entries(entries)) {\n if (allowBuilds[pkg] !== decision) {\n allowBuilds[pkg] = decision;\n changed = true;\n }\n if (decision === true && !onlyBuiltDependencies.has(pkg)) {\n onlyBuiltDependencies.add(pkg);\n changed = true;\n }\n }\n\n if (!changed) {\n return;\n }\n\n parsed.allowBuilds = allowBuilds;\n parsed.onlyBuiltDependencies = [...onlyBuiltDependencies];\n\n tree.write(WORKSPACE_FILE, yaml.dump(parsed, { quotingType: \"'\" }));\n};\n"],"names":["yaml","detectWorkspacePackageManager","WORKSPACE_FILE","registerPnpmBuiltDependencies","tree","entries","exists","original","read","parsed","load","allowBuilds","onlyBuiltDependencies","Set","changed","pkg","decision","Object","has","add","write","dump","quotingType"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,UAAU,UAAU;AAC3B,SAASC,6BAA6B,QAAQ,oBAAoB;AAElE,MAAMC,iBAAiB;AAQvB;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,gCAAgC,CAC3CC,MACAC;IAEA,IAAIJ,8BAA8BG,UAAU,QAAQ;QAClD;IACF;IACA,IAAI,CAACA,KAAKE,MAAM,CAACJ,iBAAiB;QAChC;IACF;IAEA,MAAMK,WAAWH,KAAKI,IAAI,CAACN,gBAAgB,YAAY;IACvD,MAAMO,SAAS,AAACT,KAAKU,IAAI,CAACH,aAA0C,CAAC;IAErE,MAAMI,cAAc;QAAE,GAAIF,OAAOE,WAAW,IAAI,CAAC,CAAC;IAAE;IACpD,MAAMC,wBAAwB,IAAIC,IAAIJ,OAAOG,qBAAqB,IAAI,EAAE;IACxE,IAAIE,UAAU;IAEd,KAAK,MAAM,CAACC,KAAKC,SAAS,IAAIC,OAAOZ,OAAO,CAACA,SAAU;QACrD,IAAIM,WAAW,CAACI,IAAI,KAAKC,UAAU;YACjCL,WAAW,CAACI,IAAI,GAAGC;YACnBF,UAAU;QACZ;QACA,IAAIE,aAAa,QAAQ,CAACJ,sBAAsBM,GAAG,CAACH,MAAM;YACxDH,sBAAsBO,GAAG,CAACJ;YAC1BD,UAAU;QACZ;IACF;IAEA,IAAI,CAACA,SAAS;QACZ;IACF;IAEAL,OAAOE,WAAW,GAAGA;IACrBF,OAAOG,qBAAqB,GAAG;WAAIA;KAAsB;IAEzDR,KAAKgB,KAAK,CAAClB,gBAAgBF,KAAKqB,IAAI,CAACZ,QAAQ;QAAEa,aAAa;IAAI;AAClE,EAAE"}
|
|
@@ -27,5 +27,27 @@ export declare const SHADCN_DEPENDENCIES: readonly [{
|
|
|
27
27
|
readonly name: "vitest";
|
|
28
28
|
}, {
|
|
29
29
|
readonly name: "@vitest/coverage-v8";
|
|
30
|
+
}, {
|
|
31
|
+
readonly name: "jsdom";
|
|
32
|
+
}, {
|
|
33
|
+
readonly name: "@nx/vitest";
|
|
34
|
+
readonly dev: true;
|
|
35
|
+
readonly root: true;
|
|
36
|
+
}, {
|
|
37
|
+
readonly name: "@types/node";
|
|
38
|
+
readonly dev: true;
|
|
39
|
+
}, {
|
|
40
|
+
readonly name: "@types/node";
|
|
41
|
+
readonly dev: true;
|
|
42
|
+
readonly root: true;
|
|
30
43
|
}];
|
|
44
|
+
/** The shared shadcn package's fully-qualified npm name for this workspace. */
|
|
45
|
+
export declare const getSharedShadcnFullyQualifiedName: (tree: Tree) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Declares a `workspace:*` dependency on the shared shadcn package in a
|
|
48
|
+
* consumer's own package.json, so it resolves through the shared package's
|
|
49
|
+
* `exports` map (real package resolution) rather than a tsconfig `paths`
|
|
50
|
+
* alias - see `sharedShadcnGenerator` for why.
|
|
51
|
+
*/
|
|
52
|
+
export declare const addSharedShadcnDependency: (tree: Tree, consumerDir: string) => void;
|
|
31
53
|
export declare function sharedShadcnGenerator<const D extends DependencyDeclaration>(tree: Tree, declaration: D & MustDeclare<typeof SHADCN_DEPENDENCIES, D>): Promise<void>;
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { generateFiles, joinPathFragments, OverwriteStrategy, updateJson } from "@nx/devkit";
|
|
5
5
|
import tsProjectGenerator from "../ts/lib/generator.js";
|
|
6
|
-
import { configureTsProject } from "../ts/lib/ts-project-utils.js";
|
|
6
|
+
import { configureTsProject, TS_PROJECT_DEPENDENCIES } from "../ts/lib/ts-project-utils.js";
|
|
7
7
|
import { VITEST_DEPENDENCIES } from "../ts/lib/vitest.js";
|
|
8
8
|
import { declaredNames, forDependencies } from "./declared-dependencies.js";
|
|
9
|
-
import { addDependenciesToPackageJson } from "./dependencies.js";
|
|
9
|
+
import { addDependenciesToPackageJson, getLocalDependencySpecifier } from "./dependencies.js";
|
|
10
10
|
import { formatFilesInSubtree } from "./format.js";
|
|
11
11
|
import { esmVars } from "./module-format.js";
|
|
12
12
|
import { getNpmScopePrefix } from "./npm-scope.js";
|
|
@@ -37,13 +37,22 @@ import { withVersions } from "./versions.js";
|
|
|
37
37
|
{
|
|
38
38
|
name: 'radix-ui'
|
|
39
39
|
},
|
|
40
|
-
...VITEST_DEPENDENCIES
|
|
40
|
+
...VITEST_DEPENDENCIES,
|
|
41
|
+
...TS_PROJECT_DEPENDENCIES
|
|
41
42
|
];
|
|
43
|
+
/** The shared shadcn package's fully-qualified npm name for this workspace. */ export const getSharedShadcnFullyQualifiedName = (tree)=>`${getNpmScopePrefix(tree)}${SHARED_SHADCN_NAME}`;
|
|
44
|
+
/**
|
|
45
|
+
* Declares a `workspace:*` dependency on the shared shadcn package in a
|
|
46
|
+
* consumer's own package.json, so it resolves through the shared package's
|
|
47
|
+
* `exports` map (real package resolution) rather than a tsconfig `paths`
|
|
48
|
+
* alias - see `sharedShadcnGenerator` for why.
|
|
49
|
+
*/ export const addSharedShadcnDependency = (tree, consumerDir)=>{
|
|
50
|
+
addDependenciesToPackageJson(tree, {
|
|
51
|
+
[getSharedShadcnFullyQualifiedName(tree)]: getLocalDependencySpecifier(tree)
|
|
52
|
+
}, {}, joinPathFragments(consumerDir, 'package.json'));
|
|
53
|
+
};
|
|
42
54
|
export async function sharedShadcnGenerator(tree, declaration) {
|
|
43
|
-
const
|
|
44
|
-
const scopeAlias = npmScopePrefix;
|
|
45
|
-
const sharedShadcnAlias = `${scopeAlias}${SHARED_SHADCN_NAME}`;
|
|
46
|
-
const fullyQualifiedName = `${npmScopePrefix}${SHARED_SHADCN_NAME}`;
|
|
55
|
+
const fullyQualifiedName = getSharedShadcnFullyQualifiedName(tree);
|
|
47
56
|
const libraryRoot = joinPathFragments(PACKAGES_DIR, SHARED_SHADCN_DIR);
|
|
48
57
|
const shadcnSrcRoot = joinPathFragments(libraryRoot, 'src');
|
|
49
58
|
if (!tree.exists(joinPathFragments(libraryRoot, 'project.json'))) {
|
|
@@ -53,15 +62,11 @@ export async function sharedShadcnGenerator(tree, declaration) {
|
|
|
53
62
|
subDirectory: SHARED_SHADCN_DIR
|
|
54
63
|
});
|
|
55
64
|
tree.delete(shadcnSrcRoot);
|
|
56
|
-
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', SHARED_SHADCN_DIR, 'src'), shadcnSrcRoot, {
|
|
57
|
-
scopeAlias,
|
|
58
|
-
...esmVars(tree)
|
|
59
|
-
}, {
|
|
65
|
+
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', SHARED_SHADCN_DIR, 'src'), shadcnSrcRoot, esmVars(tree), {
|
|
60
66
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
61
67
|
});
|
|
62
68
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', SHARED_SHADCN_DIR, 'readme'), libraryRoot, {
|
|
63
|
-
fullyQualifiedName
|
|
64
|
-
scopeAlias
|
|
69
|
+
fullyQualifiedName
|
|
65
70
|
}, {
|
|
66
71
|
overwriteStrategy: OverwriteStrategy.Overwrite
|
|
67
72
|
});
|
|
@@ -87,25 +92,31 @@ export async function sharedShadcnGenerator(tree, declaration) {
|
|
|
87
92
|
]))
|
|
88
93
|
}));
|
|
89
94
|
addDependenciesToPackageJson(tree, withVersions(forDependencies(declaration), declaredNames(SHADCN_DEPENDENCIES)), {}, joinPathFragments(libraryRoot, 'package.json'));
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
// shadcn 4.x's CLI resolves the `components.json` alias via `imports`/
|
|
96
|
+
// `exports` (Node's package resolution), not a tsconfig `paths` alias.
|
|
97
|
+
// `imports` covers this package's own internal component-to-component
|
|
98
|
+
// references (aliased in components.json below); `exports` covers every
|
|
99
|
+
// other consumer.
|
|
100
|
+
updateJson(tree, joinPathFragments(libraryRoot, 'package.json'), (packageJson)=>({
|
|
101
|
+
...packageJson,
|
|
102
|
+
imports: {
|
|
103
|
+
'#components/*': './src/components/*.tsx',
|
|
104
|
+
'#lib/*': './src/lib/*.ts',
|
|
105
|
+
'#hooks/*': './src/hooks/*.ts'
|
|
106
|
+
},
|
|
107
|
+
exports: {
|
|
108
|
+
'.': './src/index.ts',
|
|
109
|
+
'./styles/*': './src/styles/*',
|
|
110
|
+
'./components/*': './src/components/*.tsx',
|
|
111
|
+
'./lib/*': './src/lib/*.ts',
|
|
112
|
+
'./hooks/*': './src/hooks/*.ts'
|
|
100
113
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
103
116
|
// components.json lives in the package so `shadcn add` runs there and
|
|
104
117
|
// installs component dependencies into the package's own manifest.
|
|
105
118
|
if (!tree.exists(joinPathFragments(libraryRoot, 'components.json'))) {
|
|
106
|
-
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'shadcn'), libraryRoot, {
|
|
107
|
-
sharedShadcnAlias
|
|
108
|
-
}, {
|
|
119
|
+
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'shadcn'), libraryRoot, {}, {
|
|
109
120
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
110
121
|
});
|
|
111
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/shared-shadcn.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../ts/lib/generator.js';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/shared-shadcn.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../ts/lib/generator.js';\nimport {\n configureTsProject,\n TS_PROJECT_DEPENDENCIES,\n} from '../ts/lib/ts-project-utils.js';\nimport { VITEST_DEPENDENCIES } from '../ts/lib/vitest.js';\nimport {\n type DependencyDeclaration,\n declaredNames,\n forDependencies,\n type MustDeclare,\n} from './declared-dependencies.js';\nimport {\n addDependenciesToPackageJson,\n getLocalDependencySpecifier,\n} from './dependencies.js';\nimport { formatFilesInSubtree } from './format.js';\nimport { esmVars } from './module-format.js';\nimport { getNpmScopePrefix } from './npm-scope.js';\nimport {\n PACKAGES_DIR,\n SHARED_SHADCN_DIR,\n SHARED_SHADCN_NAME,\n} from './shared-constructs-constants.js';\nimport { type ITsDepVersion, withVersions } from './versions.js';\n\n/** Dependencies a caller must declare to use the shared shadcn project. */\nexport const SHADCN_DEPENDENCIES = [\n { name: 'react' },\n { name: 'react-dom' },\n { name: 'class-variance-authority' },\n { name: 'clsx' },\n { name: 'tailwind-merge' },\n { name: 'lucide-react' },\n { name: 'tw-animate-css' },\n { name: 'radix-ui' },\n ...VITEST_DEPENDENCIES,\n ...TS_PROJECT_DEPENDENCIES,\n] as const satisfies readonly { name: ITsDepVersion; dev?: boolean }[];\n\n/** The shared shadcn package's fully-qualified npm name for this workspace. */\nexport const getSharedShadcnFullyQualifiedName = (tree: Tree): string =>\n `${getNpmScopePrefix(tree)}${SHARED_SHADCN_NAME}`;\n\n/**\n * Declares a `workspace:*` dependency on the shared shadcn package in a\n * consumer's own package.json, so it resolves through the shared package's\n * `exports` map (real package resolution) rather than a tsconfig `paths`\n * alias - see `sharedShadcnGenerator` for why.\n */\nexport const addSharedShadcnDependency = (\n tree: Tree,\n consumerDir: string,\n): void => {\n addDependenciesToPackageJson(\n tree,\n {\n [getSharedShadcnFullyQualifiedName(tree)]:\n getLocalDependencySpecifier(tree),\n },\n {},\n joinPathFragments(consumerDir, 'package.json'),\n );\n};\n\nexport async function sharedShadcnGenerator<\n const D extends DependencyDeclaration,\n>(tree: Tree, declaration: D & MustDeclare<typeof SHADCN_DEPENDENCIES, D>) {\n const fullyQualifiedName = getSharedShadcnFullyQualifiedName(tree);\n const libraryRoot = joinPathFragments(PACKAGES_DIR, SHARED_SHADCN_DIR);\n const shadcnSrcRoot = joinPathFragments(libraryRoot, 'src');\n\n if (!tree.exists(joinPathFragments(libraryRoot, 'project.json'))) {\n await tsProjectGenerator(tree, {\n name: SHARED_SHADCN_NAME,\n directory: PACKAGES_DIR,\n subDirectory: SHARED_SHADCN_DIR,\n });\n\n tree.delete(shadcnSrcRoot);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', SHARED_SHADCN_DIR, 'src'),\n shadcnSrcRoot,\n esmVars(tree),\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n SHARED_SHADCN_DIR,\n 'readme',\n ),\n libraryRoot,\n {\n fullyQualifiedName,\n },\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n await configureTsProject(\n tree,\n {\n dir: libraryRoot,\n fullyQualifiedName,\n },\n forDependencies<typeof SHADCN_DEPENDENCIES>(declaration),\n );\n\n updateJson(\n tree,\n joinPathFragments(libraryRoot, 'tsconfig.lib.json'),\n (json) => ({\n ...json,\n compilerOptions: {\n ...json.compilerOptions,\n jsx: 'react-jsx',\n module: 'preserve',\n moduleResolution: 'bundler',\n lib: Array.from(\n new Set([...(json.compilerOptions?.lib ?? []), 'DOM']),\n ),\n },\n include: Array.from(new Set([...(json.include ?? []), 'src/**/*.tsx'])),\n }),\n );\n\n addDependenciesToPackageJson(\n tree,\n withVersions(\n forDependencies<typeof SHADCN_DEPENDENCIES>(declaration),\n declaredNames(SHADCN_DEPENDENCIES),\n ),\n {},\n joinPathFragments(libraryRoot, 'package.json'),\n );\n\n // shadcn 4.x's CLI resolves the `components.json` alias via `imports`/\n // `exports` (Node's package resolution), not a tsconfig `paths` alias.\n // `imports` covers this package's own internal component-to-component\n // references (aliased in components.json below); `exports` covers every\n // other consumer.\n updateJson(\n tree,\n joinPathFragments(libraryRoot, 'package.json'),\n (packageJson) => ({\n ...packageJson,\n imports: {\n '#components/*': './src/components/*.tsx',\n '#lib/*': './src/lib/*.ts',\n '#hooks/*': './src/hooks/*.ts',\n },\n exports: {\n '.': './src/index.ts',\n './styles/*': './src/styles/*',\n './components/*': './src/components/*.tsx',\n './lib/*': './src/lib/*.ts',\n './hooks/*': './src/hooks/*.ts',\n },\n }),\n );\n }\n\n // components.json lives in the package so `shadcn add` runs there and\n // installs component dependencies into the package's own manifest.\n if (!tree.exists(joinPathFragments(libraryRoot, 'components.json'))) {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'shadcn'),\n libraryRoot,\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n await formatFilesInSubtree(tree);\n}\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","tsProjectGenerator","configureTsProject","TS_PROJECT_DEPENDENCIES","VITEST_DEPENDENCIES","declaredNames","forDependencies","addDependenciesToPackageJson","getLocalDependencySpecifier","formatFilesInSubtree","esmVars","getNpmScopePrefix","PACKAGES_DIR","SHARED_SHADCN_DIR","SHARED_SHADCN_NAME","withVersions","SHADCN_DEPENDENCIES","name","getSharedShadcnFullyQualifiedName","tree","addSharedShadcnDependency","consumerDir","sharedShadcnGenerator","declaration","fullyQualifiedName","libraryRoot","shadcnSrcRoot","exists","directory","subDirectory","delete","dirname","overwriteStrategy","KeepExisting","Overwrite","dir","json","compilerOptions","jsx","module","moduleResolution","lib","Array","from","Set","include","packageJson","imports","exports"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,UAAU,QACL,aAAa;AACpB,OAAOC,wBAAwB,yBAAyB;AACxD,SACEC,kBAAkB,EAClBC,uBAAuB,QAClB,gCAAgC;AACvC,SAASC,mBAAmB,QAAQ,sBAAsB;AAC1D,SAEEC,aAAa,EACbC,eAAe,QAEV,6BAA6B;AACpC,SACEC,4BAA4B,EAC5BC,2BAA2B,QACtB,oBAAoB;AAC3B,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,OAAO,QAAQ,qBAAqB;AAC7C,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SACEC,YAAY,EACZC,iBAAiB,EACjBC,kBA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EgB,KAAKV;YACLD;QACF,GACAlB,gBAA4CiB;QAG9CvB,WACEmB,MACArB,kBAAkB2B,aAAa,sBAC/B,CAACW,OAAU,CAAA;gBACT,GAAGA,IAAI;gBACPC,iBAAiB;oBACf,GAAGD,KAAKC,eAAe;oBACvBC,KAAK;oBACLC,QAAQ;oBACRC,kBAAkB;oBAClBC,KAAKC,MAAMC,IAAI,CACb,IAAIC,IAAI;2BAAKR,KAAKC,eAAe,EAAEI,OAAO,EAAE;wBAAG;qBAAM;gBAEzD;gBACAI,SAASH,MAAMC,IAAI,CAAC,IAAIC,IAAI;uBAAKR,KAAKS,OAAO,IAAI,EAAE;oBAAG;iBAAe;YACvE,CAAA;QAGFtC,6BACEY,MACAJ,aACET,gBAA4CiB,cAC5ClB,cAAcW,uBAEhB,CAAC,GACDlB,kBAAkB2B,aAAa;QAGjC,uEAAuE;QACvE,uEAAuE;QACvE,sEAAsE;QACtE,wEAAwE;QACxE,kBAAkB;QAClBzB,WACEmB,MACArB,kBAAkB2B,aAAa,iBAC/B,CAACqB,cAAiB,CAAA;gBAChB,GAAGA,WAAW;gBACdC,SAAS;oBACP,iBAAiB;oBACjB,UAAU;oBACV,YAAY;gBACd;gBACAC,SAAS;oBACP,KAAK;oBACL,cAAc;oBACd,kBAAkB;oBAClB,WAAW;oBACX,aAAa;gBACf;YACF,CAAA;IAEJ;IAEA,sEAAsE;IACtE,mEAAmE;IACnE,IAAI,CAAC7B,KAAKQ,MAAM,CAAC7B,kBAAkB2B,aAAa,qBAAqB;QACnE5B,cACEsB,MACArB,kBAAkB,YAAYiC,OAAO,EAAE,SAAS,WAChDN,aACA,CAAC,GACD;YACEO,mBAAmBjC,kBAAkBkC,YAAY;QACnD;IAEJ;IAEA,MAAMxB,qBAAqBU;AAC7B"}
|
package/src/utils/test.js
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
|
|
6
6
|
import { expect } from "vitest";
|
|
7
7
|
import { getDefaultBiomeConfig } from "./format.js";
|
|
8
|
+
/** Formatter configs Nx discovers and formats generated files with. */ const NX_FORMATTER_CONFIG_FILES = [
|
|
9
|
+
'.oxfmtrc.json',
|
|
10
|
+
'.oxfmtrc.jsonc',
|
|
11
|
+
'oxfmt.config.ts',
|
|
12
|
+
'oxfmt.config.mts',
|
|
13
|
+
'.prettierrc'
|
|
14
|
+
];
|
|
8
15
|
/**
|
|
9
16
|
* Create a workspace tree configured so that nx's `isUsingTsSolutionSetup`
|
|
10
17
|
* reports `true`, matching the workspaces our preset generates. Rather than
|
|
@@ -16,6 +23,14 @@ import { getDefaultBiomeConfig } from "./format.js";
|
|
|
16
23
|
* preset establishes
|
|
17
24
|
*/ export const createTreeUsingTsSolutionSetup = ()=>{
|
|
18
25
|
const tree = createTreeWithEmptyWorkspace();
|
|
26
|
+
// `createTreeWithEmptyWorkspace` seeds a formatter config Nx then formats
|
|
27
|
+
// generated files with. Our workspaces select `formatter: 'none'` and format
|
|
28
|
+
// with biome, so remove it to match what the preset produces.
|
|
29
|
+
for (const config of NX_FORMATTER_CONFIG_FILES){
|
|
30
|
+
if (tree.exists(config)) {
|
|
31
|
+
tree.delete(config);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
19
34
|
tree.write('pnpm-workspace.yaml', `packages:\n - packages/*`);
|
|
20
35
|
// Write both workspace markers so package-manager detection finds workspaces
|
|
21
36
|
// enabled whether tests run via pnpm or npm/npx.
|
package/src/utils/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/test.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n joinPathFragments,\n readJson,\n type Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';\nimport { expect } from 'vitest';\nimport { getDefaultBiomeConfig } from './format.js';\n\n/**\n * Create a workspace tree configured so that nx's `isUsingTsSolutionSetup`\n * reports `true`, matching the workspaces our preset generates. Rather than\n * mocking nx internals, we set up the real markers it checks for:\n * - package manager workspaces enabled (`pnpm-workspace.yaml` with `packages`)\n * - a root `tsconfig.json` extending `tsconfig.base.json` with empty `include`\n * - `composite: true` in `tsconfig.base.json`\n * - a root `package.json` with `type: module`, matching the ESM default the\n * preset establishes\n */\nexport const createTreeUsingTsSolutionSetup = (): Tree => {\n const tree = createTreeWithEmptyWorkspace();\n\n tree.write('pnpm-workspace.yaml', `packages:\\n - packages/*`);\n\n // Write both workspace markers so package-manager detection finds workspaces\n // enabled whether tests run via pnpm or npm/npx.\n updateJson(tree, 'package.json', (json) => ({\n ...json,\n type: 'module',\n workspaces: ['packages/*'],\n }));\n\n const baseTsConfig = readJson(tree, 'tsconfig.base.json');\n writeJson(tree, 'tsconfig.base.json', {\n ...baseTsConfig,\n compilerOptions: { ...baseTsConfig.compilerOptions, composite: true },\n });\n writeJson(tree, 'tsconfig.json', {\n extends: './tsconfig.base.json',\n files: [],\n include: [],\n references: [],\n });\n\n // The preset always writes biome.json at the workspace root, so mirror that\n // here for realistic lint-target configuration.\n tree.write(\n 'biome.json',\n JSON.stringify(getDefaultBiomeConfig(tree), null, 2),\n );\n return tree;\n};\n\n/**\n * Snapshot all files within a directory in the given tree\n */\nexport const snapshotTreeDir = (tree: Tree, dir: string) => {\n if (tree.isFile(dir)) {\n expect(tree.read(dir, 'utf-8')).toMatchSnapshot(dir);\n } else {\n tree\n .children(dir)\n .forEach((subDir) =>\n snapshotTreeDir(tree, joinPathFragments(dir, subDir)),\n );\n }\n};\n"],"names":["joinPathFragments","readJson","updateJson","writeJson","createTreeWithEmptyWorkspace","expect","getDefaultBiomeConfig","createTreeUsingTsSolutionSetup","tree","write","json","type","workspaces","baseTsConfig","compilerOptions","composite","extends","files","include","references","JSON","stringify","snapshotTreeDir","dir","isFile","read","toMatchSnapshot","children","forEach","subDir"],"mappings":"AAAA;;;CAGC,GAED,SACEA,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,SAAS,QACJ,aAAa;AACpB,SAASC,4BAA4B,QAAQ,qBAAqB;AAClE,SAASC,MAAM,QAAQ,SAAS;AAChC,SAASC,qBAAqB,QAAQ,cAAc;AAEpD;;;;;;;;;CASC,GACD,OAAO,MAAMC,iCAAiC;IAC5C,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/test.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n joinPathFragments,\n readJson,\n type Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';\nimport { expect } from 'vitest';\nimport { getDefaultBiomeConfig } from './format.js';\n\n/** Formatter configs Nx discovers and formats generated files with. */\nconst NX_FORMATTER_CONFIG_FILES = [\n '.oxfmtrc.json',\n '.oxfmtrc.jsonc',\n 'oxfmt.config.ts',\n 'oxfmt.config.mts',\n '.prettierrc',\n];\n\n/**\n * Create a workspace tree configured so that nx's `isUsingTsSolutionSetup`\n * reports `true`, matching the workspaces our preset generates. Rather than\n * mocking nx internals, we set up the real markers it checks for:\n * - package manager workspaces enabled (`pnpm-workspace.yaml` with `packages`)\n * - a root `tsconfig.json` extending `tsconfig.base.json` with empty `include`\n * - `composite: true` in `tsconfig.base.json`\n * - a root `package.json` with `type: module`, matching the ESM default the\n * preset establishes\n */\nexport const createTreeUsingTsSolutionSetup = (): Tree => {\n const tree = createTreeWithEmptyWorkspace();\n\n // `createTreeWithEmptyWorkspace` seeds a formatter config Nx then formats\n // generated files with. Our workspaces select `formatter: 'none'` and format\n // with biome, so remove it to match what the preset produces.\n for (const config of NX_FORMATTER_CONFIG_FILES) {\n if (tree.exists(config)) {\n tree.delete(config);\n }\n }\n\n tree.write('pnpm-workspace.yaml', `packages:\\n - packages/*`);\n\n // Write both workspace markers so package-manager detection finds workspaces\n // enabled whether tests run via pnpm or npm/npx.\n updateJson(tree, 'package.json', (json) => ({\n ...json,\n type: 'module',\n workspaces: ['packages/*'],\n }));\n\n const baseTsConfig = readJson(tree, 'tsconfig.base.json');\n writeJson(tree, 'tsconfig.base.json', {\n ...baseTsConfig,\n compilerOptions: { ...baseTsConfig.compilerOptions, composite: true },\n });\n writeJson(tree, 'tsconfig.json', {\n extends: './tsconfig.base.json',\n files: [],\n include: [],\n references: [],\n });\n\n // The preset always writes biome.json at the workspace root, so mirror that\n // here for realistic lint-target configuration.\n tree.write(\n 'biome.json',\n JSON.stringify(getDefaultBiomeConfig(tree), null, 2),\n );\n return tree;\n};\n\n/**\n * Snapshot all files within a directory in the given tree\n */\nexport const snapshotTreeDir = (tree: Tree, dir: string) => {\n if (tree.isFile(dir)) {\n expect(tree.read(dir, 'utf-8')).toMatchSnapshot(dir);\n } else {\n tree\n .children(dir)\n .forEach((subDir) =>\n snapshotTreeDir(tree, joinPathFragments(dir, subDir)),\n );\n }\n};\n"],"names":["joinPathFragments","readJson","updateJson","writeJson","createTreeWithEmptyWorkspace","expect","getDefaultBiomeConfig","NX_FORMATTER_CONFIG_FILES","createTreeUsingTsSolutionSetup","tree","config","exists","delete","write","json","type","workspaces","baseTsConfig","compilerOptions","composite","extends","files","include","references","JSON","stringify","snapshotTreeDir","dir","isFile","read","toMatchSnapshot","children","forEach","subDir"],"mappings":"AAAA;;;CAGC,GAED,SACEA,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,SAAS,QACJ,aAAa;AACpB,SAASC,4BAA4B,QAAQ,qBAAqB;AAClE,SAASC,MAAM,QAAQ,SAAS;AAChC,SAASC,qBAAqB,QAAQ,cAAc;AAEpD,qEAAqE,GACrE,MAAMC,4BAA4B;IAChC;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;;;CASC,GACD,OAAO,MAAMC,iCAAiC;IAC5C,MAAMC,OAAOL;IAEb,0EAA0E;IAC1E,6EAA6E;IAC7E,8DAA8D;IAC9D,KAAK,MAAMM,UAAUH,0BAA2B;QAC9C,IAAIE,KAAKE,MAAM,CAACD,SAAS;YACvBD,KAAKG,MAAM,CAACF;QACd;IACF;IAEAD,KAAKI,KAAK,CAAC,uBAAuB,CAAC,yBAAyB,CAAC;IAE7D,6EAA6E;IAC7E,iDAAiD;IACjDX,WAAWO,MAAM,gBAAgB,CAACK,OAAU,CAAA;YAC1C,GAAGA,IAAI;YACPC,MAAM;YACNC,YAAY;gBAAC;aAAa;QAC5B,CAAA;IAEA,MAAMC,eAAehB,SAASQ,MAAM;IACpCN,UAAUM,MAAM,sBAAsB;QACpC,GAAGQ,YAAY;QACfC,iBAAiB;YAAE,GAAGD,aAAaC,eAAe;YAAEC,WAAW;QAAK;IACtE;IACAhB,UAAUM,MAAM,iBAAiB;QAC/BW,SAAS;QACTC,OAAO,EAAE;QACTC,SAAS,EAAE;QACXC,YAAY,EAAE;IAChB;IAEA,4EAA4E;IAC5E,gDAAgD;IAChDd,KAAKI,KAAK,CACR,cACAW,KAAKC,SAAS,CAACnB,sBAAsBG,OAAO,MAAM;IAEpD,OAAOA;AACT,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMiB,kBAAkB,CAACjB,MAAYkB;IAC1C,IAAIlB,KAAKmB,MAAM,CAACD,MAAM;QACpBtB,OAAOI,KAAKoB,IAAI,CAACF,KAAK,UAAUG,eAAe,CAACH;IAClD,OAAO;QACLlB,KACGsB,QAAQ,CAACJ,KACTK,OAAO,CAAC,CAACC,SACRP,gBAAgBjB,MAAMT,kBAAkB2B,KAAKM;IAEnD;AACF,EAAE"}
|
|
@@ -39,9 +39,9 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
39
39
|
/**
|
|
40
40
|
* Whether devkit may be handed this specifier.
|
|
41
41
|
*
|
|
42
|
-
* `catalog:` is only safe where devkit has a catalog manager (pnpm, yarn).
|
|
43
|
-
*
|
|
44
|
-
*
|
|
42
|
+
* `catalog:` is only safe where devkit has a catalog manager (pnpm, yarn, bun).
|
|
43
|
+
* Without one it rewrites the reference to a literal version, severing the
|
|
44
|
+
* catalog — so those references are synced directly instead.
|
|
45
45
|
*/ const isSyncableSpecifier = (tree, declared)=>{
|
|
46
46
|
// A manifest is the user's file and may hold anything. A version that isn't a
|
|
47
47
|
// string is not one this can reason about, and throwing here would abort the
|
|
@@ -132,7 +132,7 @@ import { isVendedUpgrade } from "./vended-upgrade.js";
|
|
|
132
132
|
].map((path)=>tree.exists(path) ? tree.read(path, 'utf-8') : '').join('\0');
|
|
133
133
|
/**
|
|
134
134
|
* Upgrade vended catalog entries devkit cannot reach: those no manifest
|
|
135
|
-
* references
|
|
135
|
+
* references.
|
|
136
136
|
*/ const syncOrphanCatalogEntries = (tree, owned)=>{
|
|
137
137
|
const referenced = referencedCatalogPackages(tree);
|
|
138
138
|
const updated = [];
|