From 4d4e5cd4dca78480ec7f40e747f424cd107376a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 5 Jun 2017 21:53:49 +0200 Subject: [PATCH] require -> import --- package.json | 2 ++ server.ts | 13 +++++++------ server/controllers/api/clients.ts | 2 +- server/controllers/api/config.ts | 2 +- server/controllers/api/index.ts | 2 +- server/controllers/api/pods.ts | 2 +- server/controllers/api/remote/index.ts | 2 +- server/controllers/api/remote/pods.ts | 2 +- server/controllers/api/remote/videos.ts | 2 +- server/controllers/api/requests.ts | 2 +- server/controllers/api/users.ts | 2 +- server/controllers/api/videos/abuse.ts | 4 ++-- server/controllers/api/videos/blacklist.ts | 2 +- server/controllers/api/videos/index.ts | 8 ++++---- server/controllers/api/videos/rate.ts | 2 +- server/controllers/client.ts | 8 +++----- server/controllers/static.ts | 4 ++-- server/helpers/custom-validators/pods.ts | 4 +--- server/helpers/custom-validators/users.ts | 4 +--- server/helpers/custom-validators/videos.ts | 4 +--- server/helpers/database-utils.ts | 2 +- server/helpers/logger.ts | 6 +++--- server/helpers/peertube-crypto.ts | 8 ++++---- server/helpers/requests.ts | 4 ++-- server/initializers/checker.ts | 2 +- server/initializers/constants.ts | 2 +- server/initializers/database.ts | 4 ++-- server/initializers/installer.ts | 6 +++--- server/initializers/migrator.ts | 4 ++-- server/lib/friends.ts | 2 +- server/middlewares/oauth.ts | 2 +- server/models/video.ts | 12 ++++++------ yarn.lock | 6 +++++- 33 files changed, 66 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index 118a0aef6..e7d0c39a4 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "scripty": "^1.5.0", "sequelize": "4.0.0-2", "typescript": "~2.2.0", + "validator": "^7.0.0", "winston": "^2.1.1", "ws": "^2.0.0" }, @@ -86,6 +87,7 @@ "@types/node": "^7.0.18", "@types/request": "^0.0.43", "@types/sequelize": "^4.0.55", + "@types/validator": "^6.2.0", "@types/winston": "^2.3.2", "@types/ws": "^0.0.41", "chai": "^3.3.0", diff --git a/server.ts b/server.ts index f5413b8e3..b27a83860 100644 --- a/server.ts +++ b/server.ts @@ -3,13 +3,14 @@ if ([ 'dev', 'test'].indexOf(process.env.NODE_ENV) !== -1) { } // ----------- Node modules ----------- -import bodyParser = require('body-parser') -import express = require('express') +import * as bodyParser from 'body-parser' +import * as express from 'express' +// FIXME: cannot import express-validator const expressValidator = require('express-validator') -import http = require('http') -import morgan = require('morgan') -import path = require('path') -import bittorrentTracker = require('bittorrent-tracker') +import * as http from 'http' +import * as morgan from 'morgan' +import * as path from 'path' +import * as bittorrentTracker from 'bittorrent-tracker' import { Server as WebSocketServer } from 'ws' const TrackerServer = bittorrentTracker.Server diff --git a/server/controllers/api/clients.ts b/server/controllers/api/clients.ts index 614163c83..f6499556a 100644 --- a/server/controllers/api/clients.ts +++ b/server/controllers/api/clients.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { CONFIG } from '../../initializers'; import { logger } from '../../helpers' diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 8bdde61b3..57c9398ec 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { CONFIG } from '../../initializers' diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 18bef2d3d..98004544d 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { badRequest } from '../../helpers' diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts index 4ff1f5d9f..a028c4ab9 100644 --- a/server/controllers/api/pods.ts +++ b/server/controllers/api/pods.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { waterfall } from 'async' import { database as db } from '../../initializers/database' diff --git a/server/controllers/api/remote/index.ts b/server/controllers/api/remote/index.ts index b11439204..d3522772b 100644 --- a/server/controllers/api/remote/index.ts +++ b/server/controllers/api/remote/index.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { badRequest } from '../../../helpers' diff --git a/server/controllers/api/remote/pods.ts b/server/controllers/api/remote/pods.ts index 7a9a0c4f0..9c9d2164d 100644 --- a/server/controllers/api/remote/pods.ts +++ b/server/controllers/api/remote/pods.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import * as waterfall from 'async/waterfall' import { database as db } from '../../../initializers/database' diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index 178a21e7c..d97a3db31 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { eachSeries, waterfall } from 'async' import { database as db } from '../../../initializers/database' diff --git a/server/controllers/api/requests.ts b/server/controllers/api/requests.ts index 304499a4f..ff4b4ac1a 100644 --- a/server/controllers/api/requests.ts +++ b/server/controllers/api/requests.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { parallel } from 'async' import { diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 97a744f54..44c5ec13c 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { waterfall } from 'async' import { database as db } from '../../initializers/database' diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 3dd884354..68db025b7 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -1,8 +1,8 @@ -import express = require('express') +import * as express from 'express' import { waterfall } from 'async' import { database as db } from '../../../initializers/database' -import friends = require('../../../lib/friends') +import * as friends from '../../../lib/friends' import { logger, getFormatedObjects, diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index fb4d57d7b..58960798b 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { database as db } from '../../../initializers/database' import { logger } from '../../../helpers' diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 6eda7159b..b82b0936f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -1,7 +1,7 @@ -import express = require('express') -import fs = require('fs') -import multer = require('multer') -import path = require('path') +import * as express from 'express' +import * as fs from 'fs' +import * as multer from 'multer' +import * as path from 'path' import { waterfall } from 'async' import { database as db } from '../../../initializers/database' diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 571ff68e3..1bc575675 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts @@ -1,4 +1,4 @@ -import express = require('express') +import * as express from 'express' import { waterfall } from 'async' import { database as db } from '../../../initializers/database' diff --git a/server/controllers/client.ts b/server/controllers/client.ts index ce5608c9b..c3d28245c 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts @@ -1,10 +1,8 @@ import { parallel } from 'async' -import express = require('express') -import fs = require('fs') +import * as express from 'express' +import * as fs from 'fs' import { join } from 'path' -import expressValidator = require('express-validator') -// TODO: use .validator when express-validator typing will have validator field -const validator = expressValidator['validator'] +import * as validator from 'validator' import { database as db } from '../initializers/database' import { diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 51f75c57e..e65282339 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -1,5 +1,5 @@ -import express = require('express') -import cors = require('cors') +import * as express from 'express' +import * as cors from 'cors' import { CONFIG, diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts index e4c827feb..ee939ad04 100644 --- a/server/helpers/custom-validators/pods.ts +++ b/server/helpers/custom-validators/pods.ts @@ -1,6 +1,4 @@ -import expressValidator = require('express-validator') -// TODO: use .validator when express-validator typing will have validator field -const validator = expressValidator['validator'] +import * as validator from 'validator' import { isArray } from './misc' diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 8fd2dac4f..f303ab8db 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,7 +1,5 @@ import { values } from 'lodash' -import expressValidator = require('express-validator') -// TODO: use .validator when express-validator typing will have validator field -const validator = expressValidator['validator'] +import * as validator from 'validator' import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers' const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 2b2370be4..6389998e1 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -1,7 +1,5 @@ import { values } from 'lodash' -import expressValidator = require('express-validator') -// TODO: use .validator when express-validator typing will have validator field -const validator = expressValidator['validator'] +import * as validator from 'validator' import { CONSTRAINTS_FIELDS, diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 7d6ce4ec8..4f49c5825 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -1,5 +1,5 @@ // TODO: import from ES6 when retry typing file will include errorFilter function -import retry = require('async/retry') +import * as retry from 'async/retry' import { database as db } from '../initializers/database' import { logger } from './logger' diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 7c99db55f..d8f2f687c 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -1,7 +1,7 @@ // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ -import mkdirp = require('mkdirp') -import path = require('path') -import winston = require('winston') +import * as mkdirp from 'mkdirp' +import * as path from 'path' +import * as winston from 'winston' // Do not use barrel (dependencies issues) import { CONFIG } from '../initializers/constants' diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index a4e9672e6..feb32a4cd 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,7 +1,7 @@ -import crypto = require('crypto') -import bcrypt = require('bcrypt') -import fs = require('fs') -import openssl = require('openssl-wrapper') +import * as crypto from 'crypto' +import * as bcrypt from 'bcrypt' +import * as fs from 'fs' +import * as openssl from 'openssl-wrapper' import { join } from 'path' import { diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 8ded52972..48b1fd703 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -1,5 +1,5 @@ -import replay = require('request-replay') -import request = require('request') +import * as replay from 'request-replay' +import * as request from 'request' import { RETRY_REQUESTS, diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index 0ee01b0e3..8c3d64b60 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts @@ -1,4 +1,4 @@ -import config = require('config') +import * as config from 'config' import { database as db } from './database' import { CONFIG } from './constants' diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 1072d0de0..7ab019f44 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -1,4 +1,4 @@ -import config = require('config') +import * as config from 'config' import { join } from 'path' // Do not use barrels, remain constants as independent as possible diff --git a/server/initializers/database.ts b/server/initializers/database.ts index c89a8b23c..b0f47876e 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -1,6 +1,6 @@ -import fs = require('fs') +import * as fs from 'fs' import { join } from 'path' -import Sequelize = require('sequelize') +import * as Sequelize from 'sequelize' import { CONFIG } from './constants' // Do not use barrel, we need to load database first diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 467164107..2f9b58991 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -1,8 +1,8 @@ import { join } from 'path' -import config = require('config') +import * as config from 'config' import { each, series } from 'async' -import mkdirp = require('mkdirp') -import passwordGenerator = require('password-generator') +import * as mkdirp from 'mkdirp' +import * as passwordGenerator from 'password-generator' import { database as db } from './database' import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION } from './constants' diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts index d42cb3ccc..379d43af5 100644 --- a/server/initializers/migrator.ts +++ b/server/initializers/migrator.ts @@ -1,6 +1,6 @@ import { waterfall, eachSeries } from 'async' -import fs = require('fs') -import path = require('path') +import * as fs from 'fs' +import * as path from 'path' import * as Sequelize from 'sequelize' import { database as db } from './database' diff --git a/server/lib/friends.ts b/server/lib/friends.ts index 08b776e83..6b0fbd2bf 100644 --- a/server/lib/friends.ts +++ b/server/lib/friends.ts @@ -1,5 +1,5 @@ import { each, eachLimit, eachSeries, series, waterfall } from 'async' -import request = require('request') +import * as request from 'request' import { database as db } from '../initializers/database' import { diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 07bbded57..468e41810 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -1,4 +1,4 @@ -import OAuthServer = require('express-oauth-server') +import * as OAuthServer from 'express-oauth-server' import { OAUTH_LIFETIME } from '../initializers' import { logger } from '../helpers' diff --git a/server/models/video.ts b/server/models/video.ts index 9284dfeba..5558a7c3b 100644 --- a/server/models/video.ts +++ b/server/models/video.ts @@ -1,12 +1,12 @@ -import safeBuffer = require('safe-buffer') +import * as safeBuffer from 'safe-buffer' const Buffer = safeBuffer.Buffer -import createTorrent = require('create-torrent') -import ffmpeg = require('fluent-ffmpeg') -import fs = require('fs') -import magnetUtil = require('magnet-uri') +import * as createTorrent from 'create-torrent' +import * as ffmpeg from 'fluent-ffmpeg' +import * as fs from 'fs' +import * as magnetUtil from 'magnet-uri' import { map, values } from 'lodash' import { parallel, series } from 'async' -import parseTorrent = require('parse-torrent') +import * as parseTorrent from 'parse-torrent' import { join } from 'path' import * as Sequelize from 'sequelize' diff --git a/yarn.lock b/yarn.lock index 857aa92e6..28d33fa97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -92,7 +92,7 @@ "@types/express-serve-static-core" "*" "@types/mime" "*" -"@types/validator@*": +"@types/validator@*", "@types/validator@^6.2.0": version "6.2.0" resolved "https://registry.yarnpkg.com/@types/validator/-/validator-6.2.0.tgz#020322fe1929f69889eb675a1bdb5a98394b71f0" @@ -3382,6 +3382,10 @@ validator@^5.6.0: version "5.7.0" resolved "https://registry.yarnpkg.com/validator/-/validator-5.7.0.tgz#7a87a58146b695ac486071141c0c49d67da05e5c" +validator@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-7.0.0.tgz#c74deb8063512fac35547938e6f0b1504a282fd2" + validator@~6.2.0: version "6.2.1" resolved "https://registry.yarnpkg.com/validator/-/validator-6.2.1.tgz#bc575b78d15beb2e338a665ba9530c7f409ef667" -- 2.41.0