Skip to content

Commit

Permalink
Refactor TypeScript setup (#641)
Browse files Browse the repository at this point in the history
This replaces turbo with TypeScript project references. Instead of
`turbo run build`, now we can use `tsc --build`.

All projects now follow a consistent layout. The `src` directory is for
source files. The `dist` directory is for compiled output. The `test`
directory is for tests.

Tests still use `ts-node` and `mocha`. Every workspace now contains 2
TypeScript configuration files. `tsconfig.build.json` checks and
compiles the source files. Every dependency must be referenced via the
`references` property. The `tsconfig.json` file checks all files that
are **not** part of the source, at the moment this is test files. Note
that test files were previously not type checked at all.

The `test` workspace has a dependency on all packages’
`tsconfig.build.json` files. All workspace `tsconfig.json` files have a
dependency on the `test` workspace. It’s worth noting that cyclic
project references are not allowed, and we’re lucky tests are currently
not part of the build.

The project root’s `tsconfig.json` served as a base configuration. It
now serves as the solution file that references all workspaces. Every
workspace can now be checked with `tsc --build` individually. The entire
workspace with `tsc --build`. Instead, a new file, `tsconfig.base.json`,
now serves as a base.

Some compiler options were changes:
- `module` is now set to `node16`.
- `esModuleInterop` was removed, as it is redundant with `module`
  `node16`.
- `skipLibCheck` was removed, as it’s good to know if there are any
  conflicts with third party types.
- `forceConsistentCasingInFileNames` was removed, as this is true by
  default.
- `moduleResolution` was removed, as this is configured automatically
  with `module` node16`.
- `resolveJsonModule` was removed, as it appears to be unused.
- `composite` was enabled, as it has to be for project references.

The `types` field was removed from `package.json` files. This is
redundant if the declaration file names match the JavaScript file names.

Some additional things to consider after this PR:
- Enable `verbatimModuleSyntax` for stricter CJS interoperability
  checks.
- Enable `declarationMap` for _Go to Definition_ support.
- Enable `sourceMap` for source map support.
- Publish the source code to make declaration maps and source maps work
  for consumers.
  • Loading branch information
remcohaszing authored Aug 1, 2024
1 parent a09bb31 commit dc49198
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.eslintcache
dist
.turbo
*.tsbuildinfo
output/

# Yarn
.pnp.*
Expand Down
63 changes: 31 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"test"
],
"scripts": {
"build": "turbo run build",
"build": "tsc --build",
"demo": "npm run --workspace demo start",
"demo:gcs": "npm run --workspace demo start:gcs",
"demo:s3": "npm run --workspace demo start:s3",
"lint": "turbo run lint",
"format": "turbo run format",
"pretest": "tsc --build",
"test": "turbo run test",
"version": "changeset version",
"release": "gh workflow run release",
Expand All @@ -25,7 +26,8 @@
"eslint-config-custom": "^0.0.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.8",
"turbo": "^1.13.0"
"turbo": "^1.13.0",
"typescript": "^5.5.4"
},
"version": "0.0.0"
}
8 changes: 3 additions & 5 deletions packages/file-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "1.4.0",
"description": "Local file storage for @tus/server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/tus/tus-node-server#readme",
"bugs": "https://github.com/tus/tus-node-server/issues",
"repository": "tus/tus-node-server",
Expand All @@ -15,10 +14,10 @@
],
"license": "MIT",
"scripts": {
"build": "tsc",
"build": "tsc --build",
"lint": "eslint .",
"format": "eslint --fix .",
"test": "mocha test.ts --exit --extension ts --require ts-node/register"
"test": "mocha --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@tus/utils": "^0.3.0",
Expand All @@ -31,8 +30,7 @@
"eslint": "^8.57.0",
"eslint-config-custom": "^0.0.0",
"mocha": "^10.4.0",
"should": "^13.2.3",
"typescript": "^5.3.3"
"should": "^13.2.3"
},
"optionalDependencies": {
"@redis/client": "^1.5.13"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import path from 'node:path'

import sinon from 'sinon'

import {FileStore, FileConfigstore} from './'
import {FileStore, FileConfigstore} from '../src'
import {Upload} from '@tus/utils'

import * as shared from '../../test/stores.test'
import * as shared from 'test/stores.test'

const fixturesPath = path.resolve('../', '../', 'test', 'fixtures')
const storePath = path.resolve('../', '../', 'test', 'output', 'file-store')
Expand Down
10 changes: 10 additions & 0 deletions packages/file-store/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"references": [{"path": "../utils/tsconfig.build.json"}],
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
}
}
7 changes: 4 additions & 3 deletions packages/file-store/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"include": ["index.ts"],
"references": [{"path": "./tsconfig.build.json"}, {"path": "../../test/tsconfig.json"}],
"extends": "../../tsconfig.base.json",
"exclude": ["src"],
"compilerOptions": {
"outDir": "./dist"
"noEmit": true
}
}
8 changes: 3 additions & 5 deletions packages/gcs-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "1.3.0",
"description": "Google Cloud Storage for @tus/server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/tus/tus-node-server#readme",
"bugs": "https://github.com/tus/tus-node-server/issues",
"repository": "tus/tus-node-server",
Expand All @@ -15,10 +14,10 @@
"dist"
],
"scripts": {
"build": "tsc",
"build": "tsc --build",
"lint": "eslint .",
"format": "eslint --fix .",
"test": "mocha test.ts --timeout 30000 --exit --extension ts --require ts-node/register"
"test": "mocha --timeout 30000 --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@tus/utils": "^0.3.0",
Expand All @@ -33,8 +32,7 @@
"eslint": "^8.57.0",
"eslint-config-custom": "^0.0.0",
"mocha": "^10.4.0",
"should": "^13.2.3",
"typescript": "^5.3.3"
"should": "^13.2.3"
},
"peerDependencies": {
"@google-cloud/storage": "*"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path'

import {GCSStore} from './'
import {GCSStore} from '../src'

import * as shared from '../../test/stores.test'
import * as shared from 'test/stores.test'

import {Storage} from '@google-cloud/storage'

Expand Down
10 changes: 10 additions & 0 deletions packages/gcs-store/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"references": [{"path": "../utils//tsconfig.build.json"}],
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
}
}
7 changes: 4 additions & 3 deletions packages/gcs-store/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"include": ["index.ts"],
"references": [{"path": "./tsconfig.build.json"}, {"path": "../../test/tsconfig.json"}],
"extends": "../../tsconfig.base.json",
"exclude": ["src"],
"compilerOptions": {
"outDir": "./dist"
"noEmit": true
}
}
8 changes: 3 additions & 5 deletions packages/s3-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "1.5.0",
"description": "AWS S3 store for @tus/server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/tus/tus-node-server#readme",
"bugs": "https://github.com/tus/tus-node-server/issues",
"repository": "tus/tus-node-server",
Expand All @@ -15,10 +14,10 @@
"dist"
],
"scripts": {
"build": "tsc",
"build": "tsc --build",
"lint": "eslint .",
"format": "eslint --fix .",
"test": "mocha test.ts --timeout 40000 --exit --extension ts --require ts-node/register"
"test": "mocha --timeout 40000 --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.490.0",
Expand All @@ -35,8 +34,7 @@
"eslint": "^8.57.0",
"eslint-config-custom": "^0.0.0",
"mocha": "^10.4.0",
"should": "^13.2.3",
"typescript": "^5.3.3"
"should": "^13.2.3"
},
"engines": {
"node": ">=16"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/s3-store/test.ts → packages/s3-store/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {Readable} from 'node:stream'

import sinon from 'sinon'

import {S3Store} from './'
import * as shared from '../../test/stores.test'
import {S3Store} from '../src'
import * as shared from 'test/stores.test'
import {Upload} from '@tus/utils'

const fixturesPath = path.resolve('../', '../', 'test', 'fixtures')
Expand Down
Loading

0 comments on commit dc49198

Please sign in to comment.