diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index 22de2aa39cef..ed983f64a919 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -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 diff --git a/.github/workflows/publish-prisma-fmt-wasm.yml b/.github/workflows/publish-prisma-schema-wasm.yml similarity index 73% rename from .github/workflows/publish-prisma-fmt-wasm.yml rename to .github/workflows/publish-prisma-schema-wasm.yml index 78666ac0021f..32de3d6bb142 100644 --- a/.github/workflows/publish-prisma-fmt-wasm.yml +++ b/.github/workflows/publish-prisma-schema-wasm.yml @@ -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 @@ -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 @@ -34,7 +34,7 @@ jobs: # Build # - - run: nix build .#prisma-fmt-wasm + - run: nix build .#prisma-schema-wasm # # Publish @@ -42,13 +42,13 @@ jobs: - 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 }} @@ -65,6 +65,6 @@ jobs: if: ${{ failure() }} uses: rtCamp/action-slack-notify@v2.2.0 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 }} diff --git a/.gitignore b/.gitignore index d892e175312d..43e03e31867d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ dev_datamodel.prisma dmmf.json graph.dot -prisma-fmt-wasm/nodejs +prisma-schema-wasm/nodejs diff --git a/Cargo.lock b/Cargo.lock index 82af5ad53e57..2b511eda3c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2968,15 +2968,6 @@ dependencies = [ "structopt", ] -[[package]] -name = "prisma-fmt-build" -version = "0.1.0" -dependencies = [ - "prisma-fmt", - "wasm-bindgen", - "wasm-logger", -] - [[package]] name = "prisma-models" version = "0.0.0" @@ -2992,6 +2983,15 @@ dependencies = [ "uuid 1.1.2", ] +[[package]] +name = "prisma-schema-build" +version = "0.1.0" +dependencies = [ + "prisma-fmt", + "wasm-bindgen", + "wasm-logger", +] + [[package]] name = "prisma-value" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f51ebd876f22..7cd3521e6078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ members = [ "query-engine/schema", "libs/*", "prisma-fmt", - "prisma-fmt-wasm", + "prisma-schema-wasm", "psl/*", ] diff --git a/README.md b/README.md index b796fc870e53..ef8cd61b4ef0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/flake.nix b/flake.nix index 335e3ee3a22a..67f4042d8c68 100644 --- a/flake.nix +++ b/flake.nix @@ -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 ]; diff --git a/nix/cli-prisma.nix b/nix/cli-prisma.nix index a51204134d53..fcbc6756ee95 100644 --- a/nix/cli-prisma.nix +++ b/nix/cli-prisma.nix @@ -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 { @@ -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 diff --git a/nix/prisma-fmt-wasm.nix b/nix/prisma-schema-wasm.nix similarity index 59% rename from nix/prisma-fmt-wasm.nix rename to nix/prisma-schema-wasm.nix index 454655f60ca4..b0f0c3d2d54a 100644 --- a/nix/prisma-fmt-wasm.nix +++ b/nix/prisma-schema-wasm.nix @@ -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" ''; }; @@ -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"); } diff --git a/prisma-fmt-wasm/scripts/update-fmt-wasm.sh b/prisma-fmt-wasm/scripts/update-fmt-wasm.sh deleted file mode 100755 index c02b88ade344..000000000000 --- a/prisma-fmt-wasm/scripts/update-fmt-wasm.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -## Dirs -prisma_fmt_wasm_dir="./prisma-fmt-wasm" -language_tools="../language-tools/" -language_tools_server="$language_tools/packages/language-server/" -language_tools_node="$language_tools_server/node_modules/@prisma/prisma-fmt-wasm/" - -[ ! -d "$language_tools" ] && echo "language-tools was not found at the same level as engines" && exit 1 - -[ ! -d "$prisma_fmt_wasm_dir" ] && echo "prisma_fmt_wasm was not found in the current directory" && exit 1 - -## Script -printf '%s\n' "Starting build :: prisma-fmt-wasm" -cargo build --release --target=wasm32-unknown-unknown --manifest-path=$prisma_fmt_wasm_dir/Cargo.toml - -printf '%s\n' "Generating node module" -out=$prisma_fmt_wasm_dir/nodejs $prisma_fmt_wasm_dir/scripts/install.sh - -printf '%s\n' "Removing pre-existing wasm in language-tools" -rm -rf $language_tools_node/src/* - -printf '%s\n' "Moving generated prisma-fmt-wasm :: engines -> language-tools" -cp $prisma_fmt_wasm_dir/nodejs/src/prisma_fmt_build{_bg.wasm,_bg.wasm.d.ts,.d.ts,.js} $language_tools_node/src diff --git a/prisma-fmt-wasm/Cargo.toml b/prisma-schema-wasm/Cargo.toml similarity index 87% rename from prisma-fmt-wasm/Cargo.toml rename to prisma-schema-wasm/Cargo.toml index 9b165137c305..6387aeedfbba 100644 --- a/prisma-fmt-wasm/Cargo.toml +++ b/prisma-schema-wasm/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "prisma-fmt-build" +name = "prisma-schema-build" version = "0.1.0" edition = "2021" diff --git a/prisma-fmt-wasm/README.md b/prisma-schema-wasm/README.md similarity index 69% rename from prisma-fmt-wasm/README.md rename to prisma-schema-wasm/README.md index 2279524e8612..97186f4afe74 100644 --- a/prisma-fmt-wasm/README.md +++ b/prisma-schema-wasm/README.md @@ -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 @@ -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/). @@ -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: diff --git a/prisma-fmt-wasm/package.json b/prisma-schema-wasm/package.json similarity index 74% rename from prisma-fmt-wasm/package.json rename to prisma-schema-wasm/package.json index bf82fd3c2689..d90119b1f59b 100644 --- a/prisma-fmt-wasm/package.json +++ b/prisma-schema-wasm/package.json @@ -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" -} +} \ No newline at end of file diff --git a/prisma-fmt-wasm/rust-toolchain.toml b/prisma-schema-wasm/rust-toolchain.toml similarity index 100% rename from prisma-fmt-wasm/rust-toolchain.toml rename to prisma-schema-wasm/rust-toolchain.toml diff --git a/prisma-fmt-wasm/scripts/check.sh b/prisma-schema-wasm/scripts/check.sh similarity index 77% rename from prisma-fmt-wasm/scripts/check.sh rename to prisma-schema-wasm/scripts/check.sh index 46f467ed8f9e..860c34c5e925 100755 --- a/prisma-fmt-wasm/scripts/check.sh +++ b/prisma-schema-wasm/scripts/check.sh @@ -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 @@ -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" diff --git a/prisma-fmt-wasm/scripts/install.sh b/prisma-schema-wasm/scripts/install.sh similarity index 69% rename from prisma-fmt-wasm/scripts/install.sh rename to prisma-schema-wasm/scripts/install.sh index d56db399b4a9..541eca728805 100755 --- a/prisma-fmt-wasm/scripts/install.sh +++ b/prisma-schema-wasm/scripts/install.sh @@ -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 diff --git a/prisma-fmt-wasm/scripts/syncWasmBindgenVersions.sh b/prisma-schema-wasm/scripts/syncWasmBindgenVersions.sh similarity index 82% rename from prisma-fmt-wasm/scripts/syncWasmBindgenVersions.sh rename to prisma-schema-wasm/scripts/syncWasmBindgenVersions.sh index 1f8c7390ac68..921afc45db09 100755 --- a/prisma-fmt-wasm/scripts/syncWasmBindgenVersions.sh +++ b/prisma-schema-wasm/scripts/syncWasmBindgenVersions.sh @@ -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 diff --git a/prisma-schema-wasm/scripts/update-schema-wasm.sh b/prisma-schema-wasm/scripts/update-schema-wasm.sh new file mode 100755 index 000000000000..6d89053ec164 --- /dev/null +++ b/prisma-schema-wasm/scripts/update-schema-wasm.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -euo pipefail + +## Dirs +prisma_schema_wasm_dir="./prisma-schema-wasm" +language_tools="../language-tools/" +language_tools_server="$language_tools/packages/language-server/" +language_tools_node="$language_tools_server/node_modules/@prisma/prisma-schema-wasm/" + +[ ! -d "$language_tools" ] && echo "language-tools was not found at the same level as engines" && exit 1 + +[ ! -d "$prisma_schema_wasm_dir" ] && echo "prisma_schema_wasm was not found in the current directory" && exit 1 + +## Script +printf '%s\n' "Starting build :: prisma-schema-wasm" +cargo build --release --target=wasm32-unknown-unknown --manifest-path=$prisma_schema_wasm_dir/Cargo.toml + +printf '%s\n' "Generating node module" +out=$prisma_schema_wasm_dir/nodejs $prisma_schema_wasm_dir/scripts/install.sh + +printf '%s\n' "Removing pre-existing wasm in language-tools" +rm -rf $language_tools_node/src/* + +printf '%s\n' "Moving generated prisma-schema-wasm :: engines -> language-tools" +cp $prisma_schema_wasm_dir/nodejs/src/prisma_schema_build{_bg.wasm,_bg.wasm.d.ts,.d.ts,.js} $language_tools_node/src diff --git a/prisma-fmt-wasm/src/lib.rs b/prisma-schema-wasm/src/lib.rs similarity index 100% rename from prisma-fmt-wasm/src/lib.rs rename to prisma-schema-wasm/src/lib.rs