Skip to content

Commit 7c8a5cf

Browse files
committed
refactor: rename package to react-display-name-plugin and update references across codebase and examples
1 parent 775c467 commit 7c8a5cf

31 files changed

+290
-164
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "npm"
3+
- package-ecosystem: "pnpm"
44
directories:
55
- "/examples/*"
6+
- "/"
67
schedule:
78
interval: "monthly"
89
labels: []

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright for portions of webpack-react-component-name are held by Reflect Software, Inc (2020) as the original Authors. All other copyright for webpack-react-component-name are held by Mockingjay Pte Ltd (2024).
3+
Copyright for small portions of react-display-name-plugin are held by SmartBear Software (2020) as the original Authors of https://github.com/runreflect/webpack-react-component-name. All other copyright for react-display-name-plugin are held by Mockingjay Pte Ltd (2025)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
## Overview
22

3-
**webpack-react-component-name** is a build plugin for both Webpack and Vite that makes your custom
3+
**react-display-name-plugin** is a build plugin for both Webpack and Vite that makes your custom
44
React components visible within React Dev Tools and other tools that rely on the displayName parameter.
55

6-
_Note: This branch contains the version of this plugin that is compatible with
7-
Webpack 5 and Vite 2+. For support for Webpack 4, see 0.x [branch/version](https://github.com/mockingjay-io/webpack-react-component-name/tree/0.x.) of this plugin_
6+
_Note: This package supports Webpack 5 and Vite 2+. For older versions (Webpack 4), see the legacy package [@mockingjay-io/webpack-react-component-name](https://github.com/mockingjay-io/webpack-react-component-name)._
87

98
Normally React component names are minified during compilation. This plugin
109
makes these component names available in production bundles by hooking into
@@ -20,30 +19,30 @@ result in a small size increase to your production bundles.
2019

2120
## Installation
2221

23-
1. Install via your prefered package manager:
22+
1. Install via your preferred package manager:
2423

2524
```bash
26-
npm install @mockingjay-io/webpack-react-component-name --save-dev
25+
npm install react-display-name-plugin --save-dev
2726
```
2827

2928
### For Webpack
3029

3130
2. Import and add the plugin to your Webpack configuration:
3231

3332
```js
34-
const WebpackReactComponentNamePlugin = require('@mockingjay-io/webpack-react-component-name');
33+
const ReactDisplayNamePlugin = require('react-display-name-plugin/webpack');
3534

3635
module.exports = {
3736
// ... other config
3837
plugins: [
39-
new WebpackReactComponentNamePlugin({
38+
new ReactDisplayNamePlugin({
4039
parseDependencies: true,
4140
})
4241
],
4342
};
4443
```
4544

46-
**Next.js users** have to add this within `next.config.js`/`next.config.mjs`/`next.config.ts`. Examples available [here](https://github.com/mockingjay-io/webpack-react-component-name/tree/main/examples).
45+
**Next.js users** have to add this within `next.config.js`/`next.config.mjs`/`next.config.ts`. Examples available [here](https://github.com/mockingjay-io/react-display-name-plugin/tree/main/examples).
4746

4847
### For Vite
4948

@@ -53,12 +52,12 @@ module.exports = {
5352
// vite.config.js / vite.config.ts
5453
import { defineConfig } from 'vite';
5554
import react from '@vitejs/plugin-react';
56-
import ViteReactComponentNamePlugin from '@mockingjay-io/webpack-react-component-name/vite';
55+
import reactDisplayNamePlugin from 'react-display-name-plugin/vite';
5756

5857
export default defineConfig({
5958
plugins: [
6059
react(),
61-
ViteReactComponentNamePlugin({
60+
reactDisplayNamePlugin({
6261
parseDependencies: true,
6362
})
6463
],
@@ -67,6 +66,34 @@ export default defineConfig({
6766

6867
**Note:** The Vite plugin should be placed after the React plugin in your plugins array, as it needs to run after JSX transformation.
6968

69+
### Core Utilities (Advanced)
70+
71+
For building custom plugins for other bundlers, you can import the core utilities directly:
72+
73+
```js
74+
const {
75+
detectReactComponents,
76+
generateDisplayNameCode
77+
} = require('react-display-name-plugin');
78+
const { parse } = require('acorn');
79+
80+
const code = 'function MyComponent() { return <div>Hello</div>; }';
81+
const ast = parse(code, { ecmaVersion: 'latest', sourceType: 'module' });
82+
83+
detectReactComponents(ast, (node) => {
84+
const componentName = node.id.name;
85+
const injectionCode = generateDisplayNameCode(componentName);
86+
console.log(injectionCode); // ;try{MyComponent.displayName="MyComponent";}catch(e){}
87+
});
88+
```
89+
90+
**Available Utilities:**
91+
- `detectReactComponents(ast, callback)` - Walks an AST and detects React components
92+
- `generateDisplayNameCode(componentName)` - Generates displayName injection code
93+
- `argumentCreatesElement(argument)` - Checks if AST node is React.createElement
94+
- `argumentJsx(argument)` - Checks if AST node is JSX transform output (_jsx, _jsxs)
95+
- `shouldAddDisplayName(node)` - Checks if a node should have displayName added
96+
7097
## Options
7198

7299
```json

examples/create-react-app-ejected/config/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
99
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
1010
const TerserPlugin = require('terser-webpack-plugin');
1111
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
12-
const WebpackReactComponentNamePlugin = require('webpack-react-component-name');
12+
const WebpackReactComponentNamePlugin = require('react-display-name-plugin/webpack');
1313
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
1414
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
1515
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');

examples/create-react-app-ejected/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"workbox-webpack-plugin": "^6.4.1"
5959
},
6060
"devDependencies": {
61-
"@mockingjay-io/webpack-react-component-name": "../../"
61+
"react-display-name-plugin": "../../"
6262
},
6363
"scripts": {
6464
"start": "node scripts/start.js",

examples/nextjs12/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const WebpackReactComponentNamePlugin = require("@mockingjay-io/webpack-react-component-name");
1+
const WebpackReactComponentNamePlugin = require("react-display-name-plugin/webpack");
22

33
module.exports = {
44
reactStrictMode: true,

examples/nextjs12/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react-dom": "17.0.2"
1616
},
1717
"devDependencies": {
18-
"@mockingjay-io/webpack-react-component-name": "../../",
18+
"react-display-name-plugin": "../../",
1919
"eslint": "8.6.0",
2020
"eslint-config-next": "12.0.7",
2121
"webpack": "^5.102.1"

examples/nextjs13-app-router/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const WebpackReactComponentNamePlugin = require('@mockingjay-io/webpack-react-component-name');
1+
const WebpackReactComponentNamePlugin = require('react-display-name-plugin/webpack');
22

33
/** @type {import('next').NextConfig} */
44
const nextConfig = {

examples/nextjs13-app-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"react-dom": "^18"
1515
},
1616
"devDependencies": {
17-
"@mockingjay-io/webpack-react-component-name": "../../",
17+
"react-display-name-plugin": "../../",
1818
"@types/node": "^20.19.24",
1919
"@types/react": "^18.3.26",
2020
"@types/react-dom": "^18.3.7",

examples/nextjs13-pages-router/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const WebpackReactComponentNamePlugin = require('@mockingjay-io/webpack-react-component-name');
1+
const WebpackReactComponentNamePlugin = require('react-display-name-plugin/webpack');
22

33
/** @type {import('next').NextConfig} */
44
const nextConfig = {

0 commit comments

Comments
 (0)