Skip to content

Commit

Permalink
fix(linter): refactor pcv3 plugin, expose configFiles on context (nrw…
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored and arekkubaczkowski committed Mar 19, 2024
1 parent 3238cc4 commit 871ca91
Show file tree
Hide file tree
Showing 24 changed files with 662 additions and 242 deletions.
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

0 comments on commit 871ca91

Please sign in to comment.