fix(docker): Force npm@5 in docker builds. (#6143) r=@vladikoff

This commit is contained in:
Shane Tomlinson 2018-05-01 17:16:52 +02:00 коммит произвёл Vlad Filippov
Родитель edc23bc2ab
Коммит f707a97e72
4 изменённых файлов: 73 добавлений и 0 удалений

Просмотреть файл

@ -15,6 +15,9 @@ COPY npm-shrinkwrap.json npm-shrinkwrap.json
COPY package.json package.json
COPY scripts/download_l10n.sh scripts/download_l10n.sh
# node@6 uses npm@3 by default, which resolves dependencies incorrectly
RUN npm install -g npm@5
RUN npm install --production --unsafe-perm && rm -rf ~/.cache ~/.npm /tmp/*
COPY . /app

Просмотреть файл

@ -31,6 +31,16 @@ const serveStatic = require('serve-static');
const config = require('../lib/configuration');
const raven = require('../lib/raven');
const userAgent = require('../lib/user-agent');
if (! userAgent.isToVersionStringSupported()) {
// npm@3 installs the incorrect version of node-uap, one without `toVersionString`.
// To ensure the correct version is installed, check toVersionString is available.
logger.critical('dependency.version.error', {
error: 'node-uap does not support toVersionString()'
});
process.exit(1);
}
// This can't possibly be best way to librar-ify this module.
const isMain = process.argv[1] === __filename;
if (isMain) {

Просмотреть файл

@ -27,6 +27,22 @@ exports.parse = userAgentString => {
return result;
};
exports.isToVersionStringSupported = (result) => {
if (! result) {
result = exports.parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0');
}
if (! result || ! result.os || ! result.ua) {
return false;
}
if (typeof result.os.toVersionString !== 'function') {
return false;
}
if (typeof result.ua.toVersionString !== 'function') {
return false;
}
return true;
};
function safeFamily (parent) {
if (! VALID_FAMILY.test(parent.family)) {
parent.family = null;

Просмотреть файл

@ -15,6 +15,50 @@ registerSuite('userAgent', {
'interface is correct': () => {
assert.isFunction(userAgent.parse);
assert.lengthOf(userAgent.parse, 1);
assert.isFunction(userAgent.isToVersionStringSupported);
},
'isToVersionStringSupported returns false if os.toVersionString is not available': () => {
assert.isFalse(userAgent.isToVersionStringSupported({
os: {
major: 1,
minor: 0,
},
ua: {
major: 1,
minor: 0,
toVersionString: function () {}
}
}));
},
'isToVersionStringSupported returns false if ua.toVersionString is not available': () => {
assert.isFalse(userAgent.isToVersionStringSupported({
os: {
major: 1,
minor: 0,
toVersionString: function () {}
},
ua: {
major: 1,
minor: 0,
}
}));
},
'isToVersionStringSupported returns true if toVersionString is available': () => {
assert.isTrue(userAgent.isToVersionStringSupported({
os: {
major: 1,
minor: 0,
toVersionString: function () {}
},
ua: {
major: 1,
minor: 0,
toVersionString: function () {}
}
}));
},
'parses a valid user-agent string': () => {