Formatting
This commit is contained in:
parent
776539b9ce
commit
78c4592b28
|
@ -5,29 +5,32 @@
|
||||||
* @param cfg - Configurable minifier settings to use
|
* @param cfg - Configurable minifier settings to use
|
||||||
* @returns Minified HTML code
|
* @returns Minified HTML code
|
||||||
*/
|
*/
|
||||||
export function minify (src: Buffer, cfg: {
|
export function minify(
|
||||||
/** Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant. */
|
src: Buffer,
|
||||||
do_not_minify_doctype?: boolean,
|
cfg: {
|
||||||
/** Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification. */
|
/** Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant. */
|
||||||
ensure_spec_compliant_unquoted_attribute_values?: boolean;
|
do_not_minify_doctype?: boolean;
|
||||||
/** Do not omit closing tags when possible. */
|
/** Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification. */
|
||||||
keep_closing_tags?: boolean;
|
ensure_spec_compliant_unquoted_attribute_values?: boolean;
|
||||||
/** Do not omit `<html>` and `<head>` opening tags when they don't have attributes. */
|
/** Do not omit closing tags when possible. */
|
||||||
keep_html_and_head_opening_tags?: boolean;
|
keep_closing_tags?: boolean;
|
||||||
/** Keep spaces between attributes when possible to conform to HTML standards. */
|
/** Do not omit `<html>` and `<head>` opening tags when they don't have attributes. */
|
||||||
keep_spaces_between_attributes?: boolean;
|
keep_html_and_head_opening_tags?: boolean;
|
||||||
/** Keep all comments. */
|
/** Keep spaces between attributes when possible to conform to HTML standards. */
|
||||||
keep_comments?: boolean;
|
keep_spaces_between_attributes?: boolean;
|
||||||
/**
|
/** Keep all comments. */
|
||||||
* If enabled, content in `<script>` tags with a JS or no [MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) will be minified using [minify-js](https://github.com/wilsonzlin/minify-js).
|
keep_comments?: boolean;
|
||||||
*/
|
/**
|
||||||
minify_js?: boolean;
|
* If enabled, content in `<script>` tags with a JS or no [MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) will be minified using [minify-js](https://github.com/wilsonzlin/minify-js).
|
||||||
/**
|
*/
|
||||||
* If enabled, CSS in `<style>` tags and `style` attributes will be minified.
|
minify_js?: boolean;
|
||||||
*/
|
/**
|
||||||
minify_css?: boolean;
|
* If enabled, CSS in `<style>` tags and `style` attributes will be minified.
|
||||||
/** Remove all bangs. */
|
*/
|
||||||
remove_bangs?: boolean;
|
minify_css?: boolean;
|
||||||
/** Remove all processing_instructions. */
|
/** Remove all bangs. */
|
||||||
remove_processing_instructions?: boolean;
|
remove_bangs?: boolean;
|
||||||
}): Buffer;
|
/** Remove all processing_instructions. */
|
||||||
|
remove_processing_instructions?: boolean;
|
||||||
|
}
|
||||||
|
): Buffer;
|
||||||
|
|
|
@ -5,7 +5,15 @@
|
||||||
"minify-html": "./cli.js"
|
"minify-html": "./cli.js"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": ["src/**", "Cargo.toml", "cli.js", "index.d.ts", "index.js", "README.md", "postinstall.js"],
|
"files": [
|
||||||
|
"src/**",
|
||||||
|
"Cargo.toml",
|
||||||
|
"cli.js",
|
||||||
|
"index.d.ts",
|
||||||
|
"index.js",
|
||||||
|
"README.md",
|
||||||
|
"postinstall.js"
|
||||||
|
],
|
||||||
"version": "0.9.1",
|
"version": "0.9.1",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -39,7 +39,11 @@ const downloadNativeBinary = async () => {
|
||||||
`https://wilsonl.in/minify-html/bin/nodejs/${pkg.version}/${binaryName}.node`
|
`https://wilsonl.in/minify-html/bin/nodejs/${pkg.version}/${binaryName}.node`
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof StatusError && e.status !== 404 && attempt < MAX_DOWNLOAD_ATTEMPTS) {
|
if (
|
||||||
|
e instanceof StatusError &&
|
||||||
|
e.status !== 404 &&
|
||||||
|
attempt < MAX_DOWNLOAD_ATTEMPTS
|
||||||
|
) {
|
||||||
await wait(Math.random() * 2500 + 500);
|
await wait(Math.random() * 2500 + 500);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +62,9 @@ if (
|
||||||
downloadNativeBinary().then(
|
downloadNativeBinary().then(
|
||||||
() => console.log(`Downloaded ${pkg.name}`),
|
() => console.log(`Downloaded ${pkg.name}`),
|
||||||
(err) => {
|
(err) => {
|
||||||
console.error(`Failed to download ${pkg.name}, will build from source: ${err}`);
|
console.error(
|
||||||
|
`Failed to download ${pkg.name}, will build from source: ${err}`
|
||||||
|
);
|
||||||
const out = cp.spawnSync("npm", ["run", "build-release"], {
|
const out = cp.spawnSync("npm", ["run", "build-release"], {
|
||||||
cwd: __dirname,
|
cwd: __dirname,
|
||||||
stdio: ["ignore", "inherit", "inherit"],
|
stdio: ["ignore", "inherit", "inherit"],
|
||||||
|
|
|
@ -1,18 +1,28 @@
|
||||||
use minify_html_onepass::{Cfg, Error, in_place as minify_html_native};
|
use minify_html_onepass::{in_place as minify_html_native, Cfg, Error};
|
||||||
use pyo3::prelude::*;
|
|
||||||
use pyo3::exceptions::PySyntaxError;
|
use pyo3::exceptions::PySyntaxError;
|
||||||
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
use pyo3::wrap_pyfunction;
|
||||||
use std::str::from_utf8_unchecked;
|
use std::str::from_utf8_unchecked;
|
||||||
|
|
||||||
#[pyfunction(py_args="*", minify_js="false", minify_css="false")]
|
#[pyfunction(py_args = "*", minify_js = "false", minify_css = "false")]
|
||||||
fn minify(code: String, minify_js: bool, minify_css: bool) -> PyResult<String> {
|
fn minify(code: String, minify_js: bool, minify_css: bool) -> PyResult<String> {
|
||||||
let mut code = code.into_bytes();
|
let mut code = code.into_bytes();
|
||||||
match minify_html_native(&mut code, &Cfg {
|
match minify_html_native(
|
||||||
minify_js,
|
&mut code,
|
||||||
minify_css,
|
&Cfg {
|
||||||
}) {
|
minify_js,
|
||||||
|
minify_css,
|
||||||
|
},
|
||||||
|
) {
|
||||||
Ok(out_len) => Ok(unsafe { from_utf8_unchecked(&code[0..out_len]).to_string() }),
|
Ok(out_len) => Ok(unsafe { from_utf8_unchecked(&code[0..out_len]).to_string() }),
|
||||||
Err(Error { error_type, position }) => Err(PySyntaxError::new_err(format!("{} [Character {}]", error_type.message(), position))),
|
Err(Error {
|
||||||
|
error_type,
|
||||||
|
position,
|
||||||
|
}) => Err(PySyntaxError::new_err(format!(
|
||||||
|
"{} [Character {}]",
|
||||||
|
error_type.message(),
|
||||||
|
position
|
||||||
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
version
6
version
|
@ -114,11 +114,7 @@ for (const f of [
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const f of ["README.md", "nodejs/Cargo.toml"]) {
|
for (const f of ["README.md", "nodejs/Cargo.toml"]) {
|
||||||
replaceInFile(
|
replaceInFile(f, /^(minify-html = )"\d+\.\d+\.\d+"/m, `$1"${NEW_VERSION}"`);
|
||||||
f,
|
|
||||||
/^(minify-html = )"\d+\.\d+\.\d+"/m,
|
|
||||||
`$1"${NEW_VERSION}"`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const f of ["README.md"]) {
|
for (const f of ["README.md"]) {
|
||||||
|
|
Loading…
Reference in New Issue