@tamagui/build 1.0.1-beta.99 → 1.0.1-rc.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "1.0.1-beta.99",
3
+ "version": "1.0.1-rc.0",
4
4
  "bin": {
5
5
  "tamagui-build": "tamagui-build.js"
6
6
  },
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "chokidar": "^3.5.2",
16
- "esbuild": "^0.14.48",
16
+ "esbuild": "^0.15.11",
17
17
  "execa": "^5.0.0",
18
18
  "fast-glob": "^3.2.11",
19
19
  "fs-extra": "^10.1.0",
package/tamagui-build.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console */
2
3
 
3
4
  const exec = require('execa')
4
5
  const fs = require('fs-extra')
@@ -10,7 +11,9 @@ const { dirname } = require('path')
10
11
 
11
12
  const jsOnly = !!process.env.JS_ONLY
12
13
  const skipJS = !!(process.env.SKIP_JS || false)
13
- const shouldSkipTypes = !!(process.argv.includes('skip-types') || process.env.SKIP_TYPES)
14
+ const shouldSkipTypes = !!(process.argv.includes('--skip-types') || process.env.SKIP_TYPES)
15
+ const shouldBundle = !!process.argv.includes('--bundle')
16
+ const shouldBundleNodeModules = !!process.argv.includes('--bundle-modules')
14
17
  const shouldClean = !!process.argv.includes('clean')
15
18
  const shouldCleanBuildOnly = !!process.argv.includes('clean:build')
16
19
  const shouldWatch = process.argv.includes('--watch')
@@ -20,21 +23,32 @@ let shouldSkipInitialTypes = !!process.env.SKIP_TYPES_INITIAL
20
23
  const pkgMain = pkg.main
21
24
  const pkgModule = pkg.module
22
25
  const pkgModuleJSX = pkg['module:jsx']
26
+ const pkgTypes = Boolean(pkg['types'] || pkg['typings'])
23
27
 
24
28
  const flatOut = [pkgMain, pkgModule, pkgModuleJSX].filter(Boolean).length === 1
25
29
 
26
30
  async function clean() {
27
31
  try {
28
- await Promise.allSettled([fs.remove('.turbo'), fs.remove('types'), fs.remove('dist')])
29
- } catch {}
32
+ await Promise.allSettled([
33
+ //
34
+ fs.remove('.turbo'),
35
+ fs.remove('.ultra.cache.json'),
36
+ fs.remove('types'),
37
+ fs.remove('dist'),
38
+ ])
39
+ } catch {
40
+ // ok
41
+ }
30
42
  if (shouldCleanBuildOnly) {
31
- console.log('» cleaned', pkg.name)
43
+ console.log('🔹 cleaned', pkg.name)
32
44
  process.exit(0)
33
45
  }
34
46
  try {
35
47
  await Promise.allSettled([fs.remove('node_modules')])
36
- } catch {}
37
- console.log('» cleaned', pkg.name)
48
+ } catch {
49
+ // ok
50
+ }
51
+ console.log('🔹 cleaned', pkg.name)
38
52
  process.exit(0)
39
53
  }
40
54
 
@@ -67,7 +81,7 @@ if (shouldWatch) {
67
81
  build()
68
82
 
69
83
  async function build() {
70
- if (process.env.DEBUG) console.log('»', pkg.name)
84
+ if (process.env.DEBUG) console.log('🔹', pkg.name)
71
85
  try {
72
86
  const start = Date.now()
73
87
  await Promise.all([
@@ -81,27 +95,42 @@ async function build() {
81
95
  }
82
96
  }
83
97
 
98
+ // const targetDir = `.types${Math.floor(Math.random() * 1_000_000)}`
99
+ // const cleanup = () => {
100
+ // try {
101
+ // fs.removeSync(targetDir)
102
+ // } catch {
103
+ // // ok
104
+ // }
105
+ // }
106
+
107
+ // process.once('beforeExit', cleanup)
108
+ // process.once('SIGINT', cleanup)
109
+ // process.once('SIGTERM', cleanup)
110
+
84
111
  async function buildTsc() {
112
+ if (!pkgTypes) return
85
113
  if (jsOnly || shouldSkipTypes) return
86
114
  if (shouldSkipInitialTypes) {
87
115
  shouldSkipInitialTypes = false
88
116
  return
89
117
  }
90
118
 
91
- function buildNoMap() {
92
- return exec(
93
- 'npx',
94
- `tsc --baseUrl . --outDir types --rootDir src --declaration --emitDeclarationOnly`.split(' ')
95
- )
96
- }
97
-
98
- function buildWithMap() {
99
- return exec(
100
- 'npx',
101
- `tsc --baseUrl . --outDir types --rootDir src --declaration --emitDeclarationOnly --declarationMap`.split(
102
- ' '
103
- )
104
- )
119
+ async function buildThenCopy() {
120
+ if (!(await fs.pathExists(`tsconfig.json`))) {
121
+ throw new Error(`No tsconfig.json found`)
122
+ }
123
+ const targetDir = 'types'
124
+ try {
125
+ // typescripts build cache messes up when doing declarationOnly
126
+ await fs.remove('tsconfig.tsbuildinfo')
127
+ await fs.ensureDir(targetDir)
128
+ const cmd = `tsc --baseUrl . --outDir ${targetDir} --rootDir src --emitDeclarationOnly --declarationMap`
129
+ // console.log('\x1b[2m$', `npx ${cmd}`)
130
+ await exec('npx', cmd.split(' '))
131
+ } finally {
132
+ await fs.remove('tsconfig.tsbuildinfo')
133
+ }
105
134
  }
106
135
 
107
136
  // NOTE:
@@ -109,23 +138,18 @@ async function buildTsc() {
109
138
  // but to build things nicely we need here to reset a few things:
110
139
  // baseUrl: ., outDir: types, rootDir: src
111
140
  // for best of both worlds
112
- try {
113
- await buildWithMap()
114
- } finally {
115
- // if no types folder, patch a typescript bug...
116
- if (!(await fs.pathExists('types'))) {
117
- console.warn('BUG re-run without declaration first fixes no output bug...')
118
- await buildNoMap()
119
- await buildWithMap()
120
- }
121
- }
141
+
142
+ // there's a bug with typescript where outputting within the same dir just doesn't output for whatever reason
143
+ // i have a hunch it's some cache thing, because if i give a new outDir it works
144
+ // so fixing by always giving a random tmp outdir, and then copying
145
+ await buildThenCopy()
122
146
  }
123
147
 
124
148
  async function buildJs() {
125
149
  if (skipJS) {
126
150
  return
127
151
  }
128
- let files = (await fg(['src/**/*.(m)?ts(x)?', 'src/**/*.css'])).filter(
152
+ let files = (await fg(['src/**/*.(m)?[jt]s(x)?', 'src/**/*.css'])).filter(
129
153
  (x) => !x.includes('.d.ts')
130
154
  )
131
155
  const externalPlugin = createExternalPlugin({
@@ -137,31 +161,35 @@ async function buildJs() {
137
161
  ? esbuildWriteIfChanged({
138
162
  entryPoints: files,
139
163
  outdir: flatOut ? 'dist' : 'dist/cjs',
140
- bundle: false,
164
+ bundle: shouldBundle,
141
165
  sourcemap: true,
142
166
  target: 'node14',
143
167
  keepNames: false,
144
168
  format: 'cjs',
145
169
  color: true,
170
+ allowOverwrite: true,
171
+ jsx: 'automatic',
146
172
  logLevel: 'error',
147
- plugins: [externalPlugin],
173
+ plugins: shouldBundleNodeModules ? [] : [externalPlugin],
148
174
  minify: false,
149
175
  platform: 'node',
150
176
  })
151
177
  : null,
152
- // dont bundle for tree shaking
153
178
  pkgModule
154
179
  ? esbuildWriteIfChanged({
155
180
  entryPoints: files,
156
181
  outdir: flatOut ? 'dist' : 'dist/esm',
182
+ bundle: shouldBundle,
157
183
  sourcemap: true,
158
184
  target: 'node16',
159
185
  keepNames: false,
186
+ jsx: 'automatic',
187
+ allowOverwrite: true,
160
188
  format: 'esm',
161
189
  color: true,
162
190
  logLevel: 'error',
163
191
  minify: false,
164
- platform: 'neutral',
192
+ platform: shouldBundle ? 'node' : 'neutral',
165
193
  })
166
194
  : null,
167
195
  pkgModuleJSX
@@ -170,8 +198,10 @@ async function buildJs() {
170
198
  jsx: 'preserve',
171
199
  outdir: flatOut ? 'dist' : 'dist/jsx',
172
200
  entryPoints: files,
201
+ bundle: shouldBundle,
173
202
  sourcemap: true,
174
- target: 'es2019',
203
+ allowOverwrite: true,
204
+ target: 'es2020',
175
205
  keepNames: false,
176
206
  format: 'esm',
177
207
  color: true,
@@ -1 +0,0 @@
1
- @tamagui/build:build: cache hit, replaying output 1c47fd3f5c7392cf
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": [],
4
- "files": [],
5
- "compilerOptions": {
6
- "composite": true,
7
- "jsx": "preserve"
8
- },
9
- }