Skip to content

Commit

Permalink
feat: support custom esbuild module path (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain authored Aug 14, 2022
1 parent 27c76da commit 9cc071e
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 48 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json

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

2 changes: 2 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ project.tryFindObjectFile('.github/workflows/release.yml')?.addToArray(
// eslint
project.eslint?.addRules({
'no-console': 'error',
'eol-last': ['error', 'always'],
'@typescript-eslint/member-ordering': 'off',
});
project.eslint?.addOverride({
Expand Down Expand Up @@ -214,6 +215,7 @@ new JsonFile(project, '.vscode/settings.json', {
'[svg]': {
'editor.defaultFormatter': 'jock.svg',
},
'python.formatting.provider': 'black',
},
});

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json

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

182 changes: 175 additions & 7 deletions API.md

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

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Like every Construct, *cdk-esbuild* is a [jsii](https://github.com/aws/jsii) pro
Sometimes it is required to test these generated packages in a real life environment.
All paths in the instructions below, will assume you are testing with one of the examples.

### NodeJs
### Node.js

**Option 1:**

*This is the preferred approach, as it is more consistent and closer to how npm would behave for a real user.*

- `pj build`
- The NodeJS package can be found in `dist/js`
- The Node.js package can be found in `dist/js`
- In your Python app, run `npm install ../../dist/js/[email protected]` (path to the file in dist)
- `npx cdk synth` will use the locally build version

Expand Down
18 changes: 9 additions & 9 deletions examples/python-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ All interfaces are available, but the esbuild binary must be available in path,

To set up a new virtualenv, run

```
$ python3 -m venv .venv
```bash
python3 -m venv .venv
```

Then activate the venv and install all dependencies:

```
$ source .venv/bin/activate
$ pip install -r requirements.txt
$ npm install --location=global esbuild
```bash
source .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
npm install -g esbuild
```

Finally run the CDK app:
Run the CDK app providing the `CDK_ESBUILD_MODULE_PATH`:

```bash
CDK_ESBUILD_MODULE_PATH="$(npm prefix -g)/lib/node_modules/esbuild" cdk synth
```
$ cdk synth
```
8 changes: 7 additions & 1 deletion examples/python-app/python_app/python_app_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
self,
"Website",
sources=[
TypeScriptSource("lambda-handler/index.ts", copy_dir="lambda-handler")
TypeScriptSource(
"lambda-handler/index.ts",
copy_dir="lambda-handler",
)
],
destination_bucket=s3.Bucket(
self,
Expand All @@ -37,6 +40,9 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
build_options=BuildOptions(
format="esm", outfile="index.mjs", external=["aws-sdk"]
),
# Override the global setting with a specific path per Construct
# This can be useful if a Construct requires a different version of esbuild
esbuild_module_path="/project/node_modules/esbuild@13",
),
)

Expand Down
1 change: 1 addition & 0 deletions examples/python-app/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest==6.2.5
black>=22.6.0
4 changes: 2 additions & 2 deletions examples/python-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aws-cdk-lib==2.27.0
aws-cdk-lib==2.37.1
constructs>=10.0.0,<11.0.0
mrgrain.cdk-esbuild>=4.0.0
mrgrain.cdk-esbuild>=3.10.0
Loading

0 comments on commit 9cc071e

Please sign in to comment.