Skip to content
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

Remove superficial ESLint config #3589

Merged
merged 2 commits into from
May 15, 2022
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
7 changes: 0 additions & 7 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,3 @@ overrides:
# Ignore docusarus related webpack aliases
import/no-unresolved:
['error', { 'ignore': ['^@theme', '^@docusaurus', '^@generated'] }]
- files:
- website/docusaurus.config.js
- website/sidebars.js
- integrationTests/**/*
- resources/**/*
env:
node: true
60 changes: 31 additions & 29 deletions resources/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ const maxTime = 5;
// The minimum sample size required to perform statistical analysis.
const minSamples = 5;

// Get the revisions and make things happen!
if (require.main === module) {
async function runBenchmarks() {
// Get the revisions and make things happen!
const { benchmarks, revisions } = getArguments(process.argv.slice(2));
const benchmarkProjects = prepareBenchmarkProjects(revisions);

runBenchmarks(benchmarks, benchmarkProjects).catch((error) => {
console.error(error);
process.exit(1);
});
for (const benchmark of benchmarks) {
await runBenchmark(benchmark, benchmarkProjects);
}
}

function localDir(...paths: ReadonlyArray<string>) {
Expand Down Expand Up @@ -266,35 +265,33 @@ function maxBy<T>(array: ReadonlyArray<T>, fn: (obj: T) => number) {
}

// Prepare all revisions and run benchmarks matching a pattern against them.
async function runBenchmarks(
benchmarks: ReadonlyArray<string>,
async function runBenchmark(
benchmark: string,
benchmarkProjects: ReadonlyArray<BenchmarkProject>,
) {
for (const benchmark of benchmarks) {
const results = [];
for (let i = 0; i < benchmarkProjects.length; ++i) {
const { revision, projectPath } = benchmarkProjects[i];
const modulePath = path.join(projectPath, benchmark);

if (i === 0) {
const { name } = await sampleModule(modulePath);
console.log('⏱ ' + name);
}
const results = [];
for (let i = 0; i < benchmarkProjects.length; ++i) {
const { revision, projectPath } = benchmarkProjects[i];
const modulePath = path.join(projectPath, benchmark);

if (i === 0) {
const { name } = await sampleModule(modulePath);
console.log('⏱ ' + name);
}

try {
const samples = await collectSamples(modulePath);
try {
const samples = await collectSamples(modulePath);

results.push(computeStats(revision, samples));
process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
} catch (error) {
console.log(' ' + revision + ': ' + red(String(error)));
}
results.push(computeStats(revision, samples));
process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
} catch (error) {
console.log(' ' + revision + ': ' + red(String(error)));
}
console.log('\n');

beautifyBenchmark(results);
console.log('');
}
console.log('\n');

beautifyBenchmark(results);
console.log('');
}

function getArguments(argv: ReadonlyArray<string>) {
Expand Down Expand Up @@ -422,3 +419,8 @@ function sampleModule(modulePath: string): Promise<BenchmarkSample> {
});
});
}

runBenchmarks().catch((error) => {
console.error(error);
process.exit(1);
});
66 changes: 32 additions & 34 deletions resources/build-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,38 @@ import { addExtensionToImportPaths } from './add-extension-to-import-paths';
import { inlineInvariant } from './inline-invariant';
import { readdirRecursive, showDirStats, writeGeneratedFile } from './utils';

if (require.main === module) {
fs.rmSync('./denoDist', { recursive: true, force: true });
fs.mkdirSync('./denoDist');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
for (const filepath of srcFiles) {
if (filepath.endsWith('.ts')) {
const srcPath = path.join('./src', filepath);

const sourceFile = ts.createSourceFile(
srcPath,
fs.readFileSync(srcPath, 'utf-8'),
ts.ScriptTarget.Latest,
);

const transformed = ts.transform(sourceFile, [
addExtensionToImportPaths({ extension: '.ts' }),
inlineInvariant,
]);
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
const newContent = printer.printBundle(
ts.createBundle(transformed.transformed),
);

transformed.dispose();

const destPath = path.join('./denoDist', filepath);
fs.mkdirSync(path.dirname(destPath), { recursive: true });
writeGeneratedFile(destPath, newContent);
}
fs.rmSync('./denoDist', { recursive: true, force: true });
fs.mkdirSync('./denoDist');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
for (const filepath of srcFiles) {
if (filepath.endsWith('.ts')) {
const srcPath = path.join('./src', filepath);

const sourceFile = ts.createSourceFile(
srcPath,
fs.readFileSync(srcPath, 'utf-8'),
ts.ScriptTarget.Latest,
);

const transformed = ts.transform(sourceFile, [
addExtensionToImportPaths({ extension: '.ts' }),
inlineInvariant,
]);
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
const newContent = printer.printBundle(
ts.createBundle(transformed.transformed),
);

transformed.dispose();

const destPath = path.join('./denoDist', filepath);
fs.mkdirSync(path.dirname(destPath), { recursive: true });
writeGeneratedFile(destPath, newContent);
}
}

fs.copyFileSync('./LICENSE', './denoDist/LICENSE');
fs.copyFileSync('./README.md', './denoDist/README.md');
fs.copyFileSync('./LICENSE', './denoDist/LICENSE');
fs.copyFileSync('./README.md', './denoDist/README.md');

showDirStats('./denoDist');
}
showDirStats('./denoDist');
146 changes: 76 additions & 70 deletions resources/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,75 @@ import * as ts from 'typescript';

import { addExtensionToImportPaths } from './add-extension-to-import-paths';
import { inlineInvariant } from './inline-invariant';
import { readPackageJSON, showDirStats, writeGeneratedFile } from './utils';

if (require.main === module) {
fs.rmSync('./npmDist', { recursive: true, force: true });
fs.mkdirSync('./npmDist');

const packageJSON = buildPackageJSON();

// Based on https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file
const tsConfig = JSON.parse(
fs.readFileSync(require.resolve('../tsconfig.json'), 'utf-8'),
);
assert(
tsConfig.compilerOptions,
'"tsconfig.json" should have `compilerOptions`',
import {
readdirRecursive,
readPackageJSON,
showDirStats,
writeGeneratedFile,
} from './utils';

fs.rmSync('./npmDist', { recursive: true, force: true });
fs.mkdirSync('./npmDist');

// Based on https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file
const tsConfig = JSON.parse(
fs.readFileSync(require.resolve('../tsconfig.json'), 'utf-8'),
);
assert(
tsConfig.compilerOptions,
'"tsconfig.json" should have `compilerOptions`',
);

const { options: tsOptions, errors: tsOptionsErrors } =
ts.convertCompilerOptionsFromJson(
{
...tsConfig.compilerOptions,
module: 'es2020',
noEmit: false,
declaration: true,
declarationDir: './npmDist',
outDir: './npmDist',
},
process.cwd(),
);

const { options: tsOptions, errors: tsOptionsErrors } =
ts.convertCompilerOptionsFromJson(
{
...tsConfig.compilerOptions,
module: 'es2020',
noEmit: false,
declaration: true,
declarationDir: './npmDist',
outDir: './npmDist',
},
process.cwd(),
);

assert(
tsOptionsErrors.length === 0,
'Fail to parse options: ' + tsOptionsErrors,
);
assert(
tsOptionsErrors.length === 0,
'Fail to parse options: ' + tsOptionsErrors,
);

const tsHost = ts.createCompilerHost(tsOptions);
tsHost.writeFile = (filepath, body) => {
fs.mkdirSync(path.dirname(filepath), { recursive: true });
writeGeneratedFile(filepath, body);
};

const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {
after: [addExtensionToImportPaths({ extension: '.js' }), inlineInvariant],
});
assert(
!tsResult.emitSkipped,
'Fail to generate `*.d.ts` files, please run `npm run check`',
);

fs.copyFileSync('./LICENSE', './npmDist/LICENSE');
fs.copyFileSync('./README.md', './npmDist/README.md');

// Should be done as the last step so only valid packages can be published
writeGeneratedFile(
'./npmDist/package.json',
JSON.stringify(buildPackageJSON()),
);

showDirStats('./npmDist');

const tsHost = ts.createCompilerHost(tsOptions);
tsHost.writeFile = (filepath, body) => {
if (path.basename(filepath) === 'index.js') {
const relative = './' + path.relative('./npmDist', filepath);
const key = relative.replace(/\/?index.js$/, '');
packageJSON.exports[key] = relative;
}

fs.mkdirSync(path.dirname(filepath), { recursive: true });
writeGeneratedFile(filepath, body);
};
function buildPackageJSON() {
const packageJSON = readPackageJSON();

const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {
after: [addExtensionToImportPaths({ extension: '.js' }), inlineInvariant],
});
assert(
!tsResult.emitSkipped,
'Fail to generate `*.d.ts` files, please run `npm run check`',
);
delete packageJSON.private;
delete packageJSON.scripts;
delete packageJSON.devDependencies;

assert(packageJSON.types === undefined, 'Unexpected "types" in package.json');
const supportedTSVersions = Object.keys(packageJSON.typesVersions);
Expand All @@ -75,33 +89,25 @@ if (require.main === module) {
// Provoke syntax error to show this message
`"Package 'graphql' support only TS versions that are ${supportedTSVersions[0]}".`,
);

packageJSON.typesVersions = {
...packageJSON.typesVersions,
'*': { '*': [notSupportedTSVersionFile] },
};

fs.copyFileSync('./LICENSE', './npmDist/LICENSE');
fs.copyFileSync('./README.md', './npmDist/README.md');

// Should be done as the last step so only valid packages can be published
writeGeneratedFile('./npmDist/package.json', JSON.stringify(packageJSON));

showDirStats('./npmDist');
}

function buildPackageJSON() {
const packageJSON = readPackageJSON();
packageJSON.type = 'module';
packageJSON.exports = {};

delete packageJSON.private;
delete packageJSON.scripts;
delete packageJSON.devDependencies;
for (const filepath of readdirRecursive('./src', { ignoreDir: /^__.*__$/ })) {
if (path.basename(filepath) === 'index.ts') {
const key = path.dirname(filepath);
packageJSON.exports[key] = filepath.replace(/\.ts$/, '.js');
}
}

packageJSON.type = 'module';
// Temporary workaround to allow "internal" imports, no grantees provided
packageJSON.exports = {
'./*.js': './*.js',
'./*': './*.js',
};
packageJSON.exports['./*.js'] = './*.js';
packageJSON.exports['./*'] = './*.js';

// TODO: move to integration tests
const publishTag = packageJSON.publishConfig?.tag;
Expand Down
4 changes: 1 addition & 3 deletions resources/gen-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ export const versionInfo = Object.freeze({
});
`;

if (require.main === module) {
writeGeneratedFile('./src/version.ts', body);
}
writeGeneratedFile('./src/version.ts', body);