Skip to content

Commit

Permalink
Revert "change artifact resolving (#40)"
Browse files Browse the repository at this point in the history
This reverts commit 03b64ff.
  • Loading branch information
kearfy committed Jul 4, 2024
1 parent 03b64ff commit aed87f8
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 327 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,3 @@ examples
.idea
lib/*
test.skv
artifacts
1 change: 1 addition & 0 deletions fix-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo -e "import { ConnectionOptions } from \"./lib-src/embedded.js\";\n$(cat index.d.ts)" > index.d.ts
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ConnectionOptions } from "./lib-src/embedded.js";
/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

export declare class SurrealdbNodeEngine {
execute(data: Uint8Array): Promise<Uint8Array>
Expand Down
78 changes: 42 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* tslint:disable */
/* eslint-disable */
/* prettier-ignore */

/* auto-generated by NAPI-RS */

const { existsSync, readFileSync } = require('fs')
const { join } = require('path')

Expand Down Expand Up @@ -26,10 +32,10 @@ switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, './artifacts/surrealdb.node.android-arm64.node'))
localFileExisted = existsSync(join(__dirname, 'surrealdb.node.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.android-arm64.node')
nativeBinding = require('./surrealdb.node.android-arm64.node')
} else {
nativeBinding = require('surrealdb.node-android-arm64')
}
Expand All @@ -38,10 +44,10 @@ switch (platform) {
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, './artifacts/surrealdb.node.android-arm-eabi.node'))
localFileExisted = existsSync(join(__dirname, 'surrealdb.node.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.android-arm-eabi.node')
nativeBinding = require('./surrealdb.node.android-arm-eabi.node')
} else {
nativeBinding = require('surrealdb.node-android-arm-eabi')
}
Expand All @@ -57,11 +63,11 @@ switch (platform) {
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.win32-x64-msvc.node')
join(__dirname, 'surrealdb.node.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.win32-x64-msvc.node')
nativeBinding = require('./surrealdb.node.win32-x64-msvc.node')
} else {
nativeBinding = require('surrealdb.node-win32-x64-msvc')
}
Expand All @@ -71,11 +77,11 @@ switch (platform) {
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.win32-ia32-msvc.node')
join(__dirname, 'surrealdb.node.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.win32-ia32-msvc.node')
nativeBinding = require('./surrealdb.node.win32-ia32-msvc.node')
} else {
nativeBinding = require('surrealdb.node-win32-ia32-msvc')
}
Expand All @@ -85,11 +91,11 @@ switch (platform) {
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.win32-arm64-msvc.node')
join(__dirname, 'surrealdb.node.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.win32-arm64-msvc.node')
nativeBinding = require('./surrealdb.node.win32-arm64-msvc.node')
} else {
nativeBinding = require('surrealdb.node-win32-arm64-msvc')
}
Expand All @@ -102,21 +108,21 @@ switch (platform) {
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, './artifacts/surrealdb.node.darwin-universal.node'))
localFileExisted = existsSync(join(__dirname, 'surrealdb.node.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.darwin-universal.node')
nativeBinding = require('./surrealdb.node.darwin-universal.node')
} else {
nativeBinding = require('surrealdb.node-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, './artifacts/surrealdb.node.darwin-x64.node'))
localFileExisted = existsSync(join(__dirname, 'surrealdb.node.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.darwin-x64.node')
nativeBinding = require('./surrealdb.node.darwin-x64.node')
} else {
nativeBinding = require('surrealdb.node-darwin-x64')
}
Expand All @@ -126,11 +132,11 @@ switch (platform) {
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.darwin-arm64.node')
join(__dirname, 'surrealdb.node.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.darwin-arm64.node')
nativeBinding = require('./surrealdb.node.darwin-arm64.node')
} else {
nativeBinding = require('surrealdb.node-darwin-arm64')
}
Expand All @@ -146,10 +152,10 @@ switch (platform) {
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, './artifacts/surrealdb.node.freebsd-x64.node'))
localFileExisted = existsSync(join(__dirname, 'surrealdb.node.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.freebsd-x64.node')
nativeBinding = require('./surrealdb.node.freebsd-x64.node')
} else {
nativeBinding = require('surrealdb.node-freebsd-x64')
}
Expand All @@ -162,11 +168,11 @@ switch (platform) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-x64-musl.node')
join(__dirname, 'surrealdb.node.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-x64-musl.node')
nativeBinding = require('./surrealdb.node.linux-x64-musl.node')
} else {
nativeBinding = require('surrealdb.node-linux-x64-musl')
}
Expand All @@ -175,11 +181,11 @@ switch (platform) {
}
} else {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-x64-gnu.node')
join(__dirname, 'surrealdb.node.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-x64-gnu.node')
nativeBinding = require('./surrealdb.node.linux-x64-gnu.node')
} else {
nativeBinding = require('surrealdb.node-linux-x64-gnu')
}
Expand All @@ -191,11 +197,11 @@ switch (platform) {
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-arm64-musl.node')
join(__dirname, 'surrealdb.node.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-arm64-musl.node')
nativeBinding = require('./surrealdb.node.linux-arm64-musl.node')
} else {
nativeBinding = require('surrealdb.node-linux-arm64-musl')
}
Expand All @@ -204,11 +210,11 @@ switch (platform) {
}
} else {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-arm64-gnu.node')
join(__dirname, 'surrealdb.node.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-arm64-gnu.node')
nativeBinding = require('./surrealdb.node.linux-arm64-gnu.node')
} else {
nativeBinding = require('surrealdb.node-linux-arm64-gnu')
}
Expand All @@ -220,11 +226,11 @@ switch (platform) {
case 'arm':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-arm-musleabihf.node')
join(__dirname, 'surrealdb.node.linux-arm-musleabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-arm-musleabihf.node')
nativeBinding = require('./surrealdb.node.linux-arm-musleabihf.node')
} else {
nativeBinding = require('surrealdb.node-linux-arm-musleabihf')
}
Expand All @@ -233,11 +239,11 @@ switch (platform) {
}
} else {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-arm-gnueabihf.node')
join(__dirname, 'surrealdb.node.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-arm-gnueabihf.node')
nativeBinding = require('./surrealdb.node.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('surrealdb.node-linux-arm-gnueabihf')
}
Expand All @@ -249,11 +255,11 @@ switch (platform) {
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-riscv64-musl.node')
join(__dirname, 'surrealdb.node.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-riscv64-musl.node')
nativeBinding = require('./surrealdb.node.linux-riscv64-musl.node')
} else {
nativeBinding = require('surrealdb.node-linux-riscv64-musl')
}
Expand All @@ -262,11 +268,11 @@ switch (platform) {
}
} else {
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-riscv64-gnu.node')
join(__dirname, 'surrealdb.node.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-riscv64-gnu.node')
nativeBinding = require('./surrealdb.node.linux-riscv64-gnu.node')
} else {
nativeBinding = require('surrealdb.node-linux-riscv64-gnu')
}
Expand All @@ -277,11 +283,11 @@ switch (platform) {
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, './artifacts/surrealdb.node.linux-s390x-gnu.node')
join(__dirname, 'surrealdb.node.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./artifacts/surrealdb.node.linux-s390x-gnu.node')
nativeBinding = require('./surrealdb.node.linux-s390x-gnu.node')
} else {
nativeBinding = require('surrealdb.node-linux-s390x-gnu')
}
Expand Down
55 changes: 55 additions & 0 deletions move_artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const fs = require('fs');
const path = require('path');

const sourceDir = './artifacts';
const npmDir = './npm';

const outDirs = fs.readdirSync(npmDir);

const binaries = collectNodeBinaries(sourceDir);
console.log(binaries)

binaries.forEach((file) => {
// console.log(file);
// const sourcePath = path.join(sourceDir, file);
console.log(`moving artifact: ${file}`);
const terms = file.split('.');
if (terms.pop() !== 'node') {
console.error(`non node file found: ${file}`);
return;
}
const platform = terms.pop()
if (!platform) {
console.error(`can't find platform for: ${file}`);
return;
}

if (!outDirs.includes(platform)) {
console.error(`invalid platform: ${platform} for file: ${file}`);
return;
}

const destPath = path.join(npmDir, platform, path.parse(file).base);

fs.copyFile(file, destPath, (copyErr) => {
if (copyErr) {
console.error(`Could not copy the file: ${copyErr}`);
return;
}

console.log(`Copied ${file} to ${destPath}`);
});
});

function collectNodeBinaries(root) {
const files = fs.readdirSync(root, { withFileTypes: true })
const nodeBinaries = files
.filter((file) => file.isFile() && file.name.endsWith('.node'))
.map((file) => path.join(root, file.name))

const dirs = files.filter((file) => file.isDirectory())
for (const dir of dirs) {
nodeBinaries.push(...(collectNodeBinaries(path.join(root, dir.name))))
}
return nodeBinaries
}
35 changes: 14 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@
"description": "Node.js driver for SurrealDB",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"build": "napi build --platform --release artifacts",
"build:debug": "napi build --platform && bash ./fix-deps.sh && tsc",
"prepublishOnly": "napi prepublish -t npm",
"test": "pnpm tsx test.ts",
"universal": "napi universal",
"version": "napi version",
"ts-compile": "pnpm tsc --version && pnpm tsc"
},
"files": [
"lib",
"index.d.ts",
"index.js",
"npm",
"surrealdb.node.*.node"
],
"napi": {
"name": "surrealdb.node",
"triples": {
Expand All @@ -54,10 +38,8 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@napi-rs/cli": "^2.18.4",
"ava": "^5.1.1",
"tsx": "^4.16.2",
"typescript": "^5.5.3"
"@napi-rs/cli": "^2.18.3",
"ava": "^5.1.1"
},
"dependencies": {
"surrealdb.js": "^1.0.0-beta.12"
Expand All @@ -70,5 +52,16 @@
},
"engines": {
"node": ">= 10"
}
},
"scripts": {
"artifacts": "node move_artifacts.js",
"build": "napi build --platform --release \"$@\" && bash ./fix-deps.sh",
"build:debug": "napi build --platform && bash ./fix-deps.sh && tsc",
"prepublishOnly": "napi prepublish -t npm",
"test": "pnpx tsx test.ts",
"universal": "napi universal",
"version": "napi version",
"ts-compile": "pnpx tsc --version && pnpx tsc"
},
"files": ["lib", "index.d.ts", "index.js", "npm", "surrealdb.node.*.node"]
}
Loading

0 comments on commit aed87f8

Please sign in to comment.