diff --git a/justfile b/justfile index 223d408..824f5e7 100644 --- a/justfile +++ b/justfile @@ -3,38 +3,44 @@ ########################################################################### # just configuration ########################################################################### -set shell := ["bash", "-c"] -set dotenv-load := true + +set shell := ["bash", "-c"] +set dotenv-load := true + ########################################################################### # library configuration ########################################################################### -NPM_MODULE := `cat package.json | jq -r .name` -tsc := "./node_modules/typescript/bin/tsc" -vite := "NODE_OPTIONS='--max_old_space_size=16384' ./node_modules/vite/bin/vite.js" + +NPM_MODULE := `cat package.json | jq -r .name` +tsc := "./node_modules/typescript/bin/tsc" +vite := "NODE_OPTIONS='--max_old_space_size=16384' ./node_modules/vite/bin/vite.js" + # minimal formatting, bold is very useful -bold := '\033[1m' -normal := '\033[0m' -green := "\\e[32m" -yellow := "\\e[33m" -blue := "\\e[34m" -magenta := "\\e[35m" -grey := "\\e[90m" + +bold := '\033[1m' +normal := '\033[0m' +green := "\\e[32m" +yellow := "\\e[33m" +blue := "\\e[34m" +magenta := "\\e[35m" +grey := "\\e[90m" _help: @just --list --unsorted --list-heading $'Commands:\n' # Build the production npm distributions in dist/metaframe and dist/metapage build: _build + _build: _ensure_node_modules _build_npm _build_npm: #!/usr/bin/env bash set -euo pipefail - # Compiles the entire codebase to typescript files in ./dist. Packaged into the npm module '{{NPM_MODULE}}' + # Compiles the entire codebase to typescript files in ./dist. Packaged into the npm module '{{ NPM_MODULE }}' # How to test installation of the build? - {{tsc}} --noEmit + {{ tsc }} --noEmit echo "✅ typescript check" - {{vite}} build + {{ vite }} build echo "✅ vite build" # watch for file changes, then build ALL into ./dist @@ -42,33 +48,34 @@ watch: _ensure_node_modules #!/usr/bin/env bash set -euo pipefail echo "👀 watching and building into ./dist..." - {{tsc}} --noEmit + {{ tsc }} --noEmit echo "✅ typescript check" - {{vite}} --watch build + {{ vite }} --watch build @_tsc +args="": - {{tsc}} {{args}} + {{ tsc }} {{ args }} # Run tests -@test +args="": (_tsc "--build") - npx vitest {{args}} +test +args="": _ensure_node_modules (_tsc "--build") + npx vitest {{ args }} # Develop: # 1. just dev # 2. modify metapage/metaframe code # 3. refresh browser window + # recompile metapage/metaframe src on change, and open a browser at the test page for the local metapage test dev: _ensure_node_modules watch -# typescript check +# typescript check @check: (_tsc "--build") - echo -e "✅ {{green}}TypeScript{{normal}} check passed" + echo -e "✅ {{ green }}TypeScript{{ normal }} check passed" # npm link the package in dist for local development. In the other project: 'npm link @metapages/metapage' @link: if [ ! -d dist ]; then just build; fi cd dist && npm link - echo -e "👉 in the other project: npm link {{NPM_MODULE}}" + echo -e "👉 in the other project: npm link {{ NPM_MODULE }}" # unlink the package in dist from local development. You probably don't ever need to do this @unlink: @@ -76,7 +83,7 @@ dev: _ensure_node_modules watch # List all published versions @list: - npm view {{NPM_MODULE}} versions --json + npm view {{ NPM_MODULE }} versions --json # Bump version (patch|minor|major|), commit, tag, and push to trigger publish version bump="patch": @@ -88,7 +95,7 @@ version bump="patch": exit 1 fi # Bump version in package.json - npm version {{bump}} --no-git-tag-version + npm version {{ bump }} --no-git-tag-version VERSION=`cat package.json | jq -r '.version'` # Commit and tag git add package.json @@ -111,15 +118,18 @@ publish: _ensure_node_modules set -euo pipefail VERSION=`cat package.json | jq -r '.version'` # Check if the package exists, if not this is the first publish - if ! npm view {{NPM_MODULE}} version &> /dev/null; then - echo "📦 First time publishing {{NPM_MODULE}}" + if ! npm view {{ NPM_MODULE }} version &> /dev/null; then + echo "📦 First time publishing {{ NPM_MODULE }}" else - INDEX=`npm view {{NPM_MODULE}} versions --json | jq "index( \"$VERSION\" )"` + INDEX=`npm view {{ NPM_MODULE }} versions --json | jq "index( \"$VERSION\" )"` if [ "$INDEX" != "null" ]; then echo -e '🌳 Version exists, not publishing' exit 0 fi fi + echo "Running tests before publish..." + just test --run + echo "✅ Tests passed" just build rm -rf dist/test echo "PUBLISHING npm version $VERSION" @@ -130,11 +140,11 @@ publish: _ensure_node_modules # Unpublish version https://docs.npmjs.com/cli/v7/commands/npm-unpublish unpublish version: @echo "❗ If this fails: you cannot use .npmrc or NPM_TOKEN, you must 'npm login' 🤷‍♀️" - npm unpublish {{NPM_MODULE}}@{{version}} + npm unpublish {{ NPM_MODULE }}@{{ version }} # https://docs.npmjs.com/cli/v7/commands/npm-deprecate module_deprecate version +message: - npm deprecate {{NPM_MODULE}}@{{version}} "{{message}}" + npm deprecate {{ NPM_MODULE }}@{{ version }} "{{ message }}" # delete all generated assets/files clean: diff --git a/src/test/serialize.test.ts b/src/test/serialize.test.ts index ed60639..fe02a49 100644 --- a/src/test/serialize.test.ts +++ b/src/test/serialize.test.ts @@ -185,9 +185,9 @@ describe("Primary Serialize/Deserialize API", () => { // Large data should be uploaded (URL dataref) expect(typeof serialized.largeData).toBe("string"); - expect(serialized.largeData).toContain("text/x-uri"); + expect(serialized.largeData as unknown as string).toContain("text/x-uri"); // URL is encoded in the dataref - expect(decodeURIComponent(serialized.largeData)).toContain("https://storage.example.com"); + expect(decodeURIComponent(serialized.largeData as unknown as string)).toContain("https://storage.example.com"); // Small data should be inline expect(typeof serialized.smallData).toBe("string");