@nx/esbuild 21.0.0-canary.20250206-8bd0bcd → 21.0.0-canary.20250418-8619c1d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/esbuild",
|
3
|
-
"version": "21.0.0-canary.
|
3
|
+
"version": "21.0.0-canary.20250418-8619c1d",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for esbuild contains executors and generators that support building applications using esbuild",
|
6
6
|
"repository": {
|
@@ -31,15 +31,15 @@
|
|
31
31
|
"migrations": "./migrations.json"
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"@nx/devkit": "21.0.0-canary.
|
35
|
-
"@nx/js": "21.0.0-canary.
|
36
|
-
"tinyglobby": "^0.2.
|
34
|
+
"@nx/devkit": "21.0.0-canary.20250418-8619c1d",
|
35
|
+
"@nx/js": "21.0.0-canary.20250418-8619c1d",
|
36
|
+
"tinyglobby": "^0.2.12",
|
37
37
|
"picocolors": "^1.1.0",
|
38
38
|
"tsconfig-paths": "^4.1.2",
|
39
39
|
"tslib": "^2.3.0"
|
40
40
|
},
|
41
41
|
"peerDependencies": {
|
42
|
-
"esbuild": "
|
42
|
+
"esbuild": "^0.19.2"
|
43
43
|
},
|
44
44
|
"peerDependenciesMeta": {
|
45
45
|
"esbuild": {
|
@@ -2,6 +2,12 @@ import * as esbuild from 'esbuild';
|
|
2
2
|
import { ExecutorContext, ProjectGraphProjectNode } from '@nx/devkit';
|
3
3
|
import { NormalizedEsBuildExecutorOptions } from '../schema';
|
4
4
|
export declare function buildEsbuildOptions(format: 'cjs' | 'esm', options: NormalizedEsBuildExecutorOptions, context: ExecutorContext): esbuild.BuildOptions;
|
5
|
+
/**
|
6
|
+
* When using TS project references we need to map the paths to the referenced projects.
|
7
|
+
* This is necessary because esbuild does not support project references out of the box.
|
8
|
+
* @param context ExecutorContext
|
9
|
+
*/
|
10
|
+
export declare function createPathsFromTsConfigReferences(context: ExecutorContext): Record<string, string[]>;
|
5
11
|
export declare function getOutExtension(format: 'cjs' | 'esm', options: Pick<NormalizedEsBuildExecutorOptions, 'userDefinedBuildOptions'>): '.cjs' | '.mjs' | '.js';
|
6
12
|
export declare function getOutfile(format: 'cjs' | 'esm', options: NormalizedEsBuildExecutorOptions, context: ExecutorContext): string;
|
7
13
|
export declare function getRegisterFileContent(project: ProjectGraphProjectNode, paths: Record<string, string[]>, mainFile: string, outExtension?: string): string;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.buildEsbuildOptions = buildEsbuildOptions;
|
4
|
+
exports.createPathsFromTsConfigReferences = createPathsFromTsConfigReferences;
|
4
5
|
exports.getOutExtension = getOutExtension;
|
5
6
|
exports.getOutfile = getOutfile;
|
6
7
|
exports.getRegisterFileContent = getRegisterFileContent;
|
@@ -60,7 +61,9 @@ function buildEsbuildOptions(format, options, context) {
|
|
60
61
|
else if (options.platform === 'node' && format === 'cjs') {
|
61
62
|
// When target platform Node and target format is CJS, then also transpile workspace libs used by the app.
|
62
63
|
// Provide a `require` override in the main entry file so workspace libs can be loaded when running the app.
|
63
|
-
const paths =
|
64
|
+
const paths = options.isTsSolutionSetup
|
65
|
+
? createPathsFromTsConfigReferences(context)
|
66
|
+
: getTsConfigCompilerPaths(context);
|
64
67
|
const entryPointsFromProjects = (0, get_entry_points_1.getEntryPoints)(context.projectName, context, {
|
65
68
|
initialTsConfigFileName: options.tsConfig,
|
66
69
|
initialEntryPoints: entryPoints,
|
@@ -103,6 +106,87 @@ function buildEsbuildOptions(format, options, context) {
|
|
103
106
|
}
|
104
107
|
return esbuildOptions;
|
105
108
|
}
|
109
|
+
/**
|
110
|
+
* When using TS project references we need to map the paths to the referenced projects.
|
111
|
+
* This is necessary because esbuild does not support project references out of the box.
|
112
|
+
* @param context ExecutorContext
|
113
|
+
*/
|
114
|
+
function createPathsFromTsConfigReferences(context) {
|
115
|
+
const { findAllProjectNodeDependencies, } = require('nx/src/utils/project-graph-utils');
|
116
|
+
const { isValidPackageJsonBuildConfig, } = require('@nx/js/src/plugins/typescript/util');
|
117
|
+
const { readTsConfig } = require('@nx/js');
|
118
|
+
const { findRuntimeTsConfigName, } = require('@nx/js/src/utils/typescript/ts-solution-setup');
|
119
|
+
const deps = findAllProjectNodeDependencies(context.projectName, context.projectGraph);
|
120
|
+
const tsConfig = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(context.root, 'tsconfig.json'));
|
121
|
+
const referencesAsPaths = new Set(tsConfig.references.reduce((acc, ref) => {
|
122
|
+
if (!ref.path)
|
123
|
+
return acc;
|
124
|
+
const fullPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, ref.path);
|
125
|
+
try {
|
126
|
+
if ((0, fs_1.lstatSync)(fullPath).isDirectory()) {
|
127
|
+
acc.push(fullPath);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
catch {
|
131
|
+
// Ignore errors (e.g., path doesn't exist)
|
132
|
+
}
|
133
|
+
return acc;
|
134
|
+
}, []));
|
135
|
+
// for each dep we check if it contains a build target
|
136
|
+
// we only want to add the paths for projects that do not have a build target
|
137
|
+
return deps.reduce((acc, dep) => {
|
138
|
+
const projectNode = context.projectGraph.nodes[dep];
|
139
|
+
const projectPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectNode.data.root);
|
140
|
+
const resolvedTsConfigPath = findRuntimeTsConfigName(projectPath) ?? 'tsconfig.json';
|
141
|
+
const projTsConfig = readTsConfig(resolvedTsConfigPath);
|
142
|
+
const projectPkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(projectPath, 'package.json'));
|
143
|
+
if (projTsConfig &&
|
144
|
+
!isValidPackageJsonBuildConfig(projTsConfig, devkit_1.workspaceRoot, projectPath) &&
|
145
|
+
projectPkgJson?.name) {
|
146
|
+
const entryPoint = getProjectEntryPoint(projectPkgJson, projectPath);
|
147
|
+
if (referencesAsPaths.has(projectPath)) {
|
148
|
+
acc[projectPkgJson.name] = [path.relative(devkit_1.workspaceRoot, entryPoint)];
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return acc;
|
152
|
+
}, {});
|
153
|
+
}
|
154
|
+
// Get the entry point for the project
|
155
|
+
function getProjectEntryPoint(projectPkgJson, projectPath) {
|
156
|
+
let entryPoint = null;
|
157
|
+
if (typeof projectPkgJson.exports === 'string') {
|
158
|
+
// If exports is a string, use it as the entry point
|
159
|
+
entryPoint = path.relative(devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(projectPath, projectPkgJson.exports));
|
160
|
+
}
|
161
|
+
else if (typeof projectPkgJson.exports === 'object' &&
|
162
|
+
projectPkgJson.exports['.']) {
|
163
|
+
// If exports is an object and has a '.' key, process it
|
164
|
+
const exportEntry = projectPkgJson.exports['.'];
|
165
|
+
if (typeof exportEntry === 'object') {
|
166
|
+
entryPoint =
|
167
|
+
exportEntry.import ||
|
168
|
+
exportEntry.require ||
|
169
|
+
exportEntry.default ||
|
170
|
+
null;
|
171
|
+
}
|
172
|
+
else if (typeof exportEntry === 'string') {
|
173
|
+
entryPoint = exportEntry;
|
174
|
+
}
|
175
|
+
if (entryPoint) {
|
176
|
+
entryPoint = path.relative(devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(projectPath, entryPoint));
|
177
|
+
}
|
178
|
+
}
|
179
|
+
// If no exports were found, fall back to main and module
|
180
|
+
if (!entryPoint) {
|
181
|
+
if (projectPkgJson.main) {
|
182
|
+
entryPoint = path.relative(devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(projectPath, projectPkgJson.main));
|
183
|
+
}
|
184
|
+
else if (projectPkgJson.module) {
|
185
|
+
entryPoint = path.relative(devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(projectPath, projectPkgJson.module));
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return entryPoint;
|
189
|
+
}
|
106
190
|
function getOutExtension(format, options) {
|
107
191
|
const userDefinedExt = options.userDefinedBuildOptions?.outExtension?.['.js'];
|
108
192
|
// Allow users to change the output extensions from default CJS and ESM extensions.
|
@@ -51,10 +51,7 @@ function addBuildTarget(tree, options, isTsSolutionSetup) {
|
|
51
51
|
format: options.format,
|
52
52
|
};
|
53
53
|
if (isTsSolutionSetup) {
|
54
|
-
buildOptions.declarationRootDir =
|
55
|
-
project.sourceRoot ?? tree.exists(`${project.root}/src`)
|
56
|
-
? `${project.root}/src`
|
57
|
-
: project.root;
|
54
|
+
buildOptions.declarationRootDir = (0, ts_solution_setup_1.getProjectSourceRoot)(tree, project.sourceRoot, project.root);
|
58
55
|
}
|
59
56
|
else {
|
60
57
|
buildOptions.assets = [];
|
@@ -116,6 +113,8 @@ function updatePackageJson(tree, options, isTsSolutionSetup) {
|
|
116
113
|
const { declarationRootDir = '.', main, outputPath, outputFileName,
|
117
114
|
// the executor option defaults to [esm]
|
118
115
|
format = ['esm'], esbuildOptions, } = mergedTarget.options;
|
116
|
+
// the file must exist in the TS solution setup
|
117
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
119
118
|
// can't use the declarationRootDir as rootDir because it only affects the typings,
|
120
119
|
// not the runtime entry point
|
121
120
|
packageJson = (0, js_1.getUpdatedPackageJsonContent)(packageJson, {
|
@@ -135,6 +134,7 @@ function updatePackageJson(tree, options, isTsSolutionSetup) {
|
|
135
134
|
outputFileExtensionForEsm: (0, build_esbuild_options_1.getOutExtension)('esm', {
|
136
135
|
userDefinedBuildOptions: esbuildOptions,
|
137
136
|
}),
|
137
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
138
138
|
});
|
139
139
|
if (declarationRootDir !== (0, posix_1.dirname)(main)) {
|
140
140
|
// the declaration file entry point will be output to a location
|