piral-cli 0.14.24-beta.4150 → 0.14.24-beta.4163

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 (54) hide show
  1. package/lib/apps/new-pilet.js +1 -7
  2. package/lib/apps/new-pilet.js.map +1 -1
  3. package/lib/apps/upgrade-pilet.js +1 -7
  4. package/lib/apps/upgrade-pilet.js.map +1 -1
  5. package/lib/common/clients/index.d.ts +19 -0
  6. package/lib/common/clients/index.js +40 -0
  7. package/lib/common/clients/index.js.map +1 -0
  8. package/lib/common/clients/lerna.d.ts +3 -1
  9. package/lib/common/clients/lerna.js +36 -3
  10. package/lib/common/clients/lerna.js.map +1 -1
  11. package/lib/common/clients/npm.d.ts +2 -1
  12. package/lib/common/clients/npm.js +20 -16
  13. package/lib/common/clients/npm.js.map +1 -1
  14. package/lib/common/clients/pnpm.d.ts +1 -0
  15. package/lib/common/clients/pnpm.js +14 -11
  16. package/lib/common/clients/pnpm.js.map +1 -1
  17. package/lib/common/clients/rush.d.ts +3 -0
  18. package/lib/common/clients/rush.js +64 -0
  19. package/lib/common/clients/rush.js.map +1 -0
  20. package/lib/common/clients/yarn.d.ts +1 -0
  21. package/lib/common/clients/yarn.js +16 -13
  22. package/lib/common/clients/yarn.js.map +1 -1
  23. package/lib/common/info.d.ts +1 -0
  24. package/lib/common/info.js +2 -1
  25. package/lib/common/info.js.map +1 -1
  26. package/lib/common/io.js +1 -1
  27. package/lib/common/io.js.map +1 -1
  28. package/lib/common/npm.d.ts +0 -9
  29. package/lib/common/npm.js +58 -121
  30. package/lib/common/npm.js.map +1 -1
  31. package/lib/common/scaffold.js +2 -2
  32. package/lib/common/scaffold.js.map +1 -1
  33. package/lib/helpers.js +1 -1
  34. package/lib/helpers.js.map +1 -1
  35. package/lib/plugin.js +27 -2
  36. package/lib/plugin.js.map +1 -1
  37. package/lib/types/public.d.ts +1 -1
  38. package/package.json +2 -2
  39. package/src/apps/new-pilet.ts +1 -9
  40. package/src/apps/upgrade-pilet.ts +1 -9
  41. package/src/common/clients/index.ts +33 -0
  42. package/src/common/clients/lerna.ts +33 -1
  43. package/src/common/clients/npm.ts +18 -15
  44. package/src/common/clients/pnpm.ts +13 -12
  45. package/src/common/clients/rush.ts +49 -0
  46. package/src/common/clients/yarn.ts +15 -14
  47. package/src/common/info.ts +1 -0
  48. package/src/common/io.ts +1 -1
  49. package/src/common/npm.test.ts +25 -38
  50. package/src/common/npm.ts +72 -123
  51. package/src/common/scaffold.ts +2 -2
  52. package/src/helpers.ts +1 -1
  53. package/src/plugin.ts +33 -4
  54. package/src/types/public.ts +1 -1
@@ -0,0 +1,33 @@
1
+ import * as lerna from './lerna';
2
+ import * as npm from './npm';
3
+ import * as pnpm from './pnpm';
4
+ import * as rush from './rush';
5
+ import * as yarn from './yarn';
6
+
7
+ export const clients = {
8
+ lerna,
9
+ npm,
10
+ pnpm,
11
+ rush,
12
+ yarn,
13
+ };
14
+
15
+ type ClientName = keyof typeof clients;
16
+
17
+ const directClients = ['npm', 'yarn', 'pnpm'];
18
+
19
+ export function isWrapperClient(client: ClientName) {
20
+ return !directClients.includes(client);
21
+ }
22
+
23
+ export function detectClients(root: string) {
24
+ return Promise.all(
25
+ Object.keys(clients).map(async (client: ClientName) => {
26
+ const result = await clients[client].detectClient(root);
27
+ return {
28
+ client,
29
+ result,
30
+ };
31
+ }),
32
+ );
33
+ }
@@ -1,17 +1,49 @@
1
1
  import { resolve } from 'path';
2
2
  import { log } from '../log';
3
+ import { findFile } from '../io';
3
4
  import { runCommand } from '../scripts';
4
5
  import { MemoryStream } from '../MemoryStream';
5
6
 
7
+ // Helpers:
8
+
6
9
  function runLernaProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
7
10
  log('generalDebug_0003', 'Starting the Lerna process ...');
8
11
  const cwd = resolve(process.cwd(), target);
9
12
  return runCommand('lerna', args, cwd, output);
10
13
  }
11
14
 
12
- export async function bootstrap(target = '.', ...flags: Array<string>) {
15
+ function convert(flags: Array<string>) {
16
+ return flags.map((flag) => {
17
+ switch (flag) {
18
+ case '--save-exact':
19
+ return '--exact';
20
+ case '--save-dev':
21
+ return '--dev';
22
+ case '--no-save':
23
+ // unfortunately no
24
+ return '';
25
+ default:
26
+ return flag;
27
+ }
28
+ });
29
+ }
30
+
31
+ // Client interface functions:
32
+
33
+ export async function installDependencies(target = '.', ...flags: Array<string>) {
13
34
  const ms = new MemoryStream();
14
35
  await runLernaProcess(['bootstrap', ...flags], target, ms);
15
36
  log('generalDebug_0003', `Lerna bootstrap result: ${ms.value}`);
16
37
  return ms.value;
17
38
  }
39
+
40
+ export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
41
+ const ms = new MemoryStream();
42
+ await runLernaProcess(['add', packageRef, ...convert(flags)], target, ms);
43
+ log('generalDebug_0003', `Lerna install package result: ${ms.value}`);
44
+ return ms.value;
45
+ }
46
+
47
+ export async function detectClient(root: string) {
48
+ return !!(await findFile(root, 'lerna.json'));
49
+ }
@@ -1,14 +1,19 @@
1
1
  import { resolve } from 'path';
2
2
  import { log } from '../log';
3
+ import { findFile } from '../io';
3
4
  import { runCommand } from '../scripts';
4
5
  import { MemoryStream } from '../MemoryStream';
5
6
 
7
+ // Helpers:
8
+
6
9
  function runNpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
7
10
  log('generalDebug_0003', 'Starting the npm process ...');
8
11
  const cwd = resolve(process.cwd(), target);
9
12
  return runCommand('npm', args, cwd, output);
10
13
  }
11
14
 
15
+ // Client interface functions:
16
+
12
17
  export async function installDependencies(target = '.', ...flags: Array<string>) {
13
18
  const ms = new MemoryStream();
14
19
  await runNpmProcess(['install', '--legacy-peer-deps', ...flags], target, ms);
@@ -16,6 +21,19 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
16
21
  return ms.value;
17
22
  }
18
23
 
24
+ export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
25
+ const ms = new MemoryStream();
26
+ await runNpmProcess(['install', packageRef, '--legacy-peer-deps', ...flags], target, ms);
27
+ log('generalDebug_0003', `npm install package result: ${ms.value}`);
28
+ return ms.value;
29
+ }
30
+
31
+ export async function detectClient(root: string) {
32
+ return !!(await findFile(root, 'package-lock.json'));
33
+ }
34
+
35
+ // Functions to exclusively use from npm client:
36
+
19
37
  export async function unpackPackage(packageRef: string, target = '.', ...flags: Array<string>) {
20
38
  const ms = new MemoryStream();
21
39
  await runNpmProcess(['pack', packageRef, ...flags], target, ms);
@@ -23,21 +41,6 @@ export async function unpackPackage(packageRef: string, target = '.', ...flags:
23
41
  return ms.value;
24
42
  }
25
43
 
26
- export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
27
- try {
28
- const ms = new MemoryStream();
29
- await runNpmProcess(['install', packageRef, '--legacy-peer-deps', ...flags], target, ms);
30
- log('generalDebug_0003', `npm install package result: ${ms.value}`);
31
- return ms.value;
32
- } catch (ex) {
33
- log(
34
- 'generalError_0002',
35
- `Could not install the package "${packageRef}" using npm. Make sure npm is correctly installed and accessible: ${ex}`,
36
- );
37
- throw ex;
38
- }
39
- }
40
-
41
44
  export async function createPackage(target = '.', ...flags: Array<string>) {
42
45
  const ms = new MemoryStream();
43
46
  await runNpmProcess(['pack', ...flags], target, ms);
@@ -1,8 +1,11 @@
1
1
  import { resolve } from 'path';
2
2
  import { log } from '../log';
3
+ import { findFile } from '../io';
3
4
  import { runCommand } from '../scripts';
4
5
  import { MemoryStream } from '../MemoryStream';
5
6
 
7
+ // Helpers:
8
+
6
9
  function runPnpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
7
10
  log('generalDebug_0003', 'Starting the Pnpm process ...');
8
11
  const cwd = resolve(process.cwd(), target);
@@ -21,6 +24,8 @@ function convert(flags: Array<string>) {
21
24
  });
