Comparing version 5.11.0 to 5.12.0
# Changelog | ||
## v5.12.0 | ||
- `TERSER_DEBUG_DIR` environment variable | ||
- @copyright comments are now preserved with the comments="some" option (#1153) | ||
## v5.11.0 | ||
@@ -4,0 +9,0 @@ |
@@ -227,3 +227,3 @@ import { minify, _default_options } from "../main.js"; | ||
try { | ||
result = await minify(files, options); | ||
result = await minify(files, options, fs); | ||
} catch (ex) { | ||
@@ -291,10 +291,14 @@ if (ex.name == "SyntaxError") { | ||
try { | ||
const minified = await minify(result.code, { | ||
compress: false, | ||
mangle: false, | ||
format: { | ||
ast: true, | ||
code: false | ||
} | ||
}); | ||
const minified = await minify( | ||
result.code, | ||
{ | ||
compress: false, | ||
mangle: false, | ||
format: { | ||
ast: true, | ||
code: false | ||
} | ||
}, | ||
fs | ||
); | ||
console.log(JSON.stringify(minified.ast.to_mozilla_ast(), null, 2)); | ||
@@ -301,0 +305,0 @@ } catch (ex) { |
@@ -64,3 +64,50 @@ "use strict"; | ||
async function minify(files, options) { | ||
function log_input(files, options, fs, debug_folder) { | ||
if (!(fs && fs.writeFileSync && fs.mkdirSync)) { | ||
return; | ||
} | ||
try { | ||
fs.mkdirSync(debug_folder); | ||
} catch (e) { | ||
if (e.code !== "EEXIST") throw e; | ||
} | ||
const log_path = `${debug_folder}/terser-debug-${(Math.random() * 9999999) | 0}.log`; | ||
options = options || {}; | ||
const options_str = JSON.stringify(options, (_key, thing) => { | ||
if (typeof thing === "function") return "[Function " + thing.toString() + "]"; | ||
if (thing instanceof RegExp) return "[RegExp " + thing.toString() + "]"; | ||
return thing; | ||
}, 4); | ||
const files_str = (file) => { | ||
if (typeof file === "object" && options.parse && options.parse.spidermonkey) { | ||
return JSON.stringify(file, null, 2); | ||
} else if (typeof file === "object") { | ||
return Object.keys(file) | ||
.map((key) => key + ": " + files_str(file[key])) | ||
.join("\n\n"); | ||
} else if (typeof file === "string") { | ||
return "```\n" + file + "\n```"; | ||
} else { | ||
return file; // What do? | ||
} | ||
}; | ||
fs.writeFileSync(log_path, "Options: \n" + options_str + "\n\nInput files:\n\n" + files_str(files) + "\n"); | ||
} | ||
async function minify(files, options, _fs_module) { | ||
if ( | ||
_fs_module | ||
&& typeof process === "object" | ||
&& process.env | ||
&& typeof process.env.TERSER_DEBUG_DIR === "string" | ||
) { | ||
log_input(files, options, _fs_module, process.env.TERSER_DEBUG_DIR); | ||
} | ||
options = defaults(options, { | ||
@@ -88,2 +135,3 @@ compress: {}, | ||
}, true); | ||
var timings = options.timings && { | ||
@@ -90,0 +138,0 @@ start: Date.now() |
@@ -7,3 +7,3 @@ { | ||
"license": "BSD-2-Clause", | ||
"version": "5.11.0", | ||
"version": "5.12.0", | ||
"engines": { | ||
@@ -108,2 +108,4 @@ "node": ">=10" | ||
"require": false, | ||
"before": false, | ||
"after": false, | ||
"global": false, | ||
@@ -110,0 +112,0 @@ "process": false |
@@ -8,3 +8,3 @@ <h1><img src="https://terser.org/img/terser-banner-logo.png" alt="Terser" width="400"></h1> | ||
A JavaScript parser and mangler/compressor toolkit for ES6+. | ||
A JavaScript mangler/compressor toolkit for ES6+. | ||
@@ -131,4 +131,4 @@ *note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/fabiosantoscode"><img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" alt="patron" width="100px" height="auto"></a>. Check out [PATRONS.md](https://github.com/terser/terser/blob/master/PATRONS.md) for our first-tier patrons. | ||
default this works like Google Closure, keeping | ||
JSDoc-style comments that contain "@license" or | ||
"@preserve". You can optionally pass one of the | ||
JSDoc-style comments that contain e.g. "@license", | ||
or start with "!". You can optionally pass one of the | ||
following arguments to this flag: | ||
@@ -994,4 +994,4 @@ - "all" to keep all comments | ||
- `comments` (default `"some"`) -- by default it keeps JSDoc-style comments | ||
that contain "@license", "@preserve" or start with `!`, pass `true` or | ||
`"all"` to preserve all comments, `false` to omit comments in the output, | ||
that contain "@license", "@copyright", "@preserve" or start with `!`, pass `true` | ||
or `"all"` to preserve all comments, `false` to omit comments in the output, | ||
a regular expression string (e.g. `/^!/`) or a function. | ||
@@ -1068,5 +1068,5 @@ | ||
You can pass `--comments` to retain certain comments in the output. By | ||
default it will keep JSDoc-style comments that contain "@preserve", | ||
"@license" or "@cc_on" (conditional compilation for IE). You can pass | ||
`--comments all` to keep all the comments, or a valid JavaScript regexp to | ||
default it will keep comments starting with "!" and JSDoc-style comments that | ||
contain "@preserve", "@copyright", "@license" or "@cc_on" (conditional compilation for IE). | ||
You can pass `--comments all` to keep all the comments, or a valid JavaScript regexp to | ||
keep only comments that match this regexp. For example `--comments /^!/` | ||
@@ -1325,2 +1325,18 @@ will keep comments like `/*! Copyright Notice */`. | ||
## Obtaining the source code given to Terser | ||
Because users often don't control the call to `await minify()` or its arguments, Terser provides a `TERSER_DEBUG_DIR` environment variable to make terser output some debug logs. If you're using a bundler or a project that includes a bundler and are not sure what went wrong with your code, pass that variable like so: | ||
``` | ||
$ TERSER_DEBUG_DIR=/path/to/logs command-that-uses-terser | ||
$ ls /path/to/logs | ||
terser-debug-123456.log | ||
``` | ||
If you're not sure how to set an environment variable on your shell (the above example works in bash), you can try using cross-env: | ||
``` | ||
> npx cross-env TERSER_DEBUG_DIR=/path/to/logs command-that-uses-terser | ||
``` | ||
# README.md Patrons: | ||
@@ -1327,0 +1343,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1930346
54625
1375
7