Skip to content

Instantly share code, notes, and snippets.

@mousetraps
Last active February 23, 2016 18:32
Show Gist options
  • Save mousetraps/9b41153915411711f090 to your computer and use it in GitHub Desktop.
Save mousetraps/9b41153915411711f090 to your computer and use it in GitHub Desktop.

Node.js tooling: Engineering working notes

🏃 In-progress and incomplete: still trying to wrap my head around much of it, coordinating with partner teams to enable the right interfaces, etc., and there are a bunch of unanswered Qs, but just wanted to get the conversation started.

###Goal: Build Best-of-Breed Node.js Developer Experiences In particular, we'll be focusing on inner-loop development, but at the same time we'll want to ensure that the same awesome experience transcends product/service boundaries.

####Table Stakes First and foremost, it's important that we agree on a set of table stakes. These are the experiences that are really foundational - without them, it's a no-op.

  • Debugging (including sourcemaps) needs to be consistent and reliable
  • Really easy and lightweight project configuration - minimize time-to-F5
  • Consistent and just-works IntelliSense with a gracefully degrading experience.
  • Keep up with the constantly changing landscape: Node, JS, TS, Babel, JSX, etc.

####Execution One of the challenges about building tooling for Node.js is that we're building on top of a fast-moving platform, so it becomes that much more important to ensure that our efforts are aligned engineering-wise. In that vein, we're currently working to see how we can best leverage and consolidate our Node.js tooling efforts across VS & VSCode to enable us to move faster on both products and also provide a more seamless round-tripping experience between the two.

The basic idea is that we have a few stages to roll out here:

  • Node+VSCode and Node+VS are each at different stages in their development and have their own set of immediate priorities to execute on.
  • Combined engineering efforts, basically how do we share as much code as possible? This'll help us move faster as a team, and also help us enable a more seamless experience across product boundaries.
  • new features and future scenarios, which will be built from the beginning with the intent of sharing as much code as possible.

The next several sections dig deeper into each one of these areas. Also note that the intent of this document is to focus on some of the 'big rocks' rather than iterative changes, which, of course, we will continue to execute on in parallel.

Node.js + VSCode

Mostly prepping for GA, componentizing & producing solid platform, patching issues, or low-hanging fruit features. VSCode's roadmap is posted here: https://github.com/Microsoft/vscode/wiki/Roadmap

Node.js + VS

We recently release v1.1, so we are starting to investigate some of the big-ticket items on our plate. Added the beginnings of a roadmap below, but this is pretty raw at the moment, and still fleshing out some details before posting more broadly.

Product

  • Ship NTVS 1.1.1
  • Adopt file/folder-based project system
    • works better with node.js workflow
  • Tightly integrated task runner support
  • Lightweight installation option
  • Migrate to Salsa when we have automatic d.ts acquisition
    • helps solve perf issues with analysis engine
    • ES6 support
    • reduces duplicated effort
    • Better consistency w/ other JS-isms
  • Dev15 Support
  • Appear in VS installer feed to increase discoverability
  • Migrate to TypeScript source-map codebase
    • reduce duplication of effort
    • new features like tsconfig

Code happiness

  • Test infrastructure improvements
  • Update Web Tools npm component
  • Migrate processes & assets through org transition

Combined engineering

Goal: share as much code as possible between VS & VSCode-Node efforts, whilst enabling each product to evolve to meet the needs of their own communities.

The same build script would build for both products, and the CI server would take care of both VS & VSCode builds. This would ensure that it is easier for us to achieve our round-tripping and duplication-reduction goals between VS & VSCode, as well as enable us to keep both products updated with the latest changes.

Additionally...

  • Shared debugging & sourcemapping codebase to enable us to more easily keep up with node / javascript
    • better diagnostics to help us iterate towards the most reliable debugging experience.
  • Work with other teams in VS to prevent duplication of effort (e.g. webkit debug engine)
  • Easy round-tripping between VSCode & NTVS

At some point, a central "Node.js Tools" repo was proposed because it may enable us to more easily engage with the Node.js segment of the VS & VSCode communities (note that this does not imply that both products will share the same featureset.) While this would make it much easier for us from a technical standpoint, it may actually have a negative effect on the communities themselves - multiple product roadmaps could be confusing, and we don't want one community to feel drowned out by another.

