@logtape/logtape 0.4.2-dev.45 → 0.4.2-dev.46

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.
@@ -1,20 +1,25 @@
1
1
  import * as dntShim from "./_dnt.shims.js";
2
- import fs from "node:fs";
2
+ // @ts-ignore: a trick to avoid module resolution error on non-Node.js environ
3
+ import fsMod from "./fs.js";
3
4
  import { webDriver } from "./filesink.web.js";
4
5
  import { getFileSink as getBaseFileSink, getRotatingFileSink as getBaseRotatingFileSink, } from "./sink.js";
6
+ // @ts-ignore: a trick to avoid module resolution error on non-Node.js environ
7
+ const fs = fsMod;
5
8
  /**
6
9
  * A Node.js-specific file sink driver.
7
10
  */
8
- export const nodeDriver = {
9
- openSync(path) {
10
- return fs.openSync(path, "a");
11
- },
12
- writeSync: fs.writeSync,
13
- flushSync: fs.fsyncSync,
14
- closeSync: fs.closeSync,
15
- statSync: fs.statSync,
16
- renameSync: fs.renameSync,
17
- };
11
+ export const nodeDriver = fs == null
12
+ ? webDriver
13
+ : {
14
+ openSync(path) {
15
+ return fs.openSync(path, "a");
16
+ },
17
+ writeSync: fs.writeSync,
18
+ flushSync: fs.fsyncSync,
19
+ closeSync: fs.closeSync,
20
+ statSync: fs.statSync,
21
+ renameSync: fs.renameSync,
22
+ };
18
23
  /**
19
24
  * Get a file sink.
20
25
  *
package/esm/fs.js ADDED
@@ -0,0 +1,12 @@
1
+ let fs;
2
+ try {
3
+ fs = await import("node:fs");
4
+ } catch (e) {
5
+ if (e instanceof TypeError) {
6
+ fs = null;
7
+ } else {
8
+ throw e;
9
+ }
10
+ }
11
+
12
+ export default fs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "0.4.2-dev.45+79dd6b65",
3
+ "version": "0.4.2-dev.46+f7baedd4",
4
4
  "description": "Simple logging library with zero dependencies for Deno/Node.js/Bun/browsers",
5
5
  "keywords": [
6
6
  "logging",
@@ -28,22 +28,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getRotatingFileSink = exports.getFileSink = exports.nodeDriver = void 0;
30
30
  const dntShim = __importStar(require("./_dnt.shims.js"));
31
- const node_fs_1 = __importDefault(require("node:fs"));
31
+ // @ts-ignore: a trick to avoid module resolution error on non-Node.js environ
32
+ const fs_js_1 = __importDefault(require("./fs.js"));
32
33
  const filesink_web_js_1 = require("./filesink.web.js");
33
34
  const sink_js_1 = require("./sink.js");
35
+ // @ts-ignore: a trick to avoid module resolution error on non-Node.js environ
36
+ const fs = fs_js_1.default;
34
37
  /**
35
38
  * A Node.js-specific file sink driver.
36
39
  */
37
- exports.nodeDriver = {
38
- openSync(path) {
39
- return node_fs_1.default.openSync(path, "a");
40
- },
41
- writeSync: node_fs_1.default.writeSync,
42
- flushSync: node_fs_1.default.fsyncSync,
43
- closeSync: node_fs_1.default.closeSync,
44
- statSync: node_fs_1.default.statSync,
45
- renameSync: node_fs_1.default.renameSync,
46
- };
40
+ exports.nodeDriver = fs == null
41
+ ? filesink_web_js_1.webDriver
42
+ : {
43
+ openSync(path) {
44
+ return fs.openSync(path, "a");
45
+ },
46
+ writeSync: fs.writeSync,
47
+ flushSync: fs.fsyncSync,
48
+ closeSync: fs.closeSync,
49
+ statSync: fs.statSync,
50
+ renameSync: fs.renameSync,
51
+ };
47
52
  /**
48
53
  * Get a file sink.
49
54
  *
package/script/fs.js ADDED
@@ -0,0 +1,8 @@
1
+ let fs;
2
+ try {
3
+ fs = require("node:fs");
4
+ } catch (_) {
5
+ fs = null;
6
+ }
7
+
8
+ module.exports = fs;
@@ -3,7 +3,7 @@ import { type FileSinkOptions, type RotatingFileSinkDriver, type RotatingFileSin
3
3
  /**
4
4
  * A Node.js-specific file sink driver.
5
5
  */
6
- export declare const nodeDriver: RotatingFileSinkDriver<number>;
6
+ export declare const nodeDriver: RotatingFileSinkDriver<number | void>;
7
7
  /**
8
8
  * Get a file sink.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.node.d.ts","sourceRoot":"","sources":["../src/filesink.node.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,KAAK,eAAe,EAGpB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACV,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,sBAAsB,CAAC,MAAM,CASrD,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,IAAI,GAAG,UAAU,CAKnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,uBAA4B,GACpC,IAAI,GAAG,UAAU,CAKnB"}
1
+ {"version":3,"file":"filesink.node.d.ts","sourceRoot":"","sources":["../src/filesink.node.ts"],"names":[],"mappings":";AAKA,OAAO,EACL,KAAK,eAAe,EAGpB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACV,MAAM,WAAW,CAAC;AAKnB;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,sBAAsB,CAAC,MAAM,GAAG,IAAI,CAW1D,CAAC;AAEJ;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,IAAI,GAAG,UAAU,CAKnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,uBAA4B,GACpC,IAAI,GAAG,UAAU,CAKnB"}
package/types/fs.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ export * from "node:fs";
3
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.js"],"names":[],"mappings":""}