@angular-builders/custom-esbuild 18.0.1-beta.0 → 18.1.0-beta.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/README.md CHANGED
@@ -100,19 +100,25 @@ Builder options:
100
100
  "build": {
101
101
  "builder": "@angular-builders/custom-esbuild:application",
102
102
  "options": {
103
- "plugins": ["./esbuild/plugins.ts", "./esbuild/plugin-2.js"],
103
+ "plugins": ["./esbuild/plugins.ts", { "path": "./esbuild/define-env.ts", "options": { "stage": "development" } }],
104
104
  "indexHtmlTransformer": "./esbuild/index-html-transformer.js",
105
105
  "outputPath": "dist/my-cool-client",
106
106
  "index": "src/index.html",
107
107
  "browser": "src/main.ts",
108
108
  "polyfills": ["zone.js"],
109
109
  "tsConfig": "src/tsconfig.app.json"
110
+ },
111
+ "configurations": {
112
+ "production": {
113
+ "plugins": ["./esbuild/plugins.ts", { "path": "./esbuild/define-env.ts", "options": { "stage": "production" } }]
114
+ }
110
115
  }
116
+ }
111
117
  ```
112
118
 
113
119
  In the above example, we specify the list of `plugins` that should implement the ESBuild plugin schema. These plugins are custom user plugins and are added to the original ESBuild Angular configuration. Additionally, the `indexHtmlTransformer` property is used to specify the path to the file that exports the function used to modify the `index.html`.
114
120
 
115
- The plugin file can export either a single plugin or a list of plugins:
121
+ The plugin file can export either a single plugin or a list of plugins. If a plugin accepts configuration then the config should be provided in `angular.json`:
116
122
 
117
123
  ```ts
118
124
  // esbuild/plugins.ts
@@ -129,6 +135,25 @@ const defineTextPlugin: Plugin = {
129
135
  export default defineTextPlugin;
130
136
  ```
131
137
 
138
+ OR:
139
+
140
+ ```ts
141
+ // esbuild/plugins.ts
142
+ import type { Plugin, PluginBuild } from 'esbuild';
143
+
144
+ function defineEnv(pluginOptions: { stage: string }): Plugin {
145
+ return {
146
+ name: 'define-env',
147
+ setup(build: PluginBuild) {
148
+ const buildOptions = build.initialOptions;
149
+ buildOptions.define.stage = JSON.stringify(pluginOptions.stage);
150
+ },
151
+ };
152
+ };
153
+
154
+ export default defineEnv;
155
+ ```
156
+
132
157
  Or:
133
158
 
134
159
  ```ts
@@ -571,7 +571,25 @@
571
571
  "description": "A list of paths to ESBuild plugins",
572
572
  "default": [],
573
573
  "items": {
574
- "type": "string",
574
+ "anyOf": [
575
+ {
576
+ "type": "string"
577
+ },
578
+ {
579
+ "type": "object",
580
+ "properties": {
581
+ "path": {
582
+ "type": "string"
583
+ },
584
+ "options": {
585
+ "type": "object"
586
+ }
587
+ },
588
+ "required": [
589
+ "path"
590
+ ]
591
+ }
592
+ ],
575
593
  "uniqueItems": true
576
594
  }
577
595
  },
@@ -1,4 +1,8 @@
1
1
  import { ApplicationBuilderOptions, DevServerBuilderOptions } from '@angular-devkit/build-angular';
