@multiplatform.one/vite-plugin-webext 9.17.0 → 10.1.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.
- package/lib/index.cjs +21 -62
- package/lib/index.mjs +22 -63
- package/package.json +3 -3
- package/src/index.ts +30 -86
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
package/lib/index.cjs
CHANGED
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
//#endregion
|
|
29
29
|
let node_fs = require("node:fs");
|
|
30
30
|
node_fs = __toESM(node_fs, 1);
|
|
31
|
-
let node_module = require("node:module");
|
|
32
31
|
let node_path = require("node:path");
|
|
33
32
|
node_path = __toESM(node_path, 1);
|
|
34
33
|
let _multiplatform_one_utils_dev = require("@multiplatform.one/utils/dev");
|
|
@@ -79,70 +78,25 @@ function shikiStubPlugin() {
|
|
|
79
78
|
}
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
|
-
function barePackageName(specifier) {
|
|
83
|
-
if (!specifier || /^[./#\\]/.test(specifier)) return;
|
|
84
|
-
if (/^(node|data|file|https?):/.test(specifier)) return;
|
|
85
|
-
const packageName = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
86
|
-
if (node_module.builtinModules.includes(packageName)) return;
|
|
87
|
-
return packageName;
|
|
88
|
-
}
|
|
89
|
-
/** Node ESM bare-import resolution walks parent node_modules dirs and — unlike
|
|
90
|
-
* CJS — ignores NODE_PATH. Presence of the package dir is what we probe. */
|
|
91
|
-
function packageVisibleFromDir(packageName, fromDir) {
|
|
92
|
-
let dir = fromDir;
|
|
93
|
-
while (true) {
|
|
94
|
-
if (node_fs.default.existsSync(node_path.default.join(dir, "node_modules", packageName, "package.json"))) return true;
|
|
95
|
-
const parent = node_path.default.dirname(dir);
|
|
96
|
-
if (parent === dir) return false;
|
|
97
|
-
dir = parent;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
81
|
/**
|
|
101
|
-
* The Tamagui static extractor
|
|
102
|
-
* `<
|
|
103
|
-
*
|
|
104
|
-
* `@tamagui/core`, react…) as live imports resolved FROM that artifact. When
|
|
105
|
-
* one of them cannot be resolved there (pnpm's default isolated layout
|
|
106
|
-
* without a direct `@tamagui/web` dependency), the extractor logs "Error
|
|
107
|
-
* bundling tamagui config: Cannot find package …", swallows the error, and
|
|
108
|
-
* the build exits 0 with a silently deoptimized runtime-styled bundle.
|
|
109
|
-
* Production builds must fail instead: after the build, replay the artifact's
|
|
110
|
-
* imports with the loader semantics the extractor would use — CJS resolution
|
|
111
|
-
* for .cjs (honors NODE_PATH, which pnpm bin shims set), an ESM-style
|
|
112
|
-
* node_modules walk for .mjs (ESM ignores NODE_PATH — exactly the divergence
|
|
113
|
-
* that breaks the .mjs artifact under pnpm) — and name the missing package.
|
|
114
|
-
* A missing artifact (bundling died before writing it) is equally fatal.
|
|
82
|
+
* The Tamagui static extractor writes the app's tamagui config to
|
|
83
|
+
* `<vite root>/.tamagui/tamagui.config.json`.
|
|
84
|
+
* A missing artifact (bundling died before writing it) is fatal.
|
|
115
85
|
*/
|
|
116
86
|
function tamaguiConfigBundleGuard(isDev) {
|
|
87
|
+
let root = process.cwd();
|
|
117
88
|
return {
|
|
118
89
|
name: "webext-tamagui-config-guard",
|
|
90
|
+
configResolved(config) {
|
|
91
|
+
root = config.root;
|
|
92
|
+
},
|
|
119
93
|
closeBundle() {
|
|
120
94
|
if (isDev) return;
|
|
121
|
-
const dotDir = node_path.default.join(
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
const artifact = artifacts.sort((a, b) => node_fs.default.statSync(b).mtimeMs - node_fs.default.statSync(a).mtimeMs)[0];
|
|
128
|
-
const source = node_fs.default.readFileSync(artifact, "utf8");
|
|
129
|
-
const requireFromArtifact = (0, node_module.createRequire)(artifact);
|
|
130
|
-
const importRe = /(?:require\s*\(\s*|import\s*\(\s*|from\s*|import\s*)["']([^"'\n]+)["']/g;
|
|
131
|
-
const missing = /* @__PURE__ */ new Set();
|
|
132
|
-
for (const match of source.matchAll(importRe)) {
|
|
133
|
-
const packageName = barePackageName(match[1]);
|
|
134
|
-
if (!packageName) continue;
|
|
135
|
-
if (artifact.endsWith(".cjs")) try {
|
|
136
|
-
requireFromArtifact.resolve(packageName);
|
|
137
|
-
} catch {
|
|
138
|
-
missing.add(packageName);
|
|
139
|
-
}
|
|
140
|
-
else if (!packageVisibleFromDir(packageName, dotDir)) missing.add(packageName);
|
|
141
|
-
}
|
|
142
|
-
if (missing.size > 0) {
|
|
143
|
-
const names = [...missing].map((name) => `"${name}"`).join(", ");
|
|
144
|
-
throw new Error(`[${PLUGIN_NAME}] Tamagui config bundling failed: ${names} cannot be resolved from ${artifact}. The Tamagui static extractor swallows this ("Error bundling tamagui config") and ships a deoptimized runtime-styled build. Fix: add ${names} to your app's dependencies — under pnpm's default isolated node_modules, transitive packages are not resolvable from the app.`);
|
|
145
|
-
}
|
|
95
|
+
const dotDir = node_path.default.join(root, ".tamagui");
|
|
96
|
+
const artifact = node_path.default.join(dotDir, "tamagui.config.json");
|
|
97
|
+
if (node_fs.default.existsSync(artifact)) return;
|
|
98
|
+
if (!node_fs.default.existsSync(dotDir)) return;
|
|
99
|
+
throw new Error(`[${PLUGIN_NAME}] the Tamagui static extractor did not produce its bundled config (expected ${artifact}). The build would silently fall back to a deoptimized runtime-styled bundle. Re-run with DEBUG=tamagui to see the underlying bundling error.`);
|
|
146
100
|
}
|
|
147
101
|
};
|
|
148
102
|
}
|
|
@@ -186,6 +140,10 @@ function baseResolve(options, workspaceRoot, workspaceRootInferred) {
|
|
|
186
140
|
find,
|
|
187
141
|
replacement
|
|
188
142
|
})),
|
|
143
|
+
...Object.entries((0, _multiplatform_one_utils_dev.movedDepAliases)(workspaceRoot)).map(([find, replacement]) => ({
|
|
144
|
+
find,
|
|
145
|
+
replacement
|
|
146
|
+
})),
|
|
189
147
|
{
|
|
190
148
|
find: "react-native",
|
|
191
149
|
replacement: "react-native-web"
|
|
@@ -231,6 +189,7 @@ async function createWebextViewsConfig(options) {
|
|
|
231
189
|
base: isDev ? `http://localhost:${port}/` : "/dist/",
|
|
232
190
|
plugins: [
|
|
233
191
|
(0, _multiplatform_one_utils_dev.stubExpoTypeDeclarations)(),
|
|
192
|
+
(0, _multiplatform_one_utils_dev.nativeOnlyDepStubPlugin)(workspaceRoot),
|
|
234
193
|
(0, _multiplatform_one_utils_dev.oneServerOnlyBrowserStub)(workspaceRoot),
|
|
235
194
|
react({ jsxRuntime: "automatic" }),
|
|
236
195
|
(0, _rolldown_plugin_babel.default)({ presets: [reactCompilerPreset()] }),
|
|
@@ -275,7 +234,7 @@ function createWebextBackgroundConfig(options) {
|
|
|
275
234
|
const { workspaceRoot, workspaceRootInferred, isDev } = resolveDefaults(options);
|
|
276
235
|
return {
|
|
277
236
|
root: options.targetDir,
|
|
278
|
-
plugins: [(0, _multiplatform_one_utils_dev.oneServerOnlyBrowserStub)(workspaceRoot)],
|
|
237
|
+
plugins: [(0, _multiplatform_one_utils_dev.nativeOnlyDepStubPlugin)(workspaceRoot), (0, _multiplatform_one_utils_dev.oneServerOnlyBrowserStub)(workspaceRoot)],
|
|
279
238
|
define: baseDefine(options, isDev),
|
|
280
239
|
optimizeDeps: baseOptimizeDeps(),
|
|
281
240
|
esbuild: {
|
|
@@ -302,7 +261,7 @@ function createWebextBackgroundConfig(options) {
|
|
|
302
261
|
};
|
|
303
262
|
}
|
|
304
263
|
/** The content-script build — a single-file iife injected into pages, with
|
|
305
|
-
*
|
|
264
|
+
* the CSS it imports extracted separately (webext.css web-accessible resource). */
|
|
306
265
|
async function createWebextContentConfig(options) {
|
|
307
266
|
const { workspaceRoot, workspaceRootInferred, isDev } = resolveDefaults(options);
|
|
308
267
|
const { default: react, reactCompilerPreset } = await importPeer(() => import("@vitejs/plugin-react"), "@vitejs/plugin-react");
|
|
@@ -311,14 +270,14 @@ async function createWebextContentConfig(options) {
|
|
|
311
270
|
root: options.targetDir,
|
|
312
271
|
plugins: [
|
|
313
272
|
(0, _multiplatform_one_utils_dev.stubExpoTypeDeclarations)(),
|
|
273
|
+
(0, _multiplatform_one_utils_dev.nativeOnlyDepStubPlugin)(workspaceRoot),
|
|
314
274
|
(0, _multiplatform_one_utils_dev.oneServerOnlyBrowserStub)(workspaceRoot),
|
|
315
275
|
shikiStubPlugin(),
|
|
316
276
|
react({ jsxRuntime: "automatic" }),
|
|
317
277
|
(0, _rolldown_plugin_babel.default)({ presets: [reactCompilerPreset()] }),
|
|
318
278
|
tamaguiPlugin({
|
|
319
279
|
components: (0, _multiplatform_one_utils_dev.lookupTamaguiModules)([options.targetDir]),
|
|
320
|
-
config: options.tamaguiConfig
|
|
321
|
-
outputCSS: node_path.default.join(options.targetDir, "tamagui.content.css")
|
|
280
|
+
config: options.tamaguiConfig
|
|
322
281
|
}),
|
|
323
282
|
tamaguiConfigBundleGuard(isDev)
|
|
324
283
|
],
|
package/lib/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { builtinModules, createRequire } from "node:module";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
|
-
import { lookupProjectRoot, lookupTamaguiModules, oneServerOnlyBrowserStub, stubExpoTypeDeclarations, workspaceSourceAliases } from "@multiplatform.one/utils/dev";
|
|
3
|
+
import { lookupProjectRoot, lookupTamaguiModules, movedDepAliases, nativeOnlyDepStubPlugin, oneServerOnlyBrowserStub, stubExpoTypeDeclarations, workspaceSourceAliases } from "@multiplatform.one/utils/dev";
|
|
5
4
|
import babel from "@rolldown/plugin-babel";
|
|
6
5
|
|
|
7
6
|
//#region src/index.ts
|
|
@@ -48,70 +47,25 @@ function shikiStubPlugin() {
|
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
49
|
}
|
|
51
|
-
function barePackageName(specifier) {
|
|
52
|
-
if (!specifier || /^[./#\\]/.test(specifier)) return;
|
|
53
|
-
if (/^(node|data|file|https?):/.test(specifier)) return;
|
|
54
|
-
const packageName = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
55
|
-
if (builtinModules.includes(packageName)) return;
|
|
56
|
-
return packageName;
|
|
57
|
-
}
|
|
58
|
-
/** Node ESM bare-import resolution walks parent node_modules dirs and — unlike
|
|
59
|
-
* CJS — ignores NODE_PATH. Presence of the package dir is what we probe. */
|
|
60
|
-
function packageVisibleFromDir(packageName, fromDir) {
|
|
61
|
-
let dir = fromDir;
|
|
62
|
-
while (true) {
|
|
63
|
-
if (fs.existsSync(path.join(dir, "node_modules", packageName, "package.json"))) return true;
|
|
64
|
-
const parent = path.dirname(dir);
|
|
65
|
-
if (parent === dir) return false;
|
|
66
|
-
dir = parent;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
50
|
/**
|
|
70
|
-
* The Tamagui static extractor
|
|
71
|
-
* `<
|
|
72
|
-
*
|
|
73
|
-
* `@tamagui/core`, react…) as live imports resolved FROM that artifact. When
|
|
74
|
-
* one of them cannot be resolved there (pnpm's default isolated layout
|
|
75
|
-
* without a direct `@tamagui/web` dependency), the extractor logs "Error
|
|
76
|
-
* bundling tamagui config: Cannot find package …", swallows the error, and
|
|
77
|
-
* the build exits 0 with a silently deoptimized runtime-styled bundle.
|
|
78
|
-
* Production builds must fail instead: after the build, replay the artifact's
|
|
79
|
-
* imports with the loader semantics the extractor would use — CJS resolution
|
|
80
|
-
* for .cjs (honors NODE_PATH, which pnpm bin shims set), an ESM-style
|
|
81
|
-
* node_modules walk for .mjs (ESM ignores NODE_PATH — exactly the divergence
|
|
82
|
-
* that breaks the .mjs artifact under pnpm) — and name the missing package.
|
|
83
|
-
* A missing artifact (bundling died before writing it) is equally fatal.
|
|
51
|
+
* The Tamagui static extractor writes the app's tamagui config to
|
|
52
|
+
* `<vite root>/.tamagui/tamagui.config.json`.
|
|
53
|
+
* A missing artifact (bundling died before writing it) is fatal.
|
|
84
54
|
*/
|
|
85
55
|
function tamaguiConfigBundleGuard(isDev) {
|
|
56
|
+
let root = process.cwd();
|
|
86
57
|
return {
|
|
87
58
|
name: "webext-tamagui-config-guard",
|
|
59
|
+
configResolved(config) {
|
|
60
|
+
root = config.root;
|
|
61
|
+
},
|
|
88
62
|
closeBundle() {
|
|
89
63
|
if (isDev) return;
|
|
90
|
-
const dotDir = path.join(
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
const artifact = artifacts.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs)[0];
|
|
97
|
-
const source = fs.readFileSync(artifact, "utf8");
|
|
98
|
-
const requireFromArtifact = createRequire(artifact);
|
|
99
|
-
const importRe = /(?:require\s*\(\s*|import\s*\(\s*|from\s*|import\s*)["']([^"'\n]+)["']/g;
|
|
100
|
-
const missing = /* @__PURE__ */ new Set();
|
|
101
|
-
for (const match of source.matchAll(importRe)) {
|
|
102
|
-
const packageName = barePackageName(match[1]);
|
|
103
|
-
if (!packageName) continue;
|
|
104
|
-
if (artifact.endsWith(".cjs")) try {
|
|
105
|
-
requireFromArtifact.resolve(packageName);
|
|
106
|
-
} catch {
|
|
107
|
-
missing.add(packageName);
|
|
108
|
-
}
|
|
109
|
-
else if (!packageVisibleFromDir(packageName, dotDir)) missing.add(packageName);
|
|
110
|
-
}
|
|
111
|
-
if (missing.size > 0) {
|
|
112
|
-
const names = [...missing].map((name) => `"${name}"`).join(", ");
|
|
113
|
-
throw new Error(`[${PLUGIN_NAME}] Tamagui config bundling failed: ${names} cannot be resolved from ${artifact}. The Tamagui static extractor swallows this ("Error bundling tamagui config") and ships a deoptimized runtime-styled build. Fix: add ${names} to your app's dependencies — under pnpm's default isolated node_modules, transitive packages are not resolvable from the app.`);
|
|
114
|
-
}
|
|
64
|
+
const dotDir = path.join(root, ".tamagui");
|
|
65
|
+
const artifact = path.join(dotDir, "tamagui.config.json");
|
|
66
|
+
if (fs.existsSync(artifact)) return;
|
|
67
|
+
if (!fs.existsSync(dotDir)) return;
|
|
68
|
+
throw new Error(`[${PLUGIN_NAME}] the Tamagui static extractor did not produce its bundled config (expected ${artifact}). The build would silently fall back to a deoptimized runtime-styled bundle. Re-run with DEBUG=tamagui to see the underlying bundling error.`);
|
|
115
69
|
}
|
|
116
70
|
};
|
|
117
71
|
}
|
|
@@ -155,6 +109,10 @@ function baseResolve(options, workspaceRoot, workspaceRootInferred) {
|
|
|
155
109
|
find,
|
|
156
110
|
replacement
|
|
157
111
|
})),
|
|
112
|
+
...Object.entries(movedDepAliases(workspaceRoot)).map(([find, replacement]) => ({
|
|
113
|
+
find,
|
|
114
|
+
replacement
|
|
115
|
+
})),
|
|
158
116
|
{
|
|
159
117
|
find: "react-native",
|
|
160
118
|
replacement: "react-native-web"
|
|
@@ -200,6 +158,7 @@ async function createWebextViewsConfig(options) {
|
|
|
200
158
|
base: isDev ? `http://localhost:${port}/` : "/dist/",
|
|
201
159
|
plugins: [
|
|
202
160
|
stubExpoTypeDeclarations(),
|
|
161
|
+
nativeOnlyDepStubPlugin(workspaceRoot),
|
|
203
162
|
oneServerOnlyBrowserStub(workspaceRoot),
|
|
204
163
|
react({ jsxRuntime: "automatic" }),
|
|
205
164
|
babel({ presets: [reactCompilerPreset()] }),
|
|
@@ -244,7 +203,7 @@ function createWebextBackgroundConfig(options) {
|
|
|
244
203
|
const { workspaceRoot, workspaceRootInferred, isDev } = resolveDefaults(options);
|
|
245
204
|
return {
|
|
246
205
|
root: options.targetDir,
|
|
247
|
-
plugins: [oneServerOnlyBrowserStub(workspaceRoot)],
|
|
206
|
+
plugins: [nativeOnlyDepStubPlugin(workspaceRoot), oneServerOnlyBrowserStub(workspaceRoot)],
|
|
248
207
|
define: baseDefine(options, isDev),
|
|
249
208
|
optimizeDeps: baseOptimizeDeps(),
|
|
250
209
|
esbuild: {
|
|
@@ -271,7 +230,7 @@ function createWebextBackgroundConfig(options) {
|
|
|
271
230
|
};
|
|
272
231
|
}
|
|
273
232
|
/** The content-script build — a single-file iife injected into pages, with
|
|
274
|
-
*
|
|
233
|
+
* the CSS it imports extracted separately (webext.css web-accessible resource). */
|
|
275
234
|
async function createWebextContentConfig(options) {
|
|
276
235
|
const { workspaceRoot, workspaceRootInferred, isDev } = resolveDefaults(options);
|
|
277
236
|
const { default: react, reactCompilerPreset } = await importPeer(() => import("@vitejs/plugin-react"), "@vitejs/plugin-react");
|
|
@@ -280,14 +239,14 @@ async function createWebextContentConfig(options) {
|
|
|
280
239
|
root: options.targetDir,
|
|
281
240
|
plugins: [
|
|
282
241
|
stubExpoTypeDeclarations(),
|
|
242
|
+
nativeOnlyDepStubPlugin(workspaceRoot),
|
|
283
243
|
oneServerOnlyBrowserStub(workspaceRoot),
|
|
284
244
|
shikiStubPlugin(),
|
|
285
245
|
react({ jsxRuntime: "automatic" }),
|
|
286
246
|
babel({ presets: [reactCompilerPreset()] }),
|
|
287
247
|
tamaguiPlugin({
|
|
288
248
|
components: lookupTamaguiModules([options.targetDir]),
|
|
289
|
-
config: options.tamaguiConfig
|
|
290
|
-
outputCSS: path.join(options.targetDir, "tamagui.content.css")
|
|
249
|
+
config: options.tamaguiConfig
|
|
291
250
|
}),
|
|
292
251
|
tamaguiConfigBundleGuard(isDev)
|
|
293
252
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/vite-plugin-webext",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Vite config factories for building a browser web extension (MV3 views, background service worker, content scripts) as a target of a multiplatform.one One app — workspace source aliases, the one-server-only browser stub, Tamagui wiring, and the manifest/dev-reload prepare pipeline.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser-extension",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@babel/core": "^7.26.0",
|
|
50
|
-
"@multiplatform.one/utils": "^
|
|
50
|
+
"@multiplatform.one/utils": "^10.1.0",
|
|
51
51
|
"@rolldown/plugin-babel": "^0.2.4",
|
|
52
52
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
53
53
|
"chokidar": "^5.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@tamagui/vite-plugin": "2.
|
|
56
|
+
"@tamagui/vite-plugin": "3.2.3",
|
|
57
57
|
"@types/babel__core": "^7.20.5",
|
|
58
58
|
"@types/node": "^26.6.5",
|
|
59
59
|
"@vitejs/plugin-react": "^6.1.2",
|
package/src/index.ts
CHANGED
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
// @multiplatform.one/utils/dev so every product app shares one copy.
|
|
18
18
|
|
|
19
19
|
import fs from "node:fs";
|
|
20
|
-
import { builtinModules, createRequire } from "node:module";
|
|
21
20
|
import path from "node:path";
|
|
22
21
|
import {
|
|
23
22
|
lookupTamaguiModules,
|
|
23
|
+
movedDepAliases,
|
|
24
|
+
nativeOnlyDepStubPlugin,
|
|
24
25
|
oneServerOnlyBrowserStub,
|
|
25
26
|
stubExpoTypeDeclarations,
|
|
26
27
|
workspaceSourceAliases,
|
|
@@ -108,95 +109,33 @@ export function shikiStubPlugin(): Plugin {
|
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
function barePackageName(specifier: string): string | undefined {
|
|
112
|
-
if (!specifier || /^[./#\\]/.test(specifier)) return;
|
|
113
|
-
if (/^(node|data|file|https?):/.test(specifier)) return;
|
|
114
|
-
const packageName = specifier.startsWith("@")
|
|
115
|
-
? specifier.split("/").slice(0, 2).join("/")
|
|
116
|
-
: specifier.split("/")[0]!;
|
|
117
|
-
if (builtinModules.includes(packageName)) return;
|
|
118
|
-
return packageName;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** Node ESM bare-import resolution walks parent node_modules dirs and — unlike
|
|
122
|
-
* CJS — ignores NODE_PATH. Presence of the package dir is what we probe. */
|
|
123
|
-
function packageVisibleFromDir(packageName: string, fromDir: string): boolean {
|
|
124
|
-
let dir = fromDir;
|
|
125
|
-
while (true) {
|
|
126
|
-
if (fs.existsSync(path.join(dir, "node_modules", packageName, "package.json"))) return true;
|
|
127
|
-
const parent = path.dirname(dir);
|
|
128
|
-
if (parent === dir) return false;
|
|
129
|
-
dir = parent;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
112
|
/**
|
|
134
|
-
* The Tamagui static extractor
|
|
135
|
-
* `<
|
|
136
|
-
*
|
|
137
|
-
* `@tamagui/core`, react…) as live imports resolved FROM that artifact. When
|
|
138
|
-
* one of them cannot be resolved there (pnpm's default isolated layout
|
|
139
|
-
* without a direct `@tamagui/web` dependency), the extractor logs "Error
|
|
140
|
-
* bundling tamagui config: Cannot find package …", swallows the error, and
|
|
141
|
-
* the build exits 0 with a silently deoptimized runtime-styled bundle.
|
|
142
|
-
* Production builds must fail instead: after the build, replay the artifact's
|
|
143
|
-
* imports with the loader semantics the extractor would use — CJS resolution
|
|
144
|
-
* for .cjs (honors NODE_PATH, which pnpm bin shims set), an ESM-style
|
|
145
|
-
* node_modules walk for .mjs (ESM ignores NODE_PATH — exactly the divergence
|
|
146
|
-
* that breaks the .mjs artifact under pnpm) — and name the missing package.
|
|
147
|
-
* A missing artifact (bundling died before writing it) is equally fatal.
|
|
113
|
+
* The Tamagui static extractor writes the app's tamagui config to
|
|
114
|
+
* `<vite root>/.tamagui/tamagui.config.json`.
|
|
115
|
+
* A missing artifact (bundling died before writing it) is fatal.
|
|
148
116
|
*/
|
|
149
117
|
function tamaguiConfigBundleGuard(isDev: boolean): Plugin {
|
|
118
|
+
let root = process.cwd();
|
|
150
119
|
return {
|
|
151
120
|
name: "webext-tamagui-config-guard",
|
|
121
|
+
configResolved(config) {
|
|
122
|
+
root = config.root;
|
|
123
|
+
},
|
|
152
124
|
closeBundle() {
|
|
153
125
|
if (isDev) return;
|
|
154
|
-
const dotDir = path.join(
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
"DEBUG=tamagui to see the underlying bundling error.",
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
const artifact = artifacts.sort(
|
|
171
|
-
(a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs,
|
|
172
|
-
)[0]!;
|
|
173
|
-
const source = fs.readFileSync(artifact, "utf8");
|
|
174
|
-
const requireFromArtifact = createRequire(artifact);
|
|
175
|
-
const importRe = /(?:require\s*\(\s*|import\s*\(\s*|from\s*|import\s*)["']([^"'\n]+)["']/g;
|
|
176
|
-
const missing = new Set<string>();
|
|
177
|
-
for (const match of source.matchAll(importRe)) {
|
|
178
|
-
const packageName = barePackageName(match[1]!);
|
|
179
|
-
if (!packageName) continue;
|
|
180
|
-
if (artifact.endsWith(".cjs")) {
|
|
181
|
-
try {
|
|
182
|
-
requireFromArtifact.resolve(packageName);
|
|
183
|
-
} catch {
|
|
184
|
-
missing.add(packageName);
|
|
185
|
-
}
|
|
186
|
-
} else if (!packageVisibleFromDir(packageName, dotDir)) {
|
|
187
|
-
missing.add(packageName);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (missing.size > 0) {
|
|
191
|
-
const names = [...missing].map((name) => `"${name}"`).join(", ");
|
|
192
|
-
throw new Error(
|
|
193
|
-
`[${PLUGIN_NAME}] Tamagui config bundling failed: ${names} cannot be resolved ` +
|
|
194
|
-
`from ${artifact}. The Tamagui static extractor swallows this ("Error bundling ` +
|
|
195
|
-
'tamagui config") and ships a deoptimized runtime-styled build. Fix: add ' +
|
|
196
|
-
`${names} to your app's dependencies — under pnpm's default isolated ` +
|
|
197
|
-
"node_modules, transitive packages are not resolvable from the app.",
|
|
198
|
-
);
|
|
199
|
-
}
|
|
126
|
+
const dotDir = path.join(root, ".tamagui");
|
|
127
|
+
const artifact = path.join(dotDir, "tamagui.config.json");
|
|
128
|
+
if (fs.existsSync(artifact)) return;
|
|
129
|
+
// No .tamagui dir at all means the extractor never ran for this
|
|
130
|
+
// build (nothing to verify) — an existing dir without the config
|
|
131
|
+
// artifact means bundling died before writing it.
|
|
132
|
+
if (!fs.existsSync(dotDir)) return;
|
|
133
|
+
throw new Error(
|
|
134
|
+
`[${PLUGIN_NAME}] the Tamagui static extractor did not produce its bundled config ` +
|
|
135
|
+
`(expected ${artifact}). The build would ` +
|
|
136
|
+
"silently fall back to a deoptimized runtime-styled bundle. Re-run with " +
|
|
137
|
+
"DEBUG=tamagui to see the underlying bundling error.",
|
|
138
|
+
);
|
|
200
139
|
},
|
|
201
140
|
};
|
|
202
141
|
}
|
|
@@ -258,6 +197,10 @@ function baseResolve(
|
|
|
258
197
|
find,
|
|
259
198
|
replacement,
|
|
260
199
|
})),
|
|
200
|
+
...Object.entries(movedDepAliases(workspaceRoot)).map(([find, replacement]) => ({
|
|
201
|
+
find,
|
|
202
|
+
replacement,
|
|
203
|
+
})),
|
|
261
204
|
{ find: "react-native", replacement: "react-native-web" },
|
|
262
205
|
{ find: "@", replacement: options.targetDir },
|
|
263
206
|
...(options.aliases ?? []),
|
|
@@ -307,6 +250,7 @@ export async function createWebextViewsConfig(options: WebextTargetOptions): Pro
|
|
|
307
250
|
base: isDev ? `http://localhost:${port}/` : "/dist/",
|
|
308
251
|
plugins: [
|
|
309
252
|
stubExpoTypeDeclarations(),
|
|
253
|
+
nativeOnlyDepStubPlugin(workspaceRoot),
|
|
310
254
|
oneServerOnlyBrowserStub(workspaceRoot),
|
|
311
255
|
react({ jsxRuntime: "automatic" }),
|
|
312
256
|
// Same React Compiler pass the One app runs (react 19 built-in
|
|
@@ -362,7 +306,7 @@ export function createWebextBackgroundConfig(options: WebextTargetOptions): User
|
|
|
362
306
|
const { workspaceRoot, workspaceRootInferred, isDev } = resolveDefaults(options);
|
|
363
307
|
return {
|
|
364
308
|
root: options.targetDir,
|
|
365
|
-
plugins: [oneServerOnlyBrowserStub(workspaceRoot)],
|
|
309
|
+
plugins: [nativeOnlyDepStubPlugin(workspaceRoot), oneServerOnlyBrowserStub(workspaceRoot)],
|
|
366
310
|
define: baseDefine(options, isDev),
|
|
367
311
|
optimizeDeps: baseOptimizeDeps(),
|
|
368
312
|
esbuild: {
|
|
@@ -392,7 +336,7 @@ export function createWebextBackgroundConfig(options: WebextTargetOptions): User
|
|
|
392
336
|
}
|
|
393
337
|
|
|
394
338
|
/** The content-script build — a single-file iife injected into pages, with
|
|
395
|
-
*
|
|
339
|
+
* the CSS it imports extracted separately (webext.css web-accessible resource). */
|
|
396
340
|
export async function createWebextContentConfig(options: WebextTargetOptions): Promise<UserConfig> {
|
|
397
341
|
const { workspaceRoot, workspaceRootInferred, isDev } = resolveDefaults(options);
|
|
398
342
|
const { default: react, reactCompilerPreset } = await importPeer(
|
|
@@ -407,6 +351,7 @@ export async function createWebextContentConfig(options: WebextTargetOptions): P
|
|
|
407
351
|
root: options.targetDir,
|
|
408
352
|
plugins: [
|
|
409
353
|
stubExpoTypeDeclarations(),
|
|
354
|
+
nativeOnlyDepStubPlugin(workspaceRoot),
|
|
410
355
|
oneServerOnlyBrowserStub(workspaceRoot),
|
|
411
356
|
shikiStubPlugin(),
|
|
412
357
|
// The react plugin transforms JSX (the esbuild jsx setting below
|
|
@@ -416,7 +361,6 @@ export async function createWebextContentConfig(options: WebextTargetOptions): P
|
|
|
416
361
|
tamaguiPlugin({
|
|
417
362
|
components: lookupTamaguiModules([options.targetDir]),
|
|
418
363
|
config: options.tamaguiConfig,
|
|
419
|
-
outputCSS: path.join(options.targetDir, "tamagui.content.css"),
|
|
420
364
|
}) as Plugin,
|
|
421
365
|
tamaguiConfigBundleGuard(isDev),
|
|
422
366
|
],
|
package/types/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare function createWebextViewsConfig(options: WebextTargetOptions): P
|
|
|
42
42
|
* build — a single-file iife, no DOM. */
|
|
43
43
|
export declare function createWebextBackgroundConfig(options: WebextTargetOptions): UserConfig;
|
|
44
44
|
/** The content-script build — a single-file iife injected into pages, with
|
|
45
|
-
*
|
|
45
|
+
* the CSS it imports extracted separately (webext.css web-accessible resource). */
|
|
46
46
|
export declare function createWebextContentConfig(options: WebextTargetOptions): Promise<UserConfig>;
|
|
47
47
|
export interface WebextPrepareOptions {
|
|
48
48
|
targetDir: string;
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMtD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC;0CACsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB;2EACuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,WAAW,EAAE,iBAAiB,CAAC;IAC/B,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;qCACiC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,0DAA0D;IAC1D,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;CACnB;AA4BD;;;iDAGiD;AACjD,wBAAgB,eAAe,IAAI,MAAM,CAYxC;AAiHD;2EAC2E;AAC3E,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAO3D;AAED,qEAAqE;AACrE,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAkE/F;AAED;0CAC0C;AAC1C,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,mBAAmB,GAAG,UAAU,CA+BrF;AAED;oFACoF;AACpF,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAiEjG;AAID,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB;;uEAEmE;IACnE,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAC5C;2DACuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;sCAEsC;AACtC,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKnF;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtF;AAED;;mDAEmD;AACnD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBtF;AAED,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB3F;AAED;uBACuB;AACvB,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBnF"}
|