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

Consider switching from gulp to npm scripts to reduce bloat #473

Closed
Reinmar opened this issue Jun 15, 2017 · 21 comments
Closed

Consider switching from gulp to npm scripts to reduce bloat #473

Reinmar opened this issue Jun 15, 2017 · 21 comments
Assignees
Labels
status:discussion type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Jun 15, 2017

We have ckeditor5 repository and ckeditor5-* sub repositories. Right now all of them use gulp.

As for ckeditor5 itself, it doesn't matter that much, but we already have some npm scripts there, so it's a bit messy. We could try to standardise this.

A bigger issue is with all the other packages. All of them base on gulp which isn't the most lightweight dependency and we use it to expose two simple tasks – lint and lint-staged.

So, every ckeditor5-* package depends on @ckeditor/ckeditor5-dev-lint, gulp, guppy-pre-commit which have around 380 dependencies: https://gist.github.com/Reinmar/d9633ea5bf583c6a85111a269d273995.

We install them using Lerna and only guppy-pre-commit is installed in every package physically. But it still takes a time to calculate all the deps for every package to see what needs to be hoisted to ckeditor5.

Another thing is that we have one additional file – gulpfile.js that we could remove if we switched to npm scripts. And, we could drop the ckeditor5-dev-lint package altogether if we'd be lucky.

So, the plan would be to try to implement:

  • three scripts lint, lint-staged and pre-commit,
  • automatic git pre-commit hook installation (just like guppy-pre-commit but triggering npm instead of gulp).

It seems that it can be easily done using https://github.com/okonet/lint-staged. We just need to figure out whether this will be any real improvement in terms of dependency bloat.

@Reinmar Reinmar added candidate:1.0.0 status:discussion type:improvement This issue reports a possible enhancement of an existing feature. labels Jun 15, 2017
@Reinmar
Copy link
Member Author

Reinmar commented Jun 15, 2017

I checked that lint-staged, husky and eslint mean 200 deps (https://gist.github.com/Reinmar/56b38beec29c5ad6e5a60f2824642a39). It doesn't mean that they will really install faster when installed using Lerna, but there's a good chance for that.

I also thought about one more requirement – currently, our lint tasks ignore files listed in .gitignore but also one more directory (which is specified in gulpfile.js) – lib/**. We would also need to handle this somehow.

@Reinmar
Copy link
Member Author

Reinmar commented Jul 20, 2017

There's the sweet npx now which makes gulp even less needed.

@jodator
Copy link
Contributor

jodator commented Oct 9, 2017

So I've tested lint-staged with husky and example works (does eslint --fix on staged files) both in CLI and in PHPStorm (that was my biggest issue with guppy).

The only problem would be removing existing guppy git hook. Also from Husky README:

Existing hooks aren't replaced and you can use any Git hook.

So as I understand this would require to:

  • rm -rf .git/hooks/pre-commit && rm -rf packages && npm update to remove pre-commit hook in ckeditor5 repo and the reinstall mgit dependencies.

@jodator
Copy link
Contributor

jodator commented Oct 9, 2017

After some trial and error we can add this to every project's package.json:

{
    "scripts": {
        "lint": "eslint",
        "precommit": "lint-staged"
    },
    "lint-staged": {
        "**/[^(lib)]**/*.js": [ "eslint --fix", "git add" ]
    }
}

with additional dependencies of lint-staged, husky and eslint thus removing guppy-pre-commit, gulp, @ckeditor/ckeditor5-dev-lint.

@Reinmar
Copy link
Member Author

Reinmar commented Oct 10, 2017

rm -rf .git/hooks/pre-commit && rm -rf packages && npm update to remove pre-commit hook in ckeditor5 repo and the reinstall mgit dependencies.

This will translate too (from the main project):

rm -rf .git/hooks/pre-commit
mgit exec 'rm -rf .git/hooks/pre-commit'
lerna clean && lerna bootstrap

@oleq
Copy link
Member

oleq commented Oct 10, 2017

I think that getting rid of guppy-pre-commit is a great idea because it breaks the workflow in applications like SourceTree and some IDEs too. There's no way to commit using these tools without changing manually the content of .git/hooks/pre-commit (AFAIR wrong paths, cwd, etc.).

I'd like to use SourceTree again to more than browsing and diffing—in such a distributed project, it's a must–have thing IMO.

@Reinmar
Copy link
Member Author

Reinmar commented Oct 10, 2017

Will you check if ST works fine with Husky (which replaces guppy) after @jodator will do the changes?

@jodator
Copy link
Contributor

jodator commented Oct 10, 2017

@Reinmar Husky works nice in PHPStorm so I guess that ST will work also.

@oleq
Copy link
Member

oleq commented Oct 10, 2017

Can you check it @jodator just to make sure? I'm in a totally different context at this moment.

@Reinmar
Copy link
Member Author

Reinmar commented Oct 10, 2017

BTW, please don't add --fix – its usage should be intentional. Otherwise, you might not notice that you changed some code.

@pomek
Copy link
Member

pomek commented Oct 10, 2017

And git add should not be called. We should manually add fixed files. From my point of view – I would like to see where I made a mistake (during git add -p I have such opportunity).

Reinmar added a commit that referenced this issue Oct 10, 2017
Internal: Remove gulp dependency for pre-commit linting. Closes #473.
@Reinmar Reinmar added this to the iteration 13 milestone Oct 10, 2017
Reinmar added a commit to ckeditor/ckeditor5-autoformat that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-adapter-ckfinder that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-block-quote that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-basic-styles that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-build-balloon that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-build-classic that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-clipboard that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-core that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-editor-balloon that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-editor-classic that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-link that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-image that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-markdown-gfm that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-paragraph that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-theme-lark that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-typing that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-ui that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-undo that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-upload that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-utils that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Reinmar added a commit to ckeditor/ckeditor5-widget that referenced this issue Oct 10, 2017
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
@Reinmar
Copy link
Member Author

Reinmar commented Oct 10, 2017

Actually, I realised that only part of the job was done. The other part is completely dropping gulp from the main package too.

So, let's continue the journey :)

We already have some scripts in the scripts/ directory so this will be nothing new.

@Reinmar Reinmar reopened this Oct 10, 2017
@Reinmar
Copy link
Member Author

Reinmar commented Oct 10, 2017

It also seems that we can remove gulp from install-dependencies.sh in ckeditor5-dev-tests.

@jodator
Copy link
Contributor

jodator commented Oct 11, 2017

OK I've started checking scripts and it looks that gulp would be easy to remove thanks to a way how ckeditor5-dev scripts are build 👏. For now I can see that you'd only need to change how params are passed, ie:

gulp test --files=core
# is equal to:
npm test -- --files=core

ps.: I've found only one place that uses gulp and it's ckeditor5-dev-docs.

@Reinmar
Copy link
Member Author

Reinmar commented Oct 11, 2017

There will also be the dev env and testing env guides to update after such a change.

@Reinmar
Copy link
Member Author

Reinmar commented Oct 11, 2017

BTW, how will these calls look with npx? Is the -- separator needed too?

@pomek
Copy link
Member

pomek commented Oct 11, 2017

I'm not sure whether I understood your question but the -- separator is needed for distinguishing which parameters are for npm and which for executed command.

All parameters before -- modify the npm call. The rest parameters (after --) are passed to the executed command.

@jodator
Copy link
Contributor

jodator commented Oct 11, 2017

@pomek & @Reinmar - yep those -- before command params are needed.

@Reinmar
Copy link
Member Author

Reinmar commented Oct 11, 2017

I've been asking about npx (read more here: https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b).

@pomek
Copy link
Member

pomek commented Oct 11, 2017

Npx… 😱

@jodator
Copy link
Contributor

jodator commented Oct 12, 2017

So the thing with npx is that it needs to find command in package. So some dev tools need to add "bin" to "package.json" so we can be able to use them.

So for tests we can have either:

npm t -- --files=core
# for installed script in .bin:
npx ckeditor5-dev-tests --files=core
# for command that npx cannot guess package:
npx ckeditor5-dev-tests-manual -p @ckeditor/ckeditor5-dev-test --files=core

setting node params:

# already defined in package.json
npm t
# must  be passed to npx
npx -n=--max_old_space_size=4096 ckeditor5-dev-tests
npx --node-arg=--max_old_space_size=4096 ckeditor5-dev-tests

Which for tests we can provide both: npm run-script and npx.

Other dev dependencies might be ported as well to support npx like translations:* gulp task would require to create binary ckeditor5-dev-transaltions and expose methods like collectTranslations as script param so we could run them as (currently methods are invoked in gulpfile.js:

npx ckeditor5-dev-translations -p @ckeditor/ckeditor5-dev-env collect

In the above if binary isn't named the same as package you must define from which package take binary.

Running npx commands works well if command has the same name as package:

npx @ckeditor/ckeditor5-dev-tests

Above will fetch @ckeditor/ckeditor5-dev-tests package and will run ckeditor5-dev-tests binary (and will fail due to memory requirements ;) )

Reinmar added a commit that referenced this issue Nov 13, 2017
Internal: Removed gulp dependency in favor of npm scripts. Closes #473.
JDinABox pushed a commit to JDinABox/ckeditor5-build-markdown that referenced this issue Sep 6, 2021
Internal: Removed gulp dependency for pre-commit linting. See ckeditor/ckeditor5#473.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:discussion type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

No branches or pull requests

4 participants