Skip to content

Commit 3d9522f

Browse files
authored
Merge pull request #68 from MatrixAI/feature-esm-migrate
ESM Migration
2 parents 9fa4b84 + 11f1ba6 commit 3d9522f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3008
-2184
lines changed

.eslintrc

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
"jest": true
88
},
99
"parser": "@typescript-eslint/parser",
10-
"extends": [
11-
"eslint:recommended",
12-
"plugin:@typescript-eslint/recommended",
13-
"plugin:prettier/recommended",
14-
"prettier"
15-
],
16-
"plugins": [
17-
"import"
18-
],
1910
"parserOptions": {
2011
"project": "tsconfig.json",
2112
"sourceType": "module"
2213
},
14+
"plugins": [
15+
"import"
16+
],
17+
"extends": [
18+
"eslint:recommended",
19+
"plugin:@typescript-eslint/recommended",
20+
"plugin:prettier/recommended"
21+
],
2322
"rules": {
2423
"linebreak-style": ["error", "unix"],
2524
"no-empty": 1,

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ npm install
9494
# build the dist
9595
npm run build
9696
# run the repl (this allows you to import from ./src)
97-
npm run ts-node
97+
npm run tsx
9898
# run the tests
9999
npm run test
100100
# lint the source code

benches/db_1KiB.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import os from 'os';
22
import fs from 'fs';
33
import path from 'path';
44
import crypto from 'crypto';
5+
import url from 'node:url';
56
import b from 'benny';
67
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
7-
import DB from '@/DB';
8-
import { suiteCommon } from './utils';
8+
import { suiteCommon } from './utils/utils.js';
9+
import DB from '#DB.js';
910

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

1214
async function main() {
1315
const dataDir = await fs.promises.mkdtemp(
@@ -18,7 +20,7 @@ async function main() {
1820
const data0 = crypto.randomBytes(0);
1921
const data1KiB = crypto.randomBytes(1024);
2022
const summary = await b.suite(
21-
path.basename(__filename, path.extname(__filename)),
23+
path.basename(filename, path.extname(filename)),
2224
b.add('get 1 KiB of data', async () => {
2325
await db.put('1kib', data1KiB, true);
2426
return async () => {
@@ -44,8 +46,7 @@ async function main() {
4446
});
4547
return summary;
4648
}
47-
48-
if (require.main === module) {
49+
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
4950
void main();
5051
}
5152

benches/db_1MiB.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import os from 'os';
22
import fs from 'fs';
33
import path from 'path';
44
import crypto from 'crypto';
5+
import url from 'node:url';
56
import b from 'benny';
67
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
7-
import DB from '@/DB';
8-
import { suiteCommon } from './utils';
8+
import { suiteCommon } from './utils/utils.js';
9+
import DB from '#DB.js';
910

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

1214
async function main() {
1315
const dataDir = await fs.promises.mkdtemp(
@@ -18,7 +20,7 @@ async function main() {
1820
const data0 = crypto.randomBytes(0);
1921
const data1MiB = crypto.randomBytes(1024 * 1024);
2022
const summary = await b.suite(
21-
path.basename(__filename, path.extname(__filename)),
23+
path.basename(filename, path.extname(filename)),
2224
b.add('get 1 MiB of data', async () => {
2325
await db.put('1mib', data1MiB, true);
2426
return async () => {
@@ -45,7 +47,7 @@ async function main() {
4547
return summary;
4648
}
4749

48-
if (require.main === module) {
50+
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
4951
void main();
5052
}
5153

benches/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22

33
import fs from 'fs';
44
import path from 'path';
5+
import url from 'node:url';
56
import si from 'systeminformation';
6-
import DB1KiB from './db_1KiB';
7-
import DB1MiB from './db_1MiB';
7+
import DB1KiB from './db_1KiB.js';
8+
import DB1MiB from './db_1MiB.js';
9+
10+
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
811

912
async function main(): Promise<void> {
10-
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
13+
await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true });
1114
await DB1KiB();
1215
await DB1MiB();
1316
const resultFilenames = await fs.promises.readdir(
14-
path.join(__dirname, 'results'),
17+
path.join(dirname, 'results'),
1518
);
1619
const metricsFile = await fs.promises.open(
17-
path.join(__dirname, 'results', 'metrics.txt'),
20+
path.join(dirname, 'results', 'metrics.txt'),
1821
'w',
1922
);
2023
let concatenating = false;
2124
for (const resultFilename of resultFilenames) {
2225
if (/.+_metrics\.txt$/.test(resultFilename)) {
2326
const metricsData = await fs.promises.readFile(
24-
path.join(__dirname, 'results', resultFilename),
27+
path.join(dirname, 'results', resultFilename),
2528
);
2629
if (concatenating) {
2730
await metricsFile.write('\n');
@@ -37,7 +40,7 @@ async function main(): Promise<void> {
3740
system: 'model, manufacturer',
3841
});
3942
await fs.promises.writeFile(
40-
path.join(__dirname, 'results', 'system.json'),
43+
path.join(dirname, 'results', 'system.json'),
4144
JSON.stringify(systemData, null, 2),
4245
);
4346
}

benches/results/db_1KiB.chart.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</head>
2929
<body>
3030
<div class="container">
31-
<canvas id="chart1687684087088" width="16" height="9"></canvas>
31+
<canvas id="chart1742452282334" width="16" height="9"></canvas>
3232
</div>
3333
<script>
3434
const format = (num) => {
@@ -51,18 +51,18 @@
5151
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
5252
)
5353
}
54-
const ctx1687684087088 = document
55-
.getElementById('chart1687684087088')
54+
const ctx1742452282334 = document
55+
.getElementById('chart1742452282334')
5656
.getContext('2d')
57-
const chart1687684087088 = new Chart(ctx1687684087088, {
57+
const chart1742452282334 = new Chart(ctx1742452282334, {
5858
type: 'bar',
5959
data: {
6060
labels: ["get 1 KiB of data","put 1 KiB of data","put zero data","put zero data then del"],
6161
datasets: [
6262
{
63-
data: [47519,32985,35687,17917],
64-
backgroundColor: ["hsl(120, 85%, 55%)","hsl(83.29199999999999, 85%, 55%)","hsl(90.11999999999999, 85%, 55%)","hsl(45.24, 85%, 55%)"],
65-
borderColor: ["hsl(120, 85%, 55%)","hsl(83.29199999999999, 85%, 55%)","hsl(90.11999999999999, 85%, 55%)","hsl(45.24, 85%, 55%)"],
63+
data: [71704,40939,49028,19057],
64+
backgroundColor: ["hsl(120, 85%, 55%)","hsl(68.50800000000001, 85%, 55%)","hsl(82.056, 85%, 55%)","hsl(31.895999999999997, 85%, 55%)"],
65+
borderColor: ["hsl(120, 85%, 55%)","hsl(68.50800000000001, 85%, 55%)","hsl(82.056, 85%, 55%)","hsl(31.895999999999997, 85%, 55%)"],
6666
borderWidth: 2,
6767
},
6868
],

0 commit comments

Comments
 (0)