@mrgrain/cdk-esbuild 3.1.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +0 -1
- package/.jsii +290 -88
- package/.projenrc.ts +4 -6
- package/API.md +220 -42
- package/CHANGELOG.md +2 -8
- package/README.md +27 -25
- package/lib/asset.d.ts +1 -6
- package/lib/asset.js +3 -3
- package/lib/bundler.d.ts +32 -19
- package/lib/bundler.js +49 -13
- package/lib/code.d.ts +1 -35
- package/lib/code.js +4 -23
- package/lib/esbuild-types.d.ts +73 -275
- package/lib/esbuild-types.js +1 -1
- package/lib/inline-code.d.ts +14 -37
- package/lib/inline-code.js +13 -33
- package/lib/source.d.ts +0 -35
- package/lib/source.js +3 -26
- package/package.json +15 -15
- package/releasetag.txt +1 -1
- package/version.txt +1 -1
package/.projenrc.ts
CHANGED
|
@@ -85,14 +85,9 @@ const project = new awscdk.AwsCdkConstructLibrary({
|
|
|
85
85
|
|
|
86
86
|
// Dependencies
|
|
87
87
|
cdkVersion: '2.0.0',
|
|
88
|
-
peerDeps: [
|
|
89
|
-
'aws-cdk-lib@^2.0.0',
|
|
90
|
-
],
|
|
91
88
|
devDeps: [
|
|
92
|
-
'@aws-cdk/aws-synthetics-alpha',
|
|
89
|
+
'@aws-cdk/aws-synthetics-alpha@2.0.0-alpha.11',
|
|
93
90
|
'@types/eslint',
|
|
94
|
-
'aws-cdk-lib@2.0.0',
|
|
95
|
-
'constructs@10.0.5',
|
|
96
91
|
'esbuild@^0.14.0',
|
|
97
92
|
'jest-mock',
|
|
98
93
|
'ts-morph',
|
|
@@ -188,7 +183,10 @@ new TypeScriptSourceFile(project, 'src/esbuild-types.ts', {
|
|
|
188
183
|
|
|
189
184
|
['CommonOptions', 'BuildOptions', 'TransformOptions'].forEach(readonlyInterface);
|
|
190
185
|
removeFromInterface('BuildOptions', ['entryPoints', 'stdin', 'plugins', 'watch']);
|
|
186
|
+
esbuildTypes.getInterface('CommonOptions')?.getProperty('mangleProps')?.setType('any');
|
|
187
|
+
esbuildTypes.getInterface('CommonOptions')?.getProperty('reserveProps')?.setType('any');
|
|
191
188
|
esbuildTypes.getInterface('TransformOptions')?.getProperty('tsconfigRaw')?.setType('string');
|
|
189
|
+
esbuildTypes.getInterface('InitializeOptions')?.getProperty('wasmModule')?.setType('any');
|
|
192
190
|
},
|
|
193
191
|
});
|
|
194
192
|
|
package/API.md
CHANGED
|
@@ -39,15 +39,15 @@ public readonly buildOptions: BuildOptions;
|
|
|
39
39
|
|
|
40
40
|
Build options passed on to esbuild. Please refer to the esbuild Build API docs for details.
|
|
41
41
|
|
|
42
|
-
`buildOptions.outdir: string`
|
|
42
|
+
* `buildOptions.outdir: string`
|
|
43
43
|
The actual path for the output directory is defined by CDK. However setting this option allows to write files into a subdirectory. \
|
|
44
44
|
For example `{ outdir: 'js' }` will create an asset with a single directory called `js`, which contains all built files. This approach can be useful for static website deployments, where JavaScript code should be placed into a subdirectory. \
|
|
45
45
|
*Cannot be used together with `outfile`*.
|
|
46
|
-
|
|
46
|
+
* `buildOptions.outfile: string`
|
|
47
47
|
Relative path to a file inside the CDK asset output directory.
|
|
48
48
|
For example `{ outfile: 'js/index.js' }` will create an asset with a single directory called `js`, which contains a single file `index.js`. This can be useful to rename the entry point. \
|
|
49
49
|
*Cannot be used with multiple entryPoints or together with `outdir`.*
|
|
50
|
-
|
|
50
|
+
* `buildOptions.absWorkingDir: string`
|
|
51
51
|
Absolute path to the [esbuild working directory](https://esbuild.github.io/api/#working-directory) and defaults to the [current working directory](https://en.wikipedia.org/wiki/Working_directory). \
|
|
52
52
|
If paths cannot be found, a good starting point is to look at the concatenation of `absWorkingDir + entryPoint`. It must always be a valid absolute path pointing to the entry point. When needed, the probably easiest way to set absWorkingDir is to use a combination of `resolve` and `__dirname` (see "Library authors" section in the documentation).
|
|
53
53
|
|
|
@@ -58,14 +58,27 @@ If paths cannot be found, a good starting point is to look at the concatenation
|
|
|
58
58
|
##### `copyDir`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.AssetProps.property.copyDir"></a>
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
|
-
public readonly copyDir: string;
|
|
61
|
+
public readonly copyDir: string | string[] | {[ key: string ]: string | string[]};
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
- *Type:* `string`
|
|
64
|
+
- *Type:* `string` | `string`[] | {[ key: string ]: `string` | `string`[]}
|
|
65
|
+
|
|
66
|
+
Copy additional files to the code [asset staging directory](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetStaging.html#absolutestagedpath), before the build runs. Files copied like this will be overwritten by esbuild if they share the same name as any of the outputs.
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
* When provided with a `string` or `array`, all files are copied to the root of asset staging directory.
|
|
69
|
+
* When given a `map`, the key indicates the destination relative to the asset staging directory and the value is a list of all sources to be copied.
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
Therefore the following values for `copyDir` are all equivalent:
|
|
72
|
+
```ts
|
|
73
|
+
{ copyDir: "path/to/source" }
|
|
74
|
+
{ copyDir: ["path/to/source"] }
|
|
75
|
+
{ copyDir: { ".": "path/to/source" } }
|
|
76
|
+
{ copyDir: { ".": ["path/to/source"] } }
|
|
77
|
+
```
|
|
78
|
+
The destination cannot be outside of the asset staging directory.
|
|
79
|
+
If you are receiving the error "Cannot copy files to outside of the asset staging directory."
|
|
80
|
+
you are likely using `..` or an absolute path as key on the `copyDir` map.
|
|
81
|
+
Instead use only relative paths and avoid `..`.
|
|
69
82
|
|
|
70
83
|
---
|
|
71
84
|
|
|
@@ -237,6 +250,8 @@ public readonly drop: string[];
|
|
|
237
250
|
|
|
238
251
|
- *Type:* `string`[]
|
|
239
252
|
|
|
253
|
+
Documentation: https://esbuild.github.io/api/#drop.
|
|
254
|
+
|
|
240
255
|
---
|
|
241
256
|
|
|
242
257
|
##### `entryNames`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.entryNames"></a>
|
|
@@ -443,6 +458,42 @@ Documentation: https://esbuild.github.io/api/#mainFields.
|
|
|
443
458
|
|
|
444
459
|
---
|
|
445
460
|
|
|
461
|
+
##### `mangleCache`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.mangleCache"></a>
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
public readonly mangleCache: {[ key: string ]: string | boolean};
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
- *Type:* {[ key: string ]: `string` | `boolean`}
|
|
468
|
+
|
|
469
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
##### `mangleProps`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.mangleProps"></a>
|
|
474
|
+
|
|
475
|
+
```typescript
|
|
476
|
+
public readonly mangleProps: any;
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
- *Type:* `any`
|
|
480
|
+
|
|
481
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
##### `mangleQuoted`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.mangleQuoted"></a>
|
|
486
|
+
|
|
487
|
+
```typescript
|
|
488
|
+
public readonly mangleQuoted: boolean;
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
- *Type:* `boolean`
|
|
492
|
+
|
|
493
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
446
497
|
##### `metafile`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.metafile"></a>
|
|
447
498
|
|
|
448
499
|
```typescript
|
|
@@ -611,6 +662,18 @@ Documentation: https://esbuild.github.io/api/#pure.
|
|
|
611
662
|
|
|
612
663
|
---
|
|
613
664
|
|
|
665
|
+
##### `reserveProps`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.reserveProps"></a>
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
public readonly reserveProps: any;
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
- *Type:* `any`
|
|
672
|
+
|
|
673
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
674
|
+
|
|
675
|
+
---
|
|
676
|
+
|
|
614
677
|
##### `resolveExtensions`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BuildOptions.property.resolveExtensions"></a>
|
|
615
678
|
|
|
616
679
|
```typescript
|
|
@@ -755,15 +818,15 @@ public readonly buildOptions: BuildOptions;
|
|
|
755
818
|
|
|
756
819
|
Build options passed on to esbuild. Please refer to the esbuild Build API docs for details.
|
|
757
820
|
|
|
758
|
-
`buildOptions.outdir: string`
|
|
821
|
+
* `buildOptions.outdir: string`
|
|
759
822
|
The actual path for the output directory is defined by CDK. However setting this option allows to write files into a subdirectory. \
|
|
760
823
|
For example `{ outdir: 'js' }` will create an asset with a single directory called `js`, which contains all built files. This approach can be useful for static website deployments, where JavaScript code should be placed into a subdirectory. \
|
|
761
824
|
*Cannot be used together with `outfile`*.
|
|
762
|
-
|
|
825
|
+
* `buildOptions.outfile: string`
|
|
763
826
|
Relative path to a file inside the CDK asset output directory.
|
|
764
827
|
For example `{ outfile: 'js/index.js' }` will create an asset with a single directory called `js`, which contains a single file `index.js`. This can be useful to rename the entry point. \
|
|
765
828
|
*Cannot be used with multiple entryPoints or together with `outdir`.*
|
|
766
|
-
|
|
829
|
+
* `buildOptions.absWorkingDir: string`
|
|
767
830
|
Absolute path to the [esbuild working directory](https://esbuild.github.io/api/#working-directory) and defaults to the [current working directory](https://en.wikipedia.org/wiki/Working_directory). \
|
|
768
831
|
If paths cannot be found, a good starting point is to look at the concatenation of `absWorkingDir + entryPoint`. It must always be a valid absolute path pointing to the entry point. When needed, the probably easiest way to set absWorkingDir is to use a combination of `resolve` and `__dirname` (see "Library authors" section in the documentation).
|
|
769
832
|
|
|
@@ -774,14 +837,27 @@ If paths cannot be found, a good starting point is to look at the concatenation
|
|
|
774
837
|
##### `copyDir`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.BundlerProps.property.copyDir"></a>
|
|
775
838
|
|
|
776
839
|
```typescript
|
|
777
|
-
public readonly copyDir: string;
|
|
840
|
+
public readonly copyDir: string | string[] | {[ key: string ]: string | string[]};
|
|
778
841
|
```
|
|
779
842
|
|
|
780
|
-
- *Type:* `string`
|
|
843
|
+
- *Type:* `string` | `string`[] | {[ key: string ]: `string` | `string`[]}
|
|
781
844
|
|
|
782
|
-
Copy additional files to the
|
|
845
|
+
Copy additional files to the code [asset staging directory](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetStaging.html#absolutestagedpath), before the build runs. Files copied like this will be overwritten by esbuild if they share the same name as any of the outputs.
|
|
783
846
|
|
|
784
|
-
|
|
847
|
+
* When provided with a `string` or `array`, all files are copied to the root of asset staging directory.
|
|
848
|
+
* When given a `map`, the key indicates the destination relative to the asset staging directory and the value is a list of all sources to be copied.
|
|
849
|
+
|
|
850
|
+
Therefore the following values for `copyDir` are all equivalent:
|
|
851
|
+
```ts
|
|
852
|
+
{ copyDir: "path/to/source" }
|
|
853
|
+
{ copyDir: ["path/to/source"] }
|
|
854
|
+
{ copyDir: { ".": "path/to/source" } }
|
|
855
|
+
{ copyDir: { ".": ["path/to/source"] } }
|
|
856
|
+
```
|
|
857
|
+
The destination cannot be outside of the asset staging directory.
|
|
858
|
+
If you are receiving the error "Cannot copy files to outside of the asset staging directory."
|
|
859
|
+
you are likely using `..` or an absolute path as key on the `copyDir` map.
|
|
860
|
+
Instead use only relative paths and avoid `..`.
|
|
785
861
|
|
|
786
862
|
---
|
|
787
863
|
|
|
@@ -843,15 +919,15 @@ public readonly buildOptions: BuildOptions;
|
|
|
843
919
|
|
|
844
920
|
Build options passed on to esbuild. Please refer to the esbuild Build API docs for details.
|
|
845
921
|
|
|
846
|
-
`buildOptions.outdir: string`
|
|
922
|
+
* `buildOptions.outdir: string`
|
|
847
923
|
The actual path for the output directory is defined by CDK. However setting this option allows to write files into a subdirectory. \
|
|
848
924
|
For example `{ outdir: 'js' }` will create an asset with a single directory called `js`, which contains all built files. This approach can be useful for static website deployments, where JavaScript code should be placed into a subdirectory. \
|
|
849
925
|
*Cannot be used together with `outfile`*.
|
|
850
|
-
|
|
926
|
+
* `buildOptions.outfile: string`
|
|
851
927
|
Relative path to a file inside the CDK asset output directory.
|
|
852
928
|
For example `{ outfile: 'js/index.js' }` will create an asset with a single directory called `js`, which contains a single file `index.js`. This can be useful to rename the entry point. \
|
|
853
929
|
*Cannot be used with multiple entryPoints or together with `outdir`.*
|
|
854
|
-
|
|
930
|
+
* `buildOptions.absWorkingDir: string`
|
|
855
931
|
Absolute path to the [esbuild working directory](https://esbuild.github.io/api/#working-directory) and defaults to the [current working directory](https://en.wikipedia.org/wiki/Working_directory). \
|
|
856
932
|
If paths cannot be found, a good starting point is to look at the concatenation of `absWorkingDir + entryPoint`. It must always be a valid absolute path pointing to the entry point. When needed, the probably easiest way to set absWorkingDir is to use a combination of `resolve` and `__dirname` (see "Library authors" section in the documentation).
|
|
857
933
|
|
|
@@ -862,14 +938,27 @@ If paths cannot be found, a good starting point is to look at the concatenation
|
|
|
862
938
|
##### `copyDir`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.JavaScriptCodeProps.property.copyDir"></a>
|
|
863
939
|
|
|
864
940
|
```typescript
|
|
865
|
-
public readonly copyDir: string;
|
|
941
|
+
public readonly copyDir: string | string[] | {[ key: string ]: string | string[]};
|
|
866
942
|
```
|
|
867
943
|
|
|
868
|
-
- *Type:* `string`
|
|
944
|
+
- *Type:* `string` | `string`[] | {[ key: string ]: `string` | `string`[]}
|
|
869
945
|
|
|
870
|
-
Copy additional files to the
|
|
946
|
+
Copy additional files to the code [asset staging directory](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetStaging.html#absolutestagedpath), before the build runs. Files copied like this will be overwritten by esbuild if they share the same name as any of the outputs.
|
|
871
947
|
|
|
872
|
-
|
|
948
|
+
* When provided with a `string` or `array`, all files are copied to the root of asset staging directory.
|
|
949
|
+
* When given a `map`, the key indicates the destination relative to the asset staging directory and the value is a list of all sources to be copied.
|
|
950
|
+
|
|
951
|
+
Therefore the following values for `copyDir` are all equivalent:
|
|
952
|
+
```ts
|
|
953
|
+
{ copyDir: "path/to/source" }
|
|
954
|
+
{ copyDir: ["path/to/source"] }
|
|
955
|
+
{ copyDir: { ".": "path/to/source" } }
|
|
956
|
+
{ copyDir: { ".": ["path/to/source"] } }
|
|
957
|
+
```
|
|
958
|
+
The destination cannot be outside of the asset staging directory.
|
|
959
|
+
If you are receiving the error "Cannot copy files to outside of the asset staging directory."
|
|
960
|
+
you are likely using `..` or an absolute path as key on the `copyDir` map.
|
|
961
|
+
Instead use only relative paths and avoid `..`.
|
|
873
962
|
|
|
874
963
|
---
|
|
875
964
|
|
|
@@ -925,15 +1014,15 @@ public readonly buildOptions: BuildOptions;
|
|
|
925
1014
|
|
|
926
1015
|
Build options passed on to esbuild. Please refer to the esbuild Build API docs for details.
|
|
927
1016
|
|
|
928
|
-
`buildOptions.outdir: string`
|
|
1017
|
+
* `buildOptions.outdir: string`
|
|
929
1018
|
The actual path for the output directory is defined by CDK. However setting this option allows to write files into a subdirectory. \
|
|
930
1019
|
For example `{ outdir: 'js' }` will create an asset with a single directory called `js`, which contains all built files. This approach can be useful for static website deployments, where JavaScript code should be placed into a subdirectory. \
|
|
931
1020
|
*Cannot be used together with `outfile`*.
|
|
932
|
-
|
|
1021
|
+
* `buildOptions.outfile: string`
|
|
933
1022
|
Relative path to a file inside the CDK asset output directory.
|
|
934
1023
|
For example `{ outfile: 'js/index.js' }` will create an asset with a single directory called `js`, which contains a single file `index.js`. This can be useful to rename the entry point. \
|
|
935
1024
|
*Cannot be used with multiple entryPoints or together with `outdir`.*
|
|
936
|
-
|
|
1025
|
+
* `buildOptions.absWorkingDir: string`
|
|
937
1026
|
Absolute path to the [esbuild working directory](https://esbuild.github.io/api/#working-directory) and defaults to the [current working directory](https://en.wikipedia.org/wiki/Working_directory). \
|
|
938
1027
|
If paths cannot be found, a good starting point is to look at the concatenation of `absWorkingDir + entryPoint`. It must always be a valid absolute path pointing to the entry point. When needed, the probably easiest way to set absWorkingDir is to use a combination of `resolve` and `__dirname` (see "Library authors" section in the documentation).
|
|
939
1028
|
|
|
@@ -944,14 +1033,27 @@ If paths cannot be found, a good starting point is to look at the concatenation
|
|
|
944
1033
|
##### `copyDir`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.JavaScriptSourceProps.property.copyDir"></a>
|
|
945
1034
|
|
|
946
1035
|
```typescript
|
|
947
|
-
public readonly copyDir: string;
|
|
1036
|
+
public readonly copyDir: string | string[] | {[ key: string ]: string | string[]};
|
|
948
1037
|
```
|
|
949
1038
|
|
|
950
|
-
- *Type:* `string`
|
|
1039
|
+
- *Type:* `string` | `string`[] | {[ key: string ]: `string` | `string`[]}
|
|
1040
|
+
|
|
1041
|
+
Copy additional files to the code [asset staging directory](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetStaging.html#absolutestagedpath), before the build runs. Files copied like this will be overwritten by esbuild if they share the same name as any of the outputs.
|
|
951
1042
|
|
|
952
|
-
|
|
1043
|
+
* When provided with a `string` or `array`, all files are copied to the root of asset staging directory.
|
|
1044
|
+
* When given a `map`, the key indicates the destination relative to the asset staging directory and the value is a list of all sources to be copied.
|
|
953
1045
|
|
|
954
|
-
|
|
1046
|
+
Therefore the following values for `copyDir` are all equivalent:
|
|
1047
|
+
```ts
|
|
1048
|
+
{ copyDir: "path/to/source" }
|
|
1049
|
+
{ copyDir: ["path/to/source"] }
|
|
1050
|
+
{ copyDir: { ".": "path/to/source" } }
|
|
1051
|
+
{ copyDir: { ".": ["path/to/source"] } }
|
|
1052
|
+
```
|
|
1053
|
+
The destination cannot be outside of the asset staging directory.
|
|
1054
|
+
If you are receiving the error "Cannot copy files to outside of the asset staging directory."
|
|
1055
|
+
you are likely using `..` or an absolute path as key on the `copyDir` map.
|
|
1056
|
+
Instead use only relative paths and avoid `..`.
|
|
955
1057
|
|
|
956
1058
|
---
|
|
957
1059
|
|
|
@@ -1077,6 +1179,8 @@ public readonly drop: string[];
|
|
|
1077
1179
|
|
|
1078
1180
|
- *Type:* `string`[]
|
|
1079
1181
|
|
|
1182
|
+
Documentation: https://esbuild.github.io/api/#drop.
|
|
1183
|
+
|
|
1080
1184
|
---
|
|
1081
1185
|
|
|
1082
1186
|
##### `footer`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.footer"></a>
|
|
@@ -1219,6 +1323,42 @@ Documentation: https://esbuild.github.io/api/#log-limit.
|
|
|
1219
1323
|
|
|
1220
1324
|
---
|
|
1221
1325
|
|
|
1326
|
+
##### `mangleCache`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.mangleCache"></a>
|
|
1327
|
+
|
|
1328
|
+
```typescript
|
|
1329
|
+
public readonly mangleCache: {[ key: string ]: string | boolean};
|
|
1330
|
+
```
|
|
1331
|
+
|
|
1332
|
+
- *Type:* {[ key: string ]: `string` | `boolean`}
|
|
1333
|
+
|
|
1334
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
1335
|
+
|
|
1336
|
+
---
|
|
1337
|
+
|
|
1338
|
+
##### `mangleProps`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.mangleProps"></a>
|
|
1339
|
+
|
|
1340
|
+
```typescript
|
|
1341
|
+
public readonly mangleProps: any;
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
- *Type:* `any`
|
|
1345
|
+
|
|
1346
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
1347
|
+
|
|
1348
|
+
---
|
|
1349
|
+
|
|
1350
|
+
##### `mangleQuoted`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.mangleQuoted"></a>
|
|
1351
|
+
|
|
1352
|
+
```typescript
|
|
1353
|
+
public readonly mangleQuoted: boolean;
|
|
1354
|
+
```
|
|
1355
|
+
|
|
1356
|
+
- *Type:* `boolean`
|
|
1357
|
+
|
|
1358
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
1359
|
+
|
|
1360
|
+
---
|
|
1361
|
+
|
|
1222
1362
|
##### `minify`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.minify"></a>
|
|
1223
1363
|
|
|
1224
1364
|
```typescript
|
|
@@ -1279,6 +1419,18 @@ Documentation: https://esbuild.github.io/api/#pure.
|
|
|
1279
1419
|
|
|
1280
1420
|
---
|
|
1281
1421
|
|
|
1422
|
+
##### `reserveProps`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.reserveProps"></a>
|
|
1423
|
+
|
|
1424
|
+
```typescript
|
|
1425
|
+
public readonly reserveProps: any;
|
|
1426
|
+
```
|
|
1427
|
+
|
|
1428
|
+
- *Type:* `any`
|
|
1429
|
+
|
|
1430
|
+
Documentation: https://esbuild.github.io/api/#mangle-props.
|
|
1431
|
+
|
|
1432
|
+
---
|
|
1433
|
+
|
|
1282
1434
|
##### `sourcefile`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TransformOptions.property.sourcefile"></a>
|
|
1283
1435
|
|
|
1284
1436
|
```typescript
|
|
@@ -1395,15 +1547,15 @@ public readonly buildOptions: BuildOptions;
|
|
|
1395
1547
|
|
|
1396
1548
|
Build options passed on to esbuild. Please refer to the esbuild Build API docs for details.
|
|
1397
1549
|
|
|
1398
|
-
`buildOptions.outdir: string`
|
|
1550
|
+
* `buildOptions.outdir: string`
|
|
1399
1551
|
The actual path for the output directory is defined by CDK. However setting this option allows to write files into a subdirectory. \
|
|
1400
1552
|
For example `{ outdir: 'js' }` will create an asset with a single directory called `js`, which contains all built files. This approach can be useful for static website deployments, where JavaScript code should be placed into a subdirectory. \
|
|
1401
1553
|
*Cannot be used together with `outfile`*.
|
|
1402
|
-
|
|
1554
|
+
* `buildOptions.outfile: string`
|
|
1403
1555
|
Relative path to a file inside the CDK asset output directory.
|
|
1404
1556
|
For example `{ outfile: 'js/index.js' }` will create an asset with a single directory called `js`, which contains a single file `index.js`. This can be useful to rename the entry point. \
|
|
1405
1557
|
*Cannot be used with multiple entryPoints or together with `outdir`.*
|
|
1406
|
-
|
|
1558
|
+
* `buildOptions.absWorkingDir: string`
|
|
1407
1559
|
Absolute path to the [esbuild working directory](https://esbuild.github.io/api/#working-directory) and defaults to the [current working directory](https://en.wikipedia.org/wiki/Working_directory). \
|
|
1408
1560
|
If paths cannot be found, a good starting point is to look at the concatenation of `absWorkingDir + entryPoint`. It must always be a valid absolute path pointing to the entry point. When needed, the probably easiest way to set absWorkingDir is to use a combination of `resolve` and `__dirname` (see "Library authors" section in the documentation).
|
|
1409
1561
|
|
|
@@ -1414,14 +1566,27 @@ If paths cannot be found, a good starting point is to look at the concatenation
|
|
|
1414
1566
|
##### `copyDir`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TypeScriptCodeProps.property.copyDir"></a>
|
|
1415
1567
|
|
|
1416
1568
|
```typescript
|
|
1417
|
-
public readonly copyDir: string;
|
|
1569
|
+
public readonly copyDir: string | string[] | {[ key: string ]: string | string[]};
|
|
1418
1570
|
```
|
|
1419
1571
|
|
|
1420
|
-
- *Type:* `string`
|
|
1572
|
+
- *Type:* `string` | `string`[] | {[ key: string ]: `string` | `string`[]}
|
|
1421
1573
|
|
|
1422
|
-
Copy additional files to the
|
|
1574
|
+
Copy additional files to the code [asset staging directory](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetStaging.html#absolutestagedpath), before the build runs. Files copied like this will be overwritten by esbuild if they share the same name as any of the outputs.
|
|
1423
1575
|
|
|
1424
|
-
|
|
1576
|
+
* When provided with a `string` or `array`, all files are copied to the root of asset staging directory.
|
|
1577
|
+
* When given a `map`, the key indicates the destination relative to the asset staging directory and the value is a list of all sources to be copied.
|
|
1578
|
+
|
|
1579
|
+
Therefore the following values for `copyDir` are all equivalent:
|
|
1580
|
+
```ts
|
|
1581
|
+
{ copyDir: "path/to/source" }
|
|
1582
|
+
{ copyDir: ["path/to/source"] }
|
|
1583
|
+
{ copyDir: { ".": "path/to/source" } }
|
|
1584
|
+
{ copyDir: { ".": ["path/to/source"] } }
|
|
1585
|
+
```
|
|
1586
|
+
The destination cannot be outside of the asset staging directory.
|
|
1587
|
+
If you are receiving the error "Cannot copy files to outside of the asset staging directory."
|
|
1588
|
+
you are likely using `..` or an absolute path as key on the `copyDir` map.
|
|
1589
|
+
Instead use only relative paths and avoid `..`.
|
|
1425
1590
|
|
|
1426
1591
|
---
|
|
1427
1592
|
|
|
@@ -1477,15 +1642,15 @@ public readonly buildOptions: BuildOptions;
|
|
|
1477
1642
|
|
|
1478
1643
|
Build options passed on to esbuild. Please refer to the esbuild Build API docs for details.
|
|
1479
1644
|
|
|
1480
|
-
`buildOptions.outdir: string`
|
|
1645
|
+
* `buildOptions.outdir: string`
|
|
1481
1646
|
The actual path for the output directory is defined by CDK. However setting this option allows to write files into a subdirectory. \
|
|
1482
1647
|
For example `{ outdir: 'js' }` will create an asset with a single directory called `js`, which contains all built files. This approach can be useful for static website deployments, where JavaScript code should be placed into a subdirectory. \
|
|
1483
1648
|
*Cannot be used together with `outfile`*.
|
|
1484
|
-
|
|
1649
|
+
* `buildOptions.outfile: string`
|
|
1485
1650
|
Relative path to a file inside the CDK asset output directory.
|
|
1486
1651
|
For example `{ outfile: 'js/index.js' }` will create an asset with a single directory called `js`, which contains a single file `index.js`. This can be useful to rename the entry point. \
|
|
1487
1652
|
*Cannot be used with multiple entryPoints or together with `outdir`.*
|
|
1488
|
-
|
|
1653
|
+
* `buildOptions.absWorkingDir: string`
|
|
1489
1654
|
Absolute path to the [esbuild working directory](https://esbuild.github.io/api/#working-directory) and defaults to the [current working directory](https://en.wikipedia.org/wiki/Working_directory). \
|
|
1490
1655
|
If paths cannot be found, a good starting point is to look at the concatenation of `absWorkingDir + entryPoint`. It must always be a valid absolute path pointing to the entry point. When needed, the probably easiest way to set absWorkingDir is to use a combination of `resolve` and `__dirname` (see "Library authors" section in the documentation).
|
|
1491
1656
|
|
|
@@ -1496,14 +1661,27 @@ If paths cannot be found, a good starting point is to look at the concatenation
|
|
|
1496
1661
|
##### `copyDir`<sup>Optional</sup> <a name="@mrgrain/cdk-esbuild.TypeScriptSourceProps.property.copyDir"></a>
|
|
1497
1662
|
|
|
1498
1663
|
```typescript
|
|
1499
|
-
public readonly copyDir: string;
|
|
1664
|
+
public readonly copyDir: string | string[] | {[ key: string ]: string | string[]};
|
|
1500
1665
|
```
|
|
1501
1666
|
|
|
1502
|
-
- *Type:* `string`
|
|
1667
|
+
- *Type:* `string` | `string`[] | {[ key: string ]: `string` | `string`[]}
|
|
1503
1668
|
|
|
1504
|
-
Copy additional files to the
|
|
1669
|
+
Copy additional files to the code [asset staging directory](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetStaging.html#absolutestagedpath), before the build runs. Files copied like this will be overwritten by esbuild if they share the same name as any of the outputs.
|
|
1505
1670
|
|
|
1506
|
-
|
|
1671
|
+
* When provided with a `string` or `array`, all files are copied to the root of asset staging directory.
|
|
1672
|
+
* When given a `map`, the key indicates the destination relative to the asset staging directory and the value is a list of all sources to be copied.
|
|
1673
|
+
|
|
1674
|
+
Therefore the following values for `copyDir` are all equivalent:
|
|
1675
|
+
```ts
|
|
1676
|
+
{ copyDir: "path/to/source" }
|
|
1677
|
+
{ copyDir: ["path/to/source"] }
|
|
1678
|
+
{ copyDir: { ".": "path/to/source" } }
|
|
1679
|
+
{ copyDir: { ".": ["path/to/source"] } }
|
|
1680
|
+
```
|
|
1681
|
+
The destination cannot be outside of the asset staging directory.
|
|
1682
|
+
If you are receiving the error "Cannot copy files to outside of the asset staging directory."
|
|
1683
|
+
you are likely using `..` or an absolute path as key on the `copyDir` map.
|
|
1684
|
+
Instead use only relative paths and avoid `..`.
|
|
1507
1685
|
|
|
1508
1686
|
---
|
|
1509
1687
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
## [3.
|
|
2
|
+
## [3.4.0](https://github.com/mrgrain/cdk-esbuild/compare/v3.3.0...v3.4.0) (2022-05-26)
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
### Features
|
|
6
6
|
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### Bug Fixes
|
|
11
|
-
|
|
12
|
-
* replace mocked with version from jest-mock ([2e9761d](https://github.com/mrgrain/cdk-esbuild/commit/2e9761d5f53293a6a840897e218c2e79a6b71c66))
|
|
13
|
-
* replace removed Node.js type ([e58b268](https://github.com/mrgrain/cdk-esbuild/commit/e58b2685c519cb9c4d7e1a148c4fc9f388d3ff90))
|
|
7
|
+
* copyDir supports more complex scenarios ([08c59fb](https://github.com/mrgrain/cdk-esbuild/commit/08c59fba7bf1ee68ca103520b3e0b7ea5359a925))
|
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
_CDK constructs for [esbuild](https://github.com/evanw/esbuild), an extremely fast JavaScript bundler_
|
|
4
4
|
|
|
5
|
-
> ⚠️ This version is compatible with AWS CDK v2. For the previous, AWS CDK v1 compatible release, see [cdk-esbuild@v2](https://github.com/mrgrain/cdk-esbuild/tree/v2)
|
|
6
|
-
|
|
7
5
|
[Getting started](#getting-started) | [Migrating to v3](#migrating-to-v3) |
|
|
8
6
|
[Documentation](#documentation) | [API Reference](#api-reference) | [Versioning](#versioning)
|
|
9
7
|
|
|
8
|
+
> This version is compatible with AWS CDK v2. For the previous, AWS CDK v1 compatible release, see [cdk-esbuild@v2](https://github.com/mrgrain/cdk-esbuild/tree/v2).
|
|
9
|
+
|
|
10
10
|
## Why?
|
|
11
11
|
|
|
12
12
|
_esbuild_ is an extremely fast bundler and minifier for Typescript and JavaScript.
|
|
@@ -18,7 +18,7 @@ This package is running _esbuild_ directly in Node.js and bypasses Docker which
|
|
|
18
18
|
|
|
19
19
|
**Production readiness**
|
|
20
20
|
|
|
21
|
-
This package is
|
|
21
|
+
This package is stable and ready to be used in production, as many do. However _esbuild_ has not yet released a version 1.0.0 and its API is still in active development. Please read the guide on [esbuild's production readiness](https://esbuild.github.io/faq/#production-readiness).
|
|
22
22
|
|
|
23
23
|
Notably upgrades of the _esbuild_ minimum version requirement will be introduced in **minor versions** of this package and will inherit breaking changes from _esbuild_.
|
|
24
24
|
|
|
@@ -27,13 +27,13 @@ Notably upgrades of the _esbuild_ minimum version requirement will be introduced
|
|
|
27
27
|
Install `cdk-esbuild`:
|
|
28
28
|
|
|
29
29
|
```
|
|
30
|
-
npm install @mrgrain/cdk-esbuild
|
|
30
|
+
npm install @mrgrain/cdk-esbuild@3
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
If _peer_
|
|
33
|
+
If _peer_ or _optional dependencies_ are not installed automatically (e.g. when using npm v4-6), please use this command to install all of them:
|
|
34
34
|
|
|
35
35
|
```
|
|
36
|
-
npm install @mrgrain/cdk-esbuild
|
|
36
|
+
npm install @mrgrain/cdk-esbuild@3 esbuild
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
### AWS Lambda: Serverless function
|
|
@@ -49,7 +49,7 @@ import { TypeScriptCode } from "@mrgrain/cdk-esbuild";
|
|
|
49
49
|
const bundledCode = new TypeScriptCode("src/index.ts");
|
|
50
50
|
|
|
51
51
|
const fn = new lambda.Function(stack, "MyFunction", {
|
|
52
|
-
runtime: lambda.Runtime.
|
|
52
|
+
runtime: lambda.Runtime.NODEJS_16_X,
|
|
53
53
|
handler: "index.handler",
|
|
54
54
|
code: bundledCode,
|
|
55
55
|
});
|
|
@@ -112,7 +112,7 @@ const canary = new synthetics.Canary(stack, "MyCanary", {
|
|
|
112
112
|
});
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
## Documentation
|
|
116
116
|
|
|
117
117
|
The package exports various different constructs for use with existing CDK features. A major guiding design principal for this package is to _extend, don't replace_. Expect constructs that you can provide as props, not complete replacements.
|
|
118
118
|
|
|
@@ -129,9 +129,9 @@ For use with **S3 bucket deployments**, classes implementing `s3deploy.ISource`
|
|
|
129
129
|
|
|
130
130
|
- `TypeScriptSource` & `JavaScriptSource`
|
|
131
131
|
|
|
132
|
-
> _Code and Source constructs seamlessly
|
|
132
|
+
> _Code and Source constructs seamlessly plug-in to other high-level CDK constructs. They share the same set of parameters, props and build options._
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
The following classes power the other features. You normally won't have to use them, but they are there if you need them:
|
|
135
135
|
|
|
136
136
|
- `TypeScriptAsset` & `JavaScriptAsset` implements `s3.Asset` ([reference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_assets.Asset.html)) \
|
|
137
137
|
creates an asset uploaded to S3 which can be referenced by other constructs
|
|
@@ -139,21 +139,21 @@ Underlying classes power the other features. You normally won't have to use them
|
|
|
139
139
|
- `EsbuildBundler` implements `core.BundlingOptions` ([reference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.BundlingOptions.html)) \
|
|
140
140
|
provides an interface for a _esbuild_ bundler wherever needed
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
### [API Reference](API.md)
|
|
143
143
|
|
|
144
|
-
Auto-generated reference for classes and structs. This information is also available
|
|
144
|
+
Auto-generated reference for classes and structs. This information is also available as part of your IDE's code completion.
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
### Escape hatches
|
|
147
147
|
|
|
148
|
-
It's possible that you want to use
|
|
148
|
+
It's possible that you want to use an implementation of esbuild that's different to the default one. Common reasons are:
|
|
149
149
|
|
|
150
150
|
- The current version constraints for esbuild are not suitable
|
|
151
|
-
- To use version of esbuild that is installed by any other means than `npm`, including Docker
|
|
152
|
-
- Plugin support is needed for
|
|
151
|
+
- To use a version of esbuild that is installed by any other means than `npm`, including Docker
|
|
152
|
+
- Plugin support is needed for building
|
|
153
153
|
|
|
154
154
|
For these situations, this package offers an escape hatch to bypass regular the implementation and provide a custom build and transform function.
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
#### Custom build function
|
|
157
157
|
|
|
158
158
|
> 💡 See [Using esbuild with plugins](examples/esbuild-with-plugins) for a complete working example of a custom build function using this escape hatch.
|
|
159
159
|
|
|
@@ -175,7 +175,7 @@ Instead of esbuild, the provided function will be invoked with the calculated bu
|
|
|
175
175
|
|
|
176
176
|
Failures have to cause a `BuildFailure` exception in order to be fully handled.
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
#### Custom transform function
|
|
179
179
|
|
|
180
180
|
Constructs that result in starting a transformation, take a `transformFn` as optional prop. While the defined type for this function is `any`, it must implement the same signature as esbuild's `transformSync` function.
|
|
181
181
|
|
|
@@ -195,11 +195,11 @@ Instead of esbuild, the provided function will be invoked with the calculated tr
|
|
|
195
195
|
|
|
196
196
|
Failures have to cause a `TransformFailure` exception in order to be fully handled.
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
### Migrating to v3
|
|
199
199
|
|
|
200
200
|
The release of cdk-esbuild v3 brings compatibility with AWS CDK v2. Furthermore all deprecated properties and classes have been removed. In particular `InlineCode` classes now take `TransformerProps` as second parameter instead of transform options.
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
#### Upgrading
|
|
203
203
|
|
|
204
204
|
- This version requires AWS CDK v2. Follow the [official migration guide](https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-v2.html) to upgrade.
|
|
205
205
|
- Update the package dependency to v3: `npm install --save @mrgrain/cdk-esbuild@^3.0.0`
|
|
@@ -217,7 +217,7 @@ The release of cdk-esbuild v3 brings compatibility with AWS CDK v2. Furthermore
|
|
|
217
217
|
|
|
218
218
|
## Versioning
|
|
219
219
|
|
|
220
|
-
This package
|
|
220
|
+
This package follows [Semantic Versioning](https://semver.org/), with the exception of upgrades to `esbuild`. These will be released as **minor versions** and often include breaking changes from `esbuild`.
|
|
221
221
|
|
|
222
222
|
### Npm Tags
|
|
223
223
|
|
|
@@ -233,15 +233,15 @@ These tags also exist, but usage is strongly not recommended:
|
|
|
233
233
|
|
|
234
234
|
- ~~`cdk-1.x.x`~~ tags have been deprecated in favour of `cdk-v1`. Use that one instead.
|
|
235
235
|
|
|
236
|
-
##
|
|
236
|
+
## Roadmap & Contributions
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
[The project's roadmap is available on GitHub.](https://github.com/mrgrain/cdk-esbuild/projects/1) Please submit any feature requests as issues to the repository.
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
All contributions are welcome, no matter if they are for already planned or completely new features.
|
|
241
241
|
|
|
242
242
|
## Library authors
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
Building a library consumed by other packages that relies on `cdk-esbuild` might require you to set `buildOptions.absWorkingDir`. The easiest way to do this, is to resolve based on the directory name of the calling file, and traverse the tree upwards to the root of your library package (that's where `package.json` and `tsconfig.json` are):
|
|
245
245
|
|
|
246
246
|
```ts
|
|
247
247
|
// file: project/src/index.ts
|
|
@@ -253,3 +253,5 @@ const props = {
|
|
|
253
253
|
```
|
|
254
254
|
|
|
255
255
|
This will dynamically resolve to the correct path, wherever the package is installed.
|
|
256
|
+
|
|
257
|
+
Please open an issue if you encounter any difficulties.
|