Skip to content
This repository was archived by the owner on Jun 27, 2022. It is now read-only.

Commit 1d6e67b

Browse files
committed
add patch scripts
1 parent 2478fd3 commit 1d6e67b

File tree

7 files changed

+387
-247
lines changed

7 files changed

+387
-247
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
22
dist
33
.tmp
4-
.DS_Stores
4+
.DS_Stores
5+
.envrc
6+
default.nix

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "aria-vue",
3-
"version": "0.4.1",
3+
"version": "0.4.1-beta.0",
44
"description": "Simple testing tools for vuejs",
55
"main": "aria-vue.js",
66
"bin": {
77
"aria-vue": "./bin/aria-vue.js"
88
},
99
"scripts": {
10+
"prepare": "node ./tools/patch.js",
1011
"build": "ts-node --project ./tools/tsconfig.json ./tools/build.ts"
1112
},
1213
"repository": {
@@ -41,7 +42,7 @@
4142
"@vue/test-utils": "^2.0.0-beta.3",
4243
"aria-build": "^0.5.2",
4344
"aria-fs": "^0.5.2",
44-
"aria-mocha": "^0.5.1",
45+
"aria-mocha": "^0.5.2",
4546
"puppeteer": "^5.2.1",
4647
"typescript": "^4.0.2",
4748
"vite": "^1.0.0-rc.4",

src/plugins/plugins.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
import { existsSync } from 'fs'
12
import { UserConfig } from 'vite'
23
import { normalizeOptions, Options } from '../common/common'
34

45
import { testPlugin } from './test-plugin'
56
import { watchPlugin } from './watch-plugin'
67

8+
function patchConfig() {
9+
const config = {
10+
...existsSync("./node_modules/@babel/parser/index.js") ? {
11+
alias: {
12+
"@babel/parser": "@babel/parser/index"
13+
}
14+
} : {}
15+
};
16+
return config;
17+
}
18+
719
export function createVueTestPlugin(options?: Options) {
820
const opts = normalizeOptions(options)
921

1022
const config: UserConfig = {
23+
...patchConfig(),
1124
configureServer: [
1225
testPlugin(opts),
1326
...(opts.watch ? [ watchPlugin(opts) ]: [])
14-
],
15-
optimizeDeps: {
16-
/// https://github.com/vitejs/vite/issues/669
17-
include: [ '@vue/test-utils' ]
18-
}
27+
]
1928
}
2029

2130
return config

tools/babel-parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { parse, parseExpression } from '@babel/parser'

tools/build.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import { bundle, clean, TSRollupConfig, copy, replaceContent, symlinkDir } from 'aria-build'
1+
import { bundle, clean, TSRollupConfig, copy, replaceContent, symlinkDir, writeFile } from 'aria-build'
22
import { builtinModules } from 'module'
33

44
(async function() {
55
const pkg = require('../package.json')
66

7+
async function addPostInstall() {
8+
const json = require('../dist/package.json')
9+
json.scripts = {
10+
"prepare": "node ./node_modules/aria-vue/tools/patch.js"
11+
}
12+
await writeFile('./dist/package.json', JSON.stringify(json, null, 2))
13+
}
14+
715
const external = [
816
'sade',
917
...Object.keys(pkg.dependencies),
1018
...Object.keys(pkg.peerDependencies),
1119
...Object.keys(pkg.devDependencies),
12-
...builtinModules
20+
...builtinModules,
21+
'rollup',
22+
'@rollup/plugin-node-resolve',
23+
'@rollup/plugin-commonjs'
1324
]
1425

1526
function replace(filename: string) {
@@ -28,7 +39,8 @@ import { builtinModules } from 'module'
2839
copy({
2940
targets: [
3041
{ src: './src/*.html', dest: 'dist' },
31-
{ src: 'bin/*', dest: 'dist/bin', replace }
42+
{ src: 'bin/*', dest: 'dist/bin', replace },
43+
{ src: './tools/*.js', dest: './dist/tools' }
3244
]
3345
})
3446
],
@@ -54,6 +66,7 @@ import { builtinModules } from 'module'
5466

5567
await clean('dist')
5668
await bundle({ config, esbuild: true, write: true })
69+
await addPostInstall()
5770
await Promise.all([
5871
symlinkDir('./node_modules', './example/node_modules'),
5972
symlinkDir('./dist', './node_modules/aria-vue')

tools/patch.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(async function() {
2+
const { rollup } = require('rollup')
3+
const { join } = require('path')
4+
5+
const resolve = require('@rollup/plugin-node-resolve')
6+
const commonjs = require('@rollup/plugin-commonjs')
7+
8+
async function patchBabelParser() {
9+
const bundle = await rollup({
10+
input: join(__dirname, 'babel-parser.js'),
11+
plugins: [commonjs(), resolve.default()]
12+
});
13+
await bundle.write({
14+
file: "./node_modules/@babel/parser/index.js",
15+
format: "es",
16+
sourcemap: true
17+
})
18+
}
19+
20+
await patchBabelParser()
21+
})()

0 commit comments

Comments
 (0)