eslint-import-resolver-parcel
Advanced tools
Comparing version 1.10.2 to 1.10.3
@@ -7,10 +7,77 @@ 'use strict'; | ||
var path = _interopDefault(require('path')); | ||
var path = require('path'); | ||
var fs = _interopDefault(require('fs')); | ||
var resolve$1 = require('resolve'); | ||
/* eslint-disable no-sync */ | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
const defaultExtensions = ['.js', '.jsx']; | ||
const interfaceVersion = 2; | ||
function resolve(source, file, possibleConfig) { | ||
function findAliases() { | ||
let currentPath = path.posix.resolve(); | ||
let packagePath = path.posix.resolve(currentPath, 'package.json'); | ||
while (!fs.existsSync(packagePath)) { | ||
currentPath = path.posix.resolve(currentPath, '..'); | ||
packagePath = path.posix.resolve(currentPath, 'package.json'); | ||
} | ||
const packageJson = fs.readFileSync(packagePath); | ||
return JSON.parse(packageJson).alias || {}; | ||
} | ||
function resolvePackageLevel(source, file, rootDirectory) { | ||
let packageDirectory = path.posix.dirname(file); | ||
for (;;) { | ||
if (fs.existsSync(path.posix.resolve(packageDirectory, 'node_modules'))) { | ||
// found node_modules | ||
break; | ||
} else if (path.posix.parse(packageDirectory).root === packageDirectory) { | ||
// reached the drive root, just return null | ||
return null; | ||
} | ||
packageDirectory = path.posix.resolve(packageDirectory, '..'); | ||
} | ||
return path.posix.join( // return rootDirectory if it is nested inside the packageDirectory | ||
rootDirectory.startsWith(packageDirectory) ? rootDirectory : packageDirectory, // Get rid of the tilde | ||
source.slice(1)); | ||
} | ||
function resolve(source, file, possibleConfig = {}) { | ||
if (resolve$1.isCore(source)) return { | ||
@@ -20,24 +87,25 @@ found: true, | ||
}; | ||
const config = { | ||
const config = _objectSpread({ | ||
rootDir: '', | ||
extensions: [] | ||
}; | ||
if (possibleConfig) Object.assign(config, possibleConfig); | ||
}, possibleConfig); | ||
const [startSource] = source.split('/'); | ||
const aliases = findAliases(); | ||
const foundAlias = Object.keys(aliases).find(alias => alias == startSource); | ||
const foundAlias = Object.keys(aliases).find(alias => alias === startSource); | ||
let newSource = source.replace(foundAlias, aliases[foundAlias]); | ||
const rootDir = path.join(process.cwd(), config.rootDir); | ||
const rootDirectory = path.posix.resolve(config.rootDir); | ||
switch (newSource[0]) { | ||
case '.': | ||
newSource = path.join(path.dirname(file), newSource); | ||
newSource = path.posix.resolve(path.posix.dirname(file), newSource); | ||
break; | ||
case '~': | ||
newSource = resolvePackageLevel(newSource, file) || rootDir; | ||
newSource = resolvePackageLevel(newSource, file, rootDirectory); | ||
break; | ||
case '/': | ||
newSource = path.join(rootDir, newSource); | ||
newSource = path.posix.join(rootDirectory, newSource); | ||
break; | ||
@@ -51,3 +119,3 @@ // no default | ||
path: resolve$1.sync(newSource, { | ||
basedir: process.cwd(), | ||
basedir: path.posix.resolve(), | ||
extensions: [...defaultExtensions, ...config.extensions] | ||
@@ -63,29 +131,4 @@ }) | ||
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) { | ||
let packageDir = path.dirname(file); | ||
let isFound = false; | ||
do { | ||
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 path.join(packageDir, source.substring(1)); // get rid of the tilde | ||
} | ||
exports.interfaceVersion = interfaceVersion; | ||
exports.resolve = resolve; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,2 @@ | ||
/* eslint-disable no-sync */ | ||
import path from 'path'; | ||
import { posix as path } from 'path'; | ||
import fs from 'fs'; | ||
@@ -7,3 +6,37 @@ import { isCore, sync as resolveSync } from 'resolve'; | ||
export const interfaceVersion = 2; | ||
export function resolve(source, file, possibleConfig) { | ||
function findAliases() { | ||
let currentPath = path.resolve(); | ||
let packagePath = path.resolve(currentPath, 'package.json'); | ||
while (!fs.existsSync(packagePath)) { | ||
currentPath = path.resolve(currentPath, '..'); | ||
packagePath = path.resolve(currentPath, 'package.json'); | ||
} | ||
const packageJson = fs.readFileSync(packagePath); | ||
return JSON.parse(packageJson).alias || {}; | ||
} | ||
function resolvePackageLevel(source, file, rootDirectory) { | ||
let packageDirectory = path.dirname(file); | ||
for (;;) { | ||
if (fs.existsSync(path.resolve(packageDirectory, 'node_modules'))) { | ||
// found node_modules | ||
break; | ||
} else if (path.parse(packageDirectory).root === packageDirectory) { | ||
// reached the drive root, just return null | ||
return null; | ||
} | ||
packageDirectory = path.resolve(packageDirectory, '..'); | ||
} | ||
return path.join( // return rootDirectory if it is nested inside the packageDirectory | ||
rootDirectory.startsWith(packageDirectory) ? rootDirectory : packageDirectory, // Get rid of the tilde | ||
source.slice(1)); | ||
} | ||
export function resolve(source, file, possibleConfig = {}) { | ||
if (isCore(source)) return { | ||
@@ -15,22 +48,22 @@ found: true, | ||
rootDir: '', | ||
extensions: [] | ||
extensions: [], | ||
...possibleConfig | ||
}; | ||
if (possibleConfig) Object.assign(config, possibleConfig); | ||
const [startSource] = source.split('/'); | ||
const aliases = findAliases(); | ||
const foundAlias = Object.keys(aliases).find(alias => alias == startSource); | ||
const foundAlias = Object.keys(aliases).find(alias => alias === startSource); | ||
let newSource = source.replace(foundAlias, aliases[foundAlias]); | ||
const rootDir = path.join(process.cwd(), config.rootDir); | ||
const rootDirectory = path.resolve(config.rootDir); | ||
switch (newSource[0]) { | ||
case '.': | ||
newSource = path.join(path.dirname(file), newSource); | ||
newSource = path.resolve(path.dirname(file), newSource); | ||
break; | ||
case '~': | ||
newSource = resolvePackageLevel(newSource, file) || rootDir; | ||
newSource = resolvePackageLevel(newSource, file, rootDirectory); | ||
break; | ||
case '/': | ||
newSource = path.join(rootDir, newSource); | ||
newSource = path.join(rootDirectory, newSource); | ||
break; | ||
@@ -44,3 +77,3 @@ // no default | ||
path: resolveSync(newSource, { | ||
basedir: process.cwd(), | ||
basedir: path.resolve(), | ||
extensions: [...defaultExtensions, ...config.extensions] | ||
@@ -54,27 +87,2 @@ }) | ||
} | ||
} | ||
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) { | ||
let packageDir = path.dirname(file); | ||
let isFound = false; | ||
do { | ||
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 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.10.2", | ||
"version": "1.10.3", | ||
"license": "MIT", | ||
@@ -25,3 +25,2 @@ "files": [ | ||
"devDependencies": { | ||
"@abuffseagull/eslint-config-node": "^4.0.2", | ||
"@babel/core": "^7.8.3", | ||
@@ -38,6 +37,12 @@ "@babel/preset-env": "^7.8.3", | ||
"babel-jest": "^25.1.0", | ||
"eslint": "^6.8.0", | ||
"eslint": "6.1.0", | ||
"eslint-config-airbnb-base": "14.0.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-formatter-kakoune": "^1.0.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jest": "^23.6.0", | ||
"jest": "^25.1.0" | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"eslint-plugin-unicorn": "^15.0.1", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1" | ||
}, | ||
@@ -44,0 +49,0 @@ "esnext": "dist-src/index.js", |
Sorry, the diff of this file is not supported yet
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
15418
176
21