Skip to content

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

Merged
5 commits merged into from
Nov 11, 2016

Conversation

ghost
Copy link

@ghost ghost commented Nov 2, 2016

Fixes #11977

@ghost ghost force-pushed the common_source_directory branch from 0faeba2 to e93c776 Compare November 2, 2016 14:14
@ghost ghost assigned sandersn Nov 2, 2016
@ghost ghost force-pushed the common_source_directory branch from e93c776 to 414589f Compare November 2, 2016 15:04
@sandersn
Copy link
Member

sandersn commented Nov 2, 2016

I think @vladima should take a look too.

@ghost ghost assigned vladima Nov 2, 2016
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks ok at a low level but I don't think I'm qualified to review changes to module resolution of any complexity.

if (typeof commonSourceDirectory === "undefined") {
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
if (commonSourceDirectory === undefined) {
const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary);
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For the --outDir case that makes sense since we are just emitting .ts files. Can you provide another case where we would want the .d.ts files included?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a .d.ts file to the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need a new test case:

//@filename: app/src/index.ts

//@filename: app/lib/bar.d.ts

//@filename: app/tsconfig.json

To make sure common source directory is still app

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I added a test commonSourceDirectory_dts.ts. This appears to already be the behavior of the current compiler -- the referenced file does not become part of the output.

@@ -430,13 +430,14 @@ namespace ts {
return program;

function getCommonSourceDirectory() {
if (typeof commonSourceDirectory === "undefined") {
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
if (commonSourceDirectory === undefined) {
Copy link
Member

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

Copy link
Author

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?

Copy link
Member

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?

Copy link
Author

@ghost ghost Nov 3, 2016

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.

Copy link
Member

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 ./

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

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?

Copy link
Member

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 or system and hence there is no way to get bundled emit that includes modules from node_modules folder.

@ghost ghost force-pushed the common_source_directory branch from 9006572 to 0b71df5 Compare November 3, 2016 19:33


//// [/app/bin/index.js]
"use strict";
/// <reference path="../types/bar.d.ts"/>
Copy link
Member

Choose a reason for hiding this comment

The 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...

if (typeof commonSourceDirectory === "undefined") {
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
if (commonSourceDirectory === undefined) {
const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need a new test case:

//@filename: app/src/index.ts

//@filename: app/lib/bar.d.ts

//@filename: app/tsconfig.json

To make sure common source directory is still app

@@ -430,13 +430,14 @@ namespace ts {
return program;

function getCommonSourceDirectory() {
if (typeof commonSourceDirectory === "undefined") {
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
if (commonSourceDirectory === undefined) {
Copy link
Member

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 or system and hence there is no way to get bundled emit that includes modules from node_modules folder.

@ghost ghost force-pushed the common_source_directory branch from d4786ad to 0422a75 Compare November 10, 2016 18:25
@ghost ghost merged commit 9a3dd3e into master Nov 11, 2016
@ghost ghost deleted the common_source_directory branch November 11, 2016 21:18
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants