piral-cli 0.15.0-alpha.3640 → 0.15.0-alpha.3719

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 (61) hide show
  1. package/lib/apps/build-piral.js +4 -19
  2. package/lib/apps/build-piral.js.map +1 -1
  3. package/lib/apps/debug-pilet.d.ts +5 -0
  4. package/lib/apps/debug-pilet.js +8 -2
  5. package/lib/apps/debug-pilet.js.map +1 -1
  6. package/lib/apps/debug-piral.d.ts +4 -0
  7. package/lib/apps/debug-piral.js +6 -9
  8. package/lib/apps/debug-piral.js.map +1 -1
  9. package/lib/apps/new-pilet.js +1 -1
  10. package/lib/apps/new-pilet.js.map +1 -1
  11. package/lib/apps/new-piral.js +3 -4
  12. package/lib/apps/new-piral.js.map +1 -1
  13. package/lib/build/run-debug-pilet.js +2 -4
  14. package/lib/build/run-debug-pilet.js.map +1 -1
  15. package/lib/build/run-debug-piral.js +2 -4
  16. package/lib/build/run-debug-piral.js.map +1 -1
  17. package/lib/bundler.js +1 -1
  18. package/lib/bundler.js.map +1 -1
  19. package/lib/commands.js +9 -2
  20. package/lib/commands.js.map +1 -1
  21. package/lib/common/clients/yarn.js +2 -0
  22. package/lib/common/clients/yarn.js.map +1 -1
  23. package/lib/common/constants.d.ts +2 -1
  24. package/lib/common/constants.js +11 -1
  25. package/lib/common/constants.js.map +1 -1
  26. package/lib/common/importmap.js +1 -1
  27. package/lib/common/importmap.js.map +1 -1
  28. package/lib/common/io.d.ts +5 -0
  29. package/lib/common/io.js +17 -1
  30. package/lib/common/io.js.map +1 -1
  31. package/lib/common/npm.js +2 -2
  32. package/lib/common/npm.js.map +1 -1
  33. package/lib/common/package.js +21 -7
  34. package/lib/common/package.js.map +1 -1
  35. package/lib/external/index.js +7 -3
  36. package/lib/helpers.js +3 -12
  37. package/lib/helpers.js.map +1 -1
  38. package/lib/messages.d.ts +54 -0
  39. package/lib/messages.js +62 -1
  40. package/lib/messages.js.map +1 -1
  41. package/lib/types/public.d.ts +4 -0
  42. package/package.json +3 -2
  43. package/src/apps/build-piral.ts +5 -25
  44. package/src/apps/debug-pilet.ts +15 -2
  45. package/src/apps/debug-piral.ts +11 -1
  46. package/src/apps/new-pilet.ts +1 -1
  47. package/src/apps/new-piral.ts +9 -5
  48. package/src/build/run-debug-pilet.ts +2 -4
  49. package/src/build/run-debug-piral.ts +2 -4
  50. package/src/bundler.ts +1 -1
  51. package/src/commands.ts +9 -1
  52. package/src/common/clients/yarn.ts +2 -0
  53. package/src/common/constants.ts +11 -1
  54. package/src/common/importmap.ts +1 -1
  55. package/src/common/io.ts +21 -0
  56. package/src/common/npm.ts +2 -2
  57. package/src/common/package.test.ts +3 -3
  58. package/src/common/package.ts +22 -10
  59. package/src/helpers.ts +3 -12
  60. package/src/messages.ts +61 -0
  61. package/src/types/public.ts +4 -0
@@ -62,7 +62,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
62
62
  if (typeof url !== 'string') {
63
63
  log('generalInfo_0000', `The value of "${depName}" in the importmap is not a string and will be ignored.`);
64
64
  } else if (/^https?:\/\//.test(url)) {
65
- const hash = computeHash(url);
65
+ const hash = computeHash(url).substring(0, 7);
66
66
 
67
67
  dependencies.push({
68
68
  id: `${identifier}@${hash}`,
package/src/common/io.ts CHANGED
@@ -53,6 +53,27 @@ function isLegacy() {
53
53
  return +parts[0] < 10 || (+parts[0] === 10 && +parts[1] < 12);
54
54
  }
55
55
 
56
+ export interface Destination {
57
+ outDir: string;
58
+ outFile: string;
59
+ }
60
+
61
+ export function getDestination(entryFiles: string, target: string): Destination {
62
+ const isdir = extname(target) !== '.html';
63
+
64
+ if (isdir) {
65
+ return {
66
+ outDir: target,
67
+ outFile: basename(entryFiles),
68
+ };
69
+ } else {
70
+ return {
71
+ outDir: dirname(target),
72
+ outFile: basename(target),
73
+ };
74
+ }
75
+ }
76
+
56
77
  export async function removeAny(target: string) {
57
78
  const isDir = await checkIsDirectory(target);
58
79
 
package/src/common/npm.ts CHANGED
@@ -2,12 +2,11 @@ import { resolve, relative, dirname } from 'path';
2
2
  import { createReadStream, existsSync, access, constants } from 'fs';
3
3
  import { log, fail } from './log';
4
4
  import { config } from './config';
5
- import { legacyCoreExternals } from './constants';
5
+ import { legacyCoreExternals, frameworkLibs } from './constants';
6
6
  import { inspectPackage } from './inspect';
7
7
  import { readJson, checkExists, findFile } from './io';
8
8
  import { clientTypeKeys } from '../helpers';
9
9
  import { PackageType, NpmClientType } from '../types';
10
- import { frameworkLibs } from '.';
11
10
 
12
11
  const gitPrefix = 'git+';
13
12
  const filePrefix = 'file:';
@@ -441,6 +440,7 @@ function getCoreExternals(dependencies: Record<string, string>): Array<string> {
441
440
  }
442
441
  }
443
442
 
443
+ log('frameworkLibMissing_0078', frameworkLibs);
444
444
  return [];
445
445
  }
446
446
 
@@ -61,10 +61,10 @@ describe('CLI package module', () => {
61
61
  });
62
62
 
63
63
  it('getPiralPackage returns piral package', () => {
64
- let result = getPiralPackage('app', SourceLanguage.ts, '1.0.0', 'piral-base', 'npm');
65
- expect(result.devDependencies['piral-cli-npm']).toEqual('1.0.0');
64
+ let result = getPiralPackage('app', SourceLanguage.ts, '1.0.0', 'piral-base', 'webpack');
65
+ expect(result.devDependencies['piral-cli-webpack']).toEqual('1.0.0');
66
66
  result = getPiralPackage('app', SourceLanguage.ts, '1.0.0', 'piral-base');
67
- expect(result.devDependencies).not.toContain('piral-cli-npm');
67
+ expect(result.devDependencies).not.toContain('piral-cli-webpack');
68
68
  });
69
69
 
70
70
  it('retrievePiletData error cases', async () => {
@@ -9,11 +9,27 @@ import { deepMerge } from './merge';
9
9
  import { applyTemplate } from './template';
10
10
  import { readImportmap } from './importmap';
11
11
  import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, makePiletExternals, makeExternals } from './npm';
12
- import { filesTar, filesOnceTar, declarationEntryExtensions } from './constants';
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
15
  import { Framework, FileInfo, PiletsInfo, TemplateFileLocation } from '../types';
16
16
 
17
+ function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
18
+ if (bundler && bundler !== 'none') {
19
+ if (bundlerNames.includes(bundler as any)) {
20
+ devDependencies[`piral-cli-${bundler}`] = version;
21
+ } else if (!isValidDependency(bundler)) {
22
+ //Error case - print warning and ignore
23
+ log('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
24
+ } else {
25
+ const sep = bundler.indexOf('@', 1);
26
+ const name = bundler.substring(0, sep !== -1 ? sep : bundler.length);
27
+ const version = sep !== -1 ? bundler.substring(sep + 1) : 'latest';
28
+ devDependencies[name] = version;
29
+ }
30
+ }
31
+ }
32
+
17
33
  function getDependencyVersion(
18
34
  name: string,
19
35
  devDependencies: Record<string, string | true>,
@@ -168,9 +184,7 @@ export function getPiralPackage(
168
184
  ...getDependencies(language, packages),
169
185
  };
170
186
 
171
- if (bundler && bundler !== 'none') {
172
- devDependencies[`piral-cli-${bundler}`] = `${version}`;
173
- }
187
+ appendBundler(devDependencies, bundler, version);
174
188
 
175
189
  return {
176
190
  app,
@@ -513,7 +527,7 @@ export async function patchPiletPackage(
513
527
  }, {}),
514
528
  [name]: `*`,
515
529
  };
516
- const devDependencies = {
530
+ const devDependencies: Record<string, string> = {
517
531
  ...Object.keys(typeDependencies).reduce((deps, name) => {
518
532
  deps[name] = piralDependencies[name] || typeDependencies[name];
519
533
  return deps;
@@ -537,11 +551,9 @@ export async function patchPiletPackage(
537
551
 
538
552
  if (newInfo) {
539
553
  const bundler = newInfo.bundler;
540
- devDependencies['piral-cli'] = `^${cliVersion}`;
541
-
542
- if (bundler && bundler !== 'none') {
543
- devDependencies[`piral-cli-${bundler}`] = `^${cliVersion}`;
544
- }
554
+ const version = `^${cliVersion}`;
555
+ devDependencies['piral-cli'] = version;
556
+ appendBundler(devDependencies, bundler, version);
545
557
  }
546
558
 
547
559
  const packageContent = deepMerge(packageOverrides, {
package/src/helpers.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ForceOverwrite, SourceLanguage } from './common/enums';
2
+ import { bundlerNames, frameworkLibs } from './common/constants';
2
3
  import {
3
4
  Framework,
4
5
  NpmClientType,
@@ -13,20 +14,10 @@ export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
13
14
  export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
14
15
  export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
15
16
  export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn'];
16
- export const bundlerKeys: Array<string> = [
17
- 'none',
18
- 'esbuild',
19
- 'parcel',
20
- 'parcel2',
21
- 'rollup',
22
- 'webpack',
23
- 'webpack5',
24
- 'vite',
25
- 'xbuild',
26
- ];
17
+ export const bundlerKeys: Array<string> = ['none', ...bundlerNames];
27
18
  export const availableBundlers: Array<string> = [];
28
19
  export const availableReleaseProviders: Array<string> = [];
29
- export const frameworkKeys: Array<Framework> = ['piral', 'piral-core', 'piral-base'];
20
+ export const frameworkKeys: Array<Framework> = [...frameworkLibs];
30
21
  export const forceOverwriteKeys = Object.keys(ForceOverwrite).filter((m) => typeof ForceOverwrite[m] === 'number');
31
22
 
32
23
  export function valueOfForceOverwrite(key: string): ForceOverwrite {
package/src/messages.ts CHANGED
@@ -1882,6 +1882,67 @@ export function entryFileMissing_0077(): QuickMessage {
1882
1882
  return [LogLevels.error, '0077', 'No valid entry file for the pilet found.'];
1883
1883
  }
1884
1884
 
1885
+ /**
1886
+ * @kind Warning
1887
+ *
1888
+ * @summary
1889
+ * The Piral instance is not referencing any framework package.
1890
+ *
1891
+ * @abstract
1892
+ * A Piral instance has to reference either `piral-base`, `piral-core`
1893
+ * or the whole `piral` framework package. If none of these dependencies
1894
+ * is found then no framework dependencies can be shared automatically.
1895
+ * Framework dependencies include react and react-router.
1896
+ *
1897
+ * @example
1898
+ * You might use a monorepo where most / all dependencies are declared in
1899
+ * a top-level package.json. Therefore, the package.json of the actual
1900
+ * Piral instance could look like this:
1901
+ *
1902
+ * ```json
1903
+ * {
1904
+ * "name": "my-piral-instance",
1905
+ * "version": "1.0.0",
1906
+ * "app": "./src/index.html",
1907
+ * "pilets": {}
1908
+ * }
1909
+ * ```
1910
+ *
1911
+ * While perfectly valid, this one lacks `dependencies` and `devDependencies`.
1912
+ * Surely, those are not really needed in the described case, but under
1913
+ * those conditions we cannot know what dependencies you may want to share. It
1914
+ * could be that you only reference `piral-base` and therefore don't want to
1915
+ * share anything except `tslib`. Or you use `piral-core` and also share things
1916
+ * like `react` or `react-router-dom`.
1917
+ *
1918
+ * Either way, in order to recognize that you'll need to include the correct
1919
+ * reference:
1920
+ *
1921
+ * ```json
1922
+ * {
1923
+ * "name": "my-piral-instance",
1924
+ * "version": "1.0.0",
1925
+ * "app": "./src/index.html",
1926
+ * "pilets": {},
1927
+ * "dependencies": {
1928
+ * "piral": "latest"
1929
+ * }
1930
+ * }
1931
+ * ```
1932
+ *
1933
+ * If you only want to use `piral-base` or `piral-core` then replace `piral` in
1934
+ * the example above. Also use the version that you'll like to use - `latest`
1935
+ * is just one example.
1936
+ *
1937
+ */
1938
+ export function frameworkLibMissing_0078(frameworkLibs: Array<string>): QuickMessage {
1939
+ return [
1940
+ LogLevels.warning,
1941
+ '0078',
1942
+ `Did not find any reference to either ${frameworkLibs.join(', ')}. No framework dependencies are shared.`,
1943
+ ];
1944
+ }
1945
+
1885
1946
  /**
1886
1947
  * @kind Error
1887
1948
  *
@@ -71,6 +71,8 @@ export interface DebugPiralParameters extends BaseBundleParameters {
71
71
  hmr: boolean;
72
72
  externals: Array<string>;
73
73
  publicUrl: string;
74
+ outFile: string;
75
+ outDir: string;
74
76
  entryFiles: string;
75
77
  logLevel: LogLevels;
76
78
  }
@@ -103,6 +105,8 @@ export interface DebugPiletParameters extends BaseBundleParameters {
103
105
  externals: Array<string>;
104
106
  importmap: Array<SharedDependency>;
105
107
  targetDir: string;
108
+ outFile: string;
109
+ outDir: string;
106
110
  entryModule: string;
107
111
  logLevel: LogLevels;
108
112
  version: PiletSchemaVersion;