Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-tsconfig-paths

Package Overview
Dependencies
Maintainers
1
Versions
72
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 1.1.0 to 2.0.0-alpha.1

6

package.json
{
"name": "vite-tsconfig-paths",
"version": "1.1.0",
"version": "2.0.0-alpha.1",
"description": "Vite resolver for TypeScript compilerOptions.paths",

@@ -20,6 +20,6 @@ "main": "dist/index.js",

"typescript": "^3.9.7",
"vite": "^1.0.0-rc.4"
"vite": "latest"
},
"peerDependencies": {
"vite": "*"
"vite": ">=2"
},

@@ -26,0 +26,0 @@ "keywords": [

@@ -0,35 +1,55 @@

import type { Plugin } from 'vite'
import { relative } from 'path'
import { createMatchPath, loadConfig } from 'tsconfig-paths'
import { mainFields, supportedExts, Resolver } from 'vite/dist/node/resolver'
const debug = require('debug')('vite-tsconfig-paths')
let resolver: Resolver = {}
type PluginOptions = {
/**
* The root directory to load `tsconfig.json` from.
*
* @default viteConfig.root
*/
root?: string
/**
* File extensions to search for.
*
* @default Object.keys(require.extensions)
*/
extensions?: string[]
}
const config = loadConfig()
if (config.resultType == 'failed') {
console.warn('[vite-tsconfig-paths]', config.message)
} else if (config.paths) {
const matchPath = createMatchPath(
config.absoluteBaseUrl,
config.paths,
config.mainFields || mainFields,
config.addMatchAll
)
const resolved = new Map<string, string>()
resolver = {
alias(id) {
let path = resolved.get(id)
if (!path) {
path = matchPath(id, undefined, undefined, supportedExts)
if (path) {
resolved.set(id, (path = '/' + relative(process.cwd(), path)))
debug(`resolved "${id}" to "${path}"`)
export default (opts: PluginOptions): Plugin => ({
name: 'vite:tsconfig-paths',
configResolved({ root, logger }) {
const config = loadConfig(opts.root || root)
if (config.resultType == 'failed') {
logger.warn(`[vite-tsconfig-paths] ${config.message}`)
} else if (config.paths) {
const matchPath = createMatchPath(
config.absoluteBaseUrl,
config.paths,
config.mainFields || [
'module',
'jsnext',
'jsnext:main',
'browser',
'main',
],
config.addMatchAll
)
const resolved = new Map<string, string>()
this.resolveId = (id) => {
let path = resolved.get(id)
if (!path) {
path = matchPath(id, undefined, undefined, opts.extensions)
if (path) {
resolved.set(id, (path = '/' + relative(process.cwd(), path)))
debug(`resolved "${id}" to "${path}"`)
}
}
return path
}
return path
},
}
}
export default resolver
}
},
})
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