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

Commit

Permalink
Support name and source flags for installation
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jun 15, 2016
1 parent 7151bf0 commit c6225bc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface InstallDependencyOptions {
savePeer?: boolean
global?: boolean
cwd: string
name?: string
source?: string
emitter?: Emitter
}

Expand Down Expand Up @@ -145,7 +147,7 @@ export function installDependencyRaw (raw: string, options: InstallDependencyOpt
*/
export function installDependenciesRaw (raw: string[], options: InstallDependencyOptions): Promise<InstallResult[]> {
return new Promise(resolve => {
const expressions = raw.map(x => parseDependencyExpression(x))
const expressions = raw.map(x => parseDependencyExpression(x, options))

return resolve(installDependencies(expressions, options))
})
Expand Down
6 changes: 4 additions & 2 deletions src/lib/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ function stringifySourceFile (sourceFile: ts.SourceFile, options: StringifyOptio
if (isExternal) {
throw new TypingsError(
`Attempted to compile "${name}" as a global ` +
`module, but it looks like an external module.`
`module, but it looks like an external module. ` +
`Did you want to enable the global flag?`
)
}

Expand All @@ -503,7 +504,8 @@ function stringifySourceFile (sourceFile: ts.SourceFile, options: StringifyOptio
if (!isExternal && !(parentModule && parentModule.isExternal)) {
throw new TypingsError(
`Attempted to compile "${name}" as an external module, ` +
`but it looks like a global module.`
`but it looks like a global module.` +
`Did you want to remove the global flag?`
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ function resolveDependencyRegistry (dependency: Dependency, options: Options) {
// Wrap 404 responses in user prompt.
if (error.code === 'EINVALIDSTATUS' && error.status === 404) {
const message = `Unable to find "${meta.name}" ("${meta.source}") in the registry. ` +
`Did you want to try searching another source? ` +
`Also, if you want contribute these typings, please help us: ` +
'There are other sources available though. Would you like to try ' +
'searching for other available sources and return? You are also ' +
`welcome to help contribute these typings to the registry: ` +
`https://github.com/typings/registry`

return Promise.reject(new TypingsError(message, error))
Expand Down
20 changes: 13 additions & 7 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,23 @@ export function resolveDependency (raw: string, filename: string) {
throw new TypeError(`Unable to resolve dependency from "${raw}"`)
}

/**
* Options to use when parsing a dependency string.
*/
export interface ParseDependencyOptions {
name?: string
source?: string
}

/**
* Parse and expand the CLI dependency expression.
*/
export function parseDependencyExpression (raw: string) {
export function parseDependencyExpression (raw: string, options?: ParseDependencyOptions) {
const [, name, scheme, registry] = /^(?:([^=!:#]+)=)?(?:([\w]+\:.+)|((?:[\w]+\~)?.+))$/.exec(raw)

const location = scheme || expandRegistry(registry)

return {
name,
location
name: name || options.name,
location: scheme || expandRegistry(registry)
}
}

Expand Down Expand Up @@ -265,13 +271,13 @@ export function buildDependencyExpression (type: string, meta: DependencyMeta):
/**
* Parse the registry dependency string.
*/
export function expandRegistry (raw: string) {
export function expandRegistry (raw: string, options: ParseDependencyOptions = {}) {
if (typeof raw !== 'string') {
throw new TypeError(`Expected registry name to be a string, not ${typeof raw}`)
}

const indexOf = raw.indexOf('~')
let source = rc.defaultSource
let source = options.source || rc.defaultSource
let name: string

if (indexOf === -1) {
Expand Down

0 comments on commit c6225bc

Please sign in to comment.