···1818import { createDerivedSignal } from './lib/signals';
1919import { useSearchParams } from './lib/use-search-params';
2020import { progress } from './npm/events';
2121+import type { ProgressMessage } from './npm/types';
2122import { initPackage } from './npm/worker-client';
2222-import type { ProgressMessage } from './npm/worker-protocol';
2323import Button from './primitives/button';
2424import Tooltip from './primitives/tooltip';
2525
+1-3
src/components/package-bundle.tsx
···55import { LRUCache } from '../lib/lru';
66import { createQuery } from '../lib/query';
77import { createDerivedSignal } from '../lib/signals';
88-import type { BundleResult } from '../npm/bundler';
98import { progress } from '../npm/events';
1010-import type { DiscoveredSubpaths } from '../npm/subpaths';
99+import type { BundleResult, DiscoveredSubpaths, ProgressMessage } from '../npm/types';
1110import type { BundlerWorker } from '../npm/worker-client';
1212-import type { ProgressMessage } from '../npm/worker-protocol';
1311import Button from '../primitives/button';
1412import * as Dropdown from '../primitives/dropdown';
1513import * as Field from '../primitives/field';
+1-1
src/components/package-dependencies.tsx
···33import { LucideSearch } from '../icons/lucide';
44import { tw } from '../lib/classes';
55import { formatBytes } from '../lib/format';
66-import type { InstalledPackage } from '../npm/worker-protocol';
66+import type { InstalledPackage } from '../npm/types';
77import * as Dropdown from '../primitives/dropdown';
88import Input from '../primitives/input';
99import Tooltip from '../primitives/tooltip';
···22import { rolldown } from '@rolldown/browser';
33import { memfs } from '@rolldown/browser/experimental';
4455+import { progress } from '../events';
66+import type { BundleChunk, BundleOptions, BundleResult } from '../types';
77+58import { BundleError } from './errors';
66-import { progress } from './events';
79import { analyzeModule } from './module-type';
81099-const { volume } = memfs!;
1010-1111-// #region types
1111+export type { BundleChunk, BundleOptions, BundleResult };
12121313-/**
1414- * options for bundling.
1515- */
1616-export interface BundleOptions {
1717- /** additional rolldown options */
1818- rolldown?: {
1919- /** external packages to exclude from bundle */
2020- external?: string[];
2121- /** whether to minify */
2222- minify?: boolean;
2323- };
2424-}
2525-2626-/**
2727- * a bundled chunk.
2828- */
2929-export interface BundleChunk {
3030- /** chunk filename */
3131- fileName: string;
3232- /** the bundled code */
3333- code: string;
3434- /** raw size in bytes */
3535- size: number;
3636- /** gzipped size in bytes */
3737- gzipSize: number;
3838- /** brotli size in bytes, if supported */
3939- brotliSize?: number;
4040- /** whether this is the entry chunk */
4141- isEntry: boolean;
4242- /** exported names from this chunk */
4343- exports: string[];
4444-}
4545-4646-/**
4747- * result of bundling a package.
4848- */
4949-export interface BundleResult {
5050- /** all output chunks */
5151- chunks: BundleChunk[];
5252- /** total raw size in bytes (all chunks) */
5353- size: number;
5454- /** total gzipped size in bytes (all chunks) */
5555- gzipSize: number;
5656- /** total brotli size in bytes (all chunks), if supported */
5757- brotliSize?: number;
5858- /** exported names from the entry chunk */
5959- exports: string[];
6060- /** whether the entry module is CommonJS */
6161- isCjs: boolean;
6262-}
6363-6464-// #endregion
1313+const { volume } = memfs!;
65146615// #region helpers
6716
src/npm/errors.ts
src/npm/lib/errors.ts
+1-1
src/npm/events.ts
···11import { createEventEmitter } from '../lib/emitter';
2233-import type { ProgressMessage } from './worker-protocol';
33+import type { ProgressMessage } from './types';
4455/**
66 * emitted during package initialization and bundling.
src/npm/fetch.test.ts
src/npm/lib/fetch.test.ts
+2-1
src/npm/fetch.ts
src/npm/lib/fetch.ts
···11import { untar } from '@mary/tar';
22import type { Volume } from 'memfs';
3344+import { progress } from '../events';
55+46import { FetchError } from './errors';
55-import { progress } from './events';
67import type { HoistedNode, HoistedResult } from './types';
7889/**
···11-import type { ResolvedPackage } from './types';
22-import type { InstalledPackage } from './worker-protocol';
11+import type { InstalledPackage, PackageRef } from '../types';
3244-/**
55- * reference to a package in a dependency relationship.
66- */
77-interface PackageRef {
88- name: string;
99- version: string;
1010- isPeer: boolean;
1111-}
33+import type { ResolvedPackage } from './types';
124135/**
146 * builds the installed packages list from the resolved dependency tree.
+141
src/npm/lib/types.ts
···11+/**
22+ * the parsed package.json of the main package.
33+ * includes fields relevant for export discovery and display.
44+ */
55+export interface PackageJson {
66+ name: string;
77+ version: string;
88+ description?: string;
99+ license?: string;
1010+ main?: string;
1111+ module?: string;
1212+ browser?: string | Record<string, string | false>;
1313+ types?: string;
1414+ typings?: string;
1515+ exports?: PackageExports;
1616+ type?: 'module' | 'commonjs';
1717+ peerDependencies?: Record<string, string>;
1818+}
1919+2020+/**
2121+ * package exports field - can be a string, array, object, or nested conditions.
2222+ * https://nodejs.org/api/packages.html#exports
2323+ */
2424+export type PackageExports = string | string[] | { [key: string]: PackageExports } | null;
2525+2626+/**
2727+ * npm registry packument - the full metadata for a package including all versions.
2828+ * fetched from registry.npmjs.org/{package-name}
2929+ */
3030+export interface Packument {
3131+ name: string;
3232+ 'dist-tags': Record<string, string>;
3333+ versions: Record<string, PackageManifest>;
3434+ time?: Record<string, string>;
3535+}
3636+3737+/**
3838+ * package manifest for a specific version.
3939+ * this is what you'd find in a package.json plus registry metadata.
4040+ */
4141+export interface PackageManifest {
4242+ name: string;
4343+ version: string;
4444+ description?: string;
4545+ license?: string;
4646+ main?: string;
4747+ module?: string;
4848+ exports?: PackageExports;
4949+ type?: 'module' | 'commonjs';
5050+ dependencies?: Record<string, string>;
5151+ devDependencies?: Record<string, string>;
5252+ peerDependencies?: Record<string, string>;
5353+ peerDependenciesMeta?: Record<string, { optional?: boolean }>;
5454+ optionalDependencies?: Record<string, string>;
5555+ dist: {
5656+ tarball: string;
5757+ integrity?: string;
5858+ shasum?: string;
5959+ /** total unpacked size in bytes */
6060+ unpackedSize?: number;
6161+ /** number of files in the tarball */
6262+ fileCount?: number;
6363+ };
6464+}
6565+6666+/**
6767+ * a resolved package with its dependencies.
6868+ * this is the output of the resolution step before hoisting.
6969+ */
7070+export interface ResolvedPackage {
7171+ name: string;
7272+ version: string;
7373+ /** the tarball URL for fetching */
7474+ tarball: string;
7575+ /** SRI integrity hash if available */
7676+ integrity?: string;
7777+ /** unpacked size in bytes (from registry) */
7878+ unpackedSize?: number;
7979+ /** package description */
8080+ description?: string;
8181+ /** license identifier */
8282+ license?: string;
8383+ /** resolved dependencies (name -> ResolvedPackage) */
8484+ dependencies: Map<string, ResolvedPackage>;
8585+}
8686+8787+/**
8888+ * supported package registries.
8989+ */
9090+export type Registry = 'npm' | 'jsr';
9191+9292+/**
9393+ * the input to the resolver - a package specifier.
9494+ * can be just a name (uses latest) or name@version/range.
9595+ */
9696+export interface PackageSpecifier {
9797+ name: string;
9898+ /** version, range, or dist-tag. defaults to 'latest' */
9999+ range: string;
100100+ /** which registry to fetch from. defaults to 'npm' */
101101+ registry: Registry;
102102+}
103103+104104+/**
105105+ * the full resolution result - a tree of resolved packages.
106106+ */
107107+export interface ResolutionResult {
108108+ /** the root package(s) that were requested */
109109+ roots: ResolvedPackage[];
110110+ /** all unique packages in the resolution (for deduping) */
111111+ packages: Map<string, ResolvedPackage>;
112112+}
113113+114114+/**
115115+ * a node in the hoisted node_modules structure.
116116+ * represents what should be written to node_modules/{name}
117117+ */
118118+export interface HoistedNode {
119119+ name: string;
120120+ version: string;
121121+ tarball: string;
122122+ integrity?: string;
123123+ /** unpacked size in bytes (from registry) */
124124+ unpackedSize?: number;
125125+ /** package description */
126126+ description?: string;
127127+ /** license identifier */
128128+ license?: string;
129129+ /** number of direct dependencies */
130130+ dependencyCount: number;
131131+ /** nested node_modules for this package (when hoisting fails) */
132132+ nested: Map<string, HoistedNode>;
133133+}
134134+135135+/**
136136+ * the result of hoisting - a flat(ish) node_modules structure.
137137+ */
138138+export interface HoistedResult {
139139+ /** top-level node_modules entries */
140140+ root: Map<string, HoistedNode>;
141141+}
···11import { memfs } from '@rolldown/browser/experimental';
22import * as v from 'valibot';
3344-import { stripAnsi } from '../lib/strings';
44+import { stripAnsi } from '../../lib/strings';
55+import { progress } from '../events';
66+import {
77+ workerRequestSchema,
88+ type BundleOptions,
99+ type InitOptions,
1010+ type InitResult,
1111+ type WorkerResponse,
1212+} from '../types';
51366-import { bundlePackage, type BundleOptions } from './bundler';
77-import { progress } from './events';
1414+import { bundlePackage } from './bundler';
815import { fetchPackagesToVolume } from './fetch';
916import { hoist } from './hoist';
1017import { buildInstalledPackages } from './installed-packages';
1118import { resolve } from './resolve';
1219import { discoverSubpaths } from './subpaths';
1320import type { PackageJson } from './types';
1414-import {
1515- workerRequestSchema,
1616- type InitOptions,
1717- type InitResult,
1818- type WorkerResponse,
1919-} from './worker-protocol';
20212122const { volume } = memfs!;
2223