vite-tsconfig-paths
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -56,6 +56,15 @@ "use strict"; | ||
.filter(Boolean); | ||
var viteResolve; | ||
this.buildStart = function () { | ||
var _this = this; | ||
viteResolve = function (id, importer) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.resolve(id, importer, { skipSelf: true })]; | ||
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.id]; | ||
} | ||
}); }); }; | ||
}; | ||
this.resolveId = function (id, importer) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var viteResolve, _i, resolvers_1, resolve_1, resolved; | ||
var _this = this; | ||
var _i, resolvers_1, resolve_1, resolved; | ||
return __generator(this, function (_a) { | ||
@@ -65,8 +74,2 @@ switch (_a.label) { | ||
if (!(importer && !relativeImportRE.test(id) && !path_1.isAbsolute(id))) return [3 /*break*/, 4]; | ||
viteResolve = function (id) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.resolve(id, importer, { skipSelf: true })]; | ||
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.id]; | ||
} | ||
}); }); }; | ||
_i = 0, resolvers_1 = resolvers; | ||
@@ -77,3 +80,3 @@ _a.label = 1; | ||
resolve_1 = resolvers_1[_i]; | ||
return [4 /*yield*/, resolve_1(id, importer, viteResolve)]; | ||
return [4 /*yield*/, resolve_1(id, importer)]; | ||
case 2: | ||
@@ -103,12 +106,34 @@ resolved = _a.sent(); | ||
} | ||
if (!config.paths) { | ||
if (!config.baseUrl) { | ||
return null; | ||
} | ||
var matchPath = tsconfig_paths_1.createMatchPath(config.absoluteBaseUrl, config.paths, config.mainFields || [ | ||
'module', | ||
'jsnext', | ||
'jsnext:main', | ||
'browser', | ||
'main', | ||
], config.addMatchAll); | ||
var resolveId; | ||
if (config.paths) { | ||
var matchPath_1 = tsconfig_paths_1.createMatchPathAsync(config.absoluteBaseUrl, config.paths, config.mainFields || [ | ||
'module', | ||
'jsnext', | ||
'jsnext:main', | ||
'browser', | ||
'main', | ||
], config.addMatchAll); | ||
resolveId = function (id, importer) { | ||
return new Promise(function (done) { | ||
matchPath_1(id, void 0, void 0, extensions, function (error, path) { | ||
if (path) { | ||
path = vite_1.normalizePath(path); | ||
done(viteResolve(path, importer)); | ||
} | ||
else { | ||
error && debug(error.message); | ||
done(void 0); | ||
} | ||
}); | ||
}); | ||
}; | ||
} | ||
else { | ||
resolveId = function (id, importer) { | ||
return viteResolve(path_1.join(config.absoluteBaseUrl, id), importer); | ||
}; | ||
} | ||
var importerExtRE = /./; | ||
@@ -123,3 +148,3 @@ if (!opts.loose) { | ||
var resolved = new Map(); | ||
return function (id, importer, viteResolve) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (id, importer) { return __awaiter(_this, void 0, void 0, function () { | ||
var path; | ||
@@ -132,6 +157,3 @@ return __generator(this, function (_a) { | ||
if (!(!path && isLocalDescendant(importer, configRoot))) return [3 /*break*/, 2]; | ||
path = matchPath(id, undefined, undefined, extensions); | ||
if (!path) return [3 /*break*/, 2]; | ||
path = vite_1.normalizePath(path); | ||
return [4 /*yield*/, viteResolve(path)]; | ||
return [4 /*yield*/, resolveId(id, importer)]; | ||
case 1: | ||
@@ -138,0 +160,0 @@ path = _a.sent(); |
{ | ||
"name": "vite-tsconfig-paths", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Vite resolver for TypeScript compilerOptions.paths", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,4 +0,4 @@ | ||
import { resolve, isAbsolute } from 'path' | ||
import { join, resolve, isAbsolute } from 'path' | ||
import { normalizePath, Plugin } from 'vite' | ||
import { createMatchPath, loadConfig } from 'tsconfig-paths' | ||
import { createMatchPathAsync, loadConfig } from 'tsconfig-paths' | ||
import { loadTsconfig } from 'tsconfig-paths/lib/tsconfig-loader' | ||
@@ -42,9 +42,12 @@ | ||
let viteResolve: Resolver | ||
this.buildStart = function () { | ||
viteResolve = async (id, importer) => | ||
(await this.resolve(id, importer, { skipSelf: true }))?.id | ||
} | ||
this.resolveId = async function (id, importer) { | ||
if (importer && !relativeImportRE.test(id) && !isAbsolute(id)) { | ||
const viteResolve = async (id: string) => | ||
(await this.resolve(id, importer, { skipSelf: true }))?.id | ||
for (const resolve of resolvers) { | ||
const resolved = await resolve(id, importer, viteResolve) | ||
const resolved = await resolve(id, importer) | ||
if (resolved) { | ||
@@ -59,4 +62,3 @@ return resolved | ||
id: string, | ||
importer: string, | ||
viteResolve: (id: string) => Promise<string | undefined> | ||
importer: string | ||
) => Promise<string | undefined> | ||
@@ -74,18 +76,36 @@ | ||
} | ||
if (!config.paths) { | ||
if (!config.baseUrl) { | ||
return null | ||
} | ||
const matchPath = createMatchPath( | ||
config.absoluteBaseUrl, | ||
config.paths, | ||
config.mainFields || [ | ||
'module', | ||
'jsnext', | ||
'jsnext:main', | ||
'browser', | ||
'main', | ||
], | ||
config.addMatchAll | ||
) | ||
let resolveId: Resolver | ||
if (config.paths) { | ||
const matchPath = createMatchPathAsync( | ||
config.absoluteBaseUrl, | ||
config.paths, | ||
config.mainFields || [ | ||
'module', | ||
'jsnext', | ||
'jsnext:main', | ||
'browser', | ||
'main', | ||
], | ||
config.addMatchAll | ||
) | ||
resolveId = (id, importer) => | ||
new Promise((done) => { | ||
matchPath(id, void 0, void 0, extensions, (error, path) => { | ||
if (path) { | ||
path = normalizePath(path) | ||
done(viteResolve(path, importer)) | ||
} else { | ||
error && debug(error.message) | ||
done(void 0) | ||
} | ||
}) | ||
}) | ||
} else { | ||
resolveId = (id, importer) => | ||
viteResolve(join(config.absoluteBaseUrl, id), importer) | ||
} | ||
@@ -104,14 +124,10 @@ let importerExtRE = /./ | ||
const resolved = new Map<string, string>() | ||
return async (id, importer, viteResolve) => { | ||
return async (id, importer) => { | ||
if (importerExtRE.test(importer)) { | ||
let path = resolved.get(id) | ||
if (!path && isLocalDescendant(importer, configRoot)) { | ||
path = matchPath(id, undefined, undefined, extensions) | ||
path = await resolveId(id, importer) | ||
if (path) { | ||
path = normalizePath(path) | ||
path = await viteResolve(path) | ||
if (path) { | ||
resolved.set(id, path) | ||
debug(`resolved "${id}" to "${path}"`) | ||
} | ||
resolved.set(id, path) | ||
debug(`resolved "${id}" to "${path}"`) | ||
} | ||
@@ -118,0 +134,0 @@ } |
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
22172
345