diff --git a/tools/cdk-build-tools/bin/cdk-build.ts b/tools/cdk-build-tools/bin/cdk-build.ts index d64a701c9e0a8..b2188680a475c 100644 --- a/tools/cdk-build-tools/bin/cdk-build.ts +++ b/tools/cdk-build-tools/bin/cdk-build.ts @@ -4,11 +4,28 @@ import { shell } from '../lib/os'; import { cdkBuildOptions } from '../lib/package-info'; import { Timers } from '../lib/timer'; +interface Arguments extends yargs.Arguments { + force?: boolean; + jsii?: string; + tsc?: string; +} + async function main() { - const args = yargs + const args: Arguments = yargs + .env('CDK_BUILD') .usage('Usage: cdk-build') .option('force', { type: 'boolean', alias: 'f', desc: 'Force a rebuild' }) - .argv; + .option('jsii', { + type: 'string', + desc: 'Specify a different jsii executable', + defaultDescription: 'jsii provided by node dependencies' + }) + .option('tsc', { + type: 'string', + desc: 'Specify a different tsc executable', + defaultDescription: 'tsc provided by node dependencies' + }) + .argv as any; const options = cdkBuildOptions(); @@ -21,7 +38,7 @@ async function main() { await shell(['cfn2ts', `--scope=${options.cloudformation}`], timers); } - await compileCurrentPackage(timers, args.force); + await compileCurrentPackage(timers, { jsii: args.jsii, tsc: args.tsc }, args.force); } const timers = new Timers(); diff --git a/tools/cdk-build-tools/bin/cdk-package.ts b/tools/cdk-build-tools/bin/cdk-package.ts index 30162705cbae3..41bc4741abeed 100644 --- a/tools/cdk-build-tools/bin/cdk-package.ts +++ b/tools/cdk-build-tools/bin/cdk-package.ts @@ -1,5 +1,5 @@ import fs = require('fs-extra'); -import { ChangeDetector } from "merkle-build"; +import { ChangeDetector } from 'merkle-build'; import path = require('path'); import yargs = require('yargs'); import ignoreList = require('../lib/ignore-list'); @@ -9,11 +9,23 @@ import { Timers } from '../lib/timer'; const timers = new Timers(); const buildTimer = timers.start('Total time'); +interface Arguments extends yargs.Arguments { + verbose: boolean; + jsiiPacmak: string; +} + async function main() { - const args = yargs + const args: Arguments = yargs + .env('CDK_PACKAGE') .usage('Usage: cdk-package') .option('verbose', { type: 'boolean', default: false, alias: 'v', desc: 'verbose output' }) - .argv; + .option('jsii-pacmak', { + type: 'string', + desc: 'Specify a different jsii-pacmak executable', + default: require.resolve('jsii-pacmak/bin/jsii-pacmak'), + defaultDescription: 'jsii-pacmak provided by node dependencies' + }) + .argv as any; const detector = new ChangeDetector('.', { ignore: ignoreList, @@ -36,8 +48,7 @@ async function main() { } if (pkg.jsii) { - const pacmak = require.resolve('jsii-pacmak/bin/jsii-pacmak'); - await shell([ pacmak, args.verbose ? '-vvv' : '-v', '-o', outdir ], timers); + await shell([ args.jsiiPacmak, args.verbose ? '-vvv' : '-v', '-o', outdir ], timers); } else { // just "npm pack" and deploy to "outdir" const tarball = (await shell([ 'npm', 'pack' ], timers)).trim(); diff --git a/tools/cdk-build-tools/bin/cdk-test.ts b/tools/cdk-build-tools/bin/cdk-test.ts index b15f0cb30d41d..0fc156870a0c7 100644 --- a/tools/cdk-build-tools/bin/cdk-test.ts +++ b/tools/cdk-build-tools/bin/cdk-test.ts @@ -1,15 +1,38 @@ import fs = require('fs'); import util = require('util'); +import yargs = require('yargs'); import { compileCurrentPackage } from '../lib/compile'; import { shell } from '../lib/os'; import { configFilePath, hasIntegTests, hasOnlyAutogeneratedTests, unitTestFiles } from '../lib/package-info'; import { Timers } from '../lib/timer'; +interface Arguments extends yargs.Arguments { + force?: boolean; + jsii?: string; + tsc?: string; +} + async function main() { + const args: Arguments = yargs + .env('CDK_TEST') + .usage('Usage: cdk-test') + .option('force', { type: 'boolean', alias: 'f', desc: 'Force a rebuild' }) + .option('jsii', { + type: 'string', + desc: 'Specify a different jsii executable', + defaultDescription: 'jsii provided by node dependencies' + }) + .option('tsc', { + type: 'string', + desc: 'Specify a different tsc executable', + defaultDescription: 'tsc provided by node dependencies' + }) + .argv as any; + // Always recompile before running tests, so it's impossible to forget. // During a normal build, this means we'll compile twice, but the // hash calculation makes that cheaper on CPU (if not on disk). - await compileCurrentPackage(timers); + await compileCurrentPackage(timers, { jsii: args.jsii, tsc: args.tsc }); const testFiles = await unitTestFiles(); if (testFiles.length > 0) { diff --git a/tools/cdk-build-tools/bin/cdk-watch.ts b/tools/cdk-build-tools/bin/cdk-watch.ts index 0c2d7bdf00073..d631f8e0fc162 100644 --- a/tools/cdk-build-tools/bin/cdk-watch.ts +++ b/tools/cdk-build-tools/bin/cdk-watch.ts @@ -1,11 +1,32 @@ +import yargs = require('yargs'); import { shell } from '../lib/os'; import { packageCompiler } from '../lib/package-info'; +interface Arguments extends yargs.Arguments { + jsii?: string; + tsc?: string; +} + async function main() { - await shell([packageCompiler(), '-w']); + const args: Arguments = yargs + .env('CDK_WATCH') + .usage('Usage: cdk-watch') + .option('jsii', { + type: 'string', + desc: 'Specify a different jsii executable', + defaultDescription: 'jsii provided by node dependencies' + }) + .option('tsc', { + type: 'string', + desc: 'Specify a different tsc executable', + defaultDescription: 'tsc provided by node dependencies' + }) + .argv as any; + + await shell([packageCompiler({ jsii: args.jsii, tsc: args.tsc }), '-w']); } main().catch(e => { process.stderr.write(`${e.toString()}\n`); process.exit(1); -}); \ No newline at end of file +}); diff --git a/tools/cdk-build-tools/lib/compile.ts b/tools/cdk-build-tools/lib/compile.ts index d22ac827d55f9..161a3505b077d 100644 --- a/tools/cdk-build-tools/lib/compile.ts +++ b/tools/cdk-build-tools/lib/compile.ts @@ -1,13 +1,13 @@ import { ChangeDetector } from "merkle-build"; import ignoreList = require('./ignore-list'); import { makeExecutable, shell } from "./os"; -import { currentPackageJson, packageCompiler } from "./package-info"; +import { CompilerOverrides, currentPackageJson, packageCompiler } from "./package-info"; import { Timers } from "./timer"; /** * Run the compiler on the current package */ -export async function compileCurrentPackage(timers: Timers, force?: boolean): Promise { +export async function compileCurrentPackage(timers: Timers, compilers: CompilerOverrides = {}, force?: boolean): Promise { // We don't need to do the rest if the folder hash didn't change // NOTE: This happens post-cfn2ts on purpose, since a change in cfn2ts or the spec might lead // to different generated sources, in which case we DO need to recompile. @@ -25,7 +25,7 @@ export async function compileCurrentPackage(timers: Timers, force?: boolean): Pr return; } - await shell([packageCompiler()], timers); + await shell([packageCompiler(compilers)], timers); // Find files in bin/ that look like they should be executable, and make them so. const scripts = currentPackageJson().bin || {}; diff --git a/tools/cdk-build-tools/lib/package-info.ts b/tools/cdk-build-tools/lib/package-info.ts index 94fa450db1a10..92bdc7dd0cff8 100644 --- a/tools/cdk-build-tools/lib/package-info.ts +++ b/tools/cdk-build-tools/lib/package-info.ts @@ -88,12 +88,17 @@ export async function hasIntegTests(): Promise { return files.length > 0; } +export interface CompilerOverrides { + jsii?: string; + tsc?: string; +} + /** * Return the compiler for this package (either tsc or jsii) */ -export function packageCompiler() { - return isJsii() ? require.resolve(`jsii/bin/jsii`) - : require.resolve(`typescript/bin/tsc`); +export function packageCompiler(compilers: CompilerOverrides) { + return isJsii() ? compilers.jsii || require.resolve('jsii/bin/jsii') + : compilers.tsc || require.resolve('typescript/bin/tsc'); } export interface CDKBuildOptions {