feat: exclude _fresh dir from everything (#1788)

This commit is contained in:
Marvin Hagemeister
2023-09-18 15:05:59 +02:00
committed by GitHub
parent 795836ed29
commit ead634b0cf
6 changed files with 60 additions and 21 deletions
+3
View File
@@ -8,6 +8,9 @@
"check:types": "deno check **/*.ts && deno check **/*.tsx", "check:types": "deno check **/*.ts && deno check **/*.tsx",
"ok": "deno fmt --check && deno lint && deno task check:types && deno task test" "ok": "deno fmt --check && deno lint && deno task check:types && deno task test"
}, },
"exclude": [
"**/_fresh/*"
],
"importMap": "./.vscode/import_map.json", "importMap": "./.vscode/import_map.json",
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",
+1 -4
View File
@@ -564,11 +564,8 @@ const config = {
rules: { rules: {
tags: ["fresh", "recommended"], tags: ["fresh", "recommended"],
}, },
exclude: ["_fresh"],
},
fmt: {
exclude: ["_fresh"],
}, },
exclude: ["**/_fresh/*"],
imports: {} as Record<string, string>, imports: {} as Record<string, string>,
compilerOptions: { compilerOptions: {
jsx: "react-jsx", jsx: "react-jsx",
+1
View File
@@ -91,6 +91,7 @@ export interface DenoConfig {
fmt?: { fmt?: {
exclude?: string[]; exclude?: string[];
}; };
exclude?: string[];
compilerOptions?: { compilerOptions?: {
jsx?: string; jsx?: string;
jsxImportSource?: string; jsxImportSource?: string;
+2 -3
View File
@@ -92,11 +92,10 @@ Deno.test({
assert(json.tasks.preview, "Missing 'preview' task"); assert(json.tasks.preview, "Missing 'preview' task");
// Check lint settings // Check lint settings
assertEquals(json.lint.exclude, ["_fresh"]);
assertEquals(json.lint.rules.tags, ["fresh", "recommended"]); assertEquals(json.lint.rules.tags, ["fresh", "recommended"]);
// Check fmt settings // Check exclude settings
assertEquals(json.fmt.exclude, ["_fresh"]); assertEquals(json.exclude, ["**/_fresh/*"]);
}); });
await t.step("start up the server and access the root page", async () => { await t.step("start up the server and access the root page", async () => {
+26 -2
View File
@@ -76,8 +76,7 @@ Deno.test("fresh-update", async function fn(t) {
assertExists(json.tasks?.preview, "Missing 'preview' task"); assertExists(json.tasks?.preview, "Missing 'preview' task");
assertEquals(json.lint?.rules?.tags, ["fresh", "recommended"]); assertEquals(json.lint?.rules?.tags, ["fresh", "recommended"]);
assertEquals(json.lint?.exclude, ["_fresh"]); assertEquals(json.exclude, ["**/_fresh/*"]);
assertEquals(json.fmt?.exclude, ["_fresh"]);
}); });
const comment = "// This is a test comment"; const comment = "// This is a test comment";
@@ -223,3 +222,28 @@ Deno.test(
}); });
}, },
); );
Deno.test(
"fresh-update migrates old exclude to top level exclude",
async (t) => {
// Preparation
const tmpDirName = await initProject();
const denoJsonFile = path.join(tmpDirName, "deno.json");
const denoJson = JSON.parse(await Deno.readTextFile(denoJsonFile));
delete denoJson.exclude;
if (!denoJson.fmt) denoJson.fmt = {};
if (!denoJson.lint) denoJson.lint = {};
denoJson.fmt.exclude = ["_fresh"];
denoJson.lint.exclude = ["_fresh"];
await Deno.writeTextFile(denoJsonFile, JSON.stringify(denoJson, null, 2));
await executeUpdateCommand(t, tmpDirName);
const denoJsonAfter = JSON.parse(Deno.readTextFileSync(denoJsonFile));
assertEquals(denoJsonAfter.exclude, ["**/_fresh/*"]);
assertEquals(denoJsonAfter.lint, {
rules: { tags: ["fresh", "recommended"] },
});
assertEquals(denoJsonAfter.fmt, undefined);
},
);
+27 -12
View File
@@ -87,22 +87,37 @@ if (!denoJson.lint.rules.tags.includes("fresh")) {
if (!denoJson.lint.rules.tags.includes("recommended")) { if (!denoJson.lint.rules.tags.includes("recommended")) {
denoJson.lint.rules.tags.push("recommended"); denoJson.lint.rules.tags.push("recommended");
} }
if (!denoJson.lint.exclude) {
denoJson.lint.exclude = []; // Remove old _fresh exclude where we added it separately to
} // "lint" and "fmt"
if (!denoJson.lint.exclude.includes("_fresh")) { const fmtExcludeIdx = denoJson?.fmt?.exclude?.indexOf("_fresh");
denoJson.lint.exclude.push("_fresh"); if (fmtExcludeIdx > -1) {
denoJson.fmt.exclude.splice(fmtExcludeIdx, 1);
if (denoJson.fmt.exclude.length === 0) {
delete denoJson.fmt.exclude;
}
if (Object.keys(denoJson.fmt).length === 0) {
delete denoJson.fmt;
}
} }
// Exclude _fresh dir from linting const lintExcludeIdx = denoJson?.lint?.exclude?.indexOf("_fresh");
if (!denoJson.fmt) { if (lintExcludeIdx > -1) {
denoJson.fmt = {}; denoJson.lint.exclude.splice(lintExcludeIdx, 1);
if (denoJson.lint.exclude.length === 0) {
delete denoJson.lint.exclude;
}
if (Object.keys(denoJson.lint).length === 0) {
delete denoJson.lint;
}
} }
if (!denoJson.fmt.exclude) {
denoJson.fmt.exclude = []; // Exclude _fresh dir from everything
if (!denoJson.exclude) {
denoJson.exclude = [];
} }
if (!denoJson.fmt.exclude.includes("_fresh")) { if (!denoJson.exclude.includes("**/_fresh/*")) {
denoJson.fmt.exclude.push("_fresh"); denoJson.exclude.push("**/_fresh/*");
} }
if (!denoJson.tasks) { if (!denoJson.tasks) {