Skip to content

feat: Add sync module, refactor core module, update build#12

Merged
mitsuki31 merged 8 commits intomasterfrom
refactor/core-and-add-sync-module
Dec 11, 2025
Merged

feat: Add sync module, refactor core module, update build#12
mitsuki31 merged 8 commits intomasterfrom
refactor/core-and-add-sync-module

Conversation

@mitsuki31
Copy link
Owner

Overview

This branch reshapes several parts of the project: the core module is reorganized, type definitions are corrected, a synchronous variant of the library is introduced, and the build process gains a postbuild cleanup phase. Documentation and tests have been adjusted to match the new structure. The goal is to tighten the internal design while making the API surface more predictable for users and Intellisense.

Introduce New Sync Module

Synchronous version of LSFND has been implemented. Users can imports them from /sync submodule of lsfnd. For example:

import { ls, lsTypes } from "lsfnd/sync";
// Or:
const { ls, lsTypes } = require("lsfnd/sync");

Changes Made

  • Updated the README to reflect the current state of the project.
  • Introduced a postbuild step and modified the production TypeScript configuration to preserve comments in transpiled output.
  • Added the scripts/postbuild module, including the removeMultilineCommentsAfterUseStrict utility.
  • Removed the old API type implementations from types/index.
  • Added postbuild script to package.json.
  • Added full test coverage for the new lsfnd-sync module, including CJS and ESM variants.
  • Updated existing tests and test scripts to accommodate the new modules.
  • Added the lsfnd-sync module, a synchronous counterpart to the core module with code adapted appropriately.
  • Reorganized the core module, moving utilities into a dedicated utils module and constants into a new constants module.
  • Refined the core logic by fixing unresolved types for match and exclude, enhancing resolveOptions to accept RegExp, and adding a special case for LS_A when passed 0.
  • Improved internal type definitions, correcting the LsTypesValues type, strengthening ResolvedLsOptions, and removing redundant casts.
  • Made all ls* functions to guaranteed accept both string keys and numeric values from lsTypes, throwing errors on unknown values.

Impact

The internal structure becomes clearer and easier to maintain. Type safety improves across the board, reducing silent inconsistencies and making the API more predictable. The synchronous module fills a long-standing gap for environments where async behavior is less desirable. Tooling improvements ensure the output retains necessary comments while removing module-generated clutter. Developers will get cleaner IntelliSense results with better documentation visibility.

Summary

This update pulls several threads together: reorganized internals, corrected types, a new synchronous API, an improved build pipeline, and refined tests. The project becomes more coherent without changing its fundamental behavior.

- Fixed the `LsTypesValues` type definition to iterate through
  `LsTypesInterface` interface to get the values instead of
  `keyof typeof LsTypesInterface`
- Improved the `ResolvedLsOptions` and keeping the `exclude` property
  to have `undefined` type exclusively
- Removed redundant and unnecessary type casting in core (`lsfnd`)
  module
- Improved all types (including functions' parameters) within core
  module

In addition, this change also make all `ls*` functions (`ls`, `lsDirs`,
and `lsFiles`) to support to use `lsTypes` keys (string) or values
(numbers) with stable and will throws an error if specified any unknown
values (not including nullable values).
- Fixed unresolved type for `match` and `exclude` options
- Updated the `resolveOptions` util function to accept RegExp also for
  more convenience when being used
- Added special case with value 0 for case `LS_A`, it will behaves
  similar to `LS_A` and list both files and directories
- Several code improvements
- Migrated all utility functions to new `utils` module
- Moved all constants from core module to new `constants` module
The code inside are mirroring to the core module (`lsfnd.ts`) with some
adjustments for synchronous operations.
- Added test modules `lsfnd-sync.spec.cjs` and `lsfnd-sync.spec.mjs`
- Readjusted the expected values within the existing test modules
- Updated the `test:cjs` and `test:mjs` scripts within `package.json`
  to include and run the new test modules
- Updated the `tsconfig.production.json` to preserve comments for
  transpiled files
- Added `scripts/postbuild` module
  - Added `removeMultilineCommentsAfterUseStrict` function to remove the
    module's header comment
- Removed the APIs type implementation from `types/index` module
- Added `postbuild` script to `package.json` executing the
  `scripts/postbuild` module

With this change, we can guarantee the APIs are now will appears along
with the documentation when used with Intellisense.
@mitsuki31 mitsuki31 self-assigned this Dec 11, 2025
@mitsuki31 mitsuki31 added enhancement New feature or request minor Minor changes (e.g., introduce new features and APIs) refactor Refactor changes labels Dec 11, 2025
@mitsuki31 mitsuki31 merged commit 051c7fd into master Dec 11, 2025
4 checks passed
@mitsuki31 mitsuki31 deleted the refactor/core-and-add-sync-module branch December 11, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request minor Minor changes (e.g., introduce new features and APIs) refactor Refactor changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant