@node-minify/babel-minify 10.0.2 → 10.1.1
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts.map
CHANGED
|
@@ -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;;;;
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { readFile, warnDeprecation } from "@node-minify/utils";
|
|
2
2
|
import { transform } from "babel-core";
|
|
3
|
+
import env from "babel-preset-env";
|
|
3
4
|
import minify from "babel-preset-minify";
|
|
4
5
|
|
|
5
6
|
//#region src/index.ts
|
|
6
7
|
/**
|
|
8
|
+
* Known presets that we can resolve directly to avoid Babel 6's runtime module resolution,
|
|
9
|
+
* which can fail in monorepos or when the working directory differs from the package location.
|
|
10
|
+
*/
|
|
11
|
+
const knownPresets = {
|
|
12
|
+
env,
|
|
13
|
+
minify
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
7
16
|
* Run babel-minify.
|
|
8
17
|
* @deprecated babel-minify uses Babel 6 which is no longer maintained. Use @node-minify/terser instead.
|
|
9
18
|
* @param settings - Babel-minify options
|
|
@@ -20,7 +29,8 @@ async function babelMinify({ settings, content }) {
|
|
|
20
29
|
const babelrcPresets = babelOptions.presets || [];
|
|
21
30
|
babelOptions.presets = presets.concat(babelrcPresets);
|
|
22
31
|
}
|
|
23
|
-
|
|
32
|
+
babelOptions.presets = babelOptions.presets.map((preset) => typeof preset === "string" && preset in knownPresets ? knownPresets[preset] : preset);
|
|
33
|
+
if (!babelOptions.presets.includes(minify)) babelOptions.presets = babelOptions.presets.concat([minify]);
|
|
24
34
|
const result = transform(content ?? "", babelOptions);
|
|
25
35
|
if (typeof result.code !== "string") throw new Error("Babel minification failed: empty result");
|
|
26
36
|
return { code: result.code };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["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 minify from \"babel-preset-minify\";\n\ntype BabelOptions = {\n presets: (string |
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/babel-minify",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.1",
|
|
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": [
|
|
@@ -47,19 +47,19 @@
|
|
|
47
47
|
"lint": "biome lint .",
|
|
48
48
|
"prepublishOnly": "bun run build",
|
|
49
49
|
"test": "vitest run",
|
|
50
|
-
"test:
|
|
50
|
+
"test:coverage": "vitest run --coverage",
|
|
51
51
|
"test:watch": "vitest",
|
|
52
52
|
"typecheck": "tsc --noEmit",
|
|
53
53
|
"dev": "tsdown src/index.ts --watch"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@node-minify/utils": "
|
|
56
|
+
"@node-minify/utils": "10.1.1",
|
|
57
57
|
"babel-core": "6.26.3",
|
|
58
|
+
"babel-preset-env": "1.7.0",
|
|
58
59
|
"babel-preset-minify": "0.5.2"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@node-minify/types": "
|
|
62
|
-
"@types/babel-core": "^6.25.10"
|
|
63
|
-
"babel-preset-env": "1.7.0"
|
|
62
|
+
"@node-minify/types": "10.1.1",
|
|
63
|
+
"@types/babel-core": "^6.25.10"
|
|
64
64
|
}
|
|
65
65
|
}
|