piral-cli 0.13.8 → 0.14.0-beta.3156

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 (202) hide show
  1. package/README.md +5 -2
  2. package/lib/api.js +23 -23
  3. package/lib/api.js.map +1 -1
  4. package/lib/apps/build-pilet.js +18 -16
  5. package/lib/apps/build-pilet.js.map +1 -1
  6. package/lib/apps/build-piral.js +35 -34
  7. package/lib/apps/build-piral.js.map +1 -1
  8. package/lib/apps/debug-pilet.js +28 -27
  9. package/lib/apps/debug-pilet.js.map +1 -1
  10. package/lib/apps/debug-piral.js +15 -14
  11. package/lib/apps/debug-piral.js.map +1 -1
  12. package/lib/apps/declaration-piral.js +5 -3
  13. package/lib/apps/declaration-piral.js.map +1 -1
  14. package/lib/apps/new-pilet.js +43 -39
  15. package/lib/apps/new-pilet.js.map +1 -1
  16. package/lib/apps/new-piral.js +21 -20
  17. package/lib/apps/new-piral.js.map +1 -1
  18. package/lib/apps/pack-pilet.js +6 -4
  19. package/lib/apps/pack-pilet.js.map +1 -1
  20. package/lib/apps/publish-pilet.js +48 -47
  21. package/lib/apps/publish-pilet.js.map +1 -1
  22. package/lib/apps/publish-piral.js +23 -22
  23. package/lib/apps/publish-piral.js.map +1 -1
  24. package/lib/apps/upgrade-pilet.js +34 -33
  25. package/lib/apps/upgrade-pilet.js.map +1 -1
  26. package/lib/apps/upgrade-piral.js +20 -19
  27. package/lib/apps/upgrade-piral.js.map +1 -1
  28. package/lib/apps/validate-pilet.js +13 -11
  29. package/lib/apps/validate-pilet.js.map +1 -1
  30. package/lib/apps/validate-piral.js +12 -10
  31. package/lib/apps/validate-piral.js.map +1 -1
  32. package/lib/build/bundler-calls.d.ts +3 -0
  33. package/lib/build/bundler-calls.js +107 -0
  34. package/lib/build/bundler-calls.js.map +1 -0
  35. package/lib/build/run-build-pilet.d.ts +1 -0
  36. package/lib/build/run-build-pilet.js +65 -0
  37. package/lib/build/run-build-pilet.js.map +1 -0
  38. package/lib/build/run-build-piral.d.ts +1 -0
  39. package/lib/build/run-build-piral.js +66 -0
  40. package/lib/build/run-build-piral.js.map +1 -0
  41. package/lib/build/run-debug-mono-piral.d.ts +1 -0
  42. package/lib/build/run-debug-mono-piral.js +71 -0
  43. package/lib/build/run-debug-mono-piral.js.map +1 -0
  44. package/lib/build/run-debug-pilet.d.ts +1 -0
  45. package/lib/build/run-debug-pilet.js +90 -0
  46. package/lib/build/run-debug-pilet.js.map +1 -0
  47. package/lib/build/run-debug-piral.d.ts +1 -0
  48. package/lib/build/run-debug-piral.js +86 -0
  49. package/lib/build/run-debug-piral.js.map +1 -0
  50. package/lib/bundler.js +62 -25
  51. package/lib/bundler.js.map +1 -1
  52. package/lib/cli.js +2 -2
  53. package/lib/cli.js.map +1 -1
  54. package/lib/commands.js +12 -12
  55. package/lib/commands.js.map +1 -1
  56. package/lib/common/archive.js +8 -8
  57. package/lib/common/archive.js.map +1 -1
  58. package/lib/common/browser.js +2 -2
  59. package/lib/common/browser.js.map +1 -1
  60. package/lib/common/clients/lerna.js +4 -4
  61. package/lib/common/clients/lerna.js.map +1 -1
  62. package/lib/common/clients/npm.js +12 -12
  63. package/lib/common/clients/npm.js.map +1 -1
  64. package/lib/common/clients/pnpm.js +5 -5
  65. package/lib/common/clients/pnpm.js.map +1 -1
  66. package/lib/common/clients/yarn.js +5 -5
  67. package/lib/common/clients/yarn.js.map +1 -1
  68. package/lib/common/compatibility.js +9 -9
  69. package/lib/common/compatibility.js.map +1 -1
  70. package/lib/common/config.d.ts +5 -1
  71. package/lib/common/config.js +2 -1
  72. package/lib/common/config.js.map +1 -1
  73. package/lib/common/constants.d.ts +1 -1
  74. package/lib/common/constants.js +2 -2
  75. package/lib/common/constants.js.map +1 -1
  76. package/lib/common/declaration.js +19 -19
  77. package/lib/common/declaration.js.map +1 -1
  78. package/lib/common/emulator.js +24 -23
  79. package/lib/common/emulator.js.map +1 -1
  80. package/lib/common/envs.js +3 -3
  81. package/lib/common/envs.js.map +1 -1
  82. package/lib/common/hash.d.ts +1 -0
  83. package/lib/common/hash.js +8 -3
  84. package/lib/common/hash.js.map +1 -1
  85. package/lib/common/http.d.ts +1 -0
  86. package/lib/common/http.js +28 -14
  87. package/lib/common/http.js.map +1 -1
  88. package/lib/common/injectors.js +4 -4
  89. package/lib/common/injectors.js.map +1 -1
  90. package/lib/common/inspect.js +4 -4
  91. package/lib/common/inspect.js.map +1 -1
  92. package/lib/common/io.js +77 -73
  93. package/lib/common/io.js.map +1 -1
  94. package/lib/common/language.js +2 -2
  95. package/lib/common/language.js.map +1 -1
  96. package/lib/common/log.js +8 -8
  97. package/lib/common/log.js.map +1 -1
  98. package/lib/common/npm.d.ts +3 -1
  99. package/lib/common/npm.js +68 -48
  100. package/lib/common/npm.js.map +1 -1
  101. package/lib/common/pack.js +18 -18
  102. package/lib/common/pack.js.map +1 -1
  103. package/lib/common/package.d.ts +4 -2
  104. package/lib/common/package.js +182 -81
  105. package/lib/common/package.js.map +1 -1
  106. package/lib/common/patcher.js +20 -20
  107. package/lib/common/patcher.js.map +1 -1
  108. package/lib/common/port.js +3 -3
  109. package/lib/common/port.js.map +1 -1
  110. package/lib/common/rules.js +4 -4
  111. package/lib/common/rules.js.map +1 -1
  112. package/lib/common/scaffold.js +15 -15
  113. package/lib/common/scaffold.js.map +1 -1
  114. package/lib/common/scripts.js +5 -5
  115. package/lib/common/scripts.js.map +1 -1
  116. package/lib/common/template.js +4 -4
  117. package/lib/common/template.js.map +1 -1
  118. package/lib/external/index.js +1369 -611
  119. package/lib/helpers.js +2 -2
  120. package/lib/helpers.js.map +1 -1
  121. package/lib/inject.js +2 -2
  122. package/lib/inject.js.map +1 -1
  123. package/lib/injectors/pilet.d.ts +1 -10
  124. package/lib/injectors/pilet.js +74 -27
  125. package/lib/injectors/pilet.js.map +1 -1
  126. package/lib/injectors/piral.d.ts +4 -2
  127. package/lib/injectors/piral.js +20 -5
  128. package/lib/injectors/piral.js.map +1 -1
  129. package/lib/messages.d.ts +11 -3
  130. package/lib/messages.js +11 -3
  131. package/lib/messages.js.map +1 -1
  132. package/lib/pb-cli.js +1 -1
  133. package/lib/pb-cli.js.map +1 -1
  134. package/lib/pilet-cli.js +1 -1
  135. package/lib/pilet-cli.js.map +1 -1
  136. package/lib/piral-cli.js +1 -1
  137. package/lib/piral-cli.js.map +1 -1
  138. package/lib/plugin.js +10 -10
  139. package/lib/plugin.js.map +1 -1
  140. package/lib/release.js +3 -3
  141. package/lib/release.js.map +1 -1
  142. package/lib/resolvers.js +13 -13
  143. package/lib/resolvers.js.map +1 -1
  144. package/lib/rules/index.js +7 -7
  145. package/lib/rules/index.js.map +1 -1
  146. package/lib/rules/pilet-has-externals-as-peers.js +3 -3
  147. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  148. package/lib/rules/pilet-has-no-self-reference.js +1 -1
  149. package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
  150. package/lib/rules/pilet-stays-small.js +3 -3
  151. package/lib/rules/pilet-stays-small.js.map +1 -1
  152. package/lib/rules/pilet-uses-latest-piral.js +1 -1
  153. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  154. package/lib/rules/piral-entry-ends-with-html.js +1 -1
  155. package/lib/rules/piral-entry-ends-with-html.js.map +1 -1
  156. package/lib/rules/piral-has-valid-files.js +5 -5
  157. package/lib/rules/piral-has-valid-files.js.map +1 -1
  158. package/lib/runner.js +1 -1
  159. package/lib/runner.js.map +1 -1
  160. package/lib/select.js +6 -6
  161. package/lib/select.js.map +1 -1
  162. package/lib/types/common.d.ts +8 -0
  163. package/lib/types/public.d.ts +66 -12
  164. package/package.json +3 -3
  165. package/src/apps/build-pilet.ts +7 -4
  166. package/src/apps/build-piral.ts +6 -5
  167. package/src/apps/debug-pilet.ts +3 -2
  168. package/src/apps/debug-piral.ts +2 -1
  169. package/src/apps/declaration-piral.ts +3 -1
  170. package/src/apps/new-pilet.ts +7 -3
  171. package/src/apps/new-piral.ts +2 -1
  172. package/src/apps/pack-pilet.ts +3 -1
  173. package/src/apps/publish-pilet.ts +6 -5
  174. package/src/apps/publish-piral.ts +3 -2
  175. package/src/apps/upgrade-pilet.ts +5 -4
  176. package/src/apps/upgrade-piral.ts +2 -1
  177. package/src/apps/validate-pilet.ts +5 -2
  178. package/src/apps/validate-piral.ts +3 -1
  179. package/src/build/bundler-calls.ts +121 -0
  180. package/src/build/run-build-pilet.ts +89 -0
  181. package/src/build/run-build-piral.ts +88 -0
  182. package/src/build/run-debug-mono-piral.ts +87 -0
  183. package/src/build/run-debug-pilet.ts +114 -0
  184. package/src/build/run-debug-piral.ts +106 -0
  185. package/src/bundler.test.ts +83 -68
  186. package/src/bundler.ts +52 -12
  187. package/src/common/config.ts +6 -1
  188. package/src/common/constants.ts +1 -1
  189. package/src/common/emulator.ts +1 -0
  190. package/src/common/hash.ts +5 -0
  191. package/src/common/http.ts +18 -4
  192. package/src/common/io.ts +4 -0
  193. package/src/common/npm.test.ts +14 -14
  194. package/src/common/npm.ts +21 -2
  195. package/src/common/package.ts +120 -9
  196. package/src/helpers.ts +2 -2
  197. package/src/injectors/pilet.ts +82 -22
  198. package/src/injectors/piral.test.ts +6 -5
  199. package/src/injectors/piral.ts +21 -2
  200. package/src/messages.ts +23 -15
  201. package/src/types/common.ts +9 -0
  202. package/src/types/public.ts +71 -20
