Use Node.js native module directly without JS overhead
This commit is contained in:
parent
b6556a8a8b
commit
697823ab17
|
@ -74,7 +74,7 @@ jobs:
|
|||
run: |
|
||||
binary_name="$(node -e 'console.log([process.platform, process.arch, process.versions.modules].join("__"))')"
|
||||
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||
b2 upload-file ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./nodejs/dist/native.node.gz "minify-html/bin/nodejs/${{ steps.version.outputs.VERSION }}/$binary_name.node.gz"
|
||||
b2 upload-file ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./nodejs/dist/index.node.gz "minify-html/bin/nodejs/${{ steps.version.outputs.VERSION }}/$binary_name.node.gz"
|
||||
package:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
|
|
|
@ -2,6 +2,6 @@ const {readFileSync, writeFileSync} = require('fs');
|
|||
const {join} = require('path');
|
||||
const {gzipSync} = require('zlib');
|
||||
|
||||
const src = readFileSync(join(__dirname, 'dist', 'native.node'));
|
||||
const src = readFileSync(join(__dirname, 'dist', 'index.node'));
|
||||
const out = gzipSync(src);
|
||||
writeFileSync(join(__dirname, 'dist', 'native.node.gz'), out);
|
||||
writeFileSync(join(__dirname, 'dist', 'index.node.gz'), out);
|
||||
|
|
|
@ -2,15 +2,12 @@
|
|||
"name": "@minify-html/js",
|
||||
"version": "0.2.6",
|
||||
"description": "Fast and smart HTML + JS minifier",
|
||||
"main": "dist/index.js",
|
||||
"main": "dist/index.node",
|
||||
"files": [
|
||||
"dist/**",
|
||||
"postinstall.js"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "npm run clean && tsc",
|
||||
"build-binary": "neon build --release && mkdir -p dist && mv native/index.node dist/native.node",
|
||||
"clean": "rm -rf dist",
|
||||
"build": "neon build --release && mkdir -p dist && mv native/index.node dist/index.node",
|
||||
"postinstall": "node postinstall.js"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -28,9 +25,7 @@
|
|||
},
|
||||
"homepage": "https://github.com/wilsonzlin/minify-html#readme",
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.0.22",
|
||||
"neon-cli": "^0.4.0",
|
||||
"typescript": "^3.9.6"
|
||||
"neon-cli": "^0.4.0"
|
||||
},
|
||||
"keywords": [
|
||||
"build",
|
||||
|
|
|
@ -7,7 +7,7 @@ const pkg = require('./package.json');
|
|||
const MAX_DOWNLOAD_ATTEMPTS = 4;
|
||||
|
||||
const binaryName = [process.platform, process.arch, process.versions.modules].join('__');
|
||||
const binaryPath = path.join(__dirname, 'dist', 'native.node');
|
||||
const binaryPath = path.join(__dirname, 'dist', 'index.node');
|
||||
|
||||
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
const native = require(`./native.node`);
|
||||
|
||||
export type Configuration = {
|
||||
minifyJs: boolean;
|
||||
};
|
||||
|
||||
export const minify = (code: string, cfg: Configuration): string => {
|
||||
const buf = Buffer.from(code);
|
||||
const len = native.minify(buf, cfg);
|
||||
return buf.slice(0, len).toString();
|
||||
};
|
||||
|
||||
export const minifyInPlace = (buf: Buffer, cfg: Configuration): Buffer => {
|
||||
const len = native.minify(buf, cfg);
|
||||
// This does not do a copy.
|
||||
return buf.slice(0, len);
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"allowJs": false,
|
||||
"alwaysStrict": true,
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
"es5",
|
||||
"es6",
|
||||
"es7",
|
||||
"es2017"
|
||||
],
|
||||
"module": "commonjs",
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedParameters": true,
|
||||
"outDir": "dist",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"target": "es6"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue