Skip to content

Commit db77171

Browse files
refactor: logic
1 parent 0dacd45 commit db77171

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

packages/create-webpack-app/src/utils/generate-files.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ async function checkAndPrepareContent(config: AddConfig, isTemplate: boolean): P
162162
return { status: "identical", content: existingFileContent };
163163
}
164164

165-
// Prompt for conflict resolution
166-
const tempFilePath = path.join("/tmp", `temp_${path.basename(config.path)}`);
167-
await fs.writeFile(tempFilePath, newContent || "");
168-
169165
let userChoice: Result | undefined;
170166
while (!userChoice) {
171167
const action = await expand({
@@ -194,7 +190,14 @@ async function checkAndPrepareContent(config: AddConfig, isTemplate: boolean): P
194190
case "overwrite_all":
195191
globalConfig.overwriteAll = true;
196192
return { status: "overwrite", content: newContent };
197-
case "diff":
193+
case "diff": {
194+
// Prompt for conflict resolution
195+
const tempFilePath = path.join(
196+
config.data!.projectPath as string,
197+
`.temp_${path.basename(config.path)}`,
198+
);
199+
await fs.writeFile(tempFilePath, newContent || "");
200+
198201
if (!isTemplate && Buffer.isBuffer(existingFileContent)) {
199202
const existingStats = await fs.stat(config.path);
200203
const newStats = await fs.stat(tempFilePath);
@@ -219,17 +222,18 @@ async function checkAndPrepareContent(config: AddConfig, isTemplate: boolean): P
219222
} else {
220223
await getDiff(config.path, tempFilePath);
221224
}
225+
226+
await fs.unlink(tempFilePath).catch(() => {
227+
logger.warn(`Failed to delete temporary file: ${tempFilePath}`);
228+
});
222229
break;
230+
}
223231
case "abort":
224232
logger.error("Aborting process...");
225233
process.exit(1);
226234
}
227235
}
228236

229-
await fs.unlink(tempFilePath).catch(() => {
230-
logger.warn(`Failed to delete temporary file: ${tempFilePath}`);
231-
});
232-
233237
return userChoice;
234238
}
235239
// If the file doesn't exist, create it

test/external-command/my-loader.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export async function resolve(specifier, context, nextResolve) {
77
} catch (err) {
88
if (err.code === "ERR_MODULE_NOT_FOUND" && !specifier.startsWith(".")) {
99
try {
10-
const baseDir = pathToFileURL(join(process.cwd(), "node_modules/")).href;
10+
const baseDir = join(process.cwd(), "node_modules/");
1111
const resolved = join(baseDir, specifier, "index.js");
1212

1313
return {
14-
url: resolved,
14+
url: pathToFileURL(resolved).href,
1515
shortCircuit: true,
1616
};
1717
} catch {

0 commit comments

Comments
 (0)