@salesforce/vite-plugin-webapp-experimental 1.114.0 → 1.116.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.
@@ -3,19 +3,6 @@
3
3
  * All rights reserved.
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
- /**
7
- * React design-time Babel plugin.
8
- *
9
- * Injects DOM-locating and text metadata attributes into HTML JSX elements at compile-time.
10
- *
11
- * Attributes injected (when location is available):
12
- * - data-source-file="<file_path>:<line>:<col>"
13
- *
14
- * Optional text metadata:
15
- * - data-text-type: none | static | dynamic | mixed | element
16
- *
17
- * NOTE: This is a Babel plugin. In this repo it's run via a Vite `transform` hook.
18
- */
19
6
  declare const reactDesignTimeLocatorBabelPlugin: (api: object, options: Record<string, any> | null | undefined, dirname: string) => {
20
7
  name: string;
21
8
  visitor: {
@@ -1 +1 @@
1
- {"version":3,"file":"reactDesignTimeLocatorBabelPlugin.d.ts","sourceRoot":"","sources":["../../src/babel/reactDesignTimeLocatorBabelPlugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,iCAAiC;;;iEAiCnB,GAAG,SAAS,GAAG;;CAwEjC,CAAC;AAEH,eAAe,iCAAiC,CAAC"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,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,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CAkQ3E"}
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,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CAyQ3E"}
package/dist/index.js CHANGED
@@ -1,7 +1,23 @@
1
+ import fs from "node:fs";
1
2
  import { loadManifest, getOrgInfo } from "@salesforce/webapp-experimental/app";
2
3
  import { getDesignModeScriptContent } from "@salesforce/webapp-experimental/design";
3
4
  import { createProxyHandler, injectLivePreviewScript } from "@salesforce/webapp-experimental/proxy";
4
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
+ }
5
21
  const reactDesignTimeLocatorBabelPlugin = declare((api) => {
6
22
  api.assertVersion(7);
7
23
  const t = api.types;
@@ -62,7 +78,9 @@ const reactDesignTimeLocatorBabelPlugin = declare((api) => {
62
78
  }
63
79
  const loc = path.node.loc;
64
80
  if (loc?.start) {
65
- const source = `${filename}:${loc.start.line}:${loc.start.column}`;
81
+ const originalSource = state.opts?.originalSource;
82
+ const column = resolveColumn(loc.start, state.file?.code, originalSource);
83
+ const source = `${filename}:${loc.start.line}:${column}`;
66
84
  addAttr(openingElement, "data-source-file", source);
67
85
  }
68
86
  addAttr(openingElement, "data-text-type", textType);
@@ -269,6 +287,11 @@ function webappsPlugin(options = {}) {
269
287
  if (filepath.includes("node_modules")) return null;
270
288
  const excludePaths = options.designModeExcludePaths ?? ["/components/ui/"];
271
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
+ }
272
295
  const { transformAsync } = await import("@babel/core");
273
296
  const result = await transformAsync(code, {
274
297
  filename: filepath,
@@ -279,7 +302,7 @@ function webappsPlugin(options = {}) {
279
302
  sourceType: "module",
280
303
  plugins: isTsx ? ["jsx", "typescript"] : ["jsx"]
281
304
  },
282
- plugins: [[reactDesignTimeLocatorBabelPlugin, { excludePaths }]]
305
+ plugins: [[reactDesignTimeLocatorBabelPlugin, { excludePaths, originalSource }]]
283
306
  });
284
307
  if (!result?.code) return null;
285
308
  return { code: result.code, map: result.map };
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.114.0",
4
+ "version": "1.116.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.114.0"
31
+ "@salesforce/webapp-experimental": "^1.116.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/babel__core": "^7.20.5",