@@ -8,6 +8,7 @@ import TerserPlugin from 'terser-webpack-plugin';
8
8
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' ;
9
9
import { createRequire } from 'node:module' ;
10
10
import chalk from 'chalk' ;
11
+ import * as module from 'module' ;
11
12
import { byteSizeFormatter } from './formatUtils.js' ;
12
13
13
14
/**
@@ -27,10 +28,22 @@ const require = createRequire(import.meta.url);
27
28
*/
28
29
async function getPeerDependencies ( packageName ) {
29
30
try {
30
- // Try to resolve packageName/package.json
31
- const packageJsonPath = require . resolve ( `${ packageName } /package.json` , {
32
- paths : [ rootDir ] ,
33
- } ) ;
31
+ /** @type {string | undefined } */
32
+ let packageJsonPath ;
33
+
34
+ if ( module . findPackageJSON ) {
35
+ // findPackageJSON was added in: v23.2.0, v22.14.0
36
+ packageJsonPath = module . findPackageJSON ( packageName , `${ rootDir } /_.js` ) ;
37
+ } else {
38
+ // Try to resolve packageName/package.json
39
+ packageJsonPath = require . resolve ( `${ packageName } /package.json` , {
40
+ paths : [ rootDir ] ,
41
+ } ) ;
42
+ }
43
+
44
+ if ( ! packageJsonPath ) {
45
+ return null ;
46
+ }
34
47
35
48
// Read and parse the package.json
36
49
const packageJsonContent = await fs . readFile ( packageJsonPath , 'utf8' ) ;
@@ -160,6 +173,16 @@ async function createWebpackConfig(entry, args) {
160
173
} ,
161
174
module : {
162
175
rules : [
176
+ {
177
+ test : / \. [ j t ] s x ? $ / ,
178
+ exclude : / n o d e _ m o d u l e s / ,
179
+ use : {
180
+ loader : 'babel-loader' ,
181
+ options : {
182
+ presets : [ '@babel/preset-env' , '@babel/preset-react' , '@babel/preset-typescript' ] ,
183
+ } ,
184
+ } ,
185
+ } ,
163
186
{
164
187
test : / \. c s s $ / ,
165
188
use : [ require . resolve ( 'css-loader' ) ] ,
0 commit comments