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
@@ -8,11 +8,12 @@ import { checkAppShellCompatibility } from './compatibility';
8
8
  import { deepMerge } from './merge';
9
9
  import { applyTemplate } from './template';
10
10
  import { readImportmap } from './importmap';
11
- import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, makePiletExternals, makeExternals } from './npm';
12
11
  import { filesTar, filesOnceTar, declarationEntryExtensions, bundlerNames } from './constants';
13
12
  import { getHash, checkIsDirectory, matchFiles } from './io';
14
13
  import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
15
- import { Framework, FileInfo, PiletsInfo, TemplateFileLocation } from '../types';
14
+ import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
15
+ import { makePiletExternals, makeExternals, findPackageRoot } from './npm';
16
+ import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, PackageData } from '../types';
16
17
 
17
18
  function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
18
19
  if (bundler && bundler !== 'none') {
@@ -113,26 +114,13 @@ async function getMatchingFiles(
113
114
  }
114
115
 
115
116
  export function getPiralPath(root: string, name: string) {
116
- try {
117
- const path = require.resolve(`${name}/package.json`, {
118
- paths: [root],
119
- });
120
- return dirname(path);
121
- } catch (ex) {
122
- log('generalDebug_0003', `Could not resolve the Piral path of "${name}" in "${root}": ${ex}.`);
117
+ const path = findPackageRoot(name, root);
118
+
119
+ if (!path) {
123
120
  fail('invalidPiralReference_0043');
124
121
  }
125
- }
126
122
 
127
- export function findPackageRoot(pck: string, baseDir: string) {
128
- try {
129
- return require.resolve(`${pck}/package.json`, {
130
- paths: [baseDir],
131
- });
132
- } catch (ex) {
133
- log('generalDebug_0003', `Could not find the package root in "${baseDir}": ${ex}.`);
134
- return undefined;
135
- }
123
+ return dirname(path);
136
124
  }
137
125
 
138
126
  function findPackage(pck: string | Array<string>, baseDir: string) {
@@ -161,7 +149,7 @@ function findPackage(pck: string | Array<string>, baseDir: string) {
161
149
  return undefined;
162
150
  }
163
151
 
164
- export function readPiralPackage(root: string, name: string) {
152
+ export function readPiralPackage(root: string, name: string): Promise<PackageData> {
165
153
  log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
166
154
  const path = getPiralPath(root, name);
167
155
  return readJson(path, 'package.json');
@@ -196,7 +184,12 @@ export function getPiralPackage(
196
184
  },
197
185
  importmap: {
198
186
  imports: {},
199
- inherit: ['piral-base', framework !== 'piral-base' && 'piral-core'].filter(Boolean),
187
+ inherit: [
188
+ 'piral-base', // this we take in any case
189
+ framework !== 'piral-base' && 'piral-core', // this we take unless we selected piral-base, then obviously core is not invited to the party
190
+ framework === 'piral' && 'piral', // this we take only if we selected piral
191
+ framework === 'piral-native' && 'piral-native', // this we also only take if we selected piral-native
192
+ ].filter(Boolean),
200
193
  },
201
194
  pilets: getPiletsInfo({}),
202
195
  dependencies,
@@ -325,10 +318,19 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
325
318
  return typeof item === 'object';
326
319
  }
327
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
+
328
330
  export async function copyPiralFiles(
329
331
  root: string,
330
332
  name: string,
331
- piralInfo: any,
333
+ piralInfo: PackageData,
332
334
  forceOverwrite: ForceOverwrite,
333
335
  variables: Record<string, string>,
334
336
  originalFiles?: Array<FileInfo>,
@@ -348,7 +350,7 @@ export async function copyPiralFiles(
348
350
  await copyFiles(files, forceOverwrite, originalFiles, variables);
349
351
  }
350
352
 
351
- export function getPiletsInfo(piralInfo: any): PiletsInfo {
353
+ export function getPiletsInfo(piralInfo: Partial<PackageData>): PiletsInfo {
352
354
  const {
353
355
  files = [],
354
356
  scripts = {},
@@ -457,7 +459,7 @@ export async function retrieveExternals(root: string, packageInfo: any) {
457
459
  ...packageInfo.dependencies,
458
460
  };
459
461
  const deps = packageInfo.pilets?.externals;
460
- return makeExternals(allDeps, deps);
462
+ return makeExternals(root, allDeps, deps);
461
463
  }
462
464
 
463
465
  return sharedDependencies.map((m) => m.name);
@@ -476,9 +478,9 @@ export async function retrievePiletsInfo(entryFile: string) {
476
478
  fail('packageJsonMissing_0074');
477
479
  }
478
480
 
481
+ const root = dirname(packageJson);
479
482
  const packageInfo = require(packageJson);
480
483
  const info = getPiletsInfo(packageInfo);
481
- const root = dirname(packageJson);
482
484
  const externals = await retrieveExternals(root, packageInfo);
483
485
 
484
486
  return {
@@ -507,7 +509,7 @@ export async function patchPiletPackage(
507
509
  root: string,
508
510
  name: string,
509
511
  version: string,
510
- piralInfo: any,
512
+ piralInfo: PackageData,
511
513
  fromEmulator: boolean,
512
514
  newInfo?: { language: SourceLanguage; bundler: string },
513
515
  ) {
@@ -531,7 +533,7 @@ export async function patchPiletPackage(
531
533
  }
532
534
  : info.scripts;
533
535
  const peerModules = [];
534
- const allExternals = makePiletExternals(piralDependencies, externals, fromEmulator, piralInfo);
536
+ const allExternals = makePiletExternals(root, piralDependencies, externals, fromEmulator, piralInfo);
535
537
  const peerDependencies = {
536
538
  ...allExternals.reduce((deps, name) => {
537
539
  const valid = isValidDependency(name);
@@ -555,7 +557,7 @@ export async function patchPiletPackage(
555
557
  return deps;
556
558
  }, {}),
557
559
  ...allExternals.filter(isValidDependency).reduce((deps, name) => {
558
- const version = piralDependencies[name];
560
+ const version = piralDependencies[name] || tryFindPackageVersion(name);
559
561
 
560
562
  if (version || newInfo) {
561
563
  // set only if we have an explicit version or we are in the scaffolding case
@@ -592,7 +594,7 @@ export async function patchPiletPackage(
592
594
  /**
593
595
  * Returns true if its an emulator package, otherwise it has to be a "raw" app shell.
594
596
  */
595
- export function checkAppShellPackage(appPackage: any) {
597
+ export function checkAppShellPackage(appPackage: PackageData) {
596
598
  const { piralCLI = { generated: false, version: cliVersion } } = appPackage;
597
599
 
598
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 };
@@ -1,4 +1,4 @@
1
- import { keyOfForceOverwrite, keyOfPiletLanguage, valueOfForceOverwrite, valueOfPiletLanguage } from './helpers';
1
+ import { keyOfForceOverwrite, keyOfSourceLanguage, valueOfForceOverwrite, valueOfSourceLanguage } from './helpers';
2
2
  import { ForceOverwrite, SourceLanguage } from './common/enums';
3
3
 
4
4
  describe('Piral CLI Command Helpers Module', () => {
@@ -13,12 +13,12 @@ describe('Piral CLI Command Helpers Module', () => {
13
13
  });
14
14
 
15
15
  it('correct value of keyOfPiletLanguage results in same key', () => {
16
- const result = keyOfPiletLanguage(SourceLanguage.ts);
16
+ const result = keyOfSourceLanguage(SourceLanguage.ts);
17
17
  expect(result).toBe('ts');
18
18
  });
19
19
 
20
20
  it('incorrect value of keyOfPiletLanguage results in key for TS', () => {
21
- const result = keyOfPiletLanguage(5);
21
+ const result = keyOfSourceLanguage(5);
22
22
  expect(result).toBe('ts');
23
23
  });
24
24
 
@@ -33,12 +33,12 @@ describe('Piral CLI Command Helpers Module', () => {
33
33
  });
34
34
 
35
35
  it('correct key of valueOfPiletLanguage results in same value', () => {
36
- const result = valueOfPiletLanguage('ts');
36
+ const result = valueOfSourceLanguage('ts');
37
37
  expect(result).toBe(SourceLanguage.ts);
38
38
  });
39
39
 
40
40
  it('incorrect key of valueOfPiletLanguage results in value for TS', () => {
41
- const result = valueOfPiletLanguage('foo');
41
+ const result = valueOfSourceLanguage('foo');
42
42
  expect(result).toBe(SourceLanguage.ts);
43
43
  });
44
44
  });
package/src/helpers.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ForceOverwrite, SourceLanguage } from './common/enums';
2
2
  import { bundlerNames, frameworkLibs } from './common/constants';
3
- import {
3
+ import type {
4
4
  Framework,
5
5
  NpmClientType,
6
6
  PiletSchemaVersion,
@@ -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> = [];
@@ -42,10 +42,10 @@ export function keyOfForceOverwrite(value: ForceOverwrite) {
42
42
  return forceOverwriteKeys[0];
43
43
  }
44
44
 
45
- export const piletLanguageKeys = Object.keys(SourceLanguage).filter((m) => typeof SourceLanguage[m] === 'number');
45
+ export const sourceLanguageKeys = Object.keys(SourceLanguage).filter((m) => typeof SourceLanguage[m] === 'number');
46
46
 
47
- export function valueOfPiletLanguage(key: string): SourceLanguage {
48
- for (const piletLanguageKey of piletLanguageKeys) {
47
+ export function valueOfSourceLanguage(key: string): SourceLanguage {
48
+ for (const piletLanguageKey of sourceLanguageKeys) {
49
49
  if (piletLanguageKey === key) {
50
50
  return SourceLanguage[piletLanguageKey];
51
51
  }
@@ -54,12 +54,12 @@ export function valueOfPiletLanguage(key: string): SourceLanguage {
54
54
  return SourceLanguage.ts;
55
55
  }
56
56
 
57
- export function keyOfPiletLanguage(value: SourceLanguage) {
58
- for (const piletLanguageKey of piletLanguageKeys) {
57
+ export function keyOfSourceLanguage(value: SourceLanguage) {
58
+ for (const piletLanguageKey of sourceLanguageKeys) {
59
59
  if (SourceLanguage[piletLanguageKey] === value) {
60
60
  return piletLanguageKey;
61
61
  }
62
62
  }
63
63
 
64
- return piletLanguageKeys[0];
64
+ return sourceLanguageKeys[0];
65
65
  }
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { KrasRequest } from 'kras';
3
- import PiletInjector from './pilet';
3
+ import PiletInjector from './pilet-injector';
4
4
 
5
5
  const optionsMock = {
6
6
  pilets: [],
@@ -9,6 +9,9 @@ const optionsMock = {
9
9
  api: '',
10
10
  app: '',
11
11
  active: true,
12
+ publicUrl: '/',
13
+ meta: '',
14
+ headers: {},
12
15
  };
13
16
 
14
17
  const configMock: any = {
@@ -89,6 +92,9 @@ describe('Piral-CLI piral injector', () => {
89
92
  publicUrl: '/',
90
93
  api: 'http://someFakeApi:1234',
91
94
  app: '',
95
+ publicUrl: '/',
96
+ meta: '',
97
+ headers: {},
92
98
  active: true,
93
99
  };
94
100
 
@@ -118,6 +124,9 @@ describe('Piral-CLI piral injector', () => {
118
124
  publicUrl: '/',
119
125
  api: 'http://someFakeApi:1234',
120
126
  app: '',
127
+ publicUrl: '/',
128
+ meta: '',
129
+ headers: {},
121
130
  active: true,
122
131
  };
123
132
  const core = new EventEmitter();
@@ -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;
@@ -24,6 +24,7 @@ export interface PiletInjectorConfig extends KrasInjectorConfig {
24
24
  api: string;
25
25
  app: string;
26
26
  feed?: string;
27
+ headers: Record<string, string>;
27
28
  }
28
29
 
29
30
  interface PiletMetadata {
@@ -35,8 +36,8 @@ function fillPiletMeta(pilet: Pilet, basePath: string, metaFile: string) {
35
36
  const { root, bundler } = pilet;
36
37
  const metaPath = join(root, metaFile);
37
38
  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;
39
+ const def = jju.parse(readFileSync(packagePath, 'utf8'));
40
+ const metaOverride = existsSync(metaPath) ? jju.parse(readFileSync(metaPath, 'utf8')) : undefined;
40
41
  const file = bundler.bundle.name.replace(/^[\/\\]/, '');
41
42
  const target = join(bundler.bundle.dir, file);
42
43
  const url = new URL(file, basePath);
@@ -79,40 +80,44 @@ export default class PiletInjector implements KrasInjector {
79
80
 
80
81
  constructor(options: PiletInjectorConfig, config: KrasConfiguration, core: EventEmitter) {
81
82
  this.config = options;
82
- // either take a full URI or make it an absolute path relative to the current origin
83
- this.piletApi = /^https?:/.test(options.api)
84
- ? options.api
85
- : `${config.ssl ? 'https' : 'http'}://${host}:${config.port}${options.api}`;
86
-
87
- const { pilets, api, publicUrl } = options;
88
- this.indexPath = `${publicUrl}index.html`;
89
- const cbs = {};
90
-
91
- core.on('user-connected', (e) => {
92
- if (e.target === '*' && e.url === api.substring(1)) {
93
- cbs[e.id] = (msg: string) => e.ws.send(msg);
94
- }
95
- });
96
83
 
97
- core.on('user-disconnected', (e) => {
98
- delete cbs[e.id];
99
- });
84
+ if (this.config.active) {
85
+ // either take a full URI or make it an absolute path relative to the current origin
86
+ this.piletApi = /^https?:/.test(options.api)
87
+ ? options.api
88
+ : `${config.ssl ? 'https' : 'http'}://${host}:${config.port}${options.api}`;
100
89
 
101
- pilets.forEach((p, i) =>
102
- p.bundler.on(() => {
103
- const basePath = `${this.piletApi}/${i}/`;
104
- const meta = fillPiletMeta(p, basePath, options.meta);
90
+ const { pilets, api, publicUrl } = options;
91
+ this.indexPath = `${publicUrl}index.html`;
92
+ const cbs = {};
105
93
 
106
- for (const id of Object.keys(cbs)) {
107
- cbs[id](meta);
94
+ core.on('user-connected', (e) => {
95
+ if (e.target === '*' && e.url === api.substring(1)) {
96
+ cbs[e.id] = (msg: string) => e.ws.send(msg);
108
97
  }
109
- }),
110
- );
98
+ });
99
+
100
+ core.on('user-disconnected', (e) => {
101
+ delete cbs[e.id];
102
+ });
103
+
104
+ pilets.forEach((p, i) =>
105
+ p.bundler.on(() => {
106
+ const basePath = `${this.piletApi}/${i}/`;
107
+ const meta = fillPiletMeta(p, basePath, options.meta);
108
+
109
+ for (const id of Object.keys(cbs)) {
110
+ cbs[id](meta);
111
+ }
112
+ }),
113
+ );
114
+ }
111
115
  }
112
116
 
113
117
  get active() {
114
118
  return this.config.active;
115
119
  }
120
+
116
121
  set active(value) {
117
122
  this.config.active = value;
118
123
  }
@@ -159,9 +164,12 @@ export default class PiletInjector implements KrasInjector {
159
164
  }
160
165
 
161
166
  sendContent(content: Buffer | string, type: string, url: string): KrasResponse {
167
+ const { headers } = this.config;
168
+
162
169
  return {
163
170
  injector: { name: this.name },
164
171
  headers: {
172
+ ...headers,
165
173
  'content-type': type,
166
174
  'cache-control': 'no-cache, no-store, must-revalidate',
167
175
  pragma: 'no-cache',
@@ -1,4 +1,4 @@
1
- import PiralInjector from './piral';
1
+ import PiralInjector from './piral-injector';
2
2
  import { KrasRequest, KrasResult } from 'kras';
3
3
  import { EventEmitter } from 'events';
4
4
 
@@ -37,6 +37,7 @@ describe('Piral-CLI piral injector', () => {
37
37
  bundler,
38
38
  publicUrl: '/',
39
39
  active: true,
40
+ headers: {},
40
41
  };
41
42
  const injector = new PiralInjector(config, undefined, new EventEmitter());
42
43
  expect(injector.active).toBeTruthy();
@@ -48,6 +49,7 @@ describe('Piral-CLI piral injector', () => {
48
49
  bundler: bundlerMock,
49
50
  publicUrl: '/',
50
51
  active: true,
52
+ headers: {},
51
53
  };
52
54
  const injector = new PiralInjector(config, undefined, new EventEmitter());
53
55
 
@@ -67,6 +69,7 @@ describe('Piral-CLI piral injector', () => {
67
69
  bundler: bundlerMock,
68
70
  publicUrl: '/',
69
71
  active: true,
72
+ headers: {},
70
73
  };
71
74
  const injector = new PiralInjector(config, undefined, new EventEmitter());
72
75
 
@@ -83,6 +86,7 @@ describe('Piral-CLI piral injector', () => {
83
86
  bundler: bundlerMock,
84
87
  publicUrl: '/',
85
88
  active: true,
89
+ headers: {},
86
90
  };
87
91
  const injector = new PiralInjector(config, undefined, new EventEmitter());
88
92
  const request: KrasRequest = {
@@ -14,6 +14,7 @@ export interface PiralInjectorConfig extends KrasInjectorConfig {
14
14
  bundler: Bundler;
15
15
  publicUrl: string;
16
16
  feed?: string;
17
+ headers: Record<string, string>;
17
18
  }
18
19
 
19
20
  export default class PiralInjector implements KrasInjector {
@@ -21,29 +22,33 @@ export default class PiralInjector implements KrasInjector {
21
22
 
22
23
  constructor(options: PiralInjectorConfig, _config: KrasConfiguration, core: EventEmitter) {
23
24
  this.config = options;
24
- const api = '/$events';
25
- const cbs = {};
26
25
 
27
- core.on('user-connected', (e) => {
28
- if (e.target === '*' && e.url === api.substring(1)) {
29
- cbs[e.id] = (msg: string) => e.ws.send(msg);
30
- }
31
- });
32
-
33
- core.on('user-disconnected', (e) => {
34
- delete cbs[e.id];
35
- });
36
-
37
- this.config.bundler.on((args) => {
38
- for (const id of Object.keys(cbs)) {
39
- cbs[id](JSON.stringify(args));
40
- }
41
- });
26
+ if (this.config.active) {
27
+ const api = '/$events';
28
+ const cbs = {};
29
+
30
+ core.on('user-connected', (e) => {
31
+ if (e.target === '*' && e.url === api.substring(1)) {
32
+ cbs[e.id] = (msg: string) => e.ws.send(msg);
33
+ }
34
+ });
35
+
36
+ core.on('user-disconnected', (e) => {
37
+ delete cbs[e.id];
38
+ });
39
+
40
+ this.config.bundler.on((args) => {
41
+ for (const id of Object.keys(cbs)) {
42
+ cbs[id](JSON.stringify(args));
43
+ }
44
+ });
45
+ }
42
46
  }
43
47
 
44
48
  get active() {
45
49
  return this.config.active;
46
50
  }
51
+
47
52
  set active(value) {
48
53
  this.config.active = value;
49
54
  }
@@ -59,9 +64,11 @@ export default class PiralInjector implements KrasInjector {
59
64
  setOptions() {}
60
65
 
61
66
  sendContent(content: Buffer | string, type: string, url: string): KrasResponse {
67
+ const { headers } = this.config;
62
68
  return {
63
69
  injector: { name: this.name },
64
70
  headers: {
71
+ ...headers,
65
72
  'content-type': type,
66
73
  'cache-control': 'no-cache, no-store, must-revalidate',
67
74
  pragma: 'no-cache',
package/src/messages.ts CHANGED
@@ -549,7 +549,11 @@ export function importMapVersionSpecInvalid_0026(depName: string): QuickMessage
549
549
  * node modules are most likely not installed (correctly).
550
550
  */
551
551
  export function importMapReferenceNotFound_0027(dir: string, reference: string): QuickMessage {
552
- return [LogLevels.error, '0027', `The reference to "${reference}" could not be resolved from "${dir}". Are you sure the file or package exists?`];
552
+ return [
553
+ LogLevels.error,
554
+ '0027',
555
+ `The reference to "${reference}" could not be resolved from "${dir}". Are you sure the file or package exists?`,
556
+ ];
553
557
  }
554
558
 
555
559
  /**
@@ -1842,7 +1846,7 @@ export function packageJsonMissing_0075(): QuickMessage {
1842
1846
  * The TypeScript declaration generator will take all files as input to
1843
1847
  * gather all required information for constructing the API declaration.
1844
1848
  */
1845
- export function declarationCouldNotBeGenerated_0076(rootDir: string, error: Error): QuickMessage {
1849
+ export function declarationCouldNotBeGenerated_0076(rootDir: string, error: Error | string): QuickMessage {
1846
1850
  return [LogLevels.error, '0076', `Could not create the declaration in "${rootDir}". Error: ${error}`];
1847
1851
  }
1848
1852
 
package/src/plugin.ts CHANGED
@@ -1,10 +1,39 @@
1
1
  import { readdir, stat } from 'fs';
2
- import { join, resolve } from 'path';
3
- import { log } from './common';
2
+ import { join, resolve, sep, posix } from 'path';
3
+ import { cliName, cliVersion, log } from './common';
4
4
  import { inject } from './inject';
5
5
 
6
- function getLocalPackageDir() {
7
- return resolve(__dirname, '..', '..');
6
+ function getContainerDir() {
7
+ const currentDir = __dirname.split(sep).join(posix.sep);
8
+
9
+ if (!currentDir.includes(`/.pnpm/${cliName}@${cliVersion}/node_modules/${cliName}/`)) {
10
+ return resolve(__dirname, '..', '..');
11
+ }
12
+
13
+ return undefined;
14
+ }
15
+
16
+ async function getLocalPackageDir() {
17
+ const proposedDirs = [
18
+ getContainerDir(),
19
+ resolve(process.cwd(), 'node_modules'),
20
+ resolve(process.cwd(), '..', 'node_modules'),
21
+ resolve(process.cwd(), '..', '..', 'node_modules'),
22
+ resolve(process.cwd(), '..', '..', '..', 'node_modules'),
23
+ ];
24
+
25
+ // Right now we always take the first one, but in the future this may be different
26
+ // once we come up with more / better criteria to identify if its a good/valid
27
+ // plugin root directory
28
+ for (const dir of proposedDirs.filter(Boolean)) {
29
+ log('generalDebug_0003', `Checking for potential plugin directory "${dir}" ...`);
30
+
31
+ if (await isDirectory(dir)) {
32
+ return dir;
33
+ }
34
+ }
35
+
36
+ return undefined;
8
37
  }
9
38
 
10
39
  function isDirectory(dir: string) {
@@ -83,7 +112,7 @@ async function getAllPlugins(rootDir: string): Promise<Array<string>> {
83
112
  }
84
113
 
85
114
  export async function loadPlugins() {
86
- const localDir = getLocalPackageDir();
115
+ const localDir = await getLocalPackageDir();
87
116
  const allPlugins = await getAllPlugins(localDir);
88
117
 
89
118
  for (const pluginPath of allPlugins) {
package/src/release.ts CHANGED
@@ -21,6 +21,9 @@ const providers: Record<string, ReleaseProvider> = {
21
21
 
22
22
  await Promise.all(files.map(async (file) => copy(file, resolve(target, basename(file)))));
23
23
  },
24
+ async feed(files, args, interactive) {
25
+ //TODO post files to Piral Feed Service
26
+ },
24
27
  };
25
28
 
26
29
  function findReleaseProvider(providerName: string) {
@@ -43,7 +46,12 @@ export function setReleaseProvider(provider: QualifiedReleaseProvider) {
43
46
  }
44
47
  }
45
48
 
46
- export function publishArtifacts(providerName: string, files: Array<string>, args: Record<string, string>) {
49
+ export function publishArtifacts(
50
+ providerName: string,
51
+ files: Array<string>,
52
+ args: Record<string, string>,
53
+ interactive: boolean,
54
+ ) {
47
55
  const runRelease = findReleaseProvider(providerName);
48
- return runRelease(files, args);
56
+ return runRelease(files, args, interactive);
49
57
  }
@@ -42,7 +42,7 @@ export interface Bundler {
42
42
  }
43
43
 
44
44
  export interface ReleaseProvider {
45
- (files: Array<string>, args: Record<string, string>): Promise<void>;
45
+ (files: Array<string>, args: Record<string, string>, interactive: boolean): Promise<void>;
46
46
  }
47
47
 
48
48
  export interface TemplateFileLocation {