Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to NPM #23

Merged
merged 4 commits into from Sep 26, 2022
Merged

Publish to NPM #23

merged 4 commits into from Sep 26, 2022

Conversation

penalosa
Copy link
Collaborator

@penalosa penalosa commented Sep 26, 2022

Pending this repo being made public, this enables publishing to NPM (for Miniflare's consumption), modelled after the approach of esbuild. The scripts added in the Makefile will ideally be moved to a github action after the repo is made public.

What the trigger should be for that GH action is definitely a discussion point to have—my current thinking is that we should build on every commit to main, and publish new 1.{version}.0 packages to NPM whenever the compatibility date changes (and trigger a GH release with downloadable assets). It might also be useful to publish every commit as 1.{version}.{patchversion} to NPM if the compatibility date hasn't changes since the last release.

Makefile Outdated
@@ -0,0 +1,78 @@

LATEST_COMPATIBILITY_DATE=$(shell bazel build @capnp-cpp//src/capnp:capnp_tool && bazel-bin/external/capnp-cpp/src/capnp/capnp_tool eval src/workerd/io/compatibility-date.capnp supportedCompatibilityDate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a Makefile is likely fine for launch but given that there are bazel rules to support publishing to npm and we use bazel for everything else, we should likely convert this into a bazel task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed we should probably have a comment like # TODO(cleanup): Convert to bazel rules?

Makefile Outdated
LATEST_COMPATIBILITY_DATE=$(shell bazel build @capnp-cpp//src/capnp:capnp_tool && bazel-bin/external/capnp-cpp/src/capnp/capnp_tool eval src/workerd/io/compatibility-date.capnp supportedCompatibilityDate)
WORKERD_VERSION=1.$(shell bazel build @capnp-cpp//src/capnp:capnp_tool && bazel-bin/external/capnp-cpp/src/capnp/capnp_tool eval src/workerd/io/compatibility-date.capnp supportedCompatibilityDate | tr -d '-' | tr -d '"').0

platform-bazel-build:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the targets in this makefile appear to be actual files to be built. Instead it looks like you're using make as a way to write a shell script with multiple entrypoints. I think it would be better to write this as an actual shell script. It's easy to use case to match the first argument. Make doesn't really provide any advantages over shell when the targets aren't actually files. I would use bash (#! /bin/bash) and make sure to use set -euo pipefail at the start of the script to turn on error checking.

This would also help make it clear that this makefile is not intended to build the project. Otherwise I think many people will see Makefile and immediately assume they should use make to build the code, which will confusingly then do npm-related work.

@@ -0,0 +1,297 @@
// Adapted from evanw/esbuild
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a derivative work it should probably mention the original copyright and license.

@@ -6,7 +6,7 @@

$import "/capnp/c++.capnp".namespace("workerd");

const supportedCompatibilityDate :Text = "2022-09-17";
const supportedCompatibilityDate :Text = "2022-09-20";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's either bump this to today or leave it out of the PR.

Copy link
Contributor

@mrbbot mrbbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, evanw should really try bundling this publishing logic up as a separate package. 😅 Added a few comments. 👍

Makefile Outdated
@@ -0,0 +1,78 @@

LATEST_COMPATIBILITY_DATE=$(shell bazel build @capnp-cpp//src/capnp:capnp_tool && bazel-bin/external/capnp-cpp/src/capnp/capnp_tool eval src/workerd/io/compatibility-date.capnp supportedCompatibilityDate)
WORKERD_VERSION=1.$(shell bazel build @capnp-cpp//src/capnp:capnp_tool && bazel-bin/external/capnp-cpp/src/capnp/capnp_tool eval src/workerd/io/compatibility-date.capnp supportedCompatibilityDate | tr -d '-' | tr -d '"').0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use LATEST_COMPATIBILITY_DATE here?

npm/lib/node-install.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,6 @@
# 👷 `workerd` for macOS 64-bit, Cloudflare's JavaScript/Wasm Runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why esbuild checks the npm/* folders into the repository? Is this required for npm to fetch the README.md correctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure, but I think it just makes it easier to manage. I suppose each folder could be generated while publishing?

npm/workerd-darwin-64/package.json Outdated Show resolved Hide resolved
@penalosa penalosa self-assigned this Sep 26, 2022
npm.sh Outdated Show resolved Hide resolved
npm.sh Outdated Show resolved Hide resolved
npm/lib/node-install.ts Outdated Show resolved Hide resolved
npm/workerd/package.json Outdated Show resolved Hide resolved
@Electroid Electroid added the chore Tasks to improve the repository or builds label Sep 26, 2022
@kentonv kentonv merged commit d9b461a into main Sep 26, 2022
@kentonv kentonv deleted the build-and-publish branch September 26, 2022 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Tasks to improve the repository or builds
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants