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.8 to 1.8.9

4

dist/helpers/replacers.d.ts
import { IConfig, ReplacerOptions } from '../interfaces';
export declare function importReplacers(config: IConfig, replacers: ReplacerOptions, cmdReplacers?: string[]): Promise<void>;
export declare function replaceAlias(config: IConfig, file: string, resolveFullPath?: boolean): Promise<boolean>;
export declare function replaceAliasString(config: IConfig, file: string, code: string, resolveFullPath?: boolean): string;
export declare function replaceAlias(config: IConfig, file: string, resolveFullPath?: boolean, resolveFullExtension?: string): Promise<boolean>;
export declare function replaceAliasString(config: IConfig, file: string, code: string, resolveFullPath?: boolean, resolveFullExtension?: string): string;

@@ -112,7 +112,7 @@ "use strict";

exports.importReplacers = importReplacers;
function replaceAlias(config, file, resolveFullPath) {
function replaceAlias(config, file, resolveFullPath, resolveFullExtension) {
return __awaiter(this, void 0, void 0, function* () {
config.output.debug('Starting to replace file:', file);
const code = yield fs_1.promises.readFile(file, 'utf8');
const tempCode = replaceAliasString(config, file, code, resolveFullPath);
const tempCode = replaceAliasString(config, file, code, resolveFullPath, resolveFullExtension);
if (code !== tempCode) {

@@ -128,3 +128,3 @@ config.output.debug('replaced file with changes:', file);

exports.replaceAlias = replaceAlias;
function replaceAliasString(config, file, code, resolveFullPath) {
function replaceAliasString(config, file, code, resolveFullPath, resolveFullExtension) {
config.replacers.forEach((replacer) => {

@@ -138,3 +138,3 @@ code = (0, utils_1.replaceSourceImportPaths)(code, file, (orig) => replacer({

if (resolveFullPath) {
code = (0, utils_1.resolveFullImportPaths)(code, file);
code = (0, utils_1.resolveFullImportPaths)(code, file, resolveFullExtension);
}

@@ -141,0 +141,0 @@ return code;

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

output.debug('Found files:', files);
const replaceList = yield Promise.all(files.map((file) => OpenFilesLimit(() => (0, helpers_1.replaceAlias)(config, file, options === null || options === void 0 ? void 0 : options.resolveFullPaths))));
const replaceList = yield Promise.all(files.map((file) => OpenFilesLimit(() => (0, helpers_1.replaceAlias)(config, file, options === null || options === void 0 ? void 0 : options.resolveFullPaths, options === null || options === void 0 ? void 0 : options.resolveFullExtension))));
const replaceCount = replaceList.filter(Boolean).length;

@@ -70,3 +70,3 @@ output.info(`${replaceCount} files were affected!`);

return ({ fileContents, filePath }) => {
return (0, helpers_1.replaceAliasString)(config, filePath, fileContents, options === null || options === void 0 ? void 0 : options.resolveFullPaths);
return (0, helpers_1.replaceAliasString)(config, filePath, fileContents, options === null || options === void 0 ? void 0 : options.resolveFullPaths, options === null || options === void 0 ? void 0 : options.resolveFullExtension);
};

@@ -73,0 +73,0 @@ });

@@ -56,2 +56,3 @@ import { PathCache, TrieNode } from './utils';

resolveFullPaths?: boolean;
resolveFullExtension?: '.js' | '.mjs' | '.cjs';
replacers?: string[];

@@ -58,0 +59,0 @@ output?: IOutput;

@@ -8,7 +8,7 @@ import { StringReplacer } from '../interfaces';

replaceSourceImportPaths(replacer: StringReplacer): this;
resolveFullImportPaths(): this;
resolveFullImportPaths(ext?: string): this;
private resolveFullPath;
static newStringRegex(): RegExp;
static newImportStatementRegex(flags?: string): RegExp;
static resolveFullImportPaths(code: string, path: string): string;
static resolveFullImportPaths(code: string, path: string, ext?: string): string;
static replaceSourceImportPaths(code: string, path: string, replacer: StringReplacer): string;

@@ -15,0 +15,0 @@ }

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

const globalStyle = `(?:\\bimport\\s+${importString})`;
const globalMinimizedStyle = `(?:\\bimport${importString})`;
const fromStyle = `(?:\\bfrom\\s+${importString})`;
const fromMinimizedStyle = `(?:\\bfrom${importString})`;
const moduleStyle = `(?:\\bmodule\\s+${importString})`;

@@ -18,3 +20,5 @@ const importRegexString = `(?:${[

globalStyle,
globalMinimizedStyle,
fromStyle,
fromMinimizedStyle,
moduleStyle

@@ -34,3 +38,3 @@ ].join(`|`)})`;

}
resolveFullImportPaths() {
resolveFullImportPaths(ext = '.js') {
this.replaceSourceImportPaths((importStatement) => {

@@ -42,3 +46,3 @@ const importPathMatch = importStatement.match((0, exports.newStringRegex)());

const { path, pathWithQuotes } = importPathMatch.groups;
const fullPath = normalizePath(this.resolveFullPath(path));
const fullPath = normalizePath(this.resolveFullPath(path, ext));
return importStatement.replace(pathWithQuotes, pathWithQuotes.replace(path, fullPath));

@@ -48,8 +52,8 @@ });

}
resolveFullPath(importPath) {
if (importPath.match(/\.js$/)) {
resolveFullPath(importPath, ext = '.js') {
if (importPath.match(new RegExp(`\${ext}$`))) {
return importPath;
}
if (!importPath.match(/[/\\]$/)) {
const asFilePath = `${importPath}.js`;
const asFilePath = `${importPath}${ext}`;
if ((0, fs_1.existsSync)((0, path_1.resolve)(this.sourceDir, asFilePath))) {

@@ -59,3 +63,3 @@ return asFilePath;

}
let asFilePath = (0, path_1.join)(importPath, 'index.js');
let asFilePath = (0, path_1.join)(importPath, 'index' + ext);
if ((importPath.startsWith('./') || importPath === '.') &&

@@ -75,4 +79,5 @@ !asFilePath.startsWith('./')) {

}
static resolveFullImportPaths(code, path) {
return new ImportPathResolver(code, path).resolveFullImportPaths().source;
static resolveFullImportPaths(code, path, ext = '.js') {
return new ImportPathResolver(code, path).resolveFullImportPaths(ext)
.source;
}

@@ -79,0 +84,0 @@ static replaceSourceImportPaths(code, path, replacer) {

{
"name": "tsc-alias",
"version": "1.8.8",
"version": "1.8.9",
"description": "Replace alias paths with relative paths after typescript compilation.",

@@ -12,11 +12,2 @@ "main": "dist/index.js",

},
"scripts": {
"prepare": "husky install",
"build:dev": "tsc -w",
"clean": "rimraf dist && tsc && pnpm link -g",
"release:patch": "npm version patch",
"postversion": "git push && git push --tags && npm publish",
"format": "prettier --write \"**/*.{js,ts,json}\"",
"test": "npm run clean && jest"
},
"repository": {

@@ -61,3 +52,11 @@ "type": "git",

"typescript": "^4.5.5"
},
"scripts": {
"build:dev": "tsc -w",
"clean": "rimraf dist && tsc && pnpm link -g",
"release:patch": "npm version patch",
"postversion": "git push && git push --tags && npm publish",
"format": "prettier --write \"**/*.{js,ts,json}\"",
"test": "npm run clean && jest"
}
}
}

@@ -75,3 +75,3 @@ # tsc-alias

<tr>
<td>configFile</td>
<td>project, p</td>
<td>path to tsconfig.json</td>

@@ -101,2 +101,7 @@ <td><code>'tsconfig.json'</code></td>

<tr>
<td>resolveFullExtension</td>
<td>Allows you to specify the extension of incomplete import paths, works with <code>resolveFullPaths</code></td>
<td><code>'.js' | '.mjs' | '.cjs'</code></td>
</tr>
<tr>
<td>silent</td>

@@ -103,0 +108,0 @@ <td>Reduced terminal output. This is a deprecated option and no longer has any effect.</td>

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