Skip to content

Commit

Permalink
fix counting
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhocho committed May 9, 2019
1 parent b914fc1 commit 99622e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tscpaths",
"version": "0.0.8",
"version": "0.0.9",
"description": "Replace absolute paths to relative paths after typescript compilation",
"main": "cjs/index.js",
"module": "lib/index.js",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const toRelative = (from: string, x: string): string => {

const exts = ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.json'];

let replaceCount = 0;

const absToRel = (modulePath: string, outFile: string): string => {
const alen = aliases.length;
for (let j = 0; j < alen; j += 1) {
Expand All @@ -115,6 +117,7 @@ const absToRel = (modulePath: string, outFile: string): string => {
exts.some((ext) => existsSync(moduleSrc + ext))
) {
const rel = toRelative(dirname(srcFile), moduleSrc);
replaceCount += 1;
verboseLog(
`\treplacing '${modulePath}' -> '${rel}' referencing ${relative(
basePath,
Expand All @@ -124,7 +127,7 @@ const absToRel = (modulePath: string, outFile: string): string => {
return rel;
}
}
verboseLog(`\tcould not replace ${modulePath}`);
console.log(`could not replace ${modulePath}`);
}
}
return modulePath;
Expand All @@ -133,15 +136,12 @@ const absToRel = (modulePath: string, outFile: string): string => {
const requireRegex = /(?:import|require)\(['"]([^'"]*)['"]\)/g;
const importRegex = /(?:import|from) ['"]([^'"]*)['"]/g;

let replaceCount = 0;

const replaceImportStatement = (
orig: string,
matched: string,
outFile: string
): string => {
const index = orig.indexOf(matched);
replaceCount += 1;
return (
orig.substring(0, index) +
absToRel(matched, outFile) +
Expand Down

0 comments on commit 99622e9

Please sign in to comment.