Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
99186dba
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
99186dba
编写于
2月 07, 2020
作者:
R
Ryan Dahl
提交者:
GitHub
2月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove conditionals from installer (#3909)
上级
98fc7db4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
188 deletion
+30
-188
cli/installer.rs
cli/installer.rs
+21
-182
cli/tests/integration_tests.rs
cli/tests/integration_tests.rs
+9
-6
未找到文件。
cli/installer.rs
浏览文件 @
99186dba
...
...
@@ -48,30 +48,17 @@ fn validate_exec_name(exec_name: &str) -> Result<(), Error> {
}
#[cfg(windows)]
/// On Windows if user is using Powershell .cmd extension is need to run the
/// installed module.
/// Generate batch script to satisfy that.
fn
generate_executable_file
(
file_path
:
PathBuf
,
command
s
:
Vec
<
String
>
,
arg
s
:
Vec
<
String
>
,
)
->
Result
<
(),
Error
>
{
// On Windows if user is using Powershell .cmd extension is need to run the
// installed module.
// Generate batch script to satisfy that.
let
template_header
=
"This executable is generated by Deno. Please don't modify it unless you know what it means."
;
let
commands
:
Vec
<
String
>
=
commands
.iter
()
.map
(|
c
|
format!
(
"
\"
{}
\"
"
,
c
))
.collect
();
// TODO: remove conditionals in generated scripts
let
args
:
Vec
<
String
>
=
args
.iter
()
.map
(|
c
|
format!
(
"
\"
{}
\"
"
,
c
))
.collect
();
let
template
=
format!
(
r#"% {} %
@IF EXIST "%~dp0\deno.exe" (
"%~dp0\deno.exe" {} %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.TS;=;%
{} %*
)
"#
,
template_header
,
commands
[
1
..
]
.join
(
" "
),
commands
.join
(
" "
)
"% generated by deno install %
\n
deno.exe {} %*
\n
"
,
args
.join
(
" "
)
);
let
file_path
=
file_path
.with_extension
(
".cmd"
);
let
mut
file
=
File
::
create
(
&
file_path
)
?
;
...
...
@@ -82,37 +69,18 @@ fn generate_executable_file(
#[cfg(not(windows))]
fn
generate_executable_file
(
file_path
:
PathBuf
,
command
s
:
Vec
<
String
>
,
arg
s
:
Vec
<
String
>
,
)
->
Result
<
(),
Error
>
{
// On Windows if user is using Powershell .cmd extension is need to run the
// installed module.
// Generate batch script to satisfy that.
let
template_header
=
"This executable is generated by Deno. Please don't modify it unless you know what it means."
;
let
commands
:
Vec
<
String
>
=
commands
.iter
()
.map
(|
c
|
format!
(
"
\"
{}
\"
"
,
c
))
.collect
();
// TODO: remove conditionals in generated scripts
let
args
:
Vec
<
String
>
=
args
.iter
()
.map
(|
c
|
format!
(
"
\"
{}
\"
"
,
c
))
.collect
();
let
template
=
format!
(
r#"#!/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" {} "$@"
ret=$?
else
{} "$@"
ret=$?
fi
exit $ret
# generated by deno install
deno {} "$@"
"#
,
template_header
,
commands
[
1
..
]
.join
(
" "
),
commands
.join
(
" "
)
args
.join
(
" "
),
);
let
mut
file
=
File
::
create
(
&
file_path
)
?
;
file
.write_all
(
template
.as_bytes
())
?
;
...
...
@@ -197,7 +165,7 @@ pub fn install(
};
};
let
mut
executable_args
=
vec!
[
"
deno"
.to_string
(),
"
run"
.to_string
()];
let
mut
executable_args
=
vec!
[
"run"
.to_string
()];
executable_args
.extend_from_slice
(
&
flags
.to_permission_args
());
executable_args
.push
(
module_url
.to_string
());
executable_args
.extend_from_slice
(
&
args
);
...
...
@@ -270,39 +238,11 @@ mod tests {
assert
!
(
file_path
.exists
());
let
content
=
fs
::
read_to_string
(
file_path
)
.unwrap
();
// It's annoying when shell scripts don't have NL at the end.
assert_eq!
(
content
.chars
()
.last
()
.unwrap
(),
'\n'
);
let
expected_content
=
if
cfg!
(
windows
)
{
r#"% 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:4545/cli/tests/echo_server.ts" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.TS;=;%
"deno" "run" "http://localhost:4545/cli/tests/echo_server.ts" %*
)
"#
}
else
{
r#"#!/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"\`;;
esac
if [ -x "$basedir/deno" ]; then
"$basedir/deno" "run" "http://localhost:4545/cli/tests/echo_server.ts" "$@"
ret=$?
else
"deno" "run" "http://localhost:4545/cli/tests/echo_server.ts" "$@"
ret=$?
fi
exit $ret
"#
};
assert_eq!
(
content
,
expected_content
.to_string
());
assert
!
(
content
.contains
(
r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#
));
if
let
Some
(
home
)
=
original_home
{
env
::
set_var
(
"HOME"
,
home
);
}
...
...
@@ -314,7 +254,6 @@ exit $ret
#[test]
fn
install_custom_dir
()
{
let
temp_dir
=
TempDir
::
new
()
.expect
(
"tempdir fail"
);
install
(
DenoFlags
::
default
(),
Some
(
temp_dir
.path
()
.to_string_lossy
()
.to_string
()),
...
...
@@ -331,38 +270,8 @@ exit $ret
assert
!
(
file_path
.exists
());
let
content
=
fs
::
read_to_string
(
file_path
)
.unwrap
();
let
expected_content
=
if
cfg!
(
windows
)
{
r#"% 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:4545/cli/tests/echo_server.ts" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.TS;=;%
"deno" "run" "http://localhost:4545/cli/tests/echo_server.ts" %*
)
"#
}
else
{
r#"#!/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"\`;;
esac
if [ -x "$basedir/deno" ]; then
"$basedir/deno" "run" "http://localhost:4545/cli/tests/echo_server.ts" "$@"
ret=$?
else
"deno" "run" "http://localhost:4545/cli/tests/echo_server.ts" "$@"
ret=$?
fi
exit $ret
"#
};
assert_eq!
(
content
,
expected_content
.to_string
());
assert
!
(
content
.contains
(
r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#
));
}
#[test]
...
...
@@ -389,38 +298,7 @@ exit $ret
assert
!
(
file_path
.exists
());
let
content
=
fs
::
read_to_string
(
file_path
)
.unwrap
();
let
expected_content
=
if
cfg!
(
windows
)
{
r#"% 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-read" "--allow-net" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.TS;=;%
"deno" "run" "--allow-read" "--allow-net" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar" %*
)
"#
}
else
{
r#"#!/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"\`;;
esac
if [ -x "$basedir/deno" ]; then
"$basedir/deno" "run" "--allow-read" "--allow-net" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar" "$@"
ret=$?
else
"deno" "run" "--allow-read" "--allow-net" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar" "$@"
ret=$?
fi
exit $ret
"#
};
assert_eq!
(
content
,
expected_content
.to_string
());
assert
!
(
content
.contains
(
r#""run" "--allow-read" "--allow-net" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar""#
));
}
#[test]
...
...
@@ -446,45 +324,6 @@ exit $ret
assert
!
(
file_path
.exists
());
let
content
=
fs
::
read_to_string
(
file_path
)
.unwrap
();
let
expected_content
=
if
cfg!
(
windows
)
{
format!
(
r#"% 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" "{}" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.TS;=;%
"deno" "run" "{}" %*
)
"#
,
local_module_url
.to_string
(),
local_module_url
.to_string
()
)
}
else
{
format!
(
r#"#!/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"\`;;
esac
if [ -x "$basedir/deno" ]; then
"$basedir/deno" "run" "{}" "$@"
ret=$?
else
"deno" "run" "{}" "$@"
ret=$?
fi
exit $ret
"#
,
local_module_url
.to_string
(),
local_module_url
.to_string
()
)
};
assert_eq!
(
content
,
expected_content
);
assert
!
(
content
.contains
(
&
local_module_url
.to_string
()));
}
}
cli/tests/integration_tests.rs
浏览文件 @
99186dba
...
...
@@ -138,7 +138,7 @@ fn installer_test_local_module_run() {
let
stderr_str
=
std
::
str
::
from_utf8
(
&
output
.stderr
)
.unwrap
()
.trim
();
println!
(
"Got stdout: {:?}"
,
stdout_str
);
println!
(
"Got stderr: {:?}"
,
stderr_str
);
assert
_eq!
(
stdout_str
,
"hello, foo"
);
assert
!
(
stdout_str
.ends_with
(
"hello, foo"
)
);
drop
(
temp_dir
);
}
...
...
@@ -180,10 +180,10 @@ fn installer_test_remote_module_run() {
.env
(
path_var_name
,
path_var_value
)
.output
()
.expect
(
"failed to spawn script"
);
assert
_eq!
(
std
::
str
::
from_utf8
(
&
output
.stdout
)
.unwrap
()
.trim
(),
"hello, foo"
);
assert
!
(
std
::
str
::
from_utf8
(
&
output
.stdout
)
.unwrap
()
.trim
()
.ends_with
(
"hello, foo"
)
);
drop
(
temp_dir
);
drop
(
g
)
}
...
...
@@ -243,7 +243,10 @@ fn bundle_exports() {
.output
()
.expect
(
"failed to spawn script"
);
// check the output of the test.ts program.
assert_eq!
(
std
::
str
::
from_utf8
(
&
output
.stdout
)
.unwrap
()
.trim
(),
"Hello"
);
assert
!
(
std
::
str
::
from_utf8
(
&
output
.stdout
)
.unwrap
()
.trim
()
.ends_with
(
"Hello"
));
assert_eq!
(
output
.stderr
,
b
""
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录