@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.
- package/dist/{src/federation/src/runtime/dynamic-remote.d.ts → dynamic-remote.d.ts} +25 -19
- package/dist/dynamic-remote.js +185 -0
- package/dist/dynamic-remote.mjs +163 -0
- package/dist/index.d.ts +51 -4
- package/dist/index.js +1 -20
- package/dist/index.mjs +1 -20
- package/dist/{src/federation/src/utils/semver/satisfy.d.ts → satisfy.d.ts} +2 -1
- package/dist/satisfy.js +381 -0
- package/dist/satisfy.mjs +381 -0
- package/package.json +20 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/src/federation/src/dev/expose-development.d.ts +0 -5
- package/dist/src/federation/src/dev/expose-development.d.ts.map +0 -1
- package/dist/src/federation/src/dev/remote-development.d.ts +0 -5
- package/dist/src/federation/src/dev/remote-development.d.ts.map +0 -1
- package/dist/src/federation/src/dev/shared-development.d.ts +0 -5
- package/dist/src/federation/src/dev/shared-development.d.ts.map +0 -1
- package/dist/src/federation/src/index.d.ts +0 -7
- package/dist/src/federation/src/index.d.ts.map +0 -1
- package/dist/src/federation/src/prod/expose-production.d.ts +0 -5
- package/dist/src/federation/src/prod/expose-production.d.ts.map +0 -1
- package/dist/src/federation/src/prod/remote-production.d.ts +0 -7
- package/dist/src/federation/src/prod/remote-production.d.ts.map +0 -1
- package/dist/src/federation/src/prod/shared-production.d.ts +0 -5
- package/dist/src/federation/src/prod/shared-production.d.ts.map +0 -1
- package/dist/src/federation/src/public.d.ts +0 -40
- package/dist/src/federation/src/public.d.ts.map +0 -1
- package/dist/src/federation/src/runtime/dynamic-remote.d.ts.map +0 -1
- package/dist/src/federation/src/utils/html.d.ts +0 -12
- package/dist/src/federation/src/utils/html.d.ts.map +0 -1
- package/dist/src/federation/src/utils/index.d.ts +0 -29
- package/dist/src/federation/src/utils/index.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/compare.d.ts +0 -10
- package/dist/src/federation/src/utils/semver/compare.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/constants.d.ts +0 -11
- package/dist/src/federation/src/utils/semver/constants.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/parser.d.ts +0 -10
- package/dist/src/federation/src/utils/semver/parser.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/satisfy.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/utils.d.ts +0 -12
- package/dist/src/federation/src/utils/semver/utils.d.ts.map +0 -1
- package/dist/src/monaco-editor/index.d.ts +0 -35
- package/dist/src/monaco-editor/index.d.ts.map +0 -1
- package/dist/src/monaco-editor/languageWork.d.ts +0 -10
- package/dist/src/monaco-editor/languageWork.d.ts.map +0 -1
- package/dist/src/monaco-editor/workerMiddleware.d.ts +0 -9
- package/dist/src/monaco-editor/workerMiddleware.d.ts.map +0 -1
- package/dist/src/sharp/index.d.ts +0 -12
- package/dist/src/sharp/index.d.ts.map +0 -1
- package/index.ts +0 -3
- package/src/federation/src/dev/expose-development.ts +0 -29
- package/src/federation/src/dev/remote-development.ts +0 -435
- package/src/federation/src/dev/shared-development.ts +0 -29
- package/src/federation/src/index.ts +0 -242
- package/src/federation/src/prod/expose-production.ts +0 -333
- package/src/federation/src/prod/federation_fn_import.js +0 -75
- package/src/federation/src/prod/remote-production.ts +0 -658
- package/src/federation/src/prod/shared-production.ts +0 -268
- package/src/federation/src/public.ts +0 -54
- package/src/federation/src/runtime/dynamic-remote.ts +0 -247
- package/src/federation/src/utils/html.ts +0 -165
- package/src/federation/src/utils/index.ts +0 -255
- package/src/federation/src/utils/semver/compare.ts +0 -131
- package/src/federation/src/utils/semver/constants.ts +0 -46
- package/src/federation/src/utils/semver/parser.ts +0 -253
- package/src/federation/src/utils/semver/satisfy.ts +0 -151
- package/src/federation/src/utils/semver/utils.ts +0 -93
- package/src/federation/types/dynamic-remote.d.ts +0 -105
- package/src/federation/types/index.d.ts +0 -344
- package/src/federation/types/pluginHooks.d.ts +0 -4
- package/src/federation/types/virtual-modules.d.ts +0 -48
- package/src/federation/types/viteDevServer.d.ts +0 -22
- package/src/monaco-editor/index.ts +0 -205
- package/src/monaco-editor/languageWork.ts +0 -36
- package/src/monaco-editor/workerMiddleware.ts +0 -78
- package/src/sharp/index.ts +0 -93
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
export interface HtmlTagDescriptor {
|
|
2
|
-
tag: string
|
|
3
|
-
attrs?: Record<string, string | boolean | undefined>
|
|
4
|
-
children?: string | HtmlTagDescriptor[]
|
|
5
|
-
/**
|
|
6
|
-
* default: 'head-prepend'
|
|
7
|
-
*/
|
|
8
|
-
injectTo?: 'head' | 'body' | 'head-prepend' | 'body-prepend'
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const unaryTags = new Set(['link', 'meta', 'base'])
|
|
12
|
-
|
|
13
|
-
function serializeTag(
|
|
14
|
-
{ tag, attrs, children }: HtmlTagDescriptor,
|
|
15
|
-
indent = ''
|
|
16
|
-
): string {
|
|
17
|
-
if (unaryTags.has(tag)) {
|
|
18
|
-
return `<${tag}${serializeAttrs(attrs)}>`
|
|
19
|
-
} else {
|
|
20
|
-
return `<${tag}${serializeAttrs(attrs)}>${serializeTags(
|
|
21
|
-
children,
|
|
22
|
-
incrementIndent(indent)
|
|
23
|
-
)}</${tag}>`
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function serializeTags(
|
|
28
|
-
tags: HtmlTagDescriptor['children'],
|
|
29
|
-
indent = ''
|
|
30
|
-
): string {
|
|
31
|
-
if (typeof tags === 'string') {
|
|
32
|
-
return tags
|
|
33
|
-
} else if (tags && tags.length) {
|
|
34
|
-
return tags.map((tag) => `${indent}${serializeTag(tag, indent)}\n`).join('')
|
|
35
|
-
}
|
|
36
|
-
return ''
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function serializeAttrs(attrs: HtmlTagDescriptor['attrs']): string {
|
|
40
|
-
let res = ''
|
|
41
|
-
for (const key in attrs) {
|
|
42
|
-
if (typeof attrs[key] === 'boolean') {
|
|
43
|
-
res += attrs[key] ? ` ${key}` : ``
|
|
44
|
-
} else {
|
|
45
|
-
res += ` ${key}="${escapeHtml(attrs[key])}"`
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return res
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function incrementIndent(indent = '') {
|
|
52
|
-
return `${indent}${indent[0] === '\t' ? '\t' : ' '}`
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const matchHtmlRegExp = /["'&<>]/
|
|
56
|
-
|
|
57
|
-
function escapeHtml(string: any) {
|
|
58
|
-
const str = '' + string
|
|
59
|
-
const match = matchHtmlRegExp.exec(str)
|
|
60
|
-
|
|
61
|
-
if (!match) {
|
|
62
|
-
return str
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let escape
|
|
66
|
-
let html = ''
|
|
67
|
-
let index = 0
|
|
68
|
-
let lastIndex = 0
|
|
69
|
-
|
|
70
|
-
for (index = match.index; index < str.length; index++) {
|
|
71
|
-
switch (str.charCodeAt(index)) {
|
|
72
|
-
case 34: // "
|
|
73
|
-
escape = '"'
|
|
74
|
-
break
|
|
75
|
-
case 38: // &
|
|
76
|
-
escape = '&'
|
|
77
|
-
break
|
|
78
|
-
case 39: // '
|
|
79
|
-
escape = '''
|
|
80
|
-
break
|
|
81
|
-
case 60: // <
|
|
82
|
-
escape = '<'
|
|
83
|
-
break
|
|
84
|
-
case 62: // >
|
|
85
|
-
escape = '>'
|
|
86
|
-
break
|
|
87
|
-
default:
|
|
88
|
-
continue
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (lastIndex !== index) {
|
|
92
|
-
html += str.substring(lastIndex, index)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
lastIndex = index + 1
|
|
96
|
-
html += escape
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return lastIndex !== index ? html + str.substring(lastIndex, index) : html
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const headInjectRE = /([ \t]*)<\/head>/i
|
|
103
|
-
const headPrependInjectRE = /([ \t]*)<head[^>]*>/i
|
|
104
|
-
|
|
105
|
-
const htmlPrependInjectRE = /([ \t]*)<html[^>]*>/i
|
|
106
|
-
|
|
107
|
-
const bodyPrependInjectRE = /([ \t]*)<body[^>]*>/i
|
|
108
|
-
|
|
109
|
-
const doctypePrependInjectRE = /<!doctype html>/i
|
|
110
|
-
|
|
111
|
-
export const toPreloadTag = (href: string): HtmlTagDescriptor => ({
|
|
112
|
-
tag: 'link',
|
|
113
|
-
attrs: {
|
|
114
|
-
rel: 'modulepreload',
|
|
115
|
-
crossorigin: true,
|
|
116
|
-
href
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
export function injectToHead(
|
|
121
|
-
html: string,
|
|
122
|
-
tags: HtmlTagDescriptor[],
|
|
123
|
-
prepend = false
|
|
124
|
-
) {
|
|
125
|
-
if (tags.length === 0) return html
|
|
126
|
-
|
|
127
|
-
if (prepend) {
|
|
128
|
-
// inject as the first element of head
|
|
129
|
-
if (headPrependInjectRE.test(html)) {
|
|
130
|
-
return html.replace(
|
|
131
|
-
headPrependInjectRE,
|
|
132
|
-
(match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
// inject before head close
|
|
137
|
-
if (headInjectRE.test(html)) {
|
|
138
|
-
// respect indentation of head tag
|
|
139
|
-
return html.replace(
|
|
140
|
-
headInjectRE,
|
|
141
|
-
(match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
-
// try to inject before the body tag
|
|
145
|
-
if (bodyPrependInjectRE.test(html)) {
|
|
146
|
-
return html.replace(
|
|
147
|
-
bodyPrependInjectRE,
|
|
148
|
-
(match, p1) => `${serializeTags(tags, p1)}\n${match}`
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// if no head tag is present, we prepend the tag for both prepend and append
|
|
153
|
-
return prependInjectFallback(html, tags)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function prependInjectFallback(html: string, tags: HtmlTagDescriptor[]) {
|
|
157
|
-
// prepend to the html tag, append after doctype, or the document start
|
|
158
|
-
if (htmlPrependInjectRE.test(html)) {
|
|
159
|
-
return html.replace(htmlPrependInjectRE, `$&\n${serializeTags(tags)}`)
|
|
160
|
-
}
|
|
161
|
-
if (doctypePrependInjectRE.test(html)) {
|
|
162
|
-
return html.replace(doctypePrependInjectRE, `$&\n${serializeTags(tags)}`)
|
|
163
|
-
}
|
|
164
|
-
return serializeTags(tags) + html
|
|
165
|
-
}
|
|
@@ -1,255 +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 {
|
|
17
|
-
ConfigTypeSet,
|
|
18
|
-
Exposes,
|
|
19
|
-
Remotes,
|
|
20
|
-
RemotesConfig,
|
|
21
|
-
Shared,
|
|
22
|
-
VitePluginFederationOptions
|
|
23
|
-
} from '../../types'
|
|
24
|
-
import { readFileSync } from 'fs'
|
|
25
|
-
import { createHash } from 'crypto'
|
|
26
|
-
import path, { parse, posix } from 'path'
|
|
27
|
-
import type { PluginContext } from 'rollup'
|
|
28
|
-
|
|
29
|
-
export * from './html'
|
|
30
|
-
|
|
31
|
-
export function findDependencies(
|
|
32
|
-
this: PluginContext,
|
|
33
|
-
id: string,
|
|
34
|
-
sets: Set<string>,
|
|
35
|
-
sharedModuleIds: Map<string, string>,
|
|
36
|
-
usedSharedModuleIds: Set<string>
|
|
37
|
-
): void {
|
|
38
|
-
if (!sets.has(id)) {
|
|
39
|
-
sets.add(id)
|
|
40
|
-
const moduleInfo = this.getModuleInfo(id)
|
|
41
|
-
if (moduleInfo?.importedIds) {
|
|
42
|
-
moduleInfo.importedIds.forEach((id) => {
|
|
43
|
-
findDependencies.apply(this, [
|
|
44
|
-
id,
|
|
45
|
-
sets,
|
|
46
|
-
sharedModuleIds,
|
|
47
|
-
usedSharedModuleIds
|
|
48
|
-
])
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
if (sharedModuleIds.has(id)) {
|
|
52
|
-
usedSharedModuleIds.add(sharedModuleIds.get(id) as string)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function parseSharedOptions(
|
|
58
|
-
options: VitePluginFederationOptions
|
|
59
|
-
): (string | ConfigTypeSet)[] {
|
|
60
|
-
return parseOptions(
|
|
61
|
-
options.shared || {},
|
|
62
|
-
(value, key) => ({
|
|
63
|
-
import: true,
|
|
64
|
-
shareScope: 'default',
|
|
65
|
-
packagePath: key,
|
|
66
|
-
// Whether the path is set manually
|
|
67
|
-
manuallyPackagePathSetting: false,
|
|
68
|
-
generate: true,
|
|
69
|
-
modulePreload: false
|
|
70
|
-
}),
|
|
71
|
-
(value, key) => {
|
|
72
|
-
value.import = value.import ?? true
|
|
73
|
-
value.shareScope = value.shareScope || 'default'
|
|
74
|
-
value.packagePath = value.packagePath || key
|
|
75
|
-
value.manuallyPackagePathSetting = value.packagePath !== key
|
|
76
|
-
value.generate = value.generate ?? true
|
|
77
|
-
value.modulePreload = value.modulePreload ?? false
|
|
78
|
-
return value
|
|
79
|
-
}
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function parseExposeOptions(
|
|
84
|
-
options: VitePluginFederationOptions
|
|
85
|
-
): (string | ConfigTypeSet)[] {
|
|
86
|
-
return parseOptions(
|
|
87
|
-
options.exposes,
|
|
88
|
-
(item) => {
|
|
89
|
-
return {
|
|
90
|
-
import: item,
|
|
91
|
-
name: undefined,
|
|
92
|
-
dontAppendStylesToHead: false
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
(item) => ({
|
|
96
|
-
import: item.import,
|
|
97
|
-
name: item.name || undefined,
|
|
98
|
-
dontAppendStylesToHead: item.dontAppendStylesToHead || false
|
|
99
|
-
})
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function createContentHash(path: string): string {
|
|
104
|
-
const content = readFileSync(path, { encoding: 'utf-8' })
|
|
105
|
-
return createHash('md5').update(content).digest('hex').toString().slice(0, 8)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function parseRemoteOptions(
|
|
109
|
-
options: VitePluginFederationOptions
|
|
110
|
-
): (string | ConfigTypeSet)[] {
|
|
111
|
-
return parseOptions(
|
|
112
|
-
options.remotes ? options.remotes : {},
|
|
113
|
-
(item) => ({
|
|
114
|
-
external: Array.isArray(item) ? item : [item],
|
|
115
|
-
shareScope: options.shareScope || 'default',
|
|
116
|
-
format: 'esm',
|
|
117
|
-
from: 'vite',
|
|
118
|
-
externalType: 'url'
|
|
119
|
-
}),
|
|
120
|
-
(item) => ({
|
|
121
|
-
external: Array.isArray(item.external) ? item.external : [item.external],
|
|
122
|
-
shareScope: item.shareScope || options.shareScope || 'default',
|
|
123
|
-
format: item.format || 'esm',
|
|
124
|
-
from: item.from ?? 'vite',
|
|
125
|
-
externalType: item.externalType || 'url'
|
|
126
|
-
})
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function parseOptions(
|
|
131
|
-
options: Exposes | Remotes | Shared | undefined,
|
|
132
|
-
normalizeSimple: (value: any, key: any) => ConfigTypeSet,
|
|
133
|
-
normalizeOptions: (value: any, key: any) => ConfigTypeSet
|
|
134
|
-
): (string | ConfigTypeSet)[] {
|
|
135
|
-
if (!options) {
|
|
136
|
-
return []
|
|
137
|
-
}
|
|
138
|
-
const list: {
|
|
139
|
-
[index: number]: string | ConfigTypeSet
|
|
140
|
-
}[] = []
|
|
141
|
-
const array = (items: (string | ConfigTypeSet)[]) => {
|
|
142
|
-
for (const item of items) {
|
|
143
|
-
if (typeof item === 'string') {
|
|
144
|
-
list.push([item, normalizeSimple(item, item)])
|
|
145
|
-
} else if (item && typeof item === 'object') {
|
|
146
|
-
object(item)
|
|
147
|
-
} else {
|
|
148
|
-
throw new Error('Unexpected options format')
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const object = (obj) => {
|
|
153
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
154
|
-
if (typeof value === 'string' || Array.isArray(value)) {
|
|
155
|
-
list.push([key, normalizeSimple(value, key)])
|
|
156
|
-
} else {
|
|
157
|
-
list.push([key, normalizeOptions(value, key)])
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (Array.isArray(options)) {
|
|
162
|
-
array(options)
|
|
163
|
-
} else if (typeof options === 'object') {
|
|
164
|
-
object(options)
|
|
165
|
-
} else {
|
|
166
|
-
throw new Error('Unexpected options format')
|
|
167
|
-
}
|
|
168
|
-
return list
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const letterReg = new RegExp('[0-9a-zA-Z]+')
|
|
172
|
-
|
|
173
|
-
export function removeNonRegLetter(str: string, reg = letterReg): string {
|
|
174
|
-
let needUpperCase = false
|
|
175
|
-
let ret = ''
|
|
176
|
-
for (const c of str) {
|
|
177
|
-
if (reg.test(c)) {
|
|
178
|
-
ret += needUpperCase ? c.toUpperCase() : c
|
|
179
|
-
needUpperCase = false
|
|
180
|
-
} else {
|
|
181
|
-
needUpperCase = true
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return ret
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function getModuleMarker(value: string, type?: string): string {
|
|
188
|
-
return type ? `__rf_${type}__${value}` : `__rf_placeholder__${value}`
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function normalizePath(id: string): string {
|
|
192
|
-
return posix.normalize(id.replace(/\\/g, '/'))
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export function uniqueArr<T>(arr: T[]): T[] {
|
|
196
|
-
return Array.from(new Set(arr))
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function isSameFilepath(src: string, dest: string): boolean {
|
|
200
|
-
if (!src || !dest) {
|
|
201
|
-
return false
|
|
202
|
-
}
|
|
203
|
-
src = normalizePath(src)
|
|
204
|
-
dest = normalizePath(dest)
|
|
205
|
-
const srcExt = parse(src).ext
|
|
206
|
-
const destExt = parse(dest).ext
|
|
207
|
-
if (srcExt && destExt && srcExt !== destExt) {
|
|
208
|
-
return false
|
|
209
|
-
}
|
|
210
|
-
if (srcExt) {
|
|
211
|
-
src = src.slice(0, -srcExt.length)
|
|
212
|
-
}
|
|
213
|
-
if (destExt) {
|
|
214
|
-
dest = dest.slice(0, -destExt.length)
|
|
215
|
-
}
|
|
216
|
-
return src === dest
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export type Remote = { id: string; regexp: RegExp; config: RemotesConfig }
|
|
220
|
-
|
|
221
|
-
export function createRemotesMap(remotes: Remote[]): string {
|
|
222
|
-
const createUrl = (remote: Remote) => {
|
|
223
|
-
const external = remote.config.external[0]
|
|
224
|
-
const externalType = remote.config.externalType
|
|
225
|
-
if (externalType === 'promise') {
|
|
226
|
-
return `()=>${external}`
|
|
227
|
-
} else {
|
|
228
|
-
return `'${external}'`
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return `const remotesMap = {
|
|
232
|
-
${remotes
|
|
233
|
-
.map(
|
|
234
|
-
(remote) =>
|
|
235
|
-
`'${remote.id}':{url:${createUrl(remote)},format:'${
|
|
236
|
-
remote.config.format
|
|
237
|
-
}',from:'${remote.config.from}'}`
|
|
238
|
-
)
|
|
239
|
-
.join(',\n ')}
|
|
240
|
-
};`
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* get file extname from url
|
|
245
|
-
* @param url
|
|
246
|
-
*/
|
|
247
|
-
export function getFileExtname(url: string): string {
|
|
248
|
-
const fileNameAndParamArr = normalizePath(url).split('/')
|
|
249
|
-
const fileNameAndParam = fileNameAndParamArr[fileNameAndParamArr.length - 1]
|
|
250
|
-
const fileName = fileNameAndParam.split('?')[0]
|
|
251
|
-
return path.extname(fileName)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export const REMOTE_FROM_PARAMETER = 'remoteFrom'
|
|
255
|
-
export const NAME_CHAR_REG = new RegExp('[0-9a-zA-Z@_-]+')
|
|
@@ -1,131 +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
|
-
export interface CompareAtom {
|
|
17
|
-
operator: string
|
|
18
|
-
version: string
|
|
19
|
-
major: string
|
|
20
|
-
minor: string
|
|
21
|
-
patch: string
|
|
22
|
-
preRelease?: string[]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function compareAtom(
|
|
26
|
-
rangeAtom: string | number,
|
|
27
|
-
versionAtom: string | number
|
|
28
|
-
): number {
|
|
29
|
-
rangeAtom = +rangeAtom || rangeAtom
|
|
30
|
-
versionAtom = +versionAtom || versionAtom
|
|
31
|
-
|
|
32
|
-
if (rangeAtom > versionAtom) {
|
|
33
|
-
return 1
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (rangeAtom === versionAtom) {
|
|
37
|
-
return 0
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return -1
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function comparePreRelease(
|
|
44
|
-
rangeAtom: CompareAtom,
|
|
45
|
-
versionAtom: CompareAtom
|
|
46
|
-
): number {
|
|
47
|
-
const { preRelease: rangePreRelease } = rangeAtom
|
|
48
|
-
const { preRelease: versionPreRelease } = versionAtom
|
|
49
|
-
|
|
50
|
-
if (rangePreRelease === undefined && !!versionPreRelease) {
|
|
51
|
-
return 1
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!!rangePreRelease && versionPreRelease === undefined) {
|
|
55
|
-
return -1
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (rangePreRelease === undefined && versionPreRelease === undefined) {
|
|
59
|
-
return 0
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
for (let i = 0, n = rangePreRelease!.length; i <= n; i++) {
|
|
63
|
-
const rangeElement = rangePreRelease![i]
|
|
64
|
-
const versionElement = versionPreRelease![i]
|
|
65
|
-
|
|
66
|
-
if (rangeElement === versionElement) {
|
|
67
|
-
continue
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (rangeElement === undefined && versionElement === undefined) {
|
|
71
|
-
return 0
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!rangeElement) {
|
|
75
|
-
return 1
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!versionElement) {
|
|
79
|
-
return -1
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return compareAtom(rangeElement, versionElement)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return 0
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function compareVersion(
|
|
89
|
-
rangeAtom: CompareAtom,
|
|
90
|
-
versionAtom: CompareAtom
|
|
91
|
-
): number {
|
|
92
|
-
return (
|
|
93
|
-
compareAtom(rangeAtom.major, versionAtom.major) ||
|
|
94
|
-
compareAtom(rangeAtom.minor, versionAtom.minor) ||
|
|
95
|
-
compareAtom(rangeAtom.patch, versionAtom.patch) ||
|
|
96
|
-
comparePreRelease(rangeAtom, versionAtom)
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function eq(rangeAtom: CompareAtom, versionAtom: CompareAtom): boolean {
|
|
101
|
-
return rangeAtom.version === versionAtom.version
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function compare(
|
|
105
|
-
rangeAtom: CompareAtom,
|
|
106
|
-
versionAtom: CompareAtom
|
|
107
|
-
): boolean {
|
|
108
|
-
switch (rangeAtom.operator) {
|
|
109
|
-
case '':
|
|
110
|
-
case '=':
|
|
111
|
-
return eq(rangeAtom, versionAtom)
|
|
112
|
-
case '>':
|
|
113
|
-
return compareVersion(rangeAtom, versionAtom) < 0
|
|
114
|
-
case '>=':
|
|
115
|
-
return (
|
|
116
|
-
eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0
|
|
117
|
-
)
|
|
118
|
-
case '<':
|
|
119
|
-
return compareVersion(rangeAtom, versionAtom) > 0
|
|
120
|
-
case '<=':
|
|
121
|
-
return (
|
|
122
|
-
eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0
|
|
123
|
-
)
|
|
124
|
-
case undefined: {
|
|
125
|
-
// mean * or x -> all versions
|
|
126
|
-
return true
|
|
127
|
-
}
|
|
128
|
-
default:
|
|
129
|
-
return false
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,46 +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
|
-
// those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant
|
|
17
|
-
|
|
18
|
-
const buildIdentifier = '[0-9A-Za-z-]+'
|
|
19
|
-
const build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`
|
|
20
|
-
const numericIdentifier = '0|[1-9]\\d*'
|
|
21
|
-
const numericIdentifierLoose = '[0-9]+'
|
|
22
|
-
const nonNumericIdentifier = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
|
|
23
|
-
const preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`
|
|
24
|
-
const preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`
|
|
25
|
-
const preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`
|
|
26
|
-
const preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`
|
|
27
|
-
const xRangeIdentifier = `${numericIdentifier}|x|X|\\*`
|
|
28
|
-
const xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`
|
|
29
|
-
export const hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`
|
|
30
|
-
const mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`
|
|
31
|
-
const loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`
|
|
32
|
-
const gtlt = '((?:<|>)?=?)'
|
|
33
|
-
export const comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`
|
|
34
|
-
const loneTilde = '(?:~>?)'
|
|
35
|
-
export const tildeTrim = `(\\s*)${loneTilde}\\s+`
|
|
36
|
-
const loneCaret = '(?:\\^)'
|
|
37
|
-
export const caretTrim = `(\\s*)${loneCaret}\\s+`
|
|
38
|
-
export const star = '(<|>)?=?\\s*\\*'
|
|
39
|
-
export const caret = `^${loneCaret}${xRangePlain}$`
|
|
40
|
-
const mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`
|
|
41
|
-
const fullPlain = `v?${mainVersion}${preRelease}?${build}?`
|
|
42
|
-
export const tilde = `^${loneTilde}${xRangePlain}$`
|
|
43
|
-
export const xRange = `^${gtlt}\\s*${xRangePlain}$`
|
|
44
|
-
export const comparator = `^${gtlt}\\s*(${fullPlain})$|^$`
|
|
45
|
-
// copy from semver package
|
|
46
|
-
export const gte0 = '^\\s*>=\\s*0.0.0\\s*$'
|