Skip to content

Commit

Permalink
Use package name as suffix in import equals default declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Oct 18, 2023
1 parent 47ef3ad commit 666f18d
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 20 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Collection, JSCodeshift } from "jscodeshift";

import { getDefaultLocalName } from "../../utils";
import { getImportEqualsDeclaration } from "../getImportEqualsDeclaration";
import { getImportEqualsDeclarationType } from "../getImportEqualsDeclarationType";
import { getImportEqualsLocalNameSuffix } from "../getImportEqualsLocalNameSuffix";
import { ClientModulesOptions } from "../types";
import { getImportEqualsDefaultName } from "./getImportEqualsDefaultName";

export type ClientDefaultModuleOptions = Omit<ClientModulesOptions, "clientIdentifiers">;

Expand All @@ -13,8 +12,7 @@ export const addClientDefaultModule = (
source: Collection<unknown>,
{ v2ClientLocalName, v2ClientName, v2GlobalName, v3ClientPackageName }: ClientDefaultModuleOptions
) => {
const localNameSuffix = getImportEqualsLocalNameSuffix(v2ClientName, v3ClientPackageName);
const defaultLocalName = getDefaultLocalName(localNameSuffix);
const defaultLocalName = getImportEqualsDefaultName(v3ClientPackageName);
const existingImportEquals = source.find(
j.TSImportEqualsDeclaration,
getImportEqualsDeclarationType(v3ClientPackageName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { Collection, JSCodeshift } from "jscodeshift";

import { getDefaultLocalName } from "../../utils";
import { getImportEqualsDeclarationType } from "../getImportEqualsDeclarationType";
import { getImportEqualsLocalNameSuffix } from "../getImportEqualsLocalNameSuffix";
import { ClientModulesOptions, ImportSpecifierOptions } from "../types";
import { addClientDefaultModule } from "./addClientDefaultModule";
import { getImportEqualsDefaultName } from "./getImportEqualsDefaultName";

export const addClientNamedModule = (
j: JSCodeshift,
source: Collection<unknown>,
options: ClientModulesOptions & ImportSpecifierOptions
) => {
const { importedName, localName = importedName, ...v3ClientModulesOptions } = options;
const { v2ClientName, v3ClientPackageName } = v3ClientModulesOptions;
const { v3ClientPackageName } = v3ClientModulesOptions;

const localNameSuffix = getImportEqualsLocalNameSuffix(v2ClientName, v3ClientPackageName);
const defaultLocalName = getDefaultLocalName(localNameSuffix);
const defaultLocalName = getImportEqualsDefaultName(v3ClientPackageName);

const existingDeclaration = source.find(j.TSImportEqualsDeclaration, {
type: "TSImportEqualsDeclaration",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const getImportEqualsDefaultName = (packageName: string) =>
["AWS", ...packageName.split("/").pop()!.split("-")].join("_");
1 change: 0 additions & 1 deletion src/transforms/v2-to-v3/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./addClientModules";
export * from "./getGlobalNameFromModule";
export * from "./getImportEqualsDeclarationType";
export * from "./getImportEqualsLocalNameSuffix";
export * from "./getImportSpecifiers";
export * from "./getImportType";
export * from "./getRequireDeclaratorsWithProperty";
Expand Down
2 changes: 0 additions & 2 deletions src/transforms/v2-to-v3/utils/getDefaultLocalName.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/transforms/v2-to-v3/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./getClientDeepImportPath";
export * from "./getClientNewExpression";
export * from "./getDefaultLocalName";
export * from "./isTypeScriptFile";

0 comments on commit 666f18d

Please sign in to comment.