Skip to content

Commit

Permalink
feat: update to jiti v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 25, 2024
1 parent c4ede69 commit 6c35c70
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
84 changes: 42 additions & 42 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions src/loader/loader.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;
ignoreDefaults?: boolean;
}
Expand All @@ -15,21 +14,19 @@ export async function loadSchema(
entryPath: string,
options: LoaderOptions = {},
): Promise<Schema> {
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,
});
Expand Down
19 changes: 13 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 6c35c70

Please sign in to comment.