Skip to content
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

misc: refactor collect-strings.js to use glob and work on windows #9406

Merged
merged 17 commits into from
Jul 26, 2019

Conversation

connorjclark
Copy link
Collaborator

Fixes #9403.

`${path.sep}.git`,
`${path.sep}scripts`,
`${path.sep}node_modules`,
`${path.sep}test${path.sep}`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i kinda hate this, wb this instead

[
  '/.git',
  '/scripts',
  '/node_modules',
  '/test/',
  '-test.js',
  '-renderer.js',
].map(str => str.replace(/\//g, path.sep));

Copy link
Member

Choose a reason for hiding this comment

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

Meh, this seems even more obtuse imo.

Copy link
Collaborator

@patrickhulce patrickhulce Jul 18, 2019

Choose a reason for hiding this comment

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

I actually like @connorjclark's suggestion, the readability of the paths is the important thing IMO, the fact that we want to support multiple OS is the secondary concern, maybe just add the

// Ensure we use the OS-specific path separator comment to the map line?

@connorjclark connorjclark requested a review from exterkamp July 18, 2019 06:51
Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

LGTM, works on windows, so that's nice.

`${path.sep}.git`,
`${path.sep}scripts`,
`${path.sep}node_modules`,
`${path.sep}test${path.sep}`,
Copy link
Member

Choose a reason for hiding this comment

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

Meh, this seems even more obtuse imo.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM % nit

`${path.sep}.git`,
`${path.sep}scripts`,
`${path.sep}node_modules`,
`${path.sep}test${path.sep}`,
Copy link
Collaborator

@patrickhulce patrickhulce Jul 18, 2019

Choose a reason for hiding this comment

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

I actually like @connorjclark's suggestion, the readability of the paths is the important thing IMO, the fact that we want to support multiple OS is the secondary concern, maybe just add the

// Ensure we use the OS-specific path separator comment to the map line?

@brendankenny
Copy link
Member

sooooo...what if we just switched to using glob (already in our devDeps)? Handling OS-specific file stuff, searching for *.js files unless they match this set of patterns, and recursive subdirectory search are all included out of the box

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only "I consent." in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@paulirish
Copy link
Member

sooooo...what if we just switched to using glob

+1. I was kinda surprised to see us doing recursive directory descent ourselves.

i guess it'd be something a la

glob.sync("**/*.js", {
	ignore: ignoredPathComponents
}, fn);

though we could also read in our .gitignore and give that to ignore. Would take care of most of these.

@brendankenny
Copy link
Member

cwd would also need to be set to dir, and setting root to LH_ROOT should give the relativePath for free (which should be normalized to posix /)

@brendankenny
Copy link
Member

running yarn i18n:checks in appveyor would keep this from regressing on windows, but that involves making assert-strings-collected.sh work cross platform, so that's maybe something for the back burner :)

@vercel vercel bot temporarily deployed to staging July 18, 2019 20:38 Inactive
@connorjclark
Copy link
Collaborator Author

Updated. Will have to continue when I'm on a windows machine again. But:

  1. ignore doesn't seem to work.
  2. I don't see any affect using root when cwd is also used.

@connorjclark connorjclark changed the title misc: fix collect-strings.js for windows misc: refactor collect-strings.js to use glob and work on windows Jul 18, 2019
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

in this file's defense, it was written several months before glob was added to our deps and traversal isn't that hard :P

const files = glob.sync('**/*.js', {
cwd: dir,
// TODO: why doesn't this work ...
// ignore: ignoredPathComponents,
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably because our ignored patterns aren't globs yet :)

@brendankenny
Copy link
Member

I don't see any affect using root when cwd is also used.

whoops, root is not what we want, never mind! :)

@brendankenny
Copy link
Member

whoops, root is not what we want, never mind! :)

I think you actually want something like

glob.sync(path.posix.relative(LH_ROOT, dir) + '/**/*.js', {cwd: LH_ROOT, ignore: ignoreGlobs})

posix is important so it does the separators right (glob only takes /), and it needs to be relative (and not just ${dir}/**/*.js) so that it doesn't give absolute paths.

Maybe there's a better way, though.

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@connorjclark
Copy link
Collaborator Author

ready to gogogo

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

I believe you have the approvals @connorjclark were you wanting a re-review? :)

cwd: LH_ROOT,
ignore: ignoredPathComponents,
});
for (const relativePathToRoot of files) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for (const relativePathToRoot of files) {
for (const relativePathFromRoot of files) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

or filePathRelativeToRoot? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

relativeToRootPath to match absolutePath.

@connorjclark
Copy link
Collaborator Author

I believe you have the approvals @connorjclark were you wanting a re-review? :)

well it was 10PM and I just did a weird merge. wanted @exterkamp to stamp

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

@exterkamp probably should take a look since there is a bit changing in here and he just spent so much quality time with collect-strings :)

_processPlaceholderDirectIcu(icuDefn, examples);

Copy link
Member

@brendankenny brendankenny Jul 25, 2019

Choose a reason for hiding this comment

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

Whitespace like this comes down to author preference and should really be discussed in the original PR rather than changed in the next commit (inviting style edit wars). Presumably @exterkamp preferred it and no one brought it up in the review, so unless there's a reason to change it, the default move should be to leave it unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

+1 leave the spaces.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok sorry bud

Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

LGTM! Didn't test on Windows on the latest iteration, but I did before and it was good, and I will again later today.

_processPlaceholderDirectIcu(icuDefn, examples);

Copy link
Member

Choose a reason for hiding this comment

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

+1 leave the spaces.

@@ -382,82 +379,77 @@ const seenStrings = new Map();
let collisions = 0;

/**
* @param {string} dir
* @param {Record<string, ICUMessageDefn>} strings
* @param {string} dir absolute path
Copy link
Member

Choose a reason for hiding this comment

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

Comment on this, something like

 * Collects all lhl messsages defined in UIString vars from within Javascript files located in dir, 
 * and converts them into ctc format.

* @param {string} dir
* @param {Record<string, ICUMessageDefn>} strings
* @param {string} dir absolute path
* @return {Record<string, ICUMessageDefn>}
Copy link
Member

Choose a reason for hiding this comment

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

Good idea with the returning, I like this better!

strings[seenId].meaning = strings[seenId].description;
collisions++;
}
collisions++;
Copy link
Member

Choose a reason for hiding this comment

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

+1 to @paulirish for keeping this global so this isn't a problem 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry i have no idea what your comment is referencing but this line of code looks like i screwed up a merge?

is it supposed to double count collisions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nvm looks good

@vercel vercel bot temporarily deployed to staging July 25, 2019 22:55 Inactive
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@connorjclark
Copy link
Collaborator Author

Didn't test on Windows on the latest iteration, but I did before and it was good, and I will again later today.

i tested it already btw.

mergin'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yarn update:sample-json doesn't work on windows.
6 participants