piral-cli 0.15.0-beta.4816 → 0.15.0-beta.4828

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 (60) hide show
  1. package/lib/apps/build-pilet.js +1 -1
  2. package/lib/apps/build-pilet.js.map +1 -1
  3. package/lib/apps/build-piral.js +2 -2
  4. package/lib/apps/build-piral.js.map +1 -1
  5. package/lib/apps/debug-pilet.js +1 -1
  6. package/lib/apps/debug-pilet.js.map +1 -1
  7. package/lib/apps/debug-piral.js +1 -3
  8. package/lib/apps/debug-piral.js.map +1 -1
  9. package/lib/apps/validate-piral.js +2 -1
  10. package/lib/apps/validate-piral.js.map +1 -1
  11. package/lib/common/clients/pnpm.js +1 -1
  12. package/lib/common/clients/pnpm.js.map +1 -1
  13. package/lib/common/compatibility.js +2 -1
  14. package/lib/common/compatibility.js.map +1 -1
  15. package/lib/common/declaration.js +20 -6
  16. package/lib/common/declaration.js.map +1 -1
  17. package/lib/common/emulator.d.ts +2 -2
  18. package/lib/common/emulator.js +5 -3
  19. package/lib/common/emulator.js.map +1 -1
  20. package/lib/common/importmap.js +27 -15
  21. package/lib/common/importmap.js.map +1 -1
  22. package/lib/common/io.d.ts +1 -1
  23. package/lib/common/io.js +11 -8
  24. package/lib/common/io.js.map +1 -1
  25. package/lib/common/language.d.ts +4 -0
  26. package/lib/common/language.js +6 -2
  27. package/lib/common/language.js.map +1 -1
  28. package/lib/common/npm.d.ts +2 -2
  29. package/lib/common/npm.js +4 -31
  30. package/lib/common/npm.js.map +1 -1
  31. package/lib/common/package.d.ts +7 -5
  32. package/lib/common/package.js +44 -22
  33. package/lib/common/package.js.map +1 -1
  34. package/lib/messages.d.ts +1 -1
  35. package/lib/messages.js +12 -8
  36. package/lib/messages.js.map +1 -1
  37. package/lib/rules/pilet-has-externals-as-peers.js +4 -4
  38. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  39. package/lib/rules/piral-has-valid-externals.js +1 -1
  40. package/lib/rules/piral-has-valid-externals.js.map +1 -1
  41. package/lib/types/common.d.ts +1 -1
  42. package/package.json +3 -3
  43. package/src/apps/build-pilet.ts +1 -1
  44. package/src/apps/build-piral.ts +2 -2
  45. package/src/apps/debug-pilet.ts +1 -1
  46. package/src/apps/debug-piral.ts +1 -1
  47. package/src/apps/validate-piral.ts +2 -1
  48. package/src/common/clients/pnpm.ts +1 -1
  49. package/src/common/compatibility.ts +2 -1
  50. package/src/common/declaration.ts +23 -6
  51. package/src/common/emulator.ts +8 -6
  52. package/src/common/importmap.ts +33 -19
  53. package/src/common/io.ts +18 -10
  54. package/src/common/language.ts +9 -1
  55. package/src/common/npm.ts +5 -34
  56. package/src/common/package.ts +57 -22
  57. package/src/messages.ts +12 -8
  58. package/src/rules/pilet-has-externals-as-peers.ts +4 -4
  59. package/src/rules/piral-has-valid-externals.ts +1 -1
  60. package/src/types/common.ts +1 -1
@@ -2,15 +2,22 @@ import { resolve, join, extname, basename, dirname, relative } from 'path';
2
2
  import { log, fail } from './log';
3
3
  import { cliVersion } from './info';
4
4
  import { unpackTarball } from './archive';
5
- import { getDependencies, getDependencyPackages, getDevDependencies, getDevDependencyPackages } from './language';
6
5
  import { ForceOverwrite } from './enums';
7
6
  import { checkAppShellCompatibility } from './compatibility';
8
7
  import { deepMerge } from './merge';
9
8
  import { readImportmap } from './importmap';
10
9
  import { getHash, checkIsDirectory, matchFiles } from './io';
11
10
  import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
12
- import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
11
+ import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, tryResolvePackage } from './npm';
13
12
  import { makePiletExternals, makeExternals, findPackageRoot, findSpecificVersion } from './npm';
