vite-plugin-react-native-web 2.0.1 → 2.1.0
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/dist/cjs/index.js +36 -23
- package/dist/es/index.js +36 -23
- package/package.json +11 -9
- package/types/index.d.ts +6 -7
package/dist/cjs/index.js
CHANGED
|
@@ -2,28 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var vite = require('vite');
|
|
6
|
-
var flowRemoveTypes = require('flow-remove-types');
|
|
7
5
|
var fs = require('node:fs/promises');
|
|
6
|
+
var flowRemoveTypes = require('flow-remove-types');
|
|
7
|
+
var vite = require('vite');
|
|
8
8
|
|
|
9
9
|
// import type { ViteReactNativeWebOptions } from '../types'
|
|
10
10
|
const development = process.env.NODE_ENV === 'development';
|
|
11
11
|
const extensions = [
|
|
12
|
+
// ⚠️ This currently does not work as expected (https://github.com/evanw/esbuild/issues/4053)
|
|
13
|
+
// '.web.mjs',
|
|
14
|
+
// '.mjs',
|
|
15
|
+
// '.web.js',
|
|
16
|
+
// '.js',
|
|
17
|
+
// '.web.mts',
|
|
18
|
+
// '.mts',
|
|
19
|
+
// '.web.ts',
|
|
20
|
+
// '.ts',
|
|
21
|
+
// '.web.jsx',
|
|
22
|
+
// '.jsx',
|
|
23
|
+
// '.web.tsx',
|
|
24
|
+
// '.tsx',
|
|
25
|
+
// '.json',
|
|
26
|
+
// ⚠️ Temporary fix
|
|
12
27
|
'.web.mjs',
|
|
13
|
-
'.mjs',
|
|
14
28
|
'.web.js',
|
|
15
|
-
'.js',
|
|
16
29
|
'.web.mts',
|
|
17
|
-
'.mts',
|
|
18
30
|
'.web.ts',
|
|
19
|
-
'.ts',
|
|
20
31
|
'.web.jsx',
|
|
21
|
-
'.jsx',
|
|
22
32
|
'.web.tsx',
|
|
33
|
+
'.mjs',
|
|
34
|
+
'.js',
|
|
35
|
+
'.mts',
|
|
36
|
+
'.ts',
|
|
37
|
+
'.jsx',
|
|
23
38
|
'.tsx',
|
|
24
39
|
'.json',
|
|
25
40
|
];
|
|
26
|
-
const scriptPathPattern = /\.(js|jsx|ts|tsx|flow)$/;
|
|
27
41
|
const nativeLegacyScriptPathPattern = /\.(js|flow)$/;
|
|
28
42
|
const flowPragmaPattern = /@flow\b/;
|
|
29
43
|
const useClientPragmaPattern = /['"]use client['"]/;
|
|
@@ -44,20 +58,13 @@ const getLoader = (path) => {
|
|
|
44
58
|
const esbuildPlugin = () => ({
|
|
45
59
|
name: 'react-native-web',
|
|
46
60
|
setup: (build) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await fs.access(webPath);
|
|
53
|
-
path = webPath;
|
|
54
|
-
}
|
|
55
|
-
catch { }
|
|
56
|
-
let contents = await fs.readFile(path, 'utf-8');
|
|
57
|
-
const loader = getLoader(path);
|
|
58
|
-
if (nativeLegacyScriptPathPattern.test(path) && flowPragmaPattern.test(contents)) {
|
|
59
|
-
contents = flowRemoveTypes(contents).toString();
|
|
61
|
+
build.onLoad({ filter: nativeLegacyScriptPathPattern }, async (args) => {
|
|
62
|
+
let contents = await fs.readFile(args.path, 'utf-8');
|
|
63
|
+
if (nativeLegacyScriptPathPattern.test(args.path) && flowPragmaPattern.test(contents)) {
|
|
64
|
+
const transformed = flowRemoveTypes(contents);
|
|
65
|
+
contents = transformed.toString();
|
|
60
66
|
}
|
|
67
|
+
const loader = getLoader(args.path);
|
|
61
68
|
return {
|
|
62
69
|
contents,
|
|
63
70
|
loader,
|
|
@@ -90,10 +97,16 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
90
97
|
if (!nativeLegacyScriptPathPattern.test(id)) {
|
|
91
98
|
return;
|
|
92
99
|
}
|
|
100
|
+
let map = null;
|
|
93
101
|
if (flowPragmaPattern.test(code)) {
|
|
94
|
-
|
|
102
|
+
const transformed = flowRemoveTypes(code);
|
|
103
|
+
code = transformed.toString();
|
|
104
|
+
map = {
|
|
105
|
+
file: id,
|
|
106
|
+
toUrl: () => id,
|
|
107
|
+
...transformed.generateMap(),
|
|
108
|
+
};
|
|
95
109
|
}
|
|
96
|
-
let map = null;
|
|
97
110
|
if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
|
|
98
111
|
const loader = getLoader(id);
|
|
99
112
|
const result = await vite.transformWithEsbuild(code, id, {
|
package/dist/es/index.js
CHANGED
|
@@ -1,25 +1,39 @@
|
|
|
1
|
-
import { transformWithEsbuild } from 'vite';
|
|
2
|
-
import flowRemoveTypes from 'flow-remove-types';
|
|
3
1
|
import fs from 'node:fs/promises';
|
|
2
|
+
import flowRemoveTypes from 'flow-remove-types';
|
|
3
|
+
import { transformWithEsbuild } from 'vite';
|
|
4
4
|
|
|
5
5
|
// import type { ViteReactNativeWebOptions } from '../types'
|
|
6
6
|
const development = process.env.NODE_ENV === 'development';
|
|
7
7
|
const extensions = [
|
|
8
|
+
// ⚠️ This currently does not work as expected (https://github.com/evanw/esbuild/issues/4053)
|
|
9
|
+
// '.web.mjs',
|
|
10
|
+
// '.mjs',
|
|
11
|
+
// '.web.js',
|
|
12
|
+
// '.js',
|
|
13
|
+
// '.web.mts',
|
|
14
|
+
// '.mts',
|
|
15
|
+
// '.web.ts',
|
|
16
|
+
// '.ts',
|
|
17
|
+
// '.web.jsx',
|
|
18
|
+
// '.jsx',
|
|
19
|
+
// '.web.tsx',
|
|
20
|
+
// '.tsx',
|
|
21
|
+
// '.json',
|
|
22
|
+
// ⚠️ Temporary fix
|
|
8
23
|
'.web.mjs',
|
|
9
|
-
'.mjs',
|
|
10
24
|
'.web.js',
|
|
11
|
-
'.js',
|
|
12
25
|
'.web.mts',
|
|
13
|
-
'.mts',
|
|
14
26
|
'.web.ts',
|
|
15
|
-
'.ts',
|
|
16
27
|
'.web.jsx',
|
|
17
|
-
'.jsx',
|
|
18
28
|
'.web.tsx',
|
|
29
|
+
'.mjs',
|
|
30
|
+
'.js',
|
|
31
|
+
'.mts',
|
|
32
|
+
'.ts',
|
|
33
|
+
'.jsx',
|
|
19
34
|
'.tsx',
|
|
20
35
|
'.json',
|
|
21
36
|
];
|
|
22
|
-
const scriptPathPattern = /\.(js|jsx|ts|tsx|flow)$/;
|
|
23
37
|
const nativeLegacyScriptPathPattern = /\.(js|flow)$/;
|
|
24
38
|
const flowPragmaPattern = /@flow\b/;
|
|
25
39
|
const useClientPragmaPattern = /['"]use client['"]/;
|
|
@@ -40,20 +54,13 @@ const getLoader = (path) => {
|
|
|
40
54
|
const esbuildPlugin = () => ({
|
|
41
55
|
name: 'react-native-web',
|
|
42
56
|
setup: (build) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
await fs.access(webPath);
|
|
49
|
-
path = webPath;
|
|
50
|
-
}
|
|
51
|
-
catch { }
|
|
52
|
-
let contents = await fs.readFile(path, 'utf-8');
|
|
53
|
-
const loader = getLoader(path);
|
|
54
|
-
if (nativeLegacyScriptPathPattern.test(path) && flowPragmaPattern.test(contents)) {
|
|
55
|
-
contents = flowRemoveTypes(contents).toString();
|
|
57
|
+
build.onLoad({ filter: nativeLegacyScriptPathPattern }, async (args) => {
|
|
58
|
+
let contents = await fs.readFile(args.path, 'utf-8');
|
|
59
|
+
if (nativeLegacyScriptPathPattern.test(args.path) && flowPragmaPattern.test(contents)) {
|
|
60
|
+
const transformed = flowRemoveTypes(contents);
|
|
61
|
+
contents = transformed.toString();
|
|
56
62
|
}
|
|
63
|
+
const loader = getLoader(args.path);
|
|
57
64
|
return {
|
|
58
65
|
contents,
|
|
59
66
|
loader,
|
|
@@ -86,10 +93,16 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
86
93
|
if (!nativeLegacyScriptPathPattern.test(id)) {
|
|
87
94
|
return;
|
|
88
95
|
}
|
|
96
|
+
let map = null;
|
|
89
97
|
if (flowPragmaPattern.test(code)) {
|
|
90
|
-
|
|
98
|
+
const transformed = flowRemoveTypes(code);
|
|
99
|
+
code = transformed.toString();
|
|
100
|
+
map = {
|
|
101
|
+
file: id,
|
|
102
|
+
toUrl: () => id,
|
|
103
|
+
...transformed.generateMap(),
|
|
104
|
+
};
|
|
91
105
|
}
|
|
92
|
-
let map = null;
|
|
93
106
|
if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
|
|
94
107
|
const loader = getLoader(id);
|
|
95
108
|
const result = await transformWithEsbuild(code, id, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-native-web",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rollup -c",
|
|
27
|
+
"lint": "biome check --write ./src ./types ./biome.json ./tsconfig.json ./rollup.config.mjs",
|
|
27
28
|
"prerelease": "npm run build",
|
|
28
29
|
"release": "npm publish"
|
|
29
30
|
},
|
|
@@ -41,15 +42,16 @@
|
|
|
41
42
|
"react-native-web"
|
|
42
43
|
],
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"flow-remove-types": "^2.
|
|
45
|
+
"flow-remove-types": "^2.259.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
48
|
+
"@biomejs/biome": "^1.9.4",
|
|
49
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
50
|
+
"@types/node": "^22.10.10",
|
|
51
|
+
"rollup": "^4.32.0",
|
|
52
|
+
"tslib": "^2.8.1",
|
|
53
|
+
"typescript": "^5.7.3",
|
|
54
|
+
"vite": "^6.0.11"
|
|
53
55
|
},
|
|
54
56
|
"types": "./types/index.d.ts"
|
|
55
|
-
}
|
|
57
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Plugin as VitePlugin } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default function reactNativeWeb(options?: ViteReactNativeWebOptions): VitePlugin
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite'
|
|
2
|
+
|
|
3
|
+
// biome-ignore lint/complexity/noBannedTypes: Empty type for now
|
|
4
|
+
export type ViteReactNativeWebOptions = {}
|
|
5
|
+
|
|
6
|
+
export default function reactNativeWeb(options?: ViteReactNativeWebOptions): VitePlugin
|