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

refactor(writing-styles): add postinstall script to download vale binary based on OS platform #131

Merged
merged 2 commits into from
Dec 10, 2019

Conversation

emmenko
Copy link
Member

@emmenko emmenko commented Dec 9, 2019

This PR further improves the writing-styles package.

I noticed that the vale binary files takes up a few megabytes each, causing the package to be around 25Mb. This is a bit annoying when publishing and installing the package, as it just takes longer.

We don't need to ship the binary with the package, instead we can use a postinstall script to download the binary "on demand" upon package installation, according to the OS platform. This also ensures that we only download the proper binary and not all of them.

@vercel
Copy link

vercel bot commented Dec 9, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/commercetools/commercetools-docs-kit/ezhpju1rg
🌍 Preview: https://commercetools-docs-kit-git-nm-writing-styles-postinstall-vale.commercetools.now.sh

*.zip
*.tar.gz
bin/vale
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't put it in version control anymore

const destPath = path.join(__dirname, '../bin');

console.log('[writing-styles] Verifying vale installation...');
if (fs.existsSync(path.join(destPath, 'vale'))) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't download it again if a binary file is already there.

nkuehn
nkuehn previously requested changes Dec 9, 2019
Copy link
Collaborator

@nkuehn nkuehn left a comment

Choose a reason for hiding this comment

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

I now remember why I ended up just committing the binaries. Windows should work in a tool that targets developers but also writers and even marketing.

packages/writing-style/scripts/download-vale.js Outdated Show resolved Hide resolved
packages/writing-style/scripts/download-vale.js Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to staging December 9, 2019 21:42 Inactive
@emmenko
Copy link
Member Author

emmenko commented Dec 9, 2019

@nkuehn alright please have another look, I re-wrote the script to be cross-platform compatible.

@emmenko emmenko requested a review from nkuehn December 9, 2019 21:43
@emmenko emmenko force-pushed the nm-writing-styles-postinstall-vale branch from 924649d to 538ed22 Compare December 9, 2019 21:46
@vercel vercel bot temporarily deployed to staging December 9, 2019 21:46 Inactive
@emmenko emmenko force-pushed the nm-writing-styles-postinstall-vale branch from 538ed22 to 5840ac1 Compare December 9, 2019 21:51
@vercel vercel bot temporarily deployed to staging December 9, 2019 21:51 Inactive
@emmenko emmenko dismissed nkuehn’s stale review December 10, 2019 10:49

Change requests have been addressed

Copy link
Collaborator

@nkuehn nkuehn left a comment

Choose a reason for hiding this comment

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

I think this is running circles (see comment) and am confused about what the original intent of this change was.
But since it's working and of secondary importance let's move on.

const path = require('path');
const fetch = require('node-fetch');
const shelljs = require('shelljs');
const { path7za } = require('7zip-bin');
Copy link
Collaborator

@nkuehn nkuehn Dec 10, 2019

Choose a reason for hiding this comment

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

Sorry to be stubborn., but this is a bit absurd - we're doing a refactor to get rid of 8-10MB sized binaries committed and to be able to do that we pull a package for unzipping them that is by itself a 9MB binary committed into NPM.

What was the original problem with committed binaries? If we think it's a bad pattern to work with committed binaries we shouldn't use 7zip-bin. If we deem the pattern OK why do we need this whole refactor?
I guess it's not to save CircleCI 20MB of network egress.

Copy link
Member Author

Choose a reason for hiding this comment

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

we're doing a refactor to get rid of 8-10MB sized binaries committed and to be able to do that we pull a package for unzipping them that is by itself a 9MB binary committed into NPM

Yes it's a bit unfortunate but it's still better then before for the following reasons:

  • 7zip-bin is an external dependency, so we don't need to "deal" with the package size directly
  • our current package is 46.3MB as opposed to the 7zip-bin which is only 8.84MB

image

image

  • our package now is just a few kb, which makes publishing faster (and less error prone)

So I still think there is a good benefit of doing this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, it's not worth investing another hour to make it completely. It's odd-ish that uncompressing is so cumbersome in node, didn't expect that.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is not much about node, but uncompressing in windows

@emmenko emmenko merged commit 66162c9 into master Dec 10, 2019
@emmenko emmenko deleted the nm-writing-styles-postinstall-vale branch December 10, 2019 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants