From aab8affb3fb919826fdf7b32702c168661a6f40d Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Mon, 6 Aug 2018 16:15:27 -0300 Subject: [PATCH 1/8] fix empty object on custom plugins --- packages/workbox-build/package-lock.json | 182 +++++++++++++++--- packages/workbox-build/package.json | 1 + .../src/lib/runtime-caching-converter.js | 6 +- 3 files changed, 160 insertions(+), 29 deletions(-) diff --git a/packages/workbox-build/package-lock.json b/packages/workbox-build/package-lock.json index f1ce68920..3a431a58b 100644 --- a/packages/workbox-build/package-lock.json +++ b/packages/workbox-build/package-lock.json @@ -1,14 +1,16 @@ { - "requires": true, + "name": "workbox-build", + "version": "3.4.1", "lockfileVersion": 1, + "requires": true, "dependencies": { "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", "requires": { - "core-js": "^2.4.0", - "regenerator-runtime": "^0.11.0" + "core-js": "2.5.1", + "regenerator-runtime": "0.11.0" } }, "balanced-match": { @@ -21,7 +23,7 @@ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", "requires": { - "balanced-match": "^1.0.0", + "balanced-match": "1.0.0", "concat-map": "0.0.1" } }, @@ -30,7 +32,7 @@ "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.4.0.tgz", "integrity": "sha1-EYe+Tz1M8MBCfUP3Tu8fc1AWFMA=", "requires": { - "babel-runtime": "^6.18.0" + "babel-runtime": "6.26.0" } }, "concat-map": { @@ -48,9 +50,9 @@ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.2.tgz", "integrity": "sha1-+RcExT0bRh+JNFKwwwfZmXZHq2s=", "requires": { - "graceful-fs": "^4.1.2", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" + "graceful-fs": "4.1.11", + "jsonfile": "4.0.0", + "universalify": "0.1.1" } }, "fs.realpath": { @@ -58,17 +60,22 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "get-own-enumerable-property-symbols": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-2.0.1.tgz", + "integrity": "sha512-TtY/sbOemiMKPRUDDanGCSgBYe7Mf0vbRsWnBZ+9yghpZ1MvcpSpuZFjHdEeY/LZjZy0vdLjS77L6HosisFiug==" + }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" } }, "graceful-fs": { @@ -86,8 +93,8 @@ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "requires": { - "once": "^1.3.0", - "wrappy": "1" + "once": "1.4.0", + "wrappy": "1.0.2" } }, "inherits": { @@ -95,12 +102,22 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, + "is-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=" + }, + "is-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz", + "integrity": "sha1-/S2INUXEa6xaYz57mgnof6LLUGk=" + }, "isemail": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-3.0.0.tgz", "integrity": "sha512-rz0ng/c+fX+zACpLgDB8fnUQ845WSU06f4hlhk4K8TJxmR6f5hyvitu9a9JdMD7aq/P4E0XdG1uaab2OiXgHlA==", "requires": { - "punycode": "2.x.x" + "punycode": "2.1.0" } }, "joi": { @@ -108,9 +125,9 @@ "resolved": "https://registry.npmjs.org/joi/-/joi-11.1.1.tgz", "integrity": "sha512-hffQzH42mYLvUCqhUPZZGegiiIjVvHcOV8mrxXPci8qZFOp2sHK4778GPyI3ZlvqTOHs8qZN6DovDnBR1slO4g==", "requires": { - "hoek": "4.x.x", - "isemail": "3.x.x", - "topo": "2.x.x" + "hoek": "4.2.0", + "isemail": "3.0.0", + "topo": "2.0.2" } }, "jsonfile": { @@ -118,7 +135,7 @@ "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", "requires": { - "graceful-fs": "^4.1.6" + "graceful-fs": "4.1.11" } }, "lodash._reinterpolate": { @@ -131,8 +148,8 @@ "resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.4.0.tgz", "integrity": "sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A=", "requires": { - "lodash._reinterpolate": "~3.0.0", - "lodash.templatesettings": "^4.0.0" + "lodash._reinterpolate": "3.0.0", + "lodash.templatesettings": "4.1.0" } }, "lodash.templatesettings": { @@ -140,7 +157,7 @@ "resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.1.0.tgz", "integrity": "sha1-K01OlbpEDZFf8IvImeRVNmZxMxY=", "requires": { - "lodash._reinterpolate": "~3.0.0" + "lodash._reinterpolate": "3.0.0" } }, "minimatch": { @@ -148,7 +165,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "requires": { - "brace-expansion": "^1.1.7" + "brace-expansion": "1.1.8" } }, "once": { @@ -156,7 +173,7 @@ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "requires": { - "wrappy": "1" + "wrappy": "1.0.2" } }, "path-is-absolute": { @@ -179,12 +196,22 @@ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", "integrity": "sha512-/aA0kLeRb5N9K0d4fw7ooEbI+xDe+DKD499EQqygGqeS8N3xto15p09uY2xj7ixP81sNPXvRLnAQIqdVStgb1A==" }, + "stringify-object": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.2.2.tgz", + "integrity": "sha512-O696NF21oLiDy8PhpWu8AEqoZHw++QW6mUv0UvKZe8gWSdSvMXkiLufK7OmnP27Dro4GU5kb9U7JIO0mBuCRQg==", + "requires": { + "get-own-enumerable-property-symbols": "2.0.1", + "is-obj": "1.0.1", + "is-regexp": "1.0.0" + } + }, "topo": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/topo/-/topo-2.0.2.tgz", "integrity": "sha1-zVYVdSU5BXwNwEkaYhw7xvvh0YI=", "requires": { - "hoek": "4.x.x" + "hoek": "4.2.0" } }, "universalify": { @@ -192,6 +219,107 @@ "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", "integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=" }, + "workbox-background-sync": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-background-sync/-/workbox-background-sync-3.4.1.tgz", + "integrity": "sha512-Ksb2nCg/2wOyBMhSBqSbtCEwuKaf5sHgTY8HdCxbLIQSzDh9/qZqg+1P11CKlgJmHtje3EK3B8EsrzukZo10xA==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-broadcast-cache-update": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-broadcast-cache-update/-/workbox-broadcast-cache-update-3.4.1.tgz", + "integrity": "sha512-+WPqHFk4ER4RICAMOYrP88yBbiUQ9ZOFNruqwbl9YxGfbADV16OEGmYpIs+Az6HT6DNDCx8eQqtFiaG8N3O11Q==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-cache-expiration": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-cache-expiration/-/workbox-cache-expiration-3.4.1.tgz", + "integrity": "sha512-AzOPB+dwfxg13v4+q5jWkxsw/oim9mPIzew1anu8ALA3vB8qySaJJToXp+ZlVh/Co+sDK0tgjlB76bvSFHgZ4g==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-cacheable-response": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-cacheable-response/-/workbox-cacheable-response-3.4.1.tgz", + "integrity": "sha512-SO2k830JT93GitPwc5tzJI49d9VwyVxXwiCbyvo+Sqo+dcvWSrmpsyuXdzy6zuasbPrWUF0vsFj1uGtZbOym8Q==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-core": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-3.4.1.tgz", + "integrity": "sha512-RqMV2so9/KLAu9aUxJ/85pvrZMUn835B8zoHmqRyGNetiDr8B1zSBeKXPZAjFlX/88KdhizNwiRlJtqlXtM4tA==" + }, + "workbox-google-analytics": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-google-analytics/-/workbox-google-analytics-3.4.1.tgz", + "integrity": "sha512-w6Osz2Rr1/4+W0gram6Yzg6NNWLvHP51RwFCNAZSpEnipr0qSEtD+yvwrdaHfiJHWhcK2yH/V6E1MV8Hrczmvw==", + "requires": { + "workbox-background-sync": "3.4.1", + "workbox-core": "3.4.1", + "workbox-routing": "3.4.1", + "workbox-strategies": "3.4.1" + } + }, + "workbox-navigation-preload": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-navigation-preload/-/workbox-navigation-preload-3.4.1.tgz", + "integrity": "sha512-P3FHAcyZ8db2QiW/BpMkuosC1OkRsEoUaT7U3QOgg7JSjjsJoEbF7G5olNe+P+PQYdVhJA7TCuptI6dy2gLS/g==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-precaching": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-precaching/-/workbox-precaching-3.4.1.tgz", + "integrity": "sha512-ykU2mly9xmRrCW6iMeUWYydWiso/WSE16+7wponhI0WC53jiQSt2JvykWm0VpWFJSs6ZTSZZ1WK2gs/brRnPug==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-range-requests": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-range-requests/-/workbox-range-requests-3.4.1.tgz", + "integrity": "sha512-ktgjl6liZrRTmQjPw1pBblC5umHnTb8XcvFVitdGz17B23jj6cUV4EXzEU2ilGn6jO6+MLV1Vn9SWajtLSc2Gg==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-routing": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-routing/-/workbox-routing-3.4.1.tgz", + "integrity": "sha512-6j6cXMUYfMPYTycmElxVOfBTr6WV5zAn/JUFJ7GJ5pYFIE9cqztprnrcOsWJ42+AiNIeHPbKfyIWE/rZVviMxQ==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-strategies": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-strategies/-/workbox-strategies-3.4.1.tgz", + "integrity": "sha512-7mJuzFsgejflzjfnChXCFma1S0mi9WC6wlSU2wE50M7bJmEuf9A3j3MojpKcsTEM58hbhbnU6QF/u9iIV7+opw==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-streams": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-streams/-/workbox-streams-3.4.1.tgz", + "integrity": "sha512-krw+5bp+oe9Za5c6WlTWM3SgZGfExYcqRSn1gsyYgKeXmgzTwf+DOb5Lwult0KSWlJfq8B3Wk7sW8Sl7lRzSbA==", + "requires": { + "workbox-core": "3.4.1" + } + }, + "workbox-sw": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/workbox-sw/-/workbox-sw-3.4.1.tgz", + "integrity": "sha512-nnm2by5oaQGXRH7x4M5/n2KqjUGVmP4P8azUmJITnYa3DWVYn/ghDg3LJ5+h4A28vYq9V6ePgATaEPfb6B5pug==" + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/packages/workbox-build/package.json b/packages/workbox-build/package.json index ddcd9d086..956e67504 100644 --- a/packages/workbox-build/package.json +++ b/packages/workbox-build/package.json @@ -27,6 +27,7 @@ "joi": "^11.1.1", "lodash.template": "^4.4.0", "pretty-bytes": "^4.0.2", + "stringify-object": "^3.2.2", "workbox-background-sync": "^3.4.1", "workbox-broadcast-cache-update": "^3.4.1", "workbox-cache-expiration": "^3.4.1", diff --git a/packages/workbox-build/src/lib/runtime-caching-converter.js b/packages/workbox-build/src/lib/runtime-caching-converter.js index a83818746..4b0a0e09b 100644 --- a/packages/workbox-build/src/lib/runtime-caching-converter.js +++ b/packages/workbox-build/src/lib/runtime-caching-converter.js @@ -15,9 +15,10 @@ */ const ol = require('common-tags').oneLine; - +const objectStringify = require('stringify-object'); const errors = require('./errors'); + /** * Given a set of options that configures `sw-toolbox`'s behavior, convert it * into a string that would configure equivalent `workbox-sw` behavior. @@ -31,7 +32,8 @@ const errors = require('./errors'); function getOptionsString(options = {}) { let plugins = []; if (options.plugins) { - plugins = options.plugins.map((plugin) => JSON.stringify(plugin)); + // Using lib because JSON.stringify won't handle functions + plugins = options.plugins.map((plugin) => objectStringify(plugin)); delete options.plugins; } From a20f2b21184cf4b3bfe3d0dd648ddd74c2f18ead Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Tue, 7 Aug 2018 10:56:42 -0300 Subject: [PATCH 2/8] strip comments when parsing custom plugins --- packages/workbox-build/package-lock.json | 36 +++++++++++++++++++ packages/workbox-build/package.json | 1 + .../src/lib/runtime-caching-converter.js | 7 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/workbox-build/package-lock.json b/packages/workbox-build/package-lock.json index 3a431a58b..8a0f1e793 100644 --- a/packages/workbox-build/package-lock.json +++ b/packages/workbox-build/package-lock.json @@ -4,6 +4,28 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "babel-extract-comments": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/babel-extract-comments/-/babel-extract-comments-1.0.0.tgz", + "integrity": "sha512-qWWzi4TlddohA91bFwgt6zO/J0X+io7Qp184Fw0m2JYRSTZnJbFR8+07KmzudHCZgOiKRCrjhylwv9Xd8gfhVQ==", + "requires": { + "babylon": "6.18.0" + } + }, + "babel-plugin-syntax-object-rest-spread": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", + "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=" + }, + "babel-plugin-transform-object-rest-spread": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz", + "integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=", + "requires": { + "babel-plugin-syntax-object-rest-spread": "6.13.0", + "babel-runtime": "6.26.0" + } + }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -13,6 +35,11 @@ "regenerator-runtime": "0.11.0" } }, + "babylon": { + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", + "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==" + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -206,6 +233,15 @@ "is-regexp": "1.0.0" } }, + "strip-comments": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/strip-comments/-/strip-comments-1.0.2.tgz", + "integrity": "sha512-kL97alc47hoyIQSV165tTt9rG5dn4w1dNnBhOQ3bOU1Nc1hel09jnXANaHJ7vzHLd4Ju8kseDGzlev96pghLFw==", + "requires": { + "babel-extract-comments": "1.0.0", + "babel-plugin-transform-object-rest-spread": "6.26.0" + } + }, "topo": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/topo/-/topo-2.0.2.tgz", diff --git a/packages/workbox-build/package.json b/packages/workbox-build/package.json index 956e67504..bc1bb094c 100644 --- a/packages/workbox-build/package.json +++ b/packages/workbox-build/package.json @@ -28,6 +28,7 @@ "lodash.template": "^4.4.0", "pretty-bytes": "^4.0.2", "stringify-object": "^3.2.2", + "strip-comments": "^1.0.2", "workbox-background-sync": "^3.4.1", "workbox-broadcast-cache-update": "^3.4.1", "workbox-cache-expiration": "^3.4.1", diff --git a/packages/workbox-build/src/lib/runtime-caching-converter.js b/packages/workbox-build/src/lib/runtime-caching-converter.js index 4b0a0e09b..69b75d4fe 100644 --- a/packages/workbox-build/src/lib/runtime-caching-converter.js +++ b/packages/workbox-build/src/lib/runtime-caching-converter.js @@ -16,6 +16,7 @@ const ol = require('common-tags').oneLine; const objectStringify = require('stringify-object'); +const stripComments = require('strip-comments'); const errors = require('./errors'); @@ -32,8 +33,10 @@ const errors = require('./errors'); function getOptionsString(options = {}) { let plugins = []; if (options.plugins) { - // Using lib because JSON.stringify won't handle functions - plugins = options.plugins.map((plugin) => objectStringify(plugin)); + // Using libs because JSON.stringify won't handle functions + // and to remove comments without complexity + plugins = options.plugins.map((plugin) => + stripComments(objectStringify(plugin))); delete options.plugins; } From 1935656199493d02ffbc13b24c0380910d79660b Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Tue, 7 Aug 2018 12:24:54 -0300 Subject: [PATCH 3/8] use regex instead of strip-comments lib --- packages/workbox-build/package-lock.json | 36 ------------------- packages/workbox-build/package.json | 1 - .../src/lib/runtime-caching-converter.js | 7 ++-- 3 files changed, 3 insertions(+), 41 deletions(-) diff --git a/packages/workbox-build/package-lock.json b/packages/workbox-build/package-lock.json index 8a0f1e793..3a431a58b 100644 --- a/packages/workbox-build/package-lock.json +++ b/packages/workbox-build/package-lock.json @@ -4,28 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "babel-extract-comments": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/babel-extract-comments/-/babel-extract-comments-1.0.0.tgz", - "integrity": "sha512-qWWzi4TlddohA91bFwgt6zO/J0X+io7Qp184Fw0m2JYRSTZnJbFR8+07KmzudHCZgOiKRCrjhylwv9Xd8gfhVQ==", - "requires": { - "babylon": "6.18.0" - } - }, - "babel-plugin-syntax-object-rest-spread": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", - "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=" - }, - "babel-plugin-transform-object-rest-spread": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz", - "integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=", - "requires": { - "babel-plugin-syntax-object-rest-spread": "6.13.0", - "babel-runtime": "6.26.0" - } - }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -35,11 +13,6 @@ "regenerator-runtime": "0.11.0" } }, - "babylon": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", - "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==" - }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -233,15 +206,6 @@ "is-regexp": "1.0.0" } }, - "strip-comments": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/strip-comments/-/strip-comments-1.0.2.tgz", - "integrity": "sha512-kL97alc47hoyIQSV165tTt9rG5dn4w1dNnBhOQ3bOU1Nc1hel09jnXANaHJ7vzHLd4Ju8kseDGzlev96pghLFw==", - "requires": { - "babel-extract-comments": "1.0.0", - "babel-plugin-transform-object-rest-spread": "6.26.0" - } - }, "topo": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/topo/-/topo-2.0.2.tgz", diff --git a/packages/workbox-build/package.json b/packages/workbox-build/package.json index bc1bb094c..956e67504 100644 --- a/packages/workbox-build/package.json +++ b/packages/workbox-build/package.json @@ -28,7 +28,6 @@ "lodash.template": "^4.4.0", "pretty-bytes": "^4.0.2", "stringify-object": "^3.2.2", - "strip-comments": "^1.0.2", "workbox-background-sync": "^3.4.1", "workbox-broadcast-cache-update": "^3.4.1", "workbox-cache-expiration": "^3.4.1", diff --git a/packages/workbox-build/src/lib/runtime-caching-converter.js b/packages/workbox-build/src/lib/runtime-caching-converter.js index 69b75d4fe..8f0582aac 100644 --- a/packages/workbox-build/src/lib/runtime-caching-converter.js +++ b/packages/workbox-build/src/lib/runtime-caching-converter.js @@ -16,7 +16,6 @@ const ol = require('common-tags').oneLine; const objectStringify = require('stringify-object'); -const stripComments = require('strip-comments'); const errors = require('./errors'); @@ -34,9 +33,9 @@ function getOptionsString(options = {}) { let plugins = []; if (options.plugins) { // Using libs because JSON.stringify won't handle functions - // and to remove comments without complexity - plugins = options.plugins.map((plugin) => - stripComments(objectStringify(plugin))); + plugins = options.plugins.map((plugin) => objectStringify(plugin) + // See http://blog.moagrius.com/javascript/javascript-regexp-to-remove-comments/ + .replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm, '')); delete options.plugins; } From 855585389520586c4d96cc7a3765f5689284df3b Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Tue, 7 Aug 2018 12:26:46 -0300 Subject: [PATCH 4/8] add test cases for custom plugins --- .../node/lib/runtime-caching-converter.js | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test/workbox-build/node/lib/runtime-caching-converter.js b/test/workbox-build/node/lib/runtime-caching-converter.js index c9387ba7d..164b4d435 100644 --- a/test/workbox-build/node/lib/runtime-caching-converter.js +++ b/test/workbox-build/node/lib/runtime-caching-converter.js @@ -44,7 +44,6 @@ function validate(runtimeCachingOptions, convertedOptions) { const script = new vm.Script(convertedOptions.join('\n')); script.runInNewContext(globalScope); - runtimeCachingOptions.forEach((runtimeCachingOption, i) => { const registerRouteCall = globalScope.workbox.routing.registerRoute.getCall(i); expect(registerRouteCall.args[0]).to.eql(runtimeCachingOption.urlPattern); @@ -230,4 +229,70 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function( const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); validate(runtimeCachingOptions, convertedOptions); }); + + it(`should support custom plugins`, function() { + const runtimeCachingOptions = [{ + urlPattern: /abc/, + handler: 'cacheFirst', + options: { + expiration: { + maxEntries: 10, + }, + cacheableResponse: { + statuses: [0, 200], + }, + broadcastUpdate: { + channelName: 'test', + options: { + source: 'test-source', + }, + }, + backgroundSync: { + name: 'test', + options: { + maxRetentionTime: 123, + }, + }, + plugins: [{ + cacheWillUpdate: async ({request, response}) => { + return response; + }, + cacheDidUpdate: async ({cacheName, request, oldResponse, newResponse}) => {}, + cachedResponseWillBeUsed: async ({cacheName, request, matchOptions, cachedResponse}) => { + return cachedResponse; + }, + requestWillFetch: async ({request}) => { + return request; + }, + fetchDidFail: async ({originalRequest, request, error}) => {}, + }], + }, + }]; + + const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); + validate(runtimeCachingOptions, convertedOptions); + }); + + it(`should strip comments on custom plugins`, function() { + const runtimeCachingOptions = [{ + urlPattern: /abc/, + handler: 'cacheFirst', + options: { + plugins: [{ + cacheWillUpdate: async ({request, response}) => { + // Commenting + return response; + }, + cachedResponseWillBeUsed: async ({cacheName, request, matchOptions, cachedResponse}) => { + /* Commenting */ + return cachedResponse; + }, + }], + }, + }]; + + const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); + expect(convertedOptions[0].includes('// Commenting')).to.false; + expect(convertedOptions[0].includes('/* Commenting */')).to.false; + }); }); From 35d5c7491bc0bd2f23e71e0600f14cc3c96b2a55 Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Tue, 7 Aug 2018 12:31:22 -0300 Subject: [PATCH 5/8] check if function content remains on custom plugin tests --- .../node/lib/runtime-caching-converter.js | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/test/workbox-build/node/lib/runtime-caching-converter.js b/test/workbox-build/node/lib/runtime-caching-converter.js index 164b4d435..f73b5cc87 100644 --- a/test/workbox-build/node/lib/runtime-caching-converter.js +++ b/test/workbox-build/node/lib/runtime-caching-converter.js @@ -235,24 +235,6 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function( urlPattern: /abc/, handler: 'cacheFirst', options: { - expiration: { - maxEntries: 10, - }, - cacheableResponse: { - statuses: [0, 200], - }, - broadcastUpdate: { - channelName: 'test', - options: { - source: 'test-source', - }, - }, - backgroundSync: { - name: 'test', - options: { - maxRetentionTime: 123, - }, - }, plugins: [{ cacheWillUpdate: async ({request, response}) => { return response; @@ -270,7 +252,11 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function( }]; const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); - validate(runtimeCachingOptions, convertedOptions); + expect(convertedOptions[0].includes('cacheWillUpdate: async')).to.true; + expect(convertedOptions[0].includes('cacheDidUpdate: async')).to.true; + expect(convertedOptions[0].includes('cachedResponseWillBeUsed: async')).to.true; + expect(convertedOptions[0].includes('requestWillFetch: async')).to.true; + expect(convertedOptions[0].includes('fetchDidFail: async')).to.true; }); it(`should strip comments on custom plugins`, function() { @@ -284,14 +270,14 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function( return response; }, cachedResponseWillBeUsed: async ({cacheName, request, matchOptions, cachedResponse}) => { - /* Commenting */ + /* Commenting */ return cachedResponse; }, }], }, }]; - const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); + const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); expect(convertedOptions[0].includes('// Commenting')).to.false; expect(convertedOptions[0].includes('/* Commenting */')).to.false; }); From 23d88222f4a38586d2d8ee04a100470d16cbcfec Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Wed, 8 Aug 2018 17:18:26 -0300 Subject: [PATCH 6/8] fix misshandled strings with // on runtime-caching-converter --- packages/workbox-build/package-lock.json | 36 +++++++++++++++++++ packages/workbox-build/package.json | 1 + .../src/lib/runtime-caching-converter.js | 7 ++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/workbox-build/package-lock.json b/packages/workbox-build/package-lock.json index 3a431a58b..8a0f1e793 100644 --- a/packages/workbox-build/package-lock.json +++ b/packages/workbox-build/package-lock.json @@ -4,6 +4,28 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "babel-extract-comments": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/babel-extract-comments/-/babel-extract-comments-1.0.0.tgz", + "integrity": "sha512-qWWzi4TlddohA91bFwgt6zO/J0X+io7Qp184Fw0m2JYRSTZnJbFR8+07KmzudHCZgOiKRCrjhylwv9Xd8gfhVQ==", + "requires": { + "babylon": "6.18.0" + } + }, + "babel-plugin-syntax-object-rest-spread": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", + "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=" + }, + "babel-plugin-transform-object-rest-spread": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz", + "integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=", + "requires": { + "babel-plugin-syntax-object-rest-spread": "6.13.0", + "babel-runtime": "6.26.0" + } + }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -13,6 +35,11 @@ "regenerator-runtime": "0.11.0" } }, + "babylon": { + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", + "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==" + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -206,6 +233,15 @@ "is-regexp": "1.0.0" } }, + "strip-comments": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/strip-comments/-/strip-comments-1.0.2.tgz", + "integrity": "sha512-kL97alc47hoyIQSV165tTt9rG5dn4w1dNnBhOQ3bOU1Nc1hel09jnXANaHJ7vzHLd4Ju8kseDGzlev96pghLFw==", + "requires": { + "babel-extract-comments": "1.0.0", + "babel-plugin-transform-object-rest-spread": "6.26.0" + } + }, "topo": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/topo/-/topo-2.0.2.tgz", diff --git a/packages/workbox-build/package.json b/packages/workbox-build/package.json index 956e67504..bc1bb094c 100644 --- a/packages/workbox-build/package.json +++ b/packages/workbox-build/package.json @@ -28,6 +28,7 @@ "lodash.template": "^4.4.0", "pretty-bytes": "^4.0.2", "stringify-object": "^3.2.2", + "strip-comments": "^1.0.2", "workbox-background-sync": "^3.4.1", "workbox-broadcast-cache-update": "^3.4.1", "workbox-cache-expiration": "^3.4.1", diff --git a/packages/workbox-build/src/lib/runtime-caching-converter.js b/packages/workbox-build/src/lib/runtime-caching-converter.js index 8f0582aac..bdf56adc2 100644 --- a/packages/workbox-build/src/lib/runtime-caching-converter.js +++ b/packages/workbox-build/src/lib/runtime-caching-converter.js @@ -16,6 +16,7 @@ const ol = require('common-tags').oneLine; const objectStringify = require('stringify-object'); +const stripComments = require('strip-comments'); const errors = require('./errors'); @@ -33,9 +34,9 @@ function getOptionsString(options = {}) { let plugins = []; if (options.plugins) { // Using libs because JSON.stringify won't handle functions - plugins = options.plugins.map((plugin) => objectStringify(plugin) - // See http://blog.moagrius.com/javascript/javascript-regexp-to-remove-comments/ - .replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm, '')); + plugins = options.plugins.map((plugin) => + objectStringify(plugin, {transform: (_obj, _prop, str) => + stripComments(str)})); delete options.plugins; } From e6d98ce87bec785aee7cfe2b403868de2270ede1 Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Wed, 8 Aug 2018 17:19:12 -0300 Subject: [PATCH 7/8] add test case to misshandled // on runtime-caching-converter --- .../node/lib/runtime-caching-converter.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/workbox-build/node/lib/runtime-caching-converter.js b/test/workbox-build/node/lib/runtime-caching-converter.js index f73b5cc87..0656127ba 100644 --- a/test/workbox-build/node/lib/runtime-caching-converter.js +++ b/test/workbox-build/node/lib/runtime-caching-converter.js @@ -281,4 +281,28 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function( expect(convertedOptions[0].includes('// Commenting')).to.false; expect(convertedOptions[0].includes('/* Commenting */')).to.false; }); + + it(`should keep contents with // that are not comments`, function() { + const runtimeCachingOptions = [{ + urlPattern: /abc/, + handler: 'cacheFirst', + options: { + plugins: [{ + cacheWillUpdate: async ({request, response}) => { + // Commenting + + if (request.url === 'https://test.com') { + return null; + } + + return response; + }, + }], + }, + }]; + + const convertedOptions = runtimeCachingConverter(runtimeCachingOptions); + expect(convertedOptions[0].includes('// Commenting')).to.false; + expect(convertedOptions[0].includes('https://test.com')).to.true; + }); }); From e3c49ad36c07451734b9955c009fad975759e1e6 Mon Sep 17 00:00:00 2001 From: tsirlucas Date: Wed, 8 Aug 2018 17:51:37 -0300 Subject: [PATCH 8/8] fix identation on runtime-caching-converter changes --- .../workbox-build/src/lib/runtime-caching-converter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/workbox-build/src/lib/runtime-caching-converter.js b/packages/workbox-build/src/lib/runtime-caching-converter.js index bdf56adc2..4dd06d325 100644 --- a/packages/workbox-build/src/lib/runtime-caching-converter.js +++ b/packages/workbox-build/src/lib/runtime-caching-converter.js @@ -35,8 +35,11 @@ function getOptionsString(options = {}) { if (options.plugins) { // Using libs because JSON.stringify won't handle functions plugins = options.plugins.map((plugin) => - objectStringify(plugin, {transform: (_obj, _prop, str) => - stripComments(str)})); + objectStringify(plugin, { + transform: (_obj, _prop, str) => stripComments(str), + }) + ); + delete options.plugins; }