sliftutils 0.48.0 → 0.50.0

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.
@@ -15,9 +15,16 @@ const getPackageJsonPath = cache((directory: string): string | undefined => {
15
15
  const getMainPath = cache((directory: string): string | undefined => {
16
16
  let packageJsonPath = getPackageJsonPath(directory);
17
17
  if (!packageJsonPath) return undefined;
18
- let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
18
+ let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as {
19
+ main?: string;
20
+ exports?: {
21
+ "."?: {
22
+ require?: string;
23
+ };
24
+ };
25
+ };
19
26
  let dir = path.dirname(packageJsonPath);
20
- let mainName = packageJson.main;
27
+ let mainName = packageJson.exports?.["."]?.require || packageJson.main;
21
28
  if (!mainName) {
22
29
  if (fs.existsSync(path.resolve(dir, "index.js"))) {
23
30
  mainName = "index.js";
@@ -29,6 +36,7 @@ const getMainPath = cache((directory: string): string | undefined => {
29
36
  mainName = "index.js";
30
37
  }
31
38
  }
39
+ // Handle the negative value ESM exports thing.
32
40
  let mainPath = path.resolve(dir, mainName);
33
41
  return mainPath;
34
42
  });
@@ -62,14 +70,14 @@ export function wrapModule(module: NodeJS.Module): string {
62
70
  }
63
71
  }
64
72
 
65
- let isModuleMain: string | undefined;
73
+ let moduleMain: string | undefined;
66
74
  let dirname = path.dirname(module.filename);
67
75
  let packageJsonPath = getPackageJsonPath(dirname);
68
76
  if (packageJsonPath) {
69
77
  let mainPath = getMainPath(dirname);
70
78
  if (mainPath?.replaceAll("\\", "/") === module.filename.replaceAll("\\", "/")) {
71
79
  // Then we are the main of the module
72
- isModuleMain = path.dirname(packageJsonPath).replaceAll("\\", "/");
80
+ moduleMain = path.dirname(packageJsonPath).replaceAll("\\", "/");
73
81
  }
74
82
  }
75
83
 
@@ -77,7 +85,7 @@ export function wrapModule(module: NodeJS.Module): string {
77
85
  let objWrapped = `{`
78
86
  + ` id: ${JSON.stringify(module.id.replaceAll("\\", "/"))},`
79
87
  + ` filename: ${JSON.stringify(module.filename.replaceAll("\\", "/"))},`
80
- + ` isModuleMain: ${JSON.stringify(isModuleMain)},`
88
+ + ` isModuleMain: ${JSON.stringify(moduleMain)},`
81
89
  + ` paths: ${JSON.stringify(module.paths.map(p => p.replaceAll("\\", "/")))},`
82
90
  + ` moduleFields: ${JSON.stringify(moduleFields)},`
83
91
  + ` moduleFnc: ${wrapped}`
package/index.d.ts CHANGED
@@ -622,6 +622,32 @@ declare module "sliftutils/storage/FileFolderAPI" {
622
622
  /// <reference types="node" />
623
623
  /// <reference types="node" />
624
624
  import { IStorageRaw } from "./IStorage";
625
+ declare global {
626
+ interface Window {
627
+ showSaveFilePicker(config?: {
628
+ types: {
629
+ description: string;
630
+ accept: {
631
+ [mimeType: string]: string[];
632
+ };
633
+ }[];
634
+ }): Promise<FileSystemFileHandle>;
635
+ showDirectoryPicker(): Promise<FileSystemDirectoryHandle>;
636
+ showOpenFilePicker(config?: {
637
+ types: {
638
+ description: string;
639
+ accept: {
640
+ [mimeType: string]: string[];
641
+ };
642
+ }[];
643
+ }): Promise<FileSystemFileHandle[]>;
644
+ }
645
+ interface FileSystemDirectoryHandle {
646
+ requestPermission(config?: {
647
+ mode: "read" | "readwrite";
648
+ }): Promise<PermissionState>;
649
+ }
650
+ }
625
651
  type FileWrapper = {
626
652
  getFile(): Promise<{
627
653
  size: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "0.48.0",
3
+ "version": "0.50.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1,6 +1,32 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { IStorageRaw } from "./IStorage";
4
+ declare global {
5
+ interface Window {
6
+ showSaveFilePicker(config?: {
7
+ types: {
8
+ description: string;
9
+ accept: {
10
+ [mimeType: string]: string[];
11
+ };
12
+ }[];
13
+ }): Promise<FileSystemFileHandle>;
14
+ showDirectoryPicker(): Promise<FileSystemDirectoryHandle>;
15
+ showOpenFilePicker(config?: {
16
+ types: {
17
+ description: string;
18
+ accept: {
19
+ [mimeType: string]: string[];
20
+ };
21
+ }[];
22
+ }): Promise<FileSystemFileHandle[]>;
23
+ }
24
+ interface FileSystemDirectoryHandle {
25
+ requestPermission(config?: {
26
+ mode: "read" | "readwrite";
27
+ }): Promise<PermissionState>;
28
+ }
29
+ }
4
30
  type FileWrapper = {
5
31
  getFile(): Promise<{
6
32
  size: number;
@@ -10,20 +10,26 @@ import { getFileStorageIndexDB } from "./IndexedDBFileFolderAPI";
10
10
  import fs from "fs";
11
11
  import path from "path";
12
12
 
13
- interface Window {
14
- showSaveFilePicker(config?: {
15
- types: {
16
- description: string; accept: { [mimeType: string]: string[] }
17
- }[];
18
- }): Promise<FileSystemFileHandle>;
19
- showDirectoryPicker(): Promise<FileSystemDirectoryHandle>;
20
- showOpenFilePicker(config?: {
21
- types: {
22
- description: string; accept: { [mimeType: string]: string[] }
23
- }[];
24
- }): Promise<FileSystemFileHandle[]>;
13
+ declare global {
14
+ interface Window {
15
+ showSaveFilePicker(config?: {
16
+ types: {
17
+ description: string; accept: { [mimeType: string]: string[] }
18
+ }[];
19
+ }): Promise<FileSystemFileHandle>;
20
+ showDirectoryPicker(): Promise<FileSystemDirectoryHandle>;
21
+ showOpenFilePicker(config?: {
22
+ types: {
23
+ description: string; accept: { [mimeType: string]: string[] }
24
+ }[];
25
+ }): Promise<FileSystemFileHandle[]>;
26
+ }
27
+ interface FileSystemDirectoryHandle {
28
+ requestPermission(config?: { mode: "read" | "readwrite" }): Promise<PermissionState>;
29
+ }
25
30
  }
26
31
 
32
+
27
33
  // NOTE: IndexedDB is required for iOS, at least. We MIGHT want to make
28
34
  // this a user supported toggle too, so they can choose during runtime if they want it.
29
35
  // DO NOT enable this is isNode