@tauri-apps/plugin-fs 2.0.0-alpha.2 → 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,8 +1,7 @@
1
- var f$1=Object.defineProperty;var g$1=(a,b)=>{for(var c in b)f$1(a,c,{get:b[c],enumerable:!0});};var e=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$1=(a,b,c)=>(e(a,b,"read from private field"),c?c.call(a):b.get(a)),i$1=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j$1=(a,b,c,d)=>(e(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
1
+ 'use strict';
2
2
 
3
- var T$1={};g$1(T$1,{Channel:()=>i,PluginListener:()=>o,addPluginListener:()=>l$1,convertFileSrc:()=>v$1,invoke:()=>u$1,transformCallback:()=>_$1});function _$1(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}var r,i=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$1(this,r,()=>{});this.id=_$1(n=>{h$1(this,r).call(this,n);});}set onmessage(n){j$1(this,r,n);}get onmessage(){return h$1(this,r)}toJSON(){return `__CHANNEL__:${this.id}`}};r=new WeakMap;var o=class{constructor(n,s,t){this.plugin=n,this.event=s,this.channelId=t;}async unregister(){return u$1(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l$1(e,n,s){let t=new i;return t.onmessage=s,u$1(`plugin:${e}|register_listener`,{event:n,handler:t}).then(()=>new o(e,n,t.id))}async function u$1(e,n={},s){return window.__TAURI_INTERNALS__.invoke(e,n,s)}function v$1(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}
4
-
5
- var U={};g$1(U,{BaseDirectory:()=>t,appCacheDir:()=>p,appConfigDir:()=>s,appDataDir:()=>u,appLocalDataDir:()=>c,appLogDir:()=>w,audioDir:()=>a,basename:()=>H,cacheDir:()=>l,configDir:()=>g,dataDir:()=>d,delimiter:()=>E,desktopDir:()=>m,dirname:()=>z,documentDir:()=>y,downloadDir:()=>h,executableDir:()=>f,extname:()=>F,fontDir:()=>P,homeDir:()=>_,isAbsolute:()=>S,join:()=>j,localDataDir:()=>v,normalize:()=>N,pictureDir:()=>A,publicDir:()=>D,resolve:()=>I,resolveResource:()=>C,resourceDir:()=>b,runtimeDir:()=>L,sep:()=>k,tempDir:()=>x,templateDir:()=>R,videoDir:()=>T});var t=(r=>(r[r.Audio=1]="Audio",r[r.Cache=2]="Cache",r[r.Config=3]="Config",r[r.Data=4]="Data",r[r.LocalData=5]="LocalData",r[r.Document=6]="Document",r[r.Download=7]="Download",r[r.Picture=8]="Picture",r[r.Public=9]="Public",r[r.Video=10]="Video",r[r.Resource=11]="Resource",r[r.Temp=12]="Temp",r[r.AppConfig=13]="AppConfig",r[r.AppData=14]="AppData",r[r.AppLocalData=15]="AppLocalData",r[r.AppCache=16]="AppCache",r[r.AppLog=17]="AppLog",r[r.Desktop=18]="Desktop",r[r.Executable=19]="Executable",r[r.Font=20]="Font",r[r.Home=21]="Home",r[r.Runtime=22]="Runtime",r[r.Template=23]="Template",r))(t||{});async function s(){return u$1("plugin:path|resolve_directory",{directory:13})}async function u(){return u$1("plugin:path|resolve_directory",{directory:14})}async function c(){return u$1("plugin:path|resolve_directory",{directory:15})}async function p(){return u$1("plugin:path|resolve_directory",{directory:16})}async function a(){return u$1("plugin:path|resolve_directory",{directory:1})}async function l(){return u$1("plugin:path|resolve_directory",{directory:2})}async function g(){return u$1("plugin:path|resolve_directory",{directory:3})}async function d(){return u$1("plugin:path|resolve_directory",{directory:4})}async function m(){return u$1("plugin:path|resolve_directory",{directory:18})}async function y(){return u$1("plugin:path|resolve_directory",{directory:6})}async function h(){return u$1("plugin:path|resolve_directory",{directory:7})}async function f(){return u$1("plugin:path|resolve_directory",{directory:19})}async function P(){return u$1("plugin:path|resolve_directory",{directory:20})}async function _(){return u$1("plugin:path|resolve_directory",{directory:21})}async function v(){return u$1("plugin:path|resolve_directory",{directory:5})}async function A(){return u$1("plugin:path|resolve_directory",{directory:8})}async function D(){return u$1("plugin:path|resolve_directory",{directory:9})}async function b(){return u$1("plugin:path|resolve_directory",{directory:11})}async function C(i){return u$1("plugin:path|resolve_directory",{directory:11,path:i})}async function L(){return u$1("plugin:path|resolve_directory",{directory:22})}async function R(){return u$1("plugin:path|resolve_directory",{directory:23})}async function T(){return u$1("plugin:path|resolve_directory",{directory:10})}async function w(){return u$1("plugin:path|resolve_directory",{directory:17})}async function x(i){return u$1("plugin:path|resolve_directory",{directory:12})}function k(){return window.__TAURI_INTERNALS__.plugins.path.sep}function E(){return window.__TAURI_INTERNALS__.plugins.path.delimiter}async function I(...i){return u$1("plugin:path|resolve",{paths:i})}async function N(i){return u$1("plugin:path|normalize",{path:i})}async function j(...i){return u$1("plugin:path|join",{paths:i})}async function z(i){return u$1("plugin:path|dirname",{path:i})}async function F(i){return u$1("plugin:path|extname",{path:i})}async function H(i,e){return u$1("plugin:path|basename",{path:i,ext:e})}async function S(i){return u$1("plugin:path|isAbsolute",{path:i})}
3
+ var path = require('@tauri-apps/api/path');
4
+ var primitives = require('@tauri-apps/api/primitives');
6
5
 
7
6
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
8
7
  // SPDX-License-Identifier: Apache-2.0
@@ -61,7 +60,7 @@ var U={};g$1(U,{BaseDirectory:()=>t,appCacheDir:()=>p,appConfigDir:()=>s,appData
61
60
  * @since 2.0.0
62
61
  */
63
62
  async function readTextFile(filePath, options = {}) {
64
- return await u$1("plugin:fs|read_text_file", {
63
+ return await primitives.invoke("plugin:fs|read_text_file", {
65
64
  path: filePath,
66
65
  options,
67
66
  });
@@ -78,7 +77,7 @@ async function readTextFile(filePath, options = {}) {
78
77
  * @since 2.0.0
79
78
  */
80
79
  async function readBinaryFile(filePath, options = {}) {
81
- const arr = await u$1("plugin:fs|read_file", {
80
+ const arr = await primitives.invoke("plugin:fs|read_file", {
82
81
  path: filePath,
83
82
  options,
84
83
  });
@@ -108,12 +107,12 @@ async function writeTextFile(path, contents, options) {
108
107
  file.contents = path.contents;
109
108
  }
110
109
  if (typeof contents === "string") {
111
- file.contents = contents !== null && contents !== void 0 ? contents : "";
110
+ file.contents = contents ?? "";
112
111
  }
113
112
  else {
114
113
  fileOptions = contents;
115
114
  }
116
- return await u$1("plugin:fs|write_file", {
115
+ return await primitives.invoke("plugin:fs|write_file", {
117
116
  path: file.path,
118
117
  contents: Array.from(new TextEncoder().encode(file.contents)),
119
118
  options: fileOptions,
@@ -147,9 +146,9 @@ async function writeBinaryFile(path, contents, options) {
147
146
  }
148
147
  else if (typeof path === "string") {
149
148
  // @ts-expect-error in this case `contents` is always a BinaryFileContents
150
- file.contents = contents !== null && contents !== void 0 ? contents : [];
149
+ file.contents = contents ?? [];
151
150
  }
152
- return await u$1("plugin:fs|write_file", {
151
+ return await primitives.invoke("plugin:fs|write_file", {
153
152
  path: file.path,
154
153
  contents: Array.from(file.contents instanceof ArrayBuffer
155
154
  ? new Uint8Array(file.contents)
@@ -178,7 +177,7 @@ async function writeBinaryFile(path, contents, options) {
178
177
  * @since 2.0.0
179
178
  */
180
179
  async function readDir(dir, options = {}) {
181
- return await u$1("plugin:fs|read_dir", {
180
+ return await primitives.invoke("plugin:fs|read_dir", {
182
181
  path: dir,
183
182
  options,
184
183
  });
@@ -199,7 +198,7 @@ async function readDir(dir, options = {}) {
199
198
  * @since 2.0.0
200
199
  */
201
200
  async function createDir(dir, options = {}) {
202
- return await u$1("plugin:fs|create_dir", {
201
+ return await primitives.invoke("plugin:fs|create_dir", {
203
202
  path: dir,
204
203
  options,
205
204
  });
@@ -219,7 +218,7 @@ async function createDir(dir, options = {}) {
219
218
  * @since 2.0.0
220
219
  */
221
220
  async function removeDir(dir, options = {}) {
222
- return await u$1("plugin:fs|remove_dir", {
221
+ return await primitives.invoke("plugin:fs|remove_dir", {
223
222
  path: dir,
224
223
  options,
225
224
  });
@@ -238,7 +237,7 @@ async function removeDir(dir, options = {}) {
238
237
  * @since 2.0.0
239
238
  */
240
239
  async function copyFile(source, destination, options = {}) {
241
- return await u$1("plugin:fs|copy_file", {
240
+ return await primitives.invoke("plugin:fs|copy_file", {
242
241
  source,
243
242
  destination,
244
243
  options,
@@ -258,7 +257,7 @@ async function copyFile(source, destination, options = {}) {
258
257
  * @since 2.0.0
259
258
  */
260
259
  async function removeFile(file, options = {}) {
261
- return await u$1("plugin:fs|remove_file", {
260
+ return await primitives.invoke("plugin:fs|remove_file", {
262
261
  path: file,
263
262
  options,
264
263
  });
@@ -277,7 +276,7 @@ async function removeFile(file, options = {}) {
277
276
  * @since 2.0.0
278
277
  */
279
278
  async function renameFile(oldPath, newPath, options = {}) {
280
- return await u$1("plugin:fs|rename_file", {
279
+ return await primitives.invoke("plugin:fs|rename_file", {
281
280
  oldPath,
282
281
  newPath,
283
282
  options,
@@ -294,8 +293,8 @@ async function renameFile(oldPath, newPath, options = {}) {
294
293
  *
295
294
  * @since 2.0.0
296
295
  */
297
- async function exists(path) {
298
- return await u$1("plugin:fs|exists", { path });
296
+ async function exists(path, options = {}) {
297
+ return await primitives.invoke("plugin:fs|exists", { path, options });
299
298
  }
300
299
  /**
301
300
  * Returns the metadata for the given path.
@@ -303,7 +302,7 @@ async function exists(path) {
303
302
  * @since 2.0.0
304
303
  */
305
304
  async function metadata(path) {
306
- return await u$1("plugin:fs|metadata", {
305
+ return await primitives.invoke("plugin:fs|metadata", {
307
306
  path,
308
307
  }).then((metadata) => {
309
308
  const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
@@ -316,5 +315,24 @@ async function metadata(path) {
316
315
  });
317
316
  }
318
317
 
319
- export { t as BaseDirectory, t as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
320
- //# 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.2",
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.9"
24
+ "@tauri-apps/api": "2.0.0-alpha.12"
29
25
  },
30
26
  "scripts": {
31
27
  "build": "rollup -c"