Skip to content

Commit 5ac7474

Browse files
committed
feat: Migrate from tsc to rollup
1 parent bc2823d commit 5ac7474

18 files changed

+3656
-2108
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist/
2+
.rpt2_cache/
23
/.github/sereno/public
34
/_cache
45
test/style.css

docs/faqs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Frequently Asked Questions
22

3-
- **Why does `__file` use absolute path?**
3+
- **Why does `__file` use absolute path?**
44
The `__file` variable is used by devtools to provide "open in editor" feature. However, in production mode only filename is used. See issue [#258](https://github.com/vuejs/rollup-plugin-vue/issues/258) to enable production mode.
55

6-
- **Cannot find module `vue-template-compiler`?**
6+
- **Error: Cannot find module `vue-template-compiler`?**
77
`vue-template-compiler` has a constraint that it should be exact same version as `vue` that is why it is included as peer dependency. Make sure you install `vue-template-compiler` and `vue` in your project.
88

9-
- **Cannot find module `less` or `node-sass` or `stylus`?**
9+
- **Error: Cannot find module `less` or `node-sass` or `stylus`?**
1010
If you're using any of the style languages (other than css) supported in `.vue` file, you have to install that language's compiler.

package.json

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@
1212
"vue"
1313
],
1414
"license": "MIT",
15-
"main": "dist/index.js",
15+
"main": "dist/rollup-plugin-vue.js",
16+
"module": "dist/rollup-plugin-vue.mjs",
1617
"typings": "dist/index.d.ts",
1718
"repository": {
1819
"type": "git",
1920
"url": "git+https://github.com/vuejs/rollup-plugin-vue.git"
2021
},
2122
"standard-version": {
2223
"scripts": {
23-
"postchangelog": "yarn test && yarn build:docs && git add docs/"
24+
"postchangelog": "yarn test && yarn :build:docs && git add docs/"
2425
}
2526
},
2627
"scripts": {
2728
"prepublishOnly": "yarn build",
28-
"prebuild": "yarn lint",
29-
"build": "tsc",
30-
"prebuild:docs": "cp CHANGELOG.md docs/changelog.md",
31-
"build:docs": "vuepress build docs/",
32-
"postbuild:docs": "rm docs/changelog.md",
29+
"build": "yarn :build",
30+
"docs": "yarn :docs",
31+
"pre:build": "yarn lint",
32+
":build": "rollup -c",
33+
"pre:build:docs": "cp CHANGELOG.md docs/changelog.md",
34+
":build:docs": "vuepress build docs/",
35+
"post:build:docs": "rm docs/changelog.md",
3336
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
34-
"predocs": "cp CHANGELOG.md docs/changelog.md",
35-
"docs": "vuepress dev docs/",
36-
"postdocs": "rm docs/CHANGELOG.md",
37+
"pre:docs": "cp CHANGELOG.md docs/changelog.md",
38+
":docs": "vuepress dev docs/",
39+
"post:docs": "rm docs/CHANGELOG.md",
3740
"lint": "prettier --no-semi --single-quote --write **/*.js **/*.vue !test/target/** !dist/**",
3841
"release": "standard-version -a",
39-
"pretest": "yarn build",
4042
"test": "jest"
4143
},
4244
"files": [
43-
"dist/",
44-
"src/"
45+
"dist/"
4546
],
4647
"dependencies": {
47-
"@babel/runtime": "^7.0.0-beta.46",
4848
"@vue/component-compiler": "^3.6",
4949
"@vue/component-compiler-utils": "^2.1.0",
50-
"debug": "^2.6.0",
50+
"debug": "^4.1.1",
5151
"hash-sum": "^1.0.2",
5252
"querystring": "^0.2.0",
5353
"rollup-pluginutils": "^2.0.1",
@@ -59,37 +59,39 @@
5959
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.46",
6060
"@babel/plugin-transform-runtime": "^7.0.0-beta.46",
6161
"@babel/preset-env": "^7.0.0-beta.46",
62-
"@types/debug": "^0.0.30",
63-
"@types/jest": "^22.2.3",
64-
"@types/node": "^10.0.4",
62+
"@babel/runtime": "^7.0.0-beta.46",
63+
"@types/debug": "^0.0.31",
64+
"@types/jest": "^23.3.12",
65+
"@types/node": "^10.12.18",
6566
"@types/puppeteer": "^1.3.1",
6667
"@znck/promised": "^1.0.0",
6768
"babel-core": "7.0.0-bridge.0",
68-
"babel-jest": "^22.4.3",
69+
"babel-jest": "^23.6.0",
6970
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
70-
"conventional-changelog": "^1.1.24",
71-
"jest": "^22.4.2",
71+
"conventional-changelog": "^3.0.5",
72+
"jest": "^23.6.0",
7273
"node-sass": "^4.9.0",
73-
"postcss": "^6.0.22",
74+
"postcss": "^7.0.11",
7475
"postcss-assets": "^5.0.0",
7576
"prettier": "^1.12.1",
7677
"pug": "^2.0.3",
7778
"puppeteer": "^1.4.0",
78-
"rollup": "^0.58.2",
79+
"rollup": "^1.1.0",
7980
"rollup-plugin-babel": "^4.0.0-beta.4",
8081
"rollup-plugin-commonjs": "^9.1.3",
8182
"rollup-plugin-css-only": "^0.4.0",
8283
"rollup-plugin-md": "^0.0.7",
83-
"rollup-plugin-node-resolve": "^3.3.0",
84+
"rollup-plugin-node-resolve": "^4.0.0",
8485
"rollup-plugin-replace": "^2.0.0",
85-
"rollup-plugin-typescript": "^0.8.1",
86-
"rollup-plugin-url": "^1.4.0",
87-
"ts-jest": "^22.4.5",
88-
"typescript": "^2.8.3",
86+
"rollup-plugin-typescript": "^1.0.0",
87+
"rollup-plugin-typescript2": "^0.18.1",
88+
"rollup-plugin-url": "^2.1.0",
89+
"ts-jest": "^23.10.5",
90+
"typescript": "^3.2.2",
8991
"vue": "^2.5.16",
9092
"vue-class-component": "^6.2.0",
9193
"vue-template-compiler": "^2.5.16",
92-
"vuepress": "^0.13.0"
94+
"vuepress": "^0.14.8"
9395
},
9496
"peerDependencies": {
9597
"vue-template-compiler": "*"

rollup.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import typescript from 'rollup-plugin-typescript2'
2+
import pkg from './package.json'
3+
4+
const input = 'src/index.ts'
5+
const plugins = [typescript({
6+
typescript: require('typescript')
7+
})]
8+
9+
function external(id) {
10+
return id in pkg.dependencies || id in pkg.peerDependencies || ['path'].includes(id)
11+
}
12+
13+
export default [
14+
{
15+
input,
16+
plugins,
17+
external,
18+
output: [
19+
{
20+
file: pkg.main,
21+
format: 'cjs',
22+
exports: 'default',
23+
sourcemap: true,
24+
},
25+
{
26+
file: pkg.module,
27+
format: 'es',
28+
sourcemap: true,
29+
},
30+
],
31+
},
32+
]

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
StyleCompileResult,
1616
DescriptorCompileResult,
1717
} from '@vue/component-compiler'
18-
import { Plugin } from 'rollup'
18+
import { Plugin, RawSourceMap } from 'rollup'
1919
import * as path from 'path'
2020
import { parse, SFCDescriptor, SFCBlock } from '@vue/component-compiler-utils'
2121
import debug from 'debug'
@@ -116,7 +116,7 @@ export interface VuePluginOptions {
116116
/**
117117
* Rollup plugin for handling .vue files.
118118
*/
119-
export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
119+
export default function vue(opts: VuePluginOptions = {}): Plugin {
120120
const isVue = createVueFilter(opts.include, opts.exclude)
121121
const isProduction =
122122
process.env.NODE_ENV === 'production' || process.env.BUILD === 'production'
@@ -145,7 +145,9 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
145145
(!blacklisted.has('*') || !blacklisted.has(customBlockType)) &&
146146
(whitelisted.has('*') || whitelisted.has(customBlockType))
147147

148-
const beforeAssemble = opts.beforeAssemble || ((d: DescriptorCompileResult): DescriptorCompileResult => d)
148+
const beforeAssemble =
149+
opts.beforeAssemble ||
150+
((d: DescriptorCompileResult): DescriptorCompileResult => d)
149151

150152
delete opts.beforeAssemble
151153
delete opts.css
@@ -204,14 +206,14 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
204206
load(id: string) {
205207
const request = parseVuePartRequest(id)
206208

207-
if (!request) return
209+
if (!request) return null
208210

209211
const element = resolveVuePart(descriptors, request)
210212
const code =
211213
'code' in element
212214
? ((element as any).code as string) // .code is set when extract styles is used. { css: false }
213215
: element.content
214-
const map = element.map as any
216+
const map = element.map as RawSourceMap
215217

216218
dL(`id: ${id}\ncode: \n${code}\nmap: ${JSON.stringify(map, null, 2)}\n\n`)
217219

@@ -330,7 +332,7 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
330332
'\n' +
331333
`export * from '${createVuePartRequest(
332334
filename,
333-
block.attrs.lang ||
335+
(typeof block.attrs.lang === 'string' && block.attrs.lang) ||
334336
createVuePartRequest.defaultLang[block.type] ||
335337
block.type,
336338
'customBlocks',

test/assertions.ts

Whitespace-only changes.

test/baseline.spec.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
const puppeteer = require('puppeteer')
22
import * as fs from 'fs'
33
import * as path from 'path'
4-
import * as assertions from './assertions'
54

6-
import {build, open} from "./setup"
5+
import { build, open } from './setup'
6+
import { Browser } from 'puppeteer'
77

8-
let browser = null
9-
10-
function toCamelCase(name: string) : string {
11-
return name.replace(/-(.)/g, (_, char) => char.toUpperCase())
12-
}
8+
let browser: Browser | null = null
139

1410
beforeAll(async () => {
1511
browser = await puppeteer.launch({
1612
args: ['--no-sandbox', '--disable-setuid-sandbox'],
17-
headless: Boolean(process.env.CI)
13+
headless: Boolean(process.env.CI),
1814
})
1915
})
2016

@@ -23,33 +19,43 @@ describe('baseline', () => {
2319
.filter((filename: string) => filename.endsWith('.vue'))
2420
.map((filename: string) => filename.replace(/\.vue$/i, ''))
2521
.forEach(fixture => {
26-
const name = toCamelCase(fixture)
27-
test(fixture, () => testRunner(fixture, true, assertions[name]))
28-
test(fixture + ' (extract css)', () => testRunner(fixture, false, assertions[name]))
22+
test(fixture, () => testRunner(fixture, true))
23+
test(fixture + ' (extract css)', () => testRunner(fixture, false))
2924
})
3025
})
3126

3227
afterAll(async () => browser && (await browser.close()))
3328

34-
async function testRunner(fixture: string, extractCss: boolean, moreAssertions?: Function): Promise<void> {
29+
async function testRunner(
30+
fixture: string,
31+
extractCss: boolean,
32+
moreAssertions?: Function
33+
): Promise<void> {
3534
const filename = path.join(__dirname, 'fixtures', fixture + '.vue')
36-
const code = await build(filename, extractCss)
37-
const page = await open(
38-
fixture + (extractCss ? '-extract' : ''),
39-
browser,
40-
code
41-
)
42-
expect(await page.$('#test')).toBeTruthy()
43-
expect(
44-
await page.evaluate(() => document.getElementById('test').textContent)
45-
).toEqual(expect.stringContaining('Hello'))
46-
expect(
47-
await page.evaluate(
48-
() => window.getComputedStyle(document.getElementById('test')).color
49-
)
50-
).toEqual('rgb(255, 0, 0)')
35+
try {
36+
const code = await build(filename, extractCss)
5137

52-
moreAssertions && moreAssertions(page)
53-
54-
await page.close()
38+
const page = await open(
39+
fixture + (extractCss ? '-extract' : ''),
40+
browser!,
41+
code
42+
)
43+
expect(await page.$('#test')).toBeTruthy()
44+
expect(
45+
await page.evaluate(() => document.getElementById('test')!.textContent)
46+
).toEqual(expect.stringContaining('Hello'))
47+
expect(
48+
await page.evaluate(
49+
() => window.getComputedStyle(document.getElementById('test')!).color
50+
)
51+
).toEqual('rgb(255, 0, 0)')
52+
53+
moreAssertions && moreAssertions(page)
54+
55+
await page.close()
56+
} catch (error) {
57+
console.error({ error })
58+
59+
throw error
60+
}
5561
}

test/fixtures/with-import-script.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
<h1 id="test" style="color: red;">Hello {{ name }}!</h1>
33
</template>
44

5-
<script src="./script.js">
6-
</script>
5+
<script src="./script.js"></script>

test/fixtures/with-import-style.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ export default {
1010
}
1111
</script>
1212

13-
<style src="./style.css">
14-
</style>
13+
<style src="./style.css"></style>

test/fixtures/with-style-scoped.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ h1 {
6464
</style>
6565

6666
<template>
67-
<div>
68-
<div><h1>hi</h1></div>
69-
<p class="abc def">hi</p>
70-
<template v-if="!ok"><p class="test" id="test">Hello</p></template>
71-
<svg><template><p></p></template></svg>
72-
</div>
67+
<div>
68+
<div><h1>hi</h1></div>
69+
<p class="abc def">hi</p>
70+
<template v-if="!ok"
71+
><p class="test" id="test">Hello</p></template
72+
>
73+
<svg>
74+
<template>
75+
<p></p>
76+
</template>
77+
</svg>
78+
</div>
7379
</template>

test/fixtures/with-template-comment.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template comments>
22
<div>
3-
<h2 class="red" id="test">{{msg}}</h2><!-- comment here -->
3+
<h2 class="red" id="test">{{ msg }}</h2>
4+
<!-- comment here -->
45
</div>
56
</template>
67

test/fixtures/with-template-functional.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template functional>
22
<div>
33
<h2 id="test" style="color: red">Hello! {{ props.msg }}</h2>
4-
<slot></slot>
5-
<slot name="slot2"></slot>
4+
<slot></slot> <slot name="slot2"></slot>
65
<slot :msg="props.msg" name="scoped"></slot>
76
<div>Some <span>text</span></div>
87
<div v-if="false">Not exist</div>

0 commit comments

Comments
 (0)