@tamagui/static 1.14.9 → 1.15.1
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/dist/cjs/extractor/bundleConfig.js +343 -0
- package/dist/cjs/extractor/bundleConfig.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/generateTamaguiConfig.js +83 -0
- package/dist/cjs/extractor/generateTamaguiConfig.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +76 -292
- package/dist/cjs/extractor/loadTamagui.js.map +3 -3
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/bundleConfig.js +307 -0
- package/dist/esm/extractor/bundleConfig.js.map +7 -0
- package/dist/esm/extractor/bundleConfig.mjs +307 -0
- package/dist/esm/extractor/bundleConfig.mjs.map +7 -0
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/createExtractor.mjs.map +2 -2
- package/dist/esm/extractor/generateTamaguiConfig.js +49 -0
- package/dist/esm/extractor/generateTamaguiConfig.js.map +7 -0
- package/dist/esm/extractor/generateTamaguiConfig.mjs +49 -0
- package/dist/esm/extractor/generateTamaguiConfig.mjs.map +7 -0
- package/dist/esm/extractor/loadTamagui.js +76 -290
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.mjs +76 -290
- package/dist/esm/extractor/loadTamagui.mjs.map +2 -2
- package/package.json +16 -16
- package/src/extractor/bundleConfig.ts +389 -0
- package/src/extractor/createExtractor.ts +3 -3
- package/src/extractor/generateTamaguiConfig.ts +65 -0
- package/src/extractor/loadTamagui.ts +81 -370
- package/src/types.ts +2 -3
- package/types/extractor/bundleConfig.d.ts +35 -0
- package/types/extractor/bundleConfig.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +2 -2
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts +2 -2
- package/types/extractor/generateTamaguiConfig.d.ts +3 -0
- package/types/extractor/generateTamaguiConfig.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +6 -21
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var generateTamaguiConfig_exports = {};
|
|
30
|
+
__export(generateTamaguiConfig_exports, {
|
|
31
|
+
generateTamaguiConfig: () => generateTamaguiConfig
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(generateTamaguiConfig_exports);
|
|
34
|
+
var import_core_node = require("@tamagui/core-node");
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
+
var import_bundleConfig = require("./bundleConfig.js");
|
|
37
|
+
async function getTamaguiConfig(options) {
|
|
38
|
+
return (0, import_bundleConfig.bundleConfig)(options.tamaguiOptions);
|
|
39
|
+
}
|
|
40
|
+
async function generateTamaguiConfig(options) {
|
|
41
|
+
await (0, import_fs_extra.ensureDir)(options.paths.dotDir);
|
|
42
|
+
const config = await getTamaguiConfig(options);
|
|
43
|
+
const { components, nameToPaths } = config;
|
|
44
|
+
const { themes, tokens } = config.tamaguiConfig;
|
|
45
|
+
for (const key in themes) {
|
|
46
|
+
const theme = themes[key];
|
|
47
|
+
theme.id = key;
|
|
48
|
+
for (const tkey in theme) {
|
|
49
|
+
theme[tkey] = (0, import_core_node.getVariableValue)(theme[tkey]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const key in tokens) {
|
|
53
|
+
const token = tokens[key];
|
|
54
|
+
for (const tkey in token) {
|
|
55
|
+
token[tkey] = (0, import_core_node.getVariableValue)(token[tkey]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const component of components) {
|
|
59
|
+
for (const _ in component.nameToInfo) {
|
|
60
|
+
delete component.nameToInfo[_].staticConfig["validStyles"];
|
|
61
|
+
delete component.nameToInfo[_].staticConfig["parentStaticConfig"];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const key in nameToPaths) {
|
|
65
|
+
nameToPaths[key] = [...nameToPaths[key]];
|
|
66
|
+
}
|
|
67
|
+
const { fontsParsed, getCSS, tokensParsed, themeConfig, ...cleanedConfig } = config.tamaguiConfig;
|
|
68
|
+
await import_fs_extra.default.writeJSON(
|
|
69
|
+
options.paths.conf,
|
|
70
|
+
{
|
|
71
|
+
...config,
|
|
72
|
+
tamaguiConfig: cleanedConfig
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
spaces: 2
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
generateTamaguiConfig
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=generateTamaguiConfig.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/generateTamaguiConfig.ts"],
|
|
4
|
+
"sourcesContent": ["import { getVariableValue } from '@tamagui/core-node'\nimport { CLIResolvedOptions } from '@tamagui/types'\nimport fs, { ensureDir } from 'fs-extra'\n\nimport { bundleConfig } from './bundleConfig.js'\n\nasync function getTamaguiConfig(options: CLIResolvedOptions) {\n return bundleConfig(options.tamaguiOptions)\n}\n\nexport async function generateTamaguiConfig(options: CLIResolvedOptions) {\n await ensureDir(options.paths.dotDir)\n const config = await getTamaguiConfig(options)\n const { components, nameToPaths } = config\n const { themes, tokens } = config.tamaguiConfig\n\n // reduce down to usable, smaller json\n\n // slim themes, add name\n for (const key in themes) {\n const theme = themes[key]\n // @ts-ignore\n theme.id = key\n for (const tkey in theme) {\n theme[tkey] = getVariableValue(theme[tkey])\n }\n }\n\n // flatten variables\n for (const key in tokens) {\n const token = tokens[key]\n for (const tkey in token) {\n token[tkey] = getVariableValue(token[tkey])\n }\n }\n\n // remove bulky stuff in components\n for (const component of components) {\n for (const _ in component.nameToInfo) {\n delete component.nameToInfo[_].staticConfig['validStyles']\n delete component.nameToInfo[_].staticConfig['parentStaticConfig']\n }\n }\n\n // set to array\n for (const key in nameToPaths) {\n // @ts-ignore\n nameToPaths[key] = [...nameToPaths[key]]\n }\n\n // remove stuff we dont need to send\n const { fontsParsed, getCSS, tokensParsed, themeConfig, ...cleanedConfig } =\n config.tamaguiConfig\n\n await fs.writeJSON(\n options.paths.conf,\n {\n ...config,\n tamaguiConfig: cleanedConfig,\n },\n {\n spaces: 2,\n }\n )\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiC;AAEjC,sBAA8B;AAE9B,0BAA6B;AAE7B,eAAe,iBAAiB,SAA6B;AAC3D,aAAO,kCAAa,QAAQ,cAAc;AAC5C;AAEA,eAAsB,sBAAsB,SAA6B;AACvE,YAAM,2BAAU,QAAQ,MAAM,MAAM;AACpC,QAAM,SAAS,MAAM,iBAAiB,OAAO;AAC7C,QAAM,EAAE,YAAY,YAAY,IAAI;AACpC,QAAM,EAAE,QAAQ,OAAO,IAAI,OAAO;AAKlC,aAAW,OAAO,QAAQ;AACxB,UAAM,QAAQ,OAAO,GAAG;AAExB,UAAM,KAAK;AACX,eAAW,QAAQ,OAAO;AACxB,YAAM,IAAI,QAAI,mCAAiB,MAAM,IAAI,CAAC;AAAA,IAC5C;AAAA,EACF;AAGA,aAAW,OAAO,QAAQ;AACxB,UAAM,QAAQ,OAAO,GAAG;AACxB,eAAW,QAAQ,OAAO;AACxB,YAAM,IAAI,QAAI,mCAAiB,MAAM,IAAI,CAAC;AAAA,IAC5C;AAAA,EACF;AAGA,aAAW,aAAa,YAAY;AAClC,eAAW,KAAK,UAAU,YAAY;AACpC,aAAO,UAAU,WAAW,CAAC,EAAE,aAAa,aAAa;AACzD,aAAO,UAAU,WAAW,CAAC,EAAE,aAAa,oBAAoB;AAAA,IAClE;AAAA,EACF;AAGA,aAAW,OAAO,aAAa;AAE7B,gBAAY,GAAG,IAAI,CAAC,GAAG,YAAY,GAAG,CAAC;AAAA,EACzC;AAGA,QAAM,EAAE,aAAa,QAAQ,cAAc,aAAa,GAAG,cAAc,IACvE,OAAO;AAET,QAAM,gBAAAA,QAAG;AAAA,IACP,QAAQ,MAAM;AAAA,IACd;AAAA,MACE,GAAG;AAAA,MACH,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["fs"]
|
|
7
|
+
}
|
|
@@ -28,28 +28,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var loadTamagui_exports = {};
|
|
30
30
|
__export(loadTamagui_exports, {
|
|
31
|
+
TamaguiProjectInfo: () => import_bundleConfig.TamaguiProjectInfo,
|
|
32
|
+
getOptions: () => getOptions,
|
|
31
33
|
loadTamagui: () => loadTamagui,
|
|
32
34
|
loadTamaguiSync: () => loadTamaguiSync,
|
|
33
|
-
resolveWebOrNativeSpecificEntry: () => resolveWebOrNativeSpecificEntry
|
|
35
|
+
resolveWebOrNativeSpecificEntry: () => resolveWebOrNativeSpecificEntry,
|
|
36
|
+
watchTamaguiConfig: () => watchTamaguiConfig
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(loadTamagui_exports);
|
|
36
|
-
var import_fs = require("fs");
|
|
37
39
|
var import_path = require("path");
|
|
38
|
-
var import_generator = __toESM(require("@babel/generator"));
|
|
39
|
-
var import_traverse = __toESM(require("@babel/traverse"));
|
|
40
|
-
var t = __toESM(require("@babel/types"));
|
|
41
|
-
var import_cli_color = require("@tamagui/cli-color");
|
|
42
40
|
var import_config_default_node = require("@tamagui/config-default-node");
|
|
43
41
|
var import_core_node = require("@tamagui/core-node");
|
|
44
42
|
var import_esbuild = __toESM(require("esbuild"));
|
|
45
|
-
var import_fs_extra = require("fs-extra");
|
|
43
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
46
44
|
var import_constants = require("../constants.js");
|
|
47
45
|
var import_require = require("../require.js");
|
|
48
|
-
var
|
|
49
|
-
var
|
|
46
|
+
var import_bundleConfig = require("./bundleConfig.js");
|
|
47
|
+
var import_generateTamaguiConfig = require("./generateTamaguiConfig.js");
|
|
50
48
|
const cache = {};
|
|
51
49
|
async function loadTamagui(props) {
|
|
52
|
-
var _a, _b;
|
|
53
50
|
const key = JSON.stringify(props);
|
|
54
51
|
if (cache[key]) {
|
|
55
52
|
if (cache[key] instanceof Promise) {
|
|
@@ -62,96 +59,10 @@ async function loadTamagui(props) {
|
|
|
62
59
|
cache[key] = new Promise((res) => {
|
|
63
60
|
resolver = res;
|
|
64
61
|
});
|
|
65
|
-
const tmpDir = (0, import_path.join)(process.cwd(), ".tamagui");
|
|
66
|
-
const configOutPath = (0, import_path.join)(tmpDir, `tamagui.config.cjs`);
|
|
67
|
-
const baseComponents = props.components.filter((x) => x !== "@tamagui/core");
|
|
68
|
-
const componentOutPaths = baseComponents.map(
|
|
69
|
-
(componentModule) => (0, import_path.join)(
|
|
70
|
-
tmpDir,
|
|
71
|
-
`${componentModule.split(import_path.sep).join("-").replace(/[^a-z0-9]+/gi, "")}-components.config.cjs`
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
const external = [
|
|
75
|
-
"@tamagui/core",
|
|
76
|
-
"@tamagui/web",
|
|
77
|
-
"@tamagui/core-node",
|
|
78
|
-
"react",
|
|
79
|
-
"react-dom",
|
|
80
|
-
"react-native-svg"
|
|
81
|
-
];
|
|
82
|
-
const configEntry = props.config ? (0, import_path.join)(process.cwd(), props.config) : "";
|
|
83
|
-
if (process.env.NODE_ENV === "development" && ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui"))) {
|
|
84
|
-
console.log(`Building config entry`, configEntry);
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
await (0, import_fs_extra.ensureDir)(tmpDir);
|
|
88
|
-
} catch {
|
|
89
|
-
}
|
|
90
|
-
(0, import_cli_color.colorLog)(
|
|
91
|
-
import_cli_color.Color.FgYellow,
|
|
92
|
-
`
|
|
93
|
-
Tamagui built config and components:`
|
|
94
|
-
);
|
|
95
|
-
(0, import_cli_color.colorLog)(
|
|
96
|
-
import_cli_color.Color.Dim,
|
|
97
|
-
`
|
|
98
|
-
Config .${import_path.sep}${(0, import_path.relative)(process.cwd(), configOutPath)}
|
|
99
|
-
Components ${[
|
|
100
|
-
...componentOutPaths.map((p) => `.${import_path.sep}${(0, import_path.relative)(process.cwd(), p)}`)
|
|
101
|
-
].join("\n ")}
|
|
102
|
-
`
|
|
103
|
-
);
|
|
104
|
-
await Promise.all([
|
|
105
|
-
props.config ? (0, import_bundle.bundle)({
|
|
106
|
-
entryPoints: [configEntry],
|
|
107
|
-
external,
|
|
108
|
-
outfile: configOutPath
|
|
109
|
-
}) : null,
|
|
110
|
-
...baseComponents.map((componentModule, i) => {
|
|
111
|
-
return (0, import_bundle.bundle)({
|
|
112
|
-
entryPoints: [componentModule],
|
|
113
|
-
resolvePlatformSpecificEntries: true,
|
|
114
|
-
external,
|
|
115
|
-
outfile: componentOutPaths[i]
|
|
116
|
-
});
|
|
117
|
-
})
|
|
118
|
-
]);
|
|
119
62
|
try {
|
|
120
63
|
(0, import_require.registerRequire)();
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
if (!config) {
|
|
124
|
-
throw new Error(`No config: ${config}`);
|
|
125
|
-
}
|
|
126
|
-
let components = loadComponents({
|
|
127
|
-
...props,
|
|
128
|
-
components: componentOutPaths
|
|
129
|
-
});
|
|
130
|
-
if (!components) {
|
|
131
|
-
throw new Error(`No components found: ${componentOutPaths.join(", ")}`);
|
|
132
|
-
}
|
|
133
|
-
for (const component of components) {
|
|
134
|
-
component.moduleName = baseComponents[componentOutPaths.indexOf(component.moduleName)];
|
|
135
|
-
if (!component.moduleName) {
|
|
136
|
-
throw new Error(`Tamagui internal err`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const coreComponents = loadComponents({
|
|
140
|
-
...props,
|
|
141
|
-
components: ["@tamagui/core-node"]
|
|
142
|
-
});
|
|
143
|
-
if (coreComponents) {
|
|
144
|
-
coreComponents[0].moduleName = "@tamagui/core";
|
|
145
|
-
components = [...components, ...coreComponents];
|
|
146
|
-
}
|
|
147
|
-
if (process.env.NODE_ENV === "development" && ((_b = process.env.DEBUG) == null ? void 0 : _b.startsWith("tamagui"))) {
|
|
148
|
-
console.log("Loaded components", components);
|
|
149
|
-
}
|
|
150
|
-
cache[key] = {
|
|
151
|
-
components,
|
|
152
|
-
nameToPaths: {},
|
|
153
|
-
tamaguiConfig: config
|
|
154
|
-
};
|
|
64
|
+
const bundleInfo = await (0, import_bundleConfig.bundleConfig)(props);
|
|
65
|
+
cache[key] = bundleInfo;
|
|
155
66
|
(0, import_core_node.createTamagui)(cache[key].tamaguiConfig);
|
|
156
67
|
resolver(cache[key]);
|
|
157
68
|
return cache[key];
|
|
@@ -171,19 +82,12 @@ function resolveWebOrNativeSpecificEntry(entry) {
|
|
|
171
82
|
}
|
|
172
83
|
return entry;
|
|
173
84
|
}
|
|
174
|
-
const esbuildOptions = {
|
|
175
|
-
loader: "tsx",
|
|
176
|
-
target: "es2018",
|
|
177
|
-
format: "cjs",
|
|
178
|
-
jsx: "transform",
|
|
179
|
-
platform: "node"
|
|
180
|
-
};
|
|
181
85
|
function loadTamaguiSync(props) {
|
|
182
86
|
const key = JSON.stringify(props);
|
|
183
87
|
if (cache[key]) {
|
|
184
88
|
return cache[key];
|
|
185
89
|
}
|
|
186
|
-
const { unregister } = require("esbuild-register/dist/node").register(esbuildOptions);
|
|
90
|
+
const { unregister } = require("esbuild-register/dist/node").register(import_bundleConfig.esbuildOptions);
|
|
187
91
|
try {
|
|
188
92
|
(0, import_require.registerRequire)();
|
|
189
93
|
process.env.IS_STATIC = "is_static";
|
|
@@ -202,7 +106,7 @@ function loadTamaguiSync(props) {
|
|
|
202
106
|
Be sure you "export default" the config.`);
|
|
203
107
|
}
|
|
204
108
|
}
|
|
205
|
-
const components = loadComponents(props);
|
|
109
|
+
const components = (0, import_bundleConfig.loadComponents)(props);
|
|
206
110
|
if (!components) {
|
|
207
111
|
throw new Error(`No components loaded`);
|
|
208
112
|
}
|
|
@@ -247,201 +151,81 @@ function loadTamaguiSync(props) {
|
|
|
247
151
|
(0, import_require.unregisterRequire)();
|
|
248
152
|
}
|
|
249
153
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return;
|
|
279
|
-
if (usedNames.has(dec.id.name))
|
|
280
|
-
return;
|
|
281
|
-
usedNames.add(dec.id.name);
|
|
282
|
-
nodePath.replaceWith(
|
|
283
|
-
t.exportNamedDeclaration(t.variableDeclaration("let", [dec]), [
|
|
284
|
-
t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name))
|
|
285
|
-
])
|
|
286
|
-
);
|
|
154
|
+
async function getOptions({
|
|
155
|
+
root = process.cwd(),
|
|
156
|
+
tsconfigPath = "tsconfig.json",
|
|
157
|
+
tamaguiOptions,
|
|
158
|
+
host,
|
|
159
|
+
debug
|
|
160
|
+
} = {}) {
|
|
161
|
+
const tsConfigFilePath = (0, import_path.join)(root, tsconfigPath);
|
|
162
|
+
if (!await import_fs_extra.default.pathExists(tsConfigFilePath))
|
|
163
|
+
throw new Error(`No tsconfig found: ${tsConfigFilePath}`);
|
|
164
|
+
const dotDir = (0, import_path.join)(root, ".tamagui");
|
|
165
|
+
const pkgJson = await (0, import_fs_extra.readJSON)((0, import_path.join)(root, "package.json"));
|
|
166
|
+
return {
|
|
167
|
+
mode: process.env.NODE_ENV === "production" ? "production" : "development",
|
|
168
|
+
root,
|
|
169
|
+
host: host || "127.0.0.1",
|
|
170
|
+
pkgJson,
|
|
171
|
+
debug,
|
|
172
|
+
tsconfigPath,
|
|
173
|
+
tamaguiOptions: {
|
|
174
|
+
components: ["tamagui"],
|
|
175
|
+
config: await getDefaultTamaguiConfigPath(),
|
|
176
|
+
...tamaguiOptions
|
|
177
|
+
},
|
|
178
|
+
paths: {
|
|
179
|
+
dotDir,
|
|
180
|
+
conf: (0, import_path.join)(dotDir, "tamagui.config.json"),
|
|
181
|
+
types: (0, import_path.join)(dotDir, "types.json")
|
|
287
182
|
}
|
|
288
|
-
}
|
|
289
|
-
return (0, import_generator.default)(ast, {
|
|
290
|
-
concise: false,
|
|
291
|
-
filename: "test.tsx",
|
|
292
|
-
retainLines: false,
|
|
293
|
-
sourceMaps: false
|
|
294
|
-
}).code;
|
|
183
|
+
};
|
|
295
184
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
try {
|
|
315
|
-
const info = componentsModules.flatMap((name) => {
|
|
316
|
-
var _a;
|
|
317
|
-
const extension = (0, import_path.extname)(name);
|
|
318
|
-
const isLocal = Boolean(extension);
|
|
319
|
-
const isDynamic = isLocal && !props.config;
|
|
320
|
-
if (isDynamic && !process.env.TAMAGUI_ENABLE_DYNAMIC_LOAD) {
|
|
321
|
-
return [];
|
|
322
|
-
}
|
|
323
|
-
const fileContents = isDynamic ? (0, import_fs.readFileSync)(name, "utf-8") : "";
|
|
324
|
-
const loadModule = isDynamic ? (0, import_path.join)((0, import_path.dirname)(name), `.tamagui-dynamic-eval-${(0, import_path.basename)(name)}.tsx`) : name;
|
|
325
|
-
let writtenContents = fileContents;
|
|
326
|
-
let didBabel = false;
|
|
327
|
-
function attemptLoad({ forceExports = false } = {}) {
|
|
328
|
-
if (isDynamic) {
|
|
329
|
-
writtenContents = forceExports ? esbuildit(
|
|
330
|
-
transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern")))
|
|
331
|
-
) : esbuildit(fileContents);
|
|
332
|
-
(0, import_fs_extra.writeFileSync)(loadModule, writtenContents);
|
|
333
|
-
}
|
|
334
|
-
if (process.env.DEBUG === "tamagui") {
|
|
335
|
-
console.log(`loadModule`, loadModule, require.resolve(loadModule));
|
|
336
|
-
}
|
|
337
|
-
return {
|
|
338
|
-
moduleName: name,
|
|
339
|
-
nameToInfo: getComponentStaticConfigByName(
|
|
340
|
-
name,
|
|
341
|
-
interopDefaultExport(require(loadModule))
|
|
342
|
-
)
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
const dispose = () => {
|
|
346
|
-
isDynamic && (0, import_fs_extra.removeSync)(loadModule);
|
|
347
|
-
};
|
|
348
|
-
try {
|
|
349
|
-
const res = attemptLoad({
|
|
350
|
-
forceExports: true
|
|
351
|
-
});
|
|
352
|
-
didBabel = true;
|
|
353
|
-
return res;
|
|
354
|
-
} catch (err) {
|
|
355
|
-
console.log("babel err", err, writtenContents);
|
|
356
|
-
writtenContents = fileContents;
|
|
357
|
-
if ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui")) {
|
|
358
|
-
console.log(`Error parsing babel likely`, err);
|
|
359
|
-
}
|
|
360
|
-
} finally {
|
|
361
|
-
dispose();
|
|
362
|
-
}
|
|
363
|
-
try {
|
|
364
|
-
return attemptLoad({
|
|
365
|
-
forceExports: false
|
|
366
|
-
});
|
|
367
|
-
} catch (err) {
|
|
368
|
-
if (!process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD) {
|
|
369
|
-
console.log(`
|
|
370
|
-
|
|
371
|
-
Tamagui attempted but failed to dynamically load components in:
|
|
372
|
-
${name}
|
|
373
|
-
|
|
374
|
-
This will leave some styled() tags unoptimized.
|
|
375
|
-
Disable this file (or dynamic loading altogether):
|
|
376
|
-
|
|
377
|
-
disableExtractFoundComponents: ['${name}'] | true
|
|
378
|
-
|
|
379
|
-
Quiet this warning with environment variable:
|
|
380
|
-
|
|
381
|
-
TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1
|
|
382
|
-
|
|
383
|
-
`);
|
|
384
|
-
console.log(err);
|
|
385
|
-
console.log(
|
|
386
|
-
`At: ${loadModule}`,
|
|
387
|
-
`
|
|
388
|
-
didBabel: ${didBabel}`,
|
|
389
|
-
`
|
|
390
|
-
In:`,
|
|
391
|
-
writtenContents,
|
|
392
|
-
`
|
|
393
|
-
isDynamic: `,
|
|
394
|
-
isDynamic
|
|
395
|
-
);
|
|
185
|
+
async function watchTamaguiConfig(tamaguiOptions) {
|
|
186
|
+
const options = await getOptions({ tamaguiOptions });
|
|
187
|
+
if (!options.tamaguiOptions.config)
|
|
188
|
+
return;
|
|
189
|
+
await (0, import_generateTamaguiConfig.generateTamaguiConfig)(options);
|
|
190
|
+
const context = await import_esbuild.default.context({
|
|
191
|
+
entryPoints: [options.tamaguiOptions.config],
|
|
192
|
+
sourcemap: false,
|
|
193
|
+
// dont output just use esbuild as a watcher
|
|
194
|
+
write: false,
|
|
195
|
+
plugins: [
|
|
196
|
+
{
|
|
197
|
+
name: `on-rebuild`,
|
|
198
|
+
setup({ onEnd }) {
|
|
199
|
+
onEnd((res) => {
|
|
200
|
+
(0, import_generateTamaguiConfig.generateTamaguiConfig)(options);
|
|
201
|
+
});
|
|
396
202
|
}
|
|
397
|
-
return [];
|
|
398
|
-
} finally {
|
|
399
|
-
dispose();
|
|
400
203
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
} catch (err) {
|
|
405
|
-
console.log(`Tamagui error bundling components`, err.message, err.stack);
|
|
406
|
-
return null;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
function getComponentStaticConfigByName(name, exported) {
|
|
410
|
-
const components = {};
|
|
411
|
-
try {
|
|
412
|
-
if (!exported || typeof exported !== "object" || Array.isArray(exported)) {
|
|
413
|
-
throw new Error(`Invalid export from package ${name}: ${typeof exported}`);
|
|
414
|
-
}
|
|
415
|
-
for (const key in exported) {
|
|
416
|
-
const found = getTamaguiComponent(key, exported[key]);
|
|
417
|
-
if (found) {
|
|
418
|
-
const { Component, ...sc } = found.staticConfig;
|
|
419
|
-
components[key] = { staticConfig: sc };
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
} catch (err) {
|
|
423
|
-
if (process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD !== "1") {
|
|
424
|
-
console.error(
|
|
425
|
-
`Tamagui failed getting from ${name} (Disable error by setting environment variable TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1)`
|
|
426
|
-
);
|
|
427
|
-
console.error(err);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return components;
|
|
204
|
+
]
|
|
205
|
+
});
|
|
206
|
+
await context.watch();
|
|
431
207
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
208
|
+
const defaultPaths = ["tamagui.config.ts", (0, import_path.join)("src", "tamagui.config.ts")];
|
|
209
|
+
let cachedPath = "";
|
|
210
|
+
async function getDefaultTamaguiConfigPath() {
|
|
211
|
+
if (cachedPath)
|
|
212
|
+
return cachedPath;
|
|
213
|
+
const existingPaths = await Promise.all(defaultPaths.map((path) => (0, import_fs_extra.pathExists)(path)));
|
|
214
|
+
const existing = existingPaths.findIndex((x) => !!x);
|
|
215
|
+
const found = defaultPaths[existing];
|
|
216
|
+
if (!found) {
|
|
217
|
+
throw new Error(`No found tamagui.config.ts`);
|
|
439
218
|
}
|
|
219
|
+
cachedPath = found;
|
|
220
|
+
return found;
|
|
440
221
|
}
|
|
441
222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
442
223
|
0 && (module.exports = {
|
|
224
|
+
TamaguiProjectInfo,
|
|
225
|
+
getOptions,
|
|
443
226
|
loadTamagui,
|
|
444
227
|
loadTamaguiSync,
|
|
445
|
-
resolveWebOrNativeSpecificEntry
|
|
228
|
+
resolveWebOrNativeSpecificEntry,
|
|
229
|
+
watchTamaguiConfig
|
|
446
230
|
});
|
|
447
231
|
//# sourceMappingURL=loadTamagui.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/loadTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFileSync } from 'fs'\n/* eslint-disable no-console */\nimport { basename, dirname, extname, join, relative, resolve, sep } from 'path'\n\nimport generate from '@babel/generator'\nimport traverse from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { Color, colorLog } from '@tamagui/cli-color'\nimport { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport type { StaticConfigParsed, TamaguiInternalConfig } from '@tamagui/core-node'\nimport { createTamagui } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\nimport { ensureDir, existsSync, removeSync, writeFileSync } from 'fs-extra'\n\nimport { SHOULD_DEBUG } from '../constants.js'\nimport { getNameToPaths, registerRequire, unregisterRequire } from '../require.js'\nimport { babelParse } from './babelParse.js'\nimport { bundle } from './bundle.js'\n\ntype NameToPaths = {\n [key: string]: Set<string>\n}\n\nexport type LoadedComponents = {\n moduleName: string\n nameToInfo: Record<\n string,\n {\n staticConfig: StaticConfigParsed\n }\n >\n}\n\nexport type TamaguiProjectInfo = {\n components: LoadedComponents[]\n tamaguiConfig: TamaguiInternalConfig\n nameToPaths: NameToPaths\n}\n\ntype Props = {\n components: string[]\n config?: string\n forceExports?: boolean\n}\n\nconst cache = {}\n\n// TODO needs a plugin for webpack / vite to run this once at startup and not again until changed...\n\nexport async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {\n const key = JSON.stringify(props)\n if (cache[key]) {\n if (cache[key] instanceof Promise) {\n return await cache[key]\n }\n return cache[key]\n }\n\n let resolver: Function = () => {}\n cache[key] = new Promise((res) => {\n resolver = res\n })\n\n const tmpDir = join(process.cwd(), '.tamagui')\n const configOutPath = join(tmpDir, `tamagui.config.cjs`)\n const baseComponents = props.components.filter((x) => x !== '@tamagui/core')\n\n const componentOutPaths = baseComponents.map((componentModule) =>\n join(\n tmpDir,\n `${componentModule\n .split(sep)\n .join('-')\n .replace(/[^a-z0-9]+/gi, '')}-components.config.cjs`\n )\n )\n\n const external = [\n '@tamagui/core',\n '@tamagui/web',\n '@tamagui/core-node',\n 'react',\n 'react-dom',\n 'react-native-svg',\n ]\n const configEntry = props.config ? join(process.cwd(), props.config) : ''\n\n if (\n process.env.NODE_ENV === 'development' &&\n process.env.DEBUG?.startsWith('tamagui')\n ) {\n console.log(`Building config entry`, configEntry)\n }\n\n // build them to node-compat versions\n try {\n await ensureDir(tmpDir)\n } catch {\n //\n }\n\n colorLog(\n Color.FgYellow,\n `\nTamagui built config and components:`\n )\n colorLog(\n Color.Dim,\n `\n Config .${sep}${relative(process.cwd(), configOutPath)}\n Components ${[\n ...componentOutPaths.map((p) => `.${sep}${relative(process.cwd(), p)}`),\n ].join('\\n ')}\n`\n )\n\n await Promise.all([\n props.config\n ? bundle({\n entryPoints: [configEntry],\n external,\n outfile: configOutPath,\n })\n : null,\n ...baseComponents.map((componentModule, i) => {\n return bundle({\n entryPoints: [componentModule],\n resolvePlatformSpecificEntries: true,\n external,\n outfile: componentOutPaths[i],\n })\n }),\n ])\n\n try {\n registerRequire()\n const out = require(configOutPath)\n const config = out.default || out\n\n if (!config) {\n throw new Error(`No config: ${config}`)\n }\n\n let components = loadComponents({\n ...props,\n components: componentOutPaths,\n })\n\n if (!components) {\n throw new Error(`No components found: ${componentOutPaths.join(', ')}`)\n }\n\n // map from built back to original module names\n for (const component of components) {\n component.moduleName =\n baseComponents[componentOutPaths.indexOf(component.moduleName)]\n if (!component.moduleName) {\n throw new Error(`Tamagui internal err`)\n }\n }\n\n // always load core so we can optimize if directly importing\n const coreComponents = loadComponents({\n ...props,\n components: ['@tamagui/core-node'],\n })\n if (coreComponents) {\n coreComponents[0].moduleName = '@tamagui/core'\n components = [...components, ...coreComponents]\n }\n\n if (\n process.env.NODE_ENV === 'development' &&\n process.env.DEBUG?.startsWith('tamagui')\n ) {\n console.log('Loaded components', components)\n }\n\n cache[key] = {\n components,\n nameToPaths: {},\n tamaguiConfig: config,\n }\n\n // init core-node\n createTamagui(cache[key].tamaguiConfig)\n\n resolver(cache[key])\n\n return cache[key]\n } finally {\n unregisterRequire()\n }\n}\n\nexport function resolveWebOrNativeSpecificEntry(entry: string) {\n const workspaceRoot = resolve()\n const resolved = require.resolve(entry, { paths: [workspaceRoot] })\n const ext = extname(resolved)\n const fileName = basename(resolved).replace(ext, '')\n const specificExt = process.env.TAMAGUI_TARGET === 'web' ? 'web' : 'native'\n const specificFile = join(dirname(resolved), fileName + '.' + specificExt + ext)\n if (existsSync(specificFile)) {\n return specificFile\n }\n return entry\n}\n\nconst esbuildOptions = {\n loader: 'tsx',\n target: 'es2018',\n format: 'cjs',\n jsx: 'transform',\n platform: 'node',\n} as const\n\n// loads in-process using esbuild-register\nexport function loadTamaguiSync(props: Props): TamaguiProjectInfo {\n const key = JSON.stringify(props)\n if (cache[key]) {\n return cache[key]\n }\n\n const { unregister } = require('esbuild-register/dist/node').register(esbuildOptions)\n\n try {\n registerRequire()\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const devValueOG = globalThis['__DEV__' as any]\n globalThis['__DEV__' as any] = process.env.NODE_ENV === 'development'\n\n try {\n // config\n let tamaguiConfig: TamaguiInternalConfig | null = null\n if (props.config) {\n const configPath = join(process.cwd(), props.config)\n const exp = require(configPath)\n tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n const confPath = require.resolve(configPath)\n throw new Error(`Can't find valid config in ${confPath}:\n \n Be sure you \"export default\" the config.`)\n }\n }\n\n // components\n const components = loadComponents(props)\n if (!components) {\n throw new Error(`No components loaded`)\n }\n if (process.env.DEBUG === 'tamagui') {\n console.log(`components`, components)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n globalThis['__DEV__' as any] = devValueOG\n\n // set up core-node\n if (props.config && tamaguiConfig) {\n createTamagui(tamaguiConfig as any)\n }\n\n cache[key] = {\n components,\n tamaguiConfig,\n nameToPaths: getNameToPaths(),\n }\n } catch (err) {\n if (err instanceof Error) {\n console.warn(\n `Error loading tamagui.config.ts (set DEBUG=tamagui to see full stack), running tamagui without custom config`\n )\n console.log(`\\n\\n ${err.message}\\n\\n`)\n if (SHOULD_DEBUG) {\n console.log(err.stack)\n }\n } else {\n console.error(`Error loading tamagui.config.ts`, err)\n }\n return {\n components: [],\n tamaguiConfig: getDefaultTamaguiConfig(),\n nameToPaths: {},\n }\n }\n\n return cache[key]\n } finally {\n unregister()\n unregisterRequire()\n }\n}\n\nfunction interopDefaultExport(mod: any) {\n return mod?.default ?? mod\n}\n\nconst cacheComponents: Record<string, LoadedComponents[]> = {}\n\nfunction transformAddExports(ast: t.File) {\n const usedNames = new Set<string>()\n\n // avoid clobbering\n // @ts-ignore\n traverse(ast, {\n ExportNamedDeclaration(nodePath) {\n if (nodePath.node.specifiers) {\n for (const spec of nodePath.node.specifiers) {\n usedNames.add(\n t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value\n )\n }\n }\n },\n })\n\n // @ts-ignore\n traverse(ast, {\n VariableDeclaration(nodePath) {\n // top level only\n if (!t.isProgram(nodePath.parent)) return\n const decs = nodePath.node.declarations\n if (decs.length > 1) return\n const [dec] = decs\n if (!t.isIdentifier(dec.id)) return\n if (!dec.init) return\n if (usedNames.has(dec.id.name)) return\n usedNames.add(dec.id.name)\n nodePath.replaceWith(\n t.exportNamedDeclaration(t.variableDeclaration('let', [dec]), [\n t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name)),\n ])\n )\n },\n })\n\n // @ts-ignore\n return generate(ast as any, {\n concise: false,\n filename: 'test.tsx',\n retainLines: false,\n sourceMaps: false,\n }).code\n}\n\nconst esbuildit = (src: string, target?: 'modern') => {\n return esbuild.transformSync(src, {\n ...esbuildOptions,\n ...(target === 'modern' && {\n target: 'es2022',\n jsx: 'transform',\n loader: 'tsx',\n platform: 'neutral',\n format: 'esm',\n }),\n }).code\n}\n\nfunction loadComponents(props: Props): null | LoadedComponents[] {\n const componentsModules = props.components\n const key = componentsModules.join('')\n if (cacheComponents[key]) {\n return cacheComponents[key]\n }\n try {\n const info: LoadedComponents[] = componentsModules.flatMap((name) => {\n const extension = extname(name)\n const isLocal = Boolean(extension)\n // during props.config pass we are passing in pre-bundled stuff\n const isDynamic = isLocal && !props.config\n\n if (isDynamic && !process.env.TAMAGUI_ENABLE_DYNAMIC_LOAD) {\n return []\n }\n\n const fileContents = isDynamic ? readFileSync(name, 'utf-8') : ''\n const loadModule = isDynamic\n ? join(dirname(name), `.tamagui-dynamic-eval-${basename(name)}.tsx`)\n : name\n let writtenContents = fileContents\n let didBabel = false\n\n function attemptLoad({ forceExports = false } = {}) {\n // need to write to tsx to enable reading it properly (:/ esbuild-register)\n if (isDynamic) {\n writtenContents = forceExports\n ? esbuildit(\n transformAddExports(babelParse(esbuildit(fileContents, 'modern')))\n )\n : esbuildit(fileContents)\n\n writeFileSync(loadModule, writtenContents)\n }\n\n if (process.env.DEBUG === 'tamagui') {\n console.log(`loadModule`, loadModule, require.resolve(loadModule))\n }\n\n return {\n moduleName: name,\n nameToInfo: getComponentStaticConfigByName(\n name,\n interopDefaultExport(require(loadModule))\n ),\n }\n }\n\n const dispose = () => {\n isDynamic && removeSync(loadModule)\n }\n\n try {\n const res = attemptLoad({\n forceExports: true,\n })\n didBabel = true\n return res\n } catch (err) {\n console.log('babel err', err, writtenContents)\n // ok\n writtenContents = fileContents\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Error parsing babel likely`, err)\n }\n } finally {\n dispose()\n }\n\n try {\n return attemptLoad({\n forceExports: false,\n })\n } catch (err) {\n if (!process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD) {\n console.log(`\n\nTamagui attempted but failed to dynamically load components in:\n ${name}\n\nThis will leave some styled() tags unoptimized.\nDisable this file (or dynamic loading altogether):\n\n disableExtractFoundComponents: ['${name}'] | true\n\nQuiet this warning with environment variable:\n \n TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1\n\n`)\n console.log(err)\n console.log(\n `At: ${loadModule}`,\n `\\ndidBabel: ${didBabel}`,\n `\\nIn:`,\n writtenContents,\n `\\nisDynamic: `,\n isDynamic\n )\n }\n return []\n } finally {\n dispose()\n }\n })\n cacheComponents[key] = info\n return info\n } catch (err: any) {\n console.log(`Tamagui error bundling components`, err.message, err.stack)\n return null\n }\n}\n\nfunction getComponentStaticConfigByName(name: string, exported: any) {\n const components: Record<string, { staticConfig: StaticConfigParsed }> = {}\n try {\n if (!exported || typeof exported !== 'object' || Array.isArray(exported)) {\n throw new Error(`Invalid export from package ${name}: ${typeof exported}`)\n }\n for (const key in exported) {\n const found = getTamaguiComponent(key, exported[key])\n if (found) {\n // remove non-stringifyable\n const { Component, ...sc } = found.staticConfig\n components[key] = { staticConfig: sc }\n }\n }\n } catch (err) {\n if (process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD !== '1') {\n console.error(\n `Tamagui failed getting from ${name} (Disable error by setting environment variable TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1)`\n )\n console.error(err)\n }\n }\n return components\n}\n\nfunction getTamaguiComponent(\n name: string,\n Component: any\n): undefined | { staticConfig: StaticConfigParsed } {\n if (name[0].toUpperCase() !== name[0]) {\n return\n }\n const staticConfig = Component?.staticConfig as StaticConfigParsed | undefined\n if (staticConfig) {\n return Component\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { basename, dirname, extname, join, resolve } from 'path'\n\nimport { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport { createTamagui } from '@tamagui/core-node'\nimport { CLIResolvedOptions, CLIUserOptions } from '@tamagui/types'\nimport type { TamaguiInternalConfig } from '@tamagui/web'\nimport esbuild from 'esbuild'\nimport fs, { existsSync, pathExists, readJSON } from 'fs-extra'\n\nimport { SHOULD_DEBUG } from '../constants.js'\nimport { getNameToPaths, registerRequire, unregisterRequire } from '../require.js'\nimport { TamaguiOptions } from '../types.js'\nimport {\n Props,\n TamaguiProjectInfo,\n bundleConfig,\n esbuildOptions,\n loadComponents,\n} from './bundleConfig.js'\nimport { generateTamaguiConfig } from './generateTamaguiConfig.js'\n\nconst cache = {}\n\nexport async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {\n const key = JSON.stringify(props)\n if (cache[key]) {\n if (cache[key] instanceof Promise) {\n return await cache[key]\n }\n return cache[key]\n }\n\n let resolver: Function = () => {}\n cache[key] = new Promise((res) => {\n resolver = res\n })\n\n try {\n registerRequire()\n const bundleInfo = await bundleConfig(props)\n\n cache[key] = bundleInfo\n\n // init core-node\n createTamagui(cache[key].tamaguiConfig)\n\n resolver(cache[key])\n\n return cache[key]\n } finally {\n unregisterRequire()\n }\n}\n\nexport function resolveWebOrNativeSpecificEntry(entry: string) {\n const workspaceRoot = resolve()\n const resolved = require.resolve(entry, { paths: [workspaceRoot] })\n const ext = extname(resolved)\n const fileName = basename(resolved).replace(ext, '')\n const specificExt = process.env.TAMAGUI_TARGET === 'web' ? 'web' : 'native'\n const specificFile = join(dirname(resolved), fileName + '.' + specificExt + ext)\n if (existsSync(specificFile)) {\n return specificFile\n }\n return entry\n}\n\n// loads in-process using esbuild-register\nexport function loadTamaguiSync(props: Props): TamaguiProjectInfo {\n const key = JSON.stringify(props)\n if (cache[key]) {\n return cache[key]\n }\n\n const { unregister } = require('esbuild-register/dist/node').register(esbuildOptions)\n\n try {\n registerRequire()\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const devValueOG = globalThis['__DEV__' as any]\n globalThis['__DEV__' as any] = process.env.NODE_ENV === 'development'\n\n try {\n // config\n let tamaguiConfig: TamaguiInternalConfig | null = null\n if (props.config) {\n const configPath = join(process.cwd(), props.config)\n const exp = require(configPath)\n tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n const confPath = require.resolve(configPath)\n throw new Error(`Can't find valid config in ${confPath}:\n \n Be sure you \"export default\" the config.`)\n }\n }\n\n // components\n const components = loadComponents(props)\n if (!components) {\n throw new Error(`No components loaded`)\n }\n if (process.env.DEBUG === 'tamagui') {\n console.log(`components`, components)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n globalThis['__DEV__' as any] = devValueOG\n\n // set up core-node\n if (props.config && tamaguiConfig) {\n createTamagui(tamaguiConfig as any)\n }\n\n cache[key] = {\n components,\n tamaguiConfig,\n nameToPaths: getNameToPaths(),\n }\n } catch (err) {\n if (err instanceof Error) {\n console.warn(\n `Error loading tamagui.config.ts (set DEBUG=tamagui to see full stack), running tamagui without custom config`\n )\n console.log(`\\n\\n ${err.message}\\n\\n`)\n if (SHOULD_DEBUG) {\n console.log(err.stack)\n }\n } else {\n console.error(`Error loading tamagui.config.ts`, err)\n }\n return {\n components: [],\n tamaguiConfig: getDefaultTamaguiConfig(),\n nameToPaths: {},\n }\n }\n\n return cache[key]\n } finally {\n unregister()\n unregisterRequire()\n }\n}\n\nexport async function getOptions({\n root = process.cwd(),\n tsconfigPath = 'tsconfig.json',\n tamaguiOptions,\n host,\n debug,\n}: Partial<CLIUserOptions> = {}): Promise<CLIResolvedOptions> {\n const tsConfigFilePath = join(root, tsconfigPath)\n if (!(await fs.pathExists(tsConfigFilePath)))\n throw new Error(`No tsconfig found: ${tsConfigFilePath}`)\n const dotDir = join(root, '.tamagui')\n const pkgJson = await readJSON(join(root, 'package.json'))\n\n return {\n mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',\n root,\n host: host || '127.0.0.1',\n pkgJson,\n debug,\n tsconfigPath,\n tamaguiOptions: {\n components: ['tamagui'],\n config: await getDefaultTamaguiConfigPath(),\n ...tamaguiOptions,\n },\n paths: {\n dotDir,\n conf: join(dotDir, 'tamagui.config.json'),\n types: join(dotDir, 'types.json'),\n },\n }\n}\n\nexport async function watchTamaguiConfig(tamaguiOptions: TamaguiOptions) {\n const options = await getOptions({ tamaguiOptions })\n\n if (!options.tamaguiOptions.config) return\n\n await generateTamaguiConfig(options)\n const context = await esbuild.context({\n entryPoints: [options.tamaguiOptions.config],\n sourcemap: false,\n // dont output just use esbuild as a watcher\n write: false,\n\n plugins: [\n {\n name: `on-rebuild`,\n setup({ onEnd }) {\n onEnd((res) => {\n generateTamaguiConfig(options)\n })\n },\n },\n ],\n })\n\n await context.watch()\n}\n\nconst defaultPaths = ['tamagui.config.ts', join('src', 'tamagui.config.ts')]\nlet cachedPath = ''\n\nasync function getDefaultTamaguiConfigPath() {\n if (cachedPath) return cachedPath\n const existingPaths = await Promise.all(defaultPaths.map((path) => pathExists(path)))\n const existing = existingPaths.findIndex((x) => !!x)\n const found = defaultPaths[existing]\n if (!found) {\n throw new Error(`No found tamagui.config.ts`)\n }\n cachedPath = found\n return found\n}\n\nexport { TamaguiProjectInfo }"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0D;AAE1D,iCAAwC;AACxC,uBAA8B;AAG9B,qBAAoB;AACpB,sBAAqD;AAErD,uBAA6B;AAC7B,qBAAmE;AAEnE,0BAMO;AACP,mCAAsC;AAEtC,MAAM,QAAQ,CAAC;AAEf,eAAsB,YAAY,OAA2C;AAC3E,QAAM,MAAM,KAAK,UAAU,KAAK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AAO,mBAAmB,CAAC;AAC3E,IAAI,aAAa;AAEjB,eAAe,8BAA8B;AAC3C,MAAI;AAAY,WAAO;AACvB,QAAM,gBAAgB,MAAM,QAAQ,IAAI,aAAa,IAAI,CAAC,aAAS,4BAAW,IAAI,CAAC,CAAC;AACpF,QAAM,WAAW,cAAc,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,QAAM,QAAQ,aAAa,QAAQ;AACnC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AACA,eAAa;AACb,SAAO;AACT;",
|
|
6
|
+
"names": ["fs", "esbuild"]
|
|
7
7
|
}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["import type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { PseudoStyles, StaticConfig } from '@tamagui/core-node'\nimport type { StyleObject } from '@tamagui/helpers'\
|
|
4
|
+
"sourcesContent": ["import type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { PseudoStyles, StaticConfig } from '@tamagui/core-node'\nimport type { StyleObject } from '@tamagui/helpers'\nimport type { TamaguiOptions } from '@tamagui/types'\nimport type { ViewStyle } from 'react-native'\nimport { LoadedComponents } from './extractor/bundleConfig'\n\n\n// @ts-ignore\nexport type { TamaguiOptions } from '@tamagui/types'\n\nexport type { StyleObject } from '@tamagui/helpers'\n\nexport type ClassNameObject = t.StringLiteral | t.Expression\n\nexport interface CacheObject {\n [key: string]: any\n}\n\nexport interface LogOptions {\n clear?: boolean\n timestamp?: boolean\n error?: Error | null\n}\n\nexport interface Logger {\n info(msg: string, options?: LogOptions): void\n warn(msg: string, options?: LogOptions): void\n error(msg: string, options?: LogOptions): void\n}\n\nexport type ExtractorOptions = {\n logger?: Logger\n}\n\nexport type ExtractedAttrAttr = {\n type: 'attr'\n value: t.JSXAttribute | t.JSXSpreadAttribute\n}\n\nexport type ExtractedAttrStyle = {\n type: 'style'\n value: ViewStyle & PseudoStyles\n attr?: t.JSXAttribute | t.JSXSpreadAttribute\n name?: string\n}\n\nexport type ExtractedAttr =\n | ExtractedAttrAttr\n | { type: 'ternary'; value: Ternary }\n | ExtractedAttrStyle\n\nexport type ExtractTagProps = {\n parserProps: TamaguiOptionsWithFileInfo\n attrs: ExtractedAttr[]\n node: t.JSXOpeningElement\n attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any\n jsxPath: NodePath<t.JSXElement>\n programPath: NodePath<t.Program>\n originalNodeName: string\n lineNumbers: string\n filePath: string\n isFlattened: boolean\n completeProps: Record<string, any>\n staticConfig: StaticConfig\n}\n\nexport type TamaguiOptionsWithFileInfo = TamaguiOptions & {\n sourcePath?: string\n allLoadedComponents: LoadedComponents[]\n}\n\nexport type ExtractorParseProps = Omit<\n TamaguiOptionsWithFileInfo,\n 'allLoadedComponents'\n> & {\n target: 'native' | 'html'\n shouldPrintDebug?: boolean | 'verbose'\n onExtractTag: (props: ExtractTagProps) => void\n getFlattenedNode?: (props: { isTextView: boolean; tag: string }) => string\n extractStyledDefinitions?: boolean\n // identifer, rule\n onStyleRule?: (identifier: string, rules: string[]) => void\n}\n\nexport interface Ternary {\n test: t.Expression\n // shorthand props that don't use hooks\n inlineMediaQuery?: string\n remove: Function\n consequent: Object | null\n alternate: Object | null\n}\n\nexport type ClassNameToStyleObj = {\n [key: string]: StyleObject\n}\n\nexport interface PluginContext {\n write: (path: string, rules: { [key: string]: string }) => any\n}"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|