Skip to content

Commit

Permalink
Merge branch 'master' into yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Nov 15, 2017
2 parents 9d1aea2 + dd6dbe8 commit 90d276f
Show file tree
Hide file tree
Showing 44 changed files with 479 additions and 571 deletions.
9 changes: 1 addition & 8 deletions scripts/test-mocha.bat → scripts/node-electron.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ set NAMESHORT=%NAMESHORT: "=%
set NAMESHORT=%NAMESHORT:"=%.exe
set CODE=".build\electron\%NAMESHORT%"

rem TFS Builds
if not "%BUILD_BUILDID%" == "" (
%CODE% .\node_modules\mocha\bin\_mocha %*
)
%CODE% %*

rem Otherwise
if "%BUILD_BUILDID%" == "" (
%CODE% .\node_modules\mocha\bin\_mocha --reporter dot %*
)
popd

endlocal
Expand Down
10 changes: 2 additions & 8 deletions scripts/test-mocha.sh → scripts/node-electron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,17 @@ fi
INTENDED_VERSION="v`node -p "require('./package.json').electronVersion"`"
INSTALLED_VERSION=$(cat .build/electron/version 2> /dev/null)

# Node modules
test -d node_modules || ./scripts/npm.sh install

# Get electron
(test -f "$CODE" && [ $INTENDED_VERSION == $INSTALLED_VERSION ]) || ./node_modules/.bin/gulp electron

# Build
test -d out || ./node_modules/.bin/gulp compile

# Unit Tests
export VSCODE_DEV=1
if [[ "$OSTYPE" == "darwin"* ]]; then
cd $ROOT ; ulimit -n 4096 ; ELECTRON_RUN_AS_NODE=1 \
"$CODE" \
node_modules/mocha/bin/_mocha "$@"
"$@"
else
cd $ROOT ; ELECTRON_RUN_AS_NODE=1 \
"$CODE" \
node_modules/mocha/bin/_mocha "$@"
"$@"
fi
1 change: 0 additions & 1 deletion scripts/test-int-mocha.bat

This file was deleted.

1 change: 0 additions & 1 deletion scripts/test-int-mocha.sh

This file was deleted.

9 changes: 7 additions & 2 deletions scripts/test-integration.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ if not "%APPVEYOR%" == "" (
)
set VSCODEUSERDATADIR=%TMP%\vscodeuserfolder-%RANDOM%-%TIME:~6,5%

:: Integration Tests
:: Tests in the extension host
.\scripts\code.bat %~dp0\..\extensions\vscode-api-tests\testWorkspace --extensionDevelopmentPath=%~dp0\..\extensions\vscode-api-tests --extensionTestsPath=%~dp0\..\extensions\vscode-api-tests\out --disableExtensions --user-data-dir=%VSCODEUSERDATADIR%
.\scripts\code.bat %~dp0\..\extensions\vscode-colorize-tests\test --extensionDevelopmentPath=%~dp0\..\extensions\vscode-colorize-tests --extensionTestsPath=%~dp0\..\extensions\vscode-colorize-tests\out --user-data-dir=%VSCODEUSERDATADIR%
.\scripts\test-int-mocha.bat
.\scripts\code.bat $%~dp0\..\extensions\emmet\test-fixtures --extensionDevelopmentPath=%~dp0\..\extensions\emmet --extensionTestsPath=%~dp0\..\extensions\emmet\out\test --disableExtensions --user-data-dir=%VSCODEUSERDATADIR%

:: Integration & performance tests in AMD
.\scripts\test.bat --runGlob **\*.integrationTest.js %*

:: Tests in commonJS (language servers tests...)
.\scripts\mocha-electron.bat .\extensions\html\server\out\test\

rmdir /s /q %VSCODEUSERDATADIR%

popd
Expand Down
11 changes: 8 additions & 3 deletions scripts/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ fi

cd $ROOT

# Integration Tests
# Tests in the extension host
./scripts/code.sh $ROOT/extensions/vscode-api-tests/testWorkspace --extensionDevelopmentPath=$ROOT/extensions/vscode-api-tests --extensionTestsPath=$ROOT/extensions/vscode-api-tests/out --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
./scripts/code.sh $ROOT/extensions/vscode-colorize-tests/test --extensionDevelopmentPath=$ROOT/extensions/vscode-colorize-tests --extensionTestsPath=$ROOT/extensions/vscode-colorize-tests/out --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
./scripts/test-int-mocha.sh
./scripts/code.sh $ROOT/extensions/vscode-colorize-tests/test --extensionDevelopmentPath=$ROOT/extensions/vscode-colorize-tests --extensionTestsPath=$ROOT/extensions/vscode-colorize-tests/out --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
./scripts/code.sh $ROOT/extensions/emmet/test-fixtures --extensionDevelopmentPath=$ROOT/extensions/emmet --extensionTestsPath=$ROOT/extensions/emmet/out/test --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started

# Integration tests in AMD
./scripts/test.sh --runGlob **/*.integrationTest.js "$@"

# Tests in commonJS (language server tests...)
./scripts/node-electron.sh ./node_modules/mocha/bin/_mocha ./extensions/html/server/out/test/

rm -r $VSCODEUSERDATADIR
2 changes: 1 addition & 1 deletion src/vs/base/common/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { once } from 'vs/base/common/functional';

export const empty: IDisposable = Object.freeze({
export const empty: IDisposable = Object.freeze<IDisposable>({
dispose() { }
});

Expand Down
4 changes: 0 additions & 4 deletions src/vs/base/node/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export function decodeStream(encoding: string): NodeJS.ReadWriteStream {
return iconv.decodeStream(toNodeEncoding(encoding));
}

export function encodeStream(encoding: string): NodeJS.ReadWriteStream {
return iconv.encodeStream(toNodeEncoding(encoding));
}

function toNodeEncoding(enc: string): string {
if (enc === UTF8_with_bom) {
return UTF8; // iconv does not distinguish UTF 8 with or without BOM, so we need to help it
Expand Down
98 changes: 46 additions & 52 deletions src/vs/base/node/extfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import * as flow from 'vs/base/node/flow';

import * as fs from 'fs';
import * as paths from 'path';
import { TPromise } from 'vs/base/common/winjs.base';
import { nfcall } from 'vs/base/common/async';

const loop = flow.loop;

Expand Down Expand Up @@ -41,80 +43,72 @@ export function readdir(path: string, callback: (error: Error, files: string[])
return fs.readdir(path, callback);
}

export function mkdirp(path: string, mode: number, callback: (error: Error) => void): void {
fs.exists(path, exists => {
if (exists) {
return isDirectory(path, (err: Error, itIs?: boolean) => {
if (err) {
return callback(err);
}

if (!itIs) {
return callback(new Error('"' + path + '" is not a directory.'));
}

callback(null);
});
}

mkdirp(paths.dirname(path), mode, (err: Error) => {
if (err) { callback(err); return; }

if (mode) {
fs.mkdir(path, mode, error => {
if (error) {
return callback(error);
}

fs.chmod(path, mode, callback); // we need to explicitly chmod because of https://github.com/nodejs/node/issues/1104
});
} else {
fs.mkdir(path, null, callback);
}
});
});
}

function isDirectory(path: string, callback: (error: Error, isDirectory?: boolean) => void): void {
fs.stat(path, (error, stat) => {
if (error) { return callback(error); }

callback(null, stat.isDirectory());
});
}

export function copy(source: string, target: string, callback: (error: Error) => void, copiedSources?: { [path: string]: boolean }): void {
if (!copiedSources) {
copiedSources = Object.create(null);
}

fs.stat(source, (error, stat) => {
if (error) { return callback(error); }
if (!stat.isDirectory()) { return pipeFs(source, target, stat.mode & 511, callback); }
if (error) {
return callback(error);
}

if (!stat.isDirectory()) {
return pipeFs(source, target, stat.mode & 511, callback);
}

if (copiedSources[source]) {
return callback(null); // escape when there are cycles (can happen with symlinks)
} else {
copiedSources[source] = true; // remember as copied
}

mkdirp(target, stat.mode & 511, err => {
copiedSources[source] = true; // remember as copied

const proceed = function () {
readdir(source, (err, files) => {
loop(files, (file: string, clb: (error: Error, result: string[]) => void) => {
copy(paths.join(source, file), paths.join(target, file), (error: Error) => clb(error, void 0), copiedSources);
}, callback);
});
};

mkdirp(target, stat.mode & 511).done(proceed, proceed);
});
}

export function mkdirp(path: string, mode?: number): TPromise<boolean> {
const mkdir = () => nfcall(fs.mkdir, path, mode)
.then(null, (err: NodeJS.ErrnoException) => {
if (err.code === 'EEXIST') {
return nfcall(fs.stat, path)
.then((stat: fs.Stats) => stat.isDirectory
? null
: TPromise.wrapError(new Error(`'${path}' exists and is not a directory.`)));
}

return TPromise.wrapError<boolean>(err);
});

// is root?
if (path === paths.dirname(path)) {
return TPromise.as(true);
}

return mkdir().then(null, (err: NodeJS.ErrnoException) => {
if (err.code === 'ENOENT') {
return mkdirp(paths.dirname(path), mode).then(mkdir);
}

return TPromise.wrapError<boolean>(err);
});
}

function pipeFs(source: string, target: string, mode: number, callback: (error: Error) => void): void {
let callbackHandled = false;

let readStream = fs.createReadStream(source);
let writeStream = fs.createWriteStream(target, { mode: mode });
const readStream = fs.createReadStream(source);
const writeStream = fs.createWriteStream(target, { mode: mode });

let onError = (error: Error) => {
const onError = (error: Error) => {
if (!callbackHandled) {
callbackHandled = true;
callback(error);
Expand Down Expand Up @@ -163,7 +157,7 @@ export function del(path: string, tmpFolder: string, callback: (error: Error) =>
return rmRecursive(path, callback);
}

let pathInTemp = paths.join(tmpFolder, uuid.generateUuid());
const pathInTemp = paths.join(tmpFolder, uuid.generateUuid());
fs.rename(path, pathInTemp, (error: Error) => {
if (error) {
return rmRecursive(path, callback); // if rename fails, delete without tmp dir
Expand Down Expand Up @@ -200,7 +194,7 @@ function rmRecursive(path: string, callback: (error: Error) => void): void {
if (err || !stat) {
callback(err);
} else if (!stat.isDirectory() || stat.isSymbolicLink() /* !!! never recurse into links when deleting !!! */) {
let mode = stat.mode;
const mode = stat.mode;
if (!(mode & 128)) { // 128 === 0200
fs.chmod(path, mode | 128, (err: Error) => { // 128 === 0200
if (err) {
Expand Down
69 changes: 1 addition & 68 deletions src/vs/base/node/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

'use strict';

import streams = require('stream');

import mime = require('vs/base/common/mime');
import { TPromise } from 'vs/base/common/winjs.base';

Expand Down Expand Up @@ -76,18 +74,6 @@ export interface DetectMimesOption {
autoGuessEncoding?: boolean;
}

function doDetectMimesFromStream(instream: streams.Readable, option?: DetectMimesOption): TPromise<IMimeAndEncoding> {
return stream.readExactlyByStream(instream, maxBufferLen(option)).then((readResult: stream.ReadResult) => {
return detectMimeAndEncodingFromBuffer(readResult, option && option.autoGuessEncoding);
});
}

function doDetectMimesFromFile(absolutePath: string, option?: DetectMimesOption): TPromise<IMimeAndEncoding> {
return stream.readExactlyByFile(absolutePath, maxBufferLen(option)).then((readResult: stream.ReadResult) => {
return detectMimeAndEncodingFromBuffer(readResult, option && option.autoGuessEncoding);
});
}

export function detectMimeAndEncodingFromBuffer(readResult: stream.ReadResult, autoGuessEncoding?: false): IMimeAndEncoding;
export function detectMimeAndEncodingFromBuffer(readResult: stream.ReadResult, autoGuessEncoding?: boolean): TPromise<IMimeAndEncoding>;
export function detectMimeAndEncodingFromBuffer({ buffer, bytesRead }: stream.ReadResult, autoGuessEncoding?: boolean): TPromise<IMimeAndEncoding> | IMimeAndEncoding {
Expand Down Expand Up @@ -117,57 +103,4 @@ export function detectMimeAndEncodingFromBuffer({ buffer, bytesRead }: stream.Re
mimes: isText ? [mime.MIME_TEXT] : [mime.MIME_BINARY],
encoding: enc
};
}

function filterAndSortMimes(detectedMimes: string[], guessedMimes: string[]): string[] {
const mimes = detectedMimes;

// Add extension based mime as first element as this is the desire of whoever created the file.
// Never care about application/octet-stream or application/unknown as guessed mime, as this is the fallback of the guess which is never accurate
const guessedMime = guessedMimes[0];
if (guessedMime !== mime.MIME_BINARY && guessedMime !== mime.MIME_UNKNOWN) {
mimes.unshift(guessedMime);
}

// Remove duplicate elements from array and sort unspecific mime to the end
const uniqueSortedMimes = mimes.filter((element, position) => {
return element && mimes.indexOf(element) === position;
}).sort((mimeA, mimeB) => {
if (mimeA === mime.MIME_BINARY) { return 1; }
if (mimeB === mime.MIME_BINARY) { return -1; }
if (mimeA === mime.MIME_TEXT) { return 1; }
if (mimeB === mime.MIME_TEXT) { return -1; }

return 0;
});

return uniqueSortedMimes;
}

/**
* Opens the given stream to detect its mime type. Returns an array of mime types sorted from most specific to unspecific.
* @param instream the readable stream to detect the mime types from.
* @param nameHint an additional hint that can be used to detect a mime from a file extension.
*/
export function detectMimesFromStream(instream: streams.Readable, nameHint: string, option?: DetectMimesOption): TPromise<IMimeAndEncoding> {
return doDetectMimesFromStream(instream, option).then(encoding =>
handleMimeResult(nameHint, encoding)
);
}

/**
* Opens the given file to detect its mime type. Returns an array of mime types sorted from most specific to unspecific.
* @param absolutePath the absolute path of the file.
*/
export function detectMimesFromFile(absolutePath: string, option?: DetectMimesOption): TPromise<IMimeAndEncoding> {
return doDetectMimesFromFile(absolutePath, option).then(encoding =>
handleMimeResult(absolutePath, encoding)
);
}

function handleMimeResult(nameHint: string, result: IMimeAndEncoding): IMimeAndEncoding {
const filterAndSortedMimes = filterAndSortMimes(result.mimes, mime.guessMimeTypes(nameHint));
result.mimes = filterAndSortedMimes;

return result;
}
}
29 changes: 2 additions & 27 deletions src/vs/base/node/pfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { TPromise } from 'vs/base/common/winjs.base';
import * as extfs from 'vs/base/node/extfs';
import { dirname, join } from 'path';
import { join } from 'path';
import { nfcall, Queue } from 'vs/base/common/async';
import * as fs from 'fs';
import * as os from 'os';
Expand All @@ -26,32 +26,7 @@ export function chmod(path: string, mode: number): TPromise<boolean> {
return nfcall(fs.chmod, path, mode);
}

export function mkdirp(path: string, mode?: number): TPromise<boolean> {
const mkdir = () => nfcall(fs.mkdir, path, mode)
.then(null, (err: NodeJS.ErrnoException) => {
if (err.code === 'EEXIST') {
return nfcall(fs.stat, path)
.then((stat: fs.Stats) => stat.isDirectory
? null
: TPromise.wrapError(new Error(`'${path}' exists and is not a directory.`)));
}

return TPromise.wrapError<boolean>(err);
});

// is root?
if (path === dirname(path)) {
return TPromise.as(true);
}

return mkdir().then(null, (err: NodeJS.ErrnoException) => {
if (err.code === 'ENOENT') {
return mkdirp(dirname(path), mode).then(mkdir);
}

return TPromise.wrapError<boolean>(err);
});
}
export import mkdirp = extfs.mkdirp;

export function rimraf(path: string): TPromise<void> {
return lstat(path).then(stat => {
Expand Down
Loading

0 comments on commit 90d276f

Please sign in to comment.