GeezerVison is showing github.com — fix(cli): write a codepage-safe Windows t3.cmd shim by DeryFerd · Pull Request #13401 · pingdotgg/t3code
fix(cli): write a codepage-safe Windows t3.cmd shim
#13401
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ps1
(1)
.ts
(3)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
fix(cli): avoid codepage changes for ASCII Windows installs
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit 71dbf5eea76c6dc5467d34bf3996ae48cafd8abc
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -136,6 +136,15 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
assert.ok(contents.includes(`"${newExe}" %*`));
assert.match(contents, /set "T3EC=%ERRORLEVEL%"\r?\nif defined T3CP chcp %T3CP% >nul/);
assert.match(contents, /exit \/b %T3EC%/);
yield* repointLauncher({
launchedAs: newExe,
versionsDir: versions,
targetEntryPath: path.join(root, "runtime/versions/2.0.0/t3.exe"),
}).pipe(
Effect.provideService(HostProcess.Platform, "win32"),
Effect.provideService(HostProcess.Environment, { PATH: bin }),
);
assert.ok(!(yield* fs.readFileString(shim)).includes("chcp"));
return;
}
Expand All
@@ -148,15 +157,15 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
path.join(bin, "run.cmd"),
[
"@echo off",
'for /f "tokens=2 delims=:" %%c in (\'chcp\') do set "TEST_CP=%%c"',
'for /f "tokens=2 delims=:. " %%c in (\'chcp\') do set "TEST_CP=%%c"',
"chcp 437 >nul",
"for /f \"tokens=2 delims=:\" %%c in ('chcp') do echo BEFORE=%%c",
"for /f \"tokens=2 delims=:. \" %%c in ('chcp') do echo BEFORE=%%c",
'set "T3CP=caller-codepage"',
'set "T3EC=caller-status"',
'call t3.cmd fixture.cjs %1 "one two" three',
'set "TEST_EXIT=%ERRORLEVEL%"',
'if not "%T3CP%:%T3EC%"=="caller-codepage:caller-status" exit /b 99',
"for /f \"tokens=2 delims=:\" %%c in ('chcp') do echo AFTER=%%c",
"for /f \"tokens=2 delims=:. \" %%c in ('chcp') do echo AFTER=%%c",
"chcp %TEST_CP% >nul",
"exit /b %TEST_EXIT%",
"",
Expand All
@@ -167,8 +176,6 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
const child = NodeChildProcess.spawn("cmd.exe", ["/d", "/c", "run.cmd", `${status}`], {
cwd: bin,
stdio: ["ignore", "pipe", "pipe"],
// A separate console keeps the legacy codepage out of the test runner's console.
detached: true,
timeout: 10_000,
});
const [exitCode, stdout, stderr] = await Promise.all([
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -116,16 +116,21 @@ export const repointLauncher = Effect.fn("cli.update.repoint_launcher")(function
const current = yield* fs.readFileString(shimPath).pipe(Effect.option);
const quoted = Option.isSome(current) ? /^"([^"]+)"/m.exec(current.value)?.[1] : undefined;
if (quoted === undefined || !ownsTarget(quoted)) return Option.none<string>();
// cmd decodes each batch line using the console codepage, including the UTF-8 target.
const utf8 = [...input.targetEntryPath].some((character) => character.codePointAt(0)! > 0x7f);
// A Ctrl-C that ends the batch skips restoration, so only switch for a non-ASCII target.
const contents = [
"@echo off",
"setlocal EnableExtensions DisableDelayedExpansion",
'set "T3CP="',
'for /f "tokens=2 delims=:" %%c in (\'chcp\') do set "T3CP=%%c"',
"if defined T3CP chcp 65001 >nul",
...(utf8
? [
'set "T3CP="',
'for /f "tokens=2 delims=:." %%c in (\'chcp\') do set "T3CP=%%c"',
"if defined T3CP chcp 65001 >nul",
]
: []),
`"${input.targetEntryPath}" %*`,
'set "T3EC=%ERRORLEVEL%"',
"if defined T3CP chcp %T3CP% >nul",
...(utf8 ? [ "if defined T3CP chcp %T3CP% >nul"] : []) ,
"exit /b %T3EC%",
"",
].join("\r\n");
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -212,17 +212,21 @@ if ((Test-Path $marker) -and ((Get-Content $marker -Raw).Trim() -eq $version)) {
Step "Setting up the t3 command..."
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
$shim = Join-Path $binDir "t3.cmd"
# cmd decodes each batch line using the console codepage, including the UTF-8 target.
$exe = Join-Path $targetDir 't3.exe'
$utf8 = $exe -match '[^\x00-\x7F]'
# A Ctrl-C that ends the batch skips restoration, so only switch for a non-ASCII target.
$shimContents = @(
'@echo off',
'setlocal EnableExtensions DisableDelayedExpansion',
'set "T3CP="',
'for /f "tokens=2 delims=:" %%c in (''chcp'') do set "T3CP=%%c"',
'if defined T3CP chcp 65001 >nul',
"`"$(Join-Path $targetDir 't3.exe')`" %*",
'set "T3EC=%ERRORLEVEL%"',
'if defined T3CP chcp %T3CP% >nul',
'exit /b %T3EC%',
'@echo off'
'setlocal EnableExtensions DisableDelayedExpansion'
if ($utf8) {
'set "T3CP="'
'for /f "tokens=2 delims=:." %%c in (''chcp'') do set "T3CP=%%c"'
'if defined T3CP chcp 65001 >nul'
}
"`"$exe`" %*"
'set "T3EC=%ERRORLEVEL%"'
if ($utf8) { 'if defined T3CP chcp %T3CP% >nul' }
'exit /b %T3EC%'
''
) -join "`r`n"
[System.IO.File]::WriteAllText($shim, $shimContents, (New-Object System.Text.UTF8Encoding $false))
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -200,15 +200,15 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "win32")("installer wind
NodePath.join(bin, "run.cmd"),
[
"@echo off",
'for /f "tokens=2 delims=:" %%c in (\'chcp\') do set "TEST_CP=%%c"',
'for /f "tokens=2 delims=:. " %%c in (\'chcp\') do set "TEST_CP=%%c"',
"chcp 437 >nul",
"for /f \"tokens=2 delims=:\" %%c in ('chcp') do echo BEFORE=%%c",
"for /f \"tokens=2 delims=:. \" %%c in ('chcp') do echo BEFORE=%%c",
'set "T3CP=caller-codepage"',
'set "T3EC=caller-status"',
'call t3.cmd %1 "one two" three',
'set "TEST_EXIT=%ERRORLEVEL%"',
'if not "%T3CP%:%T3EC%"=="caller-codepage:caller-status" exit /b 99',
"for /f \"tokens=2 delims=:\" %%c in ('chcp') do echo AFTER=%%c",
"for /f \"tokens=2 delims=:. \" %%c in ('chcp') do echo AFTER=%%c",
"chcp %TEST_CP% >nul",
"exit /b %TEST_EXIT%",
"",
Expand All
@@ -218,8 +218,6 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "win32")("installer wind
const child = NodeChildProcess.spawn("cmd.exe", ["/d", "/c", "run.cmd", `${status}`], {
cwd: bin,
stdio: ["ignore", "pipe", "pipe"],
// A separate console keeps the legacy codepage out of the test runner's console.
detached: true,
timeout: 10_000,
});
const [exitCode, stdout, stderr] = await Promise.all([
Expand Down
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.