-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 || {}) | ||
|
@@ -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] | ||
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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