@inlang/core
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -7,6 +7,6 @@ import { EnvironmentFunctions } from "../config/index.js"; | ||
* testing inlang depends on files in the local file system, | ||
* you can copy the directory into the environment by providing | ||
* you can copy directories into the environment by providing | ||
* the `copyDirectory` argument. | ||
* | ||
* @param copyDirectory - if defined, copies the directory into the environment | ||
* @param copyDirectory - if defined, copies directories (paths) into the environment | ||
*/ | ||
@@ -16,5 +16,4 @@ export declare function mockEnvironment(args: { | ||
fs: EnvironmentFunctions["$fs"]; | ||
path: string; | ||
paths: string[]; | ||
}; | ||
}): Promise<EnvironmentFunctions>; | ||
export declare function normalizePath(path: string): string; |
import { initialize$import } from "../config/index.js"; | ||
import { fs as memfs } from "memfs"; | ||
import dedent from "dedent"; | ||
/** | ||
@@ -8,6 +9,6 @@ * Initializes a mock environment. | ||
* testing inlang depends on files in the local file system, | ||
* you can copy the directory into the environment by providing | ||
* you can copy directories into the environment by providing | ||
* the `copyDirectory` argument. | ||
* | ||
* @param copyDirectory - if defined, copies the directory into the environment | ||
* @param copyDirectory - if defined, copies directories (paths) into the environment | ||
*/ | ||
@@ -25,4 +26,5 @@ export async function mockEnvironment(args) { | ||
if (args.copyDirectory) { | ||
const { fs, path } = args.copyDirectory; | ||
await copyDirectory({ copyFrom: fs, copyTo: $fs, path }); | ||
for (const path of args.copyDirectory.paths) { | ||
await copyDirectory({ copyFrom: args.copyDirectory.fs, copyTo: $fs, path }); | ||
} | ||
} | ||
@@ -37,2 +39,14 @@ return env; | ||
async function copyDirectory(args) { | ||
try { | ||
await args.copyFrom.readdir(args.path); | ||
} | ||
catch { | ||
throw new Error(dedent ` | ||
The directory specified in \`copyDirectory.path\` does not exist. | ||
Solution: Make sure that the \`copyDirectory.path\` is relative to the current working directory. | ||
Context: The path is relative to the current working directory, not the file that calls \`mockEnvironment\`. | ||
`); | ||
} | ||
// create directory | ||
@@ -59,6 +73,3 @@ await args.copyTo.mkdir(args.path, { recursive: true }); | ||
*/ | ||
export function normalizePath(path) { | ||
if (typeof path !== "string") { | ||
throw new TypeError("expected path to be a string"); | ||
} | ||
function normalizePath(path) { | ||
if (path === "\\" || path === "/") | ||
@@ -65,0 +76,0 @@ return "/"; |
{ | ||
"name": "@inlang/core", | ||
"type": "module", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"publishConfig": { | ||
@@ -6,0 +6,0 @@ "access": "public" |
81289
2253