Comparing version 1.2.11 to 1.3.0
@@ -13,2 +13,3 @@ #! /usr/bin/env node | ||
.option('--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') | ||
.option('-s, --silent', 'reduced terminal output') | ||
@@ -20,4 +21,5 @@ .parse(process.argv); | ||
outDir: program.directory, | ||
silent: program.silent | ||
silent: program.silent, | ||
resolveFullPaths: program.resolveFullPaths | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
export declare function replaceTscAliasPaths(options?: { | ||
export interface ReplaceTscAliasPathsOptions { | ||
configFile?: string; | ||
@@ -6,2 +6,4 @@ outDir?: string; | ||
silent?: boolean; | ||
}): void; | ||
resolveFullPaths?: boolean; | ||
} | ||
export declare function replaceTscAliasPaths(options?: ReplaceTscAliasPathsOptions): void; |
@@ -118,4 +118,2 @@ "use strict"; | ||
}); | ||
const requireRegex = /(?:import|require)\(['"]([^'"]*)['"]\)/g; | ||
const importRegex = /(?:import|from) ['"]([^'"]*)['"]/g; | ||
const replaceImportStatement = ({ orig, file, alias }) => { | ||
@@ -140,3 +138,3 @@ const requiredModule = orig.split(/"|'/)[1]; | ||
}; | ||
const replaceAlias = (file) => { | ||
const replaceAlias = (file, resolveFullPath) => { | ||
const code = fs_1.readFileSync(file, 'utf8'); | ||
@@ -149,6 +147,7 @@ let tempCode = code; | ||
}; | ||
tempCode = tempCode | ||
.replace(requireRegex, (orig) => replaceImportStatement(Object.assign({ orig }, replacementParams))) | ||
.replace(importRegex, (orig) => replaceImportStatement(Object.assign({ orig }, replacementParams))); | ||
tempCode = utils_1.replaceSourceImportPaths(tempCode, file, (orig) => replaceImportStatement(Object.assign({ orig }, replacementParams))); | ||
} | ||
if (resolveFullPath) { | ||
tempCode = utils_1.resolveFullImportPaths(tempCode, file); | ||
} | ||
if (code !== tempCode) { | ||
@@ -172,3 +171,3 @@ fs_1.writeFileSync(file, tempCode, 'utf8'); | ||
const file = files[i]; | ||
if (replaceAlias(file)) { | ||
if (replaceAlias(file, options === null || options === void 0 ? void 0 : options.resolveFullPaths)) { | ||
replaceCount++; | ||
@@ -183,3 +182,3 @@ } | ||
filesWatcher.on('change', (file) => { | ||
replaceAlias(file); | ||
replaceAlias(file, options === null || options === void 0 ? void 0 : options.resolveFullPaths); | ||
}); | ||
@@ -186,0 +185,0 @@ tsconfigWatcher.on('change', (_) => { |
export * from './output'; | ||
export * from './ImportPathResolver'; |
@@ -14,2 +14,3 @@ "use strict"; | ||
__exportStar(require("./output"), exports); | ||
__exportStar(require("./ImportPathResolver"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "tsc-alias", | ||
"version": "1.2.11", | ||
"version": "1.3.0", | ||
"description": "Replace alias paths with relative paths after typescript compilation.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -82,2 +82,7 @@ # tsc-alias | ||
<tr> | ||
<td>resolveFullPaths</td> | ||
<td>Attempt to replace incomplete import paths (those not ending in <code>.js</code>) with fully resolved paths (for ECMAScript Modules compatibility)</td> | ||
<td><code>false</code></td> | ||
</tr> | ||
<tr> | ||
<td>silent</td> | ||
@@ -84,0 +89,0 @@ <td>Reduced terminal output</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
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
54601
21
484
93
3