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: language-service package built by bazel #23155

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions WORKSPACE
Expand Up @@ -2,9 +2,9 @@ workspace(name = "angular")

http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/cd368bd71a4b04fae0eafb5c5e2c906a93772584.zip",
strip_prefix = "rules_nodejs-cd368bd71a4b04fae0eafb5c5e2c906a93772584",
sha256 = "db74c61dd8bf73cc50aed56e78b7a8ad383f5869206901506cf8d3ee27f9277f",
url = "https://github.com/bazelbuild/rules_nodejs/archive/99166f8eb7fc628ca561acf9f9a51a1c26edadad.zip",
strip_prefix = "rules_nodejs-99166f8eb7fc628ca561acf9f9a51a1c26edadad",
sha256 = "338e8495e5d1fa16de7190106c5675372ff4a347f6004e203e84a168db96281e",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
Expand Down
5 changes: 4 additions & 1 deletion packages/bazel/src/ng_rollup_bundle.bzl
Expand Up @@ -51,6 +51,9 @@ def _ng_rollup_bundle(ctx):
run_uglify(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min_debug,
debug = True, comments = False)

umd_rollup_config = write_rollup_config(ctx, filename = "_%s_umd.rollup.conf.js", output_format = "umd")
run_rollup(ctx, collect_es2015_sources(ctx), umd_rollup_config, ctx.outputs.build_umd)

run_brotli(ctx, ctx.outputs.build_es5_min, ctx.outputs.build_es5_min_compressed)

return DefaultInfo(files=depset([ctx.outputs.build_es5_min]))
Expand All @@ -66,7 +69,7 @@ ng_rollup_bundle = rule(
executable = True,
cfg = "host",
default = Label("@angular//packages/bazel/src:rollup_with_build_optimizer")),
"_brotli": attr.label(
"_brotli": attr.label(
executable = True,
cfg = "host",
default = Label("@org_brotli//:brotli")),
Expand Down
8 changes: 5 additions & 3 deletions packages/language-service/BUILD.bazel
Expand Up @@ -23,8 +23,10 @@ npm_package(
name = "npm_package",
srcs = ["package.json"],
tags = [
# TODO(alexeagle): enable release after landing #23090
# "release-with-framework",
"release-with-framework",
],
deps = [
":language-service",
"//packages/language-service/bundles:language-service",
],
deps = [":language-service"],
)
14 changes: 14 additions & 0 deletions packages/language-service/bundles/BUILD.bazel
@@ -0,0 +1,14 @@
load(":rollup.bzl", "ls_rollup_bundle")

ls_rollup_bundle(
name = "language-service",
entry_point = "packages/language-service/index.js",
globals = {
"typescript": "ts",
"path": "path",
"fs": "fs",
},
license_banner = "banner.js.txt",
visibility = ["//packages/language-service:__pkg__"],
deps = ["//packages/language-service"],
)
19 changes: 19 additions & 0 deletions packages/language-service/bundles/banner.js.txt
@@ -0,0 +1,19 @@
/**
* @license Angular v0.0.0-PLACEHOLDER
* (c) 2010-2018 Google, Inc. https://angular.io/
* License: MIT
*/

var $reflect = {defineMetadata: function() {}, getOwnMetadata: function(){}};
((typeof global !== 'undefined' && global)||{})['Reflect'] = $reflect;
var $deferred, $resolved, $provided;
function $getModule(name) { return $provided[name] || require(name); }
function define(modules, cb) { $deferred = { modules: modules, cb: cb }; }
module.exports = function(provided) {
if ($resolved) return $resolved;
var result = {};
$provided = Object.assign({'reflect-metadata': $reflect}, provided || {}, { exports: result });
$deferred.cb.apply(this, $deferred.modules.map($getModule));
$resolved = result;
return result;
}
48 changes: 48 additions & 0 deletions packages/language-service/bundles/rollup.bzl
@@ -0,0 +1,48 @@
"""Custom rollup_bundle for language service.

Overrides format to AMD and produces only umd and min, no FESM.
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 add more info:

  • we do this so that we bundle all of the dependencies into the bundle except for typescript, fs and path. This allows editors and other tools to easily use the language service bundle without having to provide all of the angular specific peer dependencies.
  • the file is called "umd.js" and "umd.min.js" because of historical reasons. the format is actually amd and not umd, but we are afraid to rename the file because that would likely break the IDE and other integrations that have the path hardcoded in them.

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


We do this so that we bundle all of the dependencies into the bundle
except for typescript, fs and path.

This allows editors and other tools to easily use the language service bundle
without having to provide all of the angular specific peer dependencies.
"""

load("@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
"ROLLUP_ATTRS",
"rollup_module_mappings_aspect",
"write_rollup_config",
"run_rollup",
"run_uglify"
)
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir")

# Note: the file is called "umd.js" and "umd.min.js" because of historical
# reasons. The format is actually amd and not umd, but we are afraid to rename
# the file because that would likely break the IDE and other integrations that
# have the path hardcoded in them.
_ROLLUP_OUTPUTS = {
"build_umd": "%{name}.umd.js",
"build_umd_min": "%{name}.umd.min.js",
}

def _ls_rollup_bundle(ctx):
esm5_sources = flatten_esm5(ctx)
rollup_config = write_rollup_config(ctx,
root_dir = "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]),
output_format = "amd")
run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_umd)
source_map = run_uglify(ctx, ctx.outputs.build_umd, ctx.outputs.build_umd_min)
return DefaultInfo(files=depset([ctx.outputs.build_umd, ctx.outputs.build_umd_min, source_map]))

ls_rollup_bundle = rule(
implementation = _ls_rollup_bundle,
attrs = dict(ROLLUP_ATTRS, **{
"deps": attr.label_list(aspects = [
rollup_module_mappings_aspect,
esm5_outputs_aspect,
]),
}),
outputs = _ROLLUP_OUTPUTS,
)
3 changes: 0 additions & 3 deletions scripts/release/publish-next
Expand Up @@ -8,6 +8,3 @@ set -u -e -o pipefail
for p in $(bazel query --output=label 'attr("tags", "\[.*release-with-framework.*\]", //...) intersect kind(".*_package", //...) except //dist/...'); do
bazel run -- $p.publish --access public --tag next
done

# TODO(alexeagle): publish everything from bazel and remove this
(cd dist/packages-dist; for p in language-service; do npm publish --access public --tag next $p; done)