diff --git a/.github/workflows/bench.yaml b/.github/workflows/bench.yaml index 20db9b8..7e63563 100644 --- a/.github/workflows/bench.yaml +++ b/.github/workflows/bench.yaml @@ -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 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index de3be20..e593bc1 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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 diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 0bce247..63dc035 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -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. diff --git a/README.md b/README.md index 081d5f6..7c32147 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Check out the [docs](https://docs.rs/minify-html) for API and usage examples.
Node.js -- 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("

Hello, world!

", cfg); diff --git a/bench/run b/bench/run index 4f42232..01789d2 100755 --- a/bench/run +++ b/bench/run @@ -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 diff --git a/bench/runners/@minify-html%2Fjs/package.json b/bench/runners/@minify-html%2Fjs/package.json deleted file mode 100644 index b0625b3..0000000 --- a/bench/runners/@minify-html%2Fjs/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "dependencies": { - "@minify-html/js": "file:../../../nodejs" - } -} diff --git a/bench/runners/@minify-html%2Fjs/.gitignore b/bench/runners/@minify-html%2Fnode/.gitignore similarity index 100% rename from bench/runners/@minify-html%2Fjs/.gitignore rename to bench/runners/@minify-html%2Fnode/.gitignore diff --git a/bench/runners/@minify-html%2Fjs/build b/bench/runners/@minify-html%2Fnode/build similarity index 100% rename from bench/runners/@minify-html%2Fjs/build rename to bench/runners/@minify-html%2Fnode/build diff --git a/bench/runners/@minify-html%2Fjs/index.js b/bench/runners/@minify-html%2Fnode/index.js similarity index 81% rename from bench/runners/@minify-html%2Fjs/index.js rename to bench/runners/@minify-html%2Fnode/index.js index 66c3608..9084bd8 100644 --- a/bench/runners/@minify-html%2Fjs/index.js +++ b/bench/runners/@minify-html%2Fnode/index.js @@ -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({ diff --git a/bench/runners/@minify-html%2Fnode/package.json b/bench/runners/@minify-html%2Fnode/package.json new file mode 100644 index 0000000..2a90c72 --- /dev/null +++ b/bench/runners/@minify-html%2Fnode/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "@minify-html/node": "file:../../../nodejs" + } +} diff --git a/bench/runners/@minify-html%2Fjs/run b/bench/runners/@minify-html%2Fnode/run similarity index 100% rename from bench/runners/@minify-html%2Fjs/run rename to bench/runners/@minify-html%2Fnode/run diff --git a/nodejs/.gitignore b/nodejs/.gitignore index b273d37..03c3b23 100644 --- a/nodejs/.gitignore +++ b/nodejs/.gitignore @@ -3,5 +3,4 @@ /native/Cargo.lock /native/target /package-lock.json -/package.json node_modules/ diff --git a/nodejs/buildnative.js b/nodejs/buildnative.js index 0b96193..14de45e 100644 --- a/nodejs/buildnative.js +++ b/nodejs/buildnative.js @@ -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", diff --git a/nodejs/package.json b/nodejs/package.json new file mode 100644 index 0000000..cf85f29 --- /dev/null +++ b/nodejs/package.json @@ -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" + ] +} diff --git a/nodejs/package.json.gen.js b/nodejs/package.json.gen.js deleted file mode 100644 index 8bdabb9..0000000 --- a/nodejs/package.json.gen.js +++ /dev/null @@ -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 - ) -); diff --git a/python/.gitignore b/python/.gitignore index 4dc02c3..ffcf2b4 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -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/ diff --git a/python/Cargo.core.toml b/python/Cargo.core.toml deleted file mode 100644 index f3bb49f..0000000 --- a/python/Cargo.core.toml +++ /dev/null @@ -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 "] -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"] diff --git a/python/Cargo.js.toml b/python/Cargo.toml similarity index 100% rename from python/Cargo.js.toml rename to python/Cargo.toml diff --git a/python/prepare.py b/python/prepare.py deleted file mode 100644 index 4c8e985..0000000 --- a/python/prepare.py +++ /dev/null @@ -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") diff --git a/python/src/lib.template.rs b/python/src/lib.rs similarity index 62% rename from python/src/lib.template.rs rename to python/src/lib.rs index 9cd43d0..81b1d02 100644 --- a/python/src/lib.template.rs +++ b/python/src/lib.rs @@ -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 { 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(()) diff --git a/version b/version index 5b2a7e8..aebf9f9 100755 --- a/version +++ b/version @@ -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}",` ); }