@gjsify/fs 0.0.2 → 0.0.4

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/lib/cjs/sync.js CHANGED
@@ -1,70 +1,24 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var sync_exports = {};
29
- __export(sync_exports, {
30
- existsSync: () => import_utils.existsSync,
31
- lstatSync: () => import_fs_lstat.lstatSync,
32
- mkdirSync: () => mkdirSync,
33
- mkdtempSync: () => mkdtempSync,
34
- openSync: () => openSync,
35
- readFileSync: () => readFileSync,
36
- readdirSync: () => import_fs_readdir.readdirSync,
37
- realpathSync: () => import_fs_realpath.realpathSync,
38
- rmSync: () => rmSync,
39
- rmdirSync: () => rmdirSync,
40
- statSync: () => import_fs_stat.statSync,
41
- symlinkSync: () => import_fs_symlink.symlinkSync,
42
- unlinkSync: () => unlinkSync,
43
- watch: () => watch,
44
- writeFileSync: () => writeFileSync
45
- });
46
- module.exports = __toCommonJS(sync_exports);
47
- var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
48
- var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
49
- var import_utils = require("@gjsify/utils");
50
- var import_path = require("path");
51
- var import_fs_watcher = __toESM(require("./fs-watcher.js"), 1);
52
- var import_encoding = require("./encoding.js");
53
- var import_file_handle = require("./file-handle.js");
54
- var import_dirent = require("./dirent.js");
55
- var import_utils2 = require("./utils.js");
56
- var import_fs_realpath = require("@gjsify/deno_std/node/_fs/_fs_realpath");
57
- var import_fs_readdir = require("@gjsify/deno_std/node/_fs/_fs_readdir");
58
- var import_fs_symlink = require("@gjsify/deno_std/node/_fs/_fs_symlink");
59
- var import_fs_lstat = require("@gjsify/deno_std/node/_fs/_fs_lstat");
60
- var import_fs_stat = require("@gjsify/deno_std/node/_fs/_fs_stat");
1
+ import GLib from "@girs/glib-2.0";
2
+ import Gio from "@girs/gio-2.0";
3
+ import { existsSync } from "@gjsify/utils";
4
+ import { join } from "path";
5
+ import FSWatcher from "./fs-watcher.js";
6
+ import { getEncodingFromOptions, encodeUint8Array, decode } from "./encoding.js";
7
+ import { FileHandle } from "./file-handle.js";
8
+ import { Dirent } from "./dirent.js";
9
+ import { tempDirPath } from "./utils.js";
10
+ import { realpathSync } from "@gjsify/deno_std/node/_fs/_fs_realpath";
11
+ import { readdirSync } from "@gjsify/deno_std/node/_fs/_fs_readdir";
12
+ import { symlinkSync } from "@gjsify/deno_std/node/_fs/_fs_symlink";
13
+ import { lstatSync } from "@gjsify/deno_std/node/_fs/_fs_lstat";
14
+ import { statSync } from "@gjsify/deno_std/node/_fs/_fs_stat";
61
15
  function readFileSync(path, options = { encoding: null, flag: "r" }) {
62
- const file = import_gio_2.default.File.new_for_path(path);
16
+ const file = Gio.File.new_for_path(path);
63
17
  const [ok, data] = file.load_contents(null);
64
18
  if (!ok) {
65
19
  throw new Error("failed to read file");
66
20
  }
67
- return (0, import_encoding.encodeUint8Array)((0, import_encoding.getEncodingFromOptions)(options, "buffer"), data);
21
+ return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
68
22
  }
69
23
  function mkdirSync(path, options) {
70
24
  let recursive = false;
@@ -83,7 +37,7 @@ function mkdirSync(path, options) {
83
37
  if (typeof mode === "string") {
84
38
  throw new TypeError("mode as string is currently not supported!");
85
39
  }
86
- if (import_glib_2.default.mkdir_with_parents(path, mode) !== 0) {
40
+ if (GLib.mkdir_with_parents(path, mode) !== 0) {
87
41
  throw new Error(`failed to make ${path} directory`);
88
42
  }
89
43
  if (recursive) {
@@ -93,57 +47,57 @@ function mkdirSync(path, options) {
93
47
  }
94
48
  function rmdirSync(path, options) {
95
49
  const recursive = options?.recursive || false;
96
- const childFiles = (0, import_fs_readdir.readdirSync)(path, { withFileTypes: true });
50
+ const childFiles = readdirSync(path, { withFileTypes: true });
97
51
  if (!recursive && childFiles.length) {
98
52
  throw new Error("Dir is not empty!");
99
53
  }
100
54
  for (const childFile of childFiles) {
101
55
  if (childFile.isDirectory()) {
102
- rmdirSync((0, import_path.join)(path.toString(), childFile.name));
56
+ rmdirSync(join(path.toString(), childFile.name));
103
57
  } else if (childFile.isFile()) {
104
- rmSync((0, import_path.join)(path.toString(), childFile.name));
58
+ rmSync(join(path.toString(), childFile.name));
105
59
  }
106
60
  }
107
- const result = import_glib_2.default.rmdir(path.toString());
61
+ const result = GLib.rmdir(path.toString());
108
62
  if (result !== 0) {
109
63
  throw new Error(`Failed to remove ${path} directory`);
110
64
  }
111
65
  }
112
66
  function unlinkSync(path) {
113
- import_glib_2.default.unlink(path);
67
+ GLib.unlink(path);
114
68
  }
115
69
  function writeFileSync(path, data) {
116
- import_glib_2.default.file_set_contents(path, data);
70
+ GLib.file_set_contents(path, data);
117
71
  }
118
72
  function watch(filename, options, listener) {
119
- return new import_fs_watcher.default(filename, options, listener);
73
+ return new FSWatcher(filename, options, listener);
120
74
  }
121
75
  function openSync(path, flags, mode) {
122
- return new import_file_handle.FileHandle({ path, flags, mode });
76
+ return new FileHandle({ path, flags, mode });
123
77
  }
124
78
  function mkdtempSync(prefix, options) {
125
- const encoding = (0, import_encoding.getEncodingFromOptions)(options);
126
- const path = (0, import_utils2.tempDirPath)(prefix);
79
+ const encoding = getEncodingFromOptions(options);
80
+ const path = tempDirPath(prefix);
127
81
  mkdirSync(
128
82
  path,
129
83
  { recursive: false, mode: 511 }
130
84
  );
131
- return (0, import_encoding.decode)(path, encoding);
85
+ return decode(path, encoding);
132
86
  }
133
87
  function rmSync(path, options) {
134
- const file = import_gio_2.default.File.new_for_path(path.toString());
88
+ const file = Gio.File.new_for_path(path.toString());
135
89
  const recursive = options?.recursive || false;
136
- const dirent = new import_dirent.Dirent(path.toString());
90
+ const dirent = new Dirent(path.toString());
137
91
  if (dirent.isDirectory()) {
138
- const childFiles = (0, import_fs_readdir.readdirSync)(path, { withFileTypes: true });
92
+ const childFiles = readdirSync(path, { withFileTypes: true });
139
93
  if (!recursive && childFiles.length) {
140
94
  throw new Error("Dir is not empty!");
141
95
  }
142
96
  for (const childFile of childFiles) {
143
97
  if (childFile.isDirectory()) {
144
- rmdirSync((0, import_path.join)(path.toString(), childFile.name), options);
98
+ rmdirSync(join(path.toString(), childFile.name), options);
145
99
  } else if (childFile.isFile()) {
146
- rmSync((0, import_path.join)(path.toString(), childFile.name), options);
100
+ rmSync(join(path.toString(), childFile.name), options);
147
101
  }
148
102
  }
149
103
  }
@@ -153,3 +107,20 @@ function rmSync(path, options) {
153
107
  throw err;
154
108
  }
155
109
  }
110
+ export {
111
+ existsSync,
112
+ lstatSync,
113
+ mkdirSync,
114
+ mkdtempSync,
115
+ openSync,
116
+ readFileSync,
117
+ readdirSync,
118
+ realpathSync,
119
+ rmSync,
120
+ rmdirSync,
121
+ statSync,
122
+ symlinkSync,
123
+ unlinkSync,
124
+ watch,
125
+ writeFileSync
126
+ };
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var encoding_option_exports = {};
15
- module.exports = __toCommonJS(encoding_option_exports);
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var file_read_options_exports = {};
15
- module.exports = __toCommonJS(file_read_options_exports);
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var file_read_result_exports = {};
15
- module.exports = __toCommonJS(file_read_result_exports);
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var flag_and_open_mode_exports = {};
15
- module.exports = __toCommonJS(flag_and_open_mode_exports);
@@ -1,22 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
17
- __reExport(types_exports, require("./encoding-option.js"), module.exports);
18
- __reExport(types_exports, require("./file-read-options.js"), module.exports);
19
- __reExport(types_exports, require("./file-read-result.js"), module.exports);
20
- __reExport(types_exports, require("./flag-and-open-mode.js"), module.exports);
21
- __reExport(types_exports, require("./open-flags.js"), module.exports);
22
- __reExport(types_exports, require("./read-options.js"), module.exports);
1
+ export * from "./encoding-option.js";
2
+ export * from "./file-read-options.js";
3
+ export * from "./file-read-result.js";
4
+ export * from "./flag-and-open-mode.js";
5
+ export * from "./open-flags.js";
6
+ export * from "./read-options.js";
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var open_flags_exports = {};
15
- module.exports = __toCommonJS(open_flags_exports);
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var read_options_exports = {};
15
- module.exports = __toCommonJS(read_options_exports);
package/lib/cjs/utils.js CHANGED
@@ -1,27 +1,4 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var utils_exports = {};
19
- __export(utils_exports, {
20
- randomName: () => randomName,
21
- tempDirPath: () => tempDirPath
22
- });
23
- module.exports = __toCommonJS(utils_exports);
24
- var import_sync = require("./sync.js");
1
+ import { existsSync } from "./sync.js";
25
2
  const CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
26
3
  function randomName() {
27
4
  return [...Array(6)].map(
@@ -32,6 +9,10 @@ function tempDirPath(prefix) {
32
9
  let path;
33
10
  do {
34
11
  path = prefix + randomName();
35
- } while ((0, import_sync.existsSync)(path));
12
+ } while (existsSync(path));
36
13
  return path;
37
14
  }
15
+ export {
16
+ randomName,
17
+ tempDirPath
18
+ };
@@ -1,39 +1,15 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var write_stream_exports = {};
19
- __export(write_stream_exports, {
20
- WriteStream: () => WriteStream,
21
- createWriteStream: () => createWriteStream,
22
- toPathIfFileURL: () => toPathIfFileURL
23
- });
24
- module.exports = __toCommonJS(write_stream_exports);
25
- var import_stream = require("stream");
26
- var import_url = require("url");
27
- var import_callback = require("./callback.js");
1
+ import { Writable } from "stream";
2
+ import { fileURLToPath, URL } from "url";
3
+ import { open, write, close } from "./callback.js";
28
4
  const kIsPerformingIO = Symbol("kIsPerformingIO");
29
5
  const kIoDone = Symbol("kIoDone");
30
6
  function toPathIfFileURL(fileURLOrPath) {
31
- if (!(fileURLOrPath instanceof import_url.URL)) {
7
+ if (!(fileURLOrPath instanceof URL)) {
32
8
  return fileURLOrPath;
33
9
  }
34
- return (0, import_url.fileURLToPath)(fileURLOrPath);
10
+ return fileURLToPath(fileURLOrPath);
35
11
  }
36
- class WriteStream extends import_stream.Writable {
12
+ class WriteStream extends Writable {
37
13
  /**
38
14
  * Closes `writeStream`. Optionally accepts a
39
15
  * callback that will be executed once the `writeStream`is closed.
@@ -43,7 +19,7 @@ class WriteStream extends import_stream.Writable {
43
19
  if (!this.fd) {
44
20
  callback(err);
45
21
  } else {
46
- (0, import_callback.close)(this.fd, (er) => {
22
+ close(this.fd, (er) => {
47
23
  callback(er || err);
48
24
  });
49
25
  this.fd = null;
@@ -81,7 +57,7 @@ class WriteStream extends import_stream.Writable {
81
57
  }
82
58
  }
83
59
  _construct(callback) {
84
- (0, import_callback.open)(
60
+ open(
85
61
  this.path.toString(),
86
62
  this.flags,
87
63
  this.mode,
@@ -99,7 +75,7 @@ class WriteStream extends import_stream.Writable {
99
75
  }
100
76
  _write(data, _encoding, cb) {
101
77
  this[kIsPerformingIO] = true;
102
- (0, import_callback.write)(
78
+ write(
103
79
  this.fd,
104
80
  data,
105
81
  0,
@@ -133,3 +109,8 @@ class WriteStream extends import_stream.Writable {
133
109
  function createWriteStream(path, opts) {
134
110
  return new WriteStream(path, opts);
135
111
  }
112
+ export {
113
+ WriteStream,
114
+ createWriteStream,
115
+ toPathIfFileURL
116
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Node.js fs module for Gjs",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -46,18 +46,19 @@
46
46
  "fs"
47
47
  ],
48
48
  "devDependencies": {
49
- "@gjsify/cli": "^0.0.2",
50
- "@gjsify/unit": "^0.0.2",
51
- "@types/node": "^20.3.1",
52
- "typescript": "^5.1.3"
49
+ "@gjsify/cli": "^0.0.4",
50
+ "@gjsify/unit": "^0.0.4",
51
+ "@types/node": "^20.10.5",
52
+ "typescript": "^5.3.3"
53
53
  },
54
54
  "dependencies": {
55
- "@girs/glib-2.0": "2.76.1-3.1.0",
56
- "@gjsify/buffer": "^0.0.2",
57
- "@gjsify/deno_std": "^0.0.2",
58
- "@gjsify/gio-2.0": "^0.0.2",
59
- "@gjsify/stream": "^0.0.2",
60
- "@gjsify/url": "^0.0.2",
61
- "@gjsify/utils": "^0.0.2"
55
+ "@girs/glib-2.0": "2.78.0-3.2.6",
56
+ "@gjsify/buffer": "^0.0.4",
57
+ "@gjsify/deno_std": "^0.0.4",
58
+ "@gjsify/events": "^0.0.4",
59
+ "@gjsify/gio-2.0": "^0.0.4",
60
+ "@gjsify/stream": "^0.0.4",
61
+ "@gjsify/url": "^0.0.4",
62
+ "@gjsify/utils": "^0.0.4"
62
63
  }
63
64
  }