publish-microfrontend 1.8.0-beta.7544 → 1.8.0-beta.7655
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/lib/index.js +9074 -8804
- package/package.json +5 -5
- package/src/http.ts +18 -7
- package/src/index.ts +9 -4
- package/src/utils.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "publish-microfrontend",
|
|
3
|
-
"version": "1.8.0-beta.
|
|
3
|
+
"version": "1.8.0-beta.7655",
|
|
4
4
|
"description": "A CLI for publishing micro frontends to a feed service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modules",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/rc": "^1.1.0",
|
|
51
51
|
"@types/rimraf": "^2.0.2",
|
|
52
52
|
"@types/tar": "^4.0.0",
|
|
53
|
-
"@types/yargs": "^
|
|
53
|
+
"@types/yargs": "^17",
|
|
54
54
|
"axios": "^1.7.7",
|
|
55
55
|
"chalk": "^4.0.0",
|
|
56
56
|
"enhanced-resolve": "^5.10.0",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"rc": "^1.2.8",
|
|
67
67
|
"rimraf": "^3.0.0",
|
|
68
68
|
"tar": "^6.2.0",
|
|
69
|
-
"typescript": "^5
|
|
70
|
-
"yargs": "^
|
|
69
|
+
"typescript": "^5",
|
|
70
|
+
"yargs": "^17"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "68e1232fe36c56cf7edaa546389bc635693907bf"
|
|
73
73
|
}
|
package/src/http.ts
CHANGED
|
@@ -34,10 +34,22 @@ export interface PostFormResult {
|
|
|
34
34
|
|
|
35
35
|
export type FormDataObj = Record<string, string | [Buffer, string]>;
|
|
36
36
|
|
|
37
|
+
export interface AgentOptions {
|
|
38
|
+
ca?: Buffer;
|
|
39
|
+
allowSelfSigned?: boolean;
|
|
40
|
+
}
|
|
37
41
|
|
|
38
|
-
export
|
|
39
|
-
|
|
42
|
+
export function getAgent({ allowSelfSigned, ca }: AgentOptions) {
|
|
43
|
+
if (ca) {
|
|
44
|
+
return new Agent({ ca });
|
|
45
|
+
} else if (allowSelfSigned) {
|
|
46
|
+
return new Agent({ rejectUnauthorized: false });
|
|
47
|
+
} else {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
40
51
|
|
|
52
|
+
export async function downloadFile(url: string, httpsAgent?: Agent): Promise<Array<string>> {
|
|
41
53
|
try {
|
|
42
54
|
const res = await axios.get<Stream>(url, {
|
|
43
55
|
responseType: 'stream',
|
|
@@ -58,10 +70,9 @@ export function postForm(
|
|
|
58
70
|
key: string,
|
|
59
71
|
formData: FormDataObj,
|
|
60
72
|
customHeaders: Record<string, string> = {},
|
|
61
|
-
|
|
73
|
+
httpsAgent?: Agent,
|
|
62
74
|
interactive = false,
|
|
63
75
|
): Promise<PostFormResult> {
|
|
64
|
-
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
65
76
|
const form = new FormData();
|
|
66
77
|
|
|
67
78
|
Object.keys(formData).forEach((key) => {
|
|
@@ -124,7 +135,7 @@ export function postForm(
|
|
|
124
135
|
|
|
125
136
|
if (typeof interactiveAuth === 'string') {
|
|
126
137
|
return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
|
|
127
|
-
postForm(target, mode, token, formData, customHeaders,
|
|
138
|
+
postForm(target, mode, token, formData, customHeaders, httpsAgent, false),
|
|
128
139
|
);
|
|
129
140
|
}
|
|
130
141
|
}
|
|
@@ -173,9 +184,9 @@ export function postFile(
|
|
|
173
184
|
file: Buffer,
|
|
174
185
|
customFields: Record<string, string> = {},
|
|
175
186
|
customHeaders: Record<string, string> = {},
|
|
176
|
-
|
|
187
|
+
agent?: Agent,
|
|
177
188
|
interactive = false,
|
|
178
189
|
): Promise<PostFormResult> {
|
|
179
190
|
const data: FormDataObj = { ...customFields, file: [file, 'microfrontend.tgz'] };
|
|
180
|
-
return postForm(target, scheme, key, data, customHeaders,
|
|
191
|
+
return postForm(target, scheme, key, data, customHeaders, agent, interactive);
|
|
181
192
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,13 +7,14 @@ import { basename } from 'path';
|
|
|
7
7
|
import { readFile } from 'fs/promises';
|
|
8
8
|
import { progress, fail, logDone, logFail, logInfo } from './log';
|
|
9
9
|
import { getCa, getFiles } from './utils';
|
|
10
|
-
import { postFile } from './http';
|
|
10
|
+
import { getAgent, postFile } from './http';
|
|
11
11
|
|
|
12
12
|
const current = process.cwd();
|
|
13
13
|
const defaultArgs = rc('microfrontend', {
|
|
14
14
|
url: undefined,
|
|
15
15
|
apiKey: undefined,
|
|
16
16
|
cert: undefined,
|
|
17
|
+
allowSelfSigned: false,
|
|
17
18
|
mode: 'basic',
|
|
18
19
|
from: 'local',
|
|
19
20
|
fields: {},
|
|
@@ -34,6 +35,9 @@ const args = yargs
|
|
|
34
35
|
.string('cert')
|
|
35
36
|
.describe('cert', 'Sets a custom certificate authority to use, if any.')
|
|
36
37
|
.default('cert', defaultArgs.cert)
|
|
38
|
+
.boolean('allow-self-signed')
|
|
39
|
+
.describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
|
|
40
|
+
.default('allow-self-signed', defaultArgs.allowSelfSigned)
|
|
37
41
|
.choices('mode', publishModeKeys)
|
|
38
42
|
.describe('mode', 'Sets the authorization mode to use.')
|
|
39
43
|
.default('mode', defaultArgs.mode)
|
|
@@ -52,10 +56,11 @@ const args = yargs
|
|
|
52
56
|
.default('interactive', defaultArgs.interactive).argv;
|
|
53
57
|
|
|
54
58
|
async function run() {
|
|
55
|
-
const { cert, source, from, url, 'api-key': apiKey, headers, fields, interactive, mode } = args;
|
|
59
|
+
const { cert, source, from, url, 'api-key': apiKey, 'allow-self-signed': allowSelfSigned, headers, fields, interactive, mode } = args;
|
|
56
60
|
const sources = Array.isArray(source) ? source : [source];
|
|
57
61
|
const ca = await getCa(cert);
|
|
58
|
-
const
|
|
62
|
+
const agent = getAgent({ ca, allowSelfSigned });
|
|
63
|
+
const files = await getFiles(current, sources, from, agent);
|
|
59
64
|
const successfulUploads: Array<string> = [];
|
|
60
65
|
|
|
61
66
|
if (files.length === 0) {
|
|
@@ -76,7 +81,7 @@ async function run() {
|
|
|
76
81
|
content,
|
|
77
82
|
fields,
|
|
78
83
|
headers,
|
|
79
|
-
|
|
84
|
+
agent,
|
|
80
85
|
interactive,
|
|
81
86
|
);
|
|
82
87
|
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import glob from 'glob';
|
|
2
|
+
import { Agent } from 'https';
|
|
2
3
|
import { existsSync, statSync } from 'fs';
|
|
3
4
|
import { stat, readFile, readdir, copyFile, rm } from 'fs/promises';
|
|
4
5
|
import { dirname, basename, resolve } from 'path';
|
|
@@ -83,7 +84,7 @@ export async function getFiles(
|
|
|
83
84
|
baseDir: string,
|
|
84
85
|
sources: Array<string>,
|
|
85
86
|
from: string,
|
|
86
|
-
|
|
87
|
+
agent: Agent,
|
|
87
88
|
): Promise<Array<string>> {
|
|
88
89
|
switch (from) {
|
|
89
90
|
case 'local': {
|
|
@@ -127,12 +128,12 @@ export async function getFiles(
|
|
|
127
128
|
return allMatches.filter(isFile);
|
|
128
129
|
}
|
|
129
130
|
case 'remote': {
|
|
130
|
-
const allFiles = await Promise.all(sources.map((s) => downloadFile(s,
|
|
131
|
+
const allFiles = await Promise.all(sources.map((s) => downloadFile(s, agent)));
|
|
131
132
|
return allFiles.reduce((result, files) => [...result, ...files], []);
|
|
132
133
|
}
|
|
133
134
|
case 'npm': {
|
|
134
135
|
const allUrls = await Promise.all(sources.map((s) => findTarball(s)));
|
|
135
|
-
const allFiles = await Promise.all(allUrls.map((url) => downloadFile(url,
|
|
136
|
+
const allFiles = await Promise.all(allUrls.map((url) => downloadFile(url, agent)));
|
|
136
137
|
return allFiles.reduce((result, files) => [...result, ...files], []);
|
|
137
138
|
}
|
|
138
139
|
}
|