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

refactor(betterer 🔧): add .js extensions to imports #1166

Merged
merged 2 commits into from
Jul 17, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 23 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,41 @@ const BASE_EXTENDS = [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended'
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:eslint-comments/recommended',
'plugin:require-extensions/recommended'
];

const BASE_RULES = {
'eol-last': [2, 'always'],
'@typescript-eslint/return-await': [2, 'always']
'eol-last': ['error', 'always'],
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', disallowTypeAnnotations: false }],
'eslint-comments/require-description': ['error', { ignore: ['eslint-enable'] }],
'import/no-unresolved': 'off'
};

const OVERRIDE_RULES = {
...BASE_RULES,
'no-console': 2,
'@typescript-eslint/unbound-method': 0,
'@typescript-eslint/no-use-before-define': [2, { functions: false }],
'@typescript-eslint/member-ordering': 2,
'@typescript-eslint/consistent-type-imports': [2, { prefer: 'type-imports', disallowTypeAnnotations: false }]
'no-console': 'error',
'@typescript-eslint/unbound-method': 'off'
};

module.exports = {
env: {
es6: true,
es2021: true,
node: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
ecmaVersion: 2021,
project: path.resolve(__dirname, './tsconfig.eslint.json'),
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'require-extensions'],
rules: {
...BASE_RULES
},
Expand All @@ -57,5 +63,10 @@ module.exports = {
browser: true
}
}
]
],
settings: {
'import/resolver': {
typescript: true
}
}
};
2 changes: 1 addition & 1 deletion .github/workflows/build-extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [16.x]
operating-system: [macOS-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x]
operating-system: [windows-latest, macOS-latest, ubuntu-latest]

steps:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"GOLDENS",
"hasher",
"initialise",
"initialised",
"Initialising",
"Lifecycles",
"loglevel",
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"prepare": "ngcc && husky install"
},
"engines": {
"node": ">=12"
"node": ">=16"
},
"types": "test/betterer-public-api.d.ts",
"devDependencies": {
Expand All @@ -68,6 +68,10 @@
"dependency-check": "^4.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-require-extensions": "^0.1.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* @packageDocumentation
*/

export { angular } from './angular';
export { angular } from './angular.js';
12 changes: 6 additions & 6 deletions packages/betterer/src/betterer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import type {
BettererOptionsResults,
BettererOptionsWatch,
BettererOptionsMerge
} from './config';
import type { BettererRunner } from './runner';
import type { BettererResultsSummary } from './results';
import type { BettererSuiteSummary } from './suite';
} from './config/index.js';
import type { BettererRunner } from './runner/index.js';
import type { BettererResultsSummary } from './results/index.js';
import type { BettererSuiteSummary } from './suite/index.js';

import { BettererRunnerΩ } from './runner';
import { BettererMergerΩ, BettererResultsSummaryΩ } from './results';
import { BettererRunnerΩ } from './runner/index.js';
import { BettererMergerΩ, BettererResultsSummaryΩ } from './results/index.js';

