1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

chore: remove third_party submodule (#20201)

removes third_party submodule, tools are installed on-demand.

- removed `load_test` and websocket benchmark (covered by benchy)
- removed node/bun http benchmarks (covered by benchy)
- `dlint` & `dprint` downloaded on-demand. 
- `wrk` & `hyperfine` downloaded before CI benchmark run. 
   Install locally using: `./tools/install_prebuilt.js wrk hyperfine`

#### updating dlint/dprint

update version in `tools/util.js` and place binary in
`denoland/deno_third_party`.
This commit is contained in:
Divy Srivastava 2023-08-19 09:56:12 +05:30 committed by GitHub
parent 0e4469c7a1
commit c2259f78eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 132 additions and 16537 deletions

View file

@ -65,8 +65,8 @@ sudo mount --rbind /sys /sysroot/sys
sudo mount --rbind /home /sysroot/home sudo mount --rbind /home /sysroot/home
sudo mount -t proc /proc /sysroot/proc sudo mount -t proc /proc /sysroot/proc
cp third_party/prebuilt/linux64/libdl/libdl.so.2 . wget https://github.com/denoland/deno_third_party/raw/master/prebuilt/linux64/libdl/libdl.a
cp third_party/prebuilt/linux64/libdl/libdl.a . wget https://github.com/denoland/deno_third_party/raw/master/prebuilt/linux64/libdl/libdl.so.2
sudo ln -s libdl.so.2 /sysroot/lib/x86_64-linux-gnu/libdl.so sudo ln -s libdl.so.2 /sysroot/lib/x86_64-linux-gnu/libdl.so
sudo ln -s libdl.a /sysroot/lib/x86_64-linux-gnu/libdl.a sudo ln -s libdl.a /sysroot/lib/x86_64-linux-gnu/libdl.a
@ -106,6 +106,8 @@ CFLAGS=-flto=thin --sysroot=/sysroot
__0`, __0`,
}; };
const installBenchTools = "./tools/install_prebuilt.js wrk hyperfine";
// The Windows builder is a little strange -- there's lots of room on C: and not so much on D: // The Windows builder is a little strange -- there's lots of room on C: and not so much on D:
// We'll check out to D:, but then all of our builds should happen on a C:-mapped drive // We'll check out to D:, but then all of our builds should happen on a C:-mapped drive
const reconfigureWindowsStorage = { const reconfigureWindowsStorage = {
@ -395,7 +397,6 @@ const ci = {
reconfigureWindowsStorage, reconfigureWindowsStorage,
...cloneRepoStep, ...cloneRepoStep,
submoduleStep("./test_util/std"), submoduleStep("./test_util/std"),
submoduleStep("./third_party"),
{ {
...submoduleStep("./test_util/wpt"), ...submoduleStep("./test_util/wpt"),
if: "matrix.wpt", if: "matrix.wpt",
@ -504,6 +505,8 @@ const ci = {
'if [ "${{ matrix.job }}" == "bench" ]', 'if [ "${{ matrix.job }}" == "bench" ]',
"then", "then",
" node -v", " node -v",
// Install benchmark tools.
installBenchTools,
"fi", "fi",
].join("\n"), ].join("\n"),
}, },
@ -552,7 +555,7 @@ const ci = {
name: "test_format.js", name: "test_format.js",
if: "matrix.job == 'lint' && startsWith(matrix.os, 'ubuntu')", if: "matrix.job == 'lint' && startsWith(matrix.os, 'ubuntu')",
run: run:
"deno run --unstable --allow-write --allow-read --allow-run ./tools/format.js --check", "deno run --unstable --allow-write --allow-read --allow-run --allow-net ./tools/format.js --check",
}, },
{ {
name: "Lint PR title", name: "Lint PR title",
@ -567,7 +570,7 @@ const ci = {
name: "lint.js", name: "lint.js",
if: "matrix.job == 'lint'", if: "matrix.job == 'lint'",
run: run:
"deno run --unstable --allow-write --allow-read --allow-run ./tools/lint.js", "deno run --unstable --allow-write --allow-read --allow-run --allow-net ./tools/lint.js",
}, },
{ {
name: "node_compat/setup.ts --check", name: "node_compat/setup.ts --check",

View file

@ -128,9 +128,6 @@ jobs:
- name: Clone submodule ./test_util/std - name: Clone submodule ./test_util/std
run: git submodule update --init --recursive --depth=1 -- ./test_util/std run: git submodule update --init --recursive --depth=1 -- ./test_util/std
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr)' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr)'
- name: Clone submodule ./third_party
run: git submodule update --init --recursive --depth=1 -- ./third_party
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr)'
- name: Clone submodule ./test_util/wpt - name: Clone submodule ./test_util/wpt
run: git submodule update --init --recursive --depth=1 -- ./test_util/wpt run: git submodule update --init --recursive --depth=1 -- ./test_util/wpt
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.wpt)' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.wpt)'
@ -252,8 +249,8 @@ jobs:
sudo mount --rbind /home /sysroot/home sudo mount --rbind /home /sysroot/home
sudo mount -t proc /proc /sysroot/proc sudo mount -t proc /proc /sysroot/proc
cp third_party/prebuilt/linux64/libdl/libdl.so.2 . wget https://github.com/denoland/deno_third_party/raw/master/prebuilt/linux64/libdl/libdl.a
cp third_party/prebuilt/linux64/libdl/libdl.a . wget https://github.com/denoland/deno_third_party/raw/master/prebuilt/linux64/libdl/libdl.so.2
sudo ln -s libdl.so.2 /sysroot/lib/x86_64-linux-gnu/libdl.so sudo ln -s libdl.so.2 /sysroot/lib/x86_64-linux-gnu/libdl.so
sudo ln -s libdl.a /sysroot/lib/x86_64-linux-gnu/libdl.a sudo ln -s libdl.a /sysroot/lib/x86_64-linux-gnu/libdl.a
@ -303,6 +300,7 @@ jobs:
if [ "${{ matrix.job }}" == "bench" ] if [ "${{ matrix.job }}" == "bench" ]
then then
node -v node -v
./tools/install_prebuilt.js wrk hyperfine
fi fi
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr)' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr)'
- name: Cache Cargo home - name: Cache Cargo home
@ -332,7 +330,7 @@ jobs:
cache-path: ./target cache-path: ./target
- name: test_format.js - name: test_format.js
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'' && startsWith(matrix.os, ''ubuntu''))' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'' && startsWith(matrix.os, ''ubuntu''))'
run: deno run --unstable --allow-write --allow-read --allow-run ./tools/format.js --check run: deno run --unstable --allow-write --allow-read --allow-run --allow-net ./tools/format.js --check
- name: Lint PR title - name: Lint PR title
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'' && github.event_name == ''pull_request'' && startsWith(matrix.os, ''ubuntu''))' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'' && github.event_name == ''pull_request'' && startsWith(matrix.os, ''ubuntu''))'
env: env:
@ -340,7 +338,7 @@ jobs:
run: deno run ./tools/verify_pr_title.js "$PR_TITLE" run: deno run ./tools/verify_pr_title.js "$PR_TITLE"
- name: lint.js - name: lint.js
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'')' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'')'
run: deno run --unstable --allow-write --allow-read --allow-run ./tools/lint.js run: deno run --unstable --allow-write --allow-read --allow-run --allow-net ./tools/lint.js
- name: node_compat/setup.ts --check - name: node_compat/setup.ts --check
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'' && startsWith(matrix.os, ''ubuntu''))' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (matrix.job == ''lint'' && startsWith(matrix.os, ''ubuntu''))'
run: deno run --allow-write --allow-read --allow-run=git ./tools/node_compat/setup.ts --check run: deno run --allow-write --allow-read --allow-run=git ./tools/node_compat/setup.ts --check

1
.gitignore vendored
View file

@ -11,6 +11,7 @@ gclient_config.py_entries
/target/ /target/
/std/hash/_wasm/target /std/hash/_wasm/target
/tools/wpt/manifest.json /tools/wpt/manifest.json
/third_party/
/test_napi/node_modules /test_napi/node_modules
/test_napi/build /test_napi/build
/test_napi/third_party_tests/node_modules /test_napi/third_party_tests/node_modules

4
.gitmodules vendored
View file

@ -1,7 +1,3 @@
[submodule "deno_third_party"]
path = third_party
url = https://github.com/denoland/deno_third_party.git
shallow = true
[submodule "test_util/std"] [submodule "test_util/std"]
path = test_util/std path = test_util/std
url = https://github.com/denoland/deno_std url = https://github.com/denoland/deno_std

View file

@ -38,7 +38,6 @@ pub fn benchmark(
if path.ends_with(".lua") { if path.ends_with(".lua") {
continue; continue;
} }
let name = entry.file_name().into_string().unwrap();
let file_stem = pathbuf.file_stem().unwrap().to_str().unwrap(); let file_stem = pathbuf.file_stem().unwrap().to_str().unwrap();
let lua_script = http_dir.join(format!("{file_stem}.lua")); let lua_script = http_dir.join(format!("{file_stem}.lua"));
@ -48,65 +47,25 @@ pub fn benchmark(
} }
let port = get_port(); let port = get_port();
if name.starts_with("node") { // deno run -A --unstable <path> <addr>
// node <path> <port> res.insert(
res.insert( file_stem.to_string(),
file_stem.to_string(), run(
run( &[
&["node", path, &port.to_string()], deno_exe.as_str(),
port, "run",
None, "--allow-all",
None, "--unstable",
maybe_lua, "--enable-testing-features-do-not-use",
)?, path,
); &server_addr(port),
} else if name.starts_with("bun") && !cfg!(target_os = "windows") { ],
// Bun does not support Windows. port,
#[cfg(target_arch = "x86_64")] None,
#[cfg(not(target_vendor = "apple"))] None,
let bun_exe = test_util::prebuilt_tool_path("bun"); maybe_lua,
#[cfg(target_vendor = "apple")] )?,
#[cfg(target_arch = "x86_64")] );
let bun_exe = test_util::prebuilt_tool_path("bun-x64");
#[cfg(target_vendor = "apple")]
#[cfg(target_arch = "aarch64")]
let bun_exe = test_util::prebuilt_tool_path("bun-aarch64");
#[cfg(target_os = "linux")]
#[cfg(target_arch = "aarch64")]
let bun_exe = test_util::prebuilt_tool_path("bun-aarch64");
// bun <path> <port>
res.insert(
file_stem.to_string(),
run(
&[&bun_exe.to_string(), path, &port.to_string()],
port,
None,
None,
maybe_lua,
)?,
);
} else {
// deno run -A --unstable <path> <addr>
res.insert(
file_stem.to_string(),
run(
&[
deno_exe.as_str(),
"run",
"--allow-all",
"--unstable",
"--enable-testing-features-do-not-use",
path,
&server_addr(port),
],
port,
None,
None,
maybe_lua,
)?,
);
}
} }
res.insert("hyper".to_string(), hyper_http(hyper_hello_exe)?); res.insert("hyper".to_string(), hyper_http(hyper_hello_exe)?);

View file

@ -1,17 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const port = Bun.argv[2] || "4545";
const { Hono } = require("../testdata/npm/hono/dist/index.js");
const app = new Hono();
app.use("*", async (c, n) => {
c.res.headers.set("Date", (new Date()).toUTCString());
await n();
});
app.get("/", (c) => c.text("Hello, World!"));
Bun.serve({
fetch(r) {
return app.fetch(r);
},
port: Number(port),
});

View file

@ -1,10 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const port = Bun.argv[2] || "4545";
Bun.serve({
fetch(_req) {
return new Response("Hello World", {
headers: { "Date": (new Date()).toUTCString() },
});
},
port: Number(port),
});

View file

@ -1,14 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const port = Bun.argv[2] || "4545";
const path = new URL("../testdata/128k.bin", import.meta.url).pathname;
Bun.serve({
fetch(_req) {
const file = Bun.file(path);
return new Response(file, {
headers: { "Date": (new Date()).toUTCString() },
});
},
port: Number(port),
});

View file

@ -1,9 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const http = require("http");
const port = process.argv[2] || "4544";
console.log("port", port);
http
.Server((req, res) => {
res.end("Hello World");
})
.listen(port);

View file

@ -1,10 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const http = require("http");
const port = process.argv[2] || "4544";
console.log("port", port);
http
.Server((req, res) => {
const bar = req.headers["foo"];
res.end(bar);
})
.listen(port);

View file

@ -1,5 +0,0 @@
wrk.headers["foo"] = "bar"
wrk.headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
wrk.headers["Viewport-Width"] = "1920"
wrk.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
wrk.headers["Accept-Language"] = "en,la;q=0.9"

View file

