@@ -17,8 +17,30 @@ import {
1717 assertTypes
1818} from './datatypes'
1919
20+ /**
21+ * Parse info of scope package.
22+ */
23+
2024const SCOPE_PACKAGE_RE = / ^ @ ( .* ) \/ ( .* ) /
2125
26+ export interface ScopePackage {
27+ org : string ;
28+ name : string ;
29+ }
30+
31+ export function resolveScopePackage ( name : string ) {
32+ if ( SCOPE_PACKAGE_RE . test ( name ) ) {
33+ return {
34+ org : RegExp . $1 ,
35+ name : RegExp . $2
36+ }
37+ }
38+ return {
39+ org : '' ,
40+ name : ''
41+ }
42+ }
43+
2244/**
2345 * Common module constructor.
2446 */
@@ -33,20 +55,20 @@ export class CommonModule {
3355 ) { }
3456}
3557
36- function getNoopModule ( error ?: Error ) {
58+ function getNoopModule ( error ?: Error ) {
3759 return new CommonModule ( null , null , null , null , error )
3860}
3961
4062export interface NormalizedModuleRequest {
41- name : string | null
42- shortcut : string | null
63+ name : string | null ;
64+ shortcut : string | null ;
4365}
4466
4567/**
4668 * Expose ModuleResolver.
4769 */
4870
49- type Type = String | Number | Boolean | RegExp | Function | Object | Record < string , any > | Array < any >
71+ type Type = string | number | boolean | RegExp | Function | Record < string , any > | Record < string , any > | Array < any >
5072
5173class ModuleResolver {
5274 private nonScopePrefix : string
@@ -162,8 +184,8 @@ class ModuleResolver {
162184 const { shortcut, name } = this . normalizeName ( req )
163185 try {
164186 const entry = this . load
165- ? loadModule ( < string > name , this . cwd )
166- : resolveModule ( < string > name , this . cwd )
187+ ? loadModule ( name as string , this . cwd )
188+ : resolveModule ( name as string , this . cwd )
167189 return new CommonModule ( entry , name , shortcut , true /* fromDep */ )
168190 } catch ( error ) {
169191 return getNoopModule ( error )
@@ -185,8 +207,8 @@ class ModuleResolver {
185207 */
186208
187209 normalizeName ( req : string ) : NormalizedModuleRequest {
188- let name = null
189- let shortcut = null
210+ let name : string | null = null
211+ let shortcut : string | null = null
190212
191213 if ( req . startsWith ( '@' ) ) {
192214 const pkg = resolveScopePackage ( req )
@@ -237,28 +259,6 @@ class ModuleResolver {
237259 }
238260}
239261
240- /**
241- * Parse info of scope package.
242- */
243-
244- export interface ScopePackage {
245- org : string ;
246- name : string ;
247- }
248-
249- export function resolveScopePackage ( name : string ) {
250- if ( SCOPE_PACKAGE_RE . test ( name ) ) {
251- return {
252- org : RegExp . $1 ,
253- name : RegExp . $2
254- }
255- }
256- return {
257- org : '' ,
258- name : ''
259- }
260- }
261-
262262export const getMarkdownItResolver = ( cwd : string ) => new ModuleResolver (
263263 'markdown-it' , '' , [ String , Function ] , true /* load module */ , cwd
264264)
0 commit comments