| const resolve = require('resolve') | ||
| const path = require('path') | ||
| module.exports = cssResolve | ||
| // find a file in CSS with either a {style} field | ||
| // or main with `.css` in it | ||
| // (str, str) -> str | ||
| function cssResolve (pkgname, basedir) { | ||
| try { | ||
| const res = resolve.sync(pkgname, { | ||
| basedir: pkgname, | ||
| packageFilter: packageFilter | ||
| }) | ||
| if (path.extname(res) !== '.css') { | ||
| throw new Error('path ' + res + ' is not a CSS file') | ||
| } | ||
| return res | ||
| } catch (e) { | ||
| return | ||
| } | ||
| function packageFilter (pkg, path) { | ||
| if (pkg.style) pkg.main = pkg.style | ||
| return pkg | ||
| } | ||
| } |
| const sf = require('sheetify') | ||
| sf('./not-a-file.css') |
+1
-1
| { | ||
| "name": "sheetify", | ||
| "version": "4.0.2", | ||
| "version": "4.0.3", | ||
| "description": "Modular CSS bundler", | ||
@@ -5,0 +5,0 @@ "repository": "sheetify/sheetify", |
+17
-0
@@ -193,2 +193,10 @@ # sheetify | ||
| ## FAQ | ||
| ### Help, why isn't my inline CSS being transformed? | ||
| Well, that might be because you're running `babelify` before running | ||
| `sheetify`. `sheetify` looks for template strings in your code and then | ||
| transforms them as inline stylesheets. If these are caught and transformed to | ||
| ES5 strings by `babelify` then `sheetify` ends up sad. So try running | ||
| `sheetify` before `babelify` and you should be good, we hope. | ||
| ## Installation | ||
@@ -199,2 +207,11 @@ ```sh | ||
| ## See Also | ||
| - [browserify](https://github.com/substack/node-browserify) - browser-side | ||
| require() the node.js way | ||
| - [glslify](https://github.com/stackgl/glslify) - module system for GLSL | ||
| shaders | ||
| - [hyperx](https://github.com/substack/hyperx) - transform inline HTML to JS | ||
| - [bankai](https://github.com/yoshuawuyts/bankai) - DIY server middleware for | ||
| JS, CSS and HTML | ||
| ## License | ||
@@ -201,0 +218,0 @@ [MIT](https://tldrlegal.com/license/mit-license) |
+30
-2
@@ -8,4 +8,2 @@ const browserify = require('browserify') | ||
| const sheetify = require(path.join(__dirname, '../transform')) | ||
| const expath = require.resolve('css-type-base/index.css') | ||
| const expected = fs.readFileSync(expath, 'utf8').trim() | ||
@@ -15,2 +13,5 @@ test('import', function (t) { | ||
| const expath = require.resolve('css-type-base/index.css') | ||
| const expected = fs.readFileSync(expath, 'utf8').trim() | ||
| const ws = concat(function (buf) { | ||
@@ -34,1 +35,28 @@ const res = String(buf).trim() | ||
| }) | ||
| test('broken import should emit an error', function (t) { | ||
| t.plan(1) | ||
| const inpath = path.join(__dirname, 'import/broken.js') | ||
| const ws = concat(function (buf) { | ||
| const res = String(buf).trim() | ||
| console.log(res) | ||
| }) | ||
| const bOpts = { browserField: false } | ||
| const b = browserify(inpath, bOpts) | ||
| b.transform(sheetify, { | ||
| basedir: path.join(__dirname, 'plugins'), | ||
| o: ws | ||
| }) | ||
| const r = b.bundle() | ||
| r.resume() | ||
| r.on('error', function (e) { | ||
| t.ok(/cannot be imported/.test(e), 'emits an error') | ||
| }) | ||
| r.on('end', function () { | ||
| ws.end() | ||
| }) | ||
| }) |
+19
-39
@@ -6,3 +6,2 @@ const mapLimit = require('map-limit') | ||
| const falafel = require('falafel') | ||
| const resolve = require('resolve') | ||
| const assert = require('assert') | ||
@@ -14,2 +13,3 @@ const mkdirp = require('mkdirp') | ||
| const cssResolve = require('./lib/css-resolve') | ||
| const sheetify = require('./index') | ||
@@ -150,18 +150,23 @@ | ||
| else transformStream.emit('file', fnp) | ||
| const fnCss = fs.readFileSync(fnp, 'utf8').trim() | ||
| try { | ||
| const fnCss = fs.readFileSync(fnp, 'utf8').trim() | ||
| // read optional arguments passed in to node | ||
| // e.g. { global: false } | ||
| if (node.arguments[1] && node.arguments[1].properties) { | ||
| const props = node.arguments[1].properties | ||
| props.forEach(function (prop) { | ||
| opts[prop.key.name] = prop.value.value | ||
| // read optional arguments passed in to node | ||
| // e.g. { global: false } | ||
| if (node.arguments[1] && node.arguments[1].properties) { | ||
| const props = node.arguments[1].properties | ||
| props.forEach(function (prop) { | ||
| opts[prop.key.name] = prop.value.value | ||
| }) | ||
| } | ||
| sheetify(fnCss, fnp, opts, function (tf) { | ||
| nodes.push([ tf, node ]) | ||
| }) | ||
| return | ||
| } catch (e) { | ||
| const errMsg = 'sheetify: ' + e.path + ' cannot be imported' | ||
| return transformStream.emit('error', errMsg) | ||
| } | ||
| sheetify(fnCss, fnp, opts, function (tf) { | ||
| nodes.push([ tf, node ]) | ||
| }) | ||
| return | ||
| } | ||
@@ -173,26 +178,1 @@ } | ||
| function expr (ex) { return { _expr: ex.source() } } | ||
| // find a file in CSS with either a {style} field | ||
| // or main with `.css` in it | ||
| // (str, str) -> str | ||
| function cssResolve (pkgname, basedir) { | ||
| try { | ||
| const res = resolve.sync(pkgname, { | ||
| basedir: pkgname, | ||
| packageFilter: packageFilter | ||
| }) | ||
| if (path.extname(res) !== '.css') { | ||
| throw new Error('path ' + res + ' is not a CSS file') | ||
| } | ||
| return res | ||
| } catch (e) { | ||
| return | ||
| } | ||
| function packageFilter (pkg, path) { | ||
| if (pkg.style) pkg.main = pkg.style | ||
| return pkg | ||
| } | ||
| } |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
26295
6.97%35
6.06%558
6.08%228
8.06%