99// Requirements
1010//------------------------------------------------------------------------------
1111
12- const path = require ( "path" )
13- const resolve = require ( "resolve" )
1412const getAllowModules = require ( "./get-allow-modules" )
15- const getConvertPath = require ( "./get-convert-path" )
1613const getPackageJson = require ( "./get-package-json" )
1714
18- //------------------------------------------------------------------------------
19- // Helpers
20- //------------------------------------------------------------------------------
21-
22- /**
23- * Check whether the given package exists or not.
24- * @param {string } name The package name to check.
25- * @param {string } basedir The path to starting directory.
26- * @returns {boolean } `true` if the package was found.
27- */
28- function exists ( name , basedir ) {
29- try {
30- resolve . sync ( name , { basedir} )
31- return true
32- }
33- catch ( _err ) {
34- return false
35- }
36- }
37-
3815//------------------------------------------------------------------------------
3916// Public Interface
4017//------------------------------------------------------------------------------
@@ -49,24 +26,13 @@ function exists(name, basedir) {
4926 * @param {ImportTarget[] } targets - A list of target information to check.
5027 * @returns {void }
5128 */
52- module . exports = function checkForExtraeous ( context , filePath , targets ) {
29+ module . exports = function checkForExtraneous ( context , filePath , targets ) {
5330 const packageInfo = getPackageJson ( filePath )
5431 if ( ! packageInfo ) {
5532 return
5633 }
5734
5835 const allowed = new Set ( getAllowModules ( context ) )
59- const convertPath = getConvertPath ( context )
60- const rootPath = path . dirname ( packageInfo . filePath )
61- const toRelative = function ( fullPath ) { // eslint-disable-line func-style
62- const retv = path . relative ( rootPath , fullPath ) . replace ( / \\ / g, "/" )
63- return convertPath ( retv )
64- }
65- const convertedPath = path . resolve (
66- rootPath ,
67- toRelative ( path . resolve ( filePath ) )
68- )
69- const basedir = path . dirname ( convertedPath )
7036 const dependencies = new Set (
7137 [ ] . concat (
7238 Object . keys ( packageInfo . dependencies || { } ) ,
@@ -77,12 +43,11 @@ module.exports = function checkForExtraeous(context, filePath, targets) {
7743 )
7844
7945 for ( const target of targets ) {
80- const name = target . moduleName
8146 const extraneous = (
82- name != null &&
83- ! dependencies . has ( name ) &&
84- ! allowed . has ( name ) &&
85- exists ( name , basedir )
47+ target . moduleName != null &&
48+ target . filePath != null &&
49+ ! dependencies . has ( target . moduleName ) &&
50+ ! allowed . has ( target . moduleName )
8651 )
8752
8853 if ( extraneous ) {
0 commit comments