Skip to content

Commit 02296da

Browse files
wip(core): normalize getFile()
1 parent 031d9e1 commit 02296da

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { posix as Path } from 'path'
33
import { createJSModule } from './tools'
44
import { createSFCModule, vueVersion } from './createSFCModule'
55

6-
import { ModuleExport, ModuleHandler, PathHandlers, Options } from './types'
6+
import { ModuleExport, ModuleHandler, PathHandlers, Options, File } from './types'
77

88
/**
99
* the version of the library (process.env.VERSION is set by webpack, at compile-time)
@@ -117,11 +117,20 @@ export async function loadModule(path : string, options_ : Options = throwNotDef
117117
loadModule,
118118
} = options_;
119119

120+
121+
// TBD: remove this in v1.0
122+
async function normalizedGetFile(path : string) : Promise<File> {
123+
124+
const res = await getFile(path);
125+
return typeof res === 'object' ? res : { content: res, extname: pathHandlers.extname(path) };
126+
}
127+
120128
const options = {
121129
moduleCache,
122130
additionalModuleHandlers,
123131
pathHandlers,
124-
...options_
132+
...options_,
133+
getFile: normalizedGetFile,
125134
};
126135

127136
if ( path in moduleCache ) {
@@ -142,9 +151,7 @@ export async function loadModule(path : string, options_ : Options = throwNotDef
142151
return moduleCache[path] = module;
143152
}
144153

145-
const res = await getFile(path);
146-
147-
const file = typeof res === 'object' ? res : { content: res, extname: pathHandlers.extname(path) };
154+
const file = await options.getFile(path);
148155

149156
const moduleHandlers = { ...defaultModuleHandlers, ...additionalModuleHandlers };
150157

src/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ export interface ModuleHandler {
5555

5656

5757
/**
58-
* Represents the content of the file or the content and the extension name.
58+
* Represents a file content and the extension name.
5959
*/
60-
export type File = string | { content : string, extname : string };
6160

61+
export interface File {
62+
content : string,
63+
extname : string,
64+
}
6265

6366
/**
6467
* CustomBlockCallback function type

0 commit comments

Comments
 (0)