Skip to content

Commit 3984511

Browse files
author
Robert Jackson
authored
Merge pull request #250 from ember-cli/rename
2 parents 844c3dd + d982049 commit 3984511

File tree

7 files changed

+59
-59
lines changed

7 files changed

+59
-59
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
[![Build Status](https://travis-ci.org/ember-cli/broccoli-uglify-sourcemap.svg?branch=master)](https://travis-ci.org/ember-cli/broccoli-uglify-sourcemap)
1+
[![Build Status](https://travis-ci.org/ember-cli/broccoli-terser-sourcemap.svg?branch=master)](https://travis-ci.org/ember-cli/broccoli-terser-sourcemap)
22

33
A broccoli filter that applies [terser](https://github.com/terser/terser) to
4-
uglify code while properly generating or maintaining sourcemaps.
4+
minify code while properly generating or maintaining sourcemaps.
55

66
### installation
77

88
```sh
9-
npm install --save broccoli-uglify-sourcemap
9+
npm install --save broccoli-terser-sourcemap
1010
```
1111

1212
### usage
1313

1414
```js
15-
const Uglify = require('broccoli-uglify-sourcemap');
15+
const Terser = require('broccoli-terser-sourcemap');
1616

1717
// basic usage
18-
let uglified = new Uglify(input);
18+
let minified = new Terser(input);
1919

2020
// advanced usage
21-
let uglified = new Uglify(input, {
21+
let minified = new Terser(input, {
2222
exclude: [..], // array of globs, to not minify
2323

24-
uglify: {
24+
terser: {
2525
mangle: false, // defaults to true
2626
compress: false, // defaults to true
2727
sourceMap: false, // defaults to true

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const path = require('path');
77
const defaults = require('lodash.defaultsdeep');
88
const symlinkOrCopy = require('symlink-or-copy');
99
const MatcherCollection = require('matcher-collection');
10-
const debug = require('debug')('broccoli-uglify-sourcemap');
10+
const debug = require('debug')('broccoli-terser-sourcemap');
1111
const queue = require('async-promise-queue');
1212
const workerpool = require('workerpool');
1313

@@ -23,7 +23,7 @@ const MatchNothing = {
2323
},
2424
};
2525

26-
module.exports = class UglifyWriter extends Plugin {
26+
module.exports = class TerserWriter extends Plugin {
2727
constructor(_inputNodes, options = {}) {
2828
let inputNodes = Array.isArray(_inputNodes) ? _inputNodes : [_inputNodes];
2929

@@ -34,7 +34,7 @@ module.exports = class UglifyWriter extends Plugin {
3434
});
3535

3636
this.options = defaults(options, {
37-
uglify: {
37+
terser: {
3838
sourceMap: {},
3939
},
4040
});
@@ -75,8 +75,8 @@ module.exports = class UglifyWriter extends Plugin {
7575

7676
if (this._isJSExt(relativePath) && !this.excludes.match(relativePath)) {
7777
// wrap this in a function so it doesn't actually run yet, and can be throttled
78-
let uglifyOperation = () => this.processFile(inFile, outFile, relativePath, this.outputPath);
79-
pendingWork.push(uglifyOperation);
78+
let terserOperation = () => this.processFile(inFile, outFile, relativePath, this.outputPath);
79+
pendingWork.push(terserOperation);
8080
} else if (relativePath.slice(-4) === '.map') {
8181
if (this.excludes.match(`${relativePath.slice(0, -4)}.{js,mjs}`)) {
8282
// ensure .map files for excluded JS paths are also copied forward

lib/get-sourcemap-content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function getSourceMapContent(src, inFileDirname, relativePath,
2020
}
2121
if (!silent) {
2222
console.warn(
23-
`[WARN] (broccoli-uglify-sourcemap) ${urls
23+
`[WARN] (broccoli-terser-sourcemap) ${urls
2424
.map(u => `"${u}"`)
2525
.join(', ')} referenced in "${relativePath}" could not be found`
2626
);

lib/process-file.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const debug = require('debug')('broccoli-uglify-sourcemap');
3+
const debug = require('debug')('broccoli-terser-sourcemap');
44
const defaults = require('lodash.defaultsdeep');
55
const fs = require('fs');
66
const path = require('path');
@@ -18,7 +18,7 @@ module.exports = async function processFile(inFile, outFile, relativePath, outDi
1818
mapDir = path.dirname(path.join(outDir, relativePath));
1919
}
2020

21-
let options = defaults({}, _options.uglify);
21+
let options = defaults({}, _options.terser);
2222
if (options.sourceMap) {
2323
let filename = path.basename(inFile);
2424
let url = _options.sourceMapDir ? `/${path.join(_options.sourceMapDir, mapName)}` : mapName;
@@ -52,7 +52,7 @@ module.exports = async function processFile(inFile, outFile, relativePath, outDi
5252
let total = end - start;
5353

5454
if (total > 20000 && !silent) {
55-
console.warn(`[WARN] (broccoli-uglify-sourcemap) Minifying "${relativePath}" took: ${total}ms (more than 20,000ms)`);
55+
console.warn(`[WARN] (broccoli-terser-sourcemap) Minifying "${relativePath}" took: ${total}ms (more than 20,000ms)`);
5656
}
5757

5858
debug('[finished]: %s %dKB in %dms', relativePath, (result.code.length / 1000), total);
@@ -73,7 +73,7 @@ module.exports = async function processFile(inFile, outFile, relativePath, outDi
7373
// `//# sourceMappingURL=out.js.map` in `result.code`.
7474
// The value of `filename` is only used to set `file` attribute
7575
// in source map file.
76-
// In broccoli-uglify-sourcemap we know in this case we are generating
76+
// In broccoli-terser-sourcemap we know in this case we are generating
7777
// sourcemap for the file we are processing, changing 0 to the actual
7878
// file gives us the correct source.
7979
return relativePath;

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"name": "broccoli-uglify-sourcemap",
2+
"name": "broccoli-terser-sourcemap",
33
"version": "4.0.0",
4-
"description": "Broccoli filter to uglify files while preserving their sourcemaps.",
5-
"homepage": "https://github.com/ember-cli/broccoli-uglify-sourcemap#readme",
4+
"description": "Broccoli filter to minify files with terser while preserving their sourcemaps.",
5+
"homepage": "https://github.com/ember-cli/broccoli-terser-sourcemap#readme",
66
"bugs": {
7-
"url": "https://github.com/ember-cli/broccoli-uglify-sourcemap/issues"
7+
"url": "https://github.com/ember-cli/broccoli-terser-sourcemap/issues"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/ember-cli/broccoli-uglify-sourcemap.git"
11+
"url": "git+https://github.com/ember-cli/broccoli-terser-sourcemap.git"
1212
},
1313
"license": "MIT",
1414
"author": "Edward Faulkner <ef@alum.mit.edu>",
@@ -62,7 +62,7 @@
6262
"registry": "https://registry.npmjs.org"
6363
},
6464
"changelog": {
65-
"repo": "ember-cli/broccoli-uglify-sourcemap",
65+
"repo": "ember-cli/broccoli-terser-sourcemap",
6666
"labels": {
6767
"breaking": ":boom: Breaking Change",
6868
"enhancement": ":rocket: Enhancement",

test/__snapshots__/test.js.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`broccoli-uglify-sourcemap can disable sourcemaps 1`] = `
3+
exports[`broccoli-terser-sourcemap can disable sourcemaps 1`] = `
44
Object {
55
"inside": Object {
66
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}",
@@ -19,7 +19,7 @@ Object {
1919
}
2020
`;
2121

22-
exports[`broccoli-uglify-sourcemap can exclude files from getting uglified 1`] = `
22+
exports[`broccoli-terser-sourcemap can exclude files from getting uglified 1`] = `
2323
Object {
2424
"inside": Object {
2525
"with-upstream-sourcemap.js": "/* This is my header. */
@@ -68,15 +68,15 @@ function third(){
6868
}
6969
`;
7070

71-
exports[`broccoli-uglify-sourcemap can handle ES6 code 1`] = `
71+
exports[`broccoli-terser-sourcemap can handle ES6 code 1`] = `
7272
Object {
7373
"es6.js": "class Foo{bar(){console.log(this.baz)}}let{bar:bar}=Foo.prototype;
7474
//# sourceMappingURL=es6.map",
7575
"es6.map": "{\\"version\\":3,\\"sources\\":[\\"es6.js\\"],\\"names\\":[\\"Foo\\",\\"[object Object]\\",\\"console\\",\\"log\\",\\"this\\",\\"baz\\",\\"bar\\",\\"prototype\\"],\\"mappings\\":\\"AAAA,MAAMA,IACJC,MACEC,QAAQC,IAAIC,KAAKC,MAIrB,IAAIC,IAAEA,KAAQN,IAAIO\\",\\"file\\":\\"es6.js\\"}",
7676
}
7777
`;
7878

79-
exports[`broccoli-uglify-sourcemap generates expected output 1`] = `
79+
exports[`broccoli-terser-sourcemap generates expected output 1`] = `
8080
Object {
8181
"inside": Object {
8282
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}
@@ -105,7 +105,7 @@ Object {
105105
}
106106
`;
107107

108-
exports[`broccoli-uglify-sourcemap mjs can uglify .mjs files 1`] = `
108+
exports[`broccoli-terser-sourcemap mjs can minify .mjs files 1`] = `
109109
Object {
110110
"inside": Object {
111111
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}
@@ -134,11 +134,11 @@ Object {
134134
}
135135
`;
136136

137-
exports[`broccoli-uglify-sourcemap on error rejects with BuildError 1`] = `Object {}`;
137+
exports[`broccoli-terser-sourcemap on error rejects with BuildError 1`] = `Object {}`;
138138

139-
exports[`broccoli-uglify-sourcemap on error shuts down the workerpool 1`] = `Object {}`;
139+
exports[`broccoli-terser-sourcemap on error shuts down the workerpool 1`] = `Object {}`;
140140

141-
exports[`broccoli-uglify-sourcemap shuts down the workerpool 1`] = `
141+
exports[`broccoli-terser-sourcemap shuts down the workerpool 1`] = `
142142
Object {
143143
"inside": Object {
144144
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}
@@ -167,7 +167,7 @@ Object {
167167
}
168168
`;
169169

170-
exports[`broccoli-uglify-sourcemap supports alternate sourcemap location 1`] = `
170+
exports[`broccoli-terser-sourcemap supports alternate sourcemap location 1`] = `
171171
Object {
172172
"inside": Object {
173173
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}
@@ -198,7 +198,7 @@ Object {
198198
}
199199
`;
200200

201-
exports[`broccoli-uglify-sourcemap supports hidden sourcemaps 1`] = `
201+
exports[`broccoli-terser-sourcemap supports hidden sourcemaps 1`] = `
202202
Object {
203203
"inside": Object {
204204
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}",
@@ -222,7 +222,7 @@ Object {
222222
}
223223
`;
224224

225-
exports[`broccoli-uglify-sourcemap supports public URL for sourcemaps 1`] = `
225+
exports[`broccoli-terser-sourcemap supports public URL for sourcemaps 1`] = `
226226
Object {
227227
"inside": Object {
228228
"with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}

test/test.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
/* global describe, afterEach, it, expect */
44

5-
const Uglify = require('..');
5+
const Terser = require('..');
66
const path = require('path');
77
const { createTempDir, createBuilder } = require('broccoli-test-helper');
88

99
const fixtures = path.join(__dirname, 'fixtures');
1010
const fixturesError = path.join(__dirname, 'fixtures-error');
1111

12-
describe('broccoli-uglify-sourcemap', function() {
12+
describe('broccoli-terser-sourcemap', function() {
1313
let input, builder;
1414

1515
beforeEach(async function() {
1616
input = await createTempDir();
1717
});
1818

1919
it('generates expected output', async function() {
20-
builder = createBuilder(new Uglify(fixtures));
20+
builder = createBuilder(new Terser(fixtures));
2121

2222
await builder.build();
2323

@@ -35,39 +35,39 @@ describe('broccoli-uglify-sourcemap', function() {
3535
let { bar } = Foo.prototype;`,
3636
});
3737

38-
builder = createBuilder(new Uglify(input.path()));
38+
builder = createBuilder(new Terser(input.path()));
3939

4040
await builder.build();
4141

4242
expect(builder.read()).toMatchSnapshot();
4343
});
4444

4545
it('can disable sourcemaps', async function() {
46-
builder = createBuilder(new Uglify(fixtures, { uglify: { sourceMap: false } }));
46+
builder = createBuilder(new Terser(fixtures, { terser: { sourceMap: false } }));
4747

4848
await builder.build();
4949

5050
expect(builder.read()).toMatchSnapshot();
5151
});
5252

5353
it('supports hidden sourcemaps', async function() {
54-
builder = createBuilder(new Uglify(fixtures, { hiddenSourceMap: true }));
54+
builder = createBuilder(new Terser(fixtures, { hiddenSourceMap: true }));
5555

5656
await builder.build();
5757

5858
expect(builder.read()).toMatchSnapshot();
5959
});
6060

6161
it('supports public URL for sourcemaps', async function() {
62-
builder = createBuilder(new Uglify(fixtures, { publicUrl: 'https://example.com' }));
62+
builder = createBuilder(new Terser(fixtures, { publicUrl: 'https://example.com' }));
6363

6464
await builder.build();
6565

6666
expect(builder.read()).toMatchSnapshot();
6767
});
6868

6969
it('can exclude files from getting uglified', async function() {
70-
builder = createBuilder(new Uglify(fixtures, {
70+
builder = createBuilder(new Terser(fixtures, {
7171
exclude: ['inside/with-up*'],
7272
}));
7373

@@ -78,26 +78,26 @@ let { bar } = Foo.prototype;`,
7878

7979

8080
it('supports alternate sourcemap location', async function() {
81-
builder = createBuilder(new Uglify(fixtures, { sourceMapDir: 'maps' }));
81+
builder = createBuilder(new Terser(fixtures, { sourceMapDir: 'maps' }));
8282

8383
await builder.build();
8484

8585
expect(builder.read()).toMatchSnapshot();
8686
});
8787

8888
it('shuts down the workerpool', async function() {
89-
let testUglify = new Uglify(fixtures);
90-
builder = createBuilder(testUglify);
89+
let testTerser = new Terser(fixtures);
90+
builder = createBuilder(testTerser);
9191

9292
await builder.build();
9393

9494
expect(builder.read()).toMatchSnapshot();
95-
expect(testUglify.pool.stats().totalWorkers).toEqual(0);
95+
expect(testTerser.pool.stats().totalWorkers).toEqual(0);
9696
});
9797

9898
describe('on error', function() {
9999
it('rejects with BuildError', async function() {
100-
builder = createBuilder(new Uglify(fixturesError));
100+
builder = createBuilder(new Terser(fixturesError));
101101

102102
let shouldError;
103103
await builder.build()
@@ -110,13 +110,13 @@ let { bar } = Foo.prototype;`,
110110
});
111111

112112
it('shuts down the workerpool', async function() {
113-
let testUglify = new Uglify(fixturesError);
114-
builder = createBuilder(testUglify);
113+
let testTerser = new Terser(fixturesError);
114+
builder = createBuilder(testTerser);
115115

116116
await builder.build().catch(() => {});
117117

118118
expect(builder.read()).toMatchSnapshot();
119-
expect(testUglify.pool.stats().totalWorkers).toEqual(0);
119+
expect(testTerser.pool.stats().totalWorkers).toEqual(0);
120120
});
121121
});
122122

@@ -126,28 +126,28 @@ let { bar } = Foo.prototype;`,
126126
});
127127

128128
it('defaults to CPUs-1 workers', async function() {
129-
let testUglify = new Uglify(fixturesError);
129+
let testTerser = new Terser(fixturesError);
130130

131-
expect(testUglify.concurrency).toEqual(require('os').cpus().length - 1);
131+
expect(testTerser.concurrency).toEqual(require('os').cpus().length - 1);
132132
});
133133

134134
it('sets concurrency using the option', async function() {
135-
let testUglify = new Uglify(fixturesError, { concurrency: 145 });
135+
let testTerser = new Terser(fixturesError, { concurrency: 145 });
136136

137-
expect(testUglify.concurrency).toEqual(145);
137+
expect(testTerser.concurrency).toEqual(145);
138138
});
139139

140140
it('overrides concurrency with JOBS env variable', async function() {
141141
process.env.JOBS = '7';
142-
let testUglify = new Uglify(fixturesError, { concurrency: 145 });
142+
let testTerser = new Terser(fixturesError, { concurrency: 145 });
143143

144-
expect(testUglify.concurrency).toEqual(7);
144+
expect(testTerser.concurrency).toEqual(7);
145145
});
146146
});
147147

148148
describe('mjs', function() {
149-
it('can uglify .mjs files', async function() {
150-
builder = createBuilder(new Uglify(fixtures));
149+
it('can minify .mjs files', async function() {
150+
builder = createBuilder(new Terser(fixtures));
151151

152152
await builder.build();
153153

@@ -159,7 +159,7 @@ let { bar } = Foo.prototype;`,
159159
it('deprecated async option', async function() {
160160
let shouldError;
161161
try {
162-
builder = createBuilder(new Uglify(fixtures, { async: true }));
162+
builder = createBuilder(new Terser(fixtures, { async: true }));
163163
} catch (err) {
164164
shouldError = err;
165165
}

0 commit comments

Comments
 (0)