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 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
- // We need to manually resolve .web files since the resolveExtensions option does not seem to work properly.
48
- build.onLoad({ filter: scriptPathPattern }, async (args) => {
49
- let path = args.path;
50
- const webPath = args.path.replace(/(\.[^/.]+)$/, '.web$1');
51
- try {
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
- code = flowRemoveTypes(code).toString();
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
- // We need to manually resolve .web files since the resolveExtensions option does not seem to work properly.
44
- build.onLoad({ filter: scriptPathPattern }, async (args) => {
45
- let path = args.path;
46
- const webPath = args.path.replace(/(\.[^/.]+)$/, '.web$1');
47
- try {
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
- code = flowRemoveTypes(code).toString();
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.1",
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.233.0"
45
+ "flow-remove-types": "^2.259.1"
45
46
  },
46
47
  "devDependencies": {
47
- "@rollup/plugin-typescript": "^11.1.6",
48
- "@types/node": "^20.12.4",
49
- "rollup": "^4.14.0",
50
- "tslib": "^2.6.2",
51
- "typescript": "^5.4.4",
52
- "vite": "^5.2.8"
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 "vite"
2
-
3
- export type ViteReactNativeWebOptions = {
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