piral-cli 0.14.24-beta.4161 → 0.14.24-beta.4171

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 (84) hide show
  1. package/lib/apps/new-pilet.js +5 -9
  2. package/lib/apps/new-pilet.js.map +1 -1
  3. package/lib/apps/new-piral.js +5 -3
  4. package/lib/apps/new-piral.js.map +1 -1
  5. package/lib/apps/publish-pilet.js +1 -1
  6. package/lib/apps/publish-pilet.js.map +1 -1
  7. package/lib/apps/publish-piral.js +1 -1
  8. package/lib/apps/publish-piral.js.map +1 -1
  9. package/lib/apps/upgrade-pilet.js +2 -8
  10. package/lib/apps/upgrade-pilet.js.map +1 -1
  11. package/lib/apps/upgrade-piral.js +1 -1
  12. package/lib/apps/upgrade-piral.js.map +1 -1
  13. package/lib/bundler.js +1 -1
  14. package/lib/bundler.js.map +1 -1
  15. package/lib/common/clients/index.d.ts +19 -0
  16. package/lib/common/clients/index.js +40 -0
  17. package/lib/common/clients/index.js.map +1 -0
  18. package/lib/common/clients/lerna.d.ts +4 -1
  19. package/lib/common/clients/lerna.js +40 -3
  20. package/lib/common/clients/lerna.js.map +1 -1
  21. package/lib/common/clients/npm.d.ts +3 -1
  22. package/lib/common/clients/npm.js +24 -16
  23. package/lib/common/clients/npm.js.map +1 -1
  24. package/lib/common/clients/pnpm.d.ts +2 -0
  25. package/lib/common/clients/pnpm.js +18 -11
  26. package/lib/common/clients/pnpm.js.map +1 -1
  27. package/lib/common/clients/rush.d.ts +4 -0
  28. package/lib/common/clients/rush.js +91 -0
  29. package/lib/common/clients/rush.js.map +1 -0
  30. package/lib/common/clients/yarn.d.ts +2 -0
  31. package/lib/common/clients/yarn.js +20 -13
  32. package/lib/common/clients/yarn.js.map +1 -1
  33. package/lib/common/emulator.js +1 -1
  34. package/lib/common/emulator.js.map +1 -1
  35. package/lib/common/inspect.js +2 -1
  36. package/lib/common/inspect.js.map +1 -1
  37. package/lib/common/npm.d.ts +7 -15
  38. package/lib/common/npm.js +69 -127
  39. package/lib/common/npm.js.map +1 -1
  40. package/lib/common/pack.js +1 -1
  41. package/lib/common/pack.js.map +1 -1
  42. package/lib/common/package.d.ts +6 -6
  43. package/lib/common/package.js +10 -1
  44. package/lib/common/package.js.map +1 -1
  45. package/lib/common/scaffold.js +2 -2
  46. package/lib/common/scaffold.js.map +1 -1
  47. package/lib/external/index.js +1982 -92
  48. package/lib/helpers.js +1 -1
  49. package/lib/helpers.js.map +1 -1
  50. package/lib/injectors/pilet.js +2 -2
  51. package/lib/injectors/pilet.js.map +1 -1
  52. package/lib/plugin.js +4 -4
  53. package/lib/plugin.js.map +1 -1
  54. package/lib/types/internal.d.ts +9 -1
  55. package/lib/types/public.d.ts +1 -1
  56. package/package.json +4 -2
  57. package/src/apps/new-pilet.ts +9 -13
  58. package/src/apps/new-piral.ts +9 -5
  59. package/src/apps/publish-pilet.ts +2 -2
  60. package/src/apps/publish-piral.ts +2 -2
  61. package/src/apps/upgrade-pilet.ts +4 -12
  62. package/src/apps/upgrade-piral.ts +2 -2
  63. package/src/bundler.test.ts +1 -1
  64. package/src/bundler.ts +2 -2
  65. package/src/common/clients/index.ts +33 -0
  66. package/src/common/clients/lerna.ts +35 -1
  67. package/src/common/clients/npm.ts +20 -15
  68. package/src/common/clients/pnpm.ts +15 -12
  69. package/src/common/clients/rush.ts +85 -0
  70. package/src/common/clients/yarn.ts +17 -14
  71. package/src/common/emulator.ts +2 -2
  72. package/src/common/inspect.ts +2 -1
  73. package/src/common/npm.test.ts +51 -62
  74. package/src/common/npm.ts +82 -128
  75. package/src/common/pack.test.ts +1 -1
  76. package/src/common/pack.ts +2 -2
  77. package/src/common/package.ts +16 -7
  78. package/src/common/scaffold.ts +2 -2
  79. package/src/external/index.ts +2 -1
  80. package/src/helpers.ts +1 -1
  81. package/src/injectors/pilet.ts +3 -3
  82. package/src/plugin.ts +4 -4
  83. package/src/types/internal.ts +6 -1
  84. package/src/types/public.ts +1 -1
