Skip to content

Exclude legacy safelist files in external projects #19542

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
merged 9 commits into from
Nov 10, 2017

Conversation

RyanCavanaugh
Copy link
Member

Fixes half of #19533

image

@amcasey
Copy link
Member

amcasey commented Oct 27, 2017

                    this.logger.info(`Excluding files based on rule ${name}`);

While I was poking around, I noticed that this didn't include the name of the file being excluded. Would you mind adding that?


Refers to: src/server/editorServices.ts:2155 in da63c2c. [](commit_id = da63c2c, deletion_comment = False)

const inferredTypingName = removeFileExtension(baseName);
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
if (this.legacySafelist[cleanedTypingName]) {
this.logger.info(`Excluded '${normalizedNames[i]}'`);
Copy link
Member

Choose a reason for hiding this comment

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

this.logger.info(Excluded '${normalizedNames[i]}'); [](start = 32, length = 53)

I think it would be helpful (and consistent) to indicate why the file is being excluded (i.e. legacy safelist).

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

:shipit:

@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2017

Can you also add a test.

* Takes a string like "jquery-min.4.2.3" and returns "jquery"
*/
export function removeMinAndVersionNumbers(fileName: string) {
return fileName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
Copy link
Member

Choose a reason for hiding this comment

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

This also removes digits without the min, for example "jquery.4.2-test" also becomes "jquery-test". Probably not intended. (Also why use non-capturing groups (i.e. (?: )? You are not using the groups for anything, so it's just syntactic noise).

Copy link
Member Author

Choose a reason for hiding this comment

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

What exactly should the rule be? Remove all characters after the first . if the thing after the . is min or a number?

Copy link
Member Author

Choose a reason for hiding this comment

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

@DanielRosenwasser wrote us a nice regex

@@ -2417,7 +2417,13 @@ namespace ts {
* Takes a string like "jquery-min.4.2.3" and returns "jquery"
*/
export function removeMinAndVersionNumbers(fileName: string) {
return fileName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
const match = /((\w|(-(?!min)))+)(\.|-)?.*/.exec(fileName);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this also take something like "foo.bar.js", and turn it into just "foo.js"? Is that intended?

Copy link
Member

Choose a reason for hiding this comment

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

I just whipped up the below, which seems to work. Take a look and see what you think.

Note: I don't think we need to worry about .jsx files being library files, or trying to handle suffixes like "-beta" after the min or version.

function removeMinAndVersionNumbers(path) {
  // Match a "." or "-" followed by a version number or 'min', that occurs right before the final ".js"
  let trailingMinOrVersion = /[.-]((min)|(\d+(\.\d+)*))\.js$/;

  // The "min" or version may both be present, in either order, so try applying the above twice.
  // Note the final ".js" is part of the match, so add this back as the substitution.
  let result = path.replace(trailingMinOrVersion, ".js").replace(trailingMinOrVersion, ".js");
  return result;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't handle jquery.6.min.js; not sure how common that is

Copy link
Member

Choose a reason for hiding this comment

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

Yes it does. I just tried it in the Console.

removeMinAndVersionNumbers("jquery.6.min.js");
"jquery.js"

/**
* Takes a string like "jquery-min.4.2.3" and returns "jquery"
*/
export function removeMinAndVersionNumbers(fileName: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this function in compiler? Can it be part of services\utilities instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This functions needs to be used in the typings installer and in tsserver; I couldn't find another file that was shared by them. services\utilities isn't involved in the typings installer and adding it introduced more errors because it needs references to e.g. Project

["jquery-min.4.2.3", "jquery"],
// ["jquery.4.2-test.js", "jquery"],
["jquery.min.4.2.1", "jquery"],
// ["jquery.7.min.js", "jquery"],
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 pretty much the same format as the case you thought didn't work. Any reason not to include it? (without the .js, if that's already removed by the time it gets here).

Also, why leave commented out tests? It looks like they should pass but are currently failing. We should just remove them if that is not the behavior we want (or enable them and change the expectations to the correct behavior).

@RyanCavanaugh RyanCavanaugh merged commit de7fbc0 into microsoft:master Nov 10, 2017
RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this pull request Nov 16, 2017
RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this pull request Nov 16, 2017
RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this pull request Nov 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
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