Remove core variant

This commit is contained in:
Wilson Lin 2022-06-21 21:52:28 +10:00
parent c7d0652fbc
commit ec8c4e338a
21 changed files with 92 additions and 156 deletions

View File

@ -40,9 +40,7 @@ jobs:
- name: Set up Node.js module
working-directory: ./nodejs
run: |
node package.json.gen.js js
npm install
run: npm install
- name: Build bench
working-directory: ./bench

View File

@ -11,7 +11,6 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
feature: [core, js]
os: [macos-11.0, ubuntu-18.04, windows-2019, self-hosted-linux-arm64, self-hosted-macos-arm64]
steps:
- uses: actions/checkout@v1
@ -54,7 +53,6 @@ jobs:
id: module
shell: bash
run: |
node package.json.gen.js ${{ matrix.feature }}
npm install
npm run build
node compress.js
@ -70,9 +68,6 @@ jobs:
file: ./nodejs/index.node.gz
package:
strategy:
matrix:
feature: [core, js]
runs-on: ubuntu-18.04
needs: build
steps:
@ -93,7 +88,6 @@ jobs:
//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}
EOF
cp ../README.md .
node package.json.gen.js ${{ matrix.feature }}
if [[ "${{ steps.version.outputs.VERSION }}" != "0.0.0" ]]; then
npm publish --access public
fi

View File

@ -11,7 +11,6 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
feature: [core, js]
os: [macos-11.0, ubuntu-18.04, windows-2019, self-hosted-linux-arm64, self-hosted-macos-arm64]
python: [3.8, 3.9, '3.10']
steps:
@ -61,9 +60,7 @@ jobs:
- name: Build native module
working-directory: ./python
run: |
python prepare.py ${{ matrix.feature }}
cargo build --release
run: cargo build --release
- name: Install Python build tools (macOS x64)
if: runner.os == 'macOS' && runner.name != 'macos-arm64'
@ -103,7 +100,7 @@ jobs:
else
pathToPython="$(which python)"
fi
# On macOS ARM64 this may emit a warning like "Couldn't find the symbol `PyInit_minify_html_core` in the native library. Python will fail to import this module." Ignore this message.
# On macOS ARM64 this may emit a warning like "Couldn't find the symbol `PyInit_minify_html` in the native library. Python will fail to import this module." Ignore this message.
maturin build --release --strip -i "$pathToPython"
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
# For idempotency, ignore any existing built wheels that have already been successfully uploaded.

View File

@ -67,7 +67,7 @@ Check out the [docs](https://docs.rs/minify-html) for API and usage examples.
<details>
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/nodejs.png"> <strong>Node.js</strong></summary>
- Package: [@minify-html/js](https://www.npmjs.com/package/@minify-html/js)
- Package: [@minify-html/node](https://www.npmjs.com/package/@minify-html/node)
- Binding: [N-API](https://nodejs.org/api/n-api.html)
- Platforms: Linux (ARM64 and x64), macOS (ARM64 and x64), Windows (x64); Node.js 8.6.0 and higher
@ -76,13 +76,13 @@ Check out the [docs](https://docs.rs/minify-html) for API and usage examples.
Using npm:
```bash
npm i @minify-html/js
npm i @minify-html/node
```
Using Yarn:
```bash
yarn add @minify-html/js
yarn add @minify-html/node
```
### Use
@ -90,8 +90,8 @@ yarn add @minify-html/js
TypeScript definitions are available.
```ts
import * as minifyHtml from "@minify-html/js";
// Or `const minifyHtml = require("@minify-html/js")` if not using TS/ESM.
import * as minifyHtml from "@minify-html/node";
// Or `const minifyHtml = require("@minify-html/node")` if not using TS/ESM.
const cfg = minifyHtml.createConfiguration({ keep_spaces_between_attributes: true, keep_comments: true });
const minified = minifyHtml.minify("<p> Hello, world! </p>", cfg);

View File

@ -24,7 +24,11 @@ for r in *; do
echo "Running $r..."
pushd "$r" >/dev/null
out="$results_dir/$r.json"
sudo --preserve-env=MHB_HTML_ONLY,PATH MHB_ITERATIONS="$iterations" MHB_INPUT_DIR="$input_dir" RUST_BACKTRACE=1 nice -n -20 taskset -c 1 ./run >"$out"
if [[ "$(uname -s)" = "Darwin" ]]; then
MHB_ITERATIONS="$iterations" MHB_INPUT_DIR="$input_dir" RUST_BACKTRACE=1 ./run >"$out"
else
sudo --preserve-env=MHB_HTML_ONLY,PATH MHB_ITERATIONS="$iterations" MHB_INPUT_DIR="$input_dir" RUST_BACKTRACE=1 nice -n -20 taskset -c 1 ./run >"$out"
fi
popd >/dev/null
done
popd >/dev/null

View File

@ -1,6 +0,0 @@
{
"private": true,
"dependencies": {
"@minify-html/js": "file:../../../nodejs"
}
}

View File

@ -1,4 +1,4 @@
const minifyHtml = require("@minify-html/js");
const minifyHtml = require("@minify-html/node");
const { htmlOnly, run } = require("../common");
const minifyHtmlCfg = minifyHtml.createConfiguration({

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"@minify-html/node": "file:../../../nodejs"
}
}

1
nodejs/.gitignore vendored
View File

@ -3,5 +3,4 @@
/native/Cargo.lock
/native/target
/package-lock.json
/package.json
node_modules/

View File

@ -1,6 +1,5 @@
const cp = require("child_process");
const path = require("path");
const pkg = require("./package.json");
cp.spawnSync(
"cargo",
@ -9,8 +8,6 @@ cp.spawnSync(
"--manifest-path",
path.join(__dirname, "native", "Cargo.toml"),
"--release",
"--features",
pkg.name.split("/")[1],
],
{
stdio: "inherit",

51
nodejs/package.json Normal file
View File

@ -0,0 +1,51 @@
{
"name": "@minify-html/node",
"description": "Extremely fast and smart HTML + JS + CSS minifier",
"bin": {
"minify-html": "./cli.js"
},
"version": "0.8.1",
"main": "index.js",
"types": "index.d.ts",
"files": [
"cli.js",
"postinstall.js",
"index.d.ts",
"index.js"
],
"scripts": {
"build": "node-gyp build && shx mv build/Release/index.node index.node",
"clean": "cd native && cargo clean && cd .. && node-gyp clean && node-gyp configure && shx rm -f index.node",
"postinstall": "node postinstall.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wilsonzlin/minify-html.git"
},
"author": {
"email": "npm@wilsonl.in",
"name": "Wilson Lin",
"url": "https://wilsonl.in/"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/wilsonzlin/minify-html/issues"
},
"engines": {
"node": ">= 8.6.0"
},
"homepage": "https://github.com/wilsonzlin/minify-html#readme",
"devDependencies": {
"@types/node": "^14.6.0",
"node-gyp": "^7.0.0",
"shx": "^0.3.2"
},
"keywords": [
"compress",
"compressor",
"fast",
"html",
"minifier",
"minify"
]
}

View File

@ -1,66 +0,0 @@
const fs = require("fs");
const common = {
version: "0.8.1",
main: "index.js",
types: "index.d.ts",
files: ["cli.js", "postinstall.js", "index.d.ts", "index.js"],
scripts: {
build: "node-gyp build && shx mv build/Release/index.node index.node",
clean:
"cd native && cargo clean && cd .. && node-gyp clean && node-gyp configure && shx rm -f index.node",
postinstall: "node postinstall.js",
},
repository: {
type: "git",
url: "git+https://github.com/wilsonzlin/minify-html.git",
},
author: {
email: "npm@wilsonl.in",
name: "Wilson Lin",
url: "https://wilsonl.in/",
},
license: "MIT",
bugs: {
url: "https://github.com/wilsonzlin/minify-html/issues",
},
engines: {
node: ">= 8.6.0",
},
homepage: "https://github.com/wilsonzlin/minify-html#readme",
devDependencies: {
"@types/node": "^14.6.0",
"node-gyp": "^7.0.0",
shx: "^0.3.2",
},
keywords: ["compress", "compressor", "fast", "html", "minifier", "minify"],
};
const specifics = {
core: {
name: "@minify-html/core",
description: "Extremely fast and smart HTML minifier",
bin: {
"minify-html-core": "./cli.js",
},
},
js: {
name: "@minify-html/js",
description: "Extremely fast and smart HTML + JS + CSS minifier",
bin: {
"minify-html": "./cli.js",
},
},
}[process.argv[2]];
fs.writeFileSync(
"package.json",
JSON.stringify(
{
...common,
...specifics,
},
null,
2
)
);

6
python/.gitignore vendored
View File

@ -1,15 +1,9 @@
/Cargo.lock
/Cargo.toml
/src/lib.rs
/target/
__pycache__/
/venv/
# Ignore locally built native modules.
/hyperbuild/**/*.so
/hyperbuild/**/*.pyd
# Used by Python setuptools.
/build/
/dist/

View File

@ -1,21 +0,0 @@
[package]
publish = false
name = "minify_html_core"
description = "Extremely fast and smart HTML minifier"
license = "MIT"
homepage = "https://github.com/wilsonzlin/minify-html"
readme = "README.md"
repository = "https://github.com/wilsonzlin/minify-html.git"
version = "0.8.1"
authors = ["Wilson Lin <code@wilsonl.in>"]
edition = "2018"
[lib]
name = "minify_html_core"
crate-type = ["cdylib"]
[dependencies]
minify-html = { path = "../rust/main", features = [] }
[dependencies.pyo3]
version = "0.13.0"
features = ["extension-module"]

View File

@ -1,14 +0,0 @@
import shutil
import sys
feature = sys.argv[1]
module_name = "minify_html_core" if feature == "core" else "minify_html"
cargo_file = "Cargo.core.toml" if feature == "core" else "Cargo.js.toml"
with open("src/lib.template.rs", "r") as template:
actual = template.read().replace("REPLACE_WITH_MODULE_NAME", module_name)
with open("src/lib.rs", "w") as librs:
librs.write(actual)
shutil.copyfile(cargo_file, "Cargo.toml")

View File

@ -1,4 +1,4 @@
use minify_html::{Cfg, minify as minify_html_native};
use minify_html::{minify as minify_html_native, Cfg};
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use std::string::String;
@ -14,7 +14,7 @@ use std::string::String;
minify_css = "false",
minify_js = "false",
remove_bangs = "false",
remove_processing_instructions = "false",
remove_processing_instructions = "false"
)]
fn minify(
code: String,
@ -30,23 +30,26 @@ fn minify(
remove_processing_instructions: bool,
) -> PyResult<String> {
let code = code.into_bytes();
let out_code = minify_html_native(&code, &Cfg {
do_not_minify_doctype,
ensure_spec_compliant_unquoted_attribute_values,
keep_closing_tags,
keep_comments,
keep_html_and_head_opening_tags,
keep_spaces_between_attributes,
minify_css,
minify_js,
remove_bangs,
remove_processing_instructions,
});
let out_code = minify_html_native(
&code,
&Cfg {
do_not_minify_doctype,
ensure_spec_compliant_unquoted_attribute_values,
keep_closing_tags,
keep_comments,
keep_html_and_head_opening_tags,
keep_spaces_between_attributes,
minify_css,
minify_js,
remove_bangs,
remove_processing_instructions,
},
);
Ok(String::from_utf8(out_code).unwrap())
}
#[pymodule]
fn REPLACE_WITH_MODULE_NAME(_py: Python, m: &PyModule) -> PyResult<()> {
fn minify_html(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(minify))?;
Ok(())

View File

@ -103,7 +103,7 @@ for (const f of [
"cli/Cargo.toml",
"nodejs/native/Cargo.toml",
"java/Cargo.toml",
"python/Cargo.core.toml",
"python/Cargo.toml",
"python/Cargo.js.toml",
"ruby/Cargo.toml",
]) {
@ -146,10 +146,10 @@ for (const f of ["java/pom.xml", "README.md"]) {
);
}
for (const f of ["nodejs/package.json.gen.js"]) {
for (const f of ["nodejs/package.json"]) {
replaceInFile(
f,
/^(\s*version: )"\d+\.\d+\.\d+",\s*$/m,
/^(\s*"version": )"\d+\.\d+\.\d+",\s*$/m,
`$1"${NEW_VERSION}",`
);
}