@meethive/vite 0.0.1 → 0.0.3

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.
Files changed (76) hide show
  1. package/dist/{src/federation/src/runtime/dynamic-remote.d.ts → dynamic-remote.d.ts} +25 -19
  2. package/dist/dynamic-remote.js +185 -0
  3. package/dist/dynamic-remote.mjs +163 -0
  4. package/dist/index.d.ts +51 -4
  5. package/dist/index.js +1 -20
  6. package/dist/index.mjs +1 -20
  7. package/dist/{src/federation/src/utils/semver/satisfy.d.ts → satisfy.d.ts} +2 -1
  8. package/dist/satisfy.js +381 -0
  9. package/dist/satisfy.mjs +381 -0
  10. package/package.json +20 -4
  11. package/dist/index.d.ts.map +0 -1
  12. package/dist/src/federation/src/dev/expose-development.d.ts +0 -5
  13. package/dist/src/federation/src/dev/expose-development.d.ts.map +0 -1
  14. package/dist/src/federation/src/dev/remote-development.d.ts +0 -5
  15. package/dist/src/federation/src/dev/remote-development.d.ts.map +0 -1
  16. package/dist/src/federation/src/dev/shared-development.d.ts +0 -5
  17. package/dist/src/federation/src/dev/shared-development.d.ts.map +0 -1
  18. package/dist/src/federation/src/index.d.ts +0 -7
  19. package/dist/src/federation/src/index.d.ts.map +0 -1
  20. package/dist/src/federation/src/prod/expose-production.d.ts +0 -5
  21. package/dist/src/federation/src/prod/expose-production.d.ts.map +0 -1
  22. package/dist/src/federation/src/prod/remote-production.d.ts +0 -7
  23. package/dist/src/federation/src/prod/remote-production.d.ts.map +0 -1
  24. package/dist/src/federation/src/prod/shared-production.d.ts +0 -5
  25. package/dist/src/federation/src/prod/shared-production.d.ts.map +0 -1
  26. package/dist/src/federation/src/public.d.ts +0 -40
  27. package/dist/src/federation/src/public.d.ts.map +0 -1
  28. package/dist/src/federation/src/runtime/dynamic-remote.d.ts.map +0 -1
  29. package/dist/src/federation/src/utils/html.d.ts +0 -12
  30. package/dist/src/federation/src/utils/html.d.ts.map +0 -1
  31. package/dist/src/federation/src/utils/index.d.ts +0 -29
  32. package/dist/src/federation/src/utils/index.d.ts.map +0 -1
  33. package/dist/src/federation/src/utils/semver/compare.d.ts +0 -10
  34. package/dist/src/federation/src/utils/semver/compare.d.ts.map +0 -1
  35. package/dist/src/federation/src/utils/semver/constants.d.ts +0 -11
  36. package/dist/src/federation/src/utils/semver/constants.d.ts.map +0 -1
  37. package/dist/src/federation/src/utils/semver/parser.d.ts +0 -10
  38. package/dist/src/federation/src/utils/semver/parser.d.ts.map +0 -1
  39. package/dist/src/federation/src/utils/semver/satisfy.d.ts.map +0 -1
  40. package/dist/src/federation/src/utils/semver/utils.d.ts +0 -12
  41. package/dist/src/federation/src/utils/semver/utils.d.ts.map +0 -1
  42. package/dist/src/monaco-editor/index.d.ts +0 -35
  43. package/dist/src/monaco-editor/index.d.ts.map +0 -1
  44. package/dist/src/monaco-editor/languageWork.d.ts +0 -10
  45. package/dist/src/monaco-editor/languageWork.d.ts.map +0 -1
  46. package/dist/src/monaco-editor/workerMiddleware.d.ts +0 -9
  47. package/dist/src/monaco-editor/workerMiddleware.d.ts.map +0 -1
  48. package/dist/src/sharp/index.d.ts +0 -12
  49. package/dist/src/sharp/index.d.ts.map +0 -1
  50. package/index.ts +0 -3
  51. package/src/federation/src/dev/expose-development.ts +0 -29
  52. package/src/federation/src/dev/remote-development.ts +0 -435
  53. package/src/federation/src/dev/shared-development.ts +0 -29
  54. package/src/federation/src/index.ts +0 -242
  55. package/src/federation/src/prod/expose-production.ts +0 -333
  56. package/src/federation/src/prod/federation_fn_import.js +0 -75
  57. package/src/federation/src/prod/remote-production.ts +0 -658
  58. package/src/federation/src/prod/shared-production.ts +0 -268
  59. package/src/federation/src/public.ts +0 -54
  60. package/src/federation/src/runtime/dynamic-remote.ts +0 -247
  61. package/src/federation/src/utils/html.ts +0 -165
  62. package/src/federation/src/utils/index.ts +0 -255
  63. package/src/federation/src/utils/semver/compare.ts +0 -131
  64. package/src/federation/src/utils/semver/constants.ts +0 -46
  65. package/src/federation/src/utils/semver/parser.ts +0 -253
  66. package/src/federation/src/utils/semver/satisfy.ts +0 -151
  67. package/src/federation/src/utils/semver/utils.ts +0 -93
  68. package/src/federation/types/dynamic-remote.d.ts +0 -105
  69. package/src/federation/types/index.d.ts +0 -344
  70. package/src/federation/types/pluginHooks.d.ts +0 -4
  71. package/src/federation/types/virtual-modules.d.ts +0 -48
  72. package/src/federation/types/viteDevServer.d.ts +0 -22
  73. package/src/monaco-editor/index.ts +0 -205
  74. package/src/monaco-editor/languageWork.ts +0 -36
  75. package/src/monaco-editor/workerMiddleware.ts +0 -78
  76. package/src/sharp/index.ts +0 -93
