Skip to content

Commit 4954757

Browse files
authored
Merge pull request #11 from astrohelm/dev
Isolation v2.1.0
2 parents 0eda0f1 + d349412 commit 4954757

File tree

10 files changed

+307
-1011
lines changed

10 files changed

+307
-1011
lines changed

CHANGELOG.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
## [Unreleased][unreleased]
44

5+
## [2.1.0][] - 2024-01-13 / 2024-03-18
6+
7+
- Updated packages
8+
- Grammar fixes
9+
- Contextify micro task mode fixed
10+
- New timeout test case
11+
512
## [2.0.0][] - 2023-12-12
613

7-
- Majure release
14+
- Major release
815
- Stable API
916
- Documentation enhancement
1017
- Renamed access property for realm
@@ -62,7 +69,7 @@
6269
## [1.3.0][] - 2023-10-26
6370

6471
- Renamed from isolation -> isolation
65-
- Inhanced documentation
72+
- Enhanced documentation
6673

6774
## [1.2.0][] - 2023-10-25
6875

@@ -86,17 +93,17 @@
8693
isolation.require.script('./my-path/to/script.js');
8794
isolation.require.dir('./my-path/to');
8895
```
89-
2. New access controll feature, see access updates
96+
2. New access control feature, see access updates
9097
- Access updates, now this option work for both sandbox and reader, you need to provide function
9198
```js
9299
const option = { access: pathOrModule => pathOrModule === 'fs' || pathOrModule.endsWith('.js') };
93100
isolation.execute('module.exports = require("fs")');
94101
isolation.read('./path/to/script.js');
95-
// But you still can controll them by each own function
102+
// But you still can control them by each own function
96103
const option = {
97104
access: {
98-
internal: path => true, // Reader controll
99-
sandbox: module => {}, // Sandbox require controll
105+
internal: path => true, // Reader control
106+
sandbox: module => {}, // Sandbox require control
100107
},
101108
};
102109
```
@@ -127,7 +134,8 @@
127134
- Quality of life improvements
128135
- Massive README update, documentation improvement
129136

130-
[unreleased]: https://github.com/astrohelm/isolation/compare/v2.0.0...HEAD
137+
[unreleased]: https://github.com/astrohelm/isolation/compare/v2.1.0...HEAD
138+
[2.1.0]: https://github.com/astrohelm/isolation/compare/v2.0.0...v2.1.0
131139
[2.0.0]: https://github.com/astrohelm/isolation/compare/v1.0.0...v2.0.0
132140
[1.9.0]: https://github.com/astrohelm/isolation/compare/v1.8.0...v1.9.0
133141
[1.8.0]: https://github.com/astrohelm/isolation/compare/v1.7.0...v1.8.0

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ issues. Also, isolation prevents global scope and prototypes pollution.
1010

1111
> [!TIP]
1212
>
13-
> ## **Possible usecase**
13+
> ## **Possible use case**
1414
>
1515
> May be useful as routing loader, if some loaded route makes an error while runtime, you may
1616
> recreate it - to prevent memory leaks. Another worlds, with this library you can create
@@ -149,7 +149,7 @@ provide your custom variables to the context without requiring any module.
149149

150150
> [!TIP]
151151
>
152-
> Remember to reuse your contexts. This will encrease performance of your application. To help you
152+
> Remember to reuse your contexts. This will increase performance of your application. To help you
153153
> with this we have default contexts:
154154
155155
### **Context example**
@@ -280,19 +280,19 @@ console.log(result); // Output: Isolation.js Works !
280280

281281
</h2>
282282

283-
| Option | Possible | Default | Description |
284-
| ---------------- | ---------------------------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------- |
285-
| **type** | iso&nbsp;\|&nbsp;cjs | cjs | Type&nbsp;of&nbsp;script&nbsp;handling, see [syntax types](#module-types) |
286-
| **ctx** | object | - | Realm&nbsp;context, see [Context API](#context-api) |
287-
| **filename** | string | ISO | Name&nbsp;of&nbsp;the&nbsp;module&nbsp;, also it is global variable **\_\_filename** for root realm |
288-
| **dir** | string | process.cwd() | Module&nbsp;directory&nbsp;, also it is global varibale **\_\_dirname** and realm require startpoint |
289-
| **npmIsolation** | boolean | false | Controls&nbsp;npm&nbsp;modules&nbsp;isolation |
290-
| **access** | [Access](./types/options.d.ts#L51) | - | Isolation&nbsp;restrictions, see [Access API](#reader-api) |
291-
| **prepare** | boolean | false | Reader&nbsp;would'nt&nbsp;execute script for you |
292-
| **flat** | boolean | false | Reader&nbsp;will&nbsp;flat&nbsp;nested&nbsp;scripts |
293-
| **depth** | boolean&nbsp;\|&nbsp;number | true | Restricts&nbsp;dir&nbsp;reading&nbsp;depth |
294-
| **script** | [ScriptOptions](./types/options.d.ts#L63) | - | Configuration&nbsp;for VM.Script initialization |
295-
| **run** | [RunningCodeOptions](./types/options.d.ts#L62) | {&nbsp;timeout:&nbsp;1000&nbsp;} | Configuration&nbsp;for VM.Script execution |
283+
| Option | Possible | Default | Description |
284+
| ---------------- | ---------------------------------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------- |
285+
| **type** | iso&nbsp;\|&nbsp;cjs | cjs | Type&nbsp;of&nbsp;script&nbsp;handling, see [syntax types](#module-types) |
286+
| **ctx** | object | - | Realm&nbsp;context, see [Context API](#context-api) |
287+
| **filename** | string | ISO | Name&nbsp;of&nbsp;the&nbsp;module&nbsp;, also it is global variable **\_\_filename** for root realm |
288+
| **dir** | string | process.cwd() | Module&nbsp;directory&nbsp;, also it is global variable **\_\_dirname** and realm require start point |
289+
| **npmIsolation** | boolean | false | Controls&nbsp;npm&nbsp;modules&nbsp;isolation |
290+
| **access** | [Access](./types/options.d.ts#L51) | - | Isolation&nbsp;restrictions, see [Access API](#reader-api) |
291+
| **prepare** | boolean | false | Reader&nbsp;would'nt&nbsp;execute script for you |
292+
| **flat** | boolean | false | Reader&nbsp;will&nbsp;flat&nbsp;nested&nbsp;scripts |
293+
| **depth** | boolean&nbsp;\|&nbsp;number | true | Restricts&nbsp;dir&nbsp;reading&nbsp;depth |
294+
| **script** | [ScriptOptions](./types/options.d.ts#L63) | - | Configuration&nbsp;for VM.Script initialization |
295+
| **run** | [RunningCodeOptions](./types/options.d.ts#L62) | {&nbsp;timeout:&nbsp;1000&nbsp;} | Configuration&nbsp;for VM.Script execution |
296296

297297
<h2 align="center">Copyright & contributors</h2>
298298

SECURITY.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/context/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var contextify = module.exports = (ctx, mode = false) => {
1010
if (isContext(ctx)) return ctx;
1111
return createContext(ctx, {
1212
...contextify.OPTIONS,
13-
preventEscape: mode ? 'afterEvaluate' : '',
13+
microtaskMode: mode ? 'afterEvaluate' : undefined,
1414
});
1515
};
1616

lib/reader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function file(path, { prepare, ...estimated } = {}) {
2020

2121
const JS_EXT = /^\.[cme]?js$/;
2222
const READ_OPTS = { withFileTypes: true };
23-
const futher = (max, depth) => max === true || (typeof max === 'number' && depth + 1 <= max);
23+
const further = (max, depth) => max === true || (typeof max === 'number' && depth + 1 <= max);
2424
function dir(src, options = {}) {
2525
const { depth: max = true, flat = false, access } = options;
2626
const isAllow = checkAccess.bind(null, 'reader', access);
@@ -32,7 +32,7 @@ function dir(src, options = {}) {
3232
const storage = flat ? scripts : {};
3333
await Promise.all(files.map(async f => {
3434
var isDir = f.isDirectory(), name = f.name, path = join(src, name);
35-
if ((isDir && !futher(max, depth)) || !isAllow(path)) return;
35+
if ((isDir && !further(max, depth)) || !isAllow(path)) return;
3636
if (isDir && flat) return void await pull(path, depth + 1);
3737
var ext = extname(name), key = base(name, ext.match(JS_EXT) ? ext : '');
3838
storage[key] = await (isDir ? pull(path, depth + 1) : file(path, options));

0 commit comments

Comments
 (0)