forked from electron-userland/electron-builder
-
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.
chore: use depcheck to lint unused/incorrect dependencies
- Loading branch information
Showing
13 changed files
with
218 additions
and
132 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -19,9 +19,9 @@ [email protected]: | |
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
|
||
fs-extra-p@^1.1.10: | ||
version "1.1.10" | ||
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-1.1.10.tgz#10ff1f1091454b99d9cd6c6eaad84ca8ae85d977" | ||
fs-extra-p@^1.2.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-1.2.0.tgz#16abed58ec63219cf9244a5a54ba200d4864b347" | ||
dependencies: | ||
bluebird "^3.4.6" | ||
fs-extra-tf "^0.30.3" | ||
|
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,63 @@ | ||
import * as path from "path" | ||
import { readJson } from "fs-extra-p" | ||
import BluebirdPromise from "bluebird" | ||
import depCheck, { DepCheckResult } from "depcheck" | ||
|
||
const printErrorAndExit = require("../../../out/util/promise").printErrorAndExit | ||
|
||
const knownUnusedDevDependencies = new Set([ | ||
"@develar/types", | ||
"@types/source-map-support", | ||
"ava-tf", | ||
"decompress-zip", | ||
"diff", | ||
"husky", | ||
"json8", | ||
"path-sort", | ||
"typescript", | ||
"depcheck" | ||
]) | ||
|
||
async function main(): Promise<void> { | ||
const projectDir = path.join(__dirname, "..", "..", "..") | ||
|
||
console.log(`Checking ${projectDir}`) | ||
|
||
const result = await new BluebirdPromise<DepCheckResult>(function (resolve) { | ||
depCheck(projectDir, { | ||
ignoreDirs: [ | ||
"out", "test", "docs", "typings", "docker", "certs", "templates", "nsis-auto-updater", ".idea", ".github", | ||
], | ||
}, resolve) | ||
}) | ||
|
||
if (result.dependencies.length > 0) { | ||
throw new Error(`Unused dependencies: ${JSON.stringify(result.dependencies, null, 2)}`) | ||
} | ||
|
||
const unusedDevDependencies = result.devDependencies.filter(it => !knownUnusedDevDependencies.has(it)) | ||
if (unusedDevDependencies.length > 0) { | ||
throw new Error(`Unused devDependencies: ${JSON.stringify(unusedDevDependencies, null, 2)}`) | ||
} | ||
|
||
if (result.missing.length > 0) { | ||
throw new Error(`Missing devDependencies: ${JSON.stringify(result.missing, null, 2)}`) | ||
} | ||
|
||
const packageData = await readJson(path.join(projectDir, "package.json")) | ||
for (let name of Object.keys(packageData.devDependencies)) { | ||
const usages = result.using[name] | ||
if (usages == null || usages.length === 0) { | ||
continue | ||
} | ||
|
||
for (let file of usages) { | ||
if (file.startsWith(path.join(projectDir, "src") + path.sep)) { | ||
throw new Error(`Dev dependency ${name} is used in the sources`) | ||
} | ||
} | ||
} | ||
} | ||
|
||
main() | ||
.catch(printErrorAndExit) |
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,15 @@ | ||
module "depcheck" { | ||
interface DepCheckOptions { | ||
ignoreDirs?: Array<string> | ||
} | ||
|
||
interface DepCheckResult { | ||
dependencies: Array<string> | ||
devDependencies: Array<string> | ||
missing: Array<string> | ||
|
||
using: { [name: string]: Array<string>; } | ||
} | ||
|
||
export default function (directory: string, options: DepCheckOptions, callback: (result: DepCheckResult) => void) | ||
} |
Oops, something went wrong.