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

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 (72) hide show
  1. package/lib/apps/build-pilet.d.ts +4 -0
  2. package/lib/apps/build-pilet.js +7 -5
  3. package/lib/apps/build-pilet.js.map +1 -1
  4. package/lib/apps/build-piral.js.map +1 -1
  5. package/lib/apps/debug-pilet.d.ts +5 -0
  6. package/lib/apps/debug-pilet.js +10 -7
  7. package/lib/apps/debug-pilet.js.map +1 -1
  8. package/lib/apps/debug-piral.js.map +1 -1
  9. package/lib/apps/index.js +5 -1
  10. package/lib/apps/index.js.map +1 -1
  11. package/lib/apps/new-pilet.js +4 -3
  12. package/lib/apps/new-pilet.js.map +1 -1
  13. package/lib/build/bundler-calls.d.ts +1 -1
  14. package/lib/build/run-build-pilet.js.map +1 -1
  15. package/lib/build/run-build-piral.js.map +1 -1
  16. package/lib/build/run-debug-mono-piral.js +5 -5
  17. package/lib/build/run-debug-mono-piral.js.map +1 -1
  18. package/lib/build/run-debug-pilet.js.map +1 -1
  19. package/lib/build/run-debug-piral.js.map +1 -1
  20. package/lib/commands.js +8 -0
  21. package/lib/commands.js.map +1 -1
  22. package/lib/common/clients/npm.js +10 -4
  23. package/lib/common/clients/npm.js.map +1 -1
  24. package/lib/common/clients/pnpm.js +10 -4
  25. package/lib/common/clients/pnpm.js.map +1 -1
  26. package/lib/common/clients/yarn.js +10 -4
  27. package/lib/common/clients/yarn.js.map +1 -1
  28. package/lib/common/config.js.map +1 -1
  29. package/lib/common/importmap.js +23 -3
  30. package/lib/common/importmap.js.map +1 -1
  31. package/lib/common/index.js +5 -1
  32. package/lib/common/index.js.map +1 -1
  33. package/lib/common/package.d.ts +7 -0
  34. package/lib/common/package.js +30 -9
  35. package/lib/common/package.js.map +1 -1
  36. package/lib/common/scaffold.js.map +1 -1
  37. package/lib/external/index.js +482 -462
  38. package/lib/index.js +5 -1
  39. package/lib/index.js.map +1 -1
  40. package/lib/injectors/pilet.d.ts +2 -0
  41. package/lib/injectors/pilet.js +18 -14
  42. package/lib/injectors/pilet.js.map +1 -1
  43. package/lib/rules/pilet-has-externals-as-peers.js +1 -1
  44. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  45. package/lib/types/common.d.ts +3 -1
  46. package/lib/types/index.js +5 -1
  47. package/lib/types/index.js.map +1 -1
  48. package/lib/types/public.d.ts +1 -0
  49. package/package.json +2 -2
  50. package/src/apps/build-pilet.ts +14 -5
  51. package/src/apps/debug-pilet.ts +18 -5
  52. package/src/apps/new-pilet.ts +4 -3
  53. package/src/build/bundler-calls.ts +1 -1
  54. package/src/build/run-build-pilet.ts +1 -1
  55. package/src/build/run-build-piral.ts +1 -1
  56. package/src/build/run-debug-mono-piral.ts +6 -4
  57. package/src/build/run-debug-pilet.ts +1 -1
  58. package/src/build/run-debug-piral.ts +1 -1
  59. package/src/commands.ts +8 -0
  60. package/src/common/clients/npm.ts +12 -4
  61. package/src/common/clients/pnpm.ts +12 -4
  62. package/src/common/clients/yarn.ts +12 -4
  63. package/src/common/config.ts +3 -3
  64. package/src/common/importmap.ts +29 -3
  65. package/src/common/package.test.ts +2 -2
  66. package/src/common/package.ts +31 -11
  67. package/src/common/scaffold.ts +1 -0
  68. package/src/injectors/pilet.test.ts +6 -0
  69. package/src/injectors/pilet.ts +22 -15
  70. package/src/rules/pilet-has-externals-as-peers.ts +2 -2
  71. package/src/types/common.ts +3 -1
  72. package/src/types/public.ts +1 -0
@@ -7,8 +7,11 @@ import { SharedDependency } from '../types';
7
7
 
8
8
  interface Importmap {
9
9
  imports: Record<string, string>;
10
+ inherit: Array<string>;
10
11
  }
11
12
 
13
+ const shorthandsUrls = ['', '.', '...'];
14
+
12
15
  function tryResolve(baseDir: string, name: string) {
13
16
  try {
14
17
  return require.resolve(name, {
@@ -53,6 +56,7 @@ function getLocalDependencyVersion(
53
56
  async function resolveImportmap(dir: string, importmap: Importmap) {
54
57
  const dependencies: Array<SharedDependency> = [];
55
58
  const sharedImports = importmap?.imports;
59
+ const inheritedImports = importmap?.inherit;
56
60
 
57
61
  if (typeof sharedImports === 'object' && sharedImports) {
58
62
  for (const depName of Object.keys(sharedImports)) {
@@ -72,7 +76,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
72
76
  ref: url,
73
77
  type: 'remote',
74
78
  });
75
- } else if (url === identifier) {
79
+ } else if (url === identifier || shorthandsUrls.includes(url)) {
76
80
  const entry = tryResolve(dir, identifier);
77
81
 
78
82
  if (entry) {
@@ -88,7 +92,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
88
92
  type: 'local',
89
93
  });
90
94
  } else {
91
- fail('importMapReferenceNotFound_0027', dir, url);
95
+ fail('importMapReferenceNotFound_0027', dir, identifier);
92
96
  }
93
97
  } else {
94
98
  const entry = resolve(dir, url);
@@ -96,7 +100,9 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
96
100
 
97
101
  if (exists) {
98
102
  const isDirectory = await checkIsDirectory(entry);
99
- const packageJson = isDirectory ? resolve(entry, 'package.json') : await findFile(dirname(entry), 'package.json');
103
+ const packageJson = isDirectory
104
+ ? resolve(entry, 'package.json')
105
+ : await findFile(dirname(entry), 'package.json');
100
106
  const packageJsonExists = await checkExists(packageJson);
101
107
 
102
108
  if (packageJsonExists) {
@@ -131,6 +137,26 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
131
137
  }
132
138
  }
133
139
 
140
+ if (Array.isArray(inheritedImports)) {
141
+ for (const inheritedImport of inheritedImports) {
142
+ const packageJson = tryResolve(dir, `${inheritedImport}/package.json`);
143
+
144
+ if (packageJson) {
145
+ const packageDir = dirname(packageJson);
146
+ const packageDetails = require(packageJson);
147
+ const otherDependencies = await readImportmap(packageDir, packageDetails);
148
+
149
+ for (const dependency of otherDependencies) {
150
+ const entry = dependencies.find((dep) => dep.name === dependency.name);
151
+
152
+ if (!entry) {
153
+ dependencies.push(dependency);
154
+ }
155
+ }
156
+ }
157
+ }
158
+ }
159
+
134
160
  return dependencies;
135
161
  }
136
162
 
@@ -29,7 +29,7 @@ describe('CLI package module', () => {
29
29
  it('getPiletsInfo returns pilets information about provided piralInfo', () => {
30
30
  const emptyPiletsInfo = {
31
31
  files: [],
32
- externals: [],
32
+ template: 'default',
33
33
  scripts: {},
34
34
  validators: {},
35
35
  devDependencies: {},
@@ -45,7 +45,7 @@ describe('CLI package module', () => {
45
45
  const piralInfo = {
46
46
  pilets: {
47
47
  files: ['foo.tgz', 'foo2.tgz'],
48
- externals: [],
48
+ template: 'default',
49
49
  scripts: {},
50
50
  validators: {},
51
51
  devDependencies: {},
@@ -150,8 +150,10 @@ function findPackage(pck: string | Array<string>, baseDir: string) {
150
150
  if (path) {
151
151
  log('generalDebug_0003', `Following the app package in "${path}" ...`);
152
152
  const appPackage = require(path);
153
+ const root = dirname(path);
153
154
  const relPath = appPackage && appPackage.app;
154
- appPackage.app = relPath && resolve(dirname(path), relPath);
155
+ appPackage.app = relPath && resolve(root, relPath);
156
+ appPackage.root = root;
155
157
  return appPackage;
156
158
  }
157
159
  }
@@ -192,6 +194,10 @@ export function getPiralPackage(
192
194
  start: 'piral debug',
193
195
  build: 'piral build',
194
196
  },
197
+ importmap: {
198
+ imports: {},
199
+ inherit: ['piral-base', framework !== 'piral-base' && 'piral-core'].filter(Boolean),
200
+ },
195
201
  pilets: getPiletsInfo({}),
196
202
  dependencies,
197
203
  devDependencies,
@@ -345,8 +351,8 @@ export async function copyPiralFiles(
345
351
  export function getPiletsInfo(piralInfo: any): PiletsInfo {
346
352
  const {
347
353
  files = [],
348
- externals = [],
349
354
  scripts = {},
355
+ template = 'default',
350
356
  validators = {},
351
357
  devDependencies = {},
352
358
  preScaffold = '',
@@ -358,8 +364,8 @@ export function getPiletsInfo(piralInfo: any): PiletsInfo {
358
364
 
359
365
  return {
360
366
  files,
361
- externals,
362
367
  scripts,
368
+ template,
363
369
  validators,
364
370
  devDependencies,
365
371
  preScaffold,
@@ -442,6 +448,21 @@ export async function findPackageVersion(rootPath: string, packageName: string):
442
448
  }
443
449
  }
444
450
 
451
+ export async function retrieveExternals(root: string, packageInfo: any) {
452
+ const sharedDependencies = await readImportmap(root, packageInfo);
453
+
454
+ if (sharedDependencies.length === 0) {
455
+ const allDeps = {
456
+ ...packageInfo.devDependencies,
457
+ ...packageInfo.dependencies,
458
+ };
459
+ const deps = packageInfo.pilets?.externals;
460
+ return makeExternals(allDeps, deps);
461
+ }
462
+
463
+ return sharedDependencies.map((m) => m.name);
464
+ }
465
+
445
466
  export async function retrievePiletsInfo(entryFile: string) {
446
467
  const exists = await checkExists(entryFile);
447
468
 
@@ -456,12 +477,9 @@ export async function retrievePiletsInfo(entryFile: string) {
456
477
  }
457
478
 
458
479
  const packageInfo = require(packageJson);
459
- const allDeps = {
460
- ...packageInfo.devDependencies,
461
- ...packageInfo.dependencies,
462
- };
463
480
  const info = getPiletsInfo(packageInfo);
464
- const externals = makeExternals(allDeps, info.externals);
481
+ const root = dirname(packageJson);
482
+ const externals = await retrieveExternals(root, packageInfo);
465
483
 
466
484
  return {
467
485
  ...info,
@@ -475,7 +493,7 @@ export async function retrievePiletsInfo(entryFile: string) {
475
493
  },
476
494
  scripts: packageInfo.scripts,
477
495
  ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
478
- root: dirname(packageJson),
496
+ root,
479
497
  };
480
498
  }
481
499
 
@@ -599,9 +617,10 @@ export async function retrievePiletData(target: string, app?: string) {
599
617
  app || (piletPackage.piral && piletPackage.piral.name) || Object.keys(piletPackage.devDependencies),
600
618
  target,
601
619
  );
602
- const appFile: string = appPackage && appPackage.app;
620
+ const appFile: string = appPackage?.app;
621
+ const appRoot: string = appPackage?.root;
603
622
 
604
- if (!appFile) {
623
+ if (!appFile || !appRoot) {
605
624
  fail('appInstanceInvalid_0011');
606
625
  }
607
626
 
@@ -616,6 +635,7 @@ export async function retrievePiletData(target: string, app?: string) {
616
635
  ignored: checkArrayOrUndefined(piletPackage, 'preservedDependencies'),
617
636
  importmap,
618
637
  appFile,
638
+ appRoot,
619
639
  piletPackage,
620
640
  appPackage,
621
641
  emulator,
@@ -39,6 +39,7 @@ async function getTemplateFiles(
39
39
  } else {
40
40
  await installPackage(templatePackageName, __dirname, '--registry', registry);
41
41
  }
42
+
42
43
  const templateRunner = getTemplatePackage(templatePackageName);
43
44
  const logLevel = getLogLevel();
44
45
  const details = {
@@ -4,6 +4,8 @@ import PiletInjector from './pilet';
4
4
 
5
5
  const optionsMock = {
6
6
  pilets: [],
7
+ publicUrl: '/',
8
+ meta: 'debug-meta.json',
7
9
  api: '',
8
10
  app: '',
9
11
  active: true,
@@ -83,6 +85,8 @@ describe('Piral-CLI piral injector', () => {
83
85
  // Arrange
84
86
  const optionsMock = {
85
87
  pilets: [],
88
+ meta: 'debug-meta.json',
89
+ publicUrl: '/',
86
90
  api: 'http://someFakeApi:1234',
87
91
  app: '',
88
92
  active: true,
@@ -110,6 +114,8 @@ describe('Piral-CLI piral injector', () => {
110
114
  // Arrange
111
115
  const optionsMock = {
112
116
  pilets: [],
117
+ meta: 'debug-meta.json',
118
+ publicUrl: '/',
113
119
  api: 'http://someFakeApi:1234',
114
120
  app: '',
115
121
  active: true,
@@ -19,6 +19,7 @@ interface Pilet {
19
19
 
20
20
  export interface PiletInjectorConfig extends KrasInjectorConfig {
21
21
  pilets: Array<Pilet>;
22
+ publicUrl: string;
22
23
  meta: string;
23
24
  api: string;
24
25
  app: string;
@@ -74,6 +75,7 @@ async function loadFeed(feed: string) {
74
75
  export default class PiletInjector implements KrasInjector {
75
76
  public config: PiletInjectorConfig;
76
77
  private piletApi: string;
78
+ private indexPath: string;
77
79
 
78
80
  constructor(options: PiletInjectorConfig, config: KrasConfiguration, core: EventEmitter) {
79
81
  this.config = options;
@@ -82,7 +84,8 @@ export default class PiletInjector implements KrasInjector {
82
84
  ? options.api
83
85
  : `${config.ssl ? 'https' : 'http'}://${host}:${config.port}${options.api}`;
84
86
 
85
- const { pilets, api } = options;
87
+ const { pilets, api, publicUrl } = options;
88
+ this.indexPath = `${publicUrl}index.html`;
86
89
  const cbs = {};
87
90
 
88
91
  core.on('user-connected', (e) => {
@@ -210,26 +213,30 @@ export default class PiletInjector implements KrasInjector {
210
213
  }
211
214
 
212
215
  handle(req: KrasRequest): KrasResponse {
213
- const { app, api } = this.config;
214
- const path = req.url.substring(1).split('?')[0];
216
+ const { app, api, publicUrl } = this.config;
215
217
 
216
218
  if (!req.target) {
217
- const target = join(app, path);
219
+ if (req.url.startsWith(publicUrl)) {
220
+ const path = req.url.substring(publicUrl.length).split('?')[0];
221
+ const target = join(app, path);
218
222
 
219
- if (existsSync(target) && statSync(target).isFile()) {
220
- if (req.url === '/index.html') {
221
- return this.sendIndexFile(target, req.url);
223
+ if (existsSync(target) && statSync(target).isFile()) {
224
+ if (req.url === this.indexPath) {
225
+ return this.sendIndexFile(target, req.url);
226
+ } else {
227
+ return this.sendFile(target, req.url);
228
+ }
229
+ } else if (req.url !== this.indexPath) {
230
+ return this.handle({
231
+ ...req,
232
+ url: this.indexPath,
233
+ });
222
234
  }
223
- return this.sendFile(target, req.url);
224
- } else if (req.url !== '/index.html') {
225
- return this.handle({
226
- ...req,
227
- url: '/index.html',
228
- });
229
- } else {
230
- return undefined;
231
235
  }
236
+
237
+ return undefined;
232
238
  } else if (req.target === api) {
239
+ const path = req.url.substring(1).split('?')[0];
233
240
  return this.sendResponse(path, req.url);
234
241
  }
235
242
  }
@@ -1,5 +1,5 @@
1
1
  import { PiletRuleContext } from '../types';
2
- import { getPiletsInfo, getSourceFiles, isValidDependency } from '../common';
2
+ import { retrieveExternals, getSourceFiles, isValidDependency } from '../common';
3
3
 
4
4
  export type Options = 'ignore' | 'active' | 'only-used';
5
5
 
@@ -21,7 +21,7 @@ Received: Missing "${missingNames.join('", "')}".
21
21
  */
22
22
  export default async function (context: PiletRuleContext, options: Options = 'ignore') {
23
23
  if (options !== 'ignore') {
24
- const { externals } = getPiletsInfo(context.data.appPackage);
24
+ const externals = await retrieveExternals(context.data.appRoot, context.data.appPackage);
25
25
  const markedPeerDependencies = Object.keys(context.peerDependencies);
26
26
  const markedPeerModules = context.peerModules;
27
27
  const missingExternals = externals
@@ -55,7 +55,8 @@ export interface TemplateFileLocation {
55
55
 
56
56
  export interface PiletsInfo {
57
57
  files: Array<string | TemplateFileLocation>;
58
- externals: Array<string>;
58
+ template: string;
59
+ externals?: Array<string>;
59
60
  devDependencies: Record<string, string | true>;
60
61
  scripts: Record<string, string>;
61
62
  validators: Record<string, any>;
@@ -106,6 +107,7 @@ export interface PiletRuleContext extends RuleContext {
106
107
  }
107
108
 
108
109
  export interface PiralData {
110
+ appRoot: string;
109
111
  appFile: string;
110
112
  appPackage: any;
111
113
  piletPackage: any;
@@ -80,6 +80,7 @@ export interface DebugPiralParameters extends BaseBundleParameters {
80
80
  export interface WatchPiralParameters extends BaseBundleParameters {
81
81
  piral: string;
82
82
  externals: Array<string>;
83
+ publicUrl: string;
83
84
  entryFiles: string;
84
85
  logLevel: LogLevels;
85
86
  }