@meethive/vite 0.0.1 → 0.0.2

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 (78) hide show
  1. package/dist/dynamic-remote.d.ts +2 -0
  2. package/dist/dynamic-remote.js +185 -0
  3. package/dist/dynamic-remote.mjs +163 -0
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +9 -325
  6. package/dist/index.mjs +9 -303
  7. package/dist/satisfy.d.ts +2 -0
  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 +0 -79
  29. package/dist/src/federation/src/runtime/dynamic-remote.d.ts.map +0 -1
  30. package/dist/src/federation/src/utils/html.d.ts +0 -12
  31. package/dist/src/federation/src/utils/html.d.ts.map +0 -1
  32. package/dist/src/federation/src/utils/index.d.ts +0 -29
  33. package/dist/src/federation/src/utils/index.d.ts.map +0 -1
  34. package/dist/src/federation/src/utils/semver/compare.d.ts +0 -10
  35. package/dist/src/federation/src/utils/semver/compare.d.ts.map +0 -1
  36. package/dist/src/federation/src/utils/semver/constants.d.ts +0 -11
  37. package/dist/src/federation/src/utils/semver/constants.d.ts.map +0 -1
  38. package/dist/src/federation/src/utils/semver/parser.d.ts +0 -10
  39. package/dist/src/federation/src/utils/semver/parser.d.ts.map +0 -1
  40. package/dist/src/federation/src/utils/semver/satisfy.d.ts +0 -2
  41. package/dist/src/federation/src/utils/semver/satisfy.d.ts.map +0 -1
  42. package/dist/src/federation/src/utils/semver/utils.d.ts +0 -12
  43. package/dist/src/federation/src/utils/semver/utils.d.ts.map +0 -1
  44. package/dist/src/monaco-editor/index.d.ts +0 -35
  45. package/dist/src/monaco-editor/index.d.ts.map +0 -1
  46. package/dist/src/monaco-editor/languageWork.d.ts +0 -10
  47. package/dist/src/monaco-editor/languageWork.d.ts.map +0 -1
  48. package/dist/src/monaco-editor/workerMiddleware.d.ts +0 -9
  49. package/dist/src/monaco-editor/workerMiddleware.d.ts.map +0 -1
  50. package/dist/src/sharp/index.d.ts +0 -12
  51. package/dist/src/sharp/index.d.ts.map +0 -1
  52. package/index.ts +0 -3
  53. package/src/federation/src/dev/expose-development.ts +0 -29
  54. package/src/federation/src/dev/remote-development.ts +0 -435
  55. package/src/federation/src/dev/shared-development.ts +0 -29
  56. package/src/federation/src/index.ts +0 -242
  57. package/src/federation/src/prod/expose-production.ts +0 -333
  58. package/src/federation/src/prod/federation_fn_import.js +0 -75
  59. package/src/federation/src/prod/remote-production.ts +0 -658
  60. package/src/federation/src/prod/shared-production.ts +0 -268
  61. package/src/federation/src/public.ts +0 -54
  62. package/src/federation/src/runtime/dynamic-remote.ts +0 -247
  63. package/src/federation/src/utils/html.ts +0 -165
  64. package/src/federation/src/utils/index.ts +0 -255
  65. package/src/federation/src/utils/semver/compare.ts +0 -131
  66. package/src/federation/src/utils/semver/constants.ts +0 -46
  67. package/src/federation/src/utils/semver/parser.ts +0 -253
  68. package/src/federation/src/utils/semver/satisfy.ts +0 -151
  69. package/src/federation/src/utils/semver/utils.ts +0 -93
  70. package/src/federation/types/dynamic-remote.d.ts +0 -105
  71. package/src/federation/types/index.d.ts +0 -344
  72. package/src/federation/types/pluginHooks.d.ts +0 -4
  73. package/src/federation/types/virtual-modules.d.ts +0 -48
  74. package/src/federation/types/viteDevServer.d.ts +0 -22
  75. package/src/monaco-editor/index.ts +0 -205
  76. package/src/monaco-editor/languageWork.ts +0 -36
  77. package/src/monaco-editor/workerMiddleware.ts +0 -78
  78. package/src/sharp/index.ts +0 -93
@@ -1,333 +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 { resolve, parse, basename, extname, relative, dirname } from 'path'
17
- import {
18
- getModuleMarker,
19
- normalizePath,
20
- parseExposeOptions,
21
- removeNonRegLetter,
22
- NAME_CHAR_REG
23
- } from '../utils'
24
- import {
25
- builderInfo,
26
- DYNAMIC_LOADING_CSS,
27
- DYNAMIC_LOADING_CSS_PREFIX,
28
- EXPOSES_MAP,
29
- EXPOSES_KEY_MAP,
30
- EXTERNALS,
31
- parsedOptions,
32
- SHARED,
33
- viteConfigResolved
34
- } from '../public'
35
- // @ts-ignore
36
- import type { AcornNode, OutputAsset, OutputChunk } from 'rollup'
37
- import type { VitePluginFederationOptions } from '../../types'
38
- import type { PluginHooks } from '../../types/pluginHooks'
39
- import MagicString from 'magic-string'
40
- import { walk } from 'estree-walker'
41
- import type { ResolvedConfig } from 'vite'
42
-
43
- export function prodExposePlugin(
44
- options: VitePluginFederationOptions
45
- ): PluginHooks {
46
- let moduleMap = ''
47
- const hasOptions = parsedOptions.prodExpose.some((expose) => {
48
- return expose[0] === parseExposeOptions(options)[0]?.[0]
49
- })
50
- if (!hasOptions) {
51
- parsedOptions.prodExpose = Array.prototype.concat(
52
- parsedOptions.prodExpose,
53
- parseExposeOptions(options)
54
- )
55
- }
56
- // exposes module
57
- for (const item of parseExposeOptions(options)) {
58
- const moduleName = getModuleMarker(`\${${item[0]}}`, SHARED)
59
- EXTERNALS.push(moduleName)
60
- const exposeFilepath = normalizePath(resolve(item[1].import))
61
- EXPOSES_MAP.set(item[0], exposeFilepath)
62
- EXPOSES_KEY_MAP.set(
63
- item[0],
64
- `__federation_expose_${removeNonRegLetter(item[0], NAME_CHAR_REG)}`
65
- )
66
- moduleMap += `\n"${item[0]}":()=>{
67
- ${DYNAMIC_LOADING_CSS}('${DYNAMIC_LOADING_CSS_PREFIX}${exposeFilepath}', ${item[1].dontAppendStylesToHead}, '${item[0]}')
68
- return __federation_import('\${__federation_expose_${item[0]}}').then(module =>Object.keys(module).every(item => exportSet.has(item)) ? () => module.default : () => module)},`
69
- }
70
-
71
- // let viteConfigResolved: ResolvedConfig
72
-
73
- return {
74
- name: 'originjs:expose-production',
75
- virtualFile: {
76
- // code generated for remote
77
- // language=JS
78
- [`__remoteEntryHelper__${options.filename}`]: `
79
- const currentImports = {}
80
- const exportSet = new Set(['Module', '__esModule', 'default', '_export_sfc']);
81
- let moduleMap = {${moduleMap}}
82
- const seen = {}
83
- export const ${DYNAMIC_LOADING_CSS} = (cssFilePaths, dontAppendStylesToHead, exposeItemName) => {
84
- const metaUrl = import.meta.url;
85
- if (typeof metaUrl === 'undefined') {
86
- console.warn('The remote style takes effect only when the build.target option in the vite.config.ts file is higher than that of "es2020".');
87
- return;
88
- }
89
-
90
- const curUrl = metaUrl.substring(0, metaUrl.lastIndexOf('${options.filename}'));
91
- const base = __VITE_BASE_PLACEHOLDER__;
92
- const assetsDir = __VITE_ASSETS_DIR_PLACEHOLDER__;
93
-
94
- cssFilePaths.forEach(cssPath => {
95
- let href = '';
96
- const baseUrl = base || curUrl;
97
- if (baseUrl) {
98
- const trimmer = {
99
- trailing: (path) => (path.endsWith('/') ? path.slice(0, -1) : path),
100
- leading: (path) => (path.startsWith('/') ? path.slice(1) : path)
101
- }
102
- const isAbsoluteUrl = (url) => url.startsWith('http') || url.startsWith('//');
103
-
104
- const cleanBaseUrl = trimmer.trailing(baseUrl).replace('.', '');
105
- const cleanAssetsDir = trimmer.leading(assetsDir);
106
- const cleanCssPath = trimmer.leading(cssPath);
107
- const cleanCurUrl = trimmer.trailing(curUrl);
108
-
109
- if (isAbsoluteUrl(baseUrl)) {
110
- href = [cleanBaseUrl, cleanAssetsDir, cleanCssPath].filter(Boolean).join('/');
111
- } else {
112
- // 当remoteEntry.js和CSS都在assets目录下时,使用相对路径
113
- const remoteEntryInAssets = cleanCurUrl.endsWith('/assets/') || cleanCurUrl.endsWith('/assets');
114
-
115
- if (remoteEntryInAssets) {
116
- // 都在assets目录下,直接使用CSS文件名
117
- href = [cleanCurUrl, cleanCssPath].filter(Boolean).join('/');
118
- } else if (cleanCurUrl.includes(cleanBaseUrl)) {
119
- href = [cleanCurUrl, cleanAssetsDir, cleanCssPath].filter(Boolean).join('/');
120
- } else {
121
- href = [cleanCurUrl + cleanBaseUrl, cleanAssetsDir, cleanCssPath].filter(Boolean).join('/');
122
- }
123
- }
124
- } else {
125
- href = cssPath;
126
- }
127
-
128
- if (dontAppendStylesToHead) {
129
- const key = 'css__${options.name}__' + exposeItemName;
130
- window[key] = window[key] || [];
131
- window[key].push(href);
132
- return;
133
- }
134
-
135
- if (href in seen) return;
136
- seen[href] = true;
137
-
138
- const element = document.createElement('link');
139
- element.rel = 'stylesheet';
140
- element.href = href;
141
- document.head.appendChild(element);
142
- });
143
- };
144
- async function __federation_import(name) {
145
- currentImports[name] ??= import(name)
146
- return currentImports[name]
147
- };
148
- export const get =(module) => {
149
- if(!moduleMap[module]) throw new Error('Can not find remote module ' + module)
150
- return moduleMap[module]();
151
- };
152
- export const init =(shareScope) => {
153
- globalThis.__federation_shared__= globalThis.__federation_shared__|| {};
154
- Object.entries(shareScope).forEach(([key, value]) => {
155
- for (const [versionKey, versionValue] of Object.entries(value)) {
156
- const scope = versionValue.scope || 'default'
157
- globalThis.__federation_shared__[scope] = globalThis.__federation_shared__[scope] || {};
158
- const shared= globalThis.__federation_shared__[scope];
159
- (shared[key] = shared[key]||{})[versionKey] = versionValue;
160
- }
161
- });
162
- }`
163
- },
164
-
165
- configResolved(config: ResolvedConfig) {
166
- if (config) {
167
- viteConfigResolved.config = config
168
- }
169
- },
170
-
171
- buildStart() {
172
- // if we don't expose any modules, there is no need to emit file
173
- if (parsedOptions.prodExpose.length > 0) {
174
- const assetsDir = builderInfo.assetsDir
175
- this.emitFile({
176
- fileName: assetsDir ? `${assetsDir}/${options.filename}` : options.filename ,
177
- type: 'chunk',
178
- id: `__remoteEntryHelper__${options.filename}`,
179
- preserveSignature: 'strict'
180
- })
181
- }
182
- },
183
-
184
- generateBundle(_options, bundle) {
185
- // replace import absolute path to chunk's fileName in remoteEntry.js
186
- let remoteEntryChunk
187
- for (const file in bundle) {
188
- const chunk = bundle[file] as OutputChunk
189
- if (
190
- chunk?.facadeModuleId ===
191
- `\0virtual:__remoteEntryHelper__${options.filename}`
192
- ) {
193
- remoteEntryChunk = chunk
194
- break
195
- }
196
- }
197
- // placeholder replace
198
- if (remoteEntryChunk) {
199
- // 替换 base 和 assetsDir 占位符
200
- remoteEntryChunk.code = remoteEntryChunk.code
201
- .replace(
202
- '__VITE_BASE_PLACEHOLDER__',
203
- `'${viteConfigResolved.config?.base || ''}'`
204
- )
205
- .replace(
206
- '__VITE_ASSETS_DIR_PLACEHOLDER__',
207
- `'${builderInfo.assetsDir || ''}'`
208
- )
209
-
210
- const filepathMap = new Map()
211
- const getFilename = (name) => parse(parse(name).name).name
212
- const cssBundlesMap: Map<string, OutputAsset | OutputChunk> =
213
- Object.keys(bundle)
214
- .filter((name) => extname(name) === '.css')
215
- .reduce((res, name) => {
216
- const filename = getFilename(name)
217
- res.set(filename, bundle[name])
218
- return res
219
- }, new Map())
220
- remoteEntryChunk.code = remoteEntryChunk.code.replace(
221
- new RegExp(`(["'])${DYNAMIC_LOADING_CSS_PREFIX}.*?\\1`, 'g'),
222
- (str) => {
223
- // when build.cssCodeSplit: false, all files are aggregated into style.xxxxxxxx.css
224
- if (
225
- viteConfigResolved.config &&
226
- !viteConfigResolved.config.build.cssCodeSplit
227
- ) {
228
- if (cssBundlesMap.size) {
229
- return `[${[...cssBundlesMap.values()]
230
- .map((cssBundle) =>
231
- JSON.stringify(basename(cssBundle.fileName))
232
- )
233
- .join(',')}]`
234
- } else {
235
- return '[]'
236
- }
237
- }
238
- const filepath = str.slice(
239
- (`'` + DYNAMIC_LOADING_CSS_PREFIX).length,
240
- -1
241
- )
242
- if (!filepath || !filepath.length) return str
243
- let fileBundle = filepathMap.get(filepath)
244
- if (!fileBundle) {
245
- fileBundle = Object.values(bundle).find(
246
- (b) => 'facadeModuleId' in b && b.facadeModuleId === filepath
247
- )
248
- if (fileBundle) filepathMap.set(filepath, fileBundle)
249
- else return str
250
- }
251
- const depCssFiles: Set<string> = new Set()
252
- const addDepCss = (bundleName) => {
253
- const theBundle = bundle[bundleName] as any
254
- if (theBundle && theBundle.viteMetadata) {
255
- for (const cssFileName of theBundle.viteMetadata.importedCss.values()) {
256
- const cssBundle = cssBundlesMap.get(getFilename(cssFileName))
257
- if (cssBundle) {
258
- depCssFiles.add(cssBundle.fileName)
259
- }
260
- }
261
- }
262
- if (theBundle && theBundle.imports && theBundle.imports.length) {
263
- theBundle.imports.forEach((name) => addDepCss(name))
264
- }
265
- }
266
-
267
- ;[fileBundle.fileName, ...fileBundle.imports].forEach(addDepCss)
268
-
269
- return `[${[...depCssFiles]
270
- .map((d) => JSON.stringify(basename(d)))
271
- .join(',')}]`
272
- }
273
- )
274
-
275
- // replace the export file placeholder path to final chunk path
276
- for (const expose of parseExposeOptions(options)) {
277
- const module = Object.keys(bundle).find((module) => {
278
- const chunk = bundle[module]
279
- return chunk.name === EXPOSES_KEY_MAP.get(expose[0])
280
- })
281
-
282
- if (module) {
283
- const chunk = bundle[module]
284
- const fileRelativePath = relative(
285
- dirname(remoteEntryChunk.fileName),
286
- chunk.fileName
287
- )
288
- const slashPath = fileRelativePath.replace(/\\/g, '/')
289
- remoteEntryChunk.code = remoteEntryChunk.code.replace(
290
- `\${__federation_expose_${expose[0]}}`,
291
- viteConfigResolved.config?.base?.replace(/\/+$/, '')
292
- ? [
293
- viteConfigResolved.config.base.replace(/\/+$/, ''),
294
- slashPath
295
- ]
296
- .filter(Boolean)
297
- .join('/')
298
- : `./${slashPath}`
299
- )
300
- }
301
- }
302
-
303
- // remove all __f__dynamic_loading_css__ after replace
304
- let ast: AcornNode | null = null
305
- try {
306
- ast = this.parse(remoteEntryChunk.code)
307
- } catch (err) {
308
- console.error(err)
309
- }
310
- if (!ast) {
311
- return
312
- }
313
- const magicString = new MagicString(remoteEntryChunk.code)
314
- // let cssFunctionName: string = DYNAMIC_LOADING_CSS
315
- walk(ast, {
316
- enter(node: any) {
317
- if (
318
- node &&
319
- node.type === 'CallExpression' &&
320
- typeof node.arguments[0]?.value === 'string' &&
321
- node.arguments[0]?.value.indexOf(
322
- `${DYNAMIC_LOADING_CSS_PREFIX}`
323
- ) > -1
324
- ) {
325
- magicString.remove(node.start, node.end + 1)
326
- }
327
- }
328
- })
329
- remoteEntryChunk.code = magicString.toString()
330
- }
331
- }
332
- }
333
- }
@@ -1,75 +0,0 @@
1
- import { satisfy } from '__federation_fn_satisfy'
2
-
3
- const currentImports = {}
4
-
5
- // eslint-disable-next-line no-undef
6
- const moduleMap = __rf_var__moduleMap
7
- const moduleCache = Object.create(null)
8
- async function importShared(name, shareScope = 'default') {
9
- return moduleCache[name]
10
- ? new Promise((r) => r(moduleCache[name]))
11
- : (await getSharedFromRuntime(name, shareScope)) || getSharedFromLocal(name)
12
- }
13
- // eslint-disable-next-line
14
- async function __federation_import(name) {
15
- currentImports[name] ??= import(name)
16
- return currentImports[name]
17
- }
18
- async function getSharedFromRuntime(name, shareScope) {
19
- let module = null
20
- if (globalThis?.__federation_shared__?.[shareScope]?.[name]) {
21
- const versionObj = globalThis.__federation_shared__[shareScope][name]
22
- const requiredVersion = moduleMap[name]?.requiredVersion
23
- const hasRequiredVersion = !!requiredVersion
24
- if (hasRequiredVersion) {
25
- const versionKey = Object.keys(versionObj).find((version) =>
26
- satisfy(version, requiredVersion)
27
- )
28
- if (versionKey) {
29
- const versionValue = versionObj[versionKey]
30
- module = await (await versionValue.get())()
31
- } else {
32
- console.log(
33
- `provider support ${name}(${versionKey}) is not satisfied requiredVersion(\${moduleMap[name].requiredVersion})`
34
- )
35
- }
36
- } else {
37
- const versionKey = Object.keys(versionObj)[0]
38
- const versionValue = versionObj[versionKey]
39
- module = await (await versionValue.get())()
40
- }
41
- }
42
- if (module) {
43
- return flattenModule(module, name)
44
- }
45
- }
46
- async function getSharedFromLocal(name) {
47
- if (moduleMap[name]?.import) {
48
- let module = await (await moduleMap[name].get())()
49
- return flattenModule(module, name)
50
- } else {
51
- console.error(
52
- `consumer config import=false,so cant use callback shared module`
53
- )
54
- }
55
- }
56
- function flattenModule(module, name) {
57
- // use a shared module which export default a function will getting error 'TypeError: xxx is not a function'
58
- if (typeof module.default === 'function') {
59
- Object.keys(module).forEach((key) => {
60
- if (key !== 'default') {
61
- module.default[key] = module[key]
62
- }
63
- })
64
- moduleCache[name] = module.default
65
- return module.default
66
- }
67
- if (module.default) module = Object.assign({}, module.default, module)
68
- moduleCache[name] = module
69
- return module
70
- }
71
- export {
72
- importShared,
73
- getSharedFromRuntime as importSharedRuntime,
74
- getSharedFromLocal as importSharedLocal
75
- }