Skip to content

Commit

Permalink
Rename prisma-fmt-wasm -> prisma-schema-wasm (prisma#4033)
Browse files Browse the repository at this point in the history
Co-authored-by: Joël Galeran <[email protected]>
  • Loading branch information
Druue and Jolg42 authored Jul 3, 2023
1 parent 27eb244 commit 43aefb4
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 93 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ on:
- main
pull_request:
paths-ignore:
- '.buildkite/**'
- '*.md'
- 'LICENSE'
- 'CODEOWNERS'
- 'renovate.json'
- ".buildkite/**"
- "*.md"
- "LICENSE"
- "CODEOWNERS"
- "renovate.json"

jobs:
build:
name: "prisma-fmt-wasm build ${{ github.event.ref }} for commit ${{ github.event.inputs.commit }}"
name: "prisma-schema-wasm build ${{ github.event.ref }} for commit ${{ github.event.inputs.commit }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22

- run: nix build .#prisma-fmt-wasm
- run: nix build .#prisma-schema-wasm
- run: nix flake check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build and publish @prisma/prisma-fmt-wasm
name: Build and publish @prisma/prisma-schema-wasm

concurrency: build-prisma-fmt-wasm
concurrency: build-prisma-schema-wasm

on:
# usually triggered via GH Actions Workflow in prisma/engines-wrapper repo
Expand All @@ -12,16 +12,16 @@ on:
required: true
npmDistTag:
required: true
default: 'latest'
default: "latest"

jobs:
build:
name: Build and publish @prisma/prisma-fmt-wasm
name: Build and publish @prisma/prisma-schema-wasm
runs-on: ubuntu-latest
steps:
- name: Print input
env:
THE_INPUT: '${{ toJson(github.event.inputs) }}'
THE_INPUT: "${{ toJson(github.event.inputs) }}"
run: |
echo $THE_INPUT
Expand All @@ -34,21 +34,21 @@ jobs:
# Build
#

- run: nix build .#prisma-fmt-wasm
- run: nix build .#prisma-schema-wasm

#
# Publish
#

- uses: actions/setup-node@v3
with:
node-version: '14.x'
node-version: "14.x"

- name: Set up NPM token
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- run: |
PACKAGE_DIR=$( nix run .#renderPrismaFmtWasmPackage ${{ github.event.inputs.enginesWrapperVersion }})
PACKAGE_DIR=$( nix run .#renderPrismaSchemaWasmPackage ${{ github.event.inputs.enginesWrapperVersion }})
npm publish "$PACKAGE_DIR" --access public --tag ${{ github.event.inputs.npmDistTag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -65,6 +65,6 @@ jobs:
if: ${{ failure() }}
uses: rtCamp/[email protected]
env:
SLACK_TITLE: 'prisma-fmt-wasm publishing failed :x:'
SLACK_COLOR: '#FF0000'
SLACK_TITLE: "prisma-schema-wasm publishing failed :x:"
SLACK_COLOR: "#FF0000"
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_WASM_FAILING }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ dev_datamodel.prisma
dmmf.json
graph.dot

prisma-fmt-wasm/nodejs
prisma-schema-wasm/nodejs
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ members = [
"query-engine/schema",
"libs/*",
"prisma-fmt",
"prisma-fmt-wasm",
"prisma-schema-wasm",
"psl/*",
]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ The engine uses:
## Prisma format

Prisma format can format prisma schema files. It also comes as a WASM module via
a node package. You can read more [here](./prisma-fmt-wasm/README.md).
a node package. You can read more [here](./prisma-schema-wasm/README.md).

## Debugging

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
./nix/cli-prisma.nix
./nix/dev-vm.nix
./nix/memory-profiling.nix
./nix/prisma-fmt-wasm.nix
./nix/prisma-schema-wasm.nix
./nix/publish-engine-size.nix
./nix/shell.nix
];
Expand Down
8 changes: 4 additions & 4 deletions nix/cli-prisma.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{ config, pkgs, self', ... }:

# This is an impure build for prisma/prisma. We need this because of the way we
# pakage `prisma-fmt-wasm` and the fact that there's no `pnpm2nix`.
# package `prisma-schema-wasm` and the fact that there's no `pnpm2nix`.
# See https://zimbatm.com/notes/nix-packaging-the-heretic-way for more details
# on impure builds.
let
fmt-wasm = self'.packages.prisma-fmt-wasm;
schema-wasm = self'.packages.prisma-schema-wasm;
version = "4.11.0";
in
{
Expand All @@ -30,8 +30,8 @@ in
patchShebangs .
# Remove prisma-fmt and copy it over from our local build.
rm node_modules/prisma/build/prisma_fmt_build_bg.wasm
cp ${fmt-wasm}/src/prisma_fmt_build_bg.wasm node_modules/prisma/build/prisma_fmt_build_bg.wasm
rm node_modules/prisma/build/prisma_schema_build_bg.wasm
cp ${schema-wasm}/src/prisma_schema_build_bg.wasm node_modules/prisma/build/prisma_schema_build_bg.wasm
# Copy node_modules and everything else.
mkdir -p $out/share
Expand Down
24 changes: 12 additions & 12 deletions nix/prisma-fmt-wasm.nix → nix/prisma-schema-wasm.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{ pkgs, system, self', ... }:

let
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../prisma-fmt-wasm/rust-toolchain.toml;
scriptsDir = ../prisma-fmt-wasm/scripts;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../prisma-schema-wasm/rust-toolchain.toml;
scriptsDir = ../prisma-schema-wasm/scripts;
inherit (pkgs) jq nodejs coreutils wasm-bindgen-cli stdenv;
inherit (builtins) readFile replaceStrings;
in
{
packages.prisma-fmt-wasm = stdenv.mkDerivation {
name = "prisma-fmt-wasm";
packages.prisma-schema-wasm = stdenv.mkDerivation {
name = "prisma-schema-wasm";
nativeBuildInputs = with pkgs; [ git wasm-bindgen-cli toolchain ];
inherit (self'.packages.prisma-engines) configurePhase src;

buildPhase = "cargo build --release --target=wasm32-unknown-unknown -p prisma-fmt-build";
buildPhase = "cargo build --release --target=wasm32-unknown-unknown -p prisma-schema-build";
installPhase = readFile "${scriptsDir}/install.sh";
};

# Takes a package version as its single argument, and produces
# prisma-fmt-wasm with the right package.json in a temporary directory,
# prisma-schema-wasm with the right package.json in a temporary directory,
# then prints the directory's path. This is used by the publish pipeline in CI.
packages.renderPrismaFmtWasmPackage =
packages.renderPrismaSchemaWasmPackage =
pkgs.writeShellApplication {
name = "renderPrismaFmtWasmPackage";
name = "renderPrismaSchemaWasmPackage";
runtimeInputs = [ jq ];
text = ''
set -euxo pipefail
PACKAGE_DIR=$(mktemp -d)
cp -r --no-target-directory ${self'.packages.prisma-fmt-wasm} "$PACKAGE_DIR"
cp -r --no-target-directory ${self'.packages.prisma-schema-wasm} "$PACKAGE_DIR"
rm -f "$PACKAGE_DIR/package.json"
jq ".version = \"$1\"" ${self'.packages.prisma-fmt-wasm}/package.json > "$PACKAGE_DIR/package.json"
jq ".version = \"$1\"" ${self'.packages.prisma-schema-wasm}/package.json > "$PACKAGE_DIR/package.json"
echo "$PACKAGE_DIR"
'';
};
Expand All @@ -41,7 +41,7 @@ in
text = replaceStrings [ "$WASM_BINDGEN_VERSION" ] [ wasm-bindgen-cli.version ] template;
};

checks.prismaFmtWasmE2E = pkgs.runCommand "prismaFmtWasmE2E"
{ PRISMA_FMT_WASM = self'.packages.prisma-fmt-wasm; NODE = "${nodejs}/bin/node"; }
checks.prismaSchemaWasmE2E = pkgs.runCommand "prismaSchemaWasmE2E"
{ PRISMA_SCHEMA_WASM = self'.packages.prisma-schema-wasm; NODE = "${nodejs}/bin/node"; }
(readFile "${scriptsDir}/check.sh");
}
26 changes: 0 additions & 26 deletions prisma-fmt-wasm/scripts/update-fmt-wasm.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "prisma-fmt-build"
name = "prisma-schema-build"
version = "0.1.0"
edition = "2021"

Expand Down
20 changes: 10 additions & 10 deletions prisma-fmt-wasm/README.md → prisma-schema-wasm/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @prisma/prisma-fmt-wasm
# @prisma/prisma-schema-wasm

[![Publish pipeline](https://github.com/prisma/prisma-engines/actions/workflows/publish-prisma-fmt-wasm.yml/badge.svg)](https://github.com/prisma/prisma-engines/actions/workflows/publish-prisma-fmt-wasm.yml)
[![npm package](https://img.shields.io/npm/v/@prisma/prisma-fmt-wasm/latest)](https://www.npmjs.com/package/@prisma/prisma-fmt-wasm)
[![install size](https://packagephobia.com/badge?p=@prisma/prisma-fmt-wasm)](https://packagephobia.com/result?p=@prisma/prisma-fmt-wasm)
[![Publish pipeline](https://github.com/prisma/prisma-engines/actions/workflows/publish-prisma-schema-wasm.yml/badge.svg)](https://github.com/prisma/prisma-engines/actions/workflows/publish-prisma-schema-wasm.yml)
[![npm package](https://img.shields.io/npm/v/@prisma/prisma-schema-wasm/latest)](https://www.npmjs.com/package/@prisma/prisma-schema-wasm)
[![install size](https://packagephobia.com/badge?p=@prisma/prisma-schema-wasm)](https://packagephobia.com/result?p=@prisma/prisma-schema-wasm)

This directory only contains build logic to package the `prisma-fmt` engine
into a Node package as a WASM module. All the functionality is implemented in
Expand All @@ -13,15 +13,15 @@ The published NPM package is internal to Prisma. Its API will break without prio
## Example

```bash
node -e "const prismaFmt = require('@prisma/prisma-fmt-wasm'); console.log(prismaFmt.version())"
node -e "const prismaSchema = require('@prisma/prisma-schema-wasm'); console.log(prismaSchema.version())"
```

## Components

- The GitHub Actions workflow that publishes the NPM package: https://github.com/prisma/prisma-engines/blob/main/.github/workflows/publish-prisma-fmt-wasm.yml
- The GitHub Actions workflow that publishes the NPM package: https://github.com/prisma/prisma-engines/blob/main/.github/workflows/publish-prisma-schema-wasm.yml
- It is triggered from the https://github.com/prisma/engines-wrapper publish action.
- The [Rust source code](https://github.com/prisma/prisma-engines/tree/main/prisma-fmt-wasm/src) for the wasm module
- The [nix build definition](https://github.com/prisma/prisma-engines/blob/main/prisma-fmt-wasm/default.nix)
- The [Rust source code](https://github.com/prisma/prisma-engines/tree/main/prisma-schema-wasm/src) for the wasm module
- The [nix build definition](https://github.com/prisma/prisma-engines/blob/main/prisma-schema-wasm/default.nix)
- It gives us a fully reproducible, thoroughly described build process and environment. The alternative would be a bash script with installs through `rustup`, `cargo install` and `apt`, with underspecified system dependencies and best-effort version pinning.
- You can read more about nix on [nix.dev](https://nix.dev/) and the [official website](https://nixos.org/).

Expand All @@ -35,14 +35,14 @@ When implementing features for `language-tools` in `prisma-engines`, to sync wit
rustup update
rustup target add wasm32-unknown-unknown
cargo update -p wasm-bindgen
# Check the version defined in `prisma-fmt-wasm/cargo.toml` for `wasm-bindgen` and replace `version` below:
# Check the version defined in `prisma-schema-wasm/cargo.toml` for `wasm-bindgen` and replace `version` below:
cargo install -f wasm-bindgen-cli@version
```

### On Changes

```bash
./prisma-fmt-wasm/scripts/update-fmt-wasm.sh
./prisma-schema-wasm/scripts/update-schema-wasm.sh
```

This script has the following expectations:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@prisma/prisma-fmt-wasm",
"name": "@prisma/prisma-schema-wasm",
"version": null,
"description": "The WASM package for prisma-fmt",
"main": "src/prisma_fmt_build.js",
"main": "src/prisma_schema_build.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/prisma/prisma-engines",
"directory": "prisma-fmt-wasm"
"directory": "prisma-schema-wasm"
},
"author": "Prisma",
"license": "Apache-2.0",
"homepage": "https://github.com/prisma/prisma-engines"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -euo pipefail

echo -n '1. The final wasm file is not empty: '

EXPECTED_FINAL_WASM_FILE_PATH="$PRISMA_FMT_WASM/src/prisma_fmt_build_bg.wasm";
EXPECTED_FINAL_WASM_FILE_PATH="$PRISMA_SCHEMA_WASM/src/prisma_schema_build_bg.wasm";
WASM_FILE_SIZE=$(wc -c "$EXPECTED_FINAL_WASM_FILE_PATH" | sed 's/ .*$//')

if [[ $WASM_FILE_SIZE == '0' ]]; then
Expand All @@ -20,7 +20,7 @@ echo 'ok.'

echo '2. We can call the module directly and get back a valid result.'

REFORMATTED_MEOW=$($NODE -e "const prismaFmt = require('$PRISMA_FMT_WASM'); console.log(prismaFmt.format('meow', '{}'))")
REFORMATTED_MEOW=$($NODE -e "const prismaSchema = require('$PRISMA_SCHEMA_WASM'); console.log(prismaSchema.format('meow', '{}'))")

echo "REFORMATTED_MEOW=$REFORMATTED_MEOW"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ printf '%s\n' " -> Creating out dir..."
mkdir -p "$out"/src

printf '%s\n' " -> Copying package.json"
cp ./prisma-fmt-wasm/package.json "$out"/
cp ./prisma-schema-wasm/package.json "$out"/

printf '%s\n' " -> Copying README.md"
cp ./prisma-fmt-wasm/README.md "$out"/
cp ./prisma-schema-wasm/README.md "$out"/

printf '%s\n' " -> Generating node package"
wasm-bindgen \
--target nodejs \
--out-dir "$out"/src \
target/wasm32-unknown-unknown/release/prisma_fmt_build.wasm
target/wasm32-unknown-unknown/release/prisma_schema_build.wasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

echo 'Syncing wasm-bindgen version in crate with that of the installed CLI...'
sed -i "s/^wasm-bindgen\ =.*$/wasm-bindgen = \"=$WASM_BINDGEN_VERSION\"/" ./prisma-fmt-wasm/Cargo.toml
sed -i "s/^wasm-bindgen\ =.*$/wasm-bindgen = \"=$WASM_BINDGEN_VERSION\"/" ./prisma-schema-wasm/Cargo.toml
cargo update --package wasm-bindgen
Loading

0 comments on commit 43aefb4

Please sign in to comment.