
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@slimlib/smart-mock
Advanced tools
Yet another proxy mock (YAPM?). Still in a very early state (EXPECT BUGS!).
Mock that records operations for code generation later. Idea is somewhat similar to prepack
but instead of interpreting code by other JS code we run it in JS VM and later use mock to repeat the same operations. Ideally combined with a terser like optimizer. Please check the example in pkgbld
how it is used to eject config.
() => { createMock, generateGlobals, generate }
Default export function is a factory that creates 3 other functions with shared state.
createMock<T extends object>(object: T, name: string): T
Function to create mock wrapper around object and defining global name for later usage. object
can be a real original object or a pure mock object with the same behavior for the specific situation. All operations on this object will be recorded by mock.
generate(object: unknown): string
Function to generate code for some export point (exit point). It will try to automatically inline operations that can be inlined.
generateGlobals(): string
Function to generate global code that cannot be inlined to exit point.
import createMockProvider from '@slimlib/smart-mock';
const { createMock, generate, generateGlobals } = createMockProvider();
const mock = createMock({
fly() { return { status: 'flying' }; },
land() {},
name: ''
}, 'fly');
mock.name = 'Moth';
const status = mock.fly();
mock.land();
At this point generate(mock)
will result in mock
, generate(mock.name)
in 'Moth'
and generate(status)
in fly.fly()
. And if you afterwards call generateGlobals()
you get something like:
fly.name = "Moth"
const tmp_0 = fly.land
tmp_0()
Each generate
call updates counters / flags in mock so generateGlobals
only emits what was not generated at the time of call.
FAQs
One more proxy based mock
The npm package @slimlib/smart-mock receives a total of 69 weekly downloads. As such, @slimlib/smart-mock popularity was classified as not popular.
We found that @slimlib/smart-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.