chore(core package): re-organize files
This commit is contained in:
parent
5b728b8144
commit
95006a7471
16 changed files with 28 additions and 34 deletions
|
|
@ -5,8 +5,7 @@ import { spawn } from "node:child_process";
|
||||||
import { OPERATION_TIMEOUT, SSH_KEYS_DIR } from "../../../core/constants";
|
import { OPERATION_TIMEOUT, SSH_KEYS_DIR } from "../../../core/constants";
|
||||||
import { cryptoUtils } from "../../../utils/crypto";
|
import { cryptoUtils } from "../../../utils/crypto";
|
||||||
import { toMessage } from "../../../utils/errors";
|
import { toMessage } from "../../../utils/errors";
|
||||||
import { logger } from "@zerobyte/core/node";
|
import { logger, FILE_MODES, writeFileWithMode } from "@zerobyte/core/node";
|
||||||
import { FILE_MODES, writeFileWithMode } from "@zerobyte/core/utils";
|
|
||||||
import { getMountForPath } from "../../../utils/mountinfo";
|
import { getMountForPath } from "../../../utils/mountinfo";
|
||||||
import { withTimeout } from "../../../utils/timeout";
|
import { withTimeout } from "../../../utils/timeout";
|
||||||
import type { VolumeBackend } from "../backend";
|
import type { VolumeBackend } from "../backend";
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"test": "vitest run",
|
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"deploy": "bun run build && wrangler deploy",
|
"deploy": "bun run build && wrangler deploy",
|
||||||
"cf-typegen": "wrangler types"
|
"cf-typegen": "wrangler types"
|
||||||
|
|
@ -52,7 +51,6 @@
|
||||||
"typescript": "^5.7.2",
|
"typescript": "^5.7.2",
|
||||||
"vite": "^8.0.8",
|
"vite": "^8.0.8",
|
||||||
"vite-plugin-killer-instincts": "^1.0.0",
|
"vite-plugin-killer-instincts": "^1.0.0",
|
||||||
"vite-tsconfig-paths": "^5.1.4",
|
|
||||||
"vitest": "^3.0.5",
|
"vitest": "^3.0.5",
|
||||||
"wrangler": "^4.82.1"
|
"wrangler": "^4.82.1"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import { devtools } from "@tanstack/devtools-vite";
|
import { devtools } from "@tanstack/devtools-vite";
|
||||||
import tsconfigPaths from "vite-tsconfig-paths";
|
|
||||||
|
|
||||||
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
||||||
import { cloudflare } from "@cloudflare/vite-plugin";
|
import { cloudflare } from "@cloudflare/vite-plugin";
|
||||||
|
|
@ -17,12 +16,14 @@ const config = defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
mdx(MdxConfig),
|
mdx(MdxConfig),
|
||||||
devtools(),
|
devtools(),
|
||||||
tsconfigPaths({ projects: ["./tsconfig.json"] }),
|
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
cloudflare({ viteEnvironment: { name: "ssr" } }),
|
cloudflare({ viteEnvironment: { name: "ssr" } }),
|
||||||
tanstackStart(),
|
tanstackStart(),
|
||||||
viteReact(),
|
viteReact(),
|
||||||
],
|
],
|
||||||
|
resolve: {
|
||||||
|
tsconfigPaths: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,17 @@
|
||||||
import { describe, expect, test } from "vitest";
|
import { describe, expect, test } from "vitest";
|
||||||
import { safeExec, safeSpawn } from "@zerobyte/core/node";
|
import { safeExec, safeSpawn } from "../spawn";
|
||||||
|
|
||||||
describe("safeExec", () => {
|
describe("safeExec", () => {
|
||||||
|
test("falls back to the process error message when stderr is empty", async () => {
|
||||||
|
const result = await safeExec({
|
||||||
|
command: process.execPath,
|
||||||
|
args: ["-e", "process.stdout.write('a'.repeat(2 * 1024 * 1024))"],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(1);
|
||||||
|
expect(result.stderr).toContain("stdout maxBuffer length exceeded");
|
||||||
|
});
|
||||||
|
|
||||||
describe("successful commands", () => {
|
describe("successful commands", () => {
|
||||||
test("returns exitCode 0 and output for successful command", async () => {
|
test("returns exitCode 0 and output for successful command", async () => {
|
||||||
const result = await safeExec({ command: "echo", args: ["hello"] });
|
const result = await safeExec({ command: "echo", args: ["hello"] });
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
export { safeSpawn, safeExec } from "../utils/spawn.js";
|
export { safeSpawn, safeExec } from "./spawn.js";
|
||||||
export type { SafeSpawnParams, SafeSpawnParamsLines, SafeSpawnParamsRaw, SpawnResult } from "../utils/spawn.js";
|
export type { SafeSpawnParams, SafeSpawnParamsLines, SafeSpawnParamsRaw, SpawnResult } from "./spawn.js";
|
||||||
export { logger } from "../utils/logger.js";
|
export { logger } from "./logger.js";
|
||||||
export { sanitizeSensitiveData } from "../utils/sanitize.js";
|
export { sanitizeSensitiveData } from "../utils/sanitize.js";
|
||||||
|
export { FILE_MODES, writeFileWithMode } from "./fs.js";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { createConsola, type ConsolaReporter } from "consola";
|
import { createConsola, type ConsolaReporter } from "consola";
|
||||||
import { formatWithOptions } from "node:util";
|
import { formatWithOptions } from "node:util";
|
||||||
import { sanitizeSensitiveData } from "./sanitize";
|
import { sanitizeSensitiveData } from "../utils/sanitize";
|
||||||
|
|
||||||
type LogLevel = "debug" | "info" | "warn" | "error";
|
type LogLevel = "debug" | "info" | "warn" | "error";
|
||||||
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||||
import { Effect } from "effect";
|
import { Effect } from "effect";
|
||||||
import * as cleanupModule from "../../helpers/cleanup-temporary-keys";
|
import * as cleanupModule from "../../helpers/cleanup-temporary-keys";
|
||||||
import * as spawnModule from "../../../utils/spawn";
|
import * as spawnModule from "../../../node/spawn";
|
||||||
import { ResticError } from "../../error";
|
import { ResticError } from "../../error";
|
||||||
import { backup } from "../backup";
|
import { backup } from "../backup";
|
||||||
import type { ResticDeps } from "../../types";
|
import type { ResticDeps } from "../../types";
|
||||||
import type { SafeSpawnParams, SpawnResult } from "../../../utils/spawn";
|
import type { SafeSpawnParams, SpawnResult } from "../../../node/spawn";
|
||||||
|
|
||||||
const mockDeps: ResticDeps = {
|
const mockDeps: ResticDeps = {
|
||||||
resolveSecret: async (s) => s,
|
resolveSecret: async (s) => s,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||||
import * as cleanupModule from "../../helpers/cleanup-temporary-keys";
|
import * as cleanupModule from "../../helpers/cleanup-temporary-keys";
|
||||||
import * as spawnModule from "../../../utils/spawn";
|
import * as spawnModule from "../../../node/spawn";
|
||||||
import { ls } from "../ls";
|
import { ls } from "../ls";
|
||||||
import type { ResticDeps } from "../../types";
|
import type { ResticDeps } from "../../types";
|
||||||
import type { SafeSpawnParams } from "../../../utils/spawn";
|
import type { SafeSpawnParams } from "../../../node/spawn";
|
||||||
|
|
||||||
const mockDeps: ResticDeps = {
|
const mockDeps: ResticDeps = {
|
||||||
resolveSecret: async (s) => s,
|
resolveSecret: async (s) => s,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||||
import * as cleanupModule from "../../helpers/cleanup-temporary-keys";
|
import * as cleanupModule from "../../helpers/cleanup-temporary-keys";
|
||||||
import * as spawnModule from "../../../utils/spawn";
|
import * as spawnModule from "../../../node/spawn";
|
||||||
import { ResticError } from "../../error";
|
import { ResticError } from "../../error";
|
||||||
import { restore } from "../restore";
|
import { restore } from "../restore";
|
||||||
import type { ResticDeps } from "../../types";
|
import type { ResticDeps } from "../../types";
|
||||||
import type { SafeSpawnParams, SpawnResult } from "../../../utils/spawn";
|
import type { SafeSpawnParams, SpawnResult } from "../../../node/spawn";
|
||||||
|
|
||||||
const mockDeps: ResticDeps = {
|
const mockDeps: ResticDeps = {
|
||||||
resolveSecret: async (s) => s,
|
resolveSecret: async (s) => s,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import path from "node:path";
|
||||||
import type { ResticDeps, ResticEnv } from "../types";
|
import type { ResticDeps, ResticEnv } from "../types";
|
||||||
import type { RepositoryConfig } from "../schemas";
|
import type { RepositoryConfig } from "../schemas";
|
||||||
import { logger } from "../../node";
|
import { logger } from "../../node";
|
||||||
import { FILE_MODES, writeFileWithMode } from "../../utils/fs.js";
|
import { FILE_MODES, writeFileWithMode } from "../../node/fs.js";
|
||||||
|
|
||||||
export const buildEnv = async (
|
export const buildEnv = async (
|
||||||
config: RepositoryConfig,
|
config: RepositoryConfig,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
import { describe, expect, test } from "vitest";
|
|
||||||
import { safeExec } from "../spawn";
|
|
||||||
|
|
||||||
describe("safeExec", () => {
|
|
||||||
test("falls back to the process error message when stderr is empty", async () => {
|
|
||||||
const result = await safeExec({
|
|
||||||
command: process.execPath,
|
|
||||||
args: ["-e", "process.stdout.write('a'.repeat(2 * 1024 * 1024))"],
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
|
||||||
expect(result.stderr).toContain("stdout maxBuffer length exceeded");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -2,4 +2,3 @@ export { safeJsonParse } from "./json.js";
|
||||||
export { toErrorDetails, toMessage } from "./errors.js";
|
export { toErrorDetails, toMessage } from "./errors.js";
|
||||||
export { isPathWithin, normalizeAbsolutePath } from "./path.js";
|
export { isPathWithin, normalizeAbsolutePath } from "./path.js";
|
||||||
export { findCommonAncestor } from "./common-ancestor.js";
|
export { findCommonAncestor } from "./common-ancestor.js";
|
||||||
export { FILE_MODES, writeFileWithMode } from "./fs.js";
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
|
||||||
vi.mock(import("../src/utils/logger.ts"), () => ({
|
vi.mock(import("../src/node/logger.ts"), () => ({
|
||||||
logger: {
|
logger: {
|
||||||
debug: () => {},
|
debug: () => {},
|
||||||
info: () => {},
|
info: () => {},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue