Skip to content

Commit

Permalink
fix compatibility with rollup-plugin-vue
Browse files Browse the repository at this point in the history
- remove experimental scoped css and range support
  • Loading branch information
egoist committed Nov 21, 2018
1 parent 6d1ec84 commit cd405c3
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 216 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"xo": "^0.18.2"
},
"dependencies": {
"@vue/component-compiler-utils": "^1.0.0",
"chalk": "^2.0.0",
"concat-with-sourcemaps": "^1.0.5",
"cssnano": "^3.10.0",
Expand Down Expand Up @@ -80,4 +79,4 @@
]
]
}
}
}
45 changes: 1 addition & 44 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path'
import queryString from 'querystring'
import fs from 'fs-extra'
import { createFilter } from 'rollup-pluginutils'
import Concat from 'concat-with-sourcemaps'
Expand All @@ -17,20 +16,6 @@ function inferOption(option, defaultValue) {
return option ? {} : defaultValue
}

const QUERY_REGEXP = /\?(.+)$/

function hasQuery(str) {
return QUERY_REGEXP.test(str)
}

function parseQuery(str) {
return queryString.parse(QUERY_REGEXP.exec(str)[1])
}

function stripQuery(str) {
return str.replace(QUERY_REGEXP, '')
}

export default (options = {}) => {
const filter = createFilter(options.include, options.exclude)
const sourceMap = options.sourceMap
Expand Down Expand Up @@ -71,34 +56,7 @@ export default (options = {}) => {
return {
name: 'postcss',

resolveId(id, importer) {
if (importer && hasQuery(id)) {
return path.resolve(path.dirname(importer), id)
}
},

async load(id) {
if (hasQuery(id)) {
const { start, end, file } = parseQuery(id)
const bareId = stripQuery(id)
const content = await fs.readFile(
file ? path.resolve(path.dirname(bareId), file) : bareId,
'utf8'
)
return start && end ?
content.slice(Number(start), Number(end)) :
content
}
},

async transform(code, id) {
let scoped
if (hasQuery(id)) {
const query = parseQuery(id)
scoped = query.scoped
id = stripQuery(id)
}

if (!filter(id) || !loaders.isSupported(id)) {
return null
}
Expand All @@ -111,8 +69,7 @@ export default (options = {}) => {
code,
map: undefined,
id,
sourceMap,
scoped
sourceMap
})

if (postcssLoaderOptions.extract) {
Expand Down
5 changes: 0 additions & 5 deletions src/postcss-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import importCwd from 'import-cwd'
import postcss from 'postcss'
import findPostcssConfig from 'postcss-load-config'
import reserved from 'reserved-words'
import scopedPlugin from '@vue/component-compiler-utils/dist/stylePlugins/scoped'
import humanlizePath from './utils/humanlize-path'
import normalizePath from './utils/normalize-path'

Expand Down Expand Up @@ -95,10 +94,6 @@ export default {
plugins.push(require('cssnano')(options.minimize))
}

if (this.scoped) {
plugins.unshift(scopedPlugin(this.scoped))
}

const postcssOpts = {
...this.options.postcss,
...config.options,
Expand Down
75 changes: 0 additions & 75 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -885,78 +885,3 @@ styleInject(css$5);
console.log(css, css$1);
"
`;

exports[`vue range: js code 1`] = `
"'use strict';
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (!css || typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css = \\"\\\\n.foo {\\\\n color: red;\\\\n}\\\\n\\";
styleInject(css);
var css$1 = \\".foo {\\\\n color: red; }\\\\n .foo .bar {\\\\n color: yellow; }\\\\n\\";
styleInject(css$1);
"
`;

exports[`vue scopedId: js code 1`] = `
"'use strict';
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (!css || typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css = \\".foo[abc] {\\\\n color: red;\\\\n}\\\\n\\";
styleInject(css);
module.exports = css;
"
`;
19 changes: 0 additions & 19 deletions test/fixtures/vue/range/foo.vue

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/vue/range/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/vue/scoped-id/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/vue/scoped-id/style.css

This file was deleted.

11 changes: 0 additions & 11 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,6 @@ snapshotMany('sass', [
}
])

snapshotMany('vue', [
{
title: 'scopedId',
input: 'vue/scoped-id/index.js'
},
{
title: 'range',
input: 'vue/range/index.js'
}
])

test('onExtract', async () => {
const res = await write({
input: 'simple/index.js',
Expand Down
54 changes: 2 additions & 52 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -511,19 +511,6 @@
version "9.3.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.3.0.tgz#3a129cda7c4e5df2409702626892cb4b96546dd5"

"@vue/component-compiler-utils@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-1.0.0.tgz#edcb00f656202c95091f07b0fe63a75e69b35614"
dependencies:
consolidate "^0.15.1"
hash-sum "^1.0.2"
lru-cache "^4.1.2"
postcss "^6.0.20"
postcss-selector-parser "^3.1.1"
prettier "^1.11.1"
source-map "^0.5.6"
vue-template-es2015-compiler "^1.6.0"

abab@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
Expand Down Expand Up @@ -1399,10 +1386,6 @@ block-stream@*:
dependencies:
inherits "~2.0.0"

bluebird@^3.1.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"

boom@2.x.x:
version "2.10.1"
resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f"
Expand Down Expand Up @@ -1844,12 +1827,6 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"

consolidate@^0.15.1:
version "0.15.1"
resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.15.1.tgz#21ab043235c71a07d45d9aad98593b0dba56bab7"
dependencies:
bluebird "^3.1.1"

contains-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/contains-path/-/contains-path-0.1.0.tgz#fe8cf184ff6670b6baef01a9d4861a5cbec4120a"
Expand Down Expand Up @@ -2166,7 +2143,7 @@ domexception@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.0.tgz#81fe5df81b3f057052cde3a9fa9bf536a85b9ab0"

dot-prop@^4.1.0, dot-prop@^4.1.1:
dot-prop@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57"
dependencies:
Expand Down Expand Up @@ -3031,10 +3008,6 @@ has@^1.0.1:
dependencies:
function-bind "^1.0.2"

hash-sum@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/hash-sum/-/hash-sum-1.0.2.tgz#33b40777754c6432573c120cc3808bbd10d47f04"

hawk@3.1.3, hawk@~3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
Expand Down Expand Up @@ -4130,13 +4103,6 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"

lru-cache@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.2.tgz#45234b2e6e2f2b33da125624c4664929a0224c3f"
dependencies:
pseudomap "^1.0.2"
yallist "^2.1.2"

macaddress@^0.2.8:
version "0.2.8"
resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"
Expand Down Expand Up @@ -4946,14 +4912,6 @@ postcss-selector-parser@^2.0.0, postcss-selector-parser@^2.2.2:
indexes-of "^1.0.1"
uniq "^1.0.1"

postcss-selector-parser@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-3.1.1.tgz#4f875f4afb0c96573d5cf4d74011aee250a7e865"
dependencies:
dot-prop "^4.1.1"
indexes-of "^1.0.1"
uniq "^1.0.1"

postcss-svgo@^2.1.1:
version "2.1.6"
resolved "https://registry.yarnpkg.com/postcss-svgo/-/postcss-svgo-2.1.6.tgz#b6df18aa613b666e133f08adb5219c2684ac108d"
Expand Down Expand Up @@ -5016,7 +4974,7 @@ postcss@^6.0.14, postcss@^6.0.15:
source-map "^0.6.1"
supports-color "^5.1.0"

postcss@^6.0.20, postcss@^6.0.21:
postcss@^6.0.21:
version "6.0.21"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.21.tgz#8265662694eddf9e9a5960db6da33c39e4cd069d"
dependencies:
Expand All @@ -5036,10 +4994,6 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"

prettier@^1.11.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.11.1.tgz#61e43fc4cd44e68f2b0dfc2c38cd4bb0fccdcc75"

pretty-format@^22.0.3:
version "22.0.3"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-22.0.3.tgz#a2bfa59fc33ad24aa4429981bb52524b41ba5dd7"
Expand Down Expand Up @@ -6392,10 +6346,6 @@ vlq@^0.2.2:
version "0.2.3"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26"

vue-template-es2015-compiler@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18"

walker@~1.0.5:
version "1.0.7"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"
Expand Down

0 comments on commit cd405c3

Please sign in to comment.