From 5207629e87465c582c003b7261431609a2daa31b Mon Sep 17 00:00:00 2001 From: Adam Mills Date: Tue, 14 Feb 2017 15:01:32 -0500 Subject: [PATCH] Add Object.assign polyfill support (#210) * Add Object.assign polyfill support * Remove redundant polyfill check * Use ES6 in compatibility.js --- package.json | 7 +++++-- rollup/compatibility.js | 8 ++++++++ script/gen-service-worker.js | 7 ++++++- script/optimize-js.js | 4 ++++ src/compatibility.js | 2 ++ yarn.lock | 4 ++++ 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 rollup/compatibility.js create mode 100644 src/compatibility.js diff --git a/package.json b/package.json index e8c088adb0..e397d942cb 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,13 @@ "frontend_html": "script/vulcanize.js", "frontend_prod": "npm run js_prod && npm run frontend_html", "frontend_demo": "npm run js_demo && npm run frontend_html", - "ru_all": "npm run ru_core && npm run ru_demo", + "ru_all": "npm run ru_core && npm run ru_compatibility && npm run ru_demo", "ru_core": "rollup --config rollup/core.js", + "ru_compatibility": "rollup --config rollup/compatibility.js", "ru_demo": "rollup --config rollup/demo.js", - "watch_ru_all": "npm run watch_ru_core && npm run watch_ru_demo", + "watch_ru_all": "(npm run watch_ru_core & npm run watch_ru_compatibility & npm run watch_ru_demo) && wait", "watch_ru_core": "rollup --config rollup/core.js --watch --sourcemap inline", + "watch_ru_compatibility": "rollup --config rollup/compatibility.js --watch --sourcemap inline", "watch_ru_demo": "rollup --config rollup/demo.js --watch --sourcemap inline", "lint_js": "eslint src panels --ext html", "lint_html": "ls -1 src/home-assistant.html panels/**/ha-panel-*.html | xargs polymer lint --input", @@ -32,6 +34,7 @@ }, "devDependencies": { "bower": "^1.8.0", + "es6-object-assign": "^1.0.3", "eslint": "^3.14.0", "eslint-config-airbnb-base": "^11.0.1", "eslint-plugin-html": "^1.7.0", diff --git a/rollup/compatibility.js b/rollup/compatibility.js new file mode 100644 index 0000000000..9b4e046c48 --- /dev/null +++ b/rollup/compatibility.js @@ -0,0 +1,8 @@ +import config from './base-config'; + +export default Object.assign({}, config, { + entry: 'src/compatibility.js', + targets: [ + { dest: 'build/compatibility.js', format: 'iife' }, + ], +}); diff --git a/script/gen-service-worker.js b/script/gen-service-worker.js index 9e939ace19..d2019314b5 100755 --- a/script/gen-service-worker.js +++ b/script/gen-service-worker.js @@ -21,13 +21,18 @@ var rootDir = '..'; var panelDir = rootDir + '/panels'; var dynamicUrlToDependencies = { - '/': [rootDir + '/frontend.html', rootDir + '/core.js'], + '/': [ + rootDir + '/frontend.html', + rootDir + '/core.js', + rootDir + '/compatibility.js', + ], }; var staticFingerprinted = [ 'frontend.html', 'mdi.html', 'core.js', + 'compatibility.js', ]; // These panels will always be registered inside HA and thus can diff --git a/script/optimize-js.js b/script/optimize-js.js index 36dc9d7df8..112af627e7 100755 --- a/script/optimize-js.js +++ b/script/optimize-js.js @@ -6,3 +6,7 @@ var optimizeJs = require('optimize-js'); var core = fs.readFileSync('build/core.js', 'utf-8'); core = optimizeJs(core); fs.writeFileSync('build/core.js', core); + +var compatibility = fs.readFileSync('build/compatibility.js', 'utf-8'); +compatibility = optimizeJs(compatibility); +fs.writeFileSync('build/compatibility.js', compatibility); diff --git a/src/compatibility.js b/src/compatibility.js new file mode 100644 index 0000000000..b005dc8355 --- /dev/null +++ b/src/compatibility.js @@ -0,0 +1,2 @@ +import objAssign from 'es6-object-assign'; +objAssign.polyfill(); diff --git a/yarn.lock b/yarn.lock index d356c05003..281ed52a75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1762,6 +1762,10 @@ es6-map@^0.1.3: es6-symbol "~3.1.0" event-emitter "~0.3.4" +es6-object-assign@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/es6-object-assign/-/es6-object-assign-1.0.3.tgz#40a192e0fda5ee44ee8cf6f5b5d9b47cd0f69b14" + es6-promise@^2.1.0: version "2.3.0" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-2.3.0.tgz#96edb9f2fdb01995822b263dd8aadab6748181bc"