@node-minify/babel-minify 10.1.1 → 10.2.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/README.md CHANGED
@@ -1,13 +1,13 @@
1
- <p align="center"><img src="/static/node-minify.svg" width="348" alt="node-minify"></p>
1
+ <p align="center"><img src="https://raw.githubusercontent.com/srod/node-minify/main/static/node-minify.svg" width="348" alt="node-minify"></p>
2
2
 
3
3
  <p align="center">A very light minifier Node.js module.</p>
4
4
 
5
5
  <p align="center">
6
6
  <br>
7
- <a href="https://npmjs.org/package/@node-minify/babel-minify"><img src="https://img.shields.io/npm/v/@node-minify/babel-minify.svg"></a>
8
- <a href="https://npmjs.org/package/@node-minify/babel-minify"><img src="https://img.shields.io/npm/dm/@node-minify/babel-minify.svg"></a>
7
+ <a href="https://npmjs.org/package/@node-minify/babel-minify"><img src="https://img.shields.io/npm/v/@node-minify/babel-minify.svg" alt="npm version"></a>
8
+ <a href="https://npmjs.org/package/@node-minify/babel-minify"><img src="https://img.shields.io/npm/dm/@node-minify/babel-minify.svg" alt="npm downloads"></a>
9
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>
10
+ <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg" alt="code coverage"></a>
11
11
  </p>
12
12
 
13
13
  # babel-minify
package/dist/index.d.ts CHANGED
@@ -1,11 +1,47 @@
1
1
  //#region ../types/src/types.d.ts
2
2
 
3
+ /**
4
+ * Output result for multi-format image compression.
5
+ */
6
+ type CompressorOutput = {
7
+ /**
8
+ * Format of the output (e.g., 'webp', 'avif').
9
+ */
10
+ format?: string;
11
+
12
+ /**
13
+ * Output content as string or Buffer.
14
+ */
15
+ content: string | Buffer;
16
+ };
3
17
  /**
4
18
  * Result returned by a compressor function.
5
19
  */
6
20
  type CompressorResult = {
21
+ /**
22
+ * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).
23
+ */
7
24
  code: string;
25
+
26
+ /**
27
+ * Source map (for JS/CSS compressors).
28
+ */
8
29
  map?: string;
30
+
31
+ /**
32
+ * Minified content as Buffer (for binary formats like images).
33
+ * @example
34
+ * When using sharp for PNG/WebP compression
35
+ */
36
+ buffer?: Buffer;
37
+
38
+ /**
39
+ * Multiple outputs for multi-format image compression.
40
+ * Used when converting to multiple formats simultaneously.
41
+ * @example
42
+ * [{ format: 'webp', content: <Buffer> }, { format: 'avif', content: <Buffer> }]
43
+ */
44
+ outputs?: CompressorOutput[];
9
45
  };
10
46
  /**
11
47
  * Base options that all compressors can accept.
@@ -53,8 +89,10 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
53
89
  /**
54
90
  * Content to minify (for in-memory minification).
55
91
  * If provided, input/output are not required.
92
+ * For text-based formats (JS, CSS, HTML, SVG): string
93
+ * For binary formats (images): Buffer (handled internally by image compressors)
56
94
  */
57
- content?: string;
95
+ content?: string | Buffer;
58
96
 
59
97
  /**
60
98
  * Input file path(s) or glob pattern.
@@ -136,8 +174,11 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
136
174
 
137
175
  /**
138
176
  * The content to minify.
177
+ * For text-based formats (JS, CSS, HTML, SVG): string
178
+ * For binary formats (images): Buffer
179
+ * For multiple binary files: Buffer[]
139
180
  */
140
- content?: string;
181
+ content?: string | Buffer | Buffer[];
141
182
 
