Created
March 7, 2021 22:12
-
-
Save JamieMagee/ecd5ca417a7dcfaa2afd73f88d52adc3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| "use strict"; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| const child_process_1 = require("child_process"); | |
| function getProjectUrl(project) { | |
| if (typeof project === 'string') { | |
| return project; | |
| } | |
| if ((project === null || project === void 0 ? void 0 : project.url) !== undefined) { | |
| return project.url; | |
| } | |
| return 'UNKNOWN'; | |
| } | |
| function parseDependencies(dependency) { | |
| var _a; | |
| let output = []; | |
| output.push({ | |
| name: dependency.name, | |
| version: dependency.version, | |
| license: (_a = dependency.license) !== null && _a !== void 0 ? _a : 'UNKNOWN', | |
| source: getProjectUrl(dependency.repository), | |
| }); | |
| if (dependency.dependencies) { | |
| Object.entries(dependency.dependencies).forEach(([key, value]) => { | |
| output.push(...parseDependencies(value)); | |
| }); | |
| } | |
| return output; | |
| } | |
| child_process_1.exec('npm list --global --depth=1 --long --json', (error, stdout, stderr) => { | |
| const npmList = JSON.parse(stdout); | |
| console.log(JSON.stringify([ | |
| ...Object.keys(npmList.dependencies) | |
| .map((key) => { | |
| return parseDependencies(npmList.dependencies[key]); | |
| }) | |
| .reduce((a, b) => a.concat(b), []), | |
| ])); | |
| }); | |
| //# sourceMappingURL=index.js.map |
This file contains hidden or 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
| import { exec } from 'child_process'; | |
| type Repository = { type: string; url: string } | string; | |
| type Dependency = { | |
| name: string; | |
| version: string; | |
| license?: string; | |
| repository: Repository; | |
| dependencies?: { [key: string]: Dependency }; | |
| }; | |
| type NpmList = { | |
| name: 'npm'; | |
| dependencies: { [key: string]: Dependency }; | |
| }; | |
| type TernOutput = { | |
| name: string; | |
| version: string; | |
| license: string; | |
| source: string; | |
| }; | |
| function getProjectUrl(project: Repository): string { | |
| if (typeof project === 'string') { | |
| return project; | |
| } | |
| if (project?.url !== undefined) { | |
| return project.url; | |
| } | |
| return 'UNKNOWN'; | |
| } | |
| function parseDependencies(dependency: Dependency): TernOutput[] { | |
| let output: TernOutput[] = []; | |
| output.push({ | |
| name: dependency.name, | |
| version: dependency.version, | |
| license: dependency.license ?? 'UNKNOWN', | |
| source: getProjectUrl(dependency.repository), | |
| }); | |
| if (dependency.dependencies) { | |
| Object.entries(dependency.dependencies).forEach(([key, value]) => { | |
| output.push(...parseDependencies(value)); | |
| }); | |
| } | |
| return output; | |
| } | |
| exec('npm list --global --depth=1 --long --json', (error, stdout, stderr) => { | |
| const npmList: NpmList = JSON.parse(stdout); | |
| console.log( | |
| JSON.stringify([ | |
| ...Object.keys(npmList.dependencies) | |
| .map((key) => { | |
| return parseDependencies(npmList.dependencies[key]); | |
| }) | |
| .reduce((a, b) => a.concat(b), []), | |
| ]) | |
| ); | |
| }); |
This file contains hidden or 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
| [ | |
| { | |
| "name": "npm", | |
| "version": "7.6.0", | |
| "license": "Artistic-2.0", | |
| "source": "https://github.com/npm/cli" | |
| }, | |
| { | |
| "name": "@npmcli/arborist", | |
| "version": "2.2.5", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/arborist" | |
| }, | |
| { | |
| "name": "@npmcli/ci-detect", | |
| "version": "1.3.0", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/ci-detect.git" | |
| }, | |
| { | |
| "name": "@npmcli/config", | |
| "version": "1.2.9", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/config" | |
| }, | |
| { | |
| "name": "@npmcli/run-script", | |
| "version": "1.8.3", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/run-script.git" | |
| }, | |
| { | |
| "name": "abbrev", | |
| "version": "1.1.1", | |
| "license": "ISC", | |
| "source": "http://github.com/isaacs/abbrev-js" | |
| }, | |
| { | |
| "name": "ansicolors", | |
| "version": "0.3.2", | |
| "license": "MIT", | |
| "source": "git://github.com/thlorenz/ansicolors.git" | |
| }, | |
| { | |
| "name": "ansistyles", | |
| "version": "0.1.3", | |
| "license": "MIT", | |
| "source": "git://github.com/thlorenz/ansistyles.git" | |
| }, | |
| { | |
| "name": "archy", | |
| "version": "1.0.0", | |
| "license": "MIT", | |
| "source": "http://github.com/substack/node-archy.git" | |
| }, | |
| { | |
| "name": "byte-size", | |
| "version": "7.0.0", | |
| "license": "MIT", | |
| "source": "https://github.com/75lb/byte-size" | |
| }, | |
| { | |
| "name": "cacache", | |
| "version": "15.0.5", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/cacache" | |
| }, | |
| { | |
| "name": "chalk", | |
| "version": "4.1.0", | |
| "license": "MIT", | |
| "source": "chalk/chalk" | |
| }, | |
| { | |
| "name": "chownr", | |
| "version": "2.0.0", | |
| "license": "ISC", | |
| "source": "git://github.com/isaacs/chownr.git" | |
| }, | |
| { | |
| "name": "cli-columns", | |
| "version": "3.1.2", | |
| "license": "MIT", | |
| "source": "shannonmoeller/cli-columns" | |
| }, | |
| { | |
| "name": "cli-table3", | |
| "version": "0.6.0", | |
| "license": "MIT", | |
| "source": "https://github.com/cli-table/cli-table3.git" | |
| }, | |
| { | |
| "name": "columnify", | |
| "version": "1.5.4", | |
| "license": "MIT", | |
| "source": "git://github.com/timoxley/columnify.git" | |
| }, | |
| { | |
| "name": "glob", | |
| "version": "7.1.6", | |
| "license": "ISC", | |
| "source": "git://github.com/isaacs/node-glob.git" | |
| }, | |
| { | |
| "name": "graceful-fs", | |
| "version": "4.2.6", | |
| "license": "ISC", | |
| "source": "https://github.com/isaacs/node-graceful-fs" | |
| }, | |
| { | |
| "name": "hosted-git-info", | |
| "version": "3.0.8", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/hosted-git-info.git" | |
| }, | |
| { | |
| "name": "ini", | |
| "version": "2.0.0", | |
| "license": "ISC", | |
| "source": "git://github.com/isaacs/ini.git" | |
| }, | |
| { | |
| "name": "init-package-json", | |
| "version": "2.0.2", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/init-package-json.git" | |
| }, | |
| { | |
| "name": "is-cidr", | |
| "version": "4.0.2", | |
| "license": "BSD-2-Clause", | |
| "source": "silverwind/is-cidr" | |
| }, | |
| { | |
| "name": "json-parse-even-better-errors", | |
| "version": "2.3.1", | |
| "license": "MIT", | |
| "source": "https://github.com/npm/json-parse-even-better-errors" | |
| }, | |
| { | |
| "name": "leven", | |
| "version": "3.1.0", | |
| "license": "MIT", | |
| "source": "sindresorhus/leven" | |
| }, | |
| { | |
| "name": "libnpmaccess", | |
| "version": "4.0.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmaccess.git" | |
| }, | |
| { | |
| "name": "libnpmdiff", | |
| "version": "2.0.3", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmdiff" | |
| }, | |
| { | |
| "name": "libnpmfund", | |
| "version": "1.0.2", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmfund" | |
| }, | |
| { | |
| "name": "libnpmhook", | |
| "version": "6.0.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmhook" | |
| }, | |
| { | |
| "name": "libnpmorg", | |
| "version": "2.0.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmorg.git" | |
| }, | |
| { | |
| "name": "libnpmpack", | |
| "version": "2.0.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmpack.git" | |
| }, | |
| { | |
| "name": "libnpmpublish", | |
| "version": "4.0.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmpublish.git" | |
| }, | |
| { | |
| "name": "libnpmsearch", | |
| "version": "3.1.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmsearch.git" | |
| }, | |
| { | |
| "name": "libnpmteam", | |
| "version": "2.0.2", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/libnpmteam.git" | |
| }, | |
| { | |
| "name": "libnpmversion", | |
| "version": "1.0.11", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/libnpmversion" | |
| }, | |
| { | |
| "name": "make-fetch-happen", | |
| "version": "8.0.14", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/make-fetch-happen" | |
| }, | |
| { | |
| "name": "minipass-pipeline", | |
| "version": "1.2.4", | |
| "license": "ISC", | |
| "source": "UNKNOWN" | |
| }, | |
| { | |
| "name": "minipass", | |
| "version": "3.1.3", | |
| "license": "ISC", | |
| "source": "git+https://github.com/isaacs/minipass.git" | |
| }, | |
| { | |
| "name": "mkdirp-infer-owner", | |
| "version": "2.0.0", | |
| "license": "ISC", | |
| "source": "git+https://github.com/isaacs/mkdirp-infer-owner" | |
| }, | |
| { | |
| "name": "mkdirp", | |
| "version": "1.0.4", | |
| "license": "MIT", | |
| "source": "https://github.com/isaacs/node-mkdirp.git" | |
| }, | |
| { "name": "ms", "version": "2.1.3", "license": "MIT", "source": "vercel/ms" }, | |
| { | |
| "name": "node-gyp", | |
| "version": "7.1.2", | |
| "license": "MIT", | |
| "source": "git://github.com/nodejs/node-gyp.git" | |
| }, | |
| { | |
| "name": "nopt", | |
| "version": "5.0.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/nopt.git" | |
| }, | |
| { | |
| "name": "npm-audit-report", | |
| "version": "2.1.4", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/npm-audit-report.git" | |
| }, | |
| { | |
| "name": "npm-package-arg", | |
| "version": "8.1.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/npm-package-arg" | |
| }, | |
| { | |
| "name": "npm-pick-manifest", | |
| "version": "6.1.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/npm-pick-manifest" | |
| }, | |
| { | |
| "name": "npm-profile", | |
| "version": "5.0.2", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/npm-profile.git" | |
| }, | |
| { | |
| "name": "npm-registry-fetch", | |
| "version": "9.0.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/npm-registry-fetch" | |
| }, | |
| { | |
| "name": "npm-user-validate", | |
| "version": "1.0.1", | |
| "license": "BSD-2-Clause", | |
| "source": "git://github.com/npm/npm-user-validate.git" | |
| }, | |
| { | |
| "name": "npmlog", | |
| "version": "4.1.2", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/npmlog.git" | |
| }, | |
| { | |
| "name": "opener", | |
| "version": "1.5.2", | |
| "license": "(WTFPL OR MIT)", | |
| "source": "domenic/opener" | |
| }, | |
| { | |
| "name": "pacote", | |
| "version": "11.2.7", | |
| "license": "ISC", | |
| "source": "git@github.com:npm/pacote" | |
| }, | |
| { | |
| "name": "parse-conflict-json", | |
| "version": "1.1.1", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/parse-conflict-json.git" | |
| }, | |
| { | |
| "name": "qrcode-terminal", | |
| "version": "0.12.0", | |
| "license": "UNKNOWN", | |
| "source": "https://github.com/gtanner/qrcode-terminal" | |
| }, | |
| { | |
| "name": "read-package-json-fast", | |
| "version": "2.0.2", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/read-package-json-fast.git" | |
| }, | |
| { | |
| "name": "read-package-json", | |
| "version": "3.0.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/read-package-json.git" | |
| }, | |
| { | |
| "name": "read", | |
| "version": "1.0.7", | |
| "license": "ISC", | |
| "source": "git://github.com/isaacs/read.git" | |
| }, | |
| { | |
| "name": "readdir-scoped-modules", | |
| "version": "1.1.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/readdir-scoped-modules" | |
| }, | |
| { | |
| "name": "rimraf", | |
| "version": "3.0.2", | |
| "license": "ISC", | |
| "source": "git://github.com/isaacs/rimraf.git" | |
| }, | |
| { | |
| "name": "semver", | |
| "version": "7.3.4", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/node-semver" | |
| }, | |
| { | |
| "name": "ssri", | |
| "version": "8.0.1", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/ssri" | |
| }, | |
| { | |
| "name": "tar", | |
| "version": "6.1.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/node-tar.git" | |
| }, | |
| { | |
| "name": "text-table", | |
| "version": "0.2.0", | |
| "license": "MIT", | |
| "source": "git://github.com/substack/text-table.git" | |
| }, | |
| { | |
| "name": "tiny-relative-date", | |
| "version": "1.3.0", | |
| "license": "MIT", | |
| "source": "https://github.com/wildlyinaccurate/relative-date.git" | |
| }, | |
| { | |
| "name": "treeverse", | |
| "version": "1.0.4", | |
| "license": "ISC", | |
| "source": "git+https://github.com/npm/treeverse.git" | |
| }, | |
| { | |
| "name": "validate-npm-package-name", | |
| "version": "3.0.0", | |
| "license": "ISC", | |
| "source": "https://github.com/npm/validate-npm-package-name" | |
| }, | |
| { | |
| "name": "which", | |
| "version": "2.0.2", | |
| "license": "ISC", | |
| "source": "git://github.com/isaacs/node-which.git" | |
| }, | |
| { | |
| "name": "write-file-atomic", | |
| "version": "3.0.3", | |
| "license": "ISC", | |
| "source": "git://github.com/npm/write-file-atomic.git" | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment