diff --git a/.changeset/tasty-scissors-call.md b/.changeset/tasty-scissors-call.md new file mode 100644 index 000000000..10c21e354 --- /dev/null +++ b/.changeset/tasty-scissors-call.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-kit-routes': patch +--- + +fix: type when there is no element in the Record diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index bca93eae8..000000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,46 +0,0 @@ -module.exports = { - root: true, - extends: '@theguild', - rules: { - 'unicorn/no-array-push-push': 'off', - 'unicorn/filename-case': 'off', - '@typescript-eslint/no-explicit-any': 'off', - 'no-console': ['error', { allow: ['info', 'warn', 'error', 'time', 'timeEnd'] }], - 'no-restricted-syntax': 'off', - 'import/no-default-export': 'off', - '@typescript-eslint/ban-types': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/no-namespace': 'off', - '@typescript-eslint/ban-ts-comment': 'off', - '@typescript-eslint/require-await': 'off', - 'import/extensions': 'off', - 'simple-import-sort/imports': 'off', - }, - ignorePatterns: [ - 'examples', - 'website', - 'dist', - 'vite.config.ts', - 'svelte.config.js', - 'graphql.config.cjs', - 'babel.config.js', - '.eslintrc.cjs', - '.prettierrc.cjs', - ], - plugins: ['svelte3'], - overrides: [ - // { files: ['*.svelte'], processor: 'svelte3/svelte3' }, - // { - // files: ['packages/helper/*.ts'], - // parserOptions: { project: ['packages/helper/tsconfig.json'] }, - // }, - ], - settings: { - 'svelte3/typescript': () => require('typescript'), - }, - parserOptions: { - sourceType: 'module', - ecmaVersion: 2020, - project: ['./tsconfig.json'], - }, -} diff --git a/.prettierignore b/.prettierignore index 549b61c91..e29b680b9 100644 --- a/.prettierignore +++ b/.prettierignore @@ -16,4 +16,5 @@ $houdini $kitql stats.html -db/ \ No newline at end of file +db/ +ROUTES_* \ No newline at end of file diff --git a/packages/eslint-config-kitql/.eslintignore b/packages/eslint-config-kitql/.eslintignore deleted file mode 100644 index 90759f18a..000000000 --- a/packages/eslint-config-kitql/.eslintignore +++ /dev/null @@ -1,11 +0,0 @@ -# prj files -node_modules - -# svelte files -build -.svelte-kit - -# Ignore files for PNPM, NPM and YARN -pnpm-lock.yaml -package-lock.json -yarn.lock diff --git a/packages/eslint-config-kitql/index.cjs b/packages/eslint-config-kitql/index.cjs index bf4aa0cfb..d890c76eb 100644 --- a/packages/eslint-config-kitql/index.cjs +++ b/packages/eslint-config-kitql/index.cjs @@ -1,7 +1,12 @@ module.exports = { root: true, parser: '@typescript-eslint/parser', - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'prettier', + 'plugin:svelte/recommended', + ], plugins: ['unused-imports', 'svelte', '@typescript-eslint'], rules: { 'no-console': ['error', { allow: ['info', 'warn', 'error', 'time', 'timeEnd'] }], @@ -10,6 +15,7 @@ module.exports = { '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/ban-types': 'error', }, overrides: [ { diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts index f8ac4401b..1128d1d6f 100644 --- a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts +++ b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts @@ -34,8 +34,14 @@ export const PAGES = { }) => { return `${params?.lang ? `/${params?.lang}` : ''}/match/${params.id}` }, - lang_site: (params: { lang?: 'fr' | 'en' | 'hu' | 'at' | string; limit?: number } = {}) => { - return `${params?.lang ? `/${params?.lang}` : ''}/site${appendSp({ limit: params.limit })}` + lang_site: ( + params: { lang?: 'fr' | 'en' | 'hu' | 'at' | string; limit?: number } = {}, + sp?: Record, + ) => { + return `${params?.lang ? `/${params?.lang}` : ''}/site${appendSp({ + ...sp, + limit: params.limit, + })}` }, lang_site_id: ( params: { lang?: 'fr' | 'hu' | undefined; id?: string; limit?: number; demo?: string } = {}, diff --git a/packages/vite-plugin-kit-routes/src/lib/plugin.ts b/packages/vite-plugin-kit-routes/src/lib/plugin.ts index e8b2cf332..0dcca6caf 100644 --- a/packages/vite-plugin-kit-routes/src/lib/plugin.ts +++ b/packages/vite-plugin-kit-routes/src/lib/plugin.ts @@ -591,6 +591,13 @@ const shouldLog = (kind: LogKind, options?: Options) => { return options.logs.includes(kind) } +const arrayToRecord = (arr?: string[]) => { + if (arr && arr.length > 0) { + return `: { ${arr.join(', ')} }` + } + return `: Record` +} + export const run = (options?: Options) => { let files = getFilesUnder(routes_path()) @@ -703,8 +710,8 @@ const appendSp = (sp?: Record, prefix: '?' export type KIT_ROUTES = { ${objTypes .map(c => { - return ` ${c.type}: { ${c.files - .map(d => { + return ` ${c.type}${arrayToRecord( + c.files.map(d => { return `'${d.keyToUse}': ${ d.paramsFromPath.filter(e => e.fromPath === true).length === 0 ? 'never' @@ -715,15 +722,15 @@ ${objTypes }) .join(' | ') }` - }) - .join(', ')} }` + }), + )}` }) .join('\n')} - Params: { ${[ + Params${arrayToRecord([ ...new Set( objTypes.flatMap(c => c.files.flatMap(d => d.paramsFromPath.map(e => `${e.name}: never`))), ), - ].join(', ')} } + ])} } `, ]) diff --git a/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts b/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts index 6970299c2..cb4575adc 100644 --- a/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts +++ b/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts @@ -223,7 +223,6 @@ describe('run()', () => { extra_search_params: 'with', }, lang_site: { - // extra_search_params: 'with', explicit_search_params: { limit: { type: 'number' } }, params: { // yop: { type: 'number' }, @@ -541,7 +540,6 @@ describe('run()', () => { extra_search_params: 'with', }, lang_site: { - // extra_search_params: 'with', explicit_search_params: { limit: { type: 'number' } }, params: { // yop: { type: 'number' }, @@ -705,7 +703,7 @@ describe('run()', () => { }) }) - it('with_ase', () => { + it('with path base', () => { const generated_file_path = 'src/test/ROUTES_test5.ts' run({ generated_file_path, @@ -723,7 +721,6 @@ describe('run()', () => { extra_search_params: 'with', }, lang_site: { - // extra_search_params: 'with', explicit_search_params: { limit: { type: 'number' } }, params: { // yop: { type: 'number' }, diff --git a/packages/vite-plugin-kit-routes/src/test/.gitignore b/packages/vite-plugin-kit-routes/src/test/.gitignore index 68e3dc4c6..383202dc7 100644 --- a/packages/vite-plugin-kit-routes/src/test/.gitignore +++ b/packages/vite-plugin-kit-routes/src/test/.gitignore @@ -1 +1 @@ -ROUTES* +ROUTES_* diff --git a/packages/vite-plugin-kit-routes/vite.config.ts b/packages/vite-plugin-kit-routes/vite.config.ts index 3273c4f49..59d7f5bb6 100644 --- a/packages/vite-plugin-kit-routes/vite.config.ts +++ b/packages/vite-plugin-kit-routes/vite.config.ts @@ -26,7 +26,7 @@ export default defineConfig({ }, }, lang_site: { - // extra_search_params: 'with', + extra_search_params: 'with', explicit_search_params: { limit: { type: 'number' } }, params: { // yop: { type: 'number' },