@salesforce/vite-plugin-webapp-experimental 1.68.1 → 1.70.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -62
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAWlD,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAWlD,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CAoN3E"}
|
package/dist/index.js
CHANGED
|
@@ -18,18 +18,14 @@ export default function webappsPlugin(options = {}) {
|
|
|
18
18
|
let proxyHandler;
|
|
19
19
|
// Allow tests or callers to force design mode without needing to run the `config` hook.
|
|
20
20
|
let designModeEnabled = options.designMode ?? false;
|
|
21
|
-
|
|
22
|
-
name: "@salesforce/vite-plugin-webapp-experimental",
|
|
21
|
+
const corePlugin = {
|
|
22
|
+
name: "@salesforce/vite-plugin-webapp-experimental:core",
|
|
23
23
|
enforce: "pre",
|
|
24
24
|
async config(config, env) {
|
|
25
25
|
const rootPath = config.root ?? process.cwd();
|
|
26
|
-
// If caller explicitly set it, keep that value. Otherwise derive from Vite mode.
|
|
27
|
-
designModeEnabled = options.designMode ?? env.mode === "design";
|
|
28
26
|
// Note: At this stage we may not have the correct manifest path yet,
|
|
29
27
|
// so we only load the org info to get the API version
|
|
30
|
-
|
|
31
|
-
let version;
|
|
32
|
-
version = DEFAULT_API_VERSION;
|
|
28
|
+
let version = DEFAULT_API_VERSION;
|
|
33
29
|
try {
|
|
34
30
|
orgInfo = await getOrgInfo(options.orgAlias);
|
|
35
31
|
version = orgInfo?.apiVersion || DEFAULT_API_VERSION;
|
|
@@ -56,9 +52,8 @@ export default function webappsPlugin(options = {}) {
|
|
|
56
52
|
port: getPort(),
|
|
57
53
|
// Code Builder specific configuration
|
|
58
54
|
...(isCodeBuilder && {
|
|
59
|
-
// Allow any host to connect to the dev server
|
|
60
55
|
allowedHosts: true,
|
|
61
|
-
strictPort: true,
|
|
56
|
+
strictPort: true,
|
|
62
57
|
}),
|
|
63
58
|
},
|
|
64
59
|
};
|
|
@@ -76,16 +71,62 @@ export default function webappsPlugin(options = {}) {
|
|
|
76
71
|
}
|
|
77
72
|
},
|
|
78
73
|
configureServer(server) {
|
|
79
|
-
// Add middleware to handle all requests (API, rewrites, redirects, and dev server forwarding)
|
|
80
74
|
// Must run BEFORE Vite's internal middlewares (hence not returning a post-hook function)
|
|
81
75
|
server.middlewares.use(async (req, res, next) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
if (proxyHandler) {
|
|
77
|
+
try {
|
|
78
|
+
await proxyHandler(req, res, next);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error("[webapps-plugin] Proxy handler error:", error);
|
|
82
|
+
next();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
if (req.url?.startsWith("/services")) {
|
|
87
|
+
res.writeHead(503, { "Content-Type": "application/json" });
|
|
88
|
+
res.end(JSON.stringify({
|
|
89
|
+
error: "SERVICE_UNAVAILABLE",
|
|
90
|
+
message: "Proxy not initialized.",
|
|
91
|
+
}));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
next();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
async handleHotUpdate({ file, server }) {
|
|
99
|
+
if (file.endsWith("webapplication.json")) {
|
|
100
|
+
const updatedManifest = await loadManifest(file);
|
|
101
|
+
if (updatedManifest) {
|
|
102
|
+
manifest = updatedManifest;
|
|
103
|
+
const rootPath = server.config.root ?? process.cwd();
|
|
104
|
+
const target = getDevServerTarget(codeBuilderProxyUrl, server.config.server.port ?? DEFAULT_PORT);
|
|
105
|
+
const basePath = getBasePath(server.config.mode, codeBuilderProxyUrl, getPort(), rootPath);
|
|
106
|
+
proxyHandler = createProxyHandler(manifest, orgInfo, target, basePath, proxyOptions);
|
|
107
|
+
server.ws.send({
|
|
108
|
+
type: "full-reload",
|
|
109
|
+
path: "*",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
const designPlugin = {
|
|
116
|
+
name: "@salesforce/vite-plugin-webapp-experimental:design",
|
|
117
|
+
enforce: "pre",
|
|
118
|
+
config(_config, env) {
|
|
119
|
+
designModeEnabled = options.designMode ?? env.mode === "design";
|
|
120
|
+
},
|
|
121
|
+
configureServer(server) {
|
|
122
|
+
// Intercepts design-mode script requests before the core proxy middleware.
|
|
123
|
+
server.middlewares.use(async (req, res, next) => {
|
|
124
|
+
if (!designModeEnabled) {
|
|
125
|
+
next();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
85
128
|
const urlPath = stripUrlQuery(req.url);
|
|
86
|
-
if (
|
|
87
|
-
(urlPath === "/design-mode-interactions.js" ||
|
|
88
|
-
urlPath.endsWith("/design-mode-interactions.js"))) {
|
|
129
|
+
if (urlPath === "/_sfdc/design-mode-interactions.js") {
|
|
89
130
|
try {
|
|
90
131
|
const script = getDesignModeScriptContent();
|
|
91
132
|
if (script !== null) {
|
|
@@ -106,32 +147,10 @@ export default function webappsPlugin(options = {}) {
|
|
|
106
147
|
return;
|
|
107
148
|
}
|
|
108
149
|
}
|
|
109
|
-
|
|
110
|
-
if (proxyHandler) {
|
|
111
|
-
try {
|
|
112
|
-
await proxyHandler(req, res, next);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error("[webapps-plugin] Proxy handler error:", error);
|
|
116
|
-
next();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// Only return 503 for Salesforce API requests when handler not initialized
|
|
121
|
-
if (req.url?.startsWith("/services")) {
|
|
122
|
-
res.writeHead(503, { "Content-Type": "application/json" });
|
|
123
|
-
res.end(JSON.stringify({
|
|
124
|
-
error: "SERVICE_UNAVAILABLE",
|
|
125
|
-
message: "Proxy not initialized.",
|
|
126
|
-
}));
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
next();
|
|
130
|
-
}
|
|
150
|
+
next();
|
|
131
151
|
});
|
|
132
152
|
},
|
|
133
153
|
async transform(code, id) {
|
|
134
|
-
// Only inject design-time locator attributes when design mode is enabled
|
|
135
154
|
if (!designModeEnabled)
|
|
136
155
|
return null;
|
|
137
156
|
// Strip Vite query string (e.g. ?import, ?v=hash)
|
|
@@ -159,36 +178,17 @@ export default function webappsPlugin(options = {}) {
|
|
|
159
178
|
return null;
|
|
160
179
|
return { code: result.code, map: result.map };
|
|
161
180
|
},
|
|
162
|
-
async handleHotUpdate({ file, server }) {
|
|
163
|
-
// Watch for manifest changes and reload
|
|
164
|
-
if (file.endsWith("webapplication.json")) {
|
|
165
|
-
const updatedManifest = await loadManifest(file);
|
|
166
|
-
if (updatedManifest) {
|
|
167
|
-
// Update context with new manifest
|
|
168
|
-
manifest = updatedManifest;
|
|
169
|
-
// Recreate proxy handler with updated appContext
|
|
170
|
-
const rootPath = server.config.root ?? process.cwd();
|
|
171
|
-
const target = getDevServerTarget(codeBuilderProxyUrl, server.config.server.port ?? DEFAULT_PORT);
|
|
172
|
-
const basePath = getBasePath(server.config.mode, codeBuilderProxyUrl, getPort(), rootPath);
|
|
173
|
-
proxyHandler = createProxyHandler(manifest, orgInfo, target, basePath, proxyOptions);
|
|
174
|
-
server.ws.send({
|
|
175
|
-
type: "full-reload",
|
|
176
|
-
path: "*",
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
181
|
transformIndexHtml(html) {
|
|
182
|
-
// Only inject design mode interactions script when design mode is enabled in dev
|
|
183
182
|
if (designModeEnabled) {
|
|
184
|
-
|
|
185
|
-
// (e.g. VS Code Live Preview or Code Builder reverse proxies).
|
|
186
|
-
const designScriptTag = '<script src="design-mode-interactions.js"></script>';
|
|
183
|
+
const designScriptTag = '<script src="/_sfdc/design-mode-interactions.js"></script>';
|
|
187
184
|
return html.replace("</body>", `${designScriptTag}\n</body>`);
|
|
188
185
|
}
|
|
189
186
|
return html;
|
|
190
187
|
},
|
|
191
188
|
};
|
|
189
|
+
// Design plugin is listed first so its middleware intercepts design-mode
|
|
190
|
+
// script requests before the core proxy middleware.
|
|
191
|
+
return [designPlugin, corePlugin];
|
|
192
192
|
}
|
|
193
193
|
function stripUrlQuery(url) {
|
|
194
194
|
if (!url)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/vite-plugin-webapp-experimental",
|
|
3
3
|
"description": "[experimental] Vite plugin for Salesforce Web Applications",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.70.0",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/core": "^7.28.4",
|
|
30
30
|
"@babel/helper-plugin-utils": "^7.28.3",
|
|
31
|
-
"@salesforce/webapp-experimental": "^1.
|
|
31
|
+
"@salesforce/webapp-experimental": "^1.70.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/babel__core": "^7.20.5",
|