@tamagui/build 1.92.0 → 1.93.0

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.
@@ -0,0 +1,33 @@
1
+ const hasReplaced = Symbol()
2
+
3
+ module.exports = function viteMetaEnvBabelPlugin({ template, types: t }) {
4
+ return {
5
+ name: 'vite-process-to-meta-env',
6
+ visitor: {
7
+ MemberExpression(path) {
8
+ if (path[hasReplaced]) return
9
+
10
+ const envNode = t.isMemberExpression(path.node.object) && path.node.object
11
+ const variableName = t.isIdentifier(path.node.property) && path.node.property.name
12
+
13
+ if (!envNode || !variableName) {
14
+ return
15
+ }
16
+
17
+ const isProcess =
18
+ t.isIdentifier(envNode.object) && envNode.object.name === 'process'
19
+ const isEnvVar =
20
+ t.isIdentifier(envNode.property) && envNode.property.name === 'env'
21
+
22
+ if (!isProcess || !isEnvVar) {
23
+ return
24
+ }
25
+
26
+ path.replaceWith(
27
+ template.expression('import.meta.env.%%variableName%%')({ variableName })
28
+ )
29
+ path[hasReplaced] = true
30
+ },
31
+ },
32
+ }
33
+ }
@@ -0,0 +1,35 @@
1
+ import type babelCore from '@babel/core'
2
+
3
+ export default function viteMetaEnvBabelPlugin({
4
+ template,
5
+ types: t,
6
+ }: typeof babelCore): babelCore.PluginObj {
7
+ return {
8
+ name: 'vite-process-to-meta-env',
9
+ visitor: {
10
+ MemberExpression(path) {
11
+ const envNode = t.isMemberExpression(path.node.object) && path.node.object
12
+ const variableName = t.isIdentifier(path.node.property) && path.node.property.name
13
+
14
+ if (!envNode || !variableName) {
15
+ return
16
+ }
17
+
18
+ const isProcess =
19
+ t.isIdentifier(envNode.object) && envNode.object.name === 'process'
20
+ const isEnvVar =
21
+ t.isIdentifier(envNode.property) && envNode.property.name === 'env'
22
+
23
+ if (!isProcess || !isEnvVar) {
24
+ return
25
+ }
26
+
27
+ path.replaceWith(
28
+ template.expression('process.env.%%variableName%%')({
29
+ variableName: variableName === 'NODE_ENV' ? 'MODE' : variableName,
30
+ })
31
+ )
32
+ },
33
+ },
34
+ }
35
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@tamagui/build",
3
- "version": "1.92.0",
3
+ "version": "1.93.0",
4
4
  "bin": {
5
- "tamagui-build": "tamagui-build.js"
5
+ "tamagui-build": "tamagui-build.js",
6
+ "teesx": "./teesx.sh"
6
7
  },
7
8
  "scripts": {
8
9
  "build": "true",
@@ -16,8 +17,9 @@
16
17
  "@types/fs-extra": "^9.0.13",
17
18
  "babel-plugin-fully-specified": "*",
18
19
  "chokidar": "^3.5.2",
19
- "esbuild": "^0.19.11",
20
+ "esbuild": "^0.20.2",
20
21
  "esbuild-plugin-es5": "^2.1.0",
22
+ "esbuild-register": "^3.5.0",
21
23
  "execa": "^5.0.0",
22
24
  "fast-glob": "^3.2.11",
23
25
  "fs-extra": "^11.2.0",
package/tamagui-build.js CHANGED
@@ -562,8 +562,23 @@ async function esbuildWriteIfChanged(
562
562
  }
563
563
 
564
564
  if (pkgRemoveSideEffects && isESM) {
565
+ const allowedSideEffects = pkg.sideEffects || []
566
+
567
+ const result = []
568
+ const lines = outString.split('\n')
569
+ for (const line of lines) {
570
+ if (
571
+ !line.startsWith('import ') ||
572
+ allowedSideEffects.some((allowed) => line.includes(allowed))
573
+ ) {
574
+ result.push(line)
575
+ continue
576
+ }
577
+ result.push(line.replace(/import "[^"]+";/g, ''))
578
+ }
579
+
565
580
  // match whitespace to preserve sourcemaps
566
- outString = outString.replace(/\nimport "[^"]+";\n/g, '\n\n')
581
+ outString = result.join('\n')
567
582
  }
568
583
 
569
584
  async function flush(contents, path) {
@@ -601,7 +616,10 @@ async function esbuildWriteIfChanged(
601
616
  esExtensions: ['.mjs', '.js'],
602
617
  },
603
618
  ],
604
- ],
619
+ // pkg.tamagui?.build?.skipEnvToMeta
620
+ // ? null
621
+ // : require.resolve('./babel-plugin-process-env-to-meta'),
622
+ ].filter(Boolean),
605
623
  }).code
606
624
  // output to mjs fully specified
607
625
  await flush(output, mjsOutPath)
package/teesx.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ node --loader esbuild-register/loader -r esbuild-register "$@"