@@ -0,0 +1,85 @@
1
+ import { dirname, relative, resolve } from 'path';
2
+ import { log } from '../log';
3
+ import { findFile, readText, writeText } from '../io';
4
+ import { jju } from '../../external';
5
+ import { runCommand } from '../scripts';
6
+ import { MemoryStream } from '../MemoryStream';
7
+
8
+ // Helpers:
9
+ const rushJson = 'rush.json';
10
+
11
+ function runRushProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
12
+ log('generalDebug_0003', 'Starting the Rush process ...');
13
+ const cwd = resolve(process.cwd(), target);
14
+ return runCommand('rush', args, cwd, output);
15
+ }
16
+
17
+ function convert(flags: Array<string>) {
18
+ return flags.map((flag) => {
19
+ switch (flag) {
20
+ case '--save-exact':
21
+ // discard as this may lead to problems
22
+ return '';
23
+ case '--save-dev':
24
+ return '--dev';
25
+ case '--no-save':
26
+ // unfortunately no
27
+ return '';
28
+ default:
29
+ return flag;
30
+ }
31
+ });
32
+ }
33
+
34
+ // Client interface functions:
35
+
36
+ export async function installDependencies(target = '.', ...flags: Array<string>) {
37
+ const ms = new MemoryStream();
38
+ await runRushProcess(['update', ...convert(flags)], target, ms);
39
+ log('generalDebug_0003', `Rush install dependencies result: ${ms.value}`);
40
+ return ms.value;
41
+ }
42
+
43
+ export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
44
+ const ms = new MemoryStream();
45
+ await runRushProcess(['add', '--package', packageRef, ...convert(flags)], target, ms);
46
+ log('generalDebug_0003', `Rush install package result: ${ms.value}`);
47
+ return ms.value;
48
+ }
49
+
50
+ export async function detectClient(root: string) {
51
+ return !!(await findFile(root, rushJson));
52
+ }
53
+
54
+ export async function initProject(packageName: string, target: string) {
55
+ const rushPath = await findFile(target, rushJson);
56
+
57
+ if (!rushPath) {
58
+ throw new Error(
59
+ `Could not find the "${rushJson}" from "${target}". Sure you want to create the project in the right directory?`,
60
+ );
61
+ }
62
+
63
+ const rushDir = dirname(rushPath);
64
+ const rushContent = await readText(rushDir, rushJson);
65
+ const rushData = jju.parse(rushContent);
66
+ const projectFolder = relative(rushDir, target);
67
+
68
+ if (!Array.isArray(rushData.projects)) {
69
+ rushData.projects = [];
70
+ }
71
+
72
+ rushData.projects.push({
73
+ packageName,
74
+ projectFolder,
75
+ });
76
+
77
+ await writeText(
78
+ rushDir,
79
+ rushJson,
80
+ jju.update(rushContent, rushData, {
81
+ mode: 'cjson',
82
+ indent: 2,
83
+ }),
84
+ );
85
+ }
@@ -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,24 @@ 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;
48
45
  }