142
183
  /**
143
184
  * Index of current file when processing multiple files.
@@ -147,11 +188,16 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
147
188
  //#endregion
148
189
  //#region src/index.d.ts
149
190
  /**
150
- * Run babel-minify.
151
- * @deprecated babel-minify uses Babel 6 which is no longer maintained. Use @node-minify/terser instead.
152
- * @param settings - Babel-minify options
153
- * @param content - Content to minify
154
- * @returns Minified content
191
+ * Minifies JavaScript using Babel (ensures the `babel-preset-minify` preset is applied).
192
+ *
193
+ * Accepts optional Babel configuration via `settings.options.babelrc` (path to a .babelrc file)
194
+ * and `settings.options.presets` (array of presets or preset names). Known preset names are
195
+ * resolved to their bundled implementations before running Babel.
196
+ *
197
+ * @deprecated babel-minify uses Babel 6 which is no longer maintained. Migrate to @node-minify/terser for ongoing support.
198
+ * @param settings - Minifier settings; may include `options.babelrc` (string path) and `options.presets` (string[] or preset entries)
199
+ * @param content - Source content to be minified
200
+ * @returns An object with the minified code: `{ code: string }`
155
201
  */
156
202
  declare function babelMinify({
157
203
  settings,
@@ -1 +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;;;;ACtHd;;AAEI,KDLQL,UCKR,CAAA,iBDLoCF,iBCKpC,GDLwDA,iBCKxD,CAAA,GACD,CAAA,IAAA,EDLQI,eCKR,CDLwBD,QCKxB,CAAA,EAAA,GDLsCE,OCKtC,CDL8CN,gBCK9C,CAAA;;;;KDASO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwCbA;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;;;;;;;;;;;;AAnHvB;AAmBA;AAAsCH,iBCtBhB,WAAA,CDsBgBA;EAAAA,QAAAA;EAAAA;AAAAA,CAAAA,ECnBnC,eDmBmCA,CAAAA,ECnBjB,ODmBiBA,CCnBT,gBDmBSA,CAAAA"}
1
+ {"version":3,"file":"index.d.ts","names":["CompressorReturnType","ImageFormat","CompressorOutput","Buffer","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 * Supported image formats for image compression.\n */\nexport type ImageFormat =\n | \"webp\"\n | \"avif\"\n | \"png\"\n | \"jpeg\"\n | \"jpg\"\n | \"gif\"\n | \"tiff\"\n | \"heif\"\n | \"heic\";\n\n/**\n * Output result for multi-format image compression.\n */\nexport type CompressorOutput = {\n /**\n * Format of the output (e.g., 'webp', 'avif').\n */\n format?: string;\n\n /**\n * Output content as string or Buffer.\n */\n content: string | Buffer;\n};\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n /**\n * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).\n */\n code: string;\n\n /**\n * Source map (for JS/CSS compressors).\n */\n map?: string;\n\n /**\n * Minified content as Buffer (for binary formats like images).\n * @example\n * When using sharp for PNG/WebP compression\n */\n buffer?: Buffer;\n\n /**\n * Multiple outputs for multi-format image compression.\n * Used when converting to multiple formats simultaneously.\n * @example\n * [{ format: 'webp', content: <Buffer> }, { format: 'avif', content: <Buffer> }]\n */\n outputs?: CompressorOutput[];\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 * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer (handled internally by image compressors)\n */\n content?: string | Buffer;\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 * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer\n * For multiple binary files: Buffer[]\n */\n content?: string | Buffer | Buffer[];\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":";;;;;AAqNsC,KAxL1BE,gBAAAA,GAwL0B;;;;EC1KhB,MAAA,CAAA,EAAA,MAAW;;EAE7B;;;EACiB,OAAA,EAAA,MAAA,GDRCC,MCQD;CAAO;;;;KDFhBC,gBAAAA;;;;;;;;;;;;;;;;WAgBCD;;;;;;;;YAQCD;;;;;;KAOFG,iBAAAA,GAAoBC;;;;;;KAOpBC,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;qBAaJL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BTK;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;qBAQAL,SAASA;;;;;;;;;;;;;;;AA7HhC;AAmBA;;;;;AAiBuBA,iBCjFD,WAAA,CDiFCA;EAAAA,QAAAA;EAAAA;AAAAA,CAAAA,EC9EpB,eD8EoBA,CAAAA,EC9EF,OD8EEA,CC9EM,gBD8ENA,CAAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { readFile, warnDeprecation } from "@node-minify/utils";
1
+ import { ensureStringContent, readFile, warnDeprecation } from "@node-minify/utils";
2
2
  import { transform } from "babel-core";
3
3
  import env from "babel-preset-env";
4
4
  import minify from "babel-preset-minify";
@@ -13,13 +13,19 @@ const knownPresets = {
13
13
  minify
14
14
  };
15
15
  /**
16
- * Run babel-minify.
17
- * @deprecated babel-minify uses Babel 6 which is no longer maintained. Use @node-minify/terser instead.
18
- * @param settings - Babel-minify options
19
- * @param content - Content to minify
20
- * @returns Minified content
16
+ * Minifies JavaScript using Babel (ensures the `babel-preset-minify` preset is applied).
17
+ *
18
+ * Accepts optional Babel configuration via `settings.options.babelrc` (path to a .babelrc file)
19
+ * and `settings.options.presets` (array of presets or preset names). Known preset names are
20
+ * resolved to their bundled implementations before running Babel.
21
+ *
22
+ * @deprecated babel-minify uses Babel 6 which is no longer maintained. Migrate to @node-minify/terser for ongoing support.
23
+ * @param settings - Minifier settings; may include `options.babelrc` (string path) and `options.presets` (string[] or preset entries)
24
+ * @param content - Source content to be minified
25
+ * @returns An object with the minified code: `{ code: string }`
21
26
  */
22
27
  async function babelMinify({ settings, content }) {
28
+ const contentStr = ensureStringContent(content, "babel-minify");
23
29
  warnDeprecation("babel-minify", "babel-minify uses Babel 6 which is no longer maintained. Please migrate to @node-minify/terser for continued support and modern JavaScript features.");
24
30
  let babelOptions = { presets: [] };
25
31
  const babelrc = settings?.options?.babelrc;
@@ -31,7 +37,7 @@ async function babelMinify({ settings, content }) {
31
37
  }
32
38
  babelOptions.presets = babelOptions.presets.map((preset) => typeof preset === "string" && preset in knownPresets ? knownPresets[preset] : preset);
33
39
  if (!babelOptions.presets.includes(minify)) babelOptions.presets = babelOptions.presets.concat([minify]);
34
- const result = transform(content ?? "", babelOptions);
40
+ const result = transform(contentStr, babelOptions);
35
41
  if (typeof result.code !== "string") throw new Error("Babel minification failed: empty result");
36
42
  return { code: result.code };
37
43
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["knownPresets: Record<string, BabelPreset>","babelOptions: BabelOptions"],"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 { readFile, warnDeprecation } from \"@node-minify/utils\";\nimport { transform } from \"babel-core\";\nimport env from \"babel-preset-env\";\nimport minify from \"babel-preset-minify\";\n\ntype BabelPreset = typeof minify | typeof env;\n\ntype BabelOptions = {\n presets: (string | BabelPreset)[];\n};\n\n/**\n * Known presets that we can resolve directly to avoid Babel 6's runtime module resolution,\n * which can fail in monorepos or when the working directory differs from the package location.\n */\nconst knownPresets: Record<string, BabelPreset> = {\n env,\n minify,\n};\n\n/**\n * Run babel-minify.\n * @deprecated babel-minify uses Babel 6 which is no longer maintained. Use @node-minify/terser instead.\n * @param settings - Babel-minify options\n * @param content - Content to minify\n * @returns Minified content\n */\nexport async function babelMinify({\n settings,\n content,\n}: MinifierOptions): Promise<CompressorResult> {\n warnDeprecation(\n \"babel-minify\",\n \"babel-minify uses Babel 6 which is no longer maintained. \" +\n \"Please migrate to @node-minify/terser for continued support and modern JavaScript features.\"\n );\n\n let babelOptions: BabelOptions = { presets: [] };\n const babelrc = settings?.options?.babelrc as string | undefined;\n const presets = settings?.options?.presets as string[] | undefined;\n\n if (babelrc) {\n babelOptions = JSON.parse(readFile(babelrc));\n }\n\n if (presets && Array.isArray(presets)) {\n const babelrcPresets = babelOptions.presets || [];\n babelOptions.presets = presets.concat(babelrcPresets);\n }\n\n // Resolve known preset strings to their imported modules to avoid\n // Babel 6's runtime resolution which fails in monorepos/different cwd\n babelOptions.presets = babelOptions.presets.map((preset) =>\n typeof preset === \"string\" && preset in knownPresets\n ? knownPresets[preset]\n : preset\n );\n\n // Ensure minify preset is always included\n if (!babelOptions.presets.includes(minify)) {\n babelOptions.presets = babelOptions.presets.concat([minify]);\n }\n\n const result = transform(content ?? \"\", babelOptions);\n\n if (typeof result.code !== \"string\") {\n throw new Error(\"Babel minification failed: empty result\");\n }\n\n return { code: result.code };\n}\n"],"mappings":";;;;;;;;;;AAsBA,MAAMA,eAA4C;CAC9C;CACA;CACH;;;;;;;;AASD,eAAsB,YAAY,EAC9B,UACA,WAC2C;AAC3C,iBACI,gBACA,uJAEH;CAED,IAAIC,eAA6B,EAAE,SAAS,EAAE,EAAE;CAChD,MAAM,UAAU,UAAU,SAAS;CACnC,MAAM,UAAU,UAAU,SAAS;AAEnC,KAAI,QACA,gBAAe,KAAK,MAAM,SAAS,QAAQ,CAAC;AAGhD,KAAI,WAAW,MAAM,QAAQ,QAAQ,EAAE;EACnC,MAAM,iBAAiB,aAAa,WAAW,EAAE;AACjD,eAAa,UAAU,QAAQ,OAAO,eAAe;;AAKzD,cAAa,UAAU,aAAa,QAAQ,KAAK,WAC7C,OAAO,WAAW,YAAY,UAAU,eAClC,aAAa,UACb,OACT;AAGD,KAAI,CAAC,aAAa,QAAQ,SAAS,OAAO,CACtC,cAAa,UAAU,aAAa,QAAQ,OAAO,CAAC,OAAO,CAAC;CAGhE,MAAM,SAAS,UAAU,WAAW,IAAI,aAAa;AAErD,KAAI,OAAO,OAAO,SAAS,SACvB,OAAM,IAAI,MAAM,0CAA0C;AAG9D,QAAO,EAAE,MAAM,OAAO,MAAM"}
1
+ {"version":3,"file":"index.js","names":["knownPresets: Record<string, BabelPreset>","babelOptions: BabelOptions"],"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 {\n ensureStringContent,\n readFile,\n warnDeprecation,\n} from \"@node-minify/utils\";\nimport { transform } from \"babel-core\";\nimport env from \"babel-preset-env\";\nimport minify from \"babel-preset-minify\";\n\ntype BabelPreset = typeof minify | typeof env;\n\ntype BabelOptions = {\n presets: (string | BabelPreset)[];\n};\n\n/**\n * Known presets that we can resolve directly to avoid Babel 6's runtime module resolution,\n * which can fail in monorepos or when the working directory differs from the package location.\n */\nconst knownPresets: Record<string, BabelPreset> = {\n env,\n minify,\n};\n\n/**\n * Minifies JavaScript using Babel (ensures the `babel-preset-minify` preset is applied).\n *\n * Accepts optional Babel configuration via `settings.options.babelrc` (path to a .babelrc file)\n * and `settings.options.presets` (array of presets or preset names). Known preset names are\n * resolved to their bundled implementations before running Babel.\n *\n * @deprecated babel-minify uses Babel 6 which is no longer maintained. Migrate to @node-minify/terser for ongoing support.\n * @param settings - Minifier settings; may include `options.babelrc` (string path) and `options.presets` (string[] or preset entries)\n * @param content - Source content to be minified\n * @returns An object with the minified code: `{ code: string }`\n */\nexport async function babelMinify({\n settings,\n content,\n}: MinifierOptions): Promise<CompressorResult> {\n const contentStr = ensureStringContent(content, \"babel-minify\");\n\n warnDeprecation(\n \"babel-minify\",\n \"babel-minify uses Babel 6 which is no longer maintained. \" +\n \"Please migrate to @node-minify/terser for continued support and modern JavaScript features.\"\n );\n\n let babelOptions: BabelOptions = { presets: [] };\n const babelrc = settings?.options?.babelrc as string | undefined;\n const presets = settings?.options?.presets as string[] | undefined;\n\n if (babelrc) {\n babelOptions = JSON.parse(readFile(babelrc));\n }\n\n if (presets && Array.isArray(presets)) {\n const babelrcPresets = babelOptions.presets || [];\n babelOptions.presets = presets.concat(babelrcPresets);\n }\n\n // Resolve known preset strings to their imported modules to avoid\n // Babel 6's runtime resolution which fails in monorepos/different cwd\n babelOptions.presets = babelOptions.presets.map((preset) =>\n typeof preset === \"string\" && preset in knownPresets\n ? knownPresets[preset]\n : preset\n );\n\n // Ensure minify preset is always included\n if (!babelOptions.presets.includes(minify)) {\n babelOptions.presets = babelOptions.presets.concat([minify]);\n }\n\n const result = transform(contentStr, babelOptions);\n\n if (typeof result.code !== \"string\") {\n throw new Error(\"Babel minification failed: empty result\");\n }\n\n return { code: result.code };\n}\n"],"mappings":";;;;;;;;;;AA0BA,MAAMA,eAA4C;CAC9C;CACA;CACH;;;;;;;;;;;;;AAcD,eAAsB,YAAY,EAC9B,UACA,WAC2C;CAC3C,MAAM,aAAa,oBAAoB,SAAS,eAAe;AAE/D,iBACI,gBACA,uJAEH;CAED,IAAIC,eAA6B,EAAE,SAAS,EAAE,EAAE;CAChD,MAAM,UAAU,UAAU,SAAS;CACnC,MAAM,UAAU,UAAU,SAAS;AAEnC,KAAI,QACA,gBAAe,KAAK,MAAM,SAAS,QAAQ,CAAC;AAGhD,KAAI,WAAW,MAAM,QAAQ,QAAQ,EAAE;EACnC,MAAM,iBAAiB,aAAa,WAAW,EAAE;AACjD,eAAa,UAAU,QAAQ,OAAO,eAAe;;AAKzD,cAAa,UAAU,aAAa,QAAQ,KAAK,WAC7C,OAAO,WAAW,YAAY,UAAU,eAClC,aAAa,UACb,OACT;AAGD,KAAI,CAAC,aAAa,QAAQ,SAAS,OAAO,CACtC,cAAa,UAAU,aAAa,QAAQ,OAAO,CAAC,OAAO,CAAC;CAGhE,MAAM,SAAS,UAAU,YAAY,aAAa;AAElD,KAAI,OAAO,OAAO,SAAS,SACvB,OAAM,IAAI,MAAM,0CAA0C;AAG9D,QAAO,EAAE,MAAM,OAAO,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/babel-minify",
3
- "version": "10.1.1",
3
+ "version": "10.2.0",
4
4
  "deprecated": "babel-minify uses Babel 6 which is no longer maintained. Please use @node-minify/terser instead.",
5
5
  "description": "babel-minify plugin for @node-minify (DEPRECATED - use @node-minify/terser)",
6
6
  "keywords": [
@@ -53,13 +53,13 @@
53
53
  "dev": "tsdown src/index.ts --watch"
54
54
  },
55
55
  "dependencies": {
56
- "@node-minify/utils": "10.1.1",
56
+ "@node-minify/utils": "10.2.0",
57
57
  "babel-core": "6.26.3",
58
58
  "babel-preset-env": "1.7.0",
59
59
  "babel-preset-minify": "0.5.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@node-minify/types": "10.1.1",
62
+ "@node-minify/types": "10.2.0",
63
63
  "@types/babel-core": "^6.25.10"
64
64
  }
65
65
  }