@tamagui/build 1.111.3 → 1.111.5

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/README.md CHANGED
@@ -32,7 +32,7 @@ It assumes your package.json looks something like this:
32
32
  "exports": {
33
33
  "./package.json": "./package.json",
34
34
  ".": {
35
- "react-native-import": "./dist/esm/index.native.js",
35
+ "react-native-import": "./dist/esm/index.native.mjs",
36
36
  "react-native": "./dist/cjs/index.native.js",
37
37
  "types": "./types/index.d.ts",
38
38
  "import": "./dist/esm/index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tamagui-build-test-simple-tpackage",
3
- "version": "1.111.3",
3
+ "version": "1.111.5",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "types": "dist/types/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "build:target-native": "TAMAGUI_TARGET=native node ../../../tamagui-build.js"
17
17
  },
18
18
  "devDependencies": {
19
- "@tamagui/build": "1.111.3",
19
+ "@tamagui/build": "1.111.5",
20
20
  "typescript": "^5.5.2"
21
21
  }
22
22
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tamagui-build-test-watch-package",
3
- "version": "1.111.3",
3
+ "version": "1.111.5",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "types": "dist/types/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "build:target-native": "TAMAGUI_TARGET=native node ../../../tamagui-build.js"
17
17
  },
18
18
  "devDependencies": {
19
- "@tamagui/build": "1.111.3",
19
+ "@tamagui/build": "1.111.5",
20
20
  "typescript": "^5.5.2"
21
21
  }
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "1.111.3",
3
+ "version": "1.111.5",
4
4
  "bin": {
5
5
  "tamagui-build": "tamagui-build.js",
6
6
  "teesx": "./teesx.sh"
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "@babel/core": "^7.25.2",
16
16
  "@swc/core": "^1.7.21",
17
- "@tamagui/babel-plugin-fully-specified": "1.111.3",
17
+ "@tamagui/babel-plugin-fully-specified": "1.111.5",
18
18
  "@types/fs-extra": "^9.0.13",
19
19
  "babel-plugin-fully-specified": "*",
20
20
  "chokidar": "^3.5.2",
package/tamagui-build.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable no-console */
3
3
 
4
4
  const { transform } = require('@babel/core')
5
- const fs = require('fs-extra')
5
+ const FSE = require('fs-extra')
6
6
  const esbuild = require('esbuild')
7
7
  const fg = require('fast-glob')
8
8
  const createExternalPlugin = require('./externalNodePlugin')
@@ -41,7 +41,7 @@ const tsProject =
41
41
  const exclude =
42
42
  exludeIndex > -1 && process.argv[exludeIndex + 1] ? process.argv[exludeIndex + 1] : null
43
43
 
44
- const pkg = fs.readJSONSync('./package.json')
44
+ const pkg = FSE.readJSONSync('./package.json')
45
45
  let shouldSkipInitialTypes = !!process.env.SKIP_TYPES_INITIAL
46
46
  const pkgMain = pkg.main
47
47
  const pkgSource = pkg.source
@@ -71,10 +71,10 @@ async function clean() {
71
71
  try {
72
72
  await Promise.allSettled([
73
73
  //
74
- fs.remove('.turbo'),
75
- fs.remove('node_modules'),
76
- fs.remove('types'),
77
- fs.remove('dist'),
74
+ FSE.remove('.turbo'),
75
+ FSE.remove('node_modules'),
76
+ FSE.remove('types'),
77
+ FSE.remove('dist'),
78
78
  ])
79
79
  } catch {
80
80
  // ok
@@ -84,7 +84,7 @@ async function clean() {
84
84
  process.exit(0)
85
85
  }
86
86
  try {
87
- await Promise.allSettled([fs.remove('node_modules')])
87
+ await Promise.allSettled([FSE.remove('node_modules')])
88
88
  } catch {
89
89
  // ok
90
90
  }
@@ -145,7 +145,7 @@ async function buildTsc() {
145
145
  }
146
146
 
147
147
  const targetDir = 'types'
148
- await fs.ensureDir(targetDir)
148
+ await FSE.ensureDir(targetDir)
149
149
 
150
150
  try {
151
151
  const { config, error } = await loadTsConfig()
@@ -172,7 +172,7 @@ async function buildTsc() {
172
172
  process.exit(1)
173
173
  }
174
174
  } finally {
175
- await fs.remove('tsconfig.tsbuildinfo')
175
+ await FSE.remove('tsconfig.tsbuildinfo')
176
176
  }
177
177
  }
178
178
 
@@ -364,7 +364,7 @@ async function buildJs() {
364
364
 
365
365
  if (pkgSource) {
366
366
  try {
367
- const contents = await fs.readFile(pkgSource)
367
+ const contents = await FSE.readFile(pkgSource)
368
368
  if (contents.slice(0, 40).includes('GITCRYPT')) {
369
369
  // encrypted file, ignore
370
370
  console.info(`This package is encrypted, skipping`)
@@ -554,8 +554,8 @@ async function esbuildWriteIfChanged(
554
554
 
555
555
  treeShaking: true,
556
556
  minifySyntax: true,
557
- // minifyIdentifiers: true,
558
557
  write: false,
558
+
559
559
  color: true,
560
560
  allowOverwrite: true,
561
561
  keepNames: false,
@@ -593,123 +593,142 @@ async function esbuildWriteIfChanged(
593
593
 
594
594
  const cleanupNonMjsFiles = []
595
595
 
596
- await Promise.all(
597
- built.outputFiles.map(async (file) => {
598
- let outPath = file.path
599
-
600
- if (outPath.endsWith('.js') || outPath.endsWith('.js.map')) {
601
- const [_, extPlatform] =
602
- outPath.match(/(web|native|ios|android)\.js(\.map)?$/) ?? []
596
+ async function flush(path, contents) {
597
+ if (shouldWatch) {
598
+ if (
599
+ !(await FSE.pathExists(path)) ||
600
+ (await FSE.readFile(path, 'utf8')) !== contents
601
+ ) {
602
+ await FSE.outputFile(path, contents, 'utf8')
603
+ return true
604
+ }
605
+ } else {
606
+ await FSE.outputFile(path, contents, 'utf8')
607
+ return true
608
+ }
609
+ }
603
610
 
604
- if (platform === 'native') {
605
- if (!extPlatform && nativeFilesMap[outPath.replace('.js', '.native.js')]) {
606
- // if native exists, avoid outputting non-native
607
- return
611
+ const outputs = (
612
+ await Promise.all(
613
+ built.outputFiles.map(async (file) => {
614
+ let path = file.path
615
+
616
+ if (path.endsWith('.js') || path.endsWith('.js.map')) {
617
+ const [_, extPlatform] =
618
+ path.match(/(web|native|ios|android)\.js(\.map)?$/) ?? []
619
+
620
+ if (platform === 'native') {
621
+ if (!extPlatform && nativeFilesMap[path.replace('.js', '.native.js')]) {
622
+ // if native exists, avoid outputting non-native
623
+ return
624
+ }
625
+
626
+ if (extPlatform === 'web') {
627
+ return
628
+ }
629
+ if (!extPlatform) {
630
+ path = path.replace('.js', '.native.js')
631
+ }
608
632
  }
609
633
 
610
- if (extPlatform === 'web') {
611
- return
612
- }
613
- if (!extPlatform) {
614
- outPath = outPath.replace('.js', '.native.js')
634
+ if (platform === 'web') {
635
+ if (
636
+ extPlatform === 'native' ||
637
+ extPlatform === 'android' ||
638
+ extPlatform === 'ios'
639
+ ) {
640
+ return
641
+ }
615
642
  }
616
643
  }
617
644
 
645
+ let contents = new TextDecoder().decode(file.contents)
646
+
618
647
  if (platform === 'web') {
619
- if (
620
- extPlatform === 'native' ||
621
- extPlatform === 'android' ||
622
- extPlatform === 'ios'
623
- ) {
624
- return
648
+ const rnWebReplacer = replaceRNWeb[opts.format]
649
+ if (rnWebReplacer) {
650
+ contents = contents.replaceAll(rnWebReplacer.from, rnWebReplacer.to)
625
651
  }
626
652
  }
627
- }
628
-
629
- const outDir = dirname(outPath)
630
653
 
631
- await fs.ensureDir(outDir)
632
- let outString = new TextDecoder().decode(file.contents)
654
+ if (pkgRemoveSideEffects && isESM) {
655
+ const allowedSideEffects = pkg.sideEffects || []
656
+
657
+ const result = []
658
+ const lines = contents.split('\n')
659
+ for (const line of lines) {
660
+ if (
661
+ !line.startsWith('import ') ||
662
+ allowedSideEffects.some((allowed) => line.includes(allowed))
663
+ ) {
664
+ result.push(line)
665
+ continue
666
+ }
667
+ result.push(line.replace(/import "[^"]+";/g, ''))
668
+ }
633
669
 
634
- if (platform === 'web') {
635
- const rnWebReplacer = replaceRNWeb[opts.format]
636
- if (rnWebReplacer) {
637
- outString = outString.replaceAll(rnWebReplacer.from, rnWebReplacer.to)
670
+ // match whitespace to preserve sourcemaps
671
+ contents = result.join('\n')
638
672
  }
639
- }
640
673
 
641
- if (pkgRemoveSideEffects && isESM) {
642
- const allowedSideEffects = pkg.sideEffects || []
643
-
644
- const result = []
645
- const lines = outString.split('\n')
646
- for (const line of lines) {
647
- if (
648
- !line.startsWith('import ') ||
649
- allowedSideEffects.some((allowed) => line.includes(allowed))
650
- ) {
651
- result.push(line)
652
- continue
653
- }
654
- result.push(line.replace(/import "[^"]+";/g, ''))
674
+ await flush(path, contents)
675
+
676
+ return {
677
+ path,
678
+ contents,
655
679
  }
680
+ })
681
+ )
682
+ ).filter(Boolean)
656
683
 
657
- // match whitespace to preserve sourcemaps
658
- outString = result.join('\n')
659
- }
684
+ // path specifics:
660
685
 
661
- async function flush(contents, path) {
662
- if (shouldWatch) {
663
- if (
664
- !(await fs.pathExists(path)) ||
665
- (await fs.readFile(path, 'utf8')) !== contents
666
- ) {
667
- await fs.writeFile(path, contents, 'utf8')
668
- }
669
- } else {
670
- await fs.writeFile(path, contents, 'utf8')
686
+ await Promise.all(
687
+ outputs.map(async (file) => {
688
+ if (!file) return
689
+ const { path, contents } = file
690
+
691
+ const shouldDoMJS = !shouldSkipMJS && isESM && mjs && path.endsWith('.js')
692
+
693
+ if (!shouldDoMJS) return
694
+
695
+ const mjsOutPath = path.replace('.js', '.mjs')
696
+ // if bundling no need to specify as its all internal
697
+ // and babel is bad on huge bundled files
698
+ const result = shouldBundle
699
+ ? { code: contents }
700
+ : transform(contents, {
701
+ filename: mjsOutPath,
702
+ configFile: false,
703
+ sourceMap: true,
704
+ plugins: [
705
+ [
706
+ require.resolve('@tamagui/babel-plugin-fully-specified'),
707
+ {
708
+ esExtensionDefault: platform === 'native' ? '.native.mjs' : '.mjs',
709
+ },
710
+ ],
711
+ // pkg.tamagui?.build?.skipEnvToMeta
712
+ // ? null
713
+ // : require.resolve('./babel-plugin-process-env-to-meta'),
714
+ ].filter(Boolean),
715
+ })
716
+
717
+ cleanupNonMjsFiles.push(path)
718
+ cleanupNonMjsFiles.push(path + '.map')
719
+
720
+ // output to mjs fully specified
721
+ if (
722
+ await flush(
723
+ mjsOutPath,
724
+ result.code +
725
+ (result.map ? `\n//# sourceMappingURL=${basename(mjsOutPath)}.map\n` : '')
726
+ )
727
+ ) {
728
+ if (result.map) {
729
+ await FSE.writeFile(mjsOutPath + '.map', JSON.stringify(result.map), 'utf8')
671
730
  }
672
731
  }
673
-
674
- // flush before fully specified so it finds the file
675
- await flush(outString, outPath)
676
-
677
- await (async () => {
678
- const shouldDoMJS = !shouldSkipMJS && isESM && mjs && outPath.endsWith('.js')
679
- if (shouldDoMJS) {
680
- const mjsOutPath = outPath.replace('.js', '.mjs')
681
- // if bundling no need to specify as its all internal
682
- // and babel is bad on huge bundled files
683
- const result = shouldBundle
684
- ? { code: outString }
685
- : transform(outString, {
686
- filename: mjsOutPath,
687
- configFile: false,
688
- sourceMap: true,
689
- plugins: [
690
- require.resolve('@tamagui/babel-plugin-fully-specified'),
691
- // pkg.tamagui?.build?.skipEnvToMeta
692
- // ? null
693
- // : require.resolve('./babel-plugin-process-env-to-meta'),
694
- ].filter(Boolean),
695
- })
696
-
697
- // output to mjs fully specified
698
- await fs.writeFile(
699
- mjsOutPath,
700
- result.code +
701
- (result.map ? `\n//# sourceMappingURL=${basename(mjsOutPath)}.map\n` : ''),
702
- 'utf8'
703
- )
704
-
705
- cleanupNonMjsFiles.push(outPath)
706
- cleanupNonMjsFiles.push(outPath + '.map')
707
-
708
- if (result.map) {
709
- await fs.writeFile(mjsOutPath + '.map', JSON.stringify(result.map), 'utf8')
710
- }
711
- }
712
- })()
713
732
  })
714
733
  )
715
734
 
@@ -718,7 +737,7 @@ async function esbuildWriteIfChanged(
718
737
  if (cleanupNonMjsFiles.length) {
719
738
  await Promise.all(
720
739
  cleanupNonMjsFiles.map(async (file) => {
721
- await fs.remove(file)
740
+ await FSE.remove(file)
722
741
  })
723
742
  )
724
743
  }