Skip to content

Commit

Permalink
fix(cli): fully support ts config paths (#7099)
Browse files Browse the repository at this point in the history
  • Loading branch information
deecewan committed Dec 14, 2022
1 parent 40779c6 commit 322a9f4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-emus-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/cli": patch
---

Support TS Config paths more completely
12 changes: 0 additions & 12 deletions pnpm-lock.yaml

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

2 changes: 0 additions & 2 deletions tooling/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"cli-welcome": "^2.2.2",
"commander": "^9.3.0",
"lodash.throttle": "^4.1.1",
"module-alias": "^2.2.2",
"ora": "^5.3.0",
"prettier": "^2.7.1",
"regenerator-runtime": "^0.13.7",
Expand All @@ -57,7 +56,6 @@
},
"devDependencies": {
"@types/lodash.throttle": "^4.1.7",
"@types/module-alias": "^2.0.1",
"@types/ora": "^3.2.0",
"@types/update-notifier": "5.0.0"
}
Expand Down
27 changes: 2 additions & 25 deletions tooling/cli/src/scripts/read-theme-file.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from "path"
import fs from "fs"
import * as tsNode from "ts-node"
import * as tsConfigPaths from "tsconfig-paths"
import moduleAlias from "module-alias"
import { createThemeTypingsInterface } from "../command/tokens/create-theme-typings-interface"
import { themeKeyConfiguration } from "../command/tokens/config"
import { isObject } from "../utils/is-object"
Expand Down Expand Up @@ -45,30 +44,8 @@ async function readTheme(themeFilePath: string) {
swc: true,
})

/**
* Replace the module aliases in the transpiled code,
* because ts-node does not resolve them to relative require paths.
*
* 🚨 Note that only the first alias target will work
* @example tsconfig.json
* {
* "baseUrl": "src",
* "paths": {
* "@alias/*": ["target/*"]
* }
* }
*/
const aliases = Object.keys(tsConfig.paths).reduce((acc, tsAlias) => {
// target/* -> target/
const firstTarget = tsConfig.paths[tsAlias][0].replace(/\*$/, "")
// @alias/* -> @alias
const jsAlias = tsAlias.replace(/\/\*$/, "")
// @alias = baseUrl/target/
acc[jsAlias] = path.join(tsConfig.absoluteBaseUrl, firstTarget)
return acc
}, {} as Record<string, string>)

moduleAlias.addAliases(aliases)
// registers a loader to help node `require` on paths in the tsConfig `paths`
tsConfigPaths.register()
} else {
// it is a JS project
const defaultProject = path.join(
Expand Down

1 comment on commit 322a9f4

@vercel
Copy link

@vercel vercel bot commented on 322a9f4 Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.