Skip to content

Commit

Permalink
fix: Import flag normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen committed Dec 18, 2024
1 parent 77f2b25 commit 011f91b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ try {
}
importSpinner.succeed("Schema resolved");

const baseImport = args.import.replace(/\/$/, "");
const options = {
baseUrls: args["base-urls"]?.split(","),
includeAbsoluteUrl: args["include-absolute-url"],
Expand All @@ -119,33 +120,33 @@ const source = project.createSourceFile(output, undefined, {

source.addImportDeclaration({
isTypeOnly: true,
moduleSpecifier: `${args["import"]}/types/json${
URL.canParse(args["import"]) ? ".ts" : ""
moduleSpecifier: `${baseImport}/types/json${
URL.canParse(baseImport) ? ".ts" : ""
}`,
namedImports: ["JSONString"],
});

source.addImportDeclaration({
isTypeOnly: true,
moduleSpecifier: `${args["import"]}/types/headers${
URL.canParse(args["import"]) ? ".ts" : ""
moduleSpecifier: `${baseImport}/types/headers${
URL.canParse(baseImport) ? ".ts" : ""
}`,
namedImports: ["TypedHeadersInit"],
});

if (options.experimentalURLSearchParams) {
source.addImportDeclaration({
isTypeOnly: true,
moduleSpecifier: `${args["import"]}/types/url_search_params_string${
URL.canParse(args["import"]) ? ".ts" : ""
moduleSpecifier: `${baseImport}/types/url_search_params_string${
URL.canParse(baseImport) ? ".ts" : ""
}`,
namedImports: ["URLSearchParamsString"],
});
} else {
source.addImportDeclaration({
isTypeOnly: true,
moduleSpecifier: `${args["import"]}/types/url_search_params${
URL.canParse(args["import"]) ? ".ts" : ""
moduleSpecifier: `${baseImport}/types/url_search_params${
URL.canParse(baseImport) ? ".ts" : ""
}`,
namedImports: ["URLSearchParamsString"],
});
Expand Down

0 comments on commit 011f91b

Please sign in to comment.