Skip to content

Commit 07ac887

Browse files
committed
fix: stringifyJS should be used in all call sites
1 parent 83f5f4f commit 07ac887

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

packages/@vue/cli/__tests__/Generator.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs-extra')
44
const path = require('path')
55
const Generator = require('../lib/Generator')
66
const { logs } = require('@vue/cli-shared-utils')
7-
const stringifyJS = require('javascript-stringify')
7+
const stringifyJS = require('../util/stringifyJS')
88

99
// prepare template fixtures
1010
const templateDir = path.resolve(__dirname, 'template')

packages/@vue/cli/__tests__/invoke.spec.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ const parseJS = file => {
1111
return res.exports
1212
}
1313

14+
const baseESLintConfig = Object.assign({}, require('@vue/cli-plugin-eslint/eslintOptions').config({
15+
hasPlugin: () => false
16+
}), {
17+
rules: {
18+
'no-console': 'off',
19+
'no-debugger': 'off'
20+
}
21+
})
22+
1423
async function createAndInstall (name) {
1524
const project = await create(name, {
1625
plugins: {
@@ -33,10 +42,9 @@ async function assertUpdates (project) {
3342
})
3443

3544
const eslintrc = parseJS(await project.read('.eslintrc.js'))
36-
expect(eslintrc).toEqual({
37-
root: true,
45+
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
3846
extends: ['plugin:vue/essential', '@vue/airbnb']
39-
})
47+
}))
4048

4149
const lintedMain = await project.read('src/main.js')
4250
expect(lintedMain).toMatch(';') // should've been linted in post-generate hook
@@ -85,10 +93,9 @@ test('invoke with existing files', async () => {
8593
await project.write('vue.config.js', `module.exports = { lintOnSave: true }`)
8694

8795
const eslintrc = parseJS(await project.read('.eslintrc.js'))
88-
expect(eslintrc).toEqual({
89-
root: true,
96+
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
9097
extends: ['plugin:vue/essential', 'eslint:recommended']
91-
})
98+
}))
9299

93100
await project.run(`${require.resolve('../bin/vue')} invoke eslint --config airbnb --lintOn commit`)
94101

@@ -111,10 +118,9 @@ test('invoke with existing files (yaml)', async () => {
111118
await project.write('package.json', JSON.stringify(pkg, null, 2))
112119

113120
const eslintrc = parseJS(await project.read('.eslintrc.js'))
114-
expect(eslintrc).toEqual({
115-
root: true,
121+
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
116122
extends: ['plugin:vue/essential', 'eslint:recommended']
117-
})
123+
}))
118124

119125
await project.rm(`.eslintrc.js`)
120126
await project.write(`.eslintrc.yml`, `
@@ -128,10 +134,9 @@ extends:
128134

129135
const updated = await project.read('.eslintrc.yml')
130136
expect(updated).toMatch(`
131-
root: true
132137
extends:
133138
- 'plugin:vue/essential'
134-
- '@vue/airbnb'
139+
- 'eslint:recommended'
135140
`.trim())
136141
})
137142

packages/@vue/cli/lib/GeneratorAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const resolve = require('resolve')
77
const isBinary = require('isbinaryfile')
88
const yaml = require('yaml-front-matter')
99
const mergeDeps = require('./util/mergeDeps')
10-
const stringifyJS = require('javascript-stringify')
10+
const stringifyJS = require('./util/stringifyJS')
1111
const { getPluginLink, toShortPluginId } = require('@vue/cli-shared-utils')
1212

1313
const isString = val => typeof val === 'string'

packages/@vue/cli/lib/util/configTransforms.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
const fs = require('fs')
22
const path = require('path')
33
const extendJSConfig = require('./extendJSConfig')
4-
const stringify = require('javascript-stringify')
5-
6-
function stringifyJS (value) {
7-
return stringify(value, (val, indent, stringify) => {
8-
if (val && val.__expression) {
9-
return val.__expression
10-
}
11-
return stringify(val)
12-
}, 2)
13-
}
4+
const stringifyJS = require('./stringifyJS')
145

156
function makeJSTransform (filename) {
167
return function transformToJS (value, checkExisting, context) {

packages/@vue/cli/lib/util/extendJSConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function extendJSConfig (value, source) {
22
const recast = require('recast')
3-
const stringifyJS = require('javascript-stringify')
3+
const stringifyJS = require('./stringifyJS')
44

55
let exportsIdentifier = null
66

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const stringify = require('javascript-stringify')
2+
3+
module.exports = function stringifyJS (value) {
4+
return stringify(value, (val, indent, stringify) => {
5+
if (val && val.__expression) {
6+
return val.__expression
7+
}
8+
return stringify(val)
9+
}, 2)
10+
}

0 commit comments

Comments
 (0)