@tamagui/build 1.110.3 → 1.110.5
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/__tests__/fixtures/simple-package/index.d.ts +2 -0
- package/__tests__/fixtures/simple-package/index.d.ts.map +1 -0
- package/__tests__/fixtures/simple-package/package.json +22 -0
- package/__tests__/fixtures/simple-package/src/index.ts +10 -0
- package/__tests__/fixtures/simple-package/tsconfig.json +42 -0
- package/__tests__/fixtures/watch-package/index.d.ts +2 -0
- package/__tests__/fixtures/watch-package/index.d.ts.map +1 -0
- package/__tests__/fixtures/watch-package/package.json +22 -0
- package/__tests__/fixtures/watch-package/src/watch.ts +3 -0
- package/__tests__/fixtures/watch-package/tsconfig.json +42 -0
- package/__tests__/fixtures/watch-package/watch.d.ts +2 -0
- package/__tests__/fixtures/watch-package/watch.d.ts.map +1 -0
- package/__tests__/integration.test.ts +208 -0
- package/package.json +10 -6
- package/tamagui-build.js +121 -26
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,MAEpC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tamagui-build-test-simple-tpackage",
|
|
3
|
+
"version": "1.110.5",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.mjs",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node ../../../tamagui-build.js",
|
|
9
|
+
"build:bundle": "node ../../../tamagui-build.js --bundle",
|
|
10
|
+
"build:skip-mjs": "node ../../../tamagui-build.js --skip-mjs",
|
|
11
|
+
"build:declaration-root": "node ../../../tamagui-build.js --declaration-root",
|
|
12
|
+
"build:ignore-base-url": "node ../../../tamagui-build.js --ignore-base-url",
|
|
13
|
+
"build:watch": "node ../../../tamagui-build.js --watch",
|
|
14
|
+
"build:minify": "MINIFY=true node ../../../tamagui-build.js",
|
|
15
|
+
"build:target-web": "TAMAGUI_TARGET=web node ../../../tamagui-build.js",
|
|
16
|
+
"build:target-native": "TAMAGUI_TARGET=native node ../../../tamagui-build.js"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tamagui/build": "1.110.5",
|
|
20
|
+
"typescript": "^5.5.2"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const greet = (name: string): string => {
|
|
2
|
+
return `Hello, ${name}!`
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const paltformGreeter = (name: string): string => {
|
|
6
|
+
let salutation
|
|
7
|
+
process.env.TAMAGUI_TARGET === 'web' ? (salutation = 'Hi') : (salutation = 'Hello')
|
|
8
|
+
process.env.TAMAGUI_TARGET === 'native' ? (salutation = 'Hey') : (salutation = 'Hello')
|
|
9
|
+
return `${salutation}, ${name}!`
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"paths": {
|
|
6
|
+
"vxrn": ["packages/vxrn"],
|
|
7
|
+
"@vxrn/*": ["packages/*"]
|
|
8
|
+
},
|
|
9
|
+
"importHelpers": true,
|
|
10
|
+
"allowJs": false,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"downlevelIteration": true,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"esModuleInterop": true,
|
|
18
|
+
"inlineSourceMap": true,
|
|
19
|
+
"preserveSymlinks": true,
|
|
20
|
+
"jsx": "react-jsx",
|
|
21
|
+
"module": "Preserve",
|
|
22
|
+
"moduleResolution": "Bundler",
|
|
23
|
+
"noEmit": false,
|
|
24
|
+
"noEmitOnError": false,
|
|
25
|
+
"noImplicitAny": false,
|
|
26
|
+
"noImplicitReturns": false,
|
|
27
|
+
"noUnusedLocals": false,
|
|
28
|
+
"noUnusedParameters": false,
|
|
29
|
+
"preserveConstEnums": true,
|
|
30
|
+
"removeComments": false,
|
|
31
|
+
"skipLibCheck": true,
|
|
32
|
+
"sourceMap": false,
|
|
33
|
+
"strictNullChecks": true,
|
|
34
|
+
"target": "es2020",
|
|
35
|
+
"types": ["vite/client", "node", "react"],
|
|
36
|
+
"lib": ["dom", "esnext"]
|
|
37
|
+
},
|
|
38
|
+
"exclude": ["**/test", "**/dist", "**/types", "**/__tests__"],
|
|
39
|
+
"typeAcquisition": {
|
|
40
|
+
"enable": true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,MAEpC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tamagui-build-test-watch-package",
|
|
3
|
+
"version": "1.110.5",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.mjs",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node ../../../tamagui-build.js",
|
|
9
|
+
"build:bundle": "node ../../../tamagui-build.js --bundle",
|
|
10
|
+
"build:skip-mjs": "node ../../../tamagui-build.js --skip-mjs",
|
|
11
|
+
"build:declaration-root": "node ../../../tamagui-build.js --declaration-root",
|
|
12
|
+
"build:ignore-base-url": "node ../../../tamagui-build.js --ignore-base-url",
|
|
13
|
+
"build:watch": "node ../../../tamagui-build.js --watch",
|
|
14
|
+
"build:minify": "MINIFY=true node ../../../tamagui-build.js",
|
|
15
|
+
"build:target-web": "TAMAGUI_TARGET=web node ../../../tamagui-build.js",
|
|
16
|
+
"build:target-native": "TAMAGUI_TARGET=native node ../../../tamagui-build.js"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tamagui/build": "1.110.5",
|
|
20
|
+
"typescript": "^5.5.2"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"paths": {
|
|
6
|
+
"vxrn": ["packages/vxrn"],
|
|
7
|
+
"@vxrn/*": ["packages/*"]
|
|
8
|
+
},
|
|
9
|
+
"importHelpers": true,
|
|
10
|
+
"allowJs": false,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"downlevelIteration": true,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"esModuleInterop": true,
|
|
18
|
+
"inlineSourceMap": true,
|
|
19
|
+
"preserveSymlinks": true,
|
|
20
|
+
"jsx": "react-jsx",
|
|
21
|
+
"module": "Preserve",
|
|
22
|
+
"moduleResolution": "Bundler",
|
|
23
|
+
"noEmit": false,
|
|
24
|
+
"noEmitOnError": false,
|
|
25
|
+
"noImplicitAny": false,
|
|
26
|
+
"noImplicitReturns": false,
|
|
27
|
+
"noUnusedLocals": false,
|
|
28
|
+
"noUnusedParameters": false,
|
|
29
|
+
"preserveConstEnums": true,
|
|
30
|
+
"removeComments": false,
|
|
31
|
+
"skipLibCheck": true,
|
|
32
|
+
"sourceMap": false,
|
|
33
|
+
"strictNullChecks": true,
|
|
34
|
+
"target": "es2020",
|
|
35
|
+
"types": ["vite/client", "node", "react"],
|
|
36
|
+
"lib": ["dom", "esnext"]
|
|
37
|
+
},
|
|
38
|
+
"exclude": ["**/test", "**/dist", "**/types", "**/__tests__"],
|
|
39
|
+
"typeAcquisition": {
|
|
40
|
+
"enable": true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["src/watch.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,MAE5B,CAAC"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { execSync, spawn } from 'node:child_process'
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, statSync } from 'node:fs'
|
|
3
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { readFile } from 'node:fs/promises'
|
|
6
|
+
|
|
7
|
+
const watchPackagePath = join(__dirname, 'fixtures', 'watch-package')
|
|
8
|
+
const watchDistPath = join(watchPackagePath, 'dist')
|
|
9
|
+
const watchSrcFilePath = join(watchPackagePath, 'src', 'watch.ts')
|
|
10
|
+
|
|
11
|
+
const simplePackagePath = join(__dirname, 'fixtures', 'simple-package')
|
|
12
|
+
const distPath = join(simplePackagePath, 'dist')
|
|
13
|
+
const srcFilePath = join(simplePackagePath, 'src', 'index.ts')
|
|
14
|
+
const distCjsFilePath = join(distPath, 'cjs', 'index.js')
|
|
15
|
+
const watchDistCjsFilePath = join(watchDistPath, 'cjs', 'watch.js')
|
|
16
|
+
const distEsmFilePath = join(distPath, 'esm', 'index.mjs')
|
|
17
|
+
const distTypesFilePath = join(simplePackagePath, 'types', 'index.d.ts')
|
|
18
|
+
// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
|
19
|
+
// console.log({
|
|
20
|
+
// distCjsFilePath,
|
|
21
|
+
// distEsmFilePath,
|
|
22
|
+
// distTypesFilePath,
|
|
23
|
+
// srcFilePath,
|
|
24
|
+
// simplePackagePath,
|
|
25
|
+
// distPath,
|
|
26
|
+
// })
|
|
27
|
+
|
|
28
|
+
describe('tamagui-build integration test', () => {
|
|
29
|
+
beforeAll(() => {
|
|
30
|
+
// Clean up dist directory before starting
|
|
31
|
+
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('should build the package correctly', () => {
|
|
35
|
+
execSync('yarn build', { cwd: simplePackagePath })
|
|
36
|
+
|
|
37
|
+
// Check if the output files exist
|
|
38
|
+
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
39
|
+
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
40
|
+
expect(existsSync(distTypesFilePath)).toBe(true)
|
|
41
|
+
|
|
42
|
+
// Check the content of the output files
|
|
43
|
+
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
44
|
+
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
45
|
+
expect(cjsOutput).toContain('Hello,')
|
|
46
|
+
expect(esmOutput).toContain('Hello,')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('should bundle the package correctly', () => {
|
|
50
|
+
execSync('yarn build:bundle', { cwd: simplePackagePath })
|
|
51
|
+
|
|
52
|
+
// Check if the output files exist
|
|
53
|
+
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
54
|
+
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
55
|
+
|
|
56
|
+
// Check the content of the output files
|
|
57
|
+
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
58
|
+
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
59
|
+
expect(cjsOutput).toContain('Hello,')
|
|
60
|
+
expect(esmOutput).toContain('Hello,')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should skip mjs files when --skip-mjs is used', () => {
|
|
64
|
+
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
65
|
+
execSync('yarn build:skip-mjs', { cwd: simplePackagePath })
|
|
66
|
+
|
|
67
|
+
// Check if the output files exist
|
|
68
|
+
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
69
|
+
expect(existsSync(distEsmFilePath)).toBe(false)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
// it('should set declaration root correctly', () => {
|
|
73
|
+
// execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
74
|
+
|
|
75
|
+
// execSync('yarn build:declaration-root', { cwd: simplePackagePath })
|
|
76
|
+
// // Check if the output files exist
|
|
77
|
+
// expect(existsSync(distTypesFilePath)).toBe(true)
|
|
78
|
+
// // clear up declaration root files
|
|
79
|
+
// execSync('rm -rf index.d.ts && index.d', { cwd: simplePackagePath })
|
|
80
|
+
// })
|
|
81
|
+
|
|
82
|
+
it('should ignore base URL when --ignore-base-url is used', () => {
|
|
83
|
+
execSync('yarn build:ignore-base-url', { cwd: simplePackagePath })
|
|
84
|
+
|
|
85
|
+
// Check if the output files exist
|
|
86
|
+
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
87
|
+
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should rebuild the package on file change when --watch is used', async () => {
|
|
91
|
+
const watchProcess = spawn('yarn', ['build:watch'], { cwd: watchPackagePath })
|
|
92
|
+
|
|
93
|
+
// Cache existing content
|
|
94
|
+
const originalContent = readFileSync(watchSrcFilePath, 'utf-8')
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
await new Promise<void>((resolve, reject) => {
|
|
98
|
+
const timeout = setTimeout(() => {
|
|
99
|
+
reject(new Error('Timeout waiting for build to complete'))
|
|
100
|
+
}, 15000) // 30 second timeout
|
|
101
|
+
|
|
102
|
+
let initialBuildComplete = false
|
|
103
|
+
let fileModified = false
|
|
104
|
+
|
|
105
|
+
watchProcess.stdout.on('data', (data) => {
|
|
106
|
+
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
|
107
|
+
console.log('Watch process output:', data.toString())
|
|
108
|
+
if (data.toString().includes('built tamagui-build-test-watch-package')) {
|
|
109
|
+
if (!initialBuildComplete) {
|
|
110
|
+
initialBuildComplete = true
|
|
111
|
+
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
|
112
|
+
console.log('Initial build complete, modifying file...')
|
|
113
|
+
// Modify the source file
|
|
114
|
+
const newContent = `export const greet = (name: string): string => {
|
|
115
|
+
return \`Hi, \${name}!\`;
|
|
116
|
+
};`
|
|
117
|
+
writeFileSync(watchSrcFilePath, newContent)
|
|
118
|
+
fileModified = true
|
|
119
|
+
} else if (fileModified) {
|
|
120
|
+
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
|
121
|
+
console.log('Rebuild after file modification complete')
|
|
122
|
+
// Check the updated content of the output file
|
|
123
|
+
const output = readFileSync(watchDistCjsFilePath, 'utf-8')
|
|
124
|
+
expect(output).toContain('Hi,')
|
|
125
|
+
|
|
126
|
+
// Change content back to original
|
|
127
|
+
writeFileSync(watchSrcFilePath, originalContent)
|
|
128
|
+
|
|
129
|
+
clearTimeout(timeout)
|
|
130
|
+
resolve()
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
} finally {
|
|
136
|
+
watchProcess.kill()
|
|
137
|
+
}
|
|
138
|
+
}, 15000)
|
|
139
|
+
|
|
140
|
+
it('should generate correct platform-specific output', async () => {
|
|
141
|
+
execSync('yarn build', { cwd: simplePackagePath })
|
|
142
|
+
|
|
143
|
+
const distCjsWebFilePath = join(distPath, 'cjs', 'index.js')
|
|
144
|
+
const distCjsNativeFilePath = join(distPath, 'cjs', 'index.native.js')
|
|
145
|
+
|
|
146
|
+
// Check if the output files exist
|
|
147
|
+
expect(existsSync(distCjsWebFilePath)).toBe(true)
|
|
148
|
+
expect(existsSync(distCjsNativeFilePath)).toBe(true)
|
|
149
|
+
|
|
150
|
+
// Read the content of the output files
|
|
151
|
+
const webOutput = await readFile(distCjsWebFilePath, 'utf-8')
|
|
152
|
+
const nativeOutput = await readFile(distCjsNativeFilePath, 'utf-8')
|
|
153
|
+
|
|
154
|
+
// Check for platform-specific content in web output
|
|
155
|
+
expect(webOutput).toContain('salutation = "Hi"')
|
|
156
|
+
expect(webOutput).not.toContain('salutation = "Hey"')
|
|
157
|
+
expect(webOutput).not.toContain('process.env.TAMAGUI_TARGET')
|
|
158
|
+
|
|
159
|
+
// Check for platform-specific content in native output
|
|
160
|
+
expect(nativeOutput).toContain('salutation = "Hey"')
|
|
161
|
+
expect(nativeOutput).not.toContain('salutation = "Hi"')
|
|
162
|
+
expect(nativeOutput).not.toContain('process.env.TAMAGUI_TARGET')
|
|
163
|
+
|
|
164
|
+
// Check that the common code is present in both outputs
|
|
165
|
+
expect(webOutput).toContain('greet:')
|
|
166
|
+
expect(nativeOutput).toContain('greet:')
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('should minify the output when MINIFY=true is set', () => {
|
|
170
|
+
// Build without minification and cache file sizes
|
|
171
|
+
execSync('yarn build', { cwd: simplePackagePath })
|
|
172
|
+
const originalCjsSize = statSync(distCjsFilePath).size
|
|
173
|
+
const originalEsmSize = statSync(distEsmFilePath).size
|
|
174
|
+
|
|
175
|
+
// Clean up the output
|
|
176
|
+
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
177
|
+
|
|
178
|
+
// Build with minification
|
|
179
|
+
execSync('yarn build:minify', { cwd: simplePackagePath })
|
|
180
|
+
|
|
181
|
+
// Check if the output files exist
|
|
182
|
+
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
183
|
+
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
184
|
+
|
|
185
|
+
// Check if the minified output is smaller
|
|
186
|
+
const minifiedCjsSize = statSync(distCjsFilePath).size
|
|
187
|
+
const minifiedEsmSize = statSync(distEsmFilePath).size
|
|
188
|
+
expect(minifiedCjsSize).toBeLessThan(originalCjsSize)
|
|
189
|
+
expect(minifiedEsmSize).toBeLessThan(originalEsmSize)
|
|
190
|
+
|
|
191
|
+
// Check the content of the minified output files
|
|
192
|
+
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
193
|
+
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
194
|
+
|
|
195
|
+
// Check for absence of excessive whitespace in minified output
|
|
196
|
+
expect(cjsOutput).not.toMatch(/^\s+$/m) // No lines with only whitespace
|
|
197
|
+
expect(esmOutput).not.toMatch(/^\s+$/m) // No lines with only whitespace
|
|
198
|
+
|
|
199
|
+
// Check that the number of lines is reduced
|
|
200
|
+
expect(cjsOutput.split('\n').length).toBeLessThan(10)
|
|
201
|
+
expect(esmOutput.split('\n').length).toBeLessThan(10)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
afterAll(() => {
|
|
205
|
+
// Clean up dist directory after tests
|
|
206
|
+
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
207
|
+
})
|
|
208
|
+
})
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/build",
|
|
3
|
-
"version": "1.110.
|
|
3
|
+
"version": "1.110.5",
|
|
4
4
|
"bin": {
|
|
5
5
|
"tamagui-build": "tamagui-build.js",
|
|
6
6
|
"teesx": "./teesx.sh"
|
|
7
7
|
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "vitest --run"
|
|
10
|
+
},
|
|
8
11
|
"publishConfig": {
|
|
9
12
|
"access": "public"
|
|
10
13
|
},
|
|
11
14
|
"dependencies": {
|
|
12
15
|
"@babel/core": "^7.25.2",
|
|
13
16
|
"@swc/core": "^1.7.21",
|
|
14
|
-
"@tamagui/babel-plugin-fully-specified": "1.110.
|
|
17
|
+
"@tamagui/babel-plugin-fully-specified": "1.110.5",
|
|
15
18
|
"@types/fs-extra": "^9.0.13",
|
|
16
19
|
"babel-plugin-fully-specified": "*",
|
|
17
20
|
"chokidar": "^3.5.2",
|
|
@@ -21,10 +24,11 @@
|
|
|
21
24
|
"execa": "^5.0.0",
|
|
22
25
|
"fast-glob": "^3.2.11",
|
|
23
26
|
"fs-extra": "^11.2.0",
|
|
24
|
-
"lodash.debounce": "^4.0.8"
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
+
"lodash.debounce": "^4.0.8",
|
|
27
28
|
"typescript": "^5.5.2"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
30
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"vitest": "0.34.3"
|
|
33
|
+
}
|
|
30
34
|
}
|
package/tamagui-build.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
|
|
4
4
|
const { transform } = require('@babel/core')
|
|
5
|
-
const exec = require('execa')
|
|
6
5
|
const fs = require('fs-extra')
|
|
7
6
|
const esbuild = require('esbuild')
|
|
8
7
|
const fg = require('fast-glob')
|
|
@@ -11,6 +10,11 @@ const debounce = require('lodash.debounce')
|
|
|
11
10
|
const { basename, dirname } = require('node:path')
|
|
12
11
|
const alias = require('./esbuildAliasPlugin')
|
|
13
12
|
const { es5Plugin } = require('./esbuild-es5')
|
|
13
|
+
const ts = require('typescript')
|
|
14
|
+
const path = require('node:path')
|
|
15
|
+
|
|
16
|
+
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
|
17
|
+
console.log('TypeScript version:', ts.version)
|
|
14
18
|
|
|
15
19
|
const jsOnly = !!process.env.JS_ONLY
|
|
16
20
|
const skipJS = !!(process.env.SKIP_JS || false)
|
|
@@ -64,6 +68,8 @@ const replaceRNWeb = {
|
|
|
64
68
|
},
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
let cachedConfig = null
|
|
72
|
+
|
|
67
73
|
async function clean() {
|
|
68
74
|
try {
|
|
69
75
|
await Promise.allSettled([
|
|
@@ -134,42 +140,41 @@ async function build({ skipTypes } = {}) {
|
|
|
134
140
|
}
|
|
135
141
|
}
|
|
136
142
|
|
|
137
|
-
// const targetDir = `.types${Math.floor(Math.random() * 1_000_000)}`
|
|
138
|
-
// const cleanup = () => {
|
|
139
|
-
// try {
|
|
140
|
-
// fs.removeSync(targetDir)
|
|
141
|
-
// } catch {
|
|
142
|
-
// // ok
|
|
143
|
-
// }
|
|
144
|
-
// }
|
|
145
|
-
|
|
146
|
-
// process.once('beforeExit', cleanup)
|
|
147
|
-
// process.once('SIGINT', cleanup)
|
|
148
|
-
// process.once('SIGTERM', cleanup)
|
|
149
|
-
|
|
150
143
|
async function buildTsc() {
|
|
151
|
-
if (!pkgTypes) return
|
|
152
|
-
if (jsOnly || shouldSkipTypes) return
|
|
144
|
+
if (!pkgTypes || jsOnly || shouldSkipTypes) return
|
|
153
145
|
if (shouldSkipInitialTypes) {
|
|
154
146
|
shouldSkipInitialTypes = false
|
|
155
147
|
return
|
|
156
148
|
}
|
|
157
149
|
|
|
158
150
|
const targetDir = 'types'
|
|
151
|
+
await fs.ensureDir(targetDir)
|
|
152
|
+
|
|
159
153
|
try {
|
|
160
|
-
|
|
161
|
-
await fs.remove('tsconfig.tsbuildinfo')
|
|
162
|
-
await fs.ensureDir(targetDir)
|
|
154
|
+
console.info(`Starting TypeScript compilation for ${pkg.name}`)
|
|
163
155
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const tsProjectFlag = tsProject ? ` --project ${tsProject}` : ''
|
|
167
|
-
const cmd = `tsc${baseUrlFlag}${tsProjectFlag} --outDir ${targetDir} --rootDir src ${declarationToRootFlag}--emitDeclarationOnly --declarationMap`
|
|
156
|
+
const { config, error } = await loadTsConfig()
|
|
157
|
+
if (error) throw error
|
|
168
158
|
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
const compilerOptions = createCompilerOptions(config.options, targetDir)
|
|
160
|
+
const { program, emitResult, diagnostics } = await compileTypeScript(
|
|
161
|
+
config.fileNames,
|
|
162
|
+
compilerOptions
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
reportDiagnostics(diagnostics)
|
|
166
|
+
|
|
167
|
+
if (emitResult.emitSkipped) {
|
|
168
|
+
throw new Error('TypeScript compilation failed')
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
console.info(`TypeScript compilation completed successfully for ${pkg.name}`)
|
|
171
172
|
} catch (err) {
|
|
172
|
-
|
|
173
|
+
if (err.code === 'ENOTFOUND' || err.code === 'ECONNREFUSED') {
|
|
174
|
+
console.error(`Network error during compilation for ${pkg.name}:`, err.message)
|
|
175
|
+
} else {
|
|
176
|
+
console.error(`Error during TypeScript compilation for ${pkg.name}:`, err)
|
|
177
|
+
}
|
|
173
178
|
if (!shouldWatch) {
|
|
174
179
|
process.exit(1)
|
|
175
180
|
}
|
|
@@ -178,6 +183,96 @@ async function buildTsc() {
|
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
185
|
|
|
186
|
+
async function loadTsConfig() {
|
|
187
|
+
if (cachedConfig && shouldWatch) {
|
|
188
|
+
return cachedConfig
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const configPath = ts.findConfigFile(
|
|
192
|
+
'./',
|
|
193
|
+
ts.sys.fileExists,
|
|
194
|
+
tsProject || 'tsconfig.json'
|
|
195
|
+
)
|
|
196
|
+
if (!configPath) {
|
|
197
|
+
return { error: new Error("Could not find a valid 'tsconfig.json'.") }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
201
|
+
if (configFile.error) {
|
|
202
|
+
return {
|
|
203
|
+
error: new Error(`Error reading tsconfig.json: ${configFile.error.messageText}`),
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const parsedCommandLine = ts.parseJsonConfigFileContent(
|
|
208
|
+
configFile.config,
|
|
209
|
+
ts.sys,
|
|
210
|
+
path.dirname(configPath)
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
if (parsedCommandLine.errors.length) {
|
|
214
|
+
return {
|
|
215
|
+
error: new Error(
|
|
216
|
+
`Error parsing tsconfig.json: ${ts.formatDiagnostics(parsedCommandLine.errors, formatHost)}`
|
|
217
|
+
),
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
cachedConfig = { config: parsedCommandLine }
|
|
222
|
+
return cachedConfig
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function createCompilerOptions(baseOptions, targetDir) {
|
|
226
|
+
const compilerOptions = {
|
|
227
|
+
...baseOptions,
|
|
228
|
+
declaration: true,
|
|
229
|
+
emitDeclarationOnly: true,
|
|
230
|
+
declarationMap: true,
|
|
231
|
+
outDir: targetDir,
|
|
232
|
+
rootDir: 'src',
|
|
233
|
+
incremental: true,
|
|
234
|
+
tsBuildInfoFile: 'tsconfig.tsbuildinfo',
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (declarationToRoot) {
|
|
238
|
+
compilerOptions.declarationDir = './'
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (!ignoreBaseUrl) {
|
|
242
|
+
compilerOptions.baseUrl = baseUrl
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return compilerOptions
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function compileTypeScript(fileNames, options) {
|
|
249
|
+
const program = ts.createProgram(fileNames, options)
|
|
250
|
+
const emitResult = program.emit()
|
|
251
|
+
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
|
|
252
|
+
|
|
253
|
+
return { program, emitResult, diagnostics: allDiagnostics }
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const formatHost = {
|
|
257
|
+
getCanonicalFileName: (path) => path,
|
|
258
|
+
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
259
|
+
getNewLine: () => ts.sys.newLine,
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function reportDiagnostics(diagnostics) {
|
|
263
|
+
diagnostics.forEach((diagnostic) => {
|
|
264
|
+
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')
|
|
265
|
+
if (diagnostic.file && diagnostic.start !== undefined) {
|
|
266
|
+
const { line, character } = ts.getLineAndCharacterOfPosition(
|
|
267
|
+
diagnostic.file,
|
|
268
|
+
diagnostic.start
|
|
269
|
+
)
|
|
270
|
+
message = `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`
|
|
271
|
+
}
|
|
272
|
+
console.error(message)
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
|
|
181
276
|
async function buildJs() {
|
|
182
277
|
if (skipJS) {
|
|
183
278
|
return
|