@bildit-platform/engine 0.1.1 → 0.1.4

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 CHANGED
@@ -1,6 +1,6 @@
1
- # @bildit/engine
1
+ # @bildit-platform/engine
2
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.
3
+ **@bildit-platform/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
4
 
5
5
  ## Features
6
6
 
@@ -13,22 +13,22 @@
13
13
  Install via npm:
14
14
 
15
15
  ```bash
16
- npm install @bildit/engine
16
+ npm install @bildit-platform/engine
17
17
  ```
18
18
  Or via yarn:
19
19
  ```bash
20
- yarn add @bildit/engine
20
+ yarn add @bildit-platform/engine
21
21
  ```
22
22
 
23
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.
24
+ When you import @bildit-platform/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
25
 
26
26
  ### Global Registration & Module Interpretation
27
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
28
 
29
29
  #### Example
30
30
  ```javascript
31
- import {interpretModuleString} from '@bildit/engine/react';
31
+ import {interpretModuleString} from '@bildit-platform/engine/react';
32
32
 
33
33
  const moduleCode = `
34
34
  ({
@@ -46,7 +46,7 @@ console.log(extraExport); // Outputs: Additional export
46
46
 
47
47
  ### Dependency Injection with createModuleWithDependencies
48
48
  ```javascript
49
- import {createModuleWithDependencies} from '@bildit/engine/react';
49
+ import {createModuleWithDependencies} from '@bildit-platform/engine/react';
50
50
 
51
51
  const moduleExports = createModuleWithDependencies(
52
52
  ['exports', 'react', 'react/jsx-runtime'],
@@ -65,11 +65,16 @@ Interprets JavaScript module code from a string and returns the specified export
65
65
 
66
66
  **Signature:**
67
67
  ```javascript
68
- function interpretModuleString<T = unknown>(moduleCode: string, exportName?: string): T | null;
68
+ function interpretModuleString<T = unknown>(
69
+ moduleCode: string,
70
+ exportName?: string,
71
+ extraDependenciesConfig: Record<string, ExtraDependencyConfig>
72
+ ): T | null;
69
73
  ```
70
74
  **Parameters:**
71
75
  - `moduleCode`: The JavaScript module code as a string.
72
76
  - `exportName` (optional): The name of the export to retrieve. Defaults to 'default'.
77
+ - `extraDependenciesConfig` (optional): Additional customer-specific dependencies.
73
78
 
74
79
  **Returns:**
75
80
  - The specified export from the module code, or `null` if not found.
@@ -81,12 +86,22 @@ Creates a module context with controlled dependencies.
81
86
  ```javascript
82
87
  function createModuleWithDependencies<T extends Record<string, unknown>>(
83
88
  dependencies: string[],
84
- moduleFactory: (...args: unknown[]) => void
89
+ moduleFactory: (...args: unknown[]) => void,
90
+ extraDependenciesConfig: Record<string, ExtraDependencyConfig>
85
91
  ): T;
86
92
  ```
87
93
  **Parameters:**
88
94
  - `dependencies`: An array of dependency names required by the module.
89
95
  - `moduleFactory`: A factory function that receives the resolved dependencies as arguments and populates the module’s exports.
96
+ - `extraDependenciesConfig` (optional): Extra dependencies configuration to set global name and module.
90
97
 
91
98
  **Returns:**
92
99
  - An object containing the module exports.
100
+
101
+ ## Types
102
+ ```javascript
103
+ export type ExtraDependencyConfig = {
104
+ module: any;
105
+ globalName?: string;
106
+ };
107
+ ```
@@ -1,10 +1,12 @@
1
+ import { ExtraDependencyConfig } from "../types";
1
2
  /**
2
3
  * Creates a module context with controlled dependencies.
3
4
  * This function is used internally by the dynamic code interpreter
4
5
  * to provide specific dependencies to the interpreted module.
5
6
  *
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
7
+ * @param {string[]} dependencies - Array of dependency names required by the module
8
+ * @param {(...args: unknown[]) => void} moduleFactory - Factory function that creates the module using the dependencies
9
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
10
+ * @returns {T extends Record<string, unknown>} The exports object from the module
9
11
  */
10
- export default function createModuleWithDependencies<T extends Record<string, unknown>>(dependencies: string[], moduleFactory: (...args: unknown[]) => void): T;
12
+ export default function createModuleWithDependencies<T extends Record<string, unknown>>(dependencies: string[], moduleFactory: (...args: unknown[]) => void, extraDependenciesConfig?: Record<string, ExtraDependencyConfig>): T;
@@ -28,18 +28,26 @@ var jsxRuntime = require('react/jsx-runtime');
28
28
  * This function is used internally by the dynamic code interpreter
29
29
  * to provide specific dependencies to the interpreted module.
30
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
31
+ * @param {string[]} dependencies - Array of dependency names required by the module
32
+ * @param {(...args: unknown[]) => void} moduleFactory - Factory function that creates the module using the dependencies
33
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
34
+ * @returns {T extends Record<string, unknown>} The exports object from the module
34
35
  */
35
- function createModuleWithDependencies(dependencies, moduleFactory) {
36
+ function createModuleWithDependencies(dependencies, moduleFactory, extraDependenciesConfig = {}) {
36
37
  // Collect all data exported from the remote code.
37
38
  const exports = {};
38
- const availableDependencies = {
39
- // Core dependencies
39
+ const coreDependencies = {
40
40
  react: ReactImport,
41
- // 'styled-components': styled,
42
- 'react/jsx-runtime': jsxRuntime
41
+ 'react/jsx-runtime': jsxRuntime,
42
+ };
43
+ const extraDependencies = Object.keys(extraDependenciesConfig).reduce((acc, key) => {
44
+ const { module } = extraDependenciesConfig[key];
45
+ acc[key] = module;
46
+ return acc;
47
+ }, {});
48
+ const availableDependencies = {
49
+ ...coreDependencies,
50
+ ...extraDependencies,
43
51
  };
44
52
  const resolvedDependencies = dependencies.map((dependencyName) => {
45
53
  if (dependencyName === 'exports') {
@@ -1,3 +1,4 @@
1
+ import { ExtraDependencyConfig } from '../types';
1
2
  import createModuleWithDependencies from './createModuleWithDependencies';
2
3
  type DefineFunction = typeof createModuleWithDependencies;
3
4
  declare global {
@@ -19,9 +20,10 @@ declare global {
19
20
  * limited access to dependencies. It's designed for dynamic code loading scenarios
20
21
  * where the code comes from a trusted source.
21
22
  *
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
23
+ * @param {string} moduleCode - JavaScript module code to interpret
24
+ * @param {string} exportName - Name of the export to return (defaults to 'default')
25
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
26
+ * @returns {T | null} The requested module export or null if interpretation fails
25
27
  */
26
- declare const interpretModuleString: <T = unknown>(moduleCode: string, exportName?: string) => T | null;
28
+ declare const interpretModuleString: <T = unknown>(moduleCode: string, exportName?: string, extraDependenciesConfig?: Record<string, ExtraDependencyConfig>) => T | null;
27
29
  export default interpretModuleString;
@@ -20,48 +20,8 @@
20
20
 
21
21
  Object.defineProperty(exports, '__esModule', { value: true });
22
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);
23
+ var registerGlobalModuleCreator = require('./registerGlobalModuleCreator.js');
44
24
 
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
25
  /**
66
26
  * Interprets JavaScript module code from a string and returns the specified export.
67
27
  *
@@ -69,12 +29,16 @@ registerGlobalModuleCreator();
69
29
  * limited access to dependencies. It's designed for dynamic code loading scenarios
70
30
  * where the code comes from a trusted source.
71
31
  *
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
32
+ * @param {string} moduleCode - JavaScript module code to interpret
33
+ * @param {string} exportName - Name of the export to return (defaults to 'default')
34
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
35
+ * @returns {T | null} The requested module export or null if interpretation fails
75
36
  */
76
- const interpretModuleString = (moduleCode, exportName = 'default') => {
37
+ const interpretModuleString = (moduleCode, exportName = 'default', extraDependenciesConfig) => {
77
38
  try {
39
+ if (!moduleCode)
40
+ return null;
41
+ registerGlobalModuleCreator.default(extraDependenciesConfig);
78
42
  const compiledModule = eval === null || eval === void 0 ? void 0 : eval(`"use strict"; ${moduleCode}`);
79
43
  if (!compiledModule)
80
44
  return null;
@@ -0,0 +1,7 @@
1
+ import { ExtraDependencyConfig } from '../types';
2
+ /**
3
+ * Registers the module creator in the global scope for use by evaluated code
4
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - extra dependencies config map
5
+ */
6
+ declare const registerGlobalModuleCreator: (extraDependenciesConfig?: Record<string, ExtraDependencyConfig>) => void;
7
+ export default registerGlobalModuleCreator;
@@ -0,0 +1,79 @@
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
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - extra dependencies config map
48
+ */
49
+ const registerGlobalModuleCreator = (extraDependenciesConfig = {}) => {
50
+ const define = (dependencies, moduleFactory) => {
51
+ return createModuleWithDependencies.default(dependencies, moduleFactory, extraDependenciesConfig);
52
+ };
53
+ const nodeJsEnvironment = typeof process !== 'undefined' &&
54
+ process.versions != null &&
55
+ process.versions.node != null;
56
+ if (nodeJsEnvironment) {
57
+ globalThis.define = define;
58
+ globalThis.React = ReactImport__namespace;
59
+ for (const [_, value] of Object.entries(extraDependenciesConfig)) {
60
+ const { module, globalName } = value;
61
+ if (globalName) {
62
+ globalThis[globalName] = module;
63
+ }
64
+ }
65
+ }
66
+ else {
67
+ // We're in a browser or other environment
68
+ window.define = define;
69
+ window.React = ReactImport__namespace;
70
+ for (const [_, value] of Object.entries(extraDependenciesConfig)) {
71
+ const { module, globalName } = value;
72
+ if (globalName) {
73
+ window[globalName] = module;
74
+ }
75
+ }
76
+ }
77
+ };
78
+
79
+ exports.default = registerGlobalModuleCreator;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ export type ExtraDependencyConfig = {
2
+ module: any;
3
+ globalName?: string;
4
+ };
@@ -1,10 +1,12 @@
1
+ import { ExtraDependencyConfig } from "../types";
1
2
  /**
2
3
  * Creates a module context with controlled dependencies.
3
4
  * This function is used internally by the dynamic code interpreter
4
5
  * to provide specific dependencies to the interpreted module.
5
6
  *
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
7
+ * @param {string[]} dependencies - Array of dependency names required by the module
8
+ * @param {(...args: unknown[]) => void} moduleFactory - Factory function that creates the module using the dependencies
9
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
10
+ * @returns {T extends Record<string, unknown>} The exports object from the module
9
11
  */
10
- export default function createModuleWithDependencies<T extends Record<string, unknown>>(dependencies: string[], moduleFactory: (...args: unknown[]) => void): T;
12
+ export default function createModuleWithDependencies<T extends Record<string, unknown>>(dependencies: string[], moduleFactory: (...args: unknown[]) => void, extraDependenciesConfig?: Record<string, ExtraDependencyConfig>): T;
@@ -24,18 +24,26 @@ import jsxRuntime from 'react/jsx-runtime';
24
24
  * This function is used internally by the dynamic code interpreter
25
25
  * to provide specific dependencies to the interpreted module.
26
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
27
+ * @param {string[]} dependencies - Array of dependency names required by the module
28
+ * @param {(...args: unknown[]) => void} moduleFactory - Factory function that creates the module using the dependencies
29
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
30
+ * @returns {T extends Record<string, unknown>} The exports object from the module
30
31
  */
31
- function createModuleWithDependencies(dependencies, moduleFactory) {
32
+ function createModuleWithDependencies(dependencies, moduleFactory, extraDependenciesConfig = {}) {
32
33
  // Collect all data exported from the remote code.
33
34
  const exports = {};
34
- const availableDependencies = {
35
- // Core dependencies
35
+ const coreDependencies = {
36
36
  react: ReactImport__default,
37
- // 'styled-components': styled,
38
- 'react/jsx-runtime': jsxRuntime
37
+ 'react/jsx-runtime': jsxRuntime,
38
+ };
39
+ const extraDependencies = Object.keys(extraDependenciesConfig).reduce((acc, key) => {
40
+ const { module } = extraDependenciesConfig[key];
41
+ acc[key] = module;
42
+ return acc;
43
+ }, {});
44
+ const availableDependencies = {
45
+ ...coreDependencies,
46
+ ...extraDependencies,
39
47
  };
40
48
  const resolvedDependencies = dependencies.map((dependencyName) => {
41
49
  if (dependencyName === 'exports') {
@@ -1,3 +1,4 @@
1
+ import { ExtraDependencyConfig } from '../types';
1
2
  import createModuleWithDependencies from './createModuleWithDependencies';
2
3
  type DefineFunction = typeof createModuleWithDependencies;
3
4
  declare global {
@@ -19,9 +20,10 @@ declare global {
19
20
  * limited access to dependencies. It's designed for dynamic code loading scenarios
20
21
  * where the code comes from a trusted source.
21
22
  *
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
23
+ * @param {string} moduleCode - JavaScript module code to interpret
24
+ * @param {string} exportName - Name of the export to return (defaults to 'default')
25
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
26
+ * @returns {T | null} The requested module export or null if interpretation fails
25
27
  */
26
- declare const interpretModuleString: <T = unknown>(moduleCode: string, exportName?: string) => T | null;
28
+ declare const interpretModuleString: <T = unknown>(moduleCode: string, exportName?: string, extraDependenciesConfig?: Record<string, ExtraDependencyConfig>) => T | null;
27
29
  export default interpretModuleString;
@@ -16,29 +16,8 @@
16
16
  * DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
17
17
  * OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
18
  */
19
- import * as ReactImport from 'react';
20
- import createModuleWithDependencies from './createModuleWithDependencies.js';
19
+ import registerGlobalModuleCreator from './registerGlobalModuleCreator.js';
21
20
 
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
21
  /**
43
22
  * Interprets JavaScript module code from a string and returns the specified export.
44
23
  *
@@ -46,12 +25,16 @@ registerGlobalModuleCreator();
46
25
  * limited access to dependencies. It's designed for dynamic code loading scenarios
47
26
  * where the code comes from a trusted source.
48
27
  *
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
28
+ * @param {string} moduleCode - JavaScript module code to interpret
29
+ * @param {string} exportName - Name of the export to return (defaults to 'default')
30
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - Additional customer-specific dependencies
31
+ * @returns {T | null} The requested module export or null if interpretation fails
52
32
  */
53
- const interpretModuleString = (moduleCode, exportName = 'default') => {
33
+ const interpretModuleString = (moduleCode, exportName = 'default', extraDependenciesConfig) => {
54
34
  try {
35
+ if (!moduleCode)
36
+ return null;
37
+ registerGlobalModuleCreator(extraDependenciesConfig);
55
38
  const compiledModule = eval === null || eval === void 0 ? void 0 : eval(`"use strict"; ${moduleCode}`);
56
39
  if (!compiledModule)
57
40
  return null;
@@ -0,0 +1,7 @@
1
+ import { ExtraDependencyConfig } from '../types';
2
+ /**
3
+ * Registers the module creator in the global scope for use by evaluated code
4
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - extra dependencies config map
5
+ */
6
+ declare const registerGlobalModuleCreator: (extraDependenciesConfig?: Record<string, ExtraDependencyConfig>) => void;
7
+ export default registerGlobalModuleCreator;
@@ -0,0 +1,56 @@
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
+ * @param {Record<string, ExtraDependencyConfig>} extraDependenciesConfig - extra dependencies config map
25
+ */
26
+ const registerGlobalModuleCreator = (extraDependenciesConfig = {}) => {
27
+ const define = (dependencies, moduleFactory) => {
28
+ return createModuleWithDependencies(dependencies, moduleFactory, extraDependenciesConfig);
29
+ };
30
+ const nodeJsEnvironment = typeof process !== 'undefined' &&
31
+ process.versions != null &&
32
+ process.versions.node != null;
33
+ if (nodeJsEnvironment) {
34
+ globalThis.define = define;
35
+ globalThis.React = ReactImport;
36
+ for (const [_, value] of Object.entries(extraDependenciesConfig)) {
37
+ const { module, globalName } = value;
38
+ if (globalName) {
39
+ globalThis[globalName] = module;
40
+ }
41
+ }
42
+ }
43
+ else {
44
+ // We're in a browser or other environment
45
+ window.define = define;
46
+ window.React = ReactImport;
47
+ for (const [_, value] of Object.entries(extraDependenciesConfig)) {
48
+ const { module, globalName } = value;
49
+ if (globalName) {
50
+ window[globalName] = module;
51
+ }
52
+ }
53
+ }
54
+ };
55
+
56
+ export { registerGlobalModuleCreator as default };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ export type ExtraDependencyConfig = {
2
+ module: any;
3
+ globalName?: string;
4
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildit-platform/engine",
3
- "version": "0.1.1",
4
- "description": "Bildit Render Engine",
3
+ "version": "0.1.4",
4
+ "description": "BILDIT Render Engine",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
@@ -24,12 +24,16 @@
24
24
  "dev": "rollup -c -w",
25
25
  "lint": "eslint src/**/*.{ts,tsx}",
26
26
  "clean": "rimraf dist",
27
- "prepare": "npm run build"
27
+ "prepare": "npm run build",
28
+ "test": "jest"
28
29
  },
29
30
  "keywords": [
30
31
  "bildit",
31
32
  "cms",
32
- "nextjs",
33
+ "core",
34
+ "engine",
35
+ "business",
36
+ "logic",
33
37
  "react"
34
38
  ],
35
39
  "author": "BILDIT",
@@ -38,11 +42,13 @@
38
42
  ],
39
43
  "license": "UNLICENSED",
40
44
  "peerDependencies": {
45
+ "next": "^15.0.0",
41
46
  "react": ">=18.0.0",
42
47
  "react-dom": ">=18.0.0"
43
48
  },
44
49
  "devDependencies": {
45
50
  "@rollup/plugin-commonjs": "^24.0.0",
51
+ "@rollup/plugin-json": "^6.1.0",
46
52
  "@rollup/plugin-node-resolve": "^15.0.0",
47
53
  "@rollup/plugin-typescript": "^11.0.0",
48
54
  "@types/jest": "^29.5.14",
@@ -51,9 +57,13 @@
51
57
  "@types/react-dom": ">=18.0.0",
52
58
  "@types/react-is": ">=18.0.0",
53
59
  "eslint": "^8.0.0",
60
+ "jest": "^29.7.0",
61
+ "jest-environment-jsdom": "^29.7.0",
54
62
  "rimraf": "^4.0.0",
55
63
  "rollup": "^3.0.0",
56
64
  "rollup-plugin-peer-deps-external": "^2.2.4",
65
+ "ts-jest": "^29.3.2",
66
+ "tslib": "^2.8.1",
57
67
  "typescript": "^5.0.0"
58
68
  },
59
69
  "dependencies": {