Socket
Socket
Sign inDemoInstall

vite-tsconfig-paths

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-tsconfig-paths - npm Package Compare versions

Comparing version 3.2.1 to 3.3.0

14

dist/index.d.ts
import { Plugin } from 'vite';
declare type PluginOptions = {
/**
* The root directories to load `tsconfig.json` from.
* The directory to crawl for `tsconfig.json` files.
*
* @default [viteConfig.root]
* @default viteConfig.root
*/
root?: string;
/**
* An array of `tsconfig.json` paths (relative to `viteConfig.root`)
* and/or directories that contain a `tsconfig.json` file.
*
* When undefined, we crawl the project for `tsconfig.json` files.
* You can set the `root` option to control where crawling starts.
*/
projects?: string[];

@@ -21,3 +29,3 @@ /**

* Useful if you want asset URLs in Vue templates to be resolved,
* or when `"checkJs": true` in your tsconfig isn't good enough.
* or when `"allowJs": true` in your tsconfig isn't good enough.
*/

@@ -24,0 +32,0 @@ loose?: boolean;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -43,2 +54,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var tsconfig_loader_1 = require("tsconfig-paths/lib/tsconfig-loader");
var recrawl_sync_1 = require("recrawl-sync");
var globRex = require("globrex");

@@ -52,8 +64,6 @@ var debug = require('debug')('vite-tsconfig-paths');

configResolved: function (_a) {
var _b;
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 || [viteRoot])
.map(createResolver)
.filter(Boolean);
var viteRoot = _a.root;
var projects = findProjects(viteRoot, opts);
var extensions = getFileExtensions(opts.extensions);
debug('options:', { projects: projects, extensions: extensions });
var viteResolve;

@@ -69,2 +79,3 @@ this.buildStart = function () {

};
var resolvers = projects.map(createResolver).filter(Boolean);
this.resolveId = function (id, importer) {

@@ -99,11 +110,11 @@ return __awaiter(this, void 0, void 0, function () {

var _this = this;
var configPath = root.endsWith('.json') ? root : null;
if (configPath)
root = path_1.dirname(root);
root = vite_1.normalizePath(path_1.resolve(viteRoot, root)) + '/';
var config = tsconfig_paths_1.loadConfig(root);
var config = tsconfig_paths_1.loadConfig(configPath || root);
debug('loadConfig:', __assign({ configPath: configPath }, config));
if (config.resultType == 'failed') {
logger.warn("[vite-tsconfig-paths] " + config.message);
return null;
}
if (!config.baseUrl) {
return null;
}
var resolveId;

@@ -180,3 +191,2 @@ if (config.paths) {

}
var implicitExtensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs'];
function loadCompilerOptions(configPath) {

@@ -199,2 +209,20 @@ var config = tsconfig_loader_1.loadTsconfig(configPath);

}
function findProjects(viteRoot, opts) {
var projects = opts.projects;
if (!projects) {
var root_1 = opts.root && vite_1.normalizePath(path_1.resolve(viteRoot, opts.root));
projects = recrawl_sync_1.crawl(root_1 || viteRoot, {
only: ['tsconfig.json'],
skip: ['node_modules', '.git'],
});
if (root_1) {
projects = projects.map(function (configPath) { return path_1.resolve(root_1, configPath); });
}
}
return projects;
}
function getFileExtensions(exts) {
var requiredExts = ['.ts', '.tsx', '.js', '.jsx', '.mjs'];
return exts ? exts.concat(requiredExts) : requiredExts;
}
//# sourceMappingURL=index.js.map
{
"name": "vite-tsconfig-paths",
"version": "3.2.1",
"version": "3.3.0",
"description": "Vite resolver for TypeScript compilerOptions.paths",

@@ -16,2 +16,3 @@ "main": "dist/index.js",

"globrex": "^0.1.2",
"recrawl-sync": "^2.0.3",
"tsconfig-paths": "^3.9.0"

@@ -18,0 +19,0 @@ },

@@ -56,3 +56,3 @@ # vite-tsconfig-paths

Say the `baseUrl` is `../root` and you import `react`. This plugin will use `../root/react` if it exists. If not found, then `react` is resolved normally.
Say the `baseUrl` is `../root` and you import `react`. This plugin will use `../root/react` if it exists. If not found, then `react` is resolved normally. The `baseUrl` is relative to the project root (where `tsconfig.json` lives).

@@ -59,0 +59,0 @@ &nbsp;

@@ -1,5 +0,6 @@

import { join, resolve, isAbsolute } from 'path'
import { dirname, join, resolve, isAbsolute } from 'path'
import { normalizePath, Plugin } from 'vite'
import { createMatchPathAsync, loadConfig } from 'tsconfig-paths'
import { loadTsconfig } from 'tsconfig-paths/lib/tsconfig-loader'
import { crawl } from 'recrawl-sync'
import globRex = require('globrex')

@@ -11,6 +12,14 @@

/**
* The root directories to load `tsconfig.json` from.
* The directory to crawl for `tsconfig.json` files.
*
* @default [viteConfig.root]
* @default viteConfig.root
*/
root?: string
/**
* An array of `tsconfig.json` paths (relative to `viteConfig.root`)
* and/or directories that contain a `tsconfig.json` file.
*
* When undefined, we crawl the project for `tsconfig.json` files.
* You can set the `root` option to control where crawling starts.
*/
projects?: string[]

@@ -29,3 +38,3 @@ /**

* Useful if you want asset URLs in Vue templates to be resolved,
* or when `"checkJs": true` in your tsconfig isn't good enough.
* or when `"allowJs": true` in your tsconfig isn't good enough.
*/

@@ -38,8 +47,6 @@ loose?: boolean

enforce: 'pre',
configResolved({ root: viteRoot, logger }) {
const extensions =
opts.extensions?.concat(implicitExtensions) || implicitExtensions
const resolvers = (opts.projects || [viteRoot])
.map(createResolver)
.filter(Boolean) as Resolver[]
configResolved({ root: viteRoot }) {
const projects = findProjects(viteRoot, opts)
const extensions = getFileExtensions(opts.extensions)
debug('options:', { projects, extensions })

@@ -52,2 +59,3 @@ let viteResolve: Resolver

const resolvers = projects.map(createResolver).filter(Boolean) as Resolver[]
this.resolveId = async function (id, importer) {

@@ -70,12 +78,11 @@ if (importer && !relativeImportRE.test(id) && !isAbsolute(id)) {

function createResolver(root: string): Resolver | null {
const configPath = root.endsWith('.json') ? root : null
if (configPath) root = dirname(root)
root = normalizePath(resolve(viteRoot, root)) + '/'
const config = loadConfig(root)
const config = loadConfig(configPath || root)
debug('loadConfig:', { configPath, ...config })
if (config.resultType == 'failed') {
logger.warn(`[vite-tsconfig-paths] ${config.message}`)
return null
}
if (!config.baseUrl) {
return null
}

@@ -150,4 +157,2 @@ let resolveId: Resolver

const implicitExtensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs']
interface CompilerOptions {

@@ -175,1 +180,21 @@ include?: string[]

}
function findProjects(viteRoot: string, opts: PluginOptions) {
let { projects } = opts
if (!projects) {
const root = opts.root && normalizePath(resolve(viteRoot, opts.root))
projects = crawl(root || viteRoot, {
only: ['tsconfig.json'],
skip: ['node_modules', '.git'],
})
if (root) {
projects = projects.map((configPath) => resolve(root, configPath))
}
}
return projects
}
function getFileExtensions(exts?: string[]) {
const requiredExts = ['.ts', '.tsx', '.js', '.jsx', '.mjs']
return exts ? exts.concat(requiredExts) : requiredExts
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc