piral-cli 0.14.24-beta.4163 → 0.14.24-beta.4191

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 (75) hide show
  1. package/lib/apps/new-pilet.js +5 -3
  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.js +1 -1
  6. package/lib/apps/publish-pilet.js.map +1 -1
  7. package/lib/apps/publish-piral.js +1 -1
  8. package/lib/apps/publish-piral.js.map +1 -1
  9. package/lib/apps/upgrade-pilet.js +2 -2
  10. package/lib/apps/upgrade-pilet.js.map +1 -1
  11. package/lib/apps/upgrade-piral.js +1 -1
  12. package/lib/apps/upgrade-piral.js.map +1 -1
  13. package/lib/bundler.js +1 -1
  14. package/lib/bundler.js.map +1 -1
  15. package/lib/common/clients/lerna.d.ts +3 -0
  16. package/lib/common/clients/lerna.js +32 -1
  17. package/lib/common/clients/lerna.js.map +1 -1
  18. package/lib/common/clients/npm.d.ts +2 -0
  19. package/lib/common/clients/npm.js +18 -1
  20. package/lib/common/clients/npm.js.map +1 -1
  21. package/lib/common/clients/pnpm.d.ts +3 -0
  22. package/lib/common/clients/pnpm.js +32 -1
  23. package/lib/common/clients/pnpm.js.map +1 -1
  24. package/lib/common/clients/rush.d.ts +3 -0
  25. package/lib/common/clients/rush.js +57 -3
  26. package/lib/common/clients/rush.js.map +1 -1
  27. package/lib/common/clients/yarn.d.ts +3 -0
  28. package/lib/common/clients/yarn.js +32 -1
  29. package/lib/common/clients/yarn.js.map +1 -1
  30. package/lib/common/emulator.js +2 -2
  31. package/lib/common/emulator.js.map +1 -1
  32. package/lib/common/inspect.js +2 -1
  33. package/lib/common/inspect.js.map +1 -1
  34. package/lib/common/npm.d.ts +9 -7
  35. package/lib/common/npm.js +53 -36
  36. package/lib/common/npm.js.map +1 -1
  37. package/lib/common/pack.js +1 -1
  38. package/lib/common/pack.js.map +1 -1
  39. package/lib/common/package.d.ts +6 -6
  40. package/lib/common/package.js +14 -4
  41. package/lib/common/package.js.map +1 -1
  42. package/lib/common/scaffold.js +1 -1
  43. package/lib/common/scaffold.js.map +1 -1
  44. package/lib/external/index.js +1982 -92
  45. package/lib/injectors/pilet.js +2 -2
  46. package/lib/injectors/pilet.js.map +1 -1
  47. package/lib/plugin.js +4 -4
  48. package/lib/plugin.js.map +1 -1
  49. package/lib/types/internal.d.ts +9 -1
  50. package/package.json +4 -2
  51. package/src/apps/new-pilet.ts +9 -6
  52. package/src/apps/new-piral.ts +9 -5
  53. package/src/apps/publish-pilet.ts +2 -2
  54. package/src/apps/publish-piral.ts +2 -2
  55. package/src/apps/upgrade-pilet.ts +4 -4
  56. package/src/apps/upgrade-piral.ts +2 -2
  57. package/src/bundler.test.ts +1 -1
  58. package/src/bundler.ts +2 -2
  59. package/src/common/clients/lerna.ts +28 -0
  60. package/src/common/clients/npm.ts +14 -0
  61. package/src/common/clients/pnpm.ts +28 -0
  62. package/src/common/clients/rush.ts +66 -4
  63. package/src/common/clients/yarn.ts +28 -0
  64. package/src/common/emulator.ts +3 -3
  65. package/src/common/inspect.ts +2 -1
  66. package/src/common/npm.test.ts +35 -33
  67. package/src/common/npm.ts +52 -33
  68. package/src/common/pack.test.ts +1 -1
  69. package/src/common/pack.ts +2 -2
  70. package/src/common/package.ts +20 -10
  71. package/src/common/scaffold.ts +2 -2
  72. package/src/external/index.ts +2 -1
  73. package/src/injectors/pilet.ts +3 -3
  74. package/src/plugin.ts +4 -4
  75. package/src/types/internal.ts +6 -1
@@ -2,11 +2,11 @@ import { resolve } from 'path';
2
2
  import { clients } from './clients';
3
3
  import {
4
4
  dissectPackageName,
5
- installPackage,
5
+ installNpmPackage,
6
6
  isMonorepoPackageRef,
7
- installDependencies,
8
- createPackage,
9
- findTarball,
7
+ installNpmDependencies,
8
+ createNpmPackage,
9
+ findNpmTarball,
10
10
  findSpecificVersion,
11
11
  findLatestVersion,
12
12
  isLocalPackage,
@@ -40,8 +40,8 @@ jest.mock('../external', () => ({
40
40
  let specialCase = false;
41
41
  let shouldFind = true;
42
42
  let wrongCase = false;
43
- const jsonValueString = JSON.stringify({ dependencies: { npm: { extraneous: true } } });
44
- const jsonValueStringWrong = JSON.stringify({ dependencies: {} });
43
+ const jsonValueString = JSON.stringify([{ name: 'npm' }]);
44
+ const jsonValueStringWrong = JSON.stringify([]);
45
45
 
46
46
  jest.mock('./scripts', () => ({
47
47
  runCommand: (exe: string, args: Array<string>, cwd: string, output?: NodeJS.WritableStream) => {
@@ -165,37 +165,39 @@ describe('npm Module', () => {
165
165
 
166
166
  it('installs a package using the npm command line tool without a target', async () => {
167
167
  wrongCase = false;
168
- await installPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
168
+ await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
169
169
  wrongCase = true;
170
- await installPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
170
+ await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
171
171
  });
172
172
 
173
173
  it('installs a package using the npm command line tool without a version', async () => {
174
174
  wrongCase = false;
175
- await installPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
175
+ await installNpmPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
176
176
  wrongCase = true;
177
- await installPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
177
+ await installNpmPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
178
178
  });
179
179
 
180
180
  it('installs a package using the Yarn command line tool without a version', async () => {
181
181
  wrongCase = false;
182
- await installPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
182
+ await installNpmPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
183
183
  wrongCase = true;
184
- await installPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
184
+ await installNpmPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
185
185
  });
186
186
 
187
187
  it('installs a package using the Pnpm command line tool without a version', async () => {
188
188
  wrongCase = false;
189
- await installPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
189
+ await installNpmPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
190
190
  wrongCase = true;
191
- await installPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
191
+ await installNpmPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
192
192
  });
193
193
 
194
194
  it('installs a package using the npm command line tool with some flag', async () => {
195
195
  wrongCase = false;
196
- await installPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) => expect(result).toEqual(jsonValueString));
196
+ await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
197
+ expect(result).toEqual(jsonValueString),
198
+ );
197
199
  wrongCase = true;
198
- await installPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
200
+ await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
199
201
  expect(result).not.toEqual(jsonValueString),
200
202
  );
201
203
  });
@@ -242,37 +244,37 @@ describe('npm Module', () => {
242
244
 
243
245
  it('install dependencies with npm client', async () => {
244
246
  wrongCase = false;
245
- await installDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
247
+ await installNpmDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
246
248
  wrongCase = true;
247
- await installDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
249
+ await installNpmDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
248
250
  });
249
251
 
250
252
  it('install dependencies with pnpm client', async () => {
251
253
  wrongCase = false;
252
- await installDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
254
+ await installNpmDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
253
255
  wrongCase = true;
254
- await installDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
256
+ await installNpmDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
255
257
  });
256
258
 
257
259
  it('install dependencies with yarn client', async () => {
258
260
  wrongCase = false;
259
- await installDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
261
+ await installNpmDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
260
262
  wrongCase = true;
261
- await installDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
263
+ await installNpmDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
262
264
  });
263
265
 
264
266
  it('create npm package', async () => {
265
267
  wrongCase = false;
266
- await createPackage().then((result) => expect(result).toEqual(jsonValueString));
268
+ await createNpmPackage().then((result) => expect(result).toEqual(jsonValueString));
267
269
  wrongCase = true;
268
- await createPackage().then((result) => expect(result).not.toEqual(jsonValueString));
270
+ await createNpmPackage().then((result) => expect(result).not.toEqual(jsonValueString));
269
271
  });
270
272
 
271
273
  it('find npm tarball', async () => {
272
274
  wrongCase = false;
273
- await findTarball('foo').then((result) => expect(result).toEqual(jsonValueString));
275
+ await findNpmTarball('foo').then((result) => expect(result).toEqual(jsonValueString));
274
276
  wrongCase = true;
275
- await findTarball('foo').then((result) => expect(result).not.toEqual(jsonValueString));
277
+ await findNpmTarball('foo').then((result) => expect(result).not.toEqual(jsonValueString));
276
278
  });
277
279
 
278
280
  it('find latest version', async () => {
@@ -438,7 +440,7 @@ describe('npm Module', () => {
438
440
  });
439
441
 
440
442
  it('makeExternals without externals returns coreExternals', () => {
441
- const externals = makeExternals({ piral: '*' });
443
+ const externals = makeExternals(process.cwd(), { piral: '*' });
442
444
  expect(externals).toEqual([
443
445
  'react',
444
446
  'react-dom',
@@ -453,7 +455,7 @@ describe('npm Module', () => {
453
455
  });
454
456
 
455
457
  it('makeExternals with no externals returns coreExternals', () => {
456
- const externals = makeExternals({ piral: '*' }, []);
458
+ const externals = makeExternals(process.cwd(), { piral: '*' }, []);
457
459
  expect(externals).toEqual([
458
460
  'react',
459
461
  'react-dom',
@@ -468,12 +470,12 @@ describe('npm Module', () => {
468
470
  });
469
471
 
470
472
  it('makeExternals with exclude coreExternals returns empty set', () => {
471
- const externals = makeExternals({ piral: '*' }, ['!*']);
473
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['!*']);
472
474
  expect(externals).toEqual([]);
473
475
  });
474
476
 
475
477
  it('makeExternals with externals concats coreExternals', () => {
476
- const externals = makeExternals({ piral: '*' }, ['foo', 'bar']);
478
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['foo', 'bar']);
477
479
  expect(externals).toEqual([
478
480
  'foo',
479
481
  'bar',
@@ -490,7 +492,7 @@ describe('npm Module', () => {
490
492
  });
491
493
 
492
494
  it('makeExternals with external duplicate only reflects coreExternals', () => {
493
- const externals = makeExternals({ piral: '*' }, ['react', 'foo']);
495
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'foo']);
494
496
  expect(externals).toEqual([
495
497
  'react',
496
498
  'foo',
@@ -506,7 +508,7 @@ describe('npm Module', () => {
506
508
  });
507
509
 
508
510
  it('makeExternals with explicit include and exclude', () => {
509
- const externals = makeExternals({ piral: '*' }, ['react', 'react-calendar', '!history']);
511
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'react-calendar', '!history']);
510
512
  expect(externals).toEqual([
511
513
  'react',
512
514
  'react-calendar',
@@ -521,7 +523,7 @@ describe('npm Module', () => {
521
523
  });
522
524
 
523
525
  it('makeExternals with all exclude and explicit include', () => {
524
- const externals = makeExternals({ piral: '*' }, ['react', 'react-router-dom', '!*']);
526
+ const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'react-router-dom', '!*']);
525
527
  expect(externals).toEqual(['react', 'react-router-dom']);
526
528
  });
527
529
  });
package/src/common/npm.ts CHANGED
@@ -5,7 +5,7 @@ import { clients, detectClients, isWrapperClient } from './clients';
5
5
  import { config } from './config';
6
6
  import { legacyCoreExternals, frameworkLibs } from './constants';
7
7
  import { inspectPackage } from './inspect';
8
- import { readJson, checkExists, findFile } from './io';
8
+ import { readJson, checkExists } from './io';
9
9
  import { clientTypeKeys } from '../helpers';
10
10
  import { PackageType, NpmClientType } from '../types';
11
11
 
@@ -24,30 +24,37 @@ function resolveAbsPath(basePath: string, fullName: string) {
24
24
  return resolve(basePath, relPath);
25
25
  }
26
26
 
27
- async function detectMonorepoRoot(root: string): Promise<string> {
27
+ async function detectMonorepoRoot(root: string): Promise<[] | [string, NpmClientType]> {
28
28
  let previous = root;
29
29
 
30
30
  do {
31
- const isMonorepo =
32
- (await checkExists(resolve(root, 'lerna.json'))) ||
33
- (await checkExists(resolve(root, 'rush.json'))) ||
34
- (await checkExists(resolve(root, 'pnpm-workspace.yaml')));
31
+ if (await checkExists(resolve(root, 'lerna.json'))) {
32
+ return [root, 'lerna'];
33
+ }
34
+
35
+ if (await checkExists(resolve(root, 'rush.json'))) {
36
+ return [root, 'rush'];
37
+ }
35
38
 
36
- if (isMonorepo) {
37
- return root;
39
+ if (await checkExists(resolve(root, 'pnpm-workspace.yaml'))) {
40
+ return [root, 'pnpm'];
38
41
  }
39
42
 
40
43
  const packageJson = await readJson(root, 'package.json');
41
44
 
42
45
  if (Array.isArray(packageJson?.workspaces)) {
43
- return root;
46
+ if (await checkExists(resolve(root, 'yarn.lock'))) {
47
+ return [root, 'yarn'];
48
+ }
49
+
50
+ return [root, 'npm'];
44
51
  }
45
52
 
46
53
  previous = root;
47
54
  root = dirname(root);
48
55
  } while (root !== previous);
49
56
 
50
- return undefined;
57
+ return [];
51
58
  }
52
59
 
53
60
  /**
@@ -103,23 +110,22 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
103
110
  }
104
111
 
105
112
  export async function isMonorepoPackageRef(refName: string, root: string): Promise<boolean> {
106
- const newRoot = await detectMonorepoRoot(root);
113
+ const [monorepoRoot, client] = await detectMonorepoRoot(root);
107
114
 
108
- if (newRoot) {
109
- const { listPackage } = clients.npm;
110
- const details = await listPackage(refName, newRoot);
111
- return details?.dependencies?.[refName]?.extraneous ?? false;
115
+ if (monorepoRoot) {
116
+ const c = clients[client];
117
+ return await c.isProject(monorepoRoot, refName);
112
118
  }
113
119
 
114
120
  return false;
115
121
  }
116
122
 
117
- export function installDependencies(client: NpmClientType, target = '.'): Promise<string> {
123
+ export function installNpmDependencies(client: NpmClientType, target = '.'): Promise<string> {
118
124
  const { installDependencies } = clients[client];
119
125
  return installDependencies(target);
120
126
  }
121
127
 
122
- export async function installPackage(
128
+ export async function installNpmPackage(
123
129
  client: NpmClientType,
124
130
  packageRef: string,
125
131
  target = '.',
@@ -137,17 +143,22 @@ export async function installPackage(
137
143
  }
138
144
  }
139
145
 
140
- export function publishPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
146
+ export function initNpmProject(client: NpmClientType, projectName: string, target: string) {
147
+ const { initProject } = clients[client];
148
+ return initProject(projectName, target);
149
+ }
150
+
151
+ export function publishNpmPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
141
152
  const { publishPackage } = clients.npm;
142
153
  return publishPackage(target, file, ...flags);
143
154
  }
144
155
 
145
- export function createPackage(target = '.'): Promise<string> {
156
+ export function createNpmPackage(target = '.'): Promise<string> {
146
157
  const { createPackage } = clients.npm;
147
158
  return createPackage(target);
148
159
  }
149
160
 
150
- export function findTarball(packageRef: string): Promise<string> {
161
+ export function findNpmTarball(packageRef: string): Promise<string> {
151
162
  const { findTarball } = clients.npm;
152
163
  return findTarball(packageRef);
153
164
  }
@@ -321,7 +332,8 @@ export function isLinkedPackage(name: string, type: PackageType, hadVersion: boo
321
332
 
322
333
  export function combinePackageRef(name: string, version: string, type: PackageType) {
323
334
  if (type === 'registry') {
324
- return `${name}@${version || 'latest'}`;
335
+ const tag = version || 'latest';
336
+ return `${name}@${tag}`;
325
337
  }
326
338
 
327
339
  return name;
@@ -375,19 +387,22 @@ export function getPackageVersion(
375
387
  }
376
388
  }
377
389
 
378
- function getExternalsFrom(packageName: string): Array<string> | undefined {
390
+ function getExternalsFrom(root: string, packageName: string): Array<string> | undefined {
379
391
  try {
380
- return require(`${packageName}/package.json`).sharedDependencies;
392
+ const target = require.resolve(`${packageName}/package.json`, {
393
+ paths: [root],
394
+ });
395
+ return require(target).sharedDependencies;
381
396
  } catch (err) {
382
397
  log('generalError_0002', `Could not get externals from "${packageName}": "${err}`);
383
398
  return undefined;
384
399
  }
385
400
  }
386
401
 
387
- function getCoreExternals(dependencies: Record<string, string>): Array<string> {
402
+ function getCoreExternals(root: string, dependencies: Record<string, string>): Array<string> {
388
403
  for (const frameworkLib of frameworkLibs) {
389
404
  if (dependencies[frameworkLib]) {
390
- const deps = getExternalsFrom(frameworkLib);
405
+ const deps = getExternalsFrom(root, frameworkLib);
391
406
 
392
407
  if (deps) {
393
408
  return deps;
@@ -400,24 +415,23 @@ function getCoreExternals(dependencies: Record<string, string>): Array<string> {
400
415
  }
401
416
 
402
417
  export function makePiletExternals(
418
+ root: string,
403
419
  dependencies: Record<string, string>,
404
420
  externals: Array<string>,
405
421
  fromEmulator: boolean,
406
422
  piralInfo: any,
407
- ) {
423
+ ): Array<string> {
408
424
  if (fromEmulator) {
409
- const { sharedDependencies = makeExternals(dependencies, externals, true) } = piralInfo;
425
+ const { sharedDependencies = mergeExternals(externals, legacyCoreExternals) } = piralInfo;
410
426
  return sharedDependencies;
411
427
  } else {
412
- return makeExternals(dependencies, externals);
428
+ return makeExternals(root, dependencies, externals);
413
429
  }
414
430
  }
415
431
 
416
- export function makeExternals(dependencies: Record<string, string>, externals?: Array<string>, legacy = false) {
417
- const coreExternals = legacy ? legacyCoreExternals : getCoreExternals(dependencies);
418
-
419
- if (externals && Array.isArray(externals)) {
420
- const [include, exclude] = externals.reduce<[Array<string>, Array<string>]>(
432
+ export function mergeExternals(customExternals?: Array<string>, coreExternals: Array<string> = []) {
433
+ if (customExternals && Array.isArray(customExternals)) {
434
+ const [include, exclude] = customExternals.reduce<[Array<string>, Array<string>]>(
421
435
  (prev, curr) => {
422
436
  if (typeof curr === 'string') {
423
437
  if (curr.startsWith('!')) {
@@ -437,3 +451,8 @@ export function makeExternals(dependencies: Record<string, string>, externals?:
437
451
 
438
452
  return coreExternals;
439
453
  }
454
+
455
+ export function makeExternals(root: string, dependencies: Record<string, string>, externals?: Array<string>) {
456
+ const coreExternals = getCoreExternals(root, dependencies);
457
+ return mergeExternals(externals, coreExternals);
458
+ }
@@ -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}".`);
@@ -12,7 +12,7 @@ import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, makePiletExtern
12
12
  import { filesTar, filesOnceTar, declarationEntryExtensions, bundlerNames } from './constants';
13
13
  import { getHash, checkIsDirectory, matchFiles } from './io';
14
14
  import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
15
- import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, SharedDependency } from '../types';
15
+ import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, SharedDependency, PackageData } from '../types';
16
16
 
17
17
  function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
18
18
  if (bundler && bundler !== 'none') {
@@ -159,7 +159,7 @@ function findPackage(pck: string | Array<string>, baseDir: string) {
159
159
  return undefined;
160
160
  }
161
161
 
162
- export function readPiralPackage(root: string, name: string) {
162
+ export function readPiralPackage(root: string, name: string): Promise<PackageData> {
163
163
  log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
164
164
  const path = getPiralPath(root, name);
165
165
  return readJson(path, 'package.json');
@@ -319,10 +319,19 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
319
319
  return typeof item === 'object';
320
320
  }
321
321
 
322
+ function tryFindPackageVersion(packageName: string): string {
323
+ try {
324
+ const { version } = require(`${packageName}/package.json`);
325
+ return version;
326
+ } catch {
327
+ return undefined;
328
+ }
329
+ }
330
+
322
331
  export async function copyPiralFiles(
323
332
  root: string,
324
333
  name: string,
325
- piralInfo: any,
334
+ piralInfo: PackageData,
326
335
  forceOverwrite: ForceOverwrite,
327
336
  variables: Record<string, string>,
328
337
  originalFiles?: Array<FileInfo>,
@@ -342,7 +351,7 @@ export async function copyPiralFiles(
342
351
  await copyFiles(files, forceOverwrite, originalFiles, variables);
343
352
  }
344
353
 
345
- export function getPiletsInfo(piralInfo: any): PiletsInfo {
354
+ export function getPiletsInfo(piralInfo: Partial<PackageData>): PiletsInfo {
346
355
  const {
347
356
  files = [],
348
357
  externals = [],
@@ -457,13 +466,14 @@ export async function retrievePiletsInfo(entryFile: string) {
457
466
  fail('packageJsonMissing_0074');
458
467
  }
459
468
 
469
+ const root = dirname(packageJson);
460
470
  const packageInfo = require(packageJson);
461
471
  const allDeps = {
462
472
  ...packageInfo.devDependencies,
463
473
  ...packageInfo.dependencies,
464
474
  };
465
475
  const info = getPiletsInfo(packageInfo);
466
- const externals = makeExternals(allDeps, info.externals);
476
+ const externals = makeExternals(root, allDeps, info.externals);
467
477
 
468
478
  return {
469
479
  ...info,
@@ -477,7 +487,7 @@ export async function retrievePiletsInfo(entryFile: string) {
477
487
  },
478
488
  scripts: packageInfo.scripts,
479
489
  ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
480
- root: dirname(packageJson),
490
+ root,
481
491
  };
482
492
  }
483
493
 
@@ -491,7 +501,7 @@ export async function patchPiletPackage(
491
501
  root: string,
492
502
  name: string,
493
503
  version: string,
494
- piralInfo: any,
504
+ piralInfo: PackageData,
495
505
  fromEmulator: boolean,
496
506
  newInfo?: { language: SourceLanguage; bundler: string },
497
507
  ) {
@@ -515,7 +525,7 @@ export async function patchPiletPackage(
515
525
  }
516
526
  : info.scripts;
517
527
  const peerModules = [];
518
- const allExternals = makePiletExternals(piralDependencies, externals, fromEmulator, piralInfo);
528
+ const allExternals = makePiletExternals(root, piralDependencies, externals, fromEmulator, piralInfo);
519
529
  const peerDependencies = {
520
530
  ...allExternals.reduce((deps, name) => {
521
531
  const valid = isValidDependency(name);
@@ -539,7 +549,7 @@ export async function patchPiletPackage(
539
549
  return deps;
540
550
  }, {}),
541
551
  ...allExternals.filter(isValidDependency).reduce((deps, name) => {
542
- const version = piralDependencies[name];
552
+ const version = piralDependencies[name] || tryFindPackageVersion(name);
543
553
 
544
554
  if (version || newInfo) {
545
555
  // set only if we have an explicit version or we are in the scaffolding case
@@ -576,7 +586,7 @@ export async function patchPiletPackage(
576
586
  /**
577
587
  * Returns true if its an emulator package, otherwise it has to be a "raw" app shell.
578
588
  */
579
- export function checkAppShellPackage(appPackage: any) {
589
+ export function checkAppShellPackage(appPackage: PackageData) {
580
590
  const { piralCLI = { generated: false, version: cliVersion } } = appPackage;
581
591
 
582
592
  if (piralCLI.generated) {
@@ -1,5 +1,5 @@
1
1
  import { join, dirname, resolve, basename, isAbsolute } from 'path';
2
- import { installPackage } from './npm';
2
+ import { installNpmPackage } from './npm';
3
3
  import { ForceOverwrite, SourceLanguage } from './enums';
4
4
  import { createDirectory, createFileIfNotExists, updateExistingJson } from './io';
5
5
  import { log, fail } from './log';
@@ -36,7 +36,7 @@ async function getTemplateFiles(
36
36
  if (templatePackageName.startsWith('.')) {
37
37
  templatePackageName = resolve(process.cwd(), templatePackageName);
38
38
  } else {
39
- await installPackage('npm', templatePackageName, __dirname, '--registry', registry);
39
+ await installNpmPackage('npm', templatePackageName, __dirname, '--registry', registry);
40
40
  }
41
41
 
42
42
  const templateRunner = getTemplatePackage(templatePackageName);
@@ -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 };
@@ -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/plugin.ts CHANGED
@@ -6,11 +6,11 @@ import { inject } from './inject';
6
6
  function getContainerDir() {
7
7
  const currentDir = __dirname.split(sep).join(posix.sep);
8
8
 
9
- if (currentDir.includes(`/.pnpm/${cliName}@${cliVersion}/node_modules/${cliName}/`)) {
10
- return resolve(__dirname, '..', '..', '..', '..', '..');
9
+ if (!currentDir.includes(`/.pnpm/${cliName}@${cliVersion}/node_modules/${cliName}/`)) {
10
+ return resolve(__dirname, '..', '..');
11
11
  }
12
12
 
13
- return resolve(__dirname, '..', '..');
13
+ return undefined;
14
14
  }
15
15
 
16
16
  async function getLocalPackageDir() {
@@ -25,7 +25,7 @@ async function getLocalPackageDir() {
25
25
  // Right now we always take the first one, but in the future this may be different
26
26
  // once we come up with more / better criteria to identify if its a good/valid
27
27
  // plugin root directory
28
- for (const dir of proposedDirs) {
28
+ for (const dir of proposedDirs.filter(Boolean)) {
29
29
  log('generalDebug_0003', `Checking for potential plugin directory "${dir}" ...`);
30
30
 
31
31
  if (await isDirectory(dir)) {
@@ -1,4 +1,4 @@
1
- import { LogLevels } from './common';
1
+ import type { LogLevels, PiletsInfo } from './common';
2
2
 
3
3
  export interface PackageData {
4
4
  name: string;
@@ -13,6 +13,11 @@ export interface PackageData {
13
13
  email?: string;
14
14
  };
15
15
  custom?: any;
16
+ pilets?: PiletsInfo;
17
+ piralCLI?: { generated: boolean; version: string };
18
+ dependencies: Record<string, string>;
19
+ peerDependencies: Record<string, string>;
20
+ devDependencies: Record<string, string>;
16
21
  }
17
22
 
18
23
  export interface PackageFiles {