Skip to content

Commit

Permalink
refactor(service): use unshfit
Browse files Browse the repository at this point in the history
  • Loading branch information
chnliquan committed Sep 1, 2022
1 parent 88dd18d commit b56684d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/service/src/core/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class PluginAPI<T extends Service = Service> {
public registerPresets(source: Plugin[], presets: unknown[]) {
assert(
this.service.stage === ServiceStage.InitPresets,
`api.registerPresets() failed, it should only used in presets.`,
`api.registerPresets() failed, it should only used in presets stage.`,
)

const plugins = presets.map(
Expand All @@ -78,7 +78,7 @@ export class PluginAPI<T extends Service = Service> {
}),
)

source.splice(0, 0, ...plugins)
source.unshift(...plugins)
}

public registerPlugins<T extends string | Plugin>(
Expand Down Expand Up @@ -116,7 +116,7 @@ export class PluginAPI<T extends Service = Service> {
if (this.service.stage === ServiceStage.InitPresets) {
source.push(...mappedPlugins)
} else {
source.splice(0, 0, ...mappedPlugins)
source.unshift(...mappedPlugins)
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/service/src/core/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class Plugin {

if (isPkgEntry) {
return nameToKey(
Plugin.stripNoneUmiScope(pkgJSON.name as string).replace(
Plugin.stripNoneScope(pkgJSON.name as string).replace(
RE[this.type],
'',
),
Expand All @@ -168,10 +168,10 @@ export class Plugin {
}

public static isPresetOrPlugin(type: PluginType, name: string) {
return RE[type].test(Plugin.stripNoneUmiScope(name))
return RE[type].test(Plugin.stripNoneScope(name))
}

public static stripNoneUmiScope(name: string) {
public static stripNoneScope(name: string) {
if (name.charAt(0) === '@' && !name.startsWith('@eljs/')) {
name = name.split('/')[1]
}
Expand Down

0 comments on commit b56684d

Please # to comment.