@tauri-apps/plugin-fs 2.0.0-alpha.3 → 2.0.0-alpha.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/README.md CHANGED
@@ -69,6 +69,22 @@ await metadata("/path/to/file");
69
69
 
70
70
  PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
71
71
 
72
+ ## Partners
73
+
74
+ <table>
75
+ <tbody>
76
+ <tr>
77
+ <td align="center" valign="middle">
78
+ <a href="https://crabnebula.dev" target="_blank">
79
+ <img src="https://github.com/tauri-apps/plugins-workspace/raw/v2/.github/sponsors/crabnebula.svg" alt="CrabNebula" width="283">
80
+ </a>
81
+ </td>
82
+ </tr>
83
+ </tbody>
84
+ </table>
85
+
86
+ For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri).
87
+
72
88
  ## License
73
89
 
74
90
  Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
@@ -1,84 +1,7 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol */
16
-
17
-
18
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
19
- var e = new Error(message);
20
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
21
- };
1
+ 'use strict';
22
2
 
23
- /**
24
- * Sends a message to the backend.
25
- * @example
26
- * ```typescript
27
- * import { invoke } from '@tauri-apps/api/primitives';
28
- * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
29
- * ```
30
- *
31
- * @param cmd The command name.
32
- * @param args The optional arguments to pass to the command.
33
- * @param options The request options.
34
- * @return A promise resolving or rejecting to the backend response.
35
- *
36
- * @since 1.0.0
37
- */
38
- async function invoke(cmd, args = {}, options) {
39
- return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
40
- }
41
-
42
- // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
43
- // SPDX-License-Identifier: Apache-2.0
44
- // SPDX-License-Identifier: MIT
45
- /**
46
- * The path module provides utilities for working with file and directory paths.
47
- *
48
- * This package is also accessible with `window.__TAURI__.path` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
49
- *
50
- * It is recommended to allowlist only the APIs you use for optimal bundle size and security.
51
- * @module
52
- */
53
- /**
54
- * @since 2.0.0
55
- */
56
- var BaseDirectory;
57
- (function (BaseDirectory) {
58
- BaseDirectory[BaseDirectory["Audio"] = 1] = "Audio";
59
- BaseDirectory[BaseDirectory["Cache"] = 2] = "Cache";
60
- BaseDirectory[BaseDirectory["Config"] = 3] = "Config";
61
- BaseDirectory[BaseDirectory["Data"] = 4] = "Data";
62
- BaseDirectory[BaseDirectory["LocalData"] = 5] = "LocalData";
63
- BaseDirectory[BaseDirectory["Document"] = 6] = "Document";
64
- BaseDirectory[BaseDirectory["Download"] = 7] = "Download";
65
- BaseDirectory[BaseDirectory["Picture"] = 8] = "Picture";
66
- BaseDirectory[BaseDirectory["Public"] = 9] = "Public";
67
- BaseDirectory[BaseDirectory["Video"] = 10] = "Video";
68
- BaseDirectory[BaseDirectory["Resource"] = 11] = "Resource";
69
- BaseDirectory[BaseDirectory["Temp"] = 12] = "Temp";
70
- BaseDirectory[BaseDirectory["AppConfig"] = 13] = "AppConfig";
71
- BaseDirectory[BaseDirectory["AppData"] = 14] = "AppData";
72
- BaseDirectory[BaseDirectory["AppLocalData"] = 15] = "AppLocalData";
73
- BaseDirectory[BaseDirectory["AppCache"] = 16] = "AppCache";
74
- BaseDirectory[BaseDirectory["AppLog"] = 17] = "AppLog";
75
- BaseDirectory[BaseDirectory["Desktop"] = 18] = "Desktop";
76
- BaseDirectory[BaseDirectory["Executable"] = 19] = "Executable";
77
- BaseDirectory[BaseDirectory["Font"] = 20] = "Font";
78
- BaseDirectory[BaseDirectory["Home"] = 21] = "Home";
79
- BaseDirectory[BaseDirectory["Runtime"] = 22] = "Runtime";
80
- BaseDirectory[BaseDirectory["Template"] = 23] = "Template";
81
- })(BaseDirectory || (BaseDirectory = {}));
3
+ var path = require('@tauri-apps/api/path');
4
+ var primitives = require('@tauri-apps/api/primitives');
82
5
 
83
6
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
84
7
  // SPDX-License-Identifier: Apache-2.0
@@ -137,7 +60,7 @@ var BaseDirectory;
137
60
  * @since 2.0.0
138
61
  */
