Skip to content

Commit c797b2d

Browse files
committed
fix(typescript) latest version of typescript expects package.json to be passed in in the initial file set
1 parent da66365 commit c797b2d

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

dist/main/lang/projectService.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ var building = require('./modules/building');
4646
function build(query) {
4747
projectCache_1.consistentPath(query);
4848
var proj = projectCache_1.getOrCreateProject(query.filePath);
49-
var filesToEmit = proj.projectFile.project.compilerOptions.out ? [proj.projectFile.project.files[0]] : proj.projectFile.project.files;
49+
var filesToEmit = proj.projectFile.project.files.filter(function (fte) { return !fte.toLowerCase().endsWith('.json'); });
50+
filesToEmit = proj.projectFile.project.compilerOptions.out ? [filesToEmit[0]] : filesToEmit;
5051
var totalCount = filesToEmit.length;
5152
var builtCount = 0;
5253
var errorCount = 0;

dist/main/tsconfig/tsconfig.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ function getProjectSync(pathOrSrcFile) {
261261
var typings = getDefinitionsForNodeModules(dir, project.files);
262262
project.files = project.files.concat(typings.implicit);
263263
project.typings = typings.ours.concat(typings.implicit);
264+
project.files = project.files.concat(typings.packagejson);
264265
project.files = uniq(project.files.map(fsu.consistentPath));
265266
projectFileDirectory = removeTrailingSlash(fsu.consistentPath(projectFileDirectory));
266267
return {
@@ -343,6 +344,7 @@ function increaseProjectForReferenceAndImports(files) {
343344
return files;
344345
}
345346
function getDefinitionsForNodeModules(projectDir, files) {
347+
var packagejson = [];
346348
function versionStringToNumber(version) {
347349
var _a = version.split('.'), maj = _a[0], min = _a[1], patch = _a[2];
348350
return parseInt(maj) * 1000000 + parseInt(min);
@@ -383,6 +385,7 @@ function getDefinitionsForNodeModules(projectDir, files) {
383385
var moduleDir = moduleDirs[_i];
384386
try {
385387
var package_json = JSON.parse(fs.readFileSync(moduleDir + "/package.json").toString());
388+
packagejson.push(moduleDir + "/package.json");
386389
}
387390
catch (ex) {
388391
continue;
@@ -411,7 +414,7 @@ function getDefinitionsForNodeModules(projectDir, files) {
411414
.filter(function (x) { return !existing[x]; });
412415
var ours = all
413416
.filter(function (x) { return existing[x]; });
414-
return { implicit: implicit, ours: ours };
417+
return { implicit: implicit, ours: ours, packagejson: packagejson };
415418
}
416419
function prettyJSON(object) {
417420
var cache = [];

lib/globals.ts

+1
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,5 @@ interface FileDependency {
183183
/** Provided by the atom team */
184184
interface String {
185185
startsWith(str: string): boolean;
186+
endsWith(str: string): boolean;
186187
}

lib/main/lang/projectService.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ export function build(query: BuildQuery): Promise<BuildResponse> {
102102
consistentPath(query);
103103
var proj = getOrCreateProject(query.filePath);
104104

105-
/** I am assuming ther was at least one file. How else would we even get here? */
106-
let filesToEmit = proj.projectFile.project.compilerOptions.out ? [proj.projectFile.project.files[0]] : proj.projectFile.project.files;
105+
let filesToEmit = proj.projectFile.project.files.filter(fte => !fte.toLowerCase().endsWith('.json'));
106+
/** I am assuming there was at least one file. How else would we even get here? */
107+
filesToEmit = proj.projectFile.project.compilerOptions.out ? [filesToEmit[0]] : filesToEmit;
107108

108109
let totalCount = filesToEmit.length;
109110
var builtCount = 0;

lib/main/tsconfig/tsconfig.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ export function getProjectSync(pathOrSrcFile: string): TypeScriptProjectFileDeta
449449
var typings = getDefinitionsForNodeModules(dir, project.files);
450450
project.files = project.files.concat(typings.implicit);
451451
project.typings = typings.ours.concat(typings.implicit);
452+
project.files = project.files.concat(typings.packagejson);
452453

453454
// Normalize to "/" for all files
454455
// And take the uniq values
@@ -575,8 +576,9 @@ interface Typings {
575576
* We will expand on files making sure that we don't have a `typing` with the same name
576577
* Also if two node_modules reference a similar sub project (and also recursively) then the one with latest `version` field wins
577578
*/
578-
function getDefinitionsForNodeModules(projectDir: string, files: string[]): { ours: string[]; implicit: string[] } {
579-
579+
function getDefinitionsForNodeModules(projectDir: string, files: string[]): { ours: string[]; implicit: string[], packagejson: string[] } {
580+
let packagejson = [];
581+
580582
/** TODO use later when we care about versions */
581583
function versionStringToNumber(version: string): number {
582584
var [maj, min, patch] = version.split('.');
@@ -636,6 +638,7 @@ function getDefinitionsForNodeModules(projectDir: string, files: string[]): { ou
636638
for (let moduleDir of moduleDirs) {
637639
try {
638640
var package_json = JSON.parse(fs.readFileSync(`${moduleDir}/package.json`).toString());
641+
packagejson.push(`${moduleDir}/package.json`);
639642
}
640643
catch (ex) {
641644
// Can't read package.json ... no worries ... move on to other modules
@@ -674,7 +677,7 @@ function getDefinitionsForNodeModules(projectDir: string, files: string[]): { ou
674677
var ours = all
675678
.filter(x=> existing[x]);
676679

677-
return { implicit, ours };
680+
return { implicit, ours, packagejson };
678681
}
679682

680683
export function prettyJSON(object: any): string {

0 commit comments

Comments
 (0)