Skip to content
Permalink
Browse files

refactor(ts): better DX for typescript support (#5079)

Breaking change : `build.useForkTsChecker` renamed to `build.typescript.typeCheck`
  • Loading branch information...
kevinmarrec authored and pi0 committed Mar 14, 2019
1 parent 8216765 commit 920f444b6eb840b0f8a697539d4afa45c0b9abea
Showing with 299 additions and 257 deletions.
  1. +1 −0 .eslintignore
  2. +5 −18 distributions/nuxt-ts/bin/nuxt-ts.js
  3. +2 −2 examples/pm2-typescript/ecosystem.config.js
  4. +6 −7 examples/pm2-typescript/package.json
  5. +1 −10 examples/pm2-typescript/tsconfig.json
  6. +0 −9 examples/pm2-typescript/tslint.json
  7. +9 −0 examples/typescript-eslint/.eslintrc.js
  8. +15 −0 examples/typescript-eslint/.gitignore
  9. +33 −0 examples/typescript-eslint/README.md
  10. +1 −0 examples/typescript-eslint/nuxt.config.ts
  11. +30 −0 examples/typescript-eslint/package.json
  12. +14 −0 examples/typescript-eslint/pages/index.vue
  13. +1 −0 examples/typescript-eslint/tsconfig.json
  14. +6 −8 examples/typescript-tsx/package.json
  15. +2 −4 examples/typescript-tsx/tsconfig.json
  16. +0 −7 examples/typescript-tsx/tslint.json
  17. +6 −7 examples/typescript-vuex/package.json
  18. +1 −11 examples/typescript-vuex/tsconfig.json
  19. +0 −9 examples/typescript-vuex/tslint.json
  20. +6 −7 examples/typescript/package.json
  21. +1 −10 examples/typescript/tsconfig.json
  22. +0 −9 examples/typescript/tslint.json
  23. +7 −1 packages/cli/src/command.js
  24. +17 −14 packages/cli/src/utils/index.js
  25. +38 −0 packages/cli/src/utils/typescript.js
  26. +1 −1 packages/cli/test/unit/__snapshots__/command.test.js.snap
  27. +3 −1 packages/config/src/config/build.js
  28. +1 −1 packages/config/src/config/index.js
  29. +1 −1 packages/config/src/options.js
  30. +3 −1 packages/config/test/__snapshots__/options.test.js.snap
  31. +6 −2 packages/config/test/config/__snapshots__/index.test.js.snap
  32. +2 −7 packages/typescript/package.json
  33. +36 −32 packages/typescript/src/index.js
  34. +7 −20 packages/typescript/test/setup.test.js
  35. +0 −30 packages/typescript/tsconfig.json
  36. +11 −17 packages/webpack/src/config/client.js
  37. +24 −2 test/fixtures/typescript/tsconfig.json
  38. +1 −1 test/unit/typescript.modern.test.js
  39. +1 −8 yarn.lock
@@ -9,6 +9,7 @@ coverage
## cofeescript
examples/coffeescript/pages/index.vue
examples/pug-stylus-coffee/
examples/typescript-eslint/
# Packages

# vue-app
@@ -1,21 +1,8 @@
#!/usr/bin/env node

const { resolve } = require('path')

// Globally indicate we are running in ts mode
process.env.NUXT_TS = 'true'

const nuxtCommands = ['dev', 'build', 'generate', 'start']
const rootDir = (process.argv[2] && !nuxtCommands.includes(process.argv[2])) ? process.argv[2] : process.cwd()
const tsConfigPath = resolve(rootDir, 'tsconfig.json')

const suffix = require('../package.json').name.includes('-edge') ? '-edge' : ''

const errorHandler = (error) => {
require('consola').fatal(error)
process.exit(2)
}

require('@nuxt/typescript' + suffix).setup(tsConfigPath).then(() => {
require('@nuxt/cli' + suffix).run().catch(errorHandler)
}).catch(errorHandler)
require('@nuxt/cli' + suffix).run()
.catch((error) => {
require('consola').fatal(error)
process.exit(2)
})
@@ -1,8 +1,8 @@
module.exports = {
apps: [
{
name: 'pm2-nuxt-ts',
script: './node_modules/.bin/nuxt-ts',
name: 'pm2-nuxt-typescript',
script: './node_modules/.bin/nuxt',
args: 'start',
instances: 2,
exec_mode: 'cluster',
@@ -2,17 +2,16 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"nuxt-ts": "latest",
"nuxt": "latest",
"vue-property-decorator": "^7.3.0"
},
"scripts": {
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start",
"generate": "nuxt-ts generate",
"lint": "tslint --project ."
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"devDependencies": {
"tslint-config-standard": "^8.0.1"
"@nuxt/typescript": "latest"
}
}
@@ -1,10 +1 @@
{
"extends": "@nuxt/typescript",
"compilerOptions": {
"baseUrl": ".",
"types": [
"@types/node",
"@nuxt/vue-app"
]
}
}
{}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,9 @@
module.exports = {
plugins: ['@typescript-eslint'],
parserOptions: {
parser: '@typescript-eslint/parser'
},
extends: [
'@nuxtjs'
]
}
@@ -0,0 +1,15 @@
# Dependencies
node_modules

# Logs
*.log*

# IDE
.idea
.vscode

# Nuxt build
.nuxt

# Nuxt generate
dist
@@ -0,0 +1,33 @@
# Nuxt with TypeScript & ESLint example

Use `yarn lint` or `npm run lint` to lint your TypeScript project !

## Why ESLint and not TSLint ?

See https://eslint.org/blog/2019/01/future-typescript-eslint

##

## VSCode settings

If you're using VSCode, we recommend using these settings :

```json
"eslint.autoFixOnSave": true,
"eslint.validate": [
{
"language": "javascript",
"autoFix": true
},
{
"language": "typescript",
"autoFix": true
},
{
"language": "vue",
"autoFix": true
}
]
```

It will lint your `.js`, `.ts` & `.vue` files whenever you're saving them.
@@ -0,0 +1 @@
export default {}
@@ -0,0 +1,30 @@
{
"version": "1.0.0",
"private": true,
"dependencies": {
"nuxt": "latest",
"vue-property-decorator": "^7.3.0"
},
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint": "eslint --ext .ts,.js,.vue --ignore-path .gitignore .",
"lint:fix": "yarn lint --fix",
"post-update": "yarn upgrade --latest"
},
"devDependencies": {
"@nuxt/typescript": "latest",
"@nuxtjs/eslint-config": "latest",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"eslint": "^5.14.1",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.3.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.2.2"
}
}
@@ -0,0 +1,14 @@
<template>
<div>
<h1>{{ title }}</h1>
</div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component
export default class Home extends Vue {
title = 'TypeScript + ESLint example'
}
</script>
@@ -0,0 +1 @@
{}
@@ -3,20 +3,18 @@
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start",
"generate": "nuxt-ts generate",
"lint": "tslint --project .",
"lint:fix": "tslint --project . --fix",
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"post-update": "yarn upgrade --latest",
"watch:css": "tcm components -w"
},
"dependencies": {
"nuxt-ts": "latest"
"nuxt": "latest"
},
"devDependencies": {
"tslint-config-standard": "^8.0.1",
"@nuxt/typescript": "latest",
"typed-css-modules": "^0.3.7"
}
}
@@ -1,8 +1,6 @@
{
"extends": "@nuxt/typescript",
"compilerOptions": {
"baseUrl": ".",
"noImplicitThis": true,
"types": ["@types/node", "@nuxt/vue-app"]
"jsx": "preserve",
"noImplicitThis": true
}
}

This file was deleted.

Oops, something went wrong.
@@ -3,20 +3,19 @@
"private": true,
"dependencies": {
"axios": "^0.18.0",
"nuxt-ts": "latest",
"nuxt": "latest",
"tachyons": "^4.11.1",
"vue-property-decorator": "^7.3.0",
"vuex-class": "^0.3.1"
},
"scripts": {
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start",
"generate": "nuxt-ts generate",
"lint": "tslint --project .",
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"post-update": "yarn upgrade --latest"
},
"devDependencies": {
"tslint-config-standard": "^8.0.1"
"@nuxt/typescript": "latest"
}
}
@@ -1,11 +1 @@
{
"extends": "@nuxt/typescript",
"compilerOptions": {
"baseUrl": ".",
"noImplicitAny": false,
"types": [
"@types/node",
"@nuxt/vue-app"
]
}
}
{}

This file was deleted.

Oops, something went wrong.
@@ -2,18 +2,17 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"nuxt-ts": "latest",
"nuxt": "latest",
"vue-property-decorator": "^7.3.0"
},
"scripts": {
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start",
"generate": "nuxt-ts generate",
"lint": "tslint --project .",
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"post-update": "yarn upgrade --latest"
},
"devDependencies": {
"tslint-config-standard": "^8.0.1"
"@nuxt/typescript": "latest"
}
}
@@ -1,10 +1 @@
{
"extends": "@nuxt/typescript",
"compilerOptions": {
"baseUrl": ".",
"types": [
"@types/node",
"@nuxt/vue-app"
]
}
}
{}

This file was deleted.

Oops, something went wrong.
@@ -1,9 +1,12 @@

import path from 'path'
import consola from 'consola'
import minimist from 'minimist'
import { name, version } from '../package.json'
import { loadNuxtConfig, forceExit } from './utils'
import { indent, foldLines, colorize } from './utils/formatting'
import { startSpaces, optionSpaces, forceExitTimeout } from './utils/constants'
import { detectAndSetupTypeScriptSupport } from './utils/typescript'
import * as imports from './imports'

export default class NuxtCommand {
@@ -73,7 +76,10 @@ export default class NuxtCommand {
return this._parsedArgv
}

async getNuxtConfig(extraOptions) {
async getNuxtConfig(extraOptions = {}) {
const rootDir = path.resolve(this.argv._[0] || '.')
extraOptions._typescript = await detectAndSetupTypeScriptSupport(rootDir, { transpileOnly: this.cmd.name === 'start' })

const config = await loadNuxtConfig(this.argv)
const options = Object.assign(config, extraOptions)

Oops, something went wrong.

0 comments on commit 920f444

Please sign in to comment.
You can’t perform that action at this time.