Socket
Socket
Sign inDemoInstall

nuclide-commons-atom

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuclide-commons-atom - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

.npmignore

53

ContextMenu.js

@@ -6,2 +6,3 @@ 'use strict';

});
exports.showMenuForEvent = showMenuForEvent;

@@ -14,2 +15,4 @@ var _UniversalDisposable;

var _electron = require('electron');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -32,2 +35,14 @@

*/
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
class ContextMenu {

@@ -194,16 +209,34 @@

exports.default = ContextMenu; /** Comparator used to sort menu items by priority: lower priorities appear earlier. */
function compareInternalItems(a, b) {
return a.priority - b.priority;
}
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
* Shows the provided menu template. This will result in [an extra call to `templateForEvent()`][1],
* but it means that we still go through `showMenuForEvent()`, maintaining its behavior wrt
* (a)synchronousness. See atom/atom#13398.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
* [1]: https://github.com/atom/atom/blob/v1.13.0/src/context-menu-manager.coffee#L200
*/
function showMenuForEvent(event, menuTemplate) {
if (!(_electron.remote != null)) {
throw new Error('Invariant violation: "remote != null"');
}
function compareInternalItems(a, b) {
return a.priority - b.priority;
const win = _electron.remote.getCurrentWindow();
const originalEmit = win.emit;
const restore = () => {
win.emit = originalEmit;
};
win.emit = (eventType, ...args) => {
if (eventType !== 'context-menu') {
return originalEmit(eventType, ...args);
}
const result = originalEmit('context-menu', menuTemplate);
restore();
return result;
};
atom.contextMenu.showForEvent(event);
return new (_UniversalDisposable || _load_UniversalDisposable()).default(restore);
}

@@ -7,2 +7,8 @@ 'use strict';

var _idx;
function _load_idx() {
return _idx = _interopRequireDefault(require('idx'));
}
var _UniversalDisposable;

@@ -14,2 +20,8 @@

var _nullthrows;
function _load_nullthrows() {
return _nullthrows = _interopRequireDefault(require('nullthrows'));
}
var _featureConfig;

@@ -23,6 +35,11 @@

var _collection;
function _load_collection() {
return _collection = require('nuclide-commons/collection');
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// eslint-disable-line rulesdir/prefer-nuclide-uri
const ALWAYS_ENABLED = 'always'; // eslint-disable-line rulesdir/prefer-nuclide-uri
/**

@@ -42,2 +59,5 @@ * Copyright (c) 2017-present, Facebook, Inc.

const NEVER_ENABLED = 'never';
const DEFAULT = 'default';
const { devMode } = atom.getLoadSettings();

@@ -47,8 +67,14 @@

constructor({ features, path: _path }) {
constructor({ features, path: _path, featureGroups }) {
this._featureGroupMap = new (_collection || _load_collection()).MultiMap();
this._currentPackageState = new Set();
this._path = _path;
this._features = features;
this._loadDisposable = new (_UniversalDisposable || _load_UniversalDisposable()).default();
this._pkgName = packageNameFromPath(this._path);
this._featureGroups = featureGroups == null ? {} : featureGroups;
// Constructs the map from feature groups to features.
this.constructFeatureGroupMap();
this._config = {

@@ -100,12 +126,14 @@ use: {

// Sample packages are disabled by default. They are meant for development
// use only, and aren't included in Nuclide builds.
const enabled = !name.startsWith('sample-');
// Migrate the current feature (from boolean on/off to enumerated states).
this.migrateFeature(feature);
// Entry for enabling/disabling the feature
const setting = {
title: featurePkg.displayName == null ? `Enable the "${name}" feature` : `Enable ${featurePkg.displayName}`,
description: featurePkg.description || '',
type: 'boolean',
default: enabled
type: 'string',
enum: [{ value: ALWAYS_ENABLED, description: 'Always enabled' }, { value: NEVER_ENABLED, description: 'Never enabled' }, {
value: DEFAULT,
description: 'Only when in an enabled package group'
}],
default: getFeatureDefaultValue(feature)
};

@@ -144,2 +172,3 @@

});
(_featureConfig || _load_featureConfig()).default.setPackageName(this._pkgName);

@@ -161,9 +190,3 @@

this._features.forEach(feature => {
// Config defaults are not merged with user defaults until activate. At
// this point `atom.config.get` returns the user set value. If it's
// `undefined`, then the user has not set it.
const enabled = atom.config.get(this.useKeyPathForFeature(feature));
const shouldEnable = enabled == null ? this._config.use.properties[packageNameFromPath(feature.path)].default : enabled;
if (shouldEnable) {
if (this.shouldEnable(feature)) {
atom.packages.loadPackage(feature.path);

@@ -202,4 +225,29 @@ }

// Hack time!! Atom's repository APIs are synchronous. Any package that tries to use them before
// we've had a chance to provide our implementation are going to get wrong answers. The correct
// thing to do would be to always go through an async API that awaits until
// `atom.packages.onDidActivateInitialPackages()` completes. However, we have some legacy sync
// codepaths that make that difficult. As a temporary (I hope) workaround, we prioritize
// activation of the features that provide this service.
const originalOrder = new Map(this._features.map((feature, i) => [feature, i]));
this._features.sort((a, b) => {
const aIsRepoProvider = packageIsRepositoryProvider(a.pkg);
const bIsRepoProvider = packageIsRepositoryProvider(b.pkg);
if (aIsRepoProvider !== bIsRepoProvider) {
return aIsRepoProvider ? -1 : 1;
}
const aIndex = (0, (_nullthrows || _load_nullthrows()).default)(originalOrder.get(a));
const bIndex = (0, (_nullthrows || _load_nullthrows()).default)(originalOrder.get(b));
return aIndex - bIndex;
});
this._features.forEach(feature => {
if (atom.config.get(this.useKeyPathForFeature(feature))) {
// Since the migration from bool to enum occurs before the config defaults
// are changed, the user's config gets filled with every Nuclide feature.
// Since these values are already the default, this `config.set`
// removes these uneccessary values from the user's config file.
// TODO: When enough users have migrated, this should be removed along with the enum migration.
atom.config.set(this.useKeyPathForFeature(feature), atom.config.get(this.useKeyPathForFeature(feature)));
if (this.shouldEnable(feature)) {
atom.packages.activatePackage(feature.path);

@@ -210,9 +258,31 @@ }

// Watch the config to manage toggling features
this._activationDisposable = new (_UniversalDisposable || _load_UniversalDisposable()).default(...this._features.map(feature => atom.config.onDidChange(this.useKeyPathForFeature(feature), event => {
if (event.newValue === true) {
this._activationDisposable = new (_UniversalDisposable || _load_UniversalDisposable()).default(atom.config.onDidChange(this.useKeyPath(), event => this.updateActiveFeatures()), atom.config.onDidChange(this.useKeyPathForFeatureGroup(), event => this.updateActiveFeatures()));
this.updateActiveFeatures();
}
updateActiveFeatures() {
const featureState = atom.config.get(this.useKeyPath());
const featureGroupState = atom.config.get(this.useKeyPathForFeatureGroup());
// we know featureGroupState must be ?Array, and featureState must
// be ?Object, since it's in our schema. However, flow thinks it's a mixed type,
// since it doesn't know about the schema enforcements. $FlowIgnore.
const desiredState = this.getDesiredState(featureState, featureGroupState);
// Enable all packages in desiredState but not in currentState.
// Disable all packages not in desiredState but in currentState.
for (const feature of desiredState) {
if (!this._currentPackageState.has(feature)) {
atom.packages.activatePackage(feature.path);
} else if (event.newValue === false) {
}
}
for (const feature of this._currentPackageState) {
if (!desiredState.has(feature)) {
safeDeactivate(feature);
}
})));
}
this._currentPackageState = desiredState;
}

@@ -240,2 +310,47 @@

getDesiredState(featureState, featureGroupState) {
// Figure out which features should be enabled:
// * Add all packages in nuclide.use
// * Remove any feature not in an active featureGroup.
let groupedPackages;
if (featureGroupState != null) {
groupedPackages = (0, (_collection || _load_collection()).setUnion)(...featureGroupState.map(featureGroup => this._featureGroupMap.get(featureGroup)));
} else {
// If featuregroups is empty or undefined, assume all features should be enabled.
groupedPackages = new Set(this._features);
}
// If a feature is "always enabled", it should be on whether or not a feature-group includes it.
// If a feature is "default", it should be on if and only if a feature-group includes it.
return new Set(this._features.filter(feature => {
const state = featureState[packageNameFromPath(feature.path)];
return state === ALWAYS_ENABLED || groupedPackages.has(feature) && state === DEFAULT || state === true;
}));
}
constructFeatureGroupMap() {
/*
* Construct a map from feature name to feature. The _featureGroupMap
* must contain the true feature objects, but featureGroups.cson only has
* the feature names.
*/
const featureMap = new Map();
this._features.forEach(feature => {
featureMap.set(_path2.default.basename(feature.path), feature);
});
for (const key of Object.keys(this._featureGroups)) {
if (Array.isArray(this._featureGroups[key])) {
const featuresForKey = this._featureGroups[key].map(featureName => featureMap.get(featureName)).filter(Boolean);
if (featuresForKey != null) {
this._featureGroupMap.set(key, featuresForKey);
}
}
}
}
getFeatureGroups() {
return this._featureGroupMap;
}
getConfig() {

@@ -257,2 +372,63 @@ return this._config;

}
useKeyPath() {
return `${this._pkgName}.use`;
}
useKeyPathForFeatureGroup() {
return `${this._pkgName}.enabledFeatureGroups`;
}
shouldEnable(feature) {
const name = packageNameFromPath(feature.path);
const currentState = atom.config.get(this.useKeyPathForFeature(feature));
switch (currentState) {
// Previously, this setting was a boolean. They should be migrated but handle it just in case.
case true:
case false:
return currentState;
case ALWAYS_ENABLED:
return true;
case NEVER_ENABLED:
return false;
case DEFAULT:
// TODO: This will become dependent on project configuration.
return true;
default:
// This default will trigger if the user explicitly
// sets a package's state to undefined or to a non-enum value.
// If this is the case, set to false if it begins with sample- and true otherwise.
return !name.startsWith('sample-');
}
}
migrateFeature(feature) {
const keyPath = this.useKeyPathForFeature(feature);
const currentState = atom.config.get(keyPath);
const setTo = this.getValueForFeatureToEnumMigration(currentState, feature);
if (setTo !== currentState) {
atom.config.set(keyPath, setTo);
}
}
getValueForFeatureToEnumMigration(currentState, feature) {
const name = packageNameFromPath(feature.path);
switch (currentState) {
case true:
return name.startsWith('sample-') ? ALWAYS_ENABLED : DEFAULT;
case false:
return name.startsWith('sample-') ? DEFAULT : NEVER_ENABLED;
case ALWAYS_ENABLED:
case NEVER_ENABLED:
case DEFAULT:
if (!(typeof currentState === 'string')) {
throw new Error('Invariant violation: "typeof currentState === \'string\'"');
}
return currentState;
default:
return getFeatureDefaultValue(feature);
}
}
}

@@ -274,2 +450,7 @@

function getFeatureDefaultValue(feature) {
const name = packageNameFromPath(feature.path);
return name.startsWith('sample-') ? NEVER_ENABLED : DEFAULT;
}
function safeSerialize(feature) {

@@ -293,2 +474,8 @@ const name = packageNameFromPath(feature.path);

return _path2.default.basename(pkgPath);
}
function packageIsRepositoryProvider(pkg) {
var _ref, _ref2;
return Boolean((_ref = pkg) != null ? (_ref2 = _ref.providedServices) != null ? _ref2['atom.repository-provider'] : _ref2 : _ref);
}

5

package.json
{
"name": "nuclide-commons-atom",
"version": "0.5.0",
"version": "0.6.0",
"description": "Common Nuclide node modules (for use with Atom only).",

@@ -19,3 +19,4 @@ "author": "NEEDS OWNER",

"log4js": "1.1.1",
"nuclide-commons": "0.5.0",
"nuclide-commons": "0.6.0",
"nullthrows": "1.0.0",
"redux-logger": "3.0.6",

@@ -22,0 +23,0 @@ "rxjs": "5.5.5",

@@ -14,5 +14,13 @@ 'use strict';

exports.onDidRemoveProjectPath = onDidRemoveProjectPath;
exports.observeRemovedHostnames = observeRemovedHostnames;
exports.observeAddedHostnames = observeAddedHostnames;
var _atom = require('atom');
var _event;
function _load_event() {
return _event = require('nuclide-commons/event');
}
var _nuclideUri;

@@ -24,4 +32,24 @@

var _observable;
function _load_observable() {
return _observable = require('nuclide-commons/observable');
}
var _rxjsBundlesRxMinJs = require('rxjs/bundles/Rx.min.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
function getValidProjectPaths() {

@@ -36,13 +64,3 @@ return atom.project.getDirectories().filter(directory => {

}).map(directory => directory.getPath());
} /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
}

@@ -138,2 +156,14 @@ function getAtomProjectRelativePath(path) {

});
}
function observeHostnames() {
return (atom.packages.initialPackagesActivated ? _rxjsBundlesRxMinJs.Observable.of(null) : (0, (_event || _load_event()).observableFromSubscribeFunction)(atom.packages.onDidActivateInitialPackages.bind(atom.packages))).switchMap(() => (0, (_event || _load_event()).observableFromSubscribeFunction)(atom.project.onDidChangePaths.bind(atom.project)).startWith(null).map(() => new Set(atom.project.getPaths().filter((_nuclideUri || _load_nuclideUri()).default.isRemote).map((_nuclideUri || _load_nuclideUri()).default.getHostname))).let((0, (_observable || _load_observable()).diffSets)()));
}
function observeRemovedHostnames() {
return observeHostnames().flatMap(diff => _rxjsBundlesRxMinJs.Observable.from(diff.removed));
}
function observeAddedHostnames() {
return observeHostnames().flatMap(diff => _rxjsBundlesRxMinJs.Observable.from(diff.added));
}

@@ -17,2 +17,8 @@ 'use strict';

var _textEditor;
function _load_textEditor() {
return _textEditor = require('./text-editor');
}
/**

@@ -24,14 +30,2 @@ * Finds the word at the position. You can either provide a word regex yourself,

*/
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
function wordAtPosition(editor, position, wordRegex) {

@@ -46,4 +40,3 @@ let wordRegex_;

// the specific position. So we re-implement it ourselves...
const scopeDescriptor = editor.scopeDescriptorForBufferPosition(position);
const nonWordChars = editor.getNonWordCharacters(scopeDescriptor);
const nonWordChars = (0, (_textEditor || _load_textEditor()).getNonWordCharacters)(editor, position);
const escaped = nonWordChars.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');

@@ -74,2 +67,14 @@ // We copied this escaping regex from atom$Cursor.wordRegexp, rather than

*/
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
function trimRange(editor, rangeToTrim, stopRegex = /\S/) {

@@ -76,0 +81,0 @@ const buffer = editor.getBuffer();

@@ -19,2 +19,3 @@ 'use strict';

exports.centerScrollToBufferLine = centerScrollToBufferLine;
exports.getNonWordCharacters = getNonWordCharacters;

@@ -29,2 +30,8 @@ var _UniversalDisposable;

var _semver;
function _load_semver() {
return _semver = _interopRequireDefault(require('semver'));
}
var _event;

@@ -48,14 +55,2 @@

*/
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
function existingEditorForUri(path) {

@@ -77,2 +72,14 @@ // This isn't ideal but realistically iterating through even a few hundred editors shouldn't be a

*/
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
function existingEditorForBuffer(buffer) {

@@ -234,2 +241,12 @@ // This isn't ideal but realistically iterating through even a few hundred editors shouldn't be a

});
}
function getNonWordCharacters(editor, position) {
if ((_semver || _load_semver()).default.gte(atom.getVersion(), '1.24.0-beta0')) {
return editor.getNonWordCharacters(position);
} else {
// This used to take a scope descriptor.
const scope = position == null ? null : editor.scopeDescriptorForBufferPosition(position);
return editor.getNonWordCharacters(scope);
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc