Skip to content

Commit 53b3bd3

Browse files
authored
build: TS6 + oxc.rs (#437)
1 parent f7e06b4 commit 53b3bd3

19 files changed

Lines changed: 1238 additions & 218 deletions

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Install dependencies
4040
run: yarn install --immutable
4141
- name: Lint
42-
run: yarn prettier:check
42+
run: yarn lint
4343
- name: Build
4444
run: yarn build
4545
- name: Test

.oxfmtrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"trailingComma": "all",
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"printWidth": 100,
7+
"sortPackageJson": false,
8+
"ignorePatterns": ["*.md", "*.yml", "*.yaml"]
9+
}

.oxlintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"plugins": ["eslint", "typescript", "unicorn", "oxc", "import"],
4+
"categories": {
5+
"correctness": "warn"
6+
},
7+
"options": {
8+
"typeAware": true
9+
}
10+
}

.prettierrc.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

benchmark/profile-extract.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import os from 'node:os';
44
import { generateFixture, FIXTURES } from './generate-fixtures.js';
5-
import { createPackage, extractAll, listPackage, getRawHeader, uncache } from '../lib/asar.js';
5+
import { createPackage, extractAll, uncache } from '../lib/asar.js';
66
import { readArchiveHeaderSync, readFilesystemSync } from '../lib/disk.js';
77

88
const config = FIXTURES.find((f) => f.name === 'many-small-files')!;
@@ -12,7 +12,9 @@ const archiveFile = path.join(tmpDir, 'test.asar');
1212
await createPackage(fixtureDir, archiveFile);
1313
const archiveSize = fs.statSync(archiveFile).size;
1414

15-
console.log(`=== Extract breakdown: ${config.fileCount} files, archive ${(archiveSize / 1024).toFixed(0)} KB ===\n`);
15+
console.log(
16+
`=== Extract breakdown: ${config.fileCount} files, archive ${(archiveSize / 1024).toFixed(0)} KB ===\n`,
17+
);
1618

1719
// 1. Header parsing
1820
{
@@ -27,7 +29,9 @@ console.log(`=== Extract breakdown: ${config.fileCount} files, archive ${(archiv
2729
const filesystem = readFilesystemSync(archiveFile);
2830
const t = performance.now();
2931
const files = filesystem.listFiles();
30-
console.log(`listFiles: ${(performance.now() - t).toFixed(2)}ms (${files.length} entries)`);
32+
console.log(
33+
`listFiles: ${(performance.now() - t).toFixed(2)}ms (${files.length} entries)`,
34+
);
3135

3236
// 3. getFile lookups
3337
const followLinks = process.platform === 'win32';
@@ -63,7 +67,9 @@ console.log(`=== Extract breakdown: ${config.fileCount} files, archive ${(archiv
6367
}
6468
}
6569
fs.closeSync(fd);
66-
console.log(`readSync (individual): ${(performance.now() - t).toFixed(2)}ms (${totalRead} bytes)`);
70+
console.log(
71+
`readSync (individual): ${(performance.now() - t).toFixed(2)}ms (${totalRead} bytes)`,
72+
);
6773

6874
// 5. Read all data in one shot
6975
const t2 = performance.now();
@@ -139,13 +145,17 @@ console.log(`=== Extract breakdown: ${config.fileCount} files, archive ${(archiv
139145

140146
let t = performance.now();
141147
for (const d of dirEntries) filesystem.insertDirectory(d, false);
142-
console.log(`insertDirectory: ${(performance.now() - t).toFixed(1)}ms (${dirEntries.length})`);
148+
console.log(
149+
`insertDirectory: ${(performance.now() - t).toFixed(1)}ms (${dirEntries.length})`,
150+
);
143151

144152
t = performance.now();
145153
for (const f of fileEntries) {
146154
await filesystem.insertFile(f, () => fs.createReadStream(f), false, metadata[f]);
147155
}
148-
console.log(`insertFile (all): ${(performance.now() - t).toFixed(1)}ms (${fileEntries.length})`);
156+
console.log(
157+
`insertFile (all): ${(performance.now() - t).toFixed(1)}ms (${fileEntries.length})`,
158+
);
149159
}
150160

151161
fs.rmSync(tmpDir, { recursive: true, force: true });

benchmark/profile-memory.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import os from 'node:os';
44
import { generateFixture, formatBytes, FIXTURES } from './generate-fixtures.js';
5-
import { createPackage, createPackageFromFiles, uncache } from '../lib/asar.js';
5+
import { createPackage, createPackageFromFiles } from '../lib/asar.js';
66
import { crawl } from '../lib/crawlfs.js';
77

88
function getMemoryUsage() {
@@ -15,8 +15,8 @@ function printMem(label: string, before: NodeJS.MemoryUsage, after: NodeJS.Memor
1515
const rssDelta = after.rss - before.rss;
1616
console.log(
1717
` ${label.padEnd(30)} ` +
18-
`heap: ${formatBytes(after.heapUsed).padStart(10)}${(heapDelta >= 0 ? '+' : '') + formatBytes(heapDelta)}) ` +
19-
`rss: ${formatBytes(after.rss).padStart(10)}${(rssDelta >= 0 ? '+' : '') + formatBytes(rssDelta)})`
18+
`heap: ${formatBytes(after.heapUsed).padStart(10)}${(heapDelta >= 0 ? '+' : '') + formatBytes(heapDelta)}) ` +
19+
`rss: ${formatBytes(after.rss).padStart(10)}${(rssDelta >= 0 ? '+' : '') + formatBytes(rssDelta)})`,
2020
);
2121
}
2222

@@ -59,9 +59,11 @@ async function profileFixture(name: string) {
5959
printMem('createPackage (after)', before, after);
6060
console.log(
6161
` ${'peak heap'.padEnd(30)} ${formatBytes(peakHeap).padStart(10)} (Δ +${formatBytes(peakHeap - before.heapUsed)}) ` +
62-
`rss: ${formatBytes(peakRss).padStart(10)} (Δ +${formatBytes(peakRss - before.rss)})`
62+
`rss: ${formatBytes(peakRss).padStart(10)} (Δ +${formatBytes(peakRss - before.rss)})`,
63+
);
64+
console.log(
65+
` ${'data / peak-heap-delta'.padEnd(30)} ${((peakHeap - before.heapUsed) / dataSize).toFixed(2)}x data size`,
6366
);
64-
console.log(` ${'data / peak-heap-delta'.padEnd(30)} ${((peakHeap - before.heapUsed) / dataSize).toFixed(2)}x data size`);
6567
}
6668

6769
// Measure: createPackageFromFiles (pre-crawled)
@@ -90,9 +92,11 @@ async function profileFixture(name: string) {
9092
printMem('createPackageFromFiles (after)', before, after);
9193
console.log(
9294
` ${'peak heap'.padEnd(30)} ${formatBytes(peakHeap).padStart(10)} (Δ +${formatBytes(peakHeap - before.heapUsed)}) ` +
93-
`rss: ${formatBytes(peakRss).padStart(10)} (Δ +${formatBytes(peakRss - before.rss)})`
95+
`rss: ${formatBytes(peakRss).padStart(10)} (Δ +${formatBytes(peakRss - before.rss)})`,
96+
);
97+
console.log(
98+
` ${'data / peak-heap-delta'.padEnd(30)} ${((peakHeap - before.heapUsed) / dataSize).toFixed(2)}x data size`,
9499
);
95-
console.log(` ${'data / peak-heap-delta'.padEnd(30)} ${((peakHeap - before.heapUsed) / dataSize).toFixed(2)}x data size`);
96100
}
97101

98102
fs.rmSync(tmpDir, { recursive: true, force: true });

benchmark/profile-pack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const config = FIXTURES.find((f) => f.name === 'many-small-files')!;
88
const fixtureDir = generateFixture(config);
99

1010
// Get all files
11-
const allFiles = fs.readdirSync(fixtureDir, { withFileTypes: true, recursive: true })
11+
const allFiles = fs
12+
.readdirSync(fixtureDir, { withFileTypes: true, recursive: true })
1213
.filter((e) => e.isFile())
1314
.map((e) => path.join(e.parentPath, e.name));
1415

benchmark/profile.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import os from 'node:os';
44
import { generateFixture, FIXTURES } from './generate-fixtures.js';
55
import { crawl } from '../lib/crawlfs.js';
6-
import { createPackage, createPackageFromFiles, extractAll, uncache } from '../lib/asar.js';
6+
import { createPackageFromFiles, extractAll, uncache } from '../lib/asar.js';
77

88
const config = FIXTURES.find((f) => f.name === 'many-small-files')!;
99
const fixtureDir = generateFixture(config);
@@ -48,7 +48,8 @@ console.log('=== Profiling many-small-files (10,000 x ~256B = 2.4MB) ===\n');
4848
const { getFileIntegrity } = await import('../lib/integrity.js');
4949

5050
// Hash 10,000 small files via streams
51-
const files = fs.readdirSync(fixtureDir, { withFileTypes: true, recursive: true })
51+
const files = fs
52+
.readdirSync(fixtureDir, { withFileTypes: true, recursive: true })
5253
.filter((e) => e.isFile())
5354
.map((e) => path.join(e.parentPath, e.name));
5455

@@ -76,7 +77,8 @@ console.log('=== Profiling many-small-files (10,000 x ~256B = 2.4MB) ===\n');
7677
// Profile: how much time is file I/O vs stream setup?
7778
{
7879
console.log('--- STREAM vs BUFFER READ ---');
79-
const files = fs.readdirSync(fixtureDir, { withFileTypes: true, recursive: true })
80+
const files = fs
81+
.readdirSync(fixtureDir, { withFileTypes: true, recursive: true })
8082
.filter((e) => e.isFile())
8183
.map((e) => path.join(e.parentPath, e.name));
8284

@@ -87,7 +89,10 @@ console.log('=== Profiling many-small-files (10,000 x ~256B = 2.4MB) ===\n');
8789
const s = fs.createReadStream(file);
8890
const chunks: Buffer[] = [];
8991
s.on('data', (c) => chunks.push(c as Buffer));
90-
s.on('end', () => { Buffer.concat(chunks); resolve(); });
92+
s.on('end', () => {
93+
Buffer.concat(chunks);
94+
resolve();
95+
});
9196
s.on('error', reject);
9297
});
9398
}

benchmark/run.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import {
1515
} from '../lib/asar.js';
1616
import { crawl } from '../lib/crawlfs.js';
1717
import { getFileIntegrity } from '../lib/integrity.js';
18-
import {
19-
FIXTURES,
20-
generateFixture,
21-
cleanFixtures,
22-
formatBytes,
23-
type FixtureConfig,
24-
} from './generate-fixtures.js';
18+
import { FIXTURES, generateFixture, formatBytes, type FixtureConfig } from './generate-fixtures.js';
2519

2620
// ─── Benchmark harness ───────────────────────────────────────────────
2721

@@ -85,9 +79,7 @@ async function benchmark(
8579
}
8680

8781
function printResult(result: BenchmarkResult) {
88-
const throughput = result.throughputMBps
89-
? ` | ${result.throughputMBps.toFixed(1)} MB/s`
90-
: '';
82+
const throughput = result.throughputMBps ? ` | ${result.throughputMBps.toFixed(1)} MB/s` : '';
9183
console.log(
9284
` ${result.name.padEnd(40)} ` +
9385
`avg=${result.avgMs.toFixed(2).padStart(9)}ms ` +
@@ -136,10 +128,7 @@ async function benchmarkCrawl(fixtureDir: string, config: FixtureConfig): Promis
136128
);
137129
}
138130

139-
async function benchmarkPack(
140-
fixtureDir: string,
141-
config: FixtureConfig,
142-
): Promise<BenchmarkResult> {
131+
async function benchmarkPack(fixtureDir: string, config: FixtureConfig): Promise<BenchmarkResult> {
143132
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'asar-bench-pack-'));
144133
const destFile = path.join(tmpDir, `${config.name}.asar`);
145134
const dataSize = getDirectorySize(fixtureDir);
@@ -359,7 +348,11 @@ async function main() {
359348
printSection('Generating fixtures');
360349
const fixtureDirs = new Map<string, string>();
361350
const activeFixtures = FIXTURES.filter(
362-
(f) => !filterArg || f.name === filterArg || f.name.startsWith(filterArg + '-') || filterArg === 'all',
351+
(f) =>
352+
!filterArg ||
353+
f.name === filterArg ||
354+
f.name.startsWith(filterArg + '-') ||
355+
filterArg === 'all',
363356
);
364357

365358
for (const config of activeFixtures) {
@@ -368,9 +361,7 @@ async function main() {
368361
const elapsed = (performance.now() - start).toFixed(1);
369362
const totalSize = getDirectorySize(dir);
370363
const fileCount = getFileCount(dir);
371-
console.log(
372-
` ${config.name}: ${fileCount} files, ${formatBytes(totalSize)} (${elapsed}ms)`,
373-
);
364+
console.log(` ${config.name}: ${fileCount} files, ${formatBytes(totalSize)} (${elapsed}ms)`);
374365
fixtureDirs.set(config.name, dir);
375366
}
376367

bin/asar.mjs

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,35 @@ import { program } from 'commander';
66
import fs from 'node:fs';
77
import path from 'node:path';
88

9-
const splitVersion = function (version) { return version.split('.').map(function (part) { return Number(part) }) }
10-
const requiredNodeVersion = splitVersion(packageJSON.engines.node.slice(2))
11-
const actualNodeVersion = splitVersion(process.versions.node)
9+
const splitVersion = function (version) {
10+
return version.split('.').map(function (part) {
11+
return Number(part);
12+
});
13+
};
14+
const requiredNodeVersion = splitVersion(packageJSON.engines.node.slice(2));
15+
const actualNodeVersion = splitVersion(process.versions.node);
1216

13-
if (actualNodeVersion[0] < requiredNodeVersion[0] || (actualNodeVersion[0] === requiredNodeVersion[0] && actualNodeVersion[1] < requiredNodeVersion[1])) {
14-
console.error('CANNOT RUN WITH NODE ' + process.versions.node)
15-
console.error('asar requires Node ' + packageJSON.engines.node + '.')
16-
process.exit(1)
17+
if (
18+
actualNodeVersion[0] < requiredNodeVersion[0] ||
19+
(actualNodeVersion[0] === requiredNodeVersion[0] && actualNodeVersion[1] < requiredNodeVersion[1])
20+
) {
21+
console.error('CANNOT RUN WITH NODE ' + process.versions.node);
22+
console.error('asar requires Node ' + packageJSON.engines.node + '.');
23+
process.exit(1);
1724
}
1825

19-
program.version('v' + packageJSON.version)
20-
.description('Manipulate asar archive files')
26+
program.version('v' + packageJSON.version).description('Manipulate asar archive files');
2127

22-
program.command('pack <dir> <output>')
28+
program
29+
.command('pack <dir> <output>')
2330
.alias('p')
2431
.description('create asar archive')
2532
.option('--ordering <file path>', 'path to a text file for ordering contents')
2633
.option('--unpack <expression>', 'do not pack files matching glob <expression>')
27-
.option('--unpack-dir <expression>', 'do not pack dirs matching glob <expression> or starting with literal <expression>')
34+
.option(
35+
'--unpack-dir <expression>',
36+
'do not pack dirs matching glob <expression> or starting with literal <expression>',
37+
)
2838
.option('--exclude-hidden', 'exclude hidden files')
2939
.action(function (dir, output, options) {
3040
options = {
@@ -34,50 +44,51 @@ program.command('pack <dir> <output>')
3444
version: options.sv,
3545
arch: options.sa,
3646
builddir: options.sb,
37-
dot: !options.excludeHidden
38-
}
39-
createPackageWithOptions(dir, output, options).catch(error => {
40-
console.error(error)
41-
process.exit(1)
42-
})
43-
})
47+
dot: !options.excludeHidden,
48+
};
49+
createPackageWithOptions(dir, output, options).catch((error) => {
50+
console.error(error);
51+
process.exit(1);
52+
});
53+
});
4454

45-
program.command('list <archive>')
55+
program
56+
.command('list <archive>')
4657
.alias('l')
4758
.description('list files of asar archive')
4859
.option('-i, --is-pack', 'each file in the asar is pack or unpack')
4960
.action(function (archive, options) {
5061
options = {
51-
isPack: options.isPack
52-
}
53-
const files = listPackage(archive, options)
62+
isPack: options.isPack,
63+
};
64+
const files = listPackage(archive, options);
5465
for (const i in files) {
55-
console.log(files[i])
66+
console.log(files[i]);
5667
}
57-
})
68+
});
5869

59-
program.command('extract-file <archive> <filename>')
70+
program
71+
.command('extract-file <archive> <filename>')
6072
.alias('ef')
6173
.description('extract one file from archive')
6274
.action(function (archive, filename) {
63-
fs.writeFileSync(path.basename(filename),
64-
extractFile(archive, filename))
65-
})
75+
fs.writeFileSync(path.basename(filename), extractFile(archive, filename));
76+
});
6677

67-
program.command('extract <archive> <dest>')
78+
program
79+
.command('extract <archive> <dest>')
6880
.alias('e')
6981
.description('extract archive')
7082
.action(function (archive, dest) {
71-
extractAll(archive, dest)
72-
})
83+
extractAll(archive, dest);
84+
});
7385

74-
program.command('*', { hidden: true})
75-
.action(function (_cmd, args) {
76-
console.log('asar: \'%s\' is not an asar command. See \'asar --help\'.', args[0])
77-
})
86+
program.command('*', { hidden: true }).action(function (_cmd, args) {
87+
console.log("asar: '%s' is not an asar command. See 'asar --help'.", args[0]);
88+
});
7889

79-
program.parse(process.argv)
90+
program.parse(process.argv);
8091

8192
if (program.args.length === 0) {
82-
program.help()
93+
program.help();
8394
}

0 commit comments

Comments
 (0)