Skip to content

Commit c2b9e75

Browse files
authored
chore(monocdk): re-do build logic (#8234)
Make the monocdk-experiment package adhere to the general flow of having a `build` phase followed by a `package` phase, instead of doing both at the same time. Additionally, using a TypeScript transform to re-write imports instead of doing search and replace. The new implementation still looks only at the ES6-style `import`s, but could be extended to go re-write other kinds of imports if the need arises. This also pre-generates submodule-local configurations for naming, which are not used right now but will become used in a future version of `jsii`. Right now this file is just metadata. Finally, this models the dependencies in the local package, instead of creating a shadow package for publishing. The `yarn gen` script will make sure `bundledDependencies`, `dependencies` and `devDependencies` are properly configured, as well as ensure the correct `nohoist` entries are in the workspace root's `package.json` (so the bundled dependencies are where `npm pack` needs to have them). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0028778 commit c2b9e75

File tree

13 files changed

+726
-380
lines changed

13 files changed

+726
-380
lines changed

package.json

+16-7
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,34 @@
4848
"nohoist": [
4949
"**/jszip",
5050
"**/jszip/**",
51-
"@aws-cdk/cdk-assets-schema/semver",
52-
"@aws-cdk/cdk-assets-schema/semver/**",
53-
"@aws-cdk/core/minimatch",
54-
"@aws-cdk/core/minimatch/**",
55-
"@aws-cdk/cloudformation-include/yaml",
56-
"@aws-cdk/cloudformation-include/yaml/**",
5751
"@aws-cdk/aws-codepipeline-actions/case",
5852
"@aws-cdk/aws-codepipeline-actions/case/**",
5953
"@aws-cdk/aws-ecr-assets/minimatch",
6054
"@aws-cdk/aws-ecr-assets/minimatch/**",
6155
"@aws-cdk/aws-lambda-nodejs/parcel-bundler",
6256
"@aws-cdk/aws-lambda-nodejs/parcel-bundler/**",
57+
"@aws-cdk/cdk-assets-schema/semver",
58+
"@aws-cdk/cdk-assets-schema/semver/**",
6359
"@aws-cdk/cloud-assembly-schema/jsonschema",
6460
"@aws-cdk/cloud-assembly-schema/jsonschema/**",
6561
"@aws-cdk/cloud-assembly-schema/semver",
6662
"@aws-cdk/cloud-assembly-schema/semver/**",
63+
"@aws-cdk/cloudformation-include/yaml",
64+
"@aws-cdk/cloudformation-include/yaml/**",
65+
"@aws-cdk/core/minimatch",
66+
"@aws-cdk/core/minimatch/**",
6767
"@aws-cdk/cx-api/semver",
6868
"@aws-cdk/cx-api/semver/**",
69-
"@aws-cdk/cx-api/semver/**"
69+
"monocdk-experiment/case",
70+
"monocdk-experiment/case/**",
71+
"monocdk-experiment/jsonschema",
72+
"monocdk-experiment/jsonschema/**",
73+
"monocdk-experiment/minimatch",
74+
"monocdk-experiment/minimatch/**",
75+
"monocdk-experiment/semver",
76+
"monocdk-experiment/semver/**",
77+
"monocdk-experiment/yaml",
78+
"monocdk-experiment/yaml/**"
7079
]
7180
}
7281
}

packages/@monocdk-experiment/assert/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"license": "Apache-2.0",
3838
"devDependencies": {
3939
"@types/jest": "^25.2.3",
40+
"@types/node": "^10.17.24",
4041
"cdk-build-tools": "0.0.0",
4142
"jest": "^25.5.4",
4243
"pkglint": "0.0.0",

packages/@monocdk-experiment/rewrite-imports/lib/rewrite.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function rewriteLine(line: string) {
1818
}
1919
}
2020
return line
21-
.replace(/(["'])@aws-cdk\/core(["'])/g, '$1monocdk-experiment$2') // monocdk-experiment => monocdk-experiment
22-
.replace(/(["'])@aws-cdk\/(.+)(["'])/g, '$1monocdk-experiment/$2$3'); // monocdk-experiment/foobar => monocdk-experiment/foobar;
21+
.replace(/(["'])@aws-cdk\/assert(["'])/g, '$1@monocdk-experiment/assert$2') // @aws-cdk/assert => @monocdk-experiment/assert
22+
.replace(/(["'])@aws-cdk\/core(["'])/g, '$1monocdk-experiment$2') // @aws-cdk/core => monocdk-experiment
23+
.replace(/(["'])@aws-cdk\/(.+)(["'])/g, '$1monocdk-experiment/$2$3'); // @aws-cdk/* => monocdk-experiment/*;
2324
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../tools/cdk-build-tools/config/eslintrc');
2+
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
3+
module.exports = baseConfig;

packages/monocdk-experiment/.gitignore

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
*.d.ts
33
!deps.js
44
!gen.js
5-
staging/
5+
lib/
66
tsconfig.json
77
.jsii
88
*.tsbuildinfo
9+
10+
dist
11+
.LAST_PACKAGE
12+
.LAST_BUILD
13+
*.snk
14+
!.eslintrc.js
15+
16+
# Ignore barrel import entry points
17+
/*.ts

packages/monocdk-experiment/.npmignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ coverage
1111
.nycrc
1212

1313
# Build gear
14+
build-tools
1415
dist
1516
.LAST_BUILD
1617
.LAST_PACKAGE
17-
.jsii
1818

1919
tsconfig.json
2020
*.tsbuildinfo
21+
22+
!.jsii
23+
.eslintrc.js

packages/monocdk-experiment/README.md

+43-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,49 @@
22

33
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)
44

5-
An __experiment__ to bundle all of the CDK into a single module. Please don't
6-
use this module.
5+
An __experiment__ to bundle all of the CDK into a single module.
76

8-
## TODO
7+
> :warning: Please don't use this module unless you are interested in providing
8+
> feedback about this experience.
99
10-
- [ ] Consider if we want core types to be available under the root namespace
11-
- [ ] jsii support
12-
- [x] Bundle all code outside of `lib`
13-
- [ ] Run unit tests
1410

11+
## Usage
12+
13+
### Installation
14+
To try out `monocdk-experiment` replace all references to CDK Construct
15+
Libraries (most `@aws-cdk/*` packages) in your `package.json` file with a single
16+
entrey referring to `monocdk-experiment`.
17+
18+
You also need to add a reference to the `constructs` library, according to the
19+
kind of project you are developing:
20+
- For libraries, model the dependency under `devDependencies` **and** `peerDependencies`
21+
- For apps, model the dependency under `dependencies` only
22+
23+
### Use in your code
24+
25+
#### Classic import
26+
27+
You can use a classic import to get access to each service namespaces:
28+
29+
```ts
30+
import { core, aws_s3 as s3 } from 'monocdk-experiment';
31+
32+
const app = new core.App();
33+
const stack = new core.Stack(app, 'MonoCDK-Stack');
34+
35+
new s3.Bucket(stack, 'TestBucket');
36+
```
37+
38+
#### Barrel import
39+
40+
Alternatively, you can use "barrel" imports:
41+
42+
```ts
43+
import { App, Stack } from 'monocdk-experiment';
44+
import { Bucket } from 'monocdk-experiment/aws-s3';
45+
46+
const app = new App();
47+
const stack = new Stack(app, 'MonoCDK-Stack');
48+
49+
new Bucket(stack, 'TestBucket');
50+
```

0 commit comments

Comments
 (0)