esbuild-node-externals
Advanced tools
Comparing version 1.5.0 to 1.6.0
# Changelog | ||
## [1.6.0](https://www.github.com/pradel/esbuild-node-externals/compare/v1.5.0...v1.6.0) (2022-12-12) | ||
### Features | ||
* allow esbuild 0.16 ([#35](https://www.github.com/pradel/esbuild-node-externals/issues/35)) ([881f75b](https://www.github.com/pradel/esbuild-node-externals/commit/881f75ba61a18b888c54d1dafb0ac5d11d05c65c)) | ||
## [1.5.0](https://www.github.com/pradel/esbuild-node-externals/compare/v1.4.1...v1.5.0) (2022-08-29) | ||
@@ -4,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Plugin } from 'esbuild'; | ||
import type { Plugin } from 'esbuild'; | ||
export interface Options { | ||
@@ -3,0 +3,0 @@ packagePath?: string | string[]; |
@@ -6,5 +6,13 @@ "use strict"; | ||
const nodeExternalsPlugin = (paramsOptions = {}) => { | ||
const options = Object.assign(Object.assign({ dependencies: true, devDependencies: true, peerDependencies: true, optionalDependencies: true, allowList: [] }, paramsOptions), { packagePath: paramsOptions.packagePath && typeof paramsOptions.packagePath === 'string' | ||
const options = { | ||
dependencies: true, | ||
devDependencies: true, | ||
peerDependencies: true, | ||
optionalDependencies: true, | ||
allowList: [], | ||
...paramsOptions, | ||
packagePath: paramsOptions.packagePath && typeof paramsOptions.packagePath === 'string' | ||
? [paramsOptions.packagePath] | ||
: paramsOptions.packagePath }); | ||
: paramsOptions.packagePath, | ||
}; | ||
const nodeModules = (0, utils_1.findDependencies)({ | ||
@@ -23,11 +31,7 @@ packagePaths: options.packagePath | ||
setup(build) { | ||
// On every module resolved, we check if the module name should be an external | ||
build.onResolve({ namespace: 'file', filter: /.*/ }, (args) => { | ||
// To allow allowList to target sub imports | ||
if (options.allowList.includes(args.path)) { | ||
return null; | ||
} | ||
// To allow sub imports from packages we take only the first path to deduct the name | ||
let moduleName = args.path.split('/')[0]; | ||
// In case of scoped package | ||
if (args.path.startsWith('@')) { | ||
@@ -37,3 +41,2 @@ const split = args.path.split('/'); | ||
} | ||
// Mark the module as external so it is not resolved | ||
if (nodeModules.includes(moduleName)) { | ||
@@ -40,0 +43,0 @@ return { path: args.path, external: true }; |
@@ -1,11 +0,2 @@ | ||
/** | ||
* Iterates over package.json file paths recursively found in parent directories, starting from the | ||
* current working directory. If the current working directory is in a git repository, then package.json | ||
* files outside of the git repository will not be yielded. | ||
* Inspired by https://github.com/Septh/rollup-plugin-node-externals/blob/f13ee95c6f1f01d8ba2276bf491aac399adc5482/src/dependencies.ts#L18 | ||
*/ | ||
export declare const findPackagePaths: () => string[]; | ||
/** | ||
* Return an array of the package.json dependencies that should be excluded from the build. | ||
*/ | ||
export declare const findDependencies: (options: { | ||
@@ -12,0 +3,0 @@ packagePaths: string[]; |
@@ -5,8 +5,5 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const fs_1 = (0, tslib_1.__importDefault)(require("fs")); | ||
const find_up_1 = (0, tslib_1.__importDefault)(require("find-up")); | ||
/** | ||
* Determines if the `child` path is under the `parent` path. | ||
*/ | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
const find_up_1 = tslib_1.__importDefault(require("find-up")); | ||
const isInDirectory = (parent, child) => { | ||
@@ -19,10 +16,3 @@ const relativePath = path_1.default.relative(parent, child); | ||
}; | ||
/** | ||
* Iterates over package.json file paths recursively found in parent directories, starting from the | ||
* current working directory. If the current working directory is in a git repository, then package.json | ||
* files outside of the git repository will not be yielded. | ||
* Inspired by https://github.com/Septh/rollup-plugin-node-externals/blob/f13ee95c6f1f01d8ba2276bf491aac399adc5482/src/dependencies.ts#L18 | ||
*/ | ||
const findPackagePaths = () => { | ||
// Find git root if in git repository | ||
const gitDirectoryPath = find_up_1.default.sync('.git', { | ||
@@ -43,5 +33,2 @@ type: 'directory', | ||
exports.findPackagePaths = findPackagePaths; | ||
/** | ||
* Return an array of the package.json dependencies that should be excluded from the build. | ||
*/ | ||
const findDependencies = (options) => { | ||
@@ -48,0 +35,0 @@ const packageJsonKeys = [ |
{ | ||
"name": "esbuild-node-externals", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"scripts": { | ||
"typecheck": "tsc --noEmit", | ||
"prebuild": "rimraf ./dist", | ||
"build": "tsc", | ||
@@ -23,14 +25,18 @@ "watch": "tsc --watch" | ||
], | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"dependencies": { | ||
"find-up": "^5.0.0", | ||
"tslib": "^2.4.1" | ||
}, | ||
"peerDependencies": { | ||
"esbuild": "0.12 - 0.15" | ||
"esbuild": "0.12 - 0.16" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "16.11.7", | ||
"esbuild": "^0.13.0", | ||
"typescript": "4.4.4" | ||
}, | ||
"dependencies": { | ||
"find-up": "5.0.0", | ||
"tslib": "2.3.1" | ||
"esbuild": "^0.16.4", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.9.4" | ||
} | ||
} |
@@ -1,2 +0,3 @@ | ||
import { Plugin } from 'esbuild'; | ||
import type { Plugin } from 'esbuild'; | ||
import { findPackagePaths, findDependencies } from './utils'; | ||
@@ -3,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21642
4
255
+ Added@esbuild/android-arm@0.16.17(transitive)
+ Added@esbuild/android-arm64@0.16.17(transitive)
+ Added@esbuild/android-x64@0.16.17(transitive)
+ Added@esbuild/darwin-arm64@0.16.17(transitive)
+ Added@esbuild/darwin-x64@0.16.17(transitive)
+ Added@esbuild/freebsd-arm64@0.16.17(transitive)
+ Added@esbuild/freebsd-x64@0.16.17(transitive)
+ Added@esbuild/linux-arm@0.16.17(transitive)
+ Added@esbuild/linux-arm64@0.16.17(transitive)
+ Added@esbuild/linux-ia32@0.16.17(transitive)
+ Added@esbuild/linux-loong64@0.16.17(transitive)
+ Added@esbuild/linux-mips64el@0.16.17(transitive)
+ Added@esbuild/linux-ppc64@0.16.17(transitive)
+ Added@esbuild/linux-riscv64@0.16.17(transitive)
+ Added@esbuild/linux-s390x@0.16.17(transitive)
+ Added@esbuild/linux-x64@0.16.17(transitive)
+ Added@esbuild/netbsd-x64@0.16.17(transitive)
+ Added@esbuild/openbsd-x64@0.16.17(transitive)
+ Added@esbuild/sunos-x64@0.16.17(transitive)
+ Added@esbuild/win32-arm64@0.16.17(transitive)
+ Added@esbuild/win32-ia32@0.16.17(transitive)
+ Added@esbuild/win32-x64@0.16.17(transitive)
+ Addedesbuild@0.16.17(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@esbuild/android-arm@0.15.18(transitive)
- Removed@esbuild/linux-loong64@0.15.18(transitive)
- Removedesbuild@0.15.18(transitive)
- Removedesbuild-android-64@0.15.18(transitive)
- Removedesbuild-android-arm64@0.15.18(transitive)
- Removedesbuild-darwin-64@0.15.18(transitive)
- Removedesbuild-darwin-arm64@0.15.18(transitive)
- Removedesbuild-freebsd-64@0.15.18(transitive)
- Removedesbuild-freebsd-arm64@0.15.18(transitive)
- Removedesbuild-linux-32@0.15.18(transitive)
- Removedesbuild-linux-64@0.15.18(transitive)
- Removedesbuild-linux-arm@0.15.18(transitive)
- Removedesbuild-linux-arm64@0.15.18(transitive)
- Removedesbuild-linux-mips64le@0.15.18(transitive)
- Removedesbuild-linux-ppc64le@0.15.18(transitive)
- Removedesbuild-linux-riscv64@0.15.18(transitive)
- Removedesbuild-linux-s390x@0.15.18(transitive)
- Removedesbuild-netbsd-64@0.15.18(transitive)
- Removedesbuild-openbsd-64@0.15.18(transitive)
- Removedesbuild-sunos-64@0.15.18(transitive)
- Removedesbuild-windows-32@0.15.18(transitive)
- Removedesbuild-windows-64@0.15.18(transitive)
- Removedesbuild-windows-arm64@0.15.18(transitive)
- Removedtslib@2.3.1(transitive)
Updatedfind-up@^5.0.0
Updatedtslib@^2.4.1