runtime-compiler 1.2.7 → 2.0.1

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,5 +1,17 @@
1
1
  # `runtime-compiler`
2
2
  A code generation system for JS.
3
3
 
4
- `runtime-compiler` combines all code generation process into one `Function` call.
5
- This makes it possible to bypass startup time code generation using ahead of time compilation while also speeds up runtime code generation.
4
+ ## Modes
5
+ - `default`: Build & run.
6
+ - `build`: Build only.
7
+ - `hydrate`: Run only.
8
+
9
+ ```ts
10
+ import { isHydrating, onlyBuild } from 'runtime-compiler/config';
11
+
12
+ // Whether the process is in `hydrate` mode
13
+ isHydrating;
14
+
15
+ // Whether the process is in `build` mode
16
+ onlyBuild;
17
+ ```
@@ -0,0 +1,8 @@
1
+ /**
2
+ * False when in `default` and `build` mode, true in `hydrate` mode
3
+ */
4
+ export declare let isHydrating: boolean;
5
+ /**
6
+ * False when in `default` and `hydrate` mode, true in `build` mode
7
+ */
8
+ export declare let onlyBuild: boolean;
@@ -0,0 +1 @@
1
+ export let isHydrating=false;export let onlyBuild=false;export let hydrating=()=>{isHydrating=true};export let building=()=>{onlyBuild=true};
@@ -0,0 +1 @@
1
+ import{building}from"../index.js";building();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{hydrating}from"../index.js";hydrating();
@@ -1 +1,2 @@
1
1
  export declare const isHydrating: boolean;
2
+ export declare const onlyBuild: boolean;
@@ -0,0 +1 @@
1
+ export let isHydrating=false;export let onlyBuild=true;
@@ -0,0 +1,2 @@
1
+ export declare const isHydrating: boolean;
2
+ export declare const onlyBuild: boolean;
@@ -0,0 +1 @@
1
+ export let isHydrating=true;export let onlyBuild=false;
package/index.d.ts CHANGED
@@ -1,53 +1,76 @@
1
- export type CompiledDependency<T> = number & [T];
1
+ export type LocalDependency<T> = string & [T];
2
+ export type ExportedDependency<T> = number & [T];
2
3
  /**
3
4
  * Inject a local dependency.
5
+ * Use in `default` and `build` mode.
4
6
  */
5
- export declare const injectDependency: (val: string) => string;
7
+ export declare const injectDependency: <T>(val: string) => LocalDependency<T>;
6
8
  /**
7
- * Wait for a dependency to resolve
9
+ * Wait for a dependency to resolve.
10
+ * Use in `default` and `build` mode.
8
11
  * @param name
9
12
  */
10
13
  export declare const waitDependency: (name: string) => void;
11
14
  /**
12
- * Export a local dependency
15
+ * Export a local dependency.
16
+ * Use in `default` and `build` mode.
13
17
  * @param name
14
18
  */
15
- export declare const exportDependency: <T>(name: string) => CompiledDependency<T>;
19
+ export declare const exportDependency: <T>(name: LocalDependency<T>) => ExportedDependency<T>;
16
20
  /**
17
- * Mark a slot in compiled dependencies
21
+ * Mark a slot in compiled dependencies.
22
+ * Use in `hydrate` mode.
18
23
  */
19
- export declare const markExported: <T>() => CompiledDependency<T>;
24
+ export declare const markExported: <T>() => ExportedDependency<T>;
20
25
  /**
21
- * Get the value of a dependency
26
+ * Get the value of a dependency.
22
27
  * @param idx
23
28
  */
24
- export declare const getDependency: <T>(idx: CompiledDependency<T>) => T;
29
+ export declare const getDependency: <T>(idx: ExportedDependency<T>) => T;
25
30
  /**
26
- * Inject an external dependency
31
+ * Inject an external dependency.
27
32
  */
28
33
  export declare const injectExternalDependency: (val: any) => string;
29
34
  /**
30
- * Get external dependency names
35
+ * Get external dependency names.
36
+ * Use in `default` and `build` mode.
31
37
  */
32
38
  export declare const externalDependencyNames: () => string;
33
39
  /**
34
- * Clear compiler data
40
+ * Clear compiler data.
41
+ * Use in `default` and `build` mode.
35
42
  */
36
43
  export declare const clear: () => void;
37
44
  /**
38
- * Clear compiler data in hydration
45
+ * Clear compiler data.
46
+ * Use in `hydrate` mode.
39
47
  */
40
48
  export declare const clearHydration: () => void;
41
49
  /**
42
- * Noop function
50
+ * Lazily add the dependency when needed.
43
51
  */
44
- export declare const noOp: () => string;
52
+ export declare const lazyDependency: <T>(inject: (v: T) => string, val: T) => (() => string);
45
53
  /**
46
- * Lazily add the dependency when needed
54
+ * Get evaluated code.
55
+ * Use in `default` and `build` mode.
47
56
  */
48
- export declare const lazyDependency: <T>(inject: (v: T) => string, val: T) => () => string;
57
+ export declare const evaluateCode: () => string;
49
58
  /**
50
- * Get evaluate code
59
+ * Run hydration.
51
60
  */
52
- export declare const evaluateCode: () => string;
53
- export declare const AsyncFunction: typeof Function;
61
+ export declare const hydrate: () => any[];
62
+ /**
63
+ * Evaluate code to string.
64
+ * Use in `default` and `build` mode.
65
+ */
66
+ export declare const evaluateToString: () => string;
67
+ /**
68
+ * Run evaluated code synchronously.
69
+ * Use in `default` and `build` mode.
70
+ */
71
+ export declare const evaluateSync: () => void;
72
+ /**
73
+ * Run evaluated code asynchronously.
74
+ * Use in `default` and `build` mode.
75
+ */
76
+ export declare const evaluate: () => Promise<void>;
package/index.js CHANGED
@@ -1 +1 @@
1
- export let compiledDependencies=[];export let externalDependencies=[];export let cache={};export let localDeps=``;let localDepsCnt=0;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let asyncDeps=``;export let waitDependency=e=>{asyncDeps+=e+`,`};export let exportedDeps=``;let exportedDepsCnt=0;export let exportDependency=e=>{exportedDeps+=e+`,`;return exportedDepsCnt++};export let markExported=()=>exportedDepsCnt++;export let getDependency=v=>compiledDependencies[v];export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let externalDependencyNames=()=>{let e=`_,`;for(let y=0;y<externalDependencies.length;y++)e+=`_`+(y+1)+`,`;return e};export let clear=()=>{externalDependencies.length=0;cache={};localDeps=``;localDepsCnt=0;asyncDeps=``;exportedDeps=``};export let clearHydration=()=>{externalDependencies.length=0;cache={}};export let noOp=()=>``;export let lazyDependency=(e,v)=>{let b=Symbol();return()=>cache[b]??=e(v)};export let evaluateCode=()=>`{var $`+localDeps+(asyncDeps===``?`;_.push(`:`;[`+asyncDeps+`]=await Promise.all([`+asyncDeps+`]);_.push(`)+exportedDeps+`)}`;export let AsyncFunction=(async()=>{}).constructor;
1
+ import{AsyncFunction}from"./utils.js";export let compiledDependencies=[];export let externalDependencies=[];export let cache={};export let localDeps=``;let localDepsCnt=0;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let asyncDeps=``;export let waitDependency=e=>{asyncDeps+=e+`,`};export let exportedDeps=``;let exportedDepsCnt=0;export let exportDependency=e=>{exportedDeps+=e+`,`;return exportedDepsCnt++};export let markExported=()=>exportedDepsCnt++;export let getDependency=e=>compiledDependencies[e];export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let externalDependencyNames=()=>{let e=`_,`;for(let S=0;S<externalDependencies.length;S++)e+=`_`+(S+1)+`,`;return e};export let clear=()=>{externalDependencies.length=0;cache={};localDeps=``;localDepsCnt=0;asyncDeps=``;exportedDeps=``};export let clearHydration=()=>{externalDependencies.length=0;cache={}};export let lazyDependency=(e,S)=>{let C=Symbol();return()=>cache[C]??=e(S)};export let evaluateCode=()=>`{var $`+localDeps+(asyncDeps===``?`;_.push(`:`;[`+asyncDeps+`]=await Promise.all([`+asyncDeps+`]);_.push(`)+exportedDeps+`)}`;export let hydrate=()=>{let e=[compiledDependencies].concat(externalDependencies);clearHydration();return e};export let evaluateToString=()=>`(`+externalDependencyNames()+`)=>`+evaluateCode();export let evaluateSync=()=>{try{Function(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies)}finally{clear()}};export let evaluate=async()=>AsyncFunction(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies).finally(clear);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-compiler",
3
- "version": "1.2.7",
3
+ "version": "2.0.1",
4
4
  "description": "Universal compiler system",
5
5
  "keywords": [],
6
6
  "repository": {},
@@ -8,11 +8,12 @@
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "exports": {
11
- "./hydrate-config": "./hydrate-config.js",
12
- "./config": "./config.js",
11
+ "./utils": "./utils.js",
12
+ "./config/mode/hydrate": "./config/mode/hydrate.js",
13
+ "./config/mode/build": "./config/mode/build.js",
14
+ "./config/loader/hydrate": "./config/loader/hydrate.js",
15
+ "./config/loader/build": "./config/loader/build.js",
13
16
  ".": "./index.js",
14
- "./hydrate-loader": "./hydrate-loader.js",
15
- "./hydrate": "./hydrate.js",
16
- "./jit": "./jit.js"
17
+ "./config": "./config/index.js"
17
18
  }
18
19
  }
package/utils.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Placeholder for `hydrate` mode.
3
+ */
4
+ export declare const noOp: () => string;
5
+ /**
6
+ * Inject a constant.
7
+ * Use in `default` and `build` mode.
8
+ */
9
+ export declare const injectConst: (val: any) => string;
10
+ /**
11
+ * Inject an argument list.
12
+ * Use in `default` and `build` mode.
13
+ */
14
+ export declare const injectArgsList: (list: any[]) => string;
15
+ /**
16
+ * Async function constructor
17
+ */
18
+ export declare const AsyncFunction: typeof Function;
package/utils.js ADDED
@@ -0,0 +1 @@
1
+ import{injectDependency}from"./index.js";export let noOp=()=>``;export let injectConst=i=>injectDependency(JSON.stringify(i));export let injectArgsList=e=>e.length!==1?`...`+injectConst(e):injectConst(e[0]);export let AsyncFunction=(async()=>{}).constructor;
package/config.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare let isHydrating: boolean;
2
- /**
3
- * @private
4
- */
5
- export declare const hydrating: () => void;
package/config.js DELETED
@@ -1 +0,0 @@
1
- export let isHydrating=false;export let hydrating=()=>{isHydrating=true};
package/hydrate-config.js DELETED
@@ -1 +0,0 @@
1
- export let isHydrating=true;
package/hydrate-loader.js DELETED
@@ -1 +0,0 @@
1
- import{hydrating}from"./config.js";hydrating();
package/hydrate.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const hydrate: () => any[];
package/hydrate.js DELETED
@@ -1 +0,0 @@
1
- import{clearHydration,compiledDependencies,externalDependencies}from"./index.js";export let hydrate=()=>{let r=[compiledDependencies].concat(externalDependencies);clearHydration();return r};
package/jit.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const evaluateToString: () => string;
2
- export declare const evaluateSync: () => void;
3
- export declare const evaluate: () => Promise<void>;
package/jit.js DELETED
@@ -1 +0,0 @@
1
- import{AsyncFunction,clear,compiledDependencies,evaluateCode,externalDependencies,externalDependencyNames}from"./index.js";export let evaluateToString=()=>`(`+externalDependencyNames()+`)=>`+evaluateCode();export let evaluateSync=()=>{try{Function(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies)}finally{clear()}};export let evaluate=async()=>AsyncFunction(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies).finally(clear);