diff --git a/README.md b/README.md index e08252e..5ec2abd 100644 --- a/README.md +++ b/README.md @@ -128,17 +128,6 @@ css('normalize.css') ``` Packages from npm will not be namespaced by default. -## Toggle namespaces -To toggle namespaces for external files or npm packages: -```js -const css = require('sheetify') - -css('./my-file.css', { global: true }) -``` -Be aware that when you toggle the namespace, the `:host` element matches won't -work anymore because the class it targets no longer exists. Only use this -toggle to write styles that are, well, global. - ## Write to separate file on disk To write the compiled CSS to a separate file, rather than keep it in the bundle use [css-extract][2]: diff --git a/index.js b/index.js index 781db02..7e4e0de 100644 --- a/index.js +++ b/index.js @@ -61,7 +61,7 @@ function parseCss (src, filename, prefix, options, done) { applyTransforms(filename, String(src), xtend(options), function (err, css) { if (err) return done(err) var p = postcss() - if (options.global !== true) p = p.use(cssPrefix('.' + prefix)) + p = p.use(cssPrefix('.' + prefix)) try { css = p.process(css).toString() diff --git a/package.json b/package.json index cd9758f..4f4b4fd 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "is-stream": "^1.0.1", "map-limit": "0.0.1", "postcss": "^5.0.10", - "postcss-prefix": "^1.0.3", + "postcss-prefix": "^2.0.0", "resolve": "^1.1.7", "stack-trace": "0.0.9", "static-eval": "^0.2.4", diff --git a/test/fixtures/plugins-expected.css b/test/fixtures/plugins-expected.css index edce3a2..cf38b0a 100644 --- a/test/fixtures/plugins-expected.css +++ b/test/fixtures/plugins-expected.css @@ -1,4 +1,4 @@ -._08548a3e hello, ._08548a3e world { +._75161010 .hello,._75161010 .world { -webkit-transform: translate(0, 0); transform: translate(0, 0); } diff --git a/test/fixtures/plugins-source.js b/test/fixtures/plugins-source.js index 9dce7ea..802f7c8 100644 --- a/test/fixtures/plugins-source.js +++ b/test/fixtures/plugins-source.js @@ -1,7 +1,7 @@ const sf = require('sheetify') const prefix = sf` - hello, world { + :host .hello, :host .world { transform: translate(0, 0); } ` diff --git a/test/fixtures/prefix-import-expected.css b/test/fixtures/prefix-import-expected.css index 531cdfc..b6a937c 100644 --- a/test/fixtures/prefix-import-expected.css +++ b/test/fixtures/prefix-import-expected.css @@ -1,3 +1,3 @@ -._0081131d .foo { +._f918f624 .foo { color: blue; } diff --git a/test/fixtures/prefix-import-source.css b/test/fixtures/prefix-import-source.css index 94ff8d4..5f8d93c 100644 --- a/test/fixtures/prefix-import-source.css +++ b/test/fixtures/prefix-import-source.css @@ -1,3 +1,3 @@ -.foo { +:host .foo { color: blue; } diff --git a/test/fixtures/prefix-inline-expected.css b/test/fixtures/prefix-inline-expected.css index 531cdfc..b6a937c 100644 --- a/test/fixtures/prefix-inline-expected.css +++ b/test/fixtures/prefix-inline-expected.css @@ -1,3 +1,3 @@ -._0081131d .foo { +._f918f624 .foo { color: blue; } diff --git a/test/fixtures/prefix-inline-source.js b/test/fixtures/prefix-inline-source.js index 058ee92..f175ba9 100644 --- a/test/fixtures/prefix-inline-source.js +++ b/test/fixtures/prefix-inline-source.js @@ -1,6 +1,6 @@ const sf = require('sheetify') -const prefix = sf`.foo { +const prefix = sf`:host .foo { color: blue; } ` diff --git a/test/prefix.js b/test/prefix.js index 5fa1142..bbfa01b 100644 --- a/test/prefix.js +++ b/test/prefix.js @@ -61,7 +61,7 @@ test('prefix', function (t) { vm.runInNewContext(src.toString(), c) function log (msg) { - t.equal(msg, '_0081131d', 'echoes prefix') + t.equal(msg, '_f918f624', 'echoes prefix') } } }) @@ -94,31 +94,8 @@ test('prefix', function (t) { vm.runInNewContext(src.toString(), c) function log (msg) { - t.equal(msg, '_0081131d', 'echoes prefix') + t.equal(msg, '_f918f624', 'echoes prefix') } } }) - - t.test('should disable prefixing when global:true', function (t) { - t.plan(1) - - const expath = path.join(__dirname, 'fixtures/prefix-global-expected.css') - const expected = fs.readFileSync(expath, 'utf8').trim() - - const ws = concat(function (buf) { - const res = String(buf).trim() - t.equal(res, expected, 'css is equal') - }) - - const bOpts = { browserField: false } - const bpath = path.join(__dirname, 'fixtures/prefix-global-source.js') - browserify(bpath, bOpts) - .transform(transform) - .plugin('css-extract', { out: outFn }) - .bundle() - - function outFn () { - return ws - } - }) }) diff --git a/transform.js b/transform.js index 83b91fa..39292ee 100644 --- a/transform.js +++ b/transform.js @@ -116,8 +116,6 @@ function transform (filename, options) { if (node.type !== 'CallExpression') return if (!node.callee || node.callee.type !== 'Identifier') return if (node.callee.name !== mname) return - const isLocalFile = /^\.{0,2}\//.test(node.arguments[0].value) - const localOptions = { global: !isLocalFile } try { var resolvePath = cssResolve(node.arguments[0].value, { basedir: path.dirname(filename) @@ -127,9 +125,9 @@ function transform (filename, options) { return self.emit('error', err) } - const iOpts = node.arguments[1] - ? xtend(opts, localOptions, staticEval(node.arguments[1])) - : xtend(opts, localOptions) + const iOpts = (node.arguments[1]) + ? xtend(opts, staticEval(node.arguments[1])) + : opts const val = { filename: resolvePath,