tamagui-loader 1.88.12 → 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.
- package/LICENSE +21 -0
- package/dist/esm/TamaguiPlugin.mjs +168 -0
- package/dist/esm/css.mjs +13 -0
- package/dist/esm/index.mjs +7 -0
- package/dist/esm/loader.mjs +57 -0
- package/dist/esm/shouldExclude.mjs +6 -0
- package/package.json +7 -7
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,168 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import path, { dirname, join } from "path";
|
|
3
|
+
import { loadTamagui, watchTamaguiConfig } from "@tamagui/static";
|
|
4
|
+
import buildResolver from "esm-resolve";
|
|
5
|
+
import webpack from "webpack";
|
|
6
|
+
import { shouldExclude } from "./shouldExclude.mjs";
|
|
7
|
+
const dir = process.cwd(),
|
|
8
|
+
resolver = buildResolver(join(dir, "index.js"), {
|
|
9
|
+
constraints: "node"
|
|
10
|
+
});
|
|
11
|
+
class TamaguiPlugin {
|
|
12
|
+
constructor(options = {
|
|
13
|
+
platform: "web",
|
|
14
|
+
components: ["@tamagui/core"]
|
|
15
|
+
}) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
pluginName = "TamaguiPlugin";
|
|
19
|
+
resolveEsm = (relativePath, onlyRequire = !1) => {
|
|
20
|
+
if (this.options.isServer || onlyRequire) return require.resolve(relativePath);
|
|
21
|
+
const esm = resolver(relativePath);
|
|
22
|
+
return esm ? path.join(dir, esm) : require.resolve(relativePath);
|
|
23
|
+
};
|
|
24
|
+
safeResolves = (resolves, multiple = !1) => {
|
|
25
|
+
const res = [];
|
|
26
|
+
for (const [out, mod] of resolves) {
|
|
27
|
+
if (out.endsWith("$")) {
|
|
28
|
+
res.push([out, mod]);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
res.push([out, this.resolveEsm(mod)]), multiple && res.push([out, this.resolveEsm(mod, !0)]);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (out.includes("@gorhom/bottom-sheet")) continue;
|
|
35
|
+
process.env.DEBUG?.startsWith("tamagui") && console.info(` withTamagui skipping resolving ${out}`, err);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
};
|
|
40
|
+
get componentsFullPaths() {
|
|
41
|
+
return this.safeResolves(this.options.components.map(moduleName => [moduleName, moduleName]), !0);
|
|
42
|
+
}
|
|
43
|
+
get componentsBaseDirs() {
|
|
44
|
+
return this.componentsFullPaths.map(([_, fullPath]) => {
|
|
45
|
+
let rootPath = dirname(fullPath);
|
|
46
|
+
for (; rootPath.length > 1;) {
|
|
47
|
+
const pkg = join(rootPath, "package.json");
|
|
48
|
+
if (existsSync(pkg)) return rootPath;
|
|
49
|
+
rootPath = join(rootPath, "..");
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
isInComponentModule = fullPath => this.componentsBaseDirs.some(componentDir => fullPath.startsWith(componentDir));
|
|
55
|
+
get defaultAliases() {
|
|
56
|
+
return Object.fromEntries(this.safeResolves([["@tamagui/core/reset.css", "@tamagui/core/reset.css"], ["@tamagui/core", "@tamagui/core"], ["@tamagui/web", "@tamagui/web"],
|
|
57
|
+
// web specific light react-native-svg, optional, can use svgs but had issues with compat
|
|
58
|
+
["react-native-svg", "@tamagui/react-native-svg"],
|
|
59
|
+
// fixes https://github.com/kentcdodds/mdx-bundler/issues/143
|
|
60
|
+
["react/jsx-runtime.js", "react/jsx-runtime"], ["react/jsx-runtime", "react/jsx-runtime"], ["react/jsx-dev-runtime.js", "react/jsx-dev-runtime"], ["react/jsx-dev-runtime", "react/jsx-dev-runtime"], ["react-native-reanimated", "react-native-reanimated"], ["@testing-library/react-native", "@tamagui/proxy-worm"], ["@gorhom/bottom-sheet$", "@gorhom/bottom-sheet"],
|
|
61
|
+
// fix reanimated 3
|
|
62
|
+
["react-native/Libraries/Renderer/shims/ReactFabric", "@tamagui/proxy-worm"],
|
|
63
|
+
// @ts-expect-error deprecated
|
|
64
|
+
...(this.options.useReactNativeWebLite ? [["react-native$", "react-native-web-lite"], ["react-native-web$", "react-native-web-lite"]] : [["react-native$", "react-native-web"], ["react-native-web$", "react-native-web"]])]));
|
|
65
|
+
}
|
|
66
|
+
apply(compiler) {
|
|
67
|
+
if (compiler.watchMode && !this.options.disableWatchConfig && watchTamaguiConfig(this.options).then(watcher => {
|
|
68
|
+
process.once("exit", () => {
|
|
69
|
+
watcher.dispose();
|
|
70
|
+
});
|
|
71
|
+
}), this.options.exclude || (this.options.exclude = path2 => this.isInComponentModule(path2) ? !1 : shouldExclude(path2)), compiler.hooks.beforeRun.tapPromise(this.pluginName, async () => {
|
|
72
|
+
await loadTamagui(this.options);
|
|
73
|
+
}), compiler.hooks.normalModuleFactory.tap(this.pluginName, nmf => {
|
|
74
|
+
nmf.hooks.createModule.tap(this.pluginName,
|
|
75
|
+
// @ts-expect-error CreateData is typed as 'object'...
|
|
76
|
+
createData => {
|
|
77
|
+
createData.matchResource?.endsWith(".tamagui.css") && (createData.settings.sideEffects = !0);
|
|
78
|
+
});
|
|
79
|
+
}), !this.options.disableAliases) {
|
|
80
|
+
const existingAlias = compiler.options.resolve.alias;
|
|
81
|
+
Array.isArray(existingAlias) || typeof existingAlias == "object" && Object.assign(existingAlias, this.defaultAliases);
|
|
82
|
+
}
|
|
83
|
+
const excludeExports = this.options.excludeReactNativeWebExports;
|
|
84
|
+
if (excludeExports && Array.isArray(excludeExports)) try {
|
|
85
|
+
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join("|")}).*js`,
|
|
86
|
+
regex = new RegExp(regexStr);
|
|
87
|
+
compiler.hooks.environment.tap("MyPlugin", () => {
|
|
88
|
+
new webpack.NormalModuleReplacementPlugin(regex, this.resolveEsm("@tamagui/proxy-worm")).apply(compiler);
|
|
89
|
+
});
|
|
90
|
+
} catch {
|
|
91
|
+
console.warn(`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(", ")}`);
|
|
92
|
+
}
|
|
93
|
+
this.options.emitSingleCSSFile && (console.info(" \u27A1 [tamagui] \u{1F3A8} combining css into one file"), compiler.hooks.make.tap(this.pluginName, compilation => {
|
|
94
|
+
compilation.hooks.processAssets.tap(this.pluginName, assets => {
|
|
95
|
+
try {
|
|
96
|
+
const cssFiles = Object.keys(assets).filter(asset => asset.endsWith(".css"));
|
|
97
|
+
if (cssFiles.length === 0) return;
|
|
98
|
+
const combinedCSS = cssFiles.reduce((acc, file) => {
|
|
99
|
+
const cssContent = compilation.assets[file].source();
|
|
100
|
+
return `${acc}
|
|
101
|
+
${cssContent}`;
|
|
102
|
+
}, "");
|
|
103
|
+
for (const [index, cssFile] of cssFiles.entries()) index > 0 ? compilation.updateAsset(cssFile, new compiler.webpack.sources.RawSource("")) : (console.info(` \u27A1 [tamagui] \u{1F3A8} emitting single css to ${cssFile}`), compilation.updateAsset(cssFile, new compiler.webpack.sources.RawSource(Buffer.from(combinedCSS))));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
compilation.errors.push(error);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
})), compiler.options.resolve.extensions = [... /* @__PURE__ */new Set([".web.tsx", ".web.ts", ".web.js", ".ts", ".tsx", ".js", ...(compiler.options.resolve.extensions || [])])];
|
|
109
|
+
const mainFields = compiler.options.resolve.mainFields;
|
|
110
|
+
if (mainFields && (compiler.options.resolve.mainFields = Array.isArray(mainFields) ? mainFields : [mainFields], this.options.disableModuleJSXEntry || mainFields.unshift("module:jsx")), !compiler.options.module) return;
|
|
111
|
+
const {
|
|
112
|
+
jsLoader
|
|
113
|
+
} = this.options,
|
|
114
|
+
existing = compiler.options.module.rules,
|
|
115
|
+
rules = existing.find(x => typeof x == "object" && "oneOf" in x ? x : null)?.oneOf ?? existing,
|
|
116
|
+
nextJsRules = rules.findIndex(x => x?.use && x.use.loader === "next-swc-loader" && x.issuerLayer !== "api"),
|
|
117
|
+
esbuildLoader = {
|
|
118
|
+
loader: require.resolve("esbuild-loader"),
|
|
119
|
+
options: {
|
|
120
|
+
target: "es2021",
|
|
121
|
+
keepNames: !0,
|
|
122
|
+
loader: "tsx",
|
|
123
|
+
tsconfigRaw: {
|
|
124
|
+
module: this.options.isServer ? "commonjs" : "esnext",
|
|
125
|
+
isolatedModules: !0,
|
|
126
|
+
resolveJsonModule: !0
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
if (!this.options.disable) {
|
|
131
|
+
const tamaguiLoader = {
|
|
132
|
+
loader: require.resolve("tamagui-loader"),
|
|
133
|
+
options: {
|
|
134
|
+
...this.options,
|
|
135
|
+
_disableLoadTamagui: !0
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
if (nextJsRules === -1) existing.push({
|
|
139
|
+
// looks like its in jsx dir (could be better but windows path sep)
|
|
140
|
+
test: /jsx.*\.m?[jt]sx?$/,
|
|
141
|
+
exclude: this.options.exclude,
|
|
142
|
+
resolve: {
|
|
143
|
+
fullySpecified: !1
|
|
144
|
+
},
|
|
145
|
+
use: [esbuildLoader]
|
|
146
|
+
}), existing.push({
|
|
147
|
+
test: this.options.test ?? /\.m?[jt]sx?$/,
|
|
148
|
+
exclude: this.options.exclude,
|
|
149
|
+
resolve: {
|
|
150
|
+
fullySpecified: !1
|
|
151
|
+
},
|
|
152
|
+
use: [tamaguiLoader]
|
|
153
|
+
});else if (!this.options.disableEsbuildLoader) {
|
|
154
|
+
const startIndex = nextJsRules ? nextJsRules + 1 : 0,
|
|
155
|
+
existingLoader = nextJsRules ? rules[startIndex] : void 0;
|
|
156
|
+
rules.splice(startIndex, 0, {
|
|
157
|
+
test: this.options.test ?? /\.m?[jt]sx?$/,
|
|
158
|
+
exclude: this.options.exclude,
|
|
159
|
+
resolve: {
|
|
160
|
+
fullySpecified: !1
|
|
161
|
+
},
|
|
162
|
+
use: [...(jsLoader ? [jsLoader] : []), ...(existingLoader && nextJsRules ? [].concat(existingLoader.use) : []), ...(jsLoader || existingLoader ? [] : [esbuildLoader]), tamaguiLoader]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export { TamaguiPlugin };
|
package/dist/esm/css.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function loader() {
|
|
2
|
+
this.async();
|
|
3
|
+
const options = {
|
|
4
|
+
...this.getOptions()
|
|
5
|
+
};
|
|
6
|
+
let out = Buffer.from(options.cssData, "base64").toString("utf-8");
|
|
7
|
+
if (out) return this.callback(null, out || "");
|
|
8
|
+
this.callback({
|
|
9
|
+
message: "No CSS found",
|
|
10
|
+
name: "missing_css"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export { loader as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./TamaguiPlugin.mjs";
|
|
2
|
+
export * from "./shouldExclude.mjs";
|
|
3
|
+
process.env.TAMAGUI_TARGET = "web";
|
|
4
|
+
process.env.IS_STATIC = "is_static";
|
|
5
|
+
process.env.TAMAGUI_IS_SERVER = "true";
|
|
6
|
+
var src_default = require("./loader").loader;
|
|
7
|
+
export { src_default as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createExtractor, extractToClassNames, getPragmaOptions } from "@tamagui/static";
|
|
2
|
+
Error.stackTraceLimit = 1 / 0;
|
|
3
|
+
const CSS_LOADER_PATH = require.resolve("./css");
|
|
4
|
+
Error.stackTraceLimit = 1 / 0;
|
|
5
|
+
const extractor = createExtractor();
|
|
6
|
+
let index = 0;
|
|
7
|
+
process.env.TAMAGUI_TARGET = "web";
|
|
8
|
+
const loader = async function (sourceIn) {
|
|
9
|
+
this.cacheable(!0);
|
|
10
|
+
const callback = this.async(),
|
|
11
|
+
source = sourceIn.toString();
|
|
12
|
+
try {
|
|
13
|
+
const options = {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
platform: "web",
|
|
16
|
+
...this.getOptions()
|
|
17
|
+
},
|
|
18
|
+
sourcePath = `${this.resourcePath}`,
|
|
19
|
+
{
|
|
20
|
+
shouldDisable,
|
|
21
|
+
shouldPrintDebug
|
|
22
|
+
} = getPragmaOptions({
|
|
23
|
+
source,
|
|
24
|
+
path: sourcePath
|
|
25
|
+
});
|
|
26
|
+
if (shouldPrintDebug === "verbose" && (console.warn(`
|
|
27
|
+
|
|
28
|
+
--- Incoming source ---
|
|
29
|
+
|
|
30
|
+
`), console.warn(source)), shouldDisable) return shouldPrintDebug && console.info("Disabling on file via pragma"), callback(null, source);
|
|
31
|
+
const cssPath = `${sourcePath}.${index++}.tamagui.css`,
|
|
32
|
+
extracted = await extractToClassNames({
|
|
33
|
+
extractor,
|
|
34
|
+
source,
|
|
35
|
+
sourcePath,
|
|
36
|
+
options,
|
|
37
|
+
shouldPrintDebug
|
|
38
|
+
});
|
|
39
|
+
if (!extracted) return callback(null, source);
|
|
40
|
+
if (extracted.styles) {
|
|
41
|
+
const cssQuery = `cssData=${Buffer.from(extracted.styles).toString("base64")}`,
|
|
42
|
+
remReq = this.remainingRequest,
|
|
43
|
+
importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`;
|
|
44
|
+
extracted.js = `${extracted.js}
|
|
45
|
+
|
|
46
|
+
require(${JSON.stringify(importPath)})`;
|
|
47
|
+
}
|
|
48
|
+
callback(null, extracted.js, extracted.map);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
const message = err instanceof Error ? `${err.message}
|
|
51
|
+
${err.stack}` : String(err);
|
|
52
|
+
console.error(`Tamagui Webpack Loader Error:
|
|
53
|
+
`, ` ${message}
|
|
54
|
+
`), message.includes("Cannot create proxy") && console.info("This is usually due to components not loading at build-time. Check for logs just below the line above:"), callback(null, source);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export { loader };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
const shouldExclude = (filePath, projectRoot) => !(projectRoot && filePath.includes(projectRoot) && filePath.endsWith("sx") || isTamaguiDistJSX(filePath));
|
|
3
|
+
function isTamaguiDistJSX(filePath) {
|
|
4
|
+
return filePath.includes("/dist/jsx/".replace(/\//g, path.sep));
|
|
5
|
+
}
|
|
6
|
+
export { shouldExclude };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tamagui-loader",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"clean:build": "tamagui-build clean:build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@tamagui/cli-color": "1.
|
|
22
|
-
"@tamagui/core": "1.
|
|
23
|
-
"@tamagui/static": "1.
|
|
24
|
-
"@tamagui/web": "1.
|
|
21
|
+
"@tamagui/cli-color": "1.89.0-1706308641099",
|
|
22
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
23
|
+
"@tamagui/static": "1.89.0-1706308641099",
|
|
24
|
+
"@tamagui/web": "1.89.0-1706308641099",
|
|
25
25
|
"esbuild-loader": "^3.0.1",
|
|
26
26
|
"esm-resolve": "^1.0.8",
|
|
27
|
-
"fs-extra": "^11.
|
|
27
|
+
"fs-extra": "^11.2.0",
|
|
28
28
|
"loader-utils": "^3.2.1",
|
|
29
29
|
"lodash": "^4.17.21"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tamagui/build": "1.
|
|
32
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
33
33
|
"prettyjson": "^1.2.5",
|
|
34
34
|
"webpack": "^5.88.2"
|
|
35
35
|
},
|