lambder 1.0.136 → 1.0.138
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 +1 -1
- package/dist/LambderResponseBuilder.js +11 -2
- package/dist/LambderUtils.js +11 -2
- package/dist/node-polyfills.d.ts +2 -0
- package/dist/node-polyfills.js +25 -0
- package/package.json +11 -1
- package/src/LambderResponseBuilder.ts +15 -3
- package/src/LambderUtils.ts +13 -2
- package/src/node-polyfills.ts +28 -0
package/Readme.md
CHANGED
|
@@ -455,7 +455,7 @@ LambderCaller is included in the same `lambder` package. Ensure you have `lambde
|
|
|
455
455
|
Begin by initializing LambderCaller with your API configuration. This setup assumes your project structure accommodates a place for initiating and configuring API handlers, possibly within a dedicated JavaScript module or directly in your main application file.
|
|
456
456
|
|
|
457
457
|
```javascript
|
|
458
|
-
import LambderCaller from "lambder
|
|
458
|
+
import { LambderCaller } from "lambder";
|
|
459
459
|
|
|
460
460
|
const lambderCaller = new LambderCaller({
|
|
461
461
|
isCorsEnabled: false,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
1
|
import mimeTypeResolver from "mime-types";
|
|
2
|
+
import { getFS, getPath } from "./node-polyfills.js";
|
|
4
3
|
const convertToMultiHeader = (headers) => Object.fromEntries(Object.entries(headers || {}).map(([k, v]) => [k, Array.isArray(v) ? v : [v]]));
|
|
5
4
|
const CORS_HEADERS = convertToMultiHeader({
|
|
6
5
|
"Access-Control-Allow-Credentials": "true",
|
|
@@ -23,6 +22,11 @@ export default class LambderResponseBuilder {
|
|
|
23
22
|
}
|
|
24
23
|
;
|
|
25
24
|
readPublicFileSync(filePath) {
|
|
25
|
+
const fs = getFS();
|
|
26
|
+
const path = getPath();
|
|
27
|
+
if (!fs || !path) {
|
|
28
|
+
throw new Error("File system operations are not available in browser environment");
|
|
29
|
+
}
|
|
26
30
|
const publicPath = path.resolve(this.publicPath);
|
|
27
31
|
const absolutePath = path.join(publicPath, filePath);
|
|
28
32
|
console.log("readPublicFileSync", { filePath, publicPath, absolutePath });
|
|
@@ -33,6 +37,11 @@ export default class LambderResponseBuilder {
|
|
|
33
37
|
}
|
|
34
38
|
;
|
|
35
39
|
checkPublicFileExist(filePath) {
|
|
40
|
+
const fs = getFS();
|
|
41
|
+
const path = getPath();
|
|
42
|
+
if (!fs || !path) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
36
45
|
const publicPath = path.resolve(this.publicPath);
|
|
37
46
|
const absolutePath = path.join(this.publicPath, filePath);
|
|
38
47
|
console.log("checkPublicFileExist", { filePath, publicPath, absolutePath });
|
package/dist/LambderUtils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
1
|
import ejs from "ejs";
|
|
2
|
+
import { getFS, getPath } from "./node-polyfills.js";
|
|
4
3
|
export default class LambderUtils {
|
|
5
4
|
ejsPath;
|
|
6
5
|
constructor({ ejsPath } = {}) {
|
|
@@ -8,6 +7,11 @@ export default class LambderUtils {
|
|
|
8
7
|
}
|
|
9
8
|
;
|
|
10
9
|
readEjsFileSync(filePath) {
|
|
10
|
+
const fs = getFS();
|
|
11
|
+
const path = getPath();
|
|
12
|
+
if (!fs || !path) {
|
|
13
|
+
throw new Error("File system operations are not available in browser environment");
|
|
14
|
+
}
|
|
11
15
|
if (!this.ejsPath) {
|
|
12
16
|
return "EJS PATH NOT SET!";
|
|
13
17
|
}
|
|
@@ -21,6 +25,11 @@ export default class LambderUtils {
|
|
|
21
25
|
}
|
|
22
26
|
;
|
|
23
27
|
checkEjsFileExist(filePath) {
|
|
28
|
+
const fs = getFS();
|
|
29
|
+
const path = getPath();
|
|
30
|
+
if (!fs || !path) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
24
33
|
if (!this.ejsPath) {
|
|
25
34
|
return "EJS PATH NOT SET!";
|
|
26
35
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Node.js polyfills for browser compatibility
|
|
2
|
+
// This file provides optional Node.js modules that fail gracefully in browser environments
|
|
3
|
+
let fs = null;
|
|
4
|
+
let path = null;
|
|
5
|
+
// Try to import Node.js modules if available
|
|
6
|
+
try {
|
|
7
|
+
// @ts-ignore - conditional import
|
|
8
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
9
|
+
// Use eval to prevent bundlers from trying to resolve these at build time
|
|
10
|
+
const requireFunc = eval('typeof require !== "undefined" ? require : null');
|
|
11
|
+
if (requireFunc) {
|
|
12
|
+
fs = requireFunc('fs');
|
|
13
|
+
path = requireFunc('path');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
// Silently fail - we're in a browser environment
|
|
19
|
+
}
|
|
20
|
+
export function getFS() {
|
|
21
|
+
return fs;
|
|
22
|
+
}
|
|
23
|
+
export function getPath() {
|
|
24
|
+
return path;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.138",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"browser": {
|
|
15
|
+
"fs": false,
|
|
16
|
+
"path": false
|
|
17
|
+
},
|
|
8
18
|
"scripts": {
|
|
9
19
|
"test": "vitest run",
|
|
10
20
|
"test:watch": "vitest",
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import ejs from "ejs";
|
|
4
1
|
import mimeTypeResolver from "mime-types";
|
|
5
2
|
import LambderUtils from "./LambderUtils.js";
|
|
6
3
|
import { LambderRenderContext } from "./Lambder.js";
|
|
7
4
|
import type { ApiContractShape } from "./LambderApiContract.js";
|
|
5
|
+
import { getFS, getPath } from "./node-polyfills.js";
|
|
8
6
|
|
|
9
7
|
const convertToMultiHeader = (
|
|
10
8
|
headers: Record<string, string|string[]> | undefined
|
|
@@ -64,6 +62,13 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
|
|
|
64
62
|
};
|
|
65
63
|
|
|
66
64
|
private readPublicFileSync(filePath: string){
|
|
65
|
+
const fs = getFS();
|
|
66
|
+
const path = getPath();
|
|
67
|
+
|
|
68
|
+
if (!fs || !path) {
|
|
69
|
+
throw new Error("File system operations are not available in browser environment");
|
|
70
|
+
}
|
|
71
|
+
|
|
67
72
|
const publicPath = path.resolve(this.publicPath);
|
|
68
73
|
const absolutePath = path.join(publicPath, filePath);
|
|
69
74
|
console.log("readPublicFileSync", { filePath, publicPath, absolutePath });
|
|
@@ -72,6 +77,13 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
|
|
|
72
77
|
};
|
|
73
78
|
|
|
74
79
|
private checkPublicFileExist(filePath: string){
|
|
80
|
+
const fs = getFS();
|
|
81
|
+
const path = getPath();
|
|
82
|
+
|
|
83
|
+
if (!fs || !path) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
75
87
|
const publicPath = path.resolve(this.publicPath);
|
|
76
88
|
const absolutePath = path.join(this.publicPath, filePath);
|
|
77
89
|
console.log("checkPublicFileExist", { filePath, publicPath, absolutePath });
|
package/src/LambderUtils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
1
|
import ejs from "ejs";
|
|
2
|
+
import { getFS, getPath } from "./node-polyfills.js";
|
|
4
3
|
|
|
5
4
|
export default class LambderUtils {
|
|
6
5
|
private ejsPath?: string;
|
|
@@ -14,6 +13,12 @@ export default class LambderUtils {
|
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
private readEjsFileSync(filePath: string){
|
|
16
|
+
const fs = getFS();
|
|
17
|
+
const path = getPath();
|
|
18
|
+
|
|
19
|
+
if (!fs || !path) {
|
|
20
|
+
throw new Error("File system operations are not available in browser environment");
|
|
21
|
+
}
|
|
17
22
|
if(!this.ejsPath){ return "EJS PATH NOT SET!"; }
|
|
18
23
|
const ejsPath = path.resolve(this.ejsPath);
|
|
19
24
|
const absolutePath = path.join(ejsPath, filePath);
|
|
@@ -23,6 +28,12 @@ export default class LambderUtils {
|
|
|
23
28
|
};
|
|
24
29
|
|
|
25
30
|
private checkEjsFileExist(filePath: string){
|
|
31
|
+
const fs = getFS();
|
|
32
|
+
const path = getPath();
|
|
33
|
+
|
|
34
|
+
if (!fs || !path) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
26
37
|
if(!this.ejsPath){ return "EJS PATH NOT SET!"; }
|
|
27
38
|
const ejsPath = path.resolve(this.ejsPath);
|
|
28
39
|
const absolutePath = path.join(this.ejsPath, filePath);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Node.js polyfills for browser compatibility
|
|
2
|
+
// This file provides optional Node.js modules that fail gracefully in browser environments
|
|
3
|
+
|
|
4
|
+
let fs: any = null;
|
|
5
|
+
let path: any = null;
|
|
6
|
+
|
|
7
|
+
// Try to import Node.js modules if available
|
|
8
|
+
try {
|
|
9
|
+
// @ts-ignore - conditional import
|
|
10
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
11
|
+
// Use eval to prevent bundlers from trying to resolve these at build time
|
|
12
|
+
const requireFunc = eval('typeof require !== "undefined" ? require : null');
|
|
13
|
+
if (requireFunc) {
|
|
14
|
+
fs = requireFunc('fs');
|
|
15
|
+
path = requireFunc('path');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
} catch (e) {
|
|
19
|
+
// Silently fail - we're in a browser environment
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getFS() {
|
|
23
|
+
return fs;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getPath() {
|
|
27
|
+
return path;
|
|
28
|
+
}
|