@tamagui/build 2.3.2 → 2.3.3-1782465561627

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.
@@ -1,2 +1,2 @@
1
1
  $ node ../../../tamagui-build.js
2
- built tamagui-build-test-js-main-package in 7299 ms
2
+ built tamagui-build-test-js-main-package in 3991 ms
@@ -1,2 +1,2 @@
1
1
  $ node ../../../tamagui-build.js
2
- built tamagui-build-test-simple-tpackage in 3371 ms
2
+ built tamagui-build-test-simple-tpackage in 2084 ms
@@ -39,6 +39,18 @@ export function getNativeImportMarker() {
39
39
  return 'web-import-marker'
40
40
  }
41
41
 
42
+ export function getNativeRequireMarker() {
43
+ if (process.env.TAMAGUI_TARGET === 'native') {
44
+ // bare require behind a native DCE guard must survive as a real require(),
45
+ // not esbuild's __require() shim which throws under Metro's esm scope.
46
+ // lodash.debounce is just an external (yet bundleable) stand-in for a native-only require.
47
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
48
+ return require('lodash.debounce').NativeRequireMarker
49
+ }
50
+
51
+ return 'web-require-marker'
52
+ }
53
+
42
54
  export function getNodeEnvMarker() {
43
55
  if (process.env.NODE_ENV === 'test') {
44
56
  return 'test-env-marker'
@@ -1,2 +1,2 @@
1
1
  $ node ../../../tamagui-build.js
2
- built tamagui-build-test-watch-package in 4935 ms
2
+ built tamagui-build-test-watch-package in 1668 ms
@@ -204,6 +204,27 @@ describe('tamagui-build integration test', () => {
204
204
 
205
205
  expect(nativeOutput).toContain('getNativeOnlyMarker')
206
206
  expect(nativeOnlyOutput).toContain('native-import-marker')
207
+ expect(nativeOutput).toContain('from "./nativeOnly.native.js"')
208
+ expect(nativeOutput).toContain('from "./nested/index.native.js"')
209
+ expect(nativeOutput).not.toContain('from "./nativeOnly"')
210
+ expect(nativeOutput).not.toContain('from "./nested"')
211
+ })
212
+
213
+ it('should emit a real require() (not the throwing __require shim) for native esm', async () => {
214
+ execSync('bun run build', { cwd: simplePackagePath })
215
+
216
+ const nativeOutput = await readFile(join(distPath, 'esm', 'index.native.js'), 'utf-8')
217
+ const webOutput = await readFile(join(distPath, 'esm', 'index.mjs'), 'utf-8')
218
+
219
+ // native keeps the require behind the DCE guard, but as a real require() that Metro
220
+ // can statically resolve — never the __require() call site that throws at runtime
221
+ expect(nativeOutput).toContain('require("lodash.debounce")')
222
+ // no __require() call sites — that shim throws "Dynamic require ... is not supported"
223
+ expect(nativeOutput).not.toContain('__require(')
224
+
225
+ // web DCE strips the native branch entirely, so the require never leaks into web
226
+ expect(webOutput).toContain('web-require-marker')
227
+ expect(webOutput).not.toContain('lodash.debounce')
207
228
  })
208
229
 
209
230
  it('should keep side-effectful native statements outside dev-only guards', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "2.3.2",
3
+ "version": "2.3.3-1782465561627",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "bin": {
6
6
  "tamagui-build": "tamagui-build.js",
@@ -17,7 +17,7 @@
17
17
  "@babel/core": "^7.25.2",
18
18
  "@babel/preset-typescript": "^7.26.0",
19
19
  "@swc/core": "^1.14.0",
20
- "@tamagui/babel-plugin-fully-specified": "2.3.2",
20
+ "@tamagui/babel-plugin-fully-specified": "2.3.3-1782465561627",
21
21
  "@types/fs-extra": "^9.0.13",
22
22
  "baseline-browser-mapping": "^2.9.15",
23
23
  "chokidar": "^3.5.2",
package/tamagui-build.js CHANGED
@@ -1254,6 +1254,15 @@ async function esbuildWriteIfChanged(
1254
1254
  if (isESM && hadTamaguiTarget) {
1255
1255
  contents = await pruneUnusedImports(contents, path)
1256
1256
  }
1257
+
1258
+ // esbuild emits bare require() in esm output as a __require() shim that throws
1259
+ // ("Dynamic require ... is not supported") under Metro's esm module scope. native
1260
+ // always has a real require, so call it directly. this keeps the
1261
+ // require('react-native')-behind-a-TAMAGUI_TARGET==='native' DCE guard working on
1262
+ // native instead of crashing at runtime (e.g. toast PanResponder).
1263
+ if (platform === 'native' && isESM) {
1264
+ contents = contents.replaceAll('__require(', 'require(')
1265
+ }
1257
1266
  }
1258
1267
 
1259
1268
  if (isESM && pkg.sideEffects !== true && pkg.sideEffects !== undefined) {