Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions pywebpack/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ def __init__(
peerDependencies=None,
aliases=None,
copy=None,
scripts=None,
):
"""Initialize webpack bundle.

Expand All @@ -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 = {
Expand Down
17 changes: 15 additions & 2 deletions pywebpack/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
7 changes: 7 additions & 0 deletions pywebpack/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading