Skip to content

Commit

Permalink
fix: embed package.json for sea (#126)
Browse files Browse the repository at this point in the history
* fix: embed package.json in sea build

* fix: specify text decoding
  • Loading branch information
bobbyg603 authored Jul 3, 2024
1 parent 55120be commit 34dcfc6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions bin/command-line-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OptionDefinition as ArgDefinition } from "command-line-args";
import { Section, OptionDefinition as UsageDefinition } from "command-line-usage";
import { existsSync, readFileSync } from "fs";
import { join } from "node:path";
import { getAsset, isSea } from "node:sea";

const packageVersion = getPackageVersion();

Expand Down Expand Up @@ -131,6 +132,10 @@ export const usageDefinitions: Array<Section> = [
];

function getPackageVersion(): string {
if (isSea()) {
return JSON.parse(`${getAsset('package.json', 'utf-8')}`).version;
}

const path = [
join(__dirname, 'package.json'),
join(__dirname, '../package.json'),
Expand Down
3 changes: 2 additions & 1 deletion sea-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"disableExperimentalSEAWarning": true,
"assets": {
"node-dump-syms.js": "dist/node-dump-syms.js",
"compression.js": "dist/compression.js"
"compression.js": "dist/compression.js",
"package.json": "package.json"
}
}
8 changes: 4 additions & 4 deletions src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { dumpSyms } from 'node-dump-syms';
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { mkdir, writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { getAsset, getAssetAsBlob, isSea } from 'node:sea';
import type { dumpSyms } from 'node-dump-syms';
import { createRequire } from "node:module";

const nativeModuleDir = join(tmpdir(), 'bugsplat');

export async function importNodeDumpSyms(): Promise<{
dumpSyms: typeof dumpSyms;
Expand All @@ -13,7 +15,6 @@ export async function importNodeDumpSyms(): Promise<{
return import('node-dump-syms');
}

const nativeModuleDir = join(tmpdir(), 'bugsplat');
if (!existsSync(nativeModuleDir)) {
await mkdir(nativeModuleDir, { recursive: true });
}
Expand All @@ -33,7 +34,6 @@ export function findCompressionWorkerPath(): string {
return join(__dirname, 'compression.js');
}

const nativeModuleDir = join(tmpdir(), 'bugsplat');
if (!existsSync(nativeModuleDir)) {
mkdirSync(nativeModuleDir, { recursive: true });
}
Expand Down

0 comments on commit 34dcfc6

Please sign in to comment.