Skip to content

Commit db32229

Browse files
committed
refactor: switched completely to ES modules
removed moment support.
1 parent b98e030 commit db32229

File tree

158 files changed

+3693
-19931
lines changed

Some content is hidden

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

158 files changed

+3693
-19931
lines changed

jest-serial-runner.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const TestRunner = require('jest-runner');
2+
3+
class SerialRunner extends TestRunner.default {
4+
constructor(...attr) {
5+
super(...attr)
6+
this.isSerial = true
7+
}
8+
}
9+
10+
module.exports = SerialRunner

package-lock.json

+1,938-1,262
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Marc J. Schmidt <[email protected]>",
55
"license": "AGPL-3.0-only",
66
"scripts": {
7-
"test": "jest --coverage --forceExit",
7+
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --forceExit",
88
"bootstrap": "lerna bootstrap --no-ci",
99
"tsc": "tsc --build",
1010
"tsc-watch": "tsc --build --watch",
@@ -18,12 +18,13 @@
1818
"peerDependencies": {},
1919
"devDependencies": {
2020
"@types/jest": "^26.0.3",
21-
"@types/node": "^12.12.6",
21+
"@types/node": "^14.14.12",
2222
"coveralls": "^3.0.3",
23-
"jest": "^26.6.3",
23+
"jest": "^27.0.0-next.2",
2424
"jest-extended": "^0.11.5",
2525
"lerna": "^3.22.1",
26-
"ts-jest": "^26.4.3",
26+
"ts-node": "^9.1.1",
27+
"ts-jest": "https://github.com/marcj/ts-jest.git",
2728
"typescript": "^4.1.2",
2829
"typedoc": "^0.16.8",
2930
"typedoc-plugin-lerna-packages": "^0.3.0"

packages/benchmark/index.ts

+58-27
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,75 @@
1-
import {mkdirSync, writeFileSync} from 'fs';
2-
import {join} from 'path';
1+
import {writeFileSync, mkdirSync, rmdirSync, readFileSync} from 'fs';
2+
import {basename, dirname, join} from 'path';
33
import 'reflect-metadata';
4-
import * as vm from 'vm';
54
import {getGlobalStore} from '@deepkit/type';
6-
const fg = require('fast-glob');
5+
import fg from 'fast-glob';
6+
import fetch from 'node-fetch';
7+
import {ensureDir} from 'fs-extra';
8+
import {spawn, spawnSync} from 'child_process';
79

810
const filter = process.argv[2] || '';
911

1012
if (filter) console.log('filter by', filter);
1113

12-
async function main() {
13-
const totalResults: { [path: string]: any } = {};
14-
let glob = ['./src/**/*.bench.ts'];
14+
const totalResults: { [path: string]: any } = {};
15+
let glob = ['./src/**/*.bench.ts'];
1516

16-
const benchmarkPaths = fg.sync(glob, {onlyFiles: true, unique: true});
17-
const filterRegex = filter ? new RegExp(filter.replace(/\*/, '.*')) : undefined;
17+
const benchmarkPaths = fg.sync(glob, {onlyFiles: true, unique: true});
18+
const filterRegex = filter ? new RegExp(filter.replace(/\*/, '.*')) : undefined;
19+
const __dirname = dirname(import.meta.url.replace('file://', ''));
20+
const resultsPath = join(__dirname, 'results');
1821

19-
for (const benchmarkPath of benchmarkPaths) {
20-
const id = benchmarkPath.substring('./src/'.length, benchmarkPath.length - '.ts'.length - '.bench'.length);
22+
for (const benchmarkPath of benchmarkPaths) {
23+
const id = benchmarkPath.substring('./src/'.length, benchmarkPath.length - '.ts'.length - '.bench'.length);
2124

22-
if (filterRegex && !filterRegex.exec(id)) continue;
25+
if (filterRegex && !filterRegex.exec(id)) continue;
2326

24-
console.log('🏃‍run', id);
27+
console.log('🏃‍run', id);
2528

26-
const onComplete = (name: string, result: { [name: string]: { hz: number, elapsed: number, rme: number, mean: number } }) => {
27-
if (!totalResults[id]) totalResults[id] = {};
28-
totalResults[id][name] = result;
29-
};
29+
if (!totalResults[id]) totalResults[id] = {};
3030

31-
for (const key in require.cache) {
32-
delete require.cache[key];
31+
const resultPath = join(resultsPath, 'bench', id);
32+
rmdirSync(resultPath, {recursive: true});
33+
mkdirSync(resultPath, {recursive: true});
34+
35+
const script = `
36+
import {BenchSuite} from './src/bench';
37+
import {main} from '${benchmarkPath}';
38+
import {writeFileSync} from 'fs';
39+
40+
BenchSuite.onComplete = function (name, result) {
41+
writeFileSync(${JSON.stringify(resultPath)} + '/' + name + '.json', JSON.stringify(result));
3342
}
34-
getGlobalStore().RegisteredEntities = {};
35-
const script = new vm.Script(`require('./src/bench').BenchSuite.onComplete = onComplete; (require(benchmarkPath).main())`);
36-
await script.runInNewContext({benchmarkPath, require, onComplete});
37-
}
43+
44+
await main();
45+
`;
46+
47+
spawnSync('node', ['--no-warnings', '--input-type=module', '--experimental-specifier-resolution=node', '--loader=ts-node/esm'],
48+
{input: script, encoding: 'utf8', stdio: ['pipe', 'inherit', 'inherit']});
3849

39-
const resultsPath = join(__dirname, 'results');
40-
mkdirSync(resultsPath, {recursive: true});
41-
writeFileSync(resultsPath + '/' + (new Date().toJSON()) + '.json', JSON.stringify(totalResults, undefined, 4));
50+
const resultPaths = fg.sync(resultPath + '/*.json', {onlyFiles: true, unique: true});
51+
for (const path of resultPaths) {
52+
const result = JSON.parse(readFileSync(path).toString());
53+
if (!totalResults[id]) totalResults[id] = {};
54+
const name = basename(path).replace('.json', '');
55+
totalResults[id][name] = result;
56+
}
4257
}
4358

44-
main();
59+
mkdirSync(resultsPath, {recursive: true});
60+
writeFileSync(resultsPath + '/' + (new Date().toJSON()) + '.json', JSON.stringify(totalResults, undefined, 4));
61+
62+
const host = process.env['BENCHMARK_HOST'] || 'http://127.0.0.1:8080';
63+
try {
64+
const res = await fetch(`${host}/benchmark/add`, {
65+
method: 'POST',
66+
headers: {
67+
'Authorization': process.env['BENCHMARK_TOKEN'] || 'notSet',
68+
'Content-Type': 'application/json',
69+
},
70+
body: JSON.stringify({created: new Date, data: totalResults}),
71+
});
72+
await res.json();
73+
} catch (error) {
74+
console.log('error sending benchmark data', error);
75+
}

packages/benchmark/index2.ts

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {mkdirSync, writeFileSync} from 'fs';
2+
import {dirname, join} from 'path';
3+
import 'reflect-metadata';
4+
import * as vm from 'vm';
5+
import {getGlobalStore} from '@deepkit/type';
6+
import fg from 'fast-glob';
7+
import fetch from 'node-fetch';
8+
import Module from 'module';
9+
10+
const filter = process.argv[2] || '';
11+
12+
if (filter) console.log('filter by', filter);
13+
14+
const totalResults: { [path: string]: any } = {};
15+
let glob = ['./src/**/*.bench.ts'];
16+
17+
const benchmarkPaths = fg.sync(glob, {onlyFiles: true, unique: true});
18+
const filterRegex = filter ? new RegExp(filter.replace(/\*/, '.*')) : undefined;
19+
20+
for (const benchmarkPath of benchmarkPaths) {
21+
const id = benchmarkPath.substring('./src/'.length, benchmarkPath.length - '.ts'.length - '.bench'.length);
22+
23+
if (filterRegex && !filterRegex.exec(id)) continue;
24+
25+
const onComplete = (name: string, result: { [name: string]: { hz: number, elapsed: number, rme: number, mean: number } }) => {
26+
if (!totalResults[id]) totalResults[id] = {};
27+
totalResults[id][name] = result;
28+
};
29+
30+
// const script = new vm.Script(`require('./src/bench').BenchSuite.onComplete = onComplete; (require(benchmarkPath).main())`);
31+
const script = new vm.Script(`console.log('hi')
32+
console.log(import('./src/bench'));
33+
`);
34+
await script.runInThisContext();
35+
36+
// @ts-ignore
37+
// const module = new vm.SourceTextModule(
38+
// `
39+
// import {BenchSuite} from './src/bench';
40+
// // import {main} from '${benchmarkPath}';
41+
//
42+
// console.log('${benchmarkPath}');
43+
// // export const o = 'asd';
44+
// // BenchSuite.onComplete = onComplete;
45+
// // (main())
46+
// // require('./src/bench').BenchSuite.onComplete = onComplete;
47+
// // (require(benchmarkPath).main())
48+
// `,
49+
// {
50+
// identifier: import.meta.url,
51+
// initializeImportMeta(meta) {
52+
// // Note: this object is created in the top context. As such,
53+
// // Object.getPrototypeOf(import.meta.prop) points to the
54+
// // Object.prototype in the top context rather than that in
55+
// // the contextified object.
56+
// meta.prop = {};
57+
// }
58+
// });
59+
// Since module has no dependencies, the linker function will never be called.
60+
// await module.link((spec) => import(spec));
61+
// await module.link(function (spec) {
62+
//
63+
// return new Promise(async function (resolve, reject) {
64+
// const mod: Module = await import( spec );
65+
// // const res = new vm.Module();
66+
// const names: string[] = [];
67+
// for (const i in mod) {
68+
// names.push(i);
69+
// }
70+
// // @ts-ignore
71+
// const res = new vm.SyntheticModule(names);
72+
//
73+
// for (const e of names) {
74+
// res.setExport(e, mod.exports[e]);
75+
// }
76+
// // res.exports = mod.exports;
77+
// // console.log('mod', mod);
78+
// resolve(res);
79+
// // resolve(new vm.SyntheticModule(['default'], function () {
80+
// // // @ts-ignore
81+
// // this.setExport('default', mod.default);
82+
// // }));
83+
// });
84+
// });
85+
//
86+
// await module.evaluate();
87+
}

packages/benchmark/model.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {entity, t} from '@deepkit/type';
2+
3+
@entity.name('benchmark/entry')
4+
export class BenchmarkEntry {
5+
@t hz!: number;
6+
@t elapsed!: number;
7+
@t rme!: number;
8+
@t mean!: number;
9+
}
10+
11+
@entity.name('benchmark/run')
12+
export class BenchmarkRun {
13+
@t.primary.autoIncrement id?: number;
14+
@t created: Date = new Date;
15+
16+
@t.map(t.map(t.map(BenchmarkEntry)))
17+
data: { [fileName: string]: { [suite: string]: { [method: string]: BenchmarkEntry } } } = {};
18+
}

packages/benchmark/package-lock.json

+32-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/benchmark/package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@deepkit/benchmark",
33
"version": "1.0.1-alpha.0",
4-
"description": "Super Hornet Benchmarks",
5-
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
4+
"description": "Deepkit Benchmarks",
5+
"type": "module",
76
"sideEffects": false,
87
"private": true,
98
"scripts": {
10-
"benchmark": "ts-node .",
11-
"benchmark-prof": "node -r ts-node/register --prof .",
9+
"benchmark": "node --no-warnings --experimental-vm-modules --experimental-specifier-resolution=node --loader @deepkit/framework/loader index.ts",
10+
"benchmark2": "node --no-warnings --experimental-vm-modules --experimental-specifier-resolution=node --loader @deepkit/framework/loader index2.ts",
11+
"benchmark-prof": "node --prof --experimental-vm-modules --no-warnings --experimental-specifier-resolution=node --loader @deepkit/framework/loader index.ts",
1212
"setup": "sh setup.sh"
1313
},
1414
"repository": "https://github.com/deepkit/deepkit-framework",
@@ -36,11 +36,13 @@
3636
"fp-ts": "^2.8.2",
3737
"io-ts": "^2.2.10",
3838
"mikro-orm": "^4.1.0",
39+
"node-fetch": "^2.6.1",
3940
"quartet": "^10.1.0",
4041
"reflect-metadata": "^0.1.13",
4142
"sqlite3": "^5.0.0",
42-
"ts-node": "^8.10.2",
43-
"typescript": "^4.1.1-rc",
4443
"typeorm": "^0.2.26"
44+
},
45+
"devDependencies": {
46+
"@types/node-fetch": "^2.5.7"
4547
}
4648
}

packages/benchmark/src/bench.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
import {performance} from 'perf_hooks';
20+
import Benchmark from 'benchmark';
2021

21-
const Benchmark = require('benchmark');
2222
const Reset = '\x1b[0m';
2323
const FgGreen = '\x1b[32m';
2424
const FgYellow = '\x1b[33m';

0 commit comments

Comments
 (0)