Load a :class:`WebModule` from a given ``file`` Parameters: name: The name of the package file: The file from which the content of the web module will be created. fallback: What to temporarily display while the module is being loaded.
(
name: str,
file: str | Path,
fallback: Any | None = None,
resolve_exports: bool | None = None,
resolve_exports_depth: int = 5,
unmount_before_update: bool = False,
symlink: bool = False,
)
| 158 | |
| 159 | |
| 160 | def module_from_file( |
| 161 | name: str, |
| 162 | file: str | Path, |
| 163 | fallback: Any | None = None, |
| 164 | resolve_exports: bool | None = None, |
| 165 | resolve_exports_depth: int = 5, |
| 166 | unmount_before_update: bool = False, |
| 167 | symlink: bool = False, |
| 168 | ) -> WebModule: |
| 169 | """Load a :class:`WebModule` from a given ``file`` |
| 170 | |
| 171 | Parameters: |
| 172 | name: |
| 173 | The name of the package |
| 174 | file: |
| 175 | The file from which the content of the web module will be created. |
| 176 | fallback: |
| 177 | What to temporarily display while the module is being loaded. |
| 178 | resolve_imports: |
| 179 | Whether to try and find all the named exports of this module. |
| 180 | resolve_exports_depth: |
| 181 | How deeply to search for those exports. |
| 182 | unmount_before_update: |
| 183 | Cause the component to be unmounted before each update. This option should |
| 184 | only be used if the imported package fails to re-render when props change. |
| 185 | Using this option has negative performance consequences since all DOM |
| 186 | elements must be changed on each render. See :issue:`461` for more info. |
| 187 | symlink: |
| 188 | Whether the web module should be saved as a symlink to the given ``file``. |
| 189 | """ |
| 190 | name += module_name_suffix(name) |
| 191 | |
| 192 | source_file = Path(file).resolve() |
| 193 | target_file = _web_module_path(name) |
| 194 | if not source_file.exists(): |
| 195 | msg = f"Source file does not exist: {source_file}" |
| 196 | raise FileNotFoundError(msg) |
| 197 | |
| 198 | if not target_file.exists(): |
| 199 | _copy_file(target_file, source_file, symlink) |
| 200 | elif not _equal_files(source_file, target_file): |
| 201 | logger.info( |
| 202 | f"Existing web module {name!r} will " |
| 203 | f"be replaced with {target_file.resolve()}" |
| 204 | ) |
| 205 | target_file.unlink() |
| 206 | _copy_file(target_file, source_file, symlink) |
| 207 | |
| 208 | return WebModule( |
| 209 | source=name, |
| 210 | source_type=NAME_SOURCE, |
| 211 | default_fallback=fallback, |
| 212 | file=target_file, |
| 213 | export_names=( |
| 214 | resolve_module_exports_from_file(source_file, resolve_exports_depth) |
| 215 | if ( |
| 216 | resolve_exports |
| 217 | if resolve_exports is not None |
nothing calls this directly
no test coverage detected