@tamagui/vite-plugin 1.88.12 → 1.88.14

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/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.
@@ -0,0 +1,2 @@
1
+ const extensions = [".ios.js", ".native.js", ".native.ts", ".native.tsx", ".js", ".jsx", ".json", ".ts", ".tsx", ".mjs"];
2
+ export { extensions };
@@ -0,0 +1,133 @@
1
+ import path from "path";
2
+ import { createExtractor, extractToClassNames, getPragmaOptions } from "@tamagui/static";
3
+ import outdent from "outdent";
4
+ import { normalizePath } from "vite";
5
+ const styleUpdateEvent = fileId => `tamagui-style-update:${fileId}`,
6
+ GLOBAL_CSS_VIRTUAL_PATH = "__tamagui_global_css__.css";
7
+ function tamaguiExtractPlugin(options) {
8
+ if (options.disable || options.disableDebugAttr && options.disableExtraction) return {
9
+ name: "tamagui-extract"
10
+ };
11
+ let extractor = null;
12
+ const cssMap = /* @__PURE__ */new Map();
13
+ let config,
14
+ server,
15
+ shouldReturnCSS = !0,
16
+ virtualExt;
17
+ const getAbsoluteVirtualFileId = filePath => filePath.startsWith(config.root) ? filePath : normalizePath(path.join(config.root, filePath));
18
+ return {
19
+ name: "tamagui-extract",
20
+ enforce: "pre",
21
+ configureServer(_server) {
22
+ server = _server;
23
+ },
24
+ buildEnd() {
25
+ extractor.cleanupBeforeExit();
26
+ },
27
+ writeBundle(options2, bundle) {
28
+ setTimeout(() => {
29
+ console.warn("some sort of dangling process or osmethign, exit for now..."), process.exit(0);
30
+ }, 100);
31
+ },
32
+ config(_userConfig, env) {
33
+ return {
34
+ optimizeDeps: {
35
+ include: env.command === "serve" ? ["@tamagui/core/inject-styles"] : []
36
+ }
37
+ };
38
+ },
39
+ async configResolved(resolvedConfig) {
40
+ config = resolvedConfig, extractor = createExtractor({
41
+ logger: resolvedConfig.logger
42
+ }), shouldReturnCSS = !0, virtualExt = `.tamagui.${shouldReturnCSS ? "css" : "js"}`;
43
+ },
44
+ async resolveId(source) {
45
+ if (source === "tamagui.css") return await extractor.loadTamagui({
46
+ components: ["tamagui"],
47
+ platform: "web",
48
+ ...options
49
+ }), GLOBAL_CSS_VIRTUAL_PATH;
50
+ const [validId, query] = source.split("?");
51
+ if (!validId.endsWith(virtualExt)) return;
52
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
53
+ if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
54
+ },
55
+ /**
56
+ * TODO
57
+ *
58
+ * mainFields module:jsx breaks, so lets just have a mapping here
59
+ * where we load() and map it to the jsx path before transform
60
+ *
61
+ */
62
+ load(id, options2) {
63
+ const [validId] = id.split("?");
64
+ if (validId === GLOBAL_CSS_VIRTUAL_PATH) return extractor.getTamagui().getCSS();
65
+ if (!cssMap.has(validId)) return;
66
+ const css = cssMap.get(validId);
67
+ if (typeof css == "string") return shouldReturnCSS || !server || server.config.isProduction ? css : outdent`
68
+ import { injectStyles } from '@tamagui/core/inject-styles';
69
+
70
+ const inject = (css) => injectStyles({
71
+ filePath: "${validId}",
72
+ css
73
+ });
74
+
75
+ inject(${JSON.stringify(css)});
76
+
77
+ if (import.meta.hot) {
78
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
79
+ inject(css);
80
+ });
81
+ }
82
+ `;
83
+ },
84
+ async transform(code, id, ssrParam) {
85
+ const [validId] = id.split("?");
86
+ if (!validId.endsWith(".tsx")) return;
87
+ const firstCommentIndex = code.indexOf("// "),
88
+ {
89
+ shouldDisable,
90
+ shouldPrintDebug
91
+ } = getPragmaOptions({
92
+ source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
93
+ path: validId
94
+ });
95
+ if (shouldDisable) return;
96
+ const extracted = await extractToClassNames({
97
+ extractor,
98
+ source: code,
99
+ sourcePath: validId,
100
+ options: {
101
+ components: ["tamagui"],
102
+ platform: "web",
103
+ ...options
104
+ },
105
+ shouldPrintDebug
106
+ });
107
+ if (!extracted) return;
108
+ const rootRelativeId = `${validId}${virtualExt}`,
109
+ absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
110
+ let source = extracted.js;
111
+ if (extracted.styles) {
112
+ if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== extracted.styles) {
113
+ const {
114
+ moduleGraph
115
+ } = server,
116
+ [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
117
+ module && (moduleGraph.invalidateModule(module), module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now()), server.ws.send({
118
+ type: "custom",
119
+ event: styleUpdateEvent(absoluteId),
120
+ data: extracted.styles
121
+ });
122
+ }
123
+ source = `${source}
124
+ import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles);
125
+ }
126
+ return {
127
+ code: source.toString(),
128
+ map: extracted.map
129
+ };
130
+ }
131
+ };
132
+ }
133
+ export { tamaguiExtractPlugin };
@@ -0,0 +1,19 @@
1
+ import { join, relative } from "path";
2
+ import resolve from "esm-resolve";
3
+ import { realpath } from "fs-extra";
4
+ async function getVitePath(importer, moduleName, absolute = !1) {
5
+ if (moduleName === "react-native") return "react-native";
6
+ if (moduleName === "react") return "react";
7
+ if (moduleName === "react/jsx-runtime") return "react/jsx-runtime";
8
+ if (moduleName === "react/jsx-dev-runtime") return "react/jsx-dev-runtime";
9
+ if (moduleName[0] === ".") return join("apps/tamastack/src", moduleName) + ".js";
10
+ {
11
+ const sourceFile = join(process.cwd(), "index.js"),
12
+ resolved = resolve(sourceFile)(moduleName);
13
+ if (!resolved) throw new Error("\u274C cant find");
14
+ const real = await realpath(resolved);
15
+ let id = real;
16
+ return absolute || (id = relative(importer, real)), id.endsWith("/react/jsx-dev-runtime.js") && (id = "react/jsx-runtime"), id;
17
+ }
18
+ }
19
+ export { getVitePath };
@@ -0,0 +1,3 @@
1
+ export * from "./plugin.mjs";
2
+ export * from "./extract.mjs";
3
+ export * from "./getVitePath.mjs";
@@ -0,0 +1,89 @@
1
+ import { watchTamaguiConfig } from "@tamagui/static";
2
+ function tamaguiPlugin({
3
+ platform = "web",
4
+ ...options
5
+ }) {
6
+ const watcher = options.disableWatchTamaguiConfig ? null : watchTamaguiConfig({
7
+ platform,
8
+ components: ["tamagui"],
9
+ config: "./src/tamagui.config.ts",
10
+ ...options
11
+ }),
12
+ components = [... /* @__PURE__ */new Set([...(options.components || []), "tamagui", "@tamagui/core"])],
13
+ noExternalSSR = new RegExp(`${components.join("|")}|react-native|expo-linear-gradient`, "ig"),
14
+ extensions = [`.${platform}.js`, `.${platform}.jsx`, `.${platform}.ts`, `.${platform}.tsx`, ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
15
+ return {
16
+ name: "tamagui-base",
17
+ enforce: "pre",
18
+ async buildEnd() {
19
+ await watcher?.then(res => {
20
+ res?.dispose();
21
+ });
22
+ },
23
+ config(userConfig, env) {
24
+ return {
25
+ plugins: [
26
+ //
27
+ // envPlugin(['NODE_ENV', 'TAMAGUI_TARGET', 'ENABLE_RSC']),
28
+ // viteCommonjs(),
29
+ ],
30
+ define: {
31
+ // reanimated support
32
+ _frameTimestamp: void 0,
33
+ _WORKLET: !1,
34
+ __DEV__: `${env.mode === "development"}`,
35
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
36
+ "process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
37
+ "process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
38
+ "process.env.IS_STATIC": JSON.stringify(!1)
39
+ },
40
+ // build: {
41
+ // commonjsOptions: {
42
+ // transformMixedEsModules: true,
43
+ // },
44
+ // },
45
+ ssr: {
46
+ noExternal: noExternalSSR
47
+ },
48
+ optimizeDeps: {
49
+ // disabled: false,
50
+ include: platform !== "native" ? ["styleq"] : [],
51
+ esbuildOptions: {
52
+ jsx: "transform",
53
+ // plugins: [
54
+ // esbuildCommonjs([
55
+ // 'styleq',
56
+ // 'inline-style-prefixer',
57
+ // 'create-react-class',
58
+ // 'copy-to-clipboard',
59
+ // 'escape-string-regexp',
60
+ // ]),
61
+ // ],
62
+ resolveExtensions: extensions,
63
+ loader: {
64
+ ".js": "jsx"
65
+ }
66
+ }
67
+ },
68
+ resolve: {
69
+ // for once it extracts
70
+ // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext', 'main'],
71
+ extensions,
72
+ alias: {
73
+ ...(platform !== "native" && {
74
+ "react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
75
+ "react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
76
+ "react-native-svg": "@tamagui/react-native-svg",
77
+ "react-native": "react-native-web",
78
+ ...(options.useReactNativeWebLite && {
79
+ "react-native": "react-native-web-lite",
80
+ "react-native-web": "react-native-web-lite"
81
+ })
82
+ })
83
+ }
84
+ }
85
+ };
86
+ }
87
+ };
88
+ }
89
+ export { tamaguiPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/vite-plugin",
3
- "version": "1.88.12",
3
+ "version": "1.88.14",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -26,16 +26,16 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@tamagui/fake-react-native": "1.88.12",
30
- "@tamagui/proxy-worm": "1.88.12",
31
- "@tamagui/react-native-svg": "1.88.12",
32
- "@tamagui/static": "1.88.12",
29
+ "@tamagui/fake-react-native": "1.88.14",
30
+ "@tamagui/proxy-worm": "1.88.14",
31
+ "@tamagui/react-native-svg": "1.88.14",
32
+ "@tamagui/static": "1.88.14",
33
33
  "esm-resolve": "^1.0.8",
34
- "fs-extra": "^11.1.0",
34
+ "fs-extra": "^11.2.0",
35
35
  "outdent": "^0.8.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@tamagui/build": "1.88.12"
38
+ "@tamagui/build": "1.88.14"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
package/src/extract.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import path from 'path'
4
4
 
5
- import { TamaguiOptions } from '@tamagui/static'
5
+ import type { TamaguiOptions } from '@tamagui/static'
6
6
  import { createExtractor, extractToClassNames, getPragmaOptions } from '@tamagui/static'
7
7
  import outdent from 'outdent'
8
8
  import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
@@ -1,4 +1,4 @@
1
- import { TamaguiOptions } from '@tamagui/static';
1
+ import type { TamaguiOptions } from '@tamagui/static';
2
2
  import type { Plugin } from 'vite';
3
3
  export declare function tamaguiExtractPlugin(options: Partial<TamaguiOptions>): Plugin;
4
4
  //# sourceMappingURL=extract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAA;AAMjE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAqP7E"}
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAA;AAMjE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAqP7E"}