From f792ac32f1994b7bdad8d93b95f6252a17b8f39d Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 22 Sep 2017 09:58:01 +0200 Subject: [PATCH 1/8] little refactoring the steal-tools plugins and adding tests --- lib/build/multi.js | 33 ++++++++++++++++++-------- package.json | 9 ++++---- test/bundle_assets_test.js | 39 +++++++++++++++++++++++++++++++ test/serviceworker/index.js | 1 + test/serviceworker/package.json | 7 ++++++ test/serviceworker_test.js | 41 +++++++++++++++++++++++++++++++++ test/test.js | 4 ++++ 7 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 test/bundle_assets_test.js create mode 100644 test/serviceworker/index.js create mode 100644 test/serviceworker/package.json create mode 100644 test/serviceworker_test.js diff --git a/lib/build/multi.js b/lib/build/multi.js index 40d5c7c0..f2a82a5b 100644 --- a/lib/build/multi.js +++ b/lib/build/multi.js @@ -109,21 +109,34 @@ module.exports = function(config, options){ } ); - writeStream.on("data", function(data){ + writeStream.on("data", function(builtResult){ this.end(); - // If bundleAssets is truthy run the bundler after the build. - if(options && options.bundleAssets) { - require("steal-bundler")(data, options.bundleAssets) - .then(function(){ - resolve(data); - }, function(err){ - reject(err); + // run external steal-tool plugins after the build + if(options){ + + var p = Promise.resolve(builtResult); + + if(options.bundleAssets){ + var bundleAssets = require("steal-bundler"); + p = p.then(function(builtResult) { + return bundleAssets(builtResult, options.bundleAssets) + }); + } + + if(options.serviceWorker){ + var precache = require("steal-serviceworker"); + p = p.then(function (builtResult) { + return precache(builtResult, options.serviceWorker) }); - return; + } } - resolve(data); + p.then(function (builtResult) { + resolve(builtResult); + }).catch(function (error) { + reject(error); + }); }); }); } diff --git a/package.json b/package.json index d3322de7..af2d393b 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,12 @@ "multimatch": "^2.1.0", "normalize-path": "^2.1.1", "pdenodeify": "^0.1.0", - "prettier": "^1.3.1", + "prettier": "^1.6.1", "pump": "^1.0.2", - "steal": "^1.5.8", + "steal": "^1.5.10", "steal-bundler": "^0.3.0", "steal-parse-amd": "^1.0.0", + "steal-serviceworker": "0.0.3", "through2": "^2.0.0", "tmp": "0.0.33", "traceur": "0.0.111", @@ -44,7 +45,7 @@ "babel-preset-steal-test": "0.0.1", "bower": "1.8.0", "browserify": "~14.3.0", - "comparify": "git://github.com/bitovi/comparify#master", + "comparify": "git://github.com/bitovi/comparify.git#master", "connect": "^3.5.0", "coveralls-send": "0.0.2", "cssify": "^1.0.3", @@ -88,7 +89,7 @@ "coverage": "istanbul cover _mocha -- test/test --timeout 600000", "coverage:upload": "istanbul cover _mocha --report lcovonly -- test/test --timeout 600000 && cat ./coverage/lcov.info | ./node_modules/coveralls-send/bin/coveralls.js", "test:slim-worker-single": "node test/slim/worker/single/build.js && testee test/slim/worker/single/worker.html --browsers firefox --reporter Spec", - "test:slim-worker-progressive": "node test/slim/worker/progressive/build.js && testee test/slim/worker/progressive/worker.html --browsers firefox --reporter Spec", + "test:slim-worker-progressive": "node test/slim/worker/progressive/build.js && testee test/slim/worker/progressive/worker.html --browsers firefox --reporter Spec", "test:exports-worker": "node test/exports_worker/exports.js && testee test/exports_worker/worker.html --browsers firefox --reporter Spec" }, "engines": { diff --git a/test/bundle_assets_test.js b/test/bundle_assets_test.js new file mode 100644 index 00000000..f9f42ba2 --- /dev/null +++ b/test/bundle_assets_test.js @@ -0,0 +1,39 @@ +var asap = require("pdenodeify"), + assert = require("assert"), + comparify = require("comparify"), + fs = require("fs-extra"), + multiBuild = require("../lib/build/multi"), + rmdir = require("rimraf"), + path = require("path"), + stealTools = require("../index"), + testHelpers = require("./helpers"); + +var find = testHelpers.find; +var open = testHelpers.open; + +describe("bundleAssets", function(){ + this.timeout(5000); + + before(function(done){ + asap(rmdir)(__dirname + "/bundle_assets/dist") + .then(function(){ + done(); + }); + }); + + it("works", function(done){ + multiBuild({ + config: __dirname + "/bundle_assets/package.json!npm" + }, { + quiet: true, + bundleAssets: true + }).then(function(){ + open("test/bundle_assets/prod.html", function(browser, close){ + find(browser, "MODULE", function(module){ + assert(true, "page loaded correctly"); + close(); + }, close); + }, done); + }); + }); +}); \ No newline at end of file diff --git a/test/serviceworker/index.js b/test/serviceworker/index.js new file mode 100644 index 00000000..02525d0f --- /dev/null +++ b/test/serviceworker/index.js @@ -0,0 +1 @@ +console.log("test"); \ No newline at end of file diff --git a/test/serviceworker/package.json b/test/serviceworker/package.json new file mode 100644 index 00000000..f8bee517 --- /dev/null +++ b/test/serviceworker/package.json @@ -0,0 +1,7 @@ +{ + "name": "serviceworker", + "version": "0.0.1", + "dependencies": { + + } +} \ No newline at end of file diff --git a/test/serviceworker_test.js b/test/serviceworker_test.js new file mode 100644 index 00000000..dffa3fb5 --- /dev/null +++ b/test/serviceworker_test.js @@ -0,0 +1,41 @@ +var asap = require("pdenodeify"), + assert = require("assert"), + comparify = require("comparify"), + fs = require("fs-extra"), + multiBuild = require("../lib/build/multi"), + rmdir = require("rimraf"), + path = require("path"), + stealTools = require("../index"), + testHelpers = require("./helpers"); + +var precache = require("steal-serviceworker"); + +var find = testHelpers.find; +var open = testHelpers.open; + +describe("serviceworker", function () { + this.timeout(5000); + + before(function (done) { + asap(rmdir)(__dirname + "/serviceworker/dist") + .then(function () { + fs.unlink(path.join(__dirname, "serviceworker", "service-worker.js"), function () { + done(); + }); + }); + }); + + it("works", function (done) { + multiBuild({ + config: __dirname + "/serviceworker/package.json!npm" + }, { + quiet: false, + serviceWorker: true, + bundleAssets: true + }).then(function (builtResult) { + + assert.ok(fs.existsSync(path.join(__dirname, "serviceworker", "service-worker.js"))); + done(); + }).catch(done); + }); +}); \ No newline at end of file diff --git a/test/test.js b/test/test.js index 87905ea1..f604bb8f 100644 --- a/test/test.js +++ b/test/test.js @@ -48,3 +48,7 @@ require("./babel_presets_test"); require("./babel_plugins_test"); require("./slim_build_test"); require("./slim_loader_size_test"); + +// external steal-tools plugins +require("./bundle_assets_test"); +require("./serviceworker_test"); \ No newline at end of file From c7e36c6aaef72ae95f2b02443a84db6680a223c0 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 22 Sep 2017 12:22:22 +0200 Subject: [PATCH 2/8] add bundle_asset test again into steal-tools. add a bundle asset test for slim loader. --- lib/build/multi.js | 2 +- lib/build/slim.js | 30 ++- test/bundle_assets/assets/some.json | 1 + test/bundle_assets/main.css | 3 + test/bundle_assets/main.js | 11 + test/bundle_assets/prod-slim.html | 10 + test/bundle_assets/prod.html | 10 + test/bundle_assets/steal-css-slim.js | 70 +++++++ test/bundle_assets/stealconfig.js | 8 + test/bundle_assets_test.js | 54 ++++- test/steal-css.js | 293 +++++++++++++++++++++++++-- 11 files changed, 462 insertions(+), 30 deletions(-) create mode 100644 test/bundle_assets/assets/some.json create mode 100644 test/bundle_assets/main.css create mode 100644 test/bundle_assets/main.js create mode 100644 test/bundle_assets/prod-slim.html create mode 100644 test/bundle_assets/prod.html create mode 100644 test/bundle_assets/steal-css-slim.js create mode 100644 test/bundle_assets/stealconfig.js diff --git a/lib/build/multi.js b/lib/build/multi.js index f2a82a5b..0d5d15e0 100644 --- a/lib/build/multi.js +++ b/lib/build/multi.js @@ -110,7 +110,7 @@ module.exports = function(config, options){ ); writeStream.on("data", function(builtResult){ - this.end(); + //this.end(); // run external steal-tool plugins after the build if(options){ diff --git a/lib/build/slim.js b/lib/build/slim.js index 45acbb76..2e5c20fd 100644 --- a/lib/build/slim.js +++ b/lib/build/slim.js @@ -87,7 +87,35 @@ module.exports = function(config, options) { } ); - final.on("data", dfd.resolve); + final.on("data", function (builtResult) { + //this.end(); + + // run external steal-tool plugins after the build + if (options) { + + var p = Promise.resolve(builtResult); + + if (options.bundleAssets) { + var bundleAssets = require("steal-bundler"); + p = p.then(function (builtResult) { + return bundleAssets(builtResult, options.bundleAssets) + }); + } + + if (options.serviceWorker) { + var precache = require("steal-serviceworker"); + p = p.then(function (builtResult) { + return precache(builtResult, options.serviceWorker) + }); + } + } + + p.then(function (builtResult) { + dfd.resolve(builtResult); + }).catch(function (error) { + dfd.reject(error) + }); + }); return dfd.promise; }); diff --git a/test/bundle_assets/assets/some.json b/test/bundle_assets/assets/some.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/test/bundle_assets/assets/some.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/bundle_assets/main.css b/test/bundle_assets/main.css new file mode 100644 index 00000000..9dee05f9 --- /dev/null +++ b/test/bundle_assets/main.css @@ -0,0 +1,3 @@ +body { + background-image: url(./images/logo.png); +} \ No newline at end of file diff --git a/test/bundle_assets/main.js b/test/bundle_assets/main.js new file mode 100644 index 00000000..66eee2d5 --- /dev/null +++ b/test/bundle_assets/main.js @@ -0,0 +1,11 @@ +require("./main.css"); + +var xhr = new XMLHttpRequest(); + +xhr.open("GET", "dist/images/logo.png"); + +xhr.onload = function(){ + window.MODULE = {}; +}; + +xhr.send(); \ No newline at end of file diff --git a/test/bundle_assets/prod-slim.html b/test/bundle_assets/prod-slim.html new file mode 100644 index 00000000..e8737566 --- /dev/null +++ b/test/bundle_assets/prod-slim.html @@ -0,0 +1,10 @@ + + + + + Test + + + + + \ No newline at end of file diff --git a/test/bundle_assets/prod.html b/test/bundle_assets/prod.html new file mode 100644 index 00000000..a26d68b7 --- /dev/null +++ b/test/bundle_assets/prod.html @@ -0,0 +1,10 @@ + + + + + Test + + + + + \ No newline at end of file diff --git a/test/bundle_assets/steal-css-slim.js b/test/bundle_assets/steal-css-slim.js new file mode 100644 index 00000000..66e3a98c --- /dev/null +++ b/test/bundle_assets/steal-css-slim.js @@ -0,0 +1,70 @@ +/* naive version of the css plugin for the slim loader */ +module.exports = function(moduleId, config) { + return new CssModule(config.paths[config.bundles[moduleId]]).injectLink(); +}; + +function CssModule(address) { + this.address = address; +} + +// timeout in seconds +CssModule.waitTimeout = 60; + +CssModule.prototype.linkExists = function() { + var styleSheets = document.styleSheets; + var anchor = document.createElement("a"); + anchor.href = this.address; + var href = anchor.href; + + for (var i = 0; i < styleSheets.length; ++i) { + if (href === styleSheets[i].href) { + return true; + } + } + + return false; +}; + +CssModule.prototype.injectLink = function() { + if (this._loadPromise) { + return this._loadPromise; + } + + if (this.linkExists()) { + this._loadPromise = Promise.resolve(""); + return this._loadPromise; + } + + // inspired by https://github.com/filamentgroup/loadCSS + var link = (this.link = document.createElement("link")); + link.type = "text/css"; + link.rel = "stylesheet"; + link.href = this.address; + + // wait until the css file is loaded + this._loadPromise = new Promise(function(resolve, reject) { + var timeout = setTimeout(function() { + reject("Unable to load CSS"); + }, CssModule.waitTimeout * 1000); + + var linkEventCallback = function(event) { + clearTimeout(timeout); + + link.removeEventListener("load", linkEventCallback); + link.removeEventListener("error", linkEventCallback); + + if (event && event.type === "error") { + reject("Unable to load CSS"); + } else { + resolve(""); + } + }; + + link.addEventListener("load", linkEventCallback); + link.addEventListener("error", linkEventCallback); + + document.head.appendChild(link); + }); + + return this._loadPromise; +}; \ No newline at end of file diff --git a/test/bundle_assets/stealconfig.js b/test/bundle_assets/stealconfig.js new file mode 100644 index 00000000..d4297edc --- /dev/null +++ b/test/bundle_assets/stealconfig.js @@ -0,0 +1,8 @@ +steal.config({ + ext: { + "css": "steal-css" + }, + paths: { + "steal-css": "../steal-css.js" + } +}); diff --git a/test/bundle_assets_test.js b/test/bundle_assets_test.js index f9f42ba2..831ba357 100644 --- a/test/bundle_assets_test.js +++ b/test/bundle_assets_test.js @@ -2,17 +2,17 @@ var asap = require("pdenodeify"), assert = require("assert"), comparify = require("comparify"), fs = require("fs-extra"), - multiBuild = require("../lib/build/multi"), + multiBuild = require("../index").build, + optimize = require("../index").optimize, rmdir = require("rimraf"), path = require("path"), - stealTools = require("../index"), testHelpers = require("./helpers"); var find = testHelpers.find; var open = testHelpers.open; describe("bundleAssets", function(){ - this.timeout(5000); + this.timeout(50000); before(function(done){ asap(rmdir)(__dirname + "/bundle_assets/dist") @@ -21,19 +21,61 @@ describe("bundleAssets", function(){ }); }); - it("works", function(done){ + it("works with steal-tools build", function(done){ multiBuild({ - config: __dirname + "/bundle_assets/package.json!npm" + main: "main", + config: path.join(__dirname, "bundle_assets", "stealconfig.js") }, { quiet: true, - bundleAssets: true + minify: false, + bundleAssets: { + infer: true, + glob: [ + path.join(__dirname, "bundle_assets", "assets", "*") + ] + } }).then(function(){ open("test/bundle_assets/prod.html", function(browser, close){ find(browser, "MODULE", function(module){ + const logo = path.join(__dirname, "bundle_assets", "dist", "images", "logo.png"); + assert(fs.pathExistsSync(logo), "image was copied"); + + const json = path.join(__dirname, "bundle_assets", "dist", "assets", "some.json"); + assert(fs.pathExistsSync(json), "asset was copied"); + assert(true, "page loaded correctly"); close(); }, close); }, done); }); }); + + it("works with steal-tools optimize", function (done) { + optimize({ + main: "main", + config: path.join(__dirname, "bundle_assets", "stealconfig.js") + }, { + quiet: true, + minify: false, + bundleAssets: { + infer: true, + glob: [ + path.join(__dirname, "bundle_assets", "assets", "*") + ] + } + }).then(function() { + open("test/bundle_assets/prod-slim.html", function(browser, close){ + find(browser, "MODULE", function(module){ + const logo = path.join(__dirname, "bundle_assets", "dist", "images", "logo.png"); + assert(fs.pathExistsSync(logo), "image was copied"); + + const json = path.join(__dirname, "bundle_assets", "dist", "assets", "some.json"); + assert(fs.pathExistsSync(json), "asset was copied"); + + assert(true, "page loaded correctly"); + close(); + }, close); + }, done); + }); + }) }); \ No newline at end of file diff --git a/test/steal-css.js b/test/steal-css.js index 8e473462..2fbde110 100644 --- a/test/steal-css.js +++ b/test/steal-css.js @@ -1,35 +1,284 @@ -var steal = require("@steal"); var loader = require("@loader"); +var steal = require("@steal"); + +var isNode = typeof process === "object" && {}.toString.call(process) === + "[object process]"; +var importRegEx = /@import [^uU]['"]?([^'"\)]*)['"]?/g; +var resourceRegEx = /url\(['"]?([^'"\)]*)['"]?\)/g; + +var waitSeconds = (loader.cssOptions && loader.cssOptions.timeout) + ? parseInt(loader.cssOptions.timeout, 10) : 60; +var onloadCss = function(link, cb){ + var styleSheets = getDocument().styleSheets, + i = styleSheets.length; + while( i-- ){ + if( styleSheets[ i ].href === link.href ){ + return cb(); + } + } + setTimeout(function() { + onloadCss(link, cb); + }); +}; + +function isIE9() { + var doc = getDocument(); -function CSSModule(address, source) { - this.address = address; - this.source = source; + // https://github.com/conditionizr/conditionizr/blob/111964e63ddda5f2db5dbc3c1587dfda9f5ca3b2/detects/ie9.js#L6 + return doc && + !!(Function('/*@cc_on return (/^9/.test(@_jscript_version) && /MSIE 9\.0(?!.*IEMobile)/i.test(navigator.userAgent)); @*/')()); } -CSSModule.prototype.injectStyle = function() { - var head = document.head; - var style = document.createElement("style"); +function getDocument() { + if(typeof doneSsr !== "undefined" && doneSsr.globalDocument) { + return doneSsr.globalDocument; + } - style.type = "text/css"; - style.styleSheet.cssText = this.source; + if(typeof document !== "undefined") { + return document; + } - head.appendChild(style); -}; + throw new Error("Unable to load CSS in an environment without a document."); +} + +function getHead() { + var doc = getDocument(); + var head = doc.head || doc.getElementsByTagName("head")[0]; + + if(!head) { + var docEl = doc.documentElement || doc; + head = doc.createElement("head"); + docEl.insertBefore(head, docEl.firstChild); + } + return head; +} + +/** + * + */ +function CSSModule(load, loader) { + if(typeof load === "object") { + this.load = load; + this.loader = loader; + this.address = this.load.address; + this.source = this.load.source; + } else { + this.address = load; // this is a string + this.source = loader; // this is a string + } +} + +// required for IE9 stylesheet limit hack +CSSModule.cssCount = 0; +CSSModule.ie9MaxStyleSheets = 31; +CSSModule.currentStyleSheet = null; + +CSSModule.prototype = { + injectLink: function(){ + if(this._loaded) { + return this._loaded; + } + + if(this.linkExists()) { + this._loaded = Promise.resolve(''); + return this._loaded; + } + + // inspired by https://github.com/filamentgroup/loadCSS + var doc = getDocument(); + + var link = this.link = doc.createElement("link"); + link.type = "text/css"; + link.rel = "stylesheet"; + link.href = this.address; + + // wait until the css file is loaded + this._loaded = new Promise(function(resolve, reject) { + var timeout = setTimeout(function() { + reject('Unable to load CSS'); + }, waitSeconds * 1000); + + var loadCB = function(event) { + clearTimeout(timeout); + link.removeEventListener("load", loadCB); + link.removeEventListener("error", loadCB); + + if(event && event.type === "error"){ + reject('Unable to load CSS'); + } else { + resolve(''); + } + }; + + // This code is for browsers that don’t support onload + // No support for onload (it'll bind but never fire): + // * Android 4.3 (Samsung Galaxy S4, Browserstack) + // * Android 4.2 Browser (Samsung Galaxy SIII Mini GT-I8200L) + // * Android 2.3 (Pantech Burst P9070) + // * Zombie headless browser + // Weak inference targets Android < 4.4 and + // a fallback for IE 8 and beneath + if("isApplicationInstalled" in navigator || !link.addEventListener) { + // fallback, polling styleSheets + onloadCss(link, loadCB); + } else if(navigator.noUI){ + // Zombie + loadCB(); + } else { + // attach onload event for all modern browser + link.addEventListener( "load", loadCB ); + link.addEventListener( "error", loadCB ); + } + + getHead().appendChild(link); + }); -exports.instantiate = function(load) { - var loader = this; - var css = new CSSModule(load.address, load.source); + return this._loaded; + }, - load.metadata.deps = []; - load.metadata.format = "css"; - load.metadata.execute = function() { - css.injectStyle(); + injectStyle: function(){ + var doc = getDocument(); + var head = getHead(); + var style = this.style = doc.createElement('style'); - return loader.newModule({ - source: css.source - }); - }; + // make source load relative to the current page + style.type = 'text/css'; + + // Starting with IE11, `styleSheet` isn't support but `sheet` is + // https://msdn.microsoft.com/en-us/library/dd347030(v=vs.85).aspx + if (style.sheet) { + style.sheet.cssText = this.source; + } else if (style.styleSheet) { + style.styleSheet.cssText = this.source; + } else { + style.appendChild(doc.createTextNode(this.source)); + } + + head.appendChild(style); + }, + + /** + * Inject stylesheets and re-used them to avoid IE9 limit + * https://blogs.msdn.microsoft.com/ieinternals/2011/05/14/stylesheet-limits-in-internet-explorer/ + */ + ie9StyleSheetLimitHack: function() { + var doc = getDocument(); + + // create the sheet to be re-used until limit is reached + if (!CSSModule.cssCount) { + CSSModule.currentStyleSheet = doc.createStyleSheet(); + } + + CSSModule.cssCount += 1; + CSSModule.currentStyleSheet.cssText += this.source; + + // reset the count to force the creation of a new stylesheet + if (CSSModule.cssCount === CSSModule.ie9MaxStyleSheets) { + CSSModule.cssCount = 0; + } + }, + + // Replace @import's that don't start with a "u" or "U" and do start + // with a single or double quote with a path wrapped in "url()" + // relative to the page + updateURLs: function(){ + var rawSource = this.source, + address = this.address; + + this.source = rawSource.replace(importRegEx, function(whole, part){ + if(isNode) { + return "@import url(" + part + ")"; + }else{ + return "@import url(" + steal.joinURIs(address, part) + ")"; + } + }); + + if(!loader.isEnv('build')) { + this.source = this.source + "/*# sourceURL=" + address + " */"; + this.source = this.source.replace(resourceRegEx, function(whole, part){ + return "url(" + steal.joinURIs(address, part) + ")"; + }); + + } + return this.source; + }, + + getExistingNode: function(){ + var doc = getDocument(); + var selector = "[href='" + this.address + "']"; + return doc.querySelector && doc.querySelector(selector); + }, + + linkExists: function(){ + var styleSheets = getDocument().styleSheets; + for (var i = 0; i < styleSheets.length; ++i) { + if(this.address === styleSheets[i].href){ + return true; + } + } + return false; + }, + + setupLiveReload: function(loader, name){ + var head = getHead(); + var css = this; + + if(loader.liveReloadInstalled) { + var cssReload = loader["import"]("live-reload", { + name: module.id + }); + + Promise.resolve(cssReload).then(function(reload){ + loader["import"](name).then(function(){ + reload.once("!dispose/" + name, function(){ + css.style.__isDirty = true; + reload.once("!cycleComplete", function(){ + head.removeChild(css.style); + }); + }); + }); + }); + } + } }; + +if(loader.isEnv("production")) { + exports.fetch = function(load) { + var css = new CSSModule(load.address); + return css.injectLink(); + }; +} else { + exports.instantiate = function(load) { + var loader = this; + + var css = new CSSModule(load.address, load.source); + load.source = css.updateURLs(); + + load.metadata.deps = []; + load.metadata.format = "css"; + load.metadata.execute = function(){ + if (getDocument()) { + if (isIE9()) { + css.ie9StyleSheetLimitHack(); + } else { + css.injectStyle(); + } + css.setupLiveReload(loader, load.name); + } + + return loader.newModule({ + source: css.source + }); + }; + }; + +} + +exports.CSSModule = CSSModule; +exports.getDocument = getDocument; +exports.getHead = getHead; +exports.locateScheme = true; exports.buildType = "css"; exports.includeInBuild = true; +exports.pluginBuilder = "steal-css-slim"; // different from the original steal-css !!!! \ No newline at end of file From c6500365e2fd32bba2da642b49c4e8f2749b4903 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 22 Sep 2017 12:27:17 +0200 Subject: [PATCH 3/8] resolve conflicts and add logo.png --- test/bundle_assets/images/logo.png | Bin 0 -> 300 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/bundle_assets/images/logo.png diff --git a/test/bundle_assets/images/logo.png b/test/bundle_assets/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..efaf564b8aba78d64c9be23e0b628fa18ce2b37a GIT binary patch literal 300 zcmeAS@N?(olHy`uVBq!ia0vp^DImFdgVpIx4hPe8_}KN%<_n;8;O;+&tGo0?Yw Date: Fri, 22 Sep 2017 12:39:38 +0200 Subject: [PATCH 4/8] jshin funcsscope true for slim and multibuild files --- lib/build/multi.js | 5 +++-- lib/build/slim.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/build/multi.js b/lib/build/multi.js index 0d5d15e0..7f234816 100644 --- a/lib/build/multi.js +++ b/lib/build/multi.js @@ -1,3 +1,4 @@ +/*jshint funcscope:true*/ /* # lib/build/multi.js @@ -120,14 +121,14 @@ module.exports = function(config, options){ if(options.bundleAssets){ var bundleAssets = require("steal-bundler"); p = p.then(function(builtResult) { - return bundleAssets(builtResult, options.bundleAssets) + return bundleAssets(builtResult, options.bundleAssets); }); } if(options.serviceWorker){ var precache = require("steal-serviceworker"); p = p.then(function (builtResult) { - return precache(builtResult, options.serviceWorker) + return precache(builtResult, options.serviceWorker); }); } } diff --git a/lib/build/slim.js b/lib/build/slim.js index 472a3c1d..c452d49b 100644 --- a/lib/build/slim.js +++ b/lib/build/slim.js @@ -1,3 +1,4 @@ +/*jshint funcscope:true*/ var pump = require("pump"); var arrify = require("../arrify"); var assign = require("lodash/assign"); @@ -96,20 +97,19 @@ module.exports = function(cfg, opts) { // run external steal-tool plugins after the build if (options) { - var p = Promise.resolve(builtResult); if (options.bundleAssets) { var bundleAssets = require("steal-bundler"); p = p.then(function (builtResult) { - return bundleAssets(builtResult, options.bundleAssets) + return bundleAssets(builtResult, options.bundleAssets); }); } if (options.serviceWorker) { var precache = require("steal-serviceworker"); p = p.then(function (builtResult) { - return precache(builtResult, options.serviceWorker) + return precache(builtResult, options.serviceWorker); }); } } @@ -117,7 +117,7 @@ module.exports = function(cfg, opts) { p.then(function (builtResult) { dfd.resolve(builtResult); }).catch(function (error) { - dfd.reject(error) + dfd.reject(error); }); }); return dfd.promise; From 04d420747be6c576bb5551f932d81860dc0b5a32 Mon Sep 17 00:00:00 2001 From: Julian Kern Date: Sun, 24 Sep 2017 19:38:40 +0200 Subject: [PATCH 5/8] simple serviceworker test --- .gitignore | 1 + package.json | 18 +++++++++--------- test/serviceworker_test.js | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 14afd765..7bb86c59 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ test/live_reload/out.js test/transform_export/out.js test/exports_basics/out.js test/circular/export/ +/test/serviceworker/service-worker.js diff --git a/package.json b/package.json index a11eab42..77c7e14b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "babel-standalone": "^6.23.1", "bitovi-source-map": "0.4.2-bitovi.2", "chokidar": "^1.0.1", - "clean-css": "^4.0.5", + "clean-css": "^4.1.9", "colors": "^1.1.2", "find-line-column": "^0.5.2", "fs-extra": "~4.0.2", @@ -24,20 +24,20 @@ "multimatch": "^2.1.0", "normalize-path": "^2.1.1", "pdenodeify": "^0.1.0", - "prettier": "^1.6.1", + "prettier": "^1.7.0", "pump": "^1.0.2", "steal": "^1.5.13", "steal-bundler": "^0.3.0", "steal-parse-amd": "^1.0.0", - "steal-serviceworker": "0.0.3", + "steal-serviceworker": "^1.0.0", "through2": "^2.0.0", "tmp": "0.0.33", "traceur": "0.0.111", "transpile": "^2.5.3", - "uglify-es": "^3.0.26", + "uglify-es": "^3.1.2", "urix": "^0.1.0", "winston": "^2.2.0", - "ws": "^3.0.0", + "ws": "^3.2.0", "yargs": "^8.0.1" }, "devDependencies": { @@ -46,7 +46,7 @@ "bower": "1.8.2", "browserify": "~14.3.0", "comparify": "git://github.com/bitovi/comparify.git#master", - "connect": "^3.5.0", + "connect": "^3.6.5", "coveralls-send": "0.0.2", "cssify": "^1.0.3", "istanbul": "^0.4.2", @@ -56,12 +56,12 @@ "mocha-lcov-reporter": "^1.2.0", "mock-fs": "4.4.1", "mockery": "^2.0.0", - "rimraf": "^2.5.2", - "serve-static": "^1.11.2", + "rimraf": "^2.6.2", + "serve-static": "^1.12.6", "steal-conditional": "^0.4.0", "steal-qunit": "^1.0.0", "testee": "^0.4.0", - "tree-kill": "^1.0.0", + "tree-kill": "^1.2.0", "zombie": "^5.0.6" }, "bin": { diff --git a/test/serviceworker_test.js b/test/serviceworker_test.js index dffa3fb5..eada7329 100644 --- a/test/serviceworker_test.js +++ b/test/serviceworker_test.js @@ -1,17 +1,9 @@ var asap = require("pdenodeify"), assert = require("assert"), - comparify = require("comparify"), fs = require("fs-extra"), multiBuild = require("../lib/build/multi"), rmdir = require("rimraf"), - path = require("path"), - stealTools = require("../index"), - testHelpers = require("./helpers"); - -var precache = require("steal-serviceworker"); - -var find = testHelpers.find; -var open = testHelpers.open; + path = require("path"); describe("serviceworker", function () { this.timeout(5000); @@ -29,13 +21,21 @@ describe("serviceworker", function () { multiBuild({ config: __dirname + "/serviceworker/package.json!npm" }, { - quiet: false, - serviceWorker: true, - bundleAssets: true + quiet: true, + minify: false, + serviceWorker: true }).then(function (builtResult) { + // a valid buildResult? + assert.equal(builtResult.mains[0], "serviceworker@0.0.1#index"); + assert.ok(builtResult.hasOwnProperty("configuration")); + assert.ok(builtResult.hasOwnProperty("graph")); + assert.ok(builtResult.hasOwnProperty("loader")); + assert.ok(fs.existsSync(path.join(__dirname, "serviceworker", "service-worker.js"))); done(); }).catch(done); }); + + // for more tests, see https://github.com/stealjs/steal-serviceworker/blob/master/test/test.js }); \ No newline at end of file From e151814a1aded495b3a60ed07890e5043ffb3df6 Mon Sep 17 00:00:00 2001 From: Julian Kern Date: Mon, 25 Sep 2017 14:59:08 +0200 Subject: [PATCH 6/8] serviceworker script transpiled to node 4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77c7e14b..d6d19567 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "steal": "^1.5.13", "steal-bundler": "^0.3.0", "steal-parse-amd": "^1.0.0", - "steal-serviceworker": "^1.0.0", + "steal-serviceworker": "git://github.com/stealjs/steal-serviceworker.git#node4", "through2": "^2.0.0", "tmp": "0.0.33", "traceur": "0.0.111", From 0d933cb2e7ef8f3b6905fc9aee7cfb17fe9a80d4 Mon Sep 17 00:00:00 2001 From: Julian Kern Date: Mon, 25 Sep 2017 15:28:18 +0200 Subject: [PATCH 7/8] remove serviceworker integration until we drop node 4 support --- lib/build/multi.js | 15 +++++++++------ lib/build/slim.js | 15 +++++++++------ package.json | 1 - test/test.js | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/build/multi.js b/lib/build/multi.js index 7f234816..fe009256 100644 --- a/lib/build/multi.js +++ b/lib/build/multi.js @@ -125,12 +125,15 @@ module.exports = function(config, options){ }); } - if(options.serviceWorker){ - var precache = require("steal-serviceworker"); - p = p.then(function (builtResult) { - return precache(builtResult, options.serviceWorker); - }); - } + // steal-serviceworker can't be integrated until we drop support for node 4 + // tests are written and ready + // maybe we come up with a better idea integrate post-build-plugins + // if(options.serviceWorker){ + // var precache = require("steal-serviceworker"); + // p = p.then(function (builtResult) { + // return precache(builtResult, options.serviceWorker); + // }); + // } } p.then(function (builtResult) { diff --git a/lib/build/slim.js b/lib/build/slim.js index c452d49b..5747499f 100644 --- a/lib/build/slim.js +++ b/lib/build/slim.js @@ -106,12 +106,15 @@ module.exports = function(cfg, opts) { }); } - if (options.serviceWorker) { - var precache = require("steal-serviceworker"); - p = p.then(function (builtResult) { - return precache(builtResult, options.serviceWorker); - }); - } + // steal-serviceworker can't be integrated until we drop support for node 4 + // tests are written and ready + // maybe we come up with a better idea integrate post-build-plugins + // if(options.serviceWorker){ + // var precache = require("steal-serviceworker"); + // p = p.then(function (builtResult) { + // return precache(builtResult, options.serviceWorker); + // }); + // } } p.then(function (builtResult) { diff --git a/package.json b/package.json index d6d19567..5b472146 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "steal": "^1.5.13", "steal-bundler": "^0.3.0", "steal-parse-amd": "^1.0.0", - "steal-serviceworker": "git://github.com/stealjs/steal-serviceworker.git#node4", "through2": "^2.0.0", "tmp": "0.0.33", "traceur": "0.0.111", diff --git a/test/test.js b/test/test.js index 1429fa96..b1b016b2 100644 --- a/test/test.js +++ b/test/test.js @@ -52,4 +52,4 @@ require("./slim_loader_size_test"); // external steal-tools plugins require("./bundle_assets_test"); -require("./serviceworker_test"); \ No newline at end of file +//require("./serviceworker_test"); skip for now \ No newline at end of file From ceb089d5c27bccafc2a167d65e991a58e48fa058 Mon Sep 17 00:00:00 2001 From: Julian Kern Date: Sat, 30 Sep 2017 02:02:17 +0200 Subject: [PATCH 8/8] remove integrated serviceworker plugin --- lib/build/multi.js | 12 ------------ lib/build/slim.js | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/lib/build/multi.js b/lib/build/multi.js index fe009256..1d611ca0 100644 --- a/lib/build/multi.js +++ b/lib/build/multi.js @@ -111,8 +111,6 @@ module.exports = function(config, options){ ); writeStream.on("data", function(builtResult){ - //this.end(); - // run external steal-tool plugins after the build if(options){ @@ -124,16 +122,6 @@ module.exports = function(config, options){ return bundleAssets(builtResult, options.bundleAssets); }); } - - // steal-serviceworker can't be integrated until we drop support for node 4 - // tests are written and ready - // maybe we come up with a better idea integrate post-build-plugins - // if(options.serviceWorker){ - // var precache = require("steal-serviceworker"); - // p = p.then(function (builtResult) { - // return precache(builtResult, options.serviceWorker); - // }); - // } } p.then(function (builtResult) { diff --git a/lib/build/slim.js b/lib/build/slim.js index b1a6ca5b..62cc217c 100644 --- a/lib/build/slim.js +++ b/lib/build/slim.js @@ -94,8 +94,6 @@ module.exports = function(cfg, opts) { ); final.on("data", function (builtResult) { - //this.end(); - // run external steal-tool plugins after the build if (options) { var p = Promise.resolve(builtResult); @@ -106,16 +104,6 @@ module.exports = function(cfg, opts) { return bundleAssets(builtResult, options.bundleAssets); }); } - - // steal-serviceworker can't be integrated until we drop support for node 4 - // tests are written and ready - // maybe we come up with a better idea integrate post-build-plugins - // if(options.serviceWorker){ - // var precache = require("steal-serviceworker"); - // p = p.then(function (builtResult) { - // return precache(builtResult, options.serviceWorker); - // }); - // } } p.then(function (builtResult) {