GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add a new project root option (fixes #1513). by msprotz · Pull Request #2034 · microsoft/TypeScript

Conversation

@msprotz

@msprotz Jonathan Protzenko (defunct account, use @protz now) (msprotz) commented Feb 14, 2015

Copy link
Copy Markdown

When generating source maps, if the sourceRoot option is specified and the
projectRoot is specified, then the filenames that appear in the "sources" field
of the source map are relative to the projectRoot.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@protz
Add a new project root option (fixes microsoft#1513).
5c24df0
When generating source maps, if the sourceRoot option is specified and the
projectRoot is specified, then the filenames that appear in the "sources" field
of the source map are relative to the projectRoot.
@msftclas

Microsoft Contribution License Agreements (msftclas) commented Feb 14, 2015

Copy link
Copy Markdown

Hi Jonathan Protzenko (defunct account, use @protz now) (@msprotz), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Jonathan Protzenko). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Feb 14, 2015
@msprotz

Jonathan Protzenko (defunct account, use @protz now) (msprotz) commented Feb 14, 2015

Copy link
Copy Markdown
Author

This is a preliminary pull request to discuss the proposed change. (There's no test at the moment.) I'd be happy to know whether the change looks good, or if you'd rather have me modify something.

Thanks,

Jonathan

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Feb 16, 2015

Copy link
Copy Markdown
Contributor

Thanks for the PR.

+1 for the flag, i think it is a common pain point and we need to fix it. A few comments though,

  • I do not think it should be "projectRoot" i do not think the word project is well defined in this context. I think it is more about CommonSourceDirectory calculation, and the name should reflect that. May be "commonSourceRoot" (it should have been soruceRoot, but unfortunately we used that to mean something slightly different).
  • We would need to check that it is really a commonDirectory, sometimes a common path is not possible (e.g. sources on different directories) and we emit files to locations relative to the common path, and if that is not correct you could overwrite files silently, and that is bad. verifyCompilerOptions in program.ts is a good place for that checking, and it already has some of that logic.
  • Once you have figured out the common path, you just want the normal soucemap emit to happen, without jamming the projectRoot value in there. that is what sourceMap is for.
  • you also need tests :), look at project tests under tests\cases\project (and their contents under tests\cases\projects) for examples.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msprotz

Jonathan Protzenko (defunct account, use @protz now) (msprotz) commented Feb 16, 2015

Copy link
Copy Markdown
Author

Thanks for the review!

  1. I agree about changing the name of the option, commonSourceRoot seems fine.

  2. I don't understand your remark about overwriting files silently. The option I introduce has no effect whatsoever on code generation, it only affects the sources field of the sourceMap. Here's an example.

# without the patch
protz@Joprotze-Z420:/cygdrive/d/t $ tsc --sourceRoot "http://localhost/editor/local" --sourceMap --module commonjs a/a.ts
protz@Joprotze-Z420:/cygdrive/d/t $ cat a/a.js.map 
{"version":3,"file":"a.js","sourceRoot":"http://localhost/editor/local/","sources":["a.ts"],"names":["a"],"mappings":"AAAA,SAAgB,CAAC;AAAKA,CAACA;AAAP,SAAC,GAAD,CAAO,CAAA"}
# with the patch
protz@Joprotze-Z420:/cygdrive/d/t $ node ../TypeScript/built/local/tsc.js --projectRoot . --sourceRoot "http://localhost/editor/local/" --sourceMap --module commonjs a/a.ts && cat a/a.js.map
{"version":3,"file":"a.js","sourceRoot":"http://localhost/editor/local/","sources":["a/a.ts"],"names":[],"mappings":"AAAA,SAAgB,CAAC;AAAD,SAAC,GAAD,CAAO,CAAA"}

Which files get generated, and where they get generated, remains unchanged.

Furthermore, there is no way the code can figure out by itself that the common source root is ., not ./a... so I don't think I can improve the common source directory calculation, because in the example above, we just can't compute it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Feb 23, 2015

Copy link
Copy Markdown
Contributor

Sorry for the delay. yes that is one application of a commonRoot, other ones are related to --outDir use, where you want to mimic the input directory structure in the output (this is where my overwrite comment fits). I thnink plugging this in the common path calculation would work for outDir as well as your scenario, is that accurate?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Mar 30, 2015

Copy link
Copy Markdown
Contributor

Jonathan Protzenko (defunct account, use @protz now) (@msprotz) can you refresh and resubmit?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) closed this Mar 30, 2015
@basarat

