fix(js): swc exclude config may not a array (#21904)

[swc config is not
required](https://swc.rs/docs/configuration/compilation#exclude)

## Current Behavior
if not configed `"exclude"` will get a error
```text
TypeError: Cannot read properties of undefined (reading 'concat')
    at generateTmpSwcrc (/Users/hongxu/repos/smallfish/node_modules/@nrwl/js/src/utils/swc/inline.js:7:41)
```

## Expected Behavior
give a default value for swc exclude if nx must need it
This commit is contained in:
Every 2024-06-05 20:09:51 +08:00 committed by GitHub
parent e658c16a8f
commit a8c4e2479b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,11 @@ export function generateTmpSwcrc(
tmpSwcrcPath: string tmpSwcrcPath: string
) { ) {
const swcrc = readJsonFile(swcrcPath); const swcrc = readJsonFile(swcrcPath);
swcrc['exclude'] ??= [];
if (!Array.isArray(swcrc['exclude'])) {
swcrc['exclude'] = [swcrc['exclude']];
}
swcrc['exclude'] = swcrc['exclude'].concat( swcrc['exclude'] = swcrc['exclude'].concat(
Object.values(inlineProjectGraph.externals).map( Object.values(inlineProjectGraph.externals).map(