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

Implement liftoff into grunt-cli #117

Merged
merged 5 commits into from
Aug 15, 2018
Merged

Implement liftoff into grunt-cli #117

merged 5 commits into from
Aug 15, 2018

Conversation

shama
Copy link
Member

@shama shama commented Feb 10, 2018

Ref: https://github.com/gruntjs/rfcs/blob/master/text/0001-liftoff.md

This is a conservative implementation of Liftoff into grunt-cli. It should be fully backwards compatible with existing Grunt versions. It needs a bit more vetting though to be sure.

This adds the ability to write your Gruntfile in any language: Gruntfile.ts, Gruntfile.coffee, Gruntfile.babel.js and many others. Or if the language isnt natively supported, you can run your own: grunt --require custom-lang/register.

You can also now specify v8 flags, so grunt --harmony gets passed to the node process (maybe not as useful these days but at least it can now).


Down the road, this change will allow us to remove the coffeescript dependency and lib/grunt/cli.js (among other related deps). When we do so, anyone who previously had a Gruntfile.coffee, would need to separately npm install coffeescript but the good news is they'll no longer be stuck to our old version. But all that can wait until we do a grunt@2.0.0 release.

@shama shama requested a review from vladikoff February 10, 2018 05:42
@jsf-clabot
Copy link

jsf-clabot commented Feb 10, 2018

CLA assistant check
All committers have signed the CLA.

@shama
Copy link
Member Author

shama commented Mar 5, 2018

FYI, I've been using this branch as my grunt command for the past 2 weeks on all my projects. Everything has been 👍. There are a few more edge cases I want to test and then will merge/release this.

bin/grunt Outdated
var options = nopt(known, aliases, process.argv, 2);

if (options.version) {
console.log('grunt-cli v' + pkg.version);
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 you need to exit after this line as it will cause an exception in the line 53. Here is what I got when I run grunt --version:

$ grunt --version
grunt-cli v1.2.0

assert.js:84
  throw new assert.AssertionError({
  ^
AssertionError: missing path
    at Module.require (module.js:502:3)
    at require (internal/module.js:20:19)
    at Liftoff.<anonymous> (/home/arkni/.local/lib/node_modules/grunt-cli/bin/grunt:53:17)
    at Liftoff.execute (/home/arkni/.local/lib/node_modules/grunt-cli/node_modules/liftoff/index.js:203:12)
    at module.exports (/home/arkni/.local/lib/node_modules/grunt-cli/node_modules/flagged-respawn/index.js:51:3)
    at Liftoff.<anonymous> (/home/arkni/.local/lib/node_modules/grunt-cli/node_modules/liftoff/index.js:195:5)
    at Liftoff.<anonymous> (/home/arkni/.local/lib/node_modules/grunt-cli/node_modules/liftoff/index.js:170:7)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Copy link
Member

Choose a reason for hiding this comment

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

Note that I runned that command in an arbitrary folder which doesn't have Grunt installed to its node_modules.

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 that would be fixed by doing the same as the original version of the CLI: exit if the modulePath is not defined and the user requested the version of the CLI.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sweet, fixed. Thanks for the review!

bin/grunt Outdated

// Do stuff based on CLI options.
if ('completion' in options) {
completion.print(options.completion);
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to drop the completion command line flag? If someone was configuring the auto-completion as pointed in the README, they will only see Grunt trying to run their tasks directly after opening a new terminal session, which will result in an exception simular to the one in my other comment.

Copy link
Member

@vladikoff vladikoff left a comment

Choose a reason for hiding this comment

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

r+ with comment

package.json Outdated
"interpret": "^1.1.0",
"liftoff": "^2.5.0",
"nopt": "^4.0.1",
"v8flags": "^3.0.1"
Copy link
Member

Choose a reason for hiding this comment

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

are you sure you want to change from ~ to ^?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed! Thanks!

@tkellen
Copy link
Member

tkellen commented Mar 15, 2018

@shama, @vladikoff, @Arkni, ya'll are saints. Thank you for working on this!

@shama
Copy link
Member Author

shama commented Mar 16, 2018

One part I'm having second thoughts about is whether to support all the v8 flags. At the moment, v8flags needs to shell out node --v8-options to get the list of options. This adds a tiny perf hit in the beginning and takes a lot of options from userland.

The alternative is someone could do node --harmony ./node_modules/.bin/grunt --my-flag if they needed to run node with a specific flag.

@vladikoff
Copy link
Member

a tiny perf hit

If it's a really tiny hit that's fine.

@tkellen
Copy link
Member

tkellen commented Mar 23, 2018

@shama That perf hit is only incurred once, we cache the output and read it from a file after subsequent runs.

@jorrit
Copy link

jorrit commented May 7, 2018

Is anything holding this issue back? It sounds great!

@vladikoff
Copy link
Member

Soon.

@vladikoff vladikoff merged commit eaf78d6 into master Aug 15, 2018
@shama shama deleted the liftoff branch August 19, 2018 01:51
Krinkle added a commit to Krinkle/grunt that referenced this pull request Jul 20, 2024
* grunt-cli updated to nopt 4.x in gruntjs/grunt-cli#117
* grunt-cli updated to nopt 5.0 in gruntjs/grunt-cli#156
* changelog: https://github.com/npm/nopt/blob/v5.0.0/CHANGELOG.md

The simple usage of `nopt(known, alias, argv, 2)` has remained
unchanged through both changes, same as in this repo.

Installation of latest grunt- produces a warning:

> npm WARN deprecated osenv@0.1.5: This package is no longer supported.

This package was used by nopt to call `os.homedir()` which has been built-in
since Node.js 2. The dependency was removed in nopt 5.0.0 with
npm/nopt@5c0e45b.

Newer versions of nopt are available, but those raise the required
Node.js engine level. In order to make this safe to land, and easy to release,
resolve the warning first by moving to nopt 5.0.0, matching grunt-cli.

I'm loosening grunt-cli to allow for grunt-cli 1.5.0, which was just
released with a similar fix. This way it will update by default, but
not cause duplicate installations for downstream projects that depend
on grunt-cli 1.4 directly.
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.

6 participants