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

fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs #1402

Conversation

gregmagolan
Copy link
Collaborator

@gregmagolan gregmagolan commented Nov 27, 2019

This allows generating an index.html file into a different folder in the output tree (so that it doesn't collide within put index.html file) and then re-mapping
the output in pkg_web back to /index.html. ts_devserver already supports this via additional_root_paths so this brings the same functionality to pkg_web.

It is useful for the case where you have a single input index.html file and you inject scripts tags and output to a dir such as _/index.html and consume the output in both ts_devserver & pkg_web. For example,

html_insert_assets(
    name = "inject_scripts",
    # We can't output "src/index.html" since that collides with the input file.
    # We output "src/_/index.html" instead ond remap in ts_devserver & pkg_web
    # using additional_root_paths.
    outs = ["_/index.html"],
    args = [
        "--html",
        "$(location :index.html)",
        "--out",
        "$@",
        "--assets",
        "$(location @npm//:node_modules/zone.js/dist/zone.min.js)",
        # Bundle path for both prodapp & devserver
        "bundle.min.js",
    ],
    data = [
        ":index.html",
        "@npm//:node_modules/zone.js/dist/zone.min.js",
    ],
)

ts_devserver(
    name = "devserver",
    # Remap "src/_/index.html" => "index.html"
    additional_root_paths = ["src/_"],
    entry_module = "bazel_integration_test/src/main",
    scripts = [
        ":rxjs_umd_modules",
    ],
    # Use the same bundle serving path as prodserver so that we can share
    # an index.html file.
    serving_path = "/bundle.min.js",
    static_files = [
        ":inject_scripts",
        "@npm//:node_modules/zone.js/dist/zone.min.js",
    ],
    deps = ["//src"],
)

rollup_bundle(
    name = "bundle",
    config_file = "rollup.config.js",
    entry_point = ":main.ts",
    deps = [
        "//src",
        "@npm//rollup-plugin-commonjs",
        "@npm//rollup-plugin-node-resolve",
    ],
)

terser_minified(
    name = "bundle.min",
    src = ":bundle",
)

pkg_web(
    name = "prodapp",
    # Remap "src/_/index.html" => "index.html"
    additional_root_paths = ["src/_"],
    srcs = [
        ":inject_scripts",
        "@npm//:node_modules/zone.js/dist/zone.min.js",
        ":bundle.min",
    ],
)

http_server(
    name = "prodserver",
    data = [":prodapp"],
    templated_args = ["src/prodapp"],
)

…ths in genfiles and bin dirs

This allows generating an index.html file into a different folder in the output tree (so that it doesn't collide within put index.html file) and then re-mapping
the output in pkg_web back to /index.html. ts_devserver already supports this via additional_root_paths so this brings the same functionality to pkg_web.

It is useful for the case where you have a single input index.html file and you inject scripts tags and output to a dir such as _/index.html and consume the output in both ts_devserver & pkg_web. For example,

```
html_insert_assets(
    name = "inject_scripts",
    # We can't output "index.html" since that collides with the input file.
    # We output "_/index.html" instead ond remap in ts_devserver & pkg_web
    # using additional_root_paths.
    outs = ["_/index.html"],
    args = [
        "--html",
        "$(location :index.html)",
        "--out",
        "$@",
        "--assets",
        # We load zone.js outside the bundle. That's because it's a "pollyfill"
        # which speculates that such features might be available in a browser.
        # Also it's tricky to configure dead code elimination to understand that
        # zone.js is used, given that we don't have any import statement that
        # imports from it.
        "$(location @npm//:node_modules/zone.js/dist/zone.min.js)",
        # Bundle path for both prodapp & devserver
        "bundle.min.js",
    ],
    data = [
        ":index.html",
        "@npm//:node_modules/zone.js/dist/zone.min.js",
    ],
)

ts_devserver(
    name = "devserver",
    # Remap "_/index.html" => "index.html"
    additional_root_paths = ["src/_"],
    entry_module = "bazel_integration_test/src/main",
    scripts = [
        ":rxjs_umd_modules",
    ],
    # Use the same bundle serving path as prodserver so that we can share
    # an index.html file.
    serving_path = "/bundle.min.js",
    static_files = [
        ":inject_scripts",
        "@npm//:node_modules/zone.js/dist/zone.min.js",
    ],
    deps = ["//src"],
)

rollup_bundle(
    name = "bundle",
    config_file = "rollup.config.js",
    entry_point = ":main.ts",
    deps = [
        "//src",
        "@npm//rollup-plugin-commonjs",
        "@npm//rollup-plugin-node-resolve",
    ],
)

terser_minified(
    name = "bundle.min",
    src = ":bundle",
)

pkg_web(
    name = "prodapp",
    # Remap "_/index.html" => "index.html"
    additional_root_paths = ["src/_"],
    srcs = [
        ":inject_scripts",
        "@npm//:node_modules/zone.js/dist/zone.min.js",
        ":bundle.min",
    ],
)

http_server(
    name = "prodserver",
    data = [":prodapp"],
    templated_args = ["src/prodapp"],
)
```
Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Note, genfiles_dir is now same as bin_dir (pending some flag flip?)

@gregmagolan
Copy link
Collaborator Author

Yeah. I figured it would be so this will get cleanup up with the rest of the genfiles references at some point.

@gregmagolan gregmagolan merged commit 9ce8c85 into bazel-contrib:master Nov 27, 2019
gregmagolan added a commit to gregmagolan/angular that referenced this pull request Dec 5, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for angular#34112
2) fix(typescript): fix for cross platform ts_devserver issue angular#1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific angular#1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.
gregmagolan added a commit to gregmagolan/angular that referenced this pull request Dec 5, 2019
…nodejs 0.42.1

This release brings a bug fix that angular#34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)
gregmagolan added a commit to gregmagolan/angular that referenced this pull request Dec 5, 2019
…nodejs 0.42.1

This release brings a bug fix that angular#34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)
gregmagolan added a commit to gregmagolan/angular that referenced this pull request Dec 5, 2019
…nodejs 0.42.1

This release brings a bug fix that angular#34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Dec 5, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for #34112
2) fix(typescript): fix for cross platform ts_devserver issue #1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific #1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.

PR Close #34243
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Dec 5, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for #34112
2) fix(typescript): fix for cross platform ts_devserver issue #1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific #1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.

PR Close #34243
josephperrott pushed a commit to josephperrott/angular that referenced this pull request Dec 11, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for angular#34112
2) fix(typescript): fix for cross platform ts_devserver issue angular#1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific angular#1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.

PR Close angular#34243
josephperrott pushed a commit to josephperrott/angular that referenced this pull request Dec 11, 2019
…nodejs 0.42.1

This release brings a bug fix that angular#34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)
kara pushed a commit to angular/angular that referenced this pull request Dec 11, 2019
…nodejs 0.42.1 (#34112)

This release brings a bug fix that #34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)

PR Close #34112
kara pushed a commit to angular/angular that referenced this pull request Dec 11, 2019
…nodejs 0.42.1 (#34112)

This release brings a bug fix that #34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)

PR Close #34112
gregmagolan added a commit to gregmagolan/angular that referenced this pull request Dec 28, 2019
…nodejs 0.42.1

This release brings a bug fix that angular#34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants