-
Notifications
You must be signed in to change notification settings - Fork 16
feat(nx-plugin): add project prefix to plugin #792
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7a8e3bb
refactor(nx-plugin): process projectPrefix option
BioPhoton 59be1ab
refactor(nx-plugin): introduce constants
BioPhoton 0c6f9ab
refactor(nx-plugin): remove dryRun
BioPhoton b2addcb
refactor(nx-plugin): add implicit dependency
BioPhoton fb2e76a
refactor: format
BioPhoton 35b0fd0
refactor: add test for report.json
BioPhoton 87a8056
test(nx-plugin-e2e): add executor tests
BioPhoton b6993ca
refactor tests
BioPhoton 7816344
fix test
BioPhoton 19624f5
fix format
BioPhoton 01dbd82
Merge branch 'main' into add-project-prefix-to-plugin
BioPhoton d27866d
fix test
BioPhoton d6631bd
Update e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts
BioPhoton f621d3e
Merge remote-tracking branch 'origin/main' into add-project-prefix-to…
BioPhoton 18e16ef
Update constants.ts
BioPhoton dd3aa3f
Update executor.target.unit.test.ts
BioPhoton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { mkdir, writeFile } from "node:fs/promises"; | ||
import { join } from "node:path"; | ||
import { mkdir, writeFile } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
|
||
export async function createNpmWorkspace(cwd: string) { | ||
await mkdir(cwd, { recursive: true }); | ||
await writeFile(join(cwd, 'package.json'), JSON.stringify({ | ||
name: 'create-npm-workspace', | ||
version: '0.0.1', | ||
scripts: { | ||
test: 'echo "Error: no test specified" && exit 1', | ||
}, | ||
keywords: [], | ||
}, null, 2)); | ||
await writeFile( | ||
join(cwd, 'package.json'), | ||
JSON.stringify( | ||
{ | ||
name: 'create-npm-workspace', | ||
version: '0.0.1', | ||
scripts: { | ||
test: 'echo "Error: no test specified" && exit 1', | ||
}, | ||
keywords: [], | ||
}, | ||
null, | ||
2, | ||
), | ||
); | ||
} |
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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,85 @@ | ||
import { Tree, updateProjectConfiguration } from '@nx/devkit'; | ||
import { rm } from 'node:fs/promises'; | ||
import { join, relative } from 'node:path'; | ||
import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; | ||
import { afterEach, expect } from 'vitest'; | ||
import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; | ||
import { | ||
generateWorkspaceAndProject, | ||
materializeTree, | ||
} from '@code-pushup/test-nx-utils'; | ||
import { removeColorCodes } from '@code-pushup/test-utils'; | ||
import { executeProcess } from '@code-pushup/utils'; | ||
|
||
function relativePathToCwd(testDir: string): string { | ||
return relative(join(process.cwd(), testDir), process.cwd()); | ||
} | ||
|
||
async function addTargetToWorkspace( | ||
tree: Tree, | ||
options: { cwd: string; project: string }, | ||
) { | ||
const { cwd, project } = options; | ||
const pathRelativeToPackage = relative(join(cwd, 'libs', project), cwd); | ||
const projectCfg = readProjectConfiguration(tree, project); | ||
updateProjectConfiguration(tree, project, { | ||
...projectCfg, | ||
targets: { | ||
...projectCfg.targets, | ||
['code-pushup']: { | ||
executor: `${join( | ||
relativePathToCwd(cwd), | ||
'dist/packages/nx-plugin', | ||
)}:autorun`, | ||
}, | ||
}, | ||
}); | ||
const { root } = projectCfg; | ||
generateCodePushupConfig(tree, root, { | ||
fileImports: `import type {CoreConfig} from "${join( | ||
relativePathToCwd(cwd), | ||
pathRelativeToPackage, | ||
'dist/packages/models', | ||
)}";`, | ||
plugins: [ | ||
{ | ||
fileImports: `import {customPlugin} from "${join( | ||
relativePathToCwd(cwd), | ||
pathRelativeToPackage, | ||
'dist/testing/test-utils', | ||
)}";`, | ||
codeStrings: 'customPlugin()', | ||
}, | ||
], | ||
}); | ||
await materializeTree(tree, cwd); | ||
} | ||
|
||
describe('executor autorun', () => { | ||
let tree: Tree; | ||
const project = 'my-lib'; | ||
const baseDir = 'tmp/nx-plugin-e2e/executor'; | ||
|
||
beforeEach(async () => { | ||
tree = await generateWorkspaceAndProject(project); | ||
}); | ||
|
||
afterEach(async () => { | ||
await rm(baseDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it('should execute autorun executor', async () => { | ||
const cwd = join(baseDir, 'execute-dynamic-executor'); | ||
await addTargetToWorkspace(tree, { cwd, project }); | ||
|
||
const { stdout, code } = await executeProcess({ | ||
command: 'npx', | ||
args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'], | ||
cwd, | ||
}); | ||
|
||
expect(code).toBe(0); | ||
const cleanStdout = removeColorCodes(stdout); | ||
expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export type DynamicTargetOptions = { | ||
// @TODO add prefix https://github.com/code-pushup/cli/issues/619 | ||
targetName?: string; | ||
bin?: string; | ||
}; |
This file contains hidden or 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 hidden or 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,2 @@ | ||
export const CODE_PUSHUP_CONFIG_REGEX = | ||
/^code-pushup\.config\.(\w*\.)*(ts|js|mjs)$/; |
This file contains hidden or 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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { TargetConfiguration } from '@nx/devkit'; | ||
import { RunCommandsOptions } from 'nx/src/executors/run-commands/run-commands.impl'; | ||
import { PACKAGE_NAME } from '../../internal/constants'; | ||
import { ProjectPrefixOptions } from '../types'; | ||
|
||
export function createExecutorTarget(options?: { | ||
bin?: string; | ||
}): TargetConfiguration<RunCommandsOptions> { | ||
const { bin = PACKAGE_NAME } = options ?? {}; | ||
projectPrefix?: string; | ||
}): TargetConfiguration<ProjectPrefixOptions> { | ||
const { bin = PACKAGE_NAME, projectPrefix } = options ?? {}; | ||
return { | ||
executor: `${bin}:autorun`, | ||
...(projectPrefix | ||
? { | ||
options: { | ||
projectPrefix, | ||
}, | ||
} | ||
: {}), | ||
}; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.