22
25
  }
23
26
 
27
+ // Client interface functions:
28
+
24
29
  export async function installDependencies(target = '.', ...flags: Array<string>) {
25
30
  const ms = new MemoryStream();
26
31
  await runPnpmProcess(['install', ...convert(flags)], target, ms);
@@ -29,16 +34,12 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
29
34
  }
30
35
 
31
36
  export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
32
- try {
33
- const ms = new MemoryStream();
34
- await runPnpmProcess(['add', packageRef, ...convert(flags)], target, ms);
35
- log('generalDebug_0003', `Pnpm install package result: ${ms.value}`);
36
- return ms.value;
37
- } catch (ex) {
38
- log(
39
- 'generalError_0002',
40
- `Could not install the package "${packageRef}" using Pnpm. Make sure Pnpm is correctly installed and accessible: ${ex}`,
41
- );
42
- throw ex;
43
- }
37
+ const ms = new MemoryStream();
38
+ await runPnpmProcess(['add', packageRef, ...convert(flags)], target, ms);
39
+ log('generalDebug_0003', `Pnpm install package result: ${ms.value}`);
40
+ return ms.value;
41
+ }
42
+
43
+ export async function detectClient(root: string) {
44
+ return !!(await findFile(root, 'pnpm-lock.yaml'));
44
45
  }
@@ -0,0 +1,49 @@
1
+ import { resolve } from 'path';
2
+ import { log } from '../log';
3
+ import { findFile } from '../io';
4
+ import { runCommand } from '../scripts';
5
+ import { MemoryStream } from '../MemoryStream';
6
+
7
+ // Helpers:
8
+
9
+ function runRushProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
10
+ log('generalDebug_0003', 'Starting the Rush process ...');
11
+ const cwd = resolve(process.cwd(), target);
12
+ return runCommand('rush', args, cwd, output);
13
+ }
14
+
15
+ function convert(flags: Array<string>) {
16
+ return flags.map((flag) => {
17
+ switch (flag) {
18
+ case '--save-exact':
19
+ return '--exact';
20
+ case '--save-dev':
21
+ return '--dev';
22
+ case '--no-save':
23
+ // unfortunately no
24
+ return '';
25
+ default:
26
+ return flag;
27
+ }
28
+ });
29
+ }
30
+
31
+ // Client interface functions:
32
+
33
+ export async function installDependencies(target = '.', ...flags: Array<string>) {
34
+ const ms = new MemoryStream();
35
+ await runRushProcess(['update', ...convert(flags)], target, ms);
36
+ log('generalDebug_0003', `Rush install dependencies result: ${ms.value}`);
37
+ return ms.value;
38
+ }
39
+
40
+ export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
41
+ const ms = new MemoryStream();
42
+ await runRushProcess(['add', '--package', packageRef, ...convert(flags)], target, ms);
43
+ log('generalDebug_0003', `Rush install package result: ${ms.value}`);
44
+ return ms.value;
45
+ }
46
+
47
+ export async function detectClient(root: string) {
48
+ return !!(await findFile(root, 'rush.json'));
49
+ }
@@ -1,10 +1,13 @@
1
1
  import { resolve } from 'path';
2
2
  import { log } from '../log';
3
+ import { findFile } from '../io';
3
4
  import { runCommand } from '../scripts';
4
5
  import { MemoryStream } from '../MemoryStream';
5
6
 
7
+ // Helpers:
8
+
6
9
  function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
7
- log('generalDebug_0003', 'Starting the Yarn process ...');
10
+ log('generalDebug_0003', 'Starting the Yarn@1 process ...');
8
11
  const cwd = resolve(process.cwd(), target);
9
12
  return runCommand('yarn', args, cwd, output);
10
13
  }
@@ -25,24 +28,22 @@ function convert(flags: Array<string>) {
25
28
  });
26
29
  }
27
30
 
31
+ // Client interface functions:
32
+
28
33
  export async function installDependencies(target = '.', ...flags: Array<string>) {
29
34
  const ms = new MemoryStream();
30
35
  await runYarnProcess(['install', ...convert(flags)], target, ms);
31
- log('generalDebug_0003', `Yarn install dependencies result: ${ms.value}`);
36
+ log('generalDebug_0003', `Yarn@1 install dependencies result: ${ms.value}`);
32
37
  return ms.value;
33
38
  }
34
39
 
35
40
  export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
36
- try {
37
- const ms = new MemoryStream();
38
- await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
39
- log('generalDebug_0003', `Yarn install package result: ${ms.value}`);
40
- return ms.value;
41
- } catch (ex) {
42
- log(
43
- 'generalError_0002',
44
- `Could not install the package "${packageRef}" using Yarn. Make sure Yarn@1 is correctly installed and accessible: ${ex}`,
45
- );
46
- throw ex;
47
- }
41
+ const ms = new MemoryStream();
42
+ await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
43
+ log('generalDebug_0003', `Yarn@1 install package result: ${ms.value}`);
44
+ return ms.value;
45
+ }
46
+
47
+ export async function detectClient(root: string) {
48
+ return !!(await findFile(root, 'yarn.lock'));
48
49
  }
@@ -15,6 +15,7 @@ export function findCompatVersion(version: string) {
15
15
  }
16
16
 
17
17
  export const nodeVersion = process.version.substring(1);
18
+ export const cliName = info.name;
18
19
  export const cliVersion = info.version;
19
20
  export const compatVersion = findCompatVersion(cliVersion);
20
21
  export const repositoryUrl = info.repository.url;
