ci: fix typechecking in ci

This commit is contained in:
iCrawl 2022-08-15 00:42:33 +02:00
parent cb856860b7
commit c052f56f3e
No known key found for this signature in database
GPG key ID: 1AB888B16355FBB2
30 changed files with 887 additions and 1023 deletions

View file

@ -72,10 +72,12 @@ jobs:
cache: 'yarn'
- name: Install dependencies
run: yarn workspaces focus ${{ matrix.package }}
run: yarn install --immutable
- name: Build dependencies
run: yarn workspace ${{ matrix.package }} build
run: |
yarn workspace @discordjs/docgen build
yarn workspaces foreach --parallel --topological --recursive --from ${{ matrix.package }} build
- name: ESLint
run: yarn workspace ${{ matrix.package }} lint

View file

@ -1,5 +1,5 @@
{
"*": "prettier --ignore-unknown --write",
"{src/**,__tests__/**}.{mjs,js,ts}": "eslint --ext mjs,js,ts --fix",
"src/**.ts": "vitest related"
"src/**.ts": "vitest related --run"
}

View file

@ -1,5 +1,6 @@
import { relative, resolve } from 'node:path';
import glob from 'fast-glob';
import isCi from 'is-ci';
import typescript from 'rollup-plugin-typescript2';
import { defineBuildConfig, BuildEntry } from 'unbuild';
@ -26,7 +27,7 @@ export function createUnbuildConfig({
preserveModules = true,
preserveModulesRoot = 'src',
declaration = true,
typeCheck = false,
typeCheck = isCi,
}: Partial<ConfigOptions> = {}) {
const files = glob
.sync('**', { cwd: 'src' })
@ -45,6 +46,7 @@ export function createUnbuildConfig({
cjsBridge,
json: {
namedExports: false,
preferConst: true,
},
},

View file

@ -41,6 +41,7 @@
"@commitlint/config-angular": "^17.0.3",
"@favware/cliff-jumper": "^1.8.6",
"@favware/npm-deprecate": "^1.0.5",
"@types/is-ci": "^3.0.0",
"conventional-changelog-cli": "^2.2.2",
"fast-glob": "^3.2.11",
"husky": "^8.0.1",

View file

@ -43,7 +43,7 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"c8": "^7.12.0",
@ -55,7 +55,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -64,7 +64,7 @@
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.6",
"@microsoft/api-extractor": "^7.29.2",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"c8": "^7.12.0",
@ -77,7 +77,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -53,7 +53,7 @@
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.6",
"@microsoft/api-extractor": "^7.29.2",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"c8": "^7.12.0",
@ -66,7 +66,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -64,7 +64,7 @@
"devDependencies": {
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.6",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"dtslint": "^4.2.1",
"eslint": "^8.22.0",
"jest": "^28.1.3",

View file

@ -1,3 +1,9 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig({ minify: true, externals: ['package.cjs', 'package.mjs'] });
export default createUnbuildConfig({
entries: [
{ builder: 'rollup', input: 'src/index' },
{ builder: 'rollup', input: 'src/cli' },
],
minify: true,
});

View file

@ -11,7 +11,7 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/docgen/*'",
"release": "cliff-jumper"
},
"bin": "./dist/index.cjs",
"bin": "./dist/cli.cjs",
"directories": {
"lib": "src"
},

View file

@ -0,0 +1,25 @@
#!/usr/bin/env node
import { createCommand } from 'commander';
import { build } from './index.js';
import packageFile from '../package.json';
export interface CLIOptions {
input: string[];
custom: string;
root: string;
output: string;
typescript: boolean;
}
const command = createCommand()
.version(packageFile.version)
.option('-i, --input <string...>', 'Source directories to parse JSDocs in')
.option('-c, --custom <string>', 'Custom docs definition file to use')
.option('-r, --root [string]', 'Root directory of the project', '.')
.option('-o, --output <string>', 'Path to output file')
.option('--typescript', '', false);
const program = command.parse(process.argv);
const options = program.opts<CLIOptions>();
build(options);

View file

@ -1,20 +1,10 @@
#!/usr/bin/env node
import { readFileSync, writeFileSync } from 'node:fs';
import { join, basename, extname, dirname, relative } from 'node:path';
import { createCommand } from 'commander';
import { dirname, join, extname, basename, relative } from 'node:path';
import jsdoc2md from 'jsdoc-to-markdown';
import { Application, DeclarationReflection, TSConfigReader } from 'typedoc';
import { Documentation } from './documentation.js';
import type { ChildTypes, CustomDocs, RootTypes } from './interfaces/index.js';
import packageFile from '../package.json';
interface CLIOptions {
input: string[];
custom: string;
root: string;
output: string;
typescript: boolean;
}
import { type DeclarationReflection, Application, TSConfigReader } from 'typedoc';
import type { CLIOptions } from './cli';
import { Documentation } from './documentation';
import type { RootTypes, ChildTypes, CustomDocs } from './interfaces';
interface CustomFiles {
id?: string;
@ -27,79 +17,70 @@ interface CustomFiles {
}[];
}
const command = createCommand()
.version(packageFile.version)
.option('-i, --input <string...>', 'Source directories to parse JSDocs in')
.option('-c, --custom <string>', 'Custom docs definition file to use')
.option('-r, --root [string]', 'Root directory of the project', '.')
.option('-o, --output <string>', 'Path to output file')
.option('--typescript', '', false);
const program = command.parse(process.argv);
const options = program.opts<CLIOptions>();
let data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];
if (options.typescript) {
console.log('Parsing Typescript in source files...');
const app = new Application();
app.options.addReader(new TSConfigReader());
app.bootstrap({ entryPoints: options.input });
const project = app.convert();
if (project) {
// @ts-expect-error
data = app.serializer.toObject(project).children!;
console.log(`${data.length} items parsed.`);
}
} else {
console.log('Parsing JSDocs in source files...');
data = jsdoc2md.getTemplateDataSync({ files: options.input }) as (RootTypes & ChildTypes)[];
console.log(`${data.length} JSDoc items parsed.`);
}
const custom: Record<string, CustomDocs> = {};
if (options.custom) {
console.log('Loading custom docs files...');
const customDir = dirname(options.custom);
const file = readFileSync(options.custom, 'utf-8');
const data = JSON.parse(file) as CustomFiles[];
for (const category of data) {
const categoryId = category.id ?? category.name.toLowerCase();
const dir = join(customDir, category.path ?? categoryId);
custom[categoryId] = {
name: category.name || category.id!,
files: {},
};
for (const f of category.files) {
const fileRootPath = join(dir, f.path);
const extension = extname(f.path);
const fileId = f.id ?? basename(f.path, extension);
const fileData = readFileSync(fileRootPath, 'utf-8');
custom[categoryId]!.files[fileId] = {
name: f.name,
type: extension.toLowerCase().replace(/^\./, ''),
content: fileData,
path: relative(options.root, fileRootPath).replace(/\\/g, '/'),
};
export function build({ input, custom: customDocs, root, output, typescript }: CLIOptions) {
let data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];
if (typescript) {
console.log('Parsing Typescript in source files...');
const app = new Application();
app.options.addReader(new TSConfigReader());
app.bootstrap({ entryPoints: input });
const project = app.convert();
if (project) {
// @ts-expect-error
data = app.serializer.toObject(project).children!;
console.log(`${data.length} items parsed.`);
}
} else {
console.log('Parsing JSDocs in source files...');
data = jsdoc2md.getTemplateDataSync({ files: input }) as (RootTypes & ChildTypes)[];
console.log(`${data.length} JSDoc items parsed.`);
}
const fileCount = Object.keys(custom)
.map((k) => Object.keys(custom[k]!))
.reduce((prev, c) => prev + c.length, 0);
const categoryCount = Object.keys(custom).length;
console.log(
`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +
`${categoryCount} categor${categoryCount === 1 ? 'y' : 'ies'} loaded.`,
);
}
const custom: Record<string, CustomDocs> = {};
if (customDocs) {
console.log('Loading custom docs files...');
const customDir = dirname(customDocs);
const file = readFileSync(customDocs, 'utf-8');
const data = JSON.parse(file) as CustomFiles[];
console.log(`Serializing documentation with format version ${Documentation.FORMAT_VERSION}...`);
const docs = new Documentation(data, options, custom);
for (const category of data) {
const categoryId = category.id ?? category.name.toLowerCase();
const dir = join(customDir, category.path ?? categoryId);
custom[categoryId] = {
name: category.name || category.id!,
files: {},
};
if (options.output) {
console.log(`Writing to ${options.output}...`);
writeFileSync(options.output, JSON.stringify(docs.serialize()));
for (const f of category.files) {
const fileRootPath = join(dir, f.path);
const extension = extname(f.path);
const fileId = f.id ?? basename(f.path, extension);
const fileData = readFileSync(fileRootPath, 'utf-8');
custom[categoryId]!.files[fileId] = {
name: f.name,
type: extension.toLowerCase().replace(/^\./, ''),
content: fileData,
path: relative(root, fileRootPath).replace(/\\/g, '/'),
};
}
}
const fileCount = Object.keys(custom)
.map((k) => Object.keys(custom[k]!))
.reduce((prev, c) => prev + c.length, 0);
const categoryCount = Object.keys(custom).length;
console.log(
`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +
`${categoryCount} categor${categoryCount === 1 ? 'y' : 'ies'} loaded.`,
);
}
console.log(`Serializing documentation with format version ${Documentation.FORMAT_VERSION}...`);
const docs = new Documentation(data, { input, custom: customDocs, root, output, typescript }, custom);
if (output) {
console.log(`Writing to ${output}...`);
writeFileSync(output, JSON.stringify(docs.serialize()));
}
console.log('Done!');
}
console.log('Done!');

View file

@ -1,7 +1,7 @@
import type { Type } from './index.js';
export interface Return {
type: Type;
type: Required<Type>;
nullable?: boolean;
description?: string;
}

View file

@ -1,3 +1,3 @@
export interface Type {
names?: string[];
names?: string[] | undefined;
}

View file

@ -1,7 +1,7 @@
import type { Type } from './index.js';
export interface VarType extends Type {
type?: Required<Type>;
description?: string;
nullable?: boolean;
type?: Required<Type> | undefined;
description?: string | undefined;
nullable?: boolean | undefined;
}

View file

@ -49,7 +49,7 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint": "^8.22.0",
@ -60,7 +60,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4"
"unbuild": "^0.8.8"
},
"engines": {
"node": ">=16.9.0"

View file

@ -62,7 +62,7 @@
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.6",
"@microsoft/api-extractor": "^7.29.2",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
@ -77,7 +77,7 @@
"rollup-plugin-typescript2": "0.32.1",
"supertest": "^6.2.4",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -1,7 +1,4 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"exactOptionalPropertyTypes": false
},
"include": ["src/**/*.ts"]
}

View file

@ -64,7 +64,7 @@
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.6",
"@microsoft/api-extractor": "^7.29.2",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"c8": "^7.12.0",
@ -77,7 +77,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -48,7 +48,7 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"c8": "^7.12.0",
@ -60,7 +60,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -67,7 +67,7 @@
"@favware/cliff-jumper": "^1.8.6",
"@microsoft/api-extractor": "^7.29.2",
"@types/jest": "^28.1.6",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"downlevel-dts": "^0.10.0",
@ -83,7 +83,7 @@
"rollup-plugin-typescript2": "0.32.1",
"tweetnacl": "^1.0.3",
"typescript": "^4.7.4",
"unbuild": "^0.8.4"
"unbuild": "^0.8.8"
},
"engines": {
"node": ">=16.9.0"

View file

@ -53,7 +53,7 @@ export enum VoiceConnectionStatus {
*/
export interface VoiceConnectionSignallingState {
status: VoiceConnectionStatus.Signalling;
subscription?: PlayerSubscription;
subscription?: PlayerSubscription | undefined;
adapter: DiscordGatewayAdapterImplementerMethods;
}
@ -88,7 +88,7 @@ export enum VoiceConnectionDisconnectReason {
*/
export interface VoiceConnectionDisconnectedBaseState {
status: VoiceConnectionStatus.Disconnected;
subscription?: PlayerSubscription;
subscription?: PlayerSubscription | undefined;
adapter: DiscordGatewayAdapterImplementerMethods;
}
@ -128,7 +128,7 @@ export type VoiceConnectionDisconnectedState =
export interface VoiceConnectionConnectingState {
status: VoiceConnectionStatus.Connecting;
networking: Networking;
subscription?: PlayerSubscription;
subscription?: PlayerSubscription | undefined;
adapter: DiscordGatewayAdapterImplementerMethods;
}
@ -139,7 +139,7 @@ export interface VoiceConnectionConnectingState {
export interface VoiceConnectionReadyState {
status: VoiceConnectionStatus.Ready;
networking: Networking;
subscription?: PlayerSubscription;
subscription?: PlayerSubscription | undefined;
adapter: DiscordGatewayAdapterImplementerMethods;
}
@ -688,7 +688,7 @@ export class VoiceConnection extends EventEmitter {
*
* @param subscription - The removed subscription
*/
private onSubscriptionRemoved(subscription: PlayerSubscription) {
protected onSubscriptionRemoved(subscription: PlayerSubscription) {
if (this.state.status !== VoiceConnectionStatus.Destroyed && this.state.subscription === subscription) {
this.state = {
...this.state,

View file

@ -13,6 +13,6 @@ export class AudioPlayerError extends Error {
super(error.message);
this.resource = resource;
this.name = error.name;
this.stack = error.stack;
this.stack = error.stack!;
}
}

View file

@ -73,7 +73,7 @@ export class AudioResource<T = unknown> {
/**
* The audio player that the resource is subscribed to, if any.
*/
public audioPlayer?: AudioPlayer;
public audioPlayer?: AudioPlayer | undefined;
/**
* The playback duration of this audio resource, given in milliseconds.

View file

@ -10,7 +10,7 @@ export interface CreateVoiceConnectionOptions {
* If true, debug messages will be enabled for the voice connection and its
* related components. Defaults to false.
*/
debug?: boolean;
debug?: boolean | undefined;
adapterCreator: DiscordGatewayAdapterCreator;
}

View file

@ -81,7 +81,7 @@ export interface NetworkingReadyState {
udp: VoiceUDPSocket;
connectionOptions: ConnectionOptions;
connectionData: ConnectionData;
preparedPacket?: Buffer;
preparedPacket?: Buffer | undefined;
}
/**
@ -94,7 +94,7 @@ export interface NetworkingResumingState {
udp: VoiceUDPSocket;
connectionOptions: ConnectionOptions;
connectionData: ConnectionData;
preparedPacket?: Buffer;
preparedPacket?: Buffer | undefined;
}
/**

View file

@ -1,7 +1,4 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"exactOptionalPropertyTypes": false
},
"include": ["src/**/*.ts"]
}

View file

@ -51,8 +51,8 @@
"@microsoft/tsdoc": "0.14.1",
"@microsoft/tsdoc-config": "0.16.1",
"@vscode/codicons": "^0.0.32",
"framer-motion": "^7.0.1",
"next": "^12.2.4",
"framer-motion": "^7.1.0",
"next": "^12.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.4.0",
@ -65,15 +65,15 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^14.4.3",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@types/react-dom": "^18.0.6",
"@types/react-syntax-highlighter": "^15.5.4",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"@unocss/cli": "^0.45.5",
"@unocss/preset-web-fonts": "^0.45.5",
"@unocss/reset": "^0.45.5",
"@vitejs/plugin-react": "^2.0.0",
"@unocss/cli": "^0.45.6",
"@unocss/preset-web-fonts": "^0.45.6",
"@unocss/reset": "^0.45.6",
"@vitejs/plugin-react": "^2.0.1",
"c8": "^7.12.0",
"concurrently": "^7.3.0",
"cypress": "^10.4.0",
@ -88,8 +88,8 @@
"msw": "^0.44.2",
"prettier": "^2.7.1",
"typescript": "^4.7.4",
"unocss": "^0.45.5",
"vercel": "^27.4.0",
"unocss": "^0.45.6",
"vercel": "^28.0.1",
"vitest": "^0.21.1"
},
"engines": {

View file

@ -65,7 +65,7 @@
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.6",
"@microsoft/api-extractor": "^7.29.2",
"@types/node": "^16.11.47",
"@types/node": "^16.11.48",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"c8": "^7.12.0",
@ -78,7 +78,7 @@
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"typescript": "^4.7.4",
"unbuild": "^0.8.4",
"unbuild": "^0.8.8",
"undici": "^5.8.2",
"vitest": "^0.21.1",
"zlib-sync": "^0.1.7"

1619
yarn.lock

File diff suppressed because it is too large Load diff