@bildit-platform/engine 0.1.0
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 +92 -0
- package/dist/cjs/react/createModuleWithDependencies.d.ts +10 -0
- package/dist/cjs/react/createModuleWithDependencies.js +54 -0
- package/dist/cjs/react/createModuleWithDependencies.test.d.ts +1 -0
- package/dist/cjs/react/index.d.ts +2 -0
- package/dist/cjs/react/interpretModuleString.d.ts +27 -0
- package/dist/cjs/react/interpretModuleString.js +92 -0
- package/dist/cjs/react/interpretModuleString.test.d.ts +1 -0
- package/dist/cjs/react.js +27 -0
- package/dist/esm/react/createModuleWithDependencies.d.ts +10 -0
- package/dist/esm/react/createModuleWithDependencies.js +50 -0
- package/dist/esm/react/createModuleWithDependencies.test.d.ts +1 -0
- package/dist/esm/react/index.d.ts +2 -0
- package/dist/esm/react/interpretModuleString.d.ts +27 -0
- package/dist/esm/react/interpretModuleString.js +69 -0
- package/dist/esm/react/interpretModuleString.test.d.ts +1 -0
- package/dist/esm/react.js +20 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @bildit/engine
|
|
2
|
+
|
|
3
|
+
**@bildit/engine** is a dynamic module engine that allows you to evaluate and interpret module code on the fly in a controlled environment. It automatically registers a global module creator and injects specific dependencies into dynamically evaluated modules.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Global Module Registration:** Automatically registers a global `define` function (and sets `React`) so that evaluated modules can access controlled dependencies.
|
|
8
|
+
- **Dynamic Module Interpretation:** Provides a safe way to evaluate module code strings and retrieve specific exports.
|
|
9
|
+
- **Dependency Injection:** Uses a dependency injection mechanism to supply controlled dependencies (such as React and jsx-runtime) to your module factory functions.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install via npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @bildit/engine
|
|
17
|
+
```
|
|
18
|
+
Or via yarn:
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @bildit/engine
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
When you import @bildit/engine, it automatically registers a global module creator on globalThis (or window in browsers) and sets up the React dependency. The library provides two main functions: interpretModuleString and createModuleWithDependencies.
|
|
25
|
+
|
|
26
|
+
### Global Registration & Module Interpretation
|
|
27
|
+
The library registers a global define function that you can use for dynamic module creation. The helper function interpretModuleString evaluates a module code string and returns the desired export.
|
|
28
|
+
|
|
29
|
+
#### Example
|
|
30
|
+
```javascript
|
|
31
|
+
import {interpretModuleString} from '@bildit/engine/react';
|
|
32
|
+
|
|
33
|
+
const moduleCode = `
|
|
34
|
+
({
|
|
35
|
+
default: function hello() { return 'Hello, world!'; },
|
|
36
|
+
extra: 'Additional export'
|
|
37
|
+
})
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const helloFunction = interpretModuleString(moduleCode); // Defaults to 'default'
|
|
41
|
+
console.log(helloFunction()); // Outputs: Hello, world!
|
|
42
|
+
|
|
43
|
+
const extraExport = interpretModuleString(moduleCode, 'extra');
|
|
44
|
+
console.log(extraExport); // Outputs: Additional export
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Dependency Injection with createModuleWithDependencies
|
|
48
|
+
```javascript
|
|
49
|
+
import {createModuleWithDependencies} from '@bildit/engine/react';
|
|
50
|
+
|
|
51
|
+
const moduleExports = createModuleWithDependencies(
|
|
52
|
+
['exports', 'react', 'react/jsx-runtime'],
|
|
53
|
+
(exports, React, jsxRuntime) => {
|
|
54
|
+
// Example: Attach a React component to the module exports.
|
|
55
|
+
exports.MyComponent = () => React.createElement('div', null, 'Hello from MyComponent');
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
console.log(moduleExports.MyComponent()); // Renders your component
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
### interpretModuleString
|
|
64
|
+
Interprets JavaScript module code from a string and returns the specified export.
|
|
65
|
+
|
|
66
|
+
**Signature:**
|
|
67
|
+
```javascript
|
|
68
|
+
function interpretModuleString<T = unknown>(moduleCode: string, exportName?: string): T | null;
|
|
69
|
+
```
|
|
70
|
+
**Parameters:**
|
|
71
|
+
- `moduleCode`: The JavaScript module code as a string.
|
|
72
|
+
- `exportName` (optional): The name of the export to retrieve. Defaults to 'default'.
|
|
73
|
+
|
|
74
|
+
**Returns:**
|
|
75
|
+
- The specified export from the module code, or `null` if not found.
|
|
76
|
+
|
|
77
|
+
### createModuleWithDependencies
|
|
78
|
+
Creates a module context with controlled dependencies.
|
|
79
|
+
|
|
80
|
+
**Signature:**
|
|
81
|
+
```javascript
|
|
82
|
+
function createModuleWithDependencies<T extends Record<string, unknown>>(
|
|
83
|
+
dependencies: string[],
|
|
84
|
+
moduleFactory: (...args: unknown[]) => void
|
|
85
|
+
): T;
|
|
86
|
+
```
|
|
87
|
+
**Parameters:**
|
|
88
|
+
- `dependencies`: An array of dependency names required by the module.
|
|
89
|
+
- `moduleFactory`: A factory function that receives the resolved dependencies as arguments and populates the module’s exports.
|
|
90
|
+
|
|
91
|
+
**Returns:**
|
|
92
|
+
- An object containing the module exports.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a module context with controlled dependencies.
|
|
3
|
+
* This function is used internally by the dynamic code interpreter
|
|
4
|
+
* to provide specific dependencies to the interpreted module.
|
|
5
|
+
*
|
|
6
|
+
* @param dependencies - Array of dependency names required by the module
|
|
7
|
+
* @param moduleFactory - Factory function that creates the module using the dependencies
|
|
8
|
+
* @returns The exports object from the module
|
|
9
|
+
*/
|
|
10
|
+
export default function createModuleWithDependencies<T extends Record<string, unknown>>(dependencies: string[], moduleFactory: (...args: unknown[]) => void): T;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 BILDIT, INC.
|
|
3
|
+
*
|
|
4
|
+
* This file, and the software contained herein, are the exclusive property of BILDIT, INC.
|
|
5
|
+
* Unauthorized copying, distribution, or modification of this software is strictly prohibited.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This file is licensed under the ENT License ("License"). Use of this file is subject to the
|
|
9
|
+
* terms and conditions specified in the License. You may obtain a copy of the License at:
|
|
10
|
+
*
|
|
11
|
+
* https://bildit.co/ENTLicense
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
15
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
* DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
22
|
+
|
|
23
|
+
var ReactImport = require('react');
|
|
24
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a module context with controlled dependencies.
|
|
28
|
+
* This function is used internally by the dynamic code interpreter
|
|
29
|
+
* to provide specific dependencies to the interpreted module.
|
|
30
|
+
*
|
|
31
|
+
* @param dependencies - Array of dependency names required by the module
|
|
32
|
+
* @param moduleFactory - Factory function that creates the module using the dependencies
|
|
33
|
+
* @returns The exports object from the module
|
|
34
|
+
*/
|
|
35
|
+
function createModuleWithDependencies(dependencies, moduleFactory) {
|
|
36
|
+
// Collect all data exported from the remote code.
|
|
37
|
+
const exports = {};
|
|
38
|
+
const availableDependencies = {
|
|
39
|
+
// Core dependencies
|
|
40
|
+
react: ReactImport,
|
|
41
|
+
// 'styled-components': styled,
|
|
42
|
+
'react/jsx-runtime': jsxRuntime
|
|
43
|
+
};
|
|
44
|
+
const resolvedDependencies = dependencies.map((dependencyName) => {
|
|
45
|
+
if (dependencyName === 'exports') {
|
|
46
|
+
return exports;
|
|
47
|
+
}
|
|
48
|
+
return availableDependencies[dependencyName];
|
|
49
|
+
});
|
|
50
|
+
moduleFactory(...resolvedDependencies);
|
|
51
|
+
return exports;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.default = createModuleWithDependencies;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import createModuleWithDependencies from './createModuleWithDependencies';
|
|
2
|
+
type DefineFunction = typeof createModuleWithDependencies;
|
|
3
|
+
declare global {
|
|
4
|
+
namespace NodeJS {
|
|
5
|
+
interface Global {
|
|
6
|
+
define: DefineFunction;
|
|
7
|
+
React: any;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
interface Window {
|
|
11
|
+
define: DefineFunction;
|
|
12
|
+
React: any;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interprets JavaScript module code from a string and returns the specified export.
|
|
17
|
+
*
|
|
18
|
+
* This function safely interprets module code in a controlled environment with
|
|
19
|
+
* limited access to dependencies. It's designed for dynamic code loading scenarios
|
|
20
|
+
* where the code comes from a trusted source.
|
|
21
|
+
*
|
|
22
|
+
* @param moduleCode - JavaScript module code to interpret
|
|
23
|
+
* @param exportName - Name of the export to return (defaults to 'default')
|
|
24
|
+
* @returns The requested module export or null if interpretation fails
|
|
25
|
+
*/
|
|
26
|
+
declare const interpretModuleString: <T = unknown>(moduleCode: string, exportName?: string) => T | null;
|
|
27
|
+
export default interpretModuleString;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 BILDIT, INC.
|
|
3
|
+
*
|
|
4
|
+
* This file, and the software contained herein, are the exclusive property of BILDIT, INC.
|
|
5
|
+
* Unauthorized copying, distribution, or modification of this software is strictly prohibited.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This file is licensed under the ENT License ("License"). Use of this file is subject to the
|
|
9
|
+
* terms and conditions specified in the License. You may obtain a copy of the License at:
|
|
10
|
+
*
|
|
11
|
+
* https://bildit.co/ENTLicense
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
15
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
* DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
22
|
+
|
|
23
|
+
var ReactImport = require('react');
|
|
24
|
+
var createModuleWithDependencies = require('./createModuleWithDependencies.js');
|
|
25
|
+
|
|
26
|
+
function _interopNamespaceDefault(e) {
|
|
27
|
+
var n = Object.create(null);
|
|
28
|
+
if (e) {
|
|
29
|
+
Object.keys(e).forEach(function (k) {
|
|
30
|
+
if (k !== 'default') {
|
|
31
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
32
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return e[k]; }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
n.default = e;
|
|
40
|
+
return Object.freeze(n);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var ReactImport__namespace = /*#__PURE__*/_interopNamespaceDefault(ReactImport);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Registers the module creator in the global scope for use by evaluated code
|
|
47
|
+
*/
|
|
48
|
+
const registerGlobalModuleCreator = () => {
|
|
49
|
+
// Check if we're in a Node.js environment
|
|
50
|
+
if (typeof process !== 'undefined' &&
|
|
51
|
+
process.versions != null &&
|
|
52
|
+
process.versions.node != null) {
|
|
53
|
+
// We're in Node.js
|
|
54
|
+
globalThis.define = createModuleWithDependencies.default;
|
|
55
|
+
globalThis.React = ReactImport__namespace;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// We're in a browser or other environment
|
|
59
|
+
window.define = createModuleWithDependencies.default;
|
|
60
|
+
window.React = ReactImport__namespace;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Execute the registration
|
|
64
|
+
registerGlobalModuleCreator();
|
|
65
|
+
/**
|
|
66
|
+
* Interprets JavaScript module code from a string and returns the specified export.
|
|
67
|
+
*
|
|
68
|
+
* This function safely interprets module code in a controlled environment with
|
|
69
|
+
* limited access to dependencies. It's designed for dynamic code loading scenarios
|
|
70
|
+
* where the code comes from a trusted source.
|
|
71
|
+
*
|
|
72
|
+
* @param moduleCode - JavaScript module code to interpret
|
|
73
|
+
* @param exportName - Name of the export to return (defaults to 'default')
|
|
74
|
+
* @returns The requested module export or null if interpretation fails
|
|
75
|
+
*/
|
|
76
|
+
const interpretModuleString = (moduleCode, exportName = 'default') => {
|
|
77
|
+
try {
|
|
78
|
+
const compiledModule = eval === null || eval === void 0 ? void 0 : eval(`"use strict"; ${moduleCode}`);
|
|
79
|
+
if (!compiledModule)
|
|
80
|
+
return null;
|
|
81
|
+
if ((exportName === null || exportName === void 0 ? void 0 : exportName.length) > 0) {
|
|
82
|
+
return compiledModule[exportName];
|
|
83
|
+
}
|
|
84
|
+
return compiledModule;
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.error('Evaluation error:', e);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
exports.default = interpretModuleString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 BILDIT, INC.
|
|
3
|
+
*
|
|
4
|
+
* This file, and the software contained herein, are the exclusive property of BILDIT, INC.
|
|
5
|
+
* Unauthorized copying, distribution, or modification of this software is strictly prohibited.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This file is licensed under the ENT License ("License"). Use of this file is subject to the
|
|
9
|
+
* terms and conditions specified in the License. You may obtain a copy of the License at:
|
|
10
|
+
*
|
|
11
|
+
* https://bildit.co/ENTLicense
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
15
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
* DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
var interpretModuleString = require('./react/interpretModuleString.js');
|
|
22
|
+
var createModuleWithDependencies = require('./react/createModuleWithDependencies.js');
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.interpretModuleString = interpretModuleString.default;
|
|
27
|
+
exports.createModuleWithDependencies = createModuleWithDependencies.default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a module context with controlled dependencies.
|
|
3
|
+
* This function is used internally by the dynamic code interpreter
|
|
4
|
+
* to provide specific dependencies to the interpreted module.
|
|
5
|
+
*
|
|
6
|
+
* @param dependencies - Array of dependency names required by the module
|
|
7
|
+
* @param moduleFactory - Factory function that creates the module using the dependencies
|
|
8
|
+
* @returns The exports object from the module
|
|
9
|
+
*/
|
|
10
|
+
export default function createModuleWithDependencies<T extends Record<string, unknown>>(dependencies: string[], moduleFactory: (...args: unknown[]) => void): T;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 BILDIT, INC.
|
|
3
|
+
*
|
|
4
|
+
* This file, and the software contained herein, are the exclusive property of BILDIT, INC.
|
|
5
|
+
* Unauthorized copying, distribution, or modification of this software is strictly prohibited.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This file is licensed under the ENT License ("License"). Use of this file is subject to the
|
|
9
|
+
* terms and conditions specified in the License. You may obtain a copy of the License at:
|
|
10
|
+
*
|
|
11
|
+
* https://bildit.co/ENTLicense
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
15
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
* DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
import ReactImport__default from 'react';
|
|
20
|
+
import jsxRuntime from 'react/jsx-runtime';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a module context with controlled dependencies.
|
|
24
|
+
* This function is used internally by the dynamic code interpreter
|
|
25
|
+
* to provide specific dependencies to the interpreted module.
|
|
26
|
+
*
|
|
27
|
+
* @param dependencies - Array of dependency names required by the module
|
|
28
|
+
* @param moduleFactory - Factory function that creates the module using the dependencies
|
|
29
|
+
* @returns The exports object from the module
|
|
30
|
+
*/
|
|
31
|
+
function createModuleWithDependencies(dependencies, moduleFactory) {
|
|
32
|
+
// Collect all data exported from the remote code.
|
|
33
|
+
const exports = {};
|
|
34
|
+
const availableDependencies = {
|
|
35
|
+
// Core dependencies
|
|
36
|
+
react: ReactImport__default,
|
|
37
|
+
// 'styled-components': styled,
|
|
38
|
+
'react/jsx-runtime': jsxRuntime
|
|
39
|
+
};
|
|
40
|
+
const resolvedDependencies = dependencies.map((dependencyName) => {
|
|
41
|
+
if (dependencyName === 'exports') {
|
|
42
|
+
return exports;
|
|
43
|
+
}
|
|
44
|
+
return availableDependencies[dependencyName];
|
|
45
|
+
});
|
|
46
|
+
moduleFactory(...resolvedDependencies);
|
|
47
|
+
return exports;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createModuleWithDependencies as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import createModuleWithDependencies from './createModuleWithDependencies';
|
|
2
|
+
type DefineFunction = typeof createModuleWithDependencies;
|
|
3
|
+
declare global {
|
|
4
|
+
namespace NodeJS {
|
|
5
|
+
interface Global {
|
|
6
|
+
define: DefineFunction;
|
|
7
|
+
React: any;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
interface Window {
|
|
11
|
+
define: DefineFunction;
|
|
12
|
+
React: any;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interprets JavaScript module code from a string and returns the specified export.
|
|
17
|
+
*
|
|
18
|
+
* This function safely interprets module code in a controlled environment with
|
|
19
|
+
* limited access to dependencies. It's designed for dynamic code loading scenarios
|
|
20
|
+
* where the code comes from a trusted source.
|
|
21
|
+
*
|
|
22
|
+
* @param moduleCode - JavaScript module code to interpret
|
|
23
|
+
* @param exportName - Name of the export to return (defaults to 'default')
|
|
24
|
+
* @returns The requested module export or null if interpretation fails
|
|
25
|
+
*/
|
|
26
|
+
declare const interpretModuleString: <T = unknown>(moduleCode: string, exportName?: string) => T | null;
|
|
27
|
+
export default interpretModuleString;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 BILDIT, INC.
|
|
3
|
+
*
|
|
4
|
+
* This file, and the software contained herein, are the exclusive property of BILDIT, INC.
|
|
5
|
+
* Unauthorized copying, distribution, or modification of this software is strictly prohibited.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This file is licensed under the ENT License ("License"). Use of this file is subject to the
|
|
9
|
+
* terms and conditions specified in the License. You may obtain a copy of the License at:
|
|
10
|
+
*
|
|
11
|
+
* https://bildit.co/ENTLicense
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
15
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
* DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
import * as ReactImport from 'react';
|
|
20
|
+
import createModuleWithDependencies from './createModuleWithDependencies.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Registers the module creator in the global scope for use by evaluated code
|
|
24
|
+
*/
|
|
25
|
+
const registerGlobalModuleCreator = () => {
|
|
26
|
+
// Check if we're in a Node.js environment
|
|
27
|
+
if (typeof process !== 'undefined' &&
|
|
28
|
+
process.versions != null &&
|
|
29
|
+
process.versions.node != null) {
|
|
30
|
+
// We're in Node.js
|
|
31
|
+
globalThis.define = createModuleWithDependencies;
|
|
32
|
+
globalThis.React = ReactImport;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// We're in a browser or other environment
|
|
36
|
+
window.define = createModuleWithDependencies;
|
|
37
|
+
window.React = ReactImport;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// Execute the registration
|
|
41
|
+
registerGlobalModuleCreator();
|
|
42
|
+
/**
|
|
43
|
+
* Interprets JavaScript module code from a string and returns the specified export.
|
|
44
|
+
*
|
|
45
|
+
* This function safely interprets module code in a controlled environment with
|
|
46
|
+
* limited access to dependencies. It's designed for dynamic code loading scenarios
|
|
47
|
+
* where the code comes from a trusted source.
|
|
48
|
+
*
|
|
49
|
+
* @param moduleCode - JavaScript module code to interpret
|
|
50
|
+
* @param exportName - Name of the export to return (defaults to 'default')
|
|
51
|
+
* @returns The requested module export or null if interpretation fails
|
|
52
|
+
*/
|
|
53
|
+
const interpretModuleString = (moduleCode, exportName = 'default') => {
|
|
54
|
+
try {
|
|
55
|
+
const compiledModule = eval === null || eval === void 0 ? void 0 : eval(`"use strict"; ${moduleCode}`);
|
|
56
|
+
if (!compiledModule)
|
|
57
|
+
return null;
|
|
58
|
+
if ((exportName === null || exportName === void 0 ? void 0 : exportName.length) > 0) {
|
|
59
|
+
return compiledModule[exportName];
|
|
60
|
+
}
|
|
61
|
+
return compiledModule;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.error('Evaluation error:', e);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { interpretModuleString as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 BILDIT, INC.
|
|
3
|
+
*
|
|
4
|
+
* This file, and the software contained herein, are the exclusive property of BILDIT, INC.
|
|
5
|
+
* Unauthorized copying, distribution, or modification of this software is strictly prohibited.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This file is licensed under the ENT License ("License"). Use of this file is subject to the
|
|
9
|
+
* terms and conditions specified in the License. You may obtain a copy of the License at:
|
|
10
|
+
*
|
|
11
|
+
* https://bildit.co/ENTLicense
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
15
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
* DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
export { default as interpretModuleString } from './react/interpretModuleString.js';
|
|
20
|
+
export { default as createModuleWithDependencies } from './react/createModuleWithDependencies.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bildit-platform/engine",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bildit Render Engine",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
"./react": {
|
|
10
|
+
"require": "./dist/cjs/react.js",
|
|
11
|
+
"types": "./dist/esm/react/index.d.ts",
|
|
12
|
+
"import": "./dist/esm/react.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
"react": [
|
|
18
|
+
"dist/esm/react/index.d.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rollup -c",
|
|
24
|
+
"dev": "rollup -c -w",
|
|
25
|
+
"lint": "eslint src/**/*.{ts,tsx}",
|
|
26
|
+
"clean": "rimraf dist",
|
|
27
|
+
"prepare": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"bildit",
|
|
31
|
+
"cms",
|
|
32
|
+
"nextjs",
|
|
33
|
+
"react"
|
|
34
|
+
],
|
|
35
|
+
"author": "BILDIT",
|
|
36
|
+
"contributors": [
|
|
37
|
+
"Wes Guirra"
|
|
38
|
+
],
|
|
39
|
+
"license": "UNLICENSED",
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^18.0.0",
|
|
42
|
+
"react-dom": "^18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@rollup/plugin-commonjs": "^24.0.0",
|
|
46
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
47
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
48
|
+
"@types/jest": "^29.5.14",
|
|
49
|
+
"@types/node": "^22.13.14",
|
|
50
|
+
"@types/react": "^18.0.0",
|
|
51
|
+
"@types/react-dom": "^18.0.0",
|
|
52
|
+
"@types/react-is": "^19.0.0",
|
|
53
|
+
"eslint": "^8.0.0",
|
|
54
|
+
"rimraf": "^4.0.0",
|
|
55
|
+
"rollup": "^3.0.0",
|
|
56
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
57
|
+
"typescript": "^5.0.0"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"react-is": "^19.0.0"
|
|
61
|
+
}
|
|
62
|
+
}
|