diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..9d08a1a8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..29741968 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +dist +playground-temp +temp diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 00000000..59a3579c --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,197 @@ +// @ts-check +const { builtinModules } = require('node:module') +const { defineConfig } = require('eslint-define-config') + +module.exports = defineConfig({ + root: true, + extends: [ + 'eslint:recommended', + 'plugin:node/recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:regexp/recommended' + ], + plugins: ['import', 'regexp'], + 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', '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-extraneous-import': [ + 'error', + { + allowModules: ['vite', 'less', 'sass', 'vitest'] + } + ], + '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/explicit-module-boundary-types': [ + 'error', + { allowArgumentsExplicitlyTypedAsAny: true } + ], + '@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', + '@typescript-eslint/consistent-type-imports': [ + 'error', + { prefer: 'type-imports' } + ], + + 'import/no-nodejs-modules': [ + 'error', + { allow: builtinModules.map((mod) => `node:${mod}`) } + ], + 'import/no-duplicates': 'error', + 'import/order': 'error', + 'sort-imports': [ + 'error', + { + ignoreCase: false, + ignoreDeclarationSort: true, + ignoreMemberSort: false, + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], + allowSeparatedGroups: false + } + ], + + 'regexp/no-contradiction-with-assertion': 'error' + }, + overrides: [ + { + files: ['packages/**'], + excludedFiles: '**/__tests__/**', + rules: { + 'no-restricted-globals': ['error', 'require', '__dirname', '__filename'] + } + }, + { + files: 'packages/vite/**/*.*', + rules: { + '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.` + })) + ] + } + }, + { + files: ['packages/vite/src/node/**'], + rules: { + 'no-console': ['error'] + } + }, + { + files: ['packages/vite/src/types/**', '*.spec.ts'], + rules: { + 'node/no-extraneous-import': 'off' + } + }, + { + files: ['packages/create-vite/template-*/**', '**/build.config.ts'], + rules: { + 'no-undef': 'off', + 'node/no-missing-import': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off' + } + }, + { + files: ['playground/**'], + rules: { + 'node/no-extraneous-import': 'off', + 'node/no-extraneous-require': 'off', + 'node/no-missing-import': 'off', + 'node/no-missing-require': 'off', + // engine field doesn't exist in playgrounds + 'node/no-unsupported-features/es-builtins': [ + 'error', + { + version: '^14.18.0 || >=16.0.0' + } + ], + 'node/no-unsupported-features/node-builtins': [ + 'error', + { + version: '^14.18.0 || >=16.0.0' + } + ], + '@typescript-eslint/explicit-module-boundary-types': 'off' + } + }, + { + files: ['playground/**'], + excludedFiles: '**/__tests__/**', + rules: { + 'no-undef': 'off', + 'no-empty': 'off', + 'no-constant-condition': 'off', + '@typescript-eslint/no-empty-function': 'off' + } + }, + { + files: ['*.js', '*.mjs', '*.cjs'], + rules: { + '@typescript-eslint/explicit-module-boundary-types': 'off' + } + }, + { + files: ['*.d.ts'], + rules: { + '@typescript-eslint/triple-slash-reference': 'off' + } + } + ], + reportUnusedDisableDirectives: true +}) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6313b56c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f7fc8786 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +!**/glob-import/dir/node_modules +.DS_Store +.idea +*.cpuprofile +*.local +*.log +/.vscode/ +dist +dist-ssr +explorations +node_modules +playground-temp +temp +TODOs.md +.eslintcache diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..4d97f291 --- /dev/null +++ b/.npmrc @@ -0,0 +1,10 @@ +hoist-pattern[]=*eslint* +hoist-pattern[]=*babel* +hoist-pattern[]=@emotion/* +hoist-pattern[]=postcss +hoist-pattern[]=pug +hoist-pattern[]=source-map-support +hoist-pattern[]=ts-node +strict-peer-dependencies=false +shell-emulator=true +auto-install-peers=false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..e7938c73 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +packages/*/CHANGELOG.md +playground-temp/ +dist/ +temp/ +LICENSE.md +pnpm-lock.yaml +pnpm-workspace.yaml diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..3a87ddf3 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,22 @@ +{ + "semi": false, + "tabWidth": 2, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "none", + "overrides": [ + { + "files": ["*.json5"], + "options": { + "singleQuote": false, + "quoteProps": "preserve" + } + }, + { + "files": ["*.yml"], + "options": { + "singleQuote": false + } + } + ] +}