@@ -1,12 +0,0 @@
1
- export declare function parseRegex(source: string): RegExp;
2
- export declare function isXVersion(version: string): boolean;
3
- export declare function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: TArgs) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7): (...args: TArgs) => R7;
4
- export declare function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6>(f1: (...args: TArgs) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6): (...args: TArgs) => R6;
5
- export declare function pipe<TArgs extends any[], R1, R2, R3, R4, R5>(f1: (...args: TArgs) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5): (...args: TArgs) => R5;
6
- export declare function pipe<TArgs extends any[], R1, R2, R3, R4>(f1: (...args: TArgs) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4): (...args: TArgs) => R4;
7
- export declare function pipe<TArgs extends any[], R1, R2, R3>(f1: (...args: TArgs) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: TArgs) => R3;
8
- export declare function pipe<TArgs extends any[], R1, R2>(f1: (...args: TArgs) => R1, f2: (a: R1) => R2): (...args: TArgs) => R2;
9
- export declare function pipe<TArgs extends any[], R1>(f1: (...args: TArgs) => R1): (...args: TArgs) => R1;
10
- export declare function extractComparator(comparatorString: string): RegExpMatchArray | null;
11
- export declare function combineVersion(major: string, minor: string, patch: string, preRelease: string): string;
12
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/federation/src/utils/semver/utils.ts"],"names":[],"mappings":"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"}
@@ -1,35 +0,0 @@
1
- import { Plugin } from 'vite';
2
- import { EditorLanguageWorks, IWorkerDefinition } from './languageWork';
3
-
4
- /**
5
- * Return a resolved path for a given Monaco file.
6
- */
7
- export declare function resolveMonacoPath(filePath: string): string;
8
- export declare function getWorks(options: IMonacoEditorOpts): IWorkerDefinition[];
9
- export interface IMonacoEditorOpts {
10
- /**
11
- * include only a subset of the languageWorkers supported.
12
- */
13
- languageWorkers?: EditorLanguageWorks[];
14
- customWorkers?: IWorkerDefinition[];
15
- /**
16
- * Override the public path from which files generated by this plugin will be served.
17
- * This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross-
18
- * origin when using a CDN for other static resources.
19
- * Use e.g. '/' if you want to load your resources from the current origin.
20
- */
21
- publicPath?: string;
22
- customDistPath?: (root: string, buildOutDir: string, base: string) => string;
23
- forceBuildCDN?: boolean;
24
- /**
25
- * Specify whether the editor API should be exposed through a global `monaco` object or not. This
26
- * option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM
27
- * version of the monaco editor does no longer define a global `monaco` object unless
28
- * `global.MonacoEnvironment = { globalAPI: true }` is set ([change
29
- * log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
30
- */
31
- globalAPI?: boolean;
32
- }
33
- export default function monacoEditorPlugin(options: IMonacoEditorOpts): Plugin;
34
- export declare function isCDN(publicPath: string): boolean;
35
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/monaco-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAkB,MAAM,MAAM,CAAC;AAIjE,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAwB,MAAM,gBAAgB,CAAC;AAG9F;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,iBAAiB,uBAQlD;AAED,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,eAAe,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAExC,aAAa,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEpC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAE7E,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAeD,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CA6H7E;AAED,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,WAMvC"}
@@ -1,10 +0,0 @@
1
- export interface IWorkerDefinition {
2
- label: string;
3
- entry: string;
4
- }
5
- export declare const languageWorkAttr: IWorkerDefinition[];
6
- export declare const languageWorksByLabel: {
7
- [language: string]: IWorkerDefinition;
8
- };
9
- export type EditorLanguageWorks = 'css' | 'html' | 'json' | 'typescript' | 'editorWorkerService';
10
- //# sourceMappingURL=languageWork.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"languageWork.d.ts","sourceRoot":"","sources":["../../../src/monaco-editor/languageWork.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,gBAAgB,EAAE,iBAAiB,EAqB/C,CAAC;AAGF,eAAO,MAAM,oBAAoB,EAAE;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAO,CAAC;AAMlF,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,qBAAqB,CAAA"}
@@ -1,9 +0,0 @@
1
- import { Connect, ResolvedConfig } from 'vite';
2
- import { IMonacoEditorOpts } from './index';
3
- import { IWorkerDefinition } from './languageWork';
4
-
5
- export declare function getFilenameByEntry(entry: string): string;
6
- export declare const cacheDir = "node_modules/.monaco/";
7
- export declare function getWorkPath(works: IWorkerDefinition[], options: IMonacoEditorOpts, config: ResolvedConfig): {};
8
- export declare function workerMiddleware(middlewares: Connect.Server, config: ResolvedConfig, options: IMonacoEditorOpts): void;
9
- //# sourceMappingURL=workerMiddleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workerMiddleware.d.ts","sourceRoot":"","sources":["../../../src/monaco-editor/workerMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAY,iBAAiB,EAA4B,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKnD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,UAG/C;AAED,eAAO,MAAM,QAAQ,0BAA0B,CAAC;AAEhD,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EAAE,EAC1B,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,cAAc,MA6BvB;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,CAAC,MAAM,EAC3B,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,iBAAiB,GACzB,IAAI,CAyBN"}
@@ -1,12 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
3
- export type SharpOptimizeOptions = {
4
- include?: (string | RegExp)[];
5
- exclude?: (string | RegExp)[];
6
- jpegQuality?: number;
7
- pngQuality?: number;
8
- webpQuality?: number;
9
- avifQuality?: number;
10
- };
11
- export default function sharpOptimize(options?: SharpOptimizeOptions): Plugin;
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sharp/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC7B,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AASD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAsEhF"}
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as federation } from './src/federation/src'
2
- export { default as monacoEditorPlugin } from './src/monaco-editor'
3
- export { default as sharpOptimize } from './src/sharp'
@@ -1,29 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Origin.js and others.
3
- //
4
- // This program and the accompanying materials are licensed under Mulan PSL v2.
5
- // You can use this software according to the terms and conditions of the Mulan PSL v2.
6
- // You may obtain a copy of Mulan PSL v2 at:
7
- // http://license.coscl.org.cn/MulanPSL2
8
- // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
- // EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
- // MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
- // See the Mulan PSL v2 for more details.
12
- //
13
- // SPDX-License-Identifier: MulanPSL-2.0
14
- // *****************************************************************************
15
-
16
- import { parseExposeOptions } from '../utils'
17
- import { parsedOptions } from '../public'
18
- import type { VitePluginFederationOptions } from '../../types'
19
- import type { PluginHooks } from '../../types/pluginHooks'
20
-
21
- export function devExposePlugin(
22
- options: VitePluginFederationOptions
23
- ): PluginHooks {
24
- parsedOptions.devExpose = parseExposeOptions(options)
25
-
26
- return {
27
- name: 'originjs:expose-development'
28
- }
29
- }
@@ -1,435 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Origin.js and others.
3
- //
4
- // This program and the accompanying materials are licensed under Mulan PSL v2.
5
- // You can use this software according to the terms and conditions of the Mulan PSL v2.
6
- // You may obtain a copy of Mulan PSL v2 at:
7
- // http://license.coscl.org.cn/MulanPSL2
8
- // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
- // EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
- // MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
- // See the Mulan PSL v2 for more details.
12
- //
13
- // SPDX-License-Identifier: MulanPSL-2.0
14
- // *****************************************************************************
15
-
16
- import type { UserConfig } from 'vite'
17
- import type { ConfigTypeSet, VitePluginFederationOptions } from '../../types'
18
- import { walk } from 'estree-walker'
19
- import MagicString from 'magic-string'
20
- import { readFileSync } from 'fs'
21
- import { posix } from 'path'
22
- import type { TransformPluginContext } from 'rollup'
23
- import type { ViteDevServer } from '../../types/viteDevServer'
24
- import {
25
- createRemotesMap,
26
- getFileExtname,
27
- getModuleMarker,
28
- normalizePath,
29
- parseRemoteOptions,
30
- REMOTE_FROM_PARAMETER
31
- } from '../utils'
32
- import { builderInfo, parsedOptions, devRemotes } from '../public'
33
- import type { PluginHooks } from '../../types/pluginHooks'
34
-
35
- export function devRemotePlugin(
36
- options: VitePluginFederationOptions
37
- ): PluginHooks {
38
- parsedOptions.devRemote = parseRemoteOptions(options)
39
- // const remotes: { id: string; regexp: RegExp; config: RemotesConfig }[] = []
40
- for (const item of parsedOptions.devRemote) {
41
- devRemotes.push({
42
- id: item[0],
43
- regexp: new RegExp(`^${item[0]}/.+?`),
44
- config: item[1]
45
- })
46
- }
47
-
48
- const needHandleFileType = [
49
- '.js',
50
- '.ts',
51
- '.jsx',
52
- '.tsx',
53
- '.mjs',
54
- '.cjs',
55
- '.vue',
56
- '.svelte'
57
- ]
58
- options.transformFileTypes = (options.transformFileTypes ?? [])
59
- .concat(needHandleFileType)
60
- .map((item) => item.toLowerCase())
61
- const transformFileTypeSet = new Set(options.transformFileTypes)
62
- let viteDevServer: ViteDevServer
63
- return {
64
- name: 'originjs:remote-development',
65
- virtualFile: options.remotes || options.enableDynamicRemotes
66
- ? {
67
- __federation__: `
68
- ${createRemotesMap(devRemotes)}
69
- const loadJS = async (url, fn) => {
70
- const resolvedUrl = typeof url === 'function' ? await url() : url;
71
- const script = document.createElement('script')
72
- script.type = 'text/javascript';
73
- script.onload = fn;
74
- script.src = resolvedUrl;
75
- document.getElementsByTagName('head')[0].appendChild(script);
76
- }
77
- function get(name, ${REMOTE_FROM_PARAMETER}){
78
- return import(/* @vite-ignore */ name).then(module => ()=> {
79
- if (${REMOTE_FROM_PARAMETER} === 'webpack') {
80
- return Object.prototype.toString.call(module).indexOf('Module') > -1 && module.default ? module.default : module
81
- }
82
- return module
83
- })
84
- }
85
- const wrapShareScope = ${REMOTE_FROM_PARAMETER} => {
86
- return {
87
- ${getModuleMarker('shareScope')}
88
- }
89
- }
90
-
91
- const initMap = Object.create(null);
92
- async function __federation_method_ensure(remoteId) {
93
- const remote = remotesMap[remoteId];
94
- if (!remote.inited) {
95
- if ('var' === remote.format) {
96
- // loading js with script tag
97
- return new Promise(resolve => {
98
- const callback = () => {
99
- if (!remote.inited) {
100
- remote.lib = window[remoteId];
101
- remote.lib.init(wrapShareScope(remote.from))
102
- remote.inited = true;
103
- }
104
- resolve(remote.lib);
105
- }
106
- return loadJS(remote.url, callback);
107
- });
108
- } else if (['esm', 'systemjs'].includes(remote.format)) {
109
- // loading js with import(...)
110
- return new Promise((resolve, reject) => {
111
- const getUrl = typeof remote.url === 'function' ? remote.url : () => Promise.resolve(remote.url);
112
- getUrl().then(url => {
113
- import(/* @vite-ignore */ url).then(lib => {
114
- if (!remote.inited) {
115
- const shareScope = wrapShareScope(remote.from)
116
- lib.init(shareScope);
117
- remote.lib = lib;
118
- remote.lib.init(shareScope);
119
- remote.inited = true;
120
- }
121
- resolve(remote.lib);
122
- }).catch(reject)
123
- })
124
- })
125
- }
126
- } else {
127
- return remote.lib;
128
- }
129
- }
130
-
131
- function __federation_method_unwrapDefault(module) {
132
- return (module?.__esModule || module?.[Symbol.toStringTag] === 'Module')?module.default:module
133
- }
134
-
135
- function __federation_method_wrapDefault(module ,need){
136
- if (!module?.default && need) {
137
- let obj = Object.create(null);
138
- obj.default = module;
139
- obj.__esModule = true;
140
- return obj;
141
- }
142
- return module;
143
- }
144
-
145
- function __federation_method_getRemote(remoteName, componentName){
146
- return __federation_method_ensure(remoteName).then((remote) => remote.get(componentName).then(factory => factory()));
147
- }
148
-
149
- function __federation_method_setRemote(remoteName, remoteConfig) {
150
- remotesMap[remoteName] = remoteConfig;
151
- }
152
-
153
- async function __federation_method_add_origin_setRemote(remoteName, remoteUrl, options) {
154
- const _options = options || {}
155
- const _item = {
156
- external: Array.isArray(_options.external) ? _options.external : [_options.external],
157
- shareScope: _options.shareScope || 'default',
158
- format: _options.format || 'esm',
159
- from: _options.from ?? 'vite',
160
- externalType: _options.externalType || 'url'
161
- }
162
-
163
- __federation_method_setRemote(remoteName, {
164
- url: remoteUrl,
165
- format: _item.format,
166
- from: _item.from
167
- })
168
- }
169
-
170
- export {__federation_method_ensure, __federation_method_getRemote , __federation_method_setRemote , __federation_method_unwrapDefault , __federation_method_wrapDefault, __federation_method_add_origin_setRemote}
171
- ;`
172
- }
173
- : { __federation__: '' },
174
- config(config: UserConfig) {
175
- // need to include remotes in the optimizeDeps.exclude
176
- if (parsedOptions.devRemote.length) {
177
- const excludeRemotes: string[] = []
178
- parsedOptions.devRemote.forEach((item) => excludeRemotes.push(item[0]))
179
- let optimizeDeps = config.optimizeDeps
180
- if (!optimizeDeps) {
181
- optimizeDeps = config.optimizeDeps = {}
182
- }
183
- if (!optimizeDeps.exclude) {
184
- optimizeDeps.exclude = []
185
- }
186
- optimizeDeps.exclude = optimizeDeps.exclude.concat(excludeRemotes)
187
- }
188
- },
189
-
190
- configureServer(server: ViteDevServer) {
191
- // get moduleGraph for dev mode dynamic reference
192
- viteDevServer = server
193
- },
194
- async transform(this: TransformPluginContext, code: string, id: string) {
195
- if (builderInfo.isHost && !builderInfo.isRemote) {
196
- for (const arr of parsedOptions.devShared) {
197
- if (!arr[1].version && !arr[1].manuallyPackagePathSetting) {
198
- const packageJsonPath = (
199
- await this.resolve(`${arr[0]}/package.json`)
200
- )?.id
201
- if (!packageJsonPath) {
202
- this.error(
203
- `No description file or no version in description file (usually package.json) of ${arr[0]}(${packageJsonPath}). Add version to description file, or manually specify version in shared config.`
204
- )
205
- } else {
206
- const json = JSON.parse(
207
- readFileSync(packageJsonPath, { encoding: 'utf-8' })
208
- )
209
- arr[1].version = json.version
210
- }
211
- }
212
- }
213
- }
214
-
215
- if (id === '\0virtual:__federation__') {
216
- const scopeCode = await devSharedScopeCode.call(
217
- this,
218
- parsedOptions.devShared
219
- )
220
- return code.replace(getModuleMarker('shareScope'), scopeCode.join(','))
221
- }
222
-
223
- // ignore some not need to handle file types
224
- const fileExtname = getFileExtname(id)
225
- if (!transformFileTypeSet.has((fileExtname ?? '').toLowerCase())) {
226
- return
227
- }
228
-
229
- let ast: any | null = null
230
- try {
231
- ast = this.parse(code)
232
- } catch (err) {
233
- console.error(err)
234
- }
235
- if (!ast) {
236
- return null
237
- }
238
-
239
- const magicString = new MagicString(code)
240
- const hasStaticImported = new Map<string, string>()
241
-
242
- let requiresRuntime = false
243
- let manualRequired: any = null // set static import if exists
244
- walk(ast, {
245
- enter(node: any) {
246
- if (
247
- node.type === 'ImportDeclaration' &&
248
- node.source?.value === 'virtual:__federation__'
249
- ) {
250
- manualRequired = node
251
- }
252
-
253
- if (
254
- (node.type === 'ImportExpression' ||
255
- node.type === 'ImportDeclaration' ||
256
- node.type === 'ExportNamedDeclaration') &&
257
- node.source?.value?.indexOf('/') > -1
258
- ) {
259
- const moduleId = node.source.value
260
- const remote = devRemotes.find((r) => r.regexp.test(moduleId))
261
- const needWrap = remote?.config.from === 'vite'
262
- if (remote) {
263
- requiresRuntime = true
264
- const modName = `.${moduleId.slice(remote.id.length)}`
265
- switch (node.type) {
266
- case 'ImportExpression': {
267
- magicString.overwrite(
268
- node.start,
269
- node.end,
270
- `__federation_method_getRemote(${JSON.stringify(
271
- remote.id
272
- )} , ${JSON.stringify(
273
- modName
274
- )}).then(module=>__federation_method_wrapDefault(module, ${needWrap}))`
275
- )
276
- break
277
- }
278
- case 'ImportDeclaration': {
279
- if (node.specifiers?.length) {
280
- const afterImportName = `__federation_var_${moduleId.replace(
281
- /[@/\\.-]/g,
282
- ''
283
- )}`
284
- if (!hasStaticImported.has(moduleId)) {
285
- magicString.overwrite(
286
- node.start,
287
- node.end,
288
- `const ${afterImportName} = await __federation_method_getRemote(${JSON.stringify(
289
- remote.id
290
- )} , ${JSON.stringify(modName)});`
291
- )
292
- hasStaticImported.set(moduleId, afterImportName)
293
- }
294
- let deconstructStr = ''
295
- node.specifiers.forEach((spec) => {
296
- // default import , like import a from 'lib'
297
- if (spec.type === 'ImportDefaultSpecifier') {
298
- magicString.appendRight(
299
- node.end,
300
- `\n let ${spec.local.name} = __federation_method_unwrapDefault(${afterImportName}) `
301
- )
302
- } else if (spec.type === 'ImportSpecifier') {
303
- // like import {a as b} from 'lib'
304
- const importedName = spec.imported.name
305
- const localName = spec.local.name
306
- deconstructStr += `${
307
- importedName === localName
308
- ? localName
309
- : `${importedName} : ${localName}`
310
- },`
311
- } else if (spec.type === 'ImportNamespaceSpecifier') {
312
- // like import * as a from 'lib'
313
- magicString.appendRight(
314
- node.end,
315
- `let {${spec.local.name}} = ${afterImportName}`
316
- )
317
- }
318
- })
319
- if (deconstructStr.length > 0) {
320
- magicString.appendRight(
321
- node.end,
322
- `\n let {${deconstructStr.slice(
323
- 0,
324
- -1
325
- )}} = ${afterImportName}`
326
- )
327
- }
328
- }
329
- break
330
- }
331
- case 'ExportNamedDeclaration': {
332
- // handle export like export {a} from 'remotes/lib'
333
- const afterImportName = `__federation_var_${moduleId.replace(
334
- /[@/\\.-]/g,
335
- ''
336
- )}`
337
- if (!hasStaticImported.has(moduleId)) {
338
- hasStaticImported.set(moduleId, afterImportName)
339
- magicString.overwrite(
340
- node.start,
341
- node.end,
342
- `const ${afterImportName} = await __federation_method_getRemote(${JSON.stringify(
343
- remote.id
344
- )} , ${JSON.stringify(modName)});`
345
- )
346
- }
347
- if (node.specifiers.length > 0) {
348
- const specifiers = node.specifiers
349
- let exportContent = ''
350
- let deconstructContent = ''
351
- specifiers.forEach((spec) => {
352
- const localName = spec.local.name
353
- const exportName = spec.exported.name
354
- const variableName = `${afterImportName}_${localName}`
355
- deconstructContent = deconstructContent.concat(
356
- `${localName}:${variableName},`
357
- )
358
- exportContent = exportContent.concat(
359
- `${variableName} as ${exportName},`
360
- )
361
- })
362
- magicString.append(
363
- `\n const {${deconstructContent.slice(
364
- 0,
365
- deconstructContent.length - 1
366
- )}} = ${afterImportName}; \n`
367
- )
368
- magicString.append(
369
- `\n export {${exportContent.slice(
370
- 0,
371
- exportContent.length - 1
372
- )}}; `
373
- )
374
- }
375
- break
376
- }
377
- }
378
- }
379
- }
380
- }
381
- })
382
-
383
- if (requiresRuntime) {
384
- let requiresCode = `import {__federation_method_ensure, __federation_method_getRemote , __federation_method_wrapDefault , __federation_method_unwrapDefault, __federation_method_add_origin_setRemote} from '__federation__';\n\n`
385
- // clear static required
386
- if (manualRequired) {
387
- requiresCode = `import {__federation_method_setRemote, __federation_method_ensure, __federation_method_getRemote , __federation_method_wrapDefault , __federation_method_unwrapDefault, __federation_method_add_origin_setRemote} from '__federation__';\n\n`
388
- magicString.overwrite(manualRequired.start, manualRequired.end, ``)
389
- }
390
- magicString.prepend(requiresCode)
391
- }
392
- return magicString.toString()
393
- }
394
- }
395
-
396
- async function devSharedScopeCode(
397
- this: TransformPluginContext,
398
- shared: (string | ConfigTypeSet)[]
399
- ): Promise<string[]> {
400
- const res: string[] = []
401
- if (shared.length) {
402
- const serverConfiguration = viteDevServer.config.server
403
- const base = viteDevServer.config.base
404
- const cwdPath = normalizePath(process.cwd())
405
-
406
- for (const item of shared) {
407
- const moduleInfo = await this.resolve(item[1].packagePath, undefined, {
408
- skipSelf: true
409
- })
410
-
411
- if (!moduleInfo) continue
412
-
413
- const moduleFilePath = normalizePath(moduleInfo.id)
414
- const idx = moduleFilePath.indexOf(cwdPath)
415
-
416
- const relativePath =
417
- idx === 0 ? posix.join(base, moduleFilePath.slice(cwdPath.length)) : null
418
-
419
- const sharedName = item[0]
420
- const obj = item[1]
421
- let str = ''
422
- if (typeof obj === 'object') {
423
- const origin = serverConfiguration.origin
424
- const pathname = relativePath ?? `/@fs/${moduleInfo.id}`
425
- const url = origin
426
- ? `'${origin}${pathname}'`
427
- : `window.location.origin+'${pathname}'`
428
- str += `get:()=> get(${url}, ${REMOTE_FROM_PARAMETER})`
429
- res.push(`'${sharedName}':{'${obj.version}':{${str}}}`)
430
- }
431
- }
432
- }
433
- return res
434
- }
435
- }
@@ -1,29 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Origin.js and others.
3
- //
4
- // This program and the accompanying materials are licensed under Mulan PSL v2.
5
- // You can use this software according to the terms and conditions of the Mulan PSL v2.
6
- // You may obtain a copy of Mulan PSL v2 at:
7
- // http://license.coscl.org.cn/MulanPSL2
8
- // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
- // EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
- // MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
- // See the Mulan PSL v2 for more details.
12
- //
13
- // SPDX-License-Identifier: MulanPSL-2.0
14
- // *****************************************************************************
15
-
16
- import type { PluginHooks } from '../../types/pluginHooks'
17
- import { parseSharedOptions } from '../utils'
18
- import { parsedOptions } from '../public'
19
- import type { VitePluginFederationOptions } from '../../types'
20
-
21
- export function devSharedPlugin(
22
- options: VitePluginFederationOptions
23
- ): PluginHooks {
24
- parsedOptions.devShared = parseSharedOptions(options)
25
-
26
- return {
27
- name: 'originjs:shared-development'
28
- }
29
- }