piral-cli 0.15.0-alpha.4098 → 0.15.0-alpha.4257

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 (154) hide show
  1. package/lib/apps/debug-pilet.js +26 -41
  2. package/lib/apps/debug-pilet.js.map +1 -1
  3. package/lib/apps/debug-piral.js +18 -33
  4. package/lib/apps/debug-piral.js.map +1 -1
  5. package/lib/apps/new-pilet.js +5 -9
  6. package/lib/apps/new-pilet.js.map +1 -1
  7. package/lib/apps/new-piral.js +9 -3
  8. package/lib/apps/new-piral.js.map +1 -1
  9. package/lib/apps/publish-pilet.d.ts +4 -0
  10. package/lib/apps/publish-pilet.js +4 -3
  11. package/lib/apps/publish-pilet.js.map +1 -1
  12. package/lib/apps/publish-piral.d.ts +4 -0
  13. package/lib/apps/publish-piral.js +9 -7
  14. package/lib/apps/publish-piral.js.map +1 -1
  15. package/lib/apps/upgrade-pilet.js +2 -8
  16. package/lib/apps/upgrade-pilet.js.map +1 -1
  17. package/lib/apps/upgrade-piral.js +1 -1
  18. package/lib/apps/upgrade-piral.js.map +1 -1
  19. package/lib/bundler.js +1 -1
  20. package/lib/bundler.js.map +1 -1
  21. package/lib/commands.js +14 -6
  22. package/lib/commands.js.map +1 -1
  23. package/lib/common/browser.d.ts +1 -0
  24. package/lib/common/browser.js +16 -10
  25. package/lib/common/browser.js.map +1 -1
  26. package/lib/common/clients/index.d.ts +19 -0
  27. package/lib/common/clients/index.js +40 -0
  28. package/lib/common/clients/index.js.map +1 -0
  29. package/lib/common/clients/lerna.d.ts +6 -1
  30. package/lib/common/clients/lerna.js +67 -3
  31. package/lib/common/clients/lerna.js.map +1 -1
  32. package/lib/common/clients/npm.d.ts +4 -1
  33. package/lib/common/clients/npm.js +37 -16
  34. package/lib/common/clients/npm.js.map +1 -1
  35. package/lib/common/clients/pnpm.d.ts +4 -0
  36. package/lib/common/clients/pnpm.js +43 -9
  37. package/lib/common/clients/pnpm.js.map +1 -1
  38. package/lib/common/clients/rush.d.ts +6 -0
  39. package/lib/common/clients/rush.js +118 -0
  40. package/lib/common/clients/rush.js.map +1 -0
  41. package/lib/common/clients/yarn.d.ts +4 -0
  42. package/lib/common/clients/yarn.js +45 -11
  43. package/lib/common/clients/yarn.js.map +1 -1
  44. package/lib/common/constants.d.ts +1 -1
  45. package/lib/common/constants.js +1 -1
  46. package/lib/common/constants.js.map +1 -1
  47. package/lib/common/declaration.js +14 -10
  48. package/lib/common/declaration.js.map +1 -1
  49. package/lib/common/emulator.js +2 -2
  50. package/lib/common/emulator.js.map +1 -1
  51. package/lib/common/http.d.ts +1 -1
  52. package/lib/common/http.js +12 -7
  53. package/lib/common/http.js.map +1 -1
  54. package/lib/common/importmap.js +4 -14
  55. package/lib/common/importmap.js.map +1 -1
  56. package/lib/common/info.d.ts +4 -0
  57. package/lib/common/info.js +6 -1
  58. package/lib/common/info.js.map +1 -1
  59. package/lib/common/injectors.d.ts +36 -7
  60. package/lib/common/injectors.js +39 -11
  61. package/lib/common/injectors.js.map +1 -1
  62. package/lib/common/inspect.js +2 -1
  63. package/lib/common/inspect.js.map +1 -1
  64. package/lib/common/interactive.d.ts +9 -0
  65. package/lib/common/interactive.js +31 -1
  66. package/lib/common/interactive.js.map +1 -1
  67. package/lib/common/io.js +1 -1
  68. package/lib/common/io.js.map +1 -1
  69. package/lib/common/npm.d.ts +11 -16
  70. package/lib/common/npm.js +165 -158
  71. package/lib/common/npm.js.map +1 -1
  72. package/lib/common/pack.js +1 -1
  73. package/lib/common/pack.js.map +1 -1
  74. package/lib/common/package.d.ts +6 -7
  75. package/lib/common/package.js +26 -28
  76. package/lib/common/package.js.map +1 -1
  77. package/lib/common/scaffold.js +5 -2
  78. package/lib/common/scaffold.js.map +1 -1
  79. package/lib/common/version.js +4 -4
  80. package/lib/common/version.js.map +1 -1
  81. package/lib/external/index.js +1982 -92
  82. package/lib/helpers.d.ts +4 -4
  83. package/lib/helpers.js +10 -10
  84. package/lib/helpers.js.map +1 -1
  85. package/lib/injectors/{pilet.d.ts → pilet-injector.d.ts} +1 -0
  86. package/lib/injectors/{pilet.js → pilet-injector.js} +29 -31
  87. package/lib/injectors/pilet-injector.js.map +1 -0
  88. package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +1 -0
  89. package/lib/injectors/{piral.js → piral-injector.js} +20 -22
  90. package/lib/injectors/piral-injector.js.map +1 -0
  91. package/lib/messages.d.ts +1 -1
  92. package/lib/messages.js +5 -1
  93. package/lib/messages.js.map +1 -1
  94. package/lib/plugin.js +27 -2
  95. package/lib/plugin.js.map +1 -1
  96. package/lib/release.d.ts +1 -1
  97. package/lib/release.js +7 -2
  98. package/lib/release.js.map +1 -1
  99. package/lib/types/common.d.ts +1 -1
  100. package/lib/types/internal.d.ts +9 -1
  101. package/lib/types/public.d.ts +2 -2
  102. package/package.json +6 -4
  103. package/src/apps/debug-pilet.ts +25 -47
  104. package/src/apps/debug-piral.ts +19 -36
  105. package/src/apps/new-pilet.ts +9 -14
  106. package/src/apps/new-piral.ts +16 -5
  107. package/src/apps/publish-pilet.ts +10 -3
  108. package/src/apps/publish-piral.ts +21 -6
  109. package/src/apps/upgrade-pilet.ts +4 -12
  110. package/src/apps/upgrade-piral.ts +2 -2
  111. package/src/bundler.test.ts +1 -1
  112. package/src/bundler.ts +2 -2
  113. package/src/commands.ts +17 -9
  114. package/src/common/browser.ts +12 -8
  115. package/src/common/clients/index.ts +33 -0
  116. package/src/common/clients/lerna.ts +61 -1
  117. package/src/common/clients/npm.ts +32 -15
  118. package/src/common/clients/pnpm.ts +39 -10
  119. package/src/common/clients/rush.ts +111 -0
  120. package/src/common/clients/yarn.ts +41 -12
  121. package/src/common/constants.ts +1 -1
  122. package/src/common/declaration.ts +17 -10
  123. package/src/common/emulator.ts +3 -3
  124. package/src/common/http.ts +20 -6
  125. package/src/common/importmap.ts +4 -14
  126. package/src/common/info.ts +6 -1
  127. package/src/common/injectors.ts +46 -17
  128. package/src/common/inspect.ts +2 -1
  129. package/src/common/interactive.test.ts +3 -0
  130. package/src/common/interactive.ts +48 -1
  131. package/src/common/io.ts +1 -1
  132. package/src/common/npm.test.ts +122 -76
  133. package/src/common/npm.ts +177 -152
  134. package/src/common/pack.test.ts +1 -1
  135. package/src/common/pack.ts +2 -2
  136. package/src/common/package.test.ts +1 -14
  137. package/src/common/package.ts +31 -29
  138. package/src/common/scaffold.ts +6 -2
  139. package/src/common/version.ts +4 -4
  140. package/src/external/index.ts +2 -1
  141. package/src/helpers.test.ts +5 -5
  142. package/src/helpers.ts +8 -8
  143. package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +10 -1
  144. package/src/injectors/{pilet.ts → pilet-injector.ts} +36 -28
  145. package/src/injectors/{piral.test.ts → piral-injector.test.ts} +5 -1
  146. package/src/injectors/{piral.ts → piral-injector.ts} +24 -17
  147. package/src/messages.ts +6 -2
  148. package/src/plugin.ts +34 -5
  149. package/src/release.ts +10 -2
  150. package/src/types/common.ts +1 -1
  151. package/src/types/internal.ts +6 -1
  152. package/src/types/public.ts +2 -2
  153. package/lib/injectors/pilet.js.map +0 -1
  154. package/lib/injectors/piral.js.map +0 -1
