Skip to content

Commit 4398a66

Browse files
author
johnd0e
authored
Merge pull request #356 from johnd0e/code-before-wrapper
build_plugin.py: some code can be placed outside of wrapper Close #354 To leave some code out of wrapper use special marker (on separate line): ```js 'this_is_unwrapped'; /*wrapped-from-here*/ ```
2 parents ea9cb98 + ae5b9f1 commit 4398a66

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

build_plugin.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,22 @@ def process_file(source, out_dir, dist_path=None, deps_list=None):
166166

167167
path = source.parent # used as root for all (relative) paths
168168
script = re.sub(r"'@bundle_code@';", partial(bundle_code, path=path), script)
169+
try:
170+
script_before_wrapper, script = script.split('\n/*wrapped-from-here*/\n', 1)
171+
except ValueError:
172+
script_before_wrapper = ''
173+
169174
wrapper = get_module(settings.plugin_wrapper)
170175
template = r"'@(\w+)(?::([\w./-]+))?@'" # to find '@keyword[:path]@' patterns
171176
repl = partial(expand_template, path=path)
172177
data = [
173178
meta,
179+
script_before_wrapper,
174180
re.sub(template, repl, wrapper.start),
175181
re.sub(template, repl, script),
176-
wrapper.setup,
182+
wrapper.setup if not is_main else '', # it's for plugins only
177183
wrapper.end,
178184
]
179-
if is_main:
180-
data.pop(3) # remove wrapper.setup (it's for plugins only)
181185

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

0 commit comments

Comments
 (0)