Skip to content

Add dynamic workspace creation#2

Open
butlersrepos wants to merge 4 commits intomasterfrom
add-dynamic-workspace-creation
Open

Add dynamic workspace creation#2
butlersrepos wants to merge 4 commits intomasterfrom
add-dynamic-workspace-creation

Conversation

@butlersrepos
Copy link
Copy Markdown
Collaborator

Summary

This PR adds the ability to dynamically create namespace files during parsing when they don't exist, eliminating the need to pre-create namespace files before scanning.

Changes

  • Configuration Option: Added dynamicNamespaceCreation: false (disabled by default for backward compatibility)
  • Helper Method: Added createNamespaceFile(lng, ns) that safely creates namespace files and directory structure
  • Parser Integration: Modified parser logic to create namespaces when encountered instead of erroring
  • Comprehensive Tests: Added 5 test cases covering all scenarios including error handling

How it works

When dynamicNamespaceCreation: true is set in the configuration:

  1. Parser encounters a new namespace during key extraction
  2. Instead of throwing an error, it calls createNamespaceFile(lng, ns)
  3. Helper creates directory structure recursively if needed
  4. Writes empty JSON {} to the new namespace file
  5. Initializes internal resStore and resScan objects
  6. Parsing continues normally

Backward Compatibility

  • Feature is disabled by default (dynamicNamespaceCreation: false)
  • Existing behavior is preserved when disabled
  • No breaking changes to the API

Test Coverage

  • Dynamic creation when enabled
  • Error behavior when disabled (maintains existing functionality)
  • Recursive directory structure creation
  • Handling of existing files
  • Error scenarios and graceful failure

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings September 11, 2025 04:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optional dynamic namespace creation functionality that allows the parser to automatically create namespace files during parsing when they don't exist, instead of throwing errors. This eliminates the need to pre-create all namespace files before scanning begins.

  • Adds a new configuration option dynamicNamespaceCreation (disabled by default for backward compatibility)
  • Implements a helper method createNamespaceFile() that safely creates namespace files with proper directory structure
  • Modifies the parser's set() method to handle missing namespaces by creating them when the feature is enabled

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/parser.js Adds the core dynamic namespace creation functionality including configuration option, helper method, and parser logic modifications
test/parser.test.js Comprehensive test suite covering all scenarios including dynamic creation, error handling, and edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants