Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ jobs:
- name: Install dependencies (skip build — we have prebuilts)
run: npm install --ignore-scripts

- name: Restore bundled CLI permissions
run: chmod 755 prebuilds/linux-x64/doltlite prebuilds/darwin-arm64/doltlite

- name: Smoke test npm archive
run: node scripts/test-package.js

- name: Verify npm publish identity
run: |
npm config get registry
Expand Down
16 changes: 16 additions & 0 deletions scripts/build-amalgamation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ console.log("Preparing released doltlite amalgamation...")
fs.mkdirSync(outDir, { recursive: true })
let amalgamation = fs.readFileSync(inC, "utf8")

const lockPathVla = ' char zLock[nDir + (nPath - nDir) + sizeof(".-lock") + 1];'
if (amalgamation.includes(lockPathVla)) {
amalgamation = `/* DOLTLITE_NODE_MSVC_LOCK_PATH_FALLBACK */
#ifdef _MSC_VER
# include <malloc.h>
#endif

${amalgamation.replace(lockPathVla, [
"#ifdef _MSC_VER",
' char *zLock = (char*)_alloca(nPath + sizeof(".-lock"));',
"#else",
lockPathVla,
"#endif",
].join("\n"))}`
}

// DoltLite releases before v0.11.37 emitted the Winsock 2 headers after
// SQLite's Windows VFS had already included windows.h. Keep those releases
// buildable while newer release amalgamations carry the ordering fix directly.
Expand Down
37 changes: 37 additions & 0 deletions scripts/test-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict"

const assert = require("node:assert/strict")
const fs = require("node:fs")
const os = require("node:os")
const path = require("node:path")
const { execFileSync } = require("node:child_process")

const root = path.resolve(__dirname, "..")
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "doltlite-package-"))

try {
const packed = JSON.parse(execFileSync("npm", [
"pack", "--ignore-scripts", "--json", "--pack-destination", tmp,
], { cwd: root, encoding: "utf8" }))
execFileSync("tar", ["xzf", path.join(tmp, packed[0].filename), "-C", tmp])
const packageRoot = path.join(tmp, "package")
for (const platform of ["linux-x64", "darwin-arm64"]) {
const cli = path.join(packageRoot, "prebuilds", platform, "doltlite")
assert.notEqual(fs.statSync(cli).mode & 0o111, 0, `${platform} CLI is not executable`)
}
const { DatabaseSync, binPath } = require(packageRoot)
const db = new DatabaseSync(":memory:")
try {
assert.equal(db.prepare("SELECT doltlite_engine() AS engine").get().engine, "prolly")
db.exec("CREATE TABLE t(id INTEGER PRIMARY KEY); INSERT INTO t VALUES(1)")
assert.equal(db.prepare("SELECT count(*) AS n FROM t").get().n, 1)
} finally {
db.close()
}
assert.equal(execFileSync(binPath(), [":memory:", "SELECT doltlite_engine();"], {
encoding: "utf8",
}).trim(), "prolly")
console.log("npm archive: native addon and executable bundled CLIs PASS")
} finally {
fs.rmSync(tmp, { recursive: true, force: true })
}
13 changes: 7 additions & 6 deletions test/amalgamation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ describe("released amalgamation preparation", () => {
expect(winsock).toBeLessThan(windows)
})

test("uses an unmodified fixed release amalgamation", () => {
test("preserves release source outside compiler compatibility fixes", () => {
const source = readFileSync(sourcePath, "utf8")
const output = readFileSync(outputPath, "utf8")
const vla = ' char zLock[nDir + (nPath - nDir) + sizeof(".-lock") + 1];'
const restored = output
.replace(/^\/\* DOLTLITE_NODE_WINSOCK2_EARLY_FALLBACK \*\/\n#ifdef _WIN32\n# include <winsock2.h>\n# include <ws2tcpip.h>\n#endif\n\n/, "")
.replace(/^\/\* DOLTLITE_NODE_MSVC_LOCK_PATH_FALLBACK \*\/\n#ifdef _MSC_VER\n# include <malloc.h>\n#endif\n\n/, "")
.replace(`#ifdef _MSC_VER\n char *zLock = (char*)_alloca(nPath + sizeof(".-lock"));\n#else\n${vla}\n#endif`, vla)

if (source.includes("DOLTLITE_AMALGAMATION_WINSOCK2_EARLY")) {
expect(output).toBe(source)
} else {
expect(output).toContain("DOLTLITE_NODE_WINSOCK2_EARLY_FALLBACK")
}
expect(restored).toBe(source)
})
})
Loading