46
+
47
+ export async function detectClient(root: string) {
48
+ return !!(await findFile(root, 'yarn.lock'));
49
+ }
50
+
51
+ export async function initProject(projectName: string, target: string) {}
@@ -3,7 +3,7 @@ import { findDependencyVersion, copyScaffoldingFiles, isValidDependency } from '
3
3
  import { createFileFromTemplateIfNotExists } from './template';
4
4
  import { filesTar, filesOnceTar } from './constants';
5
5
  import { cliVersion } from './info';
6
- import { createPackage, makeExternals } from './npm';
6
+ import { createNpmPackage, makeExternals } from './npm';
7
7
  import { createPiralDeclaration } from './declaration';
8
8
  import { ForceOverwrite } from './enums';
9
9
  import { createTarball } from './archive';
@@ -138,7 +138,7 @@ export async function createEmulatorSources(
138
138
 
139
139
  export async function packageEmulator(rootDir: string) {
140
140
  // finally package everything up
141
- await createPackage(rootDir);
141
+ await createNpmPackage(rootDir);
142
142
 
143
143
  // get all files
144
144
  const names = await getFileNames(rootDir);
@@ -1,5 +1,6 @@
1
1
  import { dirname, basename } from 'path';
2
2
  import { unpackGzTar } from './archive';
3
+ import { jju } from '../external';
3
4
  import { PackageData, PackageFiles } from '../types';
4
5
 
5
6
  const packageRoot = 'package/';
@@ -8,7 +9,7 @@ function getPackageJson(files: PackageFiles): PackageData {
8
9
  const fileName = `${packageRoot}package.json`;
9
10
  const fileContent = files[fileName];
10
11
  const content = fileContent.toString('utf8');
11
- return JSON.parse(content);
12
+ return jju.parse(content);
12
13
  }
13
14
 
14
15
  function getPiletMainPath(data: PackageData, files: PackageFiles) {
@@ -1,16 +1,12 @@
1
1
  import { resolve } from 'path';
2
+ import { clients } from './clients';
2
3
  import {
3
4
  dissectPackageName,
4
- installPackage,
5
- detectNpm,
6
- detectPnpm,
7
- detectYarn,
5
+ installNpmPackage,
8
6
  isMonorepoPackageRef,
9
- detectMonorepo,
10
- bootstrapMonorepo,
11
- installDependencies,
12
- createPackage,
13
- findTarball,
7
+ installNpmDependencies,
8
+ createNpmPackage,
9
+ findNpmTarball,
14
10
  findSpecificVersion,
15
11
  findLatestVersion,
16
12
  isLocalPackage,
@@ -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', () => {
@@ -174,55 +165,66 @@ describe('npm Module', () => {
174
165
 
175
166
  it('installs a package using the npm command line tool without a target', async () => {
176
167
  wrongCase = false;
177
- await installPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
168
+ await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
178
169
  wrongCase = true;
179
- await installPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
170
+ await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
180
171
  });
181
172
 
182
173
  it('installs a package using the npm command line tool without a version', async () => {
183
174
  wrongCase = false;
184
- await installPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
175
+ await installNpmPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
185
176
  wrongCase = true;
186
- await installPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
177
+ await installNpmPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
187
178
  });
188
179
 
189
180
  it('installs a package using the Yarn command line tool without a version', async () => {
190
181
  wrongCase = false;
191
- await installPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
182
+ await installNpmPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
192
183
  wrongCase = true;
193
- await installPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
184
+ await installNpmPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
194
185
  });
195
186
 
196
187
  it('installs a package using the Pnpm command line tool without a version', async () => {
197
188
  wrongCase = false;
198
- await installPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
189
+ await installNpmPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
199
190
  wrongCase = true;
200
- await installPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
191
+ await installNpmPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
201
192
  });
202
193
 
203
194
  it('installs a package using the npm command line tool with some flag', async () => {
204
195
  wrongCase = false;
205
- await installPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) => expect(result).toEqual(jsonValueString));
196
+ await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
197
+ expect(result).toEqual(jsonValueString),
198
+ );
206
199
  wrongCase = true;
207
- await installPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
200
+ await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
208
201
  expect(result).not.toEqual(jsonValueString),
209
202
  );
210
203
  });
211
204
 
212
205
  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());
206
+ shouldFind = true;
207
+ await clients.npm.detectClient('test').then((result) => expect(result).toBeTruthy());
208
+ shouldFind = false;
209
+ await clients.npm.detectClient('toast').then((result) => expect(result).toBeFalsy());
210
+ shouldFind = true;
215
211
  });
