Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpaige committed Nov 28, 2024
1 parent a74f16b commit dc66ab8
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 61 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions lib/packages/shared-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"@radix-ui/react-select": "^1.0.0",
"@radix-ui/react-switch": "^1.0.0",
"react-day-picker": "^8.0.0",
"react-hook-form": "^7.0.0",
"shared-utils": "workspace:*"
"react-hook-form": "^7.0.0"
},
"peerDependencies": {
"react": "*",
Expand Down
11 changes: 7 additions & 4 deletions lib/packages/shared-types/src/attachments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { s3ParseUrl } from "../shared-utils/s3-url-parser";
import { s3ParseUrl } from "shared-utils";

export const attachmentTitleMap = {
// SPA
Expand Down Expand Up @@ -28,9 +28,12 @@ export const attachmentTitleMap = {
supportingDocumentation: "Supporting Documentation",
bCapWaiverApplication: "1915(b) Comprehensive (Capitated) Waiver Application Pre-print",
bCapCostSpreadsheets: "1915(b) Comprehensive (Capitated) Waiver Cost Effectiveness Spreadsheets",
bCapIndependentAssessment: "1915(b) Comprehensive (Capitated) Waiver Independent Assessment (first two renewals only)",
b4WaiverApplication: "1915(b)(4) FFS Selective Contracting (Streamlined) Waiver Application Pre-print",
b4IndependentAssessment: "1915(b)(4) FFS Selective Contracting (Streamlined) Independent Assessment (first two renewals only)",
bCapIndependentAssessment:
"1915(b) Comprehensive (Capitated) Waiver Independent Assessment (first two renewals only)",
b4WaiverApplication:
"1915(b)(4) FFS Selective Contracting (Streamlined) Waiver Application Pre-print",
b4IndependentAssessment:
"1915(b)(4) FFS Selective Contracting (Streamlined) Independent Assessment (first two renewals only)",
appk: "1915(c) Appendix K Amendment Waiver Template",
waiverExtensionRequest: "Waiver Extension Request",
};
Expand Down
2 changes: 2 additions & 0 deletions lib/packages/shared-types/src/opensearch/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ export const transforms = {
"respond-to-rai": respondToRai,
"upload-subsequent-documents": uploadSubsequentDocuments,
};

type TargetType = string | number | bigint | boolean;
2 changes: 1 addition & 1 deletion lib/packages/shared-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"resolveJsonModule": true,
"verbatimModuleSyntax": false
},
"include": ["./**/*.ts"],
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
10 changes: 10 additions & 0 deletions lib/packages/shared-types/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ export default defineConfig({
format: ["esm", "cjs"],
dts: true,
clean: true,
external: [
"react-hook-form",
"react-day-picker",
"@radix-ui/react-radio-group",
"@radix-ui/react-switch",
"@radix-ui/react-select",
"shared-types",
"../shared-utils/s3-url-parser",
"../../../../shared-utils/seatool-date-helper",
],
});
10 changes: 3 additions & 7 deletions lib/packages/shared-utils/package-actions/getAvailableActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action, CognitoUserAttributes, opensearch } from "../../shared-types";
import { Action, CognitoUserAttributes, opensearch } from "shared-types";
import rules from "./rules";
import { PackageCheck } from "../package-check";

Expand Down Expand Up @@ -30,14 +30,10 @@ export const getAvailableActions = (
const allRaiRequestedDates = allMembers.map((member) => {
return member.raiRequestedDate;
});
const isRaiRequestedDateIdentical = allRaiRequestedDates.every(
(date, _, arr) => date === arr[0],
);
const isRaiRequestedDateIdentical = allRaiRequestedDates.every((date, _, arr) => date === arr[0]);
if (!isRaiRequestedDateIdentical) {
const actionsToRemove = [Action.RESPOND_TO_RAI, Action.WITHDRAW_RAI];
commonActions = commonActions.filter(
(action: any) => !actionsToRemove.includes(action),
);
commonActions = commonActions.filter((action: any) => !actionsToRemove.includes(action));
}
return commonActions;
};
5 changes: 3 additions & 2 deletions lib/packages/shared-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"dependencies": {
"shared-types": "workspace:*",
"moment-timezone": "~0.5.45"
"@18f/us-federal-holidays": "^4.0.0",
"moment-timezone": "~0.5.45",
"shared-types": "workspace:*"
},
"devDependencies": {
"shared-config": "workspace:*",
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@
"zod": "~3.22.3"
},
"devDependencies": {
"@vitest/coverage-v8": "~2.0.5",
"@vitest/ui": "~2.0.5",
"vitest": "~2.1.1",
"@playwright/test": "^1.49.0",
"typescript": "~5.6.2",
"@types/node": "~22.7.4",
"eslint": "~9.10.0",
"eslint-config-custom": "workspace:*",
"@typescript-eslint/eslint-plugin": "~8.5.0",
"@typescript-eslint/parser": "~8.5.0",
"turbo": "~2.1.2",
"ts-node": "~10.9.2",
"@vitest/coverage-v8": "~2.0.5",
"@vitest/ui": "~2.0.5",
"eslint": "~9.10.0",
"eslint-config-custom": "workspace:*",
"husky": "~8.0.0",
"prettier": "~3.0.0",
"husky": "~8.0.0"
"ts-node": "~10.9.2",
"turbo": "^2.3.3",
"typescript": "~5.6.2",
"vitest": "~2.1.1"
},
"resolutions": {
"typescript": "~5.6.2",
Expand Down
68 changes: 32 additions & 36 deletions scripts/dependency-check.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync } from 'fs';
import { join } from 'path';
import * as glob from 'glob';
import { describe, it, expect } from "vitest";
import { readFileSync, readdirSync } from "fs";
import { join } from "path";
import * as glob from "glob";

