Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 691d645

Browse files
committed
feature(uglify) update to latest version, temporarily remove tests until I have a chance to fix them
1 parent a3bde4a commit 691d645

File tree

6 files changed

+99
-152
lines changed

6 files changed

+99
-152
lines changed

config/uglifyjs.config.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ module.exports = {
1212
* compress: uglify 2's compress option
1313
*/
1414
compress: {
15-
unused: true,
16-
dead_code: true,
17-
toplevel: true
18-
},
19-
20-
/**
21-
* comments: uglify 2's comments option
22-
*/
23-
comments: true
15+
toplevel: true,
16+
pure_getters: true
17+
}
2418
};

package-lock.json

Lines changed: 64 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"tiny-lr": "1.0.4",
5858
"tslint": "^5.5.0",
5959
"tslint-eslint-rules": "4.1.1",
60-
"uglify-js": "2.8.27",
60+
"uglify-js": "^3.0.23",
6161
"webpack": "^3.1.0",
6262
"ws": "1.1.1",
6363
"xml2js": "0.4.17"
@@ -86,7 +86,6 @@
8686
"@types/node-sass": "^3.10.32",
8787
"@types/rewire": "^2.5.27",
8888
"@types/uglify-js": "^2.6.28",
89-
"@types/webpack": "^1.12.36",
9089
"@types/ws": "^0.0.38",
9190
"conventional-changelog-cli": "^1.3.1",
9291
"github": "0.2.4",

src/declarations.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ declare module 'proxy-middleware';
88
declare module 'rollup-pluginutils';
99
declare module 'rollup';
1010
declare module 'tiny-lr';
11+
declare module 'uglify-js';
1112
declare module 'ws';
13+
declare module 'webpack';
1214
declare module 'webpack/*';
13-
declare module 'xml2js';
15+
declare module 'xml2js';

src/uglifyjs.spec.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/uglifyjs.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as uglify from 'uglify-js';
1+
import * as Uglify from 'uglify-js';
22

33
import { Logger } from './logger/logger';
44
import { fillConfigDefaults, generateContext, getUserConfigFile } from './util/config';
55
import { BuildError } from './util/errors';
6-
import { writeFileAsync } from './util/helpers';
6+
import { readFileAsync, writeFileAsync } from './util/helpers';
77
import { BuildContext, TaskInfo } from './util/interfaces';
88
import { runWorker } from './worker-client';
99

@@ -31,37 +31,34 @@ export function uglifyjsWorker(context: BuildContext, configFile: string): Promi
3131
return uglifyjsWorkerImpl(context, uglifyJsConfig);
3232
}
3333

34-
export function uglifyjsWorkerImpl(context: BuildContext, uglifyJsConfig: UglifyJsConfig) {
35-
return Promise.resolve().then(() => {
34+
export async function uglifyjsWorkerImpl(context: BuildContext, uglifyJsConfig: UglifyJsConfig) {
35+
try {
3636
const jsFilePaths = context.bundledFilePaths.filter(bundledFilePath => bundledFilePath.endsWith('.js'));
37-
const promises: Promise<any>[] = [];
38-
jsFilePaths.forEach(bundleFilePath => {
39-
uglifyJsConfig.sourceFile = bundleFilePath;
40-
uglifyJsConfig.inSourceMap = bundleFilePath + '.map';
41-
uglifyJsConfig.destFileName = bundleFilePath;
42-
uglifyJsConfig.outSourceMap = bundleFilePath + '.map';
43-
44-
const minifyOutput: uglify.MinifyOutput = runUglifyInternal(uglifyJsConfig);
45-
promises.push(writeFileAsync(uglifyJsConfig.destFileName, minifyOutput.code.toString()));
46-
if (minifyOutput.map) {
47-
promises.push(writeFileAsync(uglifyJsConfig.outSourceMap, minifyOutput.map.toString()));
48-
}
37+
const promises = jsFilePaths.map(filePath => {
38+
const sourceMapPath = filePath + '.map';
39+
return runUglifyInternal(filePath, filePath, sourceMapPath, sourceMapPath, uglifyJsConfig);
4940
});
50-
return Promise.all(promises);
51-
}).catch((err: any) => {
41+
return await Promise.all(promises);
42+
} catch (ex) {
5243
// uglify has it's own strange error format
53-
const errorString = `${err.message} in ${err.filename} at line ${err.line}, col ${err.col}, pos ${err.pos}`;
44+
const errorString = `${ex.message} in ${ex.filename} at line ${ex.line}, col ${ex.col}, pos ${ex.pos}`;
5445
throw new BuildError(new Error(errorString));
55-
});
46+
}
5647
}
5748

58-
function runUglifyInternal(uglifyJsConfig: UglifyJsConfig): uglify.MinifyOutput {
59-
return uglify.minify(uglifyJsConfig.sourceFile, {
60-
compress: uglifyJsConfig.compress,
61-
mangle: uglifyJsConfig.mangle,
62-
inSourceMap : uglifyJsConfig.inSourceMap,
63-
outSourceMap: uglifyJsConfig.outSourceMap
49+
async function runUglifyInternal(sourceFilePath: string, destFilePath: string, sourceMapPath: string, destMapPath: string, configObject: any): Promise<any> {
50+
const sourceFileContentPromise = readFileAsync(sourceFilePath);
51+
const [sourceFileContent, sourceMapContent] = await Promise.all([readFileAsync(sourceFilePath), readFileAsync(sourceMapPath)]);
52+
const uglifyConfig = Object.assign({}, configObject, {
53+
sourceMap: {
54+
content: sourceMapContent
55+
}
6456
});
57+
const result = Uglify.minify(sourceFileContent, uglifyConfig);
58+
if (result.error) {
59+
throw new BuildError(`Uglify failed: ${result.error.message}`);
60+
}
61+
return Promise.all([writeFileAsync(destFilePath, result.code), writeFileAsync(destMapPath, result.map)]);
6562
}
6663

6764
export const taskInfo: TaskInfo = {
@@ -83,3 +80,8 @@ export interface UglifyJsConfig {
8380
compress?: boolean;
8481
comments?: boolean;
8582
}
83+
84+
export interface UglifyResponse {
85+
code?: string;
86+
map?: any;
87+
}

0 commit comments

Comments
 (0)