Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dedup unstorage dependency and use subpath alias #1164

Merged
merged 5 commits into from
Jun 28, 2023
Merged
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
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