-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): process hangs when plugin exits unexpectedly
- Loading branch information
1 parent
f43d3e9
commit 1a06066
Showing
7 changed files
with
132 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { dirname } from 'node:path'; | ||
|
||
import { toProjectName } from '../../config/workspaces'; | ||
import { combineGlobPatterns } from '../../utils/globs'; | ||
|
||
import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated'; | ||
import type { NormalizedPlugin, RemotePlugin } from './internal-api'; | ||
import type { NxPlugin, NxPluginV2 } from './public-api'; | ||
|
||
export function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2 { | ||
return 'createNodes' in plugin || 'createDependencies' in plugin; | ||
} | ||
|
||
export function isNxPluginV1( | ||
plugin: NxPlugin | RemotePlugin | ||
): plugin is NxPluginV1 { | ||
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin; | ||
} | ||
|
||
export function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin { | ||
if (isNxPluginV2(plugin)) { | ||
return plugin; | ||
} | ||
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) { | ||
return { | ||
...plugin, | ||
createNodes: [ | ||
`*/**/${combineGlobPatterns(plugin.projectFilePatterns)}`, | ||
(configFilePath) => { | ||
const root = dirname(configFilePath); | ||
return { | ||
projects: { | ||
[root]: { | ||
name: toProjectName(configFilePath), | ||
targets: plugin.registerProjectTargets?.(configFilePath), | ||
}, | ||
}, | ||
}; | ||
}, | ||
], | ||
}; | ||
} | ||
return plugin; | ||
} | ||
|
||
export class CreateNodesError extends Error { | ||
constructor(msg, cause: Error | unknown) { | ||
const message = `${msg} ${ | ||
!cause | ||
? '' | ||
: cause instanceof Error | ||
? `\n\n\t Inner Error: ${cause.stack}` | ||
: cause | ||
}`; | ||
// These errors are thrown during a JS callback which is invoked via rust. | ||
// The errors messaging gets lost in the rust -> js -> rust transition, but | ||
// logging the error here will ensure that it is visible in the console. | ||
console.error(message); | ||
super(message, { cause }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters