Comparing version 0.5.6 to 0.6.0-dev.1
@@ -11,8 +11,3 @@ import * as yargs from 'yargs'; | ||
} | ||
export interface GroupOptions { | ||
uri?: string; | ||
conflictResolution?: 'takeDump' | 'takeDB'; | ||
name?: string; | ||
rootUri?: string; | ||
description?: string; | ||
export interface SourceOptions { | ||
repository?: { | ||
@@ -23,2 +18,10 @@ type: string; | ||
} | ||
export interface ConfigOptions { | ||
__brand: 'inlineConfig'; | ||
configFilePath: string | undefined; | ||
kind?: 'ts' | 'js'; | ||
} | ||
export declare namespace ConfigOptions { | ||
function is(value: any): value is ConfigOptions; | ||
} | ||
export declare type Options = { | ||
@@ -28,3 +31,3 @@ help: boolean; | ||
config: string | undefined; | ||
p: string | undefined; | ||
p: string | ConfigOptions | undefined; | ||
id: 'number' | 'uuid'; | ||
@@ -38,3 +41,4 @@ outputFormat: 'json' | 'line' | 'vis' | 'graphSON'; | ||
moniker: 'strict' | 'lenient'; | ||
group: string | GroupOptions | undefined; | ||
workspaceRoot: string | undefined; | ||
source: string | SourceOptions | undefined; | ||
projectName: string | undefined; | ||
@@ -44,2 +48,8 @@ package: string | undefined; | ||
log: string | boolean; | ||
files: Map<string, string> | undefined; | ||
outputWriter: { | ||
write(...data: string[]): void; | ||
writeEOL(): void; | ||
writeln(...data: string[]): void; | ||
} | undefined; | ||
}; | ||
@@ -46,0 +56,0 @@ export declare namespace Options { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.builder = exports.Options = exports.PublishedPackageOptions = exports.describe = exports.command = void 0; | ||
exports.builder = exports.Options = exports.ConfigOptions = exports.PublishedPackageOptions = exports.describe = exports.command = void 0; | ||
/* -------------------------------------------------------------------------------------------- | ||
@@ -20,2 +20,10 @@ * Copyright (c) Microsoft Corporation. All rights reserved. | ||
})(PublishedPackageOptions = exports.PublishedPackageOptions || (exports.PublishedPackageOptions = {})); | ||
var ConfigOptions; | ||
(function (ConfigOptions) { | ||
function is(value) { | ||
const candidate = value; | ||
return candidate && candidate.__brand === 'inlineConfig'; | ||
} | ||
ConfigOptions.is = is; | ||
})(ConfigOptions = exports.ConfigOptions || (exports.ConfigOptions = {})); | ||
var Options; | ||
@@ -36,11 +44,17 @@ (function (Options) { | ||
moniker: 'lenient', | ||
group: undefined, | ||
workspaceRoot: undefined, | ||
source: undefined, | ||
projectName: undefined, | ||
package: undefined, | ||
publishedPackages: undefined, | ||
log: '' | ||
log: '', | ||
files: undefined, | ||
outputWriter: undefined | ||
}; | ||
function sanitize(options) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const result = Object.assign({}, options); | ||
if (options.p !== undefined && typeof options.p !== 'string') { | ||
result.p = Object.assign({}, options.p, { __brand: 'inlineConfig', configFilePath: getConfigFilePath(options) }); | ||
} | ||
if (!Array.isArray(result.publishedPackages)) { | ||
@@ -59,28 +73,20 @@ result.publishedPackages = undefined; | ||
} | ||
if (result.group === undefined || typeof result.group === 'string') { | ||
return result; | ||
if (result.source !== undefined) { | ||
if (typeof result.source !== 'string') { | ||
const source = {}; | ||
if (typeof ((_a = result.source.repository) === null || _a === void 0 ? void 0 : _a.url) === 'string' && (typeof ((_b = result.source.repository) === null || _b === void 0 ? void 0 : _b.type) === 'string' || ((_c = result.source.repository) === null || _c === void 0 ? void 0 : _c.type) === undefined)) { | ||
source.repository = { url: result.source.repository.url, type: result.source.repository.type }; | ||
} | ||
result.source = Object.keys(source).length > 0 ? source : undefined; | ||
} | ||
} | ||
const group = {}; | ||
if (typeof result.group.name === 'string') { | ||
group.name = result.group.name; | ||
} | ||
if (typeof result.group.uri === 'string') { | ||
group.uri = result.group.uri; | ||
} | ||
if (result.group.conflictResolution === 'takeDB' || result.group.conflictResolution === 'takeDump') { | ||
group.conflictResolution = result.group.conflictResolution; | ||
} | ||
if (typeof result.group.rootUri === 'string') { | ||
group.rootUri = result.group.rootUri; | ||
} | ||
if (typeof result.group.description === 'string') { | ||
group.description = result.group.description; | ||
} | ||
if (typeof ((_a = result.group.repository) === null || _a === void 0 ? void 0 : _a.type) === 'string' && typeof ((_b = result.group.repository) === null || _b === void 0 ? void 0 : _b.url) === 'string') { | ||
group.repository = { url: result.group.repository.url, type: result.group.repository.type }; | ||
} | ||
Object.keys(group).length > 0 ? result.group = group : result.group = undefined; | ||
return result; | ||
} | ||
Options.sanitize = sanitize; | ||
function getConfigFilePath(options) { | ||
if (options.config === undefined) { | ||
return undefined; | ||
} | ||
return path.isAbsolute(options.config) ? options.config : path.join(process.cwd(), options.config); | ||
} | ||
function resolvePathToConfig(options) { | ||
@@ -95,4 +101,4 @@ if (options.config === undefined) { | ||
const result = Object.assign({}, options); | ||
if (typeof options.group === 'string' && options.group !== 'stdin') { | ||
result.group = makeAbsolute(options.group); | ||
if (typeof options.workspaceRoot === 'string') { | ||
result.workspaceRoot = makeAbsolute(options.workspaceRoot); | ||
} | ||
@@ -167,4 +173,4 @@ if (typeof options.package === 'string') { | ||
}). | ||
option('group', { | ||
description: 'Specifies the group config file, the group folder or stdin to read the group information from stdin.', | ||
option('workspaceRoot', { | ||
description: 'Specifies the root of the workspace. If omitted defaults to the current working directory', | ||
string: true | ||
@@ -171,0 +177,0 @@ }). |
@@ -1,2 +0,2 @@ | ||
import { lsp, Id, Vertex, E, Edge, Group, Project, Document, HoverResult, ReferenceResult, contains, textDocument_definition, textDocument_references, textDocument_diagnostic, textDocument_hover, item, DiagnosticResult, Range, DeclarationRange, ReferenceRange, DocumentSymbolResult, textDocument_documentSymbol, ReferenceTag, DeclarationTag, UnknownTag, DefinitionResult, ImplementationResult, textDocument_implementation, textDocument_typeDefinition, TypeDefinitionResult, FoldingRangeResult, textDocument_foldingRange, RangeBasedDocumentSymbol, DefinitionTag, DefinitionRange, ResultSet, MetaData, Location, EdgeLabels, Moniker, PackageInformation, moniker, packageInformation, MonikerKind, ItemEdgeProperties, Event, EventKind, EventScope, DeclarationResult, textDocument_declaration, next, belongsTo, UniquenessLevel, Uri, attach } from 'lsif-protocol'; | ||
import { lsp, Id, Vertex, E, Edge, Project, Document, HoverResult, ReferenceResult, contains, textDocument_definition, textDocument_references, textDocument_diagnostic, textDocument_hover, item, DiagnosticResult, Range, DeclarationRange, ReferenceRange, DocumentSymbolResult, textDocument_documentSymbol, ReferenceTag, DeclarationTag, UnknownTag, DefinitionResult, ImplementationResult, textDocument_implementation, textDocument_typeDefinition, TypeDefinitionResult, FoldingRangeResult, textDocument_foldingRange, RangeBasedDocumentSymbol, DefinitionTag, DefinitionRange, ResultSet, MetaData, Location, EdgeLabels, Moniker, PackageInformation, moniker, packageInformation, MonikerKind, ItemEdgeProperties, Event, EventKind, EventScope, DeclarationResult, textDocument_declaration, next, UniquenessLevel, Uri, attach, Source, Capabilities } from 'lsif-protocol'; | ||
export interface BuilderOptions { | ||
@@ -16,7 +16,7 @@ idGenerator?: () => Id; | ||
metaData(version: string): MetaData; | ||
event(scope: EventScope.group, kind: EventKind, data: Group): Event; | ||
event(scope: EventScope.project, kind: EventKind, data: Project): Event; | ||
event(scope: EventScope.document, kind: EventKind, data: Document): Event; | ||
event(scope: EventScope.monikerAttach, kind: EventKind): Event; | ||
group(uri: Uri, name: string, rootUri: Uri): Group; | ||
source(workspaceRoot: Uri): Source; | ||
capabilities(defaultValue?: boolean): Capabilities; | ||
project(name: string, contents?: string): Project; | ||
@@ -51,3 +51,2 @@ document(path: string, contents?: string): Document; | ||
contains(from: Document, to: Range[]): contains; | ||
belongsTo(from: Project, to: Group): belongsTo; | ||
next(from: Range, to: ResultSet): next; | ||
@@ -54,0 +53,0 @@ next(from: ResultSet, to: ResultSet): next; |
@@ -42,14 +42,26 @@ /* -------------------------------------------------------------------------------------------- | ||
} | ||
group(uri, name, rootUri) { | ||
source(workspaceRoot) { | ||
const result = { | ||
id: this.nextId(), | ||
type: lsif_protocol_1.ElementTypes.vertex, | ||
label: lsif_protocol_1.VertexLabels.group, | ||
uri, | ||
conflictResolution: 'takeDB', | ||
name, | ||
rootUri | ||
label: lsif_protocol_1.VertexLabels.source, | ||
workspaceRoot | ||
}; | ||
return result; | ||
} | ||
capabilities(defaultValue = false) { | ||
return { | ||
id: this.nextId(), | ||
type: lsif_protocol_1.ElementTypes.vertex, | ||
label: lsif_protocol_1.VertexLabels.capabilities, | ||
hoverProvider: defaultValue, | ||
declarationProvider: defaultValue, | ||
definitionProvider: defaultValue, | ||
typeDefinitionProvider: defaultValue, | ||
referencesProvider: defaultValue, | ||
documentSymbolProvider: defaultValue, | ||
foldingRangeProvider: defaultValue, | ||
diagnosticProvider: defaultValue | ||
}; | ||
} | ||
project(name, contents) { | ||
@@ -247,11 +259,2 @@ const result = { | ||
} | ||
belongsTo(from, to) { | ||
return { | ||
id: this.nextId(), | ||
type: lsif_protocol_1.ElementTypes.edge, | ||
label: lsif_protocol_1.EdgeLabels.belongsTo, | ||
outV: from.id, | ||
inV: to.id | ||
}; | ||
} | ||
next(from, to) { | ||
@@ -258,0 +261,0 @@ return { |
@@ -157,2 +157,5 @@ "use strict"; | ||
label: element.label, | ||
// properties: { | ||
// result: [ { id: idGenerator(), value: JSON.stringify(element.result, undefined, 0) }] | ||
// } | ||
}; | ||
@@ -159,0 +162,0 @@ vertices.set(gs.id, gs); |
import * as ts from 'typescript'; | ||
import * as tss from './typescripts'; | ||
import { lsp, Vertex, Edge, Project, Group, Document, ReferenceResult, RangeBasedDocumentSymbol, ResultSet, DefinitionRange, DefinitionResult, MonikerKind, ItemEdgeProperties, Range, TypeDefinitionResult, Moniker, UniquenessLevel } from 'lsif-protocol'; | ||
import { lsp, Vertex, Edge, Project, Document, ReferenceResult, RangeBasedDocumentSymbol, ResultSet, DefinitionRange, DefinitionResult, MonikerKind, ItemEdgeProperties, Range, TypeDefinitionResult, Moniker, UniquenessLevel } from 'lsif-protocol'; | ||
import { VertexBuilder, EdgeBuilder, EmitterContext } from './common/graph'; | ||
@@ -27,7 +27,6 @@ import { ExportMonikers } from './npm/exportMonikers'; | ||
declare class ProjectData extends LSIFData<EmitterContext> { | ||
readonly group: Group | undefined; | ||
readonly project: Project; | ||
private documents; | ||
private diagnostics; | ||
constructor(emitter: EmitterContext, group: Group | undefined, project: Project); | ||
constructor(emitter: EmitterContext, project: Project); | ||
begin(): void; | ||
@@ -48,2 +47,3 @@ addDocument(document: Document): void; | ||
private ranges; | ||
private rangesEmitted; | ||
private diagnostics; | ||
@@ -61,2 +61,3 @@ private foldingRanges; | ||
addDocumentSymbols(documentSymbols: RangeBasedDocumentSymbol[]): void; | ||
flushRanges(): void; | ||
end(): void; | ||
@@ -185,2 +186,3 @@ } | ||
getSymbolId(symbol: ts.Symbol): SymbolId; | ||
getSymbolAtLocation(node: ts.Node): ts.Symbol | undefined; | ||
getTypeAtLocation(node: ts.Node): ts.Type; | ||
@@ -238,4 +240,3 @@ getTypeOfSymbol(symbol: ts.Symbol, location?: ts.Node | (() => ts.Node | undefined)): ts.Type; | ||
export interface Options { | ||
group: Group; | ||
workspaceFolder: string; | ||
workspaceRoot: string; | ||
projectName: string; | ||
@@ -252,6 +253,9 @@ tsConfigFile: string | undefined; | ||
} | ||
interface ProjectDataManagerContext extends EmitterContext { | ||
workspaceRoot: string; | ||
} | ||
declare abstract class ProjectDataManager { | ||
readonly id: ProjectId; | ||
private startTime; | ||
protected readonly emitter: EmitterContext; | ||
protected readonly context: ProjectDataManagerContext; | ||
private readonly projectData; | ||
@@ -263,3 +267,3 @@ private readonly reporter; | ||
private readonly managedSymbolDataItems; | ||
constructor(id: ProjectId, emitter: EmitterContext, group: Group, project: Project, reporter: Reporter); | ||
constructor(id: ProjectId, context: ProjectDataManagerContext, project: Project, reporter: Reporter); | ||
abstract getParseMode(): ParseMode; | ||
@@ -278,3 +282,3 @@ manageSymbolData(symbolData: SymbolData): void; | ||
interface TSProjectConfig { | ||
workspaceFolder: string; | ||
workspaceRoot: string; | ||
configLocation: string | undefined; | ||
@@ -345,12 +349,11 @@ sourceRoot: string; | ||
} | ||
export declare class DataManager implements SymbolDataContext { | ||
private static readonly GlobalId; | ||
export declare class DataManager implements SymbolDataContext, ProjectDataManagerContext { | ||
private static readonly MachineId; | ||
private static readonly DefaultLibsId; | ||
private readonly context; | ||
private readonly group; | ||
private readonly reporter; | ||
private readonly dataMode; | ||
private readonly globalPDM; | ||
private readonly workspacePDM; | ||
private readonly machinePDM; | ||
private readonly defaultLibsPDM; | ||
private readonly groupPDM; | ||
private currentTSProject; | ||
@@ -364,5 +367,6 @@ private currentPDM; | ||
private readonly validateVisibilityOn; | ||
constructor(context: EmitterContext, group: Group, workspaceFolder: string, reporter: Reporter, dataMode: DataMode); | ||
get vertex(): VertexBuilder; | ||
get edge(): EdgeBuilder; | ||
readonly workspaceRoot: string; | ||
readonly vertex: VertexBuilder; | ||
readonly edge: EdgeBuilder; | ||
constructor(context: EmitterContext, workspaceRoot: string, reporter: Reporter, dataMode: DataMode); | ||
emit(element: Vertex | Edge): void; | ||
@@ -369,0 +373,0 @@ begin(): void; |
311
lib/main.js
@@ -17,11 +17,8 @@ "use strict"; | ||
* ------------------------------------------------------------------------------------------ */ | ||
const util_1 = require("util"); | ||
const fs = require("fs"); | ||
var pfs; | ||
(function (pfs) { | ||
pfs.stat = util_1.promisify(fs.stat); | ||
pfs.readFile = util_1.promisify(fs.readFile); | ||
function isFile(path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const stat = yield pfs.stat(path); | ||
const stat = yield fs.promises.stat(path); | ||
return stat.isFile(); | ||
@@ -31,2 +28,9 @@ }); | ||
pfs.isFile = isFile; | ||
function isDirectory(path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const stat = yield fs.promises.stat(path); | ||
return stat.isDirectory(); | ||
}); | ||
} | ||
pfs.isDirectory = isDirectory; | ||
})(pfs || (pfs = {})); | ||
@@ -50,19 +54,2 @@ const path = require("path"); | ||
const package_1 = require("./npm/package"); | ||
var ResolvedGroupOptions; | ||
(function (ResolvedGroupOptions) { | ||
function from(groupConfig) { | ||
if (groupConfig.uri === undefined || groupConfig.name === undefined || groupConfig.rootUri === undefined) { | ||
return undefined; | ||
} | ||
return { | ||
uri: groupConfig.uri, | ||
conflictResolution: groupConfig.conflictResolution === 'takeDump' ? 'takeDump' : 'takeDB', | ||
name: groupConfig.name, | ||
rootUri: groupConfig.rootUri, | ||
description: groupConfig.description, | ||
repository: groupConfig.repository | ||
}; | ||
} | ||
ResolvedGroupOptions.from = from; | ||
})(ResolvedGroupOptions || (ResolvedGroupOptions = {})); | ||
function loadConfigFile(file) { | ||
@@ -84,2 +71,17 @@ let absolute = path.resolve(file); | ||
} | ||
function parseConfigFileContent(options, basePath) { | ||
const configFileName = options.kind === 'ts' ? 'tsconfig.json' : 'jsconfig.json'; | ||
const config = Object.assign({}, options); | ||
delete config.__brand; | ||
delete config.configFilePath; | ||
delete config.kind; | ||
if (config.compilerOptions !== undefined) { | ||
config.compilerOptions = Object.assign(config.compilerOptions, tss.getDefaultCompilerOptions(configFileName)); | ||
} | ||
let result = ts.parseJsonConfigFileContent(config, ts.sys, basePath); | ||
if (result.errors.length > 0) { | ||
throw new Error(ts.formatDiagnostics(result.errors, ts.createCompilerHost({}))); | ||
} | ||
return result; | ||
} | ||
function createEmitter(options, writer, idGenerator) { | ||
@@ -118,94 +120,5 @@ let emitterModule; | ||
} | ||
function readGroupConfig(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const group = options.group; | ||
if (group === 'stdin') { | ||
try { | ||
const result = yield new Promise((resolve, reject) => { | ||
const stdin = process.stdin; | ||
let buffer; | ||
stdin.on('data', (data) => { | ||
if (buffer === undefined) { | ||
buffer = data; | ||
} | ||
else { | ||
buffer = Buffer.concat([buffer, data]); | ||
} | ||
}); | ||
stdin.on('end', () => { | ||
try { | ||
if (buffer === undefined) { | ||
resolve(undefined); | ||
} | ||
else { | ||
resolve(JSON.parse(buffer.toString('utf8'))); | ||
} | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
stdin.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
if (result === undefined) { | ||
return 1; | ||
} | ||
return result; | ||
} | ||
catch (err) { | ||
if (err) { | ||
console.error(err); | ||
} | ||
return 1; | ||
} | ||
} | ||
else if (typeof group === 'string' || group === undefined) { | ||
const filePath = group !== undefined ? group : process.cwd(); | ||
try { | ||
const stat = yield pfs.stat(filePath); | ||
if (stat.isFile()) { | ||
let groupConfig; | ||
try { | ||
groupConfig = JSON.parse(yield pfs.readFile(filePath, { encoding: 'utf8' })); | ||
} | ||
catch (err) { | ||
console.error(`Reading group config file ${options.group} failed.`); | ||
if (err) { | ||
console.error(err); | ||
} | ||
} | ||
if (groupConfig === undefined) { | ||
return 1; | ||
} | ||
return groupConfig; | ||
} | ||
else if (stat.isDirectory()) { | ||
const absolute = tss.makeAbsolute(filePath); | ||
const uri = vscode_uri_1.URI.file(absolute).toString(true); | ||
return { | ||
uri: uri, | ||
conflictResolution: 'takeDB', | ||
name: path.basename(absolute), | ||
rootUri: uri | ||
}; | ||
} | ||
else { | ||
return 1; | ||
} | ||
} | ||
catch (error) { | ||
console.error(`Group config file system path ${options.group} doesn't exist.`); | ||
return 1; | ||
} | ||
} | ||
else { | ||
return group; | ||
} | ||
}); | ||
} | ||
function makeKey(config) { | ||
let hash = crypto.createHash('md5'); | ||
hash.update(JSON.stringify(config.options, undefined, 0)); | ||
hash.update(JSON.stringify(args_1.ConfigOptions.is(config) ? config : config.options, undefined, 0)); | ||
return hash.digest('base64'); | ||
@@ -303,20 +216,38 @@ } | ||
} | ||
function processProject(config, emitter, typingsInstaller, dataManager, importMonikers, exportMonikers, options) { | ||
function processProject(pclOrOptions, emitter, typingsInstaller, dataManager, importMonikers, exportMonikers, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const configFilePath = tss.CompileOptions.getConfigFilePath(config.options); | ||
const key = configFilePath !== null && configFilePath !== void 0 ? configFilePath : makeKey(config); | ||
if (options.processed.has(key)) { | ||
return options.processed.get(key); | ||
let config; | ||
let configFilePath; | ||
let key; | ||
if (args_1.ConfigOptions.is(pclOrOptions)) { | ||
if (pclOrOptions.configFilePath === undefined) { | ||
console.error(`No config file path available although --config is used.`); | ||
return -1; | ||
} | ||
configFilePath = pclOrOptions.configFilePath; | ||
key = configFilePath !== null && configFilePath !== void 0 ? configFilePath : makeKey(pclOrOptions); | ||
if (options.processed.has(key)) { | ||
return options.processed.get(key); | ||
} | ||
config = parseConfigFileContent(pclOrOptions, path.dirname(configFilePath)); | ||
} | ||
if (configFilePath && !ts.sys.fileExists(configFilePath)) { | ||
console.error(`Project configuration file ${configFilePath} does not exist`); | ||
return 1; | ||
else { | ||
config = pclOrOptions; | ||
configFilePath = tss.CompileOptions.getConfigFilePath(config.options); | ||
key = configFilePath !== null && configFilePath !== void 0 ? configFilePath : makeKey(config); | ||
if (options.processed.has(key)) { | ||
return options.processed.get(key); | ||
} | ||
if (configFilePath && !ts.sys.fileExists(configFilePath)) { | ||
console.error(`Project configuration file ${configFilePath} does not exist`); | ||
return 1; | ||
} | ||
// we have a config file path that came from a -p option. Load the file. | ||
if (configFilePath && config.options.project) { | ||
config = loadConfigFile(configFilePath); | ||
} | ||
} | ||
// we have a config file path that came from a -p option. Load the file. | ||
if (configFilePath && config.options.project) { | ||
config = loadConfigFile(configFilePath); | ||
} | ||
// Check if we need to do type acquisition | ||
if (options.typeAcquisition && (config.typeAcquisition === undefined || !!config.typeAcquisition.enable)) { | ||
const projectRoot = options.workspaceFolder; | ||
const projectRoot = options.workspaceRoot; | ||
if (config.options.types !== undefined) { | ||
@@ -336,3 +267,3 @@ const start = configFilePath !== undefined ? configFilePath : process.cwd(); | ||
if (packageJson !== undefined) { | ||
exportMonikers = new exportMonikers_1.ExportMonikers(emitter, options.workspaceFolder, packageJson); | ||
exportMonikers = new exportMonikers_1.ExportMonikers(emitter, options.workspaceRoot, packageJson); | ||
} | ||
@@ -362,6 +293,6 @@ } | ||
if (result === undefined) { | ||
if (!ts.sys.fileExists(fileName)) { | ||
return undefined; | ||
let content = options.files !== undefined ? options.files.get(fileName) : undefined; | ||
if (content === undefined && ts.sys.fileExists(fileName)) { | ||
content = ts.sys.readFile(fileName); | ||
} | ||
let content = ts.sys.readFile(fileName); | ||
if (content === undefined) { | ||
@@ -441,3 +372,3 @@ return undefined; | ||
else { | ||
projectName = `${path.basename(options.workspaceFolder)}/${level + 1}`; | ||
projectName = `${path.basename(options.workspaceRoot)}/${level + 1}`; | ||
} | ||
@@ -455,4 +386,3 @@ } | ||
const lsifOptions = { | ||
group: options.group, | ||
workspaceFolder: options.workspaceFolder, | ||
workspaceRoot: options.workspaceRoot, | ||
projectName: projectName, | ||
@@ -473,2 +403,3 @@ tsConfigFile: configFilePath, | ||
function run(options) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -489,3 +420,3 @@ if (options.help) { | ||
if (options.package && !(yield pfs.isFile(options.package))) { | ||
console.log(`The package.json file referenced by the package option doesn't exist. The value is ${options.package}`); | ||
console.error(`The package.json file referenced by the package option doesn't exist. The value is ${options.package}`); | ||
process.exitCode = -1; | ||
@@ -498,7 +429,7 @@ return; | ||
if (!(yield pfs.isFile(item.package))) { | ||
console.log(`The package.json file referenced by the 'publishedPackages' option doesn't exist. The value is ${JSON.stringify(item, undefined, 0)}`); | ||
console.error(`The package.json file referenced by the 'publishedPackages' option doesn't exist. The value is ${JSON.stringify(item, undefined, 0)}`); | ||
failed = true; | ||
} | ||
if (!(yield pfs.isFile(item.project))) { | ||
console.log(`The project file referenced by the 'publishedPackages' options doesn't exist. The value is ${JSON.stringify(item, undefined, 0)}`); | ||
console.error(`The project file referenced by the 'publishedPackages' options doesn't exist. The value is ${JSON.stringify(item, undefined, 0)}`); | ||
failed = true; | ||
@@ -512,9 +443,11 @@ } | ||
} | ||
let writer; | ||
if (options.out) { | ||
writer = new writer_1.FileWriter(fs.openSync(options.out, 'w')); | ||
let writer = options.outputWriter; | ||
if (writer === undefined) { | ||
if (options.stdout) { | ||
writer = new writer_1.StdoutWriter(); | ||
} | ||
else if (options.out) { | ||
writer = new writer_1.FileWriter(fs.openSync(options.out, 'w')); | ||
} | ||
} | ||
else if (options.stdout) { | ||
writer = new writer_1.StdoutWriter(); | ||
} | ||
if (writer === undefined) { | ||
@@ -525,31 +458,20 @@ console.log(`Either a output file using --out or --stdout must be specified.`); | ||
} | ||
let groupConfig = yield readGroupConfig(options); | ||
if (typeof groupConfig === 'number') { | ||
process.exitCode = groupConfig; | ||
const workspaceRoot = tss.normalizePath((_a = options.workspaceRoot) !== null && _a !== void 0 ? _a : process.cwd()); | ||
if (!(yield pfs.isDirectory(workspaceRoot))) { | ||
console.error(`The workspace root doesn't denote a folder on disk. The value is ${workspaceRoot}`); | ||
process.exitCode = -1; | ||
return; | ||
} | ||
let resolvedGroupConfig; | ||
if (groupConfig !== undefined) { | ||
if (!groupConfig.uri) { | ||
console.error(`Group config must provide an URI.`); | ||
process.exitCode = 1; | ||
if (typeof options.source === 'string') { | ||
if (!(yield pfs.isFile(options.source))) { | ||
console.error(`The source option doesn't denote a valid file on disk. The value is ${options.source}`); | ||
process.exitCode = -1; | ||
return; | ||
} | ||
if (!groupConfig.name) { | ||
console.error(`Group config must provide a group name.`); | ||
process.exitCode = 1; | ||
if (path.basename(options.source) !== 'package.json') { | ||
console.error(`The source option can only point to a package.json file. The value is ${options.source}`); | ||
process.exitCode = -1; | ||
return; | ||
} | ||
if (!groupConfig.rootUri) { | ||
console.error(`Group config must provide a file system root URI.`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
resolvedGroupConfig = ResolvedGroupOptions.from(groupConfig); | ||
} | ||
if (resolvedGroupConfig === undefined) { | ||
console.error(`Couldn't resolve group configuration to proper values:\n\r${JSON.stringify(groupConfig, undefined, 4)}`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
// We have read the config from file. See if we need to put back a -p to successfully | ||
@@ -573,6 +495,12 @@ // parse the command line. | ||
} | ||
if (needsProject && options.p !== undefined) { | ||
if (needsProject && typeof options.p === 'string') { | ||
args.push('-p', options.p); | ||
} | ||
const config = ts.parseCommandLine(args); | ||
// Push in memory file onto the args so that the TS compiler sees them. | ||
if (options.files !== undefined) { | ||
for (const filename of options.files.keys()) { | ||
args.push(filename); | ||
} | ||
} | ||
const config = args_1.ConfigOptions.is(options.p) ? options.p : ts.parseCommandLine(args); | ||
const idGenerator = createIdGenerator(options); | ||
@@ -596,9 +524,36 @@ const emitter = createEmitter(options, writer, idGenerator); | ||
}; | ||
emitter.emit(builder.vertex.metaData(lsif_protocol_1.Version)); | ||
const group = builder.vertex.group(resolvedGroupConfig.uri, resolvedGroupConfig.name, resolvedGroupConfig.rootUri); | ||
group.conflictResolution = resolvedGroupConfig.conflictResolution; | ||
group.description = resolvedGroupConfig.description; | ||
group.repository = resolvedGroupConfig.repository; | ||
emitter.emit(group); | ||
emitter.emit(builder.vertex.event(lsif_protocol_1.EventScope.group, lsif_protocol_1.EventKind.begin, group)); | ||
const metaData = builder.vertex.metaData(lsif_protocol_1.Version); | ||
const source = yield function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = builder.vertex.source(vscode_uri_1.URI.file(workspaceRoot).toString(true)); | ||
if (typeof options.source === 'string') { | ||
try { | ||
const pjc = JSON.parse(yield fs.promises.readFile(options.source, { encoding: 'utf8' })); | ||
if (pjc.repository !== undefined && typeof pjc.repository.type === 'string' && typeof pjc.repository.url === 'string') { | ||
result.repository = Object.assign({}, pjc.repository); | ||
} | ||
} | ||
catch (error) { | ||
console.error(`Reading package.json file to obtain repository source failed.`); | ||
return -1; | ||
} | ||
} | ||
else if (options.source !== undefined && options.source.repository !== undefined) { | ||
result.repository = { | ||
url: options.source.repository.url, | ||
type: options.source.repository.type | ||
}; | ||
} | ||
return result; | ||
}); | ||
}(); | ||
if (typeof source === 'number') { | ||
process.exitCode = source; | ||
return; | ||
} | ||
emitter.emit(metaData); | ||
emitter.emit(source); | ||
const capabilities = builder.vertex.capabilities(true); | ||
capabilities.declarationProvider = false; | ||
emitter.emit(capabilities); | ||
let reporter; | ||
@@ -643,3 +598,2 @@ if (options.log === '') { // --log not provided | ||
} | ||
const workspaceFolder = tss.normalizePath(vscode_uri_1.URI.parse(group.rootUri).fsPath); | ||
let exportMonikers; | ||
@@ -649,3 +603,3 @@ if (typeof packageInfo === 'string') { | ||
if (packageJson !== undefined) { | ||
exportMonikers = new exportMonikers_1.ExportMonikers(emitterContext, workspaceFolder, packageJson); | ||
exportMonikers = new exportMonikers_1.ExportMonikers(emitterContext, workspaceRoot, packageJson); | ||
} | ||
@@ -655,4 +609,3 @@ packageInfo = undefined; | ||
const processProjectOptions = { | ||
group: group, | ||
workspaceFolder: workspaceFolder, | ||
workspaceRoot: workspaceRoot, | ||
projectName: options.projectName, | ||
@@ -665,10 +618,10 @@ typeAcquisition: options.typeAcquisition, | ||
reporter: reporter, | ||
processed: new Map() | ||
processed: new Map(), | ||
files: options.files | ||
}; | ||
const dataManager = new lsif_1.DataManager(emitterContext, group, processProjectOptions.workspaceFolder, processProjectOptions.reporter, processProjectOptions.dataMode); | ||
const importMonikers = new importMonikers_1.ImportMonikers(emitterContext, processProjectOptions.workspaceFolder); | ||
const dataManager = new lsif_1.DataManager(emitterContext, processProjectOptions.workspaceRoot, processProjectOptions.reporter, processProjectOptions.dataMode); | ||
const importMonikers = new importMonikers_1.ImportMonikers(emitterContext, processProjectOptions.workspaceRoot); | ||
dataManager.begin(); | ||
yield processProject(config, emitterContext, new typings_1.TypingsInstaller(), dataManager, importMonikers, exportMonikers, processProjectOptions); | ||
dataManager.end(); | ||
emitter.emit(builder.vertex.event(lsif_protocol_1.EventScope.group, lsif_protocol_1.EventKind.end, group)); | ||
emitter.end(); | ||
@@ -675,0 +628,0 @@ reporter.end(); |
@@ -6,7 +6,7 @@ import { Moniker } from 'lsif-protocol'; | ||
private readonly emitter; | ||
private readonly workspaceFolder; | ||
private readonly workspaceRoot; | ||
private readonly packageJson; | ||
private readonly pathPrefix; | ||
private _packageInformation; | ||
constructor(emitter: EmitterContext, workspaceFolder: string, packageJson: PackageJson); | ||
constructor(emitter: EmitterContext, workspaceRoot: string, packageJson: PackageJson); | ||
attachMoniker(tscMoniker: Moniker, filePath: string, exportParts: string | string[]): void; | ||
@@ -13,0 +13,0 @@ private isPackaged; |
@@ -13,5 +13,5 @@ "use strict"; | ||
class ExportMonikers { | ||
constructor(emitter, workspaceFolder, packageJson) { | ||
constructor(emitter, workspaceRoot, packageJson) { | ||
this.emitter = emitter; | ||
this.workspaceFolder = workspaceFolder; | ||
this.workspaceRoot = workspaceRoot; | ||
this.packageJson = packageJson; | ||
@@ -24,3 +24,3 @@ this.pathPrefix = packageJson.$location; | ||
attachMoniker(tscMoniker, filePath, exportParts) { | ||
if (!this.isPackaged(path.join(this.workspaceFolder, filePath))) { | ||
if (!this.isPackaged(path.join(this.workspaceRoot, filePath))) { | ||
return undefined; | ||
@@ -31,3 +31,3 @@ } | ||
: `[${exportParts.join(',')}]`; | ||
const npmFilePath = this.getNpmFilePath(this.workspaceFolder, filePath); | ||
const npmFilePath = this.getNpmFilePath(this.workspaceRoot, filePath); | ||
let npmIdentifier; | ||
@@ -34,0 +34,0 @@ if (this.packageJson.main === npmFilePath || this.packageJson.typings === npmFilePath) { |
@@ -5,6 +5,6 @@ import { Moniker } from 'lsif-protocol'; | ||
private readonly emitter; | ||
private readonly workspaceFolder; | ||
private readonly workspaceRoot; | ||
private readonly packageData; | ||
constructor(emitter: EmitterContext, workspaceFolder: string); | ||
constructor(emitter: EmitterContext, workspaceRoot: string); | ||
attachMoniker(tscMoniker: Moniker, fileName: string, packageName: string, filePath: string, exportParts: string | string[]): void; | ||
} |
@@ -13,6 +13,6 @@ "use strict"; | ||
class ImportMonikers { | ||
constructor(emitter, workspaceFolder) { | ||
constructor(emitter, workspaceRoot) { | ||
this.packageData = new Map(); | ||
this.emitter = emitter; | ||
this.workspaceFolder = workspaceFolder; | ||
this.workspaceRoot = workspaceRoot; | ||
} | ||
@@ -25,3 +25,3 @@ attachMoniker(tscMoniker, fileName, packageName, filePath, exportParts) { | ||
} | ||
const fullFilePath = path.posix.join(this.workspaceFolder, filePath); | ||
const fullFilePath = path.posix.join(this.workspaceRoot, filePath); | ||
const packageLocation = path.posix.join(fileName.substr(0, index), packagePart); | ||
@@ -28,0 +28,0 @@ if (!fullFilePath.startsWith(packageLocation + '/')) { |
@@ -21,2 +21,3 @@ import * as ts from 'typescript'; | ||
function getParent(symbol: ts.Symbol): ts.Symbol | undefined; | ||
function getTypeFromSymbolLink(symbol: ts.Symbol): ts.Type | undefined; | ||
function is(value: ts.Symbol | ts.Type): value is ts.Symbol; | ||
@@ -23,0 +24,0 @@ } |
@@ -183,2 +183,11 @@ /* -------------------------------------------------------------------------------------------- | ||
Symbol.getParent = getParent; | ||
function getTypeFromSymbolLink(symbol) { | ||
// Symbol links are merged into transient symbols. See | ||
// https://github.com/microsoft/TypeScript/blob/master/src/compiler/types.ts#L4871 | ||
if ((symbol.flags & ts.SymbolFlags.Transient) !== 0) { | ||
return symbol.type; | ||
} | ||
return undefined; | ||
} | ||
Symbol.getTypeFromSymbolLink = getTypeFromSymbolLink; | ||
function is(value) { | ||
@@ -185,0 +194,0 @@ const sc = value; |
{ | ||
"name": "lsif-tsc", | ||
"description": "Tool to create an LSIF dump for TypeScript projects.", | ||
"version": "0.5.6", | ||
"version": "0.6.0-dev.1", | ||
"author": "Microsoft Corporation", | ||
@@ -20,12 +20,11 @@ "license": "MIT", | ||
"dependencies": { | ||
"lsif-protocol": "0.5.3", | ||
"yargs": "16.2.0", | ||
"latest-version": "5.1.0", | ||
"lsif-protocol": "0.6.0-next.5", | ||
"typescript": "https://github.com/dbaeumer/TypeScript/releases/download/4.4.0-lsif.1/lsif-typescript-4.4.0-dev.bf4642f089.tgz", | ||
"uuid": "^8.3.2", | ||
"latest-version": "5.1.0", | ||
"vscode-uri": "^3.0.2", | ||
"typescript": "https://github.com/dbaeumer/TypeScript/releases/download/4.1.3-lsif.1/typescript-4.1.3-lsif.1.tgz" | ||
"yargs": "16.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/uuid": "^8.3.0", | ||
"@types/npm": "^2.0.31" | ||
"@types/uuid": "^8.3.0" | ||
}, | ||
@@ -32,0 +31,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
629155
1
7189
+ Addedlsif-protocol@0.6.0-next.5(transitive)
- Removedlsif-protocol@0.5.3(transitive)
Updatedlsif-protocol@0.6.0-next.5