Skip to content

Commit d58d3ed

Browse files
fix(cli): init writes the project into a folder with a non-ASCII name on Windows (#5833)
* test(cli): init scaffolds into a folder with a Cyrillic name * fix(cli): init writes the project into a folder with a non-ASCII name on Windows
1 parent b98a1ac commit d58d3ed

7 files changed

Lines changed: 53 additions & 9 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { afterEach, expect, it, vi } from "vitest";
2+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
3+
import { tmpdir } from "node:os";
4+
import { join } from "node:path";
5+
import { runCommand } from "citty";
6+
import init from "./init.js";
7+
8+
vi.mock("../telemetry/events.js", () => ({ trackInitTemplate: vi.fn() }));
9+
10+
afterEach(() => {
11+
vi.restoreAllMocks();
12+
vi.unstubAllEnvs();
13+
});
14+
15+
// Node 22's native directory copy wrote nothing to such a path on Windows, without an error.
16+
it("scaffolds the template into a folder with a Cyrillic name", async () => {
17+
const dir = mkdtempSync(join(tmpdir(), "hf-init-cyrillic-"));
18+
const project = join(dir, "Проект");
19+
vi.stubEnv("HYPERFRAMES_SKIP_SKILLS", "1");
20+
vi.spyOn(console, "log").mockImplementation(() => {});
21+
try {
22+
await runCommand(init, { rawArgs: [project, "--example", "blank", "--non-interactive"] });
23+
expect(existsSync(join(project, "index.html"))).toBe(true);
24+
expect(existsSync(join(project, "hyperframes.json"))).toBe(true);
25+
} finally {
26+
rmSync(dir, { recursive: true, force: true });
27+
}
28+
});

‎packages/cli/src/commands/init.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import {
2727
existsSync,
2828
mkdirSync,
2929
copyFileSync,
30-
cpSync,
3130
writeFileSync,
3231
readFileSync,
3332
readdirSync,
3433
} from "node:fs";
34+
import { copyDirSync } from "../utils/copyDir.js";
3535
import { resolve, basename, join, dirname } from "node:path";
3636
import { fileURLToPath } from "node:url";
3737
import { execFileSync, spawn } from "node:child_process";
@@ -575,7 +575,7 @@ async function scaffoldProject(
575575
// build toolchain should not prevent the remote fetch fallback.
576576
const templateDir = getStaticTemplateDir(templateId);
577577
if (existsSync(join(templateDir, "index.html"))) {
578-
cpSync(templateDir, destDir, { recursive: true });
578+
copyDirSync(templateDir, destDir);
579579
} else {
580580
await fetchRemoteTemplate(templateId, destDir);
581581
}

‎packages/cli/src/media-use/lib/recipe-store.mjs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { appendRecord, mediaDir, nextId } from "./manifest.mjs";
1414
import { regenerateIndex } from "./index-gen.mjs";
1515
import { mergedPreferences } from "./prefs-store.mjs";
1616

17+
// A filter keeps Node 22 off its native copy, which writes nothing under a non-ASCII path on Windows.
18+
const NON_ASCII_SAFE_DIR_COPY = { recursive: true, force: true, filter: () => true };
19+
1720
/**
1821
* Recipes — the heavyweight tier of HyperFrames user memory.
1922
*
@@ -279,7 +282,7 @@ export function freezeRecipe({ projectDir, name, workflow, blocks }) {
279282
try {
280283
const userDir = join(userRecipesDir(), slug);
281284
mkdirSync(userDir, { recursive: true });
282-
cpSync(dir, userDir, { recursive: true, force: true });
285+
cpSync(dir, userDir, NON_ASCII_SAFE_DIR_COPY);
283286
} catch {
284287
// The project-tier freeze already landed.
285288
}
@@ -339,7 +342,7 @@ export function useRecipe({ projectDir, name }) {
339342
);
340343
}
341344
mkdirSync(dir, { recursive: true });
342-
cpSync(userDir, dir, { recursive: true, force: true });
345+
cpSync(userDir, dir, NON_ASCII_SAFE_DIR_COPY);
343346
const imported = readRecipeJson(dir);
344347
appendRecord(root, {
345348
id: nextId(root, "recipe"),

‎packages/cli/src/utils/copyDir.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { cpSync, type CopySyncOptions } from "node:fs";
2+
3+
export function copyDirSync(
4+
src: string,
5+
dest: string,
6+
options: Omit<CopySyncOptions, "recursive" | "filter"> = {},
7+
): void {
8+
// Any filter keeps Node 22 off its native copy, which writes nothing under a non-ASCII path on Windows.
9+
cpSync(src, dest, { ...options, recursive: true, filter: () => true });
10+
}

‎packages/cli/src/utils/skillsMirror.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// those set mirrors into the exact dir the agent reads.
2424

2525
import {
26-
cpSync,
2726
existsSync,
2827
lstatSync,
2928
mkdirSync,
@@ -34,6 +33,7 @@ import {
3433
symlinkSync,
3534
unlinkSync,
3635
} from "node:fs";
36+
import { copyDirSync } from "./copyDir.js";
3737
import { homedir } from "node:os";
3838
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3939
import { AGENT_GLOBAL_DIRS, type AgentDirBase } from "./agentDirs.generated.js";
@@ -195,7 +195,7 @@ function linkOrCopy(
195195
if (unsafe) return unsafe;
196196
rmSync(targetSkill, { recursive: true, force: true });
197197
if (platform === "win32") {
198-
cpSync(sourceSkill, targetSkill, { recursive: true });
198+
copyDirSync(sourceSkill, targetSkill);
199199
} else {
200200
symlinkSync(relative(dirname(targetSkill), sourceSkill), targetSkill);
201201
}

‎skills-manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"files": 1
5555
},
5656
"media-use": {
57-
"hash": "2816313a2f72e636",
57+
"hash": "1a2c3f1c16ab3ef7",
5858
"files": 113
5959
},
6060
"motion-graphics": {

‎skills/media-use/scripts/lib/recipe-store.mjs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { appendRecord, mediaDir, nextId } from "./manifest.mjs";
1414
import { regenerateIndex } from "./index-gen.mjs";
1515
import { mergedPreferences } from "./prefs-store.mjs";
1616

17+
// A filter keeps Node 22 off its native copy, which writes nothing under a non-ASCII path on Windows.
18+
const NON_ASCII_SAFE_DIR_COPY = { recursive: true, force: true, filter: () => true };
19+
1720
/**
1821
* Recipes — the heavyweight tier of HyperFrames user memory.
1922
*
@@ -279,7 +282,7 @@ export function freezeRecipe({ projectDir, name, workflow, blocks }) {
279282
try {
280283
const userDir = join(userRecipesDir(), slug);
281284
mkdirSync(userDir, { recursive: true });
282-
cpSync(dir, userDir, { recursive: true, force: true });
285+
cpSync(dir, userDir, NON_ASCII_SAFE_DIR_COPY);
283286
} catch {
284287
// The project-tier freeze already landed.
285288
}
@@ -339,7 +342,7 @@ export function useRecipe({ projectDir, name }) {
339342
);
340343
}
341344
mkdirSync(dir, { recursive: true });
342-
cpSync(userDir, dir, { recursive: true, force: true });
345+
cpSync(userDir, dir, NON_ASCII_SAFE_DIR_COPY);
343346
const imported = readRecipeJson(dir);
344347
appendRecord(root, {
345348
id: nextId(root, "recipe"),

0 commit comments

Comments
 (0)