minify icon indicating copy to clipboard operation
minify copied to clipboard

Error on overwriting file with minified content

Open rschristian opened this issue 3 years ago • 6 comments

I'd like to use this tool in my CD pipeline to overwrite a simple HTML file I have for a site. However, using the same input & output throws an error and does not succeed.

➜  start_page git:(master) ✗ npx minify static/index.html > static/index.html
npx: installed 25 in 2.483s
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(data)

    at AsyncFunction.module.exports [as html] (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/html.js:38:5)
    at onDataRead (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/minify.js:75:44)
    at optimize (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/minify.js:61:18)
    at async minify (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/minify.js:35:12)
    at async Promise.all (index 0) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: '',
  expected: true,
  operator: '=='
}

As this is the very last step in a deploy I really have no need to keep the original, unminified version around, so overwriting is ideal. As of now I have to write, remove the original, and then rename the minified version, which is a bit of an annoyance.

I'll take a look myself, see if I can't get something together to resolve this.

rschristian avatar Nov 19 '20 18:11 rschristian

Why don't use:

npx minify static/index.html > static/.index.html && mv static/.index.html static/index.html

coderaiser avatar Nov 20 '20 18:11 coderaiser

I do in fact use that.

Perhaps "remove the original" is a bit poorly worded when I meant "overwrite", but I digress.

Feature would certainly be nice regardless, certainly there are work arounds in the mean time so low priority.

rschristian avatar Nov 20 '20 19:11 rschristian

That's a good idea for a pull request :).

coderaiser avatar Feb 01 '21 09:02 coderaiser

I did end up getting something together, not sure what ended up happening to it. If I find some time I'll do it again, but as I'm not using minify (not even sure what I was using it for in the first place) it's not a high priority for me right now. Certainly doesn't mean it should be any sort of priority (or even on the radar) for you either, don't get me wrong.

rschristian avatar Feb 01 '21 22:02 rschristian

This is actually an issue in Bash. using $ minify hello.js > hello.js Bash will first execute the file redirect, prepare hello.js for writing by wiping it. Then it will execute the left hand side, allowing minify to read the now empty hello.js

Short of adding a flag called something like --overwrite-source that minifies, then writes the files back over themselves this project cannot support this.

@coderaiser What are your thoughts? would you be interested in a PR to that effect?

code-forger avatar Jul 16 '21 13:07 code-forger

@code-forger yes, that's amazing idea for a PR :).

coderaiser avatar Jul 16 '21 13:07 coderaiser

Closed due to a long time of inactivity 🏝

coderaiser avatar Jun 05 '23 06:06 coderaiser