@node-minify/terser 9.0.1 → 10.0.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Rodolphe Stoclin
3
+ Copyright (c) 2025 Rodolphe Stoclin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -6,8 +6,8 @@
6
6
  <br>
7
7
  <a href="https://npmjs.org/package/@node-minify/terser"><img src="https://img.shields.io/npm/v/@node-minify/terser.svg"></a>
8
8
  <a href="https://npmjs.org/package/@node-minify/terser"><img src="https://img.shields.io/npm/dm/@node-minify/terser.svg"></a>
9
- <a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%3Ddevelop&style=flat" /></a>
10
- <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/develop/graph/badge.svg"></a>
9
+ <a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%3Dmain&style=flat" /></a>
10
+ <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg"></a>
11
11
  </p>
12
12
 
13
13
  # terser
@@ -25,14 +25,13 @@ npm install @node-minify/core @node-minify/terser
25
25
  ## Usage
26
26
 
27
27
  ```js
28
- const minify = require('@node-minify/core');
29
- const terser = require('@node-minify/terser');
28
+ import { minify } from '@node-minify/core';
29
+ import { terser } from '@node-minify/terser';
30
30
 
31
- minify({
31
+ await minify({
32
32
  compressor: terser,
33
33
  input: 'foo.js',
34
- output: 'bar.js',
35
- callback: function (err, min) {}
34
+ output: 'bar.js'
36
35
  });
37
36
  ```
38
37
 
@@ -42,4 +41,4 @@ Visit https://node-minify.2clics.net/compressors/terser.html for full documentat
42
41
 
43
42
  ## License
44
43
 
