diff --git a/pywebpack/bundle.py b/pywebpack/bundle.py index d4905f6..bdc0afc 100644 --- a/pywebpack/bundle.py +++ b/pywebpack/bundle.py @@ -2,6 +2,7 @@ # # This file is part of PyWebpack # Copyright (C) 2017 CERN. +# Copyright (C) 2025 Graz University of Technology. # # PyWebpack is free software; you can redistribute it and/or modify # it under the terms of the Revised BSD License; see LICENSE file for @@ -22,6 +23,7 @@ def __init__( peerDependencies=None, aliases=None, copy=None, + scripts=None, ): """Initialize webpack bundle. @@ -37,6 +39,7 @@ def __init__( ``{"from": "source_path", "to": "dest_path"}`` for copying assets. Paths are relative to the directory of the resulting config. """ + self.scripts = scripts self.path = path self.entry = entry or {} self.dependencies = { diff --git a/pywebpack/project.py b/pywebpack/project.py index ffbd820..3177caa 100644 --- a/pywebpack/project.py +++ b/pywebpack/project.py @@ -3,6 +3,7 @@ # This file is part of PyWebpack # Copyright (C) 2017-2020 CERN. # Copyright (C) 2020 Cottage Labs LLP. +# Copyright (C) 2025 Graz University of Technology. # # PyWebpack is free software; you can redistribute it and/or modify # it under the terms of the Revised BSD License; see LICENSE file for @@ -350,14 +351,26 @@ def dependencies(self): raise MergeConflictError(new_msg) return res + @property + @cached + def scripts(self): + """Get scripts.""" + res = {} + for b in self.bundles: + if b.scripts: + res.update(b.scripts) + return res + @property @cached def package_json(self): - """Merge bundle dependencies into ``package.json``.""" + """Merge bundle configuration into ``package.json``.""" # Reads package.json from the project_template_dir and merges in # bundle dependencies. Note, that package.json is not symlinked # because then we risk changing the source package.json automatically. - return merge_deps(self.package_json_source, self.dependencies) + package_json = merge_deps(self.package_json_source, self.dependencies) + package_json["scripts"].update(self.scripts) + return package_json def collect(self, force=None): """Collect asset files from bundles.""" diff --git a/pywebpack/storage.py b/pywebpack/storage.py index 01415b4..68b27eb 100644 --- a/pywebpack/storage.py +++ b/pywebpack/storage.py @@ -2,6 +2,7 @@ # # This file is part of PyWebpack # Copyright (C) 2017 CERN. +# Copyright (C) 2025 Graz University of Technology. # # PyWebpack is free software; you can redistribute it and/or modify # it under the terms of the Revised BSD License; see LICENSE file for @@ -16,6 +17,9 @@ def iter_files(folder): """Iterate all files in a given root directory.""" + if folder is None: + return + for root, dirnames, filenames in walk(folder): for f in filenames: f = join(root, f) @@ -27,6 +31,9 @@ def iter_paths(folder, root=None, depth=None): assert depth is None or depth >= 0 root = root or folder # needed to compute the relative name + if folder is None: + return + if depth is None: # yield all paths for result in iter_files(folder): yield result