@fedify/init
Advanced tools
+74
-11
@@ -8,2 +8,4 @@ import { merge } from "../utils.js"; | ||
| import { uniq } from "es-toolkit"; | ||
| import { execFileSync } from "node:child_process"; | ||
| import { getLogger } from "@logtape/logtape"; | ||
| import { realpathSync } from "node:fs"; | ||
@@ -14,2 +16,8 @@ import { join, relative } from "node:path"; | ||
| //#region src/action/configs.ts | ||
| const logger = getLogger([ | ||
| "fedify", | ||
| "init", | ||
| "action", | ||
| "configs" | ||
| ]); | ||
| /** | ||
@@ -22,14 +30,69 @@ * Loads Deno configuration object with compiler options, unstable features, and tasks. | ||
| */ | ||
| const loadDenoConfig = (data) => ({ | ||
| path: "deno.json", | ||
| data: { | ||
| ...pick(["compilerOptions", "tasks"], data.initializer), | ||
| unstable: getUnstable(data), | ||
| nodeModulesDir: "auto", | ||
| imports: joinDepsReg("deno")(getDependencies(data)), | ||
| lint: { plugins: ["jsr:@fedify/lint"] }, | ||
| ...data.testMode ? { links: getLinks(data) } : {} | ||
| const loadDenoConfig = (data) => { | ||
| const unstable = getUnstable(data); | ||
| return { | ||
| path: "deno.json", | ||
| data: { | ||
| ...pick(["compilerOptions", "tasks"], data.initializer), | ||
| ...unstable.length > 0 ? { unstable } : {}, | ||
| nodeModulesDir: "auto", | ||
| imports: joinDepsReg("deno")(getDependencies(data)), | ||
| lint: { plugins: ["jsr:@fedify/lint"] }, | ||
| ...data.testMode ? { links: getLinks(data) } : {} | ||
| } | ||
| }; | ||
| }; | ||
| const getUnstable = ({ kv: { denoUnstable: kv = [] }, mq: { denoUnstable: mq = [] } }) => pipe(needsUnstableTemporal() ? ["temporal"] : [], concat(kv), concat(mq), toArray, uniq); | ||
| const TEMPORAL_STABLE_FROM = [ | ||
| 2, | ||
| 7, | ||
| 0 | ||
| ]; | ||
| const needsUnstableTemporal = () => { | ||
| const version = getInstalledDenoVersion(); | ||
| if (version == null) return true; | ||
| return compareVersions(version, TEMPORAL_STABLE_FROM) < 0; | ||
| }; | ||
| const getInstalledDenoVersion = () => { | ||
| const deno = getDenoVersionFromRuntime(); | ||
| if (deno != null) return deno; | ||
| try { | ||
| const output = execFileSync("deno", ["--version"], { | ||
| encoding: "utf8", | ||
| stdio: [ | ||
| "ignore", | ||
| "pipe", | ||
| "ignore" | ||
| ] | ||
| }); | ||
| const version = output.match(/^deno\s+(\d+)\.(\d+)\.(\d+)/m); | ||
| if (version == null) return null; | ||
| return [ | ||
| Number(version[1]), | ||
| Number(version[2]), | ||
| Number(version[3]) | ||
| ]; | ||
| } catch (error) { | ||
| logger.debug("Failed to get Deno version by executing `deno --version`: {error}", { error }); | ||
| return null; | ||
| } | ||
| }); | ||
| const getUnstable = ({ kv: { denoUnstable: kv = [] }, mq: { denoUnstable: mq = [] } }) => pipe(["temporal"], concat(kv), concat(mq), toArray, uniq); | ||
| }; | ||
| const getDenoVersionFromRuntime = () => { | ||
| const deno = globalThis.Deno?.version?.deno; | ||
| if (deno == null) return null; | ||
| const version = deno.match(/^(\d+)\.(\d+)\.(\d+)/); | ||
| if (version == null) return null; | ||
| return [ | ||
| Number(version[1]), | ||
| Number(version[2]), | ||
| Number(version[3]) | ||
| ]; | ||
| }; | ||
| const compareVersions = (a, b) => { | ||
| for (let i = 0; i < a.length; i++) { | ||
| if (a[i] < b[i]) return -1; | ||
| if (a[i] > b[i]) return 1; | ||
| } | ||
| return 0; | ||
| }; | ||
| const getLinks = ({ kv, mq, initializer, dir }) => pipe({ "@fedify/fedify": "" }, merge(initializer.dependencies), merge(kv.dependencies), merge(mq.dependencies), keys, filter((dep) => dep.includes("@fedify/")), map((dep) => dep.replace("@fedify/", "")), map((dep) => join(PACKAGES_PATH, dep)), map((absolutePath) => realpathSync(absolutePath)), map((realAbsolutePath) => relative(realpathSync(dir), realAbsolutePath)), toArray); | ||
@@ -36,0 +99,0 @@ /** |
+1
-1
| //#region deno.json | ||
| var name = "@fedify/init"; | ||
| var version = "2.1.0-dev.408+5c3c9d78"; | ||
| var version = "2.1.0-dev.411+13731841"; | ||
| var license = "MIT"; | ||
@@ -5,0 +5,0 @@ var exports = "./src/mod.ts"; |
+1
-1
| { | ||
| "name": "@fedify/init", | ||
| "version": "2.1.0-dev.408+5c3c9d78", | ||
| "version": "2.1.0-dev.411+13731841", | ||
| "description": "Project initializer for Fedify", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
105843
1.46%2572
2.51%