question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Project references: Option to bundle dependencies with multi-file output

See original GitHub issue

Search Terms

“project references” bundle copy dependencies

Suggestion

When using project references, add an option to bundle a project’s dependencies when using outDir. This would be the analogue of prepend, which only works with outFile. This would be useful when targeting a module format that doesn’t work with outFile, such as commonjs.

Use Cases

Two Stack Overflow questions today: https://stackoverflow.com/questions/51938528 https://stackoverflow.com/questions/51939395

For the specific case of CommonJS output, I had the idea to generate single-file AMD output and then use amdefine to wrap the result as a CommonJS module. This sort of works but is extremely ugly.

Edit: I realized that both the prepend option and the suggested option are of limited use for composite projects with external dependencies, because a separate tool is needed to aggregate the external dependencies, and that tool may be able to aggregate the components too. Concretely, if the components have external dependencies in node_modules, then the inter-component dependencies can be added to package.json using relative paths and npm install will make symlinks under node_modules, so if the packaging tool is capable of following those symlinks, it will pack everything up. (A similar technique to make symlinks is possible using yarn workspaces instead of dependencies with relative paths, and has in fact been used to solve https://stackoverflow.com/questions/51939395 .) However, symlink support is still uneven on Windows, as pointed out here.

I’m still interested in the rationale for offering prepend and not the analogous thing for multi-file output. Was it just that prepend was designed to suit the needs of the TypeScript compiler?

Examples

Straw-man proposal:

{
  "references": [
      { "path": "foo", "copyOutDirTo": "some/path" },
  ]
}

Copies the outDir of the referenced project to some/path. By specifying copyOutDirTo and the project’s own outDir in the correct relationship, one can produce a single output tree in which modules will be able to find each other.

Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript / JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. new expression-level syntax)

Possibly related

#17611

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:36
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
ajhoolcommented, Aug 22, 2018

Creating individual ts bundles for microservices in a monorepo has become a little bit of a nightmare due to recent improvements in dependency management, ironically. It had been as simple as copying node_modules into dist, zipping, and deploying to aws lambda.

Yarn workspaces, project references, and lerna all bring useful tooling but move dependencies into hard-to-reach places via hoisting or other magic. I expect a lot of people to be confused about how to build -> bundle w/ dependencies. Project references and workspaces are alluring but come with some possibly surprising hazards

8reactions
peterjurascommented, Mar 30, 2019

Any updates on whether outDir based projects can be prepended?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declaring Package with dependencies in multiples files?
If you want to develop several applications which refer to each other, you can do this using project references. Suppose that you have...
Read more >
PackageReference in project files - NuGet - Microsoft Learn
Package references, using <PackageReference> MSBuild items, specify NuGet package dependencies directly within project files, as opposed to ...
Read more >
Declaring dependencies - Gradle User Manual
The following example declares the dependencies on the utils and api project from the web-service project. The method Project.project(java.lang.String) creates ...
Read more >
Output Management - webpack
The generated bundles would be renamed on a build, but our index.html file would still reference the old names. Let's fix that with...
Read more >
Bigger Applications - Multiple Files - FastAPI
As it is inside a Python package (a directory with a file __init__.py ), it is a "module" of that package: app.main ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found