Skip to content

ESM Migration #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
"jest": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
],
"plugins": [
"import"
],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"import"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"linebreak-style": ["error", "unix"],
"no-empty": 1,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run ts-node
npm run tsx
# run the tests
npm run test
# lint the source code
Expand Down
11 changes: 6 additions & 5 deletions benches/db_1KiB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import os from 'os';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import url from 'node:url';
import b from 'benny';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import DB from '@/DB';
import { suiteCommon } from './utils';
import { suiteCommon } from './utils/utils.js';
import DB from '#DB.js';

const logger = new Logger('DB1KiB Bench', LogLevel.WARN, [new StreamHandler()]);
const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const dataDir = await fs.promises.mkdtemp(
Expand All @@ -18,7 +20,7 @@ async function main() {
const data0 = crypto.randomBytes(0);
const data1KiB = crypto.randomBytes(1024);
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filename, path.extname(filename)),
b.add('get 1 KiB of data', async () => {
await db.put('1kib', data1KiB, true);
return async () => {
Expand All @@ -44,8 +46,7 @@ async function main() {
});
return summary;
}

if (require.main === module) {
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
void main();
}

Expand Down
10 changes: 6 additions & 4 deletions benches/db_1MiB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import os from 'os';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import url from 'node:url';
import b from 'benny';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import DB from '@/DB';
import { suiteCommon } from './utils';
import { suiteCommon } from './utils/utils.js';
import DB from '#DB.js';

const logger = new Logger('DB1MiB Bench', LogLevel.WARN, [new StreamHandler()]);
const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const dataDir = await fs.promises.mkdtemp(
Expand All @@ -18,7 +20,7 @@ async function main() {
const data0 = crypto.randomBytes(0);
const data1MiB = crypto.randomBytes(1024 * 1024);
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filename, path.extname(filename)),
b.add('get 1 MiB of data', async () => {
await db.put('1mib', data1MiB, true);
return async () => {
Expand All @@ -45,7 +47,7 @@ async function main() {
return summary;
}

if (require.main === module) {
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
void main();
}

Expand Down
17 changes: 10 additions & 7 deletions benches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@

import fs from 'fs';
import path from 'path';
import url from 'node:url';
import si from 'systeminformation';
import DB1KiB from './db_1KiB';
import DB1MiB from './db_1MiB';
import DB1KiB from './db_1KiB.js';
import DB1MiB from './db_1MiB.js';

const dirname = url.fileURLToPath(new URL('.', import.meta.url));

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true });
await DB1KiB();
await DB1MiB();
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
path.join(dirname, 'results'),
);
const metricsFile = await fs.promises.open(
path.join(__dirname, 'results', 'metrics.txt'),
path.join(dirname, 'results', 'metrics.txt'),
'w',
);
let concatenating = false;
for (const resultFilename of resultFilenames) {
if (/.+_metrics\.txt$/.test(resultFilename)) {
const metricsData = await fs.promises.readFile(
path.join(__dirname, 'results', resultFilename),
path.join(dirname, 'results', resultFilename),
);
if (concatenating) {
await metricsFile.write('\n');
Expand All @@ -37,7 +40,7 @@ async function main(): Promise<void> {
system: 'model, manufacturer',
});
await fs.promises.writeFile(
path.join(__dirname, 'results', 'system.json'),
path.join(dirname, 'results', 'system.json'),
JSON.stringify(systemData, null, 2),
);
}
Expand Down
14 changes: 7 additions & 7 deletions benches/results/db_1KiB.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</head>
<body>
<div class="container">
<canvas id="chart1687684087088" width="16" height="9"></canvas>
<canvas id="chart1742452282334" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1687684087088 = document
.getElementById('chart1687684087088')
const ctx1742452282334 = document
.getElementById('chart1742452282334')
.getContext('2d')
const chart1687684087088 = new Chart(ctx1687684087088, {
const chart1742452282334 = new Chart(ctx1742452282334, {
type: 'bar',
data: {
labels: ["get 1 KiB of data","put 1 KiB of data","put zero data","put zero data then del"],
datasets: [
{
data: [47519,32985,35687,17917],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(83.29199999999999, 85%, 55%)","hsl(90.11999999999999, 85%, 55%)","hsl(45.24, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(83.29199999999999, 85%, 55%)","hsl(90.11999999999999, 85%, 55%)","hsl(45.24, 85%, 55%)"],
data: [71704,40939,49028,19057],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(68.50800000000001, 85%, 55%)","hsl(82.056, 85%, 55%)","hsl(31.895999999999997, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(68.50800000000001, 85%, 55%)","hsl(82.056, 85%, 55%)","hsl(31.895999999999997, 85%, 55%)"],
borderWidth: 2,
},
],
Expand Down
Loading