From 54e7755a67658d7d0596c034e80b74b3b1ff8702 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 00:54:55 +0800 Subject: [PATCH 01/28] prettier: support read code from stdin and output to stdout --- prettier/main.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/prettier/main.ts b/prettier/main.ts index 584b90b3959e..413feafeafd8 100755 --- a/prettier/main.ts +++ b/prettier/main.ts @@ -11,7 +11,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // This script formats the given source files. If the files are omitted, it // formats the all files in the repository. -const { args, exit, readFile, writeFile, stdout } = Deno; +const { args, exit, readFile, writeFile, stdout, stdin, readAll } = Deno; import { glob, isGlob, GlobOptions } from "../fs/glob.ts"; import { walk, WalkInfo } from "../fs/walk.ts"; import { parse } from "../flags/mod.ts"; @@ -26,6 +26,7 @@ Options: -H, --help Show this help message and exit. --check Check if the source files are formatted. --write Whether to write to the file, otherwise it will output to stdout, Defaults to false. + --from-stdin Read the typescript/javascript code from stdin and output formatted code to stdout. --ignore Ignore the given path(s). JS/TS Styling Options: @@ -227,6 +228,19 @@ async function formatSourceFiles( exit(0); } +/** + * Format source code + */ +function format(text: string, prettierOpts: PrettierOptions): string { + const formatted: string = prettier.format(text, { + ...prettierOpts, + parser: selectParser("stdin.ts"), + plugins: prettierPlugins + }); + + return formatted; +} + /** * Get the files to format. * @param selectors The glob patterns to select the files. @@ -306,6 +320,15 @@ async function main(opts): Promise { write: opts["write"] }; + const isReadFromStdin: boolean = opts["from-stdin"]; + + if (isReadFromStdin) { + const byte = await readAll(stdin); + const formattedCode = format(new TextDecoder().decode(byte), prettierOpts); + stdout.write(new TextEncoder().encode(formattedCode)); + return; + } + if (help) { console.log(HELP_MESSAGE); exit(0); @@ -348,7 +371,8 @@ main( "use-tabs", "single-quote", "bracket-spacing", - "write" + "write", + "from-stdin" ], default: { ignore: [], @@ -362,7 +386,8 @@ main( "arrow-parens": "avoid", "prose-wrap": "preserve", "end-of-line": "auto", - write: false + write: false, + "from-stdin": false }, alias: { H: "help" From de5f2526bb4cf5ff355da3f19822874b642f3ca9 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 11:30:19 +0800 Subject: [PATCH 02/28] try support windows --- installer/mod.ts | 78 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index ba98074f324b..93859dc25d7a 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -10,7 +10,7 @@ const { stdin, stat, readAll, - run, + chmod, remove } = Deno; import * as path from "../fs/path.ts"; @@ -140,17 +140,74 @@ async function fetchModule(url: string): Promise { function showHelp(): void { console.log(`deno installer Install remote or local script as executables. - + USAGE: - deno https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] + deno https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] ARGS: - EXE_NAME Name for executable + EXE_NAME Name for executable SCRIPT_URL Local or remote URL of script to install [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. `); } +async function genereateExecutable( + filePath: string, + commands: string[] +): Promise { + // genereate Batch script + if (Deno.platform.os === "win") { + const cmdTemplate = ` +@IF EXIST "%~dp0\deno.exe" ( + "%~dp0\deno.exe" ${commands.slice(1).join(" ")} %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.TS;=;% + ${commands.join(" ")} %* +) +`; + const cmdFile = filePath + ".cmd"; + await writeFile(cmdFile, encoder.encode(cmdTemplate)); + await chmod(cmdFile, 0x755); + + // generate Shell script + const shellTemplate = `#/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case \`uname\` in + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/deno" ]; then + "$basedir/deno" ${commands.slice(1).join(" ")} "$@" + ret=$? +else + ${commands.join(" ")} "$@" + ret=$? +fi +exit $ret +`; + await writeFile(filePath, encoder.encode(shellTemplate)); + await chmod(filePath, 0x755); + } else { + // generate Shell script + const shellTemplate = `#/bin/sh +basedir=$(dirname "$(echo "$0")") + +if [ -x "$basedir/deno" ]; then + "$basedir/deno" ${commands.slice(1).join(" ")} "$@" + ret=$? +else + ${commands.join(" ")} "$@" + ret=$? +fi +exit $ret +`; + await writeFile(filePath, encoder.encode(shellTemplate)); + await chmod(filePath, 0x755); + } +} + export async function install( moduleName: string, moduleUrl: string, @@ -201,23 +258,14 @@ export async function install( const commands = [ "deno", + "run", ...grantedPermissions.map(getFlagFromPermission), moduleUrl, ...scriptArgs, "$@" ]; - // TODO: add windows Version - const template = `#/bin/sh\n${commands.join(" ")}`; - await writeFile(filePath, encoder.encode(template)); - - const makeExecutable = run({ args: ["chmod", "+x", filePath] }); - const { code } = await makeExecutable.status(); - makeExecutable.close(); - - if (code !== 0) { - throw new Error("Failed to make file executable"); - } + await genereateExecutable(filePath, commands); console.log(`✅ Successfully installed ${moduleName}`); console.log(filePath); From 6e7e1e1e34504bd633d296833fa2991557661b13 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 11:37:37 +0800 Subject: [PATCH 03/28] fix --- installer/mod.ts | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 93859dc25d7a..1edef9c835d2 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -157,7 +157,7 @@ async function genereateExecutable( ): Promise { // genereate Batch script if (Deno.platform.os === "win") { - const cmdTemplate = ` + const template = ` @IF EXIST "%~dp0\deno.exe" ( "%~dp0\deno.exe" ${commands.slice(1).join(" ")} %* ) ELSE ( @@ -167,12 +167,14 @@ async function genereateExecutable( ) `; const cmdFile = filePath + ".cmd"; - await writeFile(cmdFile, encoder.encode(cmdTemplate)); + await writeFile(cmdFile, encoder.encode(template)); await chmod(cmdFile, 0x755); + } + + // generate Shell script + const template = `#/bin/sh - // generate Shell script - const shellTemplate = `#/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\,/,g')") case \`uname\` in *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; @@ -187,25 +189,8 @@ else fi exit $ret `; - await writeFile(filePath, encoder.encode(shellTemplate)); - await chmod(filePath, 0x755); - } else { - // generate Shell script - const shellTemplate = `#/bin/sh -basedir=$(dirname "$(echo "$0")") - -if [ -x "$basedir/deno" ]; then - "$basedir/deno" ${commands.slice(1).join(" ")} "$@" - ret=$? -else - ${commands.join(" ")} "$@" - ret=$? -fi -exit $ret -`; - await writeFile(filePath, encoder.encode(shellTemplate)); - await chmod(filePath, 0x755); - } + await writeFile(filePath, encoder.encode(template)); + await chmod(filePath, 0x755); } export async function install( @@ -261,8 +246,7 @@ export async function install( "run", ...grantedPermissions.map(getFlagFromPermission), moduleUrl, - ...scriptArgs, - "$@" + ...scriptArgs ]; await genereateExecutable(filePath, commands); From 33f51154efc235041f7eddfb73d4394f98fad44b Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 11:49:41 +0800 Subject: [PATCH 04/28] fix --- installer/mod.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 1edef9c835d2..9d948bc7eb55 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -17,6 +17,7 @@ import * as path from "../fs/path.ts"; const encoder = new TextEncoder(); const decoder = new TextDecoder("utf-8"); +const isWindows = Deno.platform.os === "win"; enum Permission { Read, @@ -89,7 +90,7 @@ function createDirIfNotExists(path: string): void { function checkIfExistsInPath(path: string): boolean { const { PATH } = env(); - const paths = (PATH as string).split(":"); + const paths = (PATH as string).split(isWindows ? ";" : ":"); return paths.includes(path); } @@ -156,7 +157,7 @@ async function genereateExecutable( commands: string[] ): Promise { // genereate Batch script - if (Deno.platform.os === "win") { + if (isWindows) { const template = ` @IF EXIST "%~dp0\deno.exe" ( "%~dp0\deno.exe" ${commands.slice(1).join(" ")} %* @@ -174,7 +175,7 @@ async function genereateExecutable( // generate Shell script const template = `#/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\,/,g')") +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") case \`uname\` in *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; From 53590b4f94883123b2deac6a1d0f5647244b5bf1 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 12:07:13 +0800 Subject: [PATCH 05/28] fix permission --- installer/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 9d948bc7eb55..3308808f4347 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -169,7 +169,7 @@ async function genereateExecutable( `; const cmdFile = filePath + ".cmd"; await writeFile(cmdFile, encoder.encode(template)); - await chmod(cmdFile, 0x755); + await chmod(cmdFile, 0o755); } // generate Shell script @@ -191,7 +191,7 @@ fi exit $ret `; await writeFile(filePath, encoder.encode(template)); - await chmod(filePath, 0x755); + await chmod(filePath, 0o755); } export async function install( From cd99ac16eb21eeff858a7eacd7dc06666e900075 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 12:14:05 +0800 Subject: [PATCH 06/28] Revert "prettier: support read code from stdin and output to stdout" This reverts commit 54e7755a67658d7d0596c034e80b74b3b1ff8702. --- prettier/main.ts | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/prettier/main.ts b/prettier/main.ts index 413feafeafd8..584b90b3959e 100755 --- a/prettier/main.ts +++ b/prettier/main.ts @@ -11,7 +11,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // This script formats the given source files. If the files are omitted, it // formats the all files in the repository. -const { args, exit, readFile, writeFile, stdout, stdin, readAll } = Deno; +const { args, exit, readFile, writeFile, stdout } = Deno; import { glob, isGlob, GlobOptions } from "../fs/glob.ts"; import { walk, WalkInfo } from "../fs/walk.ts"; import { parse } from "../flags/mod.ts"; @@ -26,7 +26,6 @@ Options: -H, --help Show this help message and exit. --check Check if the source files are formatted. --write Whether to write to the file, otherwise it will output to stdout, Defaults to false. - --from-stdin Read the typescript/javascript code from stdin and output formatted code to stdout. --ignore Ignore the given path(s). JS/TS Styling Options: @@ -228,19 +227,6 @@ async function formatSourceFiles( exit(0); } -/** - * Format source code - */ -function format(text: string, prettierOpts: PrettierOptions): string { - const formatted: string = prettier.format(text, { - ...prettierOpts, - parser: selectParser("stdin.ts"), - plugins: prettierPlugins - }); - - return formatted; -} - /** * Get the files to format. * @param selectors The glob patterns to select the files. @@ -320,15 +306,6 @@ async function main(opts): Promise { write: opts["write"] }; - const isReadFromStdin: boolean = opts["from-stdin"]; - - if (isReadFromStdin) { - const byte = await readAll(stdin); - const formattedCode = format(new TextDecoder().decode(byte), prettierOpts); - stdout.write(new TextEncoder().encode(formattedCode)); - return; - } - if (help) { console.log(HELP_MESSAGE); exit(0); @@ -371,8 +348,7 @@ main( "use-tabs", "single-quote", "bracket-spacing", - "write", - "from-stdin" + "write" ], default: { ignore: [], @@ -386,8 +362,7 @@ main( "arrow-parens": "avoid", "prose-wrap": "preserve", "end-of-line": "auto", - write: false, - "from-stdin": false + write: false }, alias: { H: "help" From f593e6aabe088809fde9e654b49fb30992573cdd Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 12:16:58 +0800 Subject: [PATCH 07/28] update --- installer/mod.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/installer/mod.ts b/installer/mod.ts index 3308808f4347..36c8d24c7462 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -174,7 +174,6 @@ async function genereateExecutable( // generate Shell script const template = `#/bin/sh - basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") case \`uname\` in From e2f9bbb4a13de922ee061f6e3c776841ff7082ef Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 12:28:40 +0800 Subject: [PATCH 08/28] fix test --- installer/test.ts | 77 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/installer/test.ts b/installer/test.ts index 1b1aa4200be2..3d588ef3ac03 100644 --- a/installer/test.ts +++ b/installer/test.ts @@ -9,6 +9,7 @@ import { install, uninstall } from "./mod.ts"; import * as path from "../fs/path.ts"; let fileServer: Deno.Process; +const isWindows = Deno.platform.os === "win"; // copied from `http/file_server_test.ts` async function startFileServer(): Promise { @@ -65,10 +66,40 @@ installerTest(async function installBasic(): Promise { const fileBytes = await readFile(filePath); const fileContents = new TextDecoder().decode(fileBytes); - assertEquals( - fileContents, - "#/bin/sh\ndeno http://localhost:4500/http/file_server.ts $@" - ); + if (isWindows) { + assertEquals( + fileContents, + ` +@IF EXIST "%~dp0\deno.exe" ( + "%~dp0\deno.exe" run http://localhost:4500/http/file_server.ts %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.TS;=;% + deno run http://localhost:4500/http/file_server.ts %* +) +` + ); + } else { + assertEquals( + fileContents, + `#/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/deno" ]; then + "$basedir/deno" run http://localhost:4500/http/file_server.ts "$@" + ret=$? +else + deno run http://localhost:4500/http/file_server.ts "$@" + ret=$? +fi +exit $ret +` + ); + } }); installerTest(async function installWithFlags(): Promise { @@ -83,10 +114,40 @@ installerTest(async function installWithFlags(): Promise { const fileBytes = await readFile(filePath); const fileContents = new TextDecoder().decode(fileBytes); - assertEquals( - fileContents, - "#/bin/sh\ndeno --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar $@" - ); + if (isWindows) { + assertEquals( + fileContents, + ` +@IF EXIST "%~dp0\deno.exe" ( + "%~dp0\deno.exe" run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.TS;=;% + deno run http://localhost:4500/http/file_server.ts %* +) +` + ); + } else { + assertEquals( + fileContents, + `#/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/deno" ]; then + "$basedir/deno" run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar "$@" + ret=$? +else + deno run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar "$@" + ret=$? +fi +exit $ret +` + ); + } }); installerTest(async function uninstallBasic(): Promise { From 7d6b67b38c80798e3c0cbbf7fb2c91eeb26a08ac Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 14:36:39 +0800 Subject: [PATCH 09/28] fix test --- installer/mod.ts | 11 ++++++---- installer/test.ts | 55 +++++++++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 36c8d24c7462..17d1bd0f369b 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -1,5 +1,5 @@ #!/usr/bin/env deno --allow-all - +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { args, env, @@ -158,7 +158,7 @@ async function genereateExecutable( ): Promise { // genereate Batch script if (isWindows) { - const template = ` + const template = `% This executable is generated by Deno. Please don't modify it unless you know what it means. % @IF EXIST "%~dp0\deno.exe" ( "%~dp0\deno.exe" ${commands.slice(1).join(" ")} %* ) ELSE ( @@ -174,10 +174,11 @@ async function genereateExecutable( // generate Shell script const template = `#/bin/sh +# This executable is generated by Deno. Please don't modify it unless you know what it means. basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") case \`uname\` in - *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; esac if [ -x "$basedir/deno" ]; then @@ -254,7 +255,6 @@ export async function install( console.log(`✅ Successfully installed ${moduleName}`); console.log(filePath); - // TODO: add Windows version if (!checkIfExistsInPath(installerDir)) { console.log("\nℹ️ Add ~/.deno/bin to PATH"); console.log( @@ -276,6 +276,9 @@ export async function uninstall(moduleName: string): Promise { } await remove(filePath); + if (isWindows) { + await remove(filePath + ".cmd"); + } console.log(`ℹ️ Uninstalled ${moduleName}`); } diff --git a/installer/test.ts b/installer/test.ts index 3d588ef3ac03..88f685ea0c11 100644 --- a/installer/test.ts +++ b/installer/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -const { readFile, run, stat, makeTempDir, remove, env } = Deno; +const { run, stat, makeTempDir, remove, env } = Deno; import { test, runIfMain, TestFunction } from "../testing/mod.ts"; import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; @@ -7,6 +7,7 @@ import { BufReader, EOF } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { install, uninstall } from "./mod.ts"; import * as path from "../fs/path.ts"; +import * as fs from "../fs/mod.ts"; let fileServer: Deno.Process; const isWindows = Deno.platform.os === "win"; @@ -64,12 +65,10 @@ installerTest(async function installBasic(): Promise { const fileInfo = await stat(filePath); assert(fileInfo.isFile()); - const fileBytes = await readFile(filePath); - const fileContents = new TextDecoder().decode(fileBytes); if (isWindows) { assertEquals( - fileContents, - ` + await fs.readFileStr(filePath + ".cmd"), + `% This executable is generated by Deno. Please don't modify it unless you know what it means. % @IF EXIST "%~dp0\deno.exe" ( "%~dp0\deno.exe" run http://localhost:4500/http/file_server.ts %* ) ELSE ( @@ -79,14 +78,16 @@ installerTest(async function installBasic(): Promise { ) ` ); - } else { - assertEquals( - fileContents, - `#/bin/sh + } + + assertEquals( + await fs.readFileStr(filePath), + `#/bin/sh +# This executable is generated by Deno. Please don't modify it unless you know what it means. basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") case \`uname\` in - *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; esac if [ -x "$basedir/deno" ]; then @@ -98,8 +99,7 @@ else fi exit $ret ` - ); - } + ); }); installerTest(async function installWithFlags(): Promise { @@ -112,12 +112,10 @@ installerTest(async function installWithFlags(): Promise { const { HOME } = env(); const filePath = path.resolve(HOME, ".deno/bin/file_server"); - const fileBytes = await readFile(filePath); - const fileContents = new TextDecoder().decode(fileBytes); if (isWindows) { assertEquals( - fileContents, - ` + await fs.readFileStr(filePath + ".cmd"), + `% This executable is generated by Deno. Please don't modify it unless you know what it means. % @IF EXIST "%~dp0\deno.exe" ( "%~dp0\deno.exe" run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %* ) ELSE ( @@ -127,14 +125,16 @@ installerTest(async function installWithFlags(): Promise { ) ` ); - } else { - assertEquals( - fileContents, - `#/bin/sh + } + + assertEquals( + await fs.readFileStr(filePath), + `#/bin/sh +# This executable is generated by Deno. Please don't modify it unless you know what it means. basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") case \`uname\` in - *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; esac if [ -x "$basedir/deno" ]; then @@ -146,8 +146,7 @@ else fi exit $ret ` - ); - } + ); }); installerTest(async function uninstallBasic(): Promise { @@ -167,6 +166,16 @@ installerTest(async function uninstallBasic(): Promise { assertEquals(e.kind, Deno.ErrorKind.NotFound); } + if (isWindows) { + try { + await stat(filePath + ".cmd"); + } catch (e) { + thrown = true; + assert(e instanceof Deno.DenoError); + assertEquals(e.kind, Deno.ErrorKind.NotFound); + } + } + assert(thrown); }); From a92f6e4d9a517448313eba99b83309dda735b59f Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 14:42:46 +0800 Subject: [PATCH 10/28] fix test --- installer/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/test.ts b/installer/test.ts index 88f685ea0c11..a44b68dd46ee 100644 --- a/installer/test.ts +++ b/installer/test.ts @@ -121,7 +121,7 @@ installerTest(async function installWithFlags(): Promise { ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.TS;=;% - deno run http://localhost:4500/http/file_server.ts %* + deno run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %* ) ` ); From 0ed3128c2c49051d9e57411bd431ff62e0f7740d Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 14:57:14 +0800 Subject: [PATCH 11/28] fix /Users/axetroy env in powershell --- installer/mod.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 17d1bd0f369b..a2ce9bd46fe6 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -96,13 +96,16 @@ function checkIfExistsInPath(path: string): boolean { } function getInstallerDir(): string { - const { HOME } = env(); + // In windows's powershell. $HOME environmental variable maybe null. use $HOMEPATH instread. + let { HOME, HOMEPATH } = env(); - if (!HOME) { + const HOME_PATH = HOME || HOMEPATH + + if (!HOME_PATH) { throw new Error("$HOME is not defined."); } - return path.join(HOME, ".deno", "bin"); + return path.join(HOME_PATH, ".deno", "bin"); } // TODO: fetch doesn't handle redirects yet - once it does this function From 668356aaaba93a094dde2e4a5135bce6e88f749d Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 15:02:06 +0800 Subject: [PATCH 12/28] try fix error in powershell --- installer/mod.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index a2ce9bd46fe6..099c5faa9b4e 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -88,18 +88,21 @@ function createDirIfNotExists(path: string): void { } function checkIfExistsInPath(path: string): boolean { - const { PATH } = env(); + // In windows's powershell. $PATH not exist. use $Path instead. + const { PATH, Path } = env(); - const paths = (PATH as string).split(isWindows ? ";" : ":"); + const paths = ((PATH as string) || (Path as string)).split( + isWindows ? ";" : ":" + ); return paths.includes(path); } function getInstallerDir(): string { - // In windows's powershell. $HOME environmental variable maybe null. use $HOMEPATH instread. + // In windows's powershell. $HOME environmental variable maybe null. use $HOMEPATH instead. let { HOME, HOMEPATH } = env(); - const HOME_PATH = HOME || HOMEPATH + const HOME_PATH = HOME || HOMEPATH; if (!HOME_PATH) { throw new Error("$HOME is not defined."); From 86fb41b971ad3183f59cdce7b2ad7394777c62d7 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 15:20:44 +0800 Subject: [PATCH 13/28] fix path in windows --- installer/mod.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 099c5faa9b4e..09232c3b4ae7 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -91,9 +91,13 @@ function checkIfExistsInPath(path: string): boolean { // In windows's powershell. $PATH not exist. use $Path instead. const { PATH, Path } = env(); - const paths = ((PATH as string) || (Path as string)).split( - isWindows ? ";" : ":" - ); + let envPath = (PATH as string) || (Path as string) || ""; + + if (isWindows) { + envPath = envPath.replace("\\", "\\\\"); + } + + const paths = envPath.split(isWindows ? ";" : ":"); return paths.includes(path); } From 69ef4283d2172fdea03d2a7cb06c27b8dd2c90a7 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 15:29:15 +0800 Subject: [PATCH 14/28] update --- installer/mod.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 09232c3b4ae7..083d425e9a66 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -87,19 +87,22 @@ function createDirIfNotExists(path: string): void { } } -function checkIfExistsInPath(path: string): boolean { +function checkIfExistsInPath(filePath: string): boolean { // In windows's powershell. $PATH not exist. use $Path instead. const { PATH, Path } = env(); let envPath = (PATH as string) || (Path as string) || ""; - if (isWindows) { - envPath = envPath.replace("\\", "\\\\"); - } - const paths = envPath.split(isWindows ? ";" : ":"); - return paths.includes(path); + for (const p of paths) { + const pathInEnv = path.normalize(p); + if (pathInEnv === filePath) { + return true; + } + } + + return false; } function getInstallerDir(): string { From ab69e342e3720b34468c9d9b2a3aa76981023a4f Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 15:57:03 +0800 Subject: [PATCH 15/28] fix --- installer/mod.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 083d425e9a66..0e3abd4e7cec 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -88,25 +88,37 @@ function createDirIfNotExists(path: string): void { } function checkIfExistsInPath(filePath: string): boolean { - // In windows's powershell. $PATH not exist. use $Path instead. - const { PATH, Path } = env(); + // In Windows's powershell. $PATH not exist. use $Path instead. + // $HOMEDRIVE is only use in Windows. + const { PATH, Path, HOMEDRIVE } = env(); let envPath = (PATH as string) || (Path as string) || ""; const paths = envPath.split(isWindows ? ";" : ":"); + let fileAbsolutePath = filePath; + for (const p of paths) { - const pathInEnv = path.normalize(p); - if (pathInEnv === filePath) { + let pathInEnv = path.normalize(p); + // In Windows. We can get the path from env. eg. C:\Users\username\.deno\bin + // But in the path of Deno, there is no drive letter. eg \Users\username\.deno\bin in deno + if (isWindows) { + const driverLetterReg = /^[c-z]:/i; + if (driverLetterReg.test(pathInEnv)) { + fileAbsolutePath = HOMEDRIVE + "\\" + fileAbsolutePath; + } + } + if (pathInEnv === fileAbsolutePath) { return true; } + fileAbsolutePath = filePath; } return false; } function getInstallerDir(): string { - // In windows's powershell. $HOME environmental variable maybe null. use $HOMEPATH instead. + // In Windows's powershell. $HOME environmental variable maybe null. use $HOMEPATH instead. let { HOME, HOMEPATH } = env(); const HOME_PATH = HOME || HOMEPATH; @@ -155,10 +167,10 @@ function showHelp(): void { console.log(`deno installer Install remote or local script as executables. -USAGE: + USAGE: deno https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] -ARGS: + ARGS: EXE_NAME Name for executable SCRIPT_URL Local or remote URL of script to install [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. From 7cf1ca8dd211d260c47ee04a7a97f08c0b6ebadc Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 16:49:29 +0800 Subject: [PATCH 16/28] update help message --- installer/mod.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 0e3abd4e7cec..adb8b9e0b659 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -168,12 +168,12 @@ function showHelp(): void { Install remote or local script as executables. USAGE: - deno https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] + deno run https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] ARGS: - EXE_NAME Name for executable - SCRIPT_URL Local or remote URL of script to install - [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. + EXE_NAME Name for executable + SCRIPT_URL Local or remote URL of script to install + [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. `); } From 6cc2d695f9c2e364b9d78b9a013266a2d2d2d2f9 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 16:52:10 +0800 Subject: [PATCH 17/28] update help message --- installer/mod.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index adb8b9e0b659..488984944f70 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -167,14 +167,14 @@ function showHelp(): void { console.log(`deno installer Install remote or local script as executables. - USAGE: - deno run https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] - - ARGS: - EXE_NAME Name for executable - SCRIPT_URL Local or remote URL of script to install - [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. - `); +USAGE: + deno run https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] + +ARGS: + EXE_NAME Name for executable + SCRIPT_URL Local or remote URL of script to install + [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. +`); } async function genereateExecutable( From 78bff3f5a975c33b997509f4ef8e237da37d2b29 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 17:11:33 +0800 Subject: [PATCH 18/28] remove deno run --- installer/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/mod.ts b/installer/mod.ts index 488984944f70..0fb8ea1639af 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -168,7 +168,7 @@ function showHelp(): void { Install remote or local script as executables. USAGE: - deno run https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] + deno https://deno.land/std/installer/mod.ts EXE_NAME SCRIPT_URL [FLAGS...] ARGS: EXE_NAME Name for executable From f333afcd8d85569bdf23981ee31fea0bd645e336 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 17:13:04 +0800 Subject: [PATCH 19/28] fix function name typo --- installer/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 0fb8ea1639af..c0754cd40517 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -177,7 +177,7 @@ ARGS: `); } -async function genereateExecutable( +async function generateExecutable( filePath: string, commands: string[] ): Promise { @@ -275,7 +275,7 @@ export async function install( ...scriptArgs ]; - await genereateExecutable(filePath, commands); + await generateExecutable(filePath, commands); console.log(`✅ Successfully installed ${moduleName}`); console.log(filePath); From 552066d7d43e2b7bd044e0b4a7bb609fd4d20bb3 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 17:48:48 +0800 Subject: [PATCH 20/28] update comment --- installer/mod.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index c0754cd40517..5dbf066f895a 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -88,7 +88,7 @@ function createDirIfNotExists(path: string): void { } function checkIfExistsInPath(filePath: string): boolean { - // In Windows's powershell. $PATH not exist. use $Path instead. + // In Windows's Powershell. $PATH not exist. use $Path instead. // $HOMEDRIVE is only use in Windows. const { PATH, Path, HOMEDRIVE } = env(); @@ -118,7 +118,7 @@ function checkIfExistsInPath(filePath: string): boolean { } function getInstallerDir(): string { - // In Windows's powershell. $HOME environmental variable maybe null. use $HOMEPATH instead. + // In Windows's Powershell. $HOME environmental variable maybe null. use $HOMEPATH instead. let { HOME, HOMEPATH } = env(); const HOME_PATH = HOME || HOMEPATH; @@ -181,6 +181,7 @@ async function generateExecutable( filePath: string, commands: string[] ): Promise { + // In Windows. if use Powershell to run the installed module. It will look up .cmd file. // genereate Batch script if (isWindows) { const template = `% This executable is generated by Deno. Please don't modify it unless you know what it means. % From 5ddf7bb942abffe16237ea828cf9b11ce7aa69df Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 18:09:08 +0800 Subject: [PATCH 21/28] use deno fetch instead of fetch request --- installer/mod.ts | 51 +++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 5dbf066f895a..d525097172fc 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -9,9 +9,9 @@ const { exit, stdin, stat, - readAll, chmod, - remove + remove, + run } = Deno; import * as path from "../fs/path.ts"; @@ -130,39 +130,6 @@ function getInstallerDir(): string { return path.join(HOME_PATH, ".deno", "bin"); } -// TODO: fetch doesn't handle redirects yet - once it does this function -// can be removed -async function fetchWithRedirects( - url: string, - redirectLimit: number = 10 - // eslint-disable-next-line @typescript-eslint/no-explicit-any -): Promise { - // TODO: `Response` is not exposed in global so 'any' - const response = await fetch(url); - - if (response.status === 301 || response.status === 302) { - if (redirectLimit > 0) { - const redirectUrl = response.headers.get("location")!; - return await fetchWithRedirects(redirectUrl, redirectLimit - 1); - } - } - - return response; -} - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -async function fetchModule(url: string): Promise { - const response = await fetchWithRedirects(url); - - if (response.status !== 200) { - // TODO: show more debug information like status and maybe body - throw new Error(`Failed to get remote script ${url}.`); - } - - const body = await readAll(response.body); - return decoder.decode(body); -} - function showHelp(): void { console.log(`deno installer Install remote or local script as executables. @@ -245,10 +212,20 @@ export async function install( } // ensure script that is being installed exists - if (moduleUrl.startsWith("http")) { + if (/^https?:\/\/.{3,}/.test(moduleUrl)) { // remote module console.log(`Downloading: ${moduleUrl}\n`); - await fetchModule(moduleUrl); + const ps = run({ + args: ["deno", "fetch", moduleUrl], + stdout: "inherit", + stderr: "inherit" + }); + + const { code } = await ps.status(); + + if (code !== 0) { + throw new Error("Fail to fetch remote module."); + } } else { // assume that it's local file moduleUrl = path.resolve(moduleUrl); From 0d0bade55f6f41e515ca0fd9796a4f8affc3f260 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 18:15:30 +0800 Subject: [PATCH 22/28] feat local/remote module with deno fetch --- installer/mod.ts | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index d525097172fc..13bd421b2fb4 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -212,25 +212,17 @@ export async function install( } // ensure script that is being installed exists - if (/^https?:\/\/.{3,}/.test(moduleUrl)) { - // remote module - console.log(`Downloading: ${moduleUrl}\n`); - const ps = run({ - args: ["deno", "fetch", moduleUrl], - stdout: "inherit", - stderr: "inherit" - }); - - const { code } = await ps.status(); - - if (code !== 0) { - throw new Error("Fail to fetch remote module."); - } - } else { - // assume that it's local file - moduleUrl = path.resolve(moduleUrl); - console.log(`Looking for: ${moduleUrl}\n`); - await stat(moduleUrl); + console.log(`Downloading: ${moduleUrl}\n`); + const ps = run({ + args: ["deno", "fetch", moduleUrl], + stdout: "inherit", + stderr: "inherit" + }); + + const { code } = await ps.status(); + + if (code !== 0) { + throw new Error("Failed to fetch module."); } const grantedPermissions: Permission[] = []; From bf204eaf7232ed8d50c57ae3d47a812a0c0d300a Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 18:18:22 +0800 Subject: [PATCH 23/28] refactor code. make it clean. --- installer/mod.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 13bd421b2fb4..baa32cd877dc 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -8,12 +8,12 @@ const { writeFile, exit, stdin, - stat, chmod, remove, run } = Deno; import * as path from "../fs/path.ts"; +import { exists } from "../fs/exists.ts"; const encoder = new TextEncoder(); const decoder = new TextDecoder("utf-8"); @@ -197,14 +197,7 @@ export async function install( const filePath = path.join(installerDir, moduleName); - let fileInfo; - try { - fileInfo = await stat(filePath); - } catch (e) { - // pass - } - - if (fileInfo) { + if (await exists(filePath)) { const msg = `⚠️ ${moduleName} is already installed, do you want to overwrite it?`; if (!(await yesNoPrompt(msg))) { return; @@ -262,12 +255,8 @@ export async function uninstall(moduleName: string): Promise { const installerDir = getInstallerDir(); const filePath = path.join(installerDir, moduleName); - try { - await stat(filePath); - } catch (e) { - if (e instanceof Deno.DenoError && e.kind === Deno.ErrorKind.NotFound) { - throw new Error(`ℹ️ ${moduleName} not found`); - } + if ((await exists(filePath)) === false) { + throw new Error(`ℹ️ ${moduleName} not found`); } await remove(filePath); From 0956017558a3bed9eae2e53c896a71ef280d55e8 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 20:14:31 +0800 Subject: [PATCH 24/28] refactor --- installer/test.ts | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/installer/test.ts b/installer/test.ts index a44b68dd46ee..d28a9d4485af 100644 --- a/installer/test.ts +++ b/installer/test.ts @@ -157,26 +157,8 @@ installerTest(async function uninstallBasic(): Promise { await uninstall("file_server"); - let thrown = false; - try { - await stat(filePath); - } catch (e) { - thrown = true; - assert(e instanceof Deno.DenoError); - assertEquals(e.kind, Deno.ErrorKind.NotFound); - } - - if (isWindows) { - try { - await stat(filePath + ".cmd"); - } catch (e) { - thrown = true; - assert(e instanceof Deno.DenoError); - assertEquals(e.kind, Deno.ErrorKind.NotFound); - } - } - - assert(thrown); + assert(!(await fs.exists(filePath))); + assert(!(await fs.exists(filePath + ".cmd"))); }); installerTest(async function uninstallNonExistentModule(): Promise { From 89fcef454c14637986a47809d49e6025cecf14ec Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 20:15:29 +0800 Subject: [PATCH 25/28] refactor --- installer/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/mod.ts b/installer/mod.ts index baa32cd877dc..95507b724eb9 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -255,7 +255,7 @@ export async function uninstall(moduleName: string): Promise { const installerDir = getInstallerDir(); const filePath = path.join(installerDir, moduleName); - if ((await exists(filePath)) === false) { + if (!(await exists(filePath))) { throw new Error(`ℹ️ ${moduleName} not found`); } From 55114e27a0fcaacbd9cde7742583753cbbad8e98 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 20:23:53 +0800 Subject: [PATCH 26/28] refactor --- installer/mod.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 95507b724eb9..e456e774bb8d 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -18,6 +18,7 @@ import { exists } from "../fs/exists.ts"; const encoder = new TextEncoder(); const decoder = new TextDecoder("utf-8"); const isWindows = Deno.platform.os === "win"; +const driverLetterReg = /^[c-z]:/i; // Regular expression to test disk driver letter. eg "C:\\User\username\path\to" enum Permission { Read, @@ -88,8 +89,8 @@ function createDirIfNotExists(path: string): void { } function checkIfExistsInPath(filePath: string): boolean { - // In Windows's Powershell. $PATH not exist. use $Path instead. - // $HOMEDRIVE is only use in Windows. + // In Windows's Powershell $PATH not exist, so use $Path instead. + // $HOMEDRIVE is only used on Windows. const { PATH, Path, HOMEDRIVE } = env(); let envPath = (PATH as string) || (Path as string) || ""; @@ -99,11 +100,10 @@ function checkIfExistsInPath(filePath: string): boolean { let fileAbsolutePath = filePath; for (const p of paths) { - let pathInEnv = path.normalize(p); - // In Windows. We can get the path from env. eg. C:\Users\username\.deno\bin - // But in the path of Deno, there is no drive letter. eg \Users\username\.deno\bin in deno + const pathInEnv = path.normalize(p); + // On Windows paths from env contain drive letter. (eg. C:\Users\username.deno\bin) + // But in the path of Deno, there is no drive letter. (eg \Users\username\.deno\bin) if (isWindows) { - const driverLetterReg = /^[c-z]:/i; if (driverLetterReg.test(pathInEnv)) { fileAbsolutePath = HOMEDRIVE + "\\" + fileAbsolutePath; } @@ -118,7 +118,7 @@ function checkIfExistsInPath(filePath: string): boolean { } function getInstallerDir(): string { - // In Windows's Powershell. $HOME environmental variable maybe null. use $HOMEPATH instead. + // In Windows's Powershell $HOME environmental variable maybe null, if so use $HOMEPATH instead. let { HOME, HOMEPATH } = env(); const HOME_PATH = HOME || HOMEPATH; @@ -148,7 +148,7 @@ async function generateExecutable( filePath: string, commands: string[] ): Promise { - // In Windows. if use Powershell to run the installed module. It will look up .cmd file. + // On Windows if user is using Powershell .cmd extension is need to run the installed module. Generate batch script to satisfy that. // genereate Batch script if (isWindows) { const template = `% This executable is generated by Deno. Please don't modify it unless you know what it means. % @@ -205,7 +205,6 @@ export async function install( } // ensure script that is being installed exists - console.log(`Downloading: ${moduleUrl}\n`); const ps = run({ args: ["deno", "fetch", moduleUrl], stdout: "inherit", From 670c659fc96a7025526c6fe3aaa2a4b8f4175b83 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 20:32:10 +0800 Subject: [PATCH 27/28] update comment --- installer/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/mod.ts b/installer/mod.ts index e456e774bb8d..68353fa531fd 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -101,7 +101,7 @@ function checkIfExistsInPath(filePath: string): boolean { for (const p of paths) { const pathInEnv = path.normalize(p); - // On Windows paths from env contain drive letter. (eg. C:\Users\username.deno\bin) + // On Windows paths from env contain drive letter. (eg. C:\Users\username\.deno\bin) // But in the path of Deno, there is no drive letter. (eg \Users\username\.deno\bin) if (isWindows) { if (driverLetterReg.test(pathInEnv)) { From 156ec74b4e3a5aa832c12578c0a40c79fe6d4937 Mon Sep 17 00:00:00 2001 From: axetroy Date: Tue, 18 Jun 2019 23:48:01 +0800 Subject: [PATCH 28/28] update comment --- installer/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/mod.ts b/installer/mod.ts index 68353fa531fd..5d907bef528b 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -148,8 +148,8 @@ async function generateExecutable( filePath: string, commands: string[] ): Promise { - // On Windows if user is using Powershell .cmd extension is need to run the installed module. Generate batch script to satisfy that. - // genereate Batch script + // On Windows if user is using Powershell .cmd extension is need to run the installed module. + // Generate batch script to satisfy that. if (isWindows) { const template = `% This executable is generated by Deno. Please don't modify it unless you know what it means. % @IF EXIST "%~dp0\deno.exe" (