@@ -0,0 +1,87 @@
1
+ import type { LogLevels, PiralBuildHandler } from '../types';
2
+ import { setStandardEnvs, progress, logReset } from '../common';
3
+ import { resolve } from 'path';
4
+
5
+ let handler: PiralBuildHandler;
6
+
7
+ function run(
8
+ root: string,
9
+ outFile: string,
10
+ outDir: string,
11
+ piral: string,
12
+ hmr: boolean,
13
+ externals: Array<string>,
14
+ entryFiles: string,
15
+ logLevel: LogLevels,
16
+ args: any,
17
+ ) {
18
+ progress(`Preparing supplied Piral instance ...`);
19
+
20
+ setStandardEnvs({
21
+ piral,
22
+ dependencies: externals,
23
+ production: false,
24
+ debugPiral: true,
25
+ debugPilet: true,
26
+ root,
27
+ });
28
+
29
+ return handler.create({
30
+ root,
31
+ entryFiles,
32
+ outFile,
33
+ outDir,
34
+ externals,
35
+ emulator: true,
36
+ sourceMaps: true,
37
+ contentHash: false,
38
+ minify: false,
39
+ publicUrl: undefined,
40
+ hmr,
41
+ logLevel,
42
+ watch: true,
43
+ args,
44
+ });
45
+ }
46
+
47
+ process.on('message', async (msg) => {
48
+ try {
49
+ switch (msg.type) {
50
+ case 'init':
51
+ handler = require(msg.path);
52
+ break;
53
+ case 'start':
54
+ const root = process.cwd();
55
+ const outDir = resolve(root, 'dist', 'app');
56
+ const bundler = await run(
57
+ root,
58
+ msg.outFile,
59
+ outDir,
60
+ msg.piral,
61
+ true,
62
+ msg.externals,
63
+ msg.entryFiles,
64
+ msg.logLevel,
65
+ msg,
66
+ );
67
+ const result = await bundler.bundle();
68
+
69
+ logReset();
70
+
71
+ if (result) {
72
+ process.send({
73
+ type: 'done',
74
+ outDir: result.outDir,
75
+ outFile: result.outFile,
76
+ });
77
+ }
78
+
79
+ break;
80
+ }
81
+ } catch (error) {
82
+ process.send({
83
+ type: 'fail',
84
+ error: error?.message,
85
+ });
86
+ }
87
+ });
@@ -0,0 +1,114 @@
1
+ import type {
2
+ PiletSchemaVersion,
3
+ LogLevels,
4
+ SharedDependency,
5
+ BundleHandlerResponse,
6
+ PiletBuildHandler,
7
+ } from '../types';
8
+ import { setStandardEnvs } from '../common';
9
+ import { resolve } from 'path';
10
+
11
+ let handler: PiletBuildHandler;
12
+ let bundler: BundleHandlerResponse;
13
+
14
+ function run(
15
+ root: string,
16
+ targetDir: string,
17
+ outDir: string,
18
+ piral: string,
19
+ externals: Array<string>,
20
+ importmap: Array<SharedDependency>,
21
+ entryModule: string,
22
+ version: PiletSchemaVersion,
23
+ logLevel: LogLevels,
24
+ args: any,
25
+ ) {
26
+ setStandardEnvs({
27
+ piral,
28
+ root,
29
+ });
30
+ return handler.create({
31
+ root,
32
+ piral,
33
+ entryModule,
34
+ targetDir,
35
+ outDir,
36
+ outFile: 'index.js',
37
+ externals,
38
+ importmap,
39
+ version,
40
+ develop: true,
41
+ sourceMaps: true,
42
+ contentHash: true,
43
+ minify: false,
44
+ logLevel,
45
+ watch: true,
46
+ args,
47
+ });
48
+ }
49
+
50
+ process.on('message', async (msg) => {
51
+ const root = process.cwd();
52
+
53
+ try {
54
+ switch (msg.type) {
55
+ case 'init':
56
+ handler = require(msg.path);
57
+ break;
58
+ case 'bundle':
59
+ if (bundler) {
60
+ await bundler.bundle();
61
+ }
62
+
63
+ break;
64
+ case 'start':
65
+ const dist = resolve(root, 'dist');
66
+ bundler = await run(
67
+ root,
68
+ msg.targetDir,
69
+ dist,
70
+ msg.piral,
71
+ msg.externals,
72
+ msg.importmap,
73
+ msg.entryModule,
74
+ msg.version,
75
+ msg.logLevel,
76
+ msg,
77
+ );
78
+
79
+ if (bundler) {
80
+ bundler.onStart(() => {
81
+ process.send({
82
+ type: 'pending',
83
+ });
84
+ });
85
+ bundler.onEnd((result) => {
86
+ if (msg.hmr) {
87
+ process.send({
88
+ type: 'update',
89
+ outHash: result.hash,
90
+ outName: result.name,
91
+ args: {
92
+ requireRef: result.requireRef,
93
+ version: msg.version,
94
+ root,
95
+ },
96
+ });
97
+ }
98
+ });
99
+
100
+ process.send({
101
+ type: 'done',
102
+ outDir: dist,
103
+ });
104
+ }
105
+
106
+ break;
107
+ }
108
+ } catch (error) {
109
+ process.send({
110
+ type: 'fail',
111
+ error: error?.message,
112
+ });
113
+ }
114
+ });
@@ -0,0 +1,106 @@
1
+ import type { BundleHandlerResponse, LogLevels, PiralBuildHandler } from '../types';
2
+ import { setStandardEnvs } from '../common';
3
+ import { resolve } from 'path';
4
+
5
+ let handler: PiralBuildHandler;
6
+ let bundler: BundleHandlerResponse;
7
+
8
+ function run(
9
+ root: string,
10
+ outFile: string,
11
+ outDir: string,
12
+ piral: string,
13
+ hmr: boolean,
14
+ externals: Array<string>,
15
+ publicUrl: string,
16
+ entryFiles: string,
17
+ logLevel: LogLevels,
18
+ args: any,
19
+ ) {
20
+ setStandardEnvs({
21
+ root,
22
+ debugPiral: true,
23
+ dependencies: externals,
24
+ piral,
25
+ });
26
+
27
+ return handler.create({
28
+ root,
29
+ entryFiles,
30
+ outFile,
31
+ outDir,
32
+ externals,
33
+ emulator: true,
34
+ sourceMaps: true,
35
+ contentHash: false,
36
+ minify: false,
37
+ publicUrl,
38
+ hmr,
39
+ logLevel,
40
+ watch: true,
41
+ args,
42
+ });
43
+ }
44
+
45
+ process.on('message', async (msg) => {
46
+ const root = process.cwd();
47
+
48
+ try {
49
+ switch (msg.type) {
50
+ case 'init':
51
+ handler = require(msg.path);
52
+ break;
53
+ case 'bundle':
54
+ if (bundler) {
55
+ await bundler.bundle();
56
+ }
57
+
58
+ break;
59
+ case 'start':
60
+ const dist = resolve(root, 'dist');
61
+ bundler = await run(
62
+ root,
63
+ msg.outFile,
64
+ dist,
65
+ msg.piral,
66
+ msg.hmr,
67
+ msg.externals,
68
+ msg.publicUrl,
69
+ msg.entryFiles,
70
+ msg.logLevel,
71
+ msg,
72
+ );
73
+
74
+ if (bundler) {
75
+ bundler.onStart(() => {
76
+ process.send({
77
+ type: 'pending',
78
+ });
79
+ });
80
+
81
+ bundler.onEnd((result) => {
82
+ process.send({
83
+ type: 'update',
84
+ outHash: result.hash,
85
+ outName: 'index.html',
86
+ args: {
87
+ root,
88
+ },
89
+ });
90
+ });
91
+
92
+ process.send({
93
+ type: 'done',
94
+ outDir: dist,
95
+ });
96
+ }
97
+
98
+ break;
99
+ }
100
+ } catch (error) {
101
+ process.send({
102
+ type: 'fail',
103
+ error: error?.message,
104
+ });
105
+ }
106
+ });
@@ -6,50 +6,60 @@ import {
6
6
  callPiralDebug,
7
7
  callDebugPiralFromMonoRepo,
8
8
  } from './bundler';
9
+ import { callDynamic, callStatic } from './build/bundler-calls';
10
+ import * as common from './common';
9
11
 
10
- let common: any;
11
- let defaults = {
12
+ const defaults = {
12
13
  bundler: false,
13
14
  };
14
15
 
16
+ jest.mock('./build/bundler-calls.ts', () => ({
17
+ callDynamic: jest.fn(() =>
18
+ Promise.resolve({
19
+ bundle: {},
20
+ }),
21
+ ),
22
+ callStatic: jest.fn(() =>
23
+ Promise.resolve({
24
+ bundle: {},
25
+ }),
26
+ ),
27
+ }));
28
+
15
29
  jest.mock('./inject', () => ({
16
30
  inject() {
17
31
  if (defaults.bundler) {
18
32
  setBundler({
19
33
  name: 'default',
20
34
  actions: {
21
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
22
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
23
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
24
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
25
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
35
+ buildPilet: { path: '' },
36
+ debugPilet: { path: '' },
37
+ buildPiral: { path: '' },
38
+ debugPiral: { path: '' },
39
+ watchPiral: { path: '' },
26
40
  } as any,
27
41
  });
28
42
  }
29
43
  },
30
44
  }));
31
45
 
32
- jest.mock(
33
- './common',
34
- () =>
35
- (common = {
36
- config: {
37
- bundler: 'parcel',
38
- },
39
- cliVersion: '1.0.0',
40
- installPackage: jest.fn(),
41
- fail(msg) {
42
- throw new Error(msg);
43
- },
44
- progress() {},
45
- log() {},
46
- determineNpmClient() {
47
- return 'npm';
48
- },
49
- patchModules: jest.fn(),
50
- logReset() {},
51
- }),
52
- );
46
+ jest.mock('./common', () => ({
47
+ config: {
48
+ bundler: 'parcel',
49
+ },
50
+ cliVersion: '1.0.0',
51
+ installPackage: jest.fn(),
52
+ fail(msg) {
53
+ throw new Error(msg);
54
+ },
55
+ progress() {},
56
+ log() {},
57
+ determineNpmClient() {
58
+ return 'npm';
59
+ },
60
+ patchModules: jest.fn(),
61
+ logReset() {},
62
+ }));
53
63
 
54
64
  describe('Piral CLI Bundler Module', () => {
55
65
  it('fails if no default bundler can be installed, but required', async () => {
@@ -64,11 +74,11 @@ describe('Piral CLI Bundler Module', () => {
64
74
 
65
75
  it('setting the bundler can resolve it properly for call pilet build', async () => {
66
76
  const actions = {
67
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
68
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
69
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
70
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
71
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
77
+ buildPilet: { path: '1' },
78
+ debugPilet: { path: '2' },
79
+ buildPiral: { path: '3' },
80
+ debugPiral: { path: '4' },
81
+ watchPiral: { path: '5' },
72
82
  };
73
83
 
74
84
  setBundler({
@@ -76,17 +86,18 @@ describe('Piral CLI Bundler Module', () => {
76
86
  actions: actions as any,
77
87
  });
78
88
 
79
- await callPiletBuild({ root: undefined } as any, 'foo1');
80
- expect(actions.buildPilet.run).toHaveBeenCalled();
89
+ const args = { root: undefined };
90
+ await callPiletBuild(args as any, 'foo1');
91
+ expect(callStatic).toHaveBeenCalledWith('build-pilet', '1', args);
81
92
  });
82
93
 
83
94
  it('setting the bundler with optimize modules calls optimize modules', async () => {
84
95
  const actions = {
85
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
86
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
87
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
88
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
89
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
96
+ buildPilet: { path: '' },
97
+ debugPilet: { path: '' },
98
+ buildPiral: { path: '' },
99
+ debugPiral: { path: '' },
100
+ watchPiral: { path: '' },
90
101
  };
91
102
 
92
103
  setBundler({
@@ -105,11 +116,11 @@ describe('Piral CLI Bundler Module', () => {
105
116
 
106
117
  it('setting the bundler can resolve it properly for call piral build', async () => {
107
118
  const actions = {
108
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
109
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
110
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
111
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
112
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
119
+ buildPilet: { path: '1' },
120
+ debugPilet: { path: '2' },
121
+ buildPiral: { path: '3' },
122
+ debugPiral: { path: '4' },
123
+ watchPiral: { path: '5' },
113
124
  };
114
125
 
115
126
  setBundler({
@@ -117,17 +128,18 @@ describe('Piral CLI Bundler Module', () => {
117
128
  actions: actions as any,
118
129
  });
119
130
 
120
- await callPiralBuild({ root: undefined } as any, 'foo2');
121
- expect(actions.buildPiral.run).toHaveBeenCalled();
131
+ const args = { root: undefined };
132
+ await callPiralBuild(args as any, 'foo2');
133
+ expect(callStatic).toHaveBeenCalledWith('build-piral', '3', args);
122
134
  });
123
135
 
124
136
  it('setting the bundler can resolve it properly for call pilet debug', async () => {
125
137
  const actions = {
126
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
127
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
128
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
129
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
130
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
138
+ buildPilet: { path: '0' },
139
+ debugPilet: { path: '1' },
140
+ buildPiral: { path: '2' },
141
+ debugPiral: { path: '3' },
142
+ watchPiral: { path: '4' },
131
143
  };
132
144
 
133
145
  setBundler({
@@ -135,17 +147,18 @@ describe('Piral CLI Bundler Module', () => {
135
147
  actions: actions as any,
136
148
  });
137
149
 
138
- await callPiletDebug({ root: undefined } as any, 'foo3');
139
- expect(actions.debugPilet.run).toHaveBeenCalled();
150
+ const args = { root: undefined };
151
+ await callPiletDebug(args as any, 'foo3');
152
+ expect(callDynamic).toHaveBeenCalledWith('debug-pilet', '1', args);
140
153
  });
141
154
 
142
155
  it('setting the bundler can resolve it properly for call piral debug', async () => {
143
156
  const actions = {
144
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
145
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
146
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
147
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
148
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
157
+ buildPilet: { path: '7' },
158
+ debugPilet: { path: '8' },
159
+ buildPiral: { path: '9' },
160
+ debugPiral: { path: '10' },
161
+ watchPiral: { path: '11' },
149
162
  };
150
163
 
151
164
  setBundler({
@@ -153,17 +166,18 @@ describe('Piral CLI Bundler Module', () => {
153
166
  actions: actions as any,
154
167
  });
155
168
 
156
- await callPiralDebug({ root: undefined } as any, 'foo4');
157
- expect(actions.debugPiral.run).toHaveBeenCalled();
169
+ const args = { root: undefined };
170
+ await callPiralDebug(args as any, 'foo4');
171
+ expect(callDynamic).toHaveBeenCalledWith('debug-piral', '10', args);
158
172
  });
159
173
 
160
174
  it('setting the bundler can resolve it properly for call piral watch', async () => {
161
175
  const actions = {
162
- buildPilet: { run: jest.fn(() => Promise.resolve({})) },
163
- debugPilet: { run: jest.fn(() => Promise.resolve({})) },
164
- buildPiral: { run: jest.fn(() => Promise.resolve({})) },
165
- debugPiral: { run: jest.fn(() => Promise.resolve({})) },
166
- watchPiral: { run: jest.fn(() => Promise.resolve({})) },
176
+ buildPilet: { path: '3' },
177
+ debugPilet: { path: '4' },
178
+ buildPiral: { path: '5' },
179
+ debugPiral: { path: '6' },
180
+ watchPiral: { path: '7' },
167
181
  };
168
182
 
169
183
  setBundler({
@@ -171,8 +185,9 @@ describe('Piral CLI Bundler Module', () => {
171
185
  actions: actions as any,
172
186
  });
173
187
 
174
- await callDebugPiralFromMonoRepo({ root: undefined } as any, 'foo5');
175
- expect(actions.watchPiral.run).toHaveBeenCalled();
188
+ const args = { root: undefined };
189
+ await callDebugPiralFromMonoRepo(args as any, 'foo5');
190
+ expect(callStatic).toHaveBeenCalledWith('debug-mono-piral', '7', args);
176
191
  });
177
192
 
178
193
  it('using a non-available bundler should fail', () => {
package/src/bundler.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { callDynamic, callStatic } from './build/bundler-calls';
1
2
  import { availableBundlers } from './helpers';
2
3
  import {
3
4
  installPackage,
@@ -20,6 +21,7 @@ import {
20
21
  DebugPiletParameters,
21
22
  BundlerDefinition,
22
23
  BaseBundleParameters,
24
+ BaseBundlerDefinition,
23
25
  } from './types';
24
26
 
25
27
  export interface QualifiedBundler {
@@ -76,12 +78,18 @@ async function findBundler(root: string, bundlerName?: string) {
76
78
  return defaultBundler;
77
79
  }
78
80
 
79
- async function prepareModules(args: BaseBundleParameters) {
81
+ async function prepareArgs<T extends BaseBundleParameters>(bundler: BaseBundlerDefinition<T>, args: T): Promise<T> {
80
82
  if (args.optimizeModules) {
81
83
  progress('Preparing modules ...');
82
84
  await patchModules(args.root, args.ignored);
83
85
  logReset();
84
86
  }
87
+
88
+ if (bundler.prepare) {
89
+ return await bundler.prepare(args);
90
+ }
91
+
92
+ return args;
85
93
  }
86
94
 
87
95
  export function setBundler(bundler: QualifiedBundler) {
@@ -94,26 +102,52 @@ export function setBundler(bundler: QualifiedBundler) {
94
102
 
95
103
  export async function callPiralDebug(args: DebugPiralParameters, bundlerName?: string): Promise<Bundler> {
96
104
  const bundler = await findBundler(args.root, bundlerName);
97
- await prepareModules(args);
98
- return await bundler.actions.debugPiral.run(args).catch((err) => fail('bundlingFailed_0174', err));
105
+
106
+ try {
107
+ const action = bundler.actions.debugPiral;
108
+ const params = await prepareArgs(action, args);
109
+ return await callDynamic('debug-piral', action.path, params);
110
+ } catch (err) {
111
+ fail('bundlingFailed_0174', err);
112
+ }
99
113
  }
100
114
 
101
115
  export async function callPiletDebug(args: DebugPiletParameters, bundlerName?: string): Promise<Bundler> {
102
116
  const bundler = await findBundler(args.root, bundlerName);
103
- await prepareModules(args);
104
- return await bundler.actions.debugPilet.run(args).catch((err) => fail('bundlingFailed_0174', err));
117
+
118
+ try {
119
+ const action = bundler.actions.debugPilet;
120
+ const params = await prepareArgs(action, args);
121
+ return await callDynamic('debug-pilet', action.path, params);
122
+ } catch (err) {
123
+ fail('bundlingFailed_0174', err);
124
+ }
105
125
  }
106
126
 
107
127
  export async function callPiralBuild(args: BuildPiralParameters, bundlerName?: string): Promise<BundleDetails> {
108
128
  const bundler = await findBundler(args.root, bundlerName);
109
- await prepareModules(args);
110
- return await bundler.actions.buildPiral.run(args).catch((err) => fail('bundlingFailed_0174', err));
129
+
130
+ try {
131
+ const action = bundler.actions.buildPiral;
132
+ const params = await prepareArgs(action, args);
133
+ const instance = await callStatic('build-piral', action.path, params);
134
+ return instance.bundle;
135
+ } catch (err) {
136
+ fail('bundlingFailed_0174', err);
137
+ }
111
138
  }
112
139
 
113
140
  export async function callPiletBuild(args: BuildPiletParameters, bundlerName?: string): Promise<BundleDetails> {
114
141
  const bundler = await findBundler(args.root, bundlerName);
115
- await prepareModules(args);
116
- return await bundler.actions.buildPilet.run(args).catch((err) => fail('bundlingFailed_0174', err));
142
+
143
+ try {
144
+ const action = bundler.actions.buildPilet;
145
+ const params = await prepareArgs(action, args);
146
+ const instance = await callStatic('build-pilet', action.path, params);
147
+ return instance.bundle;
148
+ } catch (err) {
149
+ fail('bundlingFailed_0174', err);
150
+ }
117
151
  }
118
152
 
119
153
  export async function callDebugPiralFromMonoRepo(
@@ -121,7 +155,13 @@ export async function callDebugPiralFromMonoRepo(
121
155
  bundlerName?: string,
122
156
  ): Promise<BundleDetails> {
123
157
  const bundler = await findBundler(args.root, bundlerName);
124
- await prepareModules(args);
125
- const { bundle } = await bundler.actions.watchPiral.run(args).catch((err) => fail('bundlingFailed_0174', err));
126
- return bundle;
158
+
159
+ try {
160
+ const action = bundler.actions.watchPiral;
161
+ const params = await prepareArgs(action, args);
162
+ const instance = await callStatic('debug-mono-piral', action.path, params);
163
+ return instance.bundle;
164
+ } catch (err) {
165
+ fail('bundlingFailed_0174', err);
166
+ }
127
167
  }
@@ -1,5 +1,5 @@
1
1
  import { rc } from '../external';
2
- import { NpmClientType } from '../types';
2
+ import { NpmClientType, PiletSchemaVersion } from '../types';
3
3
 
4
4
  export interface PiralCliConfig {
5
5
  /**
@@ -37,6 +37,10 @@ export interface PiralCliConfig {
37
37
  * Sets the validators configuration for a Piral instance.
38
38
  */
39
39
  validators?: Record<string, any>;
40
+ /**
41
+ * Sets the schema version to be used for pilets.
42
+ */
43
+ schemaVersion?: PiletSchemaVersion;
40
44
  }
41
45
 
42
46
  export const config: PiralCliConfig = rc('piral', {
@@ -48,4 +52,5 @@ export const config: PiralCliConfig = rc('piral', {
48
52
  bundler: 'webpack',
49
53
  piletApi: '/$pilet-api',
50
54
  validators: {},
55
+ schemaVersion: 'v2',
51
56
  });
@@ -4,7 +4,7 @@ export const filesOnceTar = 'files_once';
4
4
  export const piralBaseRoot = 'piral-base/lib/types';
5
5
  export const entryModuleExtensions = ['.ts', '.tsx', '.js', '.jsx'];
6
6
  export const declarationEntryExtensions = ['.html', '.pug', ...entryModuleExtensions];
7
- export const coreExternals = [
7
+ export const legacyCoreExternals = [
8
8
  '@dbeining/react-atom',
9
9
  '@libre/atom',
10
10
  'history',