polystore 0.12.0 → 0.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polystore",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "A small compatibility layer for many popular KV stores like localStorage, Redis, FileSystem, etc.",
5
5
  "homepage": "https://polystore.dev/",
6
6
  "repository": "https://github.com/franciscop/polystore.git",
@@ -12,11 +12,15 @@ export default class File {
12
12
 
13
13
  // Run this once on launch; import the FS module and reset the file
14
14
  this.promise = (async () => {
15
- const fsp = await import("node:fs/promises");
15
+ const [fsp, path] = await Promise.all([
16
+ import("node:fs/promises"),
17
+ import("node:path"),
18
+ ]);
16
19
 
17
20
  // We want to make sure the file already exists, so attempt to
18
- // create it (but not OVERWRITE it, that's why the x flag) and
19
- // it fails if it already exists
21
+ // create the folders and the file (but not OVERWRITE it, that's why the x flag)
22
+ // It fails if it already exists, hence the catch case
23
+ await fsp.mkdir(path.dirname(this.file), { recursive: true });
20
24
  await fsp.writeFile(this.file, "{}", { flag: "wx" }).catch((err) => {
21
25
  if (err.code !== "EEXIST") throw err;
22
26
  });