This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
forked from TypeFox/npm-dependency-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82a714f
commit 689eb60
Showing
5 changed files
with
61 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2018 TypeFox | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { injectable } from "inversify"; | ||
import URI from "@theia/core/lib/common/uri"; | ||
import { Path } from "@theia/core/lib/common"; | ||
import { FileSystem } from "@theia/filesystem/lib/common"; | ||
import { DependencyGraphNodeSchema } from "../graph/graph-model"; | ||
import { VersionMetadata } from "../graph/registry-metadata"; | ||
import { NpmDependencyGraphGenerator } from "../graph/npm-dependencies"; | ||
|
||
@injectable() | ||
export class NodeModulesGraphGenerator extends NpmDependencyGraphGenerator { | ||
|
||
fileSystem?: FileSystem; | ||
startUri?: URI; | ||
|
||
protected async getMetadata(node: DependencyGraphNodeSchema): Promise<VersionMetadata> { | ||
const startUri = this.startUri; | ||
if (this.fileSystem && startUri) { | ||
const segs = startUri.path.toString().split(Path.separator); | ||
while (segs.length > 0 && segs[segs.length - 1] && segs[segs.length - 1] !== '..') { | ||
segs.splice(segs.length - 1, 1); | ||
const packageUri = startUri.withPath(`${segs.join('/')}/node_modules/${node.name}/package.json`); | ||
try { | ||
const { content } = await this.fileSystem.resolveContent(packageUri.toString()); | ||
return JSON.parse(content); | ||
} catch { | ||
// Try the parent directory | ||
} | ||
} | ||
} | ||
// Fall back to the remote package registry | ||
return super.getMetadata(node); | ||
} | ||
|
||
} |
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