Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #319 from microsoft/tell_npm_instructions
Browse files Browse the repository at this point in the history
Adds a message telling you to npm install when there's missing deps
  • Loading branch information
Orta Therox authored Feb 10, 2021
2 parents fd3eb30 + 3ebf836 commit 108f840
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
import { typeScriptPath } from "@definitelytyped/utils";
import assert = require("assert");
import { pathExists } from "fs-extra";
import { join as joinPaths, normalize } from "path";
import { dirname, join as joinPaths, normalize } from "path";
import { Configuration, ILinterOptions, Linter } from "tslint";
import * as TsType from "typescript";
type Configuration = typeof Configuration;
Expand Down Expand Up @@ -76,7 +76,28 @@ function testDependencies(
getCurrentDirectory: () => dirPath,
getNewLine: () => "\n",
});
return `Errors in typescript@${version} for external dependencies:\n${showDiags}`;

const message = `Errors in typescript@${version} for external dependencies:\n${showDiags}`;

// Add an edge-case for someone needing to `npm install` in react when they first edit a DT module which depends on it - #226
const cannotFindDepsDiags = diagnostics.find(d => d.code === 2307 && d.messageText.toString().includes("Cannot find module"));
if (cannotFindDepsDiags && cannotFindDepsDiags.file) {
const path = cannotFindDepsDiags.file.fileName;
const typesFolder = dirname(path);

return `
A module look-up failed, this often occurs when you need to run \`npm install\` on a dependent module before you can lint.
Before you debug, first try running:
npm install --prefix ${typesFolder}
Then re-run. Full error logs are below.
${message}`;
} else {
return message;
}
}

export function isExternalDependency(file: TsType.SourceFile, dirPath: string, program: TsType.Program): boolean {
Expand Down

0 comments on commit 108f840

Please sign in to comment.