@nx/esbuild 21.4.0-canary.20250809-014e775 → 21.4.0-canary.20250812-d2a0593
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 +4 -4
- package/src/executors/esbuild/esbuild.impl.d.ts.map +1 -1
- package/src/executors/esbuild/esbuild.impl.js +3 -1
- package/src/executors/esbuild/lib/build-esbuild-options.d.ts +2 -2
- package/src/executors/esbuild/lib/build-esbuild-options.d.ts.map +1 -1
- package/src/executors/esbuild/lib/build-esbuild-options.js +68 -11
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/esbuild",
|
3
|
-
"version": "21.4.0-canary.
|
3
|
+
"version": "21.4.0-canary.20250812-d2a0593",
|
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.4.0-canary.
|
35
|
-
"@nx/js": "21.4.0-canary.
|
34
|
+
"@nx/devkit": "21.4.0-canary.20250812-d2a0593",
|
35
|
+
"@nx/js": "21.4.0-canary.20250812-d2a0593",
|
36
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
|
"devDependencies": {
|
42
|
-
"nx": "21.4.0-canary.
|
42
|
+
"nx": "21.4.0-canary.20250812-d2a0593"
|
43
43
|
},
|
44
44
|
"peerDependencies": {
|
45
45
|
"esbuild": ">=0.19.2 <1.0.0"
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"esbuild.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/esbuild/src/executors/esbuild/esbuild.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmBlD,OAAO,EACL,sBAAsB,EAEvB,MAAM,UAAU,CAAC;AAwBlB,wBAAuB,eAAe,CACpC,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,eAAe;
|
1
|
+
{"version":3,"file":"esbuild.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/esbuild/src/executors/esbuild/esbuild.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmBlD,OAAO,EACL,sBAAsB,EAEvB,MAAM,UAAU,CAAC;AAwBlB,wBAAuB,eAAe,CACpC,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,eAAe;aAqEuB,OAAO;cAAY,MAAM;aA6GzE;AAkED,eAAe,eAAe,CAAC"}
|
@@ -45,10 +45,12 @@ async function* esbuildExecutor(_options, context) {
|
|
45
45
|
}
|
46
46
|
const cpjOptions = {
|
47
47
|
...options,
|
48
|
+
format: options.format,
|
48
49
|
// TODO(jack): make types generate with esbuild
|
49
50
|
skipTypings: true,
|
50
51
|
generateLockfile: true,
|
51
|
-
outputFileExtensionForCjs: (0, build_esbuild_options_1.getOutExtension)('cjs', options),
|
52
|
+
outputFileExtensionForCjs: (0, build_esbuild_options_1.getOutExtension)('cjs', options, context),
|
53
|
+
outputFileExtensionForEsm: (0, build_esbuild_options_1.getOutExtension)('esm', options, context),
|
52
54
|
excludeLibsInPackageJson: !options.thirdParty,
|
53
55
|
// TODO(jack): Remove the need to pass updateBuildableProjectDepsInPackageJson option when overrideDependencies or extraDependencies are passed.
|
54
56
|
// Add this back to fix a regression.
|
@@ -8,7 +8,7 @@ export declare function buildEsbuildOptions(format: 'cjs' | 'esm', options: Norm
|
|
8
8
|
* @param context ExecutorContext
|
9
9
|
*/
|
10
10
|
export declare function createPathsFromTsConfigReferences(context: ExecutorContext): Record<string, string[]>;
|
11
|
-
export declare function getOutExtension(format: 'cjs' | 'esm', options: Pick<NormalizedEsBuildExecutorOptions, 'userDefinedBuildOptions'
|
11
|
+
export declare function getOutExtension(format: 'cjs' | 'esm', options: Pick<NormalizedEsBuildExecutorOptions, 'userDefinedBuildOptions'>, context?: ExecutorContext): '.cjs' | '.mjs' | '.js';
|
12
12
|
export declare function getOutfile(format: 'cjs' | 'esm', options: NormalizedEsBuildExecutorOptions, context: ExecutorContext): string;
|
13
|
-
export declare function getRegisterFileContent(project: ProjectGraphProjectNode, paths: Record<string, string[]>, mainFile: string, outExtension?: string): string;
|
13
|
+
export declare function getRegisterFileContent(project: ProjectGraphProjectNode, paths: Record<string, string[]>, mainFile: string, outExtension?: string, format?: 'cjs' | 'esm'): string;
|
14
14
|
//# sourceMappingURL=build-esbuild-options.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"build-esbuild-options.d.ts","sourceRoot":"","sources":["../../../../../../../packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EACL,eAAe,EAGf,uBAAuB,EAGxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gCAAgC,EAAE,MAAM,WAAW,CAAC;AAO7D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,KAAK,GAAG,KAAK,EACrB,OAAO,EAAE,gCAAgC,EACzC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,
|
1
|
+
{"version":3,"file":"build-esbuild-options.d.ts","sourceRoot":"","sources":["../../../../../../../packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EACL,eAAe,EAGf,uBAAuB,EAGxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gCAAgC,EAAE,MAAM,WAAW,CAAC;AAO7D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,KAAK,GAAG,KAAK,EACrB,OAAO,EAAE,gCAAgC,EACzC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CA6GtB;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,eAAe,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAmE1B;AAoDD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,KAAK,GAAG,KAAK,EACrB,OAAO,EAAE,IAAI,CAAC,gCAAgC,EAAE,yBAAyB,CAAC,EAC1E,OAAO,CAAC,EAAE,eAAe,GACxB,MAAM,GAAG,MAAM,GAAG,KAAK,CAazB;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,KAAK,GAAG,KAAK,EACrB,OAAO,EAAE,gCAAgC,EACzC,OAAO,EAAE,eAAe,UASzB;AAkDD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAC/B,QAAQ,EAAE,MAAM,EAChB,YAAY,SAAQ,EACpB,MAAM,GAAE,KAAK,GAAG,KAAa,UAyI9B"}
|
@@ -14,7 +14,7 @@ const path_1 = require("path");
|
|
14
14
|
const ESM_FILE_EXTENSION = '.js';
|
15
15
|
const CJS_FILE_EXTENSION = '.cjs';
|
16
16
|
function buildEsbuildOptions(format, options, context) {
|
17
|
-
const outExtension = getOutExtension(format, options);
|
17
|
+
const outExtension = getOutExtension(format, options, context);
|
18
18
|
const esbuildOptions = {
|
19
19
|
...options.userDefinedBuildOptions,
|
20
20
|
entryNames: options.outputHashing === 'all' ? '[dir]/[name].[hash]' : '[dir]/[name]',
|
@@ -60,7 +60,7 @@ function buildEsbuildOptions(format, options, context) {
|
|
60
60
|
}
|
61
61
|
else if (options.platform === 'node' && format === 'cjs') {
|
62
62
|
// When target platform Node and target format is CJS, then also transpile workspace libs used by the app.
|
63
|
-
// Provide a
|
63
|
+
// Provide a loader override in the main entry file so workspace libs can be loaded when running the app.
|
64
64
|
const paths = options.isTsSolutionSetup
|
65
65
|
? createPathsFromTsConfigReferences(context)
|
66
66
|
: getTsConfigCompilerPaths(context);
|
@@ -71,7 +71,7 @@ function buildEsbuildOptions(format, options, context) {
|
|
71
71
|
});
|
72
72
|
esbuildOptions.entryPoints = [
|
73
73
|
// Write a main entry file that registers workspace libs and then calls the user-defined main.
|
74
|
-
writeTmpEntryWithRequireOverrides(paths, outExtension, options, context),
|
74
|
+
writeTmpEntryWithRequireOverrides(paths, outExtension, options, context, format),
|
75
75
|
...entryPointsFromProjects.map((f) => {
|
76
76
|
/**
|
77
77
|
* Maintain same directory structure as the workspace, so that other workspace libs may be used by the project.
|
@@ -187,7 +187,7 @@ function getProjectEntryPoint(projectPkgJson, projectPath) {
|
|
187
187
|
}
|
188
188
|
return entryPoint;
|
189
189
|
}
|
190
|
-
function getOutExtension(format, options) {
|
190
|
+
function getOutExtension(format, options, context) {
|
191
191
|
const userDefinedExt = options.userDefinedBuildOptions?.outExtension?.['.js'];
|
192
192
|
// Allow users to change the output extensions from default CJS and ESM extensions.
|
193
193
|
// CJS -> .js
|
@@ -201,12 +201,12 @@ function getOutExtension(format, options) {
|
|
201
201
|
: CJS_FILE_EXTENSION;
|
202
202
|
}
|
203
203
|
function getOutfile(format, options, context) {
|
204
|
-
const ext = getOutExtension(format, options);
|
204
|
+
const ext = getOutExtension(format, options, context);
|
205
205
|
const candidate = (0, devkit_1.joinPathFragments)(context.target.options.outputPath, options.outputFileName);
|
206
206
|
const { dir, name } = path.parse(candidate);
|
207
207
|
return `${dir}/${name}${ext}`;
|
208
208
|
}
|
209
|
-
function writeTmpEntryWithRequireOverrides(paths, outExtension, options, context) {
|
209
|
+
function writeTmpEntryWithRequireOverrides(paths, outExtension, options, context, format = 'cjs') {
|
210
210
|
const project = context.projectGraph?.nodes[context.projectName];
|
211
211
|
// Write a temp main entry source that registers workspace libs.
|
212
212
|
const tmpPath = path.join(context.root, 'tmp', project.name);
|
@@ -214,7 +214,7 @@ function writeTmpEntryWithRequireOverrides(paths, outExtension, options, context
|
|
214
214
|
const { name: mainFileName, dir: mainPathRelativeToDist } = path.parse(options.main);
|
215
215
|
const mainWithRequireOverridesInPath = path.join(tmpPath, `main-with-require-overrides.js`);
|
216
216
|
const mainFile = `./${path.join(mainPathRelativeToDist, `${mainFileName}${outExtension}`)}`;
|
217
|
-
(0, fs_1.writeFileSync)(mainWithRequireOverridesInPath, getRegisterFileContent(project, paths, mainFile, outExtension));
|
217
|
+
(0, fs_1.writeFileSync)(mainWithRequireOverridesInPath, getRegisterFileContent(project, paths, mainFile, outExtension, format));
|
218
218
|
let mainWithRequireOverridesOutPath;
|
219
219
|
if (options.outputFileName) {
|
220
220
|
mainWithRequireOverridesOutPath = path.parse(options.outputFileName).name;
|
@@ -232,7 +232,7 @@ function writeTmpEntryWithRequireOverrides(paths, outExtension, options, context
|
|
232
232
|
out: mainWithRequireOverridesOutPath,
|
233
233
|
};
|
234
234
|
}
|
235
|
-
function getRegisterFileContent(project, paths, mainFile, outExtension = '.js') {
|
235
|
+
function getRegisterFileContent(project, paths, mainFile, outExtension = '.js', format = 'cjs') {
|
236
236
|
mainFile = (0, devkit_1.normalizePath)(mainFile);
|
237
237
|
// Sort by longest prefix so imports match the most specific path.
|
238
238
|
const sortedKeys = Object.keys(paths).sort((a, b) => getPrefixLength(b) - getPrefixLength(a));
|
@@ -250,7 +250,59 @@ function getRegisterFileContent(project, paths, mainFile, outExtension = '.js')
|
|
250
250
|
acc.push({ module: k, exactMatch, pattern });
|
251
251
|
return acc;
|
252
252
|
}, []);
|
253
|
-
|
253
|
+
if (format === 'esm') {
|
254
|
+
return `
|
255
|
+
/**
|
256
|
+
* IMPORTANT: Do not modify this file.
|
257
|
+
* This file allows the app to run without bundling in workspace libraries.
|
258
|
+
* Must be contained in the ".nx" folder inside the output path.
|
259
|
+
*/
|
260
|
+
import { pathToFileURL } from 'node:url';
|
261
|
+
import { dirname, join } from 'node:path';
|
262
|
+
import { fileURLToPath } from 'node:url';
|
263
|
+
import { existsSync } from 'node:fs';
|
264
|
+
|
265
|
+
const __filename = fileURLToPath(import.meta.url);
|
266
|
+
const __dirname = dirname(__filename);
|
267
|
+
const distPath = __dirname;
|
268
|
+
const manifest = ${JSON.stringify(manifest)};
|
269
|
+
|
270
|
+
// Resolver for workspace libs
|
271
|
+
const originalResolve = import.meta.resolve;
|
272
|
+
if (originalResolve) {
|
273
|
+
import.meta.resolve = function(specifier, parent) {
|
274
|
+
const matchingEntry = manifest.find(
|
275
|
+
(entry) => specifier === entry.module || specifier.startsWith(entry.module + '/')
|
276
|
+
);
|
277
|
+
|
278
|
+
if (matchingEntry) {
|
279
|
+
if (matchingEntry.exactMatch) {
|
280
|
+
const candidate = join(distPath, matchingEntry.exactMatch);
|
281
|
+
if (existsSync(candidate)) {
|
282
|
+
return pathToFileURL(candidate).href;
|
283
|
+
}
|
284
|
+
} else {
|
285
|
+
const re = new RegExp(matchingEntry.module.replace(/\\*$/, "(?<rest>.*)"));
|
286
|
+
const match = specifier.match(re);
|
287
|
+
if (match?.groups) {
|
288
|
+
const candidate = join(distPath, matchingEntry.pattern.replace("*", ""), match.groups.rest);
|
289
|
+
if (existsSync(candidate)) {
|
290
|
+
return pathToFileURL(candidate).href;
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
return originalResolve.call(this, specifier, parent);
|
297
|
+
};
|
298
|
+
}
|
299
|
+
|
300
|
+
// Call the user-defined main.
|
301
|
+
await import(pathToFileURL(join(distPath, '${mainFile}')).href);
|
302
|
+
`;
|
303
|
+
}
|
304
|
+
else {
|
305
|
+
return `
|
254
306
|
/**
|
255
307
|
* IMPORTANT: Do not modify this file.
|
256
308
|
* This file allows the app to run without bundling in workspace libraries.
|
@@ -306,6 +358,7 @@ function isFile(s) {
|
|
306
358
|
// Call the user-defined main.
|
307
359
|
module.exports = require('${mainFile}');
|
308
360
|
`;
|
361
|
+
}
|
309
362
|
}
|
310
363
|
function getPrefixLength(pattern) {
|
311
364
|
const prefixIfWildcard = pattern.substring(0, pattern.indexOf('*')).length;
|
@@ -317,8 +370,12 @@ function getPrefixLength(pattern) {
|
|
317
370
|
return prefixIfWildcard || prefixWithoutWildcard;
|
318
371
|
}
|
319
372
|
function getTsConfigCompilerPaths(context) {
|
373
|
+
const rootTsConfigPath = getRootTsConfigPath(context);
|
374
|
+
if (!rootTsConfigPath) {
|
375
|
+
return {};
|
376
|
+
}
|
320
377
|
const tsconfigPaths = require('tsconfig-paths');
|
321
|
-
const tsConfigResult = tsconfigPaths.loadConfig(
|
378
|
+
const tsConfigResult = tsconfigPaths.loadConfig(rootTsConfigPath);
|
322
379
|
if (tsConfigResult.resultType !== 'success') {
|
323
380
|
throw new Error('Cannot load tsconfig file');
|
324
381
|
}
|
@@ -331,5 +388,5 @@ function getRootTsConfigPath(context) {
|
|
331
388
|
return tsConfigPath;
|
332
389
|
}
|
333
390
|
}
|
334
|
-
|
391
|
+
return null;
|
335
392
|
}
|