Skip to content

Commit 335e56f

Browse files
konardclaude
andcommitted
fix(app): update babel.cjs with data-path and attributeName support
- Change default attribute name from 'path' to 'data-path' - Add support for attributeName option in babel.cjs - Ensure idempotency with configurable attribute name This fixes the Next.js E2E test failures by updating the CommonJS entry point which is used by Next.js Babel configuration. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 749e54d commit 335e56f

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

packages/app/babel.cjs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* "plugins": ["@prover-coder-ai/component-tagger/babel"]
1212
* }
1313
*/
14-
// CHANGE: provide CommonJS entry point for Babel plugin.
15-
// WHY: Babel configuration often requires CommonJS modules.
16-
// REF: issue-12
14+
// CHANGE: provide CommonJS entry point for Babel plugin with configurable attributeName.
15+
// WHY: Babel configuration often requires CommonJS modules; support custom attribute names.
16+
// REF: issue-12, issue-14
1717
// FORMAT THEOREM: forall require: require(babel.cjs) -> PluginFactory
1818
// PURITY: SHELL
1919
// EFFECT: n/a
@@ -22,7 +22,7 @@
2222

2323
const path = require("node:path")
2424

25-
const componentPathAttributeName = "path"
25+
const componentPathAttributeName = "data-path"
2626
const jsxFilePattern = /\.(tsx|jsx)(\?.*)?$/u
2727

2828
const isJsxFile = (id) => jsxFilePattern.test(id)
@@ -58,21 +58,22 @@ module.exports = function componentTaggerBabelPlugin({ types: t }) {
5858
return
5959
}
6060

61-
// Skip if already has path attribute
62-
if (attrExists(node, componentPathAttributeName, t)) {
63-
return
64-
}
65-
66-
// Compute relative path from root
61+
// Compute relative path from root and get attribute name
6762
const opts = state.opts || {}
6863
const rootDir = opts.rootDir || state.cwd || process.cwd()
64+
const attributeName = opts.attributeName || componentPathAttributeName
6965
const relativeFilename = path.relative(rootDir, filename)
7066

67+
// Skip if already has the specified attribute (idempotency)
68+
if (attrExists(node, attributeName, t)) {
69+
return
70+
}
71+
7172
const { column, line } = node.loc.start
7273
const value = formatComponentPathValue(relativeFilename, line, column)
7374

7475
node.attributes.push(
75-
t.jsxAttribute(t.jsxIdentifier(componentPathAttributeName), t.stringLiteral(value))
76+
t.jsxAttribute(t.jsxIdentifier(attributeName), t.stringLiteral(value))
7677
)
7778
}
7879
}

0 commit comments

Comments
 (0)