Skip to content

Commit

Permalink
fix: resolve schema paths rather than joining (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Nov 19, 2021
1 parent fcd2a30 commit 3ed7119
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
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

0 comments on commit 3ed7119

Please sign in to comment.