Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuclide-commons

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuclide-commons - npm Package Compare versions

Comparing version 0.2.0 to 0.4.0

2

BatchProcessedQueue.js

@@ -21,2 +21,3 @@ "use strict";

this._items.push(item);
// eslint-disable-next-line eqeqeq
if (this._timeoutId === null) {

@@ -37,2 +38,3 @@ this._timeoutId = setTimeout(() => {

dispose() {
// eslint-disable-next-line eqeqeq
if (this._timeoutId !== null) {

@@ -39,0 +41,0 @@ clearTimeout(this._timeoutId);

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -39,2 +39,3 @@ Object.defineProperty(exports, "__esModule", {

exports.count = count;
exports.isIterable = isIterable;
/**

@@ -470,2 +471,6 @@ * Copyright (c) 2017-present, Facebook, Inc.

return size;
}
function isIterable(obj) {
return typeof obj[Symbol.iterator] === 'function';
}

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

getHash(item) {
// eslint-disable-next-line eqeqeq
if (item === null) {

@@ -47,0 +48,0 @@ return 'null';

239

nuclideUri.js

@@ -23,16 +23,13 @@ 'use strict';

// eslint-disable-next-line rulesdir/prefer-nuclide-uri
const REMOTE_PATH_URI_PREFIX = 'nuclide://';
// TODO(ljw): following regex is incorrect. A URI scheme must start with
// [A-Za-z] not [0-9_-]. Also, not all schemes require // after them.
/**
* 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
*/
const ARCHIVE_SEPARATOR = '!'; /**
* 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
*/

@@ -44,2 +41,7 @@ // NuclideUri's are either a local file path, or a URI

const KNOWN_ARCHIVE_EXTENSIONS = ['.jar', '.zip'];
const REMOTE_PATH_URI_PREFIX = 'nuclide://';
// TODO(ljw): following regex is incorrect. A URI scheme must start with
// [A-Za-z] not [0-9_-]. Also, not all schemes require // after them.
const URI_PREFIX_REGEX = /^[A-Za-z0-9_-]+:\/\/.*/;

@@ -54,4 +56,5 @@

// and are destroyed during Nuclide startup.
// On Windows, we further mangle the colon into an underscore to avoid an invalid drive prefix.
function isBrokenDeserializedUri(uri) {
return uri != null && uri.match(/nuclide:[\\/][^/]/) != null;
return uri != null && uri.match(/nuclide[:_][\\/][^/]/) != null;
}

@@ -80,2 +83,14 @@

function isInArchive(uri) {
if (isAtomUri(uri) || uri.indexOf(ARCHIVE_SEPARATOR) < 0) {
return false;
}
for (let i = uri.indexOf(ARCHIVE_SEPARATOR); i >= 0; i = uri.indexOf(ARCHIVE_SEPARATOR, i + 1)) {
if (_isArchiveSeparator(uri, i)) {
return true;
}
}
return false;
}
/**

@@ -106,2 +121,7 @@ * Parses valid Nuclide URIs into the hostname and path components.

const path = hostAndPath.substr(hostSep);
if (!!_endsWithArchiveSeparator(uri)) {
throw new Error(`Path cannot end with archive separator. Failed to parse ${uri}`);
}
return { hostname, path };

@@ -114,2 +134,6 @@ }

if (!!_endsWithArchiveSeparator(uri)) {
throw new Error(`Path cannot end with archive separator. Failed to parse ${uri}`);
}
return { hostname: null, path: uri };

@@ -157,3 +181,3 @@ }

function join(uri, ...relativePath) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -163,17 +187,28 @@ if (isRemote(uri)) {

relativePath.splice(0, 0, path);
return createRemoteUri(hostname, uriPathModule.join.apply(null, relativePath));
_archiveEncodeArrayInPlace(uriPathModule, relativePath);
return _archiveDecode(uriPathModule, createRemoteUri(hostname, uriPathModule.join.apply(null, relativePath)));
} else {
relativePath.splice(0, 0, uri);
return uriPathModule.join.apply(null, relativePath);
_archiveEncodeArrayInPlace(uriPathModule, relativePath);
return _archiveDecode(uriPathModule, uriPathModule.join.apply(null, relativePath));
}
}
function archiveJoin(uri, path) {
_testForIllegalUri(uri);
if (!KNOWN_ARCHIVE_EXTENSIONS.some(ext => uri.endsWith(ext))) {
throw new Error(`Cannot archiveJoin with non-archive ${uri} and ${path}`);
}
return uri + ARCHIVE_SEPARATOR + path;
}
function normalize(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);
if (isRemote(uri)) {
const { hostname, path } = parseRemoteUri(uri);
return createRemoteUri(hostname, uriPathModule.normalize(path));
const normal = _archiveDecode(uriPathModule, uriPathModule.normalize(_archiveEncode(uriPathModule, path)));
return createRemoteUri(hostname, normal);
} else {
return uriPathModule.normalize(uri);
return _archiveDecode(uriPathModule, uriPathModule.normalize(_archiveEncode(uriPathModule, uri)));
}

@@ -192,3 +227,3 @@ }

function relative(uri, other) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -199,23 +234,21 @@ const remote = isRemote(uri);

}
if (remote) {
return uriPathModule.relative(getPath(uri), getPath(other));
} else {
return uriPathModule.relative(uri, other);
}
const uriEncode = _archiveEncode(uriPathModule, remote ? getPath(uri) : uri);
const otherEncode = _archiveEncode(uriPathModule, remote ? getPath(other) : other);
return _archiveDecode(uriPathModule, uriPathModule.relative(_matchTrailingArchive(uriEncode, otherEncode), _matchTrailingArchive(otherEncode, uriEncode)));
}
function basename(uri, ext = '') {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);
return uriPathModule.basename(getPath(uri), ext);
return _archiveDecode(uriPathModule, uriPathModule.basename(_archiveEncode(uriPathModule, getPath(uri)), ext));
}
function dirname(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);
if (isRemote(uri)) {
const { hostname, path } = parseRemoteUri(uri);
return createRemoteUri(hostname, uriPathModule.dirname(path));
return createRemoteUri(hostname, _archiveDecode(uriPathModule, uriPathModule.dirname(_archiveEncode(uriPathModule, path))));
} else {
return uriPathModule.dirname(uri);
return _archiveDecode(uriPathModule, uriPathModule.dirname(_archiveEncode(uriPathModule, uri)));
}

@@ -225,9 +258,9 @@ }

function extname(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);
return uriPathModule.extname(getPath(uri));
return _archiveDecode(uriPathModule, uriPathModule.extname(_archiveEncode(uriPathModule, getPath(uri))));
}
function stripExtension(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const ext = extname(uri);

@@ -291,3 +324,3 @@ if (ext.length === 0) {

function nuclideUriToUri(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
if (isRemote(uri)) {

@@ -304,4 +337,4 @@ return uri;

function contains(parent, child) {
_testForAtomUri(parent);
_testForAtomUri(child);
_testForIllegalUri(parent);
_testForIllegalUri(child);

@@ -331,3 +364,3 @@ // Can't just do startsWith here. If this directory is "www" and you

return endsWithSeparator(parent) && parent.startsWith(child);
return parent.startsWith(child) && (endsWithSeparator(parent) || _isArchiveSeparator(child, parent.length));
}

@@ -344,3 +377,4 @@

const uriPathModule = _pathModuleFor(child);
return child.slice(parent.length).startsWith(uriPathModule.sep);
return _isArchiveSeparator(child, parent.length) || child.slice(parent.length).startsWith(uriPathModule.sep);
}

@@ -380,3 +414,3 @@

function nuclideUriToDisplayString(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
if (isRemote(uri)) {

@@ -399,3 +433,3 @@ let hostname = getHostname(uri);

function ensureTrailingSeparator(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -410,3 +444,3 @@ if (uri.endsWith(uriPathModule.sep)) {

function trimTrailingSeparator(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -423,3 +457,3 @@ let stripped = uri;

function endsWithSeparator(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -430,3 +464,3 @@ return uri.endsWith(uriPathModule.sep);

function isAbsolute(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
if (isRemote(uri)) {

@@ -441,3 +475,3 @@ return true;

function resolve(uri, ...paths) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -447,6 +481,8 @@ if (isRemote(uri)) {

paths.splice(0, 0, path);
return createRemoteUri(hostname, uriPathModule.resolve.apply(null, paths));
_archiveEncodeArrayInPlace(uriPathModule, paths);
return createRemoteUri(hostname, _archiveDecode(uriPathModule, uriPathModule.resolve.apply(null, paths)));
} else {
paths.splice(0, 0, uri);
return uriPathModule.resolve.apply(null, paths);
_archiveEncodeArrayInPlace(uriPathModule, paths);
return _archiveDecode(uriPathModule, uriPathModule.resolve.apply(null, paths));
}

@@ -456,3 +492,3 @@ }

function expandHomeDir(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);

@@ -528,3 +564,3 @@ // Do not expand non home relative uris

function ensureLocalPrefix(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);

@@ -549,3 +585,3 @@

function isRoot(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
return dirname(uri) === uri;

@@ -555,5 +591,16 @@ }

function parsePath(uri) {
_testForAtomUri(uri);
_testForIllegalUri(uri);
const uriPathModule = _pathModuleFor(uri);
return uriPathModule.parse(getPath(uri));
if (!isInArchive(uri)) {
return uriPathModule.parse(getPath(uri));
} else {
const parsed = uriPathModule.parse(_archiveEncode(uriPathModule, getPath(uri)));
return {
root: _archiveDecode(uriPathModule, parsed.root),
dir: _archiveDecode(uriPathModule, parsed.dir),
base: _archiveDecode(uriPathModule, parsed.base),
ext: _archiveDecode(uriPathModule, parsed.ext),
name: _archiveDecode(uriPathModule, parsed.name)
};
}
}

@@ -584,3 +631,11 @@

function hasKnownArchiveExtension(uri) {
return KNOWN_ARCHIVE_EXTENSIONS.some(ext => uri.endsWith(ext));
}
function _pathModuleFor(uri) {
if (!!_endsWithArchiveSeparator(uri)) {
throw new Error(`Path cannot end with archive separator. Failed to determine path module for ${uri}`);
}
if (uri.startsWith(_path.default.posix.sep)) {

@@ -603,2 +658,64 @@ return _path.default.posix;

// Runs _archiveEncode in-place on array, and returns argument for convenience.
function _archiveEncodeArrayInPlace(uriPathModule, array) {
array.forEach((uri, i, a) => a[i] = _archiveEncode(uriPathModule, uri));
return array;
}
// This adds a native separator after every archive separator
// so that the native path handling code sees them.
function _archiveEncode(uriPathModule, uri) {
if (uri.indexOf(ARCHIVE_SEPARATOR) < 0) {
return uri;
}
return KNOWN_ARCHIVE_EXTENSIONS.reduce((acc, ext) => acc.replace(`${ext}${ARCHIVE_SEPARATOR}`, `${ext}${ARCHIVE_SEPARATOR}${uriPathModule.sep}`), uri);
}
// This is the inverse of `encodeArchiveSeparators()` to put things
// back after the native path handler has run.
function _archiveDecode(uriPathModule, uri) {
if (uri.indexOf(ARCHIVE_SEPARATOR) < 0) {
return uri;
}
return _trimArchiveSuffix(KNOWN_ARCHIVE_EXTENSIONS.reduce((acc, ext) => acc.replace(`${ext}${ARCHIVE_SEPARATOR}${uriPathModule.sep}`, `${ext}${ARCHIVE_SEPARATOR}`), uri));
}
// When working with encoded uri's, the archive separator is part of the name
// so we can manipulate paths with uriPathModule. However, in `relative` if
// one uri contains the other, we need the names seen by uriPathModule to agree
// on whether there is an archive separator or not. E.g. if we have:
// /etc/file.zip
// /etc/file.zip!abc
// When we encode these, we get:
// /etc/file.zip
// /etc/file.zip!/abc
// We need to add a trailing '!' to the first one so uriPathModule can see that
// the first contains the second.
function _matchTrailingArchive(uri, other) {
if (uri.length < other.length && other.startsWith(uri) && _isArchiveSeparator(other, uri.length)) {
return uri + ARCHIVE_SEPARATOR;
} else {
return uri;
}
}
function _trimArchiveSuffix(path) {
if (_endsWithArchiveSeparator(path)) {
return path.substring(0, path.length - ARCHIVE_SEPARATOR.length);
} else {
return path;
}
}
function _endsWithArchiveSeparator(path) {
return _isArchiveSeparator(path, path.length - 1);
}
function _isArchiveSeparator(path, index) {
return path.length > index && path.charAt(index) === ARCHIVE_SEPARATOR && KNOWN_ARCHIVE_EXTENSIONS.some(ext => {
const extStart = index - ext.length;
return path.indexOf(ext, extStart) === extStart;
});
}
/**

@@ -613,5 +730,10 @@ * The backslash and percent characters (\ %) are, unfortunately, valid symbols to be used in POSIX

function _testForAtomUri(uri) {
if (uri != null && isAtomUri(uri)) {
throw new Error(`Path operation invoked on Atom URI ${uri}`);
function _testForIllegalUri(uri) {
if (uri != null) {
if (isAtomUri(uri)) {
throw new Error(`Path operation invoked on Atom URI ${uri}`);
}
if (_endsWithArchiveSeparator(uri)) {
throw new Error(`Path operation invoked on URI ending with ${ARCHIVE_SEPARATOR}: ${uri}`);
}
}

@@ -660,2 +782,3 @@ }

createRemoteUri,
isInArchive,
parse,

@@ -668,2 +791,3 @@ parseRemoteUri,

join,
archiveJoin,
relative,

@@ -692,2 +816,5 @@ normalize,

pathSeparatorFor,
hasKnownArchiveExtension,
ARCHIVE_SEPARATOR,
KNOWN_ARCHIVE_EXTENSIONS,
NUCLIDE_URI_TYPE_NAME

@@ -694,0 +821,0 @@ };

@@ -25,2 +25,4 @@ 'use strict';

var _rxjsBundlesRxMinJs = require('rxjs/bundles/Rx.min.js');
var _collection;

@@ -32,4 +34,2 @@

var _rxjsBundlesRxMinJs = require('rxjs/bundles/Rx.min.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -36,0 +36,0 @@

{
"name": "nuclide-commons",
"version": "0.2.0",
"version": "0.4.0",
"description": "Common Nuclide node modules.",

@@ -22,2 +22,3 @@ "license": "BSD-3-Clause",

"mkdirp": "0.5.1",
"nullthrows": "1.0.0",
"rimraf": "2.5.4",

@@ -24,0 +25,0 @@ "rxjs": "5.3.1",

@@ -331,5 +331,5 @@ 'use strict';

//
// Unlike Promises, observables have a standardized, composable cancelation mechanism _today_.
// Unlike Promises, observables have a standardized, composable cancellation mechanism _today_.
// Moreover, observables integrate nicely with Atom's callback + IDisposable formula for cancelable,
// async APIs. Along with React, [RxJS] is one of the core libaries utilized by Nuclide.
// async APIs. Along with React, [RxJS] is one of the core libraries utilized by Nuclide.
//

@@ -384,2 +384,3 @@ // ## Why errors?

default:
event.kind;
throw new Error(`Invalid event kind: ${event.kind}`);

@@ -493,3 +494,3 @@ }

//
// The following utilites don't spawn processes or necessarily use observables. Instead, they're
// The following utilities don't spawn processes or necessarily use observables. Instead, they're
// used to format arguments to the above functions or for acting on already-spawned processes.

@@ -751,3 +752,3 @@ //

const proc = _child_process.default[type]((_nuclideUri || _load_nuclideUri()).default.expandHomeDir(commandOrModulePath), args,
// $FlowFixMe: child_process$spawnOpts and child_process$forkOpts have incompatable stdio types.
// $FlowFixMe: child_process$spawnOpts and child_process$forkOpts have incompatible stdio types.
Object.assign({}, options));

@@ -754,0 +755,0 @@

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

});
exports.PromiseWithState = exports.asyncSome = exports.asyncObjFilter = exports.asyncFilter = exports.Deferred = exports.retryLimit = exports.triggerAfterWait = exports.RequestSerializer = undefined;
exports.PromiseWithState = exports.asyncSome = exports.asyncObjFilter = exports.asyncFilter = exports.Deferred = exports.retryLimit = exports.TimedOutError = exports.triggerAfterWait = exports.RequestSerializer = undefined;

@@ -41,4 +41,3 @@ var _asyncToGenerator = _interopRequireDefault(require('async-to-generator'));

/**
* Returns a Promise that resolves to the same value as the given promise, or rejects if it takes
* longer than `milliseconds` milliseconds
* Thrown by `timeoutPromise` if the timer fires before the promise resolves/rejects.
*/

@@ -370,7 +369,19 @@

});
}function timeoutPromise(promise, milliseconds) {
}class TimedOutError extends Error {
constructor(milliseconds) {
super(`Timed out after ${String(milliseconds)} ms`);
this.timeout = milliseconds;
}
}
exports.TimedOutError = TimedOutError; /**
* Returns a Promise that resolves to the same value as the given promise, or rejects with
* `TimedOutError` if it takes longer than `milliseconds` milliseconds.
*/
function timeoutPromise(promise, milliseconds) {
return new Promise((resolve, reject) => {
let timeout = setTimeout(() => {
timeout = null;
reject(new Error(`Promise timed out after ${String(milliseconds)} ms`));
reject(new TimedOutError(milliseconds));
}, milliseconds);

@@ -377,0 +388,0 @@ promise.then(value => {

@@ -53,3 +53,3 @@ 'use strict';

/**
* Write an observed readable stream into a writeable stream. Effectively a pipe() for observables.
* Write an observed readable stream into a writable stream. Effectively a pipe() for observables.
* Returns an observable accumulating the number of bytes processed.

@@ -56,0 +56,0 @@ */

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

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