@tamagui/build 1.0.1-beta.75 → 1.0.1-beta.78

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 +1 @@
1
- @tamagui/build:build: cache hit, replaying output c00fa637df78f994
1
+ @tamagui/build:build: cache hit, replaying output 8d9a65547c8e741a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "1.0.1-beta.75",
3
+ "version": "1.0.1-beta.78",
4
4
  "bin": {
5
5
  "tamagui-build": "tamagui-build.js"
6
6
  },
@@ -15,11 +15,10 @@
15
15
  "chokidar": "^3.5.2",
16
16
  "esbuild": "^0.14.36",
17
17
  "execa": "^5.0.0",
18
- "fast-glob": "^3.2.7",
19
- "fs-extra": "^9.1.0",
20
- "json5": "^2.2.0",
18
+ "fast-glob": "^3.2.11",
19
+ "fs-extra": "^10.1.0",
21
20
  "lodash.debounce": "^4.0.8",
22
- "typescript": "^4.7.2"
21
+ "typescript": "^4.7.4"
23
22
  },
24
23
  "devDependencies": {
25
24
  "@types/fs-extra": "^9.0.13"
package/tamagui-build.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const exec = require('execa')
4
4
  const fs = require('fs-extra')
5
- const json5 = require('json5')
6
5
  const esbuild = require('esbuild')
7
6
  const fg = require('fast-glob')
8
7
  const createExternalPlugin = require('./externalNodePlugin')
@@ -16,126 +15,160 @@ const shouldCleanBuildOnly = !!process.argv.includes('clean:build')
16
15
  const shouldWatch = process.argv.includes('--watch')
17
16
 
18
17
  const pkg = fs.readJSONSync('./package.json')
18
+ let shouldSkipInitialTypes = !!process.env.SKIP_TYPES_INITIAL
19
+ const pkgMain = pkg.main
20
+ const pkgModule = pkg.module
21
+ const pkgModuleJSX = pkg['module:jsx']
19
22
 
20
- if (shouldClean || shouldCleanBuildOnly) {
21
- ;(async () => {
22
- try {
23
- await Promise.allSettled([fs.remove('.turbo'), fs.remove('types'), fs.remove('dist')])
24
- } catch {}
25
- if (shouldCleanBuildOnly) {
26
- console.log( cleaned', pkg.name)
27
- process.exit(0)
28
- }
29
- try {
30
- await Promise.allSettled([fs.remove('node_modules')])
31
- } catch {}
23
+ const flatOut = [pkgMain, pkgModule, pkgModuleJSX].filter(Boolean).length === 1
24
+
25
+ async function clean() {
26
+ try {
27
+ await Promise.allSettled([fs.remove('.turbo'), fs.remove('types'), fs.remove('dist')])
28
+ } catch {}
29
+ if (shouldCleanBuildOnly) {
32
30
  console.log('» cleaned', pkg.name)
33
31
  process.exit(0)
34
- })()
35
- } else {
36
- let shouldSkipInitialTypes = !!process.env.SKIP_TYPES_INITIAL
32
+ }
33
+ try {
34
+ await Promise.allSettled([fs.remove('node_modules')])
35
+ } catch {}
36
+ console.log('» cleaned', pkg.name)
37
+ process.exit(0)
38
+ }
37
39
 
38
- const pkgMain = pkg.main
39
- const pkgModule = pkg.module
40
+ if (shouldClean || shouldCleanBuildOnly) {
41
+ clean().then(() => {
42
+ process.exit(0)
43
+ })
44
+ return
45
+ }
40
46
 
41
- async function build() {
42
- console.log('»', pkg.name)
43
- const x = Date.now()
44
- let files = (await fg(['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.css'])).filter(
45
- (x) => !x.includes('.d.ts')
46
- )
47
+ if (shouldWatch) {
48
+ process.env.IS_WATCHING = true
49
+ process.env.DISABLE_AUTORUN = true
50
+ build().then(() => {
51
+ const rebuild = debounce(build, 100)
52
+ const chokidar = require('chokidar')
53
+ chokidar
54
+ // prevent infinite loop but cause race condition if you just build directly
55
+ .watch('src', {
56
+ persistent: true,
57
+ alwaysStat: true,
58
+ ignoreInitial: true,
59
+ })
60
+ .on('change', rebuild)
61
+ .on('add', rebuild)
62
+ })
63
+ return
64
+ }
47
65
 
48
- if (process.env.NO_CLEAN) {
49
- console.log('skip typecheck')
50
- } else {
51
- fs.existsSync('tsconfig.tsbuildinfo') && fs.rmSync('tsconfig.tsbuildinfo')
52
- }
66
+ build()
53
67
 
54
- async function buildTsc() {
55
- if (jsOnly || shouldSkipTypes) return
56
- if (shouldSkipInitialTypes) {
57
- shouldSkipInitialTypes = false
58
- return
59
- }
68
+ async function build() {
69
+ if (process.env.DEBUG) console.log('»', pkg.name)
70
+ try {
71
+ const start = Date.now()
72
+ await Promise.all([
73
+ //
74
+ buildTsc(),
75
+ buildJs(),
76
+ ])
77
+ console.log('built', pkg.name, 'in', Date.now() - start, 'ms')
78
+ } catch (error) {
79
+ console.log(error.message)
80
+ process.exit(1)
81
+ }
82
+ }
83
+
84
+ async function buildTsc() {
85
+ if (jsOnly || shouldSkipTypes) return
86
+ if (shouldSkipInitialTypes) {
87
+ shouldSkipInitialTypes = false
88
+ return
89
+ }
60
90
 
61
- // NOTE:
62
- // for Intellisense to work in monorepo you need baseUrl: "../.."
63
- // but to build things nicely we need here to reset a few things:
64
- // baseUrl: ., outDir: types, rootDir: src
65
- // now we can have the best of both worlds
91
+ function buildNoMap() {
92
+ return exec(
93
+ 'npx',
94
+ `tsc --baseUrl . --outDir types --rootDir src --declaration --emitDeclarationOnly`.split(' ')
95
+ )
96
+ }
66
97
 
67
- // NOTE: to get intellisense to *not* suggest importing from the index file when it re-exports another package...
68
- // (like tamagui does with @tamagui/core...)
69
- // we add `exclude: ['src/index.ts']` to the tsconfig.json which fixes that
70
- // but then it causes it to not export the types out from index... so....
71
- // we do a stupid, stupid thing to re-write it temporarily without it before build. then restore it after
72
- // honestly hate typescript config all around but this seems to work so fuck it
73
- const tsConfOg = await fs.readFile('tsconfig.json')
74
- const tsConfJSON = json5.parse(tsConfOg)
75
- if (tsConfJSON.exclude && tsConfJSON.exclude.includes('src/index.ts')) {
76
- tsConfJSON.exclude = tsConfJSON.exclude.filter((x) => x !== 'src/index.ts')
77
- await fs.writeJSON('tsconfig.json', tsConfJSON)
78
- }
79
- try {
80
- await exec('npx', [
81
- 'tsc',
82
- '--baseUrl',
83
- '.',
84
- '--outDir',
85
- 'types',
86
- '--rootDir',
87
- 'src',
88
- '--declaration',
89
- '--emitDeclarationOnly',
90
- '--declarationMap',
91
- ])
92
- } finally {
93
- // restore
94
- await fs.writeFile('tsconfig.json', tsConfOg)
95
- }
98
+ function buildWithMap() {
99
+ return exec(
100
+ 'npx',
101
+ `tsc --baseUrl . --outDir types --rootDir src --declaration --emitDeclarationOnly --declarationMap`.split(
102
+ ' '
103
+ )
104
+ )
105
+ }
106
+
107
+ // NOTE:
108
+ // for Intellisense to work in monorepo you need baseUrl: "../.."
109
+ // but to build things nicely we need here to reset a few things:
110
+ // baseUrl: ., outDir: types, rootDir: src
111
+ // 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()
96
120
  }
121
+ }
122
+ }
97
123
 
98
- async function buildJs() {
99
- if (skipJS) {
100
- return
101
- }
102
- const start = Date.now()
103
- return await Promise.all([
104
- pkgMain
105
- ? esbuild.build({
106
- entryPoints: files,
107
- outdir: 'dist/cjs',
108
- bundle: false,
109
- sourcemap: true,
110
- target: 'node14',
111
- keepNames: false,
112
- format: 'cjs',
113
- color: true,
114
- logLevel: 'error',
115
- plugins: [externalPlugin],
116
- minify: false,
117
- platform: 'node',
118
- })
119
- : null,
120
- // dont bundle for tree shaking
121
- pkgModule
122
- ? esbuild.build({
123
- entryPoints: files,
124
- outdir: 'dist/esm',
125
- sourcemap: true,
126
- target: 'es2019',
127
- keepNames: false,
128
- format: 'esm',
129
- color: true,
130
- logLevel: 'error',
131
- minify: false,
132
- platform: 'neutral',
133
- })
134
- : null,
135
- esbuild.build({
124
+ async function buildJs() {
125
+ if (skipJS) {
126
+ return
127
+ }
128
+ let files = (await fg(['src/**/*.(m)?ts(x)?', 'src/**/*.css'])).filter(
129
+ (x) => !x.includes('.d.ts')
130
+ )
131
+ const externalPlugin = createExternalPlugin({
132
+ skipNodeModulesBundle: true,
133
+ })
134
+ const start = Date.now()
135
+ return await Promise.all([
136
+ pkgMain
137
+ ? esbuild.build({
138
+ entryPoints: files,
139
+ outdir: flatOut ? 'dist' : 'dist/cjs',
140
+ bundle: false,
141
+ sourcemap: true,
142
+ target: 'node14',
143
+ keepNames: false,
144
+ format: 'cjs',
145
+ color: true,
146
+ logLevel: 'error',
147
+ plugins: [externalPlugin],
148
+ minify: false,
149
+ platform: 'node',
150
+ })
151
+ : null,
152
+ // dont bundle for tree shaking
153
+ pkgModule
154
+ ? esbuild.build({
155
+ entryPoints: files,
156
+ outdir: flatOut ? 'dist' : 'dist/esm',
157
+ sourcemap: true,
158
+ target: 'node16',
159
+ keepNames: false,
160
+ format: 'esm',
161
+ color: true,
162
+ logLevel: 'error',
163
+ minify: false,
164
+ platform: 'neutral',
165
+ })
166
+ : null,
167
+ pkgModuleJSX
168
+ ? esbuild.build({
136
169
  // only diff is jsx preserve and outdir
137
170
  jsx: 'preserve',
138
- outdir: 'dist/jsx',
171
+ outdir: flatOut ? 'dist' : 'dist/jsx',
139
172
  entryPoints: files,
140
173
  sourcemap: false,
141
174
  target: 'es2019',
@@ -145,47 +178,9 @@ if (shouldClean || shouldCleanBuildOnly) {
145
178
  logLevel: 'error',
146
179
  minify: false,
147
180
  platform: 'neutral',
148
- }),
149
- ]).then(() => {
150
- console.log(`built js in ${Date.now() - start}ms`)
151
- })
152
- }
153
-
154
- const externalPlugin = createExternalPlugin({
155
- skipNodeModulesBundle: true,
156
- })
157
-
158
- try {
159
- await Promise.all([
160
- //
161
- buildTsc(),
162
- buildJs(),
163
- ])
164
- } catch (error) {
165
- console.log('error', error)
166
- } finally {
167
- console.log('built in', `${(Date.now() - x) / 1000}s`)
168
- }
169
- }
170
-
171
- if (shouldWatch) {
172
- const path = require('path')
173
- process.env.IS_WATCHING = true
174
- process.env.DISABLE_AUTORUN = true
175
- build().then(() => {
176
- const rebuild = debounce(build, 100)
177
- const chokidar = require('chokidar')
178
- chokidar
179
- // prevent infinite loop but cause race condition if you just build directly
180
- .watch('src', {
181
- persistent: true,
182
- alwaysStat: true,
183
- ignoreInitial: true,
184
181
  })
185
- .on('change', rebuild)
186
- .on('add', rebuild)
187
- })
188
- } else {
189
- build()
190
- }
182
+ : null,
183
+ ]).then(() => {
184
+ if (process.env.DEBUG) console.log(`built js in ${Date.now() - start}ms`)
185
+ })
191
186
  }