13
+ import { getModulePath } from '../external';
14
+ import {
15
+ getDependencies,
16
+ getDependencyPackages,
17
+ getDevDependencies,
18
+ getDevDependencyPackages,
19
+ getFrameworkDependencies,
20
+ } from './language';
14
21
  import {
15
22
  filesTar,
16
23
  filesOnceTar,
@@ -18,8 +25,8 @@ import {
18
25
  bundlerNames,
19
26
  piralJsonSchemaUrl,
20
27
  piletJsonSchemaUrl,
28
+ frameworkLibs,
21
29
  } from './constants';
22
- import { getModulePath } from '../external';
23
30
  import {
24
31
  SourceLanguage,
25
32
  Framework,
@@ -235,6 +242,7 @@ export async function getPiralPackage(app: string, data: PiralInstanceData, vers
235
242
  'piral-cli': `${version}`,
236
243
  };
237
244
  const dependencies = {
245
+ ...getFrameworkDependencies(framework, version),
238
246
  ...getDependencies(data.language, getDependencyPackages(framework, data.reactVersion, data.reactRouterVersion)),
239
247
  };
240
248
 
@@ -481,9 +489,11 @@ export function findDependencyVersion(
481
489
  pckg: Record<string, any>,
482
490
  rootPath: string,
483
491
  packageName: string,
492
+ parents: Array<string> = [],
484
493
  ): Promise<string> {
485
494
  const { devDependencies = {}, dependencies = {} } = pckg;
486
495
  const desiredVersion = dependencies[packageName] ?? devDependencies[packageName];
496
+ const [parent] = parents;
487
497
 
488
498
  if (desiredVersion) {
489
499
  if (isGitPackage(desiredVersion)) {
@@ -493,22 +503,36 @@ export function findDependencyVersion(
493
503
  }
494
504
  }
495
505
 
506
+ if (parent) {
507
+ // in case the dependency came from another package (= parent)
508
+ // we should start the lookup in its directory (pnpm issue)
509
+ const parentPath = tryResolvePackage(parent, rootPath);
510
+
511
+ if (parentPath) {
512
+ rootPath = dirname(parentPath);
513
+ }
514
+ }
515
+
496
516
  return findPackageVersion(rootPath, packageName);
497
517
  }
498
518
 
499
- export async function findPackageVersion(rootPath: string, packageName: string): Promise<string> {
500
- try {
501
- log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
502
- const moduleName = getModulePath(rootPath, packageName);
503
- const packageJson = await findFile(moduleName, 'package.json');
504
- return require(packageJson).version;
505
- } catch (e) {
506
- log('cannotResolveDependency_0053', packageName, rootPath);
507
- return 'latest';
519
+ export async function findPackageVersion(rootPath: string, packageName: string | Array<string>): Promise<string> {
520
+ const packages = Array.isArray(packageName) ? packageName : [packageName];
521
+
522
+ for (const pckg of packages) {
523
+ try {
524
+ log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
525
+ const moduleName = getModulePath(rootPath, pckg);
526
+ const packageJson = await findFile(moduleName, 'package.json');
527
+ return require(packageJson).version;
528
+ } catch {}
508
529
  }
530
+
531
+ log('cannotResolveDependency_0053', packages, rootPath);
532
+ return 'latest';
509
533
  }
510
534
 
511
- export async function retrieveExternals(root: string, packageInfo: any) {
535
+ export async function retrieveExternals(root: string, packageInfo: any): Promise<Array<SharedDependency>> {
512
536
  const sharedDependencies = await readImportmap(root, packageInfo);
513
537
 
514
538
  if (sharedDependencies.length === 0) {
@@ -517,10 +541,18 @@ export async function retrieveExternals(root: string, packageInfo: any) {
517
541
  ...packageInfo.dependencies,
518
542
  };
519
543
  const deps = packageInfo.pilets?.externals;
520
- return makeExternals(root, allDeps, deps);
544
+ const externals = makeExternals(root, allDeps, deps);
545
+ return externals.map((ext) => ({
546
+ id: ext,
547
+ name: ext,
548
+ entry: ext,
549
+ type: 'local',
550
+ ref: undefined,
551
+ requireId: ext,
552
+ }));
521
553
  }
522
554
 
523
- return sharedDependencies.map((m) => m.name);
555
+ return sharedDependencies;
524
556
  }
525
557
 
526
558
  export async function retrievePiletsInfo(entryFile: string) {
@@ -540,17 +572,20 @@ export async function retrievePiletsInfo(entryFile: string) {
540
572
  const packageInfo = require(packageJson);
541
573
  const info = getPiletsInfo(packageInfo);
542
574
  const externals = await retrieveExternals(root, packageInfo);
575
+ const dependencies = {
576
+ std: packageInfo.dependencies || {},
577
+ dev: packageInfo.devDependencies || {},
578
+ peer: packageInfo.peerDependencies || {},
579
+ };
580
+ const framework = frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
543
581
 
544
582
  return {
545
583
  ...info,
546
584
  externals,
547
585
  name: packageInfo.name,
548
586
  version: packageInfo.version,
549
- dependencies: {
550
- std: packageInfo.dependencies || {},
551
- dev: packageInfo.devDependencies || {},
552
- peer: packageInfo.peerDependencies || {},
553
- },
587
+ framework,
588
+ dependencies,
554
589
  scripts: packageInfo.scripts,
555
590
  ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
556
591
  root,
@@ -595,7 +630,7 @@ async function getPiletPackage(
595
630
  newInfo?: { language: SourceLanguage; bundler: string },
596
631
  ) {
597
632
  const { piralCLI = { version: cliVersion } } = piralInfo;
598
- const { externals, packageOverrides, ...info } = getPiletsInfo(piralInfo);
633
+ const { packageOverrides, ...info } = getPiletsInfo(piralInfo);
599
634
  const piralDependencies = {
600
635
  ...piralInfo.devDependencies,
601
636
  ...piralInfo.dependencies,
@@ -610,7 +645,7 @@ async function getPiletPackage(
610
645
  ...info.scripts,
611
646
  }
612
647
  : info.scripts;
613
- const allExternals = makePiletExternals(root, piralDependencies, externals, fromEmulator, piralInfo);
648
+ const allExternals = makePiletExternals(root, piralDependencies, fromEmulator, piralInfo);
614
649
  const devDependencies: Record<string, string> = {
615
650
  ...Object.keys(typeDependencies).reduce((deps, name) => {
616
651
  deps[name] = piralDependencies[name] || typeDependencies[name];
package/src/messages.ts CHANGED
@@ -1231,8 +1231,12 @@ export function cannotResolveVersion_0052(name: string): QuickMessage {
1231
1231
  * }
1232
1232
  * ```
1233
1233
  */
1234
- export function cannotResolveDependency_0053(name: string, rootDir: string): QuickMessage {
1235
- return [LogLevels.warning, '0053', `Could not resolve "${name}" from "${rootDir}". Taking "latest" version.`];
1234
+ export function cannotResolveDependency_0053(names: Array<string>, rootDir: string): QuickMessage {
1235
+ return [
1236
+ LogLevels.warning,
1237
+ '0053',
1238
+ `Could not resolve any package (tried "${names.join('", "')}") from "${rootDir}". Taking "latest" version.`,
1239
+ ];
1236
1240
  }
1237
1241
 
1238
1242
  /**
@@ -2387,7 +2391,11 @@ export function publishFeedMissingUrl_0115(): QuickMessage {
2387
2391
  * ```
2388
2392
  */
2389
2393
  export function publishFeedMissingVersion_0116(): QuickMessage {
2390
- return [LogLevels.error, '0116', `The "feed" provider requires either a "--opts.version" argument or a package.json with a version.`];
2394
+ return [
2395
+ LogLevels.error,
2396
+ '0116',
2397
+ `The "feed" provider requires either a "--opts.version" argument or a package.json with a version.`,
2398
+ ];
2391
2399
  }
2392
2400
 
2393
2401
  /**
@@ -2624,11 +2632,7 @@ export function bundlerUnspecified_0175(available: Array<string>): QuickMessage
2624
2632
  * ```
2625
2633
  */
2626
2634
  export function bundlerNotInstalled_0176(): QuickMessage {
2627
- return [
2628
- LogLevels.warning,
2629
- '0176',
2630
- `Installing default bundler since no bundler has been found.`,
2631
- ];
2635
+ return [LogLevels.warning, '0176', `Installing default bundler since no bundler has been found.`];
2632
2636
  }
2633
2637
 
2634
2638
  /**
@@ -26,10 +26,10 @@ export default async function (context: PiletRuleContext, options: Options = 'ig
26
26
  const markedPeerDependencies = Object.keys(context.peerDependencies);
27
27
  const markedPeerModules = context.peerModules;
28
28
  const missingExternals = externals
29
- .map((name) => {
30
- const valid = isValidDependency(name);
31
- const missing = !(valid ? markedPeerDependencies : markedPeerModules).includes(name);
32
- return { name, valid, missing };
29
+ .map((external) => {
30
+ const valid = isValidDependency(external.name);
31
+ const missing = !(valid ? markedPeerDependencies : markedPeerModules).includes(external.name);
32
+ return { name: external.name, valid, missing };
33
33
  })
34
34
  .filter((m) => m.missing);
35
35
 
@@ -6,7 +6,7 @@ export type Options = void;
6
6
  * Checks that the externals to be used in pilets are valid.
7
7
  */
8
8
  export default function (context: PiralRuleContext, options: Options = undefined) {
9
- const { externals } = context.info;
9
+ const { externals } = context;
10
10
 
11
11
  if (!Array.isArray(externals)) {
12
12
  context.error(
@@ -104,7 +104,6 @@ export interface TemplateFileLocation {
104
104
  export interface PiletsInfo {
105
105
  files: Array<string | TemplateFileLocation>;
106
106
  template: string;
107
- externals?: Array<string>;
108
107
  devDependencies: Record<string, string | true>;
109
108
  scripts: Record<string, string>;
110
109
  validators: Record<string, any>;
@@ -147,6 +146,7 @@ export interface Rule<T extends RuleContext> {
147
146
 
148
147
  export interface PiralRuleContext extends RuleContext {
149
148
  info: PiletsInfo;
149
+ externals: Array<SharedDependency>;
150
150
  }
151
151
 
152
152
  export interface PiletRuleContext extends RuleContext {