Skip to content

Commit

Permalink
Added workaround for the 'tsconfig.json' bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJPhilp committed Apr 16, 2024
1 parent a20ed57 commit 37761c2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
29 changes: 22 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,28 @@ The outputFileName name lets you set the name of the produced by Pkl.
outputFileName = "totally_tsconfig.json
```

To build, run `pkl eval tsconfig.pkl -m .`, and it will create a `tsconfig.json` in the same directory.
### Warning ###
There is a bug where in VsCode (at least), when you set *outputFileName* to 'tsconfig.json',
Pkl creates the proper 'tsconfig.json' file but it has the type Typescript, not JSON.
All other file names are fine.

If you don't have `pkl` installed on your local machine, you can use your Javascript runtime to run
a remote version of `pkl`:
As a workaround, pklTsConfig will set *outputFileName* to 'totally_tsconfig.json' when it is set to 'tsconfig.json'. Just
change the file name to 'tsconfig.json' and your all set.

With `npx`:
`npx pkl eval tsconfig.pkl -m .`
### Running pklTsConfig ###

With `bunx`:
`bunx pkl eval tsconfig.pkl -m .`
1) If you have `Pkl` installed locally:

To generate you tsconfig, run `pkl eval tsconfig.pkl -m .`, and it will create a `tsconfig.json` file in the same directory.

You can download Pkl by following Pkl's [installation instructions](https://pkl-lang.org/main/current/pkl-cli/index.html#installation).

2) If you don't have `Pkl` installed on your local machine:

You can use your Javascript bundler (npm, bun) to run a remote version of `pkl`:

With `npx`:
`npx pkl eval tsconfig.pkl -m .`

With `bunx`:
`bunx pkl eval tsconfig.pkl -m .`
4 changes: 2 additions & 2 deletions src/default.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ root = new Schema.RootSchema {

amend = new Schema.AmendSchema { }

outputFileName: String = "tsconfig.json"
outputFileName:Schema.ValidOutputFileName = "tsconfig.json"

output {
files {
[outputFileName] {
[if (outputFileName == "tsconfig.json") "totally_tsconfig.json" else outputFileName] {
value = Render.renderTsConfig(config, root, amend)
renderer = new JsonRenderer {
converters {
Expand Down
1 change: 1 addition & 0 deletions src/schema.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typealias ConfigItemValue = String | Boolean | List<String>

typealias FileName = String(contains(".ts") || contains(".tsx") || contains(".json") || contains(".js"))
typealias FileList = Listing<FileName>
typealias ValidOutputFileName = String(matches(Regex(#"[a-zA-Z0-9-_. ]{1,255}.json"#)))

class pklTsConfigSchema {
compilerOptions: CompilerOptionsSchema
Expand Down
2 changes: 1 addition & 1 deletion src/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.1
0.6.1
2 changes: 1 addition & 1 deletion tsconfig.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ amend {
["allowJs"] = false
}

outputFileName = "totally_tsconfig.json"
outputFileName = "tsconfig.json"

0 comments on commit 37761c2

Please sign in to comment.