Skip to content

Commit

Permalink
perf(npm): reduce use of string.split
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jul 24, 2024
1 parent 9cede2b commit 23b6801
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 49 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions e2e/pnpm_lockfiles/v54/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v54/snapshots/rollup_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions e2e/pnpm_lockfiles/v60/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v60/snapshots/rollup_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions e2e/pnpm_lockfiles/v61/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v61/snapshots/rollup_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions e2e/pnpm_lockfiles/v90/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v90/snapshots/rollup_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions npm/private/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def npm_link_imported_package(
npm_link_imported_package_store(name = link_target_name)
if {public_visibility}:
link_targets.append(":{{}}".format(link_target_name))
if len(link_alias.split("/", 1)) > 1:
link_scope = link_alias.split("/", 1)[0]
link_scope = link_alias[:link_alias.find("/", 1)] if link_alias[0] == "@" else None
if link_scope:
if link_scope not in scoped_targets:
scoped_targets[link_scope] = []
scoped_targets[link_scope].append(link_target_name)
Expand Down Expand Up @@ -584,7 +584,7 @@ bin = bin_factory("node_modules")
if rctx.attr.generate_bzl_library_targets:
rctx_files[build_file].append("""load("@bazel_skylib//:bzl_library.bzl", "bzl_library")""")
rctx_files[build_file].append(_BZL_LIBRARY_TMPL.format(
name = link_package.split("/")[-1] or package_name_no_scope,
name = link_package.split("/")[-1] if link_package else package_name_no_scope,
src = _PACKAGE_JSON_BZL_FILENAME,
))
rctx_files[build_file].append("""exports_files(["{}", "{}"])""".format(_PACKAGE_JSON_BZL_FILENAME, package_src))
Expand Down
10 changes: 5 additions & 5 deletions npm/private/npm_translate_lock_generate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
add_to_link_targets = """ link_targets.append("//{{}}:{{}}/{name}".format(bazel_package, name))""".format(name = link_alias)
links_bzl[link_package].append(add_to_link_targets)
links_targets_bzl[link_package].append(add_to_link_targets)
if len(link_alias.split("/", 1)) > 1:
package_scope = link_alias.split("/", 1)[0]
package_scope = link_alias[:link_alias.find("/", 1)] if link_alias[0] == "@" else None
if package_scope:
add_to_scoped_targets = """ scope_targets["{package_scope}"] = scope_targets["{package_scope}"] + [link_targets[-1]] if "{package_scope}" in scope_targets else [link_targets[-1]]""".format(package_scope = package_scope)
links_bzl[link_package].append(add_to_scoped_targets)
for link_package in _import.link_packages.keys():
Expand All @@ -304,7 +304,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
dep = "@{repo_name}//{link_package}:{package_name}_bzl_library".format(
repo_name = helpers.to_apparent_repo_name(_import.name),
link_package = link_package,
package_name = link_package.split("/")[-1] or _import.package.split("/")[-1],
package_name = link_package.split("/")[-1] if link_package else _import.package.split("/")[-1],
),
))
package_json_bzl_file_path = "{}/{}/{}".format(link_package, _import.package, _PACKAGE_JSON_BZL_FILENAME) if link_package else "{}/{}".format(_import.package, _PACKAGE_JSON_BZL_FILENAME)
Expand Down Expand Up @@ -387,8 +387,8 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
if "//visibility:public" in package_visibility:
add_to_link_targets = """ link_targets.append(":{{}}/{name}".format(name))""".format(name = fp_package)
npm_link_all_packages_bzl.append(add_to_link_targets)
if len(fp_package.split("/", 1)) > 1:
package_scope = fp_package.split("/", 1)[0]
package_scope = fp_package[:fp_package.find("/", 1)] if fp_package[0] == "@" else None
if package_scope:
add_to_scoped_targets = """ scope_targets["{package_scope}"] = scope_targets["{package_scope}"] + [link_targets[-1]] if "{package_scope}" in scope_targets else [link_targets[-1]]""".format(
package_scope = package_scope,
)
Expand Down
4 changes: 2 additions & 2 deletions npm/private/test/snapshots/bzlmod/chalk_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions npm/private/test/snapshots/bzlmod/fsevents_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion npm/private/test/snapshots/bzlmod/npm_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions npm/private/test/snapshots/bzlmod/rollup_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions npm/private/test/snapshots/bzlmod/unused_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions npm/private/test/snapshots/wksp/chalk_links_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 23b6801

Please sign in to comment.