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

Creating source maps on directory emission #658

Open
marikaner opened this issue Jul 4, 2019 · 2 comments
Open

Creating source maps on directory emission #658

marikaner opened this issue Jul 4, 2019 · 2 comments

Comments

@marikaner
Copy link
Contributor

More detailed follow up on #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.

@dsherret
Copy link
Owner

dsherret commented Jul 8, 2019

@marikaner sorry, for my delay:

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?)

This is probably what you will want to do it if those tsconfig.json files in each directory have different settings that could affect the emit. Under the hood, the emit is driven by the "program", each program has a single configuration, and there is one program per ts-morph "project" object. So, you'll want to load one project per tsconfig.json.

Yeah, that will probably cause it to use a lot of memory because it's not sharing node modules anymore. To deal with the memory issue, you may want to only open one project at a time or increase the memory usage. It will also probably be a lot slower because it will have to parse a lot of the shared files many times instead of once. I've opened #660 to try to deal with this.


This is the resulting structure, the d.ts.map files are not in the outdir:

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.

I'll look into these issues soon. Could you post the configuration (tsconfig) you're using?

@marikaner
Copy link
Contributor Author

marikaner commented Jul 9, 2019

I resorted to using just one project, which is perfectly fine in my case as the configs are all the same. I am not using a tsconfig.json anymore, only the ProjectOptions:

{
    addFilesFromTsConfig: false,
    manipulationSettings: {
      indentationText: IndentationText.TwoSpaces,
      insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
      quoteKind: QuoteKind.Single
    },
    compilerOptions: {
      target: ScriptTarget.ES5,
      module: ModuleKind.CommonJS,
      declaration: true,
      declarationMap: true,
      sourceMap: true,
      diagnostics: true,
      moduleResolution: ModuleResolutionKind.NodeJs,
      esModuleInterop: true,
      inlineSources: false,
      noImplicitAny: true
    }
  }

In addition, for emitting the directories I was using { outDir: 'dist' }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants