Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: skip loading plugin if already loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 3, 2018
1 parent 69c20c7 commit 35897b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,26 @@ export interface IConfig extends Plugin.IPlugin {
}

export class Config extends Plugin.Plugin implements IConfig {
arch: ArchTypes
bin: string
cacheDir: string
configDir: string
dataDir: string
dirname: string
errlog: string
home: string
platform: PlatformTypes
shell: string
windows: boolean
userAgent: string
arch!: ArchTypes
bin!: string
cacheDir!: string
configDir!: string
dataDir!: string
dirname!: string
errlog!: string
home!: string
platform!: PlatformTypes
shell!: string
windows!: boolean
userAgent!: string
debug: number = 0
npmRegistry: string
npmRegistry!: string
pjson!: PJSON.CLI
userPJSON?: PJSON.User

constructor(opts: Plugin.Options) {
super(opts)
if (this.alreadyLoaded) return

this.arch = (os.arch() === 'ia32' ? 'x86' : os.arch() as any)
this.platform = os.platform() as any
Expand Down
6 changes: 5 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ export class Plugin implements IPlugin {
hooks!: {[k: string]: string[]}
valid!: boolean
ignoreManifest: boolean
alreadyLoaded = false

constructor(opts: Options) {
this.ignoreManifest = !!opts.ignoreManifest
this.type = opts.type || 'core'
this.tag = opts.tag
const root = findRoot(opts.name, opts.root)
if (!root) throw new Error(`could not find package.json with ${inspect(opts)}`)
if (Plugin.loadedPlugins[root]) return Plugin.loadedPlugins[root]
if (Plugin.loadedPlugins[root]) {
this.alreadyLoaded = true
return Plugin.loadedPlugins[root]
}
Plugin.loadedPlugins[root] = this
this.root = root
debug('reading plugin %s', root)
Expand Down

0 comments on commit 35897b0

Please sign in to comment.