systemjs-plugin-css
Advanced tools
Comparing version
// it's bad to do this in general, as code is now heavily environment specific | ||
var fs = System._nodeRequire('fs'); | ||
var CleanCSS = require('./clean-css.js'); | ||
@@ -45,3 +46,2 @@ function escape(source) { | ||
return loader['import']('clean-css').then(function(CleanCSS) { | ||
// SystemJS Builder 0.14 will write the stubs for use, we detect by the 3 argument over 2 argument bundle call | ||
@@ -94,7 +94,2 @@ var writeStubs = typeof outputOpts == 'undefined'; | ||
return [stubDefines, cssInject, '("' + escape(cssOutput) + '");'].join('\n'); | ||
}, function(err) { | ||
if (err.toString().indexOf('ENOENT') != -1) | ||
throw new Error('Install Clean CSS via `jspm install npm:clean-css --dev` for CSS build support. Set System.buildCSS = false to skip CSS builds.'); | ||
throw err; | ||
}); | ||
}; |
66
css.js
@@ -6,9 +6,2 @@ if (typeof window !== 'undefined') { | ||
// get all link tags in the page | ||
var links = document.getElementsByTagName('link'); | ||
var linkHrefs = []; | ||
for (var i = 0; i < links.length; i++) { | ||
linkHrefs.push(links[i].href); | ||
} | ||
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/); | ||
@@ -26,5 +19,24 @@ var webkitLoadCheck = function(link, callback) { | ||
var cssIsReloadable = function cssIsReloadable(links){ | ||
// Css loaded on the page initially should be skipped by the first | ||
// systemjs load, and marked for reload | ||
var reloadable = true; | ||
forEach(links, function(link){ | ||
if(!link.hasAttribute('data-systemjs-css')){ | ||
reloadable = false; | ||
link.setAttribute('data-systemjs-css', ''); | ||
} | ||
}); | ||
return reloadable; | ||
} | ||
var findExistingCSS = function findExistingCSS(url){ | ||
// Search for existing link to reload | ||
var links = head.getElementsByTagName('link') | ||
return filter(links, function(link){ return link.href === url; }); | ||
} | ||
var noop = function() {}; | ||
var loadCSS = function(url) { | ||
var loadCSS = function(url, existingLinks) { | ||
return new Promise(function(resolve, reject) { | ||
@@ -48,2 +60,3 @@ var timeout = setTimeout(function() { | ||
link.href = url; | ||
link.setAttribute('data-systemjs-css', ''); | ||
if (!isWebkit) { | ||
@@ -59,4 +72,12 @@ link.onload = function() { | ||
}; | ||
head.appendChild(link); | ||
}); | ||
head.insertBefore(link, existingLinks[0]); | ||
}) | ||
// Remove the old link regardless of loading outcome | ||
.then(function(result){ | ||
forEach(existingLinks, function(link){link.parentElement.removeChild(link);}) | ||
return result; | ||
}, function(err){ | ||
forEach(existingLinks, function(link){link.parentElement.removeChild(link);}) | ||
throw err; | ||
}) | ||
}; | ||
@@ -66,6 +87,6 @@ | ||
// dont reload styles loaded in the head | ||
for (var i = 0; i < linkHrefs.length; i++) | ||
if (load.address == linkHrefs[i]) | ||
var links = findExistingCSS(load.address) | ||
if(!cssIsReloadable(links)) | ||
return ''; | ||
return loadCSS(load.address); | ||
return loadCSS(load.address, links); | ||
}; | ||
@@ -86,3 +107,3 @@ } | ||
// don't load the CSS at all until build time | ||
return ''; | ||
return Promise.resolve(''); | ||
}; | ||
@@ -105,1 +126,18 @@ exports.instantiate = function() {}; | ||
} | ||
// Because IE8? | ||
function filter(arrayLike, func){ | ||
var arr = [] | ||
forEach(arrayLike, function(item){ | ||
if(func(item)) | ||
arr.push(item); | ||
}); | ||
return arr; | ||
} | ||
// Because IE8? | ||
function forEach(arrayLike, func){ | ||
for (var i = 0; i < arrayLike.length; i++) { | ||
func(arrayLike[i]) | ||
} | ||
} |
{ | ||
"name": "systemjs-plugin-css", | ||
"version": "0.1.20", | ||
"version": "0.1.22", | ||
"main": "css", | ||
"registry": "jspm" | ||
"registry": "jspm", | ||
"scripts": { | ||
"test": "mocha --harmony test/test.js" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.3.0", | ||
"mocha": "^2.4.5", | ||
"mocha-phantomjs": "^4.0.2", | ||
"sinon": "^1.17.4", | ||
"sinon-chai": "^2.8.0", | ||
"systemjs": "^0.19.28", | ||
"systemjs-builder": "^0.15.17" | ||
} | ||
} |
@@ -6,2 +6,10 @@ css | ||
Installation | ||
--- | ||
For installing with JSPM run: | ||
``` | ||
jspm install css | ||
``` | ||
Basic Use | ||
@@ -8,0 +16,0 @@ --- |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
315699
3170.81%15
87.5%8200
4723.53%74
12.12%8
Infinity%6
500%4
Infinity%