@movable/studio-framework-build-config 3.0.0-canvases.0 → 3.0.0-esmodules.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/.eslintrc.js CHANGED
@@ -1,5 +1,4 @@
1
1
  module.exports = {
2
- extends: ['airbnb-base', 'plugin:prettier/recommended'],
3
2
  parserOptions: {
4
3
  ecmaVersion: 2018,
5
4
  sourceType: 'module'
@@ -11,9 +10,6 @@ module.exports = {
11
10
  overrides: [
12
11
  {
13
12
  files: ['rollup.js', 'karma.js', 'index.js'],
14
- rules: {
15
- '@typescript-eslint/no-var-requires': 'off'
16
- },
17
13
  env: {
18
14
  node: true
19
15
  }
package/package.json CHANGED
@@ -1,54 +1,49 @@
1
1
  {
2
2
  "name": "@movable/studio-framework-build-config",
3
- "version": "3.0.0-canvases.0",
3
+ "version": "3.0.0-esmodules.1",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Movable Ink",
7
7
  "repository": "movableink/studio-apps",
8
8
  "homepage": "https://github.com/movableink/studio-apps#README.md",
9
9
  "main": "src/index.js",
10
- "scripts": {
11
- "lint": "eslint . --ext .js"
12
- },
13
10
  "dependencies": {
14
- "@babel/core": "^7.7.5",
15
- "@babel/plugin-external-helpers": "^7.7.4",
16
- "@babel/plugin-transform-runtime": "^7.7.6",
17
- "@babel/preset-env": "^7.5.4",
18
- "@babel/preset-react": "^7.0.0",
19
- "@babel/runtime-corejs2": "^7.5.4",
20
- "@movable/rollup-plugin-manifest-merger": "^3.0.0-canvases.0",
21
- "glob": "^7.1.6",
22
- "karma": "^4.4.1",
11
+ "@babel/core": "^7.14.0",
12
+ "@babel/plugin-external-helpers": "^7.12.13",
13
+ "@babel/plugin-transform-runtime": "^7.13.15",
14
+ "@babel/preset-env": "^7.20.2",
15
+ "@babel/preset-react": "^7.14.5",
16
+ "@movable/rollup-plugin-manifest-merger": "^2.43.0",
17
+ "@movable/rollup-plugin-package-manifest-validator": "^3.0.0-esmodules.1",
18
+ "@rollup/plugin-url": "^6.0.0",
19
+ "esbuild": "^0.15.14",
20
+ "glob": "^7.1.7",
21
+ "is-docker": "^2.2.1",
22
+ "karma": "^6.3.4",
23
23
  "karma-chrome-launcher": "^3.1.0",
24
- "karma-html2js-preprocessor": "^1.1.0",
25
- "karma-qunit": "^4.0.0",
26
- "karma-rollup-preprocessor": "^7.0.2",
27
- "qunit": "^2.9.3",
28
- "rollup": "^1.27.10",
24
+ "karma-qunit": "^4.1.2",
25
+ "karma-rollup-preprocessor": "7.0.7",
26
+ "postcss": "^8.2.15",
27
+ "qunit": "^2.16.0",
28
+ "rollup": "^2.52.2",
29
29
  "rollup-plugin-babel": "^4.3.3",
30
- "rollup-plugin-babel-minify": "^9.1.1",
30
+ "rollup-plugin-babel-minify": "^10.0.0",
31
31
  "rollup-plugin-commonjs": "^10.1.0",
32
- "rollup-plugin-copy-assets": "^2.0.1",
32
+ "rollup-plugin-copy-assets": "^2.0.3",
33
33
  "rollup-plugin-image": "^1.0.2",
34
34
  "rollup-plugin-json": "^4.0.0",
35
35
  "rollup-plugin-node-resolve": "^5.2.0",
36
- "rollup-plugin-peer-deps-external": "^2.2.0",
37
- "rollup-plugin-postcss": "^2.0.3",
36
+ "rollup-plugin-peer-deps-external": "^2.2.4",
37
+ "rollup-plugin-postcss": "^4.0.0",
38
38
  "rollup-plugin-replace": "^2.2.0",
39
- "rollup-plugin-serve": "^1.0.1",
40
- "rollup-plugin-url": "^3.0.1",
39
+ "rollup-plugin-serve": "^1.1.0",
41
40
  "rollup-split-index": "^1.1.0"
42
41
  },
43
42
  "publishConfig": {
44
43
  "access": "public"
45
44
  },
46
- "devDependencies": {
47
- "eslint": "^6.7.2",
48
- "eslint-config-airbnb-base": "^14.0.0",
49
- "eslint-config-prettier": "^6.7.0",
50
- "eslint-plugin-import": "^2.19.1",
51
- "eslint-plugin-prettier": "^3.1.1"
45
+ "volta": {
46
+ "extends": "../../package.json"
52
47
  },
53
- "gitHead": "13dbb367ccbba108236f1bf0188986df50970877"
48
+ "gitHead": "ea2420f0db42b95a3e1e877da7f2a0c6ac4b0240"
54
49
  }
package/src/apps/babel.js CHANGED
@@ -1,18 +1,14 @@
1
1
  module.exports = {
2
2
  babelrc: false,
3
- runtimeHelpers: true,
4
3
  include: ['app/**', 'tests/**'],
5
4
  presets: [
6
5
  [
7
6
  '@babel/env',
8
7
  {
9
- modules: false
8
+ targets: { safari: '16' },
9
+ bugfixes: true
10
10
  }
11
11
  ],
12
12
  '@babel/react'
13
- ],
14
- plugins: [
15
- '@babel/external-helpers',
16
- ['@babel/transform-runtime', { corejs: 2 }]
17
13
  ]
18
14
  };
@@ -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>
package/src/apps/karma.js CHANGED
@@ -4,40 +4,40 @@ const commonjs = require('rollup-plugin-commonjs');
4
4
  const replace = require('rollup-plugin-replace');
5
5
  const postcss = require('rollup-plugin-postcss');
6
6
  const image = require('rollup-plugin-image');
7
- const manifestMerger = require('@movable/rollup-plugin-manifest-merger');
8
7
  const json = require('rollup-plugin-json');
8
+ const isDocker = require('is-docker');
9
+ const { manifestMerger } = require('@movable/rollup-plugin-manifest-merger');
9
10
  const babelrc = require('./babel');
10
11
 
11
12
  const watchMode = process.env.KARMA_WATCH === 'true';
12
13
 
13
14
  module.exports = function karmaConfig(config) {
14
15
  config.set({
15
- browsers: ['Chrome'],
16
+ browsers: ['ChromeWithConfiguration'],
16
17
  frameworks: ['qunit'],
17
18
  files: ['tests/tests.js'],
18
19
  crossOriginAttribute: false, // otherwise can't load remote scripts
19
20
 
20
21
  preprocessors: {
21
- 'app/index.html': ['html2js'],
22
22
  'tests/tests.js': ['rollup']
23
23
  },
24
24
 
25
- html2jsPreprocessor: {},
25
+ customLaunchers: {
26
+ ChromeWithConfiguration: {
27
+ base: 'ChromeHeadless',
28
+ flags: isDocker() ? ['--no-sandbox'] : []
29
+ }
30
+ },
26
31
 
27
- plugins: [
28
- 'karma-chrome-launcher',
29
- 'karma-html2js-preprocessor',
30
- 'karma-qunit',
31
- 'karma-rollup-preprocessor'
32
- ],
32
+ plugins: ['karma-chrome-launcher', 'karma-qunit', 'karma-rollup-preprocessor'],
33
33
 
34
34
  rollupPreprocessor: {
35
35
  input: 'tests/index.js',
36
36
  context: 'window',
37
37
  plugins: [
38
- manifestMerger(),
38
+ manifestMerger({ output: 'manifest.yml' }),
39
39
  babel(babelrc),
40
- resolve({ jsnext: true, browser: true }),
40
+ resolve(),
41
41
  commonjs(),
42
42
  postcss({
43
43
  modules: false
@@ -9,13 +9,10 @@ const replace = require('rollup-plugin-replace');
9
9
  const copy = require('rollup-plugin-copy-assets');
10
10
  const minify = require('rollup-plugin-babel-minify');
11
11
  const json = require('rollup-plugin-json');
12
- const manifestMerger = require('@movable/rollup-plugin-manifest-merger');
13
- const {
14
- importExportToGlobal,
15
- dependenciesOnly
16
- } = require('rollup-split-index');
17
-
12
+ const { manifestMerger } = require('@movable/rollup-plugin-manifest-merger');
13
+ const { importExportToGlobal, dependenciesOnly } = require('rollup-split-index');
18
14
  const babelrc = require('./babel');
15
+ const buildDataLoader = require('./data-loader');
19
16
 
20
17
  module.exports = function rollupConfig(passedConfig = {}) {
21
18
  const inputFile = 'app/index.js';
@@ -30,8 +27,9 @@ module.exports = function rollupConfig(passedConfig = {}) {
30
27
  const vendorTree = {
31
28
  input: inputFile,
32
29
  plugins: [
30
+ manifestMerger({ output: 'manifest.yml', ignoreFrameworkVersionUpdate: true }),
33
31
  babel(babelrc),
34
- resolve({ jsnext: true, browser: true }),
32
+ resolve(),
35
33
  commonjs(),
36
34
  postcss({
37
35
  modules: false
@@ -45,13 +43,14 @@ module.exports = function rollupConfig(passedConfig = {}) {
45
43
  replace({
46
44
  'process.env.NODE_ENV': JSON.stringify('production')
47
45
  }),
46
+ config.dataLoader ? buildDataLoader(config.dataLoader) : null,
48
47
  config.minify ? minify({ comments: false, sourceMap: true }) : null,
49
- manifestMerger({ output: '../manifest.yml' }),
50
48
  config.serve ? serve() : null
51
49
  ].filter(Boolean),
52
50
  output: {
53
51
  name: 'studioDependencies',
54
- file: 'dist/vendor.js',
52
+ dir: './',
53
+ entryFileNames: 'dist/vendor.js',
55
54
  format: 'iife'
56
55
  }
57
56
  };
@@ -77,7 +76,7 @@ module.exports = function rollupConfig(passedConfig = {}) {
77
76
  const dummyTree = {
78
77
  input: 'app/dummy/dummy.js',
79
78
  plugins: [
80
- manifestMerger(),
79
+ manifestMerger({ output: 'manifest.yml' }),
81
80
  resolve(),
82
81
  postcss({
83
82
  modules: false
@@ -95,7 +94,5 @@ module.exports = function rollupConfig(passedConfig = {}) {
95
94
  }
96
95
  };
97
96
 
98
- return [vendorTree, indexTree, config.includeDummy ? dummyTree : null].filter(
99
- Boolean
100
- );
97
+ return [vendorTree, indexTree, config.includeDummy ? dummyTree : null].filter(Boolean);
101
98
  };
@@ -1,18 +1,14 @@
1
1
  module.exports = {
2
2
  babelrc: false,
3
- runtimeHelpers: true,
4
3
  include: ['src/**', 'tests/**'],
5
4
  presets: [
6
5
  [
7
6
  '@babel/env',
8
7
  {
9
- modules: false
8
+ targets: { safari: '16' },
9
+ bugfixes: true
10
10
  }
11
11
  ],
12
12
  '@babel/react'
13
- ],
14
- plugins: [
15
- '@babel/external-helpers',
16
- ['@babel/transform-runtime', { corejs: 2 }]
17
13
  ]
18
14
  };
@@ -4,23 +4,30 @@ const commonjs = require('rollup-plugin-commonjs');
4
4
  const replace = require('rollup-plugin-replace');
5
5
  const postcss = require('rollup-plugin-postcss');
6
6
  const json = require('rollup-plugin-json');
7
- const url = require('rollup-plugin-url');
7
+ const url = require('@rollup/plugin-url');
8
+ const isDocker = require('is-docker');
8
9
  const babelrc = require('./babel');
9
10
 
10
11
  const watchMode = process.env.KARMA_WATCH === 'true' || true;
11
12
  module.exports = function karmaConfig(config) {
12
13
  config.set({
13
- browsers: ['Chrome'],
14
+ browsers: ['ChromeWithConfiguration'],
14
15
  frameworks: ['qunit'],
15
16
  files: ['tests/tests.js'],
16
17
  crossOriginAttribute: false, // otherwise can't load remote scripts
17
18
 
18
19
  preprocessors: {
19
- 'app/index.html': ['html2js'],
20
20
  'tests/tests.js': ['rollup']
21
21
  },
22
22
 
23
- html2jsPreprocessor: {},
23
+ customLaunchers: {
24
+ ChromeWithConfiguration: {
25
+ base: 'ChromeHeadless',
26
+ flags: isDocker() ? ['--no-sandbox'] : []
27
+ }
28
+ },
29
+
30
+ plugins: ['karma-chrome-launcher', 'karma-qunit', 'karma-rollup-preprocessor'],
24
31
 
25
32
  rollupPreprocessor: {
26
33
  input: 'tests/index.js',
@@ -28,7 +35,7 @@ module.exports = function karmaConfig(config) {
28
35
  plugins: [
29
36
  babel(babelrc),
30
37
  json(),
31
- resolve({ jsnext: true, browser: true }),
38
+ resolve(),
32
39
  commonjs(),
33
40
  postcss({
34
41
  modules: false
@@ -4,27 +4,58 @@ const commonjs = require('rollup-plugin-commonjs');
4
4
  const external = require('rollup-plugin-peer-deps-external');
5
5
  const postcss = require('rollup-plugin-postcss');
6
6
  const json = require('rollup-plugin-json');
7
- const url = require('rollup-plugin-url');
7
+ const url = require('@rollup/plugin-url');
8
+ const replace = require('rollup-plugin-replace');
9
+ const {
10
+ packageBuilder,
11
+ manifestMerger,
12
+ inputFile
13
+ } = require('@movable/rollup-plugin-manifest-merger');
14
+ const { manifestValidatorPlugin } = require('@movable/rollup-plugin-package-manifest-validator');
8
15
  const babelConf = require('./babel');
9
16
 
10
17
  const reactBase = require.resolve('react');
11
18
  const reactDomBase = require.resolve('react-dom');
19
+ const STUDIO_TUNNEL_MODE = !!process.env.STUDIO_TUNNEL_MODE;
12
20
 
13
21
  module.exports = function rollupConfig(pkg) {
14
- return {
15
- input: 'src/index.js',
16
- output: [
17
- {
22
+ if (STUDIO_TUNNEL_MODE) {
23
+ const plugins = [
24
+ babel(babelConf),
25
+ packageBuilder({ entry: 'src/index.js' }),
26
+ manifestMerger({ output: 'manifest.yml', appManifest: 'test-app-manifest.yml' }),
27
+ json(),
28
+ resolve({
29
+ extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx']
30
+ }),
31
+ postcss({
32
+ modules: false
33
+ }),
34
+ commonjs({
35
+ namedExports: {
36
+ [reactBase]: ['Children', 'Component', 'PropTypes', 'createElement'],
37
+ [reactDomBase]: ['render']
38
+ }
39
+ }),
40
+ url({ limit: 1024000 }),
41
+ replace({
42
+ 'process.env.NODE_ENV': JSON.stringify('production')
43
+ })
44
+ ];
45
+
46
+ if (!process.env.SKIP_VALIDATION)
47
+ plugins.splice(1, 0, manifestValidatorPlugin({ manifestPath: 'package-manifest.yml' }));
48
+
49
+ return {
50
+ input: inputFile,
51
+ output: {
18
52
  file: pkg.main,
19
- exports: 'named',
20
- format: 'cjs'
53
+ format: 'iife'
21
54
  },
22
- {
23
- file: pkg.module,
24
- format: 'es'
25
- }
26
- ],
27
- plugins: [
55
+ plugins
56
+ };
57
+ } else {
58
+ const plugins = [
28
59
  babel(babelConf),
29
60
  json(),
30
61
  resolve({
@@ -41,6 +72,25 @@ module.exports = function rollupConfig(pkg) {
41
72
  }),
42
73
  url({ limit: 1024000 }),
43
74
  external()
44
- ]
45
- };
75
+ ];
76
+
77
+ if (!process.env.SKIP_VALIDATION)
78
+ plugins.splice(1, 0, manifestValidatorPlugin({ manifestPath: 'package-manifest.yml' }));
79
+
80
+ return {
81
+ output: [
82
+ {
83
+ file: pkg.main,
84
+ exports: 'named',
85
+ format: 'cjs'
86
+ },
87
+ {
88
+ file: pkg.module,
89
+ format: 'es'
90
+ }
91
+ ],
92
+ input: 'src/index.js',
93
+ plugins
94
+ };
95
+ }
46
96
  };
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- node_modules/*