139
62
  async function readTextFile(filePath, options = {}) {
140
- return await invoke("plugin:fs|read_text_file", {
63
+ return await primitives.invoke("plugin:fs|read_text_file", {
141
64
  path: filePath,
142
65
  options,
143
66
  });
@@ -154,7 +77,7 @@ async function readTextFile(filePath, options = {}) {
154
77
  * @since 2.0.0
155
78
  */
156
79
  async function readBinaryFile(filePath, options = {}) {
157
- const arr = await invoke("plugin:fs|read_file", {
80
+ const arr = await primitives.invoke("plugin:fs|read_file", {
158
81
  path: filePath,
159
82
  options,
160
83
  });
@@ -184,12 +107,12 @@ async function writeTextFile(path, contents, options) {
184
107
  file.contents = path.contents;
185
108
  }
186
109
  if (typeof contents === "string") {
187
- file.contents = contents !== null && contents !== void 0 ? contents : "";
110
+ file.contents = contents ?? "";
188
111
  }
189
112
  else {
190
113
  fileOptions = contents;
191
114
  }
192
- return await invoke("plugin:fs|write_file", {
115
+ return await primitives.invoke("plugin:fs|write_file", {
193
116
  path: file.path,
194
117
  contents: Array.from(new TextEncoder().encode(file.contents)),
195
118
  options: fileOptions,
@@ -223,9 +146,9 @@ async function writeBinaryFile(path, contents, options) {
223
146
  }
224
147
  else if (typeof path === "string") {
225
148
  // @ts-expect-error in this case `contents` is always a BinaryFileContents
226
- file.contents = contents !== null && contents !== void 0 ? contents : [];
149
+ file.contents = contents ?? [];
227
150
  }
228
- return await invoke("plugin:fs|write_file", {
151
+ return await primitives.invoke("plugin:fs|write_file", {
229
152
  path: file.path,
230
153
  contents: Array.from(file.contents instanceof ArrayBuffer
231
154
  ? new Uint8Array(file.contents)
@@ -254,7 +177,7 @@ async function writeBinaryFile(path, contents, options) {
254
177
  * @since 2.0.0
255
178
  */
256
179
  async function readDir(dir, options = {}) {
257
- return await invoke("plugin:fs|read_dir", {
180
+ return await primitives.invoke("plugin:fs|read_dir", {
258
181
  path: dir,
259
182
  options,
260
183
  });
@@ -275,7 +198,7 @@ async function readDir(dir, options = {}) {
275
198
  * @since 2.0.0
276
199
  */
277
200
  async function createDir(dir, options = {}) {
278
- return await invoke("plugin:fs|create_dir", {
201
+ return await primitives.invoke("plugin:fs|create_dir", {
279
202
  path: dir,
280
203
  options,
281
204
  });
@@ -295,7 +218,7 @@ async function createDir(dir, options = {}) {
295
218
  * @since 2.0.0
296
219
  */
297
220
  async function removeDir(dir, options = {}) {
298
- return await invoke("plugin:fs|remove_dir", {
221
+ return await primitives.invoke("plugin:fs|remove_dir", {
299
222
  path: dir,
300
223
  options,
301
224
  });
@@ -314,7 +237,7 @@ async function removeDir(dir, options = {}) {
314
237
  * @since 2.0.0
315
238
  */
316
239
  async function copyFile(source, destination, options = {}) {
317
- return await invoke("plugin:fs|copy_file", {
240
+ return await primitives.invoke("plugin:fs|copy_file", {
318
241
  source,
319
242
  destination,
320
243
  options,
@@ -334,7 +257,7 @@ async function copyFile(source, destination, options = {}) {
334
257
  * @since 2.0.0
335
258
  */
336
259
  async function removeFile(file, options = {}) {
337
- return await invoke("plugin:fs|remove_file", {
260
+ return await primitives.invoke("plugin:fs|remove_file", {
338
261
  path: file,
339
262
  options,
340
263
  });
@@ -353,7 +276,7 @@ async function removeFile(file, options = {}) {
353
276
  * @since 2.0.0
354
277
  */
355
278
  async function renameFile(oldPath, newPath, options = {}) {
356
- return await invoke("plugin:fs|rename_file", {
279
+ return await primitives.invoke("plugin:fs|rename_file", {
357
280
  oldPath,
358
281
  newPath,
359
282
  options,
@@ -370,8 +293,8 @@ async function renameFile(oldPath, newPath, options = {}) {
370
293
  *
371
294
  * @since 2.0.0
372
295
  */
373
- async function exists(path) {
374
- return await invoke("plugin:fs|exists", { path });
296
+ async function exists(path, options = {}) {
297
+ return await primitives.invoke("plugin:fs|exists", { path, options });
375
298
  }
376
299
  /**
377
300
  * Returns the metadata for the given path.
@@ -379,7 +302,7 @@ async function exists(path) {
379
302
  * @since 2.0.0
380
303
  */
381
304
  async function metadata(path) {
382
- return await invoke("plugin:fs|metadata", {
305
+ return await primitives.invoke("plugin:fs|metadata", {
383
306
  path,
384
307
  }).then((metadata) => {
385
308
  const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
@@ -392,5 +315,24 @@ async function metadata(path) {
392
315
  });
393
316
  }
394
317
 
395
- export { BaseDirectory, BaseDirectory as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
396
- //# sourceMappingURL=index.min.js.map
318
+ Object.defineProperty(exports, 'BaseDirectory', {
319
+ enumerable: true,
320
+ get: function () { return path.BaseDirectory; }
321
+ });
322
+ Object.defineProperty(exports, 'Dir', {
323
+ enumerable: true,
324
+ get: function () { return path.BaseDirectory; }
325
+ });
326
+ exports.copyFile = copyFile;
327
+ exports.createDir = createDir;
328
+ exports.exists = exists;
329
+ exports.metadata = metadata;
330
+ exports.readBinaryFile = readBinaryFile;
331
+ exports.readDir = readDir;
332
+ exports.readTextFile = readTextFile;
333
+ exports.removeDir = removeDir;
334
+ exports.removeFile = removeFile;
335
+ exports.renameFile = renameFile;
336
+ exports.writeBinaryFile = writeBinaryFile;
337
+ exports.writeFile = writeTextFile;
338
+ exports.writeTextFile = writeTextFile;
@@ -360,7 +360,7 @@ declare function renameFile(oldPath: string, newPath: string, options?: FsOption
360
360
  *
361
361
  * @since 2.0.0
362
362
  */
363
- declare function exists(path: string): Promise<boolean>;
363
+ declare function exists(path: string, options?: FsOptions): Promise<boolean>;
364
364
  /**
365
365
  * Returns the metadata for the given path.
366
366
  *
@@ -105,7 +105,7 @@ async function writeTextFile(path, contents, options) {
105
105
  file.contents = path.contents;
106
106
  }
107
107
  if (typeof contents === "string") {
108
- file.contents = contents !== null && contents !== void 0 ? contents : "";
108
+ file.contents = contents ?? "";
109
109
  }
110
110
  else {
111
111
  fileOptions = contents;
@@ -144,7 +144,7 @@ async function writeBinaryFile(path, contents, options) {
144
144
  }
145
145
  else if (typeof path === "string") {
146
146
  // @ts-expect-error in this case `contents` is always a BinaryFileContents
147
- file.contents = contents !== null && contents !== void 0 ? contents : [];
147
+ file.contents = contents ?? [];
148
148
  }
149
149
  return await invoke("plugin:fs|write_file", {
150
150
  path: file.path,
@@ -291,8 +291,8 @@ async function renameFile(oldPath, newPath, options = {}) {
291
291
  *
292
292
  * @since 2.0.0
293
293
  */
294
- async function exists(path) {
295
- return await invoke("plugin:fs|exists", { path });
294
+ async function exists(path, options = {}) {
295
+ return await invoke("plugin:fs|exists", { path, options });
296
296
  }
297
297
  /**
298
298
  * Returns the metadata for the given path.
@@ -314,4 +314,3 @@ async function metadata(path) {
314
314
  }
315
315
 
316
316
  export { copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
317
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,31 +1,27 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-fs",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.4",
4
4
  "description": "Access the file system.",
5
5
  "license": "MIT or APACHE-2.0",
6
6
  "authors": [
7
7
  "Tauri Programme within The Commons Conservancy"
8
8
  ],
9
9
  "type": "module",
10
- "browser": "dist-js/index.min.js",
11
- "module": "dist-js/index.mjs",
12
- "types": "dist-js/index.d.ts",
10
+ "types": "./dist-js/index.d.ts",
11
+ "main": "./dist-js/index.cjs",
12
+ "module": "./dist-js/index.js",
13
13
  "exports": {
14
- "import": "./dist-js/index.mjs",
15
14
  "types": "./dist-js/index.d.ts",
16
- "browser": "./dist-js/index.min.js"
15
+ "import": "./dist-js/index.js",
16
+ "require": "./dist-js/index.cjs"
17
17
  },
18
18
  "files": [
19
19
  "dist-js",
20
- "!dist-js/**/*.map",
21
20
  "README.md",
22
21
  "LICENSE"
23
22
  ],
24
- "devDependencies": {
25
- "tslib": "^2.4.1"
26
- },
27
23
  "dependencies": {
28
- "@tauri-apps/api": "2.0.0-alpha.11"
24
+ "@tauri-apps/api": "2.0.0-alpha.12"
29
25
  },
30
26
  "scripts": {
31
27
  "build": "rollup -c"