@multiplatform.one/vite-plugin-vscode 6.2.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/lib/index.cjs ADDED
@@ -0,0 +1,202 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let node_fs = require("node:fs");
30
+ node_fs = __toESM(node_fs, 1);
31
+ let node_path = require("node:path");
32
+ node_path = __toESM(node_path, 1);
33
+ let _multiplatform_one_utils_dev = require("@multiplatform.one/utils/dev");
34
+ let _tomjs_vite_plugin_vscode = require("@tomjs/vite-plugin-vscode");
35
+ _tomjs_vite_plugin_vscode = __toESM(_tomjs_vite_plugin_vscode, 1);
36
+ let _vitejs_plugin_react = require("@vitejs/plugin-react");
37
+ _vitejs_plugin_react = __toESM(_vitejs_plugin_react, 1);
38
+
39
+ //#region src/index.ts
40
+ /** Default CSP: the plugin's default lacks font-src/img-src and blocks
41
+ * dynamically imported chunks (script-src nonce-only) — the app bundle
42
+ * code-splits lazy providers, and Inter ships as woff2 assets. Allow the
43
+ * webview resource origin explicitly. */
44
+ const DEFAULT_WEBVIEW_CSP = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src {{cspSource}} https: data:; script-src {{cspSource}} 'nonce-{{nonce}}' 'unsafe-eval'; style-src {{cspSource}} 'unsafe-inline'; font-src {{cspSource}} data:; connect-src {{cspSource}} https:;">`;
45
+ const WEB_EXTENSIONS = [
46
+ ".web.tsx",
47
+ ".web.ts",
48
+ ".web.jsx",
49
+ ".web.js",
50
+ ".mjs",
51
+ ".mts",
52
+ ".tsx",
53
+ ".ts",
54
+ ".jsx",
55
+ ".js",
56
+ ".json"
57
+ ];
58
+ /** Resolve the seam's one-adapter: workspace source when developing inside
59
+ * the framework monorepo, the built package export otherwise. */
60
+ function resolveSeamOneAdapter(workspaceRoot) {
61
+ const source = node_path.default.join(workspaceRoot, "public/router/src/seam/oneAdapter.tsx");
62
+ if (node_fs.default.existsSync(source)) return source;
63
+ return "@multiplatform.one/router/seam";
64
+ }
65
+ async function createVscodeConfig(options) {
66
+ const workspaceRoot = options.workspaceRoot ?? (0, _multiplatform_one_utils_dev.lookupProjectRoot)();
67
+ const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
68
+ const { tamaguiPlugin } = await import("@tamagui/vite-plugin");
69
+ return {
70
+ root: options.targetDir,
71
+ base: isDev ? "/" : "./",
72
+ build: {
73
+ outDir: options.outDir,
74
+ emptyOutDir: true,
75
+ minify: false,
76
+ sourcemap: true
77
+ },
78
+ define: {
79
+ __DEV__: JSON.stringify(isDev),
80
+ global: "globalThis",
81
+ "process.env.NODE_ENV": JSON.stringify(isDev ? "development" : "production"),
82
+ "process.env.TAMAGUI_TARGET": JSON.stringify("web"),
83
+ ...options.define
84
+ },
85
+ plugins: [
86
+ (0, _multiplatform_one_utils_dev.stubExpoTypeDeclarations)(),
87
+ (0, _multiplatform_one_utils_dev.oneServerOnlyBrowserStub)(workspaceRoot),
88
+ (0, _vitejs_plugin_react.default)({ jsxRuntime: "automatic" }),
89
+ tamaguiPlugin({
90
+ components: (0, _multiplatform_one_utils_dev.lookupTamaguiModules)([options.targetDir]),
91
+ config: options.tamaguiConfig,
92
+ outputCSS: node_path.default.join(options.targetDir, "tamagui.css")
93
+ }),
94
+ (0, _tomjs_vite_plugin_vscode.default)({
95
+ recommended: true,
96
+ extension: { entry: node_path.default.join(options.targetDir, "extension/index.ts") },
97
+ webview: { csp: options.csp ?? DEFAULT_WEBVIEW_CSP }
98
+ })
99
+ ],
100
+ resolve: {
101
+ alias: [
102
+ ...Object.entries((0, _multiplatform_one_utils_dev.workspaceSourceAliases)(workspaceRoot)).map(([find, replacement]) => ({
103
+ find,
104
+ replacement
105
+ })),
106
+ {
107
+ find: /^one$/,
108
+ replacement: resolveSeamOneAdapter(workspaceRoot)
109
+ },
110
+ {
111
+ find: "@",
112
+ replacement: node_path.default.join(options.targetDir, "webview")
113
+ },
114
+ {
115
+ find: "react-native",
116
+ replacement: "react-native-web"
117
+ },
118
+ {
119
+ find: /^react$/,
120
+ replacement: node_path.default.join(workspaceRoot, "node_modules/react")
121
+ },
122
+ {
123
+ find: /^react-dom$/,
124
+ replacement: node_path.default.join(workspaceRoot, "node_modules/react-dom")
125
+ },
126
+ {
127
+ find: "react/jsx-runtime",
128
+ replacement: node_path.default.join(workspaceRoot, "node_modules/react/jsx-runtime.js")
129
+ },
130
+ {
131
+ find: "react/jsx-dev-runtime",
132
+ replacement: node_path.default.join(workspaceRoot, "node_modules/react/jsx-dev-runtime.js")
133
+ },
134
+ ...options.aliases ?? []
135
+ ],
136
+ dedupe: ["react", "react-dom"],
137
+ extensions: WEB_EXTENSIONS,
138
+ mainFields: [
139
+ "browser",
140
+ "module",
141
+ "main"
142
+ ]
143
+ },
144
+ optimizeDeps: {
145
+ include: [
146
+ "react",
147
+ "react-dom",
148
+ "@tamagui/core",
149
+ "@tamagui/web",
150
+ "tamagui",
151
+ "react-native-web",
152
+ "@multiplatform.one/components"
153
+ ],
154
+ esbuildOptions: {
155
+ resolveExtensions: [
156
+ ".web.ts",
157
+ ".web.tsx",
158
+ ".web.js",
159
+ ".web.jsx",
160
+ ".ts",
161
+ ".tsx",
162
+ ".js",
163
+ ".jsx"
164
+ ],
165
+ mainFields: ["module", "main"]
166
+ }
167
+ },
168
+ server: {
169
+ host: "0.0.0.0",
170
+ port: 5173,
171
+ strictPort: true,
172
+ hmr: {
173
+ host: "localhost",
174
+ port: 5173,
175
+ protocol: "ws"
176
+ }
177
+ }
178
+ };
179
+ }
180
+ /** Write the extension-manifest package.json into the staging dir. A VS
181
+ * Code extension's package.json IS its manifest — the product app's own
182
+ * package.json (an Expo/One app manifest) can't double as it, so `vsce
183
+ * package` runs against the staging dir instead. */
184
+ async function writeVsceManifest(stagingDir, manifest) {
185
+ const { engines, main, ...rest } = manifest;
186
+ const packageJson = {
187
+ ...rest,
188
+ main: main ?? "extension/index.js",
189
+ engines: {
190
+ vscode: "^1.75.0",
191
+ ...engines
192
+ }
193
+ };
194
+ await node_fs.default.promises.mkdir(stagingDir, { recursive: true });
195
+ await node_fs.default.promises.writeFile(node_path.default.join(stagingDir, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`, "utf-8");
196
+ }
197
+
198
+ //#endregion
199
+ exports.DEFAULT_WEBVIEW_CSP = DEFAULT_WEBVIEW_CSP;
200
+ exports.createVscodeConfig = createVscodeConfig;
201
+ exports.resolveSeamOneAdapter = resolveSeamOneAdapter;
202
+ exports.writeVsceManifest = writeVsceManifest;
package/lib/index.mjs ADDED
@@ -0,0 +1,167 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { lookupProjectRoot, lookupTamaguiModules, oneServerOnlyBrowserStub, stubExpoTypeDeclarations, workspaceSourceAliases } from "@multiplatform.one/utils/dev";
4
+ import vscode from "@tomjs/vite-plugin-vscode";
5
+ import react from "@vitejs/plugin-react";
6
+
7
+ //#region src/index.ts
8
+ /** Default CSP: the plugin's default lacks font-src/img-src and blocks
9
+ * dynamically imported chunks (script-src nonce-only) — the app bundle
10
+ * code-splits lazy providers, and Inter ships as woff2 assets. Allow the
11
+ * webview resource origin explicitly. */
12
+ const DEFAULT_WEBVIEW_CSP = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src {{cspSource}} https: data:; script-src {{cspSource}} 'nonce-{{nonce}}' 'unsafe-eval'; style-src {{cspSource}} 'unsafe-inline'; font-src {{cspSource}} data:; connect-src {{cspSource}} https:;">`;
13
+ const WEB_EXTENSIONS = [
14
+ ".web.tsx",
15
+ ".web.ts",
16
+ ".web.jsx",
17
+ ".web.js",
18
+ ".mjs",
19
+ ".mts",
20
+ ".tsx",
21
+ ".ts",
22
+ ".jsx",
23
+ ".js",
24
+ ".json"
25
+ ];
26
+ /** Resolve the seam's one-adapter: workspace source when developing inside
27
+ * the framework monorepo, the built package export otherwise. */
28
+ function resolveSeamOneAdapter(workspaceRoot) {
29
+ const source = path.join(workspaceRoot, "public/router/src/seam/oneAdapter.tsx");
30
+ if (fs.existsSync(source)) return source;
31
+ return "@multiplatform.one/router/seam";
32
+ }
33
+ async function createVscodeConfig(options) {
34
+ const workspaceRoot = options.workspaceRoot ?? lookupProjectRoot();
35
+ const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
36
+ const { tamaguiPlugin } = await import("@tamagui/vite-plugin");
37
+ return {
38
+ root: options.targetDir,
39
+ base: isDev ? "/" : "./",
40
+ build: {
41
+ outDir: options.outDir,
42
+ emptyOutDir: true,
43
+ minify: false,
44
+ sourcemap: true
45
+ },
46
+ define: {
47
+ __DEV__: JSON.stringify(isDev),
48
+ global: "globalThis",
49
+ "process.env.NODE_ENV": JSON.stringify(isDev ? "development" : "production"),
50
+ "process.env.TAMAGUI_TARGET": JSON.stringify("web"),
51
+ ...options.define
52
+ },
53
+ plugins: [
54
+ stubExpoTypeDeclarations(),
55
+ oneServerOnlyBrowserStub(workspaceRoot),
56
+ react({ jsxRuntime: "automatic" }),
57
+ tamaguiPlugin({
58
+ components: lookupTamaguiModules([options.targetDir]),
59
+ config: options.tamaguiConfig,
60
+ outputCSS: path.join(options.targetDir, "tamagui.css")
61
+ }),
62
+ vscode({
63
+ recommended: true,
64
+ extension: { entry: path.join(options.targetDir, "extension/index.ts") },
65
+ webview: { csp: options.csp ?? DEFAULT_WEBVIEW_CSP }
66
+ })
67
+ ],
68
+ resolve: {
69
+ alias: [
70
+ ...Object.entries(workspaceSourceAliases(workspaceRoot)).map(([find, replacement]) => ({
71
+ find,
72
+ replacement
73
+ })),
74
+ {
75
+ find: /^one$/,
76
+ replacement: resolveSeamOneAdapter(workspaceRoot)
77
+ },
78
+ {
79
+ find: "@",
80
+ replacement: path.join(options.targetDir, "webview")
81
+ },
82
+ {
83
+ find: "react-native",
84
+ replacement: "react-native-web"
85
+ },
86
+ {
87
+ find: /^react$/,
88
+ replacement: path.join(workspaceRoot, "node_modules/react")
89
+ },
90
+ {
91
+ find: /^react-dom$/,
92
+ replacement: path.join(workspaceRoot, "node_modules/react-dom")
93
+ },
94
+ {
95
+ find: "react/jsx-runtime",
96
+ replacement: path.join(workspaceRoot, "node_modules/react/jsx-runtime.js")
97
+ },
98
+ {
99
+ find: "react/jsx-dev-runtime",
100
+ replacement: path.join(workspaceRoot, "node_modules/react/jsx-dev-runtime.js")
101
+ },
102
+ ...options.aliases ?? []
103
+ ],
104
+ dedupe: ["react", "react-dom"],
105
+ extensions: WEB_EXTENSIONS,
106
+ mainFields: [
107
+ "browser",
108
+ "module",
109
+ "main"
110
+ ]
111
+ },
112
+ optimizeDeps: {
113
+ include: [
114
+ "react",
115
+ "react-dom",
116
+ "@tamagui/core",
117
+ "@tamagui/web",
118
+ "tamagui",
119
+ "react-native-web",
120
+ "@multiplatform.one/components"
121
+ ],
122
+ esbuildOptions: {
123
+ resolveExtensions: [
124
+ ".web.ts",
125
+ ".web.tsx",
126
+ ".web.js",
127
+ ".web.jsx",
128
+ ".ts",
129
+ ".tsx",
130
+ ".js",
131
+ ".jsx"
132
+ ],
133
+ mainFields: ["module", "main"]
134
+ }
135
+ },
136
+ server: {
137
+ host: "0.0.0.0",
138
+ port: 5173,
139
+ strictPort: true,
140
+ hmr: {
141
+ host: "localhost",
142
+ port: 5173,
143
+ protocol: "ws"
144
+ }
145
+ }
146
+ };
147
+ }
148
+ /** Write the extension-manifest package.json into the staging dir. A VS
149
+ * Code extension's package.json IS its manifest — the product app's own
150
+ * package.json (an Expo/One app manifest) can't double as it, so `vsce
151
+ * package` runs against the staging dir instead. */
152
+ async function writeVsceManifest(stagingDir, manifest) {
153
+ const { engines, main, ...rest } = manifest;
154
+ const packageJson = {
155
+ ...rest,
156
+ main: main ?? "extension/index.js",
157
+ engines: {
158
+ vscode: "^1.75.0",
159
+ ...engines
160
+ }
161
+ };
162
+ await fs.promises.mkdir(stagingDir, { recursive: true });
163
+ await fs.promises.writeFile(path.join(stagingDir, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`, "utf-8");
164
+ }
165
+
166
+ //#endregion
167
+ export { DEFAULT_WEBVIEW_CSP, createVscodeConfig, resolveSeamOneAdapter, writeVsceManifest };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@multiplatform.one/vite-plugin-vscode",
3
+ "version": "6.2.0",
4
+ "description": "Vite config factory for building a VS Code extension (extension host + Tamagui webview) as a target of a multiplatform.one One app — wraps @tomjs/vite-plugin-vscode with the workspace source aliases, the one-router seam alias, React dedupe against one's vendored copy, and a vsce staging-manifest writer.",
5
+ "keywords": [
6
+ "multiplatform.one",
7
+ "vite-plugin",
8
+ "vscode",
9
+ "vscode-extension",
10
+ "webview"
11
+ ],
12
+ "homepage": "https://multiplatform.one",
13
+ "bugs": {
14
+ "url": "https://gitlab.com/bitspur/multiplatform.one/multiplatform.one/issues",
15
+ "email": "support@risserlabs.com"
16
+ },
17
+ "license": "Apache-2.0",
18
+ "author": "BitSpur <support@risserlabs.com> (https://risserlabs.com)",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://gitlab.com/bitspur/frappe/multiplatform.one.git",
22
+ "directory": "public/vite-plugin-vscode"
23
+ },
24
+ "source": "src/index.ts",
25
+ "files": [
26
+ "lib",
27
+ "types",
28
+ "src",
29
+ "!types/.tsbuildinfo"
30
+ ],
31
+ "type": "module",
32
+ "sideEffects": false,
33
+ "main": "lib/index.cjs",
34
+ "module": "lib/index.mjs",
35
+ "types": "types/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "source": "./src/index.ts",
39
+ "types": "./types/index.d.ts",
40
+ "import": "./lib/index.mjs",
41
+ "require": "./lib/index.cjs"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "dependencies": {
49
+ "@multiplatform.one/utils": "6.2.0"
50
+ },
51
+ "devDependencies": {
52
+ "@tamagui/vite-plugin": "2.0.0-rc.41",
53
+ "@tomjs/vite-plugin-vscode": "^7.1.1",
54
+ "@types/node": "^25.6.0",
55
+ "@vitejs/plugin-react": "^6.0.1",
56
+ "typescript": "~5.9.3",
57
+ "vite": "^8.0.10"
58
+ },
59
+ "peerDependencies": {
60
+ "@tamagui/vite-plugin": "*",
61
+ "@tomjs/vite-plugin-vscode": ">=7",
62
+ "@vitejs/plugin-react": ">=4",
63
+ "vite": ">=5"
64
+ },
65
+ "scripts": {
66
+ "typecheck": "tsc --noEmit",
67
+ "build": "rm -rf lib types 2>/dev/null && tsc -b --emitDeclarationOnly && tsdown"
68
+ }
69
+ }
package/src/index.ts ADDED
@@ -0,0 +1,233 @@
1
+ // Vite config factory for the VS Code target of a One platform app.
2
+ //
3
+ // The target lives INSIDE the product app (apps/<name>/vscode/) — the same
4
+ // pattern as the GNOME/webext targets — with the layout
5
+ // @tomjs/vite-plugin-vscode's `recommended` mode expects:
6
+ //
7
+ // apps/<name>/vscode/
8
+ // index.html ← webview entry (vite root)
9
+ // extension/index.ts ← extension host (built by tsdown via the plugin)
10
+ // webview/… ← webview React sources
11
+ //
12
+ // Outputs land under `outDir` as extension/ + webview/;
13
+ // `writeVsceManifest` then drops the extension-manifest package.json next
14
+ // to them so `vsce package` can run against the staging dir — the product
15
+ // app's own package.json is an Expo/One manifest and can't double as the
16
+ // extension's.
17
+ //
18
+ // One routing layer: the factory aliases `one` to the stack-navigation
19
+ // seam's one-adapter (@multiplatform.one/router/seam), so feature screens,
20
+ // @package/layouts and the router facade all ride the seam — a webview has
21
+ // no address bar and no One server runtime for One's real router.
22
+
23
+ import fs from "node:fs";
24
+ import path from "node:path";
25
+ import {
26
+ lookupTamaguiModules,
27
+ lookupProjectRoot,
28
+ oneServerOnlyBrowserStub,
29
+ stubExpoTypeDeclarations,
30
+ workspaceSourceAliases,
31
+ } from "@multiplatform.one/utils/dev";
32
+ import vscode from "@tomjs/vite-plugin-vscode";
33
+ import react from "@vitejs/plugin-react";
34
+ import type { Alias, Plugin, UserConfig } from "vite";
35
+
36
+ /** Default CSP: the plugin's default lacks font-src/img-src and blocks
37
+ * dynamically imported chunks (script-src nonce-only) — the app bundle
38
+ * code-splits lazy providers, and Inter ships as woff2 assets. Allow the
39
+ * webview resource origin explicitly. */
40
+ export const DEFAULT_WEBVIEW_CSP = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src {{cspSource}} https: data:; script-src {{cspSource}} 'nonce-{{nonce}}' 'unsafe-eval'; style-src {{cspSource}} 'unsafe-inline'; font-src {{cspSource}} data:; connect-src {{cspSource}} https:;">`;
41
+
42
+ export interface VscodeTargetOptions {
43
+ /** Absolute path of the vscode target dir (vite root: index.html +
44
+ * extension/ + webview/). */
45
+ targetDir: string;
46
+ /** Absolute output dir (staging root: extension/ + webview/ +
47
+ * generated package.json). Keep it under the app's dist/. */
48
+ outDir: string;
49
+ /** Absolute path to the Tamagui config compiled into the webview. */
50
+ tamaguiConfig: string;
51
+ /** Workspace root (defaults to the git toplevel). */
52
+ workspaceRoot?: string;
53
+ /** Webview CSP meta (defaults to DEFAULT_WEBVIEW_CSP). */
54
+ csp?: string;
55
+ isDev?: boolean;
56
+ /** Extra defines merged over the factory defaults. */
57
+ define?: Record<string, unknown>;
58
+ /** Extra resolve aliases appended after the factory's. */
59
+ aliases?: Alias[];
60
+ }
61
+
62
+ const WEB_EXTENSIONS = [
63
+ ".web.tsx",
64
+ ".web.ts",
65
+ ".web.jsx",
66
+ ".web.js",
67
+ ".mjs",
68
+ ".mts",
69
+ ".tsx",
70
+ ".ts",
71
+ ".jsx",
72
+ ".js",
73
+ ".json",
74
+ ];
75
+
76
+ /** Resolve the seam's one-adapter: workspace source when developing inside
77
+ * the framework monorepo, the built package export otherwise. */
78
+ export function resolveSeamOneAdapter(workspaceRoot: string): string {
79
+ const source = path.join(workspaceRoot, "public/router/src/seam/oneAdapter.tsx");
80
+ if (fs.existsSync(source)) return source;
81
+ return "@multiplatform.one/router/seam";
82
+ }
83
+
84
+ export async function createVscodeConfig(options: VscodeTargetOptions): Promise<UserConfig> {
85
+ const workspaceRoot = options.workspaceRoot ?? lookupProjectRoot();
86
+ const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
87
+ const { tamaguiPlugin } = await import("@tamagui/vite-plugin");
88
+ return {
89
+ root: options.targetDir,
90
+ base: isDev ? "/" : "./",
91
+ build: {
92
+ outDir: options.outDir,
93
+ emptyOutDir: true,
94
+ minify: false,
95
+ sourcemap: true,
96
+ },
97
+ define: {
98
+ __DEV__: JSON.stringify(isDev),
99
+ // React-native deps assume Node/RN's `global` at render time.
100
+ global: "globalThis",
101
+ "process.env.NODE_ENV": JSON.stringify(isDev ? "development" : "production"),
102
+ "process.env.TAMAGUI_TARGET": JSON.stringify("web"),
103
+ ...options.define,
104
+ },
105
+ plugins: [
106
+ stubExpoTypeDeclarations(),
107
+ oneServerOnlyBrowserStub(workspaceRoot),
108
+ react({ jsxRuntime: "automatic" }),
109
+ tamaguiPlugin({
110
+ components: lookupTamaguiModules([options.targetDir]),
111
+ config: options.tamaguiConfig,
112
+ outputCSS: path.join(options.targetDir, "tamagui.css"),
113
+ }) as Plugin,
114
+ vscode({
115
+ recommended: true,
116
+ extension: {
117
+ // tsdown resolves relative entries from process.cwd() (the app
118
+ // root), not the vite root — hand it the absolute path.
119
+ entry: path.join(options.targetDir, "extension/index.ts"),
120
+ },
121
+ webview: {
122
+ csp: options.csp ?? DEFAULT_WEBVIEW_CSP,
123
+ },
124
+ }),
125
+ ],
126
+ resolve: {
127
+ alias: [
128
+ ...Object.entries(workspaceSourceAliases(workspaceRoot)).map(([find, replacement]) => ({
129
+ find,
130
+ replacement,
131
+ })),
132
+ // One routing layer: `one` rides the stack-navigation seam.
133
+ { find: /^one$/, replacement: resolveSeamOneAdapter(workspaceRoot) },
134
+ { find: "@", replacement: path.join(options.targetDir, "webview") },
135
+ { find: "react-native", replacement: "react-native-web" },
136
+ // Force every "react", "react-dom", and jsx-runtime import to the
137
+ // workspace copy. Without this, transitive imports from `one` resolve
138
+ // to its vendored React 18 (one/vendor/react/...), which uses internal
139
+ // APIs (ReactCurrentOwner) that React 19 has removed — crashing the
140
+ // webview at first render.
141
+ { find: /^react$/, replacement: path.join(workspaceRoot, "node_modules/react") },
142
+ { find: /^react-dom$/, replacement: path.join(workspaceRoot, "node_modules/react-dom") },
143
+ {
144
+ find: "react/jsx-runtime",
145
+ replacement: path.join(workspaceRoot, "node_modules/react/jsx-runtime.js"),
146
+ },
147
+ {
148
+ find: "react/jsx-dev-runtime",
149
+ replacement: path.join(workspaceRoot, "node_modules/react/jsx-dev-runtime.js"),
150
+ },
151
+ ...(options.aliases ?? []),
152
+ ],
153
+ dedupe: ["react", "react-dom"],
154
+ extensions: WEB_EXTENSIONS,
155
+ mainFields: ["browser", "module", "main"],
156
+ },
157
+ optimizeDeps: {
158
+ include: [
159
+ "react",
160
+ "react-dom",
161
+ "@tamagui/core",
162
+ "@tamagui/web",
163
+ "tamagui",
164
+ "react-native-web",
165
+ "@multiplatform.one/components",
166
+ ],
167
+ esbuildOptions: {
168
+ resolveExtensions: [
169
+ ".web.ts",
170
+ ".web.tsx",
171
+ ".web.js",
172
+ ".web.jsx",
173
+ ".ts",
174
+ ".tsx",
175
+ ".js",
176
+ ".jsx",
177
+ ],
178
+ mainFields: ["module", "main"],
179
+ },
180
+ },
181
+ server: {
182
+ host: "0.0.0.0",
183
+ port: 5173,
184
+ strictPort: true,
185
+ hmr: {
186
+ host: "localhost",
187
+ port: 5173,
188
+ protocol: "ws",
189
+ },
190
+ },
191
+ };
192
+ }
193
+
194
+ // ── vsce staging manifest ─────────────────────────────────────────
195
+
196
+ export interface VsceManifest {
197
+ name: string;
198
+ displayName?: string;
199
+ publisher: string;
200
+ version: string;
201
+ description?: string;
202
+ /** "module" when the extension host is built ESM (VS Code ≥1.100). */
203
+ type?: "module" | "commonjs";
204
+ /** Defaults to `{ vscode: "^1.75.0" }`. */
205
+ engines?: { vscode: string; [key: string]: string };
206
+ /** Defaults to `extension/index.js` (the staging layout). */
207
+ main?: string;
208
+ contributes?: Record<string, unknown>;
209
+ activationEvents?: string[];
210
+ categories?: string[];
211
+ icon?: string;
212
+ repository?: unknown;
213
+ license?: string;
214
+ }
215
+
216
+ /** Write the extension-manifest package.json into the staging dir. A VS
217
+ * Code extension's package.json IS its manifest — the product app's own
218
+ * package.json (an Expo/One app manifest) can't double as it, so `vsce
219
+ * package` runs against the staging dir instead. */
220
+ export async function writeVsceManifest(stagingDir: string, manifest: VsceManifest): Promise<void> {
221
+ const { engines, main, ...rest } = manifest;
222
+ const packageJson = {
223
+ ...rest,
224
+ main: main ?? "extension/index.js",
225
+ engines: { vscode: "^1.75.0", ...engines },
226
+ };
227
+ await fs.promises.mkdir(stagingDir, { recursive: true });
228
+ await fs.promises.writeFile(
229
+ path.join(stagingDir, "package.json"),
230
+ `${JSON.stringify(packageJson, null, 2)}\n`,
231
+ "utf-8",
232
+ );
233
+ }
@@ -0,0 +1,57 @@
1
+ import type { Alias, UserConfig } from "vite";
2
+ /** Default CSP: the plugin's default lacks font-src/img-src and blocks
3
+ * dynamically imported chunks (script-src nonce-only) — the app bundle
4
+ * code-splits lazy providers, and Inter ships as woff2 assets. Allow the
5
+ * webview resource origin explicitly. */
6
+ export declare const DEFAULT_WEBVIEW_CSP = "<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; img-src {{cspSource}} https: data:; script-src {{cspSource}} 'nonce-{{nonce}}' 'unsafe-eval'; style-src {{cspSource}} 'unsafe-inline'; font-src {{cspSource}} data:; connect-src {{cspSource}} https:;\">";
7
+ export interface VscodeTargetOptions {
8
+ /** Absolute path of the vscode target dir (vite root: index.html +
9
+ * extension/ + webview/). */
10
+ targetDir: string;
11
+ /** Absolute output dir (staging root: extension/ + webview/ +
12
+ * generated package.json). Keep it under the app's dist/. */
13
+ outDir: string;
14
+ /** Absolute path to the Tamagui config compiled into the webview. */
15
+ tamaguiConfig: string;
16
+ /** Workspace root (defaults to the git toplevel). */
17
+ workspaceRoot?: string;
18
+ /** Webview CSP meta (defaults to DEFAULT_WEBVIEW_CSP). */
19
+ csp?: string;
20
+ isDev?: boolean;
21
+ /** Extra defines merged over the factory defaults. */
22
+ define?: Record<string, unknown>;
23
+ /** Extra resolve aliases appended after the factory's. */
24
+ aliases?: Alias[];
25
+ }
26
+ /** Resolve the seam's one-adapter: workspace source when developing inside
27
+ * the framework monorepo, the built package export otherwise. */
28
+ export declare function resolveSeamOneAdapter(workspaceRoot: string): string;
29
+ export declare function createVscodeConfig(options: VscodeTargetOptions): Promise<UserConfig>;
30
+ export interface VsceManifest {
31
+ name: string;
32
+ displayName?: string;
33
+ publisher: string;
34
+ version: string;
35
+ description?: string;
36
+ /** "module" when the extension host is built ESM (VS Code ≥1.100). */
37
+ type?: "module" | "commonjs";
38
+ /** Defaults to `{ vscode: "^1.75.0" }`. */
39
+ engines?: {
40
+ vscode: string;
41
+ [key: string]: string;
42
+ };
43
+ /** Defaults to `extension/index.js` (the staging layout). */
44
+ main?: string;
45
+ contributes?: Record<string, unknown>;
46
+ activationEvents?: string[];
47
+ categories?: string[];
48
+ icon?: string;
49
+ repository?: unknown;
50
+ license?: string;
51
+ }
52
+ /** Write the extension-manifest package.json into the staging dir. A VS
53
+ * Code extension's package.json IS its manifest — the product app's own
54
+ * package.json (an Expo/One app manifest) can't double as it, so `vsce
55
+ * package` runs against the staging dir instead. */
56
+ export declare function writeVsceManifest(stagingDir: string, manifest: VsceManifest): Promise<void>;
57
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,KAAK,EAAU,UAAU,EAAE,MAAM,MAAM,CAAC;AAEtD;;;0CAG0C;AAC1C,eAAO,MAAM,mBAAmB,yRAAqR,CAAC;AAEtT,MAAM,WAAW,mBAAmB;IAClC;kCAC8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB;kEAC8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,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;AAgBD;kEACkE;AAClE,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAInE;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CA4G1F;AAID,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,2CAA2C;IAC3C,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpD,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;qDAGqD;AACrD,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAajG"}