From 43a4482482ce83e921aacb491b4a572bde2e52db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 4 Dec 2023 10:21:35 +0100 Subject: [PATCH] feat(angular): add application executor (#20529) --- docs/generated/manifests/menus.json | 8 + docs/generated/manifests/nx-api.json | 9 + docs/generated/packages-metadata.json | 9 + .../angular/executors/application.json | 693 ++++++++++++++++++ .../angular/executors/browser-esbuild.json | 1 + docs/shared/reference/sitemap.md | 1 + e2e/angular-core/src/projects.test.ts | 43 +- .../docs/application-executor-examples.md | 34 + .../angular/docs/browser-esbuild-examples.md | 34 + packages/angular/executors.json | 5 + packages/angular/executors.ts | 1 + .../builders/dev-server/dev-server.impl.ts | 2 + .../executors/application/application.impl.ts | 47 ++ .../src/executors/application/schema.d.ts | 7 + .../src/executors/application/schema.json | 624 ++++++++++++++++ .../browser-esbuild/browser-esbuild.impl.ts | 18 +- .../src/executors/browser-esbuild/schema.json | 1 + .../lib => utilities}/buildable-libs.ts | 17 +- 18 files changed, 1515 insertions(+), 39 deletions(-) create mode 100644 docs/generated/packages/angular/executors/application.json create mode 100644 packages/angular/docs/application-executor-examples.md create mode 100644 packages/angular/docs/browser-esbuild-examples.md create mode 100644 packages/angular/src/executors/application/application.impl.ts create mode 100644 packages/angular/src/executors/application/schema.d.ts create mode 100644 packages/angular/src/executors/application/schema.json rename packages/angular/src/executors/{browser-esbuild/lib => utilities}/buildable-libs.ts (66%) diff --git a/docs/generated/manifests/menus.json b/docs/generated/manifests/menus.json index 9588f94b0971b..b97eaf7636336 100644 --- a/docs/generated/manifests/menus.json +++ b/docs/generated/manifests/menus.json @@ -6552,6 +6552,14 @@ "isExternal": false, "disableCollapsible": false }, + { + "id": "application", + "path": "/nx-api/angular/executors/application", + "name": "application", + "children": [], + "isExternal": false, + "disableCollapsible": false + }, { "id": "webpack-browser", "path": "/nx-api/angular/executors/webpack-browser", diff --git a/docs/generated/manifests/nx-api.json b/docs/generated/manifests/nx-api.json index 08352ad373a34..32ac4a0de43b1 100644 --- a/docs/generated/manifests/nx-api.json +++ b/docs/generated/manifests/nx-api.json @@ -76,6 +76,15 @@ "path": "/nx-api/angular/executors/module-federation-dev-server", "type": "executor" }, + "/nx-api/angular/executors/application": { + "description": "Builds an application with esbuild with support for incremental builds.", + "file": "generated/packages/angular/executors/application.json", + "hidden": false, + "name": "application", + "originalFilePath": "/packages/angular/src/executors/application/schema.json", + "path": "/nx-api/angular/executors/application", + "type": "executor" + }, "/nx-api/angular/executors/webpack-browser": { "description": "The `webpack-browser` executor is very similar to the standard `browser` builder provided by the Angular Devkit. It allows you to build your Angular application to a build artifact that can be hosted online. There are some key differences: \n- Supports Custom Webpack Configurations \n- Supports Incremental Building", "file": "generated/packages/angular/executors/webpack-browser.json", diff --git a/docs/generated/packages-metadata.json b/docs/generated/packages-metadata.json index 4c11530819828..b646e6868e7a6 100644 --- a/docs/generated/packages-metadata.json +++ b/docs/generated/packages-metadata.json @@ -71,6 +71,15 @@ "path": "angular/executors/module-federation-dev-server", "type": "executor" }, + { + "description": "Builds an application with esbuild with support for incremental builds.", + "file": "generated/packages/angular/executors/application.json", + "hidden": false, + "name": "application", + "originalFilePath": "/packages/angular/src/executors/application/schema.json", + "path": "angular/executors/application", + "type": "executor" + }, { "description": "The `webpack-browser` executor is very similar to the standard `browser` builder provided by the Angular Devkit. It allows you to build your Angular application to a build artifact that can be hosted online. There are some key differences: \n- Supports Custom Webpack Configurations \n- Supports Incremental Building", "file": "generated/packages/angular/executors/webpack-browser.json", diff --git a/docs/generated/packages/angular/executors/application.json b/docs/generated/packages/angular/executors/application.json new file mode 100644 index 0000000000000..bbd9738293abf --- /dev/null +++ b/docs/generated/packages/angular/executors/application.json @@ -0,0 +1,693 @@ +{ + "name": "application", + "implementation": "/packages/angular/src/executors/application/application.impl.ts", + "schema": { + "$schema": "http://json-schema.org/draft-07/schema", + "title": "Schema for Nx Application Executor", + "description": "Builds an application with esbuild with support for incremental builds.", + "examplesFile": "The `@nx/angular:application` executor is very similar to the `@angular-devkit/build-angular:application` builder provided by the Angular CLI. It builds an Angular application using [esbuild](https://esbuild.github.io/) with integrated SSR and prerendering capabilities.\n\nIn addition to the features provided by the Angular CLI builder, the `@nx/angular:application` executor also supports the following:\n\n- Providing esbuild plugins\n- Incremental builds\n\n## Examples\n\n{% tabs %}\n{% tab label=\"Providing esbuild plugins\" %}\n\nThe executor accepts a `plugins` option that allows you to provide esbuild plugins that will be used when building your application. It allows providing a path to a plugin file or an object with a `path` and `options` property to provide options to the plugin.\n\n```json\n\"build\": {\n \"executor\": \"@nx/angular:application\",\n \"options\": {\n ...\n \"plugins\": [\n \"apps/my-app/plugins/plugin1.js\",\n {\n \"path\": \"apps/my-app/plugins/plugin2.js\",\n \"options\": {\n \"someOption\": \"someValue\"\n }\n }\n ]\n }\n}\n```\n\n{% /tab %}\n{% /tabs %}\n", + "outputCapture": "direct-nodejs", + "type": "object", + "properties": { + "assets": { + "type": "array", + "description": "List of static application assets.", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "followSymlinks": { + "type": "boolean", + "default": false, + "description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched." + }, + "glob": { + "type": "string", + "description": "The pattern to match." + }, + "input": { + "type": "string", + "description": "The input directory path in which to apply 'glob'. Defaults to the project root." + }, + "ignore": { + "description": "An array of globs to ignore.", + "type": "array", + "items": { "type": "string" } + }, + "output": { + "type": "string", + "description": "Absolute path within the output." + } + }, + "additionalProperties": false, + "required": ["glob", "input", "output"] + }, + { "type": "string" } + ] + } + }, + "browser": { + "type": "string", + "description": "The full path for the browser entry point to the application, relative to the current workspace." + }, + "server": { + "type": "string", + "description": "The full path for the server entry point to the application, relative to the current workspace." + }, + "polyfills": { + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", + "type": "array", + "items": { "type": "string", "uniqueItems": true }, + "default": [] + }, + "tsConfig": { + "type": "string", + "description": "The full path for the TypeScript configuration file, relative to the current workspace." + }, + "scripts": { + "description": "Global scripts to be included in the build.", + "type": "array", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "input": { + "type": "string", + "description": "The file to include.", + "pattern": "\\.[cm]?jsx?$" + }, + "bundleName": { + "type": "string", + "pattern": "^[\\w\\-.]*$", + "description": "The bundle name for this extra entry point." + }, + "inject": { + "type": "boolean", + "description": "If the bundle will be referenced in the HTML file.", + "default": true + } + }, + "additionalProperties": false, + "required": ["input"] + }, + { + "type": "string", + "description": "The JavaScript/TypeScript file or package containing the file to include." + } + ] + } + }, + "styles": { + "description": "Global styles to be included in the build.", + "type": "array", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "input": { + "type": "string", + "description": "The file to include.", + "pattern": "\\.(?:css|scss|sass|less)$" + }, + "bundleName": { + "type": "string", + "pattern": "^[\\w\\-.]*$", + "description": "The bundle name for this extra entry point." + }, + "inject": { + "type": "boolean", + "description": "If the bundle will be referenced in the HTML file.", + "default": true + } + }, + "additionalProperties": false, + "required": ["input"] + }, + { + "type": "string", + "description": "The file to include.", + "pattern": "\\.(?:css|scss|sass|less)$" + } + ] + } + }, + "inlineStyleLanguage": { + "description": "The stylesheet language to use for the application's inline component styles.", + "type": "string", + "default": "css", + "enum": ["css", "less", "sass", "scss"] + }, + "stylePreprocessorOptions": { + "description": "Options to pass to style preprocessors.", + "type": "object", + "properties": { + "includePaths": { + "description": "Paths to include. Paths will be resolved to workspace root.", + "type": "array", + "items": { "type": "string" }, + "default": [] + } + }, + "additionalProperties": false + }, + "externalDependencies": { + "description": "Exclude the listed external dependencies from being bundled into the bundle. Instead, the created bundle relies on these dependencies to be available during runtime.", + "type": "array", + "items": { "type": "string" }, + "default": [] + }, + "optimization": { + "description": "Enables optimization of the build output. Including minification of scripts and styles, tree-shaking, dead-code elimination, inlining of critical CSS and fonts inlining. For more information, see https://angular.io/guide/workspace-config#optimization-configuration.", + "default": true, + "x-user-analytics": "ep.ng_optimization", + "oneOf": [ + { + "type": "object", + "properties": { + "scripts": { + "type": "boolean", + "description": "Enables optimization of the scripts output.", + "default": true + }, + "styles": { + "description": "Enables optimization of the styles output.", + "default": true, + "oneOf": [ + { + "type": "object", + "properties": { + "minify": { + "type": "boolean", + "description": "Minify CSS definitions by removing extraneous whitespace and comments, merging identifiers and minimizing values.", + "default": true + }, + "inlineCritical": { + "type": "boolean", + "description": "Extract and inline critical CSS definitions to improve first paint time.", + "default": true + }, + "removeSpecialComments": { + "type": "boolean", + "description": "Remove comments in global CSS that contains '@license' or '@preserve' or that starts with '//!' or '/*!'.", + "default": true + } + }, + "additionalProperties": false + }, + { "type": "boolean" } + ] + }, + "fonts": { + "description": "Enables optimization for fonts. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.", + "default": true, + "oneOf": [ + { + "type": "object", + "properties": { + "inline": { + "type": "boolean", + "description": "Reduce render blocking requests by inlining external Google Fonts and Adobe Fonts CSS definitions in the application's HTML index file. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.", + "default": true + } + }, + "additionalProperties": false + }, + { "type": "boolean" } + ] + } + }, + "additionalProperties": false + }, + { "type": "boolean" } + ] + }, + "loader": { + "description": "Defines the type of loader to use with a specified file extension when used with a JavaScript `import`. `text` inlines the content as a string; `binary` inlines the content as a Uint8Array; `file` emits the file and provides the runtime location of the file; `empty` considers the content to be empty and not include it in bundles.", + "type": "object", + "patternProperties": { + "^\\.\\S+$": { "enum": ["text", "binary", "file", "empty"] } + } + }, + "fileReplacements": { + "description": "Replace compilation source files with other compilation source files in the build.", + "type": "array", + "items": { + "type": "object", + "properties": { + "replace": { + "type": "string", + "pattern": "\\.(([cm]?j|t)sx?|json)$" + }, + "with": { "type": "string", "pattern": "\\.(([cm]?j|t)sx?|json)$" } + }, + "additionalProperties": false, + "required": ["replace", "with"] + }, + "default": [] + }, + "outputPath": { + "type": "string", + "description": "The full path for the new output directory, relative to the current workspace." + }, + "aot": { + "type": "boolean", + "description": "Build using Ahead of Time compilation.", + "x-user-analytics": "ep.ng_aot", + "default": true + }, + "sourceMap": { + "description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.", + "default": false, + "oneOf": [ + { + "type": "object", + "properties": { + "scripts": { + "type": "boolean", + "description": "Output source maps for all scripts.", + "default": true + }, + "styles": { + "type": "boolean", + "description": "Output source maps for all styles.", + "default": true + }, + "hidden": { + "type": "boolean", + "description": "Output source maps used for error reporting tools.", + "default": false + }, + "vendor": { + "type": "boolean", + "description": "Resolve vendor packages source maps.", + "default": false + } + }, + "additionalProperties": false + }, + { "type": "boolean" } + ] + }, + "baseHref": { + "type": "string", + "description": "Base url for the application being built." + }, + "verbose": { + "type": "boolean", + "description": "Adds more details to output logging.", + "default": false + }, + "progress": { + "type": "boolean", + "description": "Log progress to the console while building.", + "default": true + }, + "i18nMissingTranslation": { + "type": "string", + "description": "How to handle missing translations for i18n.", + "enum": ["warning", "error", "ignore"], + "default": "warning" + }, + "i18nDuplicateTranslation": { + "type": "string", + "description": "How to handle duplicate translations for i18n.", + "enum": ["warning", "error", "ignore"], + "default": "warning" + }, + "localize": { + "description": "Translate the bundles in one or more locales.", + "oneOf": [ + { "type": "boolean", "description": "Translate all locales." }, + { + "type": "array", + "description": "List of locales ID's to translate.", + "minItems": 1, + "items": { + "type": "string", + "pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$" + } + } + ] + }, + "watch": { + "type": "boolean", + "description": "Run build when files change.", + "default": false + }, + "outputHashing": { + "type": "string", + "description": "Define the output filename cache-busting hashing mode.", + "default": "none", + "enum": ["none", "all", "media", "bundles"] + }, + "poll": { + "type": "number", + "description": "Enable and define the file watching poll time period in milliseconds." + }, + "deleteOutputPath": { + "type": "boolean", + "description": "Delete the output path before building.", + "default": true + }, + "preserveSymlinks": { + "type": "boolean", + "description": "Do not use the real path when resolving modules. If unset then will default to `true` if NodeJS option --preserve-symlinks is set." + }, + "extractLicenses": { + "type": "boolean", + "description": "Extract all licenses in a separate file.", + "default": true + }, + "namedChunks": { + "type": "boolean", + "description": "Use file name for lazy loaded chunks.", + "default": false + }, + "subresourceIntegrity": { + "type": "boolean", + "description": "Enables the use of subresource integrity validation.", + "default": false + }, + "serviceWorker": { + "description": "Generates a service worker configuration.", + "default": false, + "oneOf": [ + { "type": "string", "description": "Path to ngsw-config.json." }, + { + "const": false, + "type": "boolean", + "description": "Does not generate a service worker configuration." + } + ] + }, + "index": { + "description": "Configures the generation of the application's HTML index.", + "oneOf": [ + { + "type": "string", + "description": "The path of a file to use for the application's HTML index. The filename of the specified path will be used for the generated file and will be created in the root of the application's configured output path." + }, + { + "type": "object", + "description": "", + "properties": { + "input": { + "type": "string", + "minLength": 1, + "description": "The path of a file to use for the application's generated HTML index." + }, + "output": { + "type": "string", + "minLength": 1, + "default": "index.html", + "description": "The output path of the application's generated HTML index file. The full provided path will be used and will be considered relative to the application's configured output path." + } + }, + "required": ["input"] + }, + { + "const": false, + "type": "boolean", + "description": "Does not generate an `index.html` file." + } + ] + }, + "statsJson": { + "type": "boolean", + "description": "Generates a 'stats.json' file which can be analyzed with https://esbuild.github.io/analyze/.", + "default": false + }, + "budgets": { + "description": "Budget thresholds to ensure parts of your application stay within boundaries which you set.", + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The type of budget.", + "enum": [ + "all", + "allScript", + "any", + "anyScript", + "anyComponentStyle", + "bundle", + "initial" + ] + }, + "name": { + "type": "string", + "description": "The name of the bundle." + }, + "baseline": { + "type": "string", + "description": "The baseline size for comparison." + }, + "maximumWarning": { + "type": "string", + "description": "The maximum threshold for warning relative to the baseline." + }, + "maximumError": { + "type": "string", + "description": "The maximum threshold for error relative to the baseline." + }, + "minimumWarning": { + "type": "string", + "description": "The minimum threshold for warning relative to the baseline." + }, + "minimumError": { + "type": "string", + "description": "The minimum threshold for error relative to the baseline." + }, + "warning": { + "type": "string", + "description": "The threshold for warning relative to the baseline (min & max)." + }, + "error": { + "type": "string", + "description": "The threshold for error relative to the baseline (min & max)." + } + }, + "additionalProperties": false, + "required": ["type"] + }, + "default": [] + }, + "webWorkerTsConfig": { + "type": "string", + "description": "TypeScript configuration for Web Worker modules." + }, + "crossOrigin": { + "type": "string", + "description": "Define the crossorigin attribute setting of elements that provide CORS support.", + "default": "none", + "enum": ["none", "anonymous", "use-credentials"] + }, + "allowedCommonJsDependencies": { + "description": "A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.", + "type": "array", + "items": { "type": "string" }, + "default": [] + }, + "prerender": { + "description": "Prerender (SSG) pages of your application during build time.", + "default": false, + "oneOf": [ + { + "type": "boolean", + "description": "Enable prerending of pages of your application during build time." + }, + { + "type": "object", + "properties": { + "routesFile": { + "type": "string", + "description": "The path to a file that contains a list of all routes to prerender, separated by newlines. This option is useful if you want to prerender routes with parameterized URLs." + }, + "discoverRoutes": { + "type": "boolean", + "description": "Whether the builder should process the Angular Router configuration to find all unparameterized routes and prerender them.", + "default": true + } + }, + "additionalProperties": false + } + ] + }, + "ssr": { + "description": "Server side render (SSR) pages of your application during runtime.", + "default": false, + "oneOf": [ + { + "type": "boolean", + "description": "Enable the server bundles to be written to disk." + }, + { + "type": "object", + "properties": { + "entry": { + "type": "string", + "description": "The server entry-point that when executed will spawn the web server." + } + }, + "additionalProperties": false + } + ] + }, + "appShell": { + "type": "boolean", + "description": "Generates an application shell during build time.", + "default": false + }, + "buildLibsFromSource": { + "type": "boolean", + "description": "Read buildable libraries from source instead of building them separately.", + "default": true + }, + "plugins": { + "description": "A list of ESBuild plugins.", + "type": "array", + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "path": { + "type": "string", + "description": "The path to the plugin. Relative to the workspace root." + }, + "options": { + "type": "object", + "description": "The options to provide to the plugin.", + "properties": {}, + "additionalProperties": true + } + }, + "additionalProperties": false, + "required": ["path"] + }, + { + "type": "string", + "description": "The path to the plugin. Relative to the workspace root." + } + ] + } + } + }, + "additionalProperties": false, + "required": ["outputPath", "index", "browser", "tsConfig"], + "definitions": { + "assetPattern": { + "oneOf": [ + { + "type": "object", + "properties": { + "followSymlinks": { + "type": "boolean", + "default": false, + "description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched." + }, + "glob": { + "type": "string", + "description": "The pattern to match." + }, + "input": { + "type": "string", + "description": "The input directory path in which to apply 'glob'. Defaults to the project root." + }, + "ignore": { + "description": "An array of globs to ignore.", + "type": "array", + "items": { "type": "string" } + }, + "output": { + "type": "string", + "description": "Absolute path within the output." + } + }, + "additionalProperties": false, + "required": ["glob", "input", "output"] + }, + { "type": "string" } + ] + }, + "fileReplacement": { + "type": "object", + "properties": { + "replace": { + "type": "string", + "pattern": "\\.(([cm]?j|t)sx?|json)$" + }, + "with": { "type": "string", "pattern": "\\.(([cm]?j|t)sx?|json)$" } + }, + "additionalProperties": false, + "required": ["replace", "with"] + }, + "budget": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The type of budget.", + "enum": [ + "all", + "allScript", + "any", + "anyScript", + "anyComponentStyle", + "bundle", + "initial" + ] + }, + "name": { + "type": "string", + "description": "The name of the bundle." + }, + "baseline": { + "type": "string", + "description": "The baseline size for comparison." + }, + "maximumWarning": { + "type": "string", + "description": "The maximum threshold for warning relative to the baseline." + }, + "maximumError": { + "type": "string", + "description": "The maximum threshold for error relative to the baseline." + }, + "minimumWarning": { + "type": "string", + "description": "The minimum threshold for warning relative to the baseline." + }, + "minimumError": { + "type": "string", + "description": "The minimum threshold for error relative to the baseline." + }, + "warning": { + "type": "string", + "description": "The threshold for warning relative to the baseline (min & max)." + }, + "error": { + "type": "string", + "description": "The threshold for error relative to the baseline (min & max)." + } + }, + "additionalProperties": false, + "required": ["type"] + } + }, + "presets": [] + }, + "description": "Builds an application with esbuild with support for incremental builds.", + "aliases": [], + "hidden": false, + "path": "/packages/angular/src/executors/application/schema.json", + "type": "executor" +} diff --git a/docs/generated/packages/angular/executors/browser-esbuild.json b/docs/generated/packages/angular/executors/browser-esbuild.json index 3012f178e0763..bccdde46df0f0 100644 --- a/docs/generated/packages/angular/executors/browser-esbuild.json +++ b/docs/generated/packages/angular/executors/browser-esbuild.json @@ -5,6 +5,7 @@ "$schema": "http://json-schema.org/draft-07/schema", "title": "Schema for Nx ESBuild Executor", "description": "Nx ESBuild Executor supporting Incremental Builds.", + "examplesFile": "The `@nx/angular:browser-esbuild` executor is very similar to the `@angular-devkit/build-angular:browser-esbuild` builder provided by the Angular CLI. It builds an Angular application using [esbuild](https://esbuild.github.io/).\n\nIn addition to the features provided by the Angular CLI builder, the `@nx/angular:browser-esbuild` executor also supports the following:\n\n- Providing esbuild plugins\n- Incremental builds\n\n## Examples\n\n{% tabs %}\n{% tab label=\"Providing esbuild plugins\" %}\n\nThe executor accepts a `plugins` option that allows you to provide esbuild plugins that will be used when building your application. It allows providing a path to a plugin file or an object with a `path` and `options` property to provide options to the plugin.\n\n```json\n\"build\": {\n \"executor\": \"@nx/angular:browser-esbuild\",\n \"options\": {\n ...\n \"plugins\": [\n \"apps/my-app/plugins/plugin1.js\",\n {\n \"path\": \"apps/my-app/plugins/plugin2.js\",\n \"options\": {\n \"someOption\": \"someValue\"\n }\n }\n ]\n }\n}\n```\n\n{% /tab %}\n{% /tabs %}\n", "outputCapture": "direct-nodejs", "type": "object", "properties": { diff --git a/docs/shared/reference/sitemap.md b/docs/shared/reference/sitemap.md index b18f0046c11c6..08fe81bad9118 100644 --- a/docs/shared/reference/sitemap.md +++ b/docs/shared/reference/sitemap.md @@ -324,6 +324,7 @@ - [package](/nx-api/angular/executors/package) - [browser-esbuild](/nx-api/angular/executors/browser-esbuild) - [module-federation-dev-server](/nx-api/angular/executors/module-federation-dev-server) + - [application](/nx-api/angular/executors/application) - [webpack-browser](/nx-api/angular/executors/webpack-browser) - [dev-server](/nx-api/angular/executors/dev-server) - [webpack-server](/nx-api/angular/executors/webpack-server) diff --git a/e2e/angular-core/src/projects.test.ts b/e2e/angular-core/src/projects.test.ts index 4422e9f460c08..4eb9968fb9226 100644 --- a/e2e/angular-core/src/projects.test.ts +++ b/e2e/angular-core/src/projects.test.ts @@ -355,17 +355,6 @@ describe('Angular Projects', () => { export default replaceTextPlugin;` ); - updateJson(join(esbuildApp, 'project.json'), (config) => { - config.targets.build.executor = '@nx/angular:browser-esbuild'; - config.targets.build.options = { - ...config.targets.build.options, - outputPath: `dist/${esbuildApp}`, - main: config.targets.build.options.browser, - browser: undefined, - plugins: [`${esbuildApp}/replace-text.plugin.mjs`], - }; - return config; - }); updateFile( `${esbuildApp}/src/app/app.component.ts`, `import { Component } from '@angular/core'; @@ -382,11 +371,37 @@ describe('Angular Projects', () => { }` ); - // ACT + // check @nx/angular:application + updateJson(join(esbuildApp, 'project.json'), (config) => { + config.targets.build.executor = '@nx/angular:application'; + config.targets.build.options = { + ...config.targets.build.options, + plugins: [`${esbuildApp}/replace-text.plugin.mjs`], + }; + return config; + }); + runCLI(`build ${esbuildApp} --configuration=development`); - // ASSERT - const mainBundle = readFile(`dist/${esbuildApp}/main.js`); + let mainBundle = readFile(`dist/${esbuildApp}/browser/main.js`); + expect(mainBundle).toContain( + 'this.buildDefined = "Value was provided at build time";' + ); + + // check @nx/angular:browser-esbuild + updateJson(join(esbuildApp, 'project.json'), (config) => { + config.targets.build.executor = '@nx/angular:browser-esbuild'; + config.targets.build.options = { + ...config.targets.build.options, + main: config.targets.build.options.browser, + browser: undefined, + }; + return config; + }); + + runCLI(`build ${esbuildApp} --configuration=development`); + + mainBundle = readFile(`dist/${esbuildApp}/main.js`); expect(mainBundle).toContain( 'this.buildDefined = "Value was provided at build time";' ); diff --git a/packages/angular/docs/application-executor-examples.md b/packages/angular/docs/application-executor-examples.md new file mode 100644 index 0000000000000..945becaa907ab --- /dev/null +++ b/packages/angular/docs/application-executor-examples.md @@ -0,0 +1,34 @@ +The `@nx/angular:application` executor is very similar to the `@angular-devkit/build-angular:application` builder provided by the Angular CLI. It builds an Angular application using [esbuild](https://esbuild.github.io/) with integrated SSR and prerendering capabilities. + +In addition to the features provided by the Angular CLI builder, the `@nx/angular:application` executor also supports the following: + +- Providing esbuild plugins +- Incremental builds + +## Examples + +{% tabs %} +{% tab label="Providing esbuild plugins" %} + +The executor accepts a `plugins` option that allows you to provide esbuild plugins that will be used when building your application. It allows providing a path to a plugin file or an object with a `path` and `options` property to provide options to the plugin. + +```json +"build": { + "executor": "@nx/angular:application", + "options": { + ... + "plugins": [ + "apps/my-app/plugins/plugin1.js", + { + "path": "apps/my-app/plugins/plugin2.js", + "options": { + "someOption": "someValue" + } + } + ] + } +} +``` + +{% /tab %} +{% /tabs %} diff --git a/packages/angular/docs/browser-esbuild-examples.md b/packages/angular/docs/browser-esbuild-examples.md new file mode 100644 index 0000000000000..74321a187270c --- /dev/null +++ b/packages/angular/docs/browser-esbuild-examples.md @@ -0,0 +1,34 @@ +The `@nx/angular:browser-esbuild` executor is very similar to the `@angular-devkit/build-angular:browser-esbuild` builder provided by the Angular CLI. It builds an Angular application using [esbuild](https://esbuild.github.io/). + +In addition to the features provided by the Angular CLI builder, the `@nx/angular:browser-esbuild` executor also supports the following: + +- Providing esbuild plugins +- Incremental builds + +## Examples + +{% tabs %} +{% tab label="Providing esbuild plugins" %} + +The executor accepts a `plugins` option that allows you to provide esbuild plugins that will be used when building your application. It allows providing a path to a plugin file or an object with a `path` and `options` property to provide options to the plugin. + +```json +"build": { + "executor": "@nx/angular:browser-esbuild", + "options": { + ... + "plugins": [ + "apps/my-app/plugins/plugin1.js", + { + "path": "apps/my-app/plugins/plugin2.js", + "options": { + "someOption": "someValue" + } + } + ] + } +} +``` + +{% /tab %} +{% /tabs %} diff --git a/packages/angular/executors.json b/packages/angular/executors.json index a70cecc2903b3..d875550f8bf02 100644 --- a/packages/angular/executors.json +++ b/packages/angular/executors.json @@ -24,6 +24,11 @@ "implementation": "./src/executors/module-federation-dev-server/module-federation-dev-server.impl", "schema": "./src/executors/module-federation-dev-server/schema.json", "description": "The module-federation-dev-server executor is reserved exclusively for use with host Module Federation applications. It allows the user to specify which remote applications should be served with the host." + }, + "application": { + "implementation": "./src/executors/application/application.impl", + "schema": "./src/executors/application/schema.json", + "description": "Builds an application with esbuild with support for incremental builds." } }, "builders": { diff --git a/packages/angular/executors.ts b/packages/angular/executors.ts index 0dba28814ca62..7160a154c3a96 100644 --- a/packages/angular/executors.ts +++ b/packages/angular/executors.ts @@ -6,6 +6,7 @@ export * from './src/executors/delegate-build/delegate-build.impl'; export * from './src/executors/ng-packagr-lite/ng-packagr-lite.impl'; export * from './src/executors/package/package.impl'; export * from './src/executors/browser-esbuild/browser-esbuild.impl'; +export * from './src/executors/application/application.impl'; import { executeDevServerBuilder } from './src/builders/dev-server/dev-server.impl'; diff --git a/packages/angular/src/builders/dev-server/dev-server.impl.ts b/packages/angular/src/builders/dev-server/dev-server.impl.ts index d001b58a876fc..22a9f62d63525 100644 --- a/packages/angular/src/builders/dev-server/dev-server.impl.ts +++ b/packages/angular/src/builders/dev-server/dev-server.impl.ts @@ -145,6 +145,7 @@ export function executeDevServerBuilder( const isUsingWebpackBuilder = ![ '@angular-devkit/build-angular:application', '@angular-devkit/build-angular:browser-esbuild', + '@nx/angular:application', '@nx/angular:browser-esbuild', ].includes(buildTarget.executor); @@ -248,6 +249,7 @@ const executorToBuilderMap = new Map([ '@nx/angular:browser-esbuild', '@angular-devkit/build-angular:browser-esbuild', ], + ['@nx/angular:application', '@angular-devkit/build-angular:application'], ]); function patchBuilderContext( context: BuilderContext, diff --git a/packages/angular/src/executors/application/application.impl.ts b/packages/angular/src/executors/application/application.impl.ts new file mode 100644 index 0000000000000..453c4029b19b3 --- /dev/null +++ b/packages/angular/src/executors/application/application.impl.ts @@ -0,0 +1,47 @@ +import type { ExecutorContext } from '@nx/devkit'; +import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils'; +import { createBuilderContext } from 'nx/src/adapter/ngcli-adapter'; +import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; +import { loadPlugins } from '../utilities/esbuild-extensions'; +import type { ApplicationExecutorOptions } from './schema'; + +export default async function* applicationExecutor( + options: ApplicationExecutorOptions, + context: ExecutorContext +) { + const { + buildLibsFromSource = true, + plugins: pluginPaths, + ...delegateExecutorOptions + } = options; + + let dependencies: DependentBuildableProjectNode[]; + + if (!buildLibsFromSource) { + const { tsConfigPath, dependencies: foundDependencies } = + createTmpTsConfigForBuildableLibs( + delegateExecutorOptions.tsConfig, + context + ); + dependencies = foundDependencies; + delegateExecutorOptions.tsConfig = tsConfigPath; + } + + const plugins = await loadPlugins(pluginPaths, options.tsConfig); + + const { buildApplication } = await import('@angular-devkit/build-angular'); + const builderContext = await createBuilderContext( + { + builderName: 'application', + description: 'Build an application.', + optionSchema: await import('./schema.json'), + }, + context + ); + + return yield* buildApplication( + delegateExecutorOptions, + builderContext, + plugins + ); +} diff --git a/packages/angular/src/executors/application/schema.d.ts b/packages/angular/src/executors/application/schema.d.ts new file mode 100644 index 0000000000000..604d5fe7fb991 --- /dev/null +++ b/packages/angular/src/executors/application/schema.d.ts @@ -0,0 +1,7 @@ +import type { ApplicationBuilderOptions } from '@angular-devkit/build-angular'; +import type { PluginSpec } from '../utilities/esbuild-extensions'; + +export interface ApplicationExecutorOptions extends ApplicationBuilderOptions { + buildLibsFromSource?: boolean; + plugins?: string[] | PluginSpec[]; +} diff --git a/packages/angular/src/executors/application/schema.json b/packages/angular/src/executors/application/schema.json new file mode 100644 index 0000000000000..89b5ff5a663f1 --- /dev/null +++ b/packages/angular/src/executors/application/schema.json @@ -0,0 +1,624 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "title": "Schema for Nx Application Executor", + "description": "Builds an application with esbuild with support for incremental builds.", + "examplesFile": "../../../docs/application-executor-examples.md", + "outputCapture": "direct-nodejs", + "type": "object", + "properties": { + "assets": { + "type": "array", + "description": "List of static application assets.", + "default": [], + "items": { + "$ref": "#/definitions/assetPattern" + } + }, + "browser": { + "type": "string", + "description": "The full path for the browser entry point to the application, relative to the current workspace." + }, + "server": { + "type": "string", + "description": "The full path for the server entry point to the application, relative to the current workspace." + }, + "polyfills": { + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", + "type": "array", + "items": { + "type": "string", + "uniqueItems": true + }, + "default": [] + }, + "tsConfig": { + "type": "string", + "description": "The full path for the TypeScript configuration file, relative to the current workspace." + }, + "scripts": { + "description": "Global scripts to be included in the build.", + "type": "array", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "input": { + "type": "string", + "description": "The file to include.", + "pattern": "\\.[cm]?jsx?$" + }, + "bundleName": { + "type": "string", + "pattern": "^[\\w\\-.]*$", + "description": "The bundle name for this extra entry point." + }, + "inject": { + "type": "boolean", + "description": "If the bundle will be referenced in the HTML file.", + "default": true + } + }, + "additionalProperties": false, + "required": ["input"] + }, + { + "type": "string", + "description": "The JavaScript/TypeScript file or package containing the file to include." + } + ] + } + }, + "styles": { + "description": "Global styles to be included in the build.", + "type": "array", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "input": { + "type": "string", + "description": "The file to include.", + "pattern": "\\.(?:css|scss|sass|less)$" + }, + "bundleName": { + "type": "string", + "pattern": "^[\\w\\-.]*$", + "description": "The bundle name for this extra entry point." + }, + "inject": { + "type": "boolean", + "description": "If the bundle will be referenced in the HTML file.", + "default": true + } + }, + "additionalProperties": false, + "required": ["input"] + }, + { + "type": "string", + "description": "The file to include.", + "pattern": "\\.(?:css|scss|sass|less)$" + } + ] + } + }, + "inlineStyleLanguage": { + "description": "The stylesheet language to use for the application's inline component styles.", + "type": "string", + "default": "css", + "enum": ["css", "less", "sass", "scss"] + }, + "stylePreprocessorOptions": { + "description": "Options to pass to style preprocessors.", + "type": "object", + "properties": { + "includePaths": { + "description": "Paths to include. Paths will be resolved to workspace root.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + } + }, + "additionalProperties": false + }, + "externalDependencies": { + "description": "Exclude the listed external dependencies from being bundled into the bundle. Instead, the created bundle relies on these dependencies to be available during runtime.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + }, + "optimization": { + "description": "Enables optimization of the build output. Including minification of scripts and styles, tree-shaking, dead-code elimination, inlining of critical CSS and fonts inlining. For more information, see https://angular.io/guide/workspace-config#optimization-configuration.", + "default": true, + "x-user-analytics": "ep.ng_optimization", + "oneOf": [ + { + "type": "object", + "properties": { + "scripts": { + "type": "boolean", + "description": "Enables optimization of the scripts output.", + "default": true + }, + "styles": { + "description": "Enables optimization of the styles output.", + "default": true, + "oneOf": [ + { + "type": "object", + "properties": { + "minify": { + "type": "boolean", + "description": "Minify CSS definitions by removing extraneous whitespace and comments, merging identifiers and minimizing values.", + "default": true + }, + "inlineCritical": { + "type": "boolean", + "description": "Extract and inline critical CSS definitions to improve first paint time.", + "default": true + }, + "removeSpecialComments": { + "type": "boolean", + "description": "Remove comments in global CSS that contains '@license' or '@preserve' or that starts with '//!' or '/*!'.", + "default": true + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + }, + "fonts": { + "description": "Enables optimization for fonts. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.", + "default": true, + "oneOf": [ + { + "type": "object", + "properties": { + "inline": { + "type": "boolean", + "description": "Reduce render blocking requests by inlining external Google Fonts and Adobe Fonts CSS definitions in the application's HTML index file. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.", + "default": true + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + }, + "loader": { + "description": "Defines the type of loader to use with a specified file extension when used with a JavaScript `import`. `text` inlines the content as a string; `binary` inlines the content as a Uint8Array; `file` emits the file and provides the runtime location of the file; `empty` considers the content to be empty and not include it in bundles.", + "type": "object", + "patternProperties": { + "^\\.\\S+$": { "enum": ["text", "binary", "file", "empty"] } + } + }, + "fileReplacements": { + "description": "Replace compilation source files with other compilation source files in the build.", + "type": "array", + "items": { + "$ref": "#/definitions/fileReplacement" + }, + "default": [] + }, + "outputPath": { + "type": "string", + "description": "The full path for the new output directory, relative to the current workspace." + }, + "aot": { + "type": "boolean", + "description": "Build using Ahead of Time compilation.", + "x-user-analytics": "ep.ng_aot", + "default": true + }, + "sourceMap": { + "description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.", + "default": false, + "oneOf": [ + { + "type": "object", + "properties": { + "scripts": { + "type": "boolean", + "description": "Output source maps for all scripts.", + "default": true + }, + "styles": { + "type": "boolean", + "description": "Output source maps for all styles.", + "default": true + }, + "hidden": { + "type": "boolean", + "description": "Output source maps used for error reporting tools.", + "default": false + }, + "vendor": { + "type": "boolean", + "description": "Resolve vendor packages source maps.", + "default": false + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + }, + "baseHref": { + "type": "string", + "description": "Base url for the application being built." + }, + "verbose": { + "type": "boolean", + "description": "Adds more details to output logging.", + "default": false + }, + "progress": { + "type": "boolean", + "description": "Log progress to the console while building.", + "default": true + }, + "i18nMissingTranslation": { + "type": "string", + "description": "How to handle missing translations for i18n.", + "enum": ["warning", "error", "ignore"], + "default": "warning" + }, + "i18nDuplicateTranslation": { + "type": "string", + "description": "How to handle duplicate translations for i18n.", + "enum": ["warning", "error", "ignore"], + "default": "warning" + }, + "localize": { + "description": "Translate the bundles in one or more locales.", + "oneOf": [ + { + "type": "boolean", + "description": "Translate all locales." + }, + { + "type": "array", + "description": "List of locales ID's to translate.", + "minItems": 1, + "items": { + "type": "string", + "pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$" + } + } + ] + }, + "watch": { + "type": "boolean", + "description": "Run build when files change.", + "default": false + }, + "outputHashing": { + "type": "string", + "description": "Define the output filename cache-busting hashing mode.", + "default": "none", + "enum": ["none", "all", "media", "bundles"] + }, + "poll": { + "type": "number", + "description": "Enable and define the file watching poll time period in milliseconds." + }, + "deleteOutputPath": { + "type": "boolean", + "description": "Delete the output path before building.", + "default": true + }, + "preserveSymlinks": { + "type": "boolean", + "description": "Do not use the real path when resolving modules. If unset then will default to `true` if NodeJS option --preserve-symlinks is set." + }, + "extractLicenses": { + "type": "boolean", + "description": "Extract all licenses in a separate file.", + "default": true + }, + "namedChunks": { + "type": "boolean", + "description": "Use file name for lazy loaded chunks.", + "default": false + }, + "subresourceIntegrity": { + "type": "boolean", + "description": "Enables the use of subresource integrity validation.", + "default": false + }, + "serviceWorker": { + "description": "Generates a service worker configuration.", + "default": false, + "oneOf": [ + { + "type": "string", + "description": "Path to ngsw-config.json." + }, + { + "const": false, + "type": "boolean", + "description": "Does not generate a service worker configuration." + } + ] + }, + "index": { + "description": "Configures the generation of the application's HTML index.", + "oneOf": [ + { + "type": "string", + "description": "The path of a file to use for the application's HTML index. The filename of the specified path will be used for the generated file and will be created in the root of the application's configured output path." + }, + { + "type": "object", + "description": "", + "properties": { + "input": { + "type": "string", + "minLength": 1, + "description": "The path of a file to use for the application's generated HTML index." + }, + "output": { + "type": "string", + "minLength": 1, + "default": "index.html", + "description": "The output path of the application's generated HTML index file. The full provided path will be used and will be considered relative to the application's configured output path." + } + }, + "required": ["input"] + }, + { + "const": false, + "type": "boolean", + "description": "Does not generate an `index.html` file." + } + ] + }, + "statsJson": { + "type": "boolean", + "description": "Generates a 'stats.json' file which can be analyzed with https://esbuild.github.io/analyze/.", + "default": false + }, + "budgets": { + "description": "Budget thresholds to ensure parts of your application stay within boundaries which you set.", + "type": "array", + "items": { + "$ref": "#/definitions/budget" + }, + "default": [] + }, + "webWorkerTsConfig": { + "type": "string", + "description": "TypeScript configuration for Web Worker modules." + }, + "crossOrigin": { + "type": "string", + "description": "Define the crossorigin attribute setting of elements that provide CORS support.", + "default": "none", + "enum": ["none", "anonymous", "use-credentials"] + }, + "allowedCommonJsDependencies": { + "description": "A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + }, + "prerender": { + "description": "Prerender (SSG) pages of your application during build time.", + "default": false, + "oneOf": [ + { + "type": "boolean", + "description": "Enable prerending of pages of your application during build time." + }, + { + "type": "object", + "properties": { + "routesFile": { + "type": "string", + "description": "The path to a file that contains a list of all routes to prerender, separated by newlines. This option is useful if you want to prerender routes with parameterized URLs." + }, + "discoverRoutes": { + "type": "boolean", + "description": "Whether the builder should process the Angular Router configuration to find all unparameterized routes and prerender them.", + "default": true + } + }, + "additionalProperties": false + } + ] + }, + "ssr": { + "description": "Server side render (SSR) pages of your application during runtime.", + "default": false, + "oneOf": [ + { + "type": "boolean", + "description": "Enable the server bundles to be written to disk." + }, + { + "type": "object", + "properties": { + "entry": { + "type": "string", + "description": "The server entry-point that when executed will spawn the web server." + } + }, + "additionalProperties": false + } + ] + }, + "appShell": { + "type": "boolean", + "description": "Generates an application shell during build time.", + "default": false + }, + "buildLibsFromSource": { + "type": "boolean", + "description": "Read buildable libraries from source instead of building them separately.", + "default": true + }, + "plugins": { + "description": "A list of ESBuild plugins.", + "type": "array", + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "path": { + "type": "string", + "description": "The path to the plugin. Relative to the workspace root." + }, + "options": { + "type": "object", + "description": "The options to provide to the plugin.", + "properties": {}, + "additionalProperties": true + } + }, + "additionalProperties": false, + "required": ["path"] + }, + { + "type": "string", + "description": "The path to the plugin. Relative to the workspace root." + } + ] + } + } + }, + "additionalProperties": false, + "required": ["outputPath", "index", "browser", "tsConfig"], + "definitions": { + "assetPattern": { + "oneOf": [ + { + "type": "object", + "properties": { + "followSymlinks": { + "type": "boolean", + "default": false, + "description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched." + }, + "glob": { + "type": "string", + "description": "The pattern to match." + }, + "input": { + "type": "string", + "description": "The input directory path in which to apply 'glob'. Defaults to the project root." + }, + "ignore": { + "description": "An array of globs to ignore.", + "type": "array", + "items": { + "type": "string" + } + }, + "output": { + "type": "string", + "description": "Absolute path within the output." + } + }, + "additionalProperties": false, + "required": ["glob", "input", "output"] + }, + { + "type": "string" + } + ] + }, + "fileReplacement": { + "type": "object", + "properties": { + "replace": { + "type": "string", + "pattern": "\\.(([cm]?j|t)sx?|json)$" + }, + "with": { + "type": "string", + "pattern": "\\.(([cm]?j|t)sx?|json)$" + } + }, + "additionalProperties": false, + "required": ["replace", "with"] + }, + "budget": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The type of budget.", + "enum": [ + "all", + "allScript", + "any", + "anyScript", + "anyComponentStyle", + "bundle", + "initial" + ] + }, + "name": { + "type": "string", + "description": "The name of the bundle." + }, + "baseline": { + "type": "string", + "description": "The baseline size for comparison." + }, + "maximumWarning": { + "type": "string", + "description": "The maximum threshold for warning relative to the baseline." + }, + "maximumError": { + "type": "string", + "description": "The maximum threshold for error relative to the baseline." + }, + "minimumWarning": { + "type": "string", + "description": "The minimum threshold for warning relative to the baseline." + }, + "minimumError": { + "type": "string", + "description": "The minimum threshold for error relative to the baseline." + }, + "warning": { + "type": "string", + "description": "The threshold for warning relative to the baseline (min & max)." + }, + "error": { + "type": "string", + "description": "The threshold for error relative to the baseline (min & max)." + } + }, + "additionalProperties": false, + "required": ["type"] + } + } +} diff --git a/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts b/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts index eda934c9cfd90..a2effb197bba1 100644 --- a/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts +++ b/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts @@ -1,10 +1,8 @@ -import type { BuilderOutput } from '@angular-devkit/architect'; -import { readCachedProjectGraph, type ExecutorContext } from '@nx/devkit'; +import type { ExecutorContext } from '@nx/devkit'; import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils'; -import type { OutputFile } from 'esbuild'; import { createBuilderContext } from 'nx/src/adapter/ngcli-adapter'; +import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; import { loadPlugins } from '../utilities/esbuild-extensions'; -import { createTmpTsConfigForBuildableLibs } from './lib/buildable-libs'; import type { EsBuildSchema } from './schema'; export default async function* esbuildExecutor( @@ -20,15 +18,12 @@ export default async function* esbuildExecutor( } = options; let dependencies: DependentBuildableProjectNode[]; - let projectGraph = context.projectGraph; if (!buildLibsFromSource) { - projectGraph = projectGraph ?? readCachedProjectGraph(); const { tsConfigPath, dependencies: foundDependencies } = createTmpTsConfigForBuildableLibs( delegateExecutorOptions.tsConfig, - context, - { projectGraph } + context ); dependencies = foundDependencies; delegateExecutorOptions.tsConfig = tsConfigPath; @@ -56,10 +51,5 @@ export default async function* esbuildExecutor( builderContext, /* infrastructureSettings */ undefined, plugins - ) as AsyncIterable< - BuilderOutput & { - outputFiles?: OutputFile[]; - assetFiles?: { source: string; destination: string }[]; - } - >; + ); } diff --git a/packages/angular/src/executors/browser-esbuild/schema.json b/packages/angular/src/executors/browser-esbuild/schema.json index b78ea136800fb..668b066f03a6f 100644 --- a/packages/angular/src/executors/browser-esbuild/schema.json +++ b/packages/angular/src/executors/browser-esbuild/schema.json @@ -2,6 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema", "title": "Schema for Nx ESBuild Executor", "description": "Nx ESBuild Executor supporting Incremental Builds.", + "examplesFile": "../../../docs/browser-esbuild-examples.md", "outputCapture": "direct-nodejs", "type": "object", "properties": { diff --git a/packages/angular/src/executors/browser-esbuild/lib/buildable-libs.ts b/packages/angular/src/executors/utilities/buildable-libs.ts similarity index 66% rename from packages/angular/src/executors/browser-esbuild/lib/buildable-libs.ts rename to packages/angular/src/executors/utilities/buildable-libs.ts index 235007869d26d..6655e36017ff0 100644 --- a/packages/angular/src/executors/browser-esbuild/lib/buildable-libs.ts +++ b/packages/angular/src/executors/utilities/buildable-libs.ts @@ -1,26 +1,21 @@ +import { readCachedProjectGraph, type ExecutorContext } from '@nx/devkit'; import { calculateProjectDependencies, createTmpTsConfig, - DependentBuildableProjectNode, + type DependentBuildableProjectNode, } from '@nx/js/src/utils/buildable-libs-utils'; import { join } from 'path'; -import { - type ExecutorContext, - type ProjectGraph, - readCachedProjectGraph, -} from '@nx/devkit'; export function createTmpTsConfigForBuildableLibs( tsConfigPath: string, - context: ExecutorContext, - options?: { projectGraph?: ProjectGraph; target?: string } + context: ExecutorContext ) { let dependencies: DependentBuildableProjectNode[]; const result = calculateProjectDependencies( - options?.projectGraph ?? readCachedProjectGraph(), + context.projectGraph ?? readCachedProjectGraph(), context.root, context.projectName, - options?.target ?? context.targetName, + context.targetName, context.configurationName ); dependencies = result.dependencies; @@ -32,7 +27,7 @@ export function createTmpTsConfigForBuildableLibs( dependencies ); process.env.NX_TSCONFIG_PATH = tmpTsConfigPath; - // Angular EsBuild Builder appends the workspaceRoot to the config path, so remove it. + const tmpTsConfigPathWithoutWorkspaceRoot = tmpTsConfigPath.replace( context.root, ''