Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"dist/"
],
"scripts": {
"build": "npx stencil build --docs",
"start": "npx stencil build",
"test": "npx stencil test --spec --e2e",
"test.watch": "npx stencil test --spec --e2e --watchAll"
},
"dependencies": {},
"devDependencies": {
"@stencil/core": "~0.15.2"
},
"license": "MIT"
}`;
// add extra files
files['tsconfig.json'] = `\
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"declaration": false,
"experimentalDecorators": true,
"lib": [
"dom",
"es2017"
],
"moduleResolution": "node",
"module": "esnext",
"target": "es2017",
"noUnusedLocals": true,
"noUnusedParameters": true,
"jsx": "react",
test('tsconfig.json should be valid json', async () => {
const { files } = await generateWithPlugin([
{
id: 'ts',
apply: require('../generator'),
options: {}
}
])
expect(() => {
JSON.parse(files['tsconfig.json'])
}).not.toThrow()
expect(files['tsconfig.json']).not.toMatch('" ')
})
apply: require('@vue/cli-plugin-unit-jest/generator'),
options: {}
},
{
id: '@vue/cli-plugin-typescript',
apply: require('../generator'),
options: {
lint: true,
lintOn: ['save', 'commit']
}
}
])
expect(pkg.devDependencies).toHaveProperty('@types/jest')
expect(files['tsconfig.json']).not.toMatch('" ')
})
api.postProcessFiles(files => {
debug('postProcessFiles called')
if (!api.hasPlugin('typescript')) { return }
const tsConfigRaw = files['tsconfig.json']
if (!tsConfigRaw) { return }
const tsConfig = JSON.parse(tsConfigRaw)
tsConfig.compilerOptions.types.push('webpack')
tsConfig.compilerOptions.types.push('webpack-env')
files['tsconfig.json'] = JSON.stringify(tsConfig, null, 2)
})
}
transform: function (context) {
var options = _.defaults({}, context.compileOptions, defaultCompileOptions);
var tsconfig = context.preview.files['tsconfig.json'];
if (typeof tsconfig !== 'undefined') {
try {
tsconfig = JSON.parse(tsconfig);
_.extend(options, tsconfig.compilerOptions);
} catch (__) {}
}
context.preview.files[context.requestPath] = '';
var compilerHost = {
getSourceFile: function (filename) {
return Typescript.createSourceFile(filename, context.preview.files[filename], options.target);
},
writeFile: function (filename, text) {
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
if (
parsed.compilerOptions.types &&
!parsed.compilerOptions.types.includes('jest')
) {
parsed.compilerOptions.types.push('jest')
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}
api.postProcessFiles(files => {
debug('postProcessFiles called')
if (!api.hasPlugin('typescript')) { return }
const tsConfigRaw = files['tsconfig.json']
if (!tsConfigRaw) { return }
const tsConfig = JSON.parse(tsConfigRaw)
tsConfig.compilerOptions.types.push('webpack')
tsConfig.compilerOptions.types.push('webpack-env')
files['tsconfig.json'] = JSON.stringify(tsConfig, null, 2)
})
}
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
const types = parsed.compilerOptions.types
if (types) {
if (!types.includes('mocha')) {
types.push('mocha')
}
if (!types.includes('chai')) {
types.push('chai')
}
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
const types = parsed.compilerOptions.types
if (types) {
if (!types.includes('mocha')) {
types.push('mocha')
}
if (!types.includes('chai')) {
types.push('chai')
}
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
if (
parsed.compilerOptions.types &&
!parsed.compilerOptions.types.includes('jest')
) {
parsed.compilerOptions.types.push('jest')
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}