Add support for scoped npm packages (#612)

This commit is contained in:
Tei1988 2020-06-04 02:40:39 +09:00 committed by GitHub
parent a1da8425e4
commit e19cd9c118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 17 deletions

View file

@ -97,24 +97,28 @@ class LoadNodesAndCredentialsClass {
* @memberof LoadNodesAndCredentialsClass
*/
async getN8nNodePackages(): Promise<string[]> {
const packages: string[] = [];
for (const file of await fsReaddirAsync(this.nodeModulesPath)) {
if (file.indexOf('n8n-nodes-') !== 0) {
continue;
}
// Check if it is really a folder
if (!(await fsStatAsync(path.join(this.nodeModulesPath, file))).isDirectory()) {
continue;
}
packages.push(file);
const getN8nNodePackagesRecursive = async (relativePath: string): Promise<string[]> => {
const results: string[] = [];
const nodeModulesPath = `${this.nodeModulesPath}/${relativePath}`;
for (const file of await fsReaddirAsync(nodeModulesPath)) {
const isN8nNodesPackage = file.indexOf('n8n-nodes-') === 0;
const isNpmScopedPackage = file.indexOf('@') === 0;
if (!isN8nNodesPackage && !isNpmScopedPackage) {
continue;
}
if (!(await fsStatAsync(nodeModulesPath)).isDirectory()) {
continue;
}
if (isN8nNodesPackage) { results.push(`${relativePath}${file}`); }
if (isNpmScopedPackage) {
results.push(...await getN8nNodePackagesRecursive(`${relativePath}${file}/`));
}
}
return results;
}
return packages;
return getN8nNodePackagesRecursive('');
}
/**
* Loads credentials from a file
*

View file

@ -597,8 +597,8 @@ class App {
// Returns the node icon
this.app.get('/rest/node-icon/:nodeType', async (req: express.Request, res: express.Response): Promise<void> => {
const nodeTypeName = req.params.nodeType;
this.app.get(['/rest/node-icon/:nodeType', '/rest/node-icon/:scope/:nodeType'], async (req: express.Request, res: express.Response): Promise<void> => {
const nodeTypeName = `${req.params.scope ? `${req.params.scope}/` : ''}${req.params.nodeType}`;
const nodeTypes = NodeTypes();
const nodeType = nodeTypes.getByName(nodeTypeName);