45
- [MIT](https://github.com/srod/node-minify/blob/develop/LICENSE)
44
+ [MIT](https://github.com/srod/node-minify/blob/main/LICENSE)
package/dist/index.d.ts CHANGED
@@ -1,25 +1,161 @@
1
- import { MinifierOptions } from '@node-minify/types';
1
+ //#region ../types/src/types.d.ts
2
2
 
3
- /*!
4
- * node-minify
5
- * Copyright(c) 2011-2024 Rodolphe Stoclin
6
- * MIT Licensed
3
+ /**
4
+ * Result returned by a compressor function.
7
5
  */
8
-
9
- type OptionsTerser = {
10
- sourceMap?: {
11
- url: string;
12
- };
13
- };
14
- type SettingsTerser = {
15
- options: OptionsTerser;
16
- };
17
- type MinifierOptionsTerser = {
18
- settings: SettingsTerser;
6
+ type CompressorResult = {
7
+ code: string;
8
+ map?: string;
19
9
  };
20
- declare const minifyTerser: {
21
- ({ settings, content, callback, index, }: MinifierOptions & MinifierOptionsTerser): Promise<string | void>;
22
- default: any;
10
+ /**
11
+ * Base options that all compressors can accept.
12
+ * Specific compressors may extend this with their own options.
13
+ */
14
+ type CompressorOptions = Record<string, unknown>;
15
+ /**
16
+ * A compressor function that minifies content.
17
+ * @param args - The minifier options including settings and content
18
+ * @returns A promise resolving to the compression result
19
+ */
20
+ type Compressor<TOptions extends CompressorOptions = CompressorOptions> = (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;
21
+ /**
22
+ * File type for compressors that support multiple types (e.g., YUI).
23
+ */
24
+ type FileType = "js" | "css";
25
+ /**
26
+ * User-facing settings for the minify function.
27
+ * This is what users pass when calling minify().
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { minify } from '@node-minify/core';
32
+ * import { terser } from '@node-minify/terser';
33
+ *
34
+ * await minify({
35
+ * compressor: terser,
36
+ * input: 'src/*.js',
37
+ * output: 'dist/bundle.min.js',
38
+ * options: { mangle: true }
39
+ * });
40
+ * ```
41
+ */
42
+ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
43
+ /**
44
+ * The compressor function to use for minification.
45
+ */
46
+ compressor: Compressor<TOptions>;
47
+
48
+ /**
49
+ * Optional label for the compressor (used in logging).
50
+ */
51
+ compressorLabel?: string;
52
+
53
+ /**
54
+ * Content to minify (for in-memory minification).
55
+ * If provided, input/output are not required.
56
+ */
57
+ content?: string;
58
+
59
+ /**
60
+ * Input file path(s) or glob pattern.
61
+ * Can be a single file, array of files, or wildcard pattern.
62
+ *
63
+ * @example
64
+ * - 'src/app.js'
65
+ * - ['src/a.js', 'src/b.js']
66
+ * - 'src/**\/*.js'
67
+ */
68
+ input?: string | string[];
69
+
70
+ /**
71
+ * Output file path.
72
+ * Use $1 as placeholder for input filename in multi-file scenarios.
73
+ * Can be a single file, array of files, or pattern with $1.
74
+ *
75
+ * @example
76
+ * - 'dist/bundle.min.js'
77
+ * - ['file1.min.js', 'file2.min.js']
78
+ * - '$1.min.js' (creates app.min.js from app.js)
79
+ */
80
+ output?: string | string[];
81
+
82
+ /**
83
+ * Compressor-specific options.
84
+ * See individual compressor documentation for available options.
85
+ */
86
+ options?: TOptions;
87
+
88
+ /**
89
+ * CLI option string (used by CLI only).
90
+ * @internal
91
+ */
92
+ option?: string;
93
+
94
+ /**
95
+ * Buffer size for file operations (in bytes).
96
+ * @default 1024000 (1MB)
97
+ */
98
+ buffer?: number;
99
+
100
+ /**
101
+ * File type for compressors that support multiple types.
102
+ * Required for YUI compressor.
103
+ */
104
+ type?: FileType;
105
+
106
+ /**
107
+ * Suppress console output.
108
+ * @default false
109
+ */
110
+ silence?: boolean;
111
+
112
+ /**
113
+ * Public folder to prepend to input paths.
114
+ *
115
+ * @example
116
+ * With publicFolder: 'public/js/' and input: 'app.js',
117
+ * the actual path becomes 'public/js/app.js'
118
+ */
119
+ publicFolder?: string;
120
+
121
+ /**
122
+ * Replace files in place instead of creating new output files.
123
+ * @default false
124
+ */
125
+ replaceInPlace?: boolean;
23
126
  };
127
+ /**
128
+ * Options passed to compressor functions internally.
129
+ * This is what compressors receive, not what users pass.
130
+ */
131
+ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
132
+ /**
133
+ * The full settings object.
134
+ */
135
+ settings: Settings<TOptions>;
136
+
137
+ /**
138
+ * The content to minify.
139
+ */
140
+ content?: string;
24
141
 
25
- export { minifyTerser as default };
142
+ /**
143
+ * Index of current file when processing multiple files.
144
+ */
145
+ index?: number;
146
+ };
147
+ //#endregion
148
+ //#region src/index.d.ts
149
+ /**
150
+ * Run terser.
151
+ * @param settings - Terser options
152
+ * @param content - Content to minify
153
+ * @returns Minified content and optional source map
154
+ */
155
+ declare function terser({
156
+ settings,
157
+ content
158
+ }: MinifierOptions): Promise<CompressorResult>;
159
+ //#endregion
160
+ export { terser };
161
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":["CompressorReturnType","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * The return type of a compressor function.\n * @deprecated Use `CompressorResult` instead. Will be removed in v11.\n */\nexport type CompressorReturnType = string;\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n code: string;\n map?: string;\n};\n\n/**\n * Base options that all compressors can accept.\n * Specific compressors may extend this with their own options.\n */\nexport type CompressorOptions = Record<string, unknown>;\n\n/**\n * A compressor function that minifies content.\n * @param args - The minifier options including settings and content\n * @returns A promise resolving to the compression result\n */\nexport type Compressor<TOptions extends CompressorOptions = CompressorOptions> =\n (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;\n\n/**\n * File type for compressors that support multiple types (e.g., YUI).\n */\nexport type FileType = \"js\" | \"css\";\n\n/**\n * User-facing settings for the minify function.\n * This is what users pass when calling minify().\n *\n * @example\n * ```ts\n * import { minify } from '@node-minify/core';\n * import { terser } from '@node-minify/terser';\n *\n * await minify({\n * compressor: terser,\n * input: 'src/*.js',\n * output: 'dist/bundle.min.js',\n * options: { mangle: true }\n * });\n * ```\n */\nexport type Settings<TOptions extends CompressorOptions = CompressorOptions> = {\n /**\n * The compressor function to use for minification.\n */\n compressor: Compressor<TOptions>;\n\n /**\n * Optional label for the compressor (used in logging).\n */\n compressorLabel?: string;\n\n /**\n * Content to minify (for in-memory minification).\n * If provided, input/output are not required.\n */\n content?: string;\n\n /**\n * Input file path(s) or glob pattern.\n * Can be a single file, array of files, or wildcard pattern.\n *\n * @example\n * - 'src/app.js'\n * - ['src/a.js', 'src/b.js']\n * - 'src/**\\/*.js'\n */\n input?: string | string[];\n\n /**\n * Output file path.\n * Use $1 as placeholder for input filename in multi-file scenarios.\n * Can be a single file, array of files, or pattern with $1.\n *\n * @example\n * - 'dist/bundle.min.js'\n * - ['file1.min.js', 'file2.min.js']\n * - '$1.min.js' (creates app.min.js from app.js)\n */\n output?: string | string[];\n\n /**\n * Compressor-specific options.\n * See individual compressor documentation for available options.\n */\n options?: TOptions;\n\n /**\n * CLI option string (used by CLI only).\n * @internal\n */\n option?: string;\n\n /**\n * Buffer size for file operations (in bytes).\n * @default 1024000 (1MB)\n */\n buffer?: number;\n\n /**\n * File type for compressors that support multiple types.\n * Required for YUI compressor.\n */\n type?: FileType;\n\n /**\n * Suppress console output.\n * @default false\n */\n silence?: boolean;\n\n /**\n * Public folder to prepend to input paths.\n *\n * @example\n * With publicFolder: 'public/js/' and input: 'app.js',\n * the actual path becomes 'public/js/app.js'\n */\n publicFolder?: string;\n\n /**\n * Replace files in place instead of creating new output files.\n * @default false\n */\n replaceInPlace?: boolean;\n};\n\n/**\n * Options passed to compressor functions internally.\n * This is what compressors receive, not what users pass.\n */\nexport type MinifierOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = {\n /**\n * The full settings object.\n */\n settings: Settings<TOptions>;\n\n /**\n * The content to minify.\n */\n content?: string;\n\n /**\n * Index of current file when processing multiple files.\n */\n index?: number;\n};\n\n/**\n * Result returned after compression (used by CLI).\n */\nexport type Result = {\n /**\n * Label of the compressor used.\n */\n compressorLabel: string;\n\n /**\n * Size of minified content (formatted string, e.g., \"1.5 KB\").\n */\n size: string;\n\n /**\n * Gzipped size of minified content (formatted string).\n */\n sizeGzip: string;\n};\n\n/**\n * Type alias for user convenience.\n * @deprecated Use `Settings` instead. Will be removed in v11.\n */\nexport type MinifyOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = Settings<TOptions>;\n"],"mappings":";;AAwDA;;;AAI2BK,KA7CfJ,gBAAAA,GA6CeI;EAAXD,IAAAA,EAAAA,MAAAA;EAwCFC,GAAAA,CAAAA,EAAAA,MAAAA;CAkBHG;AA4BX;;;;AAMcC,KAhIFP,iBAAAA,GAAoBC,MAgIlBM,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;ACzId;;AAEI,KDcQL,UCdR,CAAA,iBDcoCF,iBCdpC,GDcwDA,iBCdxD,CAAA,GACD,CAAA,IAAA,EDcQI,eCdR,CDcwBD,QCdxB,CAAA,EAAA,GDcsCE,OCdtC,CDc8CN,gBCd9C,CAAA;;;;KDmBSO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwCbA;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;;;;;;;;;;;;AAnHvB;AAmBYI,iBCzCU,MAAA,CDyCFJ;EAAA,QAAA;EAAA;AAAA,CAAA,ECtCjB,eDsCiB,CAAA,ECtCC,ODsCD,CCtCS,gBDsCT,CAAA"}
package/dist/index.js CHANGED
@@ -1,43 +1,21 @@
1
- "use strict";
1
+ import { minify } from "terser";
2
2
 
3
- // src/index.ts
4
- var import_utils = require("@node-minify/utils");
5
- var import_terser = require("terser");
6
- var minifyTerser = async ({
7
- settings,
8
- content,
9
- callback,
10
- index
11
- }) => {
12
- try {
13
- const contentMinified = await (0, import_terser.minify)(content ?? "", settings?.options);
14
- if (contentMinified.map && typeof settings?.options?.sourceMap?.url === "string") {
15
- import_utils.utils.writeFile({
16
- file: settings.options.sourceMap.url,
17
- content: contentMinified.map,
18
- index
19
- });
20
- }
21
- if (settings && !settings.content && settings.output) {
22
- import_utils.utils.writeFile({
23
- file: settings.output,
24
- content: contentMinified.code,
25
- index
26
- });
27
- }
28
- if (callback) {
29
- return callback(null, contentMinified.code);
30
- }
31
- return contentMinified.code;
32
- } catch (error) {
33
- return callback?.(error);
34
- }
35
- };
36
- minifyTerser.default = minifyTerser;
37
- module.exports = minifyTerser;
38
- /*!
39
- * node-minify
40
- * Copyright(c) 2011-2024 Rodolphe Stoclin
41
- * MIT Licensed
42
- */
3
+ //#region src/index.ts
4
+ /**
5
+ * Run terser.
6
+ * @param settings - Terser options
7
+ * @param content - Content to minify
8
+ * @returns Minified content and optional source map
9
+ */
10
+ async function terser({ settings, content }) {
11
+ const result = await minify(content ?? "", settings?.options);
12
+ if (typeof result.code !== "string") throw new Error("Terser failed: empty result");
13
+ return {
14
+ code: result.code,
15
+ map: typeof result.map === "string" ? result.map : void 0
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ export { terser };
43
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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 type { MinifierOptions } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\n// @ts-expect-error moduleResolution:nodenext issue 54523\nimport { minify } from \"terser\";\n\ntype OptionsTerser = {\n sourceMap?: { url: string };\n};\n\ntype SettingsTerser = {\n options: OptionsTerser;\n};\n\ntype MinifierOptionsTerser = {\n settings: SettingsTerser;\n};\n\n/**\n * Run terser.\n * @param settings Terser options\n * @param content Content to minify\n * @param callback Callback\n * @param index Index of current file in array\n * @returns Minified content\n */\nconst minifyTerser = async ({\n settings,\n content,\n callback,\n index,\n}: MinifierOptions & MinifierOptionsTerser) => {\n try {\n const contentMinified = await minify(content ?? \"\", settings?.options);\n if (\n contentMinified.map &&\n typeof settings?.options?.sourceMap?.url === \"string\"\n ) {\n utils.writeFile({\n file: settings.options.sourceMap.url,\n content: contentMinified.map,\n index,\n });\n }\n if (settings && !settings.content && settings.output) {\n utils.writeFile({\n file: settings.output,\n content: contentMinified.code,\n index,\n });\n }\n if (callback) {\n return callback(null, contentMinified.code);\n }\n return contentMinified.code;\n } catch (error) {\n return callback?.(error);\n }\n};\n\n/**\n * Expose `minifyTerser()`.\n */\nminifyTerser.default = minifyTerser;\nexport = minifyTerser;\n"],"mappings":";;;AAUA,mBAAsB;AAEtB,oBAAuB;AAsBvB,IAAM,eAAe,OAAO;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,MAA+C;AAC3C,MAAI;AACA,UAAM,kBAAkB,UAAM,sBAAO,WAAW,IAAI,UAAU,OAAO;AACrE,QACI,gBAAgB,OAChB,OAAO,UAAU,SAAS,WAAW,QAAQ,UAC/C;AACE,yBAAM,UAAU;AAAA,QACZ,MAAM,SAAS,QAAQ,UAAU;AAAA,QACjC,SAAS,gBAAgB;AAAA,QACzB;AAAA,MACJ,CAAC;AAAA,IACL;AACA,QAAI,YAAY,CAAC,SAAS,WAAW,SAAS,QAAQ;AAClD,yBAAM,UAAU;AAAA,QACZ,MAAM,SAAS;AAAA,QACf,SAAS,gBAAgB;AAAA,QACzB;AAAA,MACJ,CAAC;AAAA,IACL;AACA,QAAI,UAAU;AACV,aAAO,SAAS,MAAM,gBAAgB,IAAI;AAAA,IAC9C;AACA,WAAO,gBAAgB;AAAA,EAC3B,SAAS,OAAO;AACZ,WAAO,WAAW,KAAK;AAAA,EAC3B;AACJ;AAKA,aAAa,UAAU;AACvB,iBAAS;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport type { CompressorResult, MinifierOptions } from \"@node-minify/types\";\nimport { minify } from \"terser\";\n\n/**\n * Run terser.\n * @param settings - Terser options\n * @param content - Content to minify\n * @returns Minified content and optional source map\n */\nexport async function terser({\n settings,\n content,\n}: MinifierOptions): Promise<CompressorResult> {\n const result = await minify(content ?? \"\", settings?.options);\n\n if (typeof result.code !== \"string\") {\n throw new Error(\"Terser failed: empty result\");\n }\n\n return {\n code: result.code,\n map: typeof result.map === \"string\" ? result.map : undefined,\n };\n}\n"],"mappings":";;;;;;;;;AAeA,eAAsB,OAAO,EACzB,UACA,WAC2C;CAC3C,MAAM,SAAS,MAAM,OAAO,WAAW,IAAI,UAAU,QAAQ;AAE7D,KAAI,OAAO,OAAO,SAAS,SACvB,OAAM,IAAI,MAAM,8BAA8B;AAGlD,QAAO;EACH,MAAM,OAAO;EACb,KAAK,OAAO,OAAO,QAAQ,WAAW,OAAO,MAAM;EACtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/terser",
3
- "version": "9.0.1",
3
+ "version": "10.0.0",
4
4
  "description": "terser plugin for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -9,25 +9,23 @@
9
9
  "terser"
10
10
  ],
11
11
  "author": "Rodolphe Stoclin <srodolphe@gmail.com>",
12
- "homepage": "https://github.com/srod/node-minify/tree/master/packages/terser#readme",
12
+ "homepage": "https://github.com/srod/node-minify/tree/main/packages/terser#readme",
13
13
  "license": "MIT",
14
+ "type": "module",
14
15
  "engines": {
15
- "node": ">=18.0.0"
16
+ "node": ">=20.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
22
  "types": "./dist/index.d.ts",
23
+ "main": "./dist/index.js",
24
24
  "exports": {
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.mjs",
28
- "require": "./dist/index.js"
29
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
30
27
  },
28
+ "sideEffects": false,
31
29
  "files": [
32
30
  "dist/**/*"
33
31
  ],
@@ -41,19 +39,23 @@
41
39
  "bugs": {
42
40
  "url": "https://github.com/srod/node-minify/issues"
43
41
  },
44
- "dependencies": {
45
- "terser": "5.36.0",
46
- "@node-minify/utils": "9.0.1"
47
- },
48
- "devDependencies": {
49
- "@node-minify/types": "9.0.0"
50
- },
51
42
  "scripts": {
52
- "clean": "pnpm dlx rimraf dist",
53
- "build": "pnpm clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
43
+ "build": "tsdown src/index.ts",
44
+ "check-exports": "attw --pack . --profile esm-only",
45
+ "format:check": "biome check .",
54
46
  "lint": "biome lint .",
47
+ "prepublishOnly": "bun run build",
55
48
  "test": "vitest run",
56
49
  "test:ci": "vitest run --coverage",
57
- "test:watch": "vitest"
50
+ "test:watch": "vitest",
51
+ "typecheck": "tsc --noEmit",
52
+ "dev": "tsdown src/index.ts --watch"
53
+ },
54
+ "dependencies": {
55
+ "@node-minify/utils": "workspace:*",
56
+ "terser": "5.44.1"
57
+ },
58
+ "devDependencies": {
59
+ "@node-minify/types": "workspace:*"
58
60
  }
59
- }
61
+ }
package/dist/index.d.mts DELETED
@@ -1,25 +0,0 @@
1
- import { MinifierOptions } from '@node-minify/types';
2
-
3
- /*!
4
- * node-minify
5
- * Copyright(c) 2011-2024 Rodolphe Stoclin
6
- * MIT Licensed
7
- */
8
-
9
- type OptionsTerser = {
10
- sourceMap?: {
11
- url: string;
12
- };
13
- };
14
- type SettingsTerser = {
15
- options: OptionsTerser;
16
- };
17
- type MinifierOptionsTerser = {
18
- settings: SettingsTerser;
19
- };
20
- declare const minifyTerser: {
21
- ({ settings, content, callback, index, }: MinifierOptions & MinifierOptionsTerser): Promise<string | void>;
22
- default: any;
23
- };
24
-
25
- export { minifyTerser as default };
package/dist/index.mjs DELETED
@@ -1,51 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
-
6
- // src/index.ts
7
- import { utils } from "@node-minify/utils";
8
- import { minify } from "terser";
9
- var require_src = __commonJS({
10
- "src/index.ts"(exports, module) {
11
- var minifyTerser = async ({
12
- settings,
13
- content,
14
- callback,
15
- index
16
- }) => {
17
- try {
18
- const contentMinified = await minify(content ?? "", settings?.options);
19
- if (contentMinified.map && typeof settings?.options?.sourceMap?.url === "string") {
20
- utils.writeFile({
21
- file: settings.options.sourceMap.url,
22
- content: contentMinified.map,
23
- index
24
- });
25
- }
26
- if (settings && !settings.content && settings.output) {
27
- utils.writeFile({
28
- file: settings.output,
29
- content: contentMinified.code,
30
- index
31
- });
32
- }
33
- if (callback) {
34
- return callback(null, contentMinified.code);
35
- }
36
- return contentMinified.code;
37
- } catch (error) {
38
- return callback?.(error);
39
- }
40
- };
41
- minifyTerser.default = minifyTerser;
42
- module.exports = minifyTerser;
43
- }
44
- });
45
- export default require_src();
46
- /*!
47
- * node-minify
48
- * Copyright(c) 2011-2024 Rodolphe Stoclin
49
- * MIT Licensed
50
- */
51
- //# sourceMappingURL=index.mjs.map
@@ -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 type { MinifierOptions } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\n// @ts-expect-error moduleResolution:nodenext issue 54523\nimport { minify } from \"terser\";\n\ntype OptionsTerser = {\n sourceMap?: { url: string };\n};\n\ntype SettingsTerser = {\n options: OptionsTerser;\n};\n\ntype MinifierOptionsTerser = {\n settings: SettingsTerser;\n};\n\n/**\n * Run terser.\n * @param settings Terser options\n * @param content Content to minify\n * @param callback Callback\n * @param index Index of current file in array\n * @returns Minified content\n */\nconst minifyTerser = async ({\n settings,\n content,\n callback,\n index,\n}: MinifierOptions & MinifierOptionsTerser) => {\n try {\n const contentMinified = await minify(content ?? \"\", settings?.options);\n if (\n contentMinified.map &&\n typeof settings?.options?.sourceMap?.url === \"string\"\n ) {\n utils.writeFile({\n file: settings.options.sourceMap.url,\n content: contentMinified.map,\n index,\n });\n }\n if (settings && !settings.content && settings.output) {\n utils.writeFile({\n file: settings.output,\n content: contentMinified.code,\n index,\n });\n }\n if (callback) {\n return callback(null, contentMinified.code);\n }\n return contentMinified.code;\n } catch (error) {\n return callback?.(error);\n }\n};\n\n/**\n * Expose `minifyTerser()`.\n */\nminifyTerser.default = minifyTerser;\nexport = minifyTerser;\n"],"mappings":";;;;;;AAUA,SAAS,aAAa;AAEtB,SAAS,cAAc;AAZvB;AAAA;AAkCA,QAAM,eAAe,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,MAA+C;AAC3C,UAAI;AACA,cAAM,kBAAkB,MAAM,OAAO,WAAW,IAAI,UAAU,OAAO;AACrE,YACI,gBAAgB,OAChB,OAAO,UAAU,SAAS,WAAW,QAAQ,UAC/C;AACE,gBAAM,UAAU;AAAA,YACZ,MAAM,SAAS,QAAQ,UAAU;AAAA,YACjC,SAAS,gBAAgB;AAAA,YACzB;AAAA,UACJ,CAAC;AAAA,QACL;AACA,YAAI,YAAY,CAAC,SAAS,WAAW,SAAS,QAAQ;AAClD,gBAAM,UAAU;AAAA,YACZ,MAAM,SAAS;AAAA,YACf,SAAS,gBAAgB;AAAA,YACzB;AAAA,UACJ,CAAC;AAAA,QACL;AACA,YAAI,UAAU;AACV,iBAAO,SAAS,MAAM,gBAAgB,IAAI;AAAA,QAC9C;AACA,eAAO,gBAAgB;AAAA,MAC3B,SAAS,OAAO;AACZ,eAAO,WAAW,KAAK;AAAA,MAC3B;AAAA,IACJ;AAKA,iBAAa,UAAU;AACvB,qBAAS;AAAA;AAAA;","names":[]}