@expofp/utils 3.0.0-alpha.10 → 3.0.0-alpha.12
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/dist/index.d.ts +12 -12
- package/dist/index.js +12 -12
- package/dist/lib/{buildZipArchive.d.ts → build-zip-archive.d.ts} +1 -1
- package/dist/lib/{deepFreeze.d.ts → deep-freeze.d.ts} +1 -1
- package/dist/lib/{niceFetch.d.ts → fetch-with-retry.d.ts} +2 -2
- package/dist/lib/{niceFetch.js → fetch-with-retry.js} +3 -3
- package/dist/lib/{importFsPromises.d.ts → import-fs-promises.d.ts} +1 -1
- package/dist/lib/{importFsPromises.js → import-fs-promises.js} +1 -1
- package/dist/lib/{importJsonModule.d.ts → import-json.d.ts} +3 -3
- package/dist/lib/{importJsonModule.js → import-json.js} +6 -6
- package/dist/lib/{importNodeModule.d.ts → import-node-module.d.ts} +1 -1
- package/dist/lib/import-runtime-json.d.ts +2 -0
- package/dist/lib/{importRuntimeJsonModule.js → import-runtime-json.js} +4 -4
- package/dist/lib/{loadScript.d.ts → load-script.d.ts} +1 -1
- package/dist/lib/{loadScript.js → load-script.js} +2 -2
- package/dist/lib/{makeLocalPath.d.ts → make-local-path.d.ts} +1 -1
- package/dist/lib/{makeLocalPath.js → make-local-path.js} +8 -8
- package/dist/lib/{readFileFromUrl.d.ts → read-file-from-url.d.ts} +1 -1
- package/dist/lib/{readFileFromUrl.js → read-file-from-url.js} +3 -3
- package/dist/lib/safe-slugify.d.ts +7 -0
- package/dist/lib/{slugifyFilesystemUnique.js → safe-slugify.js} +1 -1
- package/dist/lib/short-hash.d.ts +2 -0
- package/dist/lib/{sha256Base62Truncated.js → short-hash.js} +1 -1
- package/package.json +2 -1
- package/dist/lib/importRuntimeJsonModule.d.ts +0 -2
- package/dist/lib/sha256Base62Truncated.d.ts +0 -2
- package/dist/lib/slugifyFilesystemUnique.d.ts +0 -7
- /package/dist/lib/{buildZipArchive.js → build-zip-archive.js} +0 -0
- /package/dist/lib/{deepFreeze.js → deep-freeze.js} +0 -0
- /package/dist/lib/{importNodeModule.js → import-node-module.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/build-zip-archive.js';
|
|
2
2
|
export * from './lib/clone.js';
|
|
3
|
-
export * from './lib/
|
|
4
|
-
export * from './lib/
|
|
5
|
-
export * from './lib/
|
|
6
|
-
export * from './lib/
|
|
7
|
-
export * from './lib/
|
|
8
|
-
export * from './lib/
|
|
9
|
-
export * from './lib/
|
|
10
|
-
export * from './lib/
|
|
11
|
-
export * from './lib/
|
|
12
|
-
export * from './lib/
|
|
13
|
-
export * from './lib/
|
|
3
|
+
export * from './lib/deep-freeze.js';
|
|
4
|
+
export * from './lib/fetch-with-retry.js';
|
|
5
|
+
export * from './lib/import-fs-promises.js';
|
|
6
|
+
export * from './lib/import-json.js';
|
|
7
|
+
export * from './lib/import-node-module.js';
|
|
8
|
+
export * from './lib/import-runtime-json.js';
|
|
9
|
+
export * from './lib/load-script.js';
|
|
10
|
+
export * from './lib/make-local-path.js';
|
|
11
|
+
export * from './lib/read-file-from-url.js';
|
|
12
|
+
export * from './lib/safe-slugify.js';
|
|
13
|
+
export * from './lib/short-hash.js';
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/build-zip-archive.js';
|
|
2
2
|
export * from './lib/clone.js';
|
|
3
|
-
export * from './lib/
|
|
4
|
-
export * from './lib/
|
|
5
|
-
export * from './lib/
|
|
6
|
-
export * from './lib/
|
|
7
|
-
export * from './lib/
|
|
8
|
-
export * from './lib/
|
|
9
|
-
export * from './lib/
|
|
10
|
-
export * from './lib/
|
|
11
|
-
export * from './lib/
|
|
12
|
-
export * from './lib/
|
|
13
|
-
export * from './lib/
|
|
3
|
+
export * from './lib/deep-freeze.js';
|
|
4
|
+
export * from './lib/fetch-with-retry.js';
|
|
5
|
+
export * from './lib/import-fs-promises.js';
|
|
6
|
+
export * from './lib/import-json.js';
|
|
7
|
+
export * from './lib/import-node-module.js';
|
|
8
|
+
export * from './lib/import-runtime-json.js';
|
|
9
|
+
export * from './lib/load-script.js';
|
|
10
|
+
export * from './lib/make-local-path.js';
|
|
11
|
+
export * from './lib/read-file-from-url.js';
|
|
12
|
+
export * from './lib/safe-slugify.js';
|
|
13
|
+
export * from './lib/short-hash.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function deepFreeze<T>(obj: T): T;
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=deep-freeze.d.ts.map
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* In Node.js environments, it uses the `fetch-retry` library to add retry capabilities.
|
|
5
5
|
* Node.js are more prone to transient network errors, so retries can help improve reliability.
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
8
|
-
//# sourceMappingURL=
|
|
7
|
+
export declare const fetchWithRetry: (...args: Parameters<typeof window.fetch>) => ReturnType<typeof window.fetch>;
|
|
8
|
+
//# sourceMappingURL=fetch-with-retry.d.ts.map
|
|
@@ -6,15 +6,15 @@ let fn;
|
|
|
6
6
|
* In Node.js environments, it uses the `fetch-retry` library to add retry capabilities.
|
|
7
7
|
* Node.js are more prone to transient network errors, so retries can help improve reliability.
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const fetchWithRetry = async function fetch(...args) {
|
|
10
10
|
if (!fn) {
|
|
11
11
|
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
12
12
|
fn = window.fetch.bind(window);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
const fr = await import('fetch-retry');
|
|
16
|
-
const
|
|
17
|
-
fn =
|
|
16
|
+
const wrappedFetch = fr.default(globalThis.fetch);
|
|
17
|
+
fn = wrappedFetch;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
return fn(...args);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function importFsPromises(): Promise<typeof import("node:fs/promises")>;
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=import-fs-promises.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface ImportJsonOptions {
|
|
2
2
|
forceFetch?: boolean;
|
|
3
3
|
fetchCache?: Map<string, Promise<unknown>>;
|
|
4
4
|
/**
|
|
@@ -7,5 +7,5 @@ export interface ImportJsonModuleOptions {
|
|
|
7
7
|
importCallback?: (url: string) => void;
|
|
8
8
|
signal?: AbortSignal | null;
|
|
9
9
|
}
|
|
10
|
-
export declare function
|
|
11
|
-
//# sourceMappingURL=
|
|
10
|
+
export declare function importJson<T = unknown>(url: string, options?: ImportJsonOptions): Promise<T>;
|
|
11
|
+
//# sourceMappingURL=import-json.d.ts.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
-
import { deepFreeze } from './
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
const log = debug('efp:utils:
|
|
2
|
+
import { deepFreeze } from './deep-freeze.js';
|
|
3
|
+
import { fetchWithRetry } from './fetch-with-retry.js';
|
|
4
|
+
import { importFsPromises } from './import-fs-promises.js';
|
|
5
|
+
const log = debug('efp:utils:importJson');
|
|
6
6
|
let importJsonNotAvailable;
|
|
7
7
|
const jsonFrozen = new WeakSet();
|
|
8
8
|
// ET: this is a workaround for Vite that analyzes dynamic imports and removes 'with' option
|
|
9
9
|
// to be removed when Vite supports it properly
|
|
10
10
|
// Cons: can have CSP issues in some environments
|
|
11
11
|
const importJsonNative = new Function('url', 'return import(url, { with: { type: "json" } });');
|
|
12
|
-
export async function
|
|
12
|
+
export async function importJson(url, options) {
|
|
13
13
|
const opts = {
|
|
14
14
|
forceFetch: options?.forceFetch || false,
|
|
15
15
|
fetchCache: options?.fetchCache || new Map(),
|
|
@@ -59,7 +59,7 @@ async function loadJson(url, fetchCache, signal) {
|
|
|
59
59
|
}
|
|
60
60
|
const dataPromise = (async function loadJsonInner() {
|
|
61
61
|
// in browser just use fetch, for node - fetch-retry
|
|
62
|
-
const response = await
|
|
62
|
+
const response = await fetchWithRetry(url, { signal });
|
|
63
63
|
if (!response.ok) {
|
|
64
64
|
throw new Error(`Failed to fetch JSON from ${url}`);
|
|
65
65
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function importNodeModule<T>(moduleName: string): Promise<T>;
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=import-node-module.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
-
import {
|
|
3
|
-
const log = debug('efp:utils:
|
|
4
|
-
export async function
|
|
2
|
+
import { importJson } from './import-json.js';
|
|
3
|
+
const log = debug('efp:utils:importRuntimeJson');
|
|
4
|
+
export async function importRuntimeJson(fileName) {
|
|
5
5
|
// ignore because vite may rewrite '.' to data:...
|
|
6
6
|
const baseUrl = new URL(/* @vite-ignore */ '.', import.meta.url).href;
|
|
7
7
|
const url = new URL(fileName, baseUrl);
|
|
8
8
|
log('Loading runtime JSON from', url.href);
|
|
9
|
-
return await
|
|
9
|
+
return await importJson(url.href);
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import debug from 'debug';
|
|
3
|
-
import {
|
|
3
|
+
import { fetchWithRetry } from './fetch-with-retry.js';
|
|
4
4
|
const log = debug('efp:utils:loadScript');
|
|
5
5
|
function isBrowser() {
|
|
6
6
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
@@ -59,7 +59,7 @@ async function loadInNode(scriptUrl, signal) {
|
|
|
59
59
|
}
|
|
60
60
|
let res;
|
|
61
61
|
try {
|
|
62
|
-
res = await
|
|
62
|
+
res = await fetchWithRetry(scriptUrl, { signal });
|
|
63
63
|
}
|
|
64
64
|
catch (err) {
|
|
65
65
|
// Node / WHATWG fetch uses AbortError on abort
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { safeSlugify } from './safe-slugify.js';
|
|
3
|
+
import { shortHash } from './short-hash.js';
|
|
4
4
|
const log = debug('efp:utils:makeLocalPath');
|
|
5
5
|
/**
|
|
6
6
|
* Makes a local file path from a URL, preserving extension and automatically adding hash for files.
|
|
@@ -52,17 +52,17 @@ export async function makeLocalPath(url, filenameSuffix) {
|
|
|
52
52
|
throw new Error('filenameSuffix is not allowed for directory paths');
|
|
53
53
|
}
|
|
54
54
|
// Create hash if requested (using full URL)
|
|
55
|
-
const hash = addHash ? await
|
|
55
|
+
const hash = addHash ? await shortHash(url.href) : null;
|
|
56
56
|
// Slugify protocol and domain (e.g., "http-demo-expofp-com")
|
|
57
|
-
const protocol =
|
|
58
|
-
const domain =
|
|
57
|
+
const protocol = safeSlugify(url.protocol.replace(':', ''));
|
|
58
|
+
const domain = safeSlugify(url.hostname);
|
|
59
59
|
const port = url.port ? `-${url.port}` : '';
|
|
60
60
|
const protocolDomain = `${protocol}-${domain}${port}`;
|
|
61
61
|
// Parse the path
|
|
62
62
|
const pathParts = url.pathname.split('/').filter(Boolean);
|
|
63
63
|
if (isDirectory) {
|
|
64
64
|
// For directories, all parts are directory parts
|
|
65
|
-
const slugifiedDirs = pathParts.map((part) =>
|
|
65
|
+
const slugifiedDirs = pathParts.map((part) => safeSlugify(part));
|
|
66
66
|
// Build the full local path with trailing /
|
|
67
67
|
const pathSegments = hash
|
|
68
68
|
? [protocolDomain, ...slugifiedDirs, hash]
|
|
@@ -73,13 +73,13 @@ export async function makeLocalPath(url, filenameSuffix) {
|
|
|
73
73
|
const filename = pathParts.pop() || '';
|
|
74
74
|
const directoryParts = pathParts;
|
|
75
75
|
// Slugify directory parts
|
|
76
|
-
const slugifiedDirs = directoryParts.map((part) =>
|
|
76
|
+
const slugifiedDirs = directoryParts.map((part) => safeSlugify(part));
|
|
77
77
|
// Extract extension and base filename
|
|
78
78
|
const lastDotIndex = filename.lastIndexOf('.');
|
|
79
79
|
const extension = lastDotIndex !== -1 ? filename.slice(lastDotIndex) : '';
|
|
80
80
|
const baseFilename = lastDotIndex !== -1 ? filename.slice(0, lastDotIndex) : filename;
|
|
81
81
|
// Slugify the base filename
|
|
82
|
-
let slugifiedFilename =
|
|
82
|
+
let slugifiedFilename = safeSlugify(baseFilename);
|
|
83
83
|
// Ensure filename is max 50 characters (not including extension)
|
|
84
84
|
const maxFilenameLength = 50;
|
|
85
85
|
if (slugifiedFilename.length > maxFilenameLength) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { fetchWithRetry } from './fetch-with-retry.js';
|
|
2
|
+
import { importFsPromises } from './import-fs-promises.js';
|
|
3
3
|
export async function readFileFromUrl(url, options) {
|
|
4
4
|
if (url.protocol === 'file:') {
|
|
5
5
|
const { readFile } = await importFsPromises();
|
|
@@ -7,7 +7,7 @@ export async function readFileFromUrl(url, options) {
|
|
|
7
7
|
return { ok: true, data };
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
const response = await
|
|
10
|
+
const response = await fetchWithRetry(url, { signal: options?.signal });
|
|
11
11
|
if (!response.ok) {
|
|
12
12
|
return { ok: false };
|
|
13
13
|
}
|
|
@@ -53,7 +53,7 @@ function makeBaseSlug(input) {
|
|
|
53
53
|
* @param input
|
|
54
54
|
* @returns
|
|
55
55
|
*/
|
|
56
|
-
export function
|
|
56
|
+
export function safeSlugify(input) {
|
|
57
57
|
// If we've seen this exact input before, return the same slug
|
|
58
58
|
const existing = inputToSlug.get(input);
|
|
59
59
|
if (existing)
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expofp/utils",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ExpoFP SDK internal: shared utilities",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|