0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

feature: Update Build pipeline for Babel transpiler (#349)

feature: Update Build pipeline for Babel transpiler
This commit is contained in:
Juan Picado @jotadeveloper 2017-10-22 12:28:38 +02:00 committed by juanpicado
parent 6a0d539b61
commit a5e162d475
15 changed files with 261 additions and 212 deletions

View file

@ -1,4 +1,6 @@
{
"env": {
"ui": {
"presets": [
"react",
["env",{
@ -21,8 +23,16 @@
"transform-runtime",
"transform-object-rest-spread",
"transform-decorators-legacy"
]
},
"registry": {
"presets": [
"es2015-node4", "flow"
],
"env": {
"plugins": [
"transform-object-rest-spread"
]
},
"development": {
"presets": ["flow"],
"plugins": [

View file

@ -15,8 +15,8 @@
"verdaccio": "./bin/verdaccio"
},
"dependencies": {
"@verdaccio/file-locking": "0.0.5",
"@verdaccio/local-storage": "^0.0.10",
"@verdaccio/file-locking": "^0.0.5",
"@verdaccio/local-storage": "^0.0.11",
"@verdaccio/streams": "^0.0.2",
"@verdaccio/types": "^0.0.7",
"JSONStream": "^1.1.1",
@ -50,20 +50,26 @@
},
"devDependencies": {
"axios": "0.16.2",
"babel-cli": "6.24.1",
"babel-core": "6.25.0",
"babel-eslint": "7.2.3",
"babel-loader": "7.1.1",
"babel-cli": "^6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.0.1",
"babel-loader": "7.1.2",
"babel-plugin-flow-runtime": "0.11.1",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-es2015-classes": "^6.24.1",
"babel-plugin-transform-runtime": "6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "1.5.2",
"babel-preset-env": "1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-node4": "2.1.0",
"babel-preset-flow": "6.23.0",
"babel-preset-react": "6.24.1",
"babel-preset-stage-2": "6.24.1",
"babel-preset-stage-3": "6.24.1",
"babel-runtime": "6.23.0",
"babel-register": "^6.26.0",
"babel-runtime": "6.26.0",
"babel-jest": "^21.2.0",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"codacy-coverage": "2.0.2",
"codecov": "2.2.0",
"coveralls": "2.13.1",
@ -87,7 +93,7 @@
"html-webpack-plugin": "2.29.0",
"in-publish": "2.0.0",
"localstorage-memory": "1.0.2",
"mocha": "3.4.2",
"mocha": "3.5.3",
"mocha-lcov-reporter": "1.3.0",
"node-sass": "4.5.3",
"normalize.css": "7.0.0",
@ -126,7 +132,7 @@
"release": "standard-version -a -s",
"prepublish": "in-publish && npm run build:webui || not-in-publish",
"flow": "flow",
"test": "mocha ./test/functional ./test/unit --reporter=spec --full-trace",
"test": "BABEL_ENV=registry mocha --require babel-register ./test/functional ./test/unit --reporter=spec --full-trace",
"pre:ci": "npm run build:webui",
"test:ci": "npm run test:coverage",
"test:only": "mocha ./test/functional ./test/unit",
@ -135,9 +141,11 @@
"coverage:publish": "nyc report --reporter=lcov | codecov",
"lint": "eslint .",
"lint:css": "stylelint 'src/**/*.scss' --syntax scss",
"dev:start": "BABEL_ENV=registry babel-node src/lib/cli",
"code:build": "BABEL_ENV=registry babel src/ --out-dir build/ --ignore src/webui/ --copy-files",
"pre:webpack": "npm run lint && rimraf static/*",
"dev:webui": "babel-node tools/dev.server.js",
"build:webui": "npm run pre:webpack && webpack --config tools/webpack.prod.config.babel.js",
"build:webui": "npm run pre:webpack && BABEL_ENV=ui webpack --config tools/webpack.prod.config.babel.js",
"build:docker": "docker build -t verdaccio . --no-cache",
"build:docker:rpi": "docker build -f Dockerfile.rpi -t verdaccio:rpi ."
},

View file

@ -35,7 +35,7 @@ module.exports = function(config, auth, storage) {
// Get list of all visible package
route.get('/packages', function(req, res, next) {
storage.get_local(function(err, packages) {
storage.getLocalDatabase(function(err, packages) {
if (err) {
// that function shouldn't produce any
throw err;

166
src/lib/bootstrap.js vendored Normal file
View file

@ -0,0 +1,166 @@
import isFunction from 'lodash/isFunction';
import Path from 'path';
import URL from 'url';
import fs from 'fs';
import http from'http';
import https from 'https';
const server = require('../api/index');
const Utils = require('./utils');
const logger = require('./logger');
const constants = require('constants');
// const pkgVersion = module.exports.version;
// const pkgName = module.exports.name;
/**
* Retrieve all addresses defined in the config file.
* Verdaccio is able to listen multiple ports
* @param {String} argListen
* @param {String} configListen
* eg:
* listen:
- localhost:5555
- localhost:5557
@return {Array}
*/
function get_listen_addresses(argListen, configListen) {
// command line || config file || default
let addresses;
if (argListen) {
addresses = [argListen];
} else if (Array.isArray(configListen)) {
addresses = configListen;
} else if (configListen) {
addresses = [configListen];
} else {
addresses = ['4873'];
}
addresses = addresses.map(function(addr) {
let parsed_addr = Utils.parse_address(addr);
if (!parsed_addr) {
logger.logger.warn({addr: addr},
'invalid address - @{addr}, we expect a port (e.g. "4873"),'
+ ' host:port (e.g. "localhost:4873") or full url'
+ ' (e.g. "http://localhost:4873/")');
}
return parsed_addr;
}).filter(Boolean);
return addresses;
}
/**
* Trigger the server after configuration has been loaded.
* @param {Object} config
* @param {Object} cliArguments
* @param {String} config_path
* @param {String} pkgVersion
* @param {String} pkgName
*/
function afterConfigLoad(config, cliArguments, config_path, pkgVersion, pkgName) {
if (!config.self_path) {
config.self_path = Path.resolve(config_path);
}
if (!config.https) {
config.https = {enable: false};
}
const app = server(config);
get_listen_addresses(cliArguments.listen, config.listen).forEach(function(addr) {
let webServer;
if (addr.proto === 'https') { // https must either have key cert and ca or a pfx and (optionally) a passphrase
if (!config.https || !config.https.key || !config.https.cert || !config.https.ca) {
let conf_path = function(file) {
if (!file) {
return config_path;
}
return Path.resolve(Path.dirname(config_path), file);
};
logger.logger.fatal([
'You need to specify either ',
' "https.key", "https.cert" and "https.ca" or ',
' "https.pfx" and optionally "https.passphrase" ',
'to run https server',
'',
// commands are borrowed from node.js docs
'To quickly create self-signed certificate, use:',
' $ openssl genrsa -out ' + conf_path('verdaccio-key.pem') + ' 2048',
' $ openssl req -new -sha256 -key ' + conf_path('verdaccio-key.pem') + ' -out ' + conf_path('verdaccio-csr.pem'),
' $ openssl x509 -req -in ' + conf_path('verdaccio-csr.pem') +
' -signkey ' + conf_path('verdaccio-key.pem') + ' -out ' + conf_path('verdaccio-cert.pem'),
'',
'And then add to config file (' + conf_path() + '):',
' https:',
' key: verdaccio-key.pem',
' cert: verdaccio-cert.pem',
' ca: verdaccio-cert.pem',
].join('\n'));
process.exit(2);
}
try {
const httpsOptions = {
secureProtocol: 'SSLv23_method', // disable insecure SSLv2 and SSLv3
secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,
};
if (config.https.pfx) {
Object.assign(httpsOptions, {
pfx: fs.readFileSync(config.https.pfx),
passphrase: config.https.passphrase || '',
});
} else {
Object.assign(httpsOptions, {
key: fs.readFileSync(config.https.key),
cert: fs.readFileSync(config.https.cert),
ca: fs.readFileSync(config.https.ca),
});
}
webServer = https.createServer(httpsOptions, app);
} catch (err) { // catch errors related to certificate loading
logger.logger.fatal({err: err}, 'cannot create server: @{err.message}');
process.exit(2);
}
} else { // http
webServer = http.createServer(app);
}
if (addr.path && fs.existsSync(addr.path)) {
fs.unlinkSync(addr.path);
}
webServer
.listen(addr.port || addr.path, addr.host)
.on('error', function(err) {
logger.logger.fatal({err: err}, 'cannot create server: @{err.message}');
process.exit(2);
});
logger.logger.warn({
addr: ( addr.path
? URL.format({
protocol: 'unix',
pathname: addr.path,
})
: URL.format({
protocol: addr.proto,
hostname: addr.host,
port: addr.port,
pathname: '/',
})
),
version: pkgName + '/' + pkgVersion,
}, 'http address - @{addr} - @{version}');
});
// undocumented stuff for tests
if (isFunction(process.send)) {
process.send({
verdaccio_started: true,
});
}
}
export {afterConfigLoad};

View file

@ -2,9 +2,7 @@
/* eslint no-sync:0 */
/* eslint no-empty:0 */
'use strict';
const _ = require('lodash');
import {afterConfigLoad} from './bootstrap';
if (process.getuid && process.getuid() === 0) {
global.console.error('Verdaccio doesn\'t need superuser privileges. Don\'t run it under root.');
@ -22,13 +20,7 @@ const logger = require('./logger');
logger.setup(); // default setup
const commander = require('commander');
const constants = require('constants');
const fs = require('fs');
const http = require('http');
const https = require('https');
const Path = require('path');
const URL = require('url');
const server = require('../api/index');
const path = require('path');
const Utils = require('./utils');
const pkginfo = require('pkginfo')(module); // eslint-disable-line no-unused-vars
const pkgVersion = module.exports.version;
@ -45,7 +37,7 @@ if (commander.args.length == 1 && !commander.config) {
commander.config = commander.args.pop();
}
if (commander.args.length != 0) {
if (commander.args.length !== 0) {
commander.help();
}
@ -53,7 +45,7 @@ let config;
let config_path;
try {
if (commander.config) {
config_path = Path.resolve(commander.config);
config_path = path.resolve(commander.config);
} else {
config_path = require('./config-path')();
}
@ -66,149 +58,7 @@ try {
process.title = config.web && config.web.title || 'verdaccio';
afterConfigLoad();
/**
* Retrieve all addresses defined in the config file.
* Verdaccio is able to listen multiple ports
* eg:
* listen:
- localhost:5555
- localhost:5557
@return {Array}
*/
function get_listen_addresses() {
// command line || config file || default
let addresses;
if (commander.listen) {
addresses = [commander.listen];
} else if (Array.isArray(config.listen)) {
addresses = config.listen;
} else if (config.listen) {
addresses = [config.listen];
} else {
addresses = ['4873'];
}
addresses = addresses.map(function(addr) {
let parsed_addr = Utils.parse_address(addr);
if (!parsed_addr) {
logger.logger.warn({addr: addr},
'invalid address - @{addr}, we expect a port (e.g. "4873"),'
+ ' host:port (e.g. "localhost:4873") or full url'
+ ' (e.g. "http://localhost:4873/")');
}
return parsed_addr;
}).filter(Boolean);
return addresses;
}
/**
* Trigger the server after configuration has been loaded.
*/
function afterConfigLoad() {
if (!config.self_path) {
config.self_path = Path.resolve(config_path);
}
if (!config.https) {
config.https = {enable: false};
}
const app = server(config);
get_listen_addresses().forEach(function(addr) {
let webServer;
if (addr.proto === 'https') { // https must either have key cert and ca or a pfx and (optionally) a passphrase
if (!config.https || !((config.https.key && config.https.cert && config.https.ca) || config.https.pfx)) {
let conf_path = function(file) {
if (!file) return config_path;
return Path.resolve(Path.dirname(config_path), file);
};
logger.logger.fatal([
'You need to specify either ',
' "https.key", "https.cert" and "https.ca" or ',
' "https.pfx" and optionally "https.passphrase" ',
'to run https server',
'',
// commands are borrowed from node.js docs
'To quickly create self-signed certificate, use:',
' $ openssl genrsa -out ' + conf_path('verdaccio-key.pem') + ' 2048',
' $ openssl req -new -sha256 -key ' + conf_path('verdaccio-key.pem') + ' -out ' + conf_path('verdaccio-csr.pem'),
' $ openssl x509 -req -in ' + conf_path('verdaccio-csr.pem') +
' -signkey ' + conf_path('verdaccio-key.pem') + ' -out ' + conf_path('verdaccio-cert.pem'),
'',
'And then add to config file (' + conf_path() + '):',
' https:',
' key: verdaccio-key.pem',
' cert: verdaccio-cert.pem',
' ca: verdaccio-cert.pem',
].join('\n'));
process.exit(2);
}
try {
const httpsOptions = {
secureProtocol: 'SSLv23_method', // disable insecure SSLv2 and SSLv3
secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,
};
if (config.https.pfx) {
Object.assign(httpsOptions, {
pfx: fs.readFileSync(config.https.pfx),
passphrase: config.https.passphrase || '',
});
} else {
Object.assign(httpsOptions, {
key: fs.readFileSync(config.https.key),
cert: fs.readFileSync(config.https.cert),
ca: fs.readFileSync(config.https.ca),
});
}
webServer = https.createServer(httpsOptions, app);
} catch (err) { // catch errors related to certificate loading
logger.logger.fatal({err: err}, 'cannot create server: @{err.message}');
process.exit(2);
}
} else { // http
webServer = http.createServer(app);
}
if (addr.path && fs.existsSync(addr.path)) {
fs.unlinkSync(addr.path);
}
webServer
.listen(addr.port || addr.path, addr.host)
.on('error', function(err) {
logger.logger.fatal({err: err}, 'cannot create server: @{err.message}');
process.exit(2);
});
logger.logger.warn({
addr: ( addr.path
? URL.format({
protocol: 'unix',
pathname: addr.path,
})
: URL.format({
protocol: addr.proto,
hostname: addr.host,
port: addr.port,
pathname: '/',
})
),
version: pkgName + '/' + pkgVersion,
}, 'http address - @{addr} - @{version}');
});
// undocumented stuff for tests
if (_.isFunction(process.send)) {
process.send({
verdaccio_started: true,
});
}
}
afterConfigLoad(config, commander, config_path, pkgVersion, pkgName);
process.on('uncaughtException', function(err) {
logger.logger.fatal( {

View file

@ -14,7 +14,8 @@
2,
{
"allow": [
"log"
"log",
"error"
]
}
],

View file

@ -1,6 +1,6 @@
'use strict';
const Server = require('../lib/server');
import Server from '../lib/server';
const fs = require('fs');
const path = require('path');

View file

@ -18,6 +18,8 @@ describe('functional test verdaccio', function() {
require('./lib/startup').start('./store/test-storage3', '/store/config-3.yaml'),
]).then(() => {
done();
}).catch(function(error) {
console.error("error on start servers", error);
});
});
@ -76,7 +78,7 @@ describe('functional test verdaccio', function() {
require('./plugins/auth.spec')();
require('./plugins/middleware.spec')();
require('./notifications/notify')();
// requires packages published to server1/server2
// // requires packages published to server1/server2
require('./uplink.cache.spec')();
require('./uplink.auth.spec')();

View file

@ -1,11 +1,9 @@
'use strict';
const assert = require('assert');
const request = require('request');
const requestData = Symbol('smart_request_data');
const _ = require('lodash');
class PromiseAssert extends Promise {
export class PromiseAssert extends Promise {
constructor(options) {
super(options);
@ -96,7 +94,6 @@ function smartRequest(options) {
smartObject[requestData] = {};
smartObject[requestData].error = Error();
Error.captureStackTrace(smartObject[requestData].error, smartRequest);
const result = new PromiseAssert(function(resolve, reject) {
smartObject[requestData].request = request(options, function(err, res, body) {
if (err) {
@ -109,8 +106,10 @@ function smartRequest(options) {
});
});
// console.log("--result->", result);
return injectResponse(smartObject, result);
}
module.exports = smartRequest;
export default smartRequest;

View file

@ -1,8 +1,7 @@
'use strict';
const assert = require('assert');
const request = require('./request');
const _ = require('lodash');
import assert from 'assert';
import request from './request';
const buildAuthHeader = (user, pass) => {
return `Basic ${(new Buffer(`${user}:${pass}`)).toString('base64')}`;
@ -207,5 +206,4 @@ class Server {
}
}
module.exports = Server;
export default Server;

View file

@ -1,12 +1,14 @@
'use strict';
import express from 'express';
import Server from './server';
const _ = require('lodash');
const fork = require('child_process').fork;
const bodyParser = require('body-parser');
const express = require('express');
const rimRaf = require('rimraf');
const path = require('path');
const Server = require('./server');
const forks = process.forks = [];
process.server = new Server('http://localhost:55551/');
@ -24,6 +26,7 @@ module.exports.start = function(dir, conf) {
return new Promise(function(resolve, reject) {
const storageDir = path.join(__dirname, `/../${dir}`);
const configPath = path.join(__dirname, '../', conf);
rimRaf(storageDir, function(err) {
if(_.isNil(err) === false) {
reject(err);
@ -32,12 +35,15 @@ module.exports.start = function(dir, conf) {
// filter out --debug-brk and --inspect-brk since Node7
return (x.indexOf('--debug-brk') === -1 && x.indexOf('--inspect-brk') === -1);
});
const childFork = fork(__dirname + '/../../../bin/verdaccio',
const url = path.join(__dirname, '/../../helper/verdaccio-test');
const childFork = fork(url,
['-c', configPath],
{
silent: !process.env.TRAVIS
// silent: false
silent: !process.env.TRAVIS,
// silent: false,
env: {
BABEL_ENV: 'registry'
}
}
);

6
test/helper/register.js Normal file
View file

@ -0,0 +1,6 @@
require("babel-polyfill");
require('babel-core/register')({
ignore: /node_modules\/(?!ProjectB)/,
sourceMap: 'inline',
});
require('../../src/lib/cli');

3
test/helper/verdaccio-test Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env node
require("babel-register");
require('../../src/lib/cli');

BIN
yarn.lock

Binary file not shown.