@vxrn/compiler 1.1.397 → 1.1.398
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/configure.cjs +1 -0
- package/dist/cjs/configure.js +1 -0
- package/dist/cjs/configure.js.map +1 -1
- package/dist/cjs/index.cjs +57 -7
- package/dist/cjs/index.js +51 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/refresh-runtime.cjs +1 -3
- package/dist/cjs/refresh-runtime.js +1 -1
- package/dist/cjs/refresh-runtime.js.map +1 -1
- package/dist/cjs/transformBabel.cjs +22 -18
- package/dist/cjs/transformBabel.js +19 -22
- package/dist/cjs/transformBabel.js.map +1 -1
- package/dist/cjs/transformSWC.cjs +77 -76
- package/dist/cjs/transformSWC.js +76 -76
- package/dist/cjs/transformSWC.js.map +1 -1
- package/dist/esm/configure.js +1 -0
- package/dist/esm/configure.js.map +1 -1
- package/dist/esm/configure.mjs +1 -0
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/index.js +53 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +58 -8
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/refresh-runtime.js +1 -1
- package/dist/esm/refresh-runtime.js.map +1 -1
- package/dist/esm/refresh-runtime.mjs +1 -3
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.js +19 -21
- package/dist/esm/transformBabel.js.map +1 -1
- package/dist/esm/transformBabel.mjs +22 -18
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformSWC.js +77 -77
- package/dist/esm/transformSWC.js.map +1 -1
- package/dist/esm/transformSWC.mjs +78 -77
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/package.json +10 -8
- package/src/configure.ts +2 -0
- package/src/index.ts +108 -11
- package/src/refresh-runtime.js +1 -1
- package/src/transformBabel.ts +36 -17
- package/src/transformSWC.ts +102 -102
- package/types/configure.d.ts +1 -0
- package/types/configure.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/transformBabel.d.ts +1 -1
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformSWC.d.ts +4 -1
- package/types/transformSWC.d.ts.map +1 -1
- package/dist/cjs/configure.native.js +0 -35
- package/dist/cjs/configure.native.js.map +0 -6
- package/dist/cjs/constants.native.js +0 -65
- package/dist/cjs/constants.native.js.map +0 -6
- package/dist/cjs/index.native.js +0 -123
- package/dist/cjs/index.native.js.map +0 -6
- package/dist/cjs/refresh-runtime.native.js +0 -316
- package/dist/cjs/refresh-runtime.native.js.map +0 -6
- package/dist/cjs/transformBabel.native.js +0 -152
- package/dist/cjs/transformBabel.native.js.map +0 -6
- package/dist/cjs/transformSWC.native.js +0 -275
- package/dist/cjs/transformSWC.native.js.map +0 -6
- package/dist/cjs/types.native.js +0 -15
- package/dist/cjs/types.native.js.map +0 -6
- package/dist/esm/configure.native.js +0 -13
- package/dist/esm/configure.native.js.map +0 -6
- package/dist/esm/constants.native.js +0 -41
- package/dist/esm/constants.native.js.map +0 -6
- package/dist/esm/index.native.js +0 -104
- package/dist/esm/index.native.js.map +0 -6
- package/dist/esm/refresh-runtime.native.js +0 -290
- package/dist/esm/refresh-runtime.native.js.map +0 -6
- package/dist/esm/transformBabel.native.js +0 -125
- package/dist/esm/transformBabel.native.js.map +0 -6
- package/dist/esm/transformSWC.native.js +0 -257
- package/dist/esm/transformSWC.native.js.map +0 -6
- package/dist/esm/types.native.js +0 -1
- package/dist/esm/types.native.js.map +0 -6
package/src/index.ts
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
import { resolvePath } from '@vxrn/utils'
|
|
7
7
|
import { readFileSync } from 'node:fs'
|
|
8
8
|
import { readFile } from 'node:fs/promises'
|
|
9
|
-
import { extname, join } from 'node:path'
|
|
9
|
+
import { extname, join, sep } from 'node:path'
|
|
10
|
+
import { cssToReactNativeRuntime } from 'react-native-css-interop/css-to-rn/index.js'
|
|
11
|
+
import type { OutputChunk } from 'rollup'
|
|
10
12
|
import type { PluginOption, UserConfig } from 'vite'
|
|
13
|
+
import { configuration } from './configure'
|
|
11
14
|
import { debug, runtimePublicPath, validParsers } from './constants'
|
|
12
15
|
import { getBabelOptions, transformBabel } from './transformBabel'
|
|
13
16
|
import { transformSWC } from './transformSWC'
|
|
@@ -39,6 +42,14 @@ export async function createVXRNCompilerPlugin(
|
|
|
39
42
|
return name as Environment
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
const reactForRNVersion = reactVersion.split('.')[0] as '18' | '19'
|
|
46
|
+
|
|
47
|
+
const cssTransformCache = new Map<string, string>()
|
|
48
|
+
|
|
49
|
+
// fix so we can align the diff between vite and rollup id (rollup resolves from root monorepo)
|
|
50
|
+
const rollupPath = resolvePath('rollup')
|
|
51
|
+
const rollupNodeMods = rollupPath.slice(0, rollupPath.indexOf(sep + 'node_modules'))
|
|
52
|
+
|
|
42
53
|
return [
|
|
43
54
|
{
|
|
44
55
|
name: 'one:compiler-resolve-refresh-runtime',
|
|
@@ -51,6 +62,63 @@ export async function createVXRNCompilerPlugin(
|
|
|
51
62
|
: undefined,
|
|
52
63
|
},
|
|
53
64
|
|
|
65
|
+
{
|
|
66
|
+
name: `one:compiler-css-to-js`,
|
|
67
|
+
|
|
68
|
+
transform(codeIn, id) {
|
|
69
|
+
const environment = getEnvName(this.environment.name)
|
|
70
|
+
if (configuration.enableNativeCSS && (environment === 'ios' || environment === 'android')) {
|
|
71
|
+
if (extname(id) === '.css') {
|
|
72
|
+
const data = JSON.stringify(cssToReactNativeRuntime(codeIn, { inlineRem: 16 }))
|
|
73
|
+
// TODO were hardcoding the require id we bundle as: nativewind/dist/index.js
|
|
74
|
+
// could at least resolve this using resolvePath
|
|
75
|
+
const code = `require("nativewind/dist/index.js").StyleSheet.registerCompiled(${data})`
|
|
76
|
+
const newId = `${id}.js`
|
|
77
|
+
|
|
78
|
+
// rollup uses relative to its node_modules parent dir, vite here uses absolute
|
|
79
|
+
const cssId = newId.replace(rollupNodeMods + sep, '')
|
|
80
|
+
cssTransformCache.set(cssId, code)
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
code,
|
|
84
|
+
id: newId,
|
|
85
|
+
map: null,
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
generateBundle(_, bundle) {
|
|
92
|
+
const environment = getEnvName(this.environment.name)
|
|
93
|
+
|
|
94
|
+
if (configuration.enableNativeCSS && (environment === 'ios' || environment === 'android')) {
|
|
95
|
+
const rootJSName = Object.keys(bundle).find((i) => {
|
|
96
|
+
const chunk = bundle[i]
|
|
97
|
+
return chunk.type == 'chunk' && chunk.fileName.match(/.[cm]?js(?:\?.+)?$/) != null
|
|
98
|
+
})
|
|
99
|
+
if (!rootJSName) {
|
|
100
|
+
throw new Error(`Can't find root js, internal one error`)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const rootJS = bundle[rootJSName] as OutputChunk
|
|
104
|
+
|
|
105
|
+
const cssAssets = Object.keys(bundle).filter((i) =>
|
|
106
|
+
bundle[i].fileName.endsWith('.css.js')
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
for (const name of cssAssets) {
|
|
110
|
+
delete bundle[name]
|
|
111
|
+
|
|
112
|
+
const jsCSS = cssTransformCache.get(name)
|
|
113
|
+
rootJS.code = `
|
|
114
|
+
${jsCSS}
|
|
115
|
+
${rootJS.code}
|
|
116
|
+
`
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
|
|
54
122
|
{
|
|
55
123
|
name: 'one:compiler',
|
|
56
124
|
enforce: 'pre',
|
|
@@ -61,6 +129,10 @@ export async function createVXRNCompilerPlugin(
|
|
|
61
129
|
optimizeDeps: {
|
|
62
130
|
noDiscovery: true,
|
|
63
131
|
},
|
|
132
|
+
|
|
133
|
+
define: {
|
|
134
|
+
'process.env.NATIVEWIND_OS': 'native',
|
|
135
|
+
},
|
|
64
136
|
} satisfies UserConfig
|
|
65
137
|
|
|
66
138
|
return {
|
|
@@ -75,6 +147,29 @@ export async function createVXRNCompilerPlugin(
|
|
|
75
147
|
order: 'pre',
|
|
76
148
|
async handler(codeIn, _id) {
|
|
77
149
|
let code = codeIn
|
|
150
|
+
const environment = getEnvName(this.environment.name)
|
|
151
|
+
const isNative = environment === 'ios' || environment === 'android'
|
|
152
|
+
const production =
|
|
153
|
+
process.env.NODE_ENV === 'production' ||
|
|
154
|
+
JSON.parse(this.environment.config?.define?.['process.env.NODE_ENV'] || '""') ===
|
|
155
|
+
'production'
|
|
156
|
+
|
|
157
|
+
// it has a hidden special character
|
|
158
|
+
// TODO: use === special char this is in sensitive perf path
|
|
159
|
+
const isEntry = _id.includes('one-entry-native')
|
|
160
|
+
|
|
161
|
+
if (isEntry) {
|
|
162
|
+
if (isNative && !production) {
|
|
163
|
+
code = `import '@vxrn/vite-native-client'\n${code}`
|
|
164
|
+
}
|
|
165
|
+
if (isNative && configuration.enableNativewind) {
|
|
166
|
+
// ensure we have nativewind import in bundle root
|
|
167
|
+
code = `import * as x from 'nativewind'\n${code}`
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// TODO sourcemap add two ';;'?
|
|
171
|
+
return code
|
|
172
|
+
}
|
|
78
173
|
|
|
79
174
|
const shouldDebug =
|
|
80
175
|
process.env.NODE_ENV === 'development' && codeIn.startsWith('// debug')
|
|
@@ -85,12 +180,14 @@ export async function createVXRNCompilerPlugin(
|
|
|
85
180
|
}
|
|
86
181
|
|
|
87
182
|
const extension = extname(_id)
|
|
88
|
-
|
|
183
|
+
|
|
184
|
+
if (extension === '.css') {
|
|
185
|
+
// handled in one:compiler-css-to-js
|
|
89
186
|
return
|
|
90
187
|
}
|
|
91
188
|
|
|
92
|
-
if (extension
|
|
93
|
-
|
|
189
|
+
if (!validParsers.has(extension)) {
|
|
190
|
+
return
|
|
94
191
|
}
|
|
95
192
|
|
|
96
193
|
let id = _id.split('?')[0]
|
|
@@ -105,15 +202,12 @@ export async function createVXRNCompilerPlugin(
|
|
|
105
202
|
return
|
|
106
203
|
}
|
|
107
204
|
|
|
108
|
-
const environment = getEnvName(this.environment.name)
|
|
109
|
-
const production = process.env.NODE_ENV === 'production'
|
|
110
|
-
|
|
111
205
|
const transformProps: GetTransformProps = {
|
|
112
206
|
id,
|
|
113
207
|
code,
|
|
114
208
|
development: !production,
|
|
115
209
|
environment,
|
|
116
|
-
reactForRNVersion
|
|
210
|
+
reactForRNVersion,
|
|
117
211
|
}
|
|
118
212
|
|
|
119
213
|
const userTransform = optionsIn?.transform?.(transformProps)
|
|
@@ -129,10 +223,13 @@ export async function createVXRNCompilerPlugin(
|
|
|
129
223
|
})
|
|
130
224
|
|
|
131
225
|
if (babelOptions) {
|
|
226
|
+
// TODO we probably need to forward sourceMap here?
|
|
132
227
|
const babelOut = await transformBabel(id, code, babelOptions)
|
|
133
|
-
if (babelOut) {
|
|
228
|
+
if (babelOut?.code) {
|
|
134
229
|
debug?.(`[${id}] transformed with babel options: ${JSON.stringify(babelOptions)}`)
|
|
135
|
-
|
|
230
|
+
// TODO we may want to just avoid SWC after babel it likely is faster
|
|
231
|
+
// we'd need to have metro or metro-like preset
|
|
232
|
+
code = babelOut.code
|
|
136
233
|
}
|
|
137
234
|
}
|
|
138
235
|
|
|
@@ -142,7 +239,7 @@ export async function createVXRNCompilerPlugin(
|
|
|
142
239
|
|
|
143
240
|
const swcOptions = {
|
|
144
241
|
environment: environment,
|
|
145
|
-
mode: 'serve',
|
|
242
|
+
mode: optionsIn?.mode || 'serve',
|
|
146
243
|
production,
|
|
147
244
|
...optionsIn,
|
|
148
245
|
} satisfies Options
|
package/src/refresh-runtime.js
CHANGED
|
@@ -575,7 +575,7 @@ const enqueueUpdate = debounce(async () => {
|
|
|
575
575
|
}, 16)
|
|
576
576
|
|
|
577
577
|
export function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
|
|
578
|
-
const ignoredExports =
|
|
578
|
+
const ignoredExports = []
|
|
579
579
|
if (predicateOnExport(ignoredExports, prevExports, (key) => key in nextExports) !== true) {
|
|
580
580
|
return 'Could not Fast Refresh (export removed)'
|
|
581
581
|
}
|
package/src/transformBabel.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import babel from '@babel/core'
|
|
2
|
+
import { resolvePath } from '@vxrn/utils'
|
|
2
3
|
import { relative } from 'node:path'
|
|
3
4
|
import { configuration } from './configure'
|
|
4
5
|
import { asyncGeneratorRegex, debug } from './constants'
|
|
@@ -10,9 +11,7 @@ type Props = GetTransformProps & {
|
|
|
10
11
|
|
|
11
12
|
export function getBabelOptions(props: Props): babel.TransformOptions | null {
|
|
12
13
|
if (props.userSetting === 'babel') {
|
|
13
|
-
return
|
|
14
|
-
plugins: getPlugins(props, true),
|
|
15
|
-
}
|
|
14
|
+
return getOptions(props, true)
|
|
16
15
|
}
|
|
17
16
|
if (
|
|
18
17
|
typeof props.userSetting === 'undefined' ||
|
|
@@ -21,24 +20,32 @@ export function getBabelOptions(props: Props): babel.TransformOptions | null {
|
|
|
21
20
|
if (props.userSetting?.excludeDefaultPlugins) {
|
|
22
21
|
return props.userSetting
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
if (plugins.length) {
|
|
26
|
-
return {
|
|
27
|
-
plugins,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
23
|
+
return getOptions(props)
|
|
30
24
|
}
|
|
31
25
|
return null
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
const
|
|
28
|
+
const getOptions = (props: Props, force = false): babel.TransformOptions | null => {
|
|
29
|
+
const presets: string[] = []
|
|
35
30
|
let plugins: babel.PluginItem[] = []
|
|
36
31
|
|
|
37
32
|
if (force || shouldBabelGenerators(props)) {
|
|
38
33
|
plugins = getBasePlugins(props)
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
const enableNativewind =
|
|
37
|
+
configuration.enableNativewind &&
|
|
38
|
+
(props.environment === 'ios' || props.environment === 'android') &&
|
|
39
|
+
// only needed for createElement calls, so be a bit conservative
|
|
40
|
+
props.code.includes('createElement')
|
|
41
|
+
|
|
42
|
+
if (enableNativewind) {
|
|
43
|
+
if (!props.id.includes('node_modules')) {
|
|
44
|
+
plugins.push(resolvePath('react-native-css-interop/dist/babel-plugin.js'))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (enableNativewind || shouldBabelReanimated(props)) {
|
|
42
49
|
debug?.(`Using babel reanimated on file`)
|
|
43
50
|
plugins.push('react-native-reanimated/plugin')
|
|
44
51
|
}
|
|
@@ -53,36 +60,47 @@ const getPlugins = (props: Props, force = false) => {
|
|
|
53
60
|
plugins.push('@react-native/babel-plugin-codegen')
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
if (plugins.length || presets.length) {
|
|
64
|
+
return { plugins, presets }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return null
|
|
57
68
|
}
|
|
69
|
+
|
|
58
70
|
/**
|
|
59
71
|
* Transform input to mostly ES5 compatible code, keep ESM syntax, and transform generators.
|
|
60
72
|
*/
|
|
61
73
|
export async function transformBabel(id: string, code: string, options: babel.TransformOptions) {
|
|
62
74
|
const compilerPlugin = options.plugins?.find((x) => x && x[0] === 'babel-plugin-react-compiler')
|
|
63
75
|
|
|
64
|
-
const out = await new Promise<
|
|
76
|
+
const out = await new Promise<babel.BabelFileResult>((res, rej) => {
|
|
65
77
|
babel.transform(
|
|
66
78
|
code,
|
|
67
79
|
{
|
|
68
80
|
filename: id,
|
|
69
81
|
compact: false,
|
|
82
|
+
babelrc: false,
|
|
83
|
+
configFile: false,
|
|
84
|
+
sourceMaps: true,
|
|
70
85
|
minified: false,
|
|
71
|
-
presets: ['@babel/preset-typescript'],
|
|
72
86
|
...options,
|
|
87
|
+
presets: ['@babel/preset-typescript', ...(options.presets || [])],
|
|
73
88
|
},
|
|
74
89
|
(err: any, result) => {
|
|
75
90
|
if (!result || err) {
|
|
76
91
|
return rej(err || 'no res')
|
|
77
92
|
}
|
|
78
|
-
res(result
|
|
93
|
+
res(result!)
|
|
79
94
|
}
|
|
80
95
|
)
|
|
81
96
|
})
|
|
82
97
|
|
|
83
98
|
if (
|
|
84
99
|
compilerPlugin &&
|
|
85
|
-
|
|
100
|
+
// TODO this detection could be a lot faster
|
|
101
|
+
out.code?.includes(
|
|
102
|
+
compilerPlugin[1] === '18' ? `react-compiler-runtime` : `react/compiler-runtime`
|
|
103
|
+
)
|
|
86
104
|
) {
|
|
87
105
|
console.info(` 🪄 [compiler] ${relative(process.cwd(), id)}`)
|
|
88
106
|
}
|
|
@@ -139,8 +157,9 @@ const shouldBabelReactCompiler = (props: Props) => {
|
|
|
139
157
|
}
|
|
140
158
|
}
|
|
141
159
|
if (!/.*(.tsx?)$/.test(props.id)) return false
|
|
160
|
+
// disable node modules for now...
|
|
161
|
+
if (props.id.includes('node_modules')) return false
|
|
142
162
|
if (props.code.startsWith('// disable-compiler')) return false
|
|
143
|
-
// may want to disable in node modules? but rare to have tsx in node mods
|
|
144
163
|
return true
|
|
145
164
|
}
|
|
146
165
|
|
package/src/transformSWC.ts
CHANGED
|
@@ -6,19 +6,21 @@ import {
|
|
|
6
6
|
type TransformConfig,
|
|
7
7
|
} from '@swc/core'
|
|
8
8
|
import type { SourceMapPayload } from 'node:module'
|
|
9
|
-
import { extname } from 'node:path'
|
|
9
|
+
import { extname, sep } from 'node:path'
|
|
10
10
|
import { merge } from 'ts-deepmerge'
|
|
11
11
|
import { configuration } from './configure'
|
|
12
12
|
import { asyncGeneratorRegex, debug, parsers, runtimePublicPath } from './constants'
|
|
13
13
|
import type { Options } from './types'
|
|
14
14
|
|
|
15
|
+
const ignoreId = new RegExp(`node_modules\\${sep}(\\.vite|vite)\\${sep}`)
|
|
16
|
+
|
|
15
17
|
export async function transformSWC(
|
|
16
18
|
id: string,
|
|
17
19
|
code: string,
|
|
18
20
|
options: Options & { es5?: boolean },
|
|
19
21
|
swcOptions?: SWCOptions
|
|
20
22
|
) {
|
|
21
|
-
if (
|
|
23
|
+
if (ignoreId.test(id)) {
|
|
22
24
|
return
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -37,11 +39,11 @@ export async function transformSWC(
|
|
|
37
39
|
return
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
const enableNativeCSS =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const enableNativeCSS = configuration.enableNativeCSS
|
|
43
|
+
|
|
44
|
+
// temp fix idk why this error:
|
|
45
|
+
// node_modules/react-native-reanimated/src/component/LayoutAnimationConfig.tsx (19:9): "createInteropElement" is not exported by "../../node_modules/react-native-css-interop/dist/runtime/jsx-dev-runtime.js", imported by "node_modules/react-native-reanimated/src/component/LayoutAnimationConfig.tsx
|
|
46
|
+
!id.includes('node_modules')
|
|
45
47
|
|
|
46
48
|
const refresh =
|
|
47
49
|
options.environment !== 'ssr' && !options.production && !options.noHMR && !options.forceJSX
|
|
@@ -53,10 +55,11 @@ export async function transformSWC(
|
|
|
53
55
|
importSource: 'react',
|
|
54
56
|
...(enableNativeCSS
|
|
55
57
|
? {
|
|
56
|
-
importSource: '
|
|
57
|
-
pragma: 'createInteropElement',
|
|
58
|
+
importSource: 'nativewind',
|
|
59
|
+
// pragma: 'createInteropElement',
|
|
60
|
+
// pragmaFrag: '_InteropFragment',
|
|
58
61
|
// swc doesnt actually change the import right
|
|
59
|
-
runtime: 'classic',
|
|
62
|
+
// runtime: 'classic',
|
|
60
63
|
}
|
|
61
64
|
: {}),
|
|
62
65
|
} satisfies TransformConfig['react']
|
|
@@ -149,12 +152,13 @@ export async function transformSWC(
|
|
|
149
152
|
})()
|
|
150
153
|
|
|
151
154
|
if (enableNativeCSS) {
|
|
152
|
-
if (result.code.includes(`createInteropElement`)) {
|
|
153
|
-
|
|
155
|
+
if (result.code.includes(`createInteropElement(`)) {
|
|
156
|
+
// TODO need to fix sourceMap adding a ';'
|
|
157
|
+
result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'\n${result.code}`
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
const
|
|
161
|
+
const hasRefreshRuntime = refresh && refreshContentRE.test(result.code)
|
|
158
162
|
|
|
159
163
|
// fix for node_modules that ship tsx but don't use type-specific imports
|
|
160
164
|
if (
|
|
@@ -188,70 +192,42 @@ export async function transformSWC(
|
|
|
188
192
|
}
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
if (
|
|
192
|
-
return result
|
|
195
|
+
if (result && !options.production && !options.noHMR) {
|
|
196
|
+
return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime)
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// TODO bring back?
|
|
198
|
-
// if (result.map) {
|
|
199
|
-
// const sourceMap: SourceMapPayload = JSON.parse(result.map)
|
|
200
|
-
// sourceMap.mappings = ';;;;;;;;' + sourceMap.mappings
|
|
201
|
-
// return { code: result.code, map: sourceMap }
|
|
202
|
-
// }
|
|
203
|
-
|
|
204
|
-
return { code: result.code }
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const SWC_ENV = {
|
|
208
|
-
targets: {
|
|
209
|
-
node: '4',
|
|
210
|
-
},
|
|
211
|
-
// debug: true,
|
|
212
|
-
include: [],
|
|
213
|
-
// this breaks the uniswap app for any file with a ...spread
|
|
214
|
-
exclude: [
|
|
215
|
-
'transform-spread',
|
|
216
|
-
'transform-destructuring',
|
|
217
|
-
'transform-object-rest-spread',
|
|
218
|
-
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
219
|
-
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
220
|
-
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
221
|
-
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
222
|
-
'transform-async-to-generator',
|
|
223
|
-
'transform-regenerator', // Similar to above
|
|
224
|
-
],
|
|
225
|
-
} satisfies SWCOptions['env']
|
|
226
|
-
|
|
227
|
-
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/
|
|
228
|
-
|
|
229
|
-
function shouldSourceMap() {
|
|
230
|
-
return process.env.VXRN_ENABLE_SOURCE_MAP === '1'
|
|
199
|
+
return result
|
|
231
200
|
}
|
|
232
201
|
|
|
233
202
|
function wrapSourceInRefreshRuntime(
|
|
234
203
|
id: string,
|
|
235
204
|
result: Output,
|
|
236
205
|
options: Options,
|
|
237
|
-
|
|
206
|
+
hasRefreshRuntime: boolean
|
|
238
207
|
) {
|
|
239
|
-
if (options.environment === '
|
|
240
|
-
return
|
|
208
|
+
if (options.environment === 'ssr') {
|
|
209
|
+
return result
|
|
210
|
+
}
|
|
211
|
+
if (options.environment === 'client') {
|
|
212
|
+
return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime)
|
|
241
213
|
}
|
|
242
|
-
return wrapSourceInRefreshRuntimeNative(id, result, options,
|
|
214
|
+
return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime)
|
|
243
215
|
}
|
|
244
216
|
|
|
245
|
-
function wrapSourceInRefreshRuntimeWeb(id: string, result: Output,
|
|
246
|
-
const sourceMap
|
|
247
|
-
sourceMap
|
|
217
|
+
function wrapSourceInRefreshRuntimeWeb(id: string, result: Output, hasRefreshRuntime: boolean) {
|
|
218
|
+
const sourceMap = result.map ? JSON.parse(result.map) : undefined
|
|
219
|
+
if (sourceMap) {
|
|
220
|
+
sourceMap.mappings = ';;' + sourceMap.mappings
|
|
221
|
+
}
|
|
248
222
|
|
|
249
223
|
result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
|
|
250
224
|
|
|
251
225
|
${result.code}`
|
|
252
226
|
|
|
253
|
-
if (
|
|
254
|
-
sourceMap
|
|
227
|
+
if (hasRefreshRuntime) {
|
|
228
|
+
if (sourceMap) {
|
|
229
|
+
sourceMap.mappings = ';;;;;;' + sourceMap.mappings
|
|
230
|
+
}
|
|
255
231
|
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
256
232
|
const prevRefreshReg = window.$RefreshReg$;
|
|
257
233
|
const prevRefreshSig = window.$RefreshSig$;
|
|
@@ -275,65 +251,89 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
275
251
|
});
|
|
276
252
|
});
|
|
277
253
|
`
|
|
254
|
+
|
|
255
|
+
return { code: result.code, map: sourceMap }
|
|
278
256
|
}
|
|
279
257
|
|
|
280
258
|
function wrapSourceInRefreshRuntimeNative(
|
|
281
259
|
id: string,
|
|
282
260
|
result: Output,
|
|
283
261
|
options: Options,
|
|
284
|
-
|
|
262
|
+
hasRefreshRuntime: boolean
|
|
285
263
|
) {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
import '@vxrn/vite-native-client'
|
|
292
|
-
`
|
|
293
|
-
: ``
|
|
294
|
-
|
|
295
|
-
if (options.production) {
|
|
296
|
-
return `
|
|
297
|
-
${prefixCode}
|
|
298
|
-
module.url = '${id}'
|
|
299
|
-
${result.code}
|
|
300
|
-
`
|
|
264
|
+
const postfixCode = `if (module.hot) {
|
|
265
|
+
if (module.hot.accept) {
|
|
266
|
+
module.hot.accept((nextExports) => {
|
|
267
|
+
RefreshRuntime.performReactRefresh()
|
|
268
|
+
});
|
|
301
269
|
}
|
|
270
|
+
}`
|
|
302
271
|
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
272
|
+
if (hasRefreshRuntime) {
|
|
273
|
+
// do we need this vite-native-client here? cant we do this on its own?
|
|
274
|
+
const prefixCode = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
|
|
275
|
+
const prevRefreshReg = globalThis.$RefreshReg$;
|
|
276
|
+
const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
|
|
277
|
+
console.info("no react refresh setup!")
|
|
278
|
+
return (x) => x
|
|
279
|
+
});
|
|
280
|
+
globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" + " " + id);
|
|
281
|
+
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
282
|
+
module.url = '${id}'
|
|
283
|
+
module.hot = createHotContext(module.url)`
|
|
312
284
|
|
|
313
|
-
|
|
285
|
+
const sourceMap = result.map ? JSON.parse(result.map) : undefined
|
|
314
286
|
|
|
315
|
-
|
|
316
|
-
|
|
287
|
+
if (sourceMap) {
|
|
288
|
+
// we need ";" equal to number of lines added to the top
|
|
289
|
+
const prefixLen = prefixCode.split('\n').length + 1
|
|
290
|
+
sourceMap.mappings = new Array(prefixLen).fill(';').join('') + sourceMap.mappings
|
|
291
|
+
}
|
|
317
292
|
|
|
293
|
+
return {
|
|
294
|
+
code: `${prefixCode}
|
|
318
295
|
${result.code}
|
|
319
296
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
297
|
+
if (module.hot) {
|
|
298
|
+
globalThis.$RefreshReg$ = prevRefreshReg;
|
|
299
|
+
globalThis.$RefreshSig$ = prevRefreshSig;
|
|
300
|
+
globalThis['lastHmrExports'] = JSON.stringify(Object.keys(exports))
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
${postfixCode}
|
|
304
|
+
`,
|
|
305
|
+
map: sourceMap,
|
|
306
|
+
}
|
|
326
307
|
}
|
|
327
308
|
|
|
328
|
-
result.code
|
|
309
|
+
result.code += postfixCode
|
|
310
|
+
return result
|
|
311
|
+
}
|
|
329
312
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
313
|
+
const SWC_ENV = {
|
|
314
|
+
targets: {
|
|
315
|
+
node: '4',
|
|
316
|
+
},
|
|
317
|
+
// debug: true,
|
|
318
|
+
include: [],
|
|
319
|
+
// this breaks the uniswap app for any file with a ...spread
|
|
320
|
+
exclude: [
|
|
321
|
+
'transform-spread',
|
|
322
|
+
'transform-destructuring',
|
|
323
|
+
'transform-object-rest-spread',
|
|
324
|
+
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
325
|
+
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
326
|
+
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
327
|
+
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
328
|
+
'transform-async-to-generator',
|
|
329
|
+
'transform-regenerator', // Similar to above
|
|
330
|
+
],
|
|
331
|
+
} satisfies SWCOptions['env']
|
|
332
|
+
|
|
333
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/
|
|
334
|
+
|
|
335
|
+
function shouldSourceMap() {
|
|
336
|
+
return process.env.VXRN_ENABLE_SOURCE_MAP === '1'
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
function getParser(id: string, forceJSX = false) {
|
package/types/configure.d.ts
CHANGED
package/types/configure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,cAAc,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,CAAA;IACxC,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,cAAc,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,CAAA;IACxC,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,IAK3B,CAAA;AAED,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,IAAI,QAElD"}
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,MAAM,CAAA;AAKpD,OAAO,KAAK,EAAkC,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtE,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,wBAAsB,wBAAwB,CAC5C,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,YAAY,EAAE,CAAC,CA6OzB"}
|
|
@@ -7,6 +7,6 @@ export declare function getBabelOptions(props: Props): babel.TransformOptions |
|
|
|
7
7
|
/**
|
|
8
8
|
* Transform input to mostly ES5 compatible code, keep ESM syntax, and transform generators.
|
|
9
9
|
*/
|
|
10
|
-
export declare function transformBabel(id: string, code: string, options: babel.TransformOptions): Promise<
|
|
10
|
+
export declare function transformBabel(id: string, code: string, options: babel.TransformOptions): Promise<babel.BabelFileResult>;
|
|
11
11
|
export {};
|
|
12
12
|
//# sourceMappingURL=transformBabel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformBabel.d.ts","sourceRoot":"","sources":["../src/transformBabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"transformBabel.d.ts","sourceRoot":"","sources":["../src/transformBabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,aAAa,CAAA;AAK/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEtE,KAAK,KAAK,GAAG,iBAAiB,GAAG;IAC/B,WAAW,CAAC,EAAE,oBAAoB,CAAA;CACnC,CAAA;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAc3E;AA4CD;;GAEG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,gBAAgB,kCAoC7F"}
|
package/types/transformSWC.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { type Output, type Options as SWCOptions } from '@swc/core';
|
|
|
2
2
|
import type { Options } from './types';
|
|
3
3
|
export declare function transformSWC(id: string, code: string, options: Options & {
|
|
4
4
|
es5?: boolean;
|
|
5
|
-
}, swcOptions?: SWCOptions): Promise<Output |
|
|
5
|
+
}, swcOptions?: SWCOptions): Promise<Output | {
|
|
6
|
+
code: string;
|
|
7
|
+
map: any;
|
|
8
|
+
} | undefined>;
|
|
6
9
|
export declare const transformSWCStripJSX: (id: string, code: string) => Promise<Output | undefined>;
|
|
7
10
|
//# sourceMappingURL=transformSWC.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformSWC.d.ts","sourceRoot":"","sources":["../src/transformSWC.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EAEX,KAAK,OAAO,IAAI,UAAU,EAE3B,MAAM,WAAW,CAAA;AAMlB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"transformSWC.d.ts","sourceRoot":"","sources":["../src/transformSWC.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EAEX,KAAK,OAAO,IAAI,UAAU,EAE3B,MAAM,WAAW,CAAA;AAMlB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItC,wBAAsB,YAAY,CAChC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GAAG;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EACpC,UAAU,CAAC,EAAE,UAAU;;;eAmLxB;AAgKD,eAAO,MAAM,oBAAoB,OAAc,MAAM,QAAQ,MAAM,gCAqBlE,CAAA"}
|