diff --git a/ts/copy.bzl b/ts/copy.bzl index 2b5302671..525814259 100644 --- a/ts/copy.bzl +++ b/ts/copy.bzl @@ -27,22 +27,27 @@ def copy_files(ctx, files): return [DefaultInfo(files = depset(outputs))] -def copy_select_files(ctx, files, include, exclude, unwanted_prefix): +def remove_prefix(text, prefix): + if text.startswith(prefix): + return text[len(prefix):] + return text + +def copy_select_files(ctx, files, include, exclude, base, unwanted_prefix): wanted = [] for f in files.to_list(): - path = f.path + path = remove_prefix(f.path, base) want = True for substr in exclude: - if substr in path: + if path.startswith(substr): want = False continue if not want: continue for substr in include: - if substr in path: - output = path.replace(unwanted_prefix, "") + if path.startswith(substr): + output = remove_prefix(path, unwanted_prefix) wanted.append((f, output)) return copy_files(ctx, wanted) diff --git a/ts/css-browser-selector.bzl b/ts/css-browser-selector.bzl index d03ee3315..db235118d 100644 --- a/ts/css-browser-selector.bzl +++ b/ts/css-browser-selector.bzl @@ -6,7 +6,8 @@ _include = [ "css_browser_selector.min.js", ] -_unwanted_prefix = "external/npm/node_modules/css-browser-selector/" +_base = "external/npm/node_modules/css-browser-selector/" +_unwanted_prefix = "" def _copy_css_browser_selector_impl(ctx): return copy_select_files( @@ -14,6 +15,7 @@ def _copy_css_browser_selector_impl(ctx): ctx.attr.css_browser_selector.files, _include, [], + _base, _unwanted_prefix, ) diff --git a/ts/jquery-ui.bzl b/ts/jquery-ui.bzl index 482aa6985..baf547270 100644 --- a/ts/jquery-ui.bzl +++ b/ts/jquery-ui.bzl @@ -6,7 +6,8 @@ _include = [ "jquery-ui.min.js", ] -_unwanted_prefix = "external/npm/node_modules/jquery-ui-dist/" +_base = "external/npm/node_modules/jquery-ui-dist/" +_unwanted_prefix = "" def _copy_jquery_ui_impl(ctx): return copy_select_files( @@ -14,6 +15,7 @@ def _copy_jquery_ui_impl(ctx): ctx.attr.jquery_ui.files, _include, [], + _base, _unwanted_prefix, ) diff --git a/ts/jquery.bzl b/ts/jquery.bzl index f7a3542d8..b7f1c4a84 100644 --- a/ts/jquery.bzl +++ b/ts/jquery.bzl @@ -6,7 +6,8 @@ _include = [ "dist/jquery.min.js" ] -_unwanted_prefix = "external/npm/node_modules/jquery/dist/" +_base = "external/npm/node_modules/jquery/" +_unwanted_prefix = "dist/" def _copy_jquery_impl(ctx): return copy_select_files( @@ -14,6 +15,7 @@ def _copy_jquery_impl(ctx): ctx.attr.jquery.files, _include, [], + _base, _unwanted_prefix, ) diff --git a/ts/mathjax.bzl b/ts/mathjax.bzl index fcfd8d517..480e1f6e3 100644 --- a/ts/mathjax.bzl +++ b/ts/mathjax.bzl @@ -14,7 +14,8 @@ _exclude = [ "es5/sre/mathmaps/mathmaps_ie.js", ] -_unwanted_prefix = "external/npm/node_modules/mathjax/es5/" +_base = "external/npm/node_modules/mathjax/" +_unwanted_prefix = "es5/" def _copy_mathjax_impl(ctx): return copy_select_files( @@ -22,6 +23,7 @@ def _copy_mathjax_impl(ctx): ctx.attr.mathjax.files, _include, _exclude, + _base, _unwanted_prefix, ) diff --git a/ts/protobufjs.bzl b/ts/protobufjs.bzl index 80a26f26c..25c947251 100644 --- a/ts/protobufjs.bzl +++ b/ts/protobufjs.bzl @@ -6,7 +6,8 @@ _include = [ "dist/protobuf.min.js", ] -_unwanted_prefix = "external/npm/node_modules/protobufjs/dist/" +_base = "external/npm/node_modules/protobufjs/" +_unwanted_prefix = "dist/" def _copy_protobufjs_impl(ctx): return copy_select_files( @@ -14,6 +15,7 @@ def _copy_protobufjs_impl(ctx): ctx.attr.protobufjs.files, _include, [], + _base, _unwanted_prefix, )