piral-cli 1.4.0-beta.6288 → 1.4.0-beta.6313
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/apps/build-piral.js +26 -21
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/declaration-pilet.d.ts +23 -0
- package/lib/apps/declaration-pilet.js +31 -0
- package/lib/apps/declaration-pilet.js.map +1 -0
- package/lib/apps/index.d.ts +1 -0
- package/lib/apps/index.js +1 -0
- package/lib/apps/index.js.map +1 -1
- package/lib/apps/new-pilet.js +1 -0
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/commands.js +34 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/config.d.ts +5 -1
- package/lib/common/config.js +1 -0
- package/lib/common/config.js.map +1 -1
- package/lib/common/package.d.ts +1 -0
- package/lib/common/package.js +2 -0
- package/lib/common/package.js.map +1 -1
- package/lib/common/spec.d.ts +7 -0
- package/lib/common/spec.js +6 -0
- package/lib/common/spec.js.map +1 -1
- package/lib/common/website.js +23 -2
- package/lib/common/website.js.map +1 -1
- package/lib/helpers.js +2 -1
- package/lib/helpers.js.map +1 -1
- package/lib/injectors/pilet-injector.d.ts +1 -0
- package/lib/injectors/pilet-injector.js +25 -3
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/lib/messages.d.ts +6 -1
- package/lib/messages.js +6 -1
- package/lib/messages.js.map +1 -1
- package/lib/types/public.d.ts +13 -2
- package/package.json +2 -2
- package/src/apps/build-piral.ts +35 -21
- package/src/apps/declaration-pilet.ts +78 -0
- package/src/apps/index.ts +1 -0
- package/src/apps/new-pilet.ts +2 -0
- package/src/commands.ts +34 -0
- package/src/common/config.ts +6 -1
- package/src/common/package.ts +2 -0
- package/src/common/spec.ts +9 -0
- package/src/common/website.ts +25 -2
- package/src/helpers.ts +2 -1
- package/src/injectors/pilet-injector.ts +27 -7
- package/src/messages.ts +6 -1
- package/src/types/public.ts +22 -2
package/src/commands.ts
CHANGED
|
@@ -677,6 +677,40 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
677
677
|
});
|
|
678
678
|
},
|
|
679
679
|
},
|
|
680
|
+
{
|
|
681
|
+
name: 'declaration-pilet',
|
|
682
|
+
alias: ['declare-pilet'],
|
|
683
|
+
description: 'Creates the TypeScript declaration file (index.d.ts) for a pilet.',
|
|
684
|
+
arguments: ['[source]'],
|
|
685
|
+
flags(argv) {
|
|
686
|
+
return argv
|
|
687
|
+
.positional('source', {
|
|
688
|
+
type: 'string',
|
|
689
|
+
describe: 'Sets the source pilet path for collecting all the information.',
|
|
690
|
+
default: apps.declarationPiletDefaults.entry,
|
|
691
|
+
})
|
|
692
|
+
.string('target')
|
|
693
|
+
.describe('target', 'Sets the target directory for the generated .d.ts file.')
|
|
694
|
+
.default('target', apps.declarationPiletDefaults.target)
|
|
695
|
+
.number('log-level')
|
|
696
|
+
.describe('log-level', 'Sets the log level to use (1-5).')
|
|
697
|
+
.default('log-level', apps.declarationPiletDefaults.logLevel)
|
|
698
|
+
.choices('force-overwrite', forceOverwriteKeys)
|
|
699
|
+
.describe('force-overwrite', 'Determines if files should be overwritten by the command.')
|
|
700
|
+
.default('force-overwrite', keyOfForceOverwrite(apps.declarationPiletDefaults.forceOverwrite))
|
|
701
|
+
.string('base')
|
|
702
|
+
.default('base', process.cwd())
|
|
703
|
+
.describe('base', 'Sets the base directory. By default the current directory is used.');
|
|
704
|
+
},
|
|
705
|
+
run(args) {
|
|
706
|
+
return apps.declarationPilet(args.base as string, {
|
|
707
|
+
entry: args.source as string,
|
|
708
|
+
target: args.target as string,
|
|
709
|
+
forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
|
|
710
|
+
logLevel: args['log-level'] as LogLevels,
|
|
711
|
+
});
|
|
712
|
+
},
|
|
713
|
+
},
|
|
680
714
|
{
|
|
681
715
|
name: 'new-pilet',
|
|
682
716
|
alias: ['create-pilet', 'scaffold-pilet', 'scaffold', 'new', 'create'],
|
package/src/common/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defaultRegistry } from './constants';
|
|
2
2
|
import { rc } from '../external';
|
|
3
|
-
import { SourceLanguage, NpmClientType, PiletSchemaVersion } from '../types';
|
|
3
|
+
import { AuthConfig, SourceLanguage, NpmClientType, PiletSchemaVersion } from '../types';
|
|
4
4
|
|
|
5
5
|
export interface PiralCliConfig {
|
|
6
6
|
/**
|
|
@@ -12,6 +12,10 @@ export interface PiralCliConfig {
|
|
|
12
12
|
* Feed URL to API key specifications.
|
|
13
13
|
*/
|
|
14
14
|
apiKeys?: Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Emulator URL to auth options mapping.
|
|
17
|
+
*/
|
|
18
|
+
auth?: Record<string, AuthConfig>;
|
|
15
19
|
/**
|
|
16
20
|
* URL to be used for publishing a pilet in case
|
|
17
21
|
* there is no specialized key in url specified.
|
|
@@ -69,6 +73,7 @@ export const config: PiralCliConfig = rc(
|
|
|
69
73
|
{
|
|
70
74
|
apiKey: undefined,
|
|
71
75
|
apiKeys: {},
|
|
76
|
+
auth: {},
|
|
72
77
|
url: undefined,
|
|
73
78
|
cert: undefined,
|
|
74
79
|
npmClient: 'npm' as const,
|
package/src/common/package.ts
CHANGED
|
@@ -606,6 +606,7 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
606
606
|
externals,
|
|
607
607
|
name: packageInfo.name,
|
|
608
608
|
version: packageInfo.version,
|
|
609
|
+
emulator: piralJsonPkg.emulator,
|
|
609
610
|
framework,
|
|
610
611
|
dependencies,
|
|
611
612
|
scripts: packageInfo.scripts,
|
|
@@ -672,6 +673,7 @@ async function getPiletPackage(
|
|
|
672
673
|
start: 'pilet debug',
|
|
673
674
|
build: 'pilet build',
|
|
674
675
|
upgrade: 'pilet upgrade',
|
|
676
|
+
postinstall: 'pilet declaration',
|
|
675
677
|
...info.scripts,
|
|
676
678
|
}
|
|
677
679
|
: info.scripts;
|
package/src/common/spec.ts
CHANGED
|
@@ -55,6 +55,15 @@ export function getPiletSpecMeta(target: string, basePath: string) {
|
|
|
55
55
|
requireRef,
|
|
56
56
|
dependencies: getDependencies(plainDependencies, basePath),
|
|
57
57
|
};
|
|
58
|
+
} else if (
|
|
59
|
+
content.includes(
|
|
60
|
+
'"Container initialization failed as it has already been initialized with a different share scope"',
|
|
61
|
+
) &&
|
|
62
|
+
/^var [A-Za-z0-9_]+;/.test(content)
|
|
63
|
+
) {
|
|
64
|
+
return {
|
|
65
|
+
spec: 'mf',
|
|
66
|
+
};
|
|
58
67
|
} else {
|
|
59
68
|
// uses no arguments
|
|
60
69
|
return {
|
package/src/common/website.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join, relative, resolve } from 'path';
|
|
2
2
|
import { createPiralStubIndexIfNotExists } from './template';
|
|
3
|
+
import { config } from './config';
|
|
3
4
|
import { packageJson } from './constants';
|
|
4
5
|
import { ForceOverwrite } from './enums';
|
|
5
6
|
import { createDirectory, readJson, writeBinary } from './io';
|
|
@@ -8,6 +9,28 @@ import { progress, log } from './log';
|
|
|
8
9
|
import { axios } from '../external';
|
|
9
10
|
import { EmulatorWebsiteManifestFiles, EmulatorWebsiteManifest } from '../types';
|
|
10
11
|
|
|
12
|
+
function requestManifest(url: string) {
|
|
13
|
+
const auth = config.auth?.[url];
|
|
14
|
+
|
|
15
|
+
switch (auth?.mode) {
|
|
16
|
+
case 'header':
|
|
17
|
+
return axios.default.get(url, {
|
|
18
|
+
headers: {
|
|
19
|
+
[auth.key]: auth.value,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
case 'http':
|
|
23
|
+
return axios.default.get(url, {
|
|
24
|
+
auth: {
|
|
25
|
+
username: auth.username,
|
|
26
|
+
password: auth.password,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
default:
|
|
30
|
+
return axios.default.get(url);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
11
34
|
async function downloadEmulatorFiles(manifestUrl: string, target: string, files: EmulatorWebsiteManifestFiles) {
|
|
12
35
|
const requiredFiles = [files.typings, files.main, files.app];
|
|
13
36
|
|
|
@@ -69,7 +92,7 @@ export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl:
|
|
|
69
92
|
progress(`Updating emulator from %s ...`, manifestUrl);
|
|
70
93
|
|
|
71
94
|
try {
|
|
72
|
-
const response = await
|
|
95
|
+
const response = await requestManifest(manifestUrl);
|
|
73
96
|
const nextEmulator: EmulatorWebsiteManifest = response.data;
|
|
74
97
|
const currentEmulator = await readJson(targetDir, packageJson);
|
|
75
98
|
|
|
@@ -90,7 +113,7 @@ export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl:
|
|
|
90
113
|
|
|
91
114
|
export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl: string) {
|
|
92
115
|
progress(`Downloading emulator from %s ...`, manifestUrl);
|
|
93
|
-
const response = await
|
|
116
|
+
const response = await requestManifest(manifestUrl);
|
|
94
117
|
const emulatorJson: EmulatorWebsiteManifest = response.data;
|
|
95
118
|
const targetDir = resolve(rootDir, 'node_modules', emulatorJson.name);
|
|
96
119
|
const appDir = resolve(targetDir, 'app');
|
package/src/helpers.ts
CHANGED
|
@@ -11,13 +11,14 @@ import type {
|
|
|
11
11
|
SourceLanguage,
|
|
12
12
|
} from './types';
|
|
13
13
|
|
|
14
|
-
export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'v3', 'none'];
|
|
14
|
+
export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'v3', 'mf', 'none'];
|
|
15
15
|
export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bearer', 'digest'];
|
|
16
16
|
export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
|
|
17
17
|
export const piralBuildTypeKeys: Array<PiralBuildType> = [
|
|
18
18
|
'all',
|
|
19
19
|
'release',
|
|
20
20
|
'emulator',
|
|
21
|
+
'emulator-package',
|
|
21
22
|
'emulator-sources',
|
|
22
23
|
'emulator-website',
|
|
23
24
|
];
|
|
@@ -333,6 +333,31 @@ export default class PiletInjector implements KrasInjector {
|
|
|
333
333
|
return this.sendContent(content, mime.getType(target), url);
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
private download(path: string) {
|
|
337
|
+
const url = new URL(path, this.proxyInfo.source);
|
|
338
|
+
const auth = commonConfig.auth?.[this.proxyInfo.source];
|
|
339
|
+
|
|
340
|
+
switch (auth?.mode) {
|
|
341
|
+
case 'header':
|
|
342
|
+
return axios.default.get(url.href, {
|
|
343
|
+
responseType: 'arraybuffer',
|
|
344
|
+
headers: {
|
|
345
|
+
[auth.key]: auth.value,
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
case 'http':
|
|
349
|
+
return axios.default.get(url.href, {
|
|
350
|
+
responseType: 'arraybuffer',
|
|
351
|
+
auth: {
|
|
352
|
+
username: auth.username,
|
|
353
|
+
password: auth.password,
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
default:
|
|
357
|
+
return axios.default.get(url.href, { responseType: 'arraybuffer' });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
336
361
|
private async shouldLoad(target: string, path: string) {
|
|
337
362
|
if (this.proxyInfo) {
|
|
338
363
|
if (!this.proxyInfo.files.includes(path)) {
|
|
@@ -342,17 +367,12 @@ export default class PiletInjector implements KrasInjector {
|
|
|
342
367
|
const fileInfo = await stat(target).catch(() => undefined);
|
|
343
368
|
|
|
344
369
|
if (!fileInfo || fileInfo.mtime < this.proxyInfo.date) {
|
|
345
|
-
const url = new URL(path, this.proxyInfo.source);
|
|
346
|
-
|
|
347
370
|
try {
|
|
348
|
-
const response = await
|
|
371
|
+
const response = await this.download(path);
|
|
349
372
|
await writeFile(target, response.data);
|
|
350
373
|
} catch (ex) {
|
|
351
374
|
log('generalDebug_0003', `HTTP request for emulator asset retrieval failed: ${ex}`);
|
|
352
|
-
log(
|
|
353
|
-
fileInfo ? 'optionalEmulatorAssetUpdateSkipped_0122' : 'requiredEmulatorAssetDownloadSkipped_0123',
|
|
354
|
-
url.href,
|
|
355
|
-
);
|
|
375
|
+
log(fileInfo ? 'optionalEmulatorAssetUpdateSkipped_0122' : 'requiredEmulatorAssetDownloadSkipped_0123', path);
|
|
356
376
|
return !!fileInfo;
|
|
357
377
|
}
|
|
358
378
|
}
|
package/src/messages.ts
CHANGED
|
@@ -2628,11 +2628,12 @@ export function failedToOpenBrowser_0170(error: string): QuickMessage {
|
|
|
2628
2628
|
* the interpretation of compatible feed services slightly and has an impact of the usage
|
|
2629
2629
|
* of the pilet in the browser.
|
|
2630
2630
|
*
|
|
2631
|
-
* The selected schema version needs to be either "v0", "v1", or "
|
|
2631
|
+
* The selected schema version needs to be either "v0", "v1", "v2", or "mf".
|
|
2632
2632
|
*
|
|
2633
2633
|
* - v0: will download and evaluate the pilet explicitly
|
|
2634
2634
|
* - v1: will use a script tag for integration of the pilet
|
|
2635
2635
|
* - v2: will use SystemJS for integration of the pilet (default)
|
|
2636
|
+
* - mf: will use Module Federation for integration of the pilet (only supported bundlers)
|
|
2636
2637
|
*
|
|
2637
2638
|
* The v1 version has better support for older browsers, but requires a polyfill to work
|
|
2638
2639
|
* correctly. This polyfill is part of the `piral-ie11polyfills-utils` package.
|
|
@@ -2641,6 +2642,10 @@ export function failedToOpenBrowser_0170(error: string): QuickMessage {
|
|
|
2641
2642
|
* The v2 version uses a SystemJS format for the pilet. It has the broadest browser support
|
|
2642
2643
|
* but requires the custom format as output. Most bundlers support SystemJS directly or
|
|
2643
2644
|
* indirectly, making it a quite broad choice.
|
|
2645
|
+
*
|
|
2646
|
+
* In bundlers that support Module Federation (e.g., Webpack 5) the "mf" format may be
|
|
2647
|
+
* the best choice. Keep in mind that "mf" is only supported by applications using
|
|
2648
|
+
* Piral 1.4.0 or higher.
|
|
2644
2649
|
*
|
|
2645
2650
|
* @see
|
|
2646
2651
|
* - [GitHub currentScript-polyfill](https://github.com/amiller-gh/currentScript-polyfill)
|
package/src/types/public.ts
CHANGED
|
@@ -224,7 +224,21 @@ export type ImportmapVersions = 'all' | 'match-major' | 'any-patch' | 'exact';
|
|
|
224
224
|
|
|
225
225
|
export type ImportmapMode = 'host' | 'remote';
|
|
226
226
|
|
|
227
|
-
export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2' | 'v3';
|
|
227
|
+
export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2' | 'v3' | 'mf';
|
|
228
|
+
|
|
229
|
+
export interface HeaderAuthConfig {
|
|
230
|
+
mode: 'header';
|
|
231
|
+
key: string;
|
|
232
|
+
value: string;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface HttpAuthConfig {
|
|
236
|
+
mode: 'http';
|
|
237
|
+
username: string;
|
|
238
|
+
password: string;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export type AuthConfig = HeaderAuthConfig | HttpAuthConfig;
|
|
228
242
|
|
|
229
243
|
export type SourceLanguage = 'js' | 'ts';
|
|
230
244
|
|
|
@@ -232,7 +246,13 @@ export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
|
|
|
232
246
|
|
|
233
247
|
export type PiletPublishSource = 'local' | 'npm' | 'remote';
|
|
234
248
|
|
|
235
|
-
export type PiralBuildType =
|
|
249
|
+
export type PiralBuildType =
|
|
250
|
+
| 'all'
|
|
251
|
+
| 'release'
|
|
252
|
+
| 'emulator'
|
|
253
|
+
| 'emulator-package'
|
|
254
|
+
| 'emulator-sources'
|
|
255
|
+
| 'emulator-website';
|
|
236
256
|
|
|
237
257
|
export type PiletBuildType = 'default' | 'standalone' | 'manifest';
|
|
238
258
|
|