Skip to content

Commit

Permalink
chore: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
VicGUTT committed Nov 27, 2022
1 parent 6e99198 commit b62be07
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 18 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"@vitest/coverage-c8": "^0.25.3",
"c8": "^7.12.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
1 change: 0 additions & 1 deletion src/isSizey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type { Sizey } from './types';
* isSizey({size: 0}); // true
* ```
*/

export default function isSizey<T>(value: unknown): value is Sizey<T> {
try {
// @ts-expect-error C'mon, it's in a try/catch block
Expand Down
2 changes: 2 additions & 0 deletions src/isTypedAs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ export default function isTypedAs(value: unknown): TypedAs {
/**
* We should never get here.
*/
/* c8 ignore start */
throw IsBaseException.unknown();
/* c8 ignore end */
}
12 changes: 6 additions & 6 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export type Numeric = number | string;
export type UnknownObject = Record<string | number | symbol, unknown>;
export type Primitive = null | undefined | boolean | number | string | symbol | bigint;
export type Derivative<T> = Exclude<T, Primitive>;
export type Lengthy<T extends {} = {}> = T & { length: number };
export type Sizey<T extends {} = {}> = T & { size: number };
export type Iterable<T extends {} = {}> = T & { [Symbol.iterator]: Object };
export type Lengthy<T = unknown> = T & { length: number };
export type Sizey<T = unknown> = T & { size: number };
export type Iterable<T = unknown> = T & { [Symbol.iterator]: Object };

export interface AsyncFunction extends Function {
new (...args: string[]): Promise<any>;
Expand All @@ -75,10 +75,10 @@ export interface AsyncFunction extends Function {
*--------------------------------------------------------------------------
*/

export type UnknownConstructor<T extends {} = {}> = new (...args: any[]) => T;
export type UnknownConstructorFunction<T extends {} = {}> = (...args: any[]) => T;
export type UnknownConstructor<T = unknown> = new (...args: any[]) => T;
export type UnknownConstructorFunction<T = unknown> = (...args: any[]) => T;
export type ConstructorLike<T = unknown> = { readonly prototype: T };
export type Constructor<T extends {} = {}> = ConstructorLike & (UnknownConstructor<T> | UnknownConstructorFunction<T>);
export type Constructor<T = unknown> = ConstructorLike & (UnknownConstructor<T> | UnknownConstructorFunction<T>);

// Alterative ?
// - export type Constructor<T = object, A extends any[] = any[], Static = {}> = (new (...a: A) => T) & Static (https://github.com/trusktr/lowclass/blob/b5c526aa800e64cd20443a95faf2bf0dc31aec41/src/utils.ts#L129)
Expand Down
45 changes: 34 additions & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import fs from 'fs';
import path from 'path';
import jsdoc2md from 'jsdoc-to-markdown';
import { exec } from 'child_process';
import { exec, type ExecException } from 'child_process';
import { defineConfig } from 'vite';

const lib = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const libName = lib.name.split('/')[1] ?? lib.name;
const year = new Date().getFullYear();

export default defineConfig({
/**
* @see https://vitejs.dev/config/shared-options.html#define
*/
define: {
__APP_VERSION__: lib.version,
},
// /**
// * @see https://vitejs.dev/config/shared-options.html#define
// */
// define: {
// __APP_VERSION__: lib.version,
// },
build: {
/**
* @see https://vitejs.dev/config/#build-target
Expand Down Expand Up @@ -72,6 +72,7 @@ export default defineConfig({
coverage: {
reportsDirectory: '.coverage',
include: ['src/**/*.{ts,js}'],
exclude: ['src/Exceptions/**/*.{ts,js}'],
// Threshold
statements: 90,
branches: 90,
Expand Down Expand Up @@ -111,6 +112,26 @@ async function compileAllTsFiles() {
fs.readFileSync(paths.VERSION, 'utf-8').replace("'__APP_VERSION__'", `'${lib.version}'`)
);
}

/**
* Fallback for: https://vitejs.dev/config/shared-options.html#define,
* because for some reason it causes the tests to error out.
*/

['./dist/_isjs.es.js', './dist/_isjs.umd.cjs'].forEach(path => {
if (!fs.existsSync(path)) {
return;
}

consoleMessage(
`Replacing \`__APP_VERSION__\` with the app's version (${lib.version}) in \`${path}\`...`
);

fs.writeFileSync(
path,
fs.readFileSync(path, 'utf-8').replace('"__APP_VERSION__"', `"${lib.version}"`)
);
});
}

async function generateReadme() {
Expand Down Expand Up @@ -187,21 +208,23 @@ async function generateReadme() {
/* Helpers
------------------------------------------------*/

async function execAsync(command, callback) {
async function execAsync(
command: string,
callback?: (error: ExecException | null, stdout: string, stderr: string) => void
) {
return await new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
try {
return error ? reject(error, stdout, stderr) : resolve(callback && callback(error, stdout, stderr));
return error ? reject({ error, stdout, stderr }) : resolve(callback && callback(error, stdout, stderr));
} catch (e) {
return reject(e);
}
});
});
}

function consoleMessage(message) {
function consoleMessage(message: string): void {
process.stdout.write('\n');

console.log(message);
}

0 comments on commit b62be07

Please sign in to comment.