2024-01-26 17:35:43 -05:00
|
|
|
#!/usr/bin/env -S deno run --allow-write --allow-read --allow-run --allow-net
|
2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-08-19 00:26:12 -04:00
|
|
|
import { buildMode, getPrebuilt, getSources, join, ROOT_PATH } from "./util.js";
|
2023-01-13 13:42:15 -05:00
|
|
|
import { checkCopyright } from "./copyright_checker.js";
|
|
|
|
|
2023-09-26 00:41:07 -04:00
|
|
|
const promises = [];
|
2023-01-13 13:42:15 -05:00
|
|
|
|
2023-09-26 00:41:07 -04:00
|
|
|
let js = Deno.args.includes("--js");
|
|
|
|
let rs = Deno.args.includes("--rs");
|
|
|
|
if (!js && !rs) {
|
|
|
|
js = true;
|
|
|
|
rs = true;
|
2023-01-13 13:42:15 -05:00
|
|
|
}
|
|
|
|
|
2023-09-26 00:41:07 -04:00
|
|
|
if (js) {
|
|
|
|
promises.push(dlint());
|
|
|
|
promises.push(dlintPreferPrimordials());
|
2023-01-13 13:42:15 -05:00
|
|
|
}
|
|
|
|
|
2023-09-26 00:41:07 -04:00
|
|
|
if (rs) {
|
|
|
|
promises.push(clippy());
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:39:00 -04:00
|
|
|
if (js && rs) {
|
2023-09-26 00:41:07 -04:00
|
|
|
promises.push(checkCopyright());
|
|
|
|
}
|
|
|
|
|
|
|
|
const results = await Promise.allSettled(promises);
|
|
|
|
for (const result of results) {
|
|
|
|
if (result.status === "rejected") {
|
|
|
|
console.error(result.reason);
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
2023-01-13 13:42:15 -05:00
|
|
|
}
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
async function dlint() {
|
2021-01-16 18:32:59 -05:00
|
|
|
const configFile = join(ROOT_PATH, ".dlint.json");
|
2023-08-19 00:26:12 -04:00
|
|
|
const execPath = await getPrebuilt("dlint");
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
const sourceFiles = await getSources(ROOT_PATH, [
|
|
|
|
"*.js",
|
|
|
|
"*.ts",
|
2021-04-10 02:46:27 -04:00
|
|
|
":!:.github/mtime_cache/action.js",
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 15:22:13 -05:00
|
|
|
":!:tests/testdata/swc_syntax_error.ts",
|
|
|
|
":!:tests/testdata/error_008_checkjs.js",
|
2022-08-19 06:24:54 -04:00
|
|
|
":!:cli/bench/testdata/npm/*",
|
2022-01-18 06:58:50 -05:00
|
|
|
":!:cli/bench/testdata/express-router.js",
|
2022-08-18 08:05:02 -04:00
|
|
|
":!:cli/bench/testdata/react-dom.js",
|
2020-11-05 09:53:21 -05:00
|
|
|
":!:cli/compilers/wasm_wrap.js",
|
2022-11-25 18:29:48 -05:00
|
|
|
":!:cli/tsc/dts/**",
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 15:22:13 -05:00
|
|
|
":!:tests/testdata/encoding/**",
|
|
|
|
":!:tests/testdata/error_syntax.js",
|
|
|
|
":!:tests/testdata/file_extensions/ts_with_js_extension.js",
|
|
|
|
":!:tests/testdata/fmt/**",
|
|
|
|
":!:tests/testdata/npm/**",
|
|
|
|
":!:tests/testdata/lint/**",
|
|
|
|
":!:tests/testdata/run/**",
|
|
|
|
":!:tests/testdata/tsc/**",
|
|
|
|
":!:tests/testdata/test/glob/**",
|
2020-11-05 09:53:21 -05:00
|
|
|
":!:cli/tsc/*typescript.js",
|
2021-12-09 17:12:21 -05:00
|
|
|
":!:cli/tsc/compiler.d.ts",
|
2021-01-05 06:07:27 -05:00
|
|
|
":!:test_util/wpt/**",
|
2020-11-05 09:53:21 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (!sourceFiles.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-19 19:14:20 -04:00
|
|
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
2023-03-15 22:39:40 -04:00
|
|
|
const pending = [];
|
2020-11-05 09:53:21 -05:00
|
|
|
for (const chunk of chunks) {
|
2022-12-01 10:51:47 -05:00
|
|
|
const cmd = new Deno.Command(execPath, {
|
2023-01-13 13:42:15 -05:00
|
|
|
cwd: ROOT_PATH,
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["run", "--config=" + configFile, ...chunk],
|
2023-03-15 22:39:40 -04:00
|
|
|
// capture to not conflict with clippy output
|
|
|
|
stderr: "piped",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
2023-03-15 22:39:40 -04:00
|
|
|
pending.push(
|
|
|
|
cmd.output().then(({ stderr, code }) => {
|
|
|
|
if (code > 0) {
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
console.log("\n------ dlint ------");
|
|
|
|
console.log(decoder.decode(stderr));
|
|
|
|
throw new Error("dlint failed");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
2020-11-05 09:53:21 -05:00
|
|
|
}
|
2023-03-15 22:39:40 -04:00
|
|
|
await Promise.all(pending);
|
2020-11-05 09:53:21 -05:00
|
|
|
}
|
|
|
|
|
2021-08-19 19:14:20 -04:00
|
|
|
// `prefer-primordials` has to apply only to files related to bootstrapping,
|
|
|
|
// which is different from other lint rules. This is why this dedicated function
|
|
|
|
// is needed.
|
|
|
|
async function dlintPreferPrimordials() {
|
2023-08-19 00:26:12 -04:00
|
|
|
const execPath = await getPrebuilt("dlint");
|
2021-08-19 19:14:20 -04:00
|
|
|
const sourceFiles = await getSources(ROOT_PATH, [
|
|
|
|
"runtime/**/*.js",
|
2024-01-07 17:20:02 -05:00
|
|
|
"runtime/**/*.ts",
|
2021-08-19 19:14:20 -04:00
|
|
|
"ext/**/*.js",
|
2024-01-07 17:20:02 -05:00
|
|
|
"ext/**/*.ts",
|
|
|
|
":!:ext/**/*.d.ts",
|
2023-06-27 02:18:22 -04:00
|
|
|
"ext/node/polyfills/*.mjs",
|
2021-08-19 19:14:20 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (!sourceFiles.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
|
|
|
for (const chunk of chunks) {
|
2022-12-01 10:51:47 -05:00
|
|
|
const cmd = new Deno.Command(execPath, {
|
2023-01-13 13:42:15 -05:00
|
|
|
cwd: ROOT_PATH,
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["run", "--rule", "prefer-primordials", ...chunk],
|
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2021-08-19 19:14:20 -04:00
|
|
|
});
|
2022-12-01 10:51:47 -05:00
|
|
|
const { code } = await cmd.output();
|
|
|
|
|
|
|
|
if (code > 0) {
|
2021-08-19 19:14:20 -04:00
|
|
|
throw new Error("prefer-primordials failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function splitToChunks(paths, initCmdLen) {
|
|
|
|
let cmdLen = initCmdLen;
|
|
|
|
const MAX_COMMAND_LEN = 30000;
|
|
|
|
const chunks = [[]];
|
|
|
|
for (const p of paths) {
|
|
|
|
if (cmdLen + p.length > MAX_COMMAND_LEN) {
|
|
|
|
chunks.push([p]);
|
|
|
|
cmdLen = initCmdLen;
|
|
|
|
} else {
|
|
|
|
chunks[chunks.length - 1].push(p);
|
|
|
|
cmdLen += p.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chunks;
|
|
|
|
}
|
|
|
|
|
2020-11-05 09:53:21 -05:00
|
|
|
async function clippy() {
|
|
|
|
const currentBuildMode = buildMode();
|
2023-03-10 07:07:28 -05:00
|
|
|
const cmd = ["clippy", "--all-targets", "--all-features", "--locked"];
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
if (currentBuildMode != "debug") {
|
|
|
|
cmd.push("--release");
|
|
|
|
}
|
|
|
|
|
2022-12-01 10:51:47 -05:00
|
|
|
const cargoCmd = new Deno.Command("cargo", {
|
2023-01-13 13:42:15 -05:00
|
|
|
cwd: ROOT_PATH,
|
2022-11-10 06:53:31 -05:00
|
|
|
args: [
|
|
|
|
...cmd,
|
|
|
|
"--",
|
|
|
|
"-D",
|
|
|
|
"warnings",
|
|
|
|
],
|
2022-05-18 16:00:11 -04:00
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
2022-12-01 10:51:47 -05:00
|
|
|
const { code } = await cargoCmd.output();
|
|
|
|
|
|
|
|
if (code > 0) {
|
2020-11-05 09:53:21 -05:00
|
|
|
throw new Error("clippy failed");
|
|
|
|
}
|
|
|
|
}
|