← @electriceeli

Installing the engine in a game

nonelectric-engine is a private engine for my own games. The repository stays private, and the package is never published to npm or any other registry.

A version travels to a game as one file, a .tgz archive made by npm pack. The game installs that file, commits it, and from then on installs it again from its own repository. This guide is the whole workflow, from packing a release to upgrading a game.

Every command block says where it runs:

How a packed release reaches a game

What a version contains

These values come from the engine’s package.json:

Field Value
Package name nonelectric-engine
Current version 0.1.0, so the archive is nonelectric-engine-0.1.0.tgz
Files packed src/ and sprite/, plus package.json and README.md, which npm always includes
Command nonelectric-sprites, which runs sprite/cli.js

What you can import:

Import What it is Runs in
nonelectric-engine the runtime: dialogue, stage, clock, save browser
nonelectric-engine/sprite sprite drawing, recipes and checks browser and Node
nonelectric-engine/sprite/browser sprite preview helpers browser
nonelectric-engine/sprite/node PNG encode and decode Node

The docs, the example games and the tests aren’t in the archive.

1. Pack a release

Engine repo. First run the checks, which are the unit tests plus the sprite check:

npm test

Then look at exactly what will go into the archive, without making it:

npm pack --dry-run

At 0.1.0 that lists 17 files: README.md, package.json, nine in sprite/ and six in src/. It ends with:

npm notice filename: nonelectric-engine-0.1.0.tgz
npm notice total files: 17

If a file you didn’t expect is listed, stop and fix the files field in package.json before packing.

Then make the archive. Plain npm pack writes it into the engine repo’s own folder. To keep archives out of the engine repo, send them to a folder of their own:

mkdir -p ~/engine-packs
npm pack --pack-destination ~/engine-packs

This prints nonelectric-engine-0.1.0.tgz. The rest of this guide assumes the archive is in ~/engine-packs.

2. Try it locally

Game repo. For a quick try, install straight from the archive where it sits:

npm install ~/engine-packs/nonelectric-engine-0.1.0.tgz

The game can now import the engine by name, for example import { createDialogue } from "nonelectric-engine".

Two things to know:

3. Install it reproducibly

For a private game repository, keep the archive inside the game, so every checkout has it.

Game repo:

mkdir -p vendor
cp ~/engine-packs/nonelectric-engine-0.1.0.tgz vendor/
npm install ./vendor/nonelectric-engine-0.1.0.tgz
git add vendor/nonelectric-engine-0.1.0.tgz package.json package-lock.json
git commit -m "Install nonelectric-engine 0.1.0"

node_modules/ stays out of git, as usual.

npm records the archive by its path inside the game, and pins its exact contents with a checksum (integrity). In package.json:

"dependencies": {
  "nonelectric-engine": "file:vendor/nonelectric-engine-0.1.0.tgz"
}

In package-lock.json:

"node_modules/nonelectric-engine": {
  "version": "0.1.0",
  "resolved": "file:vendor/nonelectric-engine-0.1.0.tgz",
  "integrity": "sha512-…",

Any fresh checkout of the game, including CI:

npm ci

npm ci installs exactly what the lockfile says, from the committed vendor/ archive. It doesn’t need the engine repo, access to GitHub, an npm account or a publishing token. With no other dependencies, even npm ci --offline works. If the archive in vendor/ is changed by even one byte, npm ci stops with EINTEGRITY instead of installing something different.

4. Choose the dependency type

A game that runs the engine

A game whose code imports the runtime needs a normal dependency. It’s what the command in section 3 makes.

Game repo:

npm install ./vendor/nonelectric-engine-0.1.0.tgz
import { createDialogue } from "nonelectric-engine";

const talk = createDialogue({ start: "hi", nodes: { hi: { text: "Who goes there?", choices: [{ label: "A friend.", to: "in" }] }, in: { text: "Come in." } } });
console.log(talk.view(talk.choose(talk.begin(), 0)).text); // Come in.

A game with a normal dependency can also run the sprite command. A single install covers both.

A project that only makes art

A project that only uses the sprite tools to make or check PNGs, and never ships engine code, needs a dev dependency.

Game repo:

npm install --save-dev ./vendor/nonelectric-engine-0.1.0.tgz

This records "devDependencies": { "nonelectric-engine": "file:vendor/nonelectric-engine-0.1.0.tgz" }. The lockfile entry is marked "dev": true.

A recipe imports the toolkit by name:

// art/drawer.js
import { canvas, rect, resolve, offPalette } from "nonelectric-engine/sprite";

The command comes from the installed archive:

npx nonelectric-sprites art/drawer.js --approve --seed 1
npx nonelectric-sprites art/drawer.js

The second command checks the PNGs, and prints art/drawer.js: 3 approved files match (seed 1).

To run the check in your test command, add a script. Inside an npm script the command needs no npx:

npm pkg set scripts.sprites="nonelectric-sprites art/drawer.js"
npm run sprites

The full art/drawer.js and everything the toolkit does are in the sprite toolkit guide.

5. Upgrade a game

Each version has its own archive name, such as nonelectric-engine-0.1.1.tgz. Each game’s lockfile then names the exact archive, and its checksum, that it installed.

Engine repo. Bump the version, check, and pack:

npm version patch        # 0.1.0 → 0.1.1: commits the change and tags it v0.1.1
npm test
npm pack --dry-run
npm pack --pack-destination ~/engine-packs

npm version needs a clean working tree, and records the release as a commit plus a v0.1.1 tag. Use minor instead of patch for new features, and major for changes that break games.

Game repo. Install the new archive, check the game, and remove the old archive:

cp ~/engine-packs/nonelectric-engine-0.1.1.tgz vendor/
npm install ./vendor/nonelectric-engine-0.1.1.tgz
npm test                                  # and play the game
git grep -n "nonelectric-engine-0.1.0"    # prints nothing once nothing uses the old archive
git rm vendor/nonelectric-engine-0.1.0.tgz
git add vendor/nonelectric-engine-0.1.1.tgz package.json package-lock.json
git commit -m "Upgrade nonelectric-engine to 0.1.1"

Use npm install --save-dev … instead if the project uses the engine as a dev dependency. Check the game the way it’s normally checked: its tests, a build, and a play-through of anything the upgrade touched.

npm install repoints package.json and package-lock.json at the new archive. That’s why git grep finds no mention of the old one, and why it’s safe to delete. Afterwards, npm ci on a fresh checkout installs 0.1.1.

What stays private and what doesn’t

The engine repository stays private. But copies of the engine end up in other places, and each copy is only as private as the place it’s in.

Optional: stop an accidental publish

The engine’s package.json doesn’t set "private": true. Adding it is an optional safeguard against publishing by accident. It’s a one-line change to package.json, kept out of this documentation change:

"private": true,

npm pack works the same with it set. I checked this: packing at 0.1.1 with "private": true still made the archive with all 17 files.

According to npm’s documentation, a real npm publish refuses a package marked private. I didn’t test that here, because testing it means attempting a real publish. Also, npm publish --dry-run (npm 10.9.9) doesn’t apply the private check and reports success, so a dry run can’t confirm the safeguard.