2024-07-25 00:26:54 +00:00
|
|
|
#!/usr/bin/env -S deno run --allow-read=. --allow-run=git --config=tests/config/deno.json
|
2024-01-01 19:58:21 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-13 07:51:32 +00:00
|
|
|
|
2024-08-20 19:14:37 +00:00
|
|
|
// deno-lint-ignore-file no-console
|
|
|
|
|
2023-01-13 07:51:32 +00:00
|
|
|
import { getSources, ROOT_PATH } from "./util.js";
|
|
|
|
|
2024-01-07 00:14:38 +00:00
|
|
|
const copyrightYear = 2024;
|
|
|
|
|
2023-01-13 07:51:32 +00:00
|
|
|
const buffer = new Uint8Array(1024);
|
|
|
|
const textDecoder = new TextDecoder();
|
|
|
|
|
|
|
|
async function readFirstPartOfFile(filePath) {
|
|
|
|
const file = await Deno.open(filePath, { read: true });
|
|
|
|
try {
|
|
|
|
const byteCount = await file.read(buffer);
|
|
|
|
return textDecoder.decode(buffer.slice(0, byteCount ?? 0));
|
|
|
|
} finally {
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:42:15 +00:00
|
|
|
export async function checkCopyright() {
|
2023-01-13 07:51:32 +00:00
|
|
|
const sourceFiles = await getSources(ROOT_PATH, [
|
|
|
|
// js and ts
|
|
|
|
"*.js",
|
2024-08-12 16:41:32 +00:00
|
|
|
"*.mjs",
|
|
|
|
"*.jsx",
|
2023-01-13 07:51:32 +00:00
|
|
|
"*.ts",
|
2024-08-12 16:41:32 +00:00
|
|
|
"*.tsx",
|
2023-01-13 07:51:32 +00:00
|
|
|
":!:.github/mtime_cache/action.js",
|
|
|
|
":!:cli/bench/testdata/**",
|
2024-08-12 16:41:32 +00:00
|
|
|
":!:cli/tools/bench/mitata.rs",
|
|
|
|
":!:cli/tools/init/templates/**",
|
2023-01-13 07:51:32 +00:00
|
|
|
":!:cli/tsc/*typescript.js",
|
|
|
|
":!:cli/tsc/compiler.d.ts",
|
2024-08-12 16:41:32 +00: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 20:22:13 +00:00
|
|
|
":!:tests/node_compat/test/**",
|
2024-08-12 16:41:32 +00:00
|
|
|
":!:tests/registry/**",
|
|
|
|
":!:tests/specs/**",
|
|
|
|
":!:tests/testdata/**",
|
|
|
|
":!:tests/unit_node/testdata/**",
|
|
|
|
":!:tests/wpt/suite/**",
|
2023-01-13 07:51:32 +00:00
|
|
|
|
|
|
|
// rust
|
|
|
|
"*.rs",
|
|
|
|
":!:ops/optimizer_tests/**",
|
|
|
|
|
2024-08-12 16:41:32 +00:00
|
|
|
// c
|
|
|
|
"*.c",
|
|
|
|
|
2023-01-13 07:51:32 +00:00
|
|
|
// toml
|
|
|
|
"*Cargo.toml",
|
|
|
|
]);
|
|
|
|
|
2023-03-16 02:39:40 +00:00
|
|
|
const errors = [];
|
2023-01-13 07:51:32 +00:00
|
|
|
const sourceFilesSet = new Set(sourceFiles);
|
2023-06-26 15:38:55 +00:00
|
|
|
const ERROR_MSG = "Copyright header is missing: ";
|
2023-01-13 07:51:32 +00:00
|
|
|
|
2023-06-26 15:38:55 +00:00
|
|
|
// Acceptable content before the copyright line
|
|
|
|
const ACCEPTABLE_LINES =
|
|
|
|
/^(\/\/ deno-lint-.*|\/\/ Copyright.*|\/\/ Ported.*|\s*|#!\/.*)\n/;
|
|
|
|
const COPYRIGHT_LINE =
|
2024-01-07 00:14:38 +00:00
|
|
|
`Copyright 2018-${copyrightYear} the Deno authors. All rights reserved. MIT license.`;
|
2023-06-26 15:38:55 +00:00
|
|
|
const TOML_COPYRIGHT_LINE = "# " + COPYRIGHT_LINE;
|
|
|
|
const C_STYLE_COPYRIGHT_LINE = "// " + COPYRIGHT_LINE;
|
2023-01-13 07:51:32 +00:00
|
|
|
|
2023-06-26 15:38:55 +00:00
|
|
|
for (const file of sourceFilesSet) {
|
2023-01-13 07:51:32 +00:00
|
|
|
const fileText = await readFirstPartOfFile(file);
|
|
|
|
if (file.endsWith("Cargo.toml")) {
|
|
|
|
if (
|
2023-06-26 15:38:55 +00:00
|
|
|
!fileText.startsWith(TOML_COPYRIGHT_LINE)
|
2023-01-13 07:51:32 +00:00
|
|
|
) {
|
2023-03-16 02:39:40 +00:00
|
|
|
errors.push(ERROR_MSG + file);
|
2023-01-13 07:51:32 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2023-06-26 15:38:55 +00:00
|
|
|
!fileText.startsWith(C_STYLE_COPYRIGHT_LINE)
|
2023-01-13 07:51:32 +00:00
|
|
|
) {
|
2023-06-26 15:38:55 +00:00
|
|
|
let trimmedText = fileText;
|
2024-04-30 07:59:56 +00:00
|
|
|
// Attempt to trim acceptable lines
|
2023-06-26 15:38:55 +00:00
|
|
|
while (
|
|
|
|
ACCEPTABLE_LINES.test(trimmedText) &&
|
|
|
|
!trimmedText.startsWith(C_STYLE_COPYRIGHT_LINE)
|
|
|
|
) {
|
|
|
|
trimmedText = trimmedText.split("\n").slice(1).join("\n");
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!trimmedText.startsWith(C_STYLE_COPYRIGHT_LINE)
|
|
|
|
) {
|
|
|
|
errors.push(
|
|
|
|
`${ERROR_MSG}${file} (incorrect line is '${
|
|
|
|
trimmedText.split("\n", 1)
|
|
|
|
}')`,
|
|
|
|
);
|
|
|
|
}
|
2023-01-13 07:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-07 00:14:38 +00:00
|
|
|
// check the main license file
|
|
|
|
const licenseText = Deno.readTextFileSync(ROOT_PATH + "/LICENSE.md");
|
|
|
|
if (
|
|
|
|
!licenseText.includes(`Copyright 2018-${copyrightYear} the Deno authors`)
|
|
|
|
) {
|
|
|
|
errors.push(`LICENSE.md has old copyright year`);
|
|
|
|
}
|
|
|
|
|
2023-03-16 02:39:40 +00:00
|
|
|
if (errors.length > 0) {
|
|
|
|
// show all the errors at the same time to prevent overlap with
|
|
|
|
// other running scripts that may be outputting
|
|
|
|
console.error(errors.join("\n"));
|
2024-05-21 22:50:59 +00:00
|
|
|
console.error(`Expected copyright:\n\`\`\`\n${COPYRIGHT_LINE}\n\`\`\``);
|
2023-03-21 16:31:34 +00:00
|
|
|
throw new Error(`Copyright checker had ${errors.length} errors.`);
|
2023-01-13 07:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:42:15 +00:00
|
|
|
if (import.meta.main) {
|
2023-01-13 07:51:32 +00:00
|
|
|
await checkCopyright();
|
|
|
|
}
|