@@ -1,17 +1,14 @@
1
1
  import { join } from 'path';
2
2
  import { Agent } from 'https';
3
3
  import { Stream } from 'stream';
4
- import { platform, tmpdir } from 'os';
4
+ import { tmpdir } from 'os';
5
5
  import { createWriteStream } from 'fs';
6
6
  import { log } from './log';
7
+ import { standardHeaders } from './info';
8
+ import { getTokenInteractively } from './interactive';
7
9
  import { axios, FormData } from '../external';
8
10
  import { PiletPublishScheme } from '../types';
9
11
 
10
- const os = platform();
11
- const standardHeaders = {
12
- 'user-agent': `piral-cli/http.node-${os}`,
13
- };
14
-
15
12
  function getMessage(body: string | { message?: string }) {
16
13
  if (typeof body === 'string') {
17
14
  try {
@@ -74,6 +71,7 @@ export function postFile(
74
71
  customFields: Record<string, string> = {},
75
72
  customHeaders: Record<string, string> = {},
76
73
  ca?: Buffer,
74
+ interactive = false,
77
75
  ): Promise<PostFileResult> {
78
76
  const form = new FormData();
79
77
  const httpsAgent = ca ? new Agent({ ca }) : undefined;
@@ -124,6 +122,22 @@ export function postFile(
124
122
  // The request was made and the server responded with a status code
125
123
  // that falls out of the range of 2xx
126
124
  const { data, statusText, status } = error.response;
125
+
126
+ if (interactive && 'interactiveAuth' in data) {
127
+ const { interactiveAuth } = data;
128
+
129
+ if (typeof interactiveAuth === 'string') {
130
+ log(
131
+ 'generalDebug_0003',
132
+ `Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`,
133
+ );
134
+
135
+ return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
136
+ postFile(target, mode, token, file, customFields, customHeaders, ca, false),
137
+ );
138
+ }
139
+ }
140
+
127
141
  const message = getMessage(data) || '';
128
142
  log('unsuccessfulHttpPost_0066', statusText, status, message);
129
143
  return {
@@ -3,6 +3,7 @@ import { log, fail } from './log';
3
3
  import { satisfies, validate } from './version';
4
4
  import { computeHash } from './hash';
5
5
  import { getHash, readJson, findFile, checkExists, checkIsDirectory } from './io';
6
+ import { tryResolvePackage } from './npm';
6
7
  import { SharedDependency } from '../types';
7
8
 
8
9
  interface Importmap {
@@ -12,17 +13,6 @@ interface Importmap {
12
13
 
13
14
  const shorthandsUrls = ['', '.', '...'];
14
15
 
15
- function tryResolve(baseDir: string, name: string) {
16
- try {
17
- return require.resolve(name, {
18
- paths: [baseDir],
19
- });
20
- } catch (ex) {
21
- log('generalDebug_0003', `Could not resolve the package "${name}" in "${baseDir}": ${ex}`);
22
- return undefined;
23
- }
24
- }
25
-
26
16
  function getDependencyDetails(depName: string): [assetName: string, identifier: string, versionSpec: string] {
27
17
  const sep = depName.indexOf('@', 1);
28
18
  const version = sep > 0 ? depName.substring(sep + 1) : '';
@@ -77,7 +67,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
77
67
  type: 'remote',
78
68
  });
79
69
  } else if (url === identifier || shorthandsUrls.includes(url)) {
80
- const entry = tryResolve(dir, identifier);
70
+ const entry = tryResolvePackage(identifier, dir);
81
71
 
82
72
  if (entry) {
83
73
  const packageJson = await findFile(dirname(entry), 'package.json');
@@ -111,7 +101,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
111
101
  dependencies.push({
112
102
  id: `${identifier}@${version}`,
113
103
  requireId: `${identifier}@${requireVersion}`,
114
- entry: isDirectory ? tryResolve(dir, entry) : entry,
104
+ entry: isDirectory ? tryResolvePackage(entry, dir) : entry,
115
105
  name: identifier,
116
106
  ref: `${assetName}.js`,
117
107
  type: 'local',
@@ -139,7 +129,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
139
129
 
140
130
  if (Array.isArray(inheritedImports)) {
141
131
  for (const inheritedImport of inheritedImports) {
142
- const packageJson = tryResolve(dir, `${inheritedImport}/package.json`);
132
+ const packageJson = tryResolvePackage(`${inheritedImport}/package.json`, dir);
143
133
 
144
134
  if (packageJson) {
145
135
  const packageDir = dirname(packageJson);
@@ -1,6 +1,7 @@
1
- import { cpus } from 'os';
1
+ import { cpus, platform } from 'os';
2
2
 
3
3
  const info = require('../../package.json');
4
+ const os = platform();
4
5
 
5
6
  export function findCompatVersion(version: string) {
6
7
  // we only care about major and minor
@@ -15,9 +16,13 @@ export function findCompatVersion(version: string) {
15
16
  }
16
17
 
17
18
  export const nodeVersion = process.version.substring(1);
19
+ export const cliName = info.name;
18
20
  export const cliVersion = info.version;
19
21
  export const compatVersion = findCompatVersion(cliVersion);
20
22
  export const repositoryUrl = info.repository.url;
21
23
  export const isWindows = process.platform === 'win32';
22
24
  export const pathSeparator = isWindows ? ';' : ':';
23
25
  export const cpuCount = cpus().length;
26
+ export const standardHeaders = {
27
+ 'user-agent': `piral-cli/http.node-${os}`,
28
+ };
@@ -1,25 +1,9 @@
1
1
  import chalk from 'chalk';
2
- import { KrasConfigurationInjectors } from 'kras';
2
+ import { resolve } from 'path';
3
3
  import { liveIcon, settingsIcon } from './emoji';
4
4
  import { logInfo, log, logReset } from './log';
5
5
  import { Bundler } from '../types';
6
6
 
7
- export function reorderInjectors(injectorName: string, injectorConfig: any, injectors: KrasConfigurationInjectors) {
8
- return {
9
- script: injectors.script || {
10
- active: true,
11
- },
12
- har: injectors.har || {
13
- active: true,
14
- },
15
- json: injectors.json || {
16
- active: true,
17
- },
18
- [injectorName]: injectorConfig,
19
- ...injectors,
20
- };
21
- }
22
-
23
7
  export function notifyServerOnline(bundlers: Array<Bundler>, path: string, api: string | false) {
24
8
  return (svc: any) => {
25
9
  log('generalDebug_0003', `The kras server for debugging is online!`);
@@ -30,3 +14,48 @@ export function notifyServerOnline(bundlers: Array<Bundler>, path: string, api:
30
14
  bundlers.forEach((bundler) => bundler.start());
31
15
  };
32
16
  }
17
+
18
+ export function createInitialKrasConfig(
19
+ directory: string,
20
+ map: Record<string, string> = {},
21
+ sources: Array<string> = [],
22
+ feed: string | Array<string> = [],
23
+ ) {
24
+ return {
25
+ api: '/manage-mock-server',
26
+ directory,
27
+ map: {
28
+ '/': '',
29
+ ...map,
30
+ },
31
+ ssl: undefined,
32
+ sources,
33
+ injectorDirs: [resolve(__dirname, '../injectors')],
34
+ injectors: {
35
+ script: {
36
+ active: true,
37
+ },
38
+ har: {
39
+ active: true,
40
+ delay: false,
41
+ },
42
+ json: {
43
+ active: true,
44
+ randomize: true,
45
+ },
46
+ piral: {
47
+ active: true,
48
+ headers: {},
49
+ },
50
+ pilet: {
51
+ active: true,
52
+ meta: 'debug-meta.json',
53
+ headers: {},
54
+ feed,
55
+ },
56
+ proxy: {
57
+ active: true,
58
+ },
59
+ },
60
+ };
61
+ }
@@ -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) {
@@ -3,6 +3,9 @@ import { promptConfirm, promptSelect } from './interactive';
3
3
  const answer = 'Yes, really';
4
4
 
5
5
  jest.mock('../external', () => ({
6
+ rc(_, cfg) {
7
+ return cfg;
8
+ },
6
9
  inquirer: {
7
10
  prompt: (...any) => {
8
11
  return Promise.resolve({ q: answer });
@@ -1,4 +1,8 @@
1
- import { inquirer } from '../external';
1
+ import { Agent } from 'https';
2
+ import { openBrowserAt } from './browser';
3
+ import { standardHeaders } from './info';
4
+ import { axios, inquirer } from '../external';
5
+ import { PiletPublishScheme } from '../types';
2
6
 
3
7
  export function promptSelect(message: string, values: Array<string>, defaultValue: string): Promise<string> {
4
8
  const questions = [
@@ -24,3 +28,46 @@ export function promptConfirm(message: string, defaultValue: boolean): Promise<b
24
28
  ];
25
29
  return inquirer.prompt(questions).then((answers: any) => answers.q);
26
30
  }
31
+
32
+ type TokenResult = Promise<{ mode: PiletPublishScheme; token: string }>;
33
+
34
+ const tokenRetrievers: Record<string, TokenResult> = {};
35
+
36
+ export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResult {
37
+ if (!(url in tokenRetrievers)) {
38
+ tokenRetrievers[url] = axios.default
39
+ .post(
40
+ url,
41
+ {
42
+ clientId: 'piral-cli',
43
+ clientName: 'Piral CLI',
44
+ description: 'Authorize the Piral CLI temporarily to perform actions in your name.',
45
+ },
46
+ {
47
+ headers: {
48
+ ...standardHeaders,
49
+ 'content-type': 'application/json',
50
+ },
51
+ httpsAgent,
52
+ },
53
+ )
54
+ .then((res) => {
55
+ const { loginUrl, callbackUrl, expires } = res.data;
56
+ console.log(`Use the URL below to complete the login. The link expires at ${new Date(expires)}.`);
57
+ console.log('===');
58
+ console.log(loginUrl);
59
+ console.log('===');
60
+
61
+ openBrowserAt(loginUrl);
62
+
63
+ return axios.default.get(callbackUrl).then(({ data }) => {
64
+ console.log('Logged in successfully.');
65
+ return {
66
+ ...data,
67
+ };
68
+ });
69
+ });
70
+ }
71
+
72
+ return tokenRetrievers[url];
73
+ }
package/src/common/io.ts CHANGED
@@ -239,7 +239,7 @@ export async function matchAnyPilet(baseDir: string, patterns: Array<string>) {
239
239
  const allPatterns = patterns.reduce<Array<AnyPattern>>((agg, curr) => {
240
240
  const patterns = [];
241
241
 
242
- if (/[a-zA-Z0-9\-\*]+$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
242
+ if (/[a-zA-Z0-9\-\*]$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
243
243
  patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${nameOfPackageJson}`);
244
244
  } else if (curr.endsWith('/')) {
245
245
  patterns.push(`${curr}index.{${exts}}`, `${curr}${nameOfPackageJson}`);
@@ -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,
@@ -25,6 +21,7 @@ import {
25
21
  getPackageVersion,
26
22
  isGitPackage,
27
23
  makeExternals,
24
+ findPackageRoot,
28
25
  } from './npm';
29
26
 
30
27
  jest.mock('child_process');
@@ -42,9 +39,10 @@ jest.mock('../external', () => ({
42
39
  }));
43
40
 
44
41
  let specialCase = false;
42
+ let shouldFind = true;
45
43
  let wrongCase = false;
46
- const jsonValueString = JSON.stringify({ dependencies: { npm: { extraneous: true } } });
47
- const jsonValueStringWrong = JSON.stringify({ dependencies: {} });
44
+ const jsonValueString = JSON.stringify([{ name: 'npm' }]);
45
+ const jsonValueStringWrong = JSON.stringify([]);
48
46
 
49
47
  jest.mock('./scripts', () => ({
50
48
  runCommand: (exe: string, args: Array<string>, cwd: string, output?: NodeJS.WritableStream) => {
@@ -56,14 +54,15 @@ jest.mock('./scripts', () => ({
56
54
  }));
57
55
 
58
56
  jest.mock('fs', () => ({
59
- constants: {
60
- F_OK: 1,
61
- },
62
57
  createReadStream() {
63
58
  return undefined;
64
59
  },
65
60
  exists: (file: string, cb: (status: boolean) => void) =>
66
- cb(!file.endsWith('package.json') && !(specialCase && (file.endsWith('lerna.json') || file.endsWith('yarn.lock')))),
61
+ cb(
62
+ shouldFind &&
63
+ !file.endsWith('package.json') &&
64
+ !(specialCase && (file.endsWith('lerna.json') || file.endsWith('yarn.lock'))),
65
+ ),
67
66
  existsSync: (file: string) => {
68
67
  return true;
69
68
  },
@@ -72,16 +71,21 @@ jest.mock('fs', () => ({
72
71
  },
73
72
  realpathSync: () => ({}),
74
73
  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
74
  }));
83
75
 
84
76
  describe('npm Module', () => {
77
+ it('findPackageRoot correctly resolves the package root of parcel-bundler', () => {
78
+ const dir = process.cwd();
79
+ const version = findPackageRoot('webpack', dir);
80
+ expect(version).toBe(resolve(dir, 'node_modules', 'webpack', 'package.json'));
81
+ });
82
+
83
+ it('findPackageRoot returns undefined for invalid package', () => {
84
+ const dir = process.cwd();
85
+ const version = findPackageRoot('foo-bar-not-exist', dir);
86
+ expect(version).toBeUndefined();
87
+ });
88
+
85
89
  it('dissects a fully qualified name with latest correctly', async () => {
86
90
  wrongCase = false;
87
91
  const [name, version, hadVersion, type] = await dissectPackageName(process.cwd(), 'foo@latest');
@@ -174,55 +178,66 @@ describe('npm Module', () => {
174
178
 
175
179
  it('installs a package using the npm command line tool without a target', async () => {
176
180
  wrongCase = false;
177
- await installPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
181
+ await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
178
182
  wrongCase = true;
179
- await installPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
183
+ await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
180
184
  });
181
185
 
182
186
  it('installs a package using the npm command line tool without a version', async () => {
183
187
  wrongCase = false;
184
- await installPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
188
+ await installNpmPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
185
189
  wrongCase = true;
186
- await installPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
190
+ await installNpmPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
187
191
  });
188
192
 
189
193
  it('installs a package using the Yarn command line tool without a version', async () => {
190
194
  wrongCase = false;
191
- await installPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
195
+ await installNpmPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
192
196
  wrongCase = true;
193
- await installPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
197
+ await installNpmPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
194
198
  });
195
199
 
196
200
  it('installs a package using the Pnpm command line tool without a version', async () => {
197
201
  wrongCase = false;
198
- await installPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
202
+ await installNpmPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
199
203
  wrongCase = true;
200
- await installPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
204
+ await installNpmPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
201
205
  });
202
206
 
203
207
  it('installs a package using the npm command line tool with some flag', async () => {
204
208
  wrongCase = false;
205
- await installPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) => expect(result).toEqual(jsonValueString));
209
+ await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
210
+ expect(result).toEqual(jsonValueString),
211
+ );
206
212
  wrongCase = true;
207
- await installPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
213
+ await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
208
214
  expect(result).not.toEqual(jsonValueString),
209
215
  );
210
216
  });
211
217
 
212
218
  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());
219
+ shouldFind = true;
220
+ await clients.npm.detectClient('test').then((result) => expect(result).toBeTruthy());
221
+ shouldFind = false;
222
+ await clients.npm.detectClient('toast').then((result) => expect(result).toBeFalsy());
223
+ shouldFind = true;
215
224
  });
216
225
 
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());
226
+ it('detectPnpm finds pnpm-lock.yaml', async () => {
227
+ shouldFind = true;
228
+ await clients.pnpm.detectClient('test').then((result) => expect(result).toBeTruthy());
229
+ shouldFind = false;
230
+ await clients.pnpm.detectClient('toast').then((result) => expect(result).toBeFalsy());
231
+ shouldFind = true;
220
232
  });
221
233
 
222
234
  it('detectYarn finds yarn.lock', async () => {
223
- await detectYarn('test').then((result) => expect(result).toBeTruthy());
235
+ shouldFind = true;
236
+ await clients.yarn.detectClient('test').then((result) => expect(result).toBeTruthy());
237
+ shouldFind = false;
224
238
  specialCase = true;
225
- await detectYarn('toast').then((result) => expect(result).toBeFalsy());
239
+ await clients.yarn.detectClient('toast').then((result) => expect(result).toBeFalsy());
240
+ shouldFind = true;
226
241
  specialCase = false;
227
242
  });
228
243
 
@@ -233,59 +248,46 @@ describe('npm Module', () => {
233
248
  await isMonorepoPackageRef('npm', './').then((result) => expect(result).toBeFalsy());
234
249
  });
235
250
 
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
251
  it('verifies whether lerna bootstrap ran', async () => {
250
252
  wrongCase = false;
251
- await bootstrapMonorepo().then((result) => expect(result).toEqual(jsonValueString));
253
+ await clients.lerna.installDependencies().then((result) => expect(result).toEqual(jsonValueString));
252
254
  wrongCase = true;
253
- await bootstrapMonorepo().then((result) => expect(result).not.toEqual(jsonValueString));
255
+ await clients.lerna.installDependencies().then((result) => expect(result).not.toEqual(jsonValueString));
254
256
  });
255
257
 
256
258
  it('install dependencies with npm client', async () => {
257
259
  wrongCase = false;
258
- await installDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
260
+ await installNpmDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
259
261
  wrongCase = true;
260
- await installDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
262
+ await installNpmDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
261
263
  });
262
264
 
263
265
  it('install dependencies with pnpm client', async () => {
264
266
  wrongCase = false;
265
- await installDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
267
+ await installNpmDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
266
268
  wrongCase = true;
267
- await installDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
269
+ await installNpmDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
268
270
  });
269
271
 
270
272
  it('install dependencies with yarn client', async () => {
271
273
  wrongCase = false;
272
- await installDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
274
+ await installNpmDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
273
275
  wrongCase = true;
274
- await installDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
276
+ await installNpmDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
275
277
  });
276
278
 
277
279
  it('create npm package', async () => {
278
280
  wrongCase = false;
279
- await createPackage().then((result) => expect(result).toEqual(jsonValueString));
281
+ await createNpmPackage().then((result) => expect(result).toEqual(jsonValueString));
280
282
  wrongCase = true;
281
- await createPackage().then((result) => expect(result).not.toEqual(jsonValueString));
283
+ await createNpmPackage().then((result) => expect(result).not.toEqual(jsonValueString));
282
284
  });
283
285
 
284
286
  it('find npm tarball', async () => {
285
287
  wrongCase = false;
286
- await findTarball('foo').then((result) => expect(result).toEqual(jsonValueString));
288
+ await findNpmTarball('foo').then((result) => expect(result).toEqual(jsonValueString));
287
289
  wrongCase = true;
288
- await findTarball('foo').then((result) => expect(result).not.toEqual(jsonValueString));
290
+ await findNpmTarball('foo').then((result) => expect(result).not.toEqual(jsonValueString));
289
291
  });
290
292
 
291
293
  it('find latest version', async () => {
@@ -302,17 +304,61 @@ describe('npm Module', () => {
302
304
  await findSpecificVersion('foo', '1.0.0').then((result) => expect(result).not.toEqual(jsonValueString));
303
305
  });
304
306
 
305
- it('check if package is local', () => {
306
- let result = isLocalPackage('./', 'file://foo.tgz');
307
+ it('check if package from full file is local', () => {
308
+ const result = isLocalPackage('./', 'file://foo.tgz');
309
+ expect(result).toBeTruthy();
310
+ });
311
+
312
+ it('check if package from current dir is local', () => {
313
+ const result = isLocalPackage('./', './');
307
314
  expect(result).toBeTruthy();
308
- result = isLocalPackage('./', './');
315
+ });
316
+
317
+ it('check if package from file is local', () => {
318
+ const result = isLocalPackage('./', 'foo.tgz');
309
319
  expect(result).toBeTruthy();
310
- result = isLocalPackage('./', 'foo.tgz');
320
+ });
321
+
322
+ it('check if package from nothing is not local', () => {
323
+ const result = isLocalPackage('./', null);
324
+ expect(result).toBeFalsy();
325
+ });
326
+
327
+ it('check if package from tilde version is not local', () => {
328
+ const result = isLocalPackage('./', '~12.2.2');
329
+ expect(result).toBeFalsy();
330
+ });
331
+
332
+ it('check if package from caret version is not local', () => {
333
+ const result = isLocalPackage('./', '^12.2.2');
334
+ expect(result).toBeFalsy();
335
+ });
336
+
337
+ it('check if package from star version is not local', () => {
338
+ const result = isLocalPackage('./', '*');
339
+ expect(result).toBeFalsy();
340
+ });
341
+
342
+ it('check if package from greater than is not local', () => {
343
+ const result = isLocalPackage('./', '>=1.0.0');
344
+ expect(result).toBeFalsy();
345
+ });
346
+
347
+ it('check if package from home dir is local', () => {
348
+ const result = isLocalPackage('./', '~/foo/bar');
311
349
  expect(result).toBeTruthy();
312
- result = isLocalPackage('./', null);
350
+ });
351
+
352
+ it('check if package from zero is not local', () => {
353
+ const result = isLocalPackage('./', '.0');
313
354
  expect(result).toBeFalsy();
314
355
  });
315
356
 
357
+ it('check if package from absolute dir is local', () => {
358
+ const result = isLocalPackage('./', '/0');
359
+ expect(result).toBeTruthy();
360
+ });
361
+
316
362
  it('check if package is coming from git', () => {
317
363
  let result = isGitPackage('https://.foo.git');
318
364
  expect(result).toBeTruthy();
@@ -407,7 +453,7 @@ describe('npm Module', () => {
407
453
  });
408
454
 
409
455
  it('makeExternals without externals returns coreExternals', () => {
410
- const externals = makeExternals({ piral: '*' });
456
+ const externals = makeExternals(process.cwd(), { piral: '*' });
411
457
  expect(externals).toEqual([
412
458
  'react',
413
459
  'react-dom',
@@ -422,7 +468,7 @@ describe('npm Module', () => {
422
468
  });
423
469
 
424
470
  it('makeExternals with no externals returns coreExternals', () => {
425
- const externals = makeExternals({ piral: '*' }, []);
471
+ const externals = makeExternals(process.cwd(), { piral: '*' }, []);
426
472
  expect(externals).toEqual([
427
473
  'react',
428
474
  'react-dom',
@@ -437,12 +483,12 @@ describe('npm Module', () => {
437
483
  });
438
484
 
439
485
  it('makeExternals with exclude coreExternals returns empty set', () => {
440
- const externals = makeExternals({ piral: '*' }, ['!*']);
486
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['!*']);
441
487
  expect(externals).toEqual([]);
442
488
  });
443
489
 
444
490
  it('makeExternals with externals concats coreExternals', () => {
445
- const externals = makeExternals({ piral: '*' }, ['foo', 'bar']);
491
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['foo', 'bar']);
446
492
  expect(externals).toEqual([
447
493
  'foo',
448
494
  'bar',
@@ -459,7 +505,7 @@ describe('npm Module', () => {
459
505
  });
460
506
 
461
507
  it('makeExternals with external duplicate only reflects coreExternals', () => {
462
- const externals = makeExternals({ piral: '*' }, ['react', 'foo']);
508
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'foo']);
463
509
  expect(externals).toEqual([
464
510
  'react',
465
511
  'foo',
@@ -475,7 +521,7 @@ describe('npm Module', () => {
475
521
  });
476
522
 
477
523
  it('makeExternals with explicit include and exclude', () => {
478
- const externals = makeExternals({ piral: '*' }, ['react', 'react-calendar', '!history']);
524
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'react-calendar', '!history']);
479
525
  expect(externals).toEqual([
480
526
  'react',
481
527
  'react-calendar',
@@ -490,7 +536,7 @@ describe('npm Module', () => {
490
536
  });
491
537
 
492
538
  it('makeExternals with all exclude and explicit include', () => {
493
- const externals = makeExternals({ piral: '*' }, ['react', 'react-router-dom', '!*']);
539
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'react-router-dom', '!*']);
494
540
  expect(externals).toEqual(['react', 'react-router-dom']);
495
541
  });
496
542
  });