Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versions 1.6.2 and higher no longer replaces aliases #100

Closed
gbenson-ff opened this issue Mar 3, 2022 · 13 comments · Fixed by #101
Closed

Versions 1.6.2 and higher no longer replaces aliases #100

gbenson-ff opened this issue Mar 3, 2022 · 13 comments · Fixed by #101

Comments

@gbenson-ff
Copy link

After upgrading tsc-alias to 1.6.2 from 1.6.1, the tool seemingly no longer works.

I have a single entry in paths in my tsconfig.json:

{
  "paths": {
    "~*": ["./src/*"]
  }
}

I build my types with the following command: tsc --emitDeclarationOnly --outDir dist && tsc-alias

Previously it worked without issue. After the upgrade, tilde paths in my .d.ts files are no longer replaced with relative paths.

I'm happy to provide more info, just let me know what's needed!

Versions
Node - 17.6.0
NPM - 8.5.2
tsc-alias - 1.6.2

@raouldeheer
Copy link
Contributor

raouldeheer commented Mar 3, 2022

@gbenson-ff this is a known issue fixed in 1.6.3.
This is probably a duplicate issue of #97

Please try upgrade to 1.6.3 and check if the issue still occurs.

@gbenson-ff
Copy link
Author

Upgrading to 1.6.3 doesn't resolve the issue for me. That's actually the version I was using when I noticed the issue.

@raouldeheer
Copy link
Contributor

raouldeheer commented Mar 3, 2022

Is declarationDir set to something?
What is the baseUrl?
Is this on windows, mac or linux?

@gbenson-ff
Copy link
Author

declarationDir is set to ./dist

baseUrl is ./

This is on Linux.

@raouldeheer
Copy link
Contributor

It seems I can't reproduce this bug.
This is the config I tried with the same command:

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "declarationDir": "./dist",
    "baseUrl": "./",
    "paths": {
      "~*": ["./src/*"]
    }
  }
}

@justkey007 can you take a look at this?

@gbenson-ff
Copy link
Author

I think I've narrowed it down a bit. The tsconfig I'm using in this project extends a tsconfig from an npm package. Here's the two:

tsconfig.json (local)

{
	"extends": "@formfree/tsconfig/base.json"
}

@formfree/tsconfig/base.json (npm package)

{
	"extends": "@tsconfig/recommended/tsconfig.json",
	"compilerOptions": {
		"allowSyntheticDefaultImports": true,
		"baseUrl": "../../../",
		"declaration": true,
		"declarationMap": true,
		"declarationDir": "../../../dist",
		"importHelpers": true,
		"importsNotUsedAsValues": "error",
		"jsx": "preserve",
		"lib": ["esnext", "dom", "dom.iterable"],
		"module": "esnext",
		"moduleResolution": "node",
		"noImplicitAny": true,
		"noImplicitReturns": true,
		"noImplicitThis": true,
		"outDir": "dist",
		"paths": {
			"~*": ["./src/*"]
		},
		"resolveJsonModule": true,
		"sourceMap": true,
		"target": "esnext"
	},
	"include": [
		"../../../src/*.ts",
		"../../../src/**/*.ts"
	],
	"exclude": [
		"../../**/*",
		"../../../dist/**/*"
	]
}

If I instead dump the contents of @formfree/tsconfig/base.json into the local tsconfig.json and adjust the paths, tsc-alias works correctly. Using the extended config setup like I have above, it doesn't work.

I was using this exact same setup before with tsc-alias@1.6.1 and it worked correctly.

@justkey007
Copy link
Owner

@justkey007 can you take a look at this?
Alright, I'll try to reproduce the error so that I fully understand what it is.

@gbenson-ff can you provide us with a repo reproducing the bug in order to quickly resolve this problem?

@raouldeheer
Copy link
Contributor

@gbenson-ff can you provide us the console output when running with -r debugger.js?
With the debugger.js file contents being:

let loggedConfig = true;
exports.default = ({ orig, file, config }) => {
    if (loggedConfig) {
        console.log(config);
        loggedConfig = false;
    }
    console.log(orig);
    console.log(file);
    return orig;
};

@gbenson-ff
Copy link
Author

@justkey007 Sure, I can. It'll take me a minute, but I'll comment here again when I have something up.

@raouldeheer I did what you said, but got no console output.
Screenshot from 2022-03-04 09-02-25

@raouldeheer
Copy link
Contributor

raouldeheer commented Mar 4, 2022

No output means that it found no import statements.
Can you add: console.log(config); to index.js line 26 of tsc-alias dist directory?

@gbenson-ff
Copy link
Author

@raouldeheer Sure, here's the output:

> tsc --emitDeclarationOnly --outDir dist && tsc-alias -r debugger.js

{
  configFile: '/home/gabe/Coding/work/v2/frontend/packages/common/tsconfig.json',
  baseUrl: '../../../',
  outDir: '/home/gabe/Coding/work/v2/frontend/packages/common/node_modules/@formfree/tsconfig/dist',
  configDir: '/home/gabe/Coding/work/v2/frontend/packages/common',
  outPath: '/home/gabe/Coding/work/v2/frontend/packages/common/node_modules/@formfree/tsconfig/dist',
  confDirParentFolderName: 'common',
  hasExtraModule: false,
  configDirInOutPath: null,
  relConfDirPathInOutPath: null,
  pathCache: PathCache {
    useCache: true,
    existsCache: Map(0) {},
    absoluteCache: Map(0) {}
  },
  output: Output { verb: false },
  aliasTrie: TrieNode { children: Map(1) { '~' => [TrieNode] }, data: null },
  replacers: [
    [Function: replaceImportStatement],
    [Function: replaceBaseUrlImport],
    [Function (anonymous)]
  ]
}
{
  configFile: '/home/gabe/Coding/work/v2/frontend/packages/common/tsconfig.json',
  baseUrl: '../../../',
  outDir: '../../../dist',
  configDir: '/home/gabe/Coding/work/v2/frontend/packages/common',
  outPath: '../../../dist',
  confDirParentFolderName: 'common',
  hasExtraModule: false,
  configDirInOutPath: null,
  relConfDirPathInOutPath: null,
  pathCache: PathCache {
    useCache: true,
    existsCache: Map(0) {},
    absoluteCache: Map(0) {}
  },
  output: Output { verb: false },
  aliasTrie: TrieNode { children: Map(1) { '~' => [TrieNode] }, data: null },
  replacers: [
    [Function: replaceImportStatement],
    [Function: replaceBaseUrlImport],
    [Function (anonymous)]
  ]
}

@justkey007 I've put together a repo to reproduce my scenario: https://github.com/gbenson-ff/tsc-alias-bug

If you clone it, run npm i then npm run build then cat dist/index.d.ts you'll see that my tilde aliases are left as-is.

@raouldeheer
Copy link
Contributor

raouldeheer commented Mar 4, 2022

It has loaded the config correctly. ~ is loaded into the aliastrie.
The problem is probably something with the globPattern and the outPath being relative (../../../dist)

@raouldeheer
Copy link
Contributor

Found the problem, pushing fix soon.

justkey007 pushed a commit that referenced this issue Mar 5, 2022
* Fix: relative tsconfig paths

This issue should fix #100

* Fixed typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants