@tamagui/build 1.0.1-beta.94 → 1.0.1-beta.97

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 aeba1fa832e841ac
1
+ @tamagui/build:build: cache hit, replaying output 3d47bff6607fa91f
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "1.0.1-beta.94",
3
+ "version": "1.0.1-beta.97",
4
4
  "bin": {
5
5
  "tamagui-build": "tamagui-build.js"
6
6
  },
package/tamagui-build.js CHANGED
@@ -6,6 +6,7 @@ const esbuild = require('esbuild')
6
6
  const fg = require('fast-glob')
7
7
  const createExternalPlugin = require('./externalNodePlugin')
8
8
  const debounce = require('lodash.debounce')
9
+ const { dirname } = require('path')
9
10
 
10
11
  const jsOnly = !!process.env.JS_ONLY
11
12
  const skipJS = !!(process.env.SKIP_JS || false)
@@ -133,7 +134,7 @@ async function buildJs() {
133
134
  const start = Date.now()
134
135
  return await Promise.all([
135
136
  pkgMain
136
- ? esbuild.build({
137
+ ? esbuildWriteIfChanged({
137
138
  entryPoints: files,
138
139
  outdir: flatOut ? 'dist' : 'dist/cjs',
139
140
  bundle: false,
@@ -150,7 +151,7 @@ async function buildJs() {
150
151
  : null,
151
152
  // dont bundle for tree shaking
152
153
  pkgModule
153
- ? esbuild.build({
154
+ ? esbuildWriteIfChanged({
154
155
  entryPoints: files,
155
156
  outdir: flatOut ? 'dist' : 'dist/esm',
156
157
  sourcemap: true,
@@ -164,7 +165,7 @@ async function buildJs() {
164
165
  })
165
166
  : null,
166
167
  pkgModuleJSX
167
- ? esbuild.build({
168
+ ? esbuildWriteIfChanged({
168
169
  // only diff is jsx preserve and outdir
169
170
  jsx: 'preserve',
170
171
  outdir: flatOut ? 'dist' : 'dist/jsx',
@@ -183,3 +184,33 @@ async function buildJs() {
183
184
  if (process.env.DEBUG) console.log(`built js in ${Date.now() - start}ms`)
184
185
  })
185
186
  }
187
+
188
+ /**
189
+ * esbuild but avoids touching unchanged files to not freak out vite
190
+ * @param {esbuild.BuildOptions} opts
191
+ * @returns {Promise<void>}
192
+ */
193
+ async function esbuildWriteIfChanged(opts) {
194
+ if (shouldWatch) {
195
+ const built = await esbuild.build({ ...opts, write: false })
196
+ if (!built.outputFiles) {
197
+ return
198
+ }
199
+ await Promise.all(
200
+ built.outputFiles.map(async (file) => {
201
+ const outDir = dirname(file.path)
202
+ await fs.ensureDir(outDir)
203
+ const outString = new TextDecoder().decode(file.contents)
204
+ if (
205
+ !(await fs.pathExists(file.path)) ||
206
+ (await fs.readFile(file.path, 'utf8')) !== outString
207
+ ) {
208
+ // console.log('write', file.path)
209
+ await fs.writeFile(file.path, outString)
210
+ }
211
+ })
212
+ )
213
+ } else {
214
+ await esbuild.build(opts)
215
+ }
216
+ }