Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci - build-artifacts - generate sesify-viz for inspecting deps #7151

Merged
merged 2 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ jobs:
- store_artifacts:
path: test-artifacts
destination: test-artifacts
# important: generate sesify viz AFTER uploading builds as artifacts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this needs to be run after because otherwise it'd override the "real" build artifacts. I guess this is the main obstacle to running this in parallel - writing the output to a different location, so it can be done earlier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Could add a flag to build dist to a different dir. Though worth noting that all jobs past all-tests-pass are optional and don't block merges

- run:
name: build:sesify-viz
command: ./.circleci/scripts/create-sesify-viz
- store_artifacts:
path: build-artifacts
destination: build-artifacts
- run:
name: build:announce
command: ./development/metamaskbot-build-announce.js
Expand Down
13 changes: 13 additions & 0 deletions .circleci/scripts/create-sesify-viz
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -x
set -e
set -u
set -o pipefail

# prepare artifacts dir
mkdir -p ./build-artifacts/deps-viz/

# generate viz
SESIFY_AUTOGEN=1 npx gulp build:extension:js:background
npx sesify-viz --deps sesify/deps-background.json --config sesify/background.json --dest ./build-artifacts/deps-viz/background
51 changes: 50 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const rtlcss = require('gulp-rtlcss')
const rename = require('gulp-rename')
const gulpMultiProcess = require('gulp-multi-process')
const endOfStream = pify(require('end-of-stream'))
const sesify = require('sesify')
const mkdirp = require('mkdirp')
const { makeStringTransform } = require('browserify-transform-tools')

const packageJSON = require('./package.json')
const dependencies = Object.keys(packageJSON && packageJSON.dependencies || {})
Expand Down Expand Up @@ -493,11 +496,26 @@ function zipTask (target) {

function generateBundler (opts, performBundle) {
const browserifyOpts = assign({}, watchify.args, {
plugin: 'browserify-derequire',
plugin: [],
transform: [],
debug: opts.buildSourceMaps,
fullPaths: opts.buildWithFullPaths,
})

const bundleName = opts.filename.split('.')[0]

// activate sesify
const activateAutoConfig = Boolean(process.env.SESIFY_AUTOGEN)
// const activateSesify = activateAutoConfig
const activateSesify = activateAutoConfig && ['background'].includes(bundleName)
if (activateSesify) {
configureBundleForSesify({ browserifyOpts, bundleName })
}

if (!activateSesify) {
browserifyOpts.plugin.push('browserify-derequire')
}

if (!opts.buildLib) {
if (opts.devMode && opts.filename === 'ui.js') {
browserifyOpts['entries'] = ['./development/require-react-devtools.js', opts.filepath]
Expand Down Expand Up @@ -615,6 +633,37 @@ function bundleTask (opts) {
}
}

function configureBundleForSesify ({
browserifyOpts,
bundleName,
}) {
// add in sesify args for better globalRef usage detection
Object.assign(browserifyOpts, sesify.args)

// ensure browserify uses full paths
browserifyOpts.fullPaths = true

// record dependencies used in bundle
mkdirp.sync('./sesify')
browserifyOpts.plugin.push(['deps-dump', {
filename: `./sesify/deps-${bundleName}.json`,
}])

const sesifyConfigPath = `./sesify/${bundleName}.json`

// add sesify plugin
browserifyOpts.plugin.push([sesify, {
writeAutoConfig: sesifyConfigPath,
}])

// remove html comments that SES is alergic to
const removeHtmlComment = makeStringTransform('remove-html-comment', { excludeExtension: ['.json'] }, (content, _, cb) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So SES has some problem with HTML comments (even when they're embedded in JavaScript)? I'm be interested to hear more about whatever problem this is solving.

It should be harmless enough for this dependency visualization build I suppose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's related to this monster

1 + <!-- 2
3
// => 4

I haven't encountered html comment openings in the wild, but I have encountered html comment closings --> as part of diagrams in comments. SES has a regex that throws if present.

This isn't actually needed for the viz tho, but for sesify build runtimes. Part of this PR is sneaking in all the components for sesify so that the PR to actually enable it in prod will be quite small.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main reason it's blacklisted is that it's behavior is not standardized

Copy link
Member

@Gudahtt Gudahtt Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp - that does seem monstrous.

Maybe there's a way to make this transformation more targeted then. I'm concerned that if this transformation was used as-is for a proper sesify build, it could break HTML markup containing comments that was inserted via JavaScript.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good concern. Maybe it should warn when it encounters one.

const result = content.split('-->').join('-- >')
cb(null, result)
})
browserifyOpts.transform.push([removeHtmlComment, { global: true }])
}

function beep () {
process.stdout.write('\x07')
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"babelify": "^10.0.0",
"brfs": "^1.6.1",
"browserify": "^16.2.3",
"browserify-transform-tools": "^1.7.0",
"chai": "^4.1.0",
"chromedriver": "^2.41.0",
"concurrently": "^4.1.1",
Expand All @@ -194,6 +195,7 @@
"css-loader": "^2.1.1",
"deep-freeze-strict": "^1.1.1",
"del": "^3.0.0",
"deps-dump": "^1.1.0",
"envify": "^4.0.0",
"enzyme": "^3.4.4",
"enzyme-adapter-react-15": "^1.0.6",
Expand Down Expand Up @@ -263,6 +265,8 @@
"rimraf": "^2.6.2",
"sass-loader": "^7.0.1",
"selenium-webdriver": "^3.5.0",
"sesify": "^4.2.1",
"sesify-viz": "^2.0.1",
"sinon": "^5.0.0",
"source-map": "^0.7.2",
"static-server": "^2.2.1",
Expand Down
Loading