Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/identity-obj-proxy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @opensourceframework/identity-obj-proxy

## 3.0.1

### Patch Changes

- Initial release as `@opensourceframework/identity-obj-proxy`.
- Forked from `identity-obj-proxy` v3.0.0.
- Modernized build system to ESM + CJS using `tsup`.
- Added TypeScript type definitions.
48 changes: 48 additions & 0 deletions packages/identity-obj-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @opensourceframework/identity-obj-proxy

> An identity object using ES6 proxies. A maintained drop-in replacement for `identity-obj-proxy`.

This is a modern, actively maintained fork of the [original `identity-obj-proxy`](https://github.com/keyanzhang/identity-obj-proxy) package, which has been abandoned since 2022. It is fully backwards compatible and functions as a drop-in replacement.

## Why use this?

`identity-obj-proxy` is heavily used in the React/Next.js ecosystem for mocking CSS modules in Jest configurations. As the Node.js and Jest ecosystems have modernized, the original unmaintained package can cause compatibility issues or security warnings.

This fork is maintained by the **OpenSource Framework** team, ensuring it stays compatible with modern JavaScript environments (ESM, Node 20+, etc.).

## Installation

```bash
npm install -D @opensourceframework/identity-obj-proxy
# or
yarn add -D @opensourceframework/identity-obj-proxy
# or
pnpm add -D @opensourceframework/identity-obj-proxy
```

## Usage (Jest)

In your `jest.config.js`:

```javascript
module.exports = {
moduleNameMapper: {
"\\.(css|less|scss|sass)$": "@opensourceframework/identity-obj-proxy"
}
};
```

## How it works

When you import a CSS module in your tests, it replaces the import with a proxy object that simply returns the key.

```javascript
import styles from './styles.module.css';

console.log(styles.foo); // "foo"
console.log(styles.bar); // "bar"
```

## License

MIT
69 changes: 69 additions & 0 deletions packages/identity-obj-proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@opensourceframework/identity-obj-proxy",
"version": "3.0.1",
"description": "An identity object using ES6 proxies. A maintained drop-in replacement for the unmaintained identity-obj-proxy.",
"keywords": [
"proxy",
"proxies",
"identity",
"jest",
"mock"
],
"author": "OpenSource Framework Contributors (fork), Original: Keyan Zhang",
"license": "MIT",
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md",
"LICENSE",
"CHANGELOG.md"
],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"clean": "rm -rf dist coverage node_modules"
},
"devDependencies": {
"@types/node": "^22.0.0",
"@vitest/coverage-v8": "^2.1.9",
"tsup": "^8.5.1",
"typescript": "^5.9.3",
"vitest": "^2.1.9"
},
"repository": {
"type": "git",
"url": "git+https://github.com/riceharvest/opensourceframework.git",
"directory": "packages/identity-obj-proxy"
},
"bugs": {
"url": "https://github.com/riceharvest/opensourceframework/issues?q=is%3Aissue+is%3Aopen+identity-obj-proxy"
},
"homepage": "https://github.com/riceharvest/opensourceframework/tree/main/packages/identity-obj-proxy#readme",
"engines": {
"node": ">=18.0.0"
},
"publishConfig": {
"access": "public"
}
}
17 changes: 17 additions & 0 deletions packages/identity-obj-proxy/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* An identity object using ES6 proxies.
* Useful for mocking CSS modules in Jest where `styles.foo` evaluates to `"foo"`.
*/
const idObj = new Proxy(
{},
{
get: function getter(_target, key) {
if (key === '__esModule') {
return false;
}
return key;
},
}
);

export default idObj;
18 changes: 18 additions & 0 deletions packages/identity-obj-proxy/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest';
import idObj from '../src/index';

describe('identity-obj-proxy', () => {
it('returns the requested key as a string', () => {
// @ts-expect-error - testing proxy behavior
expect(idObj.foo).toBe('foo');
// @ts-expect-error - testing proxy behavior
expect(idObj.bar).toBe('bar');
// @ts-expect-error - testing proxy behavior
expect(idObj['some-complex-key']).toBe('some-complex-key');
});

it('returns false for __esModule to support ES module interop', () => {
// @ts-expect-error - testing proxy behavior
expect(idObj.__esModule).toBe(false);
});
});
8 changes: 8 additions & 0 deletions packages/identity-obj-proxy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/**/*", "test/**/*"],
"exclude": ["node_modules", "dist"]
}
11 changes: 11 additions & 0 deletions packages/identity-obj-proxy/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
clean: true,
sourcemap: true,
treeshake: true,
target: 'es2022',
});
Loading
Loading