Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/@cdktn/cli-core/src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`)
Expand Down Expand Up @@ -107,9 +111,24 @@ export interface Deps {
cdktf_version: string;
constructs_version: string;
}
type DistKey = Exclude<keyof Deps, "cdktf_version" | "constructs_version">;

// 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<string, DistKey[]> = {
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<Deps> {
// TS: cdktf-0.10.1-dev.2160938258
// Py: cdktf-0.10.1.dev1658821493.whl
Expand All @@ -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})`,
Expand Down
17 changes: 13 additions & 4 deletions test/run-against-dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading