From 1eac6e4f7800ba62498e62e59dde1edc120cbe08 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 8 Mar 2018 16:08:17 +0100 Subject: [PATCH 1/4] Create separate bundle for Firefox As noted in https://github.com/ipfs-shipyard/ipfs-companion/issues/398 Firefox supports additional WebExtension APIs, but Chrome throws an error on them. This change splits manifest into common and vendor-specific files and creates a dedicated bundle for each. --- .gitignore | 1 + .../{manifest.json => manifest.common.json} | 23 ----------------- add-on/manifest.firefox-beta.json | 8 ++++++ add-on/manifest.firefox.json | 25 +++++++++++++++++++ ci/Jenkinsfile | 2 +- ci/update-manifest.sh | 18 +------------ package.json | 6 ++++- yarn.lock | 4 +++ 8 files changed, 45 insertions(+), 42 deletions(-) rename add-on/{manifest.json => manifest.common.json} (74%) create mode 100644 add-on/manifest.firefox-beta.json create mode 100644 add-on/manifest.firefox.json diff --git a/.gitignore b/.gitignore index 737a73021..1e8aed7e8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ add-on/dist coverage .nyc_output add-on/ui-kit/**/* +add-on/manifest.json diff --git a/add-on/manifest.json b/add-on/manifest.common.json similarity index 74% rename from add-on/manifest.json rename to add-on/manifest.common.json index 2a6688c70..f063eef52 100644 --- a/add-on/manifest.json +++ b/add-on/manifest.common.json @@ -11,12 +11,6 @@ "38": "icons/png/ipfs-logo-on_38.png", "128": "icons/png/ipfs-logo-on_128.png" }, - "applications": { - "gecko": { - "id": "ipfs-firefox-addon@lidel.org", - "strict_min_version": "58.0" - } - }, "permissions": [ "", "idle", @@ -64,23 +58,6 @@ "run_at": "document_start" } ], - "protocol_handlers": [ - { - "protocol": "web+dweb", - "name": "IPFS Add-On: DWEB protocol handler", - "uriTemplate": "https://ipfs.io/%s" - }, - { - "protocol": "web+ipns", - "name": "IPFS Add-On: IPNS protocol handler", - "uriTemplate": "https://ipfs.io/%s" - }, - { - "protocol": "web+ipfs", - "name": "IPFS Add-On: IPFS protocol handler", - "uriTemplate": "https://ipfs.io/%s" - } - ], "content_security_policy": "script-src 'self'; object-src 'self'; frame-src 'self';", "default_locale": "en" } diff --git a/add-on/manifest.firefox-beta.json b/add-on/manifest.firefox-beta.json new file mode 100644 index 000000000..01d799d86 --- /dev/null +++ b/add-on/manifest.firefox-beta.json @@ -0,0 +1,8 @@ +{ + "applications": { + "gecko": { + "id": "ipfs-companion-dev-build@ci.ipfs.team", + "update_url": "https://ipfs-shipyard.github.io/ipfs-companion/ci/firefox/update.json" + } + } +} diff --git a/add-on/manifest.firefox.json b/add-on/manifest.firefox.json new file mode 100644 index 000000000..cada019a2 --- /dev/null +++ b/add-on/manifest.firefox.json @@ -0,0 +1,25 @@ +{ + "applications": { + "gecko": { + "id": "ipfs-firefox-addon@lidel.org", + "strict_min_version": "58.0" + } + }, + "protocol_handlers": [ + { + "protocol": "web+dweb", + "name": "IPFS Add-On: DWEB protocol handler", + "uriTemplate": "https://ipfs.io/%s" + }, + { + "protocol": "web+ipns", + "name": "IPFS Add-On: IPNS protocol handler", + "uriTemplate": "https://ipfs.io/%s" + }, + { + "protocol": "web+ipfs", + "name": "IPFS Add-On: IPFS protocol handler", + "uriTemplate": "https://ipfs.io/%s" + } + ] +} diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 0aaa91446..6c5f54178 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -19,7 +19,7 @@ node(label: 'linux') { stage('ci:build') { sh 'mkdir -p $(pwd)/build' sh 'docker run -i --rm -v $(pwd)/build:/usr/src/app/build:rw -v $(pwd)/add-on:/usr/src/app/add-on:rw ipfs-companion:$(cat git-HEAD) npm run ci:build' - archiveArtifacts artifacts: 'build/*.zip', fingerprint: true + archiveArtifacts artifacts: 'build/**/*.zip', fingerprint: true } stage('lint:web-ext') { sh 'docker run -i --rm -v $(pwd)/add-on:/usr/src/app/add-on:ro ipfs-companion:$(cat git-HEAD) npm run lint:web-ext' diff --git a/ci/update-manifest.sh b/ci/update-manifest.sh index 66bb9e8b5..a9182d773 100755 --- a/ci/update-manifest.sh +++ b/ci/update-manifest.sh @@ -3,7 +3,7 @@ # to explicitly state that produced artifact is a dev build. set -e -MANIFEST=add-on/manifest.json +MANIFEST=add-on/manifest.common.json # restore original (make this script immutable) git checkout $MANIFEST @@ -28,19 +28,3 @@ NEW_COMMITS_IN_CURRENT_BRANCH=$(git rev-list --count HEAD ^refs/remotes/origin/m BUILD_VERSION=$(($COMMITS_IN_MASTER*10+$NEW_COMMITS_IN_CURRENT_BRANCH)) set-manifest ".version = (.version + \".${BUILD_VERSION}\")" grep \"version\" $MANIFEST - -# addon-linter throws error on 'update_url' so it is disabled in dev build -# and needs to be manually opted-in when beta build is run -if [ "$1" == "firefox-beta" ]; then - # Switch to self-hosted dev-build for Firefox (https://github.com/ipfs-shipyard/ipfs-companion/issues/385) - DEV_BUILD_ADDON_ID="ipfs-companion-dev-build@ci.ipfs.team" - UPDATE_URL="https://ipfs-shipyard.github.io/ipfs-companion/ci/firefox/update.json" - - ## Set ADD-ON ID - set-manifest ".applications.gecko[\"id\"] = \"$DEV_BUILD_ADDON_ID\"" - grep ipfs-companion-dev-build $MANIFEST - - ## Add UPDATE_URL - set-manifest ".applications.gecko[\"update_url\"] = \"$UPDATE_URL\"" - grep update_url $MANIFEST -fi diff --git a/package.json b/package.json index 868d63139..9840d36ac 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,10 @@ "build:content-scripts:ipfs-proxy:content": "browserify -p prundupify -g uglifyify -t brfs -t [ browserify-package-json --global ] -s IpfsProxyContent add-on/src/contentScripts/ipfs-proxy/content.js -o add-on/dist/contentScripts/ipfs-proxy/content.js", "build:content-scripts:ipfs-proxy:cleanup": "shx rm add-on/dist/contentScripts/ipfs-proxy/page.js", "build:minimize-dist": "shx rm -rf add-on/dist/lib", - "build:bundle-extension": "web-ext build -s add-on/ -i src/ -a build/", + "build:bundle-all": "run-s bundle:generic bundle:firefox", + "bundle:generic": "shx cp add-on/manifest.common.json add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/generic -o", + "bundle:firefox": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json | json --deep-merge > add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/firefox/ -o", + "bundle:firefox:beta": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/firefox/beta/ -o", "watch": "npm-run-all build:copy --parallel watch:*", "watch:js": "watchify -p prundupify -t [ browserify-package-json --global ] add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js add-on/src/pages/proxy-acl/index.js add-on/src/pages/proxy-access-dialog/index.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js -o add-on/dist/pages/proxy-acl/proxy-acl.js -o add-on/dist/pages/proxy-access-dialog/proxy-access-dialog.js ] -o add-on/dist/ipfs-companion-common.js -v", "watch:content-scripts": "run-p watch:content-scripts:*", @@ -64,6 +67,7 @@ "geckodriver": "1.10.0", "husky": "0.14.3", "ignore-styles": "5.0.1", + "json": "9.0.6", "mem-storage-area": "1.0.3", "mocha": "5.0.1", "mocha-jenkins-reporter": "0.3.10", diff --git a/yarn.lock b/yarn.lock index 4575c95c8..3765c5ab6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4907,6 +4907,10 @@ json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" +json@9.0.6: + version "9.0.6" + resolved "https://registry.yarnpkg.com/json/-/json-9.0.6.tgz#7972c2a5a48a42678db2730c7c2c4ee6e4e24585" + jsonfile@^2.1.0: version "2.4.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" From 887e1d036cba1daf2cf119ff35ee6409719ad74d Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 8 Mar 2018 16:21:32 +0100 Subject: [PATCH 2/4] docs/developer-notes: add info about bundles --- docs/developer-notes.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/developer-notes.md b/docs/developer-notes.md index 28fbd8e64..1e4c11251 100644 --- a/docs/developer-notes.md +++ b/docs/developer-notes.md @@ -35,7 +35,7 @@ npm start # all-in-one To do each step manually: ```bash -npm run build # build +npm run build # build runs bundle:firefox at the end, so manifest will be ok npm run test # test suite npm run firefox # spawn new Firefox ``` @@ -48,7 +48,7 @@ then click "Load Temporary Add-on" and point it at `add-on/manifest.json` First, build it manually: ```bash -npm run build +npm run build bundle:generic # last part is important: it overwrites manifest ``` Then open up `chrome://extensions` in Chromium-based browser, enable "Developer mode", click "Load unpacked extension..." and point it at `add-on/manifest.json` @@ -63,7 +63,9 @@ See [`docs/firefox-for-android.md`](firefox-for-android.md) Each `npm` task can be run separately. The most useful ones are: - `npm install` -- install all NPM dependencies -- `npm run build` -- build the add-on (copy external libraries, create `.zip` bundle) +- `npm run build` -- build the add-on (copy external libraries, create `.zip` bundles for Chrome and Firefox) +- `npm run bundle:generic` -- overwrites manifest and packages a Brave/Chrome-compatible version +- `npm run bundle:firefox` -- overwrites manifest and packages a Firefox-compatible version - `npm run yarn-build` -- fast dependency install + build with yarn (installs and updates yarn.lock if needed) - `npm run ci` -- reproducible test and build (with frozen yarn.lock) - `npm test` -- run entire test suite From 324083febc3e8a6f6d35f8cae478bd3842c5df10 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 8 Mar 2018 16:33:13 +0100 Subject: [PATCH 3/4] Move custom keys to add-on/manifest.firefox.json Fixes warnings about unknown keys under Chrome --- add-on/manifest.common.json | 2 -- add-on/manifest.firefox.json | 6 ++++++ package.json | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/add-on/manifest.common.json b/add-on/manifest.common.json index f063eef52..77bcee148 100644 --- a/add-on/manifest.common.json +++ b/add-on/manifest.common.json @@ -29,7 +29,6 @@ "page": "dist/background/background.html" }, "browser_action": { - "browser_style": false, "default_icon": { "19": "icons/png/ipfs-logo-off_19.png", "38": "icons/png/ipfs-logo-off_38.png", @@ -39,7 +38,6 @@ "default_popup": "dist/popup/browser-action/index.html" }, "options_ui": { - "browser_style": false, "page": "dist/options/options.html" }, "web_accessible_resources": [ diff --git a/add-on/manifest.firefox.json b/add-on/manifest.firefox.json index cada019a2..f8322f0f2 100644 --- a/add-on/manifest.firefox.json +++ b/add-on/manifest.firefox.json @@ -1,4 +1,10 @@ { + "browser_action": { + "browser_style": false + }, + "options_ui": { + "browser_style": false + }, "applications": { "gecko": { "id": "ipfs-firefox-addon@lidel.org", diff --git a/package.json b/package.json index 9840d36ac..ef454e2a1 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "build:content-scripts:ipfs-proxy:cleanup": "shx rm add-on/dist/contentScripts/ipfs-proxy/page.js", "build:minimize-dist": "shx rm -rf add-on/dist/lib", "build:bundle-all": "run-s bundle:generic bundle:firefox", + "bundle": "run-s bundle:*", "bundle:generic": "shx cp add-on/manifest.common.json add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/generic -o", "bundle:firefox": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json | json --deep-merge > add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/firefox/ -o", "bundle:firefox:beta": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/firefox/beta/ -o", From 623786a83fb6c6a19396bf3647ccaf6eaa2da95b Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 8 Mar 2018 17:47:54 +0100 Subject: [PATCH 4/4] Move web-ext parameters to web-ext-config.js --- package.json | 10 +++++----- web-ext-config.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 web-ext-config.js diff --git a/package.json b/package.json index ef454e2a1..bc47867f7 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "build:minimize-dist": "shx rm -rf add-on/dist/lib", "build:bundle-all": "run-s bundle:generic bundle:firefox", "bundle": "run-s bundle:*", - "bundle:generic": "shx cp add-on/manifest.common.json add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/generic -o", - "bundle:firefox": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json | json --deep-merge > add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/firefox/ -o", - "bundle:firefox:beta": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext build -s add-on/ -i src/ -a build/firefox/beta/ -o", + "bundle:generic": "shx cp add-on/manifest.common.json add-on/manifest.json && web-ext build -a build/generic", + "bundle:firefox": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json | json --deep-merge > add-on/manifest.json && web-ext build -a build/firefox/", + "bundle:firefox:beta": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext build -a build/firefox/beta/", "watch": "npm-run-all build:copy --parallel watch:*", "watch:js": "watchify -p prundupify -t [ browserify-package-json --global ] add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js add-on/src/pages/proxy-acl/index.js add-on/src/pages/proxy-access-dialog/index.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js -o add-on/dist/pages/proxy-acl/proxy-acl.js -o add-on/dist/pages/proxy-access-dialog/proxy-access-dialog.js ] -o add-on/dist/ipfs-companion-common.js -v", "watch:content-scripts": "run-p watch:content-scripts:*", @@ -42,12 +42,12 @@ "test:functional": " nyc --reporter=lcov --reporter=text mocha --timeout 15000 --require ignore-styles --reporter mocha-jenkins-reporter 'test/functional/**/*.test.js'", "lint": "run-s lint:*", "lint:standard": "standard -v \"add-on/src/**/*.js\" \"test/**/*.js\"", - "lint:web-ext": "web-ext lint -s add-on/ -i src/", + "lint:web-ext": "web-ext lint", "fix:lint": "run-s fix:lint:*", "fix:lint:standard": "standard -v --fix \"add-on/src/**/*.js\" \"test/**/*.js\"", "precommit": "run-s lint:standard", "prepush": "run-s clean build lint test", - "firefox": "web-ext run -s add-on/ --browser-console", + "firefox": "web-ext run --browser-console", "ci": "run-s ci:*", "ci:install": "npx yarn@1.3.2 install --frozen-lockfile || npx yarn@1.3.2 install --frozen-lockfile", "ci:test": "npx yarn@1.3.2 test", diff --git a/web-ext-config.js b/web-ext-config.js new file mode 100644 index 000000000..3aa6e206e --- /dev/null +++ b/web-ext-config.js @@ -0,0 +1,15 @@ +// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext +module.exports = { + // Global options: + verbose: false, + artifactsDir: 'build/', + sourceDir: 'add-on/', + ignoreFiles: [ + 'src/', + 'manifest.*.json', + ], + // Command options: + build: { + overwriteDest: true, + } +}