Current VS/VSCode Feature-set comparison [in-progress]

This is meant to help us reason about the current products and better understand potential ways to share code with each of these features. Over time, we will fill in each one of the sections with more details. Also note that this is a very surface-level understanding of the state-of-the-world - e.g. even though both VSCode & VS have debugging & IntelliSense, there are, in fact, feature differences between the two implementations.

Feature Visual Studio VS Code Partner teams
Project Templates ✔️ VS Platform
launch.json/folder-based project system ✔️ VS Platform
.njsproj/MSBuild project system ✔️ Python Tools, VS Platform
V8 Debugger ✔️ ✔️ VS Debugging, Cordova webkit debug engine, maybe ASP.NET in the future
IntelliSense ✔️ ✔️ TypeScript
Node.js-specific snippets ✔️
Source Mapping ✔️ ✔️ TypeScript
Task-runner support ✔️ ✔️ Web Tools
npm Integration ✔️ Web Tools
Interactive Window ✔️ Python Tools, Roslyn, etc.
Profiling ✔️ VS Diagnostics, Glimpse?
Unit testing ✔️ Potentially bring this to all JS projects in VS?
Deployment ✔️ Azure Tools
Options ✔️ ✔️

Combined Node Debugger

Scenarios to consider

Reduce code duplication, and thereby respond to the following events once, rather than twice:

  • V8's protocol changes.
  • Enable other JS engines / Chakra-specific functionality (e.g. TTD)
  • Node.js version causes breaking changes that we want to detect and warn the user about.
  • Aggregate data and enable deeper diagnostics.
  • Iterate quickly towards a stable debugging experience
  • Source mapping? (are we using this for anything other than debugging?)

Enable the following new scenarios:

  • Attach and roam state between multiple toolsets (e.g. Glimpse)
  • Inject code during diagnostics (e.g. capturing state of event queue, handle child processes, etc.)
  • [REACH] If adopted by other tools like node-inspector, it could enable us to help improve experiences more broadly for TypeScript, Chakra, etc.
  • Increased community contributions to NTVS because the service would be written in Node.js
PROPOSED Extensible Node-Debug Adapter

image

The idea here would be to effectively turn the VS debug adapter into a shim for the VSCode adapter. And in order to enable VS and VSCode to evolve at different rates, we should consider an extensibility model that would enable us to light up new features before they become integrated into VSCode itself.

PROPOSED "Roaming Diagnostics Service"

image

We could strive for a service-based approach, where instead of actually spinning up the app in question and having a direct connection between VS & V8, we’d instead subscribe to a Node.js service that is handling all of these connections and providing the relevant information.

Next Steps

First step – currently digging into the VS / VSCode debugging interfaces to get a very thorough understanding of the two architectures and get more concrete on what it might mean to share code between the two. Additionally understanding how the functionality differs between the two will also be important.

We should also ensure to take advantage of the work of other teams who may have started or plan to start working through similar issues (powershell, python, cpp??), so hopefully we can get some ideas from them, but it also sounds like those teams are working with a very different set of constraints. For instance, unlike other teams, we’ll ideally want the bulk of our code to be written in Node.js if possible. Additionally, we have a bit of additional complexity with things like source-mapping. While we’re thinking through this too, I want to see how we could handle things like child processes better during debugging – currently those open up separate debug ports and it can be problematic when we fail to attach to them. I suspect we’ll need to intercept whichever low level functions fork the process in order to understand both when new ports are opened up and also what the port number is.

Future

Product

  • Async debugging
  • Time-travel debugging
  • Glimpse
  • Language service features / extensibility model
  • Platform / API improvements -> VSCode & VS

Principles and key learnings to bring forward

Debug-ability

The story

At some point, we started hitting flakey debugging issues with NTVS that were:

  • Frustrating for users
  • Impossible for us to reproduce
  • Impossible for the user to consistently reproduce

Given that debugging is one of our key value-adds, it's more critical than ever to ensure we can produce a solid experience. So we added a Live Diagnostics Pane that users could optionally enable, and then just copy the logs when running into these issues. It was easy for users to grab the relevant logs to their session, as they are all clearly demarcated, and it enabled us to resolve a number of threading issues in a very short period of time based off of just diffing the logs against a working version and then reasoning about the code itself.

Going forward

This feature was really successful in helping us diagnose issues, so it would be great to see just how far we can run with it. Some ideas include:

  • making it more discoverable - detecting when debugging is not working, and providing the right interfaces to diagnose and provide us with the right information to iterate on the experience. Maybe something similar to how Windows sometimes detects something wonky with the installation, so it'll ask you if it installed OK.
  • add live-logging to collect relevant source-map info?

To be continued...

Open Questions

  • There will be a disparity in featureset between VS & VSCode. The question, then, becomes what that is, and whether we ever plan on resolving it. In order to answer this Q, we'll need to consider required engineering effort, UI paradigms, worflows, etc. Either way, if possible, we should aim to design things in a way that is portable.
  • The modularity Q: are there things that belong in a separate extension, rather than in the main codebase.
  • Optimistically, we can say "hey, we're doing the same thing in two different places... what if we just built one thing that plugged into those two places?" And all this consolidation work sounds great in theory, but the fact is that this won't be easy and so far we haven't landed on, tangibly, what this means.
  • Timelines? Currently working on fleshing this out. Due to all the partner team dependencies, it may get complicated...
  • To be continued...

Other

In addition to this engineering work, we should continue to focus on recruiting / growing the team, as well as continuing to engage with the community in person, through blogs, videos, the guidelines repo, contributions to node, etc. as well as working with partner teams within Microsoft to ensure we're building best-of-breed experiences that extend beyond just inner-loop dev tooling (e.g. deployment, monitoring, etc.)

@jasonyueyang
Copy link

Regarding Node debugging in VS Code, we can prioritize the VS Code Debug Issues to select the initial set of improvements.

@jasonyueyang
Copy link

Here's the VS Code January iteration plan: microsoft/vscode#1826.

@jasonyueyang
Copy link

Better support for JSX, both in VS and VS Code, can be a useful improvement. Migrating to Salsa should help.

@mousetraps
Copy link
Author

@jasonyueyang - agreed. Salsa will definitely help with JSX.

Anyways, added a bunch more content, so lmk what you think! Does the initial framing capture the big rocks we've discussed? Additionally this is just semantics, but note the terminology change from "migration path" to "round-tripping", which implies more of a two-way street.

@joshgav
Copy link

joshgav commented Feb 11, 2016

Table Stakes
You might compact the bullet list as follows:

  • Debugging
  • Scaffolding (i.e. Yeoman)
  • Code completion (i.e. IntelliSense™)
  • Flexibility to support rapidly changing ecosystem (e.g. Node, TS, JSX, Babel)

VS and VSC
We have two significantly different audiences for VS and VSC and I think we should provide and manage components for each separately. This will help community understand and contribute to what's relevant to them without distractions. We could (should?) make them discoverable from each other and architect them to share as much as possible, but that can be mostly an internal benefit.

Are there plans for VS to adopt VSC debug protocol? I heard that from Chris Dias.

New Shared Debug Agent
Other new scenarios this enables:

  • Add new diagnostic experiences available in V8 or Chakra but not available in current V8 protocol, e.g. "Step Back", heap snapshot.
  • Bypass Node's built-in debug agent and talk directly to V8 - address concerns with only one socket, difficulty tracing fork's (child processes), etc.

I'd characterize this as an "out-of-process debug agent (daemon)" which tools like VS, VSC, Glimpse, and a CLI can spin up and talk to. Another benefit would be potential API/CLI access for those who prefer that, which would get the core community excited. So our story is, we use the debug agent to light up experiences within IDEs/Editors, and the deep technical community contributes to that core agent because it's useful outside of those tools too.

Future Opportunities

  • Additional diagnostics - heap snapshots, cpu profiling

@joshgav
Copy link

joshgav commented Feb 11, 2016

An alternative to Salsa to be aware of is TernJS.

@jasonyueyang
Copy link

The goals of this design exercise are the following:

  1. Identify how to improve the "depth" of the inner loop experience in VS Code. We don't need and should not try to cover everything VS does.
  2. Identify how to improve VS, e.g., by supporting the simplicity of Node dev workflow.
  3. Figure out where to consolidate in the technology stack so that we can have a common foundation for future enhancements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment