-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): refactor most of js graph work into its own folder (#15365)
- Loading branch information
1 parent
16b3fa0
commit 8cf8f18
Showing
101 changed files
with
551 additions
and
462 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,88 @@ | ||
import { ProjectGraphProcessor } from '../../config/project-graph'; | ||
import { ProjectGraphBuilder } from '../../project-graph/project-graph-builder'; | ||
import { buildNpmPackageNodes } from './project-graph/build-nodes/build-npm-package-nodes'; | ||
import { buildExplicitDependencies } from './project-graph/build-dependencies/build-dependencies'; | ||
import { readNxJson } from '../../config/configuration'; | ||
import { fileExists, readJsonFile } from '../../utils/fileutils'; | ||
import { PackageJson } from '../../utils/package-json'; | ||
import { | ||
lockFileExists, | ||
lockFileHash, | ||
parseLockFile, | ||
} from './lock-file/lock-file'; | ||
import { NrwlJsPluginConfig, NxJsonConfiguration } from '../../config/nx-json'; | ||
import { dirname, join } from 'path'; | ||
import { projectGraphCacheDirectory } from '../../utils/cache-directory'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { workspaceRoot } from '../../utils/workspace-root'; | ||
import { ensureDirSync } from 'fs-extra'; | ||
import { removeNpmNodes } from 'nx/src/plugins/js/lock-file/remove-npm-nodes'; | ||
|
||
export const processProjectGraph: ProjectGraphProcessor = (graph) => { | ||
export const processProjectGraph: ProjectGraphProcessor = (graph, context) => { | ||
const builder = new ProjectGraphBuilder(graph); | ||
|
||
const lockHash = lockFileHash() ?? 'n/a'; | ||
// during the create-nx-workspace lock file might not exists yet | ||
if (lockFileExists()) { | ||
if (lockFileNeedsReprocessing(lockHash)) { | ||
removeNpmNodes(graph, builder); | ||
parseLockFile(builder); | ||
} | ||
writeLastProcessedLockfileHash(lockHash); | ||
} | ||
|
||
buildNpmPackageNodes(builder); | ||
|
||
buildExplicitDependencies(jsPluginConfig(readNxJson()), context, builder); | ||
|
||
return builder.getUpdatedProjectGraph(); | ||
}; | ||
|
||
const lockFileHashFile = join(projectGraphCacheDirectory, 'lockfile.hash'); | ||
function lockFileNeedsReprocessing(lockHash: string) { | ||
try { | ||
return readFileSync(lockFileHashFile).toString() !== lockHash; | ||
} catch { | ||
return true; | ||
} | ||
} | ||
|
||
function writeLastProcessedLockfileHash(hash: string) { | ||
ensureDirSync(dirname(lockFileHashFile)); | ||
writeFileSync(lockFileHashFile, hash); | ||
} | ||
|
||
function jsPluginConfig(nxJson: NxJsonConfiguration): NrwlJsPluginConfig { | ||
if (nxJson?.pluginsConfig?.['@nrwl/js']) { | ||
return nxJson?.pluginsConfig?.['@nrwl/js']; | ||
} | ||
|
||
if (!fileExists(join(workspaceRoot, 'package.json'))) { | ||
return { | ||
analyzePackageJson: false, | ||
analyzeSourceFiles: false, | ||
}; | ||
} | ||
|
||
const packageJson = readJsonFile<PackageJson>( | ||
join(workspaceRoot, 'package.json') | ||
); | ||
|
||
const packageJsonDeps = { | ||
...packageJson.dependencies, | ||
...packageJson.devDependencies, | ||
}; | ||
if ( | ||
packageJsonDeps['@nrwl/workspace'] || | ||
packageJsonDeps['@nrwl/js'] || | ||
packageJsonDeps['@nrwl/node'] || | ||
packageJsonDeps['@nrwl/next'] || | ||
packageJsonDeps['@nrwl/react'] || | ||
packageJsonDeps['@nrwl/angular'] || | ||
packageJsonDeps['@nrwl/web'] | ||
) { | ||
return { analyzePackageJson: true, analyzeSourceFiles: true }; | ||
} else { | ||
return { analyzePackageJson: true, analyzeSourceFiles: false }; | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.
8cf8f18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx.dev
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app