Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): refactor pcv3 plugin, expose configFiles on context #21677

Merged
merged 9 commits into from Mar 15, 2024
2 changes: 1 addition & 1 deletion docs/generated/devkit/CreateNodes.md
@@ -1,6 +1,6 @@
# Type alias: CreateNodes\<T\>

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

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

Expand Down
9 changes: 9 additions & 0 deletions docs/generated/devkit/CreateNodesContext.md
Expand Up @@ -6,11 +6,20 @@ Context for [CreateNodesFunction](../../devkit/documents/CreateNodesFunction)

### Properties

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

## Properties

### configFiles

• `Readonly` **configFiles**: `string`[]

The subset of configuration files which match the createNodes pattern

---

### nxJsonConfiguration

• `Readonly` **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\>
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/src/plugins/plugin.spec.ts
Expand Up @@ -34,6 +34,7 @@ describe('@nx/cypress/plugin', () => {
},
},
workspaceRoot: tempFs.tempDir,
configFiles: [],
};
});

Expand Down
Expand Up @@ -48,6 +48,7 @@ export async function replaceProjectConfigurationsWithPlugin<T = unknown>(
const nodes = await createNodesFunction(configFile, pluginOptions, {
workspaceRoot: tree.root,
nxJsonConfiguration: readNxJson(tree),
configFiles,
});
const node = nodes.projects[Object.keys(nodes.projects)[0]];

Expand Down
22 changes: 17 additions & 5 deletions packages/devkit/src/utils/update-package-scripts.ts
Expand Up @@ -25,11 +25,18 @@ export async function updatePackageScripts(
const nxJson = readNxJson(tree);

const [pattern, createNodes] = createNodesTuple;
const files = glob(tree, [pattern]);
const matchingFiles = glob(tree, [pattern]);

for (const file of files) {
for (const file of matchingFiles) {
const projectRoot = getProjectRootFromConfigFile(file);
await processProject(tree, projectRoot, file, createNodes, nxJson);
await processProject(
tree,
projectRoot,
file,
createNodes,
nxJson,
matchingFiles
);
}
}

Expand All @@ -38,7 +45,8 @@ async function processProject(
projectRoot: string,
projectConfigurationFile: string,
createNodesFunction: CreateNodesFunction,
nxJsonConfiguration: NxJsonConfiguration
nxJsonConfiguration: NxJsonConfiguration,
configFiles: string[]
) {
const packageJsonPath = `${projectRoot}/package.json`;
if (!tree.exists(packageJsonPath)) {
Expand All @@ -52,7 +60,11 @@ async function processProject(
const result = await createNodesFunction(
projectConfigurationFile,
{},
{ nxJsonConfiguration, workspaceRoot }
{
nxJsonConfiguration,
workspaceRoot,
configFiles,
}
);

const targetCommands = getInferredTargetCommands(result);
Expand Down