@yarnpkg/core
Advanced tools
Comparing version 2.0.0-rc.7 to 2.0.0-rc.8
@@ -139,3 +139,3 @@ "use strict"; | ||
async writeFileIntoCache(file, generator) { | ||
return await fslib_2.xfs.lockPromise(`${file}.lock`, async () => { | ||
return await fslib_2.xfs.lockPromise(file, async () => { | ||
return await generator(file); | ||
@@ -142,0 +142,0 @@ }); |
@@ -18,2 +18,3 @@ "use strict"; | ||
const clipanion_1 = require("clipanion"); | ||
const is_ci_1 = __importDefault(require("is-ci")); | ||
const supports_color_1 = __importDefault(require("supports-color")); | ||
@@ -190,4 +191,11 @@ const MultiFetcher_1 = require("./MultiFetcher"); | ||
type: SettingsType.BOOLEAN, | ||
default: false, | ||
default: is_ci_1.default, | ||
defaultText: `<dynamic>`, | ||
}, | ||
enableProgressBars: { | ||
description: `If true, the CLI is allowed to show a progress bar for long-running events`, | ||
type: SettingsType.BOOLEAN, | ||
default: !is_ci_1.default && process.stdout.isTTY, | ||
defaultText: `<dynamic>`, | ||
}, | ||
enableTimers: { | ||
@@ -194,0 +202,0 @@ description: `If true, the CLI is allowed to print the time spent executing commands`, |
@@ -8,2 +8,6 @@ "use strict"; | ||
const cross_spawn_1 = __importDefault(require("cross-spawn")); | ||
function hasFd(stream) { | ||
// @ts-ignore: Not sure how to typecheck this field | ||
return stream !== null && typeof stream.fd === `number`; | ||
} | ||
async function pipevp(fileName, args, { cwd, env = process.env, strict = false, stdin = null, stdout, stderr }) { | ||
@@ -13,7 +17,7 @@ const stdio = [`pipe`, `pipe`, `pipe`]; | ||
stdio[0] = `ignore`; | ||
else if (stdin === process.stdin) | ||
else if (hasFd(stdin)) | ||
stdio[0] = stdin; | ||
if (stdout === process.stdout) | ||
if (hasFd(stdout)) | ||
stdio[1] = stdout; | ||
if (stderr === process.stderr) | ||
if (hasFd(stderr)) | ||
stdio[2] = stderr; | ||
@@ -25,7 +29,7 @@ const subprocess = cross_spawn_1.default(fileName, args, { | ||
}); | ||
if (stdin !== process.stdin && stdin !== null) | ||
if (!hasFd(stdin) && stdin !== null) | ||
stdin.pipe(subprocess.stdin); | ||
if (stdout !== process.stdout) | ||
if (!hasFd(stdout)) | ||
subprocess.stdout.pipe(stdout); | ||
if (stderr !== process.stderr) | ||
if (!hasFd(stderr)) | ||
subprocess.stderr.pipe(stderr); | ||
@@ -32,0 +36,0 @@ return new Promise((resolve, reject) => { |
@@ -79,3 +79,3 @@ "use strict"; | ||
//@ts-ignore | ||
const gotClient = got_1.default.extend(Object.assign({}, gotOptions, { hooks: makeHooks() })); | ||
const gotClient = got_1.default.extend(Object.assign(Object.assign({}, gotOptions), { hooks: makeHooks() })); | ||
const res = await gotClient(target); | ||
@@ -100,4 +100,4 @@ return await res.body; | ||
async function put(target, body, options) { | ||
return await request(target, body, Object.assign({}, options, { method: Method.PUT })); | ||
return await request(target, body, Object.assign(Object.assign({}, options), { method: Method.PUT })); | ||
} | ||
exports.put = put; |
@@ -28,2 +28,6 @@ /// <reference types="node" /> | ||
reportError(name: MessageName, text: string): void; | ||
reportProgress(progress: AsyncIterable<{ | ||
progress: number; | ||
title?: string; | ||
}>): Promise<void>; | ||
reportJson(data: any): void; | ||
@@ -30,0 +34,0 @@ finalize(): Promise<void>; |
"use strict"; | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -51,2 +58,17 @@ const Report_1 = require("./Report"); | ||
} | ||
async reportProgress(progress) { | ||
var e_1, _a; | ||
try { | ||
for (var progress_1 = __asyncValues(progress), progress_1_1; progress_1_1 = await progress_1.next(), !progress_1_1.done;) { | ||
const {} = progress_1_1.value; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (progress_1_1 && !progress_1_1.done && (_a = progress_1.return)) await _a.call(progress_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
reportJson(data) { | ||
@@ -53,0 +75,0 @@ // Just ignore the json output |
@@ -469,5 +469,5 @@ "use strict"; | ||
} | ||
exports.Manifest = Manifest; | ||
Manifest.allDependencies = [`dependencies`, `devDependencies`, `peerDependencies`]; | ||
Manifest.hardDependencies = [`dependencies`, `devDependencies`]; | ||
exports.Manifest = Manifest; | ||
; | ||
@@ -474,0 +474,0 @@ function getIndent(content) { |
@@ -42,3 +42,3 @@ import { PortablePath } from '@yarnpkg/fslib'; | ||
private addWorkspace; | ||
readonly topLevelWorkspace: Workspace; | ||
get topLevelWorkspace(): Workspace; | ||
tryWorkspaceByCwd(workspaceCwd: PortablePath): Workspace | null; | ||
@@ -45,0 +45,0 @@ getWorkspaceByCwd(workspaceCwd: PortablePath): Workspace; |
@@ -69,2 +69,6 @@ /// <reference types="node" /> | ||
export declare function isReportError(error: Error): error is ReportError; | ||
export declare type ProgressDefinition = { | ||
progress: number; | ||
title?: string; | ||
}; | ||
export declare abstract class Report { | ||
@@ -82,4 +86,12 @@ private reportedInfos; | ||
abstract reportError(name: MessageName, text: string): void; | ||
abstract reportProgress(progress: AsyncIterable<ProgressDefinition>): Promise<void>; | ||
abstract reportJson(data: any): void; | ||
abstract finalize(): void; | ||
static progressViaCounter(max: number): { | ||
[Symbol.asyncIterator](): AsyncGenerator<{ | ||
progress: number; | ||
}, void, unknown>; | ||
set: (n: number) => void; | ||
tick: (n?: number) => void; | ||
}; | ||
reportInfoOnce(name: MessageName, text: string, opts?: { | ||
@@ -86,0 +98,0 @@ key?: any; |
"use strict"; | ||
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } | ||
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
function fulfill(value) { resume("next", value); } | ||
function reject(value) { resume("throw", value); } | ||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -86,2 +98,37 @@ const stream_1 = require("stream"); | ||
} | ||
static progressViaCounter(max) { | ||
let current = 0; | ||
let unlock; | ||
let lock = new Promise(resolve => { | ||
unlock = resolve; | ||
}); | ||
const set = (n) => { | ||
const thisUnlock = unlock; | ||
lock = new Promise(resolve => { | ||
unlock = resolve; | ||
}); | ||
current = n; | ||
thisUnlock(); | ||
}; | ||
const tick = (n = 0) => { | ||
set(current + 1); | ||
}; | ||
const gen = (function () { | ||
return __asyncGenerator(this, arguments, function* () { | ||
while (current < max) { | ||
yield __await(lock); | ||
yield yield __await({ | ||
progress: current / max, | ||
}); | ||
} | ||
}); | ||
})(); | ||
return { | ||
[Symbol.asyncIterator]() { | ||
return gen; | ||
}, | ||
set, | ||
tick, | ||
}; | ||
} | ||
reportInfoOnce(name, text, opts) { | ||
@@ -88,0 +135,0 @@ const key = opts && opts.key ? opts.key : text; |
@@ -29,2 +29,5 @@ /// <reference types="node" /> | ||
private indent; | ||
private progress; | ||
private progressTime; | ||
private progressFrame; | ||
constructor({ configuration, stdout, json, includeFooter, includeLogs, includeInfos, includeWarnings }: StreamReportOptions); | ||
@@ -41,4 +44,12 @@ hasErrors(): boolean; | ||
reportError(name: MessageName, text: string): void; | ||
reportProgress(progressIt: AsyncIterable<{ | ||
progress: number; | ||
title?: string; | ||
}>): Promise<void>; | ||
reportJson(data: any): void; | ||
finalize(): Promise<void>; | ||
private writeLine; | ||
private clearProgress; | ||
private writeProgress; | ||
private refreshProgress; | ||
private formatTiming; | ||
@@ -45,0 +56,0 @@ private formatName; |
"use strict"; | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Report_1 = require("./Report"); | ||
const PROGRESS_FRAMES = [`⠋`, `⠙`, `⠹`, `⠸`, `⠼`, `⠴`, `⠦`, `⠧`, `⠇`, `⠏`]; | ||
const PROGRESS_INTERVAL = 80; | ||
const PROGRESS_SIZE = 80; | ||
class StreamReport extends Report_1.Report { | ||
@@ -13,2 +23,5 @@ constructor({ configuration, stdout, json = false, includeFooter = true, includeLogs = !json, includeInfos = includeLogs, includeWarnings = includeLogs }) { | ||
this.indent = 0; | ||
this.progress = new Map(); | ||
this.progressTime = 0; | ||
this.progressFrame = 0; | ||
this.configuration = configuration; | ||
@@ -92,3 +105,3 @@ this.includeFooter = includeFooter; | ||
if (this.indent === 0) { | ||
this.stdout.write(`\n`); | ||
this.writeLine(``); | ||
} | ||
@@ -103,3 +116,3 @@ else { | ||
if (!this.json) { | ||
this.stdout.write(`${this.configuration.format(`➤`, `blueBright`)} ${this.formatName(name)}: ${this.formatIndent()}${text}\n`); | ||
this.writeLine(`${this.configuration.format(`➤`, `blueBright`)} ${this.formatName(name)}: ${this.formatIndent()}${text}`); | ||
} | ||
@@ -115,3 +128,3 @@ else { | ||
if (!this.json) { | ||
this.stdout.write(`${this.configuration.format(`➤`, `yellowBright`)} ${this.formatName(name)}: ${this.formatIndent()}${text}\n`); | ||
this.writeLine(`${this.configuration.format(`➤`, `yellowBright`)} ${this.formatName(name)}: ${this.formatIndent()}${text}`); | ||
} | ||
@@ -125,3 +138,3 @@ else { | ||
if (!this.json) { | ||
this.stdout.write(`${this.configuration.format(`➤`, `redBright`)} ${this.formatName(name)}: ${this.formatIndent()}${text}\n`); | ||
this.writeLine(`${this.configuration.format(`➤`, `redBright`)} ${this.formatName(name)}: ${this.formatIndent()}${text}`); | ||
} | ||
@@ -132,5 +145,33 @@ else { | ||
} | ||
async reportProgress(progressIt) { | ||
var e_1, _a; | ||
const progressDefinition = { | ||
progress: 0, | ||
title: undefined, | ||
}; | ||
this.progress.set(progressIt, progressDefinition); | ||
this.refreshProgress(-1); | ||
try { | ||
for (var progressIt_1 = __asyncValues(progressIt), progressIt_1_1; progressIt_1_1 = await progressIt_1.next(), !progressIt_1_1.done;) { | ||
const { progress, title } = progressIt_1_1.value; | ||
if (progressDefinition.progress === progress && progressDefinition.title === title) | ||
continue; | ||
progressDefinition.progress = progress; | ||
progressDefinition.title = title; | ||
this.refreshProgress(); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (progressIt_1_1 && !progressIt_1_1.done && (_a = progressIt_1.return)) await _a.call(progressIt_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
this.progress.delete(progressIt); | ||
this.refreshProgress(+1); | ||
} | ||
reportJson(data) { | ||
if (this.json) { | ||
this.stdout.write(`${JSON.stringify(data)}\n`); | ||
this.writeLine(`${JSON.stringify(data)}`); | ||
} | ||
@@ -183,2 +224,36 @@ } | ||
} | ||
writeLine(str) { | ||
this.clearProgress({ clear: true }); | ||
this.stdout.write(`${str}\n`); | ||
this.writeProgress(); | ||
} | ||
clearProgress({ delta = 0, clear = false }) { | ||
if (!this.configuration.get(`enableProgressBars`) || this.json) | ||
return; | ||
if (this.progress.size + delta > 0) { | ||
this.stdout.write(`\x1b[${this.progress.size + delta}A`); | ||
if (delta > 0 || clear) { | ||
this.stdout.write(`\x1b[0J`); | ||
} | ||
} | ||
} | ||
writeProgress() { | ||
if (!this.configuration.get(`enableProgressBars`) || this.json) | ||
return; | ||
const now = Date.now(); | ||
if (now - this.progressTime > PROGRESS_INTERVAL) { | ||
this.progressFrame = (this.progressFrame + 1) % PROGRESS_FRAMES.length; | ||
this.progressTime = now; | ||
} | ||
const spinner = PROGRESS_FRAMES[this.progressFrame]; | ||
for (const { progress } of this.progress.values()) { | ||
const ok = `=`.repeat(Math.floor(PROGRESS_SIZE * progress)); | ||
const ko = `-`.repeat(PROGRESS_SIZE - ok.length); | ||
this.stdout.write(`${this.configuration.format(`➤`, `blueBright`)} ${this.formatName(null)}: ${spinner} ${ok}${ko}\n`); | ||
} | ||
} | ||
refreshProgress(delta = 0) { | ||
this.clearProgress({ delta }); | ||
this.writeProgress(); | ||
} | ||
formatTiming(timing) { | ||
@@ -185,0 +260,0 @@ return timing < 60 * 1000 |
@@ -49,3 +49,3 @@ "use strict"; | ||
function renamePackage(pkg, locator) { | ||
return Object.assign({}, locator, { version: pkg.version, languageName: pkg.languageName, linkType: pkg.linkType, dependencies: new Map(pkg.dependencies), peerDependencies: new Map(pkg.peerDependencies), dependenciesMeta: new Map(pkg.dependenciesMeta), peerDependenciesMeta: new Map(pkg.peerDependenciesMeta), bin: new Map(pkg.bin) }); | ||
return Object.assign(Object.assign({}, locator), { version: pkg.version, languageName: pkg.languageName, linkType: pkg.linkType, dependencies: new Map(pkg.dependencies), peerDependencies: new Map(pkg.peerDependencies), dependenciesMeta: new Map(pkg.dependenciesMeta), peerDependenciesMeta: new Map(pkg.peerDependenciesMeta), bin: new Map(pkg.bin) }); | ||
} | ||
@@ -52,0 +52,0 @@ exports.renamePackage = renamePackage; |
@@ -12,4 +12,8 @@ import { Report, MessageName } from './Report'; | ||
reportError(name: MessageName, text: string): void; | ||
reportProgress(progress: AsyncIterable<{ | ||
progress: number; | ||
title?: string; | ||
}>): Promise<void>; | ||
reportJson(data: any): void; | ||
finalize(): Promise<void>; | ||
} |
"use strict"; | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -23,2 +30,17 @@ const Report_1 = require("./Report"); | ||
} | ||
async reportProgress(progress) { | ||
var e_1, _a; | ||
try { | ||
for (var progress_1 = __asyncValues(progress), progress_1_1; progress_1_1 = await progress_1.next(), !progress_1_1.done;) { | ||
const {} = progress_1_1.value; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (progress_1_1 && !progress_1_1.done && (_a = progress_1.return)) await _a.call(progress_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
reportJson(data) { | ||
@@ -25,0 +47,0 @@ // Just ignore the json output |
@@ -45,5 +45,5 @@ "use strict"; | ||
const aliasFs = new fslib_1.AliasFS(virtualPath, { baseFs: sourceFetch.packageFs, pathUtils: fslib_1.ppath }); | ||
return Object.assign({}, sourceFetch, { packageFs: aliasFs }); | ||
return Object.assign(Object.assign({}, sourceFetch), { packageFs: aliasFs }); | ||
} | ||
} | ||
exports.VirtualFetcher = VirtualFetcher; |
@@ -42,3 +42,3 @@ "use strict"; | ||
} | ||
exports.VirtualResolver = VirtualResolver; | ||
VirtualResolver.protocol = `virtual:`; | ||
exports.VirtualResolver = VirtualResolver; |
@@ -41,6 +41,6 @@ "use strict"; | ||
const workspace = opts.project.getWorkspaceByCwd(locator.reference.slice(WorkspaceResolver.protocol.length)); | ||
return Object.assign({}, locator, { version: workspace.manifest.version || `0.0.0`, languageName: `unknown`, linkType: types_1.LinkType.SOFT, dependencies: new Map([...workspace.manifest.dependencies, ...workspace.manifest.devDependencies]), peerDependencies: new Map([...workspace.manifest.peerDependencies]), dependenciesMeta: workspace.manifest.dependenciesMeta, peerDependenciesMeta: workspace.manifest.peerDependenciesMeta, bin: workspace.manifest.bin }); | ||
return Object.assign(Object.assign({}, locator), { version: workspace.manifest.version || `0.0.0`, languageName: `unknown`, linkType: types_1.LinkType.SOFT, dependencies: new Map([...workspace.manifest.dependencies, ...workspace.manifest.devDependencies]), peerDependencies: new Map([...workspace.manifest.peerDependencies]), dependenciesMeta: workspace.manifest.dependenciesMeta, peerDependenciesMeta: workspace.manifest.peerDependenciesMeta, bin: workspace.manifest.bin }); | ||
} | ||
} | ||
exports.WorkspaceResolver = WorkspaceResolver; | ||
WorkspaceResolver.protocol = `workspace:`; | ||
exports.WorkspaceResolver = WorkspaceResolver; |
{ | ||
"name": "@yarnpkg/core", | ||
"version": "2.0.0-rc.7", | ||
"version": "2.0.0-rc.8", | ||
"main": "./lib/index.js", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@yarnpkg/fslib": "2.0.0-rc.3", | ||
"@yarnpkg/fslib": "2.0.0-rc.4", | ||
"@yarnpkg/json-proxy": "2.0.0-rc.2", | ||
"@yarnpkg/parsers": "2.0.0-rc.4", | ||
"@yarnpkg/pnp": "2.0.0-rc.4", | ||
"@yarnpkg/pnp": "2.0.0-rc.5", | ||
"@yarnpkg/shell": "2.0.0-rc.2", | ||
@@ -15,6 +15,7 @@ "agentkeepalive": "^4.0.2", | ||
"chalk": "^2.4.1", | ||
"clipanion": "^2.1.2", | ||
"clipanion": "^2.1.3", | ||
"cross-spawn": "^6.0.5", | ||
"globby": "^8.0.1", | ||
"got": "^9.2.2", | ||
"is-ci": "^2.0.0", | ||
"json-file-plus": "^3.3.1", | ||
@@ -29,3 +30,3 @@ "logic-solver": "^2.0.1", | ||
"stream-to-promise": "^2.2.0", | ||
"supports-color": "^5.5.0", | ||
"supports-color": "^7.1.0", | ||
"tar": "^4.4.6", | ||
@@ -32,0 +33,0 @@ "tmp": "^0.0.33", |
Sorry, the diff of this file is too big to display
289582
6343
26
+ Addedis-ci@^2.0.0
+ Added@yarnpkg/fslib@2.0.0-rc.4(transitive)
+ Added@yarnpkg/pnp@2.0.0-rc.5(transitive)
+ Addedci-info@2.0.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedis-ci@2.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removed@yarnpkg/fslib@2.0.0-rc.3(transitive)
- Removed@yarnpkg/pnp@2.0.0-rc.4(transitive)
Updated@yarnpkg/fslib@2.0.0-rc.4
Updated@yarnpkg/pnp@2.0.0-rc.5
Updatedclipanion@^2.1.3
Updatedsupports-color@^7.1.0