diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 9169002..0000000 --- a/.babelrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "target": "node" - } - ] - ], - "plugins": [ - "@babel/transform-runtime" - ], - "retainLines": true, - "comments": true -} diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 43040f9..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -jobs: - build: - working_directory: ~/project - docker: - - image: alekzonder/puppeteer # base pluginImage: node/8-slim - steps: - - checkout - - run: - name: Install yarn if required - command: curl -o- -s -L https://yarnpkg.com/install.sh | bash - - restore_cache: - key: dependency-cache-{{ checksum "package.json" }} - - run: - name: Install package dependencies - command: yarn --no-progress install --pure-lockfile - - save_cache: - key: dependency-cache-{{ checksum "package.json" }} - paths: - - node_modules - - run: - name: Test - command: npm test diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index a388ce7..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "env": { - "browser": true, - "node": true, - "jest": true - }, - "globals": { - "Promise": true - }, - "extends": "standard", - "plugins": [ "html" ], - "parser": "babel-eslint", - "rules": { - "indent": [ 2, 4 ], - - "no-multiple-empty-lines": [ 2, { "max": 1, "maxEOF": 0, "maxBOF": 0 } ], - - "no-use-before-define": [ 2, { "functions": false } ], - - "prefer-const": 1, - - "complexity": [ 1, 5 ] - }, - "settings": { - "html/indent": "0", - "html/report-bad-indent": 2 - } -} diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e7de049..66af280 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,34 +1,17 @@ # Contributing -Contributions are **welcome** and will be fully **credited**. +Contributions are **welcome** and will be **credited**. We accept contributions via Pull Requests on [Github](https://github.com/znck/rollup-plugin-vue). - ## Pull Requests - **Add tests!** - Your patch won't be accepted if it doesn't have tests. - -- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. - +- **Document any change in behavior** - Make sure the `README.md` and any other relevant documentation is kept up-to-date. - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. - - **Create feature branches** - Don't ask us to pull from your master branch. - - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. - -- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing. - +- **Send coherent history** - Make sure each commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing. - **Tip** to pass lint tests easier use the `npm run lint:fix` command. - -## Running Tests - -Launch mocha wih the watch option with: - -``` bash -$ npm run dev -``` - - **Happy coding**! diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..33d3497 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,5 @@ +open_collective: vuejs +patreon: evanyou +github: + - yyx990803 + - znck diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 3ec7ec9..edab8fc 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,5 +1 @@ -### Expected behavior - -### Actual behavior - -### Steps to reproduce the behavior +USE https://new-issue.vuejs.org/?repo=vuejs/rollup-plugin-vue diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..7c87f27 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,88 @@ +name: CI + +on: [push, pull_request] + +defaults: + run: + shell: bash + +jobs: + unit: + name: Unit tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup node_modules cache + uses: actions/cache@v1 + env: + cache-name: yarn + with: + path: .yarn + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + + - name: Install yarn + run: hash yarn 2>/dev/null || curl -s -L https://yarnpkg.com/install.sh | sudo node + + - name: Install dependencies and build packages + run: | + yarn config set cache-folder $(pwd)/.yarn + yarn install --frozen-lockfile + yarn run build + + - name: Run unit tests + run: yarn test:unit --coverage + + - uses: actions/upload-artifact@v2 + with: + name: coverage + path: coverage/ + + e2e: + name: E2E tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup node_modules cache + uses: actions/cache@v1 + env: + cache-name: yarn + with: + path: .yarn + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('yarn.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + + - name: Setup node_modules cache for fixtures + uses: actions/cache@v1 + env: + cache-name: fixtures + with: + path: examples/.yarn + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('examples/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + + - name: Install yarn + run: hash yarn 2>/dev/null || curl -s -L https://yarnpkg.com/install.sh | sudo node + + - name: Install dependencies and build packages + run: | + yarn config set cache-folder $(pwd)/.yarn + yarn install --frozen-lockfile + yarn run build + + - name: Install dependencies of fixtures + run: | + cd examples + yarn config set cache-folder $(pwd)/.yarn + yarn install --frozen-lockfile + + - name: Run e2e tests + run: yarn test:e2e diff --git a/.gitignore b/.gitignore index bcfae57..e956ddd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,6 @@ -dist/ -/.github/sereno/public -/_cache -test/style.css -output/ -# Logs -logs/ *.log -npm-debug.log* -docs/changelog.md - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -.coveralls.yml -b/ - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory +.DS_Store node_modules - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - +dist .idea -.DS_Store +coverage/ \ No newline at end of file diff --git a/.npmignore b/.npmignore index 94e308b..d3dd6be 100644 --- a/.npmignore +++ b/.npmignore @@ -1,9 +1 @@ -config/ -test/ -circle.yml -.gitignore -.eslintrc.json -CONDUCT.md -CONTRIBUTING.md -cover.png -.idea/ \ No newline at end of file +dist/test/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8edc751 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "markdownlint.config": { + "no-trailing-punctuation": false + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index d672c5a..e45b62c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,116 +1,210 @@ -# Change Log +# [6.0.0](https://github.com/vuejs/rollup-plugin-vue/compare/v6.0.0-beta.11...v6.0.0) (2020-11-25) -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - -# [4.3.0](https://github.com/vuejs/rollup-plugin-vue/compare/v4.2.0...v4.3.0) (2018-06-24) +### Features + +* new script setup compatibility ([d1a528f](https://github.com/vuejs/rollup-plugin-vue/commit/d1a528f77e0ba2dd174c9bc7d46b1f1753a6a04c)) +* support for new sfc experimental features ([d70f594](https://github.com/vuejs/rollup-plugin-vue/commit/d70f594f19087ed1440e44eb3f51e6b3ce1f298b)), closes [vuejs/rfcs#227](https://github.com/vuejs/rfcs/issues/227) [vuejs/rfcs#231](https://github.com/vuejs/rfcs/issues/231) + + + +# [6.0.0-beta.11](https://github.com/vuejs/rollup-plugin-vue/compare/v6.0.0-beta.9...v6.0.0-beta.11) (2020-11-02) ### Bug Fixes -* Transform `require` in render function compiled from ` diff --git a/test/fixtures/with-style.vue b/test/fixtures/with-style.vue deleted file mode 100644 index 72608aa..0000000 --- a/test/fixtures/with-style.vue +++ /dev/null @@ -1,17 +0,0 @@ - - - - - diff --git a/test/fixtures/with-template-comment.vue b/test/fixtures/with-template-comment.vue deleted file mode 100644 index 316a163..0000000 --- a/test/fixtures/with-template-comment.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - - - diff --git a/test/fixtures/with-template-functional-root.vue b/test/fixtures/with-template-functional-root.vue deleted file mode 100644 index 71aa25f..0000000 --- a/test/fixtures/with-template-functional-root.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/test/fixtures/with-template-functional.vue b/test/fixtures/with-template-functional.vue deleted file mode 100644 index 61c8050..0000000 --- a/test/fixtures/with-template-functional.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - diff --git a/test/fixtures/with-template-require-transform.vue b/test/fixtures/with-template-require-transform.vue deleted file mode 100644 index e189b01..0000000 --- a/test/fixtures/with-template-require-transform.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - diff --git a/test/setup/index.ts b/test/setup/index.ts deleted file mode 100644 index de44e91..0000000 --- a/test/setup/index.ts +++ /dev/null @@ -1,108 +0,0 @@ -import * as fs from 'fs' -import * as path from 'path' -import {Browser, Page} from 'puppeteer' -import {rollup} from 'rollup' -import promised from '@znck/promised' - -import {pluginCreateVueApp, plugins} from "./plugins" -import pluginVue from '../..' - -const pluginCSS = require('rollup-plugin-css-only') -const assets = require('postcss-assets') - -// -- rollup plugin inline file - -const cache = {} - -export async function build(filename, css = false): Promise { - const cacheKey = JSON.stringify({filename, css}) - if (cacheKey in cache) return cache[cacheKey] - let style: string | undefined - const input = filename + '__app.js' - const options = {defaultLang: {markdown: 'pluginMarkdown'}, css: css, style: { - postcssPlugins: [assets({ basePath: '/' })] - }} - const bundle = await rollup({ - input, - plugins: [ - pluginCreateVueApp(input, filename), - pluginCSS({ - output: (s: string) => { - style = s - } - }), - pluginVue(options), - ...plugins - ], - external: ['vue'] - }) - - const output = await bundle.generate({ - format: 'iife', - name: 'App', - sourcemap: true, - globals: { - vue: 'Vue' - } - }) - - let outputCode = output.code - - if (style) { - outputCode += `\n;(function() { - var s = document.createElement('style'); - s.type = 'text/css'; - document.head.appendChild(s); - s.appendChild(document.createTextNode(${JSON.stringify(style)})) - })()` - } - - outputCode += `\n\n//# sourceMappingURL=data:application/json;base64,${new Buffer(JSON.stringify(output.map)).toString('base64')}\n` - - cache[cacheKey] = outputCode - - return outputCode -} - -const VUE_SOURCE = promised(fs).readFile( - path.resolve(__dirname, '../../node_modules/vue/dist/vue.min.js') -) - -function encode(any: any) { - return any.toString().replace(/<\//g, '<\/') -} - -export async function open(name: string, browser: Browser, code: string, id: string = '#test'): Promise { - const page = await browser.newPage() - - const content = ` - - - - ${name} - - -
- - - - ` - - // Un-comment following lines to debug generated HTML. - if (!Boolean(process.env.CI)) { - const dir = path.join(__dirname, '../output') - - if (!await promised(fs).exists(dir)) await promised(fs).mkdir(dir) - await promised(fs).writeFile(path.join(dir, name + '.html'), content) - } - - await page.setContent(content) - - await page.waitFor(id) - - return page -} \ No newline at end of file diff --git a/test/setup/plugins.ts b/test/setup/plugins.ts deleted file mode 100644 index e524575..0000000 --- a/test/setup/plugins.ts +++ /dev/null @@ -1,61 +0,0 @@ -const pluginBabel = require('rollup-plugin-babel') -const pluginNodeResolve = require('rollup-plugin-node-resolve') -const pluginCommonJS = require('rollup-plugin-commonjs') -const pluginImage = require('rollup-plugin-url') -const pluginMarkdown = require('rollup-plugin-md') -const pluginTypescript = require('rollup-plugin-typescript') -const pluginReplace = require('rollup-plugin-replace') -const path = require('path') - -export const plugins = [ - pluginImage(), - pluginMarkdown(), - pluginNodeResolve(), - pluginCommonJS(), - pluginReplace({ 'process.env.NODE_ENV': '"production"' }), - pluginTypescript({ - tsconfig: false, - experimentalDecorators: true, - module: 'es2015' - }), - pluginBabel({ - presets: [ - [ - require.resolve('@babel/preset-env'), - { - modules: false, - targets: { - browsers: ['last 2 versions'] - } - } - ] - ], - babelrc: false, - runtimeHelpers: true - }) -] - -export function pluginCreateVueApp(filename: string, component: string): any { - return { - name: 'Inline', - resolveId(id) { - if (id === filename) return filename - }, - load(id) { - if (id === filename) - return ` - import Component from '${component}' - - Vue.config.productionTip = false - Vue.config.devtools = false - - new Vue({ - el: '#app', - render (h) { - return h(Component) - } - }) - ` - } - } -} diff --git a/test/transform.spec.ts b/test/transform.spec.ts new file mode 100644 index 0000000..30dc4a1 --- /dev/null +++ b/test/transform.spec.ts @@ -0,0 +1,170 @@ +import PluginVue from '../src/index' + +describe('Rollup Plugin Vue', () => { + describe('transform', () => { + let transform: (code: string, fileName: string) => Promise<{ code: string }> + beforeEach(() => { + transform = PluginVue({ customBlocks: ['*'] }).transform as any + }) + + it('should transform `, + `example.vue` + ) + + expect(code).toEqual( + expect.stringContaining( + `import script from "example.vue?vue&type=script&lang.js"` + ) + ) + expect(code).toEqual( + expect.stringContaining( + `export * from "example.vue?vue&type=script&lang.js"` + ) + ) + expect(code).toEqual(expect.stringContaining(`export default script`)) + }) + + it('should transform `, + `example.vue` + ) + + expect(code).toEqual( + expect.stringContaining( + `import script from "example.vue?vue&type=script&lang.ts"` + ) + ) + expect(code).toEqual( + expect.stringContaining( + `export * from "example.vue?vue&type=script&lang.ts"` + ) + ) + expect(code).toEqual(expect.stringContaining(`export default script`)) + }) + + it('should transform