piral-cli 0.15.0-alpha.3933 → 0.15.0-alpha.4027

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 (44) hide show
  1. package/lib/apps/build-pilet.d.ts +4 -0
  2. package/lib/apps/build-pilet.js +5 -4
  3. package/lib/apps/build-pilet.js.map +1 -1
  4. package/lib/apps/debug-pilet.d.ts +4 -0
  5. package/lib/apps/debug-pilet.js +4 -3
  6. package/lib/apps/debug-pilet.js.map +1 -1
  7. package/lib/apps/publish-pilet.d.ts +9 -1
  8. package/lib/apps/publish-pilet.js +4 -2
  9. package/lib/apps/publish-pilet.js.map +1 -1
  10. package/lib/commands.js +16 -0
  11. package/lib/commands.js.map +1 -1
  12. package/lib/common/http.d.ts +2 -1
  13. package/lib/common/http.js +18 -4
  14. package/lib/common/http.js.map +1 -1
  15. package/lib/common/index.d.ts +1 -0
  16. package/lib/common/index.js +1 -0
  17. package/lib/common/index.js.map +1 -1
  18. package/lib/common/info.d.ts +1 -0
  19. package/lib/common/info.js +3 -1
  20. package/lib/common/info.js.map +1 -1
  21. package/lib/common/parallel.d.ts +1 -0
  22. package/lib/common/parallel.js +29 -0
  23. package/lib/common/parallel.js.map +1 -0
  24. package/lib/common/spec.js +3 -2
  25. package/lib/common/spec.js.map +1 -1
  26. package/lib/external/index.js +69 -2
  27. package/lib/helpers.d.ts +2 -1
  28. package/lib/helpers.js +2 -1
  29. package/lib/helpers.js.map +1 -1
  30. package/lib/types/public.d.ts +1 -0
  31. package/package.json +2 -2
  32. package/src/apps/build-pilet.ts +105 -99
  33. package/src/apps/debug-pilet.ts +61 -54
  34. package/src/apps/publish-pilet.ts +16 -2
  35. package/src/commands.ts +18 -0
  36. package/src/common/http.test.ts +7 -7
  37. package/src/common/http.ts +21 -3
  38. package/src/common/index.ts +1 -0
  39. package/src/common/info.ts +3 -0
  40. package/src/common/parallel.test.ts +28 -0
  41. package/src/common/parallel.ts +21 -0
  42. package/src/common/spec.ts +3 -2
  43. package/src/helpers.ts +2 -0
  44. package/src/types/public.ts +2 -0
package/src/commands.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  fromKeys,
16
16
  bundlerKeys,
17
17
  piralBuildTypeKeys,
18
+ publishModeKeys,
18
19
  } from './helpers';
19
20
  import {
20
21
  ToolCommand,
@@ -25,6 +26,7 @@ import {
25
26
  PiletPublishSource,
26
27
  PiletSchemaVersion,
27
28
  PiletBuildType,
29
+ PiletPublishScheme,
28
30
  } from './types';
29
31
 
30
32
  function specializeCommand(commands: Array<ToolCommand<any>>, command: ToolCommand<any>, suffix: string) {
@@ -414,6 +416,9 @@ const allCommands: Array<ToolCommand<any>> = [
414
416
  .number('log-level')
415
417
  .describe('log-level', 'Sets the log level to use (1-5).')
416
418
  .default('log-level', apps.debugPiletDefaults.logLevel)
419
+ .number('concurrency')
420
+ .describe('concurrency', 'Sets the maximum number of concurrent build jobs.')
421
+ .default('concurrency', apps.debugPiletDefaults.concurrency)
417
422
  .boolean('open')
418
423
  .describe('open', 'Opens the pilet directly in the browser.')
419
424
  .default('open', apps.debugPiletDefaults.open)
@@ -452,6 +457,7 @@ const allCommands: Array<ToolCommand<any>> = [
452
457
  logLevel: args['log-level'] as LogLevels,
453
458
  open: args.open as boolean,
454
459
  schemaVersion: args.schema as PiletSchemaVersion,
460
+ concurrency: args.concurrency as number,
455
461
  feed: args.feed as string,
456
462
  hooks: args.hooks as object,
457
463
  _: args,
@@ -477,6 +483,9 @@ const allCommands: Array<ToolCommand<any>> = [
477
483
  .number('log-level')
478
484
  .describe('log-level', 'Sets the log level to use (1-5).')
479
485
  .default('log-level', apps.buildPiletDefaults.logLevel)
486
+ .number('concurrency')
487
+ .describe('concurrency', 'Sets the maximum number of concurrent build jobs.')
488
+ .default('concurrency', apps.buildPiletDefaults.concurrency)
480
489
  .boolean('source-maps')
481
490
  .describe('source-maps', 'Creates source maps for the bundles.')
482
491
  .default('source-maps', apps.buildPiletDefaults.sourceMaps)
@@ -524,6 +533,7 @@ const allCommands: Array<ToolCommand<any>> = [
524
533
  fresh: args.fresh as boolean,
525
534
  logLevel: args['log-level'] as LogLevels,
526
535
  schemaVersion: args.schema as PiletSchemaVersion,
536
+ concurrency: args.concurrency as number,
527
537
  app: args.app as string,
528
538
  hooks: args.hooks as object,
529
539
  _: args,
@@ -590,6 +600,9 @@ const allCommands: Array<ToolCommand<any>> = [
590
600
  .choices('schema', schemaKeys)
591
601
  .describe('schema', 'Sets the schema to be used when making a fresh build of the pilet.')
592
602
  .default('schema', apps.publishPiletDefaults.schemaVersion)
603
+ .choices('mode', publishModeKeys)
604
+ .describe('mode', 'Sets the authorization mode to use.')
605
+ .default('mode', apps.publishPiletDefaults.mode)
593
606
  .choices('bundler', availableBundlers)
594
607
  .describe('bundler', 'Sets the bundler to use.')
595
608
  .default('bundler', availableBundlers[0])
@@ -599,6 +612,9 @@ const allCommands: Array<ToolCommand<any>> = [
599
612
  .option('fields', undefined)
600
613
  .describe('fields', 'Sets additional fields to be included in the feed service request.')
601
614
  .default('fields', apps.publishPiletDefaults.fields)
615
+ .option('headers', undefined)
616
+ .describe('headers', 'Sets additional headers to be included in the feed service request.')
617
+ .default('headers', apps.publishPiletDefaults.headers)
602
618
  .string('base')
603
619
  .default('base', process.cwd())
604
620
  .describe('base', 'Sets the base directory. By default the current directory is used.');
@@ -615,6 +631,8 @@ const allCommands: Array<ToolCommand<any>> = [
615
631
  from: args.from as PiletPublishSource,
616
632
  schemaVersion: args.schema as PiletSchemaVersion,
617
633
  fields: args.fields as Record<string, string>,
634
+ headers: args.headers as Record<string, string>,
635
+ mode: args.mode as PiletPublishScheme,
618
636
  _: args,
619
637
  });
620
638
  },
@@ -71,7 +71,7 @@ jest.mock('axios', () => ({
71
71
 
72
72
  describe('HTTP Module', () => {
73
73
  it('postFile form posts a file successfully should be ok', async () => {
74
- const result = await postFile(apiUrl, '123', Buffer.from('example'));
74
+ const result = await postFile(apiUrl, 'basic', '123', Buffer.from('example'));
75
75
  expect(result).toEqual({
76
76
  response: undefined,
77
77
  status: 200,
@@ -80,7 +80,7 @@ describe('HTTP Module', () => {
80
80
  });
81
81
 
82
82
  it('postFile form fails to post file should be false', async () => {
83
- const result = await postFile(apiUrl, '124', Buffer.from('example'));
83
+ const result = await postFile(apiUrl, 'basic', '124', Buffer.from('example'));
84
84
  expect(result).toEqual({
85
85
  response: '',
86
86
  status: 401,
@@ -89,7 +89,7 @@ describe('HTTP Module', () => {
89
89
  });
90
90
 
91
91
  it('postFile form not found to post file should be false', async () => {
92
- const result = await postFile('http://sample.com/', '', Buffer.from('example'));
92
+ const result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
93
93
  expect(result).toEqual({
94
94
  response: '',
95
95
  status: 404,
@@ -99,7 +99,7 @@ describe('HTTP Module', () => {
99
99
 
100
100
  it('postFile call results in error request', async () => {
101
101
  errorRequest = true;
102
- const result = await postFile('http://sample.com/', '', Buffer.from('example'));
102
+ const result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
103
103
  expect(result).toEqual({
104
104
  response: undefined,
105
105
  status: 500,
@@ -110,7 +110,7 @@ describe('HTTP Module', () => {
110
110
 
111
111
  it('postFile call results in error other', async () => {
112
112
  errorOther = true;
113
- const result = await postFile('http://sample.com/', '', Buffer.from('example'));
113
+ const result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
114
114
  expect(result).toEqual({
115
115
  response: undefined,
116
116
  status: 500,
@@ -121,7 +121,7 @@ describe('HTTP Module', () => {
121
121
 
122
122
  it('postFile call results in error response', async () => {
123
123
  errorResponse = true;
124
- let result = await postFile('http://sample.com/', '', Buffer.from('example'));
124
+ let result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
125
125
  expect(result).toEqual({
126
126
  response: 'This component is not available anymore.',
127
127
  status: 410,
@@ -129,7 +129,7 @@ describe('HTTP Module', () => {
129
129
  });
130
130
  errorResponse = false;
131
131
  errorResponse2 = true;
132
- result = await postFile('http://sample.com/', '', Buffer.from('example'));
132
+ result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
133
133
  expect(result).toEqual({
134
134
  response: 'This component is not available anymore.',
135
135
  status: 410,
@@ -5,6 +5,7 @@ import { platform, tmpdir } from 'os';
5
5
  import { createWriteStream } from 'fs';
6
6
  import { log } from './log';
7
7
  import { axios, FormData } from '../external';
8
+ import { PiletPublishScheme } from '../types';
8
9
 
9
10
  const os = platform();
10
11
  const standardHeaders = {
@@ -67,25 +68,42 @@ export interface PostFileResult {
67
68
 
68
69
  export function postFile(
69
70
  target: string,
71
+ scheme: PiletPublishScheme,
70
72
  key: string,
71
73
  file: Buffer,
72
- fields: Record<string, string> = {},
74
+ customFields: Record<string, string> = {},
75
+ customHeaders: Record<string, string> = {},
73
76
  ca?: Buffer,
74
77
  ): Promise<PostFileResult> {
75
78
  const form = new FormData();
76
79
  const httpsAgent = ca ? new Agent({ ca }) : undefined;
77
80
 
78
- Object.keys(fields).forEach((key) => form.append(key, fields[key]));
81
+ Object.keys(customFields).forEach((key) => form.append(key, customFields[key]));
79
82
 
80
83
  form.append('file', file, 'pilet.tgz');
81
84
 
82
85
  const headers: Record<string, string> = {
83
86
  ...form.getHeaders(),
84
87
  ...standardHeaders,
88
+ ...customHeaders,
85
89
  };
86
90
 
87
91
  if (key) {
88
- headers.authorization = `Basic ${key}`;
92
+ switch (scheme) {
93
+ case 'basic':
94
+ headers.authorization = `Basic ${key}`;
95
+ break;
96
+ case 'bearer':
97
+ headers.authorization = `Bearer ${key}`;
98
+ break;
99
+ case 'digest':
100
+ headers.authorization = `Digest ${key}`;
101
+ break;
102
+ case 'none':
103
+ default:
104
+ headers.authorization = key;
105
+ break;
106
+ }
89
107
  }
90
108
 
91
109
  return axios.default
@@ -20,6 +20,7 @@ export * from './merge';
20
20
  export * from './npm';
21
21
  export * from './pack';
22
22
  export * from './package';
23
+ export * from './parallel';
23
24
  export * from './patcher';
24
25
  export * from './patches';
25
26
  export * from './port';
@@ -1,3 +1,5 @@
1
+ import { cpus } from 'os';
2
+
1
3
  const info = require('../../package.json');
2
4
 
3
5
  export function findCompatVersion(version: string) {
@@ -18,3 +20,4 @@ export const compatVersion = findCompatVersion(cliVersion);
18
20
  export const repositoryUrl = info.repository.url;
19
21
  export const isWindows = process.platform === 'win32';
20
22
  export const pathSeparator = isWindows ? ';' : ':';
23
+ export const cpuCount = cpus().length;
@@ -0,0 +1,28 @@
1
+ import { concurrentWorkers } from './parallel';
2
+
3
+ describe('Concurrent Workers', () => {
4
+ it('Can run against no entries', async () => {
5
+ const result = await concurrentWorkers([], 10, () => Promise.resolve('foo'));
6
+ expect(result).toEqual([]);
7
+ });
8
+
9
+ it('Can run against single entry', async () => {
10
+ const result = await concurrentWorkers(['bar'], 10, (item) => Promise.resolve('foo' + item));
11
+ expect(result).toEqual(['foobar']);
12
+ });
13
+
14
+ it('Can run against less entries than concurrency', async () => {
15
+ const result = await concurrentWorkers(['bar', 'rba', 'abr', 'rab', 'arb', 'bra'], 10, (item) => Promise.resolve('foo' + item));
16
+ expect(result).toEqual(['foobar', 'foorba', 'fooabr', 'foorab', 'fooarb', 'foobra']);
17
+ });
18
+
19
+ it('Can run against more entries than concurrency', async () => {
20
+ const result = await concurrentWorkers(['bar', 'rba', 'abr', 'rab', 'arb', 'bra'], 2, (item) => Promise.resolve('foo' + item));
21
+ expect(result).toEqual(['foobar', 'foorba', 'fooabr', 'foorab', 'fooarb', 'foobra']);
22
+ });
23
+
24
+ it('Can run against equal entries than concurrency', async () => {
25
+ const result = await concurrentWorkers(['bar', 'rba', 'abr', 'rab', 'arb', 'bra'], 6, (item) => Promise.resolve('foo' + item));
26
+ expect(result).toEqual(['foobar', 'foorba', 'fooabr', 'foorab', 'fooarb', 'foobra']);
27
+ });
28
+ });
@@ -0,0 +1,21 @@
1
+ export async function concurrentWorkers<T, R>(
2
+ items: Array<T>,
3
+ concurrency: number,
4
+ worker: (item: T) => Promise<R>,
5
+ ): Promise<Array<R>> {
6
+ const maxItems = items.length;
7
+ const results: Array<R> = new Array(maxItems);
8
+ let offset = 0;
9
+
10
+ await Promise.all(
11
+ items.slice(0, concurrency).map(async () => {
12
+ while (offset < maxItems) {
13
+ const i = offset++;
14
+ const item = items[i];
15
+ results[i] = await worker(item);
16
+ }
17
+ }),
18
+ );
19
+
20
+ return results;
21
+ }
@@ -3,6 +3,7 @@ import { computeHash, computeIntegrity } from './hash';
3
3
 
4
4
  const checkV1 = /^\/\/\s*@pilet\s+v:1\s*\(([A-Za-z0-9\_\:\-]+)\)/;
5
5
  const checkV2 = /^\/\/\s*@pilet\s+v:2\s*(?:\(([A-Za-z0-9\_\:\-]+),\s*(.*)\))?/;
6
+ const isUrl = /^https?:\/\//;
6
7
 
7
8
  function getDependencies(deps: string, basePath: string) {
8
9
  try {
@@ -13,8 +14,8 @@ function getDependencies(deps: string, basePath: string) {
13
14
  const depUrl = depMap[depName];
14
15
 
15
16
  if (typeof depUrl === 'string') {
16
- const url = new URL(depUrl, basePath);
17
- obj[depName] = url.href;
17
+ const url = isUrl.test(depUrl) ? depUrl : `${basePath}${depUrl}`;
18
+ obj[depName] = url;
18
19
  }
19
20
 
20
21
  return obj;
package/src/helpers.ts CHANGED
@@ -7,9 +7,11 @@ import {
7
7
  PiletPublishSource,
8
8
  PiralBuildType,
9
9
  PiletBuildType,
10
+ PiletPublishScheme,
10
11
  } from './types';
11
12
 
12
13
  export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'none'];
14
+ export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bearer', 'digest'];
13
15
  export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
14
16
  export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
15
17
  export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
@@ -218,6 +218,8 @@ export interface BundlerDefinition {
218
218
 
219
219
  export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2';
220
220
 
221
+ export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
222
+
221
223
  export type PiletPublishSource = 'local' | 'npm' | 'remote';
222
224
 
223
225
  export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources';