coderaiser / minify

Minifier of js, css, html and img
https://coderaiser.github.io/minify
MIT License
228 stars 29 forks source link

Error on overwriting file with minified content #61

Closed rschristian closed 1 year ago

rschristian commented 3 years ago

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.

coderaiser commented 3 years ago

Why don't use:

npx minify static/index.html > static/.index.html && mv static/.index.html static/index.html
rschristian commented 3 years ago

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.

coderaiser commented 3 years ago

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

rschristian commented 3 years ago

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.

code-forger commented 3 years ago

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?

coderaiser commented 3 years ago

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

coderaiser commented 1 year ago

Closed due to a long time of inactivity 🏝