Skip to content

Commit 6f673cb

Browse files
committed
feat: enhance dedupe-packages plugin to resolve @codebelt/classy-store imports to source files
1 parent b4bc1b2 commit 6f673cb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

examples/demo/dedupe-react.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
import {existsSync} from 'node:fs';
2+
import path from 'node:path';
13
import type {BunPlugin} from 'bun';
24

35
const root = import.meta.dir;
6+
const pkgSrc = path.resolve(root, '../../packages/classy-store/src');
47

58
const dedupeReact: BunPlugin = {
6-
name: 'dedupe-react',
9+
name: 'dedupe-packages',
710
setup(build) {
811
build.onResolve({filter: /^react(-dom)?(\/.*)?$/}, (args) => ({
912
path: Bun.resolveSync(args.path, root),
1013
}));
14+
// Resolve all @codebelt/classy-store imports to source files
15+
// to avoid duplicate module instances (src vs dist).
16+
build.onResolve(
17+
{filter: /^@codebelt\/classy-store(\/.*)?$/},
18+
(args) => {
19+
const subpath = args.path.replace('@codebelt/classy-store', '');
20+
if (!subpath || subpath === '/') {
21+
return {path: path.join(pkgSrc, 'index.ts')};
22+
}
23+
const name = subpath.slice(1);
24+
const direct = path.join(pkgSrc, name, `${name}.ts`);
25+
if (existsSync(direct)) return {path: direct};
26+
return {path: path.join(pkgSrc, name, 'index.ts')};
27+
},
28+
);
1129
},
1230
};
1331

0 commit comments

Comments
 (0)