interface PackageJson {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
}

describe('Dependency Usage', () => {
const workspaces = [
'.',
'react-app',
'lib/packages/shared-types',
'lib/packages/shared-utils'
];
describe("Dependency Usage", () => {
const workspaces = [".", "react-app", "lib/packages/shared-types", "lib/packages/shared-utils"];

// Helper to read package.json
const readPackageJson = (path: string): PackageJson => {
return JSON.parse(readFileSync(join(process.cwd(), path, 'package.json'), 'utf8'));
return JSON.parse(readFileSync(join(process.cwd(), path, "package.json"), "utf8"));
};

// Helper to check if a package is used in source files
const isPackageUsed = (packageName: string, sourceDir: string): boolean => {
const files = glob.sync(`${sourceDir}/**/*.{ts,tsx,js,jsx}`);

return files.some(file => {
const content = readFileSync(file, 'utf8');
return content.includes(`from '${packageName}'`) ||
content.includes(`require('${packageName}')`);

return files.some((file) => {
const content = readFileSync(file, "utf8");
return (
content.includes(`from '${packageName}'`) || content.includes(`require('${packageName}')`)
);
});
};

it('all dependencies should be used in source code', () => {
workspaces.forEach(workspace => {
it("all dependencies should be used in source code", () => {
workspaces.forEach((workspace) => {
const pkg = readPackageJson(workspace);
const sourceDir = join(process.cwd(), workspace, 'src');
const sourceDir = join(process.cwd(), workspace, "src");

// Skip if no src directory
if (!readdirSync(join(process.cwd(), workspace)).includes('src')) {
if (!readdirSync(join(process.cwd(), workspace)).includes("src")) {
return;
}

// Check dependencies
Object.keys(pkg.dependencies || {}).forEach(dep => {
Object.entries(pkg.dependencies || {}).forEach(([dep, version]) => {
// Skip workspace packages and types
if (dep.startsWith('@types/') || dep.includes('workspace:')) {
if (dep.startsWith("@types/") || version.includes("workspace:")) {
return;
}

Expand All @@ -56,17 +52,17 @@ describe('Dependency Usage', () => {
});
});

it('should not have duplicate dependencies across workspaces', () => {
it("should not have duplicate dependencies across workspaces", () => {
const depsMap = new Map<string, string[]>();

workspaces.forEach(workspace => {
workspaces.forEach((workspace) => {
const pkg = readPackageJson(workspace);
const allDeps = {
...(pkg.dependencies || {}),
...(pkg.devDependencies || {})
...(pkg.devDependencies || {}),
};

Object.keys(allDeps).forEach(dep => {
Object.keys(allDeps).forEach((dep) => {
if (!depsMap.has(dep)) {
depsMap.set(dep, []);
}
Expand All @@ -78,33 +74,33 @@ describe('Dependency Usage', () => {
depsMap.forEach((workspaceList, dep) => {
if (workspaceList.length > 1) {
// Allow certain packages to be duplicated
const allowedDuplicates = ['typescript', '@types/node', 'eslint'];
const allowedDuplicates = ["typescript", "@types/node", "eslint"];
if (!allowedDuplicates.includes(dep)) {
expect(
workspaceList,
`${dep} is duplicated in workspaces: ${workspaceList.join(', ')}`
`${dep} is duplicated in workspaces: ${workspaceList.join(", ")}`,
).toHaveLength(1);
}
}
});
});

it('should use consistent versions across workspaces', () => {
it("should use consistent versions across workspaces", () => {
const versionMap = new Map<string, string>();

workspaces.forEach(workspace => {
workspaces.forEach((workspace) => {
const pkg = readPackageJson(workspace);
const allDeps = {
...(pkg.dependencies || {}),
...(pkg.devDependencies || {})
...(pkg.devDependencies || {}),
};

Object.entries(allDeps).forEach(([dep, version]) => {
if (!version.includes('workspace:')) {
if (!version.includes("workspace:")) {
if (versionMap.has(dep)) {
expect(
version,
`${dep} has inconsistent versions: ${version} vs ${versionMap.get(dep)}`
`${dep} has inconsistent versions: ${version} vs ${versionMap.get(dep)}`,
).toBe(versionMap.get(dep));
} else {
versionMap.set(dep, version);
Expand All @@ -113,4 +109,4 @@ describe('Dependency Usage', () => {
});
});
});
});
});

0 comments on commit dc66ab8

Please sign in to comment.