Skip to content

Commit

Permalink
fix: dedup unstorage dependency and use subpath alias (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jun 28, 2023
1 parent e580751 commit 20c841c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { loadConfig, watchConfig, WatchConfigOptions } from "c12";
import { klona } from "klona/full";
import { camelCase } from "scule";
import { defu } from "defu";
import { resolveModuleExportNames, resolvePath as resolveModule } from "mlly";
import {
resolveModuleExportNames,
resolvePath as resolveModule,
parseNodeModulePath,
} from "mlly";
import escapeRE from "escape-string-regexp";
import { withLeadingSlash, withoutTrailingSlash, withTrailingSlash } from "ufo";
import { isTest, isDebug } from "std-env";
Expand Down Expand Up @@ -314,9 +318,16 @@ export async function loadOptions(
serverAsset.dir = resolve(options.srcDir, serverAsset.dir);
}

for (const pkg of ["defu", "h3", "radix3"]) {
if (!options.alias[pkg]) {
options.alias[pkg] = await resolveModule(pkg, { url: import.meta.url });
// Dedup built-in dependencies
for (const pkg of ["defu", "h3", "radix3", "unstorage"]) {
const entryPath = await resolveModule(pkg, { url: import.meta.url });
const { dir, name } = parseNodeModulePath(entryPath);
if (!dir || !name) {
continue;
}
if (!options.alias[pkg + "/"]) {
const pkgDir = join(dir, name);
options.alias[pkg + "/"] = pkgDir;
}
}

Expand Down

0 comments on commit 20c841c

Please sign in to comment.