Symbol extraction is the process by which napi
can extract functionality from your codebase for creating microservices, serverless functions, or other functional subsets from much, much larger codebases.
There are currently two ways that our tool supports this:
What does the extraction process do?
Put simply, symbol extraction pulls selected symbols (classes, functions, etc) from selected files and creates an output codebase in the napi
output directory (defaulted to napi_out
).
A helpful way to think of this is similar to modular monoliths, whereby microservices, or other smaller pieces of functionality can be directly lifted out of an existing codebase.
The best part - this can be achieved without any expensive rewrites of the underlying frameworks.
What is the output of an extraction?
The output of an extraction process is a sub-codebase representing only the functionality and dependencies needed to run a portion of an existing codebase.
Are there any caveats?
While the symbol extraction process is robust, there are some considerations:
-
Dynamic Language Features:
- The tool performs best with statically analyzable code. Highly dynamic features (e.g., runtime introspection, dynamic imports, or metaprogramming) may not always be fully captured.
-
Internal State Management:
-
Codebases that make use of in-memory state management systems (such as event systems or tasks) need to be extracted with caution. Events and other state operations that are triggered cross-codebase via named events may not be caught by the extraction, and could lead to a broken output codebase.
-
For these codebases, it is recommended to include all aspects of the code which use the event systems in the output codebase, or else to not include any state-dependent code.
-
-
Framework Boilerplate:
-
The output codebase could miss supporting files such as configuration files, deployment config, or framework-specific setup.
-
While we are working on improving this, for now it’s recommended to double-check these files manually after running an extraction.
-
Understanding these caveats ensures that your team leverages symbol extraction effectively and accurately.