@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
@@ -0,0 +1,13 @@
1
+ export interface EsBuildProjectSchema {
2
+ project: string;
3
+ main?: string;
4
+ tsConfig?: string;
5
+ devServer?: boolean;
6
+ skipFormat?: boolean;
7
+ skipPackageJson?: boolean;
8
+ skipValidation?: boolean;
9
+ importPath?: string;
10
+ esbuildConfig?: string;
11
+ platform?: 'node' | 'browser' | 'neutral';
12
+ buildTarget?: string;
13
+ }
@@ -0,0 +1,67 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxEsBuildProject",
4
+ "cli": "nx",
5
+ "title": "Add esbuild configuration to a project",
6
+ "description": "Add esbuild configuration to a project.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "description": "The name of the project.",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-dropdown": "project",
17
+ "x-prompt": "What is the name of the project to set up a esbuild for?",
18
+ "x-priority": "important"
19
+ },
20
+ "main": {
21
+ "type": "string",
22
+ "description": "Path relative to the workspace root for the main entry file. Defaults to `<project-root>/src/main.ts` or `<project-root>src/index.ts`, whichever is found.",
23
+ "alias": "entryFile",
24
+ "x-priority": "important"
25
+ },
26
+ "tsConfig": {
27
+ "type": "string",
28
+ "description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to `<project-root>/tsconfig.app.json` or `<project-root>/tsconfig.lib.json`, whichever is found.",
29
+ "x-priority": "important"
30
+ },
31
+ "skipFormat": {
32
+ "description": "Skip formatting files.",
33
+ "type": "boolean",
34
+ "default": false,
35
+ "x-priority": "internal"
36
+ },
37
+ "skipPackageJson": {
38
+ "type": "boolean",
39
+ "default": false,
40
+ "description": "Do not add dependencies to `package.json`.",
41
+ "x-priority": "internal"
42
+ },
43
+ "skipValidation": {
44
+ "type": "boolean",
45
+ "default": false,
46
+ "description": "Do not perform any validation on existing project.",
47
+ "x-priority": "internal"
48
+ },
49
+ "importPath": {
50
+ "type": "string",
51
+ "description": "The library name used to import it, like `@myorg/my-awesome-lib`."
52
+ },
53
+ "platform": {
54
+ "type": "string",
55
+ "description": "Platform target for outputs.",
56
+ "enum": ["browser", "node", "neutral"],
57
+ "default": "node"
58
+ },
59
+ "buildTarget": {
60
+ "description": "The build target to add.",
61
+ "type": "string",
62
+ "default": "build"
63
+ }
64
+ },
65
+ "required": [],
66
+ "examplesFile": "../../../docs/configuration-examples.md"
67
+ }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function esbuildInitGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export default esbuildInitGenerator;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.esbuildInitGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("@nx/js/src/utils/versions");
6
+ const versions_2 = require("../../utils/versions");
7
+ async function esbuildInitGenerator(tree, schema) {
8
+ let installTask = () => { };
9
+ if (!schema.skipPackageJson) {
10
+ installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
11
+ '@nx/esbuild': versions_2.nxVersion,
12
+ esbuild: versions_1.esbuildVersion,
13
+ }, undefined, schema.keepExistingVersions);
14
+ }
15
+ if (!schema.skipFormat) {
16
+ await (0, devkit_1.formatFiles)(tree);
17
+ }
18
+ return installTask;
19
+ }
20
+ exports.esbuildInitGenerator = esbuildInitGenerator;
21
+ exports.default = esbuildInitGenerator;
@@ -0,0 +1,5 @@
1
+ export interface Schema {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxEsbuildInit",
4
+ "cli": "nx",
5
+ "title": "Init Esbuild Plugin",
6
+ "description": "Init Esbuild Plugin.",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false
18
+ },
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ }
25
+ },
26
+ "required": []
27
+ }
@@ -0,0 +1,2 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ async function update(tree) {
5
+ const projects = (0, devkit_1.getProjects)(tree);
6
+ projects.forEach((projectConfig, projectName) => {
7
+ let shouldUpdate = false;
8
+ Object.entries(projectConfig.targets).forEach(([targetName, targetConfig]) => {
9
+ if (targetConfig.executor === '@nrwl/esbuild:esbuild') {
10
+ shouldUpdate = true;
11
+ projectConfig.targets[targetName].options ??= {};
12
+ projectConfig.targets[targetName].options.generatePackageJson ??=
13
+ true;
14
+ }
15
+ });
16
+ if (shouldUpdate) {
17
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
18
+ }
19
+ });
20
+ await (0, devkit_1.formatFiles)(tree);
21
+ }
22
+ exports.default = update;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function replacePackage(tree: Tree): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/esbuild', '@nx/esbuild');
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ }
9
+ exports.default = replacePackage;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(host: Tree): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-unused-vars */
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function update(host) {
6
+ const projects = (0, devkit_1.getProjects)(host);
7
+ projects.forEach((projectConfig, projectName) => {
8
+ if (!projectConfig.targets)
9
+ return;
10
+ let shouldUpdate = false;
11
+ Object.entries(projectConfig.targets).forEach(([targetName, targetConfig]) => {
12
+ if (targetConfig.executor === '@nrwl/esbuild:esbuild' ||
13
+ targetConfig.executor === '@nx/esbuild:esbuild') {
14
+ projectConfig.targets[targetName].options ??= {};
15
+ if (projectConfig.targets[targetName].options.bundle !== false) {
16
+ shouldUpdate = true;
17
+ projectConfig.targets[targetName].options.thirdParty ??= true;
18
+ }
19
+ }
20
+ });
21
+ if (shouldUpdate) {
22
+ (0, devkit_1.updateProjectConfiguration)(host, projectName, projectConfig);
23
+ }
24
+ });
25
+ await (0, devkit_1.formatFiles)(host);
26
+ }
27
+ exports.default = update;
@@ -0,0 +1 @@
1
+ export declare function getClientEnvironment(): Record<string, string>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getClientEnvironment = void 0;
4
+ function getClientEnvironment() {
5
+ const NX_APP = /^NX_/i;
6
+ return Object.keys(process.env)
7
+ .filter((key) => NX_APP.test(key) || key === 'NODE_ENV')
8
+ .reduce((env, key) => {
9
+ env[`process.env.${key}`] = JSON.stringify(process.env[key]);
10
+ return env;
11
+ }, {});
12
+ }
13
+ exports.getClientEnvironment = getClientEnvironment;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Delete an output directory, but error out if it's the root of the project.
3
+ */
4
+ export declare function deleteOutputDir(root: string, outputPath: string): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteOutputDir = void 0;
4
+ const path = require("path");
5
+ const fs_extra_1 = require("fs-extra");
6
+ /**
7
+ * Delete an output directory, but error out if it's the root of the project.
8
+ */
9
+ function deleteOutputDir(root, outputPath) {
10
+ const resolvedOutputPath = path.resolve(root, outputPath);
11
+ if (resolvedOutputPath === root) {
12
+ throw new Error('Output path MUST not be project root directory!');
13
+ }
14
+ (0, fs_extra_1.removeSync)(resolvedOutputPath);
15
+ }
16
+ exports.deleteOutputDir = deleteOutputDir;
@@ -0,0 +1,8 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ export interface GetEntryPointsOptions {
3
+ recursive?: boolean;
4
+ initialEntryPoints?: string[];
5
+ initialTsConfigFileName?: string;
6
+ onProjectFilesMatched?: (projectName: string, files: string[]) => void;
7
+ }
8
+ export declare function getEntryPoints(projectName: string, context: ExecutorContext, options?: GetEntryPointsOptions): string[];
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntryPoints = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const glob = require("fast-glob");
8
+ function getEntryPoints(projectName, context, options = {}) {
9
+ const entryPoints = options.initialEntryPoints
10
+ ? new Set(options.initialEntryPoints)
11
+ : new Set();
12
+ const seenProjects = new Set();
13
+ const findEntryPoints = (projectName, tsConfigFileName) => {
14
+ if (seenProjects.has(projectName))
15
+ return;
16
+ seenProjects.add(projectName);
17
+ const project = context.projectGraph?.nodes[projectName];
18
+ if (!project)
19
+ return;
20
+ // Known files we generate from our generators. Only one of these should be used to build the project.
21
+ const tsconfigCandidates = [
22
+ 'tsconfig.app.json',
23
+ 'tsconfig.lib.json',
24
+ 'tsconfig.json',
25
+ ];
26
+ if (tsConfigFileName)
27
+ tsconfigCandidates.unshift(tsConfigFileName);
28
+ const foundTsConfig = tsconfigCandidates.find((f) => {
29
+ try {
30
+ return fs.statSync(path.join(project.data.root, f)).isFile();
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ });
36
+ // Workspace projects may not be a TS project, so skip reading source files if tsconfig is not found.
37
+ if (foundTsConfig) {
38
+ const tsconfig = (0, devkit_1.readJsonFile)(path.join(project.data.root, foundTsConfig));
39
+ const projectFiles = glob
40
+ .sync(tsconfig.include ?? [], {
41
+ cwd: project.data.root,
42
+ ignore: tsconfig.exclude ?? [],
43
+ })
44
+ .map((f) => path.join(project.data.root, f));
45
+ projectFiles.forEach((f) => entryPoints.add(f));
46
+ options?.onProjectFilesMatched?.(projectName, projectFiles);
47
+ }
48
+ if (options.recursive) {
49
+ const deps = context.projectGraph.dependencies[projectName];
50
+ deps.forEach((dep) => {
51
+ if (context.projectGraph.nodes[dep.target]) {
52
+ findEntryPoints(dep.target);
53
+ }
54
+ });
55
+ }
56
+ };
57
+ findEntryPoints(projectName, options.initialTsConfigFileName);
58
+ return Array.from(entryPoints);
59
+ }
60
+ exports.getEntryPoints = getEntryPoints;
@@ -0,0 +1,2 @@
1
+ export declare const nxVersion: any;
2
+ export declare const tsLibVersion = "^2.3.0";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsLibVersion = exports.nxVersion = void 0;
4
+ exports.nxVersion = require('../../package.json').version;
5
+ exports.tsLibVersion = '^2.3.0';