Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ jobs:
- name: Build npm artifact
run: npm run build:npm

# Publication check: the archive must contain every export, bin, and
# template. Source tests validate the checkout; this validates the
# release artifact.
- name: Verify npm archive contents
run: deno task verify:npm-archive

# Extract version once from deno.json; reused across all publish steps (DRY).
- name: Extract version from deno.json
id: extract_version
Expand All @@ -41,23 +47,13 @@ jobs:
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

# Rewrite package.json version + exports for npm publish.
# In the repo, exports point to .ts source (for local dev/tests). Here we switch to dist/.
# In the repo, exports point to .ts source (for local dev/tests). The shared
# transform in scripts/npm-manifest.ts switches them to dist/. The package
# contract test applies the same transform, so a shipped-manifest
# regression fails the gate rather than the release.
# This runs AFTER npm install + build so the lockfile matches during install.
- name: Sync version and exports from deno.json → package.json
run: |
deno eval --node-modules-dir=none "
import pkg from './package.json' with {type:'json'};
import cfg from './deno.json' with {type:'json'};
pkg.version = cfg.version;
pkg.exports = {
'.': { import: './dist/mod.js', types: './dist/mod.d.ts' },
'./react': { import: './dist/react/hooks.js', types: './dist/react/hooks.d.ts' },
'./server': { import: './dist/server.js', types: './dist/server.d.ts' },
'./server/build': { import: './dist/server-build.js', types: './dist/server-build.d.ts' },
'./link': { import: './dist/cli/link.js', types: './dist/cli/link.d.ts' },
};
await Deno.writeTextFile('./package.json', JSON.stringify(pkg, null, 2) + '\n');
"
run: deno run -A scripts/npm-manifest.ts

- name: Publish to JSR
run: |
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ jobs:
CI: true
FC_SEED: 42

package-validation:
name: Package Archive
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.3.3 # floor: native explicit resource management (V8); see denoland/deno#29282

# Validates the JSR upload set and publish-time specifier rewriting
# without publishing. The compile E2E links local source, so it cannot
# cover this package-boundary contract.
- name: Validate JSR package
run: deno publish --dry-run

docs-build:
name: Docs Build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,6 +93,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.3.3 # floor: native explicit resource management (V8); see denoland/deno#29282

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -84,9 +106,46 @@ jobs:
- name: Install npm dependencies
run: npm install

- name: Type check npm surface
run: npm run check:npm-types

- name: Build npm package
run: npm run build:npm

# Archive membership is checked on every push, not only at tag time.
# Same verifier as publish, so a staging regression fails the PR.
- name: Verify npm archive contents
run: deno task verify:npm-archive

build-contract:
name: Build Contract
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.3.3 # floor: native explicit resource management (V8); see denoland/deno#29282

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24.x'

- name: Install npm dependencies
run: npm install

# Builds the current checkout. The suite loads dist in place and must not
# install the package or resolve it from a registry. `prefer-offline`
# keeps the registry traffic down without failing on a dependency that
# the cache does not hold yet.
- name: Package contract
run: deno task test:package
env:
GOATDB_TEST_PACKAGE: '1'
npm_config_prefer_offline: 'true'

test-browser:
name: Browser Tests
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ docs/api.json
# npm build artifacts
dist/

# npm entrypoint guard test temp dirs
.npm-entrypoints-*

# Benchmark JSON output (generated by deno task bench:json)
benchmarks/results/

Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

### Fixed

- `goatdb init` now scaffolds `.gitignore` and `.npmrc` again when run from the
published npm package. `npm pack` drops dotfile sources, so the templates use
plain names (`gitignore`, `npmrc`) that `init` maps back to their dotted
targets.
- `goatdb init` now exits non-zero when dependency installation fails, reporting
the command, its exit code and its output. Previously a failed `npm install`
only warned, so a broken scaffold looked successful.
- `deno compile` output names now include `.exe` for Windows targets, so
`compile()` returns and logs the path that the compiler actually writes.
- A `Date` inside a `map` field now uses the tagged
`{ "__t": "D", "__v": <epoch-seconds> }` wire form, the same as every other
position. It was copied raw before, so it round-tripped as an ISO string while
Expand Down Expand Up @@ -77,6 +86,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and do not start loading. A fresh unobserved query reports `loading === false`
and, when `queryInactivityTimeoutMs` is set, is eligible for auto-close. A
closed query is replaced by calling `db.query()` again.
- `compile()` now resolves to the path of the compiled executable
(`Promise<string>`). Callers that ignore the value need no change.

### Changed

- `goatdb init` on Deno now requests `react`, `react-dom`, `yargs` and
`@types/react` as `^` ranges and installs all dependencies in one `deno add`
call, bounded by a 180s timeout. Exact pins let a transitive peer resolve a
newer `react` than `react-dom`, which crashes at runtime with "Incompatible
React versions".

## [0.6.1] - 2026-09-01

Expand Down
8 changes: 7 additions & 1 deletion base/development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isWindows } from './os.ts';
type Stringable = { toString(): string };

// Cache Node.js child_process module (loaded lazily)
let childProcessModule: any = undefined;
let childProcessModule: typeof import('node:child_process') | undefined;

export async function copyToClipboard(value: string): Promise<boolean> {
if (!isDeno()) return false;
Expand Down Expand Up @@ -51,6 +51,8 @@ export interface CliOptions {
cwd?: string;
/** Timeout in milliseconds. Process is killed if it exceeds this. */
timeout?: number;
/** Environment variables to add or override for the command. */
env?: Record<string, string>;
}

function isCliOptions(arg: unknown): arg is CliOptions {
Expand Down Expand Up @@ -100,6 +102,7 @@ export async function cli(
stdout: 'piped',
stderr: 'piped',
cwd: options.cwd,
env: options.env && { ...Deno.env.toObject(), ...options.env },
signal: ac?.signal,
});
try {
Expand Down Expand Up @@ -129,6 +132,9 @@ export async function cli(
const onWindows = isWindows();
const spawnOptions: Record<string, unknown> = {};
if (options.cwd) spawnOptions.cwd = options.cwd;
if (options.env) {
spawnOptions.env = { ...globalThis.process.env, ...options.env };
}
// On Windows, .cmd batch scripts (npm.cmd, deno.cmd) can't be found by
// name without shell: true. Only safe because all cli() call sites pass
// hardcoded commands — never user-supplied input.
Expand Down
2 changes: 1 addition & 1 deletion base/file-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function createQueuedWatcher(
}

function createChokidarWatcher(
chokidar: typeof import('chokidar'),
chokidar: { watch: typeof import('chokidar').watch },
dir: string,
): FileWatcher {
const underlying = chokidar.watch(dir, {
Expand Down
25 changes: 21 additions & 4 deletions cli/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ export type CompileOptions =
* - Node.js: Uses Single Executable Application (SEA) process
*
* @param options Configuration options for the compilation process
* @returns A Promise that resolves when compilation is complete
* @returns A Promise that resolves to the path of the compiled executable
* @group Compilation
*
* @example
* ```typescript
* await compile({
* const binaryPath = await compile({
* serverEntry: "./server/main.ts",
* outputName: "my-app",
* os: "linux",
Expand All @@ -164,7 +164,7 @@ export type CompileOptions =
* });
* ```
*/
export async function compile(options: CompileOptions): Promise<void> {
export async function compile(options: CompileOptions): Promise<string> {
if (!options.buildDir) {
throw new Error('buildDir is required for compilation');
}
Expand All @@ -180,6 +180,7 @@ export async function compile(options: CompileOptions): Promise<void> {
if (options.signing) {
await signExecutable(outputFile, options.signing);
}
return outputFile;
}

/**
Expand Down Expand Up @@ -270,7 +271,7 @@ async function compileDeno(options: CompileOptions): Promise<string> {
const buildInfoJsonPath = path.join(buildDir, 'buildInfo.json');
const outputFile = path.join(
buildDir,
`${options.outputName || 'app'}-${targetOsArch}`,
denoExecutableName(options.outputName || 'app', targetOsArch),
);
let success = false;
try {
Expand Down Expand Up @@ -785,6 +786,22 @@ export function targetFromOSArch(os?: TargetOS, arch?: CPUArch): OSArchTarget {
return `${os}-${arch}`;
}

/**
* Returns the executable file name that `deno compile` produces for a target.
*
* Deno appends `.exe` when the *target* OS is Windows, regardless of the host
* OS (see deno's `get_os_specific_filepath`). The suffix therefore applies to
* cross-compiled Windows binaries too; without it the returned/logged path and
* the failure cleanup point at a file the compiler never creates.
*/
export function denoExecutableName(
outputName: string,
target: OSArchTarget,
): string {
const ext = target.startsWith('windows-') ? '.exe' : '';
return `${outputName}-${target}${ext}`;
}

/**
* Converts GoatDB OS and architecture parameters to Deno's target format.
*
Expand Down
76 changes: 61 additions & 15 deletions cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '../base/json-log/file-impl.ts';
import { cli } from '../base/development.ts';
import { kMinNodeMajor } from './compile.ts';
import { templateTargetPath } from './template-manifest.ts';

/**
* Returns the path to the templates directory.
Expand Down Expand Up @@ -61,13 +62,48 @@ async function copyTemplateFile(
await copyFile(srcPath, fullDestPath);
}

async function installDenoDependency(
spec: string,
/**
* Upper bound for dependency installation. A stalled registry must fail with a
* diagnosable error instead of hanging `init` or the worker that invoked it.
*/
const kDependencyInstallTimeoutMs = 180_000;

function installFailure(
command: string,
result: { result: string; exitCode: number },
): Error {
// Include the captured output: the child's stderr is the only evidence of
// why the registry or package manager refused the install.
return new Error(
`${command} failed with exit code ${result.exitCode}:\n${result.result}`,
);
}

/**
* npm dependencies the Deno scaffold installs, keyed by the import specifier
* `deno add` generates. Ranges keep react and react-dom on the same resolved
* version; exact pins let a transitive peer pull a newer react than react-dom,
* which crashes at runtime with "Incompatible React versions". Exported so the
* compile E2E resolves the same specs the scaffold installs.
*/
export const kDenoTemplateNpmDependencies = {
'react': 'npm:react@^19.0.0',
'react-dom/client': 'npm:react-dom@^19.0.0/client',
'yargs': 'npm:yargs@^17.7.2',
'@types/react': 'npm:@types/react@^19.0.8',
} as const;

async function installDenoDependencies(
specs: readonly string[],
targetDir: string,
): Promise<void> {
const result = await cli('deno', 'add', spec, { cwd: targetDir });
const command = `deno add ${specs.join(' ')}`;
const result = await cli('deno', 'add', ...specs, {
cwd: targetDir,
timeout: kDependencyInstallTimeoutMs,
});
if (result.exitCode !== 0) {
throw new Error(`Failed to install dependency ${spec}`);
throw installFailure(command, result);
}
}

Expand Down Expand Up @@ -132,10 +168,12 @@ export async function bootstrapProject(
'client/index.css',
projectDir,
);
// Dotfiles are excluded by npm pack, so templates use plain names and the
// scaffold restores the leading dot.
await copyTemplateFile(
templateDir,
'shared/.gitignore',
'.gitignore',
'shared/gitignore',
templateTargetPath('shared/gitignore', runtime),
projectDir,
);

Expand Down Expand Up @@ -196,12 +234,12 @@ export async function bootstrapProject(
projectDir,
);
if (!opts.skipDependencies) {
await installDenoDependency('jsr:@goatdb/goatdb', projectDir);
await installDenoDependency('jsr:@std/path', projectDir);
await installDenoDependency('npm:react@19.0.0', projectDir);
await installDenoDependency('npm:react-dom@19.0.0/client', projectDir);
await installDenoDependency('npm:yargs@17.7.2', projectDir);
await installDenoDependency('npm:@types/react@19.0.8', projectDir);
// One command: fewer registry round-trips and one bounded wait.
await installDenoDependencies([
'jsr:@goatdb/goatdb',
'jsr:@std/path',
...Object.values(kDenoTemplateNpmDependencies),
], projectDir);
}
} else if (isNode()) {
await copyNodePackageJson(templateDir, projectDir);
Expand All @@ -211,12 +249,20 @@ export async function bootstrapProject(
'tsconfig.json',
projectDir,
);
await copyTemplateFile(templateDir, 'node/.npmrc', '.npmrc', projectDir);
await copyTemplateFile(
templateDir,
'node/npmrc',
templateTargetPath('node/npmrc', runtime),
projectDir,
);

if (!opts.skipDependencies) {
const result = await cli('npm', 'install', { cwd: projectDir });
const result = await cli('npm', 'install', {
cwd: projectDir,
timeout: kDependencyInstallTimeoutMs,
});
if (result.exitCode !== 0) {
console.warn('npm install failed:', result.result);
throw installFailure('npm install', result);
}
}
}
Expand Down
Loading
Loading