piral-cli-webpack5 0.13.7 → 0.14.0-alpha.3154

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 (85) hide show
  1. package/README.md +20 -0
  2. package/extend-config.js +51 -14
  3. package/lib/actions.js +6 -40
  4. package/lib/actions.js.map +1 -1
  5. package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js +5 -5
  6. package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js.map +1 -1
  7. package/lib/enhancers/pilet-webpack-config-enhancer/helpers.d.ts +6 -0
  8. package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js +68 -1
  9. package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js.map +1 -1
  10. package/lib/enhancers/pilet-webpack-config-enhancer/index.d.ts +15 -2
  11. package/lib/enhancers/pilet-webpack-config-enhancer/index.js +86 -59
  12. package/lib/enhancers/pilet-webpack-config-enhancer/index.js.map +1 -1
  13. package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js +3 -3
  14. package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js.map +1 -1
  15. package/lib/helpers.d.ts +1 -1
  16. package/lib/helpers.js +1 -1
  17. package/lib/helpers.js.map +1 -1
  18. package/lib/index.js +1 -1
  19. package/lib/index.js.map +1 -1
  20. package/lib/{configs → plugins}/SheetPlugin.d.ts +3 -1
  21. package/lib/plugins/SheetPlugin.js +38 -0
  22. package/lib/plugins/SheetPlugin.js.map +1 -0
  23. package/lib/webpack/bundler-run.d.ts +2 -21
  24. package/lib/webpack/bundler-run.js +43 -45
  25. package/lib/webpack/bundler-run.js.map +1 -1
  26. package/lib/{configs → webpack}/common.d.ts +0 -0
  27. package/lib/{configs → webpack}/common.js +6 -7
  28. package/lib/webpack/common.js.map +1 -0
  29. package/lib/webpack/pilet.d.ts +19 -0
  30. package/lib/{configs → webpack}/pilet.js +30 -9
  31. package/lib/webpack/pilet.js.map +1 -0
  32. package/lib/webpack/piral.d.ts +16 -0
  33. package/lib/{configs → webpack}/piral.js +27 -9
  34. package/lib/webpack/piral.js.map +1 -0
  35. package/package.json +9 -9
  36. package/src/actions.ts +6 -21
  37. package/src/enhancers/pilet-webpack-config-enhancer/helpers.ts +75 -0
  38. package/src/enhancers/pilet-webpack-config-enhancer/index.ts +140 -68
  39. package/src/helpers.ts +1 -1
  40. package/src/index.ts +1 -1
  41. package/src/plugins/SheetPlugin.ts +37 -0
  42. package/src/webpack/bundler-run.ts +49 -57
  43. package/src/{configs → webpack}/common.ts +3 -4
  44. package/src/{configs → webpack}/pilet.ts +42 -4
  45. package/src/{configs → webpack}/piral.ts +32 -1
  46. package/lib/configs/SheetPlugin.js +0 -23
  47. package/lib/configs/SheetPlugin.js.map +0 -1
  48. package/lib/configs/common.js.map +0 -1
  49. package/lib/configs/index.d.ts +0 -2
  50. package/lib/configs/index.js +0 -15
  51. package/lib/configs/index.js.map +0 -1
  52. package/lib/configs/pilet.d.ts +0 -3
  53. package/lib/configs/pilet.js.map +0 -1
  54. package/lib/configs/piral.d.ts +0 -2
  55. package/lib/configs/piral.js.map +0 -1
  56. package/lib/webpack/bundler-calls.d.ts +0 -3
  57. package/lib/webpack/bundler-calls.js +0 -93
  58. package/lib/webpack/bundler-calls.js.map +0 -1
  59. package/lib/webpack/index.d.ts +0 -1
  60. package/lib/webpack/index.js +0 -14
  61. package/lib/webpack/index.js.map +0 -1
  62. package/lib/webpack/run-build-pilet.d.ts +0 -1
  63. package/lib/webpack/run-build-pilet.js +0 -53
  64. package/lib/webpack/run-build-pilet.js.map +0 -1
  65. package/lib/webpack/run-build-piral.d.ts +0 -1
  66. package/lib/webpack/run-build-piral.js +0 -56
  67. package/lib/webpack/run-build-piral.js.map +0 -1
  68. package/lib/webpack/run-debug-mono-piral.d.ts +0 -1
  69. package/lib/webpack/run-debug-mono-piral.js +0 -61
  70. package/lib/webpack/run-debug-mono-piral.js.map +0 -1
  71. package/lib/webpack/run-debug-pilet.d.ts +0 -1
  72. package/lib/webpack/run-debug-pilet.js +0 -77
  73. package/lib/webpack/run-debug-pilet.js.map +0 -1
  74. package/lib/webpack/run-debug-piral.d.ts +0 -1
  75. package/lib/webpack/run-debug-piral.js +0 -76
  76. package/lib/webpack/run-debug-piral.js.map +0 -1
  77. package/src/configs/SheetPlugin.ts +0 -21
  78. package/src/configs/index.ts +0 -2
  79. package/src/webpack/bundler-calls.ts +0 -107
  80. package/src/webpack/index.ts +0 -1
  81. package/src/webpack/run-build-pilet.ts +0 -81
  82. package/src/webpack/run-build-piral.ts +0 -82
  83. package/src/webpack/run-debug-mono-piral.ts +0 -65
  84. package/src/webpack/run-debug-pilet.ts +0 -93
  85. package/src/webpack/run-debug-piral.ts +0 -84
@@ -1,107 +0,0 @@
1
- import { resolve } from 'path';
2
- import { fork, ChildProcess } from 'child_process';
3
- import { Bundler, BundleDetails, BaseBundleParameters } from 'piral-cli';
4
-
5
- function getPath(name: string) {
6
- return resolve(__dirname, '..', '..', 'lib', 'webpack', `run-${name}.js`);
7
- }
8
-
9
- type BundleListener = (args: any) => void;
10
-
11
- function createBundler(cwd: string, ps: ChildProcess, args: any) {
12
- let promise = Promise.resolve();
13
- const listeners: Array<BundleListener> = [];
14
- const bundle: BundleDetails = {
15
- dir: cwd,
16
- hash: '',
17
- name: '',
18
- };
19
- const setPending = () => {
20
- promise = new Promise((done) => {
21
- const f = () => {
22
- done();
23
- bundler.off(f);
24
- };
25
- bundler.on(f);
26
- });
27
- };
28
- const bundler = {
29
- bundle,
30
- start() {
31
- ps.send({
32
- type: 'bundle',
33
- ...args,
34
- });
35
- },
36
- on(cb: BundleListener) {
37
- listeners.push(cb);
38
- },
39
- off(cb: BundleListener) {
40
- listeners.splice(listeners.indexOf(cb), 1);
41
- },
42
- emit(args: any) {
43
- [...listeners].forEach((cb) => cb(args));
44
- },
45
- ready() {
46
- return promise;
47
- },
48
- setPending,
49
- };
50
- setPending();
51
- return bundler;
52
- }
53
-
54
- export function callDynamic<T extends BaseBundleParameters>(name: string, args: T) {
55
- const cwd = args.root;
56
- return new Promise<Bundler>((resolve, reject) => {
57
- const ps = fork(getPath(name), [], { cwd });
58
- const bundler = createBundler(cwd, ps, args);
59
-
60
- ps.on('message', (msg: any) => {
61
- switch (msg.type) {
62
- case 'pending':
63
- bundler.setPending();
64
- break;
65
- case 'update':
66
- bundler.bundle.hash = msg.outHash;
67
- bundler.bundle.name = msg.outName;
68
- bundler.emit(msg.args);
69
- break;
70
- case 'done':
71
- bundler.bundle.dir = msg.outDir;
72
- return resolve(bundler);
73
- case 'fail':
74
- return reject(msg.error);
75
- }
76
- });
77
-
78
- ps.send({
79
- type: 'start',
80
- ...args,
81
- });
82
- });
83
- }
84
-
85
- export function callStatic<T extends BaseBundleParameters>(name: string, args: T) {
86
- const cwd = args.root;
87
- return new Promise<Bundler>((resolve, reject) => {
88
- const ps = fork(getPath(name), [], { cwd });
89
- const bundler = createBundler(cwd, ps, args);
90
-
91
- ps.on('message', (msg: any) => {
92
- switch (msg.type) {
93
- case 'done':
94
- bundler.bundle.dir = msg.outDir;
95
- bundler.bundle.name = msg.outFile;
96
- return resolve(bundler);
97
- case 'fail':
98
- return reject(msg.error);
99
- }
100
- });
101
-
102
- ps.send({
103
- type: 'start',
104
- ...args,
105
- });
106
- });
107
- }
@@ -1 +0,0 @@
1
- export * from './bundler-calls';
@@ -1,81 +0,0 @@
1
- import type { PiletSchemaVersion, LogLevels } from 'piral-cli';
2
- import { setStandardEnvs } from 'piral-cli/utils';
3
- import { resolve } from 'path';
4
- import { runWebpack } from './bundler-run';
5
- import { getPiletConfig } from '../configs';
6
- import { extendConfig } from '../helpers';
7
- import { defaultWebpackConfig } from '../constants';
8
-
9
- async function run(
10
- root: string,
11
- piral: string,
12
- sourceMaps: boolean,
13
- contentHash: boolean,
14
- minify: boolean,
15
- externals: Array<string>,
16
- outDir: string,
17
- outFile: string,
18
- entryModule: string,
19
- version: PiletSchemaVersion,
20
- logLevel: LogLevels,
21
- ) {
22
- setStandardEnvs({
23
- production: true,
24
- piral,
25
- root,
26
- });
27
-
28
- const otherConfigPath = resolve(root, defaultWebpackConfig);
29
- const baseConfig = await getPiletConfig(
30
- entryModule,
31
- outDir,
32
- outFile,
33
- externals,
34
- piral,
35
- version,
36
- false,
37
- sourceMaps,
38
- contentHash,
39
- minify,
40
- );
41
- const wpConfig = extendConfig(baseConfig, otherConfigPath, {
42
- watch: false,
43
- });
44
-
45
- const bundler = runWebpack(wpConfig, logLevel);
46
- return await bundler.bundle();
47
- }
48
-
49
- process.on('message', async (msg) => {
50
- switch (msg.type) {
51
- case 'start':
52
- const result = await run(
53
- process.cwd(),
54
- msg.piral,
55
- msg.sourceMaps,
56
- msg.contentHash,
57
- msg.minify,
58
- msg.externals,
59
- msg.outDir,
60
- msg.outFile,
61
- msg.entryModule,
62
- msg.version,
63
- msg.logLevel,
64
- ).catch((error) => {
65
- process.send({
66
- type: 'fail',
67
- error: error?.message,
68
- });
69
- });
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
- });
@@ -1,82 +0,0 @@
1
- import type { LogLevels } from 'piral-cli';
2
- import { setStandardEnvs } from 'piral-cli/utils';
3
- import { resolve } from 'path';
4
- import { runWebpack } from './bundler-run';
5
- import { getPiralConfig } from '../configs';
6
- import { extendConfig } from '../helpers';
7
- import { defaultWebpackConfig } from '../constants';
8
-
9
- async function run(
10
- root: string,
11
- piral: string,
12
- emulator: boolean,
13
- sourceMaps: boolean,
14
- contentHash: boolean,
15
- minify: boolean,
16
- externals: Array<string>,
17
- publicUrl: string,
18
- outDir: string,
19
- entryFiles: string,
20
- logLevel: LogLevels,
21
- ) {
22
- setStandardEnvs({
23
- production: !emulator,
24
- root,
25
- debugPiral: emulator,
26
- debugPilet: emulator,
27
- piral,
28
- dependencies: externals,
29
- });
30
-
31
- const otherConfigPath = resolve(root, defaultWebpackConfig);
32
- const baseConfig = await getPiralConfig(
33
- entryFiles,
34
- outDir,
35
- externals,
36
- emulator,
37
- sourceMaps,
38
- contentHash,
39
- minify,
40
- publicUrl,
41
- );
42
- const wpConfig = extendConfig(baseConfig, otherConfigPath, {
43
- watch: false,
44
- });
45
-
46
- const bundler = runWebpack(wpConfig, logLevel);
47
- return bundler.bundle();
48
- }
49
-
50
- process.on('message', async (msg) => {
51
- switch (msg.type) {
52
- case 'start':
53
- const result = await run(
54
- process.cwd(),
55
- msg.piral,
56
- msg.emulator,
57
- msg.sourceMaps,
58
- msg.contentHash,
59
- msg.minify,
60
- msg.externals,
61
- msg.publicUrl,
62
- msg.outDir,
63
- msg.entryFiles,
64
- msg.logLevel,
65
- ).catch((error) => {
66
- process.send({
67
- type: 'fail',
68
- error: error?.message,
69
- });
70
- });
71
-
72
- if (result) {
73
- process.send({
74
- type: 'done',
75
- outDir: result.outDir,
76
- outFile: result.outFile,
77
- });
78
- }
79
-
80
- break;
81
- }
82
- });
@@ -1,65 +0,0 @@
1
- import type { LogLevels } from 'piral-cli';
2
- import { setStandardEnvs, progress, getFreePort, logReset } from 'piral-cli/utils';
3
- import { resolve } from 'path';
4
- import { runWebpack } from './bundler-run';
5
- import { extendConfig } from '../helpers';
6
- import { getPiralConfig } from '../configs';
7
- import { defaultWebpackConfig } from '../constants';
8
-
9
- async function run(
10
- root: string,
11
- piral: string,
12
- hmr: boolean,
13
- externals: Array<string>,
14
- entryFiles: string,
15
- logLevel: LogLevels,
16
- ) {
17
- progress(`Preparing supplied Piral instance ...`);
18
-
19
- const outDir = resolve(root, 'dist', 'app');
20
-
21
- setStandardEnvs({
22
- piral,
23
- dependencies: externals,
24
- production: false,
25
- debugPiral: true,
26
- debugPilet: true,
27
- root,
28
- });
29
-
30
- const otherConfigPath = resolve(root, defaultWebpackConfig);
31
- const hmrPort = hmr ? await getFreePort(62123) : 0;
32
- const baseConfig = await getPiralConfig(entryFiles, outDir, externals, true, true, false, false, undefined, hmrPort);
33
- const wpConfig = extendConfig(baseConfig, otherConfigPath, {
34
- watch: true,
35
- });
36
-
37
- const bundler = runWebpack(wpConfig, logLevel);
38
- const bundle = await bundler.bundle();
39
- logReset();
40
- return bundle;
41
- }
42
-
43
- process.on('message', async (msg) => {
44
- switch (msg.type) {
45
- case 'start':
46
- const result = await run(process.cwd(), msg.piral, true, msg.externals, msg.entryFiles, msg.logLevel).catch(
47
- (error) => {
48
- process.send({
49
- type: 'fail',
50
- error: error?.message,
51
- });
52
- },
53
- );
54
-
55
- if (result) {
56
- process.send({
57
- type: 'done',
58
- outDir: result.outDir,
59
- outFile: result.outFile,
60
- });
61
- }
62
-
63
- break;
64
- }
65
- });
@@ -1,93 +0,0 @@
1
- import type { PiletSchemaVersion, LogLevels } from 'piral-cli';
2
- import { setStandardEnvs } from 'piral-cli/utils';
3
- import { resolve } from 'path';
4
- import { runWebpack } from './bundler-run';
5
- import { getPiletConfig } from '../configs';
6
- import { extendConfig } from '../helpers';
7
- import { defaultWebpackConfig } from '../constants';
8
-
9
- async function run(
10
- root: string,
11
- piral: string,
12
- externals: Array<string>,
13
- entryModule: string,
14
- version: PiletSchemaVersion,
15
- logLevel: LogLevels,
16
- ) {
17
- setStandardEnvs({
18
- piral,
19
- root,
20
- });
21
-
22
- const otherConfigPath = resolve(root, defaultWebpackConfig);
23
- const dist = resolve(root, 'dist');
24
- const baseConfig = await getPiletConfig(
25
- entryModule,
26
- dist,
27
- 'index.js',
28
- externals,
29
- piral,
30
- version,
31
- true,
32
- true,
33
- true,
34
- false,
35
- );
36
- const wpConfig = extendConfig(baseConfig, otherConfigPath, {
37
- watch: true,
38
- });
39
-
40
- return runWebpack(wpConfig, logLevel);
41
- }
42
-
43
- let bundler;
44
-
45
- process.on('message', async (msg) => {
46
- const root = process.cwd();
47
-
48
- switch (msg.type) {
49
- case 'bundle':
50
- if (bundler) {
51
- await bundler.bundle();
52
-
53
- bundler.on('buildStart', () => {
54
- process.send({
55
- type: 'pending',
56
- });
57
- });
58
- }
59
-
60
- break;
61
- case 'start':
62
- bundler = await run(root, msg.piral, msg.externals, msg.entryModule, msg.version, msg.logLevel).catch((error) => {
63
- process.send({
64
- type: 'fail',
65
- error: error?.message,
66
- });
67
- });
68
-
69
- if (bundler) {
70
- bundler.on('bundled', async () => {
71
- if (msg.hmr) {
72
- process.send({
73
- type: 'update',
74
- outHash: bundler.mainBundle.entryAsset.hash,
75
- outName: bundler.mainBundle.name.substr(bundler.options.outDir.length),
76
- args: {
77
- requireRef: bundler.mainBundle.requireRef,
78
- version: msg.version,
79
- root,
80
- },
81
- });
82
- }
83
- });
84
-
85
- process.send({
86
- type: 'done',
87
- outDir: bundler.options.outDir,
88
- });
89
- }
90
-
91
- break;
92
- }
93
- });
@@ -1,84 +0,0 @@
1
- import type { LogLevels } from 'piral-cli';
2
- import { setStandardEnvs, getFreePort } from 'piral-cli/utils';
3
- import { resolve } from 'path';
4
- import { runWebpack } from './bundler-run';
5
- import { getPiralConfig } from '../configs';
6
- import { extendConfig } from '../helpers';
7
- import { defaultWebpackConfig } from '../constants';
8
-
9
- async function run(
10
- root: string,
11
- piral: string,
12
- hmr: boolean,
13
- externals: Array<string>,
14
- publicUrl: string,
15
- entryFiles: string,
16
- logLevel: LogLevels,
17
- ) {
18
- setStandardEnvs({
19
- root,
20
- debugPiral: true,
21
- dependencies: externals,
22
- piral,
23
- });
24
-
25
- const otherConfigPath = resolve(root, defaultWebpackConfig);
26
- const dist = resolve(root, 'dist');
27
- const hmrPort = hmr ? await getFreePort(62123) : 0;
28
- const baseConfig = await getPiralConfig(entryFiles, dist, externals, true, true, false, false, publicUrl, hmrPort);
29
- const wpConfig = extendConfig(baseConfig, otherConfigPath, {
30
- watch: true,
31
- });
32
-
33
- return runWebpack(wpConfig, logLevel);
34
- }
35
-
36
- let bundler;
37
-
38
- process.on('message', async (msg) => {
39
- const root = process.cwd();
40
-
41
- switch (msg.type) {
42
- case 'bundle':
43
- if (bundler) {
44
- await bundler.bundle();
45
-
46
- bundler.on('buildStart', () => {
47
- process.send({
48
- type: 'pending',
49
- });
50
- });
51
- }
52
-
53
- break;
54
- case 'start':
55
- bundler = await run(root, msg.piral, msg.hmr, msg.externals, msg.publicUrl, msg.entryFiles, msg.logLevel).catch(
56
- (error) => {
57
- process.send({
58
- type: 'fail',
59
- error: error?.message,
60
- });
61
- },
62
- );
63
-
64
- if (bundler) {
65
- bundler.on('bundled', () => {
66
- process.send({
67
- type: 'update',
68
- outHash: bundler.mainBundle.entryAsset.hash,
69
- outName: 'index.html',
70
- args: {
71
- root,
72
- },
73
- });
74
- });
75
-
76
- process.send({
77
- type: 'done',
78
- outDir: bundler.options.outDir,
79
- });
80
- }
81
-
82
- break;
83
- }
84
- });