vite-tsconfig-paths
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -43,2 +43,3 @@ "use strict"; | ||
var tsconfig_loader_1 = require("tsconfig-paths/lib/tsconfig-loader"); | ||
var globRex = require("globrex"); | ||
var debug = require('debug')('vite-tsconfig-paths'); | ||
@@ -52,5 +53,5 @@ exports.default = (function (opts) { | ||
var _b; | ||
var root = _a.root, logger = _a.logger; | ||
var viteRoot = _a.root, logger = _a.logger; | ||
var extensions = ((_b = opts.extensions) === null || _b === void 0 ? void 0 : _b.concat(implicitExtensions)) || implicitExtensions; | ||
var resolvers = (opts.projects || [root]) | ||
var resolvers = (opts.projects || [viteRoot]) | ||
.map(createResolver) | ||
@@ -95,8 +96,6 @@ .filter(Boolean); | ||
}; | ||
function createResolver(configRoot) { | ||
function createResolver(root) { | ||
var _this = this; | ||
configRoot = | ||
(configRoot ? vite_1.normalizePath(path_1.resolve(root, configRoot)) : configRoot) + | ||
'/'; | ||
var config = tsconfig_paths_1.loadConfig(configRoot); | ||
root = vite_1.normalizePath(path_1.resolve(viteRoot, root)) + '/'; | ||
var config = tsconfig_paths_1.loadConfig(root); | ||
if (config.resultType == 'failed') { | ||
@@ -138,9 +137,9 @@ logger.warn("[vite-tsconfig-paths] " + config.message); | ||
} | ||
var compilerOptions = loadCompilerOptions(config.configFileAbsolutePath); | ||
var isIncluded = getIncluder(compilerOptions); | ||
var importerExtRE = /./; | ||
if (!opts.loose) { | ||
var _a = loadCompilerOptions(config.configFileAbsolutePath), allowJs = _a.allowJs, checkJs = _a.checkJs; | ||
importerExtRE = | ||
allowJs || checkJs // | ||
? /\.(vue|svelte|mdx|mjs|[jt]sx?)$/ | ||
: /\.tsx?$/; | ||
importerExtRE = compilerOptions.allowJs | ||
? /\.(vue|svelte|mdx|mjs|[jt]sx?)$/ | ||
: /\.tsx?$/; | ||
} | ||
@@ -155,3 +154,5 @@ var resolved = new Map(); | ||
path = resolved.get(id); | ||
if (!(!path && isLocalDescendant(importer, configRoot))) return [3 /*break*/, 2]; | ||
if (!(!path && isLocalDescendant(importer, root))) return [3 /*break*/, 2]; | ||
if (!isIncluded(importer.slice(root.length))) | ||
return [2 /*return*/]; | ||
return [4 /*yield*/, resolveId(id, importer)]; | ||
@@ -185,2 +186,15 @@ case 1: | ||
} | ||
function getIncluder(_a) { | ||
var _b = _a.include, include = _b === void 0 ? [] : _b, _c = _a.exclude, exclude = _c === void 0 ? [] : _c; | ||
if (include.length || exclude.length) { | ||
var globOpts_1 = { extended: true }; | ||
var included_1 = include.map(function (glob) { return globRex(glob, globOpts_1).regex; }); | ||
var excluded_1 = exclude.map(function (glob) { return globRex(glob, globOpts_1).regex; }); | ||
return function (path) { | ||
return (!included_1.length || included_1.some(function (glob) { return glob.test(path); })) && | ||
(!excluded_1.length || !excluded_1.some(function (glob) { return glob.test(path); })); | ||
}; | ||
} | ||
return function () { return true; }; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "vite-tsconfig-paths", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Vite resolver for TypeScript compilerOptions.paths", | ||
@@ -15,5 +15,7 @@ "main": "dist/index.js", | ||
"debug": "^4.1.1", | ||
"globrex": "^0.1.2", | ||
"tsconfig-paths": "^3.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/globrex": "^0.1.0", | ||
"@types/node": "^14.0.27", | ||
@@ -20,0 +22,0 @@ "prettier": "^2.0.5", |
@@ -5,2 +5,3 @@ import { join, resolve, isAbsolute } from 'path' | ||
import { loadTsconfig } from 'tsconfig-paths/lib/tsconfig-loader' | ||
import globRex = require('globrex') | ||
@@ -36,6 +37,6 @@ const debug = require('debug')('vite-tsconfig-paths') | ||
enforce: 'pre', | ||
configResolved({ root, logger }) { | ||
configResolved({ root: viteRoot, logger }) { | ||
const extensions = | ||
opts.extensions?.concat(implicitExtensions) || implicitExtensions | ||
const resolvers = (opts.projects || [root]) | ||
const resolvers = (opts.projects || [viteRoot]) | ||
.map(createResolver) | ||
@@ -66,8 +67,6 @@ .filter(Boolean) as Resolver[] | ||
function createResolver(configRoot: string): Resolver | null { | ||
configRoot = | ||
(configRoot ? normalizePath(resolve(root, configRoot)) : configRoot) + | ||
'/' | ||
function createResolver(root: string): Resolver | null { | ||
root = normalizePath(resolve(viteRoot, root)) + '/' | ||
const config = loadConfig(configRoot) | ||
const config = loadConfig(root) | ||
if (config.resultType == 'failed') { | ||
@@ -112,11 +111,10 @@ logger.warn(`[vite-tsconfig-paths] ${config.message}`) | ||
const compilerOptions = loadCompilerOptions(config.configFileAbsolutePath) | ||
const isIncluded = getIncluder(compilerOptions) | ||
let importerExtRE = /./ | ||
if (!opts.loose) { | ||
const { allowJs, checkJs } = loadCompilerOptions( | ||
config.configFileAbsolutePath | ||
) | ||
importerExtRE = | ||
allowJs || checkJs // | ||
? /\.(vue|svelte|mdx|mjs|[jt]sx?)$/ | ||
: /\.tsx?$/ | ||
importerExtRE = compilerOptions.allowJs | ||
? /\.(vue|svelte|mdx|mjs|[jt]sx?)$/ | ||
: /\.tsx?$/ | ||
} | ||
@@ -128,3 +126,4 @@ | ||
let path = resolved.get(id) | ||
if (!path && isLocalDescendant(importer, configRoot)) { | ||
if (!path && isLocalDescendant(importer, root)) { | ||
if (!isIncluded(importer.slice(root.length))) return | ||
path = await resolveId(id, importer) | ||
@@ -154,4 +153,5 @@ if (path) { | ||
interface CompilerOptions { | ||
include?: string[] | ||
exclude?: string[] | ||
allowJs?: boolean | ||
checkJs?: boolean | ||
} | ||
@@ -163,1 +163,13 @@ | ||
} | ||
function getIncluder({ include = [], exclude = [] }: CompilerOptions) { | ||
if (include.length || exclude.length) { | ||
const globOpts = { extended: true } | ||
const included = include.map((glob) => globRex(glob, globOpts).regex) | ||
const excluded = exclude.map((glob) => globRex(glob, globOpts).regex) | ||
return (path: string) => | ||
(!included.length || included.some((glob) => glob.test(path))) && | ||
(!excluded.length || !excluded.some((glob) => glob.test(path))) | ||
} | ||
return () => true | ||
} |
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
24477
369
4
5
+ Addedglobrex@^0.1.2
+ Addedglobrex@0.1.2(transitive)