Skip to content

Conversation

@savetheclocktower
Copy link
Contributor

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/atom dependency (the one that points to our own @pulsar-edit/types package) because those types are handy to have even for JS-only projects if the user has pulsar-ide-typescript installed. (Also, now that our types package is published to NPM, I've updated the package.json templates 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

bin/npm init --package some-package --syntax javascript --transpiled

to generate a JS package and opt into the “transpiled” flavor. (This new --transpiled flag has no effect unless you've opted into JavaScript.) Once you've generated the package, cd into the new directory, run ppm link --dev . to create a symlink in to ~/.pulsar/dev/packages, then run pulsar --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 install and then npm run build from 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).

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

Successfully merging this pull request may close these issues.

2 participants