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

chore(rollup): replace ttypescript with ts-patch #4368

Merged
merged 10 commits into from
Nov 28, 2023
2 changes: 2 additions & 0 deletions .changeset/eleven-vans-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"tailwindcss": "^3.3.5",
"ts-jest": "^29.1.1",
"turbo": "^1.10.16",
"typescript": "^4.9.5",
"typescript": "^5.3.2",
"webpack": "^5.89.0"
}
}
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"serialize-query-params": "^2.0.2",
"svgo": "^3.0.4",
"ts-jest": "^29.1.1",
"ttypescript": "^1.5.15",
"ts-patch": "^3.0.2",
"typescript-transform-paths": "^3.4.6"
},
"peerDependencies": {
Expand Down
20 changes: 8 additions & 12 deletions packages/components/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createRequire } from "node:module";
import alias from "@rollup/plugin-alias"
import { babel, getBabelOutputPlugin } from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs"
Expand All @@ -9,9 +10,12 @@ import dts from "rollup-plugin-dts"
import ignore from "rollup-plugin-ignore"
import nodeExternals from "rollup-plugin-node-externals"
import postcss from "rollup-plugin-postcss"
import ttypescript from "ttypescript"

const TYPES_TEMP_DIR = "dts"
// ts-patch needs to be in CJS, but rollup uses EMS
// https://github.com/nonara/ts-patch/issues/106
const require = createRequire(import.meta.url);
const tspCompiler = require("ts-patch/compiler");

const OUTPUT_DIR = "dist"

const getCompiledConfigByModuleType = format => ({
Expand Down Expand Up @@ -44,16 +48,8 @@ const getCompiledConfigByModuleType = format => ({
extensions: [".scss", ".css"],
}),
typescript({
declaration: true,
declarationDir: `${OUTPUT_DIR}/${format}/${TYPES_TEMP_DIR}`,
exclude: [
"node_modules",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.stories.tsx",
],
// We use ttypescript instead of typescript to allow transformer to convert alias into actual paths/dependencies
typescript: ttypescript,
tsconfig: `./tsconfig.${format}.json`,
typescript: tspCompiler,
}),
commonjs(),
image(),
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/Table/_docs/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type TableStoryProps = {
container?: TableContainerProps
row?: TableRowProps
rowCell?: TableRowCellProps
headerRowCell: Omit<TableHeaderRowCellProps, "labelText">
headerRowCell: Partial<TableHeaderRowCellProps>
card: TableCardProps
}

Expand Down
6 changes: 6 additions & 0 deletions packages/components/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.dist.json",
"compilerOptions": {
"declarationDir": "dist/cjs/dts"
}
}
21 changes: 21 additions & 0 deletions packages/components/tsconfig.dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
// Note: To transform paths for both the output .js and .d.ts files, you need both of the below entries
"plugins": [
// Transform paths in output .js files
{ "transform": "typescript-transform-paths" },
// Transform paths in output .d.ts files (Include this line if you output declarations files)
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
},
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.stories.tsx"
]
}
6 changes: 6 additions & 0 deletions packages/components/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.dist.json",
"compilerOptions": {
"declarationDir": "dist/esm/dts"
}
}
10 changes: 1 addition & 9 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@
"baseUrl": ".",
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
"paths": {
"~storybook/*": ["../../storybook/*"],
"~types/*": ["./src/types/*"],
"~utils/*": ["./src/utils/*"],
"~components/*": ["./src/*"]
},
// Note: To transform paths for both the output .js and .d.ts files, you need both of the below entries
"plugins": [
// Transform paths in output .js files
{ "transform": "typescript-transform-paths" },
// Transform paths in output .d.ts files (Include this line if you output declarations files)
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
},
"files": ["types.d.ts"],
"include": ["src/**/*"],
Expand Down
3 changes: 1 addition & 2 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
"ignoreDeps": [
// We can't always stick to latest due to infra and compatibility with other plugins
"node",
"typescript",
// 0.19.x breaks the import of rollup-plugin-esbuild
"esbuild",
// the 8.4.19 -> 8.4.21 patch causes typescript issues
"postcss"
],
"packageRules": [
{
// Any peerDep or dep within the publishable packages triggers a
// Any peerDep or dep within the publishable packages triggers a
// patch release as a _sensible default_. Merger should use their
// discretion to determine whether a major change is more appropriate
"matchPaths": ["packages/**", "draft-packages/**"],
Expand Down
25 changes: 15 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16058,7 +16058,7 @@ resolve.exports@^2.0.0:
resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-2.0.2.tgz#f8c934b8e6a13f539e38b7098e2e36134f01e800"
integrity sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==

resolve@>=1.9.0, resolve@^1.1.7, resolve@^1.10.0, resolve@^1.14.2, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.22.1, resolve@^1.22.2, resolve@^1.22.4:
resolve@^1.1.7, resolve@^1.10.0, resolve@^1.14.2, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.22.1, resolve@^1.22.2, resolve@^1.22.4:
version "1.22.8"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
Expand Down Expand Up @@ -17778,6 +17778,18 @@ ts-node@^10.9.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

ts-patch@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-3.0.2.tgz#cbdf88e4dfb596e4dab8f2c8269361d33270a0ba"
integrity sha512-iTg8euqiNsNM1VDfOsVIsP0bM4kAVXU38n7TGQSkky7YQX/syh6sDPIRkvSS0HjT8ZOr0pq1h+5Le6jdB3hiJQ==
dependencies:
chalk "^4.1.2"
global-prefix "^3.0.0"
minimist "^1.2.8"
resolve "^1.22.2"
semver "^7.3.8"
strip-ansi "^6.0.1"

tsconfig-paths@^3.14.2:
version "3.14.2"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088"
Expand Down Expand Up @@ -17818,13 +17830,6 @@ tty-table@^4.1.5:
wcwidth "^1.0.1"
yargs "^17.7.1"

ttypescript@^1.5.15:
version "1.5.15"
resolved "https://registry.yarnpkg.com/ttypescript/-/ttypescript-1.5.15.tgz#e45550ad69289d06d3bc3fd4a3c87e7c1ef3eba7"
integrity sha512-48ykDNHzFnPMnv4hYX1P8Q84TvCZyL1QlFxeuxsuZ48X2+ameBgPenvmCkHJtoOSxpoWTWi8NcgNrRnVDOmfSg==
dependencies:
resolve ">=1.9.0"

[email protected]:
version "1.10.16"
resolved "https://registry.yarnpkg.com/turbo-darwin-64/-/turbo-darwin-64-1.10.16.tgz#5a8717c1372f2a75e8cfe0b4b6455119ce410b19"
Expand Down Expand Up @@ -17995,12 +18000,12 @@ typescript-transform-paths@^3.4.6:
dependencies:
minimatch "^3.0.4"

typescript@5:
typescript@5, typescript@^5.3.2:
version "5.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.2.tgz#00d1c7c1c46928c5845c1ee8d0cc2791031d4c43"
integrity sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==

typescript@^4.3.5, typescript@^4.9.5:
typescript@^4.3.5:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
Expand Down