2
+ export type PluginConfig = string | {
3
+ path: string;
4
+ options?: Record<string, unknown>;
5
+ };
2
6
  export type CustomEsbuildApplicationSchema = ApplicationBuilderOptions & {
3
7
  plugins?: string[];
4
8
  indexHtmlTransformer?: string;
@@ -1,3 +1,4 @@
1
1
  import type { Plugin } from 'esbuild';
2
2
  import type { logging } from '@angular-devkit/core';
3
- export declare function loadPlugins(paths: string[] | undefined, workspaceRoot: string, tsConfig: string, logger: logging.LoggerApi): Promise<Plugin[]>;
3
+ import { PluginConfig } from './custom-esbuild-schema';
4
+ export declare function loadPlugins(pluginConfig: PluginConfig[] | undefined, workspaceRoot: string, tsConfig: string, logger: logging.LoggerApi): Promise<Plugin[]>;
@@ -12,9 +12,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadPlugins = void 0;
13
13
  const path = require("node:path");
14
14
  const common_1 = require("@angular-builders/common");
15
- function loadPlugins(paths, workspaceRoot, tsConfig, logger) {
15
+ function loadPlugins(pluginConfig, workspaceRoot, tsConfig, logger) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- const plugins = yield Promise.all((paths || []).map(pluginPath => (0, common_1.loadModule)(path.join(workspaceRoot, pluginPath), tsConfig, logger)));
17
+ const plugins = yield Promise.all((pluginConfig || []).map((pluginConfig) => __awaiter(this, void 0, void 0, function* () {
18
+ if (typeof pluginConfig === 'string') {
19
+ return (0, common_1.loadModule)(path.join(workspaceRoot, pluginConfig), tsConfig, logger);
20
+ }
21
+ else {
22
+ const pluginFactory = yield (0, common_1.loadModule)(path.join(workspaceRoot, pluginConfig.path), tsConfig, logger);
23
+ return pluginFactory(pluginConfig.options);
24
+ }
25
+ })));
18
26
  return plugins.flat();
19
27
  });
20
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"load-plugins.js","sourceRoot":"","sources":["../src/load-plugins.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAAkC;AAGlC,qDAAsD;AAEtD,SAAsB,WAAW,CAC/B,KAA2B,EAC3B,aAAqB,EACrB,QAAgB,EAChB,MAAyB;;QAEzB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAC7B,IAAA,mBAAU,EAAoB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CACtF,CACF,CAAC;QAEF,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CAAA;AAbD,kCAaC"}
1
+ {"version":3,"file":"load-plugins.js","sourceRoot":"","sources":["../src/load-plugins.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAAkC;AAGlC,qDAAsD;AAGtD,SAAsB,WAAW,CAC/B,YAAwC,EACxC,aAAqB,EACrB,QAAgB,EAChB,MAAyB;;QAEzB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAM,YAAY,EAAC,EAAE;YAC1C,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;gBACrC,OAAO,IAAA,mBAAU,EAAoB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YACjG,CAAC;iBAAM,CAAC;gBACN,MAAM,aAAa,GAAG,MAAM,IAAA,mBAAU,EAA6B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;gBAClI,OAAO,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC7C,CAAC;QAEH,CAAC,CAAA,CACF,CACF,CAAC;QAEF,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CAAA;AApBD,kCAoBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-builders/custom-esbuild",
3
- "version": "18.0.1-beta.0",
3
+ "version": "18.1.0-beta.0",
4
4
  "description": "Custom esbuild builders for Angular build facade. Allow to modify Angular build configuration without ejecting it",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -32,7 +32,8 @@
32
32
  "scripts": {
33
33
  "prebuild": "yarn clean",
34
34
  "build": "yarn prebuild && tsc && ts-node ../../merge-schemes.ts && yarn postbuild",
35
- "postbuild": "yarn run e2e",
35
+ "postbuild": "yarn test && yarn run e2e",
36
+ "test": "jest --config ../../jest-ut.config.js",
36
37
  "e2e": "jest --config ../../jest-e2e.config.js",
37
38
  "clean": "rimraf dist",
38
39
  "ci": "./scripts/ci.sh"
@@ -55,5 +56,5 @@
55
56
  "ts-node": "^10.0.0",
56
57
  "typescript": "5.4.5"
57
58
  },
58
- "gitHead": "1802e2324405bb47c9cbda693b729094019944a7"
59
+ "gitHead": "1b0decdede47b0d8a5a7049bbe68d8859c204edf"
59
60
  }