Skip to content

Commit

Permalink
fix(bundling): combine user-defined external esbuild options with ours (
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Feb 1, 2023
1 parent 2876996 commit 2f4f0f0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { buildEsbuildOptions } from './build-esbuild-options';
import { ExecutorContext } from 'nx/src/config/misc-interfaces';
import path = require('path');

describe('buildEsbuildOptions', () => {
const context: ExecutorContext = {
Expand All @@ -14,8 +15,8 @@ describe('buildEsbuildOptions', () => {
},
nxJsonConfiguration: {},
isVerbose: false,
root: '/',
cwd: '/',
root: path.join(__dirname, 'fixtures'),
cwd: path.join(__dirname, 'fixtures'),
target: {
executor: '@nrwl/esbuild:esbuild',
options: {
Expand Down Expand Up @@ -276,4 +277,73 @@ describe('buildEsbuildOptions', () => {
},
});
});

it('should respect user defined external', () => {
expect(
buildEsbuildOptions(
'esm',
{
bundle: true,
platform: 'node',
main: 'apps/myapp/src/index.ts',
outputPath: 'dist/apps/myapp',
tsConfig: 'apps/myapp/tsconfig.app.json',
project: 'apps/myapp/package.json',
outputFileName: 'index.js',
assets: [],
singleEntry: true,
external: ['foo'],
esbuildOptions: {
external: ['bar'],
},
},
context
)
).toEqual({
bundle: true,
entryNames: '[dir]/[name]',
entryPoints: ['apps/myapp/src/index.ts'],
format: 'esm',
platform: 'node',
outfile: 'dist/apps/myapp/index.js',
tsconfig: 'apps/myapp/tsconfig.app.json',
external: ['bar', 'foo'],
outExtension: {
'.js': '.js',
},
});
});

it('should not set external if --bundle=false', () => {
expect(
buildEsbuildOptions(
'esm',
{
bundle: false,
platform: 'node',
main: 'apps/myapp/src/index.ts',
outputPath: 'dist/apps/myapp',
tsConfig: 'apps/myapp/tsconfig.app.json',
project: 'apps/myapp/package.json',
outputFileName: 'index.js',
assets: [],
singleEntry: true,
external: ['foo'],
},
context
)
).toEqual({
bundle: false,
entryNames: '[dir]/[name]',
entryPoints: ['apps/myapp/src/index.ts'],
format: 'esm',
platform: 'node',
outdir: 'dist/apps/myapp',
tsconfig: 'apps/myapp/tsconfig.app.json',
external: undefined,
outExtension: {
'.js': '.js',
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export function buildEsbuildOptions(
entryNames:
options.outputHashing === 'all' ? '[dir]/[name].[hash]' : '[dir]/[name]',
bundle: options.bundle,
external: options.external,
// Cannot use external with bundle option
external: options.bundle
? [...(options.esbuildOptions?.external ?? []), ...options.external]
: undefined,
minify: options.minify,
platform: options.platform,
target: options.target,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"paths": {}
}
}

0 comments on commit 2f4f0f0

Please sign in to comment.