@movable/studio-framework-build-config 2.42.0 → 2.42.1-canary.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movable/studio-framework-build-config",
3
- "version": "2.42.0",
3
+ "version": "2.42.1-canary.0",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Movable Ink",
@@ -14,9 +14,10 @@
14
14
  "@babel/preset-env": "^7.14.1",
15
15
  "@babel/preset-react": "^7.14.5",
16
16
  "@babel/runtime-corejs2": "^7.14.0",
17
- "@movable/rollup-plugin-manifest-merger": "^2.42.0",
18
- "@movable/rollup-plugin-package-manifest-validator": "^2.42.0",
17
+ "@movable/rollup-plugin-manifest-merger": "^2.42.1-canary.0",
18
+ "@movable/rollup-plugin-package-manifest-validator": "^2.42.1-canary.0",
19
19
  "@rollup/plugin-url": "^6.0.0",
20
+ "esbuild": "^0.15.14",
20
21
  "glob": "^7.1.7",
21
22
  "is-docker": "^2.2.1",
22
23
  "karma": "^6.3.4",
@@ -45,5 +46,5 @@
45
46
  "volta": {
46
47
  "extends": "../../package.json"
47
48
  },
48
- "gitHead": "3d01be89a59c8e29dadd204371cca8b3007c591d"
49
+ "gitHead": "451954a037803969425f6bd06db7c1a4fd13883d"
49
50
  }
@@ -0,0 +1,56 @@
1
+ const esbuild = require('esbuild');
2
+ const fs = require('fs').promises;
3
+ const path = require('path');
4
+
5
+ const { SERVE, ENVIRONMENT } = process.env;
6
+
7
+ const loaderHtmlSourceDefault = path.resolve(__dirname, './html/loader.html');
8
+ const loaderDebugHtmlSourceDefault = path.resolve(__dirname, './html/loader-debug.html');
9
+
10
+ function sleep(ms) {
11
+ return new Promise((res) => setTimeout(res, ms));
12
+ }
13
+
14
+ async function waitForFile(filePath) {
15
+ let waitCount = 0;
16
+ while (waitCount < 500) {
17
+ try {
18
+ await fs.stat(filePath);
19
+ break;
20
+ } catch (e) {
21
+ await sleep(200);
22
+ if (++waitCount >= 500) {
23
+ throw e;
24
+ }
25
+ }
26
+ }
27
+ }
28
+
29
+ module.exports = async function buildDataLoader(buildConfig = {}) {
30
+ if (typeof buildConfig !== 'object') {
31
+ // might have passed dataLoader: true; if so, use defaults
32
+ buildConfig = {};
33
+ }
34
+
35
+ // We cannot write to dist before dist/index.js appears, or studio-tunnel will break
36
+ await waitForFile('./dist/index.js');
37
+
38
+ console.log('Copying data loader wrappers: dist/loader.html, dist/loader-debug.html');
39
+
40
+ await fs.copyFile(buildConfig.loaderHtml || loaderHtmlSourceDefault, './dist/loader.html');
41
+ await fs.copyFile(loaderDebugHtmlSourceDefault, './dist/loader-debug.html');
42
+
43
+ console.log('Building data loader: dist/loader.js');
44
+
45
+ esbuild.build({
46
+ entryPoints: ['./app/loader/index.js'],
47
+ outfile: 'dist/loader.js',
48
+ target: 'safari15',
49
+ format: 'esm',
50
+ bundle: true,
51
+ logLevel: 'info',
52
+ minify: ENVIRONMENT === 'production',
53
+ watch: !!SERVE,
54
+ ...buildConfig
55
+ });
56
+ };
@@ -0,0 +1,58 @@
1
+ <!doctype html>
2
+ <html>
3
+ <body>
4
+ <h1>Data Loader Tester</h1>
5
+
6
+ <h2>Result:</h2>
7
+ <div id="result" style="font-family: monospace; white-space: pre-wrap; padding: 20px; background-color: #EEE;"></div>
8
+
9
+ <h2>Query:</h2>
10
+ <textarea id="params" style="width: 100%; min-height: 400px;"></textarea>
11
+ <button id="submit_params" type="button">Submit</button>
12
+
13
+ <script type="module">
14
+ import loader from '../dist/loader.js';
15
+
16
+ const url = new URL(document.location);
17
+
18
+ const paramsInput = document.querySelector("#params");
19
+ let paramsValue = '';
20
+ for (let [key, value] of url.searchParams) {
21
+ paramsValue += `${key}=${value}\n`;
22
+ }
23
+ paramsInput.value = paramsValue;
24
+
25
+ const button = document.querySelector("#submit_params");
26
+ button.onclick = () => {
27
+ let newURL = new URL(url);
28
+ for (let [key, _] of newURL.searchParams) {
29
+ newURL.searchParams.delete(key);
30
+ }
31
+
32
+ const paramsList = paramsInput.value.split("\n").filter(l => l.length);
33
+ for (let line of paramsList) {
34
+ const [key, value] = line.split("=");
35
+ newURL.searchParams.set(key, value);
36
+ }
37
+ window.location = newURL;
38
+ }
39
+
40
+ const result = document.querySelector("#result");
41
+
42
+ async function registerHandler(fn) {
43
+ try {
44
+ const data = await fn(url);
45
+ result.innerText = JSON.stringify(data, null, 2);
46
+ } catch(e) {
47
+ result.innerText = [e.message, e.stack].join('\n');
48
+ throw e;
49
+ }
50
+ }
51
+ registerHandler(loader);
52
+
53
+ export default '';
54
+ </script>
55
+
56
+ <script type="module" src="../dist/loader.js"></script>
57
+ </body>
58
+ </html>
@@ -0,0 +1,22 @@
1
+ <html>
2
+ <body>
3
+ <script id="handler" type="module">
4
+ import loader from './loader.js';
5
+
6
+ if (typeof(window.registerHandler) === 'undefined') {
7
+ console.log("Missing window.registerHandler; setting mock.")
8
+ window.registerHandler = (fn) => fn(new URL(document.location));
9
+ }
10
+
11
+ window.registerHandler(loader);
12
+ </script>
13
+
14
+ <script>
15
+ window.onerror = function catchError(e) {
16
+ console.error(e);
17
+ window.MICapture && MICapture.error("Handler registration failed");
18
+ };
19
+ document.querySelector('#handler').onerror = window.onerror;
20
+ </script>
21
+ </body>
22
+ </html>
@@ -12,6 +12,7 @@ const json = require('rollup-plugin-json');
12
12
  const { manifestMerger } = require('@movable/rollup-plugin-manifest-merger');
13
13
  const { importExportToGlobal, dependenciesOnly } = require('rollup-split-index');
14
14
  const babelrc = require('./babel');
15
+ const buildDataLoader = require('./data-loader');
15
16
 
16
17
  module.exports = function rollupConfig(passedConfig = {}) {
17
18
  const inputFile = 'app/index.js';
@@ -23,6 +24,16 @@ module.exports = function rollupConfig(passedConfig = {}) {
23
24
  ...passedConfig
24
25
  };
25
26
 
27
+ if (passedConfig.dataLoader) {
28
+ const { dataLoader } = passedConfig;
29
+ delete passedConfig.dataLoader;
30
+
31
+ buildDataLoader(dataLoader).catch((error) => {
32
+ console.error(error);
33
+ process.exit(1);
34
+ });
35
+ }
36
+
26
37
  const vendorTree = {
27
38
  input: inputFile,
28
39
  plugins: [