Skip to content
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

fix: resolve schema paths rather than joining #1175

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libs/server/src/lib/utils/get-generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ async function readWorkspaceGeneratorsCollection(
collectionName,
collectionPath,
collectionDir,
{},
{
path: collectionPath,
json: {},
},
collection.json
);
} else {
Expand Down
50 changes: 30 additions & 20 deletions libs/server/src/lib/utils/read-collections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { platform } from 'os';
import { dirname, join } from 'path';
import { CollectionInfo, Generator, GeneratorType } from '@nx-console/schema';
import { platform } from 'os';
import { dirname, join, resolve } from 'path';
import {
clearJsonCache,
listOfUnnestedNpmPackages,
Expand Down Expand Up @@ -81,8 +81,8 @@ export async function readCollections(
collectionName,
packageJson.path,
nodeModulesDir,
executorCollections.json,
generatorCollections.json
executorCollections,
generatorCollections
);
} catch (e) {
return null;
Expand All @@ -93,8 +93,8 @@ export async function getCollectionInfo(
collectionName: string,
path: string,
collectionDir: string,
executorCollectionJson: any,
generatorCollectionJson: any
executorCollection: { path: string; json: any },
generatorCollection: { path: string; json: any }
): Promise<CollectionInfo[]> {
const baseDir = dirname(path);

Expand All @@ -103,13 +103,13 @@ export async function getCollectionInfo(
const buildCollectionInfo = (
name: string,
value: any,
type: 'executor' | 'generator'
type: 'executor' | 'generator',
schemaPath: string
): CollectionInfo => {
let path = '';
let path = resolve(baseDir, dirname(schemaPath), value.schema);

if (platform() === 'win32') {
path = `file:///${join(baseDir, value.schema).replace(/\\/g, '/')}`;
} else {
path = join(baseDir, value.schema);
path = `file:///${path.replace(/\\/g, '/')}`;
}

return {
Expand All @@ -120,31 +120,41 @@ export async function getCollectionInfo(
};

const executors = {
...executorCollectionJson.executors,
...executorCollectionJson.builders,
...executorCollection.json.executors,
...executorCollection.json.builders,
};
for (const [key, schema] of Object.entries<any>(executors)) {
if (!canUse(key, schema)) {
continue;
}
const collectionInfo = buildCollectionInfo(key, schema, 'executor');
const collectionInfo = buildCollectionInfo(
key,
schema,
'executor',
executorCollection.path
);
if (collectionMap.has(collectionInfo.name)) {
continue;
}
collectionMap.set(collectionInfo.name, collectionInfo);
}

const generators = {
...generatorCollectionJson.generators,
...generatorCollectionJson.schematics,
...generatorCollection.json.generators,
...generatorCollection.json.schematics,
};
for (const [key, schema] of Object.entries<any>(generators)) {
if (!canUse(key, schema)) {
continue;
}

try {
const collectionInfo = buildCollectionInfo(key, schema, 'generator');
const collectionInfo = buildCollectionInfo(
key,
schema,
'generator',
generatorCollection.path
);
collectionInfo.data = readCollectionGenerator(
collectionName,
key,
Expand All @@ -160,10 +170,10 @@ export async function getCollectionInfo(
}

if (
generatorCollectionJson.extends &&
Array.isArray(generatorCollectionJson.extends)
generatorCollection.json.extends &&
Array.isArray(generatorCollection.json.extends)
) {
const extendedSchema = generatorCollectionJson.extends as string[];
const extendedSchema = generatorCollection.json.extends as string[];
const extendedCollections = (
await Promise.all(
extendedSchema
Expand Down