plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.26k stars 44 forks source link

type-coverage-core: Missing dependencies if using pnpm #29

Open unlight opened 5 years ago

unlight commented 5 years ago

Version(if relevant): 2.0.2

Environment(if relevant):

pnpm package manager

Expected:

No error

Actual:

Error: Cannot find module 'minimatch'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (D:\Dev\node-package-starter\node_modules\.registry.npmjs.org\type-coverage-core\2.0.2_typescript@3.5.2\node_modules\type-coverage-core\dist\core.js:6:45)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
{
  "name": "type-coverage-core",
  "version": "2.0.2",
  "description": "A library to check type coverage for typescript code",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "repository": "https://github.com/plantain-00/type-coverage.git",
  "author": "york yao <yaoao12306@outlook.com>",
  "license": "MIT",
  "dependencies": {
    "glob": "7.1.4",
    "tslib": "1",
    "tsutils": "3"
  },
  "files": [
    "dist"
  ],
  "peerDependencies": {
    "typescript": "2 || 3"
  },
  "gitHead": "e3f7da37cb50d6fd93e04df8c3aac07d298ee030"
} 

Code:

Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const typescript_1 = tslib_1.__importDefault(require("typescript"));
const path = tslib_1.__importStar(require("path"));
const minimatch_1 = tslib_1.__importDefault(require("minimatch")); // <----
const tsconfig_1 = require("./tsconfig");
const checker_1 = require("./checker");
const dependencies_1 = require("./dependencies");
const ignore_1 = require("./ignore");
const cache_1 = require("./cache");
plantain-00 commented 5 years ago

glob has a dependency of minimatch: https://github.com/isaacs/node-glob/blob/master/package.json#L23 I just tried, it works with npm and yarn, It maybe a bug of pnpm

屏幕快照 2019-06-24 17 13 30
plantain-00 commented 5 years ago

It seems there is a solution: https://pnpm.js.org/docs/en/faq.html#solution-3

unlight commented 5 years ago

That's the point. You must not use modules indirectly. What if next minor version of glob will remove minimatch and replace by nanomatch, micromatch, etc. But you still will reference to minimatch. pnpm clearly says that it is bug of package.

In most cases it means that one of the dependencies require packages not declared in package.json. It is a common mistake caused by flat node_modules. If this happens, this is an error in the dependency and the dependency should be fixed. That might take time though, so pnpm supports workarounds to make the buggy packages work.

plantain-00 commented 5 years ago

v2.0.4 should fix this