Merge pull request #1425 from balena-io/1304-bump-balena-sdk

Update balena-sdk to v12 and mitigate MaxListenersExceededWarning
This commit is contained in:
Paulo Castro 2019-09-12 13:25:51 +01:00 committed by GitHub
commit 9a40f20004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 177 additions and 42 deletions

View File

@ -108,7 +108,7 @@ module.exports =
helpers = require('../utils/helpers')
Logger = require('../utils/logger')
logger = new Logger()
logger = Logger.getLogger()
logger.logDebug('Parsing input...')
# `build` accepts `[source]` as a parameter, but compose expects it

View File

@ -185,7 +185,7 @@ module.exports =
helpers = require('../utils/helpers')
Logger = require('../utils/logger')
logger = new Logger()
logger = Logger.getLogger()
logger.logDebug('Parsing input...')
# when Capitano converts a positional parameter (but not an option)

View File

@ -66,7 +66,7 @@ export const join: CommandDefinition<Args, Options> = {
const Logger = await import('../utils/logger');
const promote = await import('../utils/promote');
const sdk = balena.fromSharedOptions();
const logger = new Logger();
const logger = Logger.getLogger();
return Bluebird.try(() => {
return promote.join(logger, sdk, params.deviceIp, options.application);
}).nodeify(done);

View File

@ -51,7 +51,7 @@ export const leave: CommandDefinition<Args, {}> = {
const Logger = await import('../utils/logger');
const promote = await import('../utils/promote');
const sdk = balena.fromSharedOptions();
const logger = new Logger();
const logger = Logger.getLogger();
return Bluebird.try(() => {
return promote.leave(logger, sdk, params.deviceIp);
}).nodeify(done);

View File

@ -108,7 +108,7 @@ export const logs: CommandDefinition<
);
const Logger = await import('../utils/logger');
const logger = new Logger();
const logger = Logger.getLogger();
const servicesToDisplay =
options.service != null

View File

@ -94,7 +94,7 @@ export const tunnel: CommandDefinition<Args, Options> = {
const deviceOrApplication =
params.deviceOrApplication_raw || params.deviceOrApplication;
const Logger = await import('../utils/logger');
const logger = new Logger();
const logger = Logger.getLogger();
const balena = await import('balena-sdk');
const sdk = balena.fromSharedOptions();

View File

@ -1,9 +1,26 @@
import { BalenaSDK } from 'balena-sdk';
/**
* @license
* Copyright 2019 Balena Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BalenaSDK, Service } from 'balena-sdk';
import memoize = require('lodash/memoize');
export const serviceIdToName = memoize(
async (sdk: BalenaSDK, serviceId: number): Promise<string | undefined> => {
const serviceName = await sdk.pine.get({
const serviceName = await sdk.pine.get<Service>({
resource: 'service',
id: serviceId,
options: {

View File

@ -38,7 +38,7 @@ import { displayBuildLog } from './logs';
// Define the logger here so the debug output
// can be used everywhere
const globalLogger = new Logger();
const globalLogger = Logger.getLogger();
export interface DeviceDeployOptions {
source: string;

View File

@ -134,7 +134,9 @@ export function getArchAndDeviceType(
getApplication(applicationName),
balena.models.config.getDeviceTypes(),
function(app, deviceTypes) {
const config = _.find(deviceTypes, { slug: app.device_type });
const config = _.find<BalenaSdk.DeviceType>(deviceTypes, {
slug: app.device_type,
});
if (!config) {
throw new Error('Could not read application information!');
@ -150,7 +152,7 @@ export function getApplication(applicationName: string) {
// that off to a special handler (before importing any modules)
const match = applicationName.split('/');
const extraOptions = {
const extraOptions: BalenaSdk.PineOptionsFor<BalenaSdk.Application> = {
$expand: {
application_type: {
$select: ['name', 'slug', 'supports_multicontainer', 'is_legacy'],

View File

@ -19,6 +19,13 @@ import _ = require('lodash');
import { EOL as eol } from 'os';
import { StreamLogger } from 'resin-stream-logger';
/**
* General purpose logger class with support for log streams and colours.
* Call `Logger.getLogger()` to retrieve a global shared instance of this
* class. The `new Logger()` pattern is not recommended because it may lead
* to Node printing "MaxListenersExceededWarning" warning messages to the
* console.
*/
class Logger {
public streams: {
build: NodeJS.ReadWriteStream;
@ -33,7 +40,7 @@ class Logger {
public formatMessage: (name: string, message: string) => string;
constructor() {
protected constructor() {
const logger = new StreamLogger();
logger.addPrefix('build', chalk.blue('[Build]'));
logger.addPrefix('info', chalk.cyan('[Info]'));
@ -64,6 +71,16 @@ class Logger {
this.formatMessage = logger.formatWithPrefix.bind(logger);
}
protected static logger: Logger;
/** Retrieve a global shared instance of this class */
public static getLogger() {
if (!this.logger) {
this.logger = new Logger();
}
return this.logger;
}
public logInfo(msg: string) {
return this.streams.info.write(msg + eol);
}

View File

@ -333,7 +333,7 @@ export async function getOnlineTargetUuid(
applicationOrDevice: string,
) {
const Logger = await import('../utils/logger');
const logger = new Logger();
const logger = Logger.getLogger();
const appTest = validation.validateApplicationName(applicationOrDevice);
const uuidTest = validation.validateUuid(applicationOrDevice);

153
npm-shrinkwrap.json generated
View File

@ -511,8 +511,7 @@
"@types/common-tags": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@types/common-tags/-/common-tags-1.4.0.tgz",
"integrity": "sha512-HI1tSO87vmd1sPS3DOVSK4gvVKROvCBFvAnXlLiQtAus/+1xXMQcNyu9TX2ChwRXFeQZeB9+f+nMo99xLd5DdA==",
"dev": true
"integrity": "sha512-HI1tSO87vmd1sPS3DOVSK4gvVKROvCBFvAnXlLiQtAus/+1xXMQcNyu9TX2ChwRXFeQZeB9+f+nMo99xLd5DdA=="
},
"@types/depcheck": {
"version": "0.6.0",
@ -1749,6 +1748,41 @@
"mkdirp": "^0.5.1",
"rimraf": "^2.4.1",
"semver": "^5.3.0"
},
"dependencies": {
"@types/node": {
"version": "8.10.54",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.54.tgz",
"integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg=="
},
"balena-sdk": {
"version": "11.18.2",
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-11.18.2.tgz",
"integrity": "sha512-1umbGqBJc+18vVzKsHW8Q/8RFjqWbHY2VoZGVG96prqYjXxFIIprcoSaNY7IHaqAFkuo+xzd5ieHBo2RUNT1iw==",
"requires": {
"@types/bluebird": "3.5.21",
"@types/common-tags": "^1.4.0",
"@types/node": "^8.0.53",
"abortcontroller-polyfill": "^1.1.9",
"balena-auth": "^3.0.0",
"balena-errors": "^4.0.0",
"balena-hup-action-utils": "~1.2.0",
"balena-pine": "^9.0.0",
"balena-register-device": "^6.0.0",
"balena-request": "^10.0.0",
"balena-semver": "^2.0.0",
"balena-settings-client": "^4.0.0",
"bluebird": "^3.3.1",
"common-tags": "^1.8.0",
"lodash": "^4.4.0",
"memoizee": "^0.4.9",
"moment": "^2.18.1",
"ndjson": "^1.5.0",
"promise-memoize": "^1.2.0",
"resin-device-status": "^1.0.1",
"semver": "^5.3.0"
}
}
}
},
"balena-pine": {
@ -1802,6 +1836,39 @@
"unzipper": "^0.8.9"
},
"dependencies": {
"@types/node": {
"version": "8.10.54",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.54.tgz",
"integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg=="
},
"balena-sdk": {
"version": "11.18.2",
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-11.18.2.tgz",
"integrity": "sha512-1umbGqBJc+18vVzKsHW8Q/8RFjqWbHY2VoZGVG96prqYjXxFIIprcoSaNY7IHaqAFkuo+xzd5ieHBo2RUNT1iw==",
"requires": {
"@types/bluebird": "3.5.21",
"@types/common-tags": "^1.4.0",
"@types/node": "^8.0.53",
"abortcontroller-polyfill": "^1.1.9",
"balena-auth": "^3.0.0",
"balena-errors": "^4.0.0",
"balena-hup-action-utils": "~1.2.0",
"balena-pine": "^9.0.0",
"balena-register-device": "^6.0.0",
"balena-request": "^10.0.0",
"balena-semver": "^2.0.0",
"balena-settings-client": "^4.0.0",
"bluebird": "^3.3.1",
"common-tags": "^1.8.0",
"lodash": "^4.4.0",
"memoizee": "^0.4.9",
"moment": "^2.18.1",
"ndjson": "^1.5.0",
"promise-memoize": "^1.2.0",
"resin-device-status": "^1.0.1",
"semver": "^5.3.0"
}
},
"bl": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz",
@ -1921,17 +1988,18 @@
}
},
"balena-sdk": {
"version": "11.18.2",
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-11.18.2.tgz",
"integrity": "sha512-1umbGqBJc+18vVzKsHW8Q/8RFjqWbHY2VoZGVG96prqYjXxFIIprcoSaNY7IHaqAFkuo+xzd5ieHBo2RUNT1iw==",
"version": "12.10.0",
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-12.10.0.tgz",
"integrity": "sha512-nE3zJ5heZPVYBnoQPUo/uEFXyCtaDXOItIDcMAMBaCBurTQDHlbfg1d/C62ahBti2mowI927eIHqAQ4Huyrglw==",
"requires": {
"@types/bluebird": "3.5.21",
"@types/common-tags": "^1.4.0",
"@types/node": "^8.0.53",
"abortcontroller-polyfill": "^1.1.9",
"balena-auth": "^3.0.0",
"balena-errors": "^4.0.0",
"balena-hup-action-utils": "~1.2.0",
"balena-device-status": "^3.1.0",
"balena-errors": "^4.1.0",
"balena-hup-action-utils": "~3.0.0",
"balena-pine": "^9.0.0",
"balena-register-device": "^6.0.0",
"balena-request": "^10.0.0",
@ -1944,19 +2012,22 @@
"moment": "^2.18.1",
"ndjson": "^1.5.0",
"promise-memoize": "^1.2.0",
"resin-device-status": "^1.0.1",
"semver": "^5.3.0"
},
"dependencies": {
"@types/common-tags": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@types/common-tags/-/common-tags-1.8.0.tgz",
"integrity": "sha512-htRqZr5qn8EzMelhX/Xmx142z218lLyGaeZ3YR8jlze4TATRU9huKKvuBmAJEW4LCC4pnY1N6JAm6p85fMHjhg=="
},
"@types/node": {
"version": "8.10.49",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.49.tgz",
"integrity": "sha512-YX30JVx0PvSmJ3Eqr74fYLGeBxD+C7vIL20ek+GGGLJeUbVYRUW3EzyAXpIRA0K8c8o0UWqR/GwEFYiFoz1T8w=="
"version": "8.10.54",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.54.tgz",
"integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg=="
},
"balena-hup-action-utils": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/balena-hup-action-utils/-/balena-hup-action-utils-3.0.0.tgz",
"integrity": "sha512-vBRfcA7iBBvsY61ORpRFYGj65UmKwmsT0lZPA3lokCn8f3fDAqjXn5+c1kRH/i48HoU55FuPy2qqcuDNdqRr9w==",
"requires": {
"balena-semver": "^2.0.0",
"lodash": "^4.17.11"
}
}
}
},
@ -1971,15 +2042,10 @@
"semver": "^5.3.0"
},
"dependencies": {
"@types/lodash": {
"version": "4.14.121",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.121.tgz",
"integrity": "sha512-ORj7IBWj13iYufXt/VXrCNMbUuCTJfhzme5kx9U/UtcIPdJYuvPDUAlHlbNhz/8lKCLy9XGIZnGrqXOtQbPGoQ=="
},
"@types/semver": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-6.0.1.tgz",
"integrity": "sha512-ffCdcrEE5h8DqVxinQjo+2d1q+FV5z7iNtPofw3JsrltSoSVlOGaW0rY8XxtO9XukdTn8TaCGWmk2VFGhI70mg=="
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-6.0.2.tgz",
"integrity": "sha512-G1Ggy7/9Nsa1Jt2yiBR2riEuyK2DFNnqow6R7cromXPMNynackRY1vqFTLz/gwnef1LHokbXThcPhqMRjUbkpQ=="
}
}
},
@ -2051,6 +2117,11 @@
"underscore.string": "^3.2.3"
},
"dependencies": {
"@types/node": {
"version": "8.10.54",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.54.tgz",
"integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg=="
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
@ -2061,6 +2132,34 @@
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4="
},
"balena-sdk": {
"version": "11.18.2",
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-11.18.2.tgz",
"integrity": "sha512-1umbGqBJc+18vVzKsHW8Q/8RFjqWbHY2VoZGVG96prqYjXxFIIprcoSaNY7IHaqAFkuo+xzd5ieHBo2RUNT1iw==",
"requires": {
"@types/bluebird": "3.5.21",
"@types/common-tags": "^1.4.0",
"@types/node": "^8.0.53",
"abortcontroller-polyfill": "^1.1.9",
"balena-auth": "^3.0.0",
"balena-errors": "^4.0.0",
"balena-hup-action-utils": "~1.2.0",
"balena-pine": "^9.0.0",
"balena-register-device": "^6.0.0",
"balena-request": "^10.0.0",
"balena-semver": "^2.0.0",
"balena-settings-client": "^4.0.0",
"bluebird": "^3.3.1",
"common-tags": "^1.8.0",
"lodash": "^4.4.0",
"memoizee": "^0.4.9",
"moment": "^2.18.1",
"ndjson": "^1.5.0",
"promise-memoize": "^1.2.0",
"resin-device-status": "^1.0.1",
"semver": "^5.3.0"
}
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
@ -16990,9 +17089,9 @@
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"typescript": {
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.3.tgz",
"integrity": "sha512-FFgHdPt4T/duxx6Ndf7hwgMZZjZpB+U0nMNGVCYPq0rEzWKjEDobm4J6yb3CS7naZ0yURFqdw9Gwc7UOh/P9oQ==",
"version": "3.4.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz",
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==",
"dev": true
},
"udif": {

View File

@ -135,7 +135,7 @@
"shell-escape": "^0.2.0",
"sinon": "^7.4.1",
"ts-node": "^8.1.0",
"typescript": "3.4.3"
"typescript": "^3.4.5"
},
"dependencies": {
"@oclif/command": "^1.5.12",
@ -151,7 +151,7 @@
"balena-device-status": "^3.1.2",
"balena-image-manager": "^6.0.0",
"balena-preload": "^8.2.1",
"balena-sdk": "^11.18.0",
"balena-sdk": "^12.10.0",
"balena-settings-client": "^4.0.0",
"balena-sync": "^10.0.3",
"bash": "0.0.1",