Skip to content

Commit

Permalink
chore(monocdk): re-do build logic (#8234)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
RomainMuller authored May 27, 2020
1 parent 0028778 commit c2b9e75
Show file tree
Hide file tree
Showing 13 changed files with 726 additions and 380 deletions.
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,34 @@
"nohoist": [
"**/jszip",
"**/jszip/**",
"@aws-cdk/cdk-assets-schema/semver",
"@aws-cdk/cdk-assets-schema/semver/**",
"@aws-cdk/core/minimatch",
"@aws-cdk/core/minimatch/**",
"@aws-cdk/cloudformation-include/yaml",
"@aws-cdk/cloudformation-include/yaml/**",
"@aws-cdk/aws-codepipeline-actions/case",
"@aws-cdk/aws-codepipeline-actions/case/**",
"@aws-cdk/aws-ecr-assets/minimatch",
"@aws-cdk/aws-ecr-assets/minimatch/**",
"@aws-cdk/aws-lambda-nodejs/parcel-bundler",
"@aws-cdk/aws-lambda-nodejs/parcel-bundler/**",
"@aws-cdk/cdk-assets-schema/semver",
"@aws-cdk/cdk-assets-schema/semver/**",
"@aws-cdk/cloud-assembly-schema/jsonschema",
"@aws-cdk/cloud-assembly-schema/jsonschema/**",
"@aws-cdk/cloud-assembly-schema/semver",
"@aws-cdk/cloud-assembly-schema/semver/**",
"@aws-cdk/cloudformation-include/yaml",
"@aws-cdk/cloudformation-include/yaml/**",
"@aws-cdk/core/minimatch",
"@aws-cdk/core/minimatch/**",
"@aws-cdk/cx-api/semver",
"@aws-cdk/cx-api/semver/**",
"@aws-cdk/cx-api/semver/**"
"monocdk-experiment/case",
"monocdk-experiment/case/**",
"monocdk-experiment/jsonschema",
"monocdk-experiment/jsonschema/**",
"monocdk-experiment/minimatch",
"monocdk-experiment/minimatch/**",
"monocdk-experiment/semver",
"monocdk-experiment/semver/**",
"monocdk-experiment/yaml",
"monocdk-experiment/yaml/**"
]
}
}
1 change: 1 addition & 0 deletions packages/@monocdk-experiment/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@types/jest": "^25.2.3",
"@types/node": "^10.17.24",
"cdk-build-tools": "0.0.0",
"jest": "^25.5.4",
"pkglint": "0.0.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/@monocdk-experiment/rewrite-imports/lib/rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function rewriteLine(line: string) {
}
}
return line
.replace(/(["'])@aws-cdk\/core(["'])/g, '$1monocdk-experiment$2') // monocdk-experiment => monocdk-experiment
.replace(/(["'])@aws-cdk\/(.+)(["'])/g, '$1monocdk-experiment/$2$3'); // monocdk-experiment/foobar => monocdk-experiment/foobar;
.replace(/(["'])@aws-cdk\/assert(["'])/g, '$1@monocdk-experiment/assert$2') // @aws-cdk/assert => @monocdk-experiment/assert
.replace(/(["'])@aws-cdk\/core(["'])/g, '$1monocdk-experiment$2') // @aws-cdk/core => monocdk-experiment
.replace(/(["'])@aws-cdk\/(.+)(["'])/g, '$1monocdk-experiment/$2$3'); // @aws-cdk/* => monocdk-experiment/*;
}
3 changes: 3 additions & 0 deletions packages/monocdk-experiment/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../tools/cdk-build-tools/config/eslintrc');
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
module.exports = baseConfig;
11 changes: 10 additions & 1 deletion packages/monocdk-experiment/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
*.d.ts
!deps.js
!gen.js
staging/
lib/
tsconfig.json
.jsii
*.tsbuildinfo

dist
.LAST_PACKAGE
.LAST_BUILD
*.snk
!.eslintrc.js

# Ignore barrel import entry points
/*.ts
5 changes: 4 additions & 1 deletion packages/monocdk-experiment/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ coverage
.nycrc

# Build gear
build-tools
dist
.LAST_BUILD
.LAST_PACKAGE
.jsii

tsconfig.json
*.tsbuildinfo

!.jsii
.eslintrc.js
50 changes: 43 additions & 7 deletions packages/monocdk-experiment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,49 @@

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

An __experiment__ to bundle all of the CDK into a single module. Please don't
use this module.
An __experiment__ to bundle all of the CDK into a single module.

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

## Usage

### Installation
To try out `monocdk-experiment` replace all references to CDK Construct
Libraries (most `@aws-cdk/*` packages) in your `package.json` file with a single
entrey referring to `monocdk-experiment`.

You also need to add a reference to the `constructs` library, according to the
kind of project you are developing:
- For libraries, model the dependency under `devDependencies` **and** `peerDependencies`
- For apps, model the dependency under `dependencies` only

### Use in your code

#### Classic import

You can use a classic import to get access to each service namespaces:

```ts
import { core, aws_s3 as s3 } from 'monocdk-experiment';

const app = new core.App();
const stack = new core.Stack(app, 'MonoCDK-Stack');

new s3.Bucket(stack, 'TestBucket');
```

#### Barrel import

Alternatively, you can use "barrel" imports:

```ts
import { App, Stack } from 'monocdk-experiment';
import { Bucket } from 'monocdk-experiment/aws-s3';

const app = new App();
const stack = new Stack(app, 'MonoCDK-Stack');

new Bucket(stack, 'TestBucket');
```
Loading

0 comments on commit c2b9e75

Please sign in to comment.