Basarat Ali Syed (basarat) commented Mar 30, 2015

Copy link
Copy Markdown
Contributor

Shouldn't commonSourceRoot be driven by the location of tsconfig.json ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Mar 30, 2015

Copy link
Copy Markdown
Contributor

it think this is fair. currently it is the longest common path of all input files.. so

a
| __ c 
       | __ b.ts
       | __ c.ts

so the common root is a\c

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basarat

Basarat Ali Syed (basarat) commented Mar 31, 2015

Copy link
Copy Markdown
Contributor

I would expect:

a
| __ tsconfig.json
| __ c 
       | __ b.ts
       | __ c.ts

the common root to be a.

Consider tsconfig.json with an outDir ./b. I would expect:

a
| __ tsconfig.json
| __ c 
       | __ b.ts
       | __ c.ts
| __ b
       | __ c 
              | __ b.js
              | __ c.js

i.e copy the entire structure starting from tsconfig.json into the directory b.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Mar 31, 2015

Copy link
Copy Markdown
Contributor

i think this makes sense.

I would say we need a new commandline argument, to allow you to change that if you are not using a tsconfig.json or you want to modified. i am thinking of --commonSourceRoot.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msprotz

Jonathan Protzenko (defunct account, use @protz now) (msprotz) commented Mar 31, 2015

Copy link
Copy Markdown
Author

The suggestions above definitely make sense, both for the output file hierarchy and the source maps. The trick about using tsconfig.json or, if no such file is present, an option, seems good to me.

(--commonSourceRoot is fine, I also thought of it in #2034 (comment)).

I just need to update the patch so that the option is also used when computing the output file names. I'll try to find some time to do that soon.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basarat

Basarat Ali Syed (basarat) commented Mar 31, 2015

Copy link
Copy Markdown
Contributor

I've requested something like this in the past, I called it baseDir : #287 was rejected. I did end up agreeing with Ryan Cavanaugh (@RyanCavanaugh)'s choice of not adding another tsc flag that can be taken care elsewhere (even though it wasn't at that time).

I also like it to be implict now that we have tsconfig.json. Don't want to end up with:

a
| __ tsconfig.json
| __ c 
       | __ b.ts
       | __ c.ts
       | __ d 
              | __ b.ts
              | __ c.ts

where tsconfig.json has a completely irrational commonSourceRoot like ./c/d.

tsconfig.json is the source root.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Apr 6, 2015
Empty parent directories are not preserved with --outDir #2644
Closed
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Apr 15, 2015
Add new compiler option --rootDir #2772
Merged
@mhegazy

Mohamed Hegazy (mhegazy) commented Apr 15, 2015

Copy link
Copy Markdown
Contributor

Basarat Ali Syed (@basarat), as i started working on this I realized that the implicit tsconfig.json path will not work, as the rootDir/baseDir has to encompass all input files, but tsconfig.json does not have this restriction. "files" property can reference files outside the directory, and /// references as well as imports can pull in files from outside the directory. we do not want to make these an error, specially that you only care about this if you have outDir. you can always specify a rootDir in your tsconfig to always be "." to work around this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basarat

Basarat Ali Syed (basarat) commented Apr 15, 2015

Copy link
Copy Markdown
Contributor

Okay ❤️

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basarat

Basarat Ali Syed (basarat) commented Apr 21, 2015

Copy link
Copy Markdown
Contributor

"files" property can reference files outside the directory

Worth mentioning: If someone does that then they are going to have a really hard time if they open a file that doesn't have tsconfig.json up the directory tree.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basarat Basarat Ali Syed (basarat) mentioned this pull request May 4, 2015
Improve TS 1.5 support. TypeStrong/atom-typescript#323
Closed
@basarat Basarat Ali Syed (basarat) mentioned this pull request Oct 19, 2015
Stop creating .baseDir.ts file TypeStrong/grunt-ts#300
Open
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@msprotz @msftclas @mhegazy @basarat @protz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.