jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

rootDir warning even when set to './src' #667

Open Ponjimon opened 4 years ago

Ponjimon commented 4 years ago

Current Behavior

It complains that rootDir is set to ./ when it's not

Expected behavior

It should not complain about it since rootDir is correctly set to ./src

Additional context

[tsdx]: Your rootDir is currently set to "./". Please change your rootDir to "./src".
TSDX has deprecated setting tsconfig.compilerOptions.rootDir to "./" as it caused buggy output for declarationMaps and occassionally for type declarations themselves.
You may also need to change your include to remove "test", which also caused declarations to be unnecessarily created for test files.

tsconfig.json:

{
    "include": ["src", "types"],
    "compilerOptions": {
      "target": "esnext",
      "module": "esnext",
      "lib": ["esnext", "dom"],
      "importHelpers": true,
      "declaration": true,
      "sourceMap": true,
      "rootDir": "./src",
      "noImplicitAny": false,
      "noImplicitThis": true,
      "noUnusedLocals": false,
      "noUnusedParameters": false,
      "noFallthroughCasesInSwitch": true,
      "moduleResolution": "node",
      "baseUrl": "./",
      "esModuleInterop": true,
      "resolveJsonModule": true
    },
    "exclude": ["node_modules", "**/*.spec.ts"]
  }

Your environment

Software Version(s)
TSDX ^0.13.1
TypeScript ^3.8.3
Browser -
npm/Yarn -/1.22.4
Node v12.16.1
Operating System WSL 2 Ubuntu 18.04
agilgur5 commented 4 years ago

Can you provide a minimal reproduction? Can't say what's going on otherwise.

There is a different code-path where it could be hit, but it's highly unlikely a user has it as you'd need to have a src/src/ directory structure, which would be very confusing usage.

gustavopch commented 4 years ago

@agilgur5 Just happened to me:

agilgur5 commented 4 years ago

@gustavopch thanks for the repro. Very weird, it is indeed creating a dist/src/ directory even though you don't have a src/src/ directory. There are no other directories created either, so doesn't seem like you're importing from another directory. 🤔

The check is here, which is inside a deprecated function that moves type declarations from dist/src/ to just dist/: https://github.com/formium/tsdx/blob/f0963cb2d77f00bcd8606f8e4b99250972d81b02/src/deprecated.ts#L13-L21

I'm pretty confused as to why that's happening, maybe related to new TS version you're using. However, I was able to workaround the issue by using "files": ["./src/index.ts"] instead of the "include": ["./src"]

agilgur5 commented 4 years ago

You can also use "include": ["./src/*"] which seems to work fine as well.

gustavopch commented 4 years ago

@agilgur5 Wont' that cause some undesired side-effect like ignoring any files that are not placed directly in the src folder?

agilgur5 commented 4 years ago

Well you already had src, src/* isn't really any different except that it avoids this error. Using files means only things that are actually imported are compiled, which is even better. It's also in your tsconfig.build.json and you only want to include src when building. If you include files that aren't in src, TS will type-check, compile, and create declarations for those files too. In the past that has meant erroneously adding tests' or examples' declarations into dist, which shouldn't be there as library users don't use those (and that causes bloating as well as potential side-effects due to how TS merges declarations)

gustavopch commented 4 years ago

@agilgur5 Unfortunately, dist/application/definitions is not generated when I apply that workaround. Without the ./src/* workaround, it's generated.

ghost commented 1 year ago

so no fix for this issue yet rt, cause the work around is not working

hassanprodeveloper commented 8 months ago

Hi, I am also getting this error when I start a project using pnpm run start

image

here is my tsconfig.json

{ "include": ["src"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], "importHelpers": true, "declaration": true, "sourceMap": true, "baseUrl": "src", "strict": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "noUnusedParameters": true, "moduleResolution": "node", "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "resolveJsonModule": true, "noImplicitAny": false } }

here is my tsdx.config.json

const copy = require('rollup-plugin-copy'); const replace = require('@rollup/plugin-replace');

module.exports = { rollup(config, opts) { config.plugins = config.plugins.map((p) => p.name === 'replace' ? replace({ 'process.env.NODE_ENV': JSON.stringify(opts.env), preventAssignment: true, }) : p );

config.plugins.push(
  copy({
    targets: [{ src: 'src/*.d.ts', dest: 'dist/' }],
  })
);

return config;

}, }