Skip to content

Commit 22b9ed0

Browse files
authored
Merge pull request #12 from vite-plugin/v2.2.1
V2.2.1
2 parents 95c387e + ddd0639 commit 22b9ed0

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.1 (2023-06-29)
2+
3+
- 548fedb fix: avoid Vite built-in alias
4+
15
## 2.2.0 (2023-06-27)
26

37
- 64b881a feat: add `options.forceCopyIfUnbuilt`

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ export default {
3636
export interface NativeOptions {
3737
/** @default 'node_natives' */
3838
assetsDir?: string
39-
/** By default native modules are automatically detected if this option is not explicitly configure by the user. */
39+
/**
40+
* By default native modules are automatically detected if this option is not explicitly configure by the user.
41+
* @deprecated use `ignore` option instead
42+
*/
4043
natives?: string[] | ((natives: string[]) => string[])
44+
/** Ignore the specified native module. */
45+
ignore?: (name: string) => boolean | undefined
46+
/** Force copy *.node files to dist/node_modules path if Webpack can't bundle native modules correctly. */
47+
forceCopyIfUnbuilt?: true
4148
/** Enable and configure webpack. */
4249
webpack?: {
4350
config?: (config: Configuration) => Configuration | undefined | Promise<Configuration | undefined>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-native",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Supports Node/Electron C/C++ native addons",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ const loader1 = '@vercel/webpack-asset-relocator-loader'
4646
const outputAssetBase = 'native_modules'
4747
const NativeExt = '.native.cjs'
4848
const InteropExt = '.interop.mjs'
49-
// https://github.com/vitejs/vite/blob/v5.3.1/packages/vite/src/node/plugins/index.ts#L55
50-
const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/
5149
// `nativesMap` is placed in the global scope and can be effective for multiple builds.
5250
const nativesMap = new Map<string, ResolvedNativeRecord>
51+
// https://github.com/npm/validate-npm-package-name/blob/v5.0.1/lib/index.js#L4
52+
const scopedPackagePattern = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/
5353

5454
export default function native(options: NativeOptions): Plugin {
5555
const assetsDir = options.assetsDir ??= 'node_natives'
@@ -75,13 +75,13 @@ export default function native(options: NativeOptions): Plugin {
7575

7676
const withDistAssetBase = (p: string) => (assetsDir && p) ? `${assetsDir}/${p}` : p
7777
const alias: Alias = {
78-
find: /(.*)/,
78+
find: /^(?!(?:\/?@vite\/|\.))(.*)/,
7979
// Keep `customResolver` receive original source.
8080
// @see https://github.com/rollup/plugins/blob/alias-v5.1.0/packages/alias/src/index.ts#L92
8181
replacement: '$1',
8282
async customResolver(source, importer) {
8383
if (!importer) return
84-
if (!bareImportRE.test(source)) return
84+
if (!scopedPackagePattern.test(source)) return
8585

8686
if (!nativeRecord.has(source)) {
8787
// Dynamic deep detection.

0 commit comments

Comments
 (0)