diff --git a/packages/@cdktn/cli-core/src/lib/init.ts b/packages/@cdktn/cli-core/src/lib/init.ts index 4f9b417ce..3e1b4825f 100644 --- a/packages/@cdktn/cli-core/src/lib/init.ts +++ b/packages/@cdktn/cli-core/src/lib/init.ts @@ -68,7 +68,11 @@ export async function init({ providersForceLocal, silent, }: InitArgs) { - const deps: any = await determineDeps(cdktfVersion, dist); + const deps: any = await determineDeps( + cdktfVersion, + dist, + path.basename(templatePath), + ); const futureFlags = Object.entries(FUTURE_FLAGS) .map(([key, value]) => ` "${key}": "${value}"`) @@ -107,9 +111,24 @@ export interface Deps { cdktf_version: string; constructs_version: string; } +type DistKey = Exclude; + +// Each built-in template only consumes the dist artifact for its own +// language. Skipping the others lets `cdktn init --dist` work when only +// some language dists are present (e.g. CI ran `yarn package:js` only). +const distKeysByTemplate: Record = { + typescript: ["npm_cdktf"], + python: ["pypi_cdktf"], + "python-pip": ["pypi_cdktf"], + java: ["mvn_cdktf"], + csharp: ["nuget_cdktf"], + go: ["go_cdktf"], +}; + export async function determineDeps( version: string = pkg.version, dist?: string, + template?: string, ): Promise { // TS: cdktf-0.10.1-dev.2160938258 // Py: cdktf-0.10.1.dev1658821493.whl @@ -136,7 +155,16 @@ export async function determineDeps( go_cdktf: path.resolve(dist, "go", `cdktn`), }; - for (const file of Object.values(ret)) { + // If we know the template, only validate its artifact; otherwise fall + // back to validating everything (preserves prior behavior for unknown / + // remote templates). + const keysToValidate: DistKey[] = + template && distKeysByTemplate[template] + ? distKeysByTemplate[template] + : (Object.keys(ret) as DistKey[]); + + for (const key of keysToValidate) { + const file = ret[key]; if (!(await fs.pathExists(file))) { throw Errors.Internal( `unable to find ${file} under the "dist" directory (${dist})`, diff --git a/test/run-against-dist b/test/run-against-dist index 2a260cfb1..5d48119de 100755 --- a/test/run-against-dist +++ b/test/run-against-dist @@ -34,13 +34,22 @@ startLocalRegistry "$scriptdir"/verdaccio.yaml cd ${CDKTF_DIST} -# verify this is indeed a "dist" directory -if [ ! -d "js" ] || [ ! -d "python" ] || [ ! -d "java" ] || [ ! -d "dotnet" ] || [ ! -d "go" ] ; then - echo "ERROR: unable to find the subdirectories 'js', 'python', 'java', 'dotnet' and 'go' which should be in the 'dist' directory" - echo "Did you run 'yarn run package' to create the 'dist' directory?" +# The JS dist is always required — this script publishes cdktn-cli from +# dist/js and the CLI drives every language's tests. Per-language dists are +# only consumed by the jest tests passed in via $@, so missing ones surface +# as clear test failures rather than blocking the whole run. +if [ ! -d "js" ]; then + echo "ERROR: unable to find the 'js' subdirectory in the 'dist' directory" + echo "Did you run 'yarn run package' (or 'yarn run package:js') to create the 'dist' directory?" exit 1 fi +for lang in python java dotnet go; do + if [ ! -d "$lang" ]; then + echo "WARNING: dist/$lang is missing — tests for that language will fail. Run 'yarn run package:$lang' if you need it." + fi +done + echo "Publishing CLI from 'dist'..." for pkg in ${CDKTF_DIST}/js/*.tgz do