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

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