Skip to main content

filestate_javascript

Version: 6.6.5

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

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

  1. A filestate config declares javascript: {biome: true} for a target.
  2. JavascriptOptionsProvider.get_options surfaces JavascriptOption.
  3. JavascriptOption.set_value normalises the raw value; get_allowed_options routes it to BiomeOption.
  4. On the rectify cycle, BiomeOption.create_required_operation (via AbstractFileContentOption) collects all matching target paths, filters out generated files through _is_excluded_from_batch, and builds a batch operation.
  5. The batch operation calls _run_batch_on_paths, which calls _ensure_docker_container (building the javascript-option image from Dockerfile.javascript-option if it does not exist) and then runs biome format --write inside the container for each chunk of up to 30 paths.
  6. _apply_content_change reads back the formatted content from the in-memory cache populated by step 5.

Call path: npm package-lock

  1. A filestate config declares npm_package_lock: true for a directory target.
  2. JavascriptOption.get_allowed_options routes it to NpmPackageLockOption.
  3. NpmPackageLockOption.create_required_operation checks: is the option enabled? Does package.json exist? Is package-lock.json absent or older than package.json? If all conditions pass it returns a NpmPackageLockOperation.
  4. NpmPackageLockOperation.apply_operation deletes any stale lockfile and runs npm install --package-lock-only --ignore-scripts --prefer-online in 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.

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.3.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

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.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wexample-filestate-javascript 6.6.5
File Size Uploaded
wexample_filestate_javascript-6.6.5.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wexample-filestate-javascript 6.6.5
File Interpreter ABI Platform
wexample_filestate_javascript-6.6.5-py3-none-any.whl Python 3 none any Details

Total release size: 32.7 kB

Release files / wexample_filestate_javascript-6.6.5.tar.gz

Download URL wexample_filestate_javascript-6.6.5.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
92de69305ab3296aff855b0368bfd97b51f1ed938bd65e14c938141918a6e97b
BLAKE2b-256 checksum
How to use checksums
7bc4462d42b4976aa2fbcd5f068f2644b1f756a7fd5f4e423070dc534543c8f8
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.5-py3-none-any.whl

Download URL wexample_filestate_javascript-6.6.5-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab2f817c686e5908167188c1118fbdb66f4123bb87835afb5b36591302ef3c1a
BLAKE2b-256 checksum
How to use checksums
d67a59f05e7b6e4c7f618d0d0563754f88ec7edc1ca6debff1937f8325cfc0c3
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 history Release notifications | RSS feed

6.6.7

2 release files

6.6.6

2 release files

This release

6.6.5 This release

2 release files

6.6.4

2 release files

6.6.3

2 release files

6.6.2

2 release files

6.6.1

2 release files

6.6.0

2 release files

6.5.5

2 release files

6.5.4

2 release files

6.5.3

2 release files

6.5.2

2 release files

6.5.1

2 release files

6.5.0

2 release files

6.4.2

2 release files

6.4.1

2 release files

6.4.0

2 release files

6.3.5

2 release files

6.3.4

2 release files

6.3.3

2 release files

6.3.2

2 release files

6.3.1

2 release files

6.3.0

2 release files

6.1.0

2 release files

6.0.30

2 release files

6.0.29

2 release files

6.0.28

2 release files

6.0.23

2 release files

6.0.21

2 release files

6.0.20

2 release files

0.1.0

2 release files

0.0.15

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page