@tamagui/build 2.7.7 → 3.0.0-beta.643.1
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/README.md +19 -0
- package/package.json +27 -5
- package/pretty-print-errors.js +0 -31
- package/tamagui-build-workspace.js +296 -0
- package/tamagui-build.js +466 -206
- package/tamagui-tsgo.js +14 -0
- package/typescript-native.js +13 -0
- package/.turbo/turbo-test$colon$web.log +0 -68
- package/.turbo/turbo-test.log +0 -44
- package/__tests__/fixtures/js-main-package/.turbo/turbo-build.log +0 -2
- package/__tests__/fixtures/js-main-package/LICENSE +0 -1
- package/__tests__/fixtures/js-main-package/dist/cjs/index.js +0 -24
- package/__tests__/fixtures/js-main-package/dist/cjs/index.js.map +0 -6
- package/__tests__/fixtures/js-main-package/dist/cjs/index.native.js +0 -31
- package/__tests__/fixtures/js-main-package/dist/cjs/index.native.js.map +0 -1
- package/__tests__/fixtures/js-main-package/dist/esm/index.mjs +0 -3
- package/__tests__/fixtures/js-main-package/dist/esm/index.mjs.map +0 -1
- package/__tests__/fixtures/js-main-package/dist/esm/index.native.js +0 -3
- package/__tests__/fixtures/js-main-package/dist/esm/index.native.js.map +0 -1
- package/__tests__/fixtures/js-main-package/package.json +0 -14
- package/__tests__/fixtures/js-main-package/src/index.ts +0 -1
- package/__tests__/fixtures/js-main-package/tsconfig.json +0 -13
- package/__tests__/fixtures/js-main-package/types/index.d.ts +0 -2
- package/__tests__/fixtures/js-main-package/types/index.d.ts.map +0 -1
- package/__tests__/fixtures/simple-package/.turbo/turbo-build.log +0 -2
- package/__tests__/fixtures/simple-package/LICENSE +0 -21
- package/__tests__/fixtures/simple-package/index.d.ts +0 -2
- package/__tests__/fixtures/simple-package/index.d.ts.map +0 -1
- package/__tests__/fixtures/simple-package/package.json +0 -25
- package/__tests__/fixtures/simple-package/src/index.ts +0 -71
- package/__tests__/fixtures/simple-package/src/nativeOnly.ts +0 -3
- package/__tests__/fixtures/simple-package/src/nested/index.ts +0 -1
- package/__tests__/fixtures/simple-package/tsconfig.json +0 -42
- package/__tests__/fixtures/subpath-only-package/.turbo/turbo-build.log +0 -3
- package/__tests__/fixtures/subpath-only-package/dist/cjs/feature.cjs +0 -25
- package/__tests__/fixtures/subpath-only-package/dist/cjs/feature.native.cjs +0 -27
- package/__tests__/fixtures/subpath-only-package/dist/cjs/feature.native.js +0 -29
- package/__tests__/fixtures/subpath-only-package/dist/cjs/feature.native.js.map +0 -1
- package/__tests__/fixtures/subpath-only-package/dist/esm/feature.mjs +0 -4
- package/__tests__/fixtures/subpath-only-package/dist/esm/feature.mjs.map +0 -1
- package/__tests__/fixtures/subpath-only-package/dist/esm/feature.native.js +0 -4
- package/__tests__/fixtures/subpath-only-package/dist/esm/feature.native.js.map +0 -1
- package/__tests__/fixtures/subpath-only-package/types/feature.d.ts.map +0 -11
- package/__tests__/fixtures/watch-package/.turbo/turbo-build.log +0 -2
- package/__tests__/fixtures/watch-package/LICENSE +0 -21
- package/__tests__/fixtures/watch-package/index.d.ts +0 -2
- package/__tests__/fixtures/watch-package/index.d.ts.map +0 -1
- package/__tests__/fixtures/watch-package/package.json +0 -22
- package/__tests__/fixtures/watch-package/src/watch.ts +0 -3
- package/__tests__/fixtures/watch-package/tsconfig.json +0 -42
- package/__tests__/fixtures/watch-package/watch.d.ts +0 -2
- package/__tests__/fixtures/watch-package/watch.d.ts.map +0 -1
- package/__tests__/integration.test.ts +0 -341
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tamagui-build-test-watch-package",
|
|
3
|
-
"version": "2.0.0-rc.0-1769885482630",
|
|
4
|
-
"main": "dist/cjs",
|
|
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": "workspace:*",
|
|
20
|
-
"typescript": "~5.9.2"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["src/watch.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,MAE5B,CAAC"}
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { execSync, spawn } from 'node:child_process'
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync, statSync, readdirSync } 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.cjs')
|
|
15
|
-
const watchDistCjsFilePath = join(watchDistPath, 'cjs', 'watch.cjs')
|
|
16
|
-
const distEsmFilePath = join(distPath, 'esm', 'index.mjs')
|
|
17
|
-
const distTypesFilePath = join(simplePackagePath, 'types', 'index.d.ts')
|
|
18
|
-
const jsMainPackagePath = join(__dirname, 'fixtures', 'js-main-package')
|
|
19
|
-
const jsMainDistPath = join(jsMainPackagePath, 'dist')
|
|
20
|
-
// console.log({
|
|
21
|
-
// distCjsFilePath,
|
|
22
|
-
// distEsmFilePath,
|
|
23
|
-
// distTypesFilePath,
|
|
24
|
-
// srcFilePath,
|
|
25
|
-
// simplePackagePath,
|
|
26
|
-
// distPath,
|
|
27
|
-
// })
|
|
28
|
-
|
|
29
|
-
describe('tamagui-build integration test', () => {
|
|
30
|
-
beforeAll(() => {
|
|
31
|
-
// Clean up dist directory before starting
|
|
32
|
-
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
33
|
-
execSync('rm -rf dist', { cwd: jsMainPackagePath })
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should build the package correctly', () => {
|
|
37
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
38
|
-
|
|
39
|
-
// Check if the output files exist
|
|
40
|
-
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
41
|
-
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
42
|
-
expect(existsSync(distTypesFilePath)).toBe(true)
|
|
43
|
-
|
|
44
|
-
// Check the content of the output files
|
|
45
|
-
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
46
|
-
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
47
|
-
expect(cjsOutput).toContain('Hello,')
|
|
48
|
-
expect(esmOutput).toContain('Hello,')
|
|
49
|
-
expect(esmOutput).toContain("./nested/index.mjs")
|
|
50
|
-
expect(existsSync(join(distPath, 'cjs', 'index.cjs'))).toBe(true)
|
|
51
|
-
expect(existsSync(join(distPath, 'esm', 'index.js'))).toBe(true)
|
|
52
|
-
expect(existsSync(join(distPath, 'jsx', 'index.js'))).toBe(true)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('should bundle the package correctly', () => {
|
|
56
|
-
execSync('bun run build:bundle', { cwd: simplePackagePath })
|
|
57
|
-
|
|
58
|
-
// Check if the output files exist
|
|
59
|
-
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
60
|
-
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
61
|
-
|
|
62
|
-
// Check the content of the output files
|
|
63
|
-
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
64
|
-
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
65
|
-
expect(cjsOutput).toContain('Hello,')
|
|
66
|
-
expect(esmOutput).toContain('Hello,')
|
|
67
|
-
expect(existsSync(join(distPath, 'cjs', 'index.cjs'))).toBe(true)
|
|
68
|
-
expect(existsSync(join(distPath, 'esm', 'index.js'))).toBe(true)
|
|
69
|
-
expect(existsSync(join(distPath, 'jsx', 'index.js'))).toBe(true)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('should skip mjs files when --skip-mjs is used', () => {
|
|
73
|
-
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
74
|
-
execSync('bun run build:skip-mjs', { cwd: simplePackagePath })
|
|
75
|
-
|
|
76
|
-
// Check if the output files exist
|
|
77
|
-
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
78
|
-
expect(existsSync(distEsmFilePath)).toBe(false)
|
|
79
|
-
expect(existsSync(join(distPath, 'cjs', 'index.cjs'))).toBe(true)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('should skip sourcemaps when --skip-sourcemaps is used', () => {
|
|
83
|
-
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
84
|
-
execSync('bun run build:skip-sourcemaps', { cwd: simplePackagePath })
|
|
85
|
-
|
|
86
|
-
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
87
|
-
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
88
|
-
expect(existsSync(distTypesFilePath)).toBe(true)
|
|
89
|
-
expect(existsSync(join(distPath, 'cjs', 'index.cjs.map'))).toBe(false)
|
|
90
|
-
expect(existsSync(join(distPath, 'esm', 'index.mjs.map'))).toBe(false)
|
|
91
|
-
expect(existsSync(join(simplePackagePath, 'types', 'index.d.ts.map'))).toBe(false)
|
|
92
|
-
|
|
93
|
-
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
94
|
-
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
95
|
-
const typesOutput = readFileSync(distTypesFilePath, 'utf-8')
|
|
96
|
-
|
|
97
|
-
expect(cjsOutput).not.toContain('sourceMappingURL=')
|
|
98
|
-
expect(esmOutput).not.toContain('sourceMappingURL=')
|
|
99
|
-
expect(typesOutput).not.toContain('sourceMappingURL=')
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('should ignore base URL when --ignore-base-url is used', () => {
|
|
103
|
-
execSync('bun run build:ignore-base-url', { cwd: simplePackagePath })
|
|
104
|
-
|
|
105
|
-
// Check if the output files exist
|
|
106
|
-
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
107
|
-
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('should rebuild the package on file change when --watch is used', async () => {
|
|
111
|
-
const watchProcess = spawn('bun', ['run', 'build:watch'], { cwd: watchPackagePath })
|
|
112
|
-
|
|
113
|
-
// Cache existing content
|
|
114
|
-
const originalContent = readFileSync(watchSrcFilePath, 'utf-8')
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
await new Promise<void>((resolve, reject) => {
|
|
118
|
-
const timeout = setTimeout(() => {
|
|
119
|
-
reject(new Error('Timeout waiting for build to complete'))
|
|
120
|
-
}, 15000)
|
|
121
|
-
|
|
122
|
-
let initialBuildComplete = false
|
|
123
|
-
let fileModified = false
|
|
124
|
-
const replacementGreeting = originalContent.includes('Hi,') ? 'Hey' : 'Hi'
|
|
125
|
-
|
|
126
|
-
watchProcess.stdout.on('data', (data) => {
|
|
127
|
-
console.log('Watch process output:', data.toString())
|
|
128
|
-
if (data.toString().includes('built tamagui-build-test-watch-package')) {
|
|
129
|
-
if (!initialBuildComplete) {
|
|
130
|
-
initialBuildComplete = true
|
|
131
|
-
console.log('Initial build complete, modifying file...')
|
|
132
|
-
// Modify the source file
|
|
133
|
-
const newContent = `export const greet = (name: string): string => {
|
|
134
|
-
return \`${replacementGreeting}, \${name}!\`;
|
|
135
|
-
};`
|
|
136
|
-
writeFileSync(watchSrcFilePath, newContent)
|
|
137
|
-
fileModified = true
|
|
138
|
-
} else if (fileModified) {
|
|
139
|
-
console.log('Rebuild after file modification complete')
|
|
140
|
-
// Check the updated content of the output file
|
|
141
|
-
const output = readFileSync(watchDistCjsFilePath, 'utf-8')
|
|
142
|
-
expect(output).toContain(`${replacementGreeting},`)
|
|
143
|
-
|
|
144
|
-
// Change content back to original
|
|
145
|
-
writeFileSync(watchSrcFilePath, originalContent)
|
|
146
|
-
|
|
147
|
-
clearTimeout(timeout)
|
|
148
|
-
resolve()
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
} finally {
|
|
154
|
-
writeFileSync(watchSrcFilePath, originalContent)
|
|
155
|
-
watchProcess.kill()
|
|
156
|
-
}
|
|
157
|
-
}, 15000)
|
|
158
|
-
|
|
159
|
-
it('should generate correct platform-specific output', async () => {
|
|
160
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
161
|
-
|
|
162
|
-
const distCjsWebFilePath = join(distPath, 'cjs', 'index.cjs')
|
|
163
|
-
const distCjsNativeFilePath = join(distPath, 'cjs', 'index.native.js')
|
|
164
|
-
|
|
165
|
-
// Check if the output files exist
|
|
166
|
-
expect(existsSync(distCjsWebFilePath)).toBe(true)
|
|
167
|
-
expect(existsSync(distCjsNativeFilePath)).toBe(true)
|
|
168
|
-
|
|
169
|
-
// Read the content of the output files
|
|
170
|
-
const webOutput = await readFile(distCjsWebFilePath, 'utf-8')
|
|
171
|
-
const nativeOutput = await readFile(distCjsNativeFilePath, 'utf-8')
|
|
172
|
-
|
|
173
|
-
// Check for platform-specific content in web output
|
|
174
|
-
expect(webOutput).toContain('salutation = "Hi"')
|
|
175
|
-
expect(webOutput).not.toContain('salutation = "Hey"')
|
|
176
|
-
expect(webOutput).not.toContain('process.env.TAMAGUI_TARGET')
|
|
177
|
-
|
|
178
|
-
// Check for platform-specific content in native output
|
|
179
|
-
expect(nativeOutput).toContain('salutation = "Hey"')
|
|
180
|
-
expect(nativeOutput).not.toContain('salutation = "Hi"')
|
|
181
|
-
expect(nativeOutput).not.toContain('process.env.TAMAGUI_TARGET')
|
|
182
|
-
|
|
183
|
-
// Check that the common code is present in both outputs
|
|
184
|
-
expect(webOutput).toContain('greet:')
|
|
185
|
-
expect(nativeOutput).toContain('greet:')
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it('should prune imports left unused after platform DCE', async () => {
|
|
189
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
190
|
-
|
|
191
|
-
const webOutput = await readFile(join(distPath, 'esm', 'index.mjs'), 'utf-8')
|
|
192
|
-
const nativeOutput = await readFile(join(distPath, 'esm', 'index.native.js'), 'utf-8')
|
|
193
|
-
const nativeOnlyOutput = await readFile(
|
|
194
|
-
join(distPath, 'esm', 'nativeOnly.native.js'),
|
|
195
|
-
'utf-8'
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
expect(webOutput).toContain('web-import-marker')
|
|
199
|
-
expect(webOutput).not.toContain('native-import-marker')
|
|
200
|
-
expect(webOutput).not.toContain('getNativeOnlyMarker')
|
|
201
|
-
expect(webOutput).not.toContain('./nativeOnly')
|
|
202
|
-
expect(webOutput).toContain('process.env.NODE_ENV === "test"')
|
|
203
|
-
expect(webOutput).toContain('process.env.NODE_ENV === "development"')
|
|
204
|
-
|
|
205
|
-
expect(nativeOutput).toContain('getNativeOnlyMarker')
|
|
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')
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('should keep side-effectful native statements outside dev-only guards', async () => {
|
|
231
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
232
|
-
|
|
233
|
-
const nativeOutputPath = join(distPath, 'esm', 'index.native.js')
|
|
234
|
-
const nativeOutput = await readFile(nativeOutputPath, 'utf-8')
|
|
235
|
-
|
|
236
|
-
expect(nativeOutput).toContain('runNativeSideEffect(items);')
|
|
237
|
-
expect(nativeOutput).toContain('native-only-marker')
|
|
238
|
-
expect(nativeOutput).toContain('native-logical-marker')
|
|
239
|
-
expect(nativeOutput).not.toContain('if (runNativeSideEffect(')
|
|
240
|
-
expect(nativeOutput).not.toContain('if (false)')
|
|
241
|
-
expect(nativeOutput).not.toContain('if (true)')
|
|
242
|
-
expect(nativeOutput).not.toContain('runNativeSideEffect(items), process.env.NODE_ENV')
|
|
243
|
-
expect(nativeOutput).not.toContain('web-only-marker')
|
|
244
|
-
expect(nativeOutput).not.toContain('web-logical-marker')
|
|
245
|
-
expect(nativeOutput).not.toContain('&& items.push(')
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
it('should minify the output when MINIFY=true is set', () => {
|
|
249
|
-
// Build without minification and cache file sizes
|
|
250
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
251
|
-
const originalCjsSize = statSync(distCjsFilePath).size
|
|
252
|
-
const originalEsmSize = statSync(distEsmFilePath).size
|
|
253
|
-
const originalCjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
254
|
-
const originalEsmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
255
|
-
|
|
256
|
-
// Clean up the output
|
|
257
|
-
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
258
|
-
|
|
259
|
-
// Build with minification
|
|
260
|
-
execSync('bun run build:minify', { cwd: simplePackagePath })
|
|
261
|
-
|
|
262
|
-
// Check if the output files exist
|
|
263
|
-
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
264
|
-
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
265
|
-
|
|
266
|
-
// Check if the minified output is smaller
|
|
267
|
-
const minifiedCjsSize = statSync(distCjsFilePath).size
|
|
268
|
-
const minifiedEsmSize = statSync(distEsmFilePath).size
|
|
269
|
-
expect(minifiedCjsSize).toBeLessThan(originalCjsSize)
|
|
270
|
-
expect(minifiedEsmSize).toBeLessThan(originalEsmSize)
|
|
271
|
-
|
|
272
|
-
// Check the content of the minified output files
|
|
273
|
-
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
274
|
-
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
275
|
-
|
|
276
|
-
// Check for absence of excessive whitespace in minified output
|
|
277
|
-
expect(cjsOutput).not.toMatch(/^\s+$/m) // No lines with only whitespace
|
|
278
|
-
expect(esmOutput).not.toMatch(/^\s+$/m) // No lines with only whitespace
|
|
279
|
-
|
|
280
|
-
// Check that the number of lines is reduced
|
|
281
|
-
expect(cjsOutput.split('\n').length).toBeLessThanOrEqual(
|
|
282
|
-
originalCjsOutput.split('\n').length
|
|
283
|
-
)
|
|
284
|
-
expect(esmOutput.split('\n').length).toBeLessThanOrEqual(
|
|
285
|
-
originalEsmOutput.split('\n').length
|
|
286
|
-
)
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
it('should clean stale outputs before building', () => {
|
|
290
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
291
|
-
|
|
292
|
-
const staleFilePath = join(distPath, 'esm', 'stale.mjs')
|
|
293
|
-
const staleTypesPath = join(simplePackagePath, 'types', 'stale.d.ts')
|
|
294
|
-
writeFileSync(staleFilePath, 'stale')
|
|
295
|
-
writeFileSync(staleTypesPath, 'stale')
|
|
296
|
-
|
|
297
|
-
expect(existsSync(staleFilePath)).toBe(true)
|
|
298
|
-
expect(existsSync(staleTypesPath)).toBe(true)
|
|
299
|
-
|
|
300
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
301
|
-
|
|
302
|
-
expect(existsSync(staleFilePath)).toBe(false)
|
|
303
|
-
expect(existsSync(staleTypesPath)).toBe(false)
|
|
304
|
-
expect(readdirSync(join(distPath, 'esm'))).not.toContain('stale.mjs')
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
it('should keep only the required js aliases after postprocessing', () => {
|
|
308
|
-
execSync('bun run build', { cwd: simplePackagePath })
|
|
309
|
-
|
|
310
|
-
const distFiles = execSync('find dist -type f | sort', {
|
|
311
|
-
cwd: simplePackagePath,
|
|
312
|
-
encoding: 'utf-8',
|
|
313
|
-
})
|
|
314
|
-
.trim()
|
|
315
|
-
.split('\n')
|
|
316
|
-
.map((file) => file.replace(/^dist\//, ''))
|
|
317
|
-
|
|
318
|
-
expect(distFiles).toContain('cjs/index.cjs')
|
|
319
|
-
expect(distFiles).toContain('esm/index.js')
|
|
320
|
-
expect(distFiles).toContain('esm/index.js.map')
|
|
321
|
-
expect(distFiles).toContain('jsx/index.js')
|
|
322
|
-
expect(distFiles).toContain('jsx/index.js.map')
|
|
323
|
-
expect(distFiles).toContain('cjs/index.cjs')
|
|
324
|
-
expect(distFiles).toContain('esm/index.mjs')
|
|
325
|
-
expect(distFiles).toContain('esm/nested/index.mjs')
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
it('should keep explicit cjs .js mains as final output', () => {
|
|
329
|
-
execSync('bun run build', { cwd: jsMainPackagePath })
|
|
330
|
-
|
|
331
|
-
expect(existsSync(join(jsMainDistPath, 'cjs', 'index.js'))).toBe(true)
|
|
332
|
-
expect(existsSync(join(jsMainDistPath, 'cjs', 'index.mjs'))).toBe(false)
|
|
333
|
-
expect(existsSync(join(jsMainDistPath, 'esm', 'index.mjs'))).toBe(true)
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
afterAll(() => {
|
|
337
|
-
// Clean up dist directory after tests
|
|
338
|
-
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
339
|
-
execSync('rm -rf dist', { cwd: jsMainPackagePath })
|
|
340
|
-
})
|
|
341
|
-
})
|