@ -1,18 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const http = require("http");
const port = process.argv[2] || "4544";
console.log("port", port);
http
.Server((req, res) => {
if (req.method == "POST") {
let chunks = [];
req.on("data", function (data) {
chunks.push(data);
});
req.on("end", function () {
const buffer = Buffer.concat(chunks);
res.end(buffer.byteLength.toString());
});
}
})
.listen(port);

View file

@ -1,5 +0,0 @@
wrk.method = "POST"
wrk.headers["Content-Type"] = "application/octet-stream"
file = io.open("./cli/bench/testdata/128k.bin", "rb")
wrk.body = file:read("*a")

View file

@ -1,18 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const http = require("http");
const port = process.argv[2] || "4544";
console.log("port", port);
http
.Server((req, res) => {
if (req.method == "POST") {
let body = "";
req.on("data", function (data) {
body += data;
});
req.on("end", function () {
const { hello } = JSON.parse(body);
res.end(hello);
});
}
})
.listen(port);

View file

@ -1,3 +0,0 @@
wrk.method = "POST"
wrk.headers["Content-Type"] = "application/json"
wrk.body = '{"hello":"node"}'

File diff suppressed because it is too large Load diff

View file

@ -1,18 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// Note: this is a keep-alive server.
const { Server } = require("net");
const port = process.argv[2] || "4544";
console.log("port", port);
const response = Buffer.from(
"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n",
);
Server((socket) => {
socket.on("data", (_) => {
socket.write(response);
});
socket.on("error", (_) => {
socket.destroy();
});
}).listen(port);

View file

