@tamagui/build 1.88.13 → 1.89.0-1706308641099

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +4 -2
  3. package/tamagui-build.js +52 -21
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "1.88.13",
3
+ "version": "1.89.0-1706308641099",
4
4
  "bin": {
5
5
  "tamagui-build": "tamagui-build.js"
6
6
  },
@@ -12,12 +12,14 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
+ "@babel/core": "^7.23.3",
15
16
  "@types/fs-extra": "^9.0.13",
17
+ "babel-plugin-fully-specified": "*",
16
18
  "chokidar": "^3.5.2",
17
19
  "esbuild": "^0.19.11",
18
20
  "execa": "^5.0.0",
19
21
  "fast-glob": "^3.2.11",
20
- "fs-extra": "^11.1.0",
22
+ "fs-extra": "^11.2.0",
21
23
  "get-tsconfig": "^4.5.0",
22
24
  "lodash.debounce": "^4.0.8",
23
25
  "typescript": "^5.3.3"
package/tamagui-build.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable no-console */
3
3
 
4
+ const { transform } = require('@babel/core')
4
5
  const exec = require('execa')
5
6
  const fs = require('fs-extra')
6
7
  const esbuild = require('esbuild')
@@ -49,12 +50,12 @@ const flatOut = [pkgMain, pkgModule, pkgModuleJSX].filter(Boolean).length === 1
49
50
  const replaceRNWeb = {
50
51
  esm: {
51
52
  from: 'from "react-native"',
52
- to: 'from "react-native-web"'
53
+ to: 'from "react-native-web"',
53
54
  },
54
55
  cjs: {
55
56
  from: 'require("react-native")',
56
- to: 'require("react-native-web")'
57
- }
57
+ to: 'require("react-native-web")',
58
+ },
58
59
  }
59
60
 
60
61
  async function clean() {
@@ -93,12 +94,12 @@ if (shouldClean || shouldCleanBuildOnly) {
93
94
  process.env.DISABLE_AUTORUN = true
94
95
  const rebuild = debounce(build, 100)
95
96
  const chokidar = require('chokidar')
96
-
97
+
97
98
  // do one js build but not types
98
99
  build({
99
100
  skipTypes: true,
100
101
  })
101
-
102
+
102
103
  chokidar
103
104
  // prevent infinite loop but cause race condition if you just build directly
104
105
  .watch('src', {
@@ -110,7 +111,7 @@ if (shouldClean || shouldCleanBuildOnly) {
110
111
  .on('add', rebuild)
111
112
  } else {
112
113
  build()
113
- }
114
+ }
114
115
  }
115
116
 
116
117
  async function build({ skipTypes } = {}) {
@@ -314,10 +315,11 @@ async function buildJs() {
314
315
  pkgModule
315
316
  ? esbuildWriteIfChanged(esmConfig, {
316
317
  platform: 'web',
318
+ mjs: true,
317
319
  })
318
320
  : null,
319
321
 
320
- // web output to esm
322
+ // native output to esm
321
323
  pkgModule
322
324
  ? esbuildWriteIfChanged(esmConfig, {
323
325
  platform: 'native',
@@ -341,6 +343,7 @@ async function buildJs() {
341
343
  },
342
344
  {
343
345
  platform: 'web',
346
+ mjs: true,
344
347
  }
345
348
  )
346
349
  : null,
@@ -378,7 +381,8 @@ async function buildJs() {
378
381
  async function esbuildWriteIfChanged(
379
382
  /** @type { import('esbuild').BuildOptions } */
380
383
  opts,
381
- { platform, env } = {
384
+ { platform, env, mjs } = {
385
+ mjs: false,
382
386
  platform: '',
383
387
  env: '',
384
388
  }
@@ -393,12 +397,12 @@ async function esbuildWriteIfChanged(
393
397
  target: 'node16',
394
398
  format: 'cjs',
395
399
  supported: {
396
- 'logical-assignment': false
400
+ 'logical-assignment': false,
397
401
  },
398
402
  jsx: 'automatic',
399
403
  platform: 'node',
400
404
  }
401
-
405
+
402
406
  /** @type { import('esbuild').BuildOptions } */
403
407
  const webEsbuildSettings = {
404
408
  target: 'esnext',
@@ -412,7 +416,7 @@ async function esbuildWriteIfChanged(
412
416
  },
413
417
  },
414
418
  }
415
-
419
+
416
420
  const built = await esbuild.build({
417
421
  ...opts,
418
422
 
@@ -445,8 +449,8 @@ async function esbuildWriteIfChanged(
445
449
  sourcemap: true,
446
450
  sourcesContent: false,
447
451
  logLevel: 'error',
448
- ...platform === 'native' && nativeEsbuildSettings,
449
- ...platform === 'web' && webEsbuildSettings,
452
+ ...(platform === 'native' && nativeEsbuildSettings),
453
+ ...(platform === 'web' && webEsbuildSettings),
450
454
  define: {
451
455
  ...(platform && {
452
456
  'process.env.TAMAGUI_TARGET': `"${platform}"`,
@@ -520,16 +524,43 @@ async function esbuildWriteIfChanged(
520
524
  outString = outString.replace(/\nimport "[^"]+";\n/g, '\n')
521
525
  }
522
526
 
523
- if (shouldWatch) {
524
- if (
525
- !(await fs.pathExists(outPath)) ||
526
- (await fs.readFile(outPath, 'utf8')) !== outString
527
- ) {
528
- await fs.writeFile(outPath, outString)
527
+ async function flush(contents, path) {
528
+ if (shouldWatch) {
529
+ if (
530
+ !(await fs.pathExists(path)) ||
531
+ (await fs.readFile(path, 'utf8')) !== contents
532
+ ) {
533
+ await fs.writeFile(path, contents)
534
+ }
535
+ } else {
536
+ await fs.writeFile(path, contents)
529
537
  }
530
- } else {
531
- await fs.writeFile(outPath, outString)
532
538
  }
539
+
540
+ await Promise.all([
541
+ flush(outString, outPath),
542
+ (async () => {
543
+ if (platform === 'web' && mjs && outPath.endsWith('.js')) {
544
+ const mjsOutPath = outPath.replace('.js', '.mjs')
545
+ const output = transform(outString, {
546
+ filename: mjsOutPath,
547
+ plugins: [
548
+ [
549
+ 'babel-plugin-fully-specified',
550
+ {
551
+ ensureFileExists: false,
552
+ esExtensionDefault: '.mjs',
553
+ tryExtensions: ['.mjs', '.js'],
554
+ esExtensions: ['.mjs', '.js'],
555
+ },
556
+ ],
557
+ ],
558
+ })
559
+ // output to mjs fully specified
560
+ await flush(output.code, mjsOutPath)
561
+ }
562
+ })(),
563
+ ])
533
564
  })
534
565
  )
535
566
  }