@patternslib/dev 2.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/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ [*]
2
+ charset = utf-8
3
+ end_of_line = lf
4
+ indent_style = space
5
+ insert_final_newline = true
6
+ trim_trailing_whitespace = true
7
+
8
+ [*{js,jsx,vue,ts,json}]
9
+ indent_size = 4
10
+
11
+ [*.{css,scss,xml,html,yml}]
12
+ indent_size = 2
13
+
14
+ [Makefile]
15
+ indent_style = tab
package/.eslintrc.js ADDED
@@ -0,0 +1,28 @@
1
+ module.exports = {
2
+ extends: ["eslint:recommended", "prettier"],
3
+ root: true,
4
+ env: {
5
+ es6: "true",
6
+ browser: true,
7
+ node: true,
8
+ jest: true,
9
+ },
10
+ parser: "@babel/eslint-parser",
11
+ ignorePatterns: [
12
+ "cache/",
13
+ "coverage/",
14
+ "dist/",
15
+ "node_modules/",
16
+ "stats.json",
17
+ "style/",
18
+ ],
19
+ rules: {
20
+ "no-debugger": 1,
21
+ "no-duplicate-imports": 1,
22
+ // Do keep due avoid unintendet consequences.
23
+ "no-alert": 0,
24
+ "no-control-regex": 0,
25
+ "no-self-assign": 0,
26
+ "no-useless-escape": 0,
27
+ },
28
+ };
package/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ CHANGES.md merge=union
@@ -0,0 +1,19 @@
1
+ name: test
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ branches:
8
+ - master
9
+ jobs:
10
+ build:
11
+ name: test
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-node@v2
16
+ with:
17
+ node-version: '14'
18
+ cache: 'yarn'
19
+ - run: make check
@@ -0,0 +1,6 @@
1
+ cache/
2
+ coverage/
3
+ dist/
4
+ node_modules/
5
+ stats.json
6
+ style/
package/.release-it.js ADDED
@@ -0,0 +1,50 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const commits_template = fs
5
+ .readFileSync(
6
+ path.resolve(__dirname, "release-it", "conventional-changelog-commit.hbs")
7
+ )
8
+ .toString();
9
+
10
+ module.exports = {
11
+ npm: {
12
+ publish: true,
13
+ },
14
+ git: {
15
+ requireBranch: ["master", "main"],
16
+ commitMessage: "Release new version.",
17
+ commitArgs: ["-n"],
18
+ },
19
+ plugins: {
20
+ "@release-it/conventional-changelog": {
21
+ infile: "CHANGES.md",
22
+ header: "# Changelog\n\n",
23
+ ignoreRecommendedBump: true,
24
+ preset: {
25
+ name: "conventionalcommits",
26
+ types: [
27
+ {
28
+ type: "breaking",
29
+ section: "Breaking Changes",
30
+ },
31
+ {
32
+ type: "feat",
33
+ section: "Features",
34
+ },
35
+ {
36
+ type: "fix",
37
+ section: "Bug Fixes",
38
+ },
39
+ {
40
+ type: "maint",
41
+ section: "Maintenance",
42
+ },
43
+ ],
44
+ },
45
+ writerOpts: {
46
+ commitPartial: commits_template,
47
+ },
48
+ },
49
+ },
50
+ };
package/CHANGES.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+
4
+
5
+ ## 2.0.0 (2022-06-15)
6
+
7
+
8
+ ### Maintenance
9
+
10
+
11
+ * Add test script to package.json. ([55e8a8b](https://github.com/patternslib/dev/commit/55e8a8b00a645b9c3ff1d2f395ee2170c9f64bfb))
12
+
13
+ * Allow releases from master and from main branches. ([f4f9528](https://github.com/patternslib/dev/commit/f4f952893a67c790bd1d14a151e62e9c84aff4ea))
14
+
15
+ * Configure commitlint for extendability. ([6488bba](https://github.com/patternslib/dev/commit/6488bbac33e82d713a7d14cf7c94e6206f957983))
16
+
17
+ * Configure dependencies. ([4db723d](https://github.com/patternslib/dev/commit/4db723dedd245f2c71fe9367b7f82bec1179c024))Use dependencies field in package.json to install all development dependencies.
18
+ This way, when another package depends on it via ``devDependencies``,
19
+ all dependencies will be installed.
20
+
21
+ * Configure jest for extendability. ([f4eeb3c](https://github.com/patternslib/dev/commit/f4eeb3cdbe63e63c3d7f9a79dd6f66759837a417))
22
+
23
+ * Configure prettier for extendability. ([0f27162](https://github.com/patternslib/dev/commit/0f2716286fff157b66a7d6e16b1048d35e00b6f2))
24
+
25
+ * Configure release-it for extendability. ([4aedd68](https://github.com/patternslib/dev/commit/4aedd68faea2a6b7a56850ce07e28e03af367b6a))
26
+
27
+ * Configure webpack for extendability. ([f805856](https://github.com/patternslib/dev/commit/f805856274ccae9f3cad17186dbf5029f8524b9c))
28
+
29
+ * Initial dev setup, based on @patternslib/patternslib. ([12968fb](https://github.com/patternslib/dev/commit/12968fb0c9ee8d0b858acc88d8d3077a70cfa6d2))
30
+
31
+ * Upgrade dependencies. ([134295d](https://github.com/patternslib/dev/commit/134295d67fe7c479c73c7878fd1d3ef0a07e5a83))
package/Makefile ADDED
@@ -0,0 +1,98 @@
1
+ -include .env
2
+ export
3
+
4
+ ESLINT ?= npx eslint
5
+ YARN ?= npx yarn
6
+
7
+
8
+ .PHONY: install
9
+ stamp-yarn install:
10
+ $(YARN) install
11
+ # Install pre commit hook
12
+ $(YARN) husky install
13
+ touch stamp-yarn
14
+
15
+
16
+ clean-dist:
17
+ rm -Rf dist/
18
+
19
+
20
+ .PHONY: clean
21
+ clean: clean-dist
22
+ rm -f stamp-yarn
23
+ rm -Rf node_modules/
24
+
25
+
26
+ .PHONY: eslint
27
+ eslint: stamp-yarn
28
+ $(ESLINT) ./src
29
+
30
+
31
+ .PHONY: check
32
+ check:: stamp-yarn eslint
33
+ $(YARN) run test
34
+
35
+
36
+ .PHONY: bundle
37
+ bundle: stamp-yarn
38
+ $(YARN) run build
39
+
40
+
41
+ # If you want to release on GitHub, make sure to have a .env file with a GITHUB_TOKEN.
42
+ # Also see:
43
+ # https://github.com/settings/tokens
44
+ # and https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated
45
+
46
+
47
+ release-zip: clean-dist bundle
48
+ $(eval PACKAGE_NAME := $(subst @patternslib/,,$(shell node -p "require('./package.json').name")))
49
+ $(eval PACKAGE_VERSION := $(shell node -p "require('./package.json').version"))
50
+ @echo name is $(PACKAGE_NAME)
51
+ @echo version is $(PACKAGE_VERSION)
52
+ mkdir -p dist/$(PACKAGE_NAME)-bundle-$(PACKAGE_VERSION)
53
+ -mv dist/* dist/$(PACKAGE_NAME)-bundle-$(PACKAGE_VERSION)
54
+ cd dist/ && zip -r $(PACKAGE_NAME)-bundle-$(PACKAGE_VERSION).zip $(PACKAGE_NAME)-bundle-$(PACKAGE_VERSION)/
55
+
56
+
57
+ .PHONY: release-major
58
+ release-major: check
59
+ npx release-it major && \
60
+ make release-zip && \
61
+ npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
62
+ git checkout CHANGES.md
63
+
64
+ .PHONY: release-minor
65
+ release-minor: check
66
+ npx release-it minor && \
67
+ make release-zip && \
68
+ npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
69
+ git checkout CHANGES.md
70
+
71
+ .PHONY: release-patch
72
+ release-patch: check
73
+ npx release-it patch && \
74
+ make release-zip && \
75
+ npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
76
+ git checkout CHANGES.md
77
+
78
+ .PHONY: prerelease-alpha
79
+ prerelease-alpha: clean install
80
+ npx release-it --preRelease=alpha && \
81
+ make release-zip && \
82
+ npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
83
+ git checkout CHANGES.md
84
+
85
+ .PHONY: prerelease-beta
86
+ prerelease-beta: clean install
87
+ npx release-it --preRelease=beta && \
88
+ make release-zip && \
89
+ npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
90
+ git checkout CHANGES.md
91
+
92
+
93
+ .PHONY: serve
94
+ serve: stamp-yarn
95
+ $(YARN) run start
96
+
97
+
98
+ #
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Development helpers and config for Patternslib and add-ons.
2
+
3
+ ## Code style
4
+
5
+ The release process based on release-it includes automatic changelog generation via conventional-commit, commitlint and a pre-commit hook by husky.
6
+ Please check the [code style guide](https://github.com/Patternslib/Patterns/blob/master/docs/developer/styleguide.md#commits-messages) for the commit specification!
7
+
@@ -0,0 +1,34 @@
1
+ module.exports = (env) => {
2
+ let config = {
3
+ presets: [
4
+ [
5
+ "@babel/preset-env",
6
+ {
7
+ useBuiltIns: "entry",
8
+ corejs: 3,
9
+ },
10
+ ],
11
+ ],
12
+ };
13
+
14
+ // passed via NODE_ENV=development environment variable.
15
+ if (env.env() === "development") {
16
+ // For development, do less transformations for better readability.
17
+ config = {
18
+ presets: [
19
+ [
20
+ "@babel/preset-env",
21
+ {
22
+ modules: false,
23
+ debug: true,
24
+ useBuiltIns: false,
25
+ targets: "last 1 Chrome version, last 1 Firefox version",
26
+ },
27
+ ],
28
+ ],
29
+ plugins: ["@babel/plugin-proposal-optional-chaining"],
30
+ };
31
+ }
32
+
33
+ return config;
34
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ parserPreset: "conventional-changelog-conventionalcommits",
3
+ rules: {
4
+ "body-leading-blank": [1, "always"],
5
+ "footer-leading-blank": [1, "always"],
6
+ "subject-empty": [2, "never"],
7
+ "type-case": [2, "always", "lower-case"],
8
+ "type-empty": [2, "never"],
9
+ "type-enum": [2, "always", ["feat", "fix", "maint", "breaking"]],
10
+ },
11
+ };
@@ -0,0 +1,9 @@
1
+ // jest-raw-loader compatibility with Jest version 28.
2
+ // See: https://github.com/keplersj/jest-raw-loader/pull/239
3
+ module.exports = {
4
+ process: (content) => {
5
+ return {
6
+ code: "module.exports = " + JSON.stringify(content),
7
+ };
8
+ },
9
+ };
@@ -0,0 +1,101 @@
1
+ // need this for async/await in tests
2
+ import "core-js/stable";
3
+ import "regenerator-runtime/runtime";
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
+ // pat-fullscreen
15
+ document.requestFullscreen = jest.fn();
16
+ document.exitFullscreen = jest.fn();
17
+ document.fullscreenElement = jest.fn();
18
+ document.fullscreenEnabled = jest.fn();
19
+ document.fullscreenchange = jest.fn();
20
+ document.fullscreenerror = jest.fn();
21
+
22
+ // resize-observer
23
+ global.ResizeObserver = function () {
24
+ // Just do nothing for now...
25
+ return { observe: () => {} };
26
+ };
27
+
28
+ global.IntersectionObserver = class IntersectionObserver {
29
+ constructor(callback) {
30
+ this.callback = callback;
31
+ if (!global.__patternslib_test_intersection_observers) {
32
+ global.__patternslib_test_intersection_observers = [];
33
+ }
34
+ this._el = null;
35
+ this._do_observe = false;
36
+ this._cnt = 0;
37
+ global.__patternslib_test_intersection_observers.push(this);
38
+ }
39
+ observe(el) {
40
+ this._el = el;
41
+ this._do_observe = true;
42
+ this._set_entry(false);
43
+ }
44
+ unobserve() {
45
+ this._do_observe = false;
46
+ }
47
+ disconnect() {
48
+ this._do_observe = false;
49
+ }
50
+ takeRecords() {}
51
+ _set_entry(is_intersecting = true) {
52
+ if (!this._do_observe) {
53
+ return;
54
+ }
55
+ this.callback([
56
+ {
57
+ isIntersecting: is_intersecting,
58
+ target: this._el,
59
+ // entry.boundingClientRect
60
+ // entry.intersectionRatio
61
+ // entry.intersectionRect
62
+ // entry.rootBounds
63
+ // entry.time
64
+ },
65
+ ]);
66
+ this._cnt++;
67
+ }
68
+ };
69
+
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
+ // jsDOM does not add ``getClientRects`` or ``getBoundingClientRect`` to a ``document.createRange()``
82
+ // Originally from pat-tiptap to allow scroloing into the view when focusing the editor.
83
+ Range.prototype.getClientRects = () => [];
84
+ Range.prototype.getBoundingClientRect = () => {
85
+ return { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 };
86
+ };
87
+
88
+ // Originally from pat-tinymce.
89
+ Object.defineProperty(window, "matchMedia", {
90
+ writable: true,
91
+ value: jest.fn().mockImplementation((query) => ({
92
+ matches: false,
93
+ media: query,
94
+ onchange: null,
95
+ addListener: jest.fn(), // Deprecated
96
+ removeListener: jest.fn(), // Deprecated
97
+ addEventListener: jest.fn(),
98
+ removeEventListener: jest.fn(),
99
+ dispatchEvent: jest.fn(),
100
+ })),
101
+ });
package/jest.config.js ADDED
@@ -0,0 +1,22 @@
1
+ const path = require("path");
2
+
3
+ // Set the default roots to "./src", which would work in most projects following
4
+ // Patternslib conventions which extend this jest.config.js.
5
+ const roots = ["./src"];
6
+
7
+ module.exports = {
8
+ roots: roots,
9
+ setupFilesAfterEnv: [path.resolve(__dirname, "./jest/setup-tests.js")],
10
+ watchPlugins: ["jest-watch-typeahead/filename", "jest-watch-typeahead/testname"],
11
+ transform: {
12
+ "^.+\\.[t|j]sx?$": "babel-jest",
13
+ "\\.(html|xml|svg)$": path.resolve(__dirname, "./jest/raw-loader.js"),
14
+ },
15
+ moduleNameMapper: {
16
+ "\\.(css|less|sass|scss)$": "identity-obj-proxy",
17
+ },
18
+ testEnvironment: "jsdom",
19
+ transformIgnorePatterns: [
20
+ "/node_modules/(?!@patternslib/)(?!preact/)(?!screenfull/).+\\.[t|j]sx?$",
21
+ ],
22
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@patternslib/dev",
3
+ "version": "2.0.0",
4
+ "description": "Development base files for working with Patternslib and add-ons.",
5
+ "license": "MIT",
6
+ "dependencies": {
7
+ "@babel/core": "^7.18.5",
8
+ "@babel/eslint-parser": "^7.18.2",
9
+ "@babel/preset-env": "^7.18.2",
10
+ "@commitlint/cli": "^17.0.2",
11
+ "@commitlint/config-conventional": "^17.0.2",
12
+ "@patternslib/patternslib": "^9.0.0-alpha.0",
13
+ "@release-it/conventional-changelog": "^5.0.0",
14
+ "babel-loader": "^8.2.5",
15
+ "core-js": "3.23.1",
16
+ "css-loader": "^6.7.1",
17
+ "eslint": "^8.17.0",
18
+ "eslint-config-prettier": "^8.5.0",
19
+ "husky": "^8.0.1",
20
+ "identity-obj-proxy": "^3.0.0",
21
+ "imports-loader": "^4.0.0",
22
+ "jest": "^28.1.1",
23
+ "jest-environment-jsdom": "^28.1.1",
24
+ "jest-watch-typeahead": "^1.1.0",
25
+ "prettier": "^2.7.0",
26
+ "regenerator-runtime": "^0.13.9",
27
+ "release-it": "^15.0.0",
28
+ "sass": "^1.52.3",
29
+ "sass-loader": "^13.0.0",
30
+ "style-loader": "^3.3.0",
31
+ "terser-webpack-plugin": "^5.3.3",
32
+ "timezone-mock": "^1.3.2",
33
+ "webpack": "^5.73.0",
34
+ "webpack-bundle-analyzer": "^4.4.2",
35
+ "webpack-cli": "^4.10.0",
36
+ "webpack-dev-server": "^4.9.2",
37
+ "whybundled": "^2.0.0",
38
+ "yarn": "^1.22.19"
39
+ },
40
+ "scripts": {
41
+ "test": "jest"
42
+ },
43
+ "author": {
44
+ "name": "Syslab GesmbH",
45
+ "email": "dev@syslab.com"
46
+ },
47
+ "homepage": "https://github.com/patternslib/dev",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/patternslib/dev.git"
51
+ },
52
+ "keywords": [
53
+ "patternslib"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ tabWidth: 4,
3
+ quoteProps: "consistent",
4
+ printWidth: 89,
5
+ };
@@ -0,0 +1,70 @@
1
+
2
+ *{{#if scope}} **{{scope}}:**
3
+ {{~/if}} {{#if subject}}
4
+ {{~subject}}
5
+ {{~else}}
6
+ {{~header}}
7
+ {{~/if}}
8
+
9
+ {{~!-- commit link --}} {{#if @root.linkReferences~}}
10
+ ([{{shortHash}}](
11
+ {{~#if @root.repository}}
12
+ {{~#if @root.host}}
13
+ {{~@root.host}}/
14
+ {{~/if}}
15
+ {{~#if @root.owner}}
16
+ {{~@root.owner}}/
17
+ {{~/if}}
18
+ {{~@root.repository}}
19
+ {{~else}}
20
+ {{~@root.repoUrl}}
21
+ {{~/if}}/
22
+ {{~@root.commit}}/{{hash}}))
23
+ {{~else}}
24
+ {{~hash}}
25
+ {{~/if}}
26
+
27
+ {{~!-- commit references --}}
28
+ {{~#if references~}}
29
+ , closes
30
+ {{~#each references}} {{#if @root.linkReferences~}}
31
+ [
32
+ {{~#if this.owner}}
33
+ {{~this.owner}}/
34
+ {{~/if}}
35
+ {{~this.repository}}#{{this.issue}}](
36
+ {{~#if @root.repository}}
37
+ {{~#if @root.host}}
38
+ {{~@root.host}}/
39
+ {{~/if}}
40
+ {{~#if this.repository}}
41
+ {{~#if this.owner}}
42
+ {{~this.owner}}/
43
+ {{~/if}}
44
+ {{~this.repository}}
45
+ {{~else}}
46
+ {{~#if @root.owner}}
47
+ {{~@root.owner}}/
48
+ {{~/if}}
49
+ {{~@root.repository}}
50
+ {{~/if}}
51
+ {{~else}}
52
+ {{~@root.repoUrl}}
53
+ {{~/if}}/
54
+ {{~@root.issue}}/{{this.issue}})
55
+ {{~else}}
56
+ {{~#if this.owner}}
57
+ {{~this.owner}}/
58
+ {{~/if}}
59
+ {{~this.repository}}#{{this.issue}}
60
+ {{~/if}}{{/each}}
61
+ {{~/if}}
62
+ {{#if body}}
63
+
64
+ {{~body}}
65
+ {{~/if}}
66
+ {{#if footer}}
67
+
68
+ {{~footer}}
69
+ {{~/if}}
70
+
@@ -0,0 +1,27 @@
1
+ const webpack_helpers = require("../webpack/webpack-helpers");
2
+
3
+ describe("core.dom tests", () => {
4
+ // Tests from the core.dom module
5
+
6
+ describe("top_head_insert tests", () => {
7
+ it("Insert element in top of head if head is not empty.", (done) => {
8
+ document.head.appendChild(document.createElement("title"));
9
+ const el = document.createElement("style");
10
+
11
+ webpack_helpers.top_head_insert(el);
12
+ expect(document.head.innerHTML).toBe("<style></style><title></title>");
13
+
14
+ done();
15
+ });
16
+
17
+ it("Insert element in head if head is empty.", (done) => {
18
+ document.head.innerHTML = "";
19
+ const el = document.createElement("style");
20
+
21
+ webpack_helpers.top_head_insert(el);
22
+ expect(document.head.innerHTML).toBe("<style></style>");
23
+
24
+ done();
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,16 @@
1
+ function top_head_insert(el) {
2
+ // Insert element at the top of <head>
3
+ // Used for injecting CSS via webpack before any other CSS
4
+ // Note:
5
+ // Keep code compatible with IE11 as long as we support it.
6
+ var first_child = document.head.querySelectorAll("*")[0];
7
+ if (first_child) {
8
+ document.head.insertBefore(el, first_child);
9
+ } else {
10
+ document.head.append(el);
11
+ }
12
+ }
13
+
14
+ module.exports = {
15
+ top_head_insert: top_head_insert,
16
+ };
@@ -0,0 +1,132 @@
1
+ process.traceDeprecation = true;
2
+ const path = require("path");
3
+ const webpack = require("webpack");
4
+ const webpack_helpers = require("./webpack-helpers");
5
+
6
+ // plugins
7
+ const TerserPlugin = require("terser-webpack-plugin");
8
+
9
+ module.exports = (env, argv, config, babel_include = []) => {
10
+ // Webpack config
11
+
12
+ // Packages in node_modules to NOT exclude from babel processing.
13
+ // We exclude everything under `node_modules` except packages listed in
14
+ // babel_include, like any packages within `@patternslib`, any other
15
+ // `pat-*` and other packges which need babel processing so that node can
16
+ // make sense of it when compiling.
17
+ babel_include = new Set(["patternslib", "pat-.*", "screenfull", ...babel_include]);
18
+ let babel_exclude = "";
19
+ for (const it of babel_include) {
20
+ babel_exclude += `(?!(${it})/)`;
21
+ }
22
+ babel_exclude = `node_modules/${babel_exclude}.*`;
23
+
24
+ const base_config = {
25
+ entry: {}, // Entry point files for your JavaScript application.
26
+ externals: [
27
+ {
28
+ window: "window",
29
+ },
30
+ ],
31
+ output: {
32
+ filename: "[name].js",
33
+ chunkFilename: "chunks/[name].[contenthash].min.js",
34
+ // output.path: Set default to "dist/" which probably will work in
35
+ // projects which extend this webpack config.
36
+ // Note the extendee's webpack config should be in the top-level that
37
+ // "dist" can be found in the top level too.
38
+ path: "./dist",
39
+ clean: true, // Clean directory before compiling
40
+ publicPath: "auto",
41
+ },
42
+ optimization: {},
43
+ module: {
44
+ rules: [
45
+ {
46
+ test: /\.js$/,
47
+ // Exclude node modules except patternslib, pat-* and mockup packgages.
48
+ // Allows for extending this file without needing to override for a successful webpack build.
49
+ exclude: new RegExp(babel_exclude),
50
+ loader: "babel-loader",
51
+ },
52
+ {
53
+ test: /showdown-prettify/,
54
+ use: [
55
+ {
56
+ loader: "imports-loader?showdown,google-code-prettify",
57
+ },
58
+ ],
59
+ },
60
+ {
61
+ test: /\.(?:sass|scss|css)$/i,
62
+ use: [
63
+ {
64
+ loader: "style-loader",
65
+ options: {
66
+ insert: webpack_helpers.top_head_insert,
67
+ },
68
+ },
69
+ "css-loader",
70
+ "sass-loader",
71
+ ],
72
+ },
73
+ {
74
+ test: /\.*(?:html|xml|svg)$/i,
75
+ type: "asset/source",
76
+ },
77
+ {
78
+ test: /\.(eot|woff|woff2|ttf|png|jpe?g|gif)$/i,
79
+ type: "asset/resource",
80
+ },
81
+ ],
82
+ },
83
+ resolve: {
84
+ alias: {},
85
+ },
86
+ plugins: [
87
+ new webpack.IgnorePlugin({
88
+ resourceRegExp: /^\.\/locale$/,
89
+ contextRegExp: /moment$/,
90
+ }),
91
+ ],
92
+ };
93
+
94
+ // Override base_config with entries from config.
95
+ // Most useful the ``entry`` entry.
96
+ config = Object.assign(base_config, config);
97
+
98
+ if (process.env.NODE_ENV === "development") {
99
+ // Add a dev server.
100
+ config.devServer = {
101
+ static: {
102
+ directory: "./",
103
+ },
104
+ port: "3001",
105
+ host: "0.0.0.0",
106
+ headers: {
107
+ "Access-Control-Allow-Origin": "*",
108
+ },
109
+ };
110
+ config.optimization.minimize = false;
111
+ config.devtool = "source-map"; // Slowest option. False for no source maps.
112
+ config.watchOptions = {
113
+ ignored: ["node_modules/**", "docs/**"],
114
+ };
115
+ }
116
+ if (process.env.NODE_ENV === "production") {
117
+ // Minify all JS files in production mode.
118
+ config.optimization.minimizer = [
119
+ new TerserPlugin({
120
+ include: /(\.js$)/,
121
+ extractComments: false,
122
+ terserOptions: {
123
+ output: {
124
+ comments: false,
125
+ },
126
+ },
127
+ }),
128
+ ];
129
+ config.devtool = "source-map"; // Slowest option. False for no source maps.
130
+ }
131
+ return config;
132
+ };
@@ -0,0 +1,85 @@
1
+ const { ModuleFederationPlugin } = require("webpack").container;
2
+ const patternslib_package_json = require("@patternslib/patternslib/package.json");
3
+
4
+ // Patternslib Module Federation bundle prefix.
5
+ // This is used to filter for module federation enabled bundles.
6
+ // NOTE: This is also defined in ``module_federation.js``.
7
+ const MF_NAME_PREFIX = "__patternslib_mf__";
8
+
9
+ /**
10
+ * Get dependencies and versions for the module federation plugin from
11
+ * package.json dependency lists.
12
+ *
13
+ * @param {Array} - List of package.json dependencies fields.
14
+ * @returns {Object} - Object with dependencies for the module federation plugin.
15
+ */
16
+ function shared_from_dependencies(...dependencies) {
17
+ const shared = {};
18
+ for (const deps of dependencies) {
19
+ if (!deps) {
20
+ continue;
21
+ }
22
+ for (const [name, version] of Object.entries(deps)) {
23
+ shared[name] = {
24
+ singleton: true,
25
+ requiredVersion: version,
26
+ };
27
+ }
28
+ }
29
+ return shared;
30
+ }
31
+
32
+ /**
33
+ * Webpack module federation config factory.
34
+ *
35
+ * Use this to extend your webpack configuration for module federation support.
36
+ *
37
+ * @param {String} name - Bundle/remote name. If not given, the package.json name is used.
38
+ * @param {String} filename - Name of the generated remote entry file. Default ``remote.min.js``.
39
+ * @param {Object} package_json - Your imported project's package.json file. This is to automatically set the shared dependencies.
40
+ * @param {String} remote_entry - Path to which the new remote entry file is written to.
41
+ * @param {Object} shared - Object with dependency name - version specifier pairs. Can be used instead of the package_json parameter.
42
+ * @returns {Object} - Webpack config partial with instantiated module federation plugins.
43
+ */
44
+ function config({
45
+ name,
46
+ filename = "remote.min.js",
47
+ package_json,
48
+ remote_entry,
49
+ shared = {},
50
+ }) {
51
+ // If no name is given, use the package name.
52
+ name = name || package_json?.name || patternslib_package_json.name;
53
+
54
+ // Create a JS-variable compatible name and add a prefix.
55
+ const normalized_bundle_name =
56
+ MF_NAME_PREFIX + name.match(/([_$A-Za-z0-9])/g).join("");
57
+
58
+ shared = {
59
+ ...(!Object.keys(shared).length && // only include package.json depenencies, if shared is empty.
60
+ shared_from_dependencies(
61
+ patternslib_package_json.dependencies,
62
+ package_json?.dependencies
63
+ )),
64
+ ...shared,
65
+ };
66
+
67
+ return new ModuleFederationPlugin({
68
+ name: normalized_bundle_name,
69
+ ...(remote_entry && {
70
+ filename: filename,
71
+ exposes: {
72
+ "./main": remote_entry,
73
+ },
74
+ }),
75
+ shared: shared,
76
+ });
77
+ }
78
+
79
+ // Default export
80
+ const module_exports = (module.exports = config);
81
+
82
+ // Named exports
83
+ module_exports.config = config;
84
+ module_exports.MF_NAME_PREFIX = MF_NAME_PREFIX;
85
+ module_exports.shared_from_dependencies = shared_from_dependencies;
@@ -0,0 +1,38 @@
1
+ // Depend on (snippet from package.json):
2
+ // {
3
+ // "dependencies": {
4
+ // "vue": "^2.6.14",
5
+ // "vue-async-computed": "^3.9.0"
6
+ // },
7
+ // "devDependencies": {
8
+ // "vue-jest": "^4.0.1",
9
+ // "vue-loader": "^15.9.8",
10
+ // "vue-template-compiler": "^2.6.14"
11
+ // }
12
+ // }
13
+ //
14
+ // Add in jest.config.js:
15
+ // transform: {
16
+ // ...
17
+ // "^.+\\.vue$": "vue-jest",
18
+ // },
19
+ //
20
+ // Use in webpack like:
21
+ // const vue_config = require("./webpack.vue");
22
+ // module.exports = async (env, argv) => {
23
+ // const config = vue_config(env, argv, patternslib_config(env, argv));
24
+ // [...]
25
+ // }
26
+ const VueLoaderPlugin = require("vue-loader/lib/plugin");
27
+
28
+ module.exports = (env, argv, config) => {
29
+ // Vue Plugin config snippet
30
+ config.resolve.alias.vue$ = "vue/dist/vue.esm.js";
31
+ config.resolve.extensions = ["*", ".js", ".vue", ".json"];
32
+ config.module.rules.push({
33
+ test: /\.vue$/,
34
+ loader: "vue-loader",
35
+ });
36
+ config.plugins.push(new VueLoaderPlugin());
37
+ return config;
38
+ };