@squiz/render-runtime-lib 1.2.1-alpha.60

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.
Files changed (38) hide show
  1. package/README.md +11 -0
  2. package/lib/component-runner/component-runner.spec.d.ts +1 -0
  3. package/lib/component-runner/index.d.ts +19 -0
  4. package/lib/component-runner/worker/WorkerPool.d.ts +50 -0
  5. package/lib/component-runner/worker/getRuntimeModules.d.ts +1 -0
  6. package/lib/component-runner/worker/worker-root.d.ts +1 -0
  7. package/lib/index.d.ts +9 -0
  8. package/lib/index.js +63783 -0
  9. package/lib/index.js.map +7 -0
  10. package/lib/render-runtime-lib.spec.d.ts +1 -0
  11. package/lib/test/helpers/fixtures.d.ts +6 -0
  12. package/lib/test/helpers/stack.d.ts +2 -0
  13. package/lib/utils/convertFunctionStaticFilesToFqdn.d.ts +1 -0
  14. package/lib/utils/log.d.ts +3 -0
  15. package/lib/webserver/app.d.ts +2 -0
  16. package/lib/webserver/controllers/core.d.ts +3 -0
  17. package/lib/webserver/controllers/definition.d.ts +3 -0
  18. package/lib/webserver/controllers/definition.spec.d.ts +1 -0
  19. package/lib/webserver/controllers/index.d.ts +4 -0
  20. package/lib/webserver/controllers/render.d.ts +3 -0
  21. package/lib/webserver/controllers/render.spec.d.ts +1 -0
  22. package/lib/webserver/controllers/static.d.ts +3 -0
  23. package/lib/webserver/controllers/static.spec.d.ts +1 -0
  24. package/lib/webserver/index.d.ts +15 -0
  25. package/lib/worker/bridge.js +1000 -0
  26. package/lib/worker/compiler.js +87 -0
  27. package/lib/worker/events.js +977 -0
  28. package/lib/worker/nodevm.js +503 -0
  29. package/lib/worker/resolver-compat.js +342 -0
  30. package/lib/worker/resolver.js +882 -0
  31. package/lib/worker/script.js +388 -0
  32. package/lib/worker/setup-node-sandbox.js +464 -0
  33. package/lib/worker/setup-sandbox.js +453 -0
  34. package/lib/worker/transformer.js +176 -0
  35. package/lib/worker/vm.js +539 -0
  36. package/lib/worker/worker-root.js +40146 -0
  37. package/lib/worker/worker-root.js.map +7 -0
  38. package/package.json +55 -0
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ VMError
5
+ } = require('./bridge');
6
+
7
+ let cacheCoffeeScriptCompiler;
8
+
9
+ /**
10
+ * Returns the cached coffee script compiler or loads it
11
+ * if it is not found in the cache.
12
+ *
13
+ * @private
14
+ * @return {compileCallback} The coffee script compiler.
15
+ * @throws {VMError} If the coffee-script module can't be found.
16
+ */
17
+ function getCoffeeScriptCompiler() {
18
+ if (!cacheCoffeeScriptCompiler) {
19
+ try {
20
+ // The warning generated by webpack can be disabled by setting:
21
+ // ignoreWarnings[].message = /Can't resolve 'coffee-script'/
22
+ /* eslint-disable-next-line global-require */
23
+ const coffeeScript = require('coffee-script');
24
+ cacheCoffeeScriptCompiler = (code, filename) => {
25
+ return coffeeScript.compile(code, {header: false, bare: true});
26
+ };
27
+ } catch (e) {
28
+ throw new VMError('Coffee-Script compiler is not installed.');
29
+ }
30
+ }
31
+ return cacheCoffeeScriptCompiler;
32
+ }
33
+
34
+ /**
35
+ * Remove the shebang from source code.
36
+ *
37
+ * @private
38
+ * @param {string} code - Code from which to remove the shebang.
39
+ * @return {string} code without the shebang.
40
+ */
41
+ function removeShebang(code) {
42
+ if (!code.startsWith('#!')) return code;
43
+ return '//' + code.substring(2);
44
+ }
45
+
46
+
47
+ /**
48
+ * The JavaScript compiler, just a identity function.
49
+ *
50
+ * @private
51
+ * @type {compileCallback}
52
+ * @param {string} code - The JavaScript code.
53
+ * @param {string} filename - Filename of this script.
54
+ * @return {string} The code.
55
+ */
56
+ function jsCompiler(code, filename) {
57
+ return removeShebang(code);
58
+ }
59
+
60
+ /**
61
+ * Look up the compiler for a specific name.
62
+ *
63
+ * @private
64
+ * @param {(string|compileCallback)} compiler - A compile callback or the name of the compiler.
65
+ * @return {compileCallback} The resolved compiler.
66
+ * @throws {VMError} If the compiler is unknown or the coffee script module was needed and couldn't be found.
67
+ */
68
+ function lookupCompiler(compiler) {
69
+ if ('function' === typeof compiler) return compiler;
70
+ switch (compiler) {
71
+ case 'coffeescript':
72
+ case 'coffee-script':
73
+ case 'cs':
74
+ case 'text/coffeescript':
75
+ return getCoffeeScriptCompiler();
76
+ case 'javascript':
77
+ case 'java-script':
78
+ case 'js':
79
+ case 'text/javascript':
80
+ return jsCompiler;
81
+ default:
82
+ throw new VMError(`Unsupported compiler '${compiler}'.`);
83
+ }
84
+ }
85
+
86
+ exports.removeShebang = removeShebang;
87
+ exports.lookupCompiler = lookupCompiler;