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

Remove hardcoded node_modules in gulpfile. #8890

Merged
merged 1 commit into from
Jun 1, 2020
Merged

Remove hardcoded node_modules in gulpfile. #8890

merged 1 commit into from
Jun 1, 2020

Conversation

mramato
Copy link
Contributor

@mramato mramato commented Jun 1, 2020

  1. Use npx to execute binaries rather than hardcoded node_modules/.bin, which may not always be the right location.

  2. Streamline generateDocumentation by calling it sync.

@thw0rted when you get a chance can you verify this fixes the issues you were having? Should be same or close to the same as the changes you originally proposed.

1. Use `npx` to execute binaries rather than hardcoded `node_modules/.bin`,
which may not always be the right location.

2. Streamline generateDocumentation by calling it sync.
@cesium-concierge
Copy link

Thanks for the pull request @mramato!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.


//Run cloc on primary Source files only
var source = new Promise(function (resolve, reject) {
cmdLine =
"perl " +
clocPath +
"npx cloc" +
Copy link
Member

@kring kring Jun 1, 2020

Choose a reason for hiding this comment

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

I guess npx is ok, because it should run the version in node_modules/.bin if it exists, and only install the package if it doesn't already exist. This is important because installing the package from npm could end up installing the wrong version.

But it really shouldn't be necessary to use npx in any case. Previously we were using node_modules/cloc/lib/cloc, which is not guaranteed to work. The cloc package can be hoisted somewhere else for various reasons. This is not true of node_modules/.bin, though. The .bins should always be present, as long as the package has actually been installed. So node_modules/.bin/cloc should be equivalent to npx cloc except that the former won't ever install cloc or execute some random thing with that name from your path.

And if we do need to run node_modules/clock/lib/cloc directly (rather than the thing in .bin), you can just ask node to resolve it first. Something like this (not tested):

const clocPath = path.resolve(path.dirname(require.resolve("cloc/package.json")), "cloc", "lib", "cloc");

Copy link
Contributor

Choose a reason for hiding this comment

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

Kevin, the original problem that prompted this change was a literal node_modules/.bin/something in the gulpfile, which is only correct if you're not on Windows. This PR seems like a good opportunity to pick one consistent means of path construction and stick to it.

I never realized that npx will install missing packages -- kind of neat I guess? -- but if that's any kind of concern, there's a --no-install flag that you could use on all these invocations.

Copy link
Member

Choose a reason for hiding this comment

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

@thw0rted Windows stores the binaries in node_modules/.bin, too. One potential gotcha, though, is that, on Windows, the programs in .bin are actually cmd scripts with a .cmd extension. So doing child_process.exec("node_modules/.bin/cloc", ...) won't work because there's no file called cloc and possibly also because cloc.cmd is not an executable. Long story short, add shell: true as an option to the exec call and you'll be good to go.

Is all this better than just using npx? Especially with --no-install? I guess not. After reading up on it some more, npx is better suited to this than I remembered. Carry on. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to the path separator. node_modules/.bin/cloc does not work but I believe in my testing node_modules\\.bin\\.cloc worked. Anyway, I like how npx shows intent, handles nesting, global installs, etc. Ever since I discovered it a few years ago I've been trying to spread the word 😁

Copy link
Member

Choose a reason for hiding this comment

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

Weird, Windows is usually ok with forward slashes. 🤷

@thw0rted
Copy link
Contributor

thw0rted commented Jun 1, 2020

@mramato LGTM -- I just ran build-ts and generateDocumentation and both completed without incident.

@kring kring merged commit d342d4c into master Jun 1, 2020
@kring kring deleted the npx branch June 1, 2020 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants