Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropped ttypescript in favor of ts-patch #1432

Merged
merged 5 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/wf_check-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- 'v2.x.x'
- v2.x.x
paths-ignore:
- '**.md'
- 'website/**'
Expand All @@ -14,6 +14,7 @@ on:
pull_request:
branches:
- main
- v2.x.x
paths-ignore:
- '**.md'
- 'website/**'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wf_check-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
branches:
- main
- 'v2.x.x'
- v2.x.x
paths-ignore:
- '**.md'
- 'website/**'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/wf_test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- 'v2.x.x'
- v2.x.x
paths-ignore:
- '**.md'
- 'website/**'
Expand All @@ -14,6 +14,7 @@ on:
pull_request:
branches:
- main
- v2.x.x
paths-ignore:
- '**.md'
- 'website/**'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@boostercloud/framework-core",
"comment": "Replaced the deprecated dependency `ttypescript` with `ts-patch`",
"type": "minor"
}
],
"packageName": "@boostercloud/framework-core"
}
151 changes: 110 additions & 41 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/application-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"lint:check": "eslint --ext '.js,.ts' **/*.ts",
"lint:fix": "eslint --quiet --fix --ext '.js,.ts' **/*.ts",
"build": "tsc -b tsconfig.json",
"clean": "npx rimraf ./dist tsconfig.tsbuildinfo",
"clean": "rimraf ./dist tsconfig.tsbuildinfo",
"prepack": "tsc -b tsconfig.json",
"test": ""
},
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/templates/project/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const template = `{
"prettier": "2.3.0",
"typescript": "4.7.4",
"ts-node": "9.1.1",
"ttypescript": "1.5.15",
"@types/node": "^18.15.3",
"ts-patch": "2.0.2",
"graphql": "^16.6.0"
},
"engines": {
Expand All @@ -43,9 +43,10 @@ export const template = `{
"main": "dist/index.js",
"repository": "{{{repository}}}",
"scripts": {
"prepare": "ts-patch install -s",
"lint:check": "eslint --ext '.js,.ts' **/*.ts",
"lint:fix": "eslint --quiet --fix --ext '.js,.ts' **/*.ts",
"build": "ttsc -b tsconfig.json",
"build": "tsc -b tsconfig.json",
"clean": "rimraf ./dist tsconfig.tsbuildinfo"
},
"types": "lib/index.d.ts"
Expand Down
1 change: 0 additions & 1 deletion packages/framework-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"include": ["src/**/*"],
"ts-node": {
"compiler": "ttypescript",
"compilerOptions": {
"plugins": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ts-node": "whatever",
"@types/node": "whatever",
"@boostercloud/framework-provider-aws-infrastructure": "whatever",
"ttypescript": "whatever",
"ts-patch": "whatever",
"@boostercloud/metadata-booster": "whatever",
"graphql": "^16.6.0"
},
Expand All @@ -35,9 +35,10 @@
"main": "dist/index.js",
"repository": "repository_placeholder",
"scripts": {
"prepare": "ts-patch install -s",
"lint:check": "eslint --ext '.js,.ts' **/*.ts",
"lint:fix": "eslint --quiet --fix --ext '.js,.ts' **/*.ts",
"build": "ttsc -b tsconfig.json",
"build": "tsc -b tsconfig.json",
"clean": "rimraf ./dist tsconfig.tsbuildinfo"
},
"types": "lib/index.d.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { expect } from '../../helper/expect'
// The Booster CLI version used should match the integration tests' version
const BOOSTER_VERSION = require('../../../package.json').version


const TEST_TIMEOUT = 80000
const DESCRIPTION = 'cart-demo'
const VERSION = '1.0.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { setEnv } from '../../helper/app-helper'

before(async () => {
// Nothing so far
await setEnv()
})
43 changes: 22 additions & 21 deletions packages/framework-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"serverless-artillery": "0.5.2",
"subscriptions-transport-ws": "0.11.0",
"ts-node": "^10.9.1",
"ttypescript": "1.5.15",
"ts-patch": "2.0.2",
"typescript": "4.7.4",
"sinon": "9.2.3",
"eslint-plugin-unicorn": "~44.0.2"
Expand All @@ -84,32 +84,33 @@
"main": "dist/index.js",
"repository": "boostercloud/booster",
"scripts": {
"prepare": "ts-patch install -s",
"test": "",
"watch:local": "nodemon --watch ../framework-provider-local/dist --watch ../framework-provider-local-infrastructure --watch dist --exec \"./node_modules/.bin/boost start -e local\"",
"lint:check": "eslint --ext '.js,.ts' **/*.ts",
"lint:fix": "eslint --quiet --fix --ext '.js,.ts' **/*.ts",
"build": "ttsc -b tsconfig.json",
"build": "tsc -b tsconfig.json",
"clean": "rimraf ./dist tsconfig.tsbuildinfo *-integration-sandbox",
"postinstall": "rimraf ../../node_modules/serverless/node_modules/archiver && echo 'Deleted buggy \"archiver\" module from \"serveless\" dependencies to use the newer hoisted one'",
"integration": "npm run integration/cli && npm run integration/local && npm run integration/aws && npm run integration/azure",
"integration/cli": "mocha --exit --config \"integration/provider-unaware/cli/.mocharc.yml\" \"integration/provider-unaware/cli/**/*.integration.ts\"",
"integration/aws": "npm run integration/aws-deploy && npm run integration/aws-func && npm run integration/aws-end-to-end && npm run integration/aws-load && npm run integration/aws-nuke",
"integration/aws-deploy": "AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-specific/aws/deployment/.mocharc.yml\" \"integration/provider-specific/aws/deployment/**/*.integration.ts\"",
"integration/aws-func": "TESTED_PROVIDER=AWS AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-unaware/functionality/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\"",
"integration/aws-end-to-end": "TESTED_PROVIDER=AWS AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/aws-load": "echo 'Skipping integration tests.' # TESTED_PROVIDER=AWS AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-unaware/load/.mocharc.yml\" \"integration/provider-unaware/load/**/*.load.ts\"",
"integration/aws-nuke": "AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-specific/aws/nuke/.mocharc.yml\" \"integration/provider-specific/aws/nuke/**/*.integration.ts\"",
"integration/local": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/.mocharc.yml\" \"integration/provider-specific/local/**/*.integration.ts\"",
"integration/local-ongoing": "npm run integration/local-start && npm run integration/local-stop",
"integration/local-start": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/start/.mocharc.yml\" \"integration/provider-specific/local/start/*.integration.ts\"",
"integration/local-func": "TESTED_PROVIDER=LOCAL BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-unaware/functionality/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\"",
"integration/local-end-to-end": "TESTED_PROVIDER=LOCAL BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/local-stop": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/stop/.mocharc.yml\" \"integration/provider-specific/local/stop/*.integration.ts\"",
"integration/azure": "npm run integration/azure-deploy && npm run integration/azure-end-to-end && npm run integration/azure-func && npm run integration/azure-nuke",
"integration/azure-deploy": "TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-specific/azure/deployment/.mocharc.yml\" \"integration/provider-specific/azure/deployment/**/*.integration.ts\"",
"integration/azure-nuke": "TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-specific/azure/nuke/.mocharc.yml\" \"integration/provider-specific/azure/nuke/**/*.integration.ts\"",
"integration/azure-end-to-end": "TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/azure-func": "TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\""
"integration": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" npm run integration/cli && npm run integration/local && npm run integration/aws && npm run integration/azure",
"integration/cli": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" BOOSTER_ENV=test mocha --forbid-only --exit --config \"integration/provider-unaware/cli/.mocharc.yml\" \"integration/provider-unaware/cli/**/*.integration.ts\"",
"integration/aws": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" npm run integration/aws-deploy && npm run integration/aws-func && npm run integration/aws-end-to-end && npm run integration/aws-load && npm run integration/aws-nuke",
"integration/aws-deploy": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-specific/aws/deployment/.mocharc.yml\" \"integration/provider-specific/aws/deployment/**/*.integration.ts\"",
"integration/aws-func": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AWS AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-unaware/functionality/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\"",
"integration/aws-end-to-end": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AWS AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/aws-load": "echo 'Skipping integration tests.' # TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AWS AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-unaware/load/.mocharc.yml\" \"integration/provider-unaware/load/**/*.load.ts\"",
"integration/aws-nuke": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" AWS_SDK_LOAD_CONFIG=true BOOSTER_ENV=production mocha --forbid-only --exit --config \"integration/provider-specific/aws/nuke/.mocharc.yml\" \"integration/provider-specific/aws/nuke/**/*.integration.ts\"",
"integration/local": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/.mocharc.yml\" \"integration/provider-specific/local/**/*.integration.ts\"",
"integration/local-ongoing": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" npm run integration/local-start && npm run integration/local-stop",
"integration/local-start": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/start/.mocharc.yml\" \"integration/provider-specific/local/start/*.integration.ts\"",
"integration/local-func": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=LOCAL BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-unaware/functionality/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\"",
"integration/local-end-to-end": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=LOCAL BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/local-stop": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/stop/.mocharc.yml\" \"integration/provider-specific/local/stop/*.integration.ts\"",
"integration/azure": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" npm run integration/azure-deploy && npm run integration/azure-end-to-end && npm run integration/azure-func && npm run integration/azure-nuke",
"integration/azure-deploy": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-specific/azure/deployment/.mocharc.yml\" \"integration/provider-specific/azure/deployment/**/*.integration.ts\"",
"integration/azure-nuke": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-specific/azure/nuke/.mocharc.yml\" \"integration/provider-specific/azure/nuke/**/*.integration.ts\"",
"integration/azure-end-to-end": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/azure-func": "TS_NODE_PROJECT=\"./tsconfig.integration.json\" TESTED_PROVIDER=AZURE BOOSTER_ENV=azure mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\""
},
"types": "dist/index.d.ts"
}
3 changes: 1 addition & 2 deletions packages/framework-integration-tests/tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.json",
"include": [
"src/**/*",
"integration/**/*",
"test/**/*"
"integration/**/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"include": [
"integration/**/*"
],
"exclude": [
"integration/fixtures/**/*"
]
}
2 changes: 1 addition & 1 deletion packages/framework-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outDir": "dist",
"rootDir": "src",
"strict": true,
"target": "es2019",
"target": "ES2019",
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
Expand Down
77 changes: 49 additions & 28 deletions packages/metadata-booster/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Metadata Booster

