Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion desktop/src/handlers/moduleHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ class ModuleHandler {
bridge.send(startProgressBar(name, 0))

try {
npm.run(['install', '-S', `${name}@${version}`], {cwd: installPath}, (err) => {
const command = [
'install', '-S', `${name}@${version}`,
...options.registry && ['--registry', options.registry]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does ...options.registry do here? Should it just be options.registry without the ...?

Copy link
Contributor Author

@ele828 ele828 May 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it's equivalent to

let command = ['install', '-S', `${name}@${version}`]
if (options.registry) {
   command.concat(['--registry', options.registry])
}

]

Logger.info(`npm ${command.join(' ')}`)

npm.run(command, {cwd: installPath}, (err) => {

// Ensure a trailing throttled call doesn't fire
progressCallback.cancel()
Expand Down
11 changes: 6 additions & 5 deletions web/src/scripts/api/ModuleClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ import {
} from 'shared/constants/ipc/ModuleConstants'
import FetchUtils from '../utils/FetchUtils'

const _importModule = (name, version, path) => {
const _importModule = (name, version, path, registry) => {
return {
type: IMPORT_MODULE,
name,
path,
version,
registry,
}
}

export const importModule = (name, version, path) => {
return request(_importModule(name, version, path))
export const importModule = (name, version, path, registry) => {
return request(_importModule(name, version, path, registry))
}

export const fetchTemplateText = (url) => {
Expand All @@ -46,7 +47,7 @@ export const fetchTemplateMetadata = (url) => {
return FetchUtils.fetchResource(url).then((result) => result.json())
}

export const fetchTemplateAndImportDependencies = (deps, textUrl, metadataUrl, path) => {
export const fetchTemplateAndImportDependencies = (deps, textUrl, metadataUrl, path, registry) => {

if (deps && ! _.isEmpty(deps) && path) {

Expand All @@ -55,7 +56,7 @@ export const fetchTemplateAndImportDependencies = (deps, textUrl, metadataUrl, p
const depVersion = deps[depName]

// TODO: consider waiting for npm install to finish
importModule(depName, depVersion, path)
importModule(depName, depVersion, path, registry)
}

const performFetch = () => {
Expand Down
2 changes: 2 additions & 0 deletions web/src/scripts/components/input/StringInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class StringInput extends Component {
type="text"
style={style}
value={this.props.value}
placeholder={this.props.placeholder}
onChange={this._onInputChange}
onKeyDown={this._onKeyDown}
onBlur={this._onBlur}/>
Expand All @@ -120,6 +121,7 @@ StringInput.propTypes = {
onChange: React.PropTypes.func.isRequired,
onSubmit: React.PropTypes.func,
value: React.PropTypes.string.isRequired,
placeholder: React.PropTypes.string,
}

StringInput.defaultProps = {
Expand Down
3 changes: 2 additions & 1 deletion web/src/scripts/components/pages/PreferencesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class PreferencesPage extends Component {
vimMode={this.props.editor[PREFERENCES.EDITOR.VIM_MODE]}
showInvisibles={this.props.editor[PREFERENCES.EDITOR.SHOW_INVISIBLES]}
highlightActiveLine={this.props.editor[PREFERENCES.EDITOR.HIGHLIGHT_ACTIVE_LINE]}
showIndentGuides={this.props.editor[PREFERENCES.EDITOR.SHOW_INDENT_GUIDES]} />
showIndentGuides={this.props.editor[PREFERENCES.EDITOR.SHOW_INDENT_GUIDES]}
npmRegistry={this.props.editor[PREFERENCES.EDITOR.NPM_REGISTRY]} />
)
default:
return null
Expand Down
11 changes: 10 additions & 1 deletion web/src/scripts/components/preferences/EditorPreferences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SliderInput from '../input/SliderInput'
import CheckboxInput from '../input/CheckboxInput'
import ColorInput from '../input/ColorInput'

import { PREFERENCES } from '../../constants/PreferencesConstants'
import { PREFERENCES, METADATA, CATEGORIES } from '../../constants/PreferencesConstants'

const style = {
display: 'flex',
Expand All @@ -45,6 +45,7 @@ export default ({
showInvisibles,
highlightActiveLine,
showIndentGuides,
npmRegistry
}) => {
return (
<div style={style}>
Expand Down Expand Up @@ -76,6 +77,14 @@ export default ({
value={highlightActiveLine}
onChange={onPreferenceChange.bind(null, PREFERENCES.EDITOR.HIGHLIGHT_ACTIVE_LINE)} />
</FormRow>
<FormRow
label={'NPM Registry'}
labelWidth={LABEL_WIDTH}>
<StringInput
value={npmRegistry}
placeholder={METADATA[CATEGORIES.EDITOR][PREFERENCES[CATEGORIES.EDITOR].NPM_REGISTRY].defaultValue}
onChange={onPreferenceChange.bind(null, PREFERENCES.EDITOR.NPM_REGISTRY)} />
</FormRow>
</div>
)
}
4 changes: 4 additions & 0 deletions web/src/scripts/constants/PreferencesConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const PREFERENCES = {
'SHOW_INVISIBLES',
'SHOW_INDENT_GUIDES',
'HIGHLIGHT_ACTIVE_LINE',
'NPM_REGISTRY',
]),
}

Expand Down Expand Up @@ -67,5 +68,8 @@ export const METADATA = {
[PREFERENCES[CATEGORIES.EDITOR].SHOW_INDENT_GUIDES]: {
defaultValue: false,
},
[PREFERENCES[CATEGORIES.EDITOR].NPM_REGISTRY]: {
defaultValue: 'https://registry.npmjs.org',
},
}
}
8 changes: 6 additions & 2 deletions web/src/scripts/containers/TabbedEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ class TabbedEditor extends Component {
}

onImportItem(item) {
const {options} = this.props
this.props.dispatch(importComponent(item)).then((payload) => {
fetchTemplateAndImportDependencies(
item.dependencies,
item.template.text,
item.template.metadata,
this.props.rootPath
this.props.rootPath,
this.props.npmRegistry,
).then(({text, metadata}) => {
const {decoDoc} = this.props

Expand Down Expand Up @@ -228,7 +230,8 @@ class TabbedEditor extends Component {
this.props.progressBar && (
<ProgressBar
style={progressBarStyle}
name={`npm install ${this.props.progressBar.name}`}
name={`npm install ${this.props.progressBar.name}` +
(this.props.npmRegistry? ` --registry=${this.props.npmRegistry}`: '')}
progress={this.props.progressBar.progress} />
)
}
Expand Down Expand Up @@ -297,6 +300,7 @@ const mapStateToProps = (state, ownProps) => {
filesByTabId,
progressBar: state.ui.progressBar,
rootPath: getRootPath(state),
npmRegistry: state.preferences[CATEGORIES.EDITOR][PREFERENCES.EDITOR.NPM_REGISTRY],
options: {
keyMap: state.preferences[CATEGORIES.EDITOR][PREFERENCES.EDITOR.VIM_MODE] ? 'vim' : 'sublime',
showInvisibles: state.preferences[CATEGORIES.EDITOR][PREFERENCES.EDITOR.SHOW_INVISIBLES],
Expand Down