-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: project graph integration (#1305)
- Loading branch information
Showing
33 changed files
with
944 additions
and
79 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
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
37 changes: 37 additions & 0 deletions
37
libs/vscode/nx-workspace/src/lib/find-project-with-path.ts
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,37 @@ | ||
import { WorkspaceConfigurationStore } from '@nx-console/vscode/configuration'; | ||
import { ProjectConfiguration } from '@nrwl/devkit'; | ||
import { isAbsolute, join, relative } from 'path'; | ||
import { nxWorkspace } from './nx-workspace'; | ||
|
||
export async function findProjectWithPath( | ||
selectedPath: string | undefined | ||
): Promise<ProjectConfiguration | null> { | ||
if (!selectedPath) { | ||
return null; | ||
} | ||
const workspacePath = WorkspaceConfigurationStore.instance.get( | ||
'nxWorkspacePath', | ||
'' | ||
); | ||
const { workspace } = await nxWorkspace(); | ||
const projectEntries = Object.entries(workspace.projects); | ||
const entry = projectEntries.find(([, def]) => { | ||
const fullProjectPath = join( | ||
workspacePath, | ||
// If root is empty, that means we're in an angular project with the old ng workspace setup. Otherwise use the sourceRoot | ||
def.root || def.sourceRoot || '' | ||
); | ||
if (fullProjectPath === selectedPath) { | ||
return true; | ||
} | ||
|
||
const relativePath = relative(fullProjectPath, selectedPath); | ||
return ( | ||
relativePath && | ||
!relativePath.startsWith('..') && | ||
!isAbsolute(relativePath) | ||
); | ||
}); | ||
|
||
return entry ? { name: entry[0], ...entry[1] } : null; | ||
} |
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,18 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*", "**/*.html", "**/*.typegen.ts"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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,11 @@ | ||
# vscode-project-graph | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test vscode-project-graph` to execute the unit tests via [Jest](https://jestjs.io). | ||
|
||
## Running lint | ||
|
||
Run `nx lint vscode-project-graph` to execute the lint via [ESLint](https://eslint.org/). |
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,16 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'vscode-project-graph', | ||
preset: '../../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../../coverage/libs/vscode/project-graph', | ||
}; |
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,23 @@ | ||
{ | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/vscode/project-graph/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["libs/vscode/project-graph/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/libs/vscode/project-graph"], | ||
"options": { | ||
"jestConfig": "libs/vscode/project-graph/jest.config.ts", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
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 @@ | ||
export * from './lib/project-graph'; |
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 { detectPackageManager, getPackageManagerCommand } from '@nrwl/devkit'; | ||
import { getOutputChannel } from '@nx-console/server'; | ||
import { WorkspaceConfigurationStore } from '@nx-console/vscode/configuration'; | ||
import { execSync } from 'child_process'; | ||
import * as cacheDir from 'find-cache-dir'; | ||
|
||
let projectGraphCacheDir: string | undefined; | ||
|
||
export async function createProjectGraph() { | ||
return new Promise<void>((res, rej) => { | ||
if (!projectGraphCacheDir) { | ||
projectGraphCacheDir = cacheDir({ | ||
name: 'nx-console-project-graph', | ||
cwd: WorkspaceConfigurationStore.instance.get('nxWorkspacePath', ''), | ||
}); | ||
} | ||
|
||
const workspacePath = WorkspaceConfigurationStore.instance.get( | ||
'nxWorkspacePath', | ||
'' | ||
); | ||
const packageManager = detectPackageManager(workspacePath); | ||
const packageCommand = getPackageManagerCommand(packageManager); | ||
|
||
// TODO(cammisuli): determine the correct command depending on Nx Version | ||
const command = `${packageCommand.exec} nx dep-graph --file ${ | ||
getProjectGraphOutput().relativePath | ||
}`; | ||
|
||
getOutputChannel().appendLine( | ||
`Generating graph with command: \`${command}\`` | ||
); | ||
try { | ||
execSync(command, { | ||
cwd: workspacePath, | ||
}); | ||
|
||
res(); | ||
} catch (e) { | ||
getOutputChannel().appendLine( | ||
'Unable to create project graph: ' + e.toString() | ||
); | ||
rej(); | ||
} | ||
}); | ||
} | ||
|
||
export function getProjectGraphOutput() { | ||
const directory = projectGraphCacheDir ?? '.'; | ||
const fullPath = `${directory}/project-graph.html`; | ||
return { | ||
directory, | ||
relativePath: | ||
'.' + | ||
fullPath.replace( | ||
WorkspaceConfigurationStore.instance.get('nxWorkspacePath', ''), | ||
'' | ||
), | ||
fullPath, | ||
}; | ||
} |
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,4 @@ | ||
export const enum MessageType { | ||
focus = 'FOCUS', | ||
select = 'SELECT', | ||
} |
Oops, something went wrong.