Socket
Socket
Sign inDemoInstall

tsc-alias

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

tsc-alias - npm Package Compare versions

Comparing version 1.8.2 to 1.8.3

2

dist/bin/index.js

@@ -12,3 +12,3 @@ #! /usr/bin/env node

.option('-w, --watch', 'Observe file changes')
.option('--dir, --directory <dir>', 'Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig)')
.option('--outDir, --dir, --directory <dir>', 'Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig)')
.option('-f, --resolve-full-paths', 'Attempt to fully resolve import paths if the corresponding .js file can be found')

@@ -15,0 +15,0 @@ .option('-s, --silent', 'Reduced terminal output (default: true) [deprecated]')

@@ -57,3 +57,3 @@ "use strict";

if (aliasPath.path.match(/^(\.\/|)node_modules/g)) {
aliasPath.basePath = (0, path_1.resolve)(config.baseUrl, aliasPath.path);
aliasPath.basePath = (0, path_1.resolve)(config.baseUrl, 'node_modules');
aliasPath.isExtra = false;

@@ -60,0 +60,0 @@ return aliasPath;

@@ -16,3 +16,5 @@ "use strict";

if (config.pathCache.existsResolvedAlias(`${config.outPath}/${requiredModule}`)) {
let relativePath = normalizePath((0, path_1.relative)((0, path_1.dirname)(file), config.pathCache.getAbsoluteAliasPath(config.outPath, '')));
let relativePath = normalizePath((0, path_1.relative)((0, path_1.dirname)(file), config.pathCache
.getAbsoluteAliasPath(config.outPath, '')
.replace('---', '')));
if (!relativePath.startsWith('.')) {

@@ -19,0 +21,0 @@ relativePath = './' + relativePath;

@@ -32,4 +32,12 @@ "use strict";

for (let i = 0; i < alias.paths.length; i++) {
const absoluteAliasPath = config.pathCache.getAbsoluteAliasPath(alias.paths[i].basePath, alias.paths[i].path);
let absoluteAliasPath = config.pathCache.getAbsoluteAliasPath(alias.paths[i].basePath, alias.paths[i].path);
config.output.debug('default replacer - absoluteAliasPath: ', absoluteAliasPath);
if (absoluteAliasPath.startsWith('---')) {
if (i === alias.paths.length - 1) {
absoluteAliasPath = absoluteAliasPath.replace('---', '');
}
else {
continue;
}
}
if (!config.pathCache.existsResolvedAlias(alias.prefix.length == requiredModule.length

@@ -36,0 +44,0 @@ ? normalizePath(absoluteAliasPath)

export declare class PathCache {
useCache: boolean;
existsCache: Map<string, boolean>;
absoluteCache: Map<{
basePath: string;
aliasPath: string;
}, string>;
absoluteCache: Map<string, string>;
fileExtensions: string[];
constructor(useCache: boolean, fileExtensions?: string[]);
private exists;
existsResolvedAlias(path: string): boolean;
getAbsoluteAliasPath(basePath: string, aliasPath: string): string;
private getCacheKey;
private getAAP;
getAbsoluteAliasPath(basePath: string, aliasPath: string): string;
private exists;
}

@@ -25,6 +25,2 @@ "use strict";

}
exists(path) {
return ((0, fs_1.existsSync)(path) ||
this.fileExtensions.some((extension) => (0, fs_1.existsSync)(`${path}.${extension}`)));
}
existsResolvedAlias(path) {

@@ -42,2 +38,18 @@ if (!this.useCache)

}
getAbsoluteAliasPath(basePath, aliasPath) {
const request = { basePath, aliasPath };
if (!this.useCache)
return this.getAAP(request);
if (this.absoluteCache.has(this.getCacheKey(request))) {
return this.absoluteCache.get(this.getCacheKey(request));
}
else {
const result = this.getAAP(request);
this.absoluteCache.set(this.getCacheKey(request), result);
return result;
}
}
getCacheKey({ basePath, aliasPath }) {
return `${basePath}___${aliasPath}`;
}
getAAP({ basePath, aliasPath }) {

@@ -48,3 +60,3 @@ const aliasPathParts = aliasPath

let aliasPathPart = aliasPathParts.shift() || '';
let pathExists;
let pathExists = false;
while (!(pathExists = this.exists((0, path_1.join)(basePath, aliasPathPart))) &&

@@ -54,19 +66,13 @@ aliasPathParts.length) {

}
return (0, path_1.join)(basePath, pathExists ? aliasPathPart : '', aliasPathParts.join('/'));
}
getAbsoluteAliasPath(basePath, aliasPath) {
const request = { basePath, aliasPath };
if (!this.useCache)
return this.getAAP(request);
if (this.absoluteCache.has(request)) {
return this.absoluteCache.get(request);
if (pathExists) {
return (0, path_1.join)(basePath, aliasPathPart, aliasPathParts.join('/'));
}
else {
const result = this.getAAP(request);
this.absoluteCache.set(request, result);
return result;
}
return '---' + (0, path_1.join)(basePath, aliasPathParts.join('/'));
}
exists(path) {
return ((0, fs_1.existsSync)(path) ||
this.fileExtensions.some((extension) => (0, fs_1.existsSync)(`${path}.${extension}`)));
}
}
exports.PathCache = PathCache;
//# sourceMappingURL=path-cache.js.map
{
"name": "tsc-alias",
"version": "1.8.2",
"version": "1.8.3",
"description": "Replace alias paths with relative paths after typescript compilation.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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