Skip to content
Open
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
2 changes: 1 addition & 1 deletion npm/bin/lsif-npm
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
#!/usr/bin/env node
require('../lib/main.js').main();
36 changes: 22 additions & 14 deletions npm/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,23 @@ function makeAbsolute(p: string, root?: string): string {
}
}

const makeIntIdGenerator = () => {
let counter = Number.MAX_SAFE_INTEGER;

return () => {
return counter--;
}
}

const uuidIdGenerator = () => {
return uuid.v4()
}

class Linker {

private _idGenerator: (() => Id) | undefined;

constructor() {
constructor(private intIdGenerator: () => Id) {
}

protected get idGenerator(): () => Id {
Expand All @@ -105,14 +117,9 @@ class Linker {
return;
}
if (typeof id === 'number') {
let counter = Number.MAX_SAFE_INTEGER;
this._idGenerator = () => {
return counter--;
};
this._idGenerator = this.intIdGenerator
} else {
this._idGenerator = () => {
return uuid.v4();
};
this._idGenerator = uuidIdGenerator
}
}

Expand Down Expand Up @@ -167,8 +174,8 @@ class ExportLinker extends Linker {

private packageInformation: PackageInformation | undefined;

constructor(private projectRoot: string, private packageJson: PackageJson) {
super();
constructor(private projectRoot: string, private packageJson: PackageJson, intIdGenerator: () => Id) {
super(intIdGenerator);
}

public handleMoniker(moniker: Moniker): void {
Expand Down Expand Up @@ -212,8 +219,8 @@ class ImportLinker extends Linker {

private packageData: Map<string, { packageInfo: PackageInformation, packageJson: PackageJson } | null>;

constructor(private projectRoot: string) {
super();
constructor(private projectRoot: string, intIdGenerator: () => Id) {
super(intIdGenerator);
this.packageData = new Map();
}

Expand Down Expand Up @@ -354,11 +361,12 @@ export function main(): void {
return;
}

const intIdGenerator = makeIntIdGenerator()
let exportLinker: ExportLinker | undefined;
if (packageJson !== undefined) {
exportLinker = new ExportLinker(projectRoot, packageJson);
exportLinker = new ExportLinker(projectRoot, packageJson, intIdGenerator);
}
const importLinker: ImportLinker = new ImportLinker(projectRoot);
const importLinker: ImportLinker = new ImportLinker(projectRoot, intIdGenerator);
let input: NodeJS.ReadStream | fs.ReadStream = process.stdin;
if (options.in !== undefined && fs.existsSync(options.in)) {
input = fs.createReadStream(options.in, { encoding: 'utf8'});
Expand Down