travis-r6s / gridsome-plugin-brotli

Gridsome plugin for preparing brotli-compressed versions of assets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wait for other afterBuild finished

agaengel opened this issue · comments

Hi I just noticed that if there is some other plugin that creates files in the output dir via api.afterBuild it happens that the brotoli plugin fails to compress all the files.

Is there some way to wait for all other plugins to finish?

For testing I added in the plugin on line 10 in the function api.afterBuild(async ({ config }) => {
await new Promise(resolve => setTimeout(resolve, 1));

and this was on my system enough to wait for the finish of the @microflash/gridsome-plugin-feed plugin that generates rss and atom feeds that then are compressed by the brotoli plugin.

Regards
Alex

Hi, I'm seeing very much the same as @agaengel. I'm using brotli plugin and also gridsome-plugin-feed. Brotli plugin is failing on writeFileAsync here on line 24.

Usually happens for just a few files, e.g. in this run, only 2 out of 53 files failed. Here's the output where I've printed out the source / dest / error:

Output
Compressing build with Brotli...
{
  destFileName: '/Users/presenter/repos/jurooravec-site/new/jurooravec-site/dist/public/assets/data/contact/index.json.br',
  destFilePath: '/Users/presenter/repos/jurooravec-site/new/jurooravec-site/dist/public',
  srcFileName: '/Users/presenter/repos/jurooravec-site/new/jurooravec-site/dist/public/assets/data/contact/index.json',
  err: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received null
      at writeFile (node:fs:2106:5)
      at node:internal/util:360:7
      at new Promise ()
      at writeFile (node:internal/util:346:12)
      at compressFile (/Users/presenter/repos/jurooravec-site/new/jurooravec-site/node_modules/gridsome-plugin-brotli/worker.js:25:11) {
    code: 'ERR_INVALID_ARG_TYPE'
  }
}
{
  destFileName: '/Users/presenter/repos/jurooravec-site/new/jurooravec-site/dist/public/assets/data/about/index.json.br',
  destFilePath: '/Users/presenter/repos/jurooravec-site/new/jurooravec-site/dist/public',
  srcFileName: '/Users/presenter/repos/jurooravec-site/new/jurooravec-site/dist/public/assets/data/about/index.json',
  err: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received null
      at writeFile (node:fs:2106:5)
      at node:internal/util:360:7
      at new Promise ()
      at writeFile (node:internal/util:346:12)
      at compressFile (/Users/presenter/repos/jurooravec-site/new/jurooravec-site/node_modules/gridsome-plugin-brotli/worker.js:25:11) {
    code: 'ERR_INVALID_ARG_TYPE'
  }
}
Brotli compressed 53 files in 40.545 s

When I try / catch the writeFileAsync call, the brotli files are not created for the failed files, but at least it doesn't crash the build.

@thetre97 I made an MR here #10. It doesn't fix the issue per se, but it does allow the build to complete even if some files fail to be compressed.

Hi @JuroOravec,

i released a new plugin for precompressiong https://gridsome.org/plugins/gridsome-plugin-precompress that generates gz and br.

You can set a wait time until the plugin start generating this at leased worked for my project.

@thetre97 as we discussed in the emial I released the new plugin.

Regards
Alex

@agaengel Nice, thanks - I'll update the readme here to point to it.
@JuroOravec Does the above updated package work for you?

@agaengel @thetre97 Thanks a lot, I've just used @agaengel's plugin and it works well!