Skip to content

Commit

Permalink
STCLI-209 provide "--cache false" to disable webpack cache (#292)
Browse files Browse the repository at this point in the history
Webpack caches build output by default. Most of the time, that's what we
want, so that's good. But sometimes it isn't what we want, and we need
an easy way to turn it off, so now there's `--cache false` for that.

Refs STCLI-209
  • Loading branch information
zburke authored Jun 9, 2022
1 parent faa8290 commit 5b65690
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Upgrade `simple-git` to `^3.5.0` to avoid command injection vulnerability. Refs STCLI-200, STCLI-192.
* Upgrade `stripes-webpack` to `^4.0.0`. Refs STCLI-203.
* Update NodeJS to Active LTS. Refs STCLI-208.
* Provide `--cache false` to disable webpack caching. Refs STCLI-209.

## [2.5.1](https://github.com/folio-org/stripes-cli/tree/v2.5.1) (2022-03-25)

Expand Down
4 changes: 2 additions & 2 deletions doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ Positional | Description | Type | Notes

Option | Description | Type | Notes
---|---|---|---
`--cache` | Use HardSourceWebpackPlugin cache | boolean |
`--cache` | Use webpack cache | boolean | default: true
`--coverage` | Enable coverage generation | boolean |
`--devtool` | Specify the Webpack devtool for generating source maps | string |
`--existing-build` | Serve an existing build from the supplied directory | string |
Expand Down Expand Up @@ -1191,7 +1191,7 @@ Positional | Description | Type | Notes

Option | Description | Type | Notes
---|---|---|---
`--cache` | Use HardSourceWebpackPlugin cache | boolean |
`--cache` | Use webpack cache | boolean | default: true
`--hasAllPerms` | Set "hasAllPerms" in Stripes config | boolean |
`--host` | Development server host | string | default: "localhost"
`--languages` | Languages to include in tenant build | array |
Expand Down
5 changes: 4 additions & 1 deletion lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { stripesConfigMiddleware } = importLazy('../cli/stripes-config-middleware
const StripesCore = importLazy('../cli/stripes-core');
const StripesPlatform = importLazy('../platform/stripes-platform');
const { okapiOptions, stripesConfigFile, stripesConfigStdin, stripesConfigOptions, buildOptions } = importLazy('./common-options');
const { processError, processStats, emitLintWarnings, limitChunks } = importLazy('../webpack-common');
const { processError, processStats, emitLintWarnings, limitChunks, ignoreCache } = importLazy('../webpack-common');

let _stripesPlatform;
let _stripesCore;
Expand Down Expand Up @@ -54,6 +54,9 @@ function buildCommand(argv) {
if (argv.maxChunks) {
webpackOverrides.push(limitChunks(argv.maxChunks));
}
if (argv.cache === false) {
webpackOverrides.push(ignoreCache);
}
if (context.plugin && context.plugin.beforeBuild) {
webpackOverrides.push(context.plugin.beforeBuild(argv));
}
Expand Down
10 changes: 5 additions & 5 deletions lib/commands/common-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ module.exports.serverOptions = {
default: 'localhost',
group: 'Server Options:',
},
cache: {
type: 'boolean',
describe: 'Use HardSourceWebpackPlugin cache',
group: 'Server Options:',
},
};

module.exports.authOptions = {
Expand Down Expand Up @@ -132,6 +127,11 @@ module.exports.buildOptions = {
type: 'number',
describe: 'Limit the number of Webpack chunks in build output',
},
cache: {
type: 'boolean',
describe: 'Use webpack cache',
default: true,
},
};

const pathOptions = {
Expand Down
7 changes: 6 additions & 1 deletion lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { stripesConfigMiddleware } = importLazy('../cli/stripes-config-middleware
const StripesCore = importLazy('../cli/stripes-core');
const StripesPlatform = importLazy('../platform/stripes-platform');
const { serverOptions, okapiOptions, stripesConfigFile, stripesConfigStdin, stripesConfigOptions, buildOptions } = importLazy('./common-options');
const { processError, emitLintWarnings, limitChunks, enableMirage, enableCoverage } = importLazy('../webpack-common');
const { processError, emitLintWarnings, limitChunks, enableMirage, enableCoverage, ignoreCache } = importLazy('../webpack-common');
const server = importLazy('../server');

// stripes-core does not currently support publicPath with the dev server
Expand Down Expand Up @@ -51,6 +51,11 @@ function serveCommand(argv) {
webpackOverrides.push(limitChunks(argv.maxChunks));
}

if (argv.cache === false) {
webpackOverrides.push(ignoreCache);
}


if (argv.mirage) {
console.info('Using Mirage server');
webpackOverrides.push(enableMirage(argv.mirage));
Expand Down
5 changes: 5 additions & 0 deletions lib/webpack-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ function enableMirage(scenario) {
};
}

function ignoreCache(config) {
return { ...config, cache: false };
}

module.exports = {
processError,
processStats,
Expand All @@ -119,4 +123,5 @@ module.exports = {
limitChunks,
enableCoverage,
enableMirage,
ignoreCache,
};
12 changes: 11 additions & 1 deletion test/commands/build.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const expect = require('chai').expect;

const buildAppCommand = require('../../lib/commands/build');

const { ignoreCache } = require('../../lib/webpack-common');

const packageJsonStub = {};
const tenantConfig = {};

Expand Down Expand Up @@ -62,4 +63,13 @@ describe('The app create command', function () {
expect(console.log).to.have.been.calledWithMatch('Building...');
done();
});

it('turns off webpack caching when --output flag is used.', function () {
const expectedArgs = Object.assign({}, this.argv, { cache: false, outputPath: './output', webpackOverrides: [ignoreCache] });
this.sut.stripesOverrides(platformStub, stripesCoreStub);
this.sut.handler(Object.assign({}, this.argv, { cache: false }));

expect(buildAppCommand.handler).to.have.been.calledOnce;
expect(stripesCoreStub.api.build).to.have.been.calledWith(tenantConfig, expectedArgs);
});
});
6 changes: 6 additions & 0 deletions test/webpack-common.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ describe('The webpack-common module', function () {
expect(result.resolveLoader.modules).to.not.include('path/to/yarn/global/npm_modules');
});
});

describe('ignoreCache', () => {
it('"--cache false" turns off caching', () => {
expect(webpackCommon.ignoreCache({})).to.eql({ cache: false });
});
});
});

0 comments on commit 5b65690

Please sign in to comment.