216
212
 
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());
213
+ it('detectPnpm finds pnpm-lock.yaml', async () => {
214
+ shouldFind = true;
215
+ await clients.pnpm.detectClient('test').then((result) => expect(result).toBeTruthy());
216
+ shouldFind = false;
217
+ await clients.pnpm.detectClient('toast').then((result) => expect(result).toBeFalsy());
218
+ shouldFind = true;
220
219
  });
221
220
 
222
221
  it('detectYarn finds yarn.lock', async () => {
223
- await detectYarn('test').then((result) => expect(result).toBeTruthy());
222
+ shouldFind = true;
223
+ await clients.yarn.detectClient('test').then((result) => expect(result).toBeTruthy());
224
+ shouldFind = false;
224
225
  specialCase = true;
225
- await detectYarn('toast').then((result) => expect(result).toBeFalsy());
226
+ await clients.yarn.detectClient('toast').then((result) => expect(result).toBeFalsy());
227
+ shouldFind = true;
226
228
  specialCase = false;
227
229
  });
228
230
 
@@ -233,59 +235,46 @@ describe('npm Module', () => {
233
235
  await isMonorepoPackageRef('npm', './').then((result) => expect(result).toBeFalsy());
234
236
  });
235
237
 
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
238
  it('verifies whether lerna bootstrap ran', async () => {
250
239
  wrongCase = false;
251
- await bootstrapMonorepo().then((result) => expect(result).toEqual(jsonValueString));
240
+ await clients.lerna.installDependencies().then((result) => expect(result).toEqual(jsonValueString));
252
241
  wrongCase = true;
253
- await bootstrapMonorepo().then((result) => expect(result).not.toEqual(jsonValueString));
242
+ await clients.lerna.installDependencies().then((result) => expect(result).not.toEqual(jsonValueString));
254
243
  });
255
244
 
256
245
  it('install dependencies with npm client', async () => {
257
246
  wrongCase = false;
258
- await installDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
247
+ await installNpmDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
259
248
  wrongCase = true;
260
- await installDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
249
+ await installNpmDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
261
250
  });
262
251
 
263
252
  it('install dependencies with pnpm client', async () => {
264
253
  wrongCase = false;
265
- await installDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
254
+ await installNpmDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
266
255
  wrongCase = true;
267
- await installDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
256
+ await installNpmDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
268
257
  });
269
258
 
270
259
  it('install dependencies with yarn client', async () => {
271
260
  wrongCase = false;
272
- await installDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
261
+ await installNpmDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
273
262
  wrongCase = true;
274
- await installDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
263
+ await installNpmDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
275
264
  });
276
265
 
277
266
  it('create npm package', async () => {
278
267
  wrongCase = false;
279
- await createPackage().then((result) => expect(result).toEqual(jsonValueString));
268
+ await createNpmPackage().then((result) => expect(result).toEqual(jsonValueString));
280
269
  wrongCase = true;
281
- await createPackage().then((result) => expect(result).not.toEqual(jsonValueString));
270
+ await createNpmPackage().then((result) => expect(result).not.toEqual(jsonValueString));
282
271
  });
283
272
 
284
273
  it('find npm tarball', async () => {
285
274
  wrongCase = false;
286
- await findTarball('foo').then((result) => expect(result).toEqual(jsonValueString));
275
+ await findNpmTarball('foo').then((result) => expect(result).toEqual(jsonValueString));
287
276
  wrongCase = true;
288
- await findTarball('foo').then((result) => expect(result).not.toEqual(jsonValueString));
277
+ await findNpmTarball('foo').then((result) => expect(result).not.toEqual(jsonValueString));
289
278
  });
290
279
 
291
280
  it('find latest version', async () => {