Skip to content

resolve paths relative to tsconfig.json #421

@esc-mhild

Description

@esc-mhild

Relative paths in tsconfig.json (such as rootDir) are resolved relative to Gruntfile.js instead of tsconfig.json.
As mentioned in issue #397, this causes problems when tsconfig.json is used by other tools, such as an IDE. There are more comments in pull #399.

I am afraid to say that I could not follow the reasoning in either thread and apologize if this is repetitious. I will offer two reasons to think that the current behaviour is a bug and not a feature.

First, the Typescript documentation seems not to be explicit on resolution of relative paths (what am I missing?) except when it discusses inheritance:

All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.

However, tsc implements resolution relative to tsconfig.json. It would seem to me that grunt-ts should compile tsconfig.json correctly iff tsc -p path/to/ tsconfig.json does (when tsc is called from the parent directory of the Gruntfile). This is currently not the case.

Second, the following possible work-around is cumbersome:

  1. Author tsconfig.json with paths relative to tsconfig.json.
  2. Create an extension tsconfig.grunt.json that modifies paths for the benefit of grunt-ts.

For example, let:

projectdir/
  |-Gruntfile.js
  |-subdir/
      |-tsconfig.json
      |-tsconfig.grunt.json
      |-ts/
          |- ... ts files to compile

tsconfig.json:

{
	"compilerOptions": {
		"rootDir": "ts",
                ...
	}
}

tsconfig.json would compile correctly for use by IDE or tsc -p subdir/tsconfig.json where tsc is called from the project directory projectdir/.

tsconfig.grunt.json:

{
	"extends": "./tsconfig",
	"compilerOptions": {
		"rootDir": "subdir/ts"
	}
 }

tsconfig.grunt.json is referenced in grunt-ts via tsconfig: 'subdir/tsconfig.grunt.json'.

Many thanks for your great work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions