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

Extraneous ../ in resolved paths? #30

Closed
vendethiel opened this issue Apr 10, 2022 · 5 comments
Closed

Extraneous ../ in resolved paths? #30

vendethiel opened this issue Apr 10, 2022 · 5 comments

Comments

@vendethiel
Copy link

vendethiel commented Apr 10, 2022

Hi,

I'm trying to use tsconfig-replace-paths but the generated paths go back up one extra level.

My setup is as such:

tsconfig.json
shared/
    parser.ts
server/
    uses-parser.ts
    tsconfig.json (not interesting)
test-server/
    uses-parser.ts
    tsconfig.json
out/
    test-server/
        shared/
        server/
        test-server/

My global configuration contains

    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "@shared/*": [
        "shared/*"
      ],
      "*": [
        "node_modules/*"
      ]
    },

and then the tsconfig.json files in server/ and test-server/ are:

{
  "extends": "../tsconfig.json",
  "include": [
    "."
  ]
}

(the only extra thing test-server/tsconfig.json contains is noEmit: false to generate code, because I need to run mocha on it and all the module that offer to run TS via mocha don't seem to work with my usecase).

Running this module properly finds files & replaces in them (I tried both with and without -p test-server/tsconfig.json):

$ npx tsconfig-replace-paths -s test-server -o out/test-server
Replaced 1 paths in 1 files

But the transformation is off by one level:

import Parser from "@shared/parser";
// got changed to
import Parser from "../../shared/parser";

Which tries to find a module out/shared/parse-assert (instead of out/test-server/shared/parse-assert) and fails.

Not sure if it's because my setup is weird or because I missed an option, but I'd like to know how I can solve this.
Thanks!

@jonkwheeler
Copy link
Owner

I guess I'm unsure why you would want this. This package is for changing compiled files.

Here's an example input.

./src
  - index.ts
  - my-awesome-package.ts

Here's an example output.

./dist
  - index.js
  - index.d.ts
  - my-awesome-package.js
  - my-awesome-package.d.ts

Having the path back out of your dist folder won't work because those files need to be included for your package to work correctly.

Am I missing something?

@vendethiel
Copy link
Author

vendethiel commented Apr 10, 2022

Am I missing something?

I need my files compiled to run mocha on it; like mentioned in the original message. Trying to use ts-mocha doesn't work because tsconfig-paths is broken, so I need to compile my code/tests to run my tests.

out/ in my diagram is my output directory.

Having the path back out of your dist folder won't work because those files need to be included for your package to work correctly.

I agree, that's the bug.

@jonkwheeler
Copy link
Owner

Closing for now. Feel free to push back. I believe your setup should just be altered?

Here is what a common setup looks like referencing your files.

tsconfig.json
src/
    shared/
        parser.ts
    server/
        uses-parser.ts
        tsconfig.json (not interesting)
    test-server/
        uses-parser.ts
        tsconfig.json
out/
    shared/
        parser.js
        parser.d.ts
    server/
        uses-parser.js
        uses-parser.d.ts
    test-server/
        uses-parser.js
        uses-parser.d.ts

@vendethiel
Copy link
Author

You should probably specify in the README or something that the tool expects a specific directory structure (I don’t see a difference between my root or a src/ directory, and I don’t understand why it’s a problem)

@jonkwheeler
Copy link
Owner

The tool doesn't require a specific folder structure. I'm simply saying that having one might help you. 99% of packages have a src folder or a directory serving the same purpose.

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

No branches or pull requests

2 participants