@nx/esbuild 0.0.0-pr-22179-271588f

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.
Files changed (40) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/executors.json +9 -0
  4. package/generators.json +19 -0
  5. package/index.d.ts +4 -0
  6. package/index.js +11 -0
  7. package/migrations.json +51 -0
  8. package/package.json +53 -0
  9. package/src/executors/esbuild/esbuild.impl.d.ts +7 -0
  10. package/src/executors/esbuild/esbuild.impl.js +181 -0
  11. package/src/executors/esbuild/lib/build-esbuild-options.d.ts +7 -0
  12. package/src/executors/esbuild/lib/build-esbuild-options.js +240 -0
  13. package/src/executors/esbuild/lib/get-extra-dependencies.d.ts +3 -0
  14. package/src/executors/esbuild/lib/get-extra-dependencies.js +34 -0
  15. package/src/executors/esbuild/lib/normalize.d.ts +3 -0
  16. package/src/executors/esbuild/lib/normalize.js +64 -0
  17. package/src/executors/esbuild/schema.d.ts +36 -0
  18. package/src/executors/esbuild/schema.json +183 -0
  19. package/src/generators/configuration/configuration.d.ts +4 -0
  20. package/src/generators/configuration/configuration.js +108 -0
  21. package/src/generators/configuration/schema.d.ts +13 -0
  22. package/src/generators/configuration/schema.json +67 -0
  23. package/src/generators/init/init.d.ts +4 -0
  24. package/src/generators/init/init.js +21 -0
  25. package/src/generators/init/schema.d.ts +5 -0
  26. package/src/generators/init/schema.json +27 -0
  27. package/src/migrations/update-15-8-7/set-generate-package-json.d.ts +2 -0
  28. package/src/migrations/update-15-8-7/set-generate-package-json.js +22 -0
  29. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  30. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  31. package/src/migrations/update-16-0-1-set-thirdparty-true/update-16-0-1-set-thirdparty-true.d.ts +2 -0
  32. package/src/migrations/update-16-0-1-set-thirdparty-true/update-16-0-1-set-thirdparty-true.js +27 -0
  33. package/src/utils/environment-variables.d.ts +1 -0
  34. package/src/utils/environment-variables.js +13 -0
  35. package/src/utils/fs.d.ts +4 -0
  36. package/src/utils/fs.js +16 -0
  37. package/src/utils/get-entry-points.d.ts +8 -0
  38. package/src/utils/get-entry-points.js +60 -0
  39. package/src/utils/versions.d.ts +2 -0
  40. package/src/utils/versions.js +5 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017-2023 Narwhal Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ <p style="text-align: center;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
+ <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
+ </picture>
6
+ </p>
7
+
8
+ <div style="text-align: center;">
9
+
10
+ [![CircleCI](https://circleci.com/gh/nrwl/nx.svg?style=svg)](https://circleci.com/gh/nrwl/nx)
11
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
12
+ [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nx/workspace)
13
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
14
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
15
+ [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
16
+ [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
17
+
18
+ </div>
19
+
20
+
21
+ <hr>
22
+
23
+ # Nx: Smart Monorepos · Fast CI
24
+
25
+ Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
26
+
27
+ This package is a [EsBuild plugin for Nx](https://nx.dev/packages/esbuild).
28
+
29
+ ## Getting Started
30
+
31
+ ### Creating an Nx Workspace
32
+
33
+ **Using `npx`**
34
+
35
+ ```bash
36
+ npx create-nx-workspace
37
+ ```
38
+
39
+ **Using `npm init`**
40
+
41
+ ```bash
42
+ npm init nx-workspace
43
+ ```
44
+
45
+ **Using `yarn create`**
46
+
47
+ ```bash
48
+ yarn create nx-workspace
49
+ ```
50
+
51
+ ### Adding Nx to an Existing Repository
52
+
53
+ Run:
54
+
55
+ ```bash
56
+ npx nx@latest init
57
+ ```
58
+
59
+ ## Documentation & Resources
60
+
61
+ - [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
62
+ - [Intro to Nx](https://nx.dev/getting-started/intro)
63
+ - [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
64
+ - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
65
+
66
+ <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
67
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
68
+
package/executors.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "executors": {
3
+ "esbuild": {
4
+ "implementation": "./src/executors/esbuild/esbuild.impl",
5
+ "schema": "./src/executors/esbuild/schema.json",
6
+ "description": "Bundle a package using EsBuild."
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "Nx esbuild",
3
+ "version": "0.1",
4
+ "generators": {
5
+ "init": {
6
+ "factory": "./src/generators/init/init#esbuildInitGenerator",
7
+ "schema": "./src/generators/init/schema.json",
8
+ "description": "Initialize the `@nrwl/esbuild` plugin.",
9
+ "aliases": ["ng-add"],
10
+ "hidden": true
11
+ },
12
+ "configuration": {
13
+ "aliases": ["esbuild-project"],
14
+ "factory": "./src/generators/configuration/configuration",
15
+ "schema": "./src/generators/configuration/schema.json",
16
+ "description": "Add esbuild configuration to a project."
17
+ }
18
+ }
19
+ }
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { configurationGenerator } from './src/generators/configuration/configuration';
2
+ export { configurationGenerator };
3
+ export * from './src/generators/init/init';
4
+ export * from './src/utils/versions';
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configurationGenerator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const configuration_1 = require("./src/generators/configuration/configuration");
6
+ Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
7
+ // Exported for backwards compatibility in case a plugin is using the old name.
8
+ /** @deprecated Use `configurationGenerator` instead. */
9
+ const esbuildProjectGenerator = configuration_1.configurationGenerator;
10
+ tslib_1.__exportStar(require("./src/generators/init/init"), exports);
11
+ tslib_1.__exportStar(require("./src/utils/versions"), exports);
@@ -0,0 +1,51 @@
1
+ {
2
+ "generators": {
3
+ "set-generate-package-json": {
4
+ "cli": "nx",
5
+ "version": "15.8.7-beta.0",
6
+ "description": "Set generatePackageJson to true to maintain existing behavior of generating package.json in output path.",
7
+ "factory": "./src/migrations/update-15-8-7/set-generate-package-json"
8
+ },
9
+ "update-16-0-0-add-nx-packages": {
10
+ "cli": "nx",
11
+ "version": "16.0.0-beta.1",
12
+ "description": "Replace @nrwl/esbuild with @nx/esbuild",
13
+ "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
14
+ },
15
+ "update-16-0-1-set-thirdparty-true": {
16
+ "version": "16.0.1-beta.0",
17
+ "description": "Set thirdParty to true to maintain the existing behavior of bundling dependencies.",
18
+ "cli": "nx",
19
+ "implementation": "./src/migrations/update-16-0-1-set-thirdparty-true/update-16-0-1-set-thirdparty-true"
20
+ }
21
+ },
22
+ "packageJsonUpdates": {
23
+ "15.7.0": {
24
+ "version": "15.7.0-beta.0",
25
+ "packages": {
26
+ "esbuild": {
27
+ "version": "0.17.5",
28
+ "alwaysAddToPackageJson": false
29
+ }
30
+ }
31
+ },
32
+ "16.0.0": {
33
+ "version": "16.0.0-beta.5",
34
+ "packages": {
35
+ "esbuild": {
36
+ "version": "0.17.17",
37
+ "alwaysAddToPackageJson": false
38
+ }
39
+ }
40
+ },
41
+ "16.8.0": {
42
+ "version": "16.8.0-beta.2",
43
+ "packages": {
44
+ "esbuild": {
45
+ "version": "^0.19.2",
46
+ "alwaysAddToPackageJson": false
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@nx/esbuild",
3
+ "version": "0.0.0-pr-22179-271588f",
4
+ "private": false,
5
+ "description": "The Nx Plugin for esbuild contains executors and generators that support building applications using esbuild",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/nrwl/nx.git",
9
+ "directory": "packages/esbuild"
10
+ },
11
+ "keywords": [
12
+ "Monorepo",
13
+ "EsBuild",
14
+ "Web",
15
+ "CLI"
16
+ ],
17
+ "main": "./index.js",
18
+ "typings": "./index.d.ts",
19
+ "author": "Victor Savkin",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/nrwl/nx/issues"
23
+ },
24
+ "homepage": "https://nx.dev",
25
+ "generators": "./generators.json",
26
+ "executors": "./executors.json",
27
+ "ng-update": {
28
+ "requirements": {},
29
+ "migrations": "./migrations.json"
30
+ },
31
+ "dependencies": {
32
+ "chalk": "^4.1.0",
33
+ "fast-glob": "3.2.7",
34
+ "fs-extra": "^11.1.0",
35
+ "tslib": "^2.3.0",
36
+ "tsconfig-paths": "^4.1.2",
37
+ "@nx/devkit": "0.0.0-pr-22179-271588f",
38
+ "@nx/js": "0.0.0-pr-22179-271588f",
39
+ "@nrwl/esbuild": "0.0.0-pr-22179-271588f"
40
+ },
41
+ "peerDependencies": {
42
+ "esbuild": "~0.19.2"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "esbuild": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "type": "commonjs"
53
+ }
@@ -0,0 +1,7 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import { EsBuildExecutorOptions } from './schema';
3
+ export declare function esbuildExecutor(_options: EsBuildExecutorOptions, context: ExecutorContext): AsyncGenerator<{
4
+ success: boolean;
5
+ outfile?: string;
6
+ }, any, undefined>;
7
+ export default esbuildExecutor;
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.esbuildExecutor = void 0;
4
+ const chalk = require("chalk");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const js_1 = require("@nx/js");
7
+ const esbuild = require("esbuild");
8
+ const normalize_1 = require("./lib/normalize");
9
+ const fs_extra_1 = require("fs-extra");
10
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
11
+ const build_esbuild_options_1 = require("./lib/build-esbuild-options");
12
+ const get_extra_dependencies_1 = require("./lib/get-extra-dependencies");
13
+ const path_1 = require("path");
14
+ const BUILD_WATCH_FAILED = `[ ${chalk.red('watch')} ] build finished with errors (see above), watching for changes...`;
15
+ const BUILD_WATCH_SUCCEEDED = `[ ${chalk.green('watch')} ] build succeeded, watching for changes...`;
16
+ async function* esbuildExecutor(_options, context) {
17
+ process.env.NODE_ENV ??= context.configurationName ?? 'production';
18
+ const options = (0, normalize_1.normalizeOptions)(_options, context);
19
+ if (options.deleteOutputPath)
20
+ (0, fs_extra_1.removeSync)(options.outputPath);
21
+ const assetsResult = await (0, js_1.copyAssets)(options, context);
22
+ const externalDependencies = options.external.reduce((acc, name) => {
23
+ const externalNode = context.projectGraph.externalNodes[`npm:${name}`];
24
+ if (externalNode) {
25
+ acc.push({
26
+ name,
27
+ outputs: [],
28
+ node: externalNode,
29
+ });
30
+ }
31
+ return acc;
32
+ }, []);
33
+ if (!options.thirdParty) {
34
+ const thirdPartyDependencies = (0, get_extra_dependencies_1.getExtraDependencies)(context.projectName, context.projectGraph);
35
+ for (const tpd of thirdPartyDependencies) {
36
+ options.external.push(tpd.node.data.packageName);
37
+ externalDependencies.push(tpd);
38
+ }
39
+ }
40
+ let packageJsonResult;
41
+ if (options.generatePackageJson) {
42
+ if (context.projectGraph.nodes[context.projectName].type !== 'app') {
43
+ devkit_1.logger.warn((0, devkit_1.stripIndents) `The project ${context.projectName} is using the 'generatePackageJson' option which is deprecated for library projects. It should only be used for applications.
44
+ For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`);
45
+ }
46
+ const cpjOptions = {
47
+ ...options,
48
+ // TODO(jack): make types generate with esbuild
49
+ skipTypings: true,
50
+ generateLockfile: true,
51
+ outputFileExtensionForCjs: (0, build_esbuild_options_1.getOutExtension)('cjs', options),
52
+ excludeLibsInPackageJson: !options.thirdParty,
53
+ // TODO(jack): Remove the need to pass updateBuildableProjectDepsInPackageJson option when overrideDependencies or extraDependencies are passed.
54
+ // Add this back to fix a regression.
55
+ // See: https://github.com/nrwl/nx/issues/19773
56
+ updateBuildableProjectDepsInPackageJson: externalDependencies.length > 0,
57
+ };
58
+ // If we're bundling third-party packages, then any extra deps from external should be the only deps in package.json
59
+ if (options.thirdParty && externalDependencies.length > 0) {
60
+ cpjOptions.overrideDependencies = externalDependencies;
61
+ }
62
+ else {
63
+ cpjOptions.extraDependencies = externalDependencies;
64
+ }
65
+ packageJsonResult = await (0, js_1.copyPackageJson)(cpjOptions, context);
66
+ }
67
+ if (options.watch) {
68
+ return yield* (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
69
+ let hasTypeErrors = false;
70
+ const disposeFns = await Promise.all(options.format.map(async (format, idx) => {
71
+ const esbuildOptions = (0, build_esbuild_options_1.buildEsbuildOptions)(format, options, context);
72
+ const ctx = await esbuild.context({
73
+ ...esbuildOptions,
74
+ plugins: [
75
+ // Only emit info on one of the watch processes.
76
+ idx === 0
77
+ ? {
78
+ name: 'nx-watch-plugin',
79
+ setup(build) {
80
+ build.onEnd(async (result) => {
81
+ if (!options.skipTypeCheck) {
82
+ const { errors } = await runTypeCheck(options, context);
83
+ hasTypeErrors = errors.length > 0;
84
+ }
85
+ const success = result.errors.length === 0 && !hasTypeErrors;
86
+ if (!success) {
87
+ devkit_1.logger.info(BUILD_WATCH_FAILED);
88
+ }
89
+ else {
90
+ devkit_1.logger.info(BUILD_WATCH_SUCCEEDED);
91
+ }
92
+ next({
93
+ success,
94
+ // Need to call getOutfile directly in the case of bundle=false and outfile is not set for esbuild.
95
+ outfile: (0, path_1.join)(context.root, (0, build_esbuild_options_1.getOutfile)(format, options, context)),
96
+ });
97
+ });
98
+ },
99
+ }
100
+ : null,
101
+ ...(esbuildOptions?.plugins || []),
102
+ ].filter(Boolean),
103
+ });
104
+ await ctx.watch();
105
+ return () => ctx.dispose();
106
+ }));
107
+ registerCleanupCallback(() => {
108
+ assetsResult?.stop();
109
+ packageJsonResult?.stop();
110
+ disposeFns.forEach((fn) => fn());
111
+ done(); // return from async iterable
112
+ });
113
+ });
114
+ }
115
+ else {
116
+ // Run type-checks first and bail if they don't pass.
117
+ if (!options.skipTypeCheck) {
118
+ const { errors } = await runTypeCheck(options, context);
119
+ if (errors.length > 0) {
120
+ yield { success: false };
121
+ return;
122
+ }
123
+ }
124
+ // Emit a build event for each file format.
125
+ for (let i = 0; i < options.format.length; i++) {
126
+ const format = options.format[i];
127
+ const esbuildOptions = (0, build_esbuild_options_1.buildEsbuildOptions)(format, options, context);
128
+ const buildResult = await esbuild.build(esbuildOptions);
129
+ if (options.metafile) {
130
+ const filename = options.format.length === 1
131
+ ? 'meta.json'
132
+ : `meta.${options.format[i]}.json`;
133
+ (0, fs_extra_1.writeJsonSync)((0, devkit_1.joinPathFragments)(options.outputPath, filename), buildResult.metafile);
134
+ }
135
+ yield {
136
+ success: buildResult.errors.length === 0,
137
+ // Need to call getOutfile directly in the case of bundle=false and outfile is not set for esbuild.
138
+ // This field is needed for `@nx/js:node` executor to work.
139
+ outfile: (0, path_1.join)(context.root, (0, build_esbuild_options_1.getOutfile)(format, options, context)),
140
+ };
141
+ }
142
+ }
143
+ }
144
+ exports.esbuildExecutor = esbuildExecutor;
145
+ function getTypeCheckOptions(options, context) {
146
+ const { watch, tsConfig, outputPath } = options;
147
+ const typeCheckOptions = {
148
+ // TODO(jack): Add support for d.ts declaration files -- once the `@nx/js:tsc` changes are in we can use the same logic.
149
+ mode: 'noEmit',
150
+ tsConfigPath: tsConfig,
151
+ // outDir: outputPath,
152
+ workspaceRoot: context.root,
153
+ rootDir: context.root,
154
+ };
155
+ if (watch) {
156
+ typeCheckOptions.incremental = true;
157
+ typeCheckOptions.cacheDir = devkit_1.cacheDir;
158
+ }
159
+ return typeCheckOptions;
160
+ }
161
+ async function runTypeCheck(options, context) {
162
+ const { errors, warnings } = await (0, js_1.runTypeCheck)(getTypeCheckOptions(options, context));
163
+ const hasErrors = errors.length > 0;
164
+ const hasWarnings = warnings.length > 0;
165
+ if (hasErrors || hasWarnings) {
166
+ await (0, js_1.printDiagnostics)(errors, warnings);
167
+ }
168
+ return { errors, warnings };
169
+ }
170
+ function registerCleanupCallback(callback) {
171
+ const wrapped = () => {
172
+ callback();
173
+ process.off('SIGINT', wrapped);
174
+ process.off('SIGTERM', wrapped);
175
+ process.off('exit', wrapped);
176
+ };
177
+ process.on('SIGINT', wrapped);
178
+ process.on('SIGTERM', wrapped);
179
+ process.on('exit', wrapped);
180
+ }
181
+ exports.default = esbuildExecutor;
@@ -0,0 +1,7 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { ExecutorContext, ProjectGraphProjectNode } from '@nx/devkit';
3
+ import { NormalizedEsBuildExecutorOptions } from '../schema';
4
+ export declare function buildEsbuildOptions(format: 'cjs' | 'esm', options: NormalizedEsBuildExecutorOptions, context: ExecutorContext): esbuild.BuildOptions;
5
+ export declare function getOutExtension(format: 'cjs' | 'esm', options: NormalizedEsBuildExecutorOptions): '.cjs' | '.mjs' | '.js';
6
+ export declare function getOutfile(format: 'cjs' | 'esm', options: NormalizedEsBuildExecutorOptions, context: ExecutorContext): string;
7
+ export declare function getRegisterFileContent(project: ProjectGraphProjectNode, paths: Record<string, string[]>, mainFile: string, outExtension?: string): string;