-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Leave files from node_modules
out when calculating getCommonSourceDirectory
#11993
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
Changes from all commits
2eca0af
0b71df5
07630e9
0422a75
b65729e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -431,13 +431,14 @@ namespace ts { | |
return program; | ||
|
||
function getCommonSourceDirectory() { | ||
if (typeof commonSourceDirectory === "undefined") { | ||
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { | ||
if (commonSourceDirectory === undefined) { | ||
const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ignoring .d.ts files in the own compilation as well ? (not from external library) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. For the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But right now we didnt ignore .d.ts files from our own program to compute the common source directory? So this is intended change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need a new test case:
To make sure common source directory is still There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I added a test |
||
if (options.rootDir && checkSourceFilesBelongToPath(emittedFiles, options.rootDir)) { | ||
// If a rootDir is specified and is valid use it as the commonSourceDirectory | ||
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory); | ||
} | ||
else { | ||
commonSourceDirectory = computeCommonSourceDirectory(files); | ||
commonSourceDirectory = computeCommonSourceDirectory(emittedFiles); | ||
} | ||
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) { | ||
// Make sure directory path ends with directory separator so this string can directly | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [tests/cases/compiler/commonSourceDirectory.ts] //// | ||
|
||
//// [index.ts] | ||
// Test that importing a file from `node_modules` does not affect calculation of the common source directory. | ||
|
||
export const x = 0; | ||
|
||
//// [bar.d.ts] | ||
declare module "bar" { | ||
export const y = 0; | ||
} | ||
|
||
//// [index.ts] | ||
/// <reference path="../types/bar.d.ts"/> | ||
import { x } from "foo"; | ||
import { y } from "bar"; | ||
x + y; | ||
|
||
|
||
//// [/app/bin/index.js] | ||
"use strict"; | ||
/// <reference path="../types/bar.d.ts"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is my point... without this change it would have been bin/app/index.js -- so is this really what we want.. and this would be breaking change.. @mhegazy to take a look and confirm this is indeed expected change... |
||
var foo_1 = require("foo"); | ||
var bar_1 = require("bar"); | ||
foo_1.x + bar_1.y; | ||
//# sourceMappingURL=/app/myMapRoot/index.js.map | ||
|
||
//// [/app/bin/index.d.ts] | ||
/// <reference path="../../types/bar.d.ts" /> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
=================================================================== | ||
JsFile: index.js | ||
mapUrl: /app/myMapRoot/index.js.map | ||
sourceRoot: /app/mySourceRoot/ | ||
sources: index.ts | ||
=================================================================== | ||
------------------------------------------------------------------- | ||
emittedFile:/app/bin/index.js | ||
sourceFile:index.ts | ||
------------------------------------------------------------------- | ||
>>>"use strict"; | ||
>>>/// <reference path="../types/bar.d.ts"/> | ||
1 > | ||
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
1 > | ||
2 >/// <reference path="../types/bar.d.ts"/> | ||
1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) | ||
2 >Emitted(2, 42) Source(1, 42) + SourceIndex(0) | ||
--- | ||
>>>var foo_1 = require("foo"); | ||
1 > | ||
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
3 > ^-> | ||
1 > | ||
> | ||
2 >import { x } from "foo"; | ||
1 >Emitted(3, 1) Source(2, 1) + SourceIndex(0) | ||
2 >Emitted(3, 28) Source(2, 25) + SourceIndex(0) | ||
--- | ||
>>>var bar_1 = require("bar"); | ||
1-> | ||
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
1-> | ||
> | ||
2 >import { y } from "bar"; | ||
1->Emitted(4, 1) Source(3, 1) + SourceIndex(0) | ||
2 >Emitted(4, 28) Source(3, 25) + SourceIndex(0) | ||
--- | ||
>>>foo_1.x + bar_1.y; | ||
1 > | ||
2 >^^^^^^^ | ||
3 > ^^^ | ||
4 > ^^^^^^^ | ||
5 > ^ | ||
6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> | ||
1 > | ||
> | ||
2 >x | ||
3 > + | ||
4 > y | ||
5 > ; | ||
1 >Emitted(5, 1) Source(4, 1) + SourceIndex(0) | ||
2 >Emitted(5, 8) Source(4, 2) + SourceIndex(0) | ||
3 >Emitted(5, 11) Source(4, 5) + SourceIndex(0) | ||
4 >Emitted(5, 18) Source(4, 6) + SourceIndex(0) | ||
5 >Emitted(5, 19) Source(4, 7) + SourceIndex(0) | ||
--- | ||
>>>//# sourceMappingURL=/app/myMapRoot/index.js.map |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=== /app/index.ts === | ||
/// <reference path="../types/bar.d.ts"/> | ||
import { x } from "foo"; | ||
>x : Symbol(x, Decl(index.ts, 1, 8)) | ||
|
||
import { y } from "bar"; | ||
>y : Symbol(y, Decl(index.ts, 2, 8)) | ||
|
||
x + y; | ||
>x : Symbol(x, Decl(index.ts, 1, 8)) | ||
>y : Symbol(y, Decl(index.ts, 2, 8)) | ||
|
||
=== /node_modules/foo/index.ts === | ||
// Test that importing a file from `node_modules` does not affect calculation of the common source directory. | ||
|
||
export const x = 0; | ||
>x : Symbol(x, Decl(index.ts, 2, 12)) | ||
|
||
=== /types/bar.d.ts === | ||
declare module "bar" { | ||
export const y = 0; | ||
>y : Symbol(y, Decl(bar.d.ts, 1, 16)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
=== /app/index.ts === | ||
/// <reference path="../types/bar.d.ts"/> | ||
import { x } from "foo"; | ||
>x : 0 | ||
|
||
import { y } from "bar"; | ||
>y : 0 | ||
|
||
x + y; | ||
>x + y : number | ||
>x : 0 | ||
>y : 0 | ||
|
||
=== /node_modules/foo/index.ts === | ||
// Test that importing a file from `node_modules` does not affect calculation of the common source directory. | ||
|
||
export const x = 0; | ||
>x : 0 | ||
>0 : 0 | ||
|
||
=== /types/bar.d.ts === | ||
declare module "bar" { | ||
export const y = 0; | ||
>y : 0 | ||
>0 : 0 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//// [tests/cases/compiler/commonSourceDirectory_dts.ts] //// | ||
|
||
//// [bar.d.ts] | ||
// Test that importing a file from `node_modules` does not affect calculation of the common source directory. | ||
|
||
declare const y: number; | ||
|
||
//// [index.ts] | ||
/// <reference path="../lib/bar.d.ts" /> | ||
export const x = y; | ||
|
||
|
||
//// [/app/bin/index.js] | ||
"use strict"; | ||
/// <reference path="../lib/bar.d.ts" /> | ||
exports.x = y; | ||
//# sourceMappingURL=/app/myMapRoot/index.js.map | ||
|
||
//// [/app/bin/index.d.ts] | ||
/// <reference path="../lib/bar.d.ts" /> | ||
export declare const x: number; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also used by maproot and sourceroot.. So not doing this for bundle emit has effect on how the paths would be represented... Because --mapRoot --sourceRoot --outFile is a valid option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write a test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the files exist in node_modules and src folder and --sourceroot is specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
--sourceRoot
is specified, then the"sourceRoot"
property in the source map is whatever you specified.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but the paths are relative to common source directory and with this change the commonsourcedirectory would be different from what it used to be if say eg your sources are in ./src/ and ./node_modules/ which means the sources will be just relative to ./src/ instead or ./
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the section @sheetalkamat is referring to: https://github.com/Microsoft/TypeScript/blob/4a906143c62fcbfe113bf3f1cc607c488df47400/src/compiler/sourcemap.ts#L171-L180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote a test case. @sheetalkamat could you look at the baselines and tell me if they're what you would expect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think test case is ok, and realized that scenario I was talking about sourceroot and maproot works because --out is only allowed with
amd
orsystem
and hence there is no way to get bundled emit that includes modules fromnode_modules
folder.