mirror of
https://github.com/coderaiser/minify.git
synced 2025-12-05 18:55:58 -06:00
chore: lint
This commit is contained in:
2
.github/workflows/node.js.yml
vendored
2
.github/workflows/node.js.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
||||
node-version:
|
||||
- 16.x
|
||||
- 18.x
|
||||
- 19.x
|
||||
- 20.x
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
|
||||
2
.github/workflows/nodejs-pr.yml
vendored
2
.github/workflows/nodejs-pr.yml
vendored
@@ -9,7 +9,7 @@ jobs:
|
||||
node-version:
|
||||
- 16.x
|
||||
- 18.x
|
||||
- 19.x
|
||||
- 20.x
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
|
||||
@@ -8,4 +8,3 @@ export default {
|
||||
'fresh:lint': () => run('lint', '--fresh'),
|
||||
'lint:fresh': () => run('lint', '--fresh'),
|
||||
};
|
||||
|
||||
|
||||
3
.putout.json
Normal file
3
.putout.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"printer": "putout"
|
||||
}
|
||||
@@ -55,6 +55,7 @@ $ minify hello.js > hello.min.js
|
||||
```js
|
||||
import {minify} from 'minify';
|
||||
import tryToCatch from 'try-to-catch';
|
||||
|
||||
const options = {
|
||||
html: {
|
||||
removeAttributeQuotes: false,
|
||||
|
||||
@@ -32,6 +32,7 @@ minify();
|
||||
function readStd(callback, options) {
|
||||
const {stdin} = process;
|
||||
let chunks = '';
|
||||
|
||||
const read = () => {
|
||||
const chunk = stdin.read();
|
||||
|
||||
@@ -51,7 +52,7 @@ async function minify() {
|
||||
return help();
|
||||
|
||||
if (/^(-v|--version)$/.test(In))
|
||||
return log('v' + Version);
|
||||
return log(`v${Version}`);
|
||||
|
||||
const {readOptions} = await import('../lib/read-options.mjs');
|
||||
const [optionsError, options] = await tryToCatch(readOptions);
|
||||
@@ -85,7 +86,8 @@ async function uglifyFiles(files, options) {
|
||||
const {minify} = await import('../lib/minify.js');
|
||||
const minifiers = files.map((file) => minify(file, options));
|
||||
|
||||
Promise.all(minifiers)
|
||||
Promise
|
||||
.all(minifiers)
|
||||
.then(logAll)
|
||||
.catch(log.error);
|
||||
}
|
||||
@@ -106,4 +108,3 @@ function help() {
|
||||
console.log(' %s %s', name, bin[name]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* сжимаем код через clean-css */
|
||||
|
||||
import assert from 'assert';
|
||||
import Clean from 'clean-css';
|
||||
|
||||
@@ -26,4 +25,3 @@ export default (data, userOptions) => {
|
||||
|
||||
return styles;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* сжимаем код через htmlMinify */
|
||||
|
||||
import assert from 'assert';
|
||||
import Minifier from 'html-minifier-terser';
|
||||
|
||||
@@ -12,12 +11,10 @@ const defaultOptions = {
|
||||
removeAttributeQuotes: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
/* оставляем, поскольку у нас
|
||||
removeEmptyAttributes: true, /* оставляем, поскольку у нас
|
||||
* в элемент fm генерируеться
|
||||
* таблица файлов
|
||||
*/
|
||||
removeEmptyElements: false,
|
||||
*/removeEmptyElements: false,
|
||||
removeOptionalTags: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
@@ -42,4 +39,3 @@ export default (data, userOptions) => {
|
||||
|
||||
return Minifier.minify(data, options);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import path from 'path';
|
||||
import assert from 'assert';
|
||||
import {promisify} from 'util';
|
||||
import {createRequire} from 'module';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const fromString = promisify(require('css-b64-images').fromString);
|
||||
@@ -22,7 +23,7 @@ const defaultOptions = {
|
||||
*/
|
||||
export default (name, data, userOptions) => {
|
||||
const dir = path.dirname(name);
|
||||
const dirRelative = dir + '/../';
|
||||
const dirRelative = `${dir}/../`;
|
||||
|
||||
const options = {
|
||||
...defaultOptions,
|
||||
@@ -34,4 +35,3 @@ export default (name, data, userOptions) => {
|
||||
|
||||
return fromString(data, dir, dirRelative, options);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,4 +15,3 @@ export default async (data, userOptions) => {
|
||||
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import {readFile} from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
import tryToCatch from 'try-to-catch';
|
||||
|
||||
import debug from 'debug';
|
||||
|
||||
import js from './js.js';
|
||||
import html from './html.js';
|
||||
import css from './css.js';
|
||||
@@ -29,11 +26,18 @@ function check(name) {
|
||||
}
|
||||
|
||||
export async function minify(name, userOptions) {
|
||||
const EXT = ['js', 'html', 'css'];
|
||||
const EXT = [
|
||||
'js',
|
||||
'html',
|
||||
'css',
|
||||
];
|
||||
|
||||
check(name);
|
||||
|
||||
const ext = path.extname(name).slice(1);
|
||||
const ext = path
|
||||
.extname(name)
|
||||
.slice(1);
|
||||
|
||||
const is = EXT.includes(ext);
|
||||
|
||||
if (!is)
|
||||
@@ -55,6 +59,7 @@ async function optimize(file, userOptions) {
|
||||
log('reading file ' + path.basename(file));
|
||||
|
||||
const data = await readFile(file, 'utf8');
|
||||
|
||||
return await onDataRead(file, data, userOptions);
|
||||
}
|
||||
|
||||
@@ -65,9 +70,11 @@ async function optimize(file, userOptions) {
|
||||
* @param {object} userOptions - object with optional `html`, `css, `js`, and `img` keys, which each can contain options to be combined with defaults and passed to the respective minifier
|
||||
*/
|
||||
async function onDataRead(filename, data, userOptions) {
|
||||
log('file ' + path.basename(filename) + ' read');
|
||||
log(`file ${path.basename(filename)} read`);
|
||||
|
||||
const ext = path.extname(filename).replace(/^\./, '');
|
||||
const ext = path
|
||||
.extname(filename)
|
||||
.replace(/^\./, '');
|
||||
|
||||
const optimizedData = await minifiers[ext](data, userOptions);
|
||||
|
||||
@@ -78,4 +85,3 @@ async function onDataRead(filename, data, userOptions) {
|
||||
|
||||
return b64Optimize || optimizedData;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,14 @@ test('minify: readOptions', async (t) => {
|
||||
const fixture = {
|
||||
js: true,
|
||||
};
|
||||
|
||||
const readjson = stub().resolves(fixture);
|
||||
const find = stub().resolves('/hello');
|
||||
|
||||
const options = await readOptions({readjson, find});
|
||||
const options = await readOptions({
|
||||
readjson,
|
||||
find,
|
||||
});
|
||||
|
||||
t.deepEqual(options, fixture);
|
||||
t.end();
|
||||
@@ -21,7 +25,9 @@ test('minify: readOptions', async (t) => {
|
||||
test('minify: readOptions: cannot readFile', async (t) => {
|
||||
const find = stub().resolves('/hello');
|
||||
|
||||
const [error] = await tryToCatch(readOptions, {find});
|
||||
const [error] = await tryToCatch(readOptions, {
|
||||
find,
|
||||
});
|
||||
|
||||
t.equal(error.message, `ENOENT: no such file or directory, open '/hello'`);
|
||||
t.end();
|
||||
@@ -33,4 +39,3 @@ test('minify: readOptions: no', async (t) => {
|
||||
t.deepEqual(result, {});
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
"homepage": "http://coderaiser.github.io/minify",
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
||||
"type": "module",
|
||||
"commitType": "colon",
|
||||
"keywords": [
|
||||
"minify",
|
||||
"minimize",
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import {readFile} from 'fs/promises';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {dirname} from 'path';
|
||||
|
||||
import tryToCatch from 'try-to-catch';
|
||||
import test from 'supertape';
|
||||
import CleanCSS from 'clean-css';
|
||||
import {minify as terserMinify} from 'terser';
|
||||
import htmlMinifier from 'html-minifier-terser';
|
||||
|
||||
import {minify} from '../lib/minify.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@@ -71,12 +69,10 @@ test('minify: html', async (t) => {
|
||||
removeAttributeQuotes: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
/* оставляем, поскольку у нас
|
||||
removeEmptyAttributes: true, /* оставляем, поскольку у нас
|
||||
* в элемент fm генерируеться
|
||||
* таблица файлов
|
||||
*/
|
||||
removeEmptyElements: false,
|
||||
*/removeEmptyElements: false,
|
||||
removeOptionalTags: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
@@ -136,6 +132,7 @@ test('minify: css', async (t) => {
|
||||
|
||||
test('minify: css: with alternate options', async (t) => {
|
||||
const css = `.gradient { -ms-filter: 'progid:DXImageTransform.Microsoft.Gradient(startColorStr="#ffffff", endColorStr="#000000", GradientType=1)'; background-image: linear-gradient(to right, #ffffff 0%, #000000 100%); }`;
|
||||
|
||||
const options = {
|
||||
css: {
|
||||
compatibility: {
|
||||
@@ -155,6 +152,7 @@ test('minify: css: with alternate options', async (t) => {
|
||||
|
||||
test('minify: css: with alternate options: influence', async (t) => {
|
||||
const css = `.gradient { -ms-filter: 'progid:DXImageTransform.Microsoft.Gradient(startColorStr="#ffffff", endColorStr="#000000", GradientType=1)'; background-image: linear-gradient(to right, #ffffff 0%, #000000 100%); }`;
|
||||
|
||||
const options = {
|
||||
css: {
|
||||
compatibility: {
|
||||
@@ -187,6 +185,7 @@ test('minify: css: base64', async (t) => {
|
||||
|
||||
test('minify: css: base64 with alternate options', async (t) => {
|
||||
const pathToCSS = `${__dirname}/fixture/style.css`;
|
||||
|
||||
const options = {
|
||||
img: {
|
||||
maxSize: 512,
|
||||
@@ -224,4 +223,3 @@ test('minify: unsupported file extension', async (t) => {
|
||||
t.equal(e?.message, 'File type "md" not supported.', 'throw when file extension is unsupported');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user