This is a transformer (also known as plugin) for Typescript to generate detailed metadata for all your classes.

## Why?

There are many applications that need to know the schema of your classes to work properly, like ORMs (to know the names of the database tables and columns), GraphQL APIs (to generate the GraphQL schema), etc.

Currently, Typescript emits some metadata when you add decorators to your classes and enable the following compiler options: `"experimentalDecorators": true` and `"emitDecoratorMetadata": true`.

However, that metadata is very limited, as it doesn't include property names and information about the type parameters.

For example, if we had the following code:

```typescript
@AnyDecorator //We need to decorate the class to emit metadata
class User {
Expand Down Expand Up @@ -36,20 +39,25 @@ class Car {
}
}
```

And now we call `Reflect.getMetadata('design:paramtypes')` on each class, we would get the following:

```typescript
Reflect.getMetadata('design:paramtypes', User)
> [ [Function: String], [Function: Set] ]

Reflect.getMetadata('design:paramtypes', Car)
> [ [Function: Number], [Function: Map] ]
```

Not very helpful: we are lacking a lot of information about property names, type parameters and methods.

## Welcome to full detailed metadata

With this transformer, you will get much more detailed metadata for all your classes, without the need of using any decorator.

Following with the previous example, you can get this detailed metadata using the key `'booster:typeinfo'`:

```typescript
Reflect.getMetadata('booster:typeinfo', User)
> {
Expand Down Expand Up @@ -129,49 +137,62 @@ Reflect.getMetadata('booster:typeinfo', Car)
]
}
```

As you can see, you can now have runtime access to the information about all the properties, type parameters, methods, return types, etc. of your classes.

## How to use it
"@boostercloud/metadata-booster" is a transformer so, until the Typescript team decides to accept plugins (you can track the status in [this issue](https://github.com/microsoft/TypeScript/issues/14419)), you would want to use the [Typescript](https://github.com/cevek/ttypescript) wrapper "TTypescript" to be able to use any transformer. That being said, it works really well.

"@boostercloud/metadata-booster" is a transformer so, until the Typescript team decides to accept plugins (you can track the status in [this issue](https://github.com/microsoft/TypeScript/issues/14419)), you would want to use [TS Patch](https://github.com/nonara/ts-patch).

Here are the steps:
1. Add the "@boostercloud/metadata-booster" transformer and "ttypescript" to your `"devDependencies"`
```shell
npm install --save-dev "@boostercloud/metadata-booster"
npm install --save-dev "ttypescript"
```

1. Add the "@boostercloud/metadata-booster" transformer and "ts-patch" to your `"devDependencies"`

```shell
npm install --save-dev "@boostercloud/metadata-booster"
npm install --save-dev "ts-patch"
```

2. Add the official module "reflect-metadata" to your `"dependencies"` (you need this to access the metadata)
```shell
npm install --save-prod "reflect-metadata"
```

```shell
npm install --save-prod "reflect-metadata"
```

3. Go to your `tsconfig.json` file and
- a) Ensure you have the option `"experimentalDecorators": true`. The reason is that the metadata is automatically added as a decorator to the class. In any case, you don't need to write any decorator.
- b) Add "@boostercloud/metadata-booster" as a transformer plugin inside the `"compilerOptions"` section
```shell
{
"compilerOptions": {
(...)
"experimentalDecorators": true
"plugins": [
{ "transform": "@boostercloud/metadata-booster"}
]
},
}
```
4. _[Optional]_ From now on, to compile your code you need to use the command `ttsc` (the TTypescript wrapper), instead of `tsc`. I normally have a "build" script in my "package.json" file that calls `"tsc -b tsconfig.json"`, so I compile my code by running `npm run build`. I would recommend you to do that and change "tsc" by "ttsc". Like this:
```json
... other "package.json" options fields ...
"scripts": {
"build": "ttsc -b tsconfig.json",
"test": "..."
}
```

```shell
{
"compilerOptions": {
(...)
"experimentalDecorators": true
"plugins": [
{ "transform": "@boostercloud/metadata-booster"}
]
},
}
```

4. Create a "prepare" script to patch your typescript installation automatically after installing your dependencies. You can also add a convenient "build" script in your "package.json" file to compile your code by running `npm run build` instead of calling the compiler directly:

```json
... other "package.json" options fields ...
"scripts": {
"prepare": "ts-patch install -s",
"build": "tsc -b tsconfig.json",
"test": "..."
}
```

Now you can compile your project by running `npm run build` and have access to a full detailed metadata for all your Typescript classes.

## Compatibility

This transformer is compatible with Typescript version 4.x.x

## Missing features

- [ ] Gather interfaces metadata
- [ ] Gather method parameters metadata
5 changes: 3 additions & 2 deletions packages/metadata-booster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@
"@boostercloud/eslint-config": "workspace:^1.19.1",
"@types/node": "^18.15.3",
"ts-node": "^10.9.1",
"ttypescript": "1.5.15",
"ts-patch": "2.0.2",
"typescript": "4.7.4",
"prettier": "2.3.0",
"sinon": "9.2.3",
"rimraf": "^5.0.0",
"eslint-plugin-unicorn": "~44.0.2"
},
"scripts": {
"prepare": "ts-patch install -s",
"lint:check": "eslint --ext '.js,.ts' **/*.ts",
"lint:fix": "eslint --quiet --fix --ext '.js,.ts' **/*.ts",
"build": "tsc -b tsconfig.json",
"clean": "rimraf ./dist tsconfig.tsbuildinfo",
"prepack": "tsc -b tsconfig.json",
"test": "ttsc -p tsconfig.test.json"
"test": "tsc -p tsconfig.test.json"
},
"pnpm": {
"overrides": {
Expand Down
Loading
Loading