Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
70 lines (62 loc) · 1.47 KB
/
Copy pathbuild.js
File metadata and controls
70 lines (62 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
const nativeNodePlugin = {
name: "native-node",
setup(build) {
build.onResolve({ filter: /\.node$/ }, (args) => {
const name = path.basename(args.path);
return { path: "../" + name, external: true };
});
build.onResolve({ filter: /^@opendal\/lib-/ }, (args) => {
return { path: args.path, external: true };
});
},
};
const platforms = [
"darwin-arm64",
"darwin-x64",
"linux-arm64-gnu",
"linux-x64-gnu",
"win32-x64-msvc",
];
function copyNativeFiles(outdir) {
fs.mkdirSync(outdir, { recursive: true });
for (const platform of platforms) {
const pkgDir = path.join(
__dirname,
"node_modules",
"@opendal",
`lib-${platform}`
);
if (!fs.existsSync(pkgDir)) continue;
for (const file of fs.readdirSync(pkgDir)) {
if (file.endsWith(".node")) {
fs.copyFileSync(path.join(pkgDir, file), path.join(outdir, file));
}
}
}
}
async function build() {
const common = {
bundle: true,
platform: "node",
target: "node24",
plugins: [nativeNodePlugin],
};
await esbuild.build({
...common,
entryPoints: ["src/restore.ts"],
outfile: "dist/restore/index.js",
});
await esbuild.build({
...common,
entryPoints: ["src/save.ts"],
outfile: "dist/save/index.js",
});
copyNativeFiles("dist");
}
build().catch((e) => {
console.error(e);
process.exit(1);
});