Skip to content

outDir is not taking into account #103

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

Closed
emmkimme opened this issue May 10, 2021 · 13 comments
Closed

outDir is not taking into account #103

emmkimme opened this issue May 10, 2021 · 13 comments
Labels
Bug Something isn't working

Comments

@emmkimme
Copy link

emmkimme commented May 10, 2021

Hi

likely my mistake, but I did not get it to work.

I have the following configuration (just keep relevant fields)

{
    "include": [
        "../../eikon-framework/src/**/*.ts"
    ],
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "df-core/*": ["./build/df-core/*"],
            "*": [
                "./node_modules/*",
                "./node_modules/@types/*"
            ]
        },
        "rootDir": "../../eikon-framework/src",
        "outDir": "./build/eikon-framework"
    }
}

I have the following file:
../../src/eikon-framework/src/auth/auth-impl.ts
import { GetElectronEnvironment } from 'df-core/env';

after the compilation in the outDir folder I have
[outDir]/eikon-framework/auth/auth-impl.js
const env_1 = require("../../../products/workspace/build/df-core/env/index");

It seems the resolution has been done from the original location of TS file and not from the output location of JS file.
With "df-core/": ["./build/df-core/"] and outDir = ./build/eikon-framework/auth/auth-impl.js

I would expect
const env_1 = require("../../df-core/env/index");

Could you help me please

Thanks

@danielpza
Copy link
Member

Perhaps the virtual directories would help in this case

@emmkimme
Copy link
Author

emmkimme commented May 11, 2021

Thanks for your prompt answer
I once tried
{ "transform": "typescript-transform-paths", "useRootDirs": true },

"rootDirs": ["./build/df-core/*"],

but same result.

Is my assumptions good ?, I mean, looking at outDir + df-core path, it sounds logic to have
'const env_1 = require("../../df-core/env/index");'

Typescript compiles with such configuration and it works with tcspaths (no offense ;-)) but I much prefer your plugin.

@emmkimme
Copy link
Author

emmkimme commented May 11, 2021

Looking at your code and debugging the plugin, I found a way to deal with rootDirs.

{
    "include": [
        "../../eikon-framework/src/**/*.ts"
    ],
    "compilerOptions": {
        "rootDirs": ["./build/", "../../eikon-framework"],
        "baseUrl": ".",
        "paths": {
            "df-core/*": ["./build/df-core/*"],
            "*": [
                "./node_modules/*",
                "./node_modules/@types/*"
            ]
        },
        "rootDir": "../../eikon-framework/src",
        "outDir": "./build/eikon-framework"
    }
}

I'm wondering if we could have another way just using 'paths', 'rootDir' and 'outDir' to achieve the same. I have the feeling to duplicate the information.

Feel free to close this issue and thanks for your help and for this plugin.

@danielpza
Copy link
Member

Glad you find your solution. I'll keep the issue open in case someone wants to chime in.

@danielpza danielpza added the Bug Something isn't working label May 11, 2021
@nonara
Copy link
Collaborator

nonara commented May 20, 2021

@emmkimme I'd like to have a look into this. Would you mind making a reproduction repo / branch for me to try it? I'm not entirely sure I see what's happening here, but it looks like an issue of tsconfig being in a totally separate location from the source files. You might be right that this shouldn't be the standard behaviour. I'd need an example to see what's going on, though.

@kainstar
Copy link

I have same problem, I think the reason is transform plugin resolve relative path form source file rather than this output file, but sometimes we will emit files into the different level dir, that's why the final relative path is wrong.

I see this issue has tagged Bug label, is there has someone trying to solve it?

@couellet
Copy link

couellet commented Jun 8, 2021

I'm having a similar issue, here's my tsconfig.json file:

{
    "compilerOptions": {
        "target": "es5",
        "module": "esnext",
        "moduleResolution": "node",
        "declaration": true,
        "outDir": "dist",
        "strict": true,
        "lib": ["es5", "ES2015.Promise", "DOM"],
        "stripInternal": true,
        "sourceMap": true,
        "strictNullChecks": true,
        "esModuleInterop": true,
        "noEmitHelpers": true,
        "importHelpers": true,
        "allowSyntheticDefaultImports": true,
        "allowJs": true,
        "experimentalDecorators": true,
        "rootDirs": [".", "./dist"],
        "baseUrl": "./src",
        "rootDir": ".",
        "paths": {
            "@/*": [
                "./*"
            ]
        },
        "plugins": [
            { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
          ]
    },
    "include": [
        "src/**/*.ts"
    ]
}

I just added rootDirs and rootDir, but it didn't change anything. I have the following file tree:

| - 📂src
| - 📂dist
| - 📃 tsconfig.json

So my compiled files are in the dist folder but it seems that the transformer doesn't run on these, paths remain absolute.

@danielpza
Copy link
Member

@couellet I think you need 2 entries in the plugin section for the transformer to actually work:

https://github.com/LeDDGroup/typescript-transform-paths#example-config

    "plugins": [
      { "transform": "typescript-transform-paths", "useRootDirs": true },
      { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
    ]

@couellet
Copy link

couellet commented Jun 8, 2021

@danielpza that was it! Thank you so much.

@nonara
Copy link
Collaborator

nonara commented Jun 8, 2021

I see this issue has tagged Bug label, is there has someone trying to solve it?

I will, but I need a reproduction

@nonara nonara added Needs Reproduction and removed Bug Something isn't working labels Jun 8, 2021
nonara added a commit that referenced this issue Jun 16, 2021
- Several improvements were made for speed and efficiency.
- Now accommodating for new TS empty baseURL provision (closes #109)
- Pre-checking necessity before overwriting paths (closes #110)
- Rewrote core resolution methodology to:
  - Properly handle implicit indexes (closes #106)
  - Properly handle implicit sub-package indexes set via package.json 'main' #108)
  - Not follow symlinks (#107)
  - Resolve from output path as opposed to SourceFile path (#103)
nonara added a commit that referenced this issue Jun 16, 2021
- Several improvements were made for speed and efficiency.
- Now accommodating for new TS empty baseURL provision (closes #109)
- Pre-checking necessity before overwriting paths (closes #110)
- Rewrote core resolution methodology to:
  - Properly handle implicit indexes (closes #106)
  - Properly handle implicit sub-package indexes set via package.json 'main' #108)
  - Not follow symlinks (#107)
  - Resolve from output path as opposed to SourceFile path (#103)
nonara added a commit that referenced this issue Jun 16, 2021
- Several improvements were made for speed and efficiency.
- Now accommodating for new TS empty baseURL provision (closes #109)
- Pre-checking necessity before overwriting paths (closes #110)
- Rewrote core resolution methodology to:
  - Properly handle implicit indexes (closes #106)
  - Properly handle implicit sub-package indexes set via package.json 'main' #108)
  - Not follow symlinks (#107)
  - Resolve from output path as opposed to SourceFile path (#103)
nonara added a commit that referenced this issue Jun 16, 2021
- Several improvements were made for speed and efficiency.
- Now accommodating for new TS empty baseURL provision (closes #109)
- Pre-checking necessity before overwriting paths (closes #110)
- Rewrote core resolution methodology to:
  - Properly handle implicit indexes (closes #106)
  - Properly handle implicit sub-package indexes set via package.json 'main' #108)
  - Not follow symlinks (#107)
  - Resolve from output path as opposed to SourceFile path (#103)
@nonara
Copy link
Collaborator

nonara commented Jun 16, 2021

Ok, all. I looked deeper into this and you were correct on it not resolving from outDir. Please give v3.0 a try and let me know if you have any issues. It should be sorted!

@nonara nonara closed this as completed Jun 16, 2021
@nonara nonara added Bug Something isn't working and removed Needs Reproduction labels Jun 16, 2021
@kyle-belle
Copy link

Hey there. @nonara was it ever confirmed fixed. I am using "typescript-transform-paths": "^3.4.6" and it still seems to have this behaviour. Makes it very hard to work in a monorepo or yarn workspaces

@kyle-belle
Copy link

The rootDirs trick kind of works but now it causes error TS5055: Cannot write file '/path/to/file.js' because it would overwrite input file. after when i try to run tsc again since now my build folder is in rootDirs. i have to delete my build folder before running every time.

what would be nice is if this package had its own config where you could specify rootDirs without affecting tsc's rootDirs (And please if this is already possible kindly (or even rudely) let me know).

even an option like backwardsRootDirsLookup or something would be nice so i can put "./build" last in the rootDirs array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants