From 6c35c70a2486e6b8e13295075c5a5113e368ba4b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 26 Sep 2024 01:11:28 +0200 Subject: [PATCH] feat: update to jiti v2 --- package.json | 2 +- pnpm-lock.yaml | 84 ++++++++++++++++++++++---------------------- src/loader/loader.ts | 15 ++++---- tsconfig.json | 19 ++++++---- 4 files changed, 62 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index 09f22ad..624b85e 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@babel/standalone": "^7.25.6", "@babel/types": "^7.25.6", "defu": "^6.1.4", - "jiti": "^1.21.6", + "jiti": "^2.0.0", "mri": "^1.2.0", "scule": "^1.3.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 34c4f78..472a9d6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,8 +21,8 @@ importers: specifier: ^6.1.4 version: 6.1.4 jiti: - specifier: ^1.21.6 - version: 1.21.6 + specifier: ^2.0.0 + version: 2.0.0 mri: specifier: ^1.2.0 version: 1.2.0 @@ -53,10 +53,10 @@ importers: version: 0.5.7(magicast@0.3.5) eslint: specifier: ^9.11.1 - version: 9.11.1(jiti@1.21.6) + version: 9.11.1(jiti@2.0.0) eslint-config-unjs: specifier: ^0.4.0 - version: 0.4.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + version: 0.4.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) hljs: specifier: ^6.2.3 version: 6.2.3 @@ -71,7 +71,7 @@ importers: version: 0.52.0 nuxt: specifier: ^3.13.2 - version: 3.13.2(@parcel/watcher@2.4.1)(@types/node@22.7.2)(eslint@9.11.1(jiti@1.21.6))(ioredis@5.4.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)) + version: 3.13.2(@parcel/watcher@2.4.1)(@types/node@22.7.2)(eslint@9.11.1(jiti@2.0.0))(ioredis@5.4.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)) nuxt-windicss: specifier: ^3.0.1 version: 3.0.1(magicast@0.3.5)(rollup@3.29.5)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)) @@ -4776,9 +4776,9 @@ snapshots: '@esbuild/win32-x64@0.23.1': optional: true - '@eslint-community/eslint-utils@4.4.0(eslint@9.11.1(jiti@1.21.6))': + '@eslint-community/eslint-utils@4.4.0(eslint@9.11.1(jiti@2.0.0))': dependencies: - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) eslint-visitor-keys: 3.4.3 '@eslint-community/regexpp@4.11.1': {} @@ -5050,7 +5050,7 @@ snapshots: - supports-color - webpack-sources - '@nuxt/vite-builder@3.13.2(@types/node@22.7.2)(eslint@9.11.1(jiti@1.21.6))(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vue@3.5.8(typescript@5.6.2))': + '@nuxt/vite-builder@3.13.2(@types/node@22.7.2)(eslint@9.11.1(jiti@2.0.0))(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vue@3.5.8(typescript@5.6.2))': dependencies: '@nuxt/kit': 3.13.2(magicast@0.3.5)(rollup@3.29.5) '@rollup/plugin-replace': 5.0.7(rollup@3.29.5) @@ -5083,7 +5083,7 @@ snapshots: unplugin: 1.14.1 vite: 5.4.8(@types/node@22.7.2)(terser@5.33.0) vite-node: 2.1.1(@types/node@22.7.2)(terser@5.33.0) - vite-plugin-checker: 0.8.0(eslint@9.11.1(jiti@1.21.6))(optionator@0.9.4)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)) + vite-plugin-checker: 0.8.0(eslint@9.11.1(jiti@2.0.0))(optionator@0.9.4)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)) vue: 3.5.8(typescript@5.6.2) vue-bundle-renderer: 2.1.1 transitivePeerDependencies: @@ -5390,15 +5390,15 @@ snapshots: '@types/unist@2.0.11': {} - '@typescript-eslint/eslint-plugin@8.7.0(@typescript-eslint/parser@8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2))(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2)': + '@typescript-eslint/eslint-plugin@8.7.0(@typescript-eslint/parser@8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2))(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2)': dependencies: '@eslint-community/regexpp': 4.11.1 - '@typescript-eslint/parser': 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + '@typescript-eslint/parser': 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) '@typescript-eslint/scope-manager': 8.7.0 - '@typescript-eslint/type-utils': 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) - '@typescript-eslint/utils': 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + '@typescript-eslint/type-utils': 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) + '@typescript-eslint/utils': 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) '@typescript-eslint/visitor-keys': 8.7.0 - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) graphemer: 1.4.0 ignore: 5.3.2 natural-compare: 1.4.0 @@ -5408,14 +5408,14 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2)': + '@typescript-eslint/parser@8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2)': dependencies: '@typescript-eslint/scope-manager': 8.7.0 '@typescript-eslint/types': 8.7.0 '@typescript-eslint/typescript-estree': 8.7.0(typescript@5.6.2) '@typescript-eslint/visitor-keys': 8.7.0 debug: 4.3.7 - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) optionalDependencies: typescript: 5.6.2 transitivePeerDependencies: @@ -5426,10 +5426,10 @@ snapshots: '@typescript-eslint/types': 8.7.0 '@typescript-eslint/visitor-keys': 8.7.0 - '@typescript-eslint/type-utils@8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2)': + '@typescript-eslint/type-utils@8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2)': dependencies: '@typescript-eslint/typescript-estree': 8.7.0(typescript@5.6.2) - '@typescript-eslint/utils': 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + '@typescript-eslint/utils': 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) debug: 4.3.7 ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: @@ -5455,13 +5455,13 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2)': + '@typescript-eslint/utils@8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2)': dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1(jiti@1.21.6)) + '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1(jiti@2.0.0)) '@typescript-eslint/scope-manager': 8.7.0 '@typescript-eslint/types': 8.7.0 '@typescript-eslint/typescript-estree': 8.7.0(typescript@5.6.2) - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) transitivePeerDependencies: - supports-color - typescript @@ -6439,33 +6439,33 @@ snapshots: escape-string-regexp@5.0.0: {} - eslint-config-unjs@0.4.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2): + eslint-config-unjs@0.4.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2): dependencies: '@eslint/js': 9.11.1 - eslint: 9.11.1(jiti@1.21.6) - eslint-plugin-markdown: 5.1.0(eslint@9.11.1(jiti@1.21.6)) - eslint-plugin-unicorn: 55.0.0(eslint@9.11.1(jiti@1.21.6)) + eslint: 9.11.1(jiti@2.0.0) + eslint-plugin-markdown: 5.1.0(eslint@9.11.1(jiti@2.0.0)) + eslint-plugin-unicorn: 55.0.0(eslint@9.11.1(jiti@2.0.0)) globals: 15.9.0 typescript: 5.6.2 - typescript-eslint: 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + typescript-eslint: 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) transitivePeerDependencies: - supports-color - eslint-plugin-markdown@5.1.0(eslint@9.11.1(jiti@1.21.6)): + eslint-plugin-markdown@5.1.0(eslint@9.11.1(jiti@2.0.0)): dependencies: - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) mdast-util-from-markdown: 0.8.5 transitivePeerDependencies: - supports-color - eslint-plugin-unicorn@55.0.0(eslint@9.11.1(jiti@1.21.6)): + eslint-plugin-unicorn@55.0.0(eslint@9.11.1(jiti@2.0.0)): dependencies: '@babel/helper-validator-identifier': 7.24.7 - '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1(jiti@1.21.6)) + '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1(jiti@2.0.0)) ci-info: 4.0.0 clean-regexp: 1.0.0 core-js-compat: 3.38.1 - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) esquery: 1.6.0 globals: 15.9.0 indent-string: 4.0.0 @@ -6487,9 +6487,9 @@ snapshots: eslint-visitor-keys@4.0.0: {} - eslint@9.11.1(jiti@1.21.6): + eslint@9.11.1(jiti@2.0.0): dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1(jiti@1.21.6)) + '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1(jiti@2.0.0)) '@eslint-community/regexpp': 4.11.1 '@eslint/config-array': 0.18.0 '@eslint/core': 0.6.0 @@ -6527,7 +6527,7 @@ snapshots: strip-ansi: 6.0.1 text-table: 0.2.0 optionalDependencies: - jiti: 1.21.6 + jiti: 2.0.0 transitivePeerDependencies: - supports-color @@ -7476,14 +7476,14 @@ snapshots: - vite - webpack-sources - nuxt@3.13.2(@parcel/watcher@2.4.1)(@types/node@22.7.2)(eslint@9.11.1(jiti@1.21.6))(ioredis@5.4.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)): + nuxt@3.13.2(@parcel/watcher@2.4.1)(@types/node@22.7.2)(eslint@9.11.1(jiti@2.0.0))(ioredis@5.4.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)): dependencies: '@nuxt/devalue': 2.0.2 '@nuxt/devtools': 1.5.1(rollup@3.29.5)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0))(vue@3.5.8(typescript@5.6.2)) '@nuxt/kit': 3.13.2(magicast@0.3.5)(rollup@3.29.5) '@nuxt/schema': 3.13.2(rollup@3.29.5) '@nuxt/telemetry': 2.6.0(magicast@0.3.5)(rollup@3.29.5) - '@nuxt/vite-builder': 3.13.2(@types/node@22.7.2)(eslint@9.11.1(jiti@1.21.6))(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vue@3.5.8(typescript@5.6.2)) + '@nuxt/vite-builder': 3.13.2(@types/node@22.7.2)(eslint@9.11.1(jiti@2.0.0))(magicast@0.3.5)(optionator@0.9.4)(rollup@3.29.5)(terser@5.33.0)(typescript@5.6.2)(vue@3.5.8(typescript@5.6.2)) '@unhead/dom': 1.11.6 '@unhead/shared': 1.11.6 '@unhead/ssr': 1.11.6 @@ -8409,11 +8409,11 @@ snapshots: type-fest@3.13.1: {} - typescript-eslint@8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2): + typescript-eslint@8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2): dependencies: - '@typescript-eslint/eslint-plugin': 8.7.0(@typescript-eslint/parser@8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2))(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) - '@typescript-eslint/parser': 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) - '@typescript-eslint/utils': 8.7.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + '@typescript-eslint/eslint-plugin': 8.7.0(@typescript-eslint/parser@8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2))(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) + '@typescript-eslint/parser': 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) + '@typescript-eslint/utils': 8.7.0(eslint@9.11.1(jiti@2.0.0))(typescript@5.6.2) optionalDependencies: typescript: 5.6.2 transitivePeerDependencies: @@ -8659,7 +8659,7 @@ snapshots: - supports-color - terser - vite-plugin-checker@0.8.0(eslint@9.11.1(jiti@1.21.6))(optionator@0.9.4)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)): + vite-plugin-checker@0.8.0(eslint@9.11.1(jiti@2.0.0))(optionator@0.9.4)(typescript@5.6.2)(vite@5.4.8(@types/node@22.7.2)(terser@5.33.0)): dependencies: '@babel/code-frame': 7.24.7 ansi-escapes: 4.3.2 @@ -8677,7 +8677,7 @@ snapshots: vscode-languageserver-textdocument: 1.0.12 vscode-uri: 3.0.8 optionalDependencies: - eslint: 9.11.1(jiti@1.21.6) + eslint: 9.11.1(jiti@2.0.0) optionator: 0.9.4 typescript: 5.6.2 diff --git a/src/loader/loader.ts b/src/loader/loader.ts index ede8ce3..cdaabb8 100644 --- a/src/loader/loader.ts +++ b/src/loader/loader.ts @@ -1,12 +1,11 @@ import { defu } from "defu"; -import jiti from "jiti"; -import type { JITIOptions } from "jiti"; +import { createJiti, type JitiOptions } from "jiti"; import { resolveSchema } from "../schema"; -import type { Schema } from "../types"; +import type { InputObject, Schema } from "../types"; import untypedPlugin from "./babel"; export interface LoaderOptions { - jiti?: JITIOptions; + jiti?: JitiOptions; defaults?: Record; ignoreDefaults?: boolean; } @@ -15,21 +14,19 @@ export async function loadSchema( entryPath: string, options: LoaderOptions = {}, ): Promise { - const _jitiRequire = jiti( + const jiti = createJiti( process.cwd(), defu(options.jiti, { - esmResolve: true, interopDefault: true, transformOptions: { babel: { plugins: [[untypedPlugin, { experimentalFunctions: true }]], }, }, - }), + } satisfies JitiOptions), ); - const resolvedEntryPath = _jitiRequire.resolve(entryPath); - const rawSchema = _jitiRequire(resolvedEntryPath); + const rawSchema = await jiti.import(entryPath) as InputObject; const schema = await resolveSchema(rawSchema, options.defaults, { ignoreDefaults: options.ignoreDefaults, }); diff --git a/tsconfig.json b/tsconfig.json index bc4a107..60f4abb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,19 @@ { "compilerOptions": { "target": "ESNext", - "module": "ESNext", - "moduleResolution": "Node", + "module": "Preserve", "resolveJsonModule": true, - "esModuleInterop": true, - "strict": false, - "types": ["node"] + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "allowJs": true, + "checkJs": true, + "strict": true, + "verbatimModuleSyntax": true, + "isolatedModules": true, + "forceConsistentCasingInFileNames": true, + "noImplicitOverride": true, + "noEmit": true }, - "include": ["src"] + "include": ["src", "test"] }