@node-minify/utils 7.1.0 → 8.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * node-minify
3
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
4
+ * MIT Licensed
5
+ */
6
+ interface Utils {
7
+ readFile: Function;
8
+ writeFile: Function;
9
+ deleteFile: Function;
10
+ buildArgs: Function;
11
+ clone: Function;
12
+ getFilesizeInBytes: Function;
13
+ getFilesizeGzippedInBytes: Function;
14
+ prettyBytes: Function;
15
+ setFileNameMin: Function;
16
+ compressSingleFile: Function;
17
+ getContentFromFiles: Function;
18
+ runSync: Function;
19
+ runAsync: Function;
20
+ }
21
+ declare const utils: Utils;
22
+
23
+ export { utils };
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ utils: () => utils
29
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+ var import_fs = __toESM(require("fs"));
32
+ var import_gzip_size = __toESM(require("gzip-size"));
33
+ var utils = {};
34
+ utils.readFile = (file) => import_fs.default.readFileSync(file, "utf8");
35
+ utils.writeFile = ({ file, content, index }) => {
36
+ const _file = index !== void 0 ? file[index] : file;
37
+ if (!import_fs.default.existsSync(_file) || import_fs.default.existsSync(_file) && !import_fs.default.lstatSync(_file).isDirectory()) {
38
+ import_fs.default.writeFileSync(_file, content, "utf8");
39
+ }
40
+ return content;
41
+ };
42
+ utils.deleteFile = (file) => import_fs.default.unlinkSync(file);
43
+ utils.buildArgs = (options) => {
44
+ const args = [];
45
+ Object.keys(options).forEach((key) => {
46
+ if (options[key] && options[key] !== false) {
47
+ args.push("--" + key);
48
+ }
49
+ if (options[key] && options[key] !== true) {
50
+ args.push(options[key]);
51
+ }
52
+ });
53
+ return args;
54
+ };
55
+ utils.clone = (obj) => JSON.parse(JSON.stringify(obj));
56
+ utils.getFilesizeInBytes = (file) => {
57
+ const stats = import_fs.default.statSync(file);
58
+ const fileSizeInBytes = stats.size;
59
+ return utils.prettyBytes(fileSizeInBytes);
60
+ };
61
+ utils.getFilesizeGzippedInBytes = (file) => {
62
+ return new Promise((resolve) => {
63
+ const source = import_fs.default.createReadStream(file);
64
+ source.pipe(import_gzip_size.default.stream()).on("gzip-size", (size) => {
65
+ resolve(utils.prettyBytes(size));
66
+ });
67
+ });
68
+ };
69
+ utils.prettyBytes = (num) => {
70
+ const UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
71
+ if (!Number.isFinite(num)) {
72
+ throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);
73
+ }
74
+ const neg = num < 0;
75
+ if (neg) {
76
+ num = -num;
77
+ }
78
+ if (num < 1) {
79
+ return (neg ? "-" : "") + num + " B";
80
+ }
81
+ const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1e3)), UNITS.length - 1);
82
+ const numStr = Number((num / Math.pow(1e3, exponent)).toPrecision(3));
83
+ const unit = UNITS[exponent];
84
+ return (neg ? "-" : "") + numStr + " " + unit;
85
+ };
86
+ utils.setFileNameMin = (file, output, publicFolder, replaceInPlace) => {
87
+ const filePath = file.substr(0, file.lastIndexOf("/") + 1);
88
+ const fileWithoutPath = file.substr(file.lastIndexOf("/") + 1);
89
+ let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf("."));
90
+ if (publicFolder) {
91
+ fileWithoutExtension = publicFolder + fileWithoutExtension;
92
+ }
93
+ if (replaceInPlace) {
94
+ fileWithoutExtension = filePath + fileWithoutExtension;
95
+ }
96
+ return output.replace("$1", fileWithoutExtension);
97
+ };
98
+ utils.compressSingleFile = (settings) => {
99
+ const content = settings.content ? settings.content : utils.getContentFromFiles(settings.input);
100
+ return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });
101
+ };
102
+ utils.getContentFromFiles = (input) => {
103
+ if (!Array.isArray(input)) {
104
+ return import_fs.default.readFileSync(input, "utf8");
105
+ }
106
+ return input.map(
107
+ (path) => !import_fs.default.existsSync(path) || import_fs.default.existsSync(path) && !import_fs.default.lstatSync(path).isDirectory() ? import_fs.default.readFileSync(path, "utf8") : ""
108
+ ).join("\n");
109
+ };
110
+ utils.runSync = ({ settings, content, index }) => settings && typeof settings.compressor !== "string" ? settings.compressor({ settings, content, callback: null, index }) : null;
111
+ utils.runAsync = ({ settings, content, index }) => {
112
+ return new Promise((resolve, reject) => {
113
+ settings && typeof settings.compressor !== "string" ? settings.compressor({
114
+ settings,
115
+ content,
116
+ callback: (err, min) => {
117
+ if (err) {
118
+ return reject(err);
119
+ }
120
+ resolve(min);
121
+ },
122
+ index
123
+ }) : null;
124
+ });
125
+ };
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ utils
129
+ });
130
+ /*!
131
+ * node-minify
132
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
133
+ * MIT Licensed
134
+ */
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport fs from 'fs';\nimport gzipSize from 'gzip-size';\nimport { MinifierOptions } from '@node-minify/types';\n// import { MinifierOptions } from '../../../types';\n\ninterface Utils {\n readFile: Function;\n writeFile: Function;\n deleteFile: Function;\n buildArgs: Function;\n clone: Function;\n getFilesizeInBytes: Function;\n getFilesizeGzippedInBytes: Function;\n prettyBytes: Function;\n setFileNameMin: Function;\n compressSingleFile: Function;\n getContentFromFiles: Function;\n runSync: Function;\n runAsync: Function;\n}\n\n// interface Options {\n// // sourceMap?: { filename: string };\n// // _sourceMap?: { url: string } | boolean;\n// }\n\n// interface Settings {\n// compressor: Function;\n// options: Options;\n// content: string;\n// output: string;\n// type: string;\n// }\n\n// interface MinifierOptions {\n// settings: Settings;\n// content: string /* | Dictionary<string> */;\n// callback: Function;\n// index: number;\n// input: string;\n// sync: boolean;\n// }\n\ninterface WriteFile {\n file: string;\n content: string;\n index: number;\n}\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.readFile = (file: string) => fs.readFileSync(file, 'utf8');\n\n/**\n * Write content into file.\n *\n * @param {String} file\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @returns {String}\n */\nutils.writeFile = ({ file, content, index }: WriteFile) => {\n const _file = index !== undefined ? file[index] : file;\n if (!fs.existsSync(_file) || (fs.existsSync(_file) && !fs.lstatSync(_file).isDirectory())) {\n fs.writeFileSync(_file, content, 'utf8');\n }\n\n return content;\n};\n\n/**\n * Delete file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.deleteFile = (file: string) => fs.unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n *\n * @param {Object} options\n * @returns {Array}\n */\ninterface Dictionary<T> {\n [Key: string]: T;\n}\nutils.buildArgs = (options: Dictionary<string | boolean>) => {\n const args: (string | boolean)[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && options[key] !== false) {\n args.push('--' + key);\n }\n\n if (options[key] && options[key] !== true) {\n args.push(options[key]);\n }\n });\n\n return args;\n};\n\n/**\n * Clone an object.\n *\n * @param {Object} obj\n * @returns {Object}\n */\nutils.clone = (obj: {}) => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n *\n * @returns {String}\n */\nutils.getFilesizeInBytes = (file: string) => {\n const stats = fs.statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n *\n * @returns {Promise.<String>}\n */\nutils.getFilesizeGzippedInBytes = (file: string) => {\n return new Promise(resolve => {\n const source = fs.createReadStream(file);\n source.pipe(gzipSize.stream()).on('gzip-size', size => {\n resolve(utils.prettyBytes(size));\n });\n });\n};\n\n/**\n * Get the size in human readable.\n * From https://github.com/sindresorhus/pretty-bytes\n *\n * @returns {String}\n */\nutils.prettyBytes = (num: number) => {\n const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);\n }\n\n const neg = num < 0;\n\n if (neg) {\n num = -num;\n }\n\n if (num < 1) {\n return (neg ? '-' : '') + num + ' B';\n }\n\n const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);\n const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));\n const unit = UNITS[exponent];\n\n return (neg ? '-' : '') + numStr + ' ' + unit;\n};\n\n/**\n * Set the file name as minified.\n * eg. file.js returns file.min.js\n *\n * @param {String} file\n * @param {String} output\n * @param {String} publicFolder\n * @param {Boolean} replaceInPlace\n * @returns {String}\n */\nutils.setFileNameMin = (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => {\n const filePath = file.substr(0, file.lastIndexOf('/') + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);\n let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));\n if (publicFolder) {\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n return output.replace('$1', fileWithoutExtension);\n};\n\n/**\n * Compress a single file.\n *\n * @param {Object} settings\n */\nutils.compressSingleFile = (settings: MinifierOptions) => {\n const content = settings.content ? settings.content : utils.getContentFromFiles(settings.input);\n return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n *\n * @param {String|Array} input\n * @return {String}\n */\nutils.getContentFromFiles = (input: string) => {\n if (!Array.isArray(input)) {\n return fs.readFileSync(input, 'utf8');\n }\n\n return input\n .map(path =>\n !fs.existsSync(path) || (fs.existsSync(path) && !fs.lstatSync(path).isDirectory())\n ? fs.readFileSync(path, 'utf8')\n : ''\n )\n .join('\\n');\n};\n\n/**\n * Run compressor in sync.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {String}\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions) =>\n settings && typeof settings.compressor !== 'string'\n ? settings.compressor({ settings, content, callback: null, index })\n : null;\n\n/**\n * Run compressor in async.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {Promise}\n */\nutils.runAsync = ({ settings, content, index }: MinifierOptions) => {\n return new Promise((resolve, reject) => {\n settings && typeof settings.compressor !== 'string'\n ? settings.compressor({\n settings,\n content,\n callback: (err: Error, min: string) => {\n if (err) {\n return reject(err);\n }\n resolve(min);\n },\n index\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils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S,KAAK;AAC9F,SAAO,SAAS,OAAO,MAAM,QAAQ,EAAE,UAAU,QAAQ,CAAC,IAAI,MAAM,SAAS,EAAE,UAAU,QAAQ,CAAC;AACpG;AAQA,MAAM,sBAAsB,CAAC,UAAkB;AAC7C,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,UAAAD,QAAG,aAAa,OAAO,MAAM;AAAA,EACtC;AAEA,SAAO,MACJ;AAAA,IAAI,UACH,CAAC,UAAAA,QAAG,WAAW,IAAI,KAAM,UAAAA,QAAG,WAAW,IAAI,KAAK,CAAC,UAAAA,QAAG,UAAU,IAAI,EAAE,YAAY,IAC5E,UAAAA,QAAG,aAAa,MAAM,MAAM,IAC5B;AAAA,EACN,EACC,KAAK,IAAI;AACd;AAUA,MAAM,UAAU,CAAC,EAAE,UAAU,SAAS,MAAM,MAC1C,YAAY,OAAO,SAAS,eAAe,WACvC,SAAS,WAAW,EAAE,UAAU,SAAS,UAAU,MAAM,MAAM,CAAC,IAChE;AAUN,MAAM,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM,MAAuB;AAClE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAY,OAAO,SAAS,eAAe,WACvC,SAAS,WAAW;AAAA,MAClB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAY,QAAgB;AACrC,YAAI,KAAK;AACP,iBAAO,OAAO,GAAG;AAAA,QACnB;AACA,gBAAQ,GAAG;AAAA,MACb;AAAA,MACA;AAAA,IACF,CAAC,IACD;AAAA,EACN,CAAC;AACH;","names":["fs","gzipSize"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,105 @@
1
+ // src/index.ts
2
+ import fs from "fs";
3
+ import gzipSize from "gzip-size";
4
+ var utils = {};
5
+ utils.readFile = (file) => fs.readFileSync(file, "utf8");
6
+ utils.writeFile = ({ file, content, index }) => {
7
+ const _file = index !== void 0 ? file[index] : file;
8
+ if (!fs.existsSync(_file) || fs.existsSync(_file) && !fs.lstatSync(_file).isDirectory()) {
9
+ fs.writeFileSync(_file, content, "utf8");
10
+ }
11
+ return content;
12
+ };
13
+ utils.deleteFile = (file) => fs.unlinkSync(file);
14
+ utils.buildArgs = (options) => {
15
+ const args = [];
16
+ Object.keys(options).forEach((key) => {
17
+ if (options[key] && options[key] !== false) {
18
+ args.push("--" + key);
19
+ }
20
+ if (options[key] && options[key] !== true) {
21
+ args.push(options[key]);
22
+ }
23
+ });
24
+ return args;
25
+ };
26
+ utils.clone = (obj) => JSON.parse(JSON.stringify(obj));
27
+ utils.getFilesizeInBytes = (file) => {
28
+ const stats = fs.statSync(file);
29
+ const fileSizeInBytes = stats.size;
30
+ return utils.prettyBytes(fileSizeInBytes);
31
+ };
32
+ utils.getFilesizeGzippedInBytes = (file) => {
33
+ return new Promise((resolve) => {
34
+ const source = fs.createReadStream(file);
35
+ source.pipe(gzipSize.stream()).on("gzip-size", (size) => {
36
+ resolve(utils.prettyBytes(size));
37
+ });
38
+ });
39
+ };
40
+ utils.prettyBytes = (num) => {
41
+ const UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
42
+ if (!Number.isFinite(num)) {
43
+ throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);
44
+ }
45
+ const neg = num < 0;
46
+ if (neg) {
47
+ num = -num;
48
+ }
49
+ if (num < 1) {
50
+ return (neg ? "-" : "") + num + " B";
51
+ }
52
+ const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1e3)), UNITS.length - 1);
53
+ const numStr = Number((num / Math.pow(1e3, exponent)).toPrecision(3));
54
+ const unit = UNITS[exponent];
55
+ return (neg ? "-" : "") + numStr + " " + unit;
56
+ };
57
+ utils.setFileNameMin = (file, output, publicFolder, replaceInPlace) => {
58
+ const filePath = file.substr(0, file.lastIndexOf("/") + 1);
59
+ const fileWithoutPath = file.substr(file.lastIndexOf("/") + 1);
60
+ let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf("."));
61
+ if (publicFolder) {
62
+ fileWithoutExtension = publicFolder + fileWithoutExtension;
63
+ }
64
+ if (replaceInPlace) {
65
+ fileWithoutExtension = filePath + fileWithoutExtension;
66
+ }
67
+ return output.replace("$1", fileWithoutExtension);
68
+ };
69
+ utils.compressSingleFile = (settings) => {
70
+ const content = settings.content ? settings.content : utils.getContentFromFiles(settings.input);
71
+ return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });
72
+ };
73
+ utils.getContentFromFiles = (input) => {
74
+ if (!Array.isArray(input)) {
75
+ return fs.readFileSync(input, "utf8");
76
+ }
77
+ return input.map(
78
+ (path) => !fs.existsSync(path) || fs.existsSync(path) && !fs.lstatSync(path).isDirectory() ? fs.readFileSync(path, "utf8") : ""
79
+ ).join("\n");
80
+ };
81
+ utils.runSync = ({ settings, content, index }) => settings && typeof settings.compressor !== "string" ? settings.compressor({ settings, content, callback: null, index }) : null;
82
+ utils.runAsync = ({ settings, content, index }) => {
83
+ return new Promise((resolve, reject) => {
84
+ settings && typeof settings.compressor !== "string" ? settings.compressor({
85
+ settings,
86
+ content,
87
+ callback: (err, min) => {
88
+ if (err) {
89
+ return reject(err);
90
+ }
91
+ resolve(min);
92
+ },
93
+ index
94
+ }) : null;
95
+ });
96
+ };
97
+ export {
98
+ utils
99
+ };
100
+ /*!
101
+ * node-minify
102
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
103
+ * MIT Licensed
104
+ */
105
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport fs from 'fs';\nimport gzipSize from 'gzip-size';\nimport { MinifierOptions } from '@node-minify/types';\n// import { MinifierOptions } from '../../../types';\n\ninterface Utils {\n readFile: Function;\n writeFile: Function;\n deleteFile: Function;\n buildArgs: Function;\n clone: Function;\n getFilesizeInBytes: Function;\n getFilesizeGzippedInBytes: Function;\n prettyBytes: Function;\n setFileNameMin: Function;\n compressSingleFile: Function;\n getContentFromFiles: Function;\n runSync: Function;\n runAsync: Function;\n}\n\n// interface Options {\n// // sourceMap?: { filename: string };\n// // _sourceMap?: { url: string } | boolean;\n// }\n\n// interface Settings {\n// compressor: Function;\n// options: Options;\n// content: string;\n// output: string;\n// type: string;\n// }\n\n// interface MinifierOptions {\n// settings: Settings;\n// content: string /* | Dictionary<string> */;\n// callback: Function;\n// index: number;\n// input: string;\n// sync: boolean;\n// }\n\ninterface WriteFile {\n file: string;\n content: string;\n index: number;\n}\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.readFile = (file: string) => fs.readFileSync(file, 'utf8');\n\n/**\n * Write content into file.\n *\n * @param {String} file\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @returns {String}\n */\nutils.writeFile = ({ file, content, index }: WriteFile) => {\n const _file = index !== undefined ? file[index] : file;\n if (!fs.existsSync(_file) || (fs.existsSync(_file) && !fs.lstatSync(_file).isDirectory())) {\n fs.writeFileSync(_file, content, 'utf8');\n }\n\n return content;\n};\n\n/**\n * Delete file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.deleteFile = (file: string) => fs.unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n *\n * @param {Object} options\n * @returns {Array}\n */\ninterface Dictionary<T> {\n [Key: string]: T;\n}\nutils.buildArgs = (options: Dictionary<string | boolean>) => {\n const args: (string | boolean)[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && options[key] !== false) {\n args.push('--' + key);\n }\n\n if (options[key] && options[key] !== true) {\n args.push(options[key]);\n }\n });\n\n return args;\n};\n\n/**\n * Clone an object.\n *\n * @param {Object} obj\n * @returns {Object}\n */\nutils.clone = (obj: {}) => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n *\n * @returns {String}\n */\nutils.getFilesizeInBytes = (file: string) => {\n const stats = fs.statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n *\n * @returns {Promise.<String>}\n */\nutils.getFilesizeGzippedInBytes = (file: string) => {\n return new Promise(resolve => {\n const source = fs.createReadStream(file);\n source.pipe(gzipSize.stream()).on('gzip-size', size => {\n resolve(utils.prettyBytes(size));\n });\n });\n};\n\n/**\n * Get the size in human readable.\n * From https://github.com/sindresorhus/pretty-bytes\n *\n * @returns {String}\n */\nutils.prettyBytes = (num: number) => {\n const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);\n }\n\n const neg = num < 0;\n\n if (neg) {\n num = -num;\n }\n\n if (num < 1) {\n return (neg ? '-' : '') + num + ' B';\n }\n\n const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);\n const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));\n const unit = UNITS[exponent];\n\n return (neg ? '-' : '') + numStr + ' ' + unit;\n};\n\n/**\n * Set the file name as minified.\n * eg. file.js returns file.min.js\n *\n * @param {String} file\n * @param {String} output\n * @param {String} publicFolder\n * @param {Boolean} replaceInPlace\n * @returns {String}\n */\nutils.setFileNameMin = (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => {\n const filePath = file.substr(0, file.lastIndexOf('/') + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);\n let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));\n if (publicFolder) {\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n return output.replace('$1', fileWithoutExtension);\n};\n\n/**\n * Compress a single file.\n *\n * @param {Object} settings\n */\nutils.compressSingleFile = (settings: MinifierOptions) => {\n const content = settings.content ? settings.content : utils.getContentFromFiles(settings.input);\n return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n *\n * @param {String|Array} input\n * @return {String}\n */\nutils.getContentFromFiles = (input: string) => {\n if (!Array.isArray(input)) {\n return fs.readFileSync(input, 'utf8');\n }\n\n return input\n .map(path =>\n !fs.existsSync(path) || (fs.existsSync(path) && !fs.lstatSync(path).isDirectory())\n ? fs.readFileSync(path, 'utf8')\n : ''\n )\n .join('\\n');\n};\n\n/**\n * Run compressor in sync.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {String}\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions) =>\n settings && typeof settings.compressor !== 'string'\n ? settings.compressor({ settings, content, callback: null, index })\n : null;\n\n/**\n * Run compressor in async.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {Promise}\n */\nutils.runAsync = ({ settings, content, index }: MinifierOptions) => {\n return new Promise((resolve, reject) => {\n settings && typeof settings.compressor !== 'string'\n ? settings.compressor({\n settings,\n content,\n callback: (err: Error, min: string) => {\n if (err) {\n return reject(err);\n }\n resolve(min);\n },\n index\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils };\n"],"mappings":";AASA,OAAO,QAAQ;AACf,OAAO,cAAc;AAgDrB,IAAM,QAAQ,CAAC;AAQf,MAAM,WAAW,CAAC,SAAiB,GAAG,aAAa,MAAM,MAAM;AAU/D,MAAM,YAAY,CAAC,EAAE,MAAM,SAAS,MAAM,MAAiB;AACzD,QAAM,QAAQ,UAAU,SAAY,KAAK,SAAS;AAClD,MAAI,CAAC,GAAG,WAAW,KAAK,KAAM,GAAG,WAAW,KAAK,KAAK,CAAC,GAAG,UAAU,KAAK,EAAE,YAAY,GAAI;AACzF,OAAG,cAAc,OAAO,SAAS,MAAM;AAAA,EACzC;AAEA,SAAO;AACT;AAQA,MAAM,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AS,WAAW,EAAE,UAAU,SAAS,UAAU,MAAM,MAAM,CAAC,IAChE;AAUN,MAAM,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM,MAAuB;AAClE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAY,OAAO,SAAS,eAAe,WACvC,SAAS,WAAW;AAAA,MAClB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAY,QAAgB;AACrC,YAAI,KAAK;AACP,iBAAO,OAAO,GAAG;AAAA,QACnB;AACA,gBAAQ,GAAG;AAAA,MACb;AAAA,MACA;AAAA,IACF,CAAC,IACD;AAAA,EACN,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,25 +1,33 @@
1
1
  {
2
2
  "name": "@node-minify/utils",
3
- "version": "7.1.0",
3
+ "version": "8.0.1-beta.0",
4
4
  "description": "utils for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
7
7
  "minify",
8
- "minifier"
8
+ "minifier",
9
+ "utils"
9
10
  ],
