diff --git a/.licenserc.json b/.licenserc.json new file mode 100644 index 000000000000..26fd7542a08b --- /dev/null +++ b/.licenserc.json @@ -0,0 +1,22 @@ +{ + "**/*.{mjs,js,ts,rs}": "Copyright 2018-2025 the Deno authors. MIT license.", + "ignore": [ + "cli/testdata/", + "cli\\testdata\\", + "dotenv/testdata/", + "dotenv\\testdata\\", + "fs/testdata/", + "fs\\testdata\\", + "http/testdata/", + "http\\testdata\\", + "crypto/_wasm/target/", + "crypto\\_wasm\\target\\", + "crypto/_wasm/lib/", + "crypto\\_wasm\\lib\\", + ".git", + "docs/**", + "docs\\**", + "_tmp/", + "_tmp\\" + ] +} diff --git a/_tools/check_browser_compat.ts b/_tools/check_browser_compat.ts index 61e0fdca84da..46879693e094 100644 --- a/_tools/check_browser_compat.ts +++ b/_tools/check_browser_compat.ts @@ -6,13 +6,13 @@ * * Run using: deno run --allow-read --allow-run _tools/check_browser_compat.ts */ - +import LICENSE_JSON from "../.licenserc.json" with { type: "json" }; import { walk } from "../fs/walk.ts"; -import { COPYRIGHT } from "./check_licence.ts"; const ROOT = new URL("../", import.meta.url); const SKIP = [/(test|bench|\/_|\\_|testdata|version.ts)/]; const DECLARATION = "// This module is browser compatible."; +const COPYRIGHT = `// ${LICENSE_JSON["**/*.{mjs,js,ts,rs}"]}`; async function isBrowserCompatible(filePath: string): Promise { return (await new Deno.Command(Deno.execPath(), { diff --git a/_tools/check_licence.ts b/_tools/check_licence.ts deleted file mode 100644 index 2e9ea8ab2a5f..000000000000 --- a/_tools/check_licence.ts +++ /dev/null @@ -1,71 +0,0 @@ -// deno-lint-ignore-file no-console -// Copyright 2018-2025 the Deno authors. MIT license. -import { walk } from "../fs/walk.ts"; -import { globToRegExp } from "../path/glob_to_regexp.ts"; - -const EXTENSIONS = [".mjs", ".js", ".ts", ".rs"]; -const EXCLUDED_DIRS = [ - "**/cli/testdata", - "**/dotenv/testdata", - "**/fs/testdata", - "**/http/testdata", - "**/crypto/_wasm/target", - "**/crypto/_wasm/lib", - "**/.git", - "**/docs/**", - "**/_tmp", -]; - -const ROOT = new URL("../", import.meta.url); -const CHECK = Deno.args.includes("--check"); -const FIRST_YEAR = 2018; -const CURRENT_YEAR = new Date().getFullYear(); -const RX_COPYRIGHT = new RegExp( - `// Copyright ([0-9]{4})-([0-9]{4}) the Deno authors\\. MIT license\\.\n`, -); -export const COPYRIGHT = - `// Copyright ${FIRST_YEAR}-${CURRENT_YEAR} the Deno authors. MIT license.`; - -let failed = false; - -for await ( - const { path } of walk(ROOT, { - exts: EXTENSIONS, - skip: EXCLUDED_DIRS.map((path) => globToRegExp(path)), - includeDirs: false, - }) -) { - const content = await Deno.readTextFile(path); - const match = content.match(RX_COPYRIGHT); - - if (!match) { - if (CHECK) { - console.error(`Missing copyright header: ${path}`); - failed = true; - } else { - const contentWithCopyright = COPYRIGHT + "\n" + content; - await Deno.writeTextFile(path, contentWithCopyright); - console.log("Copyright header automatically added to " + path); - } - } else if ( - (match[1] && parseInt(match[1]) !== FIRST_YEAR) || - (match[2] && parseInt(match[2]) !== CURRENT_YEAR) - ) { - if (CHECK) { - console.error(`Incorrect copyright year: ${path}`); - failed = true; - } else { - const index = match.index ?? 0; - const contentWithoutCopyright = content.replace(match[0], ""); - const contentWithCopyright = contentWithoutCopyright.substring(0, index) + - COPYRIGHT + "\n" + contentWithoutCopyright.substring(index); - await Deno.writeTextFile(path, contentWithCopyright); - console.log("Copyright header automatically updated in " + path); - } - } -} - -if (failed) { - console.info(`Copyright header should be "${COPYRIGHT}"`); - Deno.exit(1); -} diff --git a/deno.json b/deno.json index f901c611cac3..b20bc046647b 100644 --- a/deno.json +++ b/deno.json @@ -12,8 +12,9 @@ "test:with-unsafe-proto": "deno test --unstable-http --unstable-webgpu --unstable-fs --unstable-unsafe-proto --doc --allow-all --parallel --coverage --trace-leaks --clean", "test:browser": "git grep --name-only \"This module is browser compatible.\" | grep -v deno.json | grep -v .github/workflows | grep -v _tools | grep -v encoding/README.md | grep -v media_types/vendor/update.ts | xargs deno check --config browser-compat.tsconfig.json", "test:node": "(cd _tools/node_test_runner && npm install) && node --import ./_tools/node_test_runner/register_deno_shim.mjs ./_tools/node_test_runner/run_test.mjs", + "fmt:licence-headers": " deno run --allow-read jsr:@kt3k/license-checker@3.3.1/main --quiet", + "lint:deprecations": "deno run --allow-read --allow-net --allow-env ./_tools/check_deprecation.ts", "test:bun": "(cd _tools/node_test_runner && bun install) && cp _tools/node_test_runner/tsconfig_for_bun.json ./tsconfig.json && bun test --require ./_tools/node_test_runner/register_deno_shim.mjs _tools/node_test_runner/run_test.mjs && rm tsconfig.json", - "fmt:licence-headers": "deno run --allow-read --allow-write ./_tools/check_licence.ts", "lint:circular": "deno run --allow-env --allow-read --allow-write --allow-net=deno.land,jsr.io ./_tools/check_circular_package_dependencies.ts", "lint:mod-exports": "deno run --allow-env --allow-read ./_tools/check_mod_exports.ts", "lint:tools-types": "deno check _tools/*.ts",