Skip to content

New Workload: TypeScript standalone #117

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
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: 14 additions & 3 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ class ShellScripts extends Scripts {
} else
globalObject = runString("");

globalObject.console = console;
globalObject.console = Object.assign({}, console);
globalObject.self = globalObject;
globalObject.top = {
currentResolve,
Expand Down Expand Up @@ -1710,7 +1710,7 @@ let BENCHMARKS = [
tags: ["Default", "Octane"],
}),
new DefaultBenchmark({
name: "typescript",
name: "typescript-octane",
files: [
"./Octane/typescript-compiler.js",
"./Octane/typescript-input.js",
Expand All @@ -1719,7 +1719,7 @@ let BENCHMARKS = [
iterations: 15,
worstCaseCount: 2,
deterministicRandom: true,
tags: ["Default", "Octane"],
tags: ["Default", "Octane", "typescript"],
}),
// RexBench
new DefaultBenchmark({
Expand Down Expand Up @@ -1934,6 +1934,17 @@ let BENCHMARKS = [
],
tags: ["Default", "ClassFields"],
}),
new DefaultBenchmark({
name: "typescript-lib",
files: [
"./TypeScript/src/mock/sys.js",
"./TypeScript/dist/typescript-compile-test.js",
"./TypeScript/benchmark.js",
],
iterations: 3,
worstCaseCount: 2,
tags: ["Default", "typescript"],
}),
// Generators
new AsyncBenchmark({
name: "async-fs",
Expand Down
2 changes: 2 additions & 0 deletions TypeScript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build/*.git
9 changes: 9 additions & 0 deletions TypeScript/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want a copyright here?


console.log = () => {};

class Benchmark {
runIteration() {
TypeScriptCompileTest.compileTest();
}
}
196 changes: 196 additions & 0 deletions TypeScript/build/import-src-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
const fs = require("fs");
const path = require("path");
const { spawnSync } = require("child_process");
const glob = require("glob");
const assert = require('assert/strict');


class Importer {
constructor({ projectName, size, repoUrl, srcFolder, extraFiles, extraDirs }) {
this.projectName = projectName;
assert(projectName.endsWith(`-${size}`), "missing size annotation in projectName");
this.repoUrl = repoUrl;
this.baseDir = path.resolve(__dirname);
let repoName = path.basename(this.repoUrl);
if (!repoName.endsWith(".git")) {
repoName = `${repoName}.git`;
}
this.repoDir = path.resolve(__dirname, repoName);
this.srcFolder = srcFolder;
this.outputDir = path.resolve(__dirname, `../src/gen/${this.projectName}`);
fs.mkdirSync(this.outputDir, { recursive: true });
this.srcFileData = Object.create(null);
this.extraFiles = extraFiles;
this.extraDirs = extraDirs;
}
run() {
this.cloneRepo();
this.readSrcFileData();
this.addExtraFilesFromDirs();
this.addSpecificFiles();
this.writeTsConfig();
this.writeSrcFileData();
}

cloneRepo() {
if (fs.existsSync(this.repoDir)) return;
console.info(`Cloning src data repository to ${this.repoDir}`);
spawnSync("git", ["clone", this.repoUrl, this.repoDir]);
}

readSrcFileData() {
const patterns = [`${this.srcFolder}/**/*.ts`, `${this.srcFolder}/**/*.d.ts`, `${this.srcFolder}/*.d.ts`];
patterns.forEach(pattern => {
const files = glob.sync(pattern, { cwd: this.repoDir, nodir: true });
files.forEach(file => {
const filePath = path.join(this.repoDir, file);
const relativePath = path.relative(this.repoDir, filePath).toLowerCase();
const fileContents = fs.readFileSync(filePath, "utf8");
this.addFileContents(relativePath, fileContents);
});
});
}

addExtraFilesFromDirs() {
this.extraDirs.forEach(({ dir, nameOnly = false }) => {
const absoluteSourceDir = path.resolve(__dirname, dir);
let allFiles = glob.sync("**/*.d.ts", { cwd: absoluteSourceDir, nodir: true });
allFiles = allFiles.concat(glob.sync("**/*.d.mts", { cwd: absoluteSourceDir, nodir: true }));

allFiles.forEach(file => {
const filePath = path.join(absoluteSourceDir, file);
let relativePath = path.join(dir, path.relative(absoluteSourceDir, filePath));
if (nameOnly) {
relativePath = path.basename(relativePath);
}
this.addFileContents(relativePath, fs.readFileSync(filePath, "utf8"))
});
});
}

addFileContents(relativePath, fileContents) {
if (relativePath in this.srcFileData) {
if (this.srcFileData[relativePath] !== fileContents) {
throw new Error(`${relativePath} was previously added with different contents.`);
}
} else {
this.srcFileData[relativePath] = fileContents;
}
}

addSpecificFiles() {
this.extraFiles.forEach(file => {
const filePath = path.join(this.baseDir, file);
this.srcFileData[file] = fs.readFileSync(filePath, "utf8");
});
}

writeSrcFileData() {
const filesDataPath = path.join(this.outputDir, "src_file_data.cjs");
fs.writeFileSync(
filesDataPath, `// Generated src file data from existing node modules and
// ${this.repoUrl}
// See LICENSEs in the sources.
module.exports = ${JSON.stringify(this.srcFileData, null, 2)};
`
);
const stats = fs.statSync(filesDataPath);
const fileSizeInKiB = (stats.size / 1024) | 0;
console.info(`Exported ${this.projectName}`);
console.info(` File Contents: ${path.relative(process.cwd(), filesDataPath)}`);
console.info(` Total Size: ${fileSizeInKiB} KiB`);
}

writeTsConfig() {
const tsconfigInputPath = path.join(this.repoDir, "tsconfig.json");
const mergedTsconfig = this.loadAndMergeTsconfig(tsconfigInputPath);
const tsconfigOutputPath = path.join(this.outputDir, "src_tsconfig.cjs");
fs.writeFileSync(
tsconfigOutputPath, `// Exported from ${this.repoUrl}
// See LICENSEs in the sources.
module.exports = ${JSON.stringify(mergedTsconfig, null, 2)};
`
);
}

loadAndMergeTsconfig(configPath) {
const tsconfigContent = fs.readFileSync(configPath, "utf8");
const tsconfigContentWithoutComments = tsconfigContent.replace(/(?:^|\s)\/\/.*$|\/\*[\s\S]*?\*\//gm, "");
const tsconfig = JSON.parse(tsconfigContentWithoutComments);
let baseConfigPath = tsconfig.extends;
if (!baseConfigPath) return tsconfig;
if (!baseConfigPath.startsWith('./') && !baseConfigPath.startsWith('../')) return tsconfig;

baseConfigPath = path.resolve(path.dirname(configPath), baseConfigPath);
const baseConfig = this.loadAndMergeTsconfig(baseConfigPath);

const mergedConfig = { ...baseConfig, ...tsconfig };
if (baseConfig.compilerOptions && tsconfig.compilerOptions) {
mergedConfig.compilerOptions = { ...baseConfig.compilerOptions, ...tsconfig.compilerOptions };
}
delete mergedConfig.extends;
return mergedConfig;
}
}

new Importer({
projectName: "jestjs-large",
size: "large",
repoUrl: "https://github.com/jestjs/jest.git",
srcFolder: "packages",
extraFiles: [
"../../node_modules/@babel/types/lib/index.d.ts",
"../../node_modules/callsites/index.d.ts",
"../../node_modules/camelcase/index.d.ts",
"../../node_modules/chalk/types/index.d.ts",
"../../node_modules/execa/index.d.ts",
"../../node_modules/fast-json-stable-stringify/index.d.ts",
"../../node_modules/get-stream/index.d.ts",
"../../node_modules/strip-json-comments/index.d.ts",
"../../node_modules/tempy/index.d.ts",
"../../node_modules/tempy/node_modules/type-fest/index.d.ts",
"../node_modules/@jridgewell/trace-mapping/types/trace-mapping.d.mts",
"../node_modules/@types/eslint/index.d.ts",
"../node_modules/ansi-regex/index.d.ts",
"../node_modules/ansi-styles/index.d.ts",
"../node_modules/glob/dist/esm/index.d.ts",
"../node_modules/jest-worker/build/index.d.ts",
"../node_modules/lru-cache/dist/esm/index.d.ts",
"../node_modules/minipass/dist/esm/index.d.ts",
"../node_modules/p-limit/index.d.ts",
"../node_modules/path-scurry/dist/esm/index.d.ts",
"../node_modules/typescript/lib/lib.dom.d.ts",
],
extraDirs: [
{ dir: "../node_modules/@types/" },
{ dir: "../node_modules/typescript/lib/", nameOnly: true },
{ dir: "../node_modules/jest-worker/build/" },
{ dir: "../node_modules/@jridgewell/trace-mapping/types/" },
{ dir: "../node_modules/minimatch/dist/esm/" },
{ dir: "../node_modules/glob/dist/esm/" },
{ dir: "../../node_modules/tempy/node_modules/type-fest/source/" }
],
}).run();

new Importer({
projectName: "zod-medium",
size: "medium",
repoUrl: "https://github.com/colinhacks/zod.git",
srcFolder: "packages",
extraFiles: [],
extraDirs: [
{ dir: "../node_modules/typescript/lib/", nameOnly: true },
],
}).run();

// Import tiny-sized project sources:
new Importer({
projectName: "immer-tiny",
size: "tiny",
repoUrl: "https://github.com/immerjs/immer.git",
srcFolder: "src",
extraFiles: [],
extraDirs: [
{ dir: "../node_modules/typescript/lib/", nameOnly: true },
],
}).run();
11 changes: 11 additions & 0 deletions TypeScript/build/postbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");
const path = require("path");

console.log("Creating importable source string")
const bundlePath = path.join(__dirname, "..", "dist", "typescript-compile-test.js");
const srcOutPath = path.join(__dirname, "..", "dist", "typescript-compile-test.src.js");

const bundleContent = fs.readFileSync(bundlePath, "utf8");
const srcContent = `REACT_RENDER_TEST_SRC = ${JSON.stringify(bundleContent)};`;
fs.writeFileSync(srcOutPath, srcContent);
console.log(`Successfully created ${srcOutPath}`);
7 changes: 7 additions & 0 deletions TypeScript/dist/typescript-compile-test.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions TypeScript/dist/typescript-compile-test.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions TypeScript/dist/typescript-compile-test.src.js

Large diffs are not rendered by default.

Loading
Loading