Skip to content

Commit

Permalink
build(deps-dev): bump @flex-development/tutils from 6.0.0-alpha.10 to…
Browse files Browse the repository at this point in the history
… 6.0.0-alpha.15

Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Aug 6, 2023
1 parent aa7ce00 commit 9bef0cf
Show file tree
Hide file tree
Showing 148 changed files with 1,594 additions and 1,584 deletions.
6 changes: 2 additions & 4 deletions .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const config = {
allowedNames: ['self']
}
],
'@typescript-eslint/no-throw-literal': 2,
'@typescript-eslint/no-throw-literal': 0,
'@typescript-eslint/no-type-alias': 0,
'@typescript-eslint/no-unnecessary-boolean-literal-compare': [
2,
Expand Down Expand Up @@ -661,7 +661,7 @@ const config = {
terms: ['@fixme', '@todo']
}
],
'unicorn/explicit-length-check': 2,
'unicorn/explicit-length-check': 0,
'unicorn/filename-case': [
2,
{
Expand Down Expand Up @@ -858,7 +858,6 @@ const config = {
'promise/valid-params': 0,
'unicorn/consistent-destructuring': 0,
'unicorn/error-message': 0,
'unicorn/explicit-length-check': 0,
'unicorn/no-array-for-each': 0,
'unicorn/no-hex-escape': 0,
'unicorn/no-useless-undefined': 0,
Expand Down Expand Up @@ -997,7 +996,6 @@ const config = {
'@typescript-eslint/no-misused-promises': 0,
'@typescript-eslint/no-mixed-enums': 0,
'@typescript-eslint/no-redundant-type-constituents': 0,
'@typescript-eslint/no-throw-literal': 0,
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 0,
'@typescript-eslint/no-unnecessary-condition': 0,
'@typescript-eslint/no-unnecessary-qualifier': 0,
Expand Down
72 changes: 49 additions & 23 deletions __tests__/reporters/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module tests/reporters/Notifier
*/

import type { OneOrMany } from '@flex-development/tutils'
import { cast, isArray, type OneOrMany } from '@flex-development/tutils'
import notifier from 'node-notifier'
import type NotificationCenter from 'node-notifier/notifiers/notificationcenter'
import { performance } from 'node:perf_hooks'
Expand All @@ -20,22 +20,28 @@ import type { File, Reporter, Task, Test, Vitest } from 'vitest'
*/
class Notifier implements Reporter {
/**
* Test reporter context.
*
* @public
* @member {Vitest} ctx - Test reporter context
* @member {Vitest} ctx
*/
public ctx: Vitest = {} as Vitest
public ctx!: Vitest

/**
* Test run end time (in milliseconds).
*
* @public
* @member {number} end - Test run end time (in milliseconds)
* @member {number} end
*/
public end: number = 0
public end!: number

/**
* Test run start time (in milliseconds).
*
* @public
* @member {number} start - Test run start time (in milliseconds)
* @member {number} start
*/
public start: number = 0
public start!: number

/**
* Sends a notification.
Expand All @@ -52,19 +58,39 @@ class Notifier implements Reporter {
files: File[] = this.ctx.state.getFiles(),
errors: unknown[] = this.ctx.state.getUnhandledErrors()
): Promise<void> {
/** @const {Test[]} tests - Tests run */
/**
* Tests that have been run.
*
* @const {Test[]} tests
*/
const tests: Test[] = this.tests(files)

/** @const {number} fails - Total number of failed tests */
/**
* Total number of failed tests.
*
* @const {number} fails
*/
const fails: number = tests.filter(t => t.result?.state === 'fail').length

/** @const {number} passes - Total number of passed tests */
/**
* Total number of passed tests.
*
* @const {number} passes
*/
const passes: number = tests.filter(t => t.result?.state === 'pass').length

/** @var {string} message - Notification message */
/**
* Notification message.
*
* @var {string} message
*/
let message: string = ''

/** @var {string} title - Notification title */
/**
* Notification title.
*
* @var {string} title
*/
let title: string = ''

// get notification title and message based on number of failed tests
Expand All @@ -76,7 +102,11 @@ class Notifier implements Reporter {

title = '\u274C Failed'
} else {
/** @const {number} time - Time to run all tests (in milliseconds) */
/**
* Time to run all tests (in milliseconds).
*
* @const {number} time
*/
const time: number = this.end - this.start

message = dedent`
Expand Down Expand Up @@ -128,7 +158,7 @@ class Notifier implements Reporter {
*/
public onInit(context: Vitest): void {
this.ctx = context
return void (this.start = performance.now())
return void ((this.start = performance.now()) && (this.end = 0))
}

/**
Expand All @@ -140,17 +170,13 @@ class Notifier implements Reporter {
* @return {Test[]} `Test` object array
*/
protected tests(tasks: OneOrMany<Task> = []): Test[] {
const { mode } = this.ctx

return (Array.isArray(tasks) ? tasks : [tasks]).flatMap(task => {
const { type } = task

return mode === 'typecheck' && type === 'suite' && task.tasks.length === 0
? ([task] as unknown as [Test])
: type === 'test'
return (isArray<Task>(tasks) ? tasks : [tasks]).flatMap(task => {
return task.type === 'custom'
? [cast(task)]
: task.type === 'test'
? [task]
: 'tasks' in task
? task.tasks.flatMap(t => (t.type === 'test' ? [t] : this.tests(t)))
? task.tasks.flatMap(task => this.tests(task))
: []
})
}
Expand Down
88 changes: 53 additions & 35 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,63 @@ import tsconfig from './tsconfig.build.json' assert { type: 'json' }
const config: Config = defineBuildConfig({
charset: 'utf8',
entries: [
{
dts: 'only',
plugins: [
{
name: 'ts-ignore-peers',
setup({ onEnd }: PluginBuild): void {
return void onEnd((result: BuildResult<{ write: false }>): void => {
const { outputFiles } = result

/**
* Regular expression used to insert `// @ts-ignore` above
* property declarations.
*
* @const {RegExp} regex
*/
const regex: RegExp = /\n( +)(.+?\??: )(import\('node-fetch'\).+)/

/**
* Property declaration with `// @ts-ignore` prepended.
*
* @const {string} replacement
*/
const replacement: string =
'\n$1// @ts-ignore peer dependency\n$1$2$3'

return void (result.outputFiles = outputFiles.map(output => ({
...output,
text: output.text.replace(regex, replacement)
})))
})
}
}
]
},
{ dts: 'only' },
{
dts: false,
pattern: ['**/index.ts', 'enums/*', 'internal/*', 'utils/*'],
sourcemap: true,
sourcesContent: false
sourcesContent: true
}
],
plugins: [
{
name: 'ts-ignore-peers',

/**
* Inserts `// @ts-ignore peer dependency` above property declarations
* using types from peer dependencies.
*
* [1]: https://esbuild.github.io/plugins
*
* @see https://github.com/microsoft/TypeScript/issues/38628#issuecomment-1439749496
*
* @param {PluginBuild} build - [esbuild plugin api][1]
* @param {PluginBuild['onEnd']} build.onEnd - Build end callback
* @return {void} Nothing when complete
*/
setup({ onEnd }: PluginBuild): void {
return void onEnd((result: BuildResult<{ write: false }>): void => {
const { outputFiles } = result

/**
* Regular expression used to insert `// @ts-ignore` above
* property declarations.
*
* @see https://regex101.com/r/6r7Cke
*
* @const {RegExp} regex
*/
const regex: RegExp =
/\n( +)(.+?\??: )(\w+<)?(import\('node-fetch'\).+)/g

/**
* Property declaration with `// @ts-ignore` prepended.
*
* @const {string} replacement
*/
const replacement: string =
'\n$1// @ts-ignore peer dependency\n$1$2$3$4'

return void (result.outputFiles = outputFiles.map(output => {
return output.path.endsWith('.d.mts')
? {
...output,
text: output.text.replace(regex, replacement)
}
: output
}))
})
}
}
],
target: [
Expand Down
22 changes: 14 additions & 8 deletions config/changelog.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
type Commit
} from '@flex-development/commitlint-config'
import pathe from '@flex-development/pathe'
import { CompareResult, isNIL } from '@flex-development/tutils'
import {
CompareResult,
at,
includes,
isNIL,
select
} from '@flex-development/tutils'
import addStream from 'add-stream'
import conventionalChangelog from 'conventional-changelog'
import type { Options } from 'conventional-changelog-core'
Expand Down Expand Up @@ -154,7 +160,6 @@ sade('changelog', true)
const changelog: Readable = conventionalChangelog<Commit>(
{
append: false,
debug: debug ? console.debug.bind(console) : undefined,
outputUnreleased:
typeof outputUnreleased === 'boolean'
? outputUnreleased
Expand All @@ -175,6 +180,7 @@ sade('changelog', true)
{ section: ':bug: Fixes', type: Type.FIX },
{ section: ':fire: Performance Improvements', type: Type.PERF },
{ section: ':mechanical_arm: Refactors', type: Type.REFACTOR },
{ hidden: true, type: Type.RELEASE },
{ section: ':wastebasket: Reverts', type: Type.REVERT },
{ hidden: true, type: Type.STYLE },
{ section: ':white_check_mark: Testing', type: Type.TEST },
Expand All @@ -198,10 +204,10 @@ sade('changelog', true)
return void apply(null, {
...commit,
committerDate: dateformat(commit.committerDate, 'yyyy-mm-dd', true),
mentions: commit.mentions.filter(m => m !== 'flexdevelopment'),
mentions: select(commit.mentions, m => m !== 'flexdevelopment'),
// @ts-expect-error ts(2322)
raw: commit,
references: commit.references.filter(ref => ref.action !== null),
references: select(commit.references, ref => ref.action !== null),
version: commit.gitTags ? vgx.exec(commit.gitTags)?.[1] : undefined
})
},
Expand Down Expand Up @@ -296,21 +302,21 @@ sade('changelog', true)
*
* @const {CommitEnhanced?} first_commit
*/
const first_commit: CommitEnhanced | undefined = commits.at(0)
const first_commit: CommitEnhanced | undefined = at(commits, 0)

/**
* Last commit in release.
*
* @const {CommitEnhanced?} last_commit
*/
const last_commit: CommitEnhanced | undefined = commits.at(-1)
const last_commit: CommitEnhanced | undefined = at(commits, -1)

// set current and previous tags
if (key && (!currentTag || !previousTag)) {
currentTag = key.version ?? undefined

// try setting previous tag based on current tag
if (gitSemverTags.includes(currentTag ?? '')) {
if (includes(gitSemverTags, currentTag)) {
const { version = '' } = key
previousTag = gitSemverTags[gitSemverTags.indexOf(version) + 1]
if (!previousTag) previousTag = last_commit?.hash ?? undefined
Expand All @@ -324,7 +330,7 @@ sade('changelog', true)
: !currentTag && version
? pkg.tagPrefix + version
: currentTag ?? version
previousTag = previousTag ?? gitSemverTags[0]
previousTag = previousTag ?? at(gitSemverTags, 0)
}

// set release date
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/composables/use-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import type { Root } from '@flex-development/docast'
import docastParse, { type Options } from '@flex-development/docast-parse'
import { CompareResult } from '@flex-development/tutils'
import pathe, { type ParsedPath } from '@flex-development/pathe'
import { CompareResult, sort } from '@flex-development/tutils'
import { globby } from 'globby'
import fs from 'node:fs/promises'
import pathe, { type ParsedPath } from '@flex-development/pathe'
import { unified } from 'unified'
import { VFile } from 'vfile'
import attacher from '../theme/comments/plugin'
Expand All @@ -21,7 +21,7 @@ import type Documentation from '../theme/documentation'
*
* @return {Promise<Documentation[]>} Documentation objects
*/
async function useComments(): Promise<Documentation[]> {
const useComments = async (): Promise<Documentation[]> => {
/**
* Documentation objects.
*
Expand Down Expand Up @@ -107,7 +107,7 @@ async function useComments(): Promise<Documentation[]> {
for (const doc of compilation) objects.push({ doc, file: p })
}

return objects.sort((obj1: Documentation, obj2: Documentation): number => {
return sort(objects, (obj1: Documentation, obj2: Documentation): number => {
/**
* Comparison result for {@linkcode obj1} and {@linkcode obj2}.
*
Expand Down
7 changes: 5 additions & 2 deletions docs/.vitepress/composables/use-page-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
* @module docs/vitepress/composables/usePageUrl
*/

import pathe from '@flex-development/pathe'

/**
* Creates a page url from a relative path.
*
* @param {string} hostname - Site url
* @param {string} path - Relative page path
* @return {string} Page url
*/
function usePageUrl(hostname: string, path: string): string {
return `${hostname}/${path}`
const usePageUrl = (hostname: string, path: string): string => {
return pathe
.join(hostname, path)
.replace(/\.md$/, '.html')
.replace(/index\.html$/, '')
}
Expand Down
Loading

0 comments on commit 9bef0cf

Please sign in to comment.