eslint-import-resolver-parcel
Advanced tools
Comparing version 1.8.4 to 1.9.0
'use strict'; | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function _iterableToArrayLimit(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
var path = _interopDefault(require('path')); | ||
var fs = _interopDefault(require('fs')); | ||
var resolve$1 = require('resolve'); | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const _require = require('resolve'), | ||
isCore = _require.isCore, | ||
resolveSync = _require.sync; | ||
const aliases = require('../package.json').alias || {}; | ||
/* eslint-disable no-sync */ | ||
const defaultExtensions = ['.js', '.jsx']; | ||
exports.interfaceVersion = 2; | ||
exports.resolve = function (source, file, config = {}) { | ||
if (isCore(source)) return { | ||
const interfaceVersion = 2; | ||
function resolve(source, file, possibleConfig) { | ||
if (resolve$1.isCore(source)) return { | ||
found: true, | ||
path: null | ||
}; | ||
const _source$split = source.split('/'), | ||
_source$split2 = _slicedToArray(_source$split, 1), | ||
startSource = _source$split2[0]; | ||
const config = { | ||
rootDir: '', | ||
extensions: [] | ||
}; | ||
if (possibleConfig) Object.assign(config, possibleConfig); | ||
const [startSource] = source.split('/'); | ||
const aliases = findAliases(); | ||
const foundAlias = Object.keys(aliases).find(alias => alias == startSource); | ||
if (foundAlias) source = source.replace(foundAlias, aliases[foundAlias]); | ||
let rootDir = config.rootDir || ''; | ||
rootDir = path.resolve(process.cwd(), rootDir); | ||
let newSource = source.replace(foundAlias, aliases[foundAlias]); | ||
const rootDir = path.join(process.cwd(), config.rootDir); | ||
switch (source[0]) { | ||
switch (newSource[0]) { | ||
case '.': | ||
source = path.dirname(file) + '/' + source; | ||
newSource = path.join(path.dirname(file), newSource); | ||
break; | ||
case '~': | ||
source = resolvePackageLevel(source, file) || rootDir; | ||
newSource = resolvePackageLevel(newSource, file) || rootDir; | ||
break; | ||
case '/': | ||
source = rootDir + source; | ||
newSource = path.join(rootDir, newSource); | ||
break; | ||
// no default | ||
} | ||
@@ -85,4 +48,5 @@ | ||
found: true, | ||
path: resolveSync(source, { | ||
extensions: defaultExtensions.concat(config.extensions) | ||
path: resolve$1.sync(newSource, { | ||
basedir: process.cwd(), | ||
extensions: [...defaultExtensions, ...config.extensions] | ||
}) | ||
@@ -95,4 +59,17 @@ }; | ||
} | ||
}; | ||
} | ||
function findAliases() { | ||
let currentPath = process.cwd(); | ||
let packagePath = path.join(currentPath, 'package.json'); | ||
while (!fs.existsSync(packagePath)) { | ||
currentPath = path.join(currentPath, '..'); | ||
packagePath = path.join(currentPath, 'package.json'); | ||
} | ||
const packageJson = fs.readFileSync(packagePath); | ||
return JSON.parse(packageJson).alias || {}; | ||
} | ||
function resolvePackageLevel(source, file) { | ||
@@ -103,12 +80,10 @@ let packageDir = path.dirname(file); | ||
do { | ||
if (fs.existsSync(packageDir + '/node_modules')) { | ||
isFound = true; | ||
} else if (path.parse(packageDir).root == packageDir) { | ||
return null; // reached the root, just return null | ||
} else { | ||
packageDir = path.resolve(packageDir, '..'); | ||
} | ||
if (fs.existsSync(path.resolve(packageDir, 'node_modules'))) isFound = true;else if (path.parse(packageDir).root == packageDir) return null; // reached the root, just return null | ||
else packageDir = path.join(packageDir, '..'); | ||
} while (!isFound); | ||
return packageDir + source.substring(1); // get rid of the tilde | ||
return path.join(packageDir, source.substring(1)); // get rid of the tilde | ||
} | ||
exports.interfaceVersion = interfaceVersion; | ||
exports.resolve = resolve; |
@@ -1,15 +0,8 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { | ||
isCore, | ||
sync: resolveSync | ||
} = require('resolve'); | ||
const aliases = require('../package.json').alias || {}; | ||
/* eslint-disable no-sync */ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { isCore, sync as resolveSync } from 'resolve'; | ||
const defaultExtensions = ['.js', '.jsx']; | ||
exports.interfaceVersion = 2; | ||
exports.resolve = function (source, file, config = {}) { | ||
export const interfaceVersion = 2; | ||
export function resolve(source, file, possibleConfig) { | ||
if (isCore(source)) return { | ||
@@ -19,20 +12,26 @@ found: true, | ||
}; | ||
const config = { | ||
rootDir: '', | ||
extensions: [] | ||
}; | ||
if (possibleConfig) Object.assign(config, possibleConfig); | ||
const [startSource] = source.split('/'); | ||
const aliases = findAliases(); | ||
const foundAlias = Object.keys(aliases).find(alias => alias == startSource); | ||
if (foundAlias) source = source.replace(foundAlias, aliases[foundAlias]); | ||
let rootDir = config.rootDir || ''; | ||
rootDir = path.resolve(process.cwd(), rootDir); | ||
let newSource = source.replace(foundAlias, aliases[foundAlias]); | ||
const rootDir = path.join(process.cwd(), config.rootDir); | ||
switch (source[0]) { | ||
switch (newSource[0]) { | ||
case '.': | ||
source = path.dirname(file) + '/' + source; | ||
newSource = path.join(path.dirname(file), newSource); | ||
break; | ||
case '~': | ||
source = resolvePackageLevel(source, file) || rootDir; | ||
newSource = resolvePackageLevel(newSource, file) || rootDir; | ||
break; | ||
case '/': | ||
source = rootDir + source; | ||
newSource = path.join(rootDir, newSource); | ||
break; | ||
// no default | ||
} | ||
@@ -43,4 +42,5 @@ | ||
found: true, | ||
path: resolveSync(source, { | ||
extensions: defaultExtensions.concat(config.extensions) | ||
path: resolveSync(newSource, { | ||
basedir: process.cwd(), | ||
extensions: [...defaultExtensions, ...config.extensions] | ||
}) | ||
@@ -53,4 +53,17 @@ }; | ||
} | ||
}; | ||
} | ||
function findAliases() { | ||
let currentPath = process.cwd(); | ||
let packagePath = path.join(currentPath, 'package.json'); | ||
while (!fs.existsSync(packagePath)) { | ||
currentPath = path.join(currentPath, '..'); | ||
packagePath = path.join(currentPath, 'package.json'); | ||
} | ||
const packageJson = fs.readFileSync(packagePath); | ||
return JSON.parse(packageJson).alias || {}; | ||
} | ||
function resolvePackageLevel(source, file) { | ||
@@ -61,12 +74,7 @@ let packageDir = path.dirname(file); | ||
do { | ||
if (fs.existsSync(packageDir + '/node_modules')) { | ||
isFound = true; | ||
} else if (path.parse(packageDir).root == packageDir) { | ||
return null; // reached the root, just return null | ||
} else { | ||
packageDir = path.resolve(packageDir, '..'); | ||
} | ||
if (fs.existsSync(path.resolve(packageDir, 'node_modules'))) isFound = true;else if (path.parse(packageDir).root == packageDir) return null; // reached the root, just return null | ||
else packageDir = path.join(packageDir, '..'); | ||
} while (!isFound); | ||
return packageDir + source.substring(1); // get rid of the tilde | ||
return path.join(packageDir, source.substring(1)); // get rid of the tilde | ||
} |
{ | ||
"name": "eslint-import-resolver-parcel", | ||
"description": "Parcel import resolution plugin for eslint-plugin-import.", | ||
"version": "1.8.4", | ||
"version": "1.9.0", | ||
"license": "MIT", | ||
"files": [ | ||
"dist-*/", | ||
"bin/" | ||
], | ||
"esnext": "dist-src/index.js", | ||
@@ -16,7 +20,2 @@ "main": "dist-node/index.js", | ||
], | ||
"files": [ | ||
"dist-*/", | ||
"assets/", | ||
"bin/" | ||
], | ||
"homepage": "https://github.com/ABuffSeagull/eslint-import-resolver-parcel", | ||
@@ -31,11 +30,13 @@ "bugs": { | ||
"devDependencies": { | ||
"@abuffseagull/eslint-config-node": "^3.0.0", | ||
"@babel/core": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"@iarna/toml": "^2.2.1", | ||
"@pika/plugin-build-node": "^0.3.14", | ||
"@pika/plugin-standard-pkg": "^0.3.14", | ||
"babel-jest": "^24.8.0", | ||
"eslint": "^5.15.2", | ||
"eslint-config-prettier": "^4.0.0", | ||
"eslint-formatter-kakoune": "^1.0.0", | ||
"eslint-plugin-jest": "^22.4.1", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"jest": "^24.5.0", | ||
"prettier": "^1.16.4", | ||
"stryker": "^0.35.0", | ||
@@ -42,0 +43,0 @@ "stryker-api": "^0.24.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8865
16
136