piral-cli 0.15.0-alpha.4122 → 0.15.0-alpha.4231

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 (124) 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.d.ts +4 -0
  6. package/lib/apps/publish-pilet.js +4 -3
  7. package/lib/apps/publish-pilet.js.map +1 -1
  8. package/lib/apps/publish-piral.d.ts +4 -0
  9. package/lib/apps/publish-piral.js +9 -7
  10. package/lib/apps/publish-piral.js.map +1 -1
  11. package/lib/apps/upgrade-pilet.js +2 -8
  12. package/lib/apps/upgrade-pilet.js.map +1 -1
  13. package/lib/apps/upgrade-piral.js +1 -1
  14. package/lib/apps/upgrade-piral.js.map +1 -1
  15. package/lib/bundler.js +1 -1
  16. package/lib/bundler.js.map +1 -1
  17. package/lib/commands.js +8 -0
  18. package/lib/commands.js.map +1 -1
  19. package/lib/common/browser.d.ts +1 -0
  20. package/lib/common/browser.js +16 -10
  21. package/lib/common/browser.js.map +1 -1
  22. package/lib/common/clients/index.d.ts +19 -0
  23. package/lib/common/clients/index.js +40 -0
  24. package/lib/common/clients/index.js.map +1 -0
  25. package/lib/common/clients/lerna.d.ts +6 -1
  26. package/lib/common/clients/lerna.js +67 -3
  27. package/lib/common/clients/lerna.js.map +1 -1
  28. package/lib/common/clients/npm.d.ts +4 -1
  29. package/lib/common/clients/npm.js +37 -16
  30. package/lib/common/clients/npm.js.map +1 -1
  31. package/lib/common/clients/pnpm.d.ts +4 -0
  32. package/lib/common/clients/pnpm.js +43 -9
  33. package/lib/common/clients/pnpm.js.map +1 -1
  34. package/lib/common/clients/rush.d.ts +6 -0
  35. package/lib/common/clients/rush.js +118 -0
  36. package/lib/common/clients/rush.js.map +1 -0
  37. package/lib/common/clients/yarn.d.ts +4 -0
  38. package/lib/common/clients/yarn.js +45 -11
  39. package/lib/common/clients/yarn.js.map +1 -1
  40. package/lib/common/declaration.js +12 -9
  41. package/lib/common/declaration.js.map +1 -1
  42. package/lib/common/emulator.js +2 -2
  43. package/lib/common/emulator.js.map +1 -1
  44. package/lib/common/http.d.ts +1 -1
  45. package/lib/common/http.js +12 -7
  46. package/lib/common/http.js.map +1 -1
  47. package/lib/common/info.d.ts +4 -0
  48. package/lib/common/info.js +6 -1
  49. package/lib/common/info.js.map +1 -1
  50. package/lib/common/inspect.js +2 -1
  51. package/lib/common/inspect.js.map +1 -1
  52. package/lib/common/interactive.d.ts +9 -0
  53. package/lib/common/interactive.js +31 -1
  54. package/lib/common/interactive.js.map +1 -1
  55. package/lib/common/io.js +1 -1
  56. package/lib/common/io.js.map +1 -1
  57. package/lib/common/npm.d.ts +9 -16
  58. package/lib/common/npm.js +110 -152
  59. package/lib/common/npm.js.map +1 -1
  60. package/lib/common/pack.js +1 -1
  61. package/lib/common/pack.js.map +1 -1
  62. package/lib/common/package.d.ts +6 -6
  63. package/lib/common/package.js +13 -4
  64. package/lib/common/package.js.map +1 -1
  65. package/lib/common/scaffold.js +5 -2
  66. package/lib/common/scaffold.js.map +1 -1
  67. package/lib/common/version.js +4 -4
  68. package/lib/common/version.js.map +1 -1
  69. package/lib/external/index.js +1982 -92
  70. package/lib/helpers.js +1 -1
  71. package/lib/helpers.js.map +1 -1
  72. package/lib/injectors/pilet.js +2 -2
  73. package/lib/injectors/pilet.js.map +1 -1
  74. package/lib/messages.d.ts +1 -1
  75. package/lib/messages.js.map +1 -1
  76. package/lib/plugin.js +27 -2
  77. package/lib/plugin.js.map +1 -1
  78. package/lib/release.d.ts +1 -1
  79. package/lib/release.js +7 -2
  80. package/lib/release.js.map +1 -1
  81. package/lib/types/common.d.ts +1 -1
  82. package/lib/types/internal.d.ts +9 -1
  83. package/lib/types/public.d.ts +1 -1
  84. package/package.json +5 -3
  85. package/src/apps/new-pilet.ts +9 -14
  86. package/src/apps/new-piral.ts +9 -5
  87. package/src/apps/publish-pilet.ts +10 -3
  88. package/src/apps/publish-piral.ts +21 -6
  89. package/src/apps/upgrade-pilet.ts +4 -12
  90. package/src/apps/upgrade-piral.ts +2 -2
  91. package/src/bundler.test.ts +1 -1
  92. package/src/bundler.ts +2 -2
  93. package/src/commands.ts +8 -0
  94. package/src/common/browser.ts +12 -8
  95. package/src/common/clients/index.ts +33 -0
  96. package/src/common/clients/lerna.ts +61 -1
  97. package/src/common/clients/npm.ts +32 -15
  98. package/src/common/clients/pnpm.ts +39 -10
  99. package/src/common/clients/rush.ts +111 -0
  100. package/src/common/clients/yarn.ts +41 -12
  101. package/src/common/declaration.ts +15 -9
  102. package/src/common/emulator.ts +3 -3
  103. package/src/common/http.ts +20 -6
  104. package/src/common/info.ts +6 -1
  105. package/src/common/inspect.ts +2 -1
  106. package/src/common/interactive.test.ts +3 -0
  107. package/src/common/interactive.ts +48 -1
  108. package/src/common/io.ts +1 -1
  109. package/src/common/npm.test.ts +109 -76
  110. package/src/common/npm.ts +119 -146
  111. package/src/common/pack.test.ts +1 -1
  112. package/src/common/pack.ts +2 -2
  113. package/src/common/package.ts +19 -10
  114. package/src/common/scaffold.ts +6 -2
  115. package/src/common/version.ts +4 -4
  116. package/src/external/index.ts +2 -1
  117. package/src/helpers.ts +1 -1
  118. package/src/injectors/pilet.ts +3 -3
  119. package/src/messages.ts +1 -1
  120. package/src/plugin.ts +34 -5
  121. package/src/release.ts +10 -2
  122. package/src/types/common.ts +1 -1
  123. package/src/types/internal.ts +6 -1
  124. package/src/types/public.ts +1 -1
package/src/common/npm.ts CHANGED
@@ -1,65 +1,60 @@
1
1
  import { resolve, relative, dirname, isAbsolute, sep } from 'path';
2
- import { createReadStream, existsSync, access, constants } from 'fs';
2
+ import { createReadStream, existsSync } from 'fs';
3
3
  import { log, fail } from './log';
4
+ import { clients, detectClients, isWrapperClient } from './clients';
4
5
  import { config } from './config';
5
6
  import { legacyCoreExternals, frameworkLibs } from './constants';
6
7
  import { inspectPackage } from './inspect';
7
- import { readJson, checkExists, findFile } from './io';
8
+ import { readJson, checkExists } from './io';
8
9
  import { clientTypeKeys } from '../helpers';
9
10
  import { PackageType, NpmClientType } from '../types';
10
11
 
11
12
  const gitPrefix = 'git+';
12
13
  const filePrefix = 'file:';
14
+ const pathPrefixes = ['/', './', '../', '.\\', '..\\', '~/', '~\\', filePrefix];
13
15
 
14
16
  function isProjectReference(name: string) {
15
17
  const target = resolve(name, 'package.json');
16
18
  return checkExists(target);
17
19
  }
18
20
 
19
- export function detectPnpm(root: string) {
20
- return new Promise((res) => {
21
- access(resolve(root, 'pnpm-lock.yaml'), constants.F_OK, (noPnpmLock) => {
22
- res(!noPnpmLock);
23
- });
24
- });
21
+ function resolveAbsPath(basePath: string, fullName: string) {
22
+ const prefixed = fullName.startsWith(filePrefix);
23
+ const relPath = !prefixed ? fullName : fullName.replace(filePrefix, '');
24
+ return resolve(basePath, relPath);
25
25
  }
26
26
 
27
- export function detectNpm(root: string) {
28
- return new Promise((res) => {
29
- access(resolve(root, 'package-lock.json'), constants.F_OK, (noPackageLock) => {
30
- res(!noPackageLock);
31
- });
32
- });
33
- }
27
+ async function detectMonorepoRoot(root: string): Promise<[] | [string, NpmClientType]> {
28
+ let previous = root;
34
29
 
35
- export async function detectYarn(root: string) {
36
- return !!(await findFile(root, 'yarn.lock'));
37
- }
30
+ do {
31
+ if (await checkExists(resolve(root, 'lerna.json'))) {
32
+ return [root, 'lerna'];
33
+ }
38
34
 
39
- export async function getLernaConfigPath(root: string) {
40
- log('generalDebug_0003', 'Trying to get the configuration file for Lerna ...');
41
- const file = await findFile(root, 'lerna.json');
35
+ if (await checkExists(resolve(root, 'rush.json'))) {
36
+ return [root, 'rush'];
37
+ }
42
38
 
43
- if (file) {
44
- log('generalDebug_0003', `Found Lerna config in "${file}".`);
45
- return file;
46
- }
39
+ if (await checkExists(resolve(root, 'pnpm-workspace.yaml'))) {
40
+ return [root, 'pnpm'];
41
+ }
47
42
 
48
- return undefined;
49
- }
43
+ const packageJson = await readJson(root, 'package.json');
50
44
 
51
- export async function getLernaNpmClient(root: string): Promise<NpmClientType> {
52
- const file = await getLernaConfigPath(root);
45
+ if (Array.isArray(packageJson?.workspaces)) {
46
+ if (await checkExists(resolve(root, 'yarn.lock'))) {
47
+ return [root, 'yarn'];
48
+ }
53
49
 
54
- if (file) {
55
- try {
56
- return require(file).npmClient;
57
- } catch (err) {
58
- log('generalError_0002', `Could not read lerna.json: ${err}.`);
50
+ return [root, 'npm'];
59
51
  }
60
- }
61
52
 
62
- return undefined;
53
+ previous = root;
54
+ root = dirname(root);
55
+ } while (root !== previous);
56
+
57
+ return [];
63
58
  }
64
59
 
65
60
  /**
@@ -69,36 +64,45 @@ export async function getLernaNpmClient(root: string): Promise<NpmClientType> {
69
64
  */
70
65
  export async function determineNpmClient(root: string, selected?: NpmClientType): Promise<NpmClientType> {
71
66
  if (!selected || !clientTypeKeys.includes(selected)) {
72
- log('generalDebug_0003', 'No npm client selected. Checking for lock files ...');
73
- const [hasNpm, hasYarn, hasPnpm] = await Promise.all([detectNpm(root), detectYarn(root), detectPnpm(root)]);
74
- const found = +hasNpm + +hasYarn + +hasPnpm;
75
- log('generalDebug_0003', `Results of the lock file check: npm = ${hasNpm}, Yarn = ${hasYarn}, Pnpm = ${hasPnpm}`);
67
+ log('generalDebug_0003', 'No npm client selected. Checking for lock or config files ...');
68
+
69
+ const searchedClients = await detectClients(root);
70
+ const foundClients = searchedClients.filter((m) => m.result);
71
+
72
+ log(
73
+ 'generalDebug_0003',
74
+ `Results of the lock file check: ${searchedClients.map((m) => `${m.client}=${m.result}`).join(', ')}`,
75
+ );
76
+
76
77
  const defaultClient = config.npmClient;
77
78
 
78
- if (found !== 1) {
79
- const lernaClient = await getLernaNpmClient(root);
79
+ if (foundClients.length > 1) {
80
+ const wrapperClient = foundClients.find((m) => isWrapperClient(m.client));
80
81
 
81
- if (clientTypeKeys.includes(lernaClient)) {
82
- log('generalDebug_0003', `Found valid npm client via Lerna: ${lernaClient}.`);
83
- return lernaClient;
82
+ if (wrapperClient) {
83
+ const { client } = wrapperClient;
84
+ log('generalDebug_0003', `Found valid wrapper client via lock or config file: "${client}".`);
84
85
  }
85
- } else if (hasNpm) {
86
- log('generalDebug_0003', `Found valid npm client via lockfile.`);
87
- return 'npm';
88
- } else if (hasYarn) {
89
- log('generalDebug_0003', `Found valid Yarn client via lockfile.`);
90
- return 'yarn';
91
- } else if (hasPnpm) {
92
- log('generalDebug_0003', `Found valid pnpm client via lockfile.`);
93
- return 'pnpm';
86
+ }
87
+
88
+ if (foundClients.length > 0) {
89
+ const { client } = foundClients[0];
90
+
91
+ if (foundClients.length > 1) {
92
+ const clientStr = `"${foundClients.map((m) => m.client).join('", "')}"`;
93
+ log('generalWarning_0001', `Found multiple clients via their lock or config files: ${clientStr}.`);
94
+ }
95
+
96
+ log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
97
+ return client;
94
98
  }
95
99
 
96
100
  if (clientTypeKeys.includes(defaultClient)) {
97
- log('generalDebug_0003', `Found valid Pnpm client the default client: "${defaultClient}".`);
101
+ log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
98
102
  return defaultClient;
99
103
  }
100
104
 
101
- log('generalDebug_0003', 'Using the default npm client.');
105
+ log('generalDebug_0003', 'Using the default "npm" client.');
102
106
  return 'npm';
103
107
  }
104
108
 
@@ -106,103 +110,66 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
106
110
  }
107
111
 
108
112
  export async function isMonorepoPackageRef(refName: string, root: string): Promise<boolean> {
109
- const c = require(`./clients/npm`);
110
- const newRoot = await detectMonorepoRoot(root);
113
+ const [monorepoRoot, client] = await detectMonorepoRoot(root);
111
114
 
112
- if (newRoot) {
113
- const details = await c.listPackage(refName, newRoot);
114
- return details?.dependencies?.[refName]?.extraneous ?? false;
115
+ if (monorepoRoot) {
116
+ const c = clients[client];
117
+ return await c.isProject(monorepoRoot, refName);
115
118
  }
116
119
 
117
120
  return false;
118
121
  }
119
122
 
120
- export async function detectMonorepoRoot(root: string): Promise<string> {
121
- const file = await getLernaConfigPath(root);
122
-
123
- if (file !== undefined) {
124
- return dirname(file);
125
- }
126
-
127
- let previous = root;
128
-
129
- do {
130
- const packageJson = await readJson(root, 'package.json');
131
-
132
- if (Array.isArray(packageJson?.workspaces)) {
133
- return root;
134
- }
135
-
136
- previous = root;
137
- root = dirname(root);
138
- } while (root !== previous);
139
-
140
- return undefined;
123
+ export function installNpmDependencies(client: NpmClientType, target = '.'): Promise<string> {
124
+ const { installDependencies } = clients[client];
125
+ return installDependencies(target);
141
126
  }
142
127
 
143
- export type MonorepoKind = 'none' | 'lerna' | 'yarn';
144
-
145
- export async function detectMonorepo(root: string): Promise<MonorepoKind> {
146
- const newRoot = await detectMonorepoRoot(root);
147
-
148
- if (newRoot) {
149
- const file = await getLernaConfigPath(newRoot);
150
-
151
- if (file !== undefined) {
152
- return 'lerna';
153
- }
154
-
155
- const packageJson = await readJson(newRoot, 'package.json');
156
-
157
- if (Array.isArray(packageJson?.workspaces)) {
158
- return 'yarn';
159
- }
160
- }
161
-
162
- return 'none';
163
- }
164
-
165
- export function bootstrapMonorepo(target = '.') {
166
- const c = require(`./clients/lerna`);
167
- return c.bootstrap(target);
168
- }
169
-
170
- export function installDependencies(client: NpmClientType, target = '.'): Promise<string> {
171
- const c = require(`./clients/${client}`);
172
- return c.installDependencies(target);
173
- }
174
-
175
- export function installPackage(
128
+ export async function installNpmPackage(
176
129
  client: NpmClientType,
177
130
  packageRef: string,
178
131
  target = '.',
179
132
  ...flags: Array<string>
180
133
  ): Promise<string> {
181
- const c = require(`./clients/${client}`);
182
- return c.installPackage(packageRef, target, ...flags);
134
+ try {
135
+ const { installPackage } = clients[client];
136
+ return await installPackage(packageRef, target, ...flags);
137
+ } catch (ex) {
138
+ log(
139
+ 'generalError_0002',
140
+ `Could not install the package "${packageRef}" using ${client}. Make sure ${client} is correctly installed and accessible: ${ex}`,
141
+ );
142
+ throw ex;
143
+ }
144
+ }
145
+
146
+ export function initNpmProject(client: NpmClientType, projectName: string, target: string) {
147
+ const { initProject } = clients[client];
148
+ return initProject(projectName, target);
183
149
  }
184
150
 
185
- export function publishPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
186
- const c = require(`./clients/npm`);
187
- return c.publishPackage(target, file, ...flags);
151
+ export function publishNpmPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
152
+ const { publishPackage } = clients.npm;
153
+ return publishPackage(target, file, ...flags);
188
154
  }
189
155
 
190
- export function createPackage(target = '.'): Promise<string> {
191
- const c = require(`./clients/npm`);
192
- return c.createPackage(target);
156
+ export function createNpmPackage(target = '.'): Promise<string> {
157
+ const { createPackage } = clients.npm;
158
+ return createPackage(target);
193
159
  }
194
160
 
195
- export function findTarball(packageRef: string): Promise<string> {
196
- const c = require(`./clients/npm`);
197
- return c.findTarball(packageRef);
161
+ export function findNpmTarball(packageRef: string): Promise<string> {
162
+ const { findTarball } = clients.npm;
163
+ return findTarball(packageRef);
198
164
  }
199
165
 
200
166
  export function findSpecificVersion(packageName: string, version: string): Promise<string> {
201
- const c = require(`./clients/npm`);
202
- return c.findSpecificVersion(packageName, version);
167
+ const { findSpecificVersion } = clients.npm;
168
+ return findSpecificVersion(packageName, version);
203
169
  }
204
170
 
205
171
  export function findLatestVersion(packageName: string) {
172
+ const { findSpecificVersion } = clients.npm;
206
173
  return findSpecificVersion(packageName, 'latest');
207
174
  }
208
175
 
@@ -210,7 +177,7 @@ export function isLocalPackage(baseDir: string, fullName: string) {
210
177
  log('generalDebug_0003', 'Checking if its a local package ...');
211
178
 
212
179
  if (fullName) {
213
- if (/^[\.\/\~]/.test(fullName)) {
180
+ if (pathPrefixes.some((prefix) => fullName.startsWith(prefix))) {
214
181
  log('generalDebug_0003', 'Found a local package by name.');
215
182
  return true;
216
183
  } else if (fullName.endsWith('.tgz')) {
@@ -249,9 +216,7 @@ export function makeGitUrl(fullName: string) {
249
216
  }
250
217
 
251
218
  export function makeFilePath(basePath: string, fullName: string) {
252
- const prefixed = fullName.startsWith(filePrefix);
253
- const relPath = !prefixed ? fullName : fullName.replace(filePrefix, '');
254
- const absPath = resolve(basePath, relPath);
219
+ const absPath = resolveAbsPath(basePath, fullName);
255
220
  return `${filePrefix}${absPath}`;
256
221
  }
257
222
 
@@ -275,7 +240,7 @@ export async function dissectPackageName(
275
240
  const gitUrl = makeGitUrl(fullName);
276
241
  return [gitUrl, 'latest', false, 'git'];
277
242
  } else if (isLocalPackage(baseDir, fullName)) {
278
- const fullPath = resolve(baseDir, fullName);
243
+ const fullPath = resolveAbsPath(baseDir, fullName);
279
244
  const exists = await checkExists(fullPath);
280
245
 
281
246
  if (!exists) {
@@ -418,7 +383,8 @@ export function isLinkedPackage(name: string, type: PackageType, hadVersion: boo
418
383
 
419
384
  export function combinePackageRef(name: string, version: string, type: PackageType) {
420
385
  if (type === 'registry') {
421
- return `${name}@${version || 'latest'}`;
386
+ const tag = version || 'latest';
387
+ return `${name}@${tag}`;
422
388
  }
423
389
 
424
390
  return name;
@@ -472,19 +438,22 @@ export function getPackageVersion(
472
438
  }
473
439
  }
474
440
 
475
- function getExternalsFrom(packageName: string): Array<string> | undefined {
441
+ function getExternalsFrom(root: string, packageName: string): Array<string> | undefined {
476
442
  try {
477
- return require(`${packageName}/package.json`).sharedDependencies;
443
+ const target = require.resolve(`${packageName}/package.json`, {
444
+ paths: [root],
445
+ });
446
+ return require(target).sharedDependencies;
478
447
  } catch (err) {
479
448
  log('generalError_0002', `Could not get externals from "${packageName}": "${err}`);
480
449
  return undefined;
481
450
  }
482
451
  }
483
452
 
484
- function getCoreExternals(dependencies: Record<string, string>): Array<string> {
453
+ function getCoreExternals(root: string, dependencies: Record<string, string>): Array<string> {
485
454
  for (const frameworkLib of frameworkLibs) {
486
455
  if (dependencies[frameworkLib]) {
487
- const deps = getExternalsFrom(frameworkLib);
456
+ const deps = getExternalsFrom(root, frameworkLib);
488
457
 
489
458
  if (deps) {
490
459
  return deps;
@@ -497,24 +466,23 @@ function getCoreExternals(dependencies: Record<string, string>): Array<string> {
497
466
  }
498
467
 
499
468
  export function makePiletExternals(
469
+ root: string,
500
470
  dependencies: Record<string, string>,
501
471
  externals: Array<string>,
502
472
  fromEmulator: boolean,
503
473
  piralInfo: any,
504
- ) {
474
+ ): Array<string> {
505
475
  if (fromEmulator) {
506
- const { sharedDependencies = makeExternals(dependencies, externals, true) } = piralInfo;
476
+ const { sharedDependencies = mergeExternals(externals, legacyCoreExternals) } = piralInfo;
507
477
  return sharedDependencies;
508
478
  } else {
509
- return makeExternals(dependencies, externals);
479
+ return makeExternals(root, dependencies, externals);
510
480
  }
511
481
  }
512
482
 
513
- export function makeExternals(dependencies: Record<string, string>, externals?: Array<string>, legacy = false) {
514
- const coreExternals = legacy ? legacyCoreExternals : getCoreExternals(dependencies);
515
-
516
- if (externals && Array.isArray(externals)) {
517
- const [include, exclude] = externals.reduce<[Array<string>, Array<string>]>(
483
+ export function mergeExternals(customExternals?: Array<string>, coreExternals: Array<string> = []) {
484
+ if (customExternals && Array.isArray(customExternals)) {
485
+ const [include, exclude] = customExternals.reduce<[Array<string>, Array<string>]>(
518
486
  (prev, curr) => {
519
487
  if (typeof curr === 'string') {
520
488
  if (curr.startsWith('!')) {
@@ -534,3 +502,8 @@ export function makeExternals(dependencies: Record<string, string>, externals?:
534
502
 
535
503
  return coreExternals;
536
504
  }
505
+
506
+ export function makeExternals(root: string, dependencies: Record<string, string>, externals?: Array<string>) {
507
+ const coreExternals = getCoreExternals(root, dependencies);
508
+ return mergeExternals(externals, coreExternals);
509
+ }
@@ -13,7 +13,7 @@ jest.mock('./io', () => ({
13
13
  }));
14
14
 
15
15
  jest.mock('./npm', () => ({
16
- createPackage: (target?: string) => {
16
+ createNpmPackage: (target?: string) => {
17
17
  return Promise.resolve(target);
18
18
  },
19
19
  }));
@@ -1,7 +1,7 @@
1
1
  import { resolve, join } from 'path';
2
2
  import { log, progress, fail } from './log';
3
3
  import { readJson, move } from './io';
4
- import { createPackage } from './npm';
4
+ import { createNpmPackage } from './npm';
5
5
  import { ForceOverwrite } from './enums';
6
6
 
7
7
  async function getFile(root: string, name: string, dest: string) {
@@ -38,7 +38,7 @@ export async function createPiletPackage(baseDir: string, source: string, target
38
38
 
39
39
  progress(`Packing pilet in ${dest} ...`);
40
40
  log('generalDebug_0003', 'Creating package ...');
41
- await createPackage(root);
41
+ await createNpmPackage(root);
42
42
  log('generalDebug_0003', 'Successfully created package.');
43
43
  const name = `${pckg.name}-${pckg.version}.tgz`.replace(/@/g, '').replace(/\//g, '-');
44
44
  log('generalDebug_0003', `Assumed package name "${name}".`);
@@ -13,7 +13,7 @@ import { getHash, checkIsDirectory, matchFiles } from './io';
13
13
  import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
14
14
  import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
15
15
  import { makePiletExternals, makeExternals, findPackageRoot } from './npm';
16
- import { Framework, FileInfo, PiletsInfo, TemplateFileLocation } from '../types';
16
+ import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, PackageData } from '../types';
17
17
 
18
18
  function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
19
19
  if (bundler && bundler !== 'none') {
@@ -149,7 +149,7 @@ function findPackage(pck: string | Array<string>, baseDir: string) {
149
149
  return undefined;
150
150
  }
151
151
 
152
- export function readPiralPackage(root: string, name: string) {
152
+ export function readPiralPackage(root: string, name: string): Promise<PackageData> {
153
153
  log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
154
154
  const path = getPiralPath(root, name);
155
155
  return readJson(path, 'package.json');
@@ -318,10 +318,19 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
318
318
  return typeof item === 'object';
319
319
  }
320
320
 
321
+ function tryFindPackageVersion(packageName: string): string {
322
+ try {
323
+ const { version } = require(`${packageName}/package.json`);
324
+ return version;
325
+ } catch {
326
+ return undefined;
327
+ }
328
+ }
329
+
321
330
  export async function copyPiralFiles(
322
331
  root: string,
323
332
  name: string,
324
- piralInfo: any,
333
+ piralInfo: PackageData,
325
334
  forceOverwrite: ForceOverwrite,
326
335
  variables: Record<string, string>,
327
336
  originalFiles?: Array<FileInfo>,
@@ -341,7 +350,7 @@ export async function copyPiralFiles(
341
350
  await copyFiles(files, forceOverwrite, originalFiles, variables);
342
351
  }
343
352
 
344
- export function getPiletsInfo(piralInfo: any): PiletsInfo {
353
+ export function getPiletsInfo(piralInfo: Partial<PackageData>): PiletsInfo {
345
354
  const {
346
355
  files = [],
347
356
  scripts = {},
@@ -450,7 +459,7 @@ export async function retrieveExternals(root: string, packageInfo: any) {
450
459
  ...packageInfo.dependencies,
451
460
  };
452
461
  const deps = packageInfo.pilets?.externals;
453
- return makeExternals(allDeps, deps);
462
+ return makeExternals(root, allDeps, deps);
454
463
  }
455
464
 
456
465
  return sharedDependencies.map((m) => m.name);
@@ -469,9 +478,9 @@ export async function retrievePiletsInfo(entryFile: string) {
469
478
  fail('packageJsonMissing_0074');
470
479
  }
471
480
 
481
+ const root = dirname(packageJson);
472
482
  const packageInfo = require(packageJson);
473
483
  const info = getPiletsInfo(packageInfo);
474
- const root = dirname(packageJson);
475
484
  const externals = await retrieveExternals(root, packageInfo);
476
485
 
477
486
  return {
@@ -500,7 +509,7 @@ export async function patchPiletPackage(
500
509
  root: string,
501
510
  name: string,
502
511
  version: string,
503
- piralInfo: any,
512
+ piralInfo: PackageData,
504
513
  fromEmulator: boolean,
505
514
  newInfo?: { language: SourceLanguage; bundler: string },
506
515
  ) {
@@ -524,7 +533,7 @@ export async function patchPiletPackage(
524
533
  }
525
534
  : info.scripts;
526
535
  const peerModules = [];
527
- const allExternals = makePiletExternals(piralDependencies, externals, fromEmulator, piralInfo);
536
+ const allExternals = makePiletExternals(root, piralDependencies, externals, fromEmulator, piralInfo);
528
537
  const peerDependencies = {
529
538
  ...allExternals.reduce((deps, name) => {
530
539
  const valid = isValidDependency(name);
@@ -548,7 +557,7 @@ export async function patchPiletPackage(
548
557
  return deps;
549
558
  }, {}),
550
559
  ...allExternals.filter(isValidDependency).reduce((deps, name) => {
551
- const version = piralDependencies[name];
560
+ const version = piralDependencies[name] || tryFindPackageVersion(name);
552
561
 
553
562
  if (version || newInfo) {
554
563
  // set only if we have an explicit version or we are in the scaffolding case
@@ -585,7 +594,7 @@ export async function patchPiletPackage(
585
594
  /**
586
595
  * Returns true if its an emulator package, otherwise it has to be a "raw" app shell.
587
596
  */
588
- export function checkAppShellPackage(appPackage: any) {
597
+ export function checkAppShellPackage(appPackage: PackageData) {
589
598
  const { piralCLI = { generated: false, version: cliVersion } } = appPackage;
590
599
 
591
600
  if (piralCLI.generated) {
@@ -1,5 +1,5 @@
1
1
  import { join, dirname, resolve, basename, isAbsolute } from 'path';
2
- import { installPackage } from './clients/npm';
2
+ import { installNpmPackage } from './npm';
3
3
  import { ForceOverwrite, SourceLanguage } from './enums';
4
4
  import { createDirectory, createFileIfNotExists, updateExistingJson } from './io';
5
5
  import { cliVersion, isWindows } from './info';
@@ -37,7 +37,11 @@ async function getTemplateFiles(
37
37
  if (templatePackageName.startsWith('.')) {
38
38
  templatePackageName = resolve(process.cwd(), templatePackageName);
39
39
  } else {
40
- await installPackage(templatePackageName, __dirname, '--registry', registry);
40
+ if (templatePackageName.indexOf('@', 1) === -1) {
41
+ templatePackageName = `${templatePackageName}@latest`;
42
+ }
43
+
44
+ await installNpmPackage('npm', templatePackageName, __dirname, '--registry', registry);
41
45
  }
42
46
 
43
47
  const templateRunner = getTemplatePackage(templatePackageName);
@@ -16,15 +16,15 @@ function indexOrEnd(str: string, q: string) {
16
16
  }
17
17
 
18
18
  function splitVersion(v: string) {
19
- var c = v.replace(/^v/, '').replace(/\+.*$/, '');
20
- var patchIndex = indexOrEnd(c, '-');
21
- var arr = c.substring(0, patchIndex).split('.');
19
+ const c = v.replace(/^v/, '').replace(/\+.*$/, '');
20
+ const patchIndex = indexOrEnd(c, '-');
21
+ const arr = c.substring(0, patchIndex).split('.');
22
22
  arr.push(c.substring(patchIndex + 1));
23
23
  return arr;
24
24
  }
25
25
 
26
26
  function parseSegment(v: string) {
27
- var n = parseInt(v, 10);
27
+ const n = parseInt(v, 10);
28
28
  return isNaN(n) ? v : n;
29
29
  }
30
30
 
@@ -1,6 +1,7 @@
1
1
  import logger = require('@parcel/logger');
2
2
  import stripAnsi = require('strip-ansi');
3
3
  import inquirer = require('inquirer');
4
+ import jju = require('jju');
4
5
  import glob = require('glob');
5
6
  import tar = require('tar');
6
7
  import FormData = require('form-data');
@@ -10,4 +11,4 @@ import mime = require('mime');
10
11
  import getPort = require('get-port');
11
12
  import open = require('open');
12
13
 
13
- export { logger, inquirer, glob, tar, FormData, rc, axios, mime, stripAnsi, getPort, open };
14
+ export { logger, inquirer, glob, tar, FormData, rc, axios, mime, stripAnsi, getPort, open, jju };
package/src/helpers.ts CHANGED
@@ -15,7 +15,7 @@ export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bea
15
15
  export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
16
16
  export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
17
17
  export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
18
- export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn'];
18
+ export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn', 'lerna', 'rush'];
19
19
  export const bundlerKeys: Array<string> = ['none', ...bundlerNames];
20
20
  export const availableBundlers: Array<string> = [];
21
21
  export const availableReleaseProviders: Array<string> = [];
@@ -6,7 +6,7 @@ import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfig
6
6
  import { log } from '../common/log';
7
7
  import { getPiletSpecMeta } from '../common/spec';
8
8
  import { config } from '../common/config';
9
- import { axios, mime } from '../external';
9
+ import { axios, mime, jju } from '../external';
10
10
  import { Bundler } from '../types';
11
11
 
12
12
  const { host } = config;
@@ -35,8 +35,8 @@ function fillPiletMeta(pilet: Pilet, basePath: string, metaFile: string) {
35
35
  const { root, bundler } = pilet;
36
36
  const metaPath = join(root, metaFile);
37
37
  const packagePath = join(root, 'package.json');
38
- const def = JSON.parse(readFileSync(packagePath, 'utf8'));
39
- const metaOverride = existsSync(metaPath) ? JSON.parse(readFileSync(metaPath, 'utf8')) : undefined;
38
+ const def = jju.parse(readFileSync(packagePath, 'utf8'));
39
+ const metaOverride = existsSync(metaPath) ? jju.parse(readFileSync(metaPath, 'utf8')) : undefined;
40
40
  const file = bundler.bundle.name.replace(/^[\/\\]/, '');
41
41
  const target = join(bundler.bundle.dir, file);
42
42
  const url = new URL(file, basePath);
package/src/messages.ts CHANGED
@@ -1846,7 +1846,7 @@ export function packageJsonMissing_0075(): QuickMessage {
1846
1846
  * The TypeScript declaration generator will take all files as input to
1847
1847
  * gather all required information for constructing the API declaration.
1848
1848
  */
1849
- export function declarationCouldNotBeGenerated_0076(rootDir: string, error: Error): QuickMessage {
1849
+ export function declarationCouldNotBeGenerated_0076(rootDir: string, error: Error | string): QuickMessage {
1850
1850
  return [LogLevels.error, '0076', `Could not create the declaration in "${rootDir}". Error: ${error}`];
1851
1851
  }
1852
1852