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:
- Engine repo: in your checkout of
nonelectric-engine. - Game repo: in the game that uses the engine.
- What a version contains
- 1. Pack a release
- 2. Try it locally
- 3. Install it reproducibly
- 4. Choose the dependency type
- 5. Upgrade a game
- What stays private and what doesn’t
- Optional: stop an accidental publish
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:
- It’s a snapshot. npm unpacks the archive into
node_modules/nonelectric-engine. It’s a copy, not a link back to the engine repo. If you change the engine’s source afterwards, the game doesn’t see it. To pick up the change, runnpm packagain in the engine repo andnpm installthe new archive again in the game. - It only works on this machine. npm records the dependency as a path relative to the game, such as
"file:../../engine-packs/nonelectric-engine-0.1.0.tgz". That path doesn’t exist on another machine or in CI. Use this for trying things out, and section 3 for anything you commit.
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.
- The archive is a copy of the engine’s code. It holds every file
npm pack --dry-runlists: the runtime insrc/, the sprite toolkit insprite/,README.mdandpackage.json. Anyone who can read a repository that contains the archive can unpack it and read that code. - Commit the archive to private game repositories only. In a public game repository, the archive would make the engine’s code public, even though the engine repository is still private. For a public game, keep the archive out of the public repository. The simplest way is to keep the game’s source in a private repository and publish only what players need.
- Distributing the sprite toolkit isn’t the same as shipping its PNGs. The PNGs are plain images. Putting them in a game, public or private, reveals the pictures and nothing of the toolkit’s code. A public project can ship approved PNGs while the recipes, the archive and the sprite check stay somewhere private. The sprite check needs the toolkit, so it runs where the archive is.
- The engine code that runs in the browser is visible to players. It doesn’t matter whether it’s bundled, minified or served as-is. Any player can open the browser’s developer tools and read the code the browser downloads. A private repository keeps the source private, not the code a game sends to its players. Never put secrets in game code.
- A dev dependency doesn’t reach the browser on its own. A bundler only includes modules the game imports, and the runtime (
nonelectric-engine) never importsnonelectric-engine/sprite. The Quiet Parlour has a test that enforces this for its own imports.
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.