From 152fd8e2f714c6c5190c501a5c7d0c7f539bbe4f Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 12 Jul 2023 08:20:05 -0700 Subject: [PATCH] refactor(esbuild): Optimize for Node targets. --- package-lock.json | 19 +++++++++++++++++-- package.json | 1 + src/lib/configuration/strategies/esbuild.ts | 9 ++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 47f7ac7..743d355 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "cosmiconfig": "^8.2.0", "deepmerge": "^4.3.1", "esbuild": "^0.18.11", + "esbuild-node-externals": "^1.8.0", "fs-extra": "^11.1.1", "node-version": "^3.0.0", "read-pkg-up": "^10.0.0", @@ -5704,6 +5705,21 @@ "@esbuild/win32-x64": "0.18.11" } }, + "node_modules/esbuild-node-externals": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/esbuild-node-externals/-/esbuild-node-externals-1.8.0.tgz", + "integrity": "sha512-pYslmT8Bl383UnfxzHQQRpCgBNIOwAzDaYheuIeI4CODxelsN/eQroVn5STDow5QOpRalMgWUR+R8LfSgUROcw==", + "dependencies": { + "find-up": "^5.0.0", + "tslib": "^2.4.1" + }, + "engines": { + "node": ">=12" + }, + "peerDependencies": { + "esbuild": "0.12 - 0.18" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -17640,8 +17656,7 @@ "node_modules/tslib": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", - "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==", - "devOptional": true + "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==" }, "node_modules/tsutils": { "version": "3.21.0", diff --git a/package.json b/package.json index 510b89d..3d39025 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "cosmiconfig": "^8.2.0", "deepmerge": "^4.3.1", "esbuild": "^0.18.11", + "esbuild-node-externals": "^1.8.0", "fs-extra": "^11.1.1", "node-version": "^3.0.0", "read-pkg-up": "^10.0.0", diff --git a/src/lib/configuration/strategies/esbuild.ts b/src/lib/configuration/strategies/esbuild.ts index b39cb53..aeeb2a4 100644 --- a/src/lib/configuration/strategies/esbuild.ts +++ b/src/lib/configuration/strategies/esbuild.ts @@ -2,6 +2,7 @@ import path from 'path'; import { TsconfigPathsPlugin } from '@esbuild-plugins/tsconfig-paths'; import * as esbuild from 'esbuild'; +import { nodeExternalsPlugin } from 'esbuild-node-externals'; import fs from 'fs-extra'; import currentNodeVersion from 'node-version'; import * as tsConfck from 'tsconfck'; @@ -72,7 +73,13 @@ export async function esbuildStrategy(filePath: string, pkgInfo: Packag target: `node${currentNodeVersion.major}`, outfile: tempFileName, format, - plugins: [] + platform: 'node', + bundle: true, + plugins: [ + nodeExternalsPlugin({ + packagePath: path.resolve(pkgInfo.root ?? '', 'package.json') + }) + ] }; // If the user has a TypeScript configuration file, enable TypeScript