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_plugin.py: some code can be placed outside of wrapper #356

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,22 @@ def process_file(source, out_dir, dist_path=None, deps_list=None):

path = source.parent # used as root for all (relative) paths
script = re.sub(r"'@bundle_code@';", partial(bundle_code, path=path), script)
try:
script_before_wrapper, script = script.split('\n/*wrapped-from-here*/\n', 1)
except ValueError:
script_before_wrapper = ''

wrapper = get_module(settings.plugin_wrapper)
template = r"'@(\w+)(?::([\w./-]+))?@'" # to find '@keyword[:path]@' patterns
repl = partial(expand_template, path=path)
data = [
meta,
script_before_wrapper,
re.sub(template, repl, wrapper.start),
re.sub(template, repl, script),
wrapper.setup,
wrapper.setup if not is_main else '', # it's for plugins only
wrapper.end,
]
if is_main:
data.pop(3) # remove wrapper.setup (it's for plugins only)

(out_dir / (plugin_name + '.user.js')).write_text(''.join(data), encoding='utf8')
if settings.url_dist_base and settings.update_file == '.meta.js':
Expand Down