@salesforce/vite-plugin-ui-bundle 1.117.2
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.txt +82 -0
- package/README.md +3 -0
- package/dist/babel/reactDesignTimeLocatorBabelPlugin.d.ts +13 -0
- package/dist/babel/reactDesignTimeLocatorBabelPlugin.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +334 -0
- package/dist/utils.d.ts +34 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +49 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Salesforce, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These Terms of Use govern the download, installation, and/or use of this
|
|
6
|
+
software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
|
|
7
|
+
last updated on April 15, 2025, and constitute a legally binding
|
|
8
|
+
agreement between you and Salesforce. If you do not agree to these Terms of
|
|
9
|
+
Use, do not install or use the Software.
|
|
10
|
+
|
|
11
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
|
|
12
|
+
copyright license to reproduce, prepare derivative works of, publicly
|
|
13
|
+
display, publicly perform, sublicense, and distribute the Software and
|
|
14
|
+
derivative works subject to these Terms. These Terms shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
Subject to the limited rights expressly granted hereunder, Salesforce
|
|
18
|
+
reserves all rights, title, and interest in and to all intellectual
|
|
19
|
+
property subsisting in the Software. No rights are granted to you hereunder
|
|
20
|
+
other than as expressly set forth herein. Users residing in countries on
|
|
21
|
+
the United States Office of Foreign Assets Control sanction list, or which
|
|
22
|
+
are otherwise subject to a US export embargo, may not use the Software.
|
|
23
|
+
|
|
24
|
+
Implementation of the Software may require development work, for which you
|
|
25
|
+
are responsible. The Software may contain bugs, errors and
|
|
26
|
+
incompatibilities and is made available on an AS IS basis without support,
|
|
27
|
+
updates, or service level commitments.
|
|
28
|
+
|
|
29
|
+
Salesforce reserves the right at any time to modify, suspend, or
|
|
30
|
+
discontinue, the Software (or any part thereof) with or without notice. You
|
|
31
|
+
agree that Salesforce shall not be liable to you or to any third party for
|
|
32
|
+
any modification, suspension, or discontinuance.
|
|
33
|
+
|
|
34
|
+
You agree to defend Salesforce against any claim, demand, suit or
|
|
35
|
+
proceeding made or brought against Salesforce by a third party arising out
|
|
36
|
+
of or accruing from (a) your use of the Software, and (b) any application
|
|
37
|
+
you develop with the Software that infringes any copyright, trademark,
|
|
38
|
+
trade secret, trade dress, patent, or other intellectual property right of
|
|
39
|
+
any person or defames any person or violates their rights of publicity or
|
|
40
|
+
privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
|
|
41
|
+
from any damages, attorney fees, and costs finally awarded against
|
|
42
|
+
Salesforce as a result of, or for any amounts paid by Salesforce under a
|
|
43
|
+
settlement approved by you in writing of, a Claim Against Salesforce,
|
|
44
|
+
provided Salesforce (x) promptly gives you written notice of the Claim
|
|
45
|
+
Against Salesforce, (y) gives you sole control of the defense and
|
|
46
|
+
settlement of the Claim Against Salesforce (except that you may not settle
|
|
47
|
+
any Claim Against Salesforce unless it unconditionally releases Salesforce
|
|
48
|
+
of all liability), and (z) gives you all reasonable assistance, at your
|
|
49
|
+
expense.
|
|
50
|
+
|
|
51
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
|
|
52
|
+
SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
|
|
54
|
+
INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
55
|
+
PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
|
|
56
|
+
OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
|
|
57
|
+
CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
|
|
58
|
+
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
59
|
+
|
|
60
|
+
These Terms of Use shall be governed exclusively by the internal laws of
|
|
61
|
+
the State of California, without regard to its conflicts of laws
|
|
62
|
+
rules. Each party hereby consents to the exclusive jurisdiction of the
|
|
63
|
+
state and federal courts located in San Francisco County, California to
|
|
64
|
+
adjudicate any dispute arising out of or relating to these Terms of Use and
|
|
65
|
+
the download, installation, and/or use of the Software. Except as expressly
|
|
66
|
+
stated herein, these Terms of Use constitute the entire agreement between
|
|
67
|
+
the parties, and supersede all prior and contemporaneous agreements,
|
|
68
|
+
proposals, or representations, written or oral, concerning their subject
|
|
69
|
+
matter. No modification, amendment, or waiver of any provision of these
|
|
70
|
+
Terms of Use shall be effective unless it is by an update to these Terms of
|
|
71
|
+
Use that Salesforce makes available, or is in writing and signed by the
|
|
72
|
+
party against whom the modification, amendment, or waiver is to be
|
|
73
|
+
asserted.
|
|
74
|
+
|
|
75
|
+
Data Privacy: Salesforce may collect, process, and store device,
|
|
76
|
+
system, and other information related to your use of the Software. This
|
|
77
|
+
information includes, but is not limited to, IP address, user metrics, and
|
|
78
|
+
other data ("Usage Data"). Salesforce may use Usage Data for analytics,
|
|
79
|
+
product development, and marketing purposes. You acknowledge that files
|
|
80
|
+
generated in conjunction with the Software may contain sensitive or
|
|
81
|
+
confidential data, and you are solely responsible for anonymizing and
|
|
82
|
+
protecting such data.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
declare const reactDesignTimeLocatorBabelPlugin: (api: object, options: Record<string, any> | null | undefined, dirname: string) => {
|
|
7
|
+
name: string;
|
|
8
|
+
visitor: {
|
|
9
|
+
JSXElement(this: import('@babel/core').PluginPass, path: any, state: any): void;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export default reactDesignTimeLocatorBabelPlugin;
|
|
13
|
+
//# sourceMappingURL=reactDesignTimeLocatorBabelPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactDesignTimeLocatorBabelPlugin.d.ts","sourceRoot":"","sources":["../../src/babel/reactDesignTimeLocatorBabelPlugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4CH,QAAA,MAAM,iCAAiC;;;iEAiCnB,GAAG,SAAS,GAAG;;CA0EjC,CAAC;AAEH,eAAe,iCAAiC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
export interface PluginOptions {
|
|
3
|
+
/** Salesforce org alias */
|
|
4
|
+
orgAlias?: string;
|
|
5
|
+
/** Enable verbose logging */
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Enable design-time features (inject `data-source-file`, serve & inject design interactions script).
|
|
9
|
+
*
|
|
10
|
+
* Defaults to:
|
|
11
|
+
* - enabled when Vite `mode` is `"design"` (e.g. `vite --mode design`)
|
|
12
|
+
*/
|
|
13
|
+
designMode?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* File path segments to exclude from design-time `data-source-file` injection.
|
|
16
|
+
* Files whose path contains any of these strings will be skipped entirely.
|
|
17
|
+
*
|
|
18
|
+
* @default ["/components/ui/"]
|
|
19
|
+
*/
|
|
20
|
+
designModeExcludePaths?: string[];
|
|
21
|
+
}
|
|
22
|
+
export default function uiBundlePlugin(options?: PluginOptions): Plugin[];
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,KAAK,EAAqB,MAAM,EAAiB,MAAM,MAAM,CAAC;AAUrE,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;IACrB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAID,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CAyQ5E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { loadManifest, getOrgInfo } from "@salesforce/ui-bundle/app";
|
|
3
|
+
import { getDesignModeScriptContent } from "@salesforce/ui-bundle/design";
|
|
4
|
+
import { createProxyHandler, injectLivePreviewScript } from "@salesforce/ui-bundle/proxy";
|
|
5
|
+
import { declare } from "@babel/helper-plugin-utils";
|
|
6
|
+
function resolveColumn(loc, babelCode, originalSource) {
|
|
7
|
+
if (!originalSource || !babelCode) return loc.column;
|
|
8
|
+
const babelLine = babelCode.split("\n")[loc.line - 1];
|
|
9
|
+
const originalLine = originalSource.split("\n")[loc.line - 1];
|
|
10
|
+
if (!babelLine || !originalLine) return loc.column;
|
|
11
|
+
const contentFromColumn = babelLine.slice(loc.column);
|
|
12
|
+
if (contentFromColumn) {
|
|
13
|
+
const idx = originalLine.indexOf(contentFromColumn);
|
|
14
|
+
if (idx >= 0) return idx;
|
|
15
|
+
}
|
|
16
|
+
const babelIndent = babelLine.length - babelLine.trimStart().length;
|
|
17
|
+
const originalIndent = originalLine.length - originalLine.trimStart().length;
|
|
18
|
+
const offset = babelIndent - originalIndent;
|
|
19
|
+
return Math.max(0, loc.column - offset);
|
|
20
|
+
}
|
|
21
|
+
const reactDesignTimeLocatorBabelPlugin = declare((api) => {
|
|
22
|
+
api.assertVersion(7);
|
|
23
|
+
const t = api.types;
|
|
24
|
+
function isReactFragmentName(nameNode) {
|
|
25
|
+
if (t.isJSXIdentifier(nameNode) && nameNode.name === "Fragment") return true;
|
|
26
|
+
if (t.isJSXMemberExpression(nameNode) && t.isJSXIdentifier(nameNode.object, { name: "React" }) && t.isJSXIdentifier(nameNode.property, { name: "Fragment" })) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function hasAttr(openingElement, name) {
|
|
32
|
+
return openingElement.attributes.some((attr) => {
|
|
33
|
+
return t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name === name;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function addAttr(openingElement, name, value) {
|
|
37
|
+
if (hasAttr(openingElement, name)) return;
|
|
38
|
+
openingElement.attributes.push(
|
|
39
|
+
t.jsxAttribute(t.jsxIdentifier(name), t.stringLiteral(String(value)))
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
name: "babel-plugin-react-design-time-locator",
|
|
44
|
+
visitor: {
|
|
45
|
+
JSXElement(path, state) {
|
|
46
|
+
const openingElement = path.node.openingElement;
|
|
47
|
+
if (isReactFragmentName(openingElement.name)) return;
|
|
48
|
+
if (!t.isJSXIdentifier(openingElement.name) && !t.isJSXMemberExpression(openingElement.name)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let tagHead = "";
|
|
52
|
+
if (t.isJSXIdentifier(openingElement.name)) {
|
|
53
|
+
tagHead = openingElement.name.name;
|
|
54
|
+
} else if (t.isJSXMemberExpression(openingElement.name)) {
|
|
55
|
+
tagHead = openingElement.name.property?.name ?? "";
|
|
56
|
+
}
|
|
57
|
+
if (!tagHead) return;
|
|
58
|
+
const filename = state?.file?.opts?.filename;
|
|
59
|
+
if (!filename || filename.includes("node_modules")) return;
|
|
60
|
+
const excludePaths = state.opts?.excludePaths ?? [];
|
|
61
|
+
if (excludePaths.some((p) => filename.includes(p))) return;
|
|
62
|
+
const children = path.node.children ?? [];
|
|
63
|
+
const relevantChildren = children.filter((child) => {
|
|
64
|
+
return !(t.isJSXText(child) && child.value.trim() === "");
|
|
65
|
+
});
|
|
66
|
+
let textType = "none";
|
|
67
|
+
if (relevantChildren.length === 1) {
|
|
68
|
+
const child = relevantChildren[0];
|
|
69
|
+
if (t.isJSXText(child)) {
|
|
70
|
+
textType = "static";
|
|
71
|
+
} else if (t.isJSXExpressionContainer(child)) {
|
|
72
|
+
textType = "dynamic";
|
|
73
|
+
} else {
|
|
74
|
+
textType = "element";
|
|
75
|
+
}
|
|
76
|
+
} else if (relevantChildren.length > 1) {
|
|
77
|
+
textType = "mixed";
|
|
78
|
+
}
|
|
79
|
+
const loc = path.node.loc;
|
|
80
|
+
if (loc?.start) {
|
|
81
|
+
const originalSource = state.opts?.originalSource;
|
|
82
|
+
const column = resolveColumn(loc.start, state.file?.code, originalSource);
|
|
83
|
+
const source = `${filename}:${loc.start.line}:${column}`;
|
|
84
|
+
addAttr(openingElement, "data-source-file", source);
|
|
85
|
+
}
|
|
86
|
+
addAttr(openingElement, "data-text-type", textType);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
const DEFAULT_PORT = 5173;
|
|
92
|
+
const DEFAULT_API_VERSION = "65.0";
|
|
93
|
+
function getCodeBuilderBasePath(proxyUri, port) {
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(proxyUri.replace("{{port}}", port.toString()));
|
|
96
|
+
return url.pathname;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error("Failed to parse CODE_BUILDER_FRAMEWORK_PROXY_URI:", error);
|
|
99
|
+
return `/absproxy/${port}`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function getDevServerTarget(codeBuilderProxyUrl2, port) {
|
|
103
|
+
if (codeBuilderProxyUrl2) {
|
|
104
|
+
return getCodeBuilderBasePath(codeBuilderProxyUrl2, port);
|
|
105
|
+
}
|
|
106
|
+
return `http://localhost:${port}`;
|
|
107
|
+
}
|
|
108
|
+
function getPort() {
|
|
109
|
+
return parseInt(process.env.SF_UIBUNDLE_PORT || DEFAULT_PORT.toString(), 10);
|
|
110
|
+
}
|
|
111
|
+
const codeBuilderProxyUrl = process.env.CODE_BUILDER_FRAMEWORK_PROXY_URI;
|
|
112
|
+
function uiBundlePlugin(options = {}) {
|
|
113
|
+
const proxyOptions = {
|
|
114
|
+
debug: options.debug ?? false
|
|
115
|
+
};
|
|
116
|
+
let orgInfo;
|
|
117
|
+
let manifest;
|
|
118
|
+
let environment;
|
|
119
|
+
let proxyHandler;
|
|
120
|
+
let designModeEnabled = options.designMode ?? false;
|
|
121
|
+
const corePlugin = {
|
|
122
|
+
name: "@salesforce/vite-plugin-ui-bundle:core",
|
|
123
|
+
enforce: "pre",
|
|
124
|
+
async config(_config, env) {
|
|
125
|
+
let version;
|
|
126
|
+
try {
|
|
127
|
+
orgInfo = await getOrgInfo(options.orgAlias);
|
|
128
|
+
version = orgInfo?.apiVersion || DEFAULT_API_VERSION;
|
|
129
|
+
if (options.debug) {
|
|
130
|
+
console.log(`[ui-bundle-plugin] Using Salesforce API version: ${version}`);
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
version = DEFAULT_API_VERSION;
|
|
134
|
+
}
|
|
135
|
+
const isCodeBuilder = !!codeBuilderProxyUrl;
|
|
136
|
+
const define = {
|
|
137
|
+
__SF_API_VERSION__: JSON.stringify(version)
|
|
138
|
+
};
|
|
139
|
+
if (env.mode !== "production") {
|
|
140
|
+
const basePath = isCodeBuilder ? getCodeBuilderBasePath(codeBuilderProxyUrl, getPort()) : "/";
|
|
141
|
+
environment = { basePath, apiPath: basePath };
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
define,
|
|
145
|
+
base: "./",
|
|
146
|
+
server: {
|
|
147
|
+
port: getPort(),
|
|
148
|
+
// Code Builder specific configuration
|
|
149
|
+
...isCodeBuilder && {
|
|
150
|
+
allowedHosts: true,
|
|
151
|
+
strictPort: true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
async configResolved(config) {
|
|
157
|
+
try {
|
|
158
|
+
const rootPath = config.root ?? process.cwd();
|
|
159
|
+
manifest = await loadManifest(`${rootPath}/ui-bundle.json`);
|
|
160
|
+
const target = getDevServerTarget(codeBuilderProxyUrl, config.server.port ?? DEFAULT_PORT);
|
|
161
|
+
proxyHandler = createProxyHandler(
|
|
162
|
+
manifest,
|
|
163
|
+
orgInfo,
|
|
164
|
+
target,
|
|
165
|
+
environment?.basePath,
|
|
166
|
+
proxyOptions
|
|
167
|
+
);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error(`[ui-bundle-plugin] Initialization failed:`, error);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
configureServer(server) {
|
|
173
|
+
server.middlewares.use(async (req, res, next) => {
|
|
174
|
+
if (proxyHandler) {
|
|
175
|
+
try {
|
|
176
|
+
await proxyHandler(req, res, next);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error("[ui-bundle-plugin] Proxy handler error:", error);
|
|
179
|
+
next();
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
if (req.url?.startsWith("/services")) {
|
|
183
|
+
res.writeHead(503, { "Content-Type": "application/json" });
|
|
184
|
+
res.end(
|
|
185
|
+
JSON.stringify({
|
|
186
|
+
error: "SERVICE_UNAVAILABLE",
|
|
187
|
+
message: "Proxy not initialized."
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
next();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
async handleHotUpdate({ file, server }) {
|
|
197
|
+
if (file.endsWith("ui-bundle.json")) {
|
|
198
|
+
const updatedManifest = await loadManifest(file);
|
|
199
|
+
if (updatedManifest) {
|
|
200
|
+
manifest = updatedManifest;
|
|
201
|
+
const target = getDevServerTarget(
|
|
202
|
+
codeBuilderProxyUrl,
|
|
203
|
+
server.config.server.port ?? DEFAULT_PORT
|
|
204
|
+
);
|
|
205
|
+
proxyHandler = createProxyHandler(
|
|
206
|
+
manifest,
|
|
207
|
+
orgInfo,
|
|
208
|
+
target,
|
|
209
|
+
environment?.basePath,
|
|
210
|
+
proxyOptions
|
|
211
|
+
);
|
|
212
|
+
server.ws.send({
|
|
213
|
+
type: "full-reload",
|
|
214
|
+
path: "*"
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
transformIndexHtml: {
|
|
220
|
+
order: "pre",
|
|
221
|
+
handler(html) {
|
|
222
|
+
if (environment) {
|
|
223
|
+
html = injectLivePreviewScript(html);
|
|
224
|
+
}
|
|
225
|
+
const tags = [];
|
|
226
|
+
if (environment) {
|
|
227
|
+
const baseHref = environment.basePath.endsWith("/") ? environment.basePath : `${environment.basePath}/`;
|
|
228
|
+
tags.push({
|
|
229
|
+
tag: "base",
|
|
230
|
+
attrs: { href: baseHref },
|
|
231
|
+
injectTo: "head-prepend"
|
|
232
|
+
});
|
|
233
|
+
tags.push({
|
|
234
|
+
tag: "script",
|
|
235
|
+
children: `(function() { globalThis.SFDC_ENV = { basePath: "${environment.basePath}", apiPath: "${environment.apiPath}" }; })();`,
|
|
236
|
+
injectTo: "body"
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return { html, tags };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const designPlugin = {
|
|
244
|
+
name: "@salesforce/vite-plugin-ui-bundle:design",
|
|
245
|
+
enforce: "pre",
|
|
246
|
+
config(_config, env) {
|
|
247
|
+
designModeEnabled = options.designMode ?? env.mode === "design";
|
|
248
|
+
},
|
|
249
|
+
configureServer(server) {
|
|
250
|
+
server.middlewares.use(async (req, res, next) => {
|
|
251
|
+
if (!designModeEnabled) {
|
|
252
|
+
next();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const urlPath = stripUrlQuery(req.url);
|
|
256
|
+
if (urlPath === "/_sfdc/design-mode-interactions.js") {
|
|
257
|
+
try {
|
|
258
|
+
const script = getDesignModeScriptContent();
|
|
259
|
+
if (script !== null) {
|
|
260
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
261
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
262
|
+
res.end(script);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
console.error(
|
|
266
|
+
`[ui-bundle-plugin] Design mode script not found. Run 'npm run build:design' in @salesforce/ui-bundle.`
|
|
267
|
+
);
|
|
268
|
+
res.writeHead(404);
|
|
269
|
+
res.end("Design mode script not found");
|
|
270
|
+
return;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error("[ui-bundle-plugin] Error serving design mode script:", error);
|
|
273
|
+
res.writeHead(500);
|
|
274
|
+
res.end("Error loading design mode script");
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
next();
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
async transform(code, id) {
|
|
282
|
+
if (!designModeEnabled) return null;
|
|
283
|
+
const filepath = id.split("?", 1)[0] ?? id;
|
|
284
|
+
const isTsx = filepath.endsWith(".tsx");
|
|
285
|
+
const isJsx = filepath.endsWith(".jsx");
|
|
286
|
+
if (!isTsx && !isJsx) return null;
|
|
287
|
+
if (filepath.includes("node_modules")) return null;
|
|
288
|
+
const excludePaths = options.designModeExcludePaths ?? ["/components/ui/"];
|
|
289
|
+
if (excludePaths.some((p) => filepath.includes(p))) return null;
|
|
290
|
+
let originalSource;
|
|
291
|
+
try {
|
|
292
|
+
originalSource = fs.readFileSync(filepath, "utf-8");
|
|
293
|
+
} catch {
|
|
294
|
+
}
|
|
295
|
+
const { transformAsync } = await import("@babel/core");
|
|
296
|
+
const result = await transformAsync(code, {
|
|
297
|
+
filename: filepath,
|
|
298
|
+
babelrc: false,
|
|
299
|
+
configFile: false,
|
|
300
|
+
sourceMaps: true,
|
|
301
|
+
parserOpts: {
|
|
302
|
+
sourceType: "module",
|
|
303
|
+
plugins: isTsx ? ["jsx", "typescript"] : ["jsx"]
|
|
304
|
+
},
|
|
305
|
+
plugins: [[reactDesignTimeLocatorBabelPlugin, { excludePaths, originalSource }]]
|
|
306
|
+
});
|
|
307
|
+
if (!result?.code) return null;
|
|
308
|
+
return { code: result.code, map: result.map };
|
|
309
|
+
},
|
|
310
|
+
transformIndexHtml: {
|
|
311
|
+
order: "pre",
|
|
312
|
+
handler(html) {
|
|
313
|
+
const tags = [];
|
|
314
|
+
if (designModeEnabled) {
|
|
315
|
+
tags.push({
|
|
316
|
+
tag: "script",
|
|
317
|
+
attrs: { src: "/_sfdc/design-mode-interactions.js" },
|
|
318
|
+
injectTo: "body"
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return { html, tags };
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
return [designPlugin, corePlugin];
|
|
326
|
+
}
|
|
327
|
+
function stripUrlQuery(url) {
|
|
328
|
+
if (!url) return "";
|
|
329
|
+
const queryIndex = url.indexOf("?");
|
|
330
|
+
return queryIndex === -1 ? url : url.slice(0, queryIndex);
|
|
331
|
+
}
|
|
332
|
+
export {
|
|
333
|
+
uiBundlePlugin as default
|
|
334
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_PORT = 5173;
|
|
7
|
+
export declare const DEFAULT_API_VERSION = "65.0";
|
|
8
|
+
export declare const DEFAULT_NAMESPACE = "c";
|
|
9
|
+
/**
|
|
10
|
+
* Get the app name from a *.uibundle-meta.xml file in the root path.
|
|
11
|
+
* Falls back to the directory name if no matching file is found.
|
|
12
|
+
*
|
|
13
|
+
* @param rootPath - The root directory to search for the uibundle-meta.xml file
|
|
14
|
+
* @returns The app name
|
|
15
|
+
*/
|
|
16
|
+
export declare function getAppName(rootPath: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get the namespace for the app.
|
|
19
|
+
* Currently returns the default namespace ("c") since rootPath points to the
|
|
20
|
+
* UI Bundle directory (where vite.config lives), not the sfdx project root.
|
|
21
|
+
*
|
|
22
|
+
* @returns The namespace (currently always "c")
|
|
23
|
+
*/
|
|
24
|
+
export declare function getNamespace(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Calculate the code builder base path from the proxy URI (CODE_BUILDER_FRAMEWORK_PROXY_URI) and dev server port
|
|
27
|
+
* @param proxyUri - The full proxy URI (e.g., https://name.iad.001.sf.code-builder.platform.salesforce.com/absproxy/{{port}})
|
|
28
|
+
* @param port - The port number to replace {{port}} with (e.g., "5173")
|
|
29
|
+
* @returns The parsed path with port (e.g., /absproxy/5173/)
|
|
30
|
+
*/
|
|
31
|
+
export declare function getCodeBuilderBasePath(proxyUri: string, port: number): string;
|
|
32
|
+
export declare function getDevServerTarget(codeBuilderProxyUrl: string | undefined, port: number): string;
|
|
33
|
+
export declare function getPort(): number;
|
|
34
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYnD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED,wBAAgB,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAMvF;AAED,wBAAgB,OAAO,WAEtB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/vite-plugin-ui-bundle",
|
|
3
|
+
"description": "Vite plugin for Salesforce UI Bundles",
|
|
4
|
+
"version": "1.117.2",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"dev": "vite build --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@babel/core": "^7.28.4",
|
|
30
|
+
"@babel/helper-plugin-utils": "^7.28.3",
|
|
31
|
+
"@salesforce/ui-bundle": "^1.117.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/babel__core": "^7.20.5",
|
|
35
|
+
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
36
|
+
"vite": "^7.0.0",
|
|
37
|
+
"vite-plugin-dts": "^4.5.4",
|
|
38
|
+
"vitest": "^4.0.6"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"vite": "^7.0.0"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=20.0.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|