typed-ember / glint

TypeScript powered tooling for Glimmer templates
https://typed-ember.gitbook.io/glint
MIT License
109 stars 51 forks source link

Yarn Workspaces support #136

Closed chrismllr closed 1 year ago

chrismllr commented 3 years ago

First off, love the work being done here, so thank you to the contributors!

I'm currently looking to use glint in a typescript monorepo, where we've got a ts node app, some utility libraries, and an ember app.

I am aware of the current limitation of .glintrc needing to be in the root, and I'm seeing this error within the VSCode extension output when doing so:

/Users/user/repo/node_modules/@glint/transform/lib/util.js:10
        throw new Error(message);
        ^

Error: Internal error: offset out of bounds
    at Object.assert (/Users/user/repo/node_modules/@glint/transform/lib/util.js:10:15)
    at TransformedModule.determineOriginalOffsetAndSpan (/Users/user/repo/node_modules/@glint/transform/lib/transformed-module.js:83:16)
    at TransformedModule.getOriginalRange (/Users/user/repo/node_modules/@glint/transform/lib/transformed-module.js:34:28)
    at Object.rewriteDiagnostic (/Users/user/repo/node_modules/@glint/transform/lib/index.js:28:52)
    at TransformManager.rewriteDiagnostic (/Users/user/repo/node_modules/@glint/core/lib/common/transform-manager.js:80:28)
    at /Users/user/repo/node_modules/@glint/core/lib/language-server/glint-language-server.js:86:52
    at Array.flatMap (<anonymous>)
    at GlintLanguageServer.getDiagnostics (/Users/user/repo/node_modules/@glint/core/lib/language-server/glint-language-server.js:85:11)
    at Timeout._onTimeout (/Users/user/repo/node_modules/@glint/core/lib/language-server/binding.js:69:52)
    at listOnTimeout (internal/timers.js:554:17)

Repo structure:

├── .glintrc.yml
├── packages
│   └── ui
│       └── app

.glintrc

environment: ember-loose
include:
  - packages/ui/app/**

Assuming this is an issue with using glint on a nested directory. Is there any plan on supporting yarn workspaces/ monorepos? Or is there any way to make the current configuration work with the .glintrc in the root?

chrismllr commented 3 years ago

Additional Note: Running glint using the CLI works (when the file is in the subdirectory), this is likely a request specific to the VSCode extension.

Updating, realized the caveat indeed includes the build tooling, not just the VSCode Plugin

dfreeman commented 3 years ago

Assuming this is an issue with using glint on a nested directory. Is there any plan on supporting yarn workspaces/ monorepos?

Currently how I have things set up in monorepos is with a .glintrc directly in the application directory(/ies), which it sounds like would be packages/ui for you. I then open VS Code rooted in that directory (and run the glint CLI from there as well), which allows everything to work as expected.

With this repo as an example, the ts-ember-app and ts-glimmerx-app packages under test-packages are both set up this way, and when I'm testing things out in them I usually do something like code test-packages/* at the command line, which opens up a single workspace with one root per test-package.

Getting things to Just Work so you can open your whole monorepo instead of specific subdirectories is definitely on our radar, I just can't promise how quickly we'll get there 🙂

chrismllr commented 3 years ago

@dfreeman Ah that makes sense! I may have been caught up about always opening the project at the project root. I hadn't considered opening each as a "workspace" in the same window. Will give this a go. Thanks for the response!

runspired commented 2 years ago

pretty frustrating to need to open the subdirectory. Any ideas on what it would take to patch this?

runspired commented 2 years ago

I found a nice workaround fwiw:

my root has my tsconfigs and glint config, my sub-project re-exports the tsconfig. This makes eslint, vscode, and glint happy regardless of where they are invoked from.

dfreeman commented 2 years ago

@chriskrycho was looking into general support for workspaces + composite projects both here and in ember-cli-typescript, though I think that's (understandably!) taken a backseat recently to driving the First Class Component Templates and TS Adoption RFCs.

ef4 commented 2 years ago

@runspired thanks for the tip. Moving the tsconfig and glintrc to the root worked for me.

dfreeman commented 2 years ago

As of #354 we no longer require you to configure Glint/open your editor at the root of your monorepo, and Chris has picked back up the work to get --build mode working for building composite projects from the CLI. Taken together, I think we're on track to be able to close this out when we release 0.9.x.

chriskrycho commented 2 years ago

FWIW, my latest investigation has this working in nested TS projects (it doesn’t have to be in the root), but I found an edge case with nested JS projects that we’ll try to resolve. One caveat on that: you may still want a root glint config in a root tsconfig.json for things which are shared across all sub-projects, e.g. a shared types directory, so that you don’t have to have a file open in one of the sub-projects to have things “work” in those shared files.

chriskrycho commented 1 year ago

This all works as of latest Glint!