Skip to content

Commit

Permalink
Feat ts 5.0 (#223)
Browse files Browse the repository at this point in the history
* fix: deprecate UserManagement, UserBase, OidcUserBase

* fix: simplify WebDeployment custom resource building

* feat: upgrade to TS 5.0

* fix: update pnpm-lock

* fix: ts errors from stitches code; temporarily remove .d.ts declarations to resolve issues with stitches and TS 5.0

* fix: use tsx instead of ts-node
  • Loading branch information
bestickley authored Jul 10, 2023
1 parent 5a5a9fc commit 7af36c2
Show file tree
Hide file tree
Showing 202 changed files with 1,441 additions and 1,333 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-meals-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gboost-infra": minor
---

Deprecate `UserManagement`, `UserBase`, and `OidcUserBase` because they're poor abstraction layers. User directory/pool infra is very custom and consuming developers will need to open source code to learn what's being abstracted. Recommend developers use AWS CDK's Cognito L3 constructs to setup user pools and identity providers if using Cognito and for user management developers can see `gboost create` auth template
5 changes: 5 additions & 0 deletions .changeset/nice-squids-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gboost-ui": minor
---

Deprecate `UserManagement`
9 changes: 9 additions & 0 deletions .changeset/tidy-laws-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"gboost-common": minor
"gboost-infra": minor
"gboost-node": minor
"gboost-ui": minor
"gboost": minor
---

Upgrade to TS 5.0 and enforce stricter configuration
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"./packages/gboost-node",
"./packages/gboost-ui"
],
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.tsdk": "node_modules/typescript/lib",
"search.exclude": {
"**/node_modules": true,
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/tips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tips

## JavaScript

- Avoid `export * from "./some-file"`. It makes tracking down imported functions/classes difficult.
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typedoc": "^0.23.28",
"typedoc-plugin-markdown": "^3.14.0"
"typedoc-plugin-markdown": "~3.14.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "2.3.1",
Expand All @@ -42,7 +42,7 @@
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.8",
"typescript": "~4.9.5"
"typescript": "~5.1.6"
},
"browserslist": {
"production": [
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
"test": "pnpm --recursive --filter \"./packages/**\" --parallel test",
"prepare": "husky install",
"changeset-version": "ts-node scripts/changeset-version.ts",
"license-check": "ts-node scripts/license-check.ts",
"license-check": "tsx scripts/license-check.ts",
"preinstall": "npx only-allow pnpm"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@tsconfig/esm": "^1.0.4",
"@tsconfig/node18": "^18.2.0",
"@tsconfig/strictest": "^2.0.1",
"@types/license-checker": "^25.0.3",
"@types/node": "^18.16.19",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"tsx": "^3.12.7",
"typescript": "^5.1.6"
},
"license": "Apache-2.0",
"pnpm": {
Expand Down
9 changes: 5 additions & 4 deletions packages/gboost-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@tsconfig/node18-strictest-esm": "^1.0.1",
"@tsconfig/esm": "^1.0.4",
"@tsconfig/node18": "^18.2.0",
"@tsconfig/strictest": "^2.0.1",
"@types/node": "^18.16.19",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
Expand All @@ -36,10 +38,9 @@
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.8",
"rimraf": "^4.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"typescript": "^5.1.6",
"vite": "^4.4.2",
"vitest": "^0.29.8"
"vitest": "^0.33.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/gboost-common/src/convert-case.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect } from "vitest";
import { camelToKebab } from "./convert-case.js";
import { camelToKebab } from "./convert-case";

describe("convertCase.ts", () => {
const camelCase = "longVariableName";
Expand Down
21 changes: 17 additions & 4 deletions packages/gboost-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
export * from "./convert-case.js";
export * from "./user-management.js";
export * from "./merge-deep.js";
export * from "./get-error-message.js";
export {
camelToKebab,
camelToSnake,
lowerToPascal,
pascalToKebabCase,
} from "./convert-case";
export {
type CognitoGroup,
type CognitoUser,
CognitoUserStatus,
CreateCognitoUser,
type Filter,
type ListUsersArgs,
type ListUsersInGroupArgs,
} from "./user-management";
export { mergeDeep } from "./merge-deep";
export { getErrorMessage } from "./get-error-message";
6 changes: 3 additions & 3 deletions packages/gboost-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "@tsconfig/node18-strictest-esm/tsconfig.json",
"extends": ["@tsconfig/strictest", "@tsconfig/esm", "@tsconfig/node18"],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"exactOptionalPropertyTypes": false,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"outDir": "lib",
"skipLibCheck": true,
},
Expand Down
17 changes: 9 additions & 8 deletions packages/gboost-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"lib/**/*"
],
"scripts": {
"build": "ts-node scripts/build.ts",
"build": "tsx scripts/build.ts",
"lint": "eslint \"src/**/*.ts\"",
"test": "vitest run",
"typecheck": "tsc --noEmit"
Expand All @@ -47,32 +47,33 @@
"mime-types": "^2.1.35"
},
"peerDependencies": {
"aws-cdk-lib": "^2.87.0",
"aws-cdk-lib": "^2.72.1",
"cdk-nag": "^2.25.2",
"constructs": "^10.1.300"
},
"devDependencies": {
"@aws-lambda-powertools/logger": "^1.11.0",
"@aws-sdk/client-s3": "^3.367.0",
"@aws-sdk/s3-request-presigner": "^3.367.0",
"@tsconfig/node18-strictest-esm": "^1.0.1",
"@tsconfig/esm": "^1.0.4",
"@tsconfig/node18": "^18.2.0",
"@tsconfig/strictest": "^2.0.1",
"@types/adm-zip": "^0.5.0",
"@types/aws-lambda": "^8.10.119",
"@types/mime-types": "^2.1.1",
"@types/node": "^18.16.19",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"esbuild": "^0.17.19",
"esbuild": "^0.18.11",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-define-config": "^1.21.0",
"eslint-plugin-prettier": "^4.2.1",
"joi": "^17.9.2",
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"vite": "^4.4.2",
"vitest": "^0.29.8"
"tsx": "^3.12.7",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
},
"repository": {
"type": "git",
Expand Down
40 changes: 40 additions & 0 deletions packages/gboost-infra/scripts/build-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { fileURLToPath } from "node:url";
import { resolve } from "node:path";
import { build } from "esbuild";

interface BuildFunctionProps {
/**
* Path relative to gboost-infra/src
*/
entryPointPath: string;
/**
* Path relative to gboost-infra/lib
*/
outFilePath: string;
}

const thisFilePath = fileURLToPath(import.meta.url);
const libDir = resolve(thisFilePath, "../../lib");
const srcDir = resolve(thisFilePath, "../../src");

/**
* We need a separate build step for building functions used in custom resources
* because `tsc` (used to "build" other source code in gboost-infra) only converts
* from .ts to .js, it doesn't transpile and minify so we use esbuild.
*/
export async function buildFunction(params: BuildFunctionProps) {
return build({
entryPoints: [resolve(srcDir, params.entryPointPath)],
bundle: true,
external: ["@aws-sdk/*"],
outfile: resolve(libDir, params.outFilePath),
platform: "node",
target: "node18",
minify: true,
format: "esm",
sourcemap: true,
banner: {
js: `import module from 'module';if (typeof globalThis.require === "undefined"){globalThis.require = module.createRequire(import.meta.url);}`,
},
});
}
38 changes: 0 additions & 38 deletions packages/gboost-infra/scripts/build-web-deployment-cr.ts

This file was deleted.

14 changes: 8 additions & 6 deletions packages/gboost-infra/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { execSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { cpSync, rmSync, statSync } from "node:fs";
import { resolve } from "node:path";
import { buildWebDeploymentCr } from "./build-web-deployment-cr.js";
import { buildFunction } from "./build-function.js";
import { execSync } from "node:child_process";

const thisFilePath = fileURLToPath(import.meta.url);

const libDir = resolve(thisFilePath, "../../lib");
const srcDir = resolve(thisFilePath, "../../src");

rmSync(libDir, { recursive: true, force: true });
execSync("pnpm exec tsc -p tsconfig.build.json", { stdio: "inherit" });
// bundle and minify WebDeployment custom resource lambda with esbuild
// (./src/web-deployment/custom-resource-handler)
// bundle and minify functions with esbuild
// Note, tsconfig.build.json ignores these files so tsc transpiled js files
// don't overrwrite esbuild built files
await buildWebDeploymentCr();
await buildFunction({
entryPointPath: "web-deployment/web-deploy-cr-handler.ts",
outFilePath: "web-deployment/web-deploy-cr-handler.mjs",
});
// needed for vtl and js files that aren't built with tsc
cpSync(srcDir, libDir, {
filter(source: string, destination: string) {
Expand Down
6 changes: 3 additions & 3 deletions packages/gboost-infra/src/aspects/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./gov-cloud-compat.js";
export * from "./suppress-nags/suppress-nags.js";
export * from "./suppress-nags/suppression.js";
export { GovCloudCompat } from "./gov-cloud-compat.js";
export { SuppressNags } from "./suppress-nags/suppress-nags.js";
export { Suppression } from "./suppress-nags/suppression.js";
16 changes: 8 additions & 8 deletions packages/gboost-infra/src/aspects/suppress-nags/suppress-nags.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { IAspect } from "aws-cdk-lib";
import type { IConstruct } from "constructs";
import { Suppression } from "./suppression.js";
import { suppressAwsLambdaBasicExecutionRole } from "./suppress-aws-lambda-basic-execution-role.js";
import { suppressCdkBucketNotifications } from "./suppress-cdk-bucket-notifications.js";
import { suppressCdkBucketDeployment } from "./suppress-cdk-bucket-deployment.js";
import { suppressCdkCustomResourceProvider } from "./suppress-cdk-custom-resource-provider.js";
import { suppressCdkLogRetention } from "./suppress-cdk-log-retention.js";
import { suppressCdkCustomResource } from "./suppress-cdk-custom-resource.js";
import { suppressCdkMonitoringConstructs } from "./suppress-cdk-monitoring-constructs.js";
import { Suppression } from "./suppression";
import { suppressAwsLambdaBasicExecutionRole } from "./suppress-aws-lambda-basic-execution-role";
import { suppressCdkBucketNotifications } from "./suppress-cdk-bucket-notifications";
import { suppressCdkBucketDeployment } from "./suppress-cdk-bucket-deployment";
import { suppressCdkCustomResourceProvider } from "./suppress-cdk-custom-resource-provider";
import { suppressCdkLogRetention } from "./suppress-cdk-log-retention";
import { suppressCdkCustomResource } from "./suppress-cdk-custom-resource";
import { suppressCdkMonitoringConstructs } from "./suppress-cdk-monitoring-constructs";

/**
* Suppresses common cdk-nags that are acceptable to many development teams.
Expand Down
8 changes: 4 additions & 4 deletions packages/gboost-infra/src/bucket/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Duration } from "aws-cdk-lib";
import { IGrantable, Grant } from "aws-cdk-lib/aws-iam";
import { type IGrantable, Grant } from "aws-cdk-lib/aws-iam";
import {
BlockPublicAccess,
Bucket as CdkBucket,
BucketEncryption,
BucketProps as CdkBucketProps,
type BucketProps as CdkBucketProps,
StorageClass,
} from "aws-cdk-lib/aws-s3";
import { NagSuppressions } from "cdk-nag";
import type { Construct } from "constructs";
import { mergeDeep } from "gboost-common";
import { constructDefaultProps } from "../construct-default-props.js";
import * as perms from "./permissions.js";
import { constructDefaultProps } from "../construct-default-props";
import * as perms from "./permissions";

export type BucketProps = CdkBucketProps;

Expand Down
6 changes: 3 additions & 3 deletions packages/gboost-infra/src/construct-default-props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BucketProps } from "./bucket/bucket.js";
import type { FunctionProps } from "./function.js";
import type { TableProps } from "./table.js";
import type { BucketProps } from "./bucket/bucket";
import type { FunctionProps } from "./function";
import type { TableProps } from "./table";
import { mergeDeep } from "gboost-common";

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/gboost-infra/src/db-iam-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Stack } from "aws-cdk-lib";
import { Grant, IGrantable } from "aws-cdk-lib/aws-iam";
import { Grant, type IGrantable } from "aws-cdk-lib/aws-iam";
import {
DatabaseCluster as CdkDatabaseCluster,
DatabaseClusterProps as CdkDatabaseClusterProps,
type DatabaseClusterProps as CdkDatabaseClusterProps,
} from "aws-cdk-lib/aws-rds";
import {
AwsCustomResource,
Expand Down
6 changes: 3 additions & 3 deletions packages/gboost-infra/src/file-upload/file-upload.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Construct } from "constructs";
import type { GraphqlApi } from "@aws-cdk/aws-appsync-alpha";
import { Function } from "../function.js";
import { createSchema } from "./createSchema.js";
import { Function } from "../function";
import { createSchema } from "./createSchema";
import { Duration, Stack } from "aws-cdk-lib";
import type { Bucket } from "../bucket/bucket.js";
import type { Bucket } from "../bucket/bucket";
import { NagSuppressions } from "cdk-nag";
import type { CfnBucket, CorsRule, HttpMethods } from "aws-cdk-lib/aws-s3";

Expand Down
Loading

0 comments on commit 7af36c2

Please sign in to comment.