Add ProjectManager.getVCSClient
MODIFY
packages/@romejs/core/master/project/ProjectManager.ts
packages/@romejs/core/master/project/ProjectManager.ts
@@ -49,6 +49,7 @@ import {
import {createDirectory, readFileText} from '@romejs/fs';
import {Consumer} from '@romejs/consume';
import {consumeJSON} from '@romejs/codec-json';
+import {VCSClient, getVCSClient} from '@romejs/vcs';
function cleanUidParts(parts: Array<string>): string {
let uid = '';
@@ -477,13 +478,13 @@ export default class ProjectManager {
findProjectConfigConsumer(
def: ProjectDefinition,
- test: (consumer: Consumer) => undefined | Consumer,
+ test: (consumer: Consumer) => undefined | false | Consumer,
): ProjectConfigSource {
const meta = assertHardMeta(def.meta);
for (const consumer of meta.consumersChain) {
const value = test(consumer);
- if (value !== undefined && value.exists()) {
+ if (value !== undefined && value !== false && value.exists()) {
return {value, consumer: meta.consumer};
}
}
@@ -491,6 +492,33 @@ export default class ProjectManager {
return {value: undefined, consumer: meta.consumer};
}
+ async getVCSClient(project: ProjectDefinition): Promise<VCSClient> {
+ const client = await getVCSClient(project.config.vcs.root);
+
+ if (client === undefined) {
+ const {
+ value: rootConfigConsumer,
+ consumer,
+ } = this.findProjectConfigConsumer(project, (consumer) =>
+ consumer.has('vsc') && consumer.get('vsc').get('root')
+ );
+
+ const rootConfigLocation: undefined | DiagnosticLocation =
+ rootConfigConsumer === undefined
+ ? undefined : rootConfigConsumer.getDiagnosticLocation();
+
+ const location: DiagnosticLocation = rootConfigLocation === undefined
+ ? consumer.getDiagnosticLocation() : rootConfigLocation;
+
+ throw createSingleDiagnosticError({
+ description: descriptions.PROJECT_MANAGER.NO_VCS(rootConfigLocation),
+ location,
+ });
+ } else {
+ return client;
+ }
+ }
+
async addProject(
projectFolder: AbsoluteFilePath,
configPath: AbsoluteFilePath,

MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -70,6 +70,7 @@ export type DiagnosticCategory =
| 'projectManager/nameCollision'
| 'projectManager/missing'
| 'projectManager/incorrectConfigFilename'
+ | 'projectManager/vscMissing'
| 'resolver/notFound'
| 'resolver/unsupported'
| 'resolver/fetchFailed'

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -440,6 +440,33 @@ export const descriptions = createMessages({
},
PROJECT_MANAGER: {
+ NO_VCS: (rootConfigLocation: undefined | DiagnosticLocation) =>
+ ({
+ category: 'projectManager/vscMissing',
+ message: 'Can\'t find any version control for this project',
+ advice: rootConfigLocation === undefined ? [
+ {
+ type: 'log',
+ category: 'info',
+ message: 'Version control root was set to the project root as it was not configured. To configure a different folder run',
+ },
+ {
+ type: 'command',
+ command: 'rome config set-directory vcs.root DIRECTORY_HERE',
+ },
+ ] : [
+ {
+ type: 'log',
+ category: 'info',
+ message: 'Version control root was set here',
+ },
+ {
+ type: 'frame',
+ location: rootConfigLocation,
+ },
+ ],
+ }),
+
DUPLICATE_PACKAGE: (packageName: string, existing: string) =>
({
category: 'projectManager/nameCollision',

Add ProjectManager.getVCSClient