@patternslib/dev 2.7.1 → 3.0.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/CHANGES.md CHANGED
@@ -2,6 +2,45 @@
2
2
 
3
3
 
4
4
 
5
+ ## [3.0.0](https://github.com/patternslib/dev/compare/2.7.2...3.0.0) (2022-10-15)
6
+
7
+
8
+ ### Features
9
+
10
+
11
+ * **Build:** Add Module Federation configuration for webpack. ([b84c2fb](https://github.com/patternslib/dev/commit/b84c2fb8053837206c044e3148522d9a54afa300))
12
+
13
+
14
+ ### Breaking Changes
15
+
16
+
17
+ * **Build:** Remove the showdown-prettify loading config and the now unused imports-loader. ([27ba90f](https://github.com/patternslib/dev/commit/27ba90fc9e615c57b4be0ae20b84c2f16a918759))
18
+
19
+ * **Tests:** Remove dependency on jQuery. ([259d801](https://github.com/patternslib/dev/commit/259d801ab0a203ea64073e3cc0366976a38f1e0c))Use the following in your test setup to provide jQuery to external
20
+ libraries if they depend on a global jQuery object or extend from the
21
+ jest config from @patternslib/patternslib:
22
+
23
+ ```js
24
+ import jquery from "jquery";
25
+ global.$ = global.jQuery = jquery;
26
+ ```
27
+
28
+ * **Tests:** Remove the Dependency on @patternslib/patternslib. ([afe8fee](https://github.com/patternslib/dev/commit/afe8feec6304d2ce184afd587d429f3ae5bd533c))If you need Patternslib specific test setup, extend from Patternslib.
29
+
30
+
31
+ ### Maintenance
32
+
33
+
34
+ * Upgrade dependencies. ([f868454](https://github.com/patternslib/dev/commit/f868454982447190e968ab9eab4988bfee01c43a))
35
+
36
+ ## [2.7.2](https://github.com/patternslib/dev/compare/2.7.1...2.7.2) (2022-09-28)
37
+
38
+
39
+ ### Maintenance
40
+
41
+
42
+ * Upgrade dependencies. ([1edd750](https://github.com/patternslib/dev/commit/1edd7508ff8571110c00939f29843ab9a99986d5))
43
+
5
44
  ## [2.7.1](https://github.com/patternslib/dev/compare/2.7.0...2.7.1) (2022-09-20)
6
45
 
7
46
 
@@ -2,15 +2,6 @@
2
2
  import "core-js/stable";
3
3
  import "regenerator-runtime/runtime";
4
4
 
5
- import jquery from "jquery";
6
- global.$ = global.jQuery = jquery;
7
-
8
- jquery.expr.pseudos.visible = function () {
9
- // Fix jQuery ":visible" selector always returns false in JSDOM.
10
- // https://github.com/jsdom/jsdom/issues/1048#issuecomment-401599392
11
- return true;
12
- };
13
-
14
5
  // pat-fullscreen
15
6
  document.requestFullscreen = jest.fn();
16
7
  document.exitFullscreen = jest.fn();
@@ -67,17 +58,6 @@ global.IntersectionObserver = class IntersectionObserver {
67
58
  }
68
59
  };
69
60
 
70
- // Do not output error messages
71
- import logging from "@patternslib/patternslib/src/core/logging";
72
- logging.setLevel(50); // level: FATAL
73
-
74
- // patch dom.is_visible to not rely on jest-unavailable offsetWidth/Height but
75
- // simply on el.hidden.
76
- import dom from "@patternslib/patternslib/src/core/dom";
77
- dom.is_visible = (el) => {
78
- return !el.hidden;
79
- };
80
-
81
61
  // jsDOM does not add ``getClientRects`` or ``getBoundingClientRect`` to a ``document.createRange()``
82
62
  // Originally from pat-tiptap to allow scroloing into the view when focusing the editor.
83
63
  Range.prototype.getClientRects = () => [];
package/package.json CHANGED
@@ -1,31 +1,30 @@
1
1
  {
2
2
  "name": "@patternslib/dev",
3
- "version": "2.7.1",
3
+ "version": "3.0.0",
4
4
  "description": "Development base files for working with Patternslib and add-ons.",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@babel/core": "^7.19.1",
7
+ "@babel/core": "^7.19.3",
8
8
  "@babel/eslint-parser": "^7.19.1",
9
- "@babel/preset-env": "^7.19.1",
9
+ "@babel/preset-env": "^7.19.4",
10
10
  "@commitlint/cli": "^17.1.2",
11
11
  "@commitlint/config-conventional": "^17.1.0",
12
- "@release-it/conventional-changelog": "^5.1.0",
12
+ "@release-it/conventional-changelog": "^5.1.1",
13
13
  "babel-loader": "^8.2.5",
14
- "core-js": "3.25.2",
14
+ "core-js": "3.25.5",
15
15
  "css-loader": "^6.7.1",
16
- "eslint": "^8.23.1",
16
+ "eslint": "^8.25.0",
17
17
  "eslint-config-prettier": "^8.5.0",
18
18
  "husky": "^8.0.1",
19
19
  "identity-obj-proxy": "^3.0.0",
20
- "imports-loader": "^4.0.1",
21
- "jest": "^29.0.3",
22
- "jest-environment-jsdom": "^29.0.3",
20
+ "jest": "^29.2.0",
21
+ "jest-environment-jsdom": "^29.2.0",
23
22
  "jest-watch-typeahead": "^2.2.0",
24
23
  "prettier": "^2.7.1",
25
- "regenerator-runtime": "^0.13.9",
26
- "release-it": "^15.4.2",
27
- "sass": "^1.54.9",
28
- "sass-loader": "^13.0.2",
24
+ "regenerator-runtime": "^0.13.10",
25
+ "release-it": "^15.5.0",
26
+ "sass": "^1.55.0",
27
+ "sass-loader": "^13.1.0",
29
28
  "style-loader": "^3.3.0",
30
29
  "terser-webpack-plugin": "^5.3.6",
31
30
  "timezone-mock": "^1.3.4",
@@ -36,10 +35,6 @@
36
35
  "whybundled": "^2.0.0",
37
36
  "yarn": "^1.22.19"
38
37
  },
39
- "devDependencies": {
40
- "@patternslib/patternslib": "*",
41
- "jquery": "^3.6.1"
42
- },
43
38
  "scripts": {
44
39
  "test": "jest"
45
40
  },
@@ -0,0 +1,40 @@
1
+ // Author: Manfred Steyer <manfred.steyer@gmx.net>
2
+ // Author: Johannes Raggam <thetetet@gmail.com>
3
+
4
+ // From:
5
+ // https://github.com/manfredsteyer/plugin-demo.git
6
+ // https://github.com/thet/module-federation-minimaltest.git
7
+
8
+ /**
9
+ * Load remote module / bundle.
10
+ *
11
+ * Wrapper around webpack runtime API
12
+ *
13
+ * Usage: get_container("bundle-name-xyz")
14
+ *
15
+ * @param {string} remote - the remote global name
16
+ * @returns {Promise<object>} - Federated Module Container
17
+ */
18
+ const container_map = {};
19
+ let is_default_scope_initialized = false;
20
+
21
+ export default async function get_container(remote) {
22
+ const container = window[remote];
23
+
24
+ // Do we still need to initialize the remote?
25
+ if (container_map[remote]) {
26
+ return container;
27
+ }
28
+
29
+ // Do we still need to initialize the shared scope?
30
+ if (!is_default_scope_initialized) {
31
+ await __webpack_init_sharing__("default"); // eslint-disable-line no-undef
32
+ is_default_scope_initialized = true;
33
+ }
34
+
35
+ await container.init(__webpack_share_scopes__.default); // eslint-disable-line no-undef
36
+
37
+ // Remember that the container has been initialized.
38
+ container_map[remote] = true;
39
+ return container;
40
+ }
@@ -0,0 +1,71 @@
1
+ // Author: ScriptedAlchemy <zackary.l.jackson@gmail.com>
2
+ // Author: Johannes Raggam <thetetet@gmail.com>
3
+
4
+ // From:
5
+ // https://twitter.com/ScriptedAlchemy/status/1505135006158532612
6
+ // https://gist.github.com/ScriptedAlchemy/3a24008ef60adc47fad1af7d3299a063
7
+ // https://github.com/module-federation/module-federation-examples/blob/master/dynamic-system-host/app1/src/utils/getOrLoadRemote.js
8
+
9
+ /**
10
+ * Load remote module / bundle.
11
+ *
12
+ * Usage: get_container("bundle-name-xyz", "default", "http://theRemote.com")
13
+ *
14
+ *
15
+ * @param {string} remote - the remote global name
16
+ * @param {string} share_scope - the scope key
17
+ * @param {string} remote_fallback_url - fallback url for remote module
18
+ * @returns {Promise<object>} - Federated Module Container
19
+ */
20
+ export default function get_container(
21
+ remote,
22
+ share_scope = "default",
23
+ remote_fallback_url = undefined
24
+ ) {
25
+ new Promise((resolve, reject) => {
26
+ if (!window[remote]) {
27
+ // Remote not yet globally available.
28
+
29
+ // onload hook when Module Federated resource is loaded.
30
+ const onload = async () => {
31
+ // When remote is loaded, initialize it if it wasn't already.
32
+ if (!window[remote].__initialized) {
33
+ await window[remote].init(__webpack_share_scopes__[share_scope]); // eslint-disable-line no-undef
34
+ // Mark remote as initialized.
35
+ window[remote].__initialized = true;
36
+ }
37
+ // Resolve promise so marking remote as loaded.
38
+ resolve(window[remote]);
39
+ };
40
+
41
+ // Search dom to see if the remote exists as script tag.
42
+ // It might still be loading (async).
43
+ const existing_remote = document.querySelector(`[data-webpack="${remote}"]`);
44
+
45
+ if (existing_remote) {
46
+ // If remote exists but was not loaded, hook into its onload
47
+ // and wait for it to be ready.
48
+ existing_remote.onload = onload;
49
+ existing_remote.onerror = reject;
50
+ } else if (remote_fallback_url) {
51
+ // Inject remote if a fallback exists and call the same onload
52
+ // function
53
+ const script = document.createElement("script");
54
+ script.type = "text/javascript";
55
+ // Mark as data-webpack so runtime can track it internally.
56
+ script.setAttribute("data-webpack", `${remote}`);
57
+ script.async = true;
58
+ script.onerror = reject;
59
+ script.onload = onload;
60
+ script.src = remote_fallback_url;
61
+ document.getElementsByTagName("head")[0].appendChild(script);
62
+ } else {
63
+ // No remote and no fallback exist, reject.
64
+ reject(`Cannot Find Remote ${remote} to inject`);
65
+ }
66
+ } else {
67
+ // Remote already instantiated, resolve
68
+ resolve(window[remote]);
69
+ }
70
+ });
71
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Initialize dynamic module federation.
3
+ */
4
+ import get_container from "./module_federation--dynamic-federation";
5
+
6
+ // Patternslib Module Federation bundle prefix.
7
+ // This is used to filter for module federation enabled bundles.
8
+ // NOTE: This is also defined in ``webpack.mf.js``.
9
+ export const MF_NAME_PREFIX = "__patternslib_mf__";
10
+
11
+ if (typeof window.__patternslib_container_map === "undefined") {
12
+ window.__patternslib_container_map = {};
13
+ }
14
+ const container_map = window.__patternslib_container_map;
15
+
16
+ export async function initialize_remote({ remote_name, exposed_module = "./main" }) {
17
+ if (container_map[`${remote_name}-${exposed_module}`]) {
18
+ // already initialized, return.
19
+ return;
20
+ }
21
+ const container = await get_container(remote_name);
22
+ const factory = await container.get(exposed_module);
23
+ const module = factory();
24
+
25
+ container_map[`${remote_name}-${exposed_module}`] = true;
26
+
27
+ console.debug(
28
+ `Patternslib Module Federation: Loaded and initialized bundle "${remote_name}".`
29
+ );
30
+
31
+ return module;
32
+ }
33
+
34
+ function document_ready(fn) {
35
+ // see if DOM is already available
36
+ if (document.readyState === "complete" || document.readyState === "interactive") {
37
+ // call on next available tick
38
+ setTimeout(fn, 1);
39
+ } else {
40
+ document.addEventListener("DOMContentLoaded", fn);
41
+ }
42
+ }
43
+
44
+ document_ready(function () {
45
+ // Automatically initialize all Module Federation enabled Patternslib based
46
+ // bundles by filtering for the prefix ``__patternslib_mf__``.
47
+ // Do this on document ready, as this is the time where all MF bundles have
48
+ // been registered in the global namespace.
49
+ const bundles = Object.keys(window).filter((it) => it.indexOf(MF_NAME_PREFIX) === 0);
50
+ for (const bundle_name of bundles) {
51
+ // Now load + initialize each bundle.
52
+ initialize_remote({ remote_name: bundle_name });
53
+ }
54
+ document.dispatchEvent(
55
+ new Event("patternslib__mf--loaded", { bubbles: true, cancelable: false })
56
+ );
57
+ });
@@ -54,14 +54,6 @@ const config_factory = (env, argv, config, babel_include = [], package_json) =>
54
54
  exclude: new RegExp(babel_exclude),
55
55
  loader: "babel-loader",
56
56
  },
57
- {
58
- test: /showdown-prettify/,
59
- use: [
60
- {
61
- loader: "imports-loader?showdown,google-code-prettify",
62
- },
63
- ],
64
- },
65
57
  {
66
58
  test: /\.(?:sass|scss|css)$/i,
67
59
  use: [