@ark/fs 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/fs.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  export { rmSync } from "node:fs";
2
2
  export declare const ensureDir: (path: string) => string;
3
3
  export declare const readFile: (path: string) => string;
4
- export declare const writeFile: (path: string, contents: string) => void;
5
- export declare const readJson: (path: string) => any;
4
+ export declare const writeFile: (path: string, contents: string) => string;
5
+ export declare const rewriteFile: (path: string, transform: (contents: string) => string) => string;
6
+ export declare const readJson: (path: string) => Record<string, unknown>;
6
7
  export declare const writeJson: (path: string, data: object) => void;
8
+ export type JsonTransformer = (data: object) => object;
9
+ export declare const rewriteJson: (path: string, transform: (data: object) => object) => void;
7
10
  export declare const rmRf: (target: string) => void;
8
11
  export declare const cpR: (from: string, to: string) => void;
9
- export type JsonTransformer = (data: object) => object;
10
- export declare const rewriteJson: (path: string, transform: JsonTransformer) => void;
11
12
  export type WalkOptions = {
12
13
  ignoreDirsMatching?: RegExp;
13
14
  ignoreFilesMatching?: RegExp;
package/out/fs.js CHANGED
@@ -16,12 +16,16 @@ export const ensureDir = (path) => {
16
16
  return path;
17
17
  };
18
18
  export const readFile = (path) => readFileSync(path).toString();
19
- export const writeFile = (path, contents) => writeFileSync(path, contents);
19
+ export const writeFile = (path, contents) => {
20
+ writeFileSync(path, contents);
21
+ return contents;
22
+ };
23
+ export const rewriteFile = (path, transform) => writeFile(path, transform(readFile(path)));
20
24
  export const readJson = (path) => JSON.parse(readFileSync(path, { encoding: "utf8" }));
21
25
  export const writeJson = (path, data) => writeFileSync(path, `${JSON.stringify(data, null, 4)}\n`);
26
+ export const rewriteJson = (path, transform) => writeJson(path, transform(readJson(path)));
22
27
  export const rmRf = (target) => rmSync(target, { recursive: true, force: true });
23
28
  export const cpR = (from, to) => cpSync(from, to, { recursive: true, force: true });
24
- export const rewriteJson = (path, transform) => writeJson(path, transform(readJson(path)));
25
29
  export const walkPaths = (dir, options = {}) => readdirSync(dir).reduce((paths, item) => {
26
30
  const path = join(dir, item);
27
31
  const isDir = lstatSync(path).isDirectory();
@@ -61,7 +61,7 @@ export declare const getFramesFromError: (error: Error) => string[];
61
61
  * "line": "1",
62
62
  * "char": "12",
63
63
  * "method": "Object.<anonymous>",
64
- * "file": "/Users/balupton/some-project/calling-file.js"
64
+ * "file": "/Users/balupton/some-project/calling-file.ts"
65
65
  * }
66
66
  * ```
67
67
  */
@@ -9,12 +9,14 @@ export const getFramesFromError = (error) => {
9
9
  // https://github.com/winstonjs/winston/issues/401#issuecomment-61913086
10
10
  try {
11
11
  stack = error.stack;
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
13
  }
13
14
  catch (error1) {
14
15
  try {
15
16
  // @ts-expect-error https://github.com/winstonjs/winston/issues/401#issuecomment-61913086
16
17
  const previous = err.__previous__ || err.__previous;
17
18
  stack = previous && previous.stack;
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
20
  }
19
21
  catch (error2) {
20
22
  stack = null;
@@ -152,7 +154,7 @@ const getLocationFromError = (error, offset = {
152
154
  * "line": "1",
153
155
  * "char": "12",
154
156
  * "method": "Object.<anonymous>",
155
- * "file": "/Users/balupton/some-project/calling-file.js"
157
+ * "file": "/Users/balupton/some-project/calling-file.ts"
156
158
  * }
157
159
  * ```
158
160
  */
package/out/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./caller.js";
2
- export * from "./fs.js";
3
- export * from "./shell.js";
1
+ export * from "./caller.ts";
2
+ export * from "./fs.ts";
3
+ export * from "./shell.ts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/fs",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "author": {
5
5
  "name": "David Blass",
6
6
  "email": "david@arktype.io",
@@ -15,8 +15,10 @@
15
15
  "main": "./out/index.js",
16
16
  "types": "./out/index.d.ts",
17
17
  "exports": {
18
- ".": "./out/index.js",
19
- "./internal/*": "./out/*"
18
+ ".": {
19
+ "ark-ts": "./index.ts",
20
+ "default": "./out/index.js"
21
+ }
20
22
  },
21
23
  "files": [
22
24
  "out"
@@ -25,6 +27,6 @@
25
27
  "access": "public"
26
28
  },
27
29
  "scripts": {
28
- "build": "tsx ../repo/build.ts"
30
+ "build": "ts ../repo/build.ts"
29
31
  }
30
32
  }