From 70a15d626287ee83d466f4619f7c7435de4c997f Mon Sep 17 00:00:00 2001 From: Daniel Shields Date: Mon, 29 Jul 2024 11:27:12 +0200 Subject: [PATCH 1/4] Add "explicitFileExtensions" option for nodenext module resolution --- src/config.ts | 6 +++++- src/generators/wrappers/nullable.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index da0c1a0..7497138 100644 --- a/src/config.ts +++ b/src/config.ts @@ -40,7 +40,7 @@ const configSchema = Type.Object( */ nullableName: Type.String({ default: "__nullable__" }), /** - * Wethter to allow recursion in the generated schemes (enabling reduces code size) + * Wether to allow recursion in the generated schemes (enabling reduces code size) */ allowRecursion: Type.Boolean({ default: true }), /** @@ -63,6 +63,10 @@ const configSchema = Type.Object( * E.g. Date will be of Type String when enabled. */ useJsonTypes: Type.Boolean({ default: false }), + /** + * Wether to add ".js" extensions to src file imports to support nodenext module resolution + */ + explicitFileExtensions: Type.Boolean({ default: false }), }, { additionalProperties: false }, ); diff --git a/src/generators/wrappers/nullable.ts b/src/generators/wrappers/nullable.ts index e737e2a..d47b31c 100644 --- a/src/generators/wrappers/nullable.ts +++ b/src/generators/wrappers/nullable.ts @@ -12,7 +12,7 @@ export const ${getConfig().nullableName} = (schema: T) => ${ export function nullableImport() { return `import { ${getConfig().nullableName} } from "./${ getConfig().nullableName - }"\n`; + }${getConfig().explicitFileExtensions ? ".js" : ""}"\n`; } export function wrapWithNullable(input: string) { From 5f6063f02ab56f288626134506324d5287a88d79 Mon Sep 17 00:00:00 2001 From: Daniel Shields Date: Mon, 5 Aug 2024 10:53:23 +0200 Subject: [PATCH 2/4] Arbitrary import file extensions support --- src/generators/wrappers/nullable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/wrappers/nullable.ts b/src/generators/wrappers/nullable.ts index d47b31c..568b4a7 100644 --- a/src/generators/wrappers/nullable.ts +++ b/src/generators/wrappers/nullable.ts @@ -12,7 +12,7 @@ export const ${getConfig().nullableName} = (schema: T) => ${ export function nullableImport() { return `import { ${getConfig().nullableName} } from "./${ getConfig().nullableName - }${getConfig().explicitFileExtensions ? ".js" : ""}"\n`; + }${getConfig().importFileExtension}"\n`; } export function wrapWithNullable(input: string) { From 0b8d46300f96356ed10fa83d090e91887befd6bd Mon Sep 17 00:00:00 2001 From: Daniel Shields Date: Mon, 5 Aug 2024 10:53:35 +0200 Subject: [PATCH 3/4] Add import file extensions to barrel file --- src/barrel.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/barrel.ts b/src/barrel.ts index c8661a2..969cfb2 100644 --- a/src/barrel.ts +++ b/src/barrel.ts @@ -1,3 +1,5 @@ +import { getConfig } from "./config"; + export function generateBarrelFile(imports: string[]) { - return imports.map((i) => `export * from "./${i}";`).join("\n"); + return imports.map((i) => `export * from "./${i}${getConfig().importFileExtension}";`).join("\n"); } From 0f30ca3f5e55bb7317637ab7a407365310884037 Mon Sep 17 00:00:00 2001 From: Daniel Shields Date: Mon, 5 Aug 2024 10:54:57 +0200 Subject: [PATCH 4/4] Change file extension config option to "importFileExtension" --- src/config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index 7497138..bbf07a9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -40,7 +40,7 @@ const configSchema = Type.Object( */ nullableName: Type.String({ default: "__nullable__" }), /** - * Wether to allow recursion in the generated schemes (enabling reduces code size) + * Whether to allow recursion in the generated schemes (enabling reduces code size) */ allowRecursion: Type.Boolean({ default: true }), /** @@ -64,9 +64,9 @@ const configSchema = Type.Object( */ useJsonTypes: Type.Boolean({ default: false }), /** - * Wether to add ".js" extensions to src file imports to support nodenext module resolution + * What file extension, if any, to add to src file imports. Set to ".js" to support nodenext module resolution */ - explicitFileExtensions: Type.Boolean({ default: false }), + importFileExtension: Type.String({ default: '' }), }, { additionalProperties: false }, );