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

build(ivy): create hello world rollup #22004

Closed
wants to merge 1 commit into from

Conversation

alexeagle
Copy link
Contributor

This is a customization of the rollup_bundle rule from rules_nodejs
which adds the build-optimizer as a plugin.

Add a functional test with fast round-trip that asserts the minified app
still works.

Publish the min.js artifact on circleCI so we can track its size.

@alexeagle alexeagle added the target: major This PR is targeted for the next major release label Feb 2, 2018
@mary-poppins
Copy link

You can preview dfcd36d at https://pr22004-dfcd36d.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 16af609 at https://pr22004-16af609.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 0352989 at https://pr22004-0352989.ngbuilds.io/.

@alexeagle alexeagle force-pushed the build-optimizer branch 2 times, most recently from b22fcee to 4ac0f20 Compare February 3, 2018 00:39
@mary-poppins
Copy link

You can preview 4ac0f20 at https://pr22004-4ac0f20.ngbuilds.io/.

WORKSPACE Outdated
remote = "https://github.com/bazelbuild/rules_nodejs.git",
commit = "230d39a391226f51c03448f91eb61370e2e58c42",
remote = "https://github.com/alexeagle/rules_nodejs.git",
commit = "6a4b9aa32677cbab3dfed48b9b4eda13d8c41f23",
Copy link
Contributor

Choose a reason for hiding this comment

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

please describe why we use custom build and what needs to be done to get back to upstream. Is there an issue/pr tracking the work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Landed the changes, so this now points back to HEAD on the upstream repo master

WORKSPACE Outdated
git_repository(
name = "angular_devkit",
remote = "https://github.com/alexeagle/devkit.git",
commit = "4b960f37f49a4ed87d54402ce935a4fa0da7b0f6",
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this particular commit? can't we use a tag instead? it's much easier to understand what we use if we use tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah this has a pending PR too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Landed the changes, so this now points back to HEAD on the upstream repo master

nodejs_binary(
name = "rollup_with_build_optimizer",
data = ["@angular_devkit//packages/angular_devkit/build_optimizer:lib"],
entry_point = "build_bazel_rules_nodejs_rollup_deps/node_modules/rollup/bin/rollup",
Copy link
Contributor

Choose a reason for hiding this comment

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

ouch.. really? why do we reach into that external rule? that looks super ugly. can't we do better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could have our own external repo to hold the runtime deps, but since this rule extends rollup_bundle I think it's appropriate to share the runtime deps too

Copy link
Contributor

Choose a reason for hiding this comment

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

can you document this reasoning. I'm sure more people will wonder about this in the future when looking at this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


ng_rollup_bundle(
name = "bundle",
# FIXME(alex): should start with "angular/"
Copy link
Contributor

Choose a reason for hiding this comment

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

can you capture why it can't be that way now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's pretty complicated, basically I want users to see a consistent view that looks like a runfiles view where paths start with the workspace, but in the execroot they don't currently. I need to find the right place to enforce a mapping.

Copy link
Contributor

Choose a reason for hiding this comment

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

see.. it's not that complicated after all. your description above is way better than the current fixme note.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

"""

# The provider downstream rules use to access the outputs
ES5ESMInfo = provider(
Copy link
Contributor

Choose a reason for hiding this comment

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

the terminology, we usually use for this is ESM5 not ES5ESM. see https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

return []

# We create a new tsconfig.json file that will have our compilation settings
tsconfig = ctx.actions.declare_file("%s_es5_esm.tsconfig.json" % target.label.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

esm5.tsconfig.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

workspace = target.label.workspace_root if target.label.workspace_root else ""

# re-root the outputs under a ".es5_esm" directory so the path don't collide
out_dir = ctx.label.name + ".es5_esm"
Copy link
Contributor

Choose a reason for hiding this comment

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

esm5... throughout the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup

data['angularCompilerOptions']['expectedOut'].map(
f => f.replace(/\.closure\.js$/, '.js').replace(binDir, path.join(binDir, newRoot)));
}
fs.writeFileSync(output, JSON.stringify(data), {encoding: 'utf-8'});
Copy link
Contributor

Choose a reason for hiding this comment

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

utf8 is the default for writeFileSync

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh

# We don't expect anyone to make use of this ES6 bundle, but it makes this rule
# compatible with rollup_bundle which allows them to be easily swapped back and
# forth.
es6_rollup_config = write_rollup_config(ctx, filename = "_%s.rollup_es6.conf.js")
Copy link
Contributor

Choose a reason for hiding this comment

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

es2015 - can we please be consistent. otherwise it's confusing. esX is no longer a thing. ES2018 has just been finalized: http://2ality.com/2017/02/ecmascript-2018.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, this is in a lot of places like rules_typescript, so we can't be 100% consistent without a lot of work, but will fix here

@@ -64,6 +64,10 @@ jobs:
# See https://github.com/bazelbuild/bazel/issues/4257
- run: bazel query --output=label '//modules/... union //packages/... union //tools/...' | xargs bazel test --config=ci

- store_artifacts:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you document why we do this? via an inline comment.

it's not clear to me how will the size tracking work? using an external service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@mary-poppins
Copy link

You can preview 85f77db at https://pr22004-85f77db.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 5110990 at https://pr22004-5110990.ngbuilds.io/.

"""This provides a variant of rollup_bundle that works better for Angular apps.

It registers @angular-devkit/build-optimizer as a rollup plugin, to get
better optimization. It also uses ES5-ESM format inputs, as this is what
Copy link
Contributor

Choose a reason for hiding this comment

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

esm5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

"write_rollup_config",
"run_rollup",
"run_uglify")
load("@build_bazel_rules_nodejs//internal:collect_es6_sources.bzl", collect_es2015_sources = "collect_es6_sources")
Copy link
Contributor

Choose a reason for hiding this comment

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

BO_PLUGIN="require('angular_devkit/packages/angular_devkit/build_optimizer/src/build-optimizer/rollup-plugin.js').default()"

def _ng_rollup_bundle(ctx):
# We don't expect anyone to make use of this ES6 bundle, but it makes this rule
Copy link
Contributor

Choose a reason for hiding this comment

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

it's esm2015 bundle or fesm2015

Copy link
Contributor

Choose a reason for hiding this comment

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

also we do very much expect to start switching over to esm2015 as the primary input to application bundle around the v7 timeframe.

# We don't expect anyone to make use of this ES6 bundle, but it makes this rule
# compatible with rollup_bundle which allows them to be easily swapped back and
# forth.
es2015_rollup_config = write_rollup_config(ctx, filename = "_%s.rollup_es6.conf.js")
Copy link
Contributor

Choose a reason for hiding this comment

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

esm2015

# compatible with rollup_bundle which allows them to be easily swapped back and
# forth.
es2015_rollup_config = write_rollup_config(ctx, filename = "_%s.rollup_es6.conf.js")
run_rollup(ctx, collect_es2015_sources(ctx), es2015_rollup_config, ctx.outputs.build_es6)
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this output defined? I don't see any other references to "build_es6" in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's in the ROLLUP_OUTPUTS that we inherit from rules_nodejs

@IgorMinar IgorMinar closed this Feb 4, 2018
@IgorMinar IgorMinar reopened this Feb 4, 2018
@IgorMinar
Copy link
Contributor

oops.. closed by mistake. sorry! 😇

# CircleCI will allow us to go back and view/download these artifacts after each build.
# Also we can use a service like https://buildsize.org/ to automatically track binary size of these artifacts.
- store_artifacts:
path: dist/bin/packages/core/test/bundling/hello_world/bundle.min.js
Copy link
Contributor

Choose a reason for hiding this comment

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

this is no exciting!

@mary-poppins
Copy link

You can preview 07795d3 at https://pr22004-07795d3.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 14dfcd9 at https://pr22004-14dfcd9.ngbuilds.io/.

This is a customization of the rollup_bundle rule from rules_nodejs
which adds the build-optimizer as a plugin.

Add a functional test with fast round-trip that asserts the minified app
still works.

Publish the min.js artifact on circleCI so we can track its size.
@alexeagle alexeagle added the action: merge The PR is ready for merge by the caretaker label Feb 5, 2018
@mary-poppins
Copy link

You can preview f425a66 at https://pr22004-f425a66.ngbuilds.io/.

@alxhub alxhub closed this in 370ab66 Feb 6, 2018
jbogarthyde pushed a commit to jbogarthyde/angular that referenced this pull request Feb 23, 2018
This is a customization of the rollup_bundle rule from rules_nodejs
which adds the build-optimizer as a plugin.

Add a functional test with fast round-trip that asserts the minified app
still works.

Publish the min.js artifact on circleCI so we can track its size.

PR Close angular#22004
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
This is a customization of the rollup_bundle rule from rules_nodejs
which adds the build-optimizer as a plugin.

Add a functional test with fast round-trip that asserts the minified app
still works.

Publish the min.js artifact on circleCI so we can track its size.

PR Close angular#22004
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants