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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-helpers.d.ts","sourceRoot":"","sources":["../src/sandbox-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"sandbox-helpers.d.ts","sourceRoot":"","sources":["../src/sandbox-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiDH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,kBAAkB,GAAG,MAAW,GAAG,MAAM,CA6GhF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAY/C;AAED,MAAM,WAAW,2BAA4B,SAAQ,kBAAkB;CAEtE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,2BAA2B,GAAG,MAAW,GAAG;IACxF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAuBA;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAmB/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "almostnode",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Node.js in your browser. Just like that.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
],
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/
|
|
20
|
+
"url": "https://github.com/Macaly/almostnode.git"
|
|
21
21
|
},
|
|
22
|
-
"homepage": "https://github.com/
|
|
22
|
+
"homepage": "https://github.com/Macaly/almostnode#readme",
|
|
23
23
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/
|
|
24
|
+
"url": "https://github.com/Macaly/almostnode/issues"
|
|
25
25
|
},
|
|
26
26
|
"author": "",
|
|
27
27
|
"engines": {
|
package/src/sandbox-helpers.ts
CHANGED
|
@@ -5,27 +5,44 @@
|
|
|
5
5
|
* to provide browser-enforced isolation from the main application.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import * as fs from 'fs';
|
|
9
|
-
import * as path from 'path';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
|
-
// @ts-ignore - import.meta.url is available in ESM
|
|
14
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
|
|
16
8
|
/**
|
|
17
9
|
* Get the contents of the service worker file.
|
|
18
|
-
* Returns null if
|
|
10
|
+
* Returns null if running in browser or file is not found.
|
|
11
|
+
*
|
|
12
|
+
* Note: This function only works in Node.js. In the browser, it returns null.
|
|
19
13
|
*/
|
|
20
14
|
function getServiceWorkerContent(): string | null {
|
|
15
|
+
// Only works in Node.js - check for presence of require
|
|
16
|
+
if (typeof require === 'undefined') {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
21
20
|
try {
|
|
21
|
+
// Dynamic requires to avoid bundling Node.js modules in browser build
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
|
+
const path = require('path');
|
|
26
|
+
|
|
27
|
+
// __dirname equivalent for ESM
|
|
28
|
+
let dirname: string;
|
|
29
|
+
try {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
31
|
+
const url = require('url');
|
|
32
|
+
// @ts-ignore - import.meta.url is available in ESM
|
|
33
|
+
dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
34
|
+
} catch {
|
|
35
|
+
// Fallback for CommonJS
|
|
36
|
+
dirname = __dirname;
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
// Try dist directory first (when running from built package)
|
|
23
|
-
let swPath = path.join(
|
|
40
|
+
let swPath = path.join(dirname, '__sw__.js');
|
|
24
41
|
if (fs.existsSync(swPath)) {
|
|
25
42
|
return fs.readFileSync(swPath, 'utf-8');
|
|
26
43
|
}
|
|
27
44
|
// Try relative to src (when running from source)
|
|
28
|
-
swPath = path.join(
|
|
45
|
+
swPath = path.join(dirname, '../dist/__sw__.js');
|
|
29
46
|
if (fs.existsSync(swPath)) {
|
|
30
47
|
return fs.readFileSync(swPath, 'utf-8');
|
|
31
48
|
}
|