dsherret / dsherret/ts-morph

Creating source maps on directory emission

Open
#658 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

More detailed follow up on https://github.com/dsherret/ts-morph/issues/656

I have a project where I generate multiple (more than 120) modules:
```
generated/
module1/
someFile1.ts
tsconfig.json
module2/
someFile2.ts
tsconfig.json
```

Up to now I have been transpiling the sources in a separate step on my own. Now I want to do this as part of the generation using ts-morph.

The result is supposed to be something like this:
```
generated/
module1/
dist/
someFile1.d.ts
someFile1.d.ts.map
someFile1.js
someFile1.js.map
someFile1.ts
tsconfig.json
module2/
dist/
someFile2.d.ts
someFile2.d.ts.map
someFile2.js
someFile2.js.map
someFile2.ts
tsconfig.json
```

Now I wonder how to achieve this or whether this is even possible.

What I tried:

1. I created multiple projects and tried to save + emit those asynchronously. This fails because Javascript runs out of memory. This works for just saving, but as soon as I add emission, I run out of memory. I suppose this is not intended and not a good idea. (Right?)

2. I created one project for all modules. Saving the project works as usual.
a. I emmitted the whole project at once. With this approach I don't see any possibility to specify multiple outDirs, to my understanding this is not supported by the tsconfig.json.
b. I emitted all module directories with `{ outDir: 'dist' }`. This approach has two problems:
* This is the resulting structure, the `d.ts.map` files are not in the outdir:
```
generated/
module1/
dist/
someFile1.d.ts
someFile1.js
someFile1.js.map
someFile1.d.ts.map // this should not be here
someFile1.ts
tsconfig.json
module2/
dist/
someFile2.d.ts
someFile2.js
someFile2.js.map
someFile2.d.ts.map // this should not be here
someFile2.ts
tsconfig.json
```
* The `js.map` file do not link to the correct sources: I need it to be `../someFileX.ts` but it is `someFileX.ts`. I am not sure that this is intended, but if it is I don't see any option to actually enable this behavior.

It is not 100% clear to me how emit on directories should work and whether this is a valid approach at all...
Possibly this is just a bug, if the two issues are connected. It could as well be a new feature that allows to set the `baseUrl`?
To my understanding setting the `mapRoot` in the project is not helpful in this case.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported multi-module layout and directory emission with { outDir: 'dist' }, then compare the generated .d.ts.map and .js.map locations and source paths. Read the issue's discussion of tsconfig, mapRoot, and baseUrl behavior. Done means both map files are emitted under each module's dist directory and the JavaScript map points to the intended source path.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.