From 386ee9fa7da40495fc415512ecac55425d549122 Mon Sep 17 00:00:00 2001 From: ahwayakchih Date: Sat, 30 Mar 2019 08:52:07 +0100 Subject: [PATCH 1/4] feat: use `manifest.minimum_chrome_version` as XML's `prodversionmin` Default to '29.0.0' for CRX2 and '70.0.0' for CRX3. --- src/crx.js | 6 +++++- .../{update.xml => updateCRX2.xml} | 2 +- test/expectations/updateCRX3.xml | 6 ++++++ test/expectations/updateProdVersionMin.xml | 6 ++++++ test/index.js | 20 ++++++++++++++++--- 5 files changed, 35 insertions(+), 5 deletions(-) rename test/expectations/{update.xml => updateCRX2.xml} (83%) create mode 100644 test/expectations/updateCRX3.xml create mode 100644 test/expectations/updateProdVersionMin.xml diff --git a/src/crx.js b/src/crx.js index 115065e..98d1cda 100644 --- a/src/crx.js +++ b/src/crx.js @@ -267,10 +267,14 @@ class ChromeExtension { throw new Error("No URL provided for update.xml."); } + var browserVersion = this.manifest.minimum_chrome_version + || (this.version < 3 && "29.0.0") // Earliest API available: https://developer.chrome.com/extensions/api_index + || "70.0.0"; // Around one year after Chromium started generating CRX3 packages + return Buffer.from(` - + `); } diff --git a/test/expectations/update.xml b/test/expectations/updateCRX2.xml similarity index 83% rename from test/expectations/update.xml rename to test/expectations/updateCRX2.xml index 729bd54..5d46b66 100644 --- a/test/expectations/update.xml +++ b/test/expectations/updateCRX2.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/test/expectations/updateCRX3.xml b/test/expectations/updateCRX3.xml new file mode 100644 index 0000000..0331430 --- /dev/null +++ b/test/expectations/updateCRX3.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/expectations/updateProdVersionMin.xml b/test/expectations/updateProdVersionMin.xml new file mode 100644 index 0000000..ee6f0c6 --- /dev/null +++ b/test/expectations/updateProdVersionMin.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/index.js b/test/index.js index 77f75b9..5db83ae 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,9 @@ var Zip = require("adm-zip"); var ChromeExtension = require("../"); var join = require("path").join; var privateKey = fs.readFileSync(join(__dirname, "key.pem")); -var updateXml = fs.readFileSync(join(__dirname, "expectations", "update.xml")); +var updateXml2 = fs.readFileSync(join(__dirname, "expectations", "updateCRX2.xml")); +var updateXml3 = fs.readFileSync(join(__dirname, "expectations", "updateCRX3.xml")); +var updateXmlCustom = fs.readFileSync(join(__dirname, "expectations", "updateProdVersionMin.xml")); function newCrx(opts){ return new ChromeExtension(Object.assign({ @@ -109,18 +111,30 @@ TESTS.loadContents = function(t, opts){ TESTS.generateUpdateXML = function(t, opts){ - t.plan(2); + t.plan(3); t.throws(() => new ChromeExtension({}).generateUpdateXML(), 'No URL provided for update.xml'); var crx = newCrx(opts); + var expected = crx.version === 2 ? updateXml2 : updateXml3; crx.pack().then(function(){ var xmlBuffer = crx.generateUpdateXML(); - t.equals(xmlBuffer.toString(), updateXml.toString()); + t.equals(xmlBuffer.toString(), expected.toString()); }) .catch(t.error.bind(t)); + + var crxCustom = newCrx(opts); + crxCustom.load().then(() => { + crxCustom.manifest.minimum_chrome_version = '99.99.99-crxtest'; + crxCustom.pack().then(function(){ + var xmlBuffer = crxCustom.generateUpdateXML(); + + t.equals(xmlBuffer.toString(), updateXmlCustom.toString()); + }) + .catch(t.error.bind(t)); + }); }; TESTS.generatePublicKey = function(t, opts) { From dfc3c683b46b3c066636344253a25313c9c4687a Mon Sep 17 00:00:00 2001 From: ahwayakchih Date: Sat, 30 Mar 2019 20:57:16 +0100 Subject: [PATCH 2/4] docs: explain choice of default `prodversionmin` values --- src/crx.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/crx.js b/src/crx.js index 98d1cda..89384a9 100644 --- a/src/crx.js +++ b/src/crx.js @@ -258,8 +258,18 @@ class ChromeExtension { /** * Generates an updateXML file from the extension content. * + * If manifest does not include `minimum_chrome_version`, defaults to: + * - '29.0.0' for CRX2, which is earliest extensions API available + * - '70.0.0' for CRX3, which is around one year after Chromium switched to generating CRX3 packages + * * BC BREAK `this.updateXML` is not stored anymore (since 1.0.0) * + * @see + * [Chrome Extensions APIs]{@link https://developer.chrome.com/extensions/api_index} + * @see + * [Chrome verions]{@link https://en.wikipedia.org/wiki/Google_Chrome_version_history} + * @see + * [Chromium switches to CRX3]{@link https://chromium.googlesource.com/chromium/src.git/+/b8bc9f99ef4ad6223dfdcafd924051561c05ac75} * @returns {Buffer} */ generateUpdateXML () { @@ -268,7 +278,7 @@ class ChromeExtension { } var browserVersion = this.manifest.minimum_chrome_version - || (this.version < 3 && "29.0.0") // Earliest API available: https://developer.chrome.com/extensions/api_index + || (this.version < 3 && "29.0.0") // Earliest version with extensions API || "70.0.0"; // Around one year after Chromium started generating CRX3 packages return Buffer.from(` From 636558ef853aed128de2134ca3f762da0fe8cd90 Mon Sep 17 00:00:00 2001 From: ahwayakchih Date: Sun, 31 Mar 2019 22:53:44 +0200 Subject: [PATCH 3/4] fix: switch default `prodversionmin` to 64.0.3242 That's the version at which Chrome switched to generating CRX3 packages, as found out with help of @arkon (https://github.com/oncletom/crx/pull/102#discussion_r270630820) --- src/crx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crx.js b/src/crx.js index 89384a9..4fdd98c 100644 --- a/src/crx.js +++ b/src/crx.js @@ -260,7 +260,7 @@ class ChromeExtension { * * If manifest does not include `minimum_chrome_version`, defaults to: * - '29.0.0' for CRX2, which is earliest extensions API available - * - '70.0.0' for CRX3, which is around one year after Chromium switched to generating CRX3 packages + * - '64.0.3242' for CRX3, which is when Chrome etension packager switched to CRX3 * * BC BREAK `this.updateXML` is not stored anymore (since 1.0.0) * @@ -279,7 +279,7 @@ class ChromeExtension { var browserVersion = this.manifest.minimum_chrome_version || (this.version < 3 && "29.0.0") // Earliest version with extensions API - || "70.0.0"; // Around one year after Chromium started generating CRX3 packages + || "64.0.3242"; // Chrome started generating CRX3 packages return Buffer.from(` From c9c79a28c04ddcd5ab0e91262e8b9d4463296221 Mon Sep 17 00:00:00 2001 From: ahwayakchih Date: Sun, 31 Mar 2019 22:55:36 +0200 Subject: [PATCH 4/4] test: fix CRX3 expectation --- test/expectations/updateCRX3.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/expectations/updateCRX3.xml b/test/expectations/updateCRX3.xml index 0331430..09ce532 100644 --- a/test/expectations/updateCRX3.xml +++ b/test/expectations/updateCRX3.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file