@metreeca/rack - v0.6.0
    Preparing search index...

    Function symlinks

    • Creates module hooks running a Node process against the live source of locally linked packages, with no rebuild.

      Imports of workspace members and of sibling checkouts linked into node_modules resolve to their TypeScript source, which Node runs through its built-in type stripping, so edits are picked up as they are saved. Packages installed from the registry keep resolving to their build, as do packages whose exports name none of the conditions.

      Packages are looked up as Node does, from the node_modules nearest to the importer up through its ancestors; imports with no importer start from the root. A linked checkout importing a package the project links as well loads the linked source rather than the registry copy it installs for itself, so the two never diverge.

      The process loads a single copy of every linked package and of each of their peerDependencies, as libraries holding module state such as Preact hooks require. Those packages resolve from the root, whatever copies a linked checkout installs for itself, and from the importer only where the root does not install them. Other dependencies of a linked package resolve from its checkout, as Node does, since the process loads no other copy of them.

      Relative imports of a .js file from a TypeScript module, as NodeNext module resolution requires, resolve to the .ts file next to it when the .js file does not exist. Sources compiled to dist thus run from src under plain node, with no loader such as tsx. Where such a loader is registered as well, the imports it resolves are left to it, and the hooks only add the resolution of linked packages to their TypeScript source.

      The hooks take effect once registered with registerHooks from node:module, before the first import they have to resolve, typically from a module loaded with --import. Importing @metreeca/rack/node registers them with the conditions of the tsconfig.json nearest to the current working directory, with no setup module to write.

      Parameters

      • options: { conditions: string | readonly string[]; root?: string }

        The resolution settings

        • conditions: string | readonly string[]

          The export conditions mapping each subpath to its source file, as listed in customConditions; where a package matches more than one, the key order of its own exports decides which applies.

        • Optionalroot?: string

          The project root the linked packages and their peers resolve from; defaults to the current working directory.

      Returns Readonly<{ resolve: ResolveHookSync }>

      Synchronous module hooks resolving linked imports to source, deduplicating linked packages and their peers, mapping .js relative imports to their .ts sources, and leaving all other imports to the default resolution