Skip to content

Commit c51a1fe

Browse files
authored
fix: remove padding for nintendo guids (#173)
* fix: remove padding for nintendo guids * fix: sea module parsing warning for worker
1 parent da3dd1c commit c51a1fe

File tree

9 files changed

+16
-25
lines changed

9 files changed

+16
-25
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
"build": "npm run build:esm && npm run build:cjs",
4545
"build:esm": "tsc -p tsconfig.esm.json && npm run copy:compression:esm",
4646
"build:cjs": "tsc -p tsconfig.cjs.json && npm run copy:compression:cjs",
47-
"copy:compression:esm": "copyfiles -u 1 src/compression.js src/compression.mjs dist/esm/",
48-
"copy:compression:cjs": "copyfiles -u 1 src/compression.js dist/cjs/",
47+
"copy:compression:esm": "copyfiles -u 1 src/compression.cjs src/compression.mjs dist/esm/",
48+
"copy:compression:cjs": "copyfiles -u 1 src/compression.cjs dist/cjs/",
4949
"prerelease": "npm run build",
5050
"release": "npm publish --access public",
5151
"bundle": "esbuild ./dist/esm/bin/index.js --bundle --platform=node --target=node18 --format=cjs --outfile=./dist/cjs/index.js --external:node-dump-syms",
52-
"bpkg:compression": "npx bpkg ./src/compression.js ./dist/cjs/compression.js",
52+
"bpkg:compression": "npx bpkg ./src/compression.cjs ./dist/cjs/compression.cjs",
5353
"bpkg:node-dump-syms": "npx bpkg ./node_modules/node-dump-syms ./dist/cjs/node-dump-syms.js",
5454
"prebuild:sea": "npm run clean",
5555
"prestart:sea": "npm run build:sea && npm run sea:macos",

sea-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"disableExperimentalSEAWarning": true,
55
"assets": {
66
"node-dump-syms.js": "dist/cjs/node-dump-syms.js",
7-
"compression.js": "dist/cjs/compression.js",
7+
"compression.cjs": "dist/cjs/compression.cjs",
88
"package.json": "package.json"
99
}
1010
}
File renamed without changes.

src/compression.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// ESM wrapper for compression.js (CommonJS)
1+
// ESM wrapper for compression.cjs (CommonJS)
22
// This allows the package to be imported as ESM while keeping the worker as CommonJS for SEA compatibility
33

44
import { createRequire } from 'node:module';
55
const require = createRequire(import.meta.url);
66

77
// Export the CommonJS module through the ESM wrapper
8-
export default require('./compression.js');
8+
export default require('./compression.cjs');

src/elf.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ElfFile } from '@bugsplat/elfy';
2-
import { extname } from 'node:path';
32

43
export async function tryGetElfUUID(path: string) {
54
let success: boolean, section: Buffer | undefined;
@@ -8,26 +7,18 @@ export async function tryGetElfUUID(path: string) {
87
({ success, section } = await elfFile.tryReadSection('.note.gnu.build-id'));
98

109
if (success) {
11-
return getUUID(section!, path, 16);
10+
return getUUID(section!, 16);
1211
}
1312

1413
({ success, section } = await elfFile.tryReadSection('.sce_special'));
1514

1615
if (success) {
17-
return getUUID(section!, path);
16+
return getUUID(section!);
1817
}
1918

2019
return '';
2120
}
2221

23-
function getUUID(section: Buffer, path: string, offset = 0) {
24-
let uuid = section.subarray(offset, offset + 20).toString('hex');
25-
26-
// Nintendo GUIDs seem to be 32 or 40 hex chars 0 padded to 64 hex chars
27-
// Until we know more, pad it ourselves with this hacky workaround
28-
if (extname(path)?.toLowerCase() === '.nss') {
29-
uuid = uuid.padEnd(64, '0');
30-
}
31-
32-
return uuid;
22+
function getUUID(section: Buffer, offset = 0) {
23+
return section.subarray(offset, offset + 20).toString('hex');
3324
}

src/preload.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function findCompressionWorkerPath(): string {
4040
if (!isSea()) {
4141
// @ts-ignore - Check if we're in an ESM environment
4242
const isESM = typeof import.meta?.url === 'string';
43-
const workerFile = isESM ? 'compression.mjs' : 'compression.js';
43+
const workerFile = isESM ? 'compression.mjs' : 'compression.cjs';
4444
return join(__dirname, workerFile);
4545
}
4646

@@ -49,8 +49,8 @@ export function findCompressionWorkerPath(): string {
4949
mkdirSync(nativeModuleDir, { recursive: true });
5050
}
5151

52-
const nativeModuleStream = getAsset('compression.js');
53-
const targetPath = join(nativeModuleDir, 'compression.js');
52+
const nativeModuleStream = getAsset('compression.cjs');
53+
const targetPath = join(nativeModuleDir, 'compression.cjs');
5454
writeFileSync(targetPath, Buffer.from((nativeModuleStream)));
5555

5656
return targetPath;

tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"forceConsistentCasingInFileNames": true,
1616
"allowJs": true
1717
},
18-
"files": ["./index.ts", "./bin/index.ts", "src/compression.js", "src/compression.mjs", "src/compat.ts"]
18+
"files": ["./index.ts", "./bin/index.ts", "src/compression.cjs", "src/compression.mjs", "src/compat.ts"]
1919
}

tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"isolatedModules": true,
2020
"verbatimModuleSyntax": false
2121
},
22-
"files": ["./index.ts", "./bin/index.ts", "src/compression.js", "src/compression.mjs", "src/compat.ts"]
22+
"files": ["./index.ts", "./bin/index.ts", "src/compression.cjs", "src/compression.mjs", "src/compat.ts"]
2323
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
"isolatedModules": true,
1919
"verbatimModuleSyntax": false
2020
},
21-
"files": ["./index.ts", "./bin/index.ts", "src/compression.js", "src/compression.mjs", "src/compat.ts"]
21+
"files": ["./index.ts", "./bin/index.ts", "src/compression.cjs", "src/compression.mjs", "src/compat.ts"]
2222
}

0 commit comments

Comments
 (0)