@node-minify/utils 9.0.1 → 10.0.0-next.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.
@@ -1,24 +1,49 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
1
30
  // src/index.ts
2
- import {
3
- createReadStream,
4
- existsSync,
5
- lstatSync,
6
- readFileSync,
7
- statSync,
8
- unlinkSync,
9
- writeFileSync
10
- } from "node:fs";
11
- import gzipSize from "gzip-size";
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ utils: () => utils
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_node_fs = require("fs");
12
37
  var utils = {};
13
- utils.readFile = (file) => readFileSync(file, "utf8");
38
+ utils.readFile = (file) => (0, import_node_fs.readFileSync)(file, "utf8");
14
39
  utils.writeFile = ({ file, content, index }) => {
15
40
  const _file = index !== void 0 ? file[index] : file;
16
- if (!existsSync(_file) || existsSync(_file) && !lstatSync(_file).isDirectory()) {
17
- writeFileSync(_file, content, "utf8");
41
+ if (!(0, import_node_fs.existsSync)(_file) || (0, import_node_fs.existsSync)(_file) && !(0, import_node_fs.lstatSync)(_file).isDirectory()) {
42
+ (0, import_node_fs.writeFileSync)(_file, content, "utf8");
18
43
  }
19
44
  return content;
20
45
  };
21
- utils.deleteFile = (file) => unlinkSync(file);
46
+ utils.deleteFile = (file) => (0, import_node_fs.unlinkSync)(file);
22
47
  utils.buildArgs = (options) => {
23
48
  const args = [];
24
49
  Object.keys(options).forEach((key) => {
@@ -33,14 +58,15 @@ utils.buildArgs = (options) => {
33
58
  };
34
59
  utils.clone = (obj) => JSON.parse(JSON.stringify(obj));
35
60
  utils.getFilesizeInBytes = (file) => {
36
- const stats = statSync(file);
61
+ const stats = (0, import_node_fs.statSync)(file);
37
62
  const fileSizeInBytes = stats.size;
38
63
  return utils.prettyBytes(fileSizeInBytes);
39
64
  };
40
- utils.getFilesizeGzippedInBytes = (file) => {
65
+ utils.getFilesizeGzippedInBytes = async (file) => {
66
+ const { gzipSizeStream } = await import("gzip-size");
41
67
  return new Promise((resolve) => {
42
- const source = createReadStream(file);
43
- source.pipe(gzipSize.stream()).on("gzip-size", (size) => {
68
+ const source = (0, import_node_fs.createReadStream)(file);
69
+ source.pipe(gzipSizeStream()).on("gzip-size", (size) => {
44
70
  resolve(utils.prettyBytes(size));
45
71
  });
46
72
  });
@@ -88,10 +114,10 @@ utils.compressSingleFile = (settings) => {
88
114
  };
89
115
  utils.getContentFromFiles = (input) => {
90
116
  if (!Array.isArray(input)) {
91
- return readFileSync(input, "utf8");
117
+ return (0, import_node_fs.readFileSync)(input, "utf8");
92
118
  }
93
119
  return input.map(
94
- (path) => !existsSync(path) || existsSync(path) && !lstatSync(path).isDirectory() ? readFileSync(path, "utf8") : ""
120
+ (path) => !(0, import_node_fs.existsSync)(path) || (0, import_node_fs.existsSync)(path) && !(0, import_node_fs.lstatSync)(path).isDirectory() ? (0, import_node_fs.readFileSync)(path, "utf8") : ""
95
121
  ).join("\n");
96
122
  };
97
123
  utils.runSync = ({ settings, content, index }) => settings && typeof settings.compressor !== "string" ? typeof settings.compressor === "function" ? String(
@@ -121,12 +147,19 @@ utils.runAsync = ({
121
147
  }) : null;
122
148
  });
123
149
  };
124
- export {
150
+ // Annotate the CommonJS export names for ESM import in node:
151
+ 0 && (module.exports = {
125
152
  utils
126
- };
153
+ });
127
154
  /*!
128
155
  * node-minify
129
156
  * Copyright(c) 2011-2024 Rodolphe Stoclin
130
157
  * MIT Licensed
131
158
  */
132
- //# sourceMappingURL=index.mjs.map
159
+
160
+ // fix-cjs-exports
161
+ if (module.exports.default) {
162
+ Object.assign(module.exports.default, module.exports);
163
+ module.exports = module.exports.default;
164
+ delete module.exports.default;
165
+ }
package/dist/index.js CHANGED
@@ -1,50 +1,23 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
1
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- utils: () => utils
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
- var import_node_fs = require("fs");
37
- var import_gzip_size = __toESM(require("gzip-size"));
2
+ import {
3
+ createReadStream,
4
+ existsSync,
5
+ lstatSync,
6
+ readFileSync,
7
+ statSync,
8
+ unlinkSync,
9
+ writeFileSync
10
+ } from "node:fs";
38
11
  var utils = {};
39
- utils.readFile = (file) => (0, import_node_fs.readFileSync)(file, "utf8");
12
+ utils.readFile = (file) => readFileSync(file, "utf8");
40
13
  utils.writeFile = ({ file, content, index }) => {
41
14
  const _file = index !== void 0 ? file[index] : file;
42
- if (!(0, import_node_fs.existsSync)(_file) || (0, import_node_fs.existsSync)(_file) && !(0, import_node_fs.lstatSync)(_file).isDirectory()) {
43
- (0, import_node_fs.writeFileSync)(_file, content, "utf8");
15
+ if (!existsSync(_file) || existsSync(_file) && !lstatSync(_file).isDirectory()) {
16
+ writeFileSync(_file, content, "utf8");
44
17
  }
45
18
  return content;
46
19
  };
47
- utils.deleteFile = (file) => (0, import_node_fs.unlinkSync)(file);
20
+ utils.deleteFile = (file) => unlinkSync(file);
48
21
  utils.buildArgs = (options) => {
49
22
  const args = [];
50
23
  Object.keys(options).forEach((key) => {
@@ -59,14 +32,15 @@ utils.buildArgs = (options) => {
59
32
  };
60
33
  utils.clone = (obj) => JSON.parse(JSON.stringify(obj));
61
34
  utils.getFilesizeInBytes = (file) => {
62
- const stats = (0, import_node_fs.statSync)(file);
35
+ const stats = statSync(file);
63
36
  const fileSizeInBytes = stats.size;
64
37
  return utils.prettyBytes(fileSizeInBytes);
65
38
  };
66
- utils.getFilesizeGzippedInBytes = (file) => {
39
+ utils.getFilesizeGzippedInBytes = async (file) => {
40
+ const { gzipSizeStream } = await import("gzip-size");
67
41
  return new Promise((resolve) => {
68
- const source = (0, import_node_fs.createReadStream)(file);
69
- source.pipe(import_gzip_size.default.stream()).on("gzip-size", (size) => {
42
+ const source = createReadStream(file);
43
+ source.pipe(gzipSizeStream()).on("gzip-size", (size) => {
70
44
  resolve(utils.prettyBytes(size));
71
45
  });
72
46
  });
@@ -114,10 +88,10 @@ utils.compressSingleFile = (settings) => {
114
88
  };
115
89
  utils.getContentFromFiles = (input) => {
116
90
  if (!Array.isArray(input)) {
117
- return (0, import_node_fs.readFileSync)(input, "utf8");
91
+ return readFileSync(input, "utf8");
118
92
  }
119
93
  return input.map(
120
- (path) => !(0, import_node_fs.existsSync)(path) || (0, import_node_fs.existsSync)(path) && !(0, import_node_fs.lstatSync)(path).isDirectory() ? (0, import_node_fs.readFileSync)(path, "utf8") : ""
94
+ (path) => !existsSync(path) || existsSync(path) && !lstatSync(path).isDirectory() ? readFileSync(path, "utf8") : ""
121
95
  ).join("\n");
122
96
  };
123
97
  utils.runSync = ({ settings, content, index }) => settings && typeof settings.compressor !== "string" ? typeof settings.compressor === "function" ? String(
@@ -147,13 +121,11 @@ utils.runAsync = ({
147
121
  }) : null;
148
122
  });
149
123
  };
150
- // Annotate the CommonJS export names for ESM import in node:
151
- 0 && (module.exports = {
124
+ export {
152
125
  utils
153
- });
126
+ };
154
127
  /*!
155
128
  * node-minify
156
129
  * Copyright(c) 2011-2024 Rodolphe Stoclin
157
130
  * MIT Licensed
158
131
  */
159
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/utils",
3
- "version": "9.0.1",
3
+ "version": "10.0.0-next.0",
4
4
  "description": "utils for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -9,23 +9,22 @@
9
9
  "utils"
10
10
  ],
11
11
  "author": "Rodolphe Stoclin <srodolphe@gmail.com>",
12
- "homepage": "https://github.com/srod/node-minify/tree/master/packages/utils#readme",
12
+ "homepage": "https://github.com/srod/node-minify/tree/main/packages/utils#readme",
13
13
  "license": "MIT",
14
+ "type": "module",
14
15
  "engines": {
15
- "node": ">=18.0.0"
16
+ "node": ">=22.0.0"
16
17
  },
17
18
  "directories": {
18
19
  "lib": "dist",
19
20
  "test": "__tests__"
20
21
  },
21
- "main": "./dist/index.js",
22
- "module": "./dist/index.mjs",
23
- "types": "./dist/index.d.ts",
22
+ "main": "./dist/index.cjs",
24
23
  "exports": {
24
+ "./package.json": "./package.json",
25
25
  ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.mjs",
28
- "require": "./dist/index.js"
26
+ "import": "./dist/index.js",
27
+ "default": "./dist/index.cjs"
29
28
  }
30
29
  },
31
30
  "files": [
@@ -41,18 +40,20 @@
41
40
  "bugs": {
42
41
  "url": "https://github.com/srod/node-minify/issues"
43
42
  },
44
- "dependencies": {
45
- "gzip-size": "6.0.0"
46
- },
47
- "devDependencies": {
48
- "@node-minify/types": "9.0.0"
49
- },
50
43
  "scripts": {
51
- "clean": "pnpm dlx rimraf dist",
52
- "build": "pnpm clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
44
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean && bunx fix-tsup-cjs",
45
+ "check-exports": "attw --pack .",
46
+ "format:check": "biome check .",
53
47
  "lint": "biome lint .",
48
+ "prepublishOnly": "bun run build",
54
49
  "test": "vitest run",
55
50
  "test:ci": "vitest run --coverage",
56
51
  "test:watch": "vitest"
52
+ },
53
+ "dependencies": {
54
+ "gzip-size": "7.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "@node-minify/types": "workspace:*"
57
58
  }
58
- }
59
+ }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport {\n createReadStream,\n existsSync,\n lstatSync,\n readFileSync,\n statSync,\n unlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport type {\n MinifierOptions,\n OptionsPossible,\n Settings,\n} from \"@node-minify/types\";\nimport gzipSize from \"gzip-size\";\n\ntype Utils = {\n readFile: (file: string) => string;\n writeFile: ({ file, content, index }: WriteFile) => string;\n deleteFile: (file: string) => void;\n buildArgs: (options: Record<string, OptionsPossible>) => any;\n clone: (obj: object) => object;\n getFilesizeInBytes: (file: string) => string;\n getFilesizeGzippedInBytes: (file: string) => Promise<string>;\n prettyBytes: (num: number) => string;\n setFileNameMin: (\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n ) => string;\n compressSingleFile: (settings: Settings) => string | Promise<string>;\n getContentFromFiles: (input: string | string[]) => string;\n runSync: ({ settings, content, index }: MinifierOptions) => string;\n runAsync: ({\n settings,\n content,\n index,\n }: MinifierOptions) => Promise<string>;\n};\n\ntype WriteFile = {\n file: string;\n content: any;\n index?: number;\n};\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n * @param file File name\n */\nutils.readFile = (file: string): string => readFileSync(file, \"utf8\");\n\n/**\n * Write content into file.\n * @param file File name\n * @param content Content to write\n * @param index Index of the file being processed\n */\nutils.writeFile = ({ file, content, index }: WriteFile): string => {\n const _file = index !== undefined ? file[index] : file;\n if (\n !existsSync(_file) ||\n (existsSync(_file) && !lstatSync(_file).isDirectory())\n ) {\n writeFileSync(_file, content, \"utf8\");\n }\n\n return content;\n};\n\n/**\n * Delete file.\n * @param file File name\n */\nutils.deleteFile = (file: string) => unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n * @param options\n */\nutils.buildArgs = (\n options: Record<string, OptionsPossible>\n): OptionsPossible[] => {\n const args: OptionsPossible[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && (options[key] as unknown) !== 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 * @param obj Object\n */\nutils.clone = (obj: object): object => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n * @param file File name\n */\nutils.getFilesizeInBytes = (file: string): string => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n * @param file File name\n */\nutils.getFilesizeGzippedInBytes = (file: string): Promise<string> => {\n return new Promise((resolve) => {\n const source = 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 * @param num Number\n */\nutils.prettyBytes = (num: number): string => {\n const UNITS = [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(\n `Expected a finite number, got ${typeof num}: ${num}`\n );\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(\n Math.floor(Math.log(num) / Math.log(1000)),\n UNITS.length - 1\n );\n const numStr = Number((num / 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 * @param file File name\n * @param output Output file name\n * @param publicFolder Public folder\n * @param replaceInPlace Replace in place\n */\nutils.setFileNameMin = (\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n): string => {\n const filePath = file.substr(0, file.lastIndexOf(\"/\") + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf(\"/\") + 1);\n let fileWithoutExtension = fileWithoutPath.substr(\n 0,\n fileWithoutPath.lastIndexOf(\".\")\n );\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 * @param settings Settings\n */\nutils.compressSingleFile = (settings: Settings): Promise<string> | string => {\n const content = settings.content\n ? settings.content\n : settings.input\n ? utils.getContentFromFiles(settings.input)\n : \"\";\n return settings.sync\n ? utils.runSync({ settings, content })\n : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n * @param input Input files\n */\nutils.getContentFromFiles = (input: string | string[]): string => {\n if (!Array.isArray(input)) {\n return readFileSync(input, \"utf8\");\n }\n\n return input\n .map((path) =>\n !existsSync(path) ||\n (existsSync(path) && !lstatSync(path).isDirectory())\n ? readFileSync(path, \"utf8\")\n : \"\"\n )\n .join(\"\\n\");\n};\n\n/**\n * Run compressor in sync.\n * @param settings Settings\n * @param content Content to minify\n * @param index Index of the file being processed\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions): string =>\n settings && typeof settings.compressor !== \"string\"\n ? typeof settings.compressor === \"function\"\n ? String(\n settings.compressor({\n settings,\n content,\n callback: null,\n index,\n }) || \"\"\n )\n : \"\"\n : \"\";\n\n/**\n * Run compressor in async.\n * @param settings Settings\n * @param content Content to minify\n * @param index Index of the file being processed\n */\nutils.runAsync = ({\n settings,\n content,\n index,\n}: MinifierOptions): Promise<string> => {\n return new Promise((resolve, reject) => {\n settings?.compressor && typeof settings.compressor !== \"string\"\n ? settings.compressor({\n settings,\n content,\n callback: (err: unknown, result?: string) => {\n if (err) {\n return reject(err);\n }\n resolve(result || \"\");\n },\n index,\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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ACV,MAAM,QAAQ,EAAE,UAAU,QAAQ,CAAC,IACnC,MAAM,SAAS,EAAE,UAAU,QAAQ,CAAC;AAC9C;AAMA,MAAM,sBAAsB,CAAC,UAAqC;AAC9D,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACvB,eAAO,6BAAa,OAAO,MAAM;AAAA,EACrC;AAEA,SAAO,MACF;AAAA,IAAI,CAAC,SACF,KAAC,2BAAW,IAAI,SACf,2BAAW,IAAI,KAAK,KAAC,0BAAU,IAAI,EAAE,YAAY,QAC5C,6BAAa,MAAM,MAAM,IACzB;AAAA,EACV,EACC,KAAK,IAAI;AAClB;AAQA,MAAM,UAAU,CAAC,EAAE,UAAU,SAAS,MAAM,MACxC,YAAY,OAAO,SAAS,eAAe,WACrC,OAAO,SAAS,eAAe,aAC3B;AAAA,EACI,SAAS,WAAW;AAAA,IAChB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,EACJ,CAAC,KAAK;AACV,IACA,KACJ;AAQV,MAAM,WAAW,CAAC;AAAA,EACd;AAAA,EACA;AAAA,EACA;AACJ,MAAwC;AACpC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACpC,cAAU,cAAc,OAAO,SAAS,eAAe,WACjD,SAAS,WAAW;AAAA,MAChB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAc,WAAoB;AACzC,YAAI,KAAK;AACL,iBAAO,OAAO,GAAG;AAAA,QACrB;AACA,gBAAQ,UAAU,EAAE;AAAA,MACxB;AAAA,MACA;AAAA,IACJ,CAAC,IACD;AAAA,EACV,CAAC;AACL;","names":["gzipSize"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport {\n createReadStream,\n existsSync,\n lstatSync,\n readFileSync,\n statSync,\n unlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport type {\n MinifierOptions,\n OptionsPossible,\n Settings,\n} from \"@node-minify/types\";\nimport gzipSize from \"gzip-size\";\n\ntype Utils = {\n readFile: (file: string) => string;\n writeFile: ({ file, content, index }: WriteFile) => string;\n deleteFile: (file: string) => void;\n buildArgs: (options: Record<string, OptionsPossible>) => any;\n clone: (obj: object) => object;\n getFilesizeInBytes: (file: string) => string;\n getFilesizeGzippedInBytes: (file: string) => Promise<string>;\n prettyBytes: (num: number) => string;\n setFileNameMin: (\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n ) => string;\n compressSingleFile: (settings: Settings) => string | Promise<string>;\n getContentFromFiles: (input: string | string[]) => string;\n runSync: ({ settings, content, index }: MinifierOptions) => string;\n runAsync: ({\n settings,\n content,\n index,\n }: MinifierOptions) => Promise<string>;\n};\n\ntype WriteFile = {\n file: string;\n content: any;\n index?: number;\n};\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n * @param file File name\n */\nutils.readFile = (file: string): string => readFileSync(file, \"utf8\");\n\n/**\n * Write content into file.\n * @param file File name\n * @param content Content to write\n * @param index Index of the file being processed\n */\nutils.writeFile = ({ file, content, index }: WriteFile): string => {\n const _file = index !== undefined ? file[index] : file;\n if (\n !existsSync(_file) ||\n (existsSync(_file) && !lstatSync(_file).isDirectory())\n ) {\n writeFileSync(_file, content, \"utf8\");\n }\n\n return content;\n};\n\n/**\n * Delete file.\n * @param file File name\n */\nutils.deleteFile = (file: string) => unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n * @param options\n */\nutils.buildArgs = (\n options: Record<string, OptionsPossible>\n): OptionsPossible[] => {\n const args: OptionsPossible[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && (options[key] as unknown) !== 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 * @param obj Object\n */\nutils.clone = (obj: object): object => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n * @param file File name\n */\nutils.getFilesizeInBytes = (file: string): string => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n * @param file File name\n */\nutils.getFilesizeGzippedInBytes = (file: string): Promise<string> => {\n return new Promise((resolve) => {\n const source = 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 * @param num Number\n */\nutils.prettyBytes = (num: number): string => {\n const UNITS = [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(\n `Expected a finite number, got ${typeof num}: ${num}`\n );\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(\n Math.floor(Math.log(num) / Math.log(1000)),\n UNITS.length - 1\n );\n const numStr = Number((num / 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 * @param file File name\n * @param output Output file name\n * @param publicFolder Public folder\n * @param replaceInPlace Replace in place\n */\nutils.setFileNameMin = (\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n): string => {\n const filePath = file.substr(0, file.lastIndexOf(\"/\") + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf(\"/\") + 1);\n let fileWithoutExtension = fileWithoutPath.substr(\n 0,\n fileWithoutPath.lastIndexOf(\".\")\n );\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 * @param settings Settings\n */\nutils.compressSingleFile = (settings: Settings): Promise<string> | string => {\n const content = settings.content\n ? settings.content\n : settings.input\n ? utils.getContentFromFiles(settings.input)\n : \"\";\n return settings.sync\n ? utils.runSync({ settings, content })\n : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n * @param input Input files\n */\nutils.getContentFromFiles = (input: string | string[]): string => {\n if (!Array.isArray(input)) {\n return readFileSync(input, \"utf8\");\n }\n\n return input\n .map((path) =>\n !existsSync(path) ||\n (existsSync(path) && !lstatSync(path).isDirectory())\n ? readFileSync(path, \"utf8\")\n : \"\"\n )\n .join(\"\\n\");\n};\n\n/**\n * Run compressor in sync.\n * @param settings Settings\n * @param content Content to minify\n * @param index Index of the file being processed\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions): string =>\n settings && typeof settings.compressor !== \"string\"\n ? typeof settings.compressor === \"function\"\n ? String(\n settings.compressor({\n settings,\n content,\n callback: null,\n index,\n }) || \"\"\n )\n : \"\"\n : \"\";\n\n/**\n * Run compressor in async.\n * @param settings Settings\n * @param content Content to minify\n * @param index Index of the file being processed\n */\nutils.runAsync = ({\n settings,\n content,\n index,\n}: MinifierOptions): Promise<string> => {\n return new Promise((resolve, reject) => {\n settings?.compressor && typeof settings.compressor !== \"string\"\n ? settings.compressor({\n settings,\n content,\n callback: (err: unknown, result?: string) => {\n if (err) {\n return reject(err);\n }\n resolve(result || \"\");\n },\n index,\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils };\n"],"mappings":";AASA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAMP,OAAO,cAAc;AAiCrB,IAAM,QAAQ,CAAC;AAMf,MAAM,WAAW,CAAC,SAAyB,aAAa,MAAM,MAAM;AAQpE,MAAM,YAAY,CAAC,EAAE,MAAM,SAA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