jsx-loc-plugin 0.1.24 → 0.1.26

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/loader.cjs CHANGED
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(loader_exports);
37
37
  // src/transform.ts
38
38
  var import_parser = require("@babel/parser");
39
39
  var import_magic_string = __toESM(require("magic-string"), 1);
40
+ var import_path = require("path");
40
41
  var VALID_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx"]);
41
42
  var DEFAULT_PARSER_OPTIONS = {
42
43
  sourceType: "module",
@@ -132,7 +133,12 @@ function findInsertionPoint(node, source) {
132
133
  return insertPos;
133
134
  }
134
135
  function normalizeFilePath(filePath) {
135
- return filePath.replace(/\\/g, "/");
136
+ const abs = (0, import_path.resolve)(filePath).replace(/\\/g, "/");
137
+ const cwd = (0, import_path.resolve)(process.cwd()).replace(/\\/g, "/");
138
+ if (abs === cwd || abs.startsWith(cwd + "/")) {
139
+ return (0, import_path.relative)(cwd, abs).replace(/\\/g, "/");
140
+ }
141
+ return abs;
136
142
  }
137
143
  function transformJsxCode(source, filePath, options = {}) {
138
144
  const parserOptions = {
package/dist/loader.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/transform.ts
2
2
  import { parse } from "@babel/parser";
3
3
  import MagicString from "magic-string";
4
+ import { relative, resolve } from "path";
4
5
  var VALID_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx"]);
5
6
  var DEFAULT_PARSER_OPTIONS = {
6
7
  sourceType: "module",
@@ -96,7 +97,12 @@ function findInsertionPoint(node, source) {
96
97
  return insertPos;
97
98
  }
98
99
  function normalizeFilePath(filePath) {
99
- return filePath.replace(/\\/g, "/");
100
+ const abs = resolve(filePath).replace(/\\/g, "/");
101
+ const cwd = resolve(process.cwd()).replace(/\\/g, "/");
102
+ if (abs === cwd || abs.startsWith(cwd + "/")) {
103
+ return relative(cwd, abs).replace(/\\/g, "/");
104
+ }
105
+ return abs;
100
106
  }
101
107
  function transformJsxCode(source, filePath, options = {}) {
102
108
  const parserOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsx-loc-plugin",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "Next.js plugin that adds data-loc attributes to JSX elements for UILint inspection",
5
5
  "author": "Peter Suggate",
6
6
  "license": "MIT",