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

Error on overwriting file with minified content #61

Closed
rschristian opened this issue Nov 19, 2020 · 7 comments
Closed

Error on overwriting file with minified content #61

rschristian opened this issue Nov 19, 2020 · 7 comments

Comments

@rschristian
Copy link

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
Copy link
Owner

Why don't use:

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

@rschristian
Copy link
Author

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
Copy link
Owner

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

@rschristian
Copy link
Author

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
Copy link
Contributor

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
Copy link
Owner

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

@coderaiser
Copy link
Owner

Closed due to a long time of inactivity 🏝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants