@movable/studio-framework-build-config 2.42.0 → 2.43.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.43.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.43.0",
18
+ "@movable/rollup-plugin-package-manifest-validator": "^2.43.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": "463c301a85be7f9a36d1695be3f4de3c75721d29"
49
50
  }
@@ -0,0 +1,62 @@
1
+ const esbuild = require('esbuild');
2
+ const fs = require('fs').promises;
3
+ const path = require('path');
4
+
5
+ const { 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
+ async function buildDataLoader(watchMode = false, buildConfig = {}) {
11
+ if (typeof buildConfig !== 'object') {
12
+ // might have passed dataLoader: true; if so, use defaults
13
+ buildConfig = {};
14
+ }
15
+
16
+ console.log('Copying data loader wrappers: dist/loader.html, dist/loader-debug.html');
17
+
18
+ await fs.copyFile(buildConfig.loaderHtml || loaderHtmlSourceDefault, './dist/loader.html');
19
+ await fs.copyFile(loaderDebugHtmlSourceDefault, './dist/loader-debug.html');
20
+
21
+ console.log('Building data loader: dist/loader.js');
22
+
23
+ if (watchMode) {
24
+ console.log('Watching for changes to data loader');
25
+ }
26
+
27
+ esbuild.build({
28
+ entryPoints: ['./app/loader/index.js'],
29
+ outfile: 'dist/loader.js',
30
+ target: 'safari15',
31
+ format: 'esm',
32
+ bundle: true,
33
+ logLevel: 'info',
34
+ minify: ENVIRONMENT === 'production',
35
+ watch: watchMode,
36
+ ...buildConfig
37
+ });
38
+ }
39
+
40
+ // Only invoke the first time rollup runs
41
+ let dataLoaderBuilt = false;
42
+
43
+ module.exports = function buildDataLoaderPlugin(options = {}) {
44
+ return {
45
+ name: 'build-data-loader',
46
+ closeBundle() {
47
+ if (dataLoaderBuilt) {
48
+ // closeBundle happens on every build; we only invoke esbuild the first time and
49
+ // it watches its own changes
50
+ return;
51
+ }
52
+
53
+ const { watchMode } = this.meta;
54
+ dataLoaderBuilt = true;
55
+
56
+ buildDataLoader(watchMode, options.dataLoader).catch((error) => {
57
+ console.error(error);
58
+ dataLoaderBuilt = false;
59
+ });
60
+ }
61
+ };
62
+ };
@@ -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';
@@ -42,6 +43,7 @@ module.exports = function rollupConfig(passedConfig = {}) {
42
43
  replace({
43
44
  'process.env.NODE_ENV': JSON.stringify('production')
44
45
  }),
46
+ config.dataLoader ? buildDataLoader(config.dataLoader) : null,
45
47
  config.minify ? minify({ comments: false, sourceMap: true }) : null,
46
48
  config.serve ? serve() : null
47
49
  ].filter(Boolean),