@module-federation/bridge-shared 0.0.0-next-20240619092013
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/CHANGELOG.md +3 -0
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/bridge.d.ts +0 -0
- package/dist/env.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +39 -0
- package/dist/index.umd.js +3 -0
- package/dist/logger.d.ts +8 -0
- package/dist/type.d.ts +10 -0
- package/package.json +26 -0
- package/project.json +21 -0
- package/src/bridge.ts +0 -0
- package/src/env.ts +4 -0
- package/src/index.ts +3 -0
- package/src/logger.ts +52 -0
- package/src/type.ts +9 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +41 -0
- package/tsconfig.node.json +11 -0
- package/vite.config.ts +16 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 ScriptedAlchemy LLC (Zack Jackson) Zhou Shaw (zhouxiao)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/bridge.d.ts
ADDED
|
File without changes
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dispatchPopstateEnv(): void;
|
package/dist/index.d.ts
ADDED
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var a = Object.defineProperty;
|
|
2
|
+
var c = (s, e, t) => e in s ? a(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var i = (s, e, t) => (c(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
class g {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
i(this, "name");
|
|
7
|
+
i(this, "isDebugEnabled");
|
|
8
|
+
i(this, "color");
|
|
9
|
+
this.name = e, this.isDebugEnabled = !1, this.color = this.stringToColor(e), typeof window < "u" && typeof localStorage < "u" && (this.isDebugEnabled = localStorage.getItem("debug") === "true"), typeof process < "u" && process.env && (this.isDebugEnabled = process.env.DEBUG === "true");
|
|
10
|
+
}
|
|
11
|
+
log(...e) {
|
|
12
|
+
var t, n;
|
|
13
|
+
if (this.isDebugEnabled) {
|
|
14
|
+
const o = `color: ${this.color}; font-weight: bold`, l = `%c[${this.name}]`, r = ((n = (t = new Error().stack) == null ? void 0 : t.split(`
|
|
15
|
+
`)[2]) == null ? void 0 : n.trim()) || "Stack information not available";
|
|
16
|
+
typeof console < "u" && console.debug && console.debug(l, o, ...e, `
|
|
17
|
+
(${r})`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
stringToColor(e) {
|
|
21
|
+
let t = 0;
|
|
22
|
+
for (let o = 0; o < e.length; o++)
|
|
23
|
+
t = e.charCodeAt(o) + ((t << 5) - t);
|
|
24
|
+
let n = "#";
|
|
25
|
+
for (let o = 0; o < 3; o++) {
|
|
26
|
+
const l = t >> o * 8 & 255;
|
|
27
|
+
n += ("00" + l.toString(16)).substr(-2);
|
|
28
|
+
}
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function f() {
|
|
33
|
+
const s = new PopStateEvent("popstate", { state: window.history.state });
|
|
34
|
+
window.dispatchEvent(s);
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
g as Logger,
|
|
38
|
+
f as dispatchPopstateEnv
|
|
39
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["bridge-shared"]={}))})(this,function(e){"use strict";var f=Object.defineProperty;var u=(e,t,n)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var d=(e,t,n)=>(u(e,typeof t!="symbol"?t+"":t,n),n);class t{constructor(s){d(this,"name");d(this,"isDebugEnabled");d(this,"color");this.name=s,this.isDebugEnabled=!1,this.color=this.stringToColor(s),typeof window<"u"&&typeof localStorage<"u"&&(this.isDebugEnabled=localStorage.getItem("debug")==="true"),typeof process<"u"&&process.env&&(this.isDebugEnabled=process.env.DEBUG==="true")}log(...s){var i,l;if(this.isDebugEnabled){const o=`color: ${this.color}; font-weight: bold`,r=`%c[${this.name}]`,c=((l=(i=new Error().stack)==null?void 0:i.split(`
|
|
2
|
+
`)[2])==null?void 0:l.trim())||"Stack information not available";typeof console<"u"&&console.debug&&console.debug(r,o,...s,`
|
|
3
|
+
(${c})`)}}stringToColor(s){let i=0;for(let o=0;o<s.length;o++)i=s.charCodeAt(o)+((i<<5)-i);let l="#";for(let o=0;o<3;o++){const r=i>>o*8&255;l+=("00"+r.toString(16)).substr(-2)}return l}}function n(){const a=new PopStateEvent("popstate",{state:window.history.state});window.dispatchEvent(a)}e.Logger=t,e.dispatchPopstateEnv=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
package/dist/logger.d.ts
ADDED
package/dist/type.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/bridge-shared",
|
|
3
|
+
"version": "0.0.0-next-20240619092013",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"author": "zhouxiao <codingzx@gmail.com>",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.umd.js",
|
|
10
|
+
"module": "./dist/index.es.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/node": "~16.11.7",
|
|
14
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
15
|
+
"@vitejs/plugin-vue-jsx": "^4.0.0",
|
|
16
|
+
"typescript": "^5.2.2",
|
|
17
|
+
"vite": "^5.2.0",
|
|
18
|
+
"vite-plugin-dts": "^3.9.1",
|
|
19
|
+
"vue-tsc": "^2.0.6"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite",
|
|
23
|
+
"build": "vite build",
|
|
24
|
+
"preview": "vite preview"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bridge-shared",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/bridge/bridge-shared/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"targets": {
|
|
7
|
+
"build": {
|
|
8
|
+
"executor": "nx:run-commands",
|
|
9
|
+
"options": {
|
|
10
|
+
"commands": ["npm run build --prefix packages/bridge/bridge-shared"]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"test": {
|
|
14
|
+
"executor": "nx:run-commands",
|
|
15
|
+
"options": {
|
|
16
|
+
"commands": ["npm run test --prefix packages/bridge/bridge-shared"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"tags": ["type:pkg"]
|
|
21
|
+
}
|
package/src/bridge.ts
ADDED
|
File without changes
|
package/src/env.ts
ADDED
package/src/index.ts
ADDED
package/src/logger.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
private name: string;
|
|
3
|
+
private isDebugEnabled: boolean;
|
|
4
|
+
private color: string;
|
|
5
|
+
|
|
6
|
+
constructor(name: string) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.isDebugEnabled = false;
|
|
9
|
+
this.color = this.stringToColor(name);
|
|
10
|
+
|
|
11
|
+
// Check if debug is enabled in the browser environment
|
|
12
|
+
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
|
|
13
|
+
this.isDebugEnabled = localStorage.getItem('debug') === 'true';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Check if debug is enabled in the Node.js environment
|
|
17
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
18
|
+
this.isDebugEnabled = process.env.DEBUG === 'true';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public log(...messages: any[]): void {
|
|
23
|
+
if (this.isDebugEnabled) {
|
|
24
|
+
const infoStyle = `color: ${this.color}; font-weight: bold`;
|
|
25
|
+
const logMessage = `%c[${this.name}]`;
|
|
26
|
+
const stack =
|
|
27
|
+
new Error().stack?.split('\n')[2]?.trim() ||
|
|
28
|
+
'Stack information not available';
|
|
29
|
+
|
|
30
|
+
if (typeof console !== 'undefined' && console.debug) {
|
|
31
|
+
console.debug(logMessage, infoStyle, ...messages, `\n (${stack})`);
|
|
32
|
+
|
|
33
|
+
// if (this.isDebugEnabledStack) {
|
|
34
|
+
// console.log(`%c${stack}`, 'color: grey; font-style: italic;');
|
|
35
|
+
// }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private stringToColor(str: string): string {
|
|
41
|
+
let hash = 0;
|
|
42
|
+
for (let i = 0; i < str.length; i++) {
|
|
43
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
44
|
+
}
|
|
45
|
+
let color = '#';
|
|
46
|
+
for (let i = 0; i < 3; i++) {
|
|
47
|
+
const value = (hash >> (i * 8)) & 0xff;
|
|
48
|
+
color += ('00' + value.toString(16)).substr(-2);
|
|
49
|
+
}
|
|
50
|
+
return color;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/type.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"useDefineForClassFields": true,
|
|
4
|
+
|
|
5
|
+
/* Bundler mode */
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"jsxImportSource": "vue",
|
|
10
|
+
|
|
11
|
+
/* Linting */
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true,
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"emitDeclarationOnly": true,
|
|
17
|
+
"outDir": "dist",
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"strict": true,
|
|
20
|
+
"moduleResolution": "node",
|
|
21
|
+
"target": "esnext",
|
|
22
|
+
"module": "esnext",
|
|
23
|
+
"lib": ["esnext", "dom"],
|
|
24
|
+
"jsx": "preserve",
|
|
25
|
+
"esModuleInterop": true,
|
|
26
|
+
"allowSyntheticDefaultImports": true,
|
|
27
|
+
"sourceMap": true,
|
|
28
|
+
"baseUrl": ".",
|
|
29
|
+
"paths": {
|
|
30
|
+
"@/*": ["src/*"]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"include": [
|
|
34
|
+
"src/**/*.ts",
|
|
35
|
+
"src/**/*.tsx",
|
|
36
|
+
"src/**/*.vue",
|
|
37
|
+
"src/remoteApp.tsx",
|
|
38
|
+
"src/create.ts"
|
|
39
|
+
],
|
|
40
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
41
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import dts from 'vite-plugin-dts';
|
|
5
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [vue(), dts(), vueJsx()],
|
|
9
|
+
build: {
|
|
10
|
+
lib: {
|
|
11
|
+
entry: path.resolve(__dirname, 'src/index.ts'),
|
|
12
|
+
name: 'bridge-shared',
|
|
13
|
+
fileName: (format) => `index.${format}.js`,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|