Add javascript transpiled template #161
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR will be very similar to #152. I probably should've done both at once.
A Pulsar user writing a package for the first time in the year 2025 will discover that some of the dependencies they might want to use are ESM-only. Over time, this will become an even more common method of distribution. This is a problem for Pulsar because the renderer process is CJS-only, at least if you want to be able to use dependencies from the Node universe. This is a rigid requirement and Electron is unlikely to be able to change it in the near future.
This won't affect some kinds of packages. And, indeed, if you want to solve the ESM-only problem without transpiling your code, you can probably find an older version of the same dependency that had a CJS bundle, or find another package that does a similar thing and can serve up CJS. (Core packages can use these tactics to stave off transpilation for now.)
But it's better if users don't have to care about this! Hence this PR adds a new package template that sets them up with something that will automatically transpile ESM dependencies to CJS, where possible. (It's possible unless the ESM module uses bleeding-edge features like top-level
await, but this is pretty rare.)The TypeScript template in #152 already had this toolchain. This is the same thing, but for people who prefer to write in JavaScript.
This template therefore omits the TypeScript dependencies from
package.json… but it keeps the@types/atomdependency (the one that points to our own@pulsar-edit/typespackage) because those types are handy to have even for JS-only projects if the user haspulsar-ide-typescriptinstalled. (Also, now that our types package is published to NPM, I've updated thepackage.jsontemplates for both transpiled-JS and TypeScript to reference the NPM version of the library.)Testing
Specs are updated. But for manual testing, you can run something like
to generate a JS package and opt into the “transpiled” flavor. (This new
--transpiledflag has no effect unless you've opted into JavaScript.) Once you've generated the package,cdinto the new directory, runppm link --dev .to create a symlink in to~/.pulsar/dev/packages, then runpulsar --dev .to open a new dev-mode window for the package.You should be able to invoke (name of your package): Toggle in the command palette and trigger the “you must transpile this package first!” notification. You should also be able to run
npm installand thennpm run buildfrom the terminal, then reload your Pulsar window… and now (name of your package): Toggle should do the standard thing (create a new panel and put some silly text in it).