@tamagui/native-bundle 1.135.4-1761748186554

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/cli.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { runCLI } from "./index.js";
3
+ runCLI().catch((error) => {
4
+ console.error(error);
5
+ process.exit(1);
6
+ });
package/dist/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { build } from "vite";
2
+ import { fileURLToPath } from "node:url";
3
+ import { resolve, dirname } from "node:path";
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = dirname(__filename);
6
+ async function bundleNative(options) {
7
+ const {
8
+ entry,
9
+ outDir = "dist",
10
+ fileName = "native.cjs",
11
+ cwd = process.cwd(),
12
+ define = {},
13
+ minify = false,
14
+ isTest = false
15
+ } = options;
16
+ const resolvePath = (name) => {
17
+ try {
18
+ return fileURLToPath(import.meta.resolve(name));
19
+ } catch {
20
+ return name;
21
+ }
22
+ };
23
+ const rnwl = resolvePath("@tamagui/react-native-web-lite");
24
+ const fakeRN = resolvePath("@tamagui/fake-react-native");
25
+ const entryPath = resolve(cwd, entry);
26
+ const defaultDefine = {
27
+ "process.env.TAMAGUI_TARGET": JSON.stringify("native"),
28
+ "process.env.NODE_ENV": JSON.stringify("production"),
29
+ "process.env.TAMAGUI_IS_CORE_NODE": JSON.stringify("1")
30
+ };
31
+ const external = isTest ? ["react", /^react-native($|\/)/] : ["react"];
32
+ const alias = isTest ? [
33
+ // Aliases don't work for pre-bundled deps, so we externalize and alias in vitest config
34
+ ] : [
35
+ {
36
+ find: /^react-native$/,
37
+ replacement: rnwl
38
+ },
39
+ {
40
+ find: /^react-native\/(.+)$/,
41
+ replacement: `${rnwl}/$1`
42
+ }
43
+ ];
44
+ await build({
45
+ configFile: false,
46
+ root: cwd,
47
+ build: {
48
+ lib: {
49
+ entry: entryPath,
50
+ name: "TamaguiNativeBundle",
51
+ fileName: () => fileName,
52
+ formats: ["cjs"]
53
+ },
54
+ outDir,
55
+ emptyOutDir: false,
56
+ rollupOptions: {
57
+ external,
58
+ output: {
59
+ // Ensure CommonJS output
60
+ format: "cjs",
61
+ exports: "named"
62
+ }
63
+ },
64
+ target: "es2015",
65
+ minify
66
+ },
67
+ resolve: {
68
+ // Prefer react-native exports
69
+ mainFields: ["react-native", "module", "main"],
70
+ extensions: [
71
+ ".native.ts",
72
+ ".native.tsx",
73
+ ".native.js",
74
+ ".ts",
75
+ ".tsx",
76
+ ".js",
77
+ ".jsx"
78
+ ],
79
+ conditions: ["react-native", "import", "module", "default"],
80
+ alias
81
+ },
82
+ define: {
83
+ ...defaultDefine,
84
+ ...define
85
+ },
86
+ logLevel: "warn"
87
+ });
88
+ }
89
+ async function runCLI() {
90
+ const args = process.argv.slice(2);
91
+ if (args.length === 0) {
92
+ console.error("Usage: native-bundle <entry-file> [output-file]");
93
+ process.exit(1);
94
+ }
95
+ const entry = args[0];
96
+ const fileName = args[1] || "native.cjs";
97
+ console.log(`Bundling ${entry} -> dist/${fileName}`);
98
+ try {
99
+ await bundleNative({ entry, fileName });
100
+ console.log("\u2713 Bundle created successfully");
101
+ } catch (error) {
102
+ console.error("\u2717 Bundle failed:", error);
103
+ process.exit(1);
104
+ }
105
+ }
106
+ export {
107
+ bundleNative,
108
+ runCLI
109
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@tamagui/native-bundle",
3
+ "version": "1.135.4-1761748186554",
4
+ "type": "module",
5
+ "description": "Vite-based bundler for creating native CommonJS bundles for Tamagui packages",
6
+ "main": "dist/index.js",
7
+ "types": "src/index.ts",
8
+ "scripts": {
9
+ "build": "node build.mjs",
10
+ "watch": "node build.mjs --watch"
11
+ },
12
+ "license": "MIT",
13
+ "author": {
14
+ "name": "Nate Wienert"
15
+ },
16
+ "dependencies": {
17
+ "vite": "^7.1.12"
18
+ },
19
+ "devDependencies": {
20
+ "esbuild": "^0.25.11"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "src"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { runCLI } from './index.js'
3
+
4
+ runCLI().catch((error) => {
5
+ console.error(error)
6
+ process.exit(1)
7
+ })
package/src/index.ts ADDED
@@ -0,0 +1,171 @@
1
+ import { build } from 'vite'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { resolve, dirname } from 'node:path'
4
+
5
+ const __filename = fileURLToPath(import.meta.url)
6
+ const __dirname = dirname(__filename)
7
+
8
+ export interface BundleOptions {
9
+ /**
10
+ * Entry point file path (absolute or relative to cwd)
11
+ */
12
+ entry: string
13
+
14
+ /**
15
+ * Output directory (relative to cwd)
16
+ * @default 'dist'
17
+ */
18
+ outDir?: string
19
+
20
+ /**
21
+ * Output filename
22
+ * @default 'native.cjs'
23
+ */
24
+ fileName?: string
25
+
26
+ /**
27
+ * Working directory
28
+ * @default process.cwd()
29
+ */
30
+ cwd?: string
31
+
32
+ /**
33
+ * Environment variables to define
34
+ */
35
+ define?: Record<string, string>
36
+
37
+ /**
38
+ * Whether to minify the output
39
+ * @default false
40
+ */
41
+ minify?: boolean
42
+
43
+ /**
44
+ * Whether this is a test bundle
45
+ * If true, react-native will be replaced with fake-react-native mocks
46
+ * @default false
47
+ */
48
+ isTest?: boolean
49
+ }
50
+
51
+ /**
52
+ * Bundle a Tamagui package for React Native using Vite
53
+ */
54
+ export async function bundleNative(options: BundleOptions): Promise<void> {
55
+ const {
56
+ entry,
57
+ outDir = 'dist',
58
+ fileName = 'native.cjs',
59
+ cwd = process.cwd(),
60
+ define = {},
61
+ minify = false,
62
+ isTest = false,
63
+ } = options
64
+
65
+ const resolvePath = (name: string) => {
66
+ try {
67
+ return fileURLToPath(import.meta.resolve(name))
68
+ } catch {
69
+ // Fallback for packages that might not be resolvable
70
+ return name
71
+ }
72
+ }
73
+
74
+ const rnwl = resolvePath('@tamagui/react-native-web-lite')
75
+ const fakeRN = resolvePath('@tamagui/fake-react-native')
76
+ const entryPath = resolve(cwd, entry)
77
+
78
+ const defaultDefine = {
79
+ 'process.env.TAMAGUI_TARGET': JSON.stringify('native'),
80
+ 'process.env.NODE_ENV': JSON.stringify('production'),
81
+ 'process.env.TAMAGUI_IS_CORE_NODE': JSON.stringify('1'),
82
+ }
83
+
84
+ // For test bundles, bundle a fake react-native implementation
85
+ // For production bundles, bundle react-native-web-lite
86
+ const external = isTest ? ['react', /^react-native($|\/)/] : ['react']
87
+ const alias = isTest
88
+ ? [
89
+ // Aliases don't work for pre-bundled deps, so we externalize and alias in vitest config
90
+ ]
91
+ : [
92
+ {
93
+ find: /^react-native$/,
94
+ replacement: rnwl,
95
+ },
96
+ {
97
+ find: /^react-native\/(.+)$/,
98
+ replacement: `${rnwl}/$1`,
99
+ },
100
+ ]
101
+
102
+ await build({
103
+ configFile: false,
104
+ root: cwd,
105
+ build: {
106
+ lib: {
107
+ entry: entryPath,
108
+ name: 'TamaguiNativeBundle',
109
+ fileName: () => fileName,
110
+ formats: ['cjs'],
111
+ },
112
+ outDir,
113
+ emptyOutDir: false,
114
+ rollupOptions: {
115
+ external,
116
+ output: {
117
+ // Ensure CommonJS output
118
+ format: 'cjs',
119
+ exports: 'named',
120
+ },
121
+ },
122
+ target: 'es2015',
123
+ minify,
124
+ },
125
+ resolve: {
126
+ // Prefer react-native exports
127
+ mainFields: ['react-native', 'module', 'main'],
128
+ extensions: [
129
+ '.native.ts',
130
+ '.native.tsx',
131
+ '.native.js',
132
+ '.ts',
133
+ '.tsx',
134
+ '.js',
135
+ '.jsx',
136
+ ],
137
+ conditions: ['react-native', 'import', 'module', 'default'],
138
+ alias,
139
+ },
140
+ define: {
141
+ ...defaultDefine,
142
+ ...define,
143
+ },
144
+ logLevel: 'warn',
145
+ })
146
+ }
147
+
148
+ /**
149
+ * CLI entry point for running as a script
150
+ */
151
+ export async function runCLI() {
152
+ const args = process.argv.slice(2)
153
+
154
+ if (args.length === 0) {
155
+ console.error('Usage: native-bundle <entry-file> [output-file]')
156
+ process.exit(1)
157
+ }
158
+
159
+ const entry = args[0]
160
+ const fileName = args[1] || 'native.cjs'
161
+
162
+ console.log(`Bundling ${entry} -> dist/${fileName}`)
163
+
164
+ try {
165
+ await bundleNative({ entry, fileName })
166
+ console.log('✓ Bundle created successfully')
167
+ } catch (error) {
168
+ console.error('✗ Bundle failed:', error)
169
+ process.exit(1)
170
+ }
171
+ }