diff --git a/.circleci/config.yml b/.circleci/config.yml index f018b76bd..7c43e17b6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,8 +122,9 @@ jobs: prep-build: docker: - image: circleci/node@sha256:e16740707de2ebed45c05d507f33ef204902349c7356d720610b5ec6a35d3d88 + resource_class: medium+ environment: - NODE_OPTIONS: --max_old_space_size=1024 + NODE_OPTIONS: --max_old_space_size=2048 steps: - checkout - attach_workspace: @@ -143,8 +144,9 @@ jobs: prep-build-test: docker: - image: circleci/node@sha256:e16740707de2ebed45c05d507f33ef204902349c7356d720610b5ec6a35d3d88 + resource_class: medium+ environment: - NODE_OPTIONS: --max_old_space_size=1024 + NODE_OPTIONS: --max_old_space_size=2048 steps: - checkout - attach_workspace: diff --git a/development/build/scripts.js b/development/build/scripts.js index cf19060c6..de4a59e48 100644 --- a/development/build/scripts.js +++ b/development/build/scripts.js @@ -1,6 +1,8 @@ const fs = require('fs') const gulp = require('gulp') const watch = require('gulp-watch') +const pify = require('pify') +const pump = pify(require('pump')) const source = require('vinyl-source-stream') const buffer = require('vinyl-buffer') const log = require('fancy-log') @@ -11,8 +13,6 @@ const envify = require('envify/custom') const sourcemaps = require('gulp-sourcemaps') const sesify = require('sesify') const terser = require('gulp-terser-js') -const pify = require('pify') -const endOfStream = pify(require('end-of-stream')) const { makeStringTransform } = require('browserify-transform-tools') const conf = require('rc')('metamask', { @@ -200,33 +200,19 @@ function createScriptTasks({ browserPlatforms, livereload }) { bundler.on('log', log) } - let buildStream = bundler.bundle() - - // handle errors - buildStream.on('error', (err) => { - beep() - if (opts.devMode) { - console.warn(err.stack) - } else { - throw err - } - }) - - // process bundles - buildStream = buildStream + const buildPipeline = [ + bundler.bundle(), // convert bundle stream to gulp vinyl stream - .pipe(source(opts.filename)) - // buffer file contents (?) - .pipe(buffer()) - - // Initialize Source Maps - buildStream = buildStream + source(opts.filename), + // Initialize Source Maps + buffer(), // loads map from browserify file - .pipe(sourcemaps.init({ loadMaps: true })) + sourcemaps.init({ loadMaps: true }), + ] // Minification if (!opts.devMode) { - buildStream = buildStream.pipe( + buildPipeline.push( terser({ mangle: { reserved: ['MetamaskInpageProvider'], @@ -242,18 +228,28 @@ function createScriptTasks({ browserPlatforms, livereload }) { if (opts.devMode) { // Use inline source maps for development due to Chrome DevTools bug // https://bugs.chromium.org/p/chromium/issues/detail?id=931675 - buildStream = buildStream.pipe(sourcemaps.write()) + // note: sourcemaps call arity is important + buildPipeline.push(sourcemaps.write()) } else { - buildStream = buildStream.pipe(sourcemaps.write('../sourcemaps')) + buildPipeline.push(sourcemaps.write('../sourcemaps')) } // write completed bundles browserPlatforms.forEach((platform) => { const dest = `./dist/${platform}` - buildStream = buildStream.pipe(gulp.dest(dest)) + buildPipeline.push(gulp.dest(dest)) }) - await endOfStream(buildStream) + // process bundles + if (opts.devMode) { + try { + await pump(buildPipeline) + } catch (err) { + gracefulError(err) + } + } else { + await pump(buildPipeline) + } } } @@ -406,10 +402,6 @@ function createScriptTasks({ browserPlatforms, livereload }) { } } -function beep() { - process.stdout.write('\x07') -} - function getEnvironment({ devMode, test }) { // get environment slug if (devMode) { @@ -429,3 +421,12 @@ function getEnvironment({ devMode, test }) { } return 'other' } + +function beep() { + process.stdout.write('\x07') +} + +function gracefulError(err) { + console.warn(err) + beep() +}