package/src/common/io.ts CHANGED
@@ -218,7 +218,7 @@ export async function matchAnyPilet(baseDir: string, patterns: Array<string>) {
218
218
  const allPatterns = patterns.reduce<Array<AnyPattern>>((agg, curr) => {
219
219
  const patterns = [];
220
220
 
221
- if (/[a-zA-Z0-9\-\*]+$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
221
+ if (/[a-zA-Z0-9\-\*]$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
222
222
  patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${nameOfPackageJson}`);
223
223
  } else if (curr.endsWith('/')) {
224
224
  patterns.push(`${curr}index.{${exts}}`, `${curr}${nameOfPackageJson}`);
@@ -1,13 +1,9 @@
1
1
  import { resolve } from 'path';
2
+ import { clients } from './clients';
2
3
  import {
3
4
  dissectPackageName,
4
5
  installPackage,
5
- detectNpm,
6
- detectPnpm,
7
- detectYarn,
8
6
  isMonorepoPackageRef,
9
- detectMonorepo,
10
- bootstrapMonorepo,
11
7
  installDependencies,
12
8
  createPackage,
13
9
  findTarball,
@@ -42,6 +38,7 @@ jest.mock('../external', () => ({
42
38
  }));
43
39
 
44
40
  let specialCase = false;
41
+ let shouldFind = true;
45
42
  let wrongCase = false;
46
43
  const jsonValueString = JSON.stringify({ dependencies: { npm: { extraneous: true } } });
47
44
  const jsonValueStringWrong = JSON.stringify({ dependencies: {} });
@@ -56,14 +53,15 @@ jest.mock('./scripts', () => ({
56
53
  }));
57
54
 
58
55
  jest.mock('fs', () => ({
59
- constants: {
60
- F_OK: 1,
61
- },
62
56
  createReadStream() {
63
57
  return undefined;
64
58
  },
65
59
  exists: (file: string, cb: (status: boolean) => void) =>
66
- cb(!file.endsWith('package.json') && !(specialCase && (file.endsWith('lerna.json') || file.endsWith('yarn.lock')))),
60
+ cb(
61
+ shouldFind &&
62
+ !file.endsWith('package.json') &&
63
+ !(specialCase && (file.endsWith('lerna.json') || file.endsWith('yarn.lock'))),
64
+ ),
67
65
  existsSync: (file: string) => {
68
66
  return true;
69
67
  },
@@ -72,13 +70,6 @@ jest.mock('fs', () => ({
72
70
  },
73
71
  realpathSync: () => ({}),
74
72
  readFileSync: () => '',
75
- access: (path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void) => {
76
- if (path.includes('test')) {
77
- return callback(undefined);
78
- } else {
79
- return callback(new Error('bla'));
80
- }
81
- },
82
73
  }));
83
74
 
84
75
  describe('npm Module', () => {
@@ -210,19 +201,28 @@ describe('npm Module', () => {
210
201
  });
211
202
 
212
203
  it('detectNpm finds package-lock.json', async () => {
213
- await detectNpm('test').then((result) => expect(result).toBeTruthy());
214
- await detectNpm('toast').then((result) => expect(result).toBeFalsy());
204
+ shouldFind = true;
205
+ await clients.npm.detectClient('test').then((result) => expect(result).toBeTruthy());
206
+ shouldFind = false;
207
+ await clients.npm.detectClient('toast').then((result) => expect(result).toBeFalsy());
208
+ shouldFind = true;
215
209
  });
216
210
 
217
- it('detectPnpm finds nppm-lock.yaml', async () => {
218
- await detectPnpm('test').then((result) => expect(result).toBeTruthy());
219
- await detectPnpm('toast').then((result) => expect(result).toBeFalsy());
211
+ it('detectPnpm finds pnpm-lock.yaml', async () => {
212
+ shouldFind = true;
213
+ await clients.pnpm.detectClient('test').then((result) => expect(result).toBeTruthy());
214
+ shouldFind = false;
215
+ await clients.pnpm.detectClient('toast').then((result) => expect(result).toBeFalsy());
216
+ shouldFind = true;
220
217
  });
221
218
 
222
219
  it('detectYarn finds yarn.lock', async () => {
223
- await detectYarn('test').then((result) => expect(result).toBeTruthy());
220
+ shouldFind = true;
221
+ await clients.yarn.detectClient('test').then((result) => expect(result).toBeTruthy());
222
+ shouldFind = false;
224
223
  specialCase = true;
225
- await detectYarn('toast').then((result) => expect(result).toBeFalsy());
224
+ await clients.yarn.detectClient('toast').then((result) => expect(result).toBeFalsy());
225
+ shouldFind = true;
226
226
  specialCase = false;
227
227
  });
228
228
 
@@ -233,24 +233,11 @@ describe('npm Module', () => {
233
233
  await isMonorepoPackageRef('npm', './').then((result) => expect(result).toBeFalsy());
234
234
  });
235
235
 
236
- it('verifies whether lerna config path is valid', async () => {
237
- wrongCase = false;
238
- await detectMonorepo('./').then((result) => {
239
- expect(result).toBe('lerna');
240
- });
241
- wrongCase = true;
242
- specialCase = true;
243
- await detectMonorepo('./').then((result) => {
244
- expect(result).toBe('none');
245
- });
246
- specialCase = false;
247
- });
248
-
249
236
  it('verifies whether lerna bootstrap ran', async () => {
250
237
  wrongCase = false;
251
- await bootstrapMonorepo().then((result) => expect(result).toEqual(jsonValueString));
238
+ await clients.lerna.installDependencies().then((result) => expect(result).toEqual(jsonValueString));
252
239
  wrongCase = true;
253
- await bootstrapMonorepo().then((result) => expect(result).not.toEqual(jsonValueString));
240
+ await clients.lerna.installDependencies().then((result) => expect(result).not.toEqual(jsonValueString));
254
241
  });
255
242
 
256
243
  it('install dependencies with npm client', async () => {