Skip to content

Commit

Permalink
fix: devtools fixed config file name (#5765)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asuka109 committed May 22, 2024
1 parent e435bb3 commit ba0614d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 6 additions & 2 deletions packages/devtools/plugin/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ export const devtoolsPlugin = (
const { devtools: options = {} } = appConfig;
updateContext(ctx, options);

const watcher = chokidar.watch(getConfigFilenames(), {
const basename = `${ctx.def.name.shortName}.runtime.json`;
const watcher = chokidar.watch(getConfigFilenames(basename), {
cwd: appCtx.appDirectory,
ignorePermissionErrors: true,
});
const refreshStoragePreset = async () => {
const configs = await loadConfigFiles(appCtx.appDirectory);
const configs = await loadConfigFiles(
basename,
appCtx.appDirectory,
);
if (!configs) return;
ctx.storagePresets = [];
updateContext(ctx, ...configs);
Expand Down
15 changes: 7 additions & 8 deletions packages/devtools/plugin/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ import {
} from '@modern-js/devtools-kit';
import { logger, nanoid } from '@modern-js/utils';

const CONFIG_FILENAME = 'modern.runtime.json';

export function getConfigFilenames(dir = process.cwd()) {
export function getConfigFilenames(base: string, dir = process.cwd()) {
const files: string[] = [];
let curr = dir;
while (path.dirname(curr) !== curr) {
files.push(path.join(curr, CONFIG_FILENAME));
// files.push(path.join(curr, 'node_modules/.modern-js', CONFIG_FILENAME));
files.push(path.join(curr, base));
// files.push(path.join(curr, 'node_modules/.modern-js', base));
curr = path.dirname(curr);
}
return files;
}

/** Resolve all config files from target directory upward to the root path. */
export async function resolveConfigFiles(
base: string,
dir = process.cwd(),
): Promise<string[]> {
const files = getConfigFilenames(dir);
const files = getConfigFilenames(base, dir);
const ret: string[] = [];
await Promise.all(
files.map(async file => (await fs.pathExists(file)) && ret.push(file)),
Expand Down Expand Up @@ -64,8 +63,8 @@ export async function loadConfigFile(filename: string) {
return { storagePresets: ret };
}

export async function loadConfigFiles(dir = process.cwd()) {
const filenames = await resolveConfigFiles(dir);
export async function loadConfigFiles(base: string, dir = process.cwd()) {
const filenames = await resolveConfigFiles(base, dir);
const resolved = await Promise.all(filenames.map(loadConfigFile));
const ret: Partial<DevtoolsContext>[] = [];
for (const config of resolved) {
Expand Down

0 comments on commit ba0614d

Please sign in to comment.