Skip to content

Commit 1fe5b98

Browse files
authored
fix(linter): refactor pcv3 plugin, expose configFiles on context (#21677)
1 parent cea7e93 commit 1fe5b98

File tree

24 files changed

+662
-242
lines changed

24 files changed

+662
-242
lines changed

docs/generated/devkit/CreateNodes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Type alias: CreateNodes\<T\>
22

3-
Ƭ **CreateNodes**\<`T`\>: readonly [projectFilePattern: string, createNodesFunction: CreateNodesFunction\<T\>]
3+
Ƭ **CreateNodes**\<`T`\>: readonly [configFilePattern: string, createNodesFunction: CreateNodesFunction\<T\>]
44

55
A pair of file patterns and [CreateNodesFunction](../../devkit/documents/CreateNodesFunction)
66

docs/generated/devkit/CreateNodesContext.md

+9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ Context for [CreateNodesFunction](../../devkit/documents/CreateNodesFunction)
66

77
### Properties
88

9+
- [configFiles](../../devkit/documents/CreateNodesContext#configfiles): string[]
910
- [nxJsonConfiguration](../../devkit/documents/CreateNodesContext#nxjsonconfiguration): NxJsonConfiguration<string[] | "\*">
1011
- [workspaceRoot](../../devkit/documents/CreateNodesContext#workspaceroot): string
1112

1213
## Properties
1314

15+
### configFiles
16+
17+
`Readonly` **configFiles**: `string`[]
18+
19+
The subset of configuration files which match the createNodes pattern
20+
21+
---
22+
1423
### nxJsonConfiguration
1524

1625
`Readonly` **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\>

packages/cypress/src/plugins/plugin.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('@nx/cypress/plugin', () => {
3434
},
3535
},
3636
workspaceRoot: tempFs.tempDir,
37+
configFiles: [],
3738
};
3839
});
3940

packages/devkit/src/utils/replace-project-configuration-with-plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export async function replaceProjectConfigurationsWithPlugin<T = unknown>(
4848
const nodes = await createNodesFunction(configFile, pluginOptions, {
4949
workspaceRoot: tree.root,
5050
nxJsonConfiguration: readNxJson(tree),
51+
configFiles,
5152
});
5253
const node = nodes.projects[Object.keys(nodes.projects)[0]];
5354

packages/devkit/src/utils/update-package-scripts.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ export async function updatePackageScripts(
2525
const nxJson = readNxJson(tree);
2626

2727
const [pattern, createNodes] = createNodesTuple;
28-
const files = glob(tree, [pattern]);
28+
const matchingFiles = glob(tree, [pattern]);
2929

30-
for (const file of files) {
30+
for (const file of matchingFiles) {
3131
const projectRoot = getProjectRootFromConfigFile(file);
32-
await processProject(tree, projectRoot, file, createNodes, nxJson);
32+
await processProject(
33+
tree,
34+
projectRoot,
35+
file,
36+
createNodes,
37+
nxJson,
38+
matchingFiles
39+
);
3340
}
3441
}
3542

@@ -38,7 +45,8 @@ async function processProject(
3845
projectRoot: string,
3946
projectConfigurationFile: string,
4047
createNodesFunction: CreateNodesFunction,
41-
nxJsonConfiguration: NxJsonConfiguration
48+
nxJsonConfiguration: NxJsonConfiguration,
49+
configFiles: string[]
4250
) {
4351
const packageJsonPath = `${projectRoot}/package.json`;
4452
if (!tree.exists(packageJsonPath)) {
@@ -52,7 +60,11 @@ async function processProject(
5260
const result = await createNodesFunction(
5361
projectConfigurationFile,
5462
{},
55-
{ nxJsonConfiguration, workspaceRoot }
63+
{
64+
nxJsonConfiguration,
65+
workspaceRoot,
66+
configFiles,
67+
}
5668
);
5769

5870
const targetCommands = getInferredTargetCommands(result);

0 commit comments

Comments
 (0)