Skip to content

Commit

Permalink
chore: enable project references in build (aws#1466)
Browse files Browse the repository at this point in the history
Creating project references enables quick (and more correct) full-repo
rebuilds, as well as allowing Visual Studio to do Find References across
all packages in the repository.
  • Loading branch information
rix0rrr authored Jan 3, 2019
1 parent 0d73390 commit 0f8362d
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 63 deletions.
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ fail() {

/bin/bash ./git-secrets-scan.sh

# Prepare for build with references
/bin/bash scripts/generate-aggregate-tsconfig.sh > tsconfig.json

BUILD_INDICATOR=".BUILD_COMPLETED"
rm -rf $BUILD_INDICATOR

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"nodeunit": "^0.11.2",
"nyc": "^13.0.1",
"tslint": "^5.10.0",
"typescript": "^3.1.2"
"typescript": "^3.2.2"
},
"repository": {
"type": "git",
Expand Down
12 changes: 10 additions & 2 deletions packages/@aws-cdk/assert/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target":"es2018",
"lib": ["es2016", "es2017.object", "es2017.string"],
"module": "commonjs",
"composite": true,
"declaration": true,
"strict": true,
"noImplicitAny": true,
Expand All @@ -17,6 +18,13 @@
"inlineSources": true,
"strictPropertyInitialization": false,
"experimentalDecorators": true
}
},
"include": ["**/*.ts" ],
"exclude": ["node_modules"],
"references": [
{ "path": "../cdk" },
{ "path": "../cx-api" },
{ "path": "../cfnspec" },
{ "path": "../cloudformation-diff" }
]
}

6 changes: 4 additions & 2 deletions packages/@aws-cdk/cfnspec/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "commonjs",
"lib": ["es2016", "es2017.object", "es2017.string"],
"declaration": true,
"composite": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand All @@ -17,6 +18,7 @@
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization":false
}
},
"include": ["**/*.ts" ],
"exclude": ["node_modules"]
}

9 changes: 6 additions & 3 deletions packages/@aws-cdk/cloudformation-diff/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "commonjs",
"lib": ["es2016", "es2017.object", "es2017.string"],
"declaration": true,
"composite": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand All @@ -18,8 +19,10 @@
"inlineSources": true,
"experimentalDecorators": true
},
"exclude": [
"lib/init-templates/**/*.ts"
"include": ["**/*.ts" ],
"exclude": ["node_modules"],
"references": [
{ "path": "../cfnspec" },
{ "path": "../cx-api" }
]
}

42 changes: 1 addition & 41 deletions scripts/build-typescript.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,2 @@
#!/bin/bash
cat <<EOF > tsconfig.json
{
"compilerOptions": {
"alwaysStrict": true,
"charset": "utf8",
"declaration": false,
"experimentalDecorators": true,
"inlineSourceMap": true,
"inlineSources": true,
"lib": [
"es2016",
"es2017.object",
"es2017.string"
],
"module": "CommonJS",
"noEmitOnError": false,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"target": "ES2018"
},
"include": [
"packages/**/*.ts",
"tools/**/*.ts"
],
"exclude": [
"node_modules",
"packages/@aws-cdk/aws-sns/examples",
"tools/cfn2ts/test/enrichments",
"packages/aws-cdk/lib/init-templates"
],
"_generated_by_jsii_": "Generated by jsii - safe to delete, and ideally should be in .gitignore"
}
EOF
node_modules/.bin/tsc -p . "$@"
node_modules/.bin/tsc -b "$@"
17 changes: 17 additions & 0 deletions scripts/generate-aggregate-tsconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# Generate an aggregate tsconfig.json with references to all projects in the
# repository.
prefix="$(pwd)/"

echo '{'
echo ' "__comment__": "This file is necessary to make transitive Project References in TypeScript work",'
echo ' "files": [],'
echo ' "references": ['
comma=' '
for package in $(node_modules/.bin/lerna ls -p); do
relpath=${package#"$prefix"}
echo ' '"$comma"'{ "path": "'"$relpath"'" }'
comma=', '
done
echo ' ]'
echo '}'
2 changes: 1 addition & 1 deletion tools/cdk-build-tools/bin/cdk-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {
})
.argv as any;

await shell([packageCompiler({ jsii: args.jsii, tsc: args.tsc }), '-w']);
await shell(packageCompiler({ jsii: args.jsii, tsc: args.tsc }).concat(['-w']));
}

main().catch(e => {
Expand Down
2 changes: 1 addition & 1 deletion tools/cdk-build-tools/lib/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Timers } from "./timer";
* Run the compiler on the current package
*/
export async function compileCurrentPackage(timers: Timers, compilers: CompilerOverrides = {}): Promise<void> {
await shell([packageCompiler(compilers)], 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 || {};
Expand Down
9 changes: 6 additions & 3 deletions tools/cdk-build-tools/lib/package-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ export interface CompilerOverrides {
/**
* Return the compiler for this package (either tsc or jsii)
*/
export function packageCompiler(compilers: CompilerOverrides) {
return isJsii() ? compilers.jsii || require.resolve('jsii/bin/jsii')
: compilers.tsc || require.resolve('typescript/bin/tsc');
export function packageCompiler(compilers: CompilerOverrides): string[] {
if (isJsii()) {
return [compilers.jsii || require.resolve('jsii/bin/jsii'), '--project-references'];
} else {
return [compilers.tsc || require.resolve('typescript/bin/tsc')];
}
}

export interface CDKBuildOptions {
Expand Down
4 changes: 2 additions & 2 deletions tools/cdk-build-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"dependencies": {
"fs-extra": "^7.0.0",
"jsii": "^0.7.12",
"jsii-pacmak": "^0.7.12",
"jsii": "^0.7.13",
"jsii-pacmak": "^0.7.13",
"nodeunit": "^0.11.3",
"nyc": "^13.0.1",
"typescript": "^3.1.2",
Expand Down

0 comments on commit 0f8362d

Please sign in to comment.