almostnode 0.2.0 → 0.2.2
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 +21 -1
- package/dist/index.cjs +18 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +18 -10
- package/dist/index.mjs.map +1 -1
- package/dist/sandbox-helpers.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/sandbox-helpers.ts +28 -11
package/README.md
CHANGED
|
@@ -64,6 +64,26 @@ const result = container.execute(`
|
|
|
64
64
|
console.log(result.exports); // "Hello from the browser!"
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
> **⚠️ Security Warning:** The example above runs code on the main thread with full access to your page. **Do not use `createContainer()` or `container.execute()` with untrusted code.** For untrusted code, use `createRuntime()` with a cross-origin sandbox - see [Sandbox Setup](#sandbox-setup).
|
|
68
|
+
|
|
69
|
+
### Running Untrusted Code Securely
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { createRuntime, VirtualFS } from 'almostnode';
|
|
73
|
+
|
|
74
|
+
const vfs = new VirtualFS();
|
|
75
|
+
|
|
76
|
+
// Create a secure runtime with cross-origin isolation
|
|
77
|
+
const runtime = await createRuntime(vfs, {
|
|
78
|
+
sandbox: 'https://your-sandbox.vercel.app', // Deploy with generateSandboxFiles()
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Now it's safe to run untrusted code
|
|
82
|
+
const result = await runtime.execute(untrustedCode);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
See [Sandbox Setup](#sandbox-setup) for deployment instructions.
|
|
86
|
+
|
|
67
87
|
### Working with Virtual File System
|
|
68
88
|
|
|
69
89
|
```typescript
|
|
@@ -836,7 +856,7 @@ triggerHMR('/app/page.tsx', iframe);
|
|
|
836
856
|
### Setup
|
|
837
857
|
|
|
838
858
|
```bash
|
|
839
|
-
git clone https://github.com/
|
|
859
|
+
git clone https://github.com/Macaly/almostnode.git
|
|
840
860
|
cd almostnode
|
|
841
861
|
npm install
|
|
842
862
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -6,31 +6,8 @@ const pako = require('pako');
|
|
|
6
6
|
const justBash = require('just-bash');
|
|
7
7
|
const resolve_exports = require('resolve.exports');
|
|
8
8
|
const comlink = require('comlink');
|
|
9
|
-
const fs$1 = require('fs');
|
|
10
|
-
const path$1 = require('path');
|
|
11
|
-
const url$2 = require('url');
|
|
12
9
|
|
|
13
10
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
14
|
-
function _interopNamespaceDefault(e) {
|
|
15
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
16
|
-
if (e) {
|
|
17
|
-
for (const k in e) {
|
|
18
|
-
if (k !== 'default') {
|
|
19
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: () => e[k]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
n.default = e;
|
|
28
|
-
return Object.freeze(n);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
32
|
-
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
33
|
-
|
|
34
11
|
function createNodeError(code, syscall, path, message) {
|
|
35
12
|
const errno = {
|
|
36
13
|
ENOENT: -2,
|
|
@@ -9932,16 +9909,27 @@ async function createRuntime(vfs, options = {}) {
|
|
|
9932
9909
|
return new AsyncRuntimeWrapper(vfs, runtimeOptions);
|
|
9933
9910
|
}
|
|
9934
9911
|
|
|
9935
|
-
const __dirname$1 = path__namespace.dirname(url$2.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
9936
9912
|
function getServiceWorkerContent() {
|
|
9913
|
+
if (typeof require === "undefined") {
|
|
9914
|
+
return null;
|
|
9915
|
+
}
|
|
9937
9916
|
try {
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9917
|
+
const fs = require("fs");
|
|
9918
|
+
const path = require("path");
|
|
9919
|
+
let dirname;
|
|
9920
|
+
try {
|
|
9921
|
+
const url = require("url");
|
|
9922
|
+
dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
9923
|
+
} catch {
|
|
9924
|
+
dirname = __dirname;
|
|
9925
|
+
}
|
|
9926
|
+
let swPath = path.join(dirname, "__sw__.js");
|
|
9927
|
+
if (fs.existsSync(swPath)) {
|
|
9928
|
+
return fs.readFileSync(swPath, "utf-8");
|
|
9941
9929
|
}
|
|
9942
|
-
swPath =
|
|
9943
|
-
if (
|
|
9944
|
-
return
|
|
9930
|
+
swPath = path.join(dirname, "../dist/__sw__.js");
|
|
9931
|
+
if (fs.existsSync(swPath)) {
|
|
9932
|
+
return fs.readFileSync(swPath, "utf-8");
|
|
9945
9933
|
}
|
|
9946
9934
|
return null;
|
|
9947
9935
|
} catch {
|