10
11
  "author": "Rodolphe Stoclin <srodolphe@gmail.com>",
11
12
  "homepage": "https://github.com/srod/node-minify/tree/master/packages/utils#readme",
12
13
  "license": "MIT",
13
- "main": "lib/utils.js",
14
14
  "engines": {
15
15
  "node": ">=14.0.0"
16
16
  },
17
17
  "directories": {
18
- "lib": "lib",
18
+ "lib": "dist",
19
19
  "test": "__tests__"
20
20
  },
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.mjs",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ "require": "./dist/index.js",
26
+ "import": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts"
28
+ },
21
29
  "files": [
22
- "lib"
30
+ "dist/**/*"
23
31
  ],
24
32
  "publishConfig": {
25
33
  "access": "public"
@@ -31,8 +39,16 @@
31
39
  "bugs": {
32
40
  "url": "https://github.com/srod/node-minify/issues"
33
41
  },
42
+ "scripts": {
43
+ "clean": "pnpm dlx rimraf dist",
44
+ "build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
45
+ "prepublishOnly": "npm run build"
46
+ },
34
47
  "dependencies": {
35
48
  "gzip-size": "6.0.0"
36
49
  },
37
- "gitHead": "94cef2d5d653c3bddc3e603b4e25c135b0b6f4b3"
50
+ "devDependencies": {
51
+ "@node-minify/types": "8.0.1-beta.0"
52
+ },
53
+ "gitHead": "35a8a41ec86a11cbec05d8a7db9113475ece2cef"
38
54
  }
package/lib/utils.js DELETED
@@ -1,236 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.utils = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _gzipSize = _interopRequireDefault(require("gzip-size"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /*!
11
- * node-minify
12
- * Copyright(c) 2011-2022 Rodolphe Stoclin
13
- * MIT Licensed
14
- */
15
-
16
- /**
17
- * Module dependencies.
18
- */
19
-
20
- const utils = {};
21
-
22
- /**
23
- * Read content from file.
24
- *
25
- * @param {String} file
26
- * @returns {String}
27
- */
28
- exports.utils = utils;
29
- utils.readFile = file => _fs.default.readFileSync(file, 'utf8');
30
-
31
- /**
32
- * Write content into file.
33
- *
34
- * @param {String} file
35
- * @param {String} content
36
- * @param {Number} index - index of the file being processed
37
- * @returns {String}
38
- */
39
- utils.writeFile = ({
40
- file,
41
- content,
42
- index
43
- }) => {
44
- const _file = index !== undefined ? file[index] : file;
45
- if (!_fs.default.existsSync(_file) || _fs.default.existsSync(_file) && !_fs.default.lstatSync(_file).isDirectory()) {
46
- _fs.default.writeFileSync(_file, content, 'utf8');
47
- }
48
- return content;
49
- };
50
-
51
- /**
52
- * Delete file.
53
- *
54
- * @param {String} file
55
- * @returns {String}
56
- */
57
- utils.deleteFile = file => _fs.default.unlinkSync(file);
58
-
59
- /**
60
- * Builds arguments array based on an object.
61
- *
62
- * @param {Object} options
63
- * @returns {Array}
64
- */
65
- utils.buildArgs = options => {
66
- const args = [];
67
- Object.keys(options).forEach(key => {
68
- if (options[key] && options[key] !== false) {
69
- args.push('--' + key);
70
- }
71
- if (options[key] && options[key] !== true) {
72
- args.push(options[key]);
73
- }
74
- });
75
- return args;
76
- };
77
-
78
- /**
79
- * Clone an object.
80
- *
81
- * @param {Object} obj
82
- * @returns {Object}
83
- */
84
- utils.clone = obj => JSON.parse(JSON.stringify(obj));
85
-
86
- /**
87
- * Get the file size in bytes.
88
- *
89
- * @returns {String}
90
- */
91
- utils.getFilesizeInBytes = file => {
92
- const stats = _fs.default.statSync(file);
93
- const fileSizeInBytes = stats.size;
94
- return utils.prettyBytes(fileSizeInBytes);
95
- };
96
-
97
- /**
98
- * Get the gzipped file size in bytes.
99
- *
100
- * @returns {Promise.<String>}
101
- */
102
- utils.getFilesizeGzippedInBytes = file => {
103
- return new Promise(resolve => {
104
- const source = _fs.default.createReadStream(file);
105
- source.pipe(_gzipSize.default.stream()).on('gzip-size', size => {
106
- resolve(utils.prettyBytes(size));
107
- });
108
- });
109
- };
110
-
111
- /**
112
- * Get the size in human readable.
113
- * From https://github.com/sindresorhus/pretty-bytes
114
- *
115
- * @returns {String}
116
- */
117
- utils.prettyBytes = num => {
118
- const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
119
- if (!Number.isFinite(num)) {
120
- throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);
121
- }
122
- const neg = num < 0;
123
- if (neg) {
124
- num = -num;
125
- }
126
- if (num < 1) {
127
- return (neg ? '-' : '') + num + ' B';
128
- }
129
- const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);
130
- const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));
131
- const unit = UNITS[exponent];
132
- return (neg ? '-' : '') + numStr + ' ' + unit;
133
- };
134
-
135
- /**
136
- * Set the file name as minified.
137
- * eg. file.js returns file.min.js
138
- *
139
- * @param {String} file
140
- * @param {String} output
141
- * @param {String} publicFolder
142
- * @param {Boolean} replaceInPlace
143
- * @returns {String}
144
- */
145
- utils.setFileNameMin = (file, output, publicFolder, replaceInPlace) => {
146
- const filePath = file.substr(0, file.lastIndexOf('/') + 1);
147
- const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);
148
- let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));
149
- if (publicFolder) {
150
- fileWithoutExtension = publicFolder + fileWithoutExtension;
151
- }
152
- if (replaceInPlace) {
153
- fileWithoutExtension = filePath + fileWithoutExtension;
154
- }
155
- return output.replace('$1', fileWithoutExtension);
156
- };
157
-
158
- /**
159
- * Compress a single file.
160
- *
161
- * @param {Object} settings
162
- */
163
- utils.compressSingleFile = settings => {
164
- const content = settings.content ? settings.content : utils.getContentFromFiles(settings.input);
165
- return settings.sync ? utils.runSync({
166
- settings,
167
- content
168
- }) : utils.runAsync({
169
- settings,
170
- content
171
- });
172
- };
173
-
174
- /**
175
- * Concatenate all input files and get the data.
176
- *
177
- * @param {String|Array} input
178
- * @return {String}
179
- */
180
- utils.getContentFromFiles = input => {
181
- if (!Array.isArray(input)) {
182
- return _fs.default.readFileSync(input, 'utf8');
183
- }
184
- return input.map(path => !_fs.default.existsSync(path) || _fs.default.existsSync(path) && !_fs.default.lstatSync(path).isDirectory() ? _fs.default.readFileSync(path, 'utf8') : '').join('\n');
185
- };
186
-
187
- /**
188
- * Run compressor in sync.
189
- *
190
- * @param {Object} settings
191
- * @param {String} content
192
- * @param {Number} index - index of the file being processed
193
- * @return {String}
194
- */
195
- utils.runSync = ({
196
- settings,
197
- content,
198
- index
199
- }) => settings.compressor({
200
- settings,
201
- content,
202
- callback: null,
203
- index
204
- });
205
-
206
- /**
207
- * Run compressor in async.
208
- *
209
- * @param {Object} settings
210
- * @param {String} content
211
- * @param {Number} index - index of the file being processed
212
- * @return {Promise}
213
- */
214
- utils.runAsync = ({
215
- settings,
216
- content,
217
- index
218
- }) => {
219
- return new Promise((resolve, reject) => {
220
- settings.compressor({
221
- settings,
222
- content,
223
- callback: (err, min) => {
224
- if (err) {
225
- return reject(err);
226
- }
227
- resolve(min);
228
- },
229
- index
230
- });
231
- });
232
- };
233
-
234
- /**
235
- * Expose `utils`.
236
- */