Skip to content

Commit 037e90a

Browse files
authored
feat(package): Make bundle minification configurable
fixes #998, fixes #997
1 parent 5222277 commit 037e90a

File tree

8 files changed

+65
-10
lines changed

8 files changed

+65
-10
lines changed

src/deploy.cmd.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DeployCommand extends StaticCommand {
5252
this._dryRun = false;
5353
this._createPackages = 'auto';
5454
this._addStrain = null;
55-
this._enableMinify = null;
55+
this._enableMinify = false;
5656
}
5757

5858
get requireConfigFile() {
@@ -335,10 +335,8 @@ Alternatively you can auto-add one using the {grey --add <name>} option.`);
335335
const pgkCommand = new PackageCommand(this.log)
336336
.withTarget(this._target)
337337
.withDirectory(this.directory)
338-
.withOnlyModified(this._createPackages === 'auto');
339-
if (this._enableMinify !== null) {
340-
pgkCommand.withMinify(this._enableMinify);
341-
}
338+
.withOnlyModified(this._createPackages === 'auto')
339+
.withMinify(this._enableMinify);
342340
await pgkCommand.run();
343341
}
344342

src/deploy.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ module.exports = function deploy() {
8686
choices: ['auto', 'ignore', 'always'],
8787
default: 'auto',
8888
})
89+
.option('minify', {
90+
describe: 'Enables minification of the final action bundle.',
91+
type: 'boolean',
92+
default: false,
93+
})
8994
.array('default')
9095
.nargs('default', 2)
9196
.coerce('default', arg => arg.reduce((result, value, index, array) => {
@@ -97,7 +102,7 @@ module.exports = function deploy() {
97102
}, {}))
98103
.group(['auto', 'wsk-auth', 'wsk-namespace', 'default', 'dirty'], 'Deployment Options')
99104
.group(['wsk-host', 'loggly-host', 'loggly-auth', 'target'], 'Advanced Options')
100-
.group(['package', 'target'], 'Package options')
105+
.group(['package', 'minify', 'target'], 'Package options')
101106
.check((args) => {
102107
if (!args.auto) {
103108
// single-shot deployment is easy
@@ -154,6 +159,7 @@ module.exports = function deploy() {
154159
.withCreatePackages(argv.package)
155160
.withAddStrain(argv.add)
156161
.withStatic(argv.static)
162+
.withMinify(argv.minify)
157163
.run();
158164
},
159165

src/package.cmd.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class PackageCommand extends StaticCommand {
2424
super(logger);
2525
this._target = null;
2626
this._onlyModified = false;
27-
this._enableMinify = true;
27+
this._enableMinify = false;
2828
}
2929

3030
// eslint-disable-next-line class-methods-use-this
@@ -134,8 +134,16 @@ class PackageCommand extends StaticCommand {
134134
*/
135135
async createBundles(scripts, bar) {
136136
const progressHandler = (percent, msg, ...args) => {
137-
const action = msg === 'building' ? `bundling ${args[0]}` : msg;
137+
/* eslint-disable no-param-reassign */
138+
const action = args.length > 0 ? `${msg} ${args[0]}` : msg;
139+
const rt = bar.renderThrottle;
140+
if (msg !== 'bundling') {
141+
// this is kind of a hack to force redraw for non-bundling steps.
142+
bar.renderThrottle = 0;
143+
}
138144
bar.update(percent * 0.8, { action });
145+
bar.renderThrottle = rt;
146+
/* eslint-enable no-param-reassign */
139147
};
140148

141149
// create the bundles
@@ -211,7 +219,7 @@ class PackageCommand extends StaticCommand {
211219
const bar = new ProgressBar('[:bar] :action :elapseds', {
212220
total: scripts.length * 2 * 5,
213221
width: 50,
214-
renderThrottle: 1,
222+
renderThrottle: 0,
215223
stream: process.stdout,
216224
});
217225

src/package.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ module.exports = function deploy() {
3333
type: 'boolean',
3434
default: false,
3535
})
36+
.option('minify', {
37+
describe: 'Enables minification of the final action bundle.',
38+
type: 'boolean',
39+
default: false,
40+
})
3641
.option('target', {
3742
alias: 'o',
3843
default: '.hlx/build',
3944
type: 'string',
4045
describe: 'Target directory for packaged actions',
4146
})
42-
.group(['force', 'target'], 'Package options')
47+
.group(['force', 'minify', 'target'], 'Package options')
4348
.help();
4449
},
4550
handler: async (argv) => {
@@ -53,6 +58,7 @@ module.exports = function deploy() {
5358
.withTarget(argv.target)
5459
.withOnlyModified(!argv.force)
5560
.withStatic(argv.static)
61+
.withMinify(argv.minify)
5662
.run();
5763
},
5864
};

test/fixtures/all.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ HLX_LOCAL_REPO = ., ../foo-content, ../bar-content
2222
# package
2323
HLX_FORCE = true
2424

25+
# package + deploy
26+
HLX_MINIFY = true
27+
2528
# deploy + publish + perf
2629
HLX_FASTLY_NAMESPACE = 1234
2730
HLX_FASTLY_AUTH = foobar

test/testDeployCli.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('hlx deploy', () => {
4747
mockDeploy.withCreatePackages.returnsThis();
4848
mockDeploy.withAddStrain.returnsThis();
4949
mockDeploy.withStatic.returnsThis();
50+
mockDeploy.withMinify.returnsThis();
5051
mockDeploy.run.returnsThis();
5152

5253
// disable static functions as well to avoid shelljs executions.
@@ -126,6 +127,7 @@ OpenWhisk Namespace is required`);
126127
sinon.assert.calledWith(mockDeploy.withCreatePackages, 'auto');
127128
sinon.assert.calledWith(mockDeploy.withCircleciAuth, '');
128129
sinon.assert.calledWith(mockDeploy.withDryRun, false);
130+
sinon.assert.calledWith(mockDeploy.withMinify, false);
129131
sinon.assert.calledOnce(mockDeploy.run);
130132
});
131133

@@ -148,6 +150,7 @@ OpenWhisk Namespace is required`);
148150
sinon.assert.calledWith(mockDeploy.withDefault, undefined);
149151
sinon.assert.calledWith(mockDeploy.withCircleciAuth, 'foobar');
150152
sinon.assert.calledWith(mockDeploy.withDryRun, true);
153+
sinon.assert.calledWith(mockDeploy.withMinify, true);
151154
sinon.assert.calledOnce(mockDeploy.run);
152155
});
153156

@@ -328,6 +331,19 @@ OpenWhisk Namespace is required`);
328331
sinon.assert.calledOnce(mockDeploy.run);
329332
});
330333

334+
it('hlx deploy can enable minify', () => {
335+
new CLI()
336+
.withCommandExecutor('deploy', mockDeploy)
337+
.run(['deploy',
338+
'--wsk-auth', 'secret-key',
339+
'--wsk-namespace', 'hlx',
340+
'--minify',
341+
]);
342+
343+
sinon.assert.calledWith(mockDeploy.withMinify, true);
344+
sinon.assert.calledOnce(mockDeploy.run);
345+
});
346+
331347
it('hlx deploy can add strain', () => {
332348
new CLI()
333349
.withCommandExecutor('deploy', mockDeploy)

test/testPackageCli.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('hlx package', () => {
3131
mockPackage.withTarget.returnsThis();
3232
mockPackage.withOnlyModified.returnsThis();
3333
mockPackage.withStatic.returnsThis();
34+
mockPackage.withMinify.returnsThis();
3435
mockPackage.run.returnsThis();
3536
});
3637

@@ -45,6 +46,7 @@ describe('hlx package', () => {
4546

4647
sinon.assert.calledWith(mockPackage.withOnlyModified, true);
4748
sinon.assert.calledWith(mockPackage.withTarget, '.hlx/build');
49+
sinon.assert.calledWith(mockPackage.withMinify, false);
4850
sinon.assert.calledOnce(mockPackage.run);
4951
});
5052

@@ -55,6 +57,7 @@ describe('hlx package', () => {
5557
.run(['package']);
5658
sinon.assert.calledWith(mockPackage.withTarget, 'foo');
5759
sinon.assert.calledWith(mockPackage.withOnlyModified, false);
60+
sinon.assert.calledWith(mockPackage.withMinify, true);
5861
sinon.assert.calledOnce(mockPackage.run);
5962
});
6063

@@ -67,6 +70,20 @@ describe('hlx package', () => {
6770

6871
sinon.assert.calledWith(mockPackage.withOnlyModified, false);
6972
sinon.assert.calledWith(mockPackage.withTarget, '.hlx/build');
73+
sinon.assert.calledWith(mockPackage.withMinify, false);
74+
sinon.assert.calledOnce(mockPackage.run);
75+
});
76+
77+
it('hlx package can enable minify', () => {
78+
new CLI()
79+
.withCommandExecutor('package', mockPackage)
80+
.run(['package',
81+
'--minify',
82+
]);
83+
84+
sinon.assert.calledWith(mockPackage.withOnlyModified, true);
85+
sinon.assert.calledWith(mockPackage.withTarget, '.hlx/build');
86+
sinon.assert.calledWith(mockPackage.withMinify, true);
7087
sinon.assert.calledOnce(mockPackage.run);
7188
});
7289
});

test/testPackageCmd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('hlx package (Integration)', () => {
5454
.withTarget(buildDir)
5555
.withOnlyModified(false)
5656
.withStatic('both')
57+
.withMinify(false)
5758
.on('create-package', (info) => {
5859
created[info.name] = true;
5960
})

0 commit comments

Comments
 (0)