Skip to content

Commit

Permalink
Merge pull request #2117 from GoogleChrome/js-ext-for-swDest
Browse files Browse the repository at this point in the history
Use a .js extension when generating a default swDest
  • Loading branch information
jeffposnick authored Jul 16, 2019
2 parents 5517c16 + 0431868 commit bd6edce
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const defaults = require('./defaults');
const webpackCommon = require('./webpack-common');

// See https://github.com/hapijs/joi/blob/v16.0.0-rc2/API.md#anydefaultvalue-description
const swSrcBasename = (context) => upath.basename(context.swSrc);
const swSrcBasename = (context) => {
const {name} = upath.parse(context.swSrc);
// Always use the .js extension when generating a default filename.
return name + '.js';
};
swSrcBasename.description = 'derived from the swSrc file name';

module.exports = baseSchema.keys(Object.assign({
Expand Down
33 changes: 33 additions & 0 deletions test/workbox-webpack-plugin/node/inject-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,4 +1140,37 @@ describe(`[workbox-webpack-plugin] InjectManifest (End to End)`, function() {
});
});
});

describe(`[workbox-webpack-plugin] TypeScript compilation`, function() {
it(`should rename a swSrc with a .ts extension to .js`, function(done) {
const outputDir = tempy.directory();
const config = {
mode: 'production',
entry: path.join(SRC_DIR, WEBPACK_ENTRY_FILENAME),
output: {
filename: '[name].[hash:6].js',
path: outputDir,
},
plugins: [
new InjectManifest({
swSrc: path.join(__dirname, '..', 'static', 'sw.ts'),
}),
],
};

const compiler = webpack(config);
compiler.run(async (webpackError, stats) => {
try {
webpackBuildCheck(webpackError, stats);

const files = await globby('*', {cwd: outputDir});
expect(files).to.contain('sw.js');

done();
} catch (error) {
done(error);
}
});
});
});
});
10 changes: 10 additions & 0 deletions test/workbox-webpack-plugin/static/sw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/

// At the moment, this is just used to test the extension renaming.
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST, {});

0 comments on commit bd6edce

Please sign in to comment.