-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from A-312/work-v5
gulp-terser-js 5.0.0
- Loading branch information
Showing
18 changed files
with
377 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coverage | ||
node_modules | ||
temp | ||
test/expect | ||
test/fixtures | ||
.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root: true | ||
extends: standard | ||
rules: | ||
no-param-reassign: error | ||
no-shadow: error | ||
space-before-function-paren: | ||
- error | ||
- anonymous: never | ||
named: never | ||
asyncArrow: always | ||
no-multiple-empty-lines: | ||
- error | ||
- { "max": 2 } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
node_modules | ||
node_modules/ | ||
*.sublime-workspace | ||
*.sublime-project | ||
package-lock.json | ||
.nyc_output/ | ||
.output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,62 @@ | ||
sudo: false | ||
|
||
language: node_js | ||
node_js: | ||
- "8.0.0" | ||
- "10.0.0" | ||
- "11.0.0" | ||
- "11.6.0" | ||
- "8.10" | ||
- "8.15" | ||
- "9.11" | ||
- "lts/*" | ||
matrix: | ||
fast_finish: true | ||
sudo: false | ||
cache: | ||
directories: | ||
- node_modules | ||
before_install: | ||
# Configure npm | ||
- | | ||
# Skip updating shrinkwrap / lock | ||
npm config set shrinkwrap false | ||
# Setup Node.js version-specific dependencies | ||
- | | ||
# eslint for linting | ||
# - remove on Node.js < 6 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then | ||
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ | ||
grep -E '^eslint(-|$)' | \ | ||
xargs npm rm --save-dev | ||
fi | ||
- | | ||
# mocha for testing | ||
# - use 3.x for Node.js < 4 | ||
# - use 5.x for Node.js < 6 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then | ||
npm install --save-dev [email protected] | ||
elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then | ||
npm install --save-dev [email protected] | ||
fi | ||
- | | ||
# supertest for http calls | ||
# - use 2.0.0 for Node.js < 4 | ||
# - use 3.4.2 for Node.js < 6 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then | ||
npm install --save-dev [email protected] | ||
elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then | ||
npm install --save-dev [email protected] | ||
fi | ||
# Update Node.js modules | ||
- | | ||
# Prune and rebuild node_modules | ||
if [[ -d node_modules ]]; then | ||
npm prune | ||
npm rebuild | ||
fi | ||
script: | ||
# Run test script | ||
- npm run test-ci | ||
# Run linting | ||
- | | ||
# Run linting, depending on eslint install | ||
if [[ -n "$(npm -ps ls eslint)" ]]; then | ||
npm run-script lint | ||
fi | ||
after_script: | ||
- npm run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
|
||
## [5.0.0] - 2019-08-14 | ||
### Changed | ||
|
||
- Update dependencies version (Terser is now on 4.1.4) #8 | ||
- Add test, coverage in travis #8 | ||
|
||
|
||
## [4.1.1] - 2019-08-13 | ||
### Fix | ||
|
||
- Fix printError and improve readme(caused by #3) #5 | ||
|
||
### Added | ||
|
||
- Add API for printError: `require('gulp-terser-js').printError` #5 | ||
|
||
|
||
## [4.1.0] - 2019-08-09 | ||
### Added | ||
|
||
- Add printError #3 | ||
|
||
[5.0.0]: https://github.com/A-312/gulp-terser-js/releases/tag/5.0.0 | ||
[4.1.1]: https://github.com/A-312/gulp-terser-js/releases/tag/4.1.1 | ||
[4.1.0]: https://github.com/A-312/gulp-terser-js/releases/tag/4.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const through2 = require('through2') | ||
const assign = require('object-assign') | ||
const PluginError = require('plugin-error') | ||
const applySourceMap = require('vinyl-sourcemaps-apply') | ||
const os = require('os') | ||
|
||
const terser = require('terser') | ||
|
||
function gulpTerser(options) { | ||
// Mixes in default options. | ||
const opts = assign({}, {}, options) | ||
|
||
return through2.obj(function(file, enc, next) { | ||
if (file.isNull()) { | ||
return next(null, file) | ||
} | ||
|
||
if (file.isStream()) { | ||
return next(new PluginError('gulp-terser', 'Streaming not supported')) | ||
} | ||
|
||
const str = file.contents.toString() | ||
let build = {} | ||
|
||
// Bootstrap source maps | ||
if (file.sourceMap) { | ||
opts.sourceMap = {} | ||
opts.sourceMap.filename = file.sourceMap.file | ||
} | ||
|
||
if (file.sourceMap && file.sourceMap.file) { | ||
build[file.sourceMap.file] = str | ||
} else { | ||
build = str | ||
} | ||
const res = terser.minify(build, opts) | ||
|
||
if (res.error) { | ||
res.error.filePath = file.path | ||
res.error.fileContent = (typeof build === 'string') ? build : build[res.error.filename] | ||
|
||
return next(printError(new PluginError('gulp-terser', res.error))) | ||
} | ||
|
||
file.contents = new (Buffer.from || Buffer)(res.code) // eslint-disable-line node/no-deprecated-api | ||
|
||
if (file.sourceMap && res.map) { | ||
applySourceMap(file, res.map) | ||
} | ||
|
||
return next(null, file) | ||
}) | ||
} | ||
|
||
function alignLine(num, text, longer, maxsize) { | ||
let maxlength = process.stdout.columns - 1 | ||
const spaces = num + Array(longer - (num + '').length).join(' ') | ||
maxlength -= spaces.length + 3 | ||
console.log('\x1B[36m' + spaces + ' |\x1B[00m ' + text.slice(0, (maxsize < maxlength) ? maxlength : maxsize)) | ||
} | ||
|
||
function printError(error) { | ||
if (!error.fileContent || (error.line === undefined && error.col === undefined)) { | ||
return console.error(error.stack || error) | ||
} | ||
|
||
const fileContent = error.fileContent | ||
const lines = fileContent.replace(/\t/g, ' ').split(os.EOL) | ||
const more = (error.line + ' ').length | ||
const col = error.col + 1 | ||
const pos = (more + 2) + fileContent.split(os.EOL)[error.line - 1].replace(/[^\t]/g, '').length * 3 + parseInt(col) | ||
|
||
console.log(`\nError with ${error.plugin} :`) | ||
for (let i = error.line - 5; i < error.line; i++) { | ||
if (lines[i]) { | ||
alignLine(i + 1, lines[i], more, pos) | ||
} | ||
} | ||
|
||
console.log(Array(pos).join(' ') + '\x1B[91m^\x1B[00m') | ||
console.log('(' + error.name + ') ' + error.message + ' (line : \x1B[96m' + error.line + '\x1B[00m, col : \x1B[96m' + col + '\x1B[00m).') | ||
console.log(`in : ${error.filePath}\n`) | ||
|
||
return error | ||
} | ||
|
||
gulpTerser.printError = printError | ||
|
||
module.exports = gulpTerser |
Oops, something went wrong.