@ -18,7 +18,6 @@ include!("../util/time.rs");
mod http; mod http;
mod lsp; mod lsp;
mod websocket;
fn read_json(filename: &Path) -> Result<Value> { fn read_json(filename: &Path) -> Result<Value> {
let f = fs::File::open(filename)?; let f = fs::File::open(filename)?;
@ -403,7 +402,6 @@ struct BenchResult {
max_memory: HashMap<String, i64>, max_memory: HashMap<String, i64>,
lsp_exec_time: HashMap<String, i64>, lsp_exec_time: HashMap<String, i64>,
req_per_sec: HashMap<String, i64>, req_per_sec: HashMap<String, i64>,
ws_msg_per_sec: HashMap<String, f64>,
syscall_count: HashMap<String, i64>, syscall_count: HashMap<String, i64>,
thread_count: HashMap<String, i64>, thread_count: HashMap<String, i64>,
} }
@ -419,7 +417,6 @@ async fn main() -> Result<()> {
"cargo_deps", "cargo_deps",
"lsp", "lsp",
"http", "http",
"websocket",
"strace", "strace",
"mem_usage", "mem_usage",
]; ];
@ -459,11 +456,6 @@ async fn main() -> Result<()> {
..Default::default() ..Default::default()
}; };
if benchmarks.contains(&"websocket") {
let ws = websocket::benchmark()?;
new_data.ws_msg_per_sec = ws;
}
if benchmarks.contains(&"bundle") { if benchmarks.contains(&"bundle") {
let bundle_size = bundle_benchmark(&deno_exe)?; let bundle_size = bundle_benchmark(&deno_exe)?;
new_data.bundle_size = bundle_size; new_data.bundle_size = bundle_size;

View file

@ -1,76 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::collections::HashMap;
use std::io::BufRead;
use std::path::Path;
use std::process::Command;
use std::process::Stdio;
use std::time::Duration;
use super::Result;
pub fn benchmark() -> Result<HashMap<String, f64>> {
let deno_exe = test_util::deno_exe_path();
let mut res = HashMap::new();
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let ws_dir = manifest_dir.join("bench").join("websocket");
for entry in std::fs::read_dir(&ws_dir)? {
let port = crate::http::get_port();
let entry = entry?;
let pathbuf = entry.path();
let path = pathbuf.to_str().unwrap();
let file_stem = pathbuf.file_stem().unwrap().to_str().unwrap();
let mut cmd = Command::new(&deno_exe);
let mut server = cmd
.arg("run")
.arg("-A")
.arg("--unstable")
.arg(path)
.arg(&port.to_string())
.spawn()
.unwrap();
std::thread::sleep(Duration::from_secs(5)); // wait for server to wake up.
let load_test = test_util::prebuilt_tool_path("load_test");
assert!(load_test.is_file());
// ./load_test 100 0.0.0.0 8000 0 0
// Running benchmark now...
// Msg/sec: 161327.500000
// Msg/sec: 163977.000000
// ^C⏎
let mut cmd = Command::new(load_test);
let mut process = cmd
.stdout(Stdio::piped())
.arg("100")
.arg("0.0.0.0")
.arg(&port.to_string())
.arg("0")
.arg("0")
.spawn()
.unwrap();
let mut lines = Vec::new();
let mut stdout =
std::io::BufReader::new(process.stdout.take().unwrap()).lines();
for _ in 0..5 {
let line = stdout.next().unwrap().unwrap();
lines.push(line);
}
process.kill().unwrap();
let msg_per_sec = lines
.into_iter()
.filter(|line| line.starts_with("Msg/sec:"))
.map(|line| line.split(": ").nth(1).unwrap().parse::<f64>().unwrap())
.max_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap();
res.insert(file_stem.to_string(), msg_per_sec);
server.kill().unwrap();
}
Ok(res)
}

View file

@ -1,25 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const port = Deno.args[0] ?? "8080";
const { serve } = Deno;
function handler(request) {
const { socket, response } = Deno.upgradeWebSocket(request, {
idleTimeout: 0,
});
socket.onmessage = (e) => {
socket.send(e.data);
};
socket.onopen = () => {
console.log("Connected to client");
};
socket.onerror = (e) => {
console.log(e);
};
return response;
}
serve({ port: parseInt(port), hostname: "0.0.0.0" }, handler);

@ -1 +0,0 @@
Subproject commit 7f1a41fee1bfbffd56674269db8f1e19263cf751

View file

@ -1,10 +1,10 @@
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run #!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run --allow-net
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js"; import { getPrebuilt, join, ROOT_PATH } from "./util.js";
const subcommand = Deno.args.includes("--check") ? "check" : "fmt"; const subcommand = Deno.args.includes("--check") ? "check" : "fmt";
const configFile = join(ROOT_PATH, ".dprint.json"); const configFile = join(ROOT_PATH, ".dprint.json");
const execPath = getPrebuiltToolPath("dprint"); const execPath = await getPrebuilt("dprint");
const cmd = new Deno.Command(execPath, { const cmd = new Deno.Command(execPath, {
args: [subcommand, "--config=" + configFile], args: [subcommand, "--config=" + configFile],
cwd: ROOT_PATH, cwd: ROOT_PATH,

8
tools/install_prebuilt.js Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-net
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { getPrebuilt } from "./util.js";
const args = Deno.args.slice();
for (const arg of args) {
await getPrebuilt(arg);
}

View file

@ -1,12 +1,6 @@
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run #!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run --allow-net
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { import { buildMode, getPrebuilt, getSources, join, ROOT_PATH } from "./util.js";
buildMode,
getPrebuiltToolPath,
getSources,
join,
ROOT_PATH,
} from "./util.js";
import { checkCopyright } from "./copyright_checker.js"; import { checkCopyright } from "./copyright_checker.js";
let didLint = false; let didLint = false;
@ -33,7 +27,7 @@ if (!didLint) {
async function dlint() { async function dlint() {
const configFile = join(ROOT_PATH, ".dlint.json"); const configFile = join(ROOT_PATH, ".dlint.json");
const execPath = getPrebuiltToolPath("dlint"); const execPath = await getPrebuilt("dlint");
const sourceFiles = await getSources(ROOT_PATH, [ const sourceFiles = await getSources(ROOT_PATH, [
"*.js", "*.js",
@ -41,7 +35,6 @@ async function dlint() {
":!:.github/mtime_cache/action.js", ":!:.github/mtime_cache/action.js",
":!:cli/tests/testdata/swc_syntax_error.ts", ":!:cli/tests/testdata/swc_syntax_error.ts",
":!:cli/tests/testdata/error_008_checkjs.js", ":!:cli/tests/testdata/error_008_checkjs.js",
":!:cli/bench/http/node*.js",
":!:cli/bench/testdata/npm/*", ":!:cli/bench/testdata/npm/*",
":!:cli/bench/testdata/express-router.js", ":!:cli/bench/testdata/express-router.js",
":!:cli/bench/testdata/react-dom.js", ":!:cli/bench/testdata/react-dom.js",
@ -92,7 +85,7 @@ async function dlint() {
// which is different from other lint rules. This is why this dedicated function // which is different from other lint rules. This is why this dedicated function
// is needed. // is needed.
async function dlintPreferPrimordials() { async function dlintPreferPrimordials() {
const execPath = getPrebuiltToolPath("dlint"); const execPath = await getPrebuilt("dlint");
const sourceFiles = await getSources(ROOT_PATH, [ const sourceFiles = await getSources(ROOT_PATH, [
"runtime/**/*.js", "runtime/**/*.js",
"ext/**/*.js", "ext/**/*.js",

View file

@ -6,11 +6,18 @@ import {
resolve, resolve,
toFileUrl, toFileUrl,
} from "../test_util/std/path/mod.ts"; } from "../test_util/std/path/mod.ts";
import { wait } from "https://deno.land/x/wait@0.1.13/mod.ts";
export { dirname, fromFileUrl, join, resolve, toFileUrl }; export { dirname, fromFileUrl, join, resolve, toFileUrl };
export { existsSync, walk } from "../test_util/std/fs/mod.ts"; export { existsSync, walk } from "../test_util/std/fs/mod.ts";
export { TextLineStream } from "../test_util/std/streams/text_line_stream.ts"; export { TextLineStream } from "../test_util/std/streams/text_line_stream.ts";
export { delay } from "../test_util/std/async/delay.ts"; export { delay } from "../test_util/std/async/delay.ts";
// [toolName] --version output
const versions = {
"dprint": "dprint 0.40.0",
"dlint": "dlint 0.47.0",
};
export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.url))); export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.url)));
async function getFilesFromGit(baseDir, args) { async function getFilesFromGit(baseDir, args) {
@ -100,14 +107,82 @@ export function buildPath() {
return join(ROOT_PATH, "target", buildMode()); return join(ROOT_PATH, "target", buildMode());
} }
export function getPrebuiltToolPath(toolName) { const platformDirName = {
const PREBUILT_PATH = join(ROOT_PATH, "third_party", "prebuilt"); "windows": "win",
"darwin": "mac",
"linux": "linux64",
}[Deno.build.os];
const platformDirName = { const executableSuffix = Deno.build.os === "windows" ? ".exe" : "";
"windows": "win",
"darwin": "mac", export async function getPrebuilt(toolName) {
"linux": "linux64", const toolPath = getPrebuiltToolPath(toolName);
}[Deno.build.os]; try {
const executableSuffix = Deno.build.os === "windows" ? ".exe" : ""; await Deno.stat(toolPath);
return join(PREBUILT_PATH, platformDirName, toolName + executableSuffix); const versionOk = await verifyVersion(toolName);
if (!versionOk) {
throw new Error("Version mismatch");
}
} catch {
await downloadPrebuilt(toolName);
}
return toolPath;
}
const PREBUILT_PATH = join(ROOT_PATH, "third_party", "prebuilt");
const PREBUILT_TOOL_DIR = join(PREBUILT_PATH, platformDirName);
export function getPrebuiltToolPath(toolName) {
return join(PREBUILT_TOOL_DIR, toolName + executableSuffix);
}
const downloadUrl =
`https://raw.githubusercontent.com/denoland/deno_third_party/master/prebuilt/${platformDirName}`;
export async function downloadPrebuilt(toolName) {
const spinner = wait("Downloading prebuilt tool: " + toolName).start();
const toolPath = getPrebuiltToolPath(toolName);
try {
await Deno.mkdir(PREBUILT_TOOL_DIR, { recursive: true });
const url = `${downloadUrl}/${toolName}${executableSuffix}`;
const resp = await fetch(url);
const file = await Deno.open(toolPath, {
create: true,
write: true,
mode: 0o755,
});
await resp.body.pipeTo(file.writable);
} catch (e) {
spinner.fail();
throw e;
}
spinner.succeed();
}
export async function verifyVersion(toolName) {
const requiredVersion = versions[toolName];
if (!requiredVersion) {
return true;
}
try {
const toolPath = getPrebuiltToolPath(toolName);
const cmd = new Deno.Command(toolPath, {
args: ["--version"],
stdout: "piped",
stderr: "inherit",
});
const output = await cmd.output();
const version = new TextDecoder().decode(output.stdout).trim();
return version == requiredVersion;
} catch (e) {
console.error(e);
return false;
}
} }