Skip to content

Commit

Permalink
fix: sync
Browse files Browse the repository at this point in the history
  • Loading branch information
gronxb committed Mar 9, 2025
1 parent 36dccab commit a8736c7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
7 changes: 2 additions & 5 deletions packages/hot-updater/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { Config, HotUpdaterConfigOptions } from "@hot-updater/plugin-core";

export const defineConfig = async (
config:
| Config
| ((options: HotUpdaterConfigOptions) => Config)
| ((options: HotUpdaterConfigOptions) => Promise<Config>),
export const defineConfig = (
config: Config | ((options: HotUpdaterConfigOptions) => Config),
) => {
return config;
};
5 changes: 3 additions & 2 deletions plugins/plugin-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"workspace-tools": "^0.36.4"
},
"devDependencies": {
"picocolors": "^1.0.0",
"@types/node": "^22.7.5"
"@types/node": "^22.7.5",
"es-toolkit": "^1.32.0",
"picocolors": "^1.0.0"
}
}
37 changes: 27 additions & 10 deletions plugins/plugin-core/src/loadConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cosmiconfig, cosmiconfigSync } from "cosmiconfig";
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
import { merge } from "es-toolkit";
import { getCwd } from "./cwd.js";
import type { Config, Platform } from "./types.js";

Expand All @@ -8,6 +9,22 @@ export type HotUpdaterConfigOptions = {
channel: string;
} | null;

const defaultConfig: Config = {
releaseChannel: "production",
console: {
port: 1422,
},
build: () => {
throw new Error("build plugin is required");
},
storage: () => {
throw new Error("storage plugin is required");
},
database: () => {
throw new Error("database plugin is required");
},
};

export const loadConfig = async (
options: HotUpdaterConfigOptions,
): Promise<Config | null> => {
Expand All @@ -18,7 +35,6 @@ export const loadConfig = async (
"hot-updater.config.cjs",
"hot-updater.config.ts",
"hot-updater.config.cts",
"hot-updater.config.mjs",
"hot-updater.config.cjs",
],
ignoreEmptySearchPlaces: false,
Expand All @@ -33,11 +49,12 @@ export const loadConfig = async (
return null;
}

if (typeof result.config === "function") {
return await result.config(options);
}
const config =
typeof result.config === "function"
? result.config(options)
: (result.config as Config);

return result.config as Config;
return merge(defaultConfig, config);
};

export const loadConfigSync = (
Expand All @@ -50,7 +67,6 @@ export const loadConfigSync = (
"hot-updater.config.cjs",
"hot-updater.config.ts",
"hot-updater.config.cts",
"hot-updater.config.mjs",
"hot-updater.config.cjs",
],
ignoreEmptySearchPlaces: false,
Expand All @@ -65,9 +81,10 @@ export const loadConfigSync = (
return null;
}

if (typeof result.config === "function") {
return result.config(options);
}
const config =
typeof result.config === "function"
? result.config(options)
: (result.config as Config);

return result.config as Config;
return merge(defaultConfig, config);
};
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8736c7

Please sign in to comment.