filestate_javascript
Version: 6.6.4
wexample-filestate-javascript extends wexample-filestate with two JavaScript-specific targets: it formats and lints .js, .ts, and related files through Biome running in a managed Docker container, and it regenerates package-lock.json whenever the file is absent or older than package.json. It is for Python developers who describe JavaScript project structure with the filestate declarative model and want Biome formatting and npm lockfile freshness enforced automatically during the rectify cycle.
Table of Contents
- Installation
- Quickstart
- Tests
- Architecture
- Integration in the Suite
- Dependencies
- Versioning & Compatibility Policy
- License
- About us
- Known Limitations & Roadmap
- Status & Compatibility
- Useful Links
- Migration Notes
Installation
pip install wexample-filestate-javascript
Requires Python >=3.10.
Quickstart
Install with pip:
pip install wexample-filestate-javascript
The package extends wexample-filestate through JavascriptOptionsProvider. Pass it when constructing your filestate tree so the framework discovers the javascript option key.
from wexample_filestate_javascript.options_provider.javascript_options_provider import JavascriptOptionsProvider
Declare the javascript key on any target in your filestate config. It accepts a dict of sub-options or a plain list of sub-option names.
Biome formatting — set biome: True on a file or directory target:
{
"path": "/path/to/project",
"javascript": {"biome": True},
}
On the rectify cycle the package builds and starts a Docker container from src/wexample_filestate_javascript/resources/docker/Dockerfile.javascript-option (node:20-alpine with @biomejs/biome installed globally). It then calls biome format --write against the target's .js, .ts, .jsx, and .tsx files in chunks of 30, using the Biome configuration baked into src/wexample_filestate_javascript/resources/docker/biome.json (2-space indent, line width 100, single quotes, semicolons always, trailing commas ES5, linter recommended rules plus useConst: error). Generated files — those ending in .gen.ts, .generated.ts, named next-env.d.ts, vite-env.d.ts, or located under /__generated__/ — are skipped silently.
npm lockfile freshness — set npm_package_lock: True on a directory target that contains package.json:
{
"path": "/path/to/js-project",
"javascript": {"npm_package_lock": True},
}
The operation runs only when package-lock.json is absent or its modification time is older than package.json. When it fires it deletes the stale lockfile and runs npm install --package-lock-only --ignore-scripts --prefer-online directly on the host in the target directory, writing a fresh package-lock.json.
Both options can be combined in a single declaration:
{
"path": "/path/to/js-project",
"javascript": {"biome": True, "npm_package_lock": True},
}
Tests
This project uses pytest for testing and pytest-cov for code coverage analysis.
Installation
First, install the required testing dependencies:
.venv/bin/python -m pip install pytest pytest-cov
Basic Usage
Run all tests with coverage:
.venv/bin/python -m pytest --cov --cov-report=html
Common Commands
# Run tests with coverage for a specific module
.venv/bin/python -m pytest --cov=your_module
# Show which lines are not covered
.venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
# Generate an HTML coverage report
.venv/bin/python -m pytest --cov=your_module --cov-report=html
# Combine terminal and HTML reports
.venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
# Run specific test file with coverage
.venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
Viewing HTML Reports
After generating an HTML report, open htmlcov/index.html in your browser to view detailed line-by-line coverage information.
Coverage Threshold
To enforce a minimum coverage percentage:
.venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
This will cause the test suite to fail if coverage drops below 80%.
Architecture
The package extends wexample-filestate with two JavaScript-specific behaviours: formatting and linting .js/.ts files through Biome running in a managed Docker container, and regenerating package-lock.json whenever it is absent or older than package.json. Everything in the package lives under src/wexample_filestate_javascript/.
Parts
Entry point — options provider
src/wexample_filestate_javascript/options_provider/javascript_options_provider.py is the package's registration point. JavascriptOptionsProvider extends AbstractOptionsProvider, advertises a single top-level option (JavascriptOption), and forwards the Docker image name from AbstractJavascriptFileContentOption.DOCKER_IMAGE_NAME.
File type
src/wexample_filestate_javascript/file/javascript_file.py defines JavascriptFile, which extends ItemTargetFile and sets EXTENSION_ENV = "js". It owns the extension assertion; nothing else does.
Top-level option
src/wexample_filestate_javascript/option/javascript_option.py defines JavascriptOption, a @base_class-decorated AbstractNestedConfigOption. Its get_allowed_options returns [BiomeOption, NpmPackageLockOption], making it a pure dispatcher: it accepts the raw value (list or dict), normalises a plain list to a dict, then delegates create_required_operation to _create_child_required_operation.
Typed config value and config-option name
src/wexample_filestate_javascript/config_value/javascript_config_value.py provides JavascriptConfigValue, a ConfigValue subclass with a single typed field biome: bool | None. Its to_option_raw_value converts that field to {"biome": self.biome}, bridging the typed API to the string-keyed option dispatch.
src/wexample_filestate_javascript/config_option/biome_config_option.py provides the canonical name string "biome" used as that key.
File extension constants
src/wexample_filestate_javascript/const/javascript_file.py collects JAVASCRIPT_FILE_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"] and JAVASCRIPT_FILE_EXTENSION = ".js" in one place.
Docker base for file-content options
src/wexample_filestate_javascript/option/javascript/abstract_javascript_file_content_option.py defines AbstractJavascriptFileContentOption, which extends both WithBatchDockerOptionMixin and AbstractFileContentOption. It sets DOCKER_IMAGE_NAME = "javascript-option" and returns the path to src/wexample_filestate_javascript/resources/docker/Dockerfile.javascript-option via _get_dockerfile_path. Concrete options inherit this class to run inside that container.
Biome option
src/wexample_filestate_javascript/option/javascript/biome_option.py defines BiomeOption. _is_excluded_from_batch silently skips generated files (.gen.ts, .generated.ts, next-env.d.ts, paths under /__generated__/, etc.) to avoid non-idempotent output on large codegen trees. _run_batch_on_paths sends paths to the container in chunks of 30 (_BATCH_CHUNK_SIZE = 30) to avoid OOM kills, calling biome format --write --config-path=/tmp/biome.json per chunk. _apply_content_change reads the result from the batch cache built by that run.
Npm package-lock option
src/wexample_filestate_javascript/option/javascript/npm_package_lock_option.py defines NpmPackageLockOption. create_required_operation returns None immediately if the option value is false/none, if package.json is absent, or if package-lock.json already exists and its mtime is at least as recent as package.json. Otherwise it returns a NpmPackageLockOperation.
Npm package-lock operation
src/wexample_filestate_javascript/operation/npm_package_lock_operation.py defines NpmPackageLockOperation. apply_operation deletes any stale lockfile then runs npm install --package-lock-only --ignore-scripts --prefer-online in the package directory on the host (no Docker). undo is a no-op because lockfile creation is not reversible automatically.
Docker resources
src/wexample_filestate_javascript/resources/docker/Dockerfile.javascript-option builds the javascript-option image: node:20-alpine with @biomejs/biome installed globally, and src/wexample_filestate_javascript/resources/docker/biome.json copied to /tmp/biome.json. The container runs as UID/GID 1000 and stays alive with tail -f /dev/null.
src/wexample_filestate_javascript/resources/docker/biome.json configures Biome: formatter enabled with 2-space indent and line width 100, single quotes, semicolons always, trailing commas ES5; linter enabled with the recommended rule set plus useConst: error and noUnusedVariables: warn.
Call path: Biome formatting
- A filestate config declares
javascript: {biome: true}for a target. JavascriptOptionsProvider.get_optionssurfacesJavascriptOption.JavascriptOption.set_valuenormalises the raw value;get_allowed_optionsroutes it toBiomeOption.- On the rectify cycle,
BiomeOption.create_required_operation(viaAbstractFileContentOption) collects all matching target paths, filters out generated files through_is_excluded_from_batch, and builds a batch operation. - The batch operation calls
_run_batch_on_paths, which calls_ensure_docker_container(building thejavascript-optionimage fromDockerfile.javascript-optionif it does not exist) and then runsbiome format --writeinside the container for each chunk of up to 30 paths. _apply_content_changereads back the formatted content from the in-memory cache populated by step 5.
Call path: npm package-lock
- A filestate config declares
npm_package_lock: truefor a directory target. JavascriptOption.get_allowed_optionsroutes it toNpmPackageLockOption.NpmPackageLockOption.create_required_operationchecks: is the option enabled? Doespackage.jsonexist? Ispackage-lock.jsonabsent or older thanpackage.json? If all conditions pass it returns aNpmPackageLockOperation.NpmPackageLockOperation.apply_operationdeletes any stale lockfile and runsnpm install --package-lock-only --ignore-scripts --prefer-onlinein the target directory directly on the host.
Integration in the Suite
This package is part of the Wexample Suite — a collection of high-quality, modular tools designed to work seamlessly together across multiple languages and environments.
Related Packages
The suite includes packages for configuration management, file handling, prompts, and more. Each package can be used independently or as part of the integrated suite.
Visit the Wexample Suite documentation for the complete package ecosystem.
Dependencies
- attrs: >=23.1.0
- cattrs: >=23.1.0
- wexample-filestate: >=17.2.0
Versioning & Compatibility Policy
Wexample packages follow Semantic Versioning (SemVer):
- MAJOR: Breaking changes
- MINOR: New features, backward compatible
- PATCH: Bug fixes, backward compatible
We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Free to use in both personal and commercial projects.
About us
Wexample stands as a cornerstone of the digital ecosystem — a collective of seasoned engineers, researchers, and creators driven by a relentless pursuit of technological excellence. More than a media platform, it has grown into a vibrant community where innovation meets craftsmanship, and where every line of code reflects a commitment to clarity, durability, and shared intelligence.
This packages suite embodies this spirit. Trusted by professionals and enthusiasts alike, it delivers a consistent, high-quality foundation for modern development — open, elegant, and battle-tested. Its reputation is built on years of collaboration, refinement, and rigorous attention to detail, making it a natural choice for those who demand both robustness and beauty in their tools.
Wexample cultivates a culture of mastery. Each package, each contribution carries the mark of a community that values precision, ethics, and innovation — a community proud to shape the future of digital craftsmanship.
Known Limitations & Roadmap
Current limitations and planned features are tracked in the GitHub issues.
See the project roadmap for upcoming features and improvements.
Status & Compatibility
Maturity: Production-ready
Python Support: >=3.10
OS Support: Linux, macOS, Windows
Status: Actively maintained
Useful Links
- Homepage: https://github.com/wexample/python-filestate-javascript
- Documentation: docs.wexample.com
- Issue Tracker: https://github.com/wexample/python-filestate-javascript/issues
- Discussions: https://github.com/wexample/python-filestate-javascript/discussions
- PyPI: pypi.org/project/wexample-filestate-javascript
Migration Notes
When upgrading between major versions, refer to the migration guides in the documentation.
Breaking changes are clearly documented with upgrade paths and examples.
Metadata
Release files for wexample-filestate-javascript 6.6.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wexample_filestate_javascript-6.6.4.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wexample_filestate_javascript-6.6.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.7 kB
Release files / wexample_filestate_javascript-6.6.4.tar.gz
| Download URL | wexample_filestate_javascript-6.6.4.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a849311e7bc6af8f9b409e8158ec4ab8903aab8794af27c653deac4d32ff2ba2
|
|
BLAKE2b-256 checksum How to use checksums |
9d63712d38c8c50898f14bc029f35606fc3f215d788819b74cdcf6dc2daffff2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.25.9 CPython/3.12.3 Linux/6.8.0-139-generic
|
Release files / wexample_filestate_javascript-6.6.4-py3-none-any.whl
| Download URL | wexample_filestate_javascript-6.6.4-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
642f486fcd9393e9f93fbd207b498748bae4015bbe2ad12d078c85ab174d213a
|
|
BLAKE2b-256 checksum How to use checksums |
fd1a7f9732c9ab646cf2e627091a2d14e4114120602a3d938b48daf61d10bc35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.25.9 CPython/3.12.3 Linux/6.8.0-139-generic
|