Skip to content

Commit

Permalink
feat: typescript rewrite (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Apr 8, 2022
1 parent 7529bf6 commit 21767c5
Show file tree
Hide file tree
Showing 23 changed files with 4,508 additions and 4,546 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@nuxtjs/eslint-config-typescript"
]
}
6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: ci
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
ci:
Expand All @@ -16,15 +16,15 @@ jobs:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
node: [10, 12, 14, 15]
node: [12]

steps:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v3

- name: cache node_modules
uses: actions/cache@v3
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_modules
.DS_Store
coverage
dist
sw.*
.env
5 changes: 0 additions & 5 deletions commitlint.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions husky.config.js

This file was deleted.

5 changes: 2 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
collectCoverage: true,
collectCoverageFrom: ['lib/**/*.js'],
testEnvironment: 'node'
preset: '@nuxt/test-utils',
collectCoverageFrom: ['src/**']
}
3 changes: 0 additions & 3 deletions lib/logger.js

This file was deleted.

46 changes: 0 additions & 46 deletions lib/module.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/utils.js

This file was deleted.

30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,35 @@
"contributors": [
"Ricardo Gobbo de Souza <ricardogobbosouza@yahoo.com.br>"
],
"main": "lib/module.js",
"main": "./dist/module.js",
"types": "./dist/module.d.ts",
"files": [
"lib"
"dist"
],
"scripts": {
"dev": "nuxt test/fixture",
"lint": "eslint --ext .js,.vue .",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && jest"
"build": "siroc build",
"prepublishOnly": "yarn build",
"dev": "nuxt dev test/fixture/basic",
"lint": "eslint --ext .js,.ts,.vue .",
"release": "yarn test && yarn build && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && yarn jest"
},
"dependencies": {
"consola": "^2.15.3",
"defu": "^6.0.0",
"eslint-webpack-plugin": "^2.6.0"
},
"devDependencies": {
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@nuxtjs/eslint-config": "latest",
"@nuxtjs/module-test-utils": "latest",
"@babel/preset-typescript": "latest",
"@nuxt/test-utils": "latest",
"@nuxt/types": "latest",
"@nuxtjs/eslint-config-typescript": "latest",
"@types/jest": "latest",
"@types/node": "latest",
"eslint": "latest",
"husky": "latest",
"jest": "latest",
"nuxt-edge": "latest",
"nuxt": "latest",
"siroc": "latest",
"standard-version": "latest"
},
"peerDependencies": {
Expand Down
65 changes: 65 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { resolve } from 'path'
import consola from 'consola'
import { defu } from 'defu'
import type { Module } from '@nuxt/types'
import type { Options } from 'eslint-webpack-plugin'
import { name, version } from '../package.json'
import { moduleExists } from './utils'

const logger = consola.withTag('nuxt:eslint')

export interface ModuleOptions extends Partial<Options>{}

const CONFIG_KEY = 'eslint'

const nuxtModule: Module<ModuleOptions> = function (moduleOptions) {
const DEFAULTS: ModuleOptions = {
context: this.options.srcDir,
eslintPath: 'eslint',
extensions: ['js', 'ts', 'vue'],
cache: true,
lintDirtyModulesOnly: true
}

const options: ModuleOptions = defu(
this.options[CONFIG_KEY],
moduleOptions,
DEFAULTS
)

if (!moduleExists(options.eslintPath)) {
logger.warn(
`The dependency \`${options.eslintPath}\` not found.`,
'Please run `yarn add eslint --dev` or `npm install eslint --save-dev`'
)
return
}

const filesToWatch = [
'.eslintrc',
'.eslintrc.json',
'.eslintrc.yaml',
'.eslintrc.yml',
'.eslintrc.js'
]

this.options.watch = this.options.watch || []
this.options.watch.push(...filesToWatch.map(file => resolve(this.options.rootDir, file)))

this.extendBuild((config, { isDev, isClient }) => {
if (isDev && isClient) {
const EslintPlugin = require('eslint-webpack-plugin')

config.plugins.push(new EslintPlugin(options))
}
})
}

;(nuxtModule as any).meta = { name, version }

declare module '@nuxt/types' {
interface NuxtConfig { [CONFIG_KEY]?: ModuleOptions } // Nuxt 2.14+
interface Configuration { [CONFIG_KEY]?: ModuleOptions } // Nuxt 2.9 - 2.13
}

export default nuxtModule
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function moduleExists (name) {
try {
return require.resolve(name)
} catch (e) {
return false
}
}
18 changes: 0 additions & 18 deletions test/dev.test.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/dev.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { setupTest, get } from '@nuxt/test-utils'

describe('dev', () => {
setupTest({
fixture: 'fixture',
server: true,
config: {
dev: true
}
})

test('render', async () => {
const { body } = await get('/')
expect(body).toContain('Works!')
})
})
6 changes: 3 additions & 3 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
export default {
rootDir: __dirname,
buildModules: [
{ handler: require('../../') }
modules: [
'../../src/module.ts'
]
}
2 changes: 1 addition & 1 deletion test/fixture/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

<script>
export default {
name: 'PageIndex'
}
</script>
18 changes: 0 additions & 18 deletions test/prod.test.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/prod.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { setupTest, get } from '@nuxt/test-utils'

describe('prod', () => {
setupTest({
fixture: 'fixture',
server: true,
config: {
dev: false
}
})

test('render', async () => {
const { body } = await get('/')
expect(body).toContain('Works!')
})
})
36 changes: 0 additions & 36 deletions test/warn.test.js

This file was deleted.

0 comments on commit 21767c5

Please sign in to comment.