Repository: GoogleChrome/sw-precache
Pull request #210 (2016-11-04 19:31:18)

On Windows path.join uses '\' but a '/' is needed.
Update the example code because the path.join method uses an item separator that is OS dependent. On a Windows system path.join will result in a path like this:
```
foo\bar
```
In this case the prefix is not stripped, it is isn't found because the path returned by staticFileGlobs has UNIX separators. This example code should work on all OSs.

googlebot: Thanks for your pull request.  It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed, please reply here (e.g. `I signed it!`) and we'll verify.  Thanks.

---

- If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address.  Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
- If you signed the CLA as a corporation, please let us know the company's name.

<!-- need_sender_cla -->
rlmcneary2: CLA signed.
googlebot: CLAs look good, thanks!

<!-- ok -->

Patch:
diff --git a/README.md b/README.md
index 773fcdb..243189e 100644
--- a/README.md
+++ b/README.md
@@ -136,7 +136,7 @@ gulp.task('generate-service-worker', function(callback) {
   var swPrecache = require('sw-precache');
   var rootDir = 'app';
 
-  swPrecache.write(path.join(rootDir, 'service-worker.js'), {
+  swPrecache.write(`${rootDir}/service-worker.js`), {
     staticFileGlobs: [rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'],
     stripPrefix: rootDir
   }, callback);
@@ -261,9 +261,9 @@ less flexibility:
 
 ## Runtime Caching
 
-It's often desireable, even necessary to use precaching and runtime caching together. You may have seen our [sw-toolbox](https://github.com/GoogleChrome/sw-toolbox) tool, which handles runtime caching, and wondered how to use them together. Fortunately, sw-precache handles this fro you.
+It's often desireable, even necessary to use precaching and runtime caching together. You may have seen our [`sw-toolbox`](https://github.com/GoogleChrome/sw-toolbox) tool, which handles runtime caching, and wondered how to use them together. Fortunately, `sw-precache` handles this for you.
 
-The sw-precache module has the ability to include the sw-toolbox code and configuration alongside its own configuration. Using the `runtimeCaching` configuration option in sw-precache ([see below](#runtimecaching-arrayobject)) is a shortcut that accomplishes what you could do manually by importing sw-toolbox in your service worker and writing your own routing rules.
+The `sw-precache` module has the ability to include the `sw-toolbox` code and configuration alongside its own configuration. Using the `runtimeCaching` configuration option in `sw-precache` ([see below](#runtimecaching-arrayobject)) is a shortcut that accomplishes what you could do manually by importing `sw-toolbox` in your service worker and writing your own routing rules.
 
 ## API
 
@@ -289,7 +289,7 @@ Since 2.2.0, `generate()` also returns a
 `write` takes in [options](#options), generates a service worker from them, 
 and writes the service worker to a specified file. This method always 
 invokes `callback(error)`. If no error was found, the `error` parameter will 
-be `null'
+be `null`
 
 Since 2.2.0, `write()` also returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
 
@@ -465,7 +465,8 @@ or a string, following the conventions of the `sw-toolbox` library's
 [routing configuration](https://googlechrome.github.io/sw-toolbox/docs/master/tutorial-usage.html). Also required is
 a `handler`, which should be either a string corresponding to one of the
 [built-in handlers](https://googlechrome.github.io/sw-toolbox/docs/master/tutorial-api.html) under the `toolbox.` namespace, or a function corresponding to your custom
-[request handler](https://googlechrome.github.io/sw-toolbox/docs/master/tutorial-usage). There is also
+[request handler](https://googlechrome.github.io/sw-toolbox/docs/master/tutorial-usage).
+Optionally, `method` can be added to specify one of the [supported HTTP methods](https://googlechrome.github.io/sw-toolbox/docs/master/tutorial-api.html) (_default: `'get'`_). There is also
 support for `options`, which corresponds to the same options supported by a
 [`sw-toolbox` handler](https://googlechrome.github.io/sw-toolbox/docs/master/tutorial-api.html).
 
diff --git a/cli.js b/cli.js
index b5175c4..a73c9a0 100755
--- a/cli.js
+++ b/cli.js
@@ -34,6 +34,9 @@ function setDefaults(cli, configFileFlags) {
   compositeFlags.stripPrefix = compositeFlags.stripPrefix ||
     configFileFlags.stripPrefix || compositeFlags.root;
 
+  compositeFlags.stripPrefixMulti = compositeFlags.stripPrefixMulti ||
+    configFileFlags.stripPrefixMulti || {};
+
   compositeFlags.swFile = compositeFlags.swFile || configFileFlags.swFile ||
     'service-worker.js';
   compositeFlags.swFilePath = compositeFlags.swFilePath ||
@@ -53,6 +56,9 @@ function setDefaults(cli, configFileFlags) {
   compositeFlags.navigateFallback = compositeFlags.navigateFallback ||
     configFileFlags.navigateFallback;
 
+  compositeFlags.navigateFallbackWhitelist = compositeFlags.navigateFallbackWhitelist ||
+    configFileFlags.navigateFallbackWhitelist;
+
   compositeFlags.staticFileGlobs = compositeFlags.staticFileGlobs ||
     configFileFlags.staticFileGlobs;
   if (compositeFlags.staticFileGlobs) {
@@ -103,6 +109,10 @@ function setDefaults(cli, configFileFlags) {
     (('clientsClaim' in configFileFlags) ?
       configFileFlags.clientsClaim : undefined);
 
+  compositeFlags.dontCacheBustUrlsMatching =
+    compositeFlags.dontCacheBustUrlsMatching ||
+    configFileFlags.dontCacheBustUrlsMatching;
+
   return compositeFlags;
 }
 
diff --git a/lib/sw-precache.js b/lib/sw-precache.js
index 1d0a27d..0f45a30 100644
--- a/lib/sw-precache.js
+++ b/lib/sw-precache.js
@@ -104,13 +104,22 @@ function generateRuntimeCaching(runtimeCaching) {
         // include its body inline.
         (typeof curr.handler === 'string' ? 'toolbox.' : '') + curr.handler,
         // Default to no options.
-        JSON.stringify(curr.options || {}));
+        stringifyToolboxOptions(curr.options));
     }
 
     return prev + line;
   }, '');
 }
 
+function stringifyToolboxOptions(options) {
+  options = options || {};
+  var str = JSON.stringify(options);
+  if (options.origin instanceof RegExp) {
+    str = str.replace(/("origin":)\{\}/, '$1' + options.origin);
+  }
+  return str;
+}
+
 function generate(params, callback) {
   return new Promise(function(resolve, reject) {
     params = defaults(params || {}, {
diff --git a/package.json b/package.json
index 249bbf9..9d49798 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "sw-precache",
-  "version": "4.2.1",
+  "version": "4.2.3",
   "description": "Generates a service worker to cache your local App Shell resources.",
   "author": {
     "name": "Jeff Posnick",


Test patch:
diff --git a/test/test.js b/test/test.js
index af060c2..5bb1770 100644
--- a/test/test.js
+++ b/test/test.js
@@ -445,4 +445,26 @@ describe('generateRuntimeCaching', function() {
     }]);
     assert.equal(code, '\ntoolbox.router.get(/test/, toolbox.testHandler, {});');
   });
+
+  it('should handle origin regex', function() {
+    var code = generateRuntimeCaching([{
+      urlPattern: '/*',
+      handler: 'testHandler',
+      options: {
+        origin: /http:\/\/www.example\.com/
+      }
+    }]);
+    assert.equal(code, '\ntoolbox.router.get("/*", toolbox.testHandler, {"origin":/http:\\/\\/www.example\\.com/});');
+  });
+
+  it('should handle origin string', function() {
+    var code = generateRuntimeCaching([{
+      urlPattern: '/*',
+      handler: 'testHandler',
+      options: {
+        origin: 'http://www.example.com'
+      }
+    }]);
+    assert.equal(code, '\ntoolbox.router.get("/*", toolbox.testHandler, {"origin":"http://www.example.com"});');
+  });
 });