diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 00000000..578e0041 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,133 @@ +// @ts-check +const { defineConfig } = require('eslint-define-config') + +module.exports = defineConfig({ + root: true, + extends: [ + 'eslint:recommended', + 'plugin:node/recommended', + 'plugin:@typescript-eslint/recommended' + ], + parser: '@typescript-eslint/parser', + parserOptions: { + sourceType: 'module', + ecmaVersion: 2021 + }, + rules: { + eqeqeq: ['warn', 'always', { null: 'never' }], + 'no-debugger': ['error'], + 'no-empty': ['warn', { allowEmptyCatch: true }], + 'no-process-exit': 'off', + 'no-useless-escape': 'off', + 'prefer-const': [ + 'warn', + { + destructuring: 'all' + } + ], + + 'node/no-missing-import': [ + 'error', + { + allowModules: [ + 'types', + 'estree', + 'testUtils', + 'less', + 'sass', + 'stylus' + ], + tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'] + } + ], + 'node/no-missing-require': [ + 'error', + { + // for try-catching yarn pnp + allowModules: ['pnpapi', 'vite'], + tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'] + } + ], + 'node/no-restricted-require': [ + 'error', + Object.keys(require('./packages/vite/package.json').devDependencies).map( + (d) => ({ + name: d, + message: + `devDependencies can only be imported using ESM syntax so ` + + `that they are included in the rollup bundle. If you are trying to ` + + `lazy load a dependency, use (await import('dependency')).default instead.` + }) + ) + ], + 'node/no-extraneous-import': [ + 'error', + { + allowModules: ['vite', 'less', 'sass'] + } + ], + 'node/no-extraneous-require': [ + 'error', + { + allowModules: ['vite'] + } + ], + 'node/no-deprecated-api': 'off', + 'node/no-unpublished-import': 'off', + 'node/no-unpublished-require': 'off', + 'node/no-unsupported-features/es-syntax': 'off', + + '@typescript-eslint/ban-ts-comment': 'off', // TODO: we should turn this on in a new PR + '@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR + '@typescript-eslint/no-empty-function': [ + 'error', + { allow: ['arrowFunctions'] } + ], + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-explicit-any': 'off', // maybe we should turn this on in a new PR + '@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier + '@typescript-eslint/no-inferrable-types': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', // maybe we should turn this on in a new PR + '@typescript-eslint/no-unused-vars': 'off', // maybe we should turn this on in a new PR + '@typescript-eslint/no-var-requires': 'off' + }, + overrides: [ + { + files: ['packages/vite/src/node/**'], + rules: { + 'no-console': ['error'] + } + }, + { + files: ['packages/vite/types/**'], + rules: { + 'node/no-extraneous-import': 'off' + } + }, + { + files: ['packages/playground/**'], + rules: { + 'node/no-extraneous-import': 'off', + 'node/no-extraneous-require': 'off' + } + }, + { + files: ['packages/create-vite/template-*/**'], + rules: { + 'node/no-missing-import': 'off' + } + }, + { + files: ['*.js'], + rules: { + '@typescript-eslint/explicit-module-boundary-types': 'off' + } + }, + { + files: ['*.d.ts'], + rules: { + '@typescript-eslint/triple-slash-reference': 'off' + } + } + ] +}) diff --git a/package.json b/package.json index c2c231d8..1343fc1c 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ }, "gitHooks": { "pre-commit": "lint-staged --concurrent false", - "commit-msg": "node scripts/verifyCommit.js" + "commit-msg": "node scripts/verifyCommit.cjs" }, "lint-staged": { "*": [ diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 7099ded6..3a400dda 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -11,7 +11,7 @@ "types": "index.d.ts", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx", - "release": "node ../../scripts/release.js --skipBuild" + "release": "node ../../scripts/release.cjs --skipBuild" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index b2bdc3d3..41001dc5 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -16,7 +16,7 @@ "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue", - "release": "node ../../scripts/release.js" + "release": "node ../../scripts/release.cjs" }, "engines": { "node": ">=12.0.0" diff --git a/scripts/jestEnv.js b/scripts/jestEnv.cjs similarity index 100% rename from scripts/jestEnv.js rename to scripts/jestEnv.cjs diff --git a/scripts/jestGlobalSetup.js b/scripts/jestGlobalSetup.cjs similarity index 100% rename from scripts/jestGlobalSetup.js rename to scripts/jestGlobalSetup.cjs diff --git a/scripts/jestGlobalTeardown.js b/scripts/jestGlobalTeardown.cjs similarity index 100% rename from scripts/jestGlobalTeardown.js rename to scripts/jestGlobalTeardown.cjs diff --git a/scripts/patchFileDeps.js b/scripts/patchFileDeps.cjs similarity index 100% rename from scripts/patchFileDeps.js rename to scripts/patchFileDeps.cjs diff --git a/scripts/release.js b/scripts/release.cjs similarity index 100% rename from scripts/release.js rename to scripts/release.cjs diff --git a/scripts/verifyCommit.js b/scripts/verifyCommit.cjs similarity index 100% rename from scripts/verifyCommit.js rename to scripts/verifyCommit.cjs