Skip to content

Commit b200aa4

Browse files
wip(core): enhance types usage
1 parent 3179e32 commit b200aa4

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/tools.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
Options,
3030
ValueFactory,
3131
ModuleExport,
32+
Module,
3233
LoadingType,
3334
} from './types'
3435

@@ -99,7 +100,7 @@ export function hash(...valueList : string[]) : string {
99100
* preventCache usage: non-fatal error
100101
* @internal
101102
*/
102-
export async function withCache( cacheInstance : Cache, key : string[], valueFactory : ValueFactory ) {
103+
export async function withCache( cacheInstance : Cache, key : string[], valueFactory : ValueFactory ) : Promise<any> {
103104

104105
let cachePrevented = false;
105106

@@ -198,7 +199,7 @@ export function parseDeps(fileAst : t.File) : string[] {
198199
/**
199200
* @internal
200201
*/
201-
export async function transformJSCode(source : string, moduleSourceType : boolean, filename : string, options : Options) {
202+
export async function transformJSCode(source : string, moduleSourceType : boolean, filename : string, options : Options) : Promise<[string[], string]> {
202203

203204
const { additionalBabelPlugins = [], log } = options;
204205

@@ -286,7 +287,7 @@ export async function loadModuleInternal(currentPath : string, modulePath : stri
286287
* Create a cjs module
287288
* @internal
288289
*/
289-
export function createModule(filename : string, source : string, options : Options) {
290+
export function createModule(filename : string, source : string, options : Options) : Module {
290291

291292
const { moduleCache, pathHandlers: { resolve }, getResource } = options;
292293

@@ -319,7 +320,7 @@ export function createModule(filename : string, source : string, options : Optio
319320
/**
320321
* @internal
321322
*/
322-
export async function createJSModule(source : string, moduleSourceType : boolean, filename : string, options : Options) {
323+
export async function createJSModule(source : string, moduleSourceType : boolean, filename : string, options : Options) : Promise<ModuleExport> {
323324

324325
const { compiledCache } = options;
325326

@@ -337,7 +338,7 @@ export async function createJSModule(source : string, moduleSourceType : boolean
337338
* Just load and cache given dependencies.
338339
* @internal
339340
*/
340-
export async function loadDeps(filename : string, deps : string[], options : Options) {
341+
export async function loadDeps(filename : string, deps : string[], options : Options) : Promise<void> {
341342

342343
await Promise.all(deps.map(dep => loadModuleInternal(filename, dep, options)))
343344
}

src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export type ValueFactoryApi = {
99
/**
1010
* @internal
1111
*/
12-
export type ValueFactory = {
13-
(api : ValueFactoryApi): Promise<any>;
14-
}
12+
export type ValueFactory = (api : ValueFactoryApi) => Promise<any>;
1513

1614

1715
export type Cache = {

0 commit comments

Comments
 (0)