Skip to content

Commit

Permalink
refa: temporarily allow importing ts extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 4, 2024
1 parent 2a7a947 commit bdd36a0
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 34 deletions.
3 changes: 2 additions & 1 deletion packages/cordis/src/bin/cordis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { cac } from 'cac'
import kleur from 'kleur'
import { start } from '../cli.js'
import { Dict, hyphenate } from 'cosmokit'
// @ts-ignore
import { version } from '../../package.json'

export function isInteger(source: any) {
function isInteger(source: any) {
return typeof source === 'number' && Math.floor(source) === source
}

Expand Down
1 change: 0 additions & 1 deletion packages/cordis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"strict": true,
"noImplicitAny": false,
"resolveJsonModule": true,
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineProperty, Dict, isNullable } from 'cosmokit'
import { Lifecycle } from './events'
import { Registry } from './registry'
import { getConstructor, isConstructor, isUnproxyable, resolveConfig } from './utils'
import { Lifecycle } from './events.ts'
import { Registry } from './registry.ts'
import { getConstructor, isConstructor, isUnproxyable, resolveConfig } from './utils.ts'

export namespace Context {
export type Parameterized<C, T = any> = Omit<C, 'config'> & { config: T }
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Awaitable, defineProperty, Promisify, remove } from 'cosmokit'
import { Context } from './context'
import { EffectScope, ForkScope, MainScope, ScopeStatus } from './scope'
import { Plugin } from './registry'
import { Context } from './context.ts'
import { EffectScope, ForkScope, MainScope, ScopeStatus } from './scope.ts'
import { Plugin } from './registry.ts'

export function isBailed(value: any) {
return value !== null && value !== false && value !== undefined
Expand All @@ -12,7 +12,7 @@ export type ReturnType<F> = F extends (...args: any) => infer R ? R : never
export type ThisType<F> = F extends (this: infer T, ...args: any) => any ? T : never
export type GetEvents<C extends Context> = C[typeof Context.events]

declare module './context' {
declare module './context.ts' {
export interface Context {
/* eslint-disable max-len */
[Context.events]: Events<this>
Expand Down Expand Up @@ -185,7 +185,7 @@ export class Lifecycle {
}
}

export interface Events<C extends Context = Context> {
export interface Events<in C extends Context = Context> {
'fork': Plugin.Function<C, C['config']>
'ready'(): Awaitable<void>
'dispose'(): Awaitable<void>
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './context'
export * from './events'
export * from './registry'
export * from './service'
export * from './scope'
export * from './utils'
export * from './context.ts'
export * from './events.ts'
export * from './registry.ts'
export * from './scope.ts'
export * from './service.ts'
export * from './utils.ts'
8 changes: 4 additions & 4 deletions packages/core/src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineProperty } from 'cosmokit'
import { Context } from './context'
import { ForkScope, MainScope } from './scope'
import { resolveConfig } from './utils'
import { Context } from './context.ts'
import { ForkScope, MainScope } from './scope.ts'
import { resolveConfig } from './utils.ts'

export function isApplicable(object: Plugin) {
return object && typeof object === 'object' && typeof object.apply === 'function'
Expand Down Expand Up @@ -41,7 +41,7 @@ export namespace Plugin {
}
}

declare module './context' {
declare module './context.ts' {
export interface Context {
/* eslint-disable max-len */
/** @deprecated use `ctx.inject()` instead */
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { deepEqual, defineProperty, isNullable, remove } from 'cosmokit'
import { Context } from './context'
import { Plugin, Registry } from './registry'
import { getConstructor, isConstructor, resolveConfig } from './utils'
import { Context } from './context.ts'
import { Plugin, Registry } from './registry.ts'
import { getConstructor, isConstructor, resolveConfig } from './utils.ts'

declare module './context' {
declare module './context.ts' {
export interface Context {
scope: EffectScope<this>
runtime: MainScope<this>
Expand Down Expand Up @@ -317,7 +317,7 @@ export class MainScope<C extends Context = Context> extends EffectScope<C> {
isReusable?: boolean = false
isReactive?: boolean = false

constructor(registry: Registry<C>, public plugin: Plugin, config: any, error?: any) {
constructor(registry: Registry<C>, public plugin: Plugin<C>, config: any, error?: any) {
super(registry[Context.current] as C, config)
registry.set(plugin, this)
if (!plugin) {
Expand Down Expand Up @@ -367,7 +367,7 @@ export class MainScope<C extends Context = Context> extends EffectScope<C> {
}
}

private apply = (context: Context, config: any) => {
private apply = (context: C, config: any) => {
if (typeof this.plugin !== 'function') {
return this.plugin.apply(context, config)
} else if (isConstructor(this.plugin)) {
Expand Down Expand Up @@ -395,7 +395,7 @@ export class MainScope<C extends Context = Context> extends EffectScope<C> {
start() {
if (super.start()) return true
if (!this.isReusable && this.plugin) {
this.ensure(async () => this.apply(this.context, this._config))
this.ensure(async () => this.apply(this.ctx, this._config))
}
for (const fork of this.children) {
fork.start()
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Awaitable, defineProperty } from 'cosmokit'
import { Context } from './context'
import { Context } from './context.ts'

export interface Service extends Context.Associate<'service'> {}

Expand Down
2 changes: 0 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noImplicitThis": false,
"strictFunctionTypes": false,
Expand Down
6 changes: 3 additions & 3 deletions packages/loader/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {} from '@cordisjs/logger'
import Loader from './shared.js'
import Loader from './shared.ts'
import { promises as fs } from 'fs'
import * as dotenv from 'dotenv'
import * as path from 'path'

export * from './shared.js'
export * from './shared.ts'

const oldEnv = { ...process.env }

Expand Down Expand Up @@ -47,7 +47,7 @@ class NodeLoader extends Loader<NodeLoader.Options> {
try {
return await import(name)
} catch (err: any) {
this.app.logger('loader').error(err)
this.app.emit('internal/error', err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/loader/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context, EffectScope, ForkScope } from '@cordisjs/core'
import { Dict, isNullable, valueMap } from 'cosmokit'
import { constants, promises as fs } from 'fs'
import { interpolate } from './utils.js'
import { interpolate } from './utils.ts'
import * as yaml from 'js-yaml'
import * as path from 'path'

Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"incremental": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowImportingTsExtensions": true,
"strict": true,
},
}

0 comments on commit bdd36a0

Please sign in to comment.