-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from alibaba/dev
0.9.4,支持在一个 npm package 中包含多个间件
- Loading branch information
Showing
7 changed files
with
126 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
lint: | ||
- name: lint | ||
|
||
test: | ||
- name: lint | ||
- name: unit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright (c) 2016-present Alibaba Group Holding Limited | ||
* @author Houfeng <[email protected]> | ||
*/ | ||
|
||
class PkgName { | ||
|
||
constructor(opts) { | ||
this.opts = Object.assign({}, opts); | ||
} | ||
|
||
get scope() { | ||
return this.opts.scope || ''; | ||
} | ||
|
||
get version() { | ||
return this.opts.version || ''; | ||
} | ||
|
||
get prefix() { | ||
return this.opts.prefix || ''; | ||
} | ||
|
||
get member() { | ||
return this.opts.member || ''; | ||
} | ||
|
||
get name() { | ||
const { name = '', prefix } = this.opts; | ||
return prefix && !name.startsWith(prefix) ? `${prefix}-${name}` : name; | ||
} | ||
|
||
get fullName() { | ||
const { scope, name } = this; | ||
return scope ? `${scope}/${name}` : name; | ||
} | ||
|
||
get fullNameAndVersion() { | ||
const { fullName, version } = this; | ||
return version ? `${fullName}@${version}` : fullName; | ||
} | ||
|
||
get isPath() { | ||
return !!this.opts.isPath; | ||
} | ||
|
||
toString() { | ||
const { fullNameAndVersion, member } = this; | ||
return menubar ? `${fullNameAndVersion} ${member}` : fullNameAndVersion; | ||
} | ||
|
||
} | ||
|
||
const SCOPE_REGEXP = /^(@\S+?)\//i; | ||
const VERSION_REGEXP = /\S+?@(\S+)\s*/i; | ||
const MEMBER_REGEXP = /\s(\S+)$/i; | ||
|
||
function isPath(str) { | ||
if (!str) return false; | ||
return str.startsWith('.') || | ||
str.startsWith('/') || | ||
/^[a-z]+\:/i.test(str); | ||
} | ||
|
||
function parse(str, prefix) { | ||
str = str || ''; | ||
if (isPath(str)) { | ||
const member = (MEMBER_REGEXP.exec(str) || [])[1]; | ||
const name = str.replace(MEMBER_REGEXP, ''); | ||
return new PkgName({ name, member, isPath: true }); | ||
} else { | ||
const scope = (SCOPE_REGEXP.exec(str) || [])[1]; | ||
const version = (VERSION_REGEXP.exec(str) || [])[1]; | ||
const member = (MEMBER_REGEXP.exec(str) || [])[1]; | ||
const name = str.replace(SCOPE_REGEXP, '') | ||
.split('@')[0].split(' ')[0]; | ||
return new PkgName({ scope, version, member, name, prefix }); | ||
} | ||
} | ||
|
||
module.exports = parse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters