Bump min Node.js version to 8.0, ts-node to 8.1 and typescript to 3.4.

Refactor typings folder for use with the tsconfig typeRoots option.

Change-type: major
Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
Paulo Castro 2019-04-25 18:39:16 +01:00
parent faa558b432
commit 13e3e5e8ea
43 changed files with 367 additions and 123 deletions

View File

@ -3,7 +3,7 @@ os:
- linux
- osx
node_js:
- "6"
- "8"
before_install:
- npm -g install npm@4
script: npm run ci

View File

@ -14,7 +14,7 @@ matrix:
# what combinations to test
environment:
matrix:
- nodejs_version: 6
- nodejs_version: 8
install:
- ps: Install-Product node $env:nodejs_version x64

View File

@ -1,38 +0,0 @@
declare module 'pkg' {
export function exec(args: string[]): Promise<void>;
}
declare module 'filehound' {
export function create(): FileHound;
export interface FileHound {
paths(paths: string[]): FileHound;
paths(...paths: string[]): FileHound;
ext(extensions: string[]): FileHound;
ext(...extensions: string[]): FileHound;
find(): Promise<string[]>;
}
}
declare module 'publish-release' {
interface PublishOptions {
token: string;
owner: string;
repo: string;
tag: string;
name: string;
reuseRelease?: boolean;
assets: string[];
}
interface Release {
html_url: string;
}
let publishRelease: (
args: PublishOptions,
callback: (e: Error, release: Release) => void,
) => void;
export = publishRelease;
}

View File

@ -1,16 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"target": "es2017",
"strict": true,
"strictPropertyInitialization": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true
},
"include": [
"./**/*.ts",
"../typings/*.d.ts"
]
"sourceMap": true,
"skipLibCheck": true,
"typeRoots" : [
"../node_modules/@types",
"../typings"
]
}
}

View File

@ -12,8 +12,12 @@ process.env.UV_THREADPOOL_SIZE = '64';
// Use fast-boot to cache require lookups, speeding up startup
require('fast-boot2').start({
cacheFile: '.fast-boot.json'
})
process.env['TS_NODE_PROJECT'] = require('path').dirname(__dirname);
});
require('coffeescript/register');
require('ts-node/register');
// Note: before ts-node v6.0.0, 'transpile-only' (no type checking) was the
// default option. We upgraded ts-node and found that adding 'transpile-only'
// was necessary to avoid a mysterious 'null' error message. On the plus side,
// it is supposed to run faster. We still benefit from type checking when
// running 'npm run build'.
require('ts-node/register/transpile-only');
require('../lib/app');

View File

@ -15,6 +15,7 @@ limitations under the License.
*/
import { ApplicationVariable, DeviceVariable } from 'balena-sdk';
import * as Bluebird from 'bluebird';
import { CommandDefinition } from 'capitano';
import { stripIndent } from 'common-tags';
@ -73,14 +74,13 @@ export const list: CommandDefinition<
permission: 'user',
async action(_params, options, done) {
normalizeUuidProp(options, 'device');
const Bluebird = await import('bluebird');
const _ = await import('lodash');
const balena = (await import('balena-sdk')).fromSharedOptions();
const visuals = await import('resin-cli-visuals');
const { exitWithExpectedError } = await import('../utils/patterns');
return Bluebird.try(function(): Promise<
return Bluebird.try(function(): Bluebird<
DeviceVariable[] | ApplicationVariable[]
> {
if (options.application) {
@ -209,7 +209,6 @@ export const add: CommandDefinition<
permission: 'user',
async action(params, options, done) {
normalizeUuidProp(options, 'device');
const Bluebird = await import('bluebird');
const _ = await import('lodash');
const balena = (await import('balena-sdk')).fromSharedOptions();
@ -280,7 +279,6 @@ export const rename: CommandDefinition<
permission: 'user',
options: [commandOptions.booleanDevice],
async action(params, options, done) {
const Bluebird = await import('bluebird');
const balena = (await import('balena-sdk')).fromSharedOptions();
return Bluebird.try(function() {

View File

@ -180,8 +180,8 @@ export const tunnel: CommandDefinition<Args, Options> = {
return handler(client)
.then(() => {
logConnection(
client.remoteAddress,
client.remotePort,
client.remoteAddress || '',
client.remotePort || 0,
client.localAddress,
client.localPort,
device.vpn_address || '',
@ -190,8 +190,8 @@ export const tunnel: CommandDefinition<Args, Options> = {
})
.catch(err =>
logConnection(
client.remoteAddress,
client.remotePort,
client.remoteAddress || '',
client.remotePort || 0,
client.localAddress,
client.localPort,
device.vpn_address || '',

25
lib/global.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
/**
* @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.
*/
interface Dictionary<T> {
[key: string]: T;
}
declare module '*/package.json' {
export const name: string;
export const version: string;
}

View File

@ -228,7 +228,8 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
deployOpts: opts,
});
const promises = [livepush.init()];
globalLogger.logLivepush('Watching for file changes...');
const promises: Array<Bluebird<void> | Promise<void>> = [livepush.init()];
// Only show logs if we're not detaching
if (!opts.detached) {
console.log();

View File

@ -98,7 +98,7 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
output: process.stdout,
});
rl.on('SIGINT', () => process.emit('SIGINT'));
rl.on('SIGINT', () => process.emit('SIGINT' as any));
}
return new Bluebird((resolve, reject) => {

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import * as Bluebird from 'bluebird';
import { spawn } from 'child_process';
import { spawn, StdioOptions } from 'child_process';
import { TypedError } from 'typed-error';
import { getSubShellCommand } from './helpers';
@ -45,7 +45,7 @@ export async function exec(
root@${deviceIp} \
${cmd}`;
const stdio = ['ignore', stdout ? 'pipe' : 'inherit', 'ignore'];
const stdio: StdioOptions = ['ignore', stdout ? 'pipe' : 'inherit', 'ignore'];
const { program, args } = getSubShellCommand(command);
const exitCode = await new Bluebird<number>((resolve, reject) => {

View File

@ -1,4 +1,20 @@
import { spawn } from 'child_process';
/**
* @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 { spawn, StdioOptions } from 'child_process';
import * as Bluebird from 'bluebird';
import * as rindle from 'rindle';
@ -7,9 +23,14 @@ export async function executeWithPrivileges(
command: string[],
stderr?: NodeJS.WritableStream,
): Promise<string> {
const stdio: StdioOptions = [
'inherit',
'inherit',
stderr ? 'pipe' : 'inherit',
];
const opts = {
stdio: ['inherit', 'inherit', stderr ? 'pipe' : 'inherit'],
env: process.env,
stdio,
};
const args = process.argv

View File

@ -35,9 +35,9 @@
"build": "npm run build:src && npm run build:bin",
"build:src": "npm run prettify && npm run lint && npm run build:fast && npm run build:doc",
"build:fast": "gulp build && tsc",
"build:doc": "mkdirp doc/ && ts-node automation/capitanodoc/index.ts > doc/cli.markdown",
"build:bin": "ts-node --type-check -P automation automation/build-bin.ts",
"release": "npm run build && ts-node --type-check -P automation automation/deploy-bin.ts",
"build:doc": "mkdirp doc/ && ts-node --type-check -P automation/tsconfig.json automation/capitanodoc/index.ts > doc/cli.markdown",
"build:bin": "ts-node --type-check -P automation/tsconfig.json automation/build-bin.ts",
"release": "npm run build && ts-node --type-check -P automation/tsconfig.json automation/deploy-bin.ts",
"pretest": "npm run build",
"test": "gulp test",
"test:fast": "npm run build:fast && gulp test",
@ -60,7 +60,7 @@
"author": "Juan Cruz Viotti <juan@balena.io>",
"license": "Apache-2.0",
"engines": {
"node": ">=6.0"
"node": ">=8.0"
},
"devDependencies": {
"@types/archiver": "2.1.2",
@ -76,7 +76,7 @@
"@types/mkdirp": "0.5.2",
"@types/mz": "0.0.32",
"@types/net-keepalive": "^0.4.0",
"@types/node": "6.14.2",
"@types/node": "10.14.5",
"@types/prettyjson": "0.0.28",
"@types/raven": "2.5.1",
"@types/request": "2.48.1",
@ -100,8 +100,8 @@
"require-npm4-to-publish": "^1.0.0",
"resin-lint": "^3.0.1",
"rewire": "^3.0.2",
"ts-node": "^4.0.1",
"typescript": "2.8.1"
"ts-node": "^8.1.0",
"typescript": "3.4.3"
},
"dependencies": {
"@resin.io/valid-email": "^0.1.0",

View File

@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "es2017",
"outDir": "build",
"strict": true,
"strictPropertyInitialization": false,
@ -11,20 +11,13 @@
"removeComments": true,
"sourceMap": true,
"skipLibCheck": true,
"lib": [
// es5 defaults:
"dom",
"es5",
"scripthost",
// some specific es6 bits we're sure are safe:
"es2015.collection",
"es2015.iterable",
"es2016.array.include"
"typeRoots" : [
"./node_modules/@types",
"./node_modules/etcher-sdk/typings",
"./typings"
]
},
"include": [
"./typings/*.d.ts",
"./node_modules/etcher-sdk/typings/**/*.d.ts",
"./lib/**/*.ts"
]
}

View File

@ -1 +0,0 @@
declare module '@resin.io/valid-email';

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'balena-device-init' {
import { DeviceType } from 'balena-sdk';
import * as Promise from 'bluebird';

View File

@ -1,5 +0,0 @@
declare module 'balena-sync' {
import { CommandDefinition } from 'capitano';
export function capitano(tool: 'balena-cli'): CommandDefinition;
}

22
typings/balena-sync/index.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
/**
* @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.
*/
declare module 'balena-sync' {
import { CommandDefinition } from 'capitano';
export function capitano(tool: 'balena-cli'): CommandDefinition;
}

View File

@ -1,3 +1,20 @@
/**
* @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.
*/
declare module 'capitano' {
export function parse(argv: string[]): Cli;

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'color-hash' {
interface Hasher {
hex(text: string): string;

View File

@ -1,13 +0,0 @@
declare module 'dockerfile-template' {
/**
* Variables which define what will be replaced, and what they will be replaced with.
*/
export interface TemplateVariables {
[key: string]: string;
}
export function process(
content: string,
variables: TemplateVariables,
): string;
}

30
typings/dockerfile-template/index.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
/**
* @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.
*/
declare module 'dockerfile-template' {
/**
* Variables which define what will be replaced, and what they will be replaced with.
*/
export interface TemplateVariables {
[key: string]: string;
}
export function process(
content: string,
variables: TemplateVariables,
): string;
}

1
typings/ent.d.ts vendored
View File

@ -1 +0,0 @@
declare module 'ent';

18
typings/ent/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
/**
* @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.
*/
declare module 'ent';

28
typings/filehound/index.d.ts vendored Normal file
View File

@ -0,0 +1,28 @@
/**
* @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.
*/
declare module 'filehound' {
export function create(): FileHound;
export interface FileHound {
paths(paths: string[]): FileHound;
paths(...paths: string[]): FileHound;
ext(extensions: string[]): FileHound;
ext(...extensions: string[]): FileHound;
find(): Promise<string[]>;
}
}

3
typings/global.d.ts vendored
View File

@ -1,3 +0,0 @@
interface Dictionary<T> {
[key: string]: T;
}

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'inquirer-dynamic-list' {
interface Choice {
name: string;

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'nplugm' {
import Promise = require('bluebird');
export function list(regexp: RegExp): Promise<string[]>;

View File

@ -1,4 +0,0 @@
declare module '*/package.json' {
export const name: string;
export const version: string;
}

20
typings/pkg/index.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
/**
* @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.
*/
declare module 'pkg' {
export function exec(args: string[]): Promise<void>;
}

View File

@ -1,6 +0,0 @@
declare module 'president' {
export function execute(
command: string[],
callback: (err: Error) => void,
): void;
}

23
typings/president/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
/**
* @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.
*/
declare module 'president' {
export function execute(
command: string[],
callback: (err: Error) => void,
): void;
}

39
typings/publish-release/index.d.ts vendored Normal file
View File

@ -0,0 +1,39 @@
/**
* @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.
*/
declare module 'publish-release' {
interface PublishOptions {
token: string;
owner: string;
repo: string;
tag: string;
name: string;
reuseRelease?: boolean;
assets: string[];
}
interface Release {
html_url: string;
}
let publishRelease: (
args: PublishOptions,
callback: (e: Error, release: Release) => void,
) => void;
export = publishRelease;
}

View File

@ -1 +0,0 @@
declare module 'resin-cli-form';

18
typings/resin-cli-form/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
/**
* @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.
*/
declare module 'resin-cli-form';

View File

@ -1 +0,0 @@
declare module 'resin-cli-visuals';

18
typings/resin-cli-visuals/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
/**
* @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.
*/
declare module 'resin-cli-visuals';

View File

@ -1,5 +0,0 @@
declare module 'resin-image-fs' {
import Promise = require('bluebird');
export function readFile(options: {}): Promise<string>;
}

22
typings/resin-image-fs/index.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
/**
* @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.
*/
declare module 'resin-image-fs' {
import Promise = require('bluebird');
export function readFile(options: {}): Promise<string>;
}

18
typings/resin.io/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
/**
* @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.
*/
declare module '@resin.io/valid-email';

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'rindle' {
export function extract(
stream: NodeJS.ReadableStream,