Use function wrapper replacements by default.

This commit is contained in:
Robin Heggelund Hansen 2021-08-20 10:14:46 +02:00
parent 27871e4e7c
commit b76f3718b3
3 changed files with 37 additions and 29 deletions

27
src/fs_util.ts Normal file
View File

@ -0,0 +1,27 @@
import * as fs from 'fs';
import * as path from 'path';
export function readFilesSync(dir: string): {[key: string]: string} | null {
let foundAnything = false
const files: {[key: string]: string} = {};
fs.readdirSync(dir).forEach(filename => {
const name = path.parse(filename).name;
const filepath = path.resolve(dir, filename);
const stat = fs.statSync(filepath);
const isFile = stat.isFile();
if (isFile) {
const content = fs.readFileSync(path.join(dir, filename))
files[name] = content.toString()
foundAnything = true
}
});
if (foundAnything) {
return files;
} else {
return null
}
}

View File

@ -10,6 +10,7 @@ const { version } = require('../package.json');
import * as BenchInit from './benchmark/init'
import * as Benchmark from './benchmark/benchmark';
import * as Reporting from './benchmark/reporting';
import { readFilesSync } from './fs_util';
program
.version(version)
@ -38,8 +39,12 @@ async function run(inputFilePath: string | undefined) {
const replacementDir = hasReplacements(process.argv)
let replacements = null
if (replacementDir){
if (replacementDir) {
replacements = readFilesSync(replacementDir)
} else if (program.benchmark) {
replacements = benchmarkDefaults.replacements;
} else {
replacements = toolDefaults.replacements;
}
if (program.initBenchmark) {
@ -147,30 +152,4 @@ function hasReplacements(args: string[]){
return dir
}
function readFilesSync(dir: string): {[key: string]: string} | null {
let foundAnything = false
const files: {[key: string]: string} = {};
fs.readdirSync(dir).forEach(filename => {
const name = path.parse(filename).name;
const ext = path.parse(filename).ext;
const filepath = path.resolve(dir, filename);
const stat = fs.statSync(filepath);
const isFile = stat.isFile();
if (isFile) {
const content = fs.readFileSync(path.join(dir, filename))
files[name] = content.toString()
foundAnything = true
}
});
if (foundAnything) {
return files;
} else {
return null
}
}
run(program.args[0]).catch((e) => console.error(e));

View File

@ -1,3 +1,5 @@
import { readFilesSync } from './fs_util';
export enum Mode {
Prod = 'prod',
Dev = 'dev',
@ -87,7 +89,7 @@ export const toolDefaults: Transforms = {
replaceStringFunctions: false,
recordUpdates: false,
v8Analysis: false,
replacements: null
replacements: readFilesSync(__dirname + '/replacements/faster-function-wrappers')
};
@ -107,5 +109,5 @@ export const benchmarkDefaults: Transforms = {
replaceStringFunctions: true,
recordUpdates: false,
v8Analysis: true,
replacements: null
replacements: readFilesSync(__dirname + '/replacements/faster-function-wrappers')
};