/**
* @public Run **Betterer** with the given options.
Expand Down
22 changes: 11 additions & 11 deletions packages/betterer/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BettererVersionControlWorker } from '../fs';
import type { BettererReporter } from '../reporters';
import type { BettererVersionControlWorker } from '../fs/index.js';
import type { BettererReporter } from '../reporters/index.js';
import type {
BettererConfig,
BettererConfigBase,
Expand All @@ -12,17 +12,17 @@ import type {
BettererOptionsStart,
BettererOptionsWatch,
BettererWorkerRunConfig
} from './types';
} from './types.js';

import { BettererError } from '@betterer/errors';
import assert from 'assert';
import * as os from 'os';
import * as path from 'path';

import { read } from '../fs';
import { registerExtensions } from './register';
import { loadReporters, loadSilentReporter } from '../reporters';
import { isBoolean, isNumber, isRegExp, isString, isUndefined } from '../utils';
import assert from 'node:assert';
import os from 'node:os';
import path from 'node:path';

import { read } from '../fs/index.js';
import { registerExtensions } from './register.js';
import { loadReporters, loadSilentReporter } from '../reporters/index.js';
import { isBoolean, isNumber, isRegExp, isString, isUndefined } from '../utils.js';

const TOTAL_CPUS = os.cpus().length;

Expand Down
4 changes: 2 additions & 2 deletions packages/betterer/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { createConfig, createMergeConfig, createWorkerConfig, overrideConfig } from './config';
export { createConfig, createMergeConfig, createWorkerConfig, overrideConfig } from './config.js';
export {
BettererConfig,
BettererConfigBase,
Expand Down Expand Up @@ -30,4 +30,4 @@ export {
BettererOptionsStart,
BettererOptionsWatch,
BettererWorkerRunConfig
} from './types';
} from './types.js';
2 changes: 1 addition & 1 deletion packages/betterer/src/config/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ export {
BettererOptionsStartUpdate,
BettererOptionsStart,
BettererOptionsWatch
} from './types';
} from './types.js';
2 changes: 1 addition & 1 deletion packages/betterer/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BettererReporter } from '../reporters';
import type { BettererReporter } from '../reporters/index.js';

/**
* @public An array of {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | Regular Expressions }
Expand Down
6 changes: 3 additions & 3 deletions packages/betterer/src/context/context-summary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BettererConfig } from '../config';
import type { BettererSuiteSummariesΩ, BettererSuiteSummaryΩ } from '../suite';
import type { BettererContextSummary } from './types';
import type { BettererConfig } from '../config/index.js';
import type { BettererSuiteSummariesΩ, BettererSuiteSummaryΩ } from '../suite/index.js';
import type { BettererContextSummary } from './types.js';

export class BettererContextSummaryΩ implements BettererContextSummary {
constructor(public readonly config: BettererConfig, public readonly suites: BettererSuiteSummariesΩ) {}
Expand Down
32 changes: 16 additions & 16 deletions packages/betterer/src/context/context.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import type { BettererError } from '@betterer/errors';
import type { FSWatcher } from 'chokidar';

import type { BettererConfig, BettererOptionsOverride } from '../config';
import type { BettererFilePaths, BettererVersionControlWorker } from '../fs';
import type { BettererReporterΩ } from '../reporters';
import type { BettererResultsFileΩ } from '../results';
import type { BettererSuiteSummariesΩ, BettererSuiteSummary } from '../suite';
import type { BettererGlobals } from '../types';
import type { BettererContext, BettererContextStarted, BettererContextSummary } from './types';

import { overrideConfig } from '../config';
import { BettererFileResolverΩ } from '../fs';
import { BettererRunWorkerPoolΩ, BettererRunΩ, createWorkerRunConfig } from '../run';
import { BettererSuiteΩ } from '../suite';
import { loadTestMeta } from '../test';
import { defer } from '../utils';
import { BettererContextSummaryΩ } from './context-summary';
import type { BettererConfig, BettererOptionsOverride } from '../config/index.js';
import type { BettererFilePaths, BettererVersionControlWorker } from '../fs/index.js';
import type { BettererReporterΩ } from '../reporters/index.js';
import type { BettererResultsFileΩ } from '../results/index.js';
import type { BettererSuiteSummariesΩ, BettererSuiteSummary } from '../suite/index.js';
import type { BettererGlobals } from '../types.js';
import type { BettererContext, BettererContextStarted, BettererContextSummary } from './types.js';

import { overrideConfig } from '../config/index.js';
import { BettererFileResolverΩ } from '../fs/index.js';
import { BettererRunWorkerPoolΩ, BettererRunΩ, createWorkerRunConfig } from '../run/index.js';
import { BettererSuiteΩ } from '../suite/index.js';
import { loadTestMeta } from '../test/index.js';
import { defer } from '../utils.js';
import { BettererContextSummaryΩ } from './context-summary.js';

export class BettererContextΩ implements BettererContext {
public readonly config: BettererConfig;
Expand Down Expand Up @@ -51,7 +51,7 @@ export class BettererContextΩ implements BettererContext {
// Start everything again, and trigger a new reporter:
this._started = this._start();

// eslint-disable-next-line @typescript-eslint/no-misused-promises
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- SIGTERM doesn't care about Promises
process.on('SIGTERM', () => this.stop());
}

Expand Down
4 changes: 2 additions & 2 deletions packages/betterer/src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { BettererContextΩ } from './context';
export { BettererContext, BettererContextSummary } from './types';
export { BettererContextΩ } from './context.js';
export { BettererContext, BettererContextSummary } from './types.js';
2 changes: 1 addition & 1 deletion packages/betterer/src/context/public.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { BettererContext, BettererContextSummary } from './types';
export { BettererContext, BettererContextSummary } from './types.js';
4 changes: 2 additions & 2 deletions packages/betterer/src/context/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BettererError } from '@betterer/errors';

import type { BettererConfig, BettererOptionsOverride } from '../config';
import type { BettererSuiteSummaries, BettererSuiteSummary } from '../suite';
import type { BettererConfig, BettererOptionsOverride } from '../config/index.js';
import type { BettererSuiteSummaries, BettererSuiteSummary } from '../suite/index.js';

/**
* @public The context of a set of test suite runs.
Expand Down
12 changes: 6 additions & 6 deletions packages/betterer/src/fs/file-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type {
BettererFileCache,
BettererFileHashMap,
BettererCacheFile
} from './types';
} from './types.js';

import assert from 'assert';
import path from 'path';
import { normalisedPath } from '../utils';
import { read } from './reader';
import { write } from './writer';
import assert from 'node:assert';
import path from 'node:path';
import { normalisedPath } from '../utils.js';
import { read } from './reader.js';
import { write } from './writer.js';

const BETTERER_CACHE_VERSION = 2;

Expand Down
8 changes: 4 additions & 4 deletions packages/betterer/src/fs/file-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type {
BettererFilePatterns,
BettererFileResolver,
BettererVersionControlWorker
} from './types';
} from './types.js';

import assert from 'assert';
import assert from 'node:assert';
import minimatch from 'minimatch';
import * as path from 'path';
import path from 'node:path';

import { flatten, normalisedPath } from '../utils';
import { flatten, normalisedPath } from '../utils.js';

export class BettererFileResolverΩ implements BettererFileResolver {
private _excluded: Array<RegExp> = [];
Expand Down
20 changes: 10 additions & 10 deletions packages/betterer/src/fs/git.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { SimpleGit } from 'simple-git';

import type { BettererFilePaths, BettererVersionControl } from './types';
import type { BettererFilePaths, BettererVersionControl } from './types.js';

import { BettererError } from '@betterer/errors';
import assert from 'assert';
import { promises as fs } from 'fs';
import path from 'path';
import simpleGit from 'simple-git';

import { createHash } from '../hasher';
import { normalisedPath } from '../utils';
import { BettererFileCacheΩ } from './file-cache';
import { read } from './reader';
import assert from 'node:assert';
import { promises as fs } from 'node:fs';
import path from 'node:path';
import { simpleGit } from 'simple-git';

import { createHash } from '../hasher.js';
import { normalisedPath } from '../utils.js';
import { BettererFileCacheΩ } from './file-cache.js';
import { read } from './reader.js';

export class BettererGitΩ implements BettererVersionControl {
private _cache: BettererFileCacheΩ | null = null;
Expand Down
10 changes: 5 additions & 5 deletions packages/betterer/src/fs/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { BettererFileResolverΩ } from './file-resolver';
export { read } from './reader';
export { BettererFileResolverΩ } from './file-resolver.js';
export { read } from './reader.js';
export {
BettererFileGlobs,
BettererFilePaths,
BettererFilePatterns,
BettererFileResolver,
BettererVersionControlWorker
} from './types';
export { createVersionControl } from './version-control';
export { forceRelativePaths, write } from './writer';
} from './types.js';
export { createVersionControl } from './version-control.js';
export { forceRelativePaths, write } from './writer.js';
2 changes: 1 addition & 1 deletion packages/betterer/src/fs/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export {
BettererFilePaths,
BettererFilePatterns,
BettererFileResolver
} from './types';
} from './types.js';
4 changes: 2 additions & 2 deletions packages/betterer/src/fs/reader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promises as fs } from 'fs';
import { promises as fs } from 'node:fs';

import { normaliseNewlines } from '../utils';
import { normaliseNewlines } from '../utils.js';

const READ_CACHE: Record<string, string> = {};
const READ_CACHE_TIME: Record<string, number> = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/betterer/src/fs/version-control-worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { BettererGitΩ } from './git';
import { BettererGitΩ } from './git.js';

export const versionControl = new BettererGitΩ();
2 changes: 1 addition & 1 deletion packages/betterer/src/fs/version-control.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BettererVersionControlWorker, BettererVersionControlWorkerModule } from './types';
import type { BettererVersionControlWorker, BettererVersionControlWorkerModule } from './types.js';

import { workerRequire } from '@phenomnomnominal/worker-require';

Expand Down
6 changes: 3 additions & 3 deletions packages/betterer/src/fs/writer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BettererError } from '@betterer/errors';
import path from 'path';
import { promises as fs } from 'fs';
import path from 'node:path';
import { promises as fs } from 'node:fs';

import { normalisedPath } from '../utils';
import { normalisedPath } from '../utils.js';

export function forceRelativePaths(toWrite: string, basePath: string): string {
const directory = `${normalisedPath(path.dirname(basePath))}/`;
Expand Down
Loading