@caweb/cli 1.15.2 → 1.15.4

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.
@@ -11,6 +11,42 @@ import {
11
11
  runCmd
12
12
  } from '../../lib/index.js';
13
13
 
14
+ const webpackAllowedFlags = [
15
+ "-c",
16
+ "--config",
17
+ "--config-name",
18
+ "-m",
19
+ "--merge",
20
+ "--disable-interpret",
21
+ "--env",
22
+ "--node-env",
23
+ "--config-node-env",
24
+ "--analyze",
25
+ "--progress",
26
+ "-j",
27
+ "--json",
28
+ "--fail-on-warnings",
29
+ "-d",
30
+ "--devtool",
31
+ "--no-devtool",
32
+ "--entry",
33
+ "-e",
34
+ "--extends",
35
+ "--mode",
36
+ "--name",
37
+ "-o",
38
+ "--output-path",
39
+ "--stats",
40
+ "--no-stats",
41
+ "-t",
42
+ "--target",
43
+ "--no-target",
44
+ "-w",
45
+ "--watch",
46
+ "--no-watch",
47
+ "--watch-options-stdin",
48
+ "--no-watch-options-stdin",
49
+ ];
14
50
 
15
51
  /**
16
52
  * Build the current project
@@ -29,40 +65,71 @@ export default async function webpack({
29
65
  externals
30
66
  } ) {
31
67
  const webpackCommand = 'build' === process.argv[2] ? 'build' : 'serve' ;
32
-
68
+
33
69
  // we use our default config from the @caweb/webpack
34
70
  const defaultConfigPath = path.resolve('node_modules', '@caweb', 'webpack', 'webpack.config.js' );
35
-
71
+
72
+ // prepend our default config to the arguments.
73
+ // users can overwrite any values by creating a webconfig of their own.
74
+ let webPackArgs = [
75
+ '--config',
76
+ defaultConfigPath,
77
+ ...process.argv.splice(3),
78
+ ];
79
+
36
80
  // Since we use @wordpress/scripts webpack config we can leverage
37
81
  // the environment variables as well.
38
82
  process.env.WP_COPY_PHP_FILES_TO_DIST = true;
39
83
  process.env.WP_NO_EXTERNALS = externals;
40
84
 
41
- // add our default config as an extension.
42
- // users can overwrite any values by creating a webconfig of their own.
43
- let webPackArgs = [
44
- '--config',
45
- defaultConfigPath
46
- ].filter(e => e);
47
-
48
85
  // CommonJS
49
86
  if( fs.existsSync( path.resolve( 'webpack.config.cjs' ) ) ){
50
87
  webPackArgs.push(
51
88
  '--config',
52
- path.resolve('webpack.config.cjs' ),
53
- '--merge'
89
+ path.resolve('webpack.config.cjs' )
54
90
  )
55
91
 
56
92
  // ESM
57
93
  }else if( fs.existsSync(path.resolve('webpack.config.js' )) ){
58
94
  webPackArgs.push(
59
95
  '--config',
60
- path.resolve('webpack.config.js' ),
61
- '--merge'
96
+ path.resolve('webpack.config.js' )
62
97
  )
63
98
 
64
99
  }
65
100
 
101
+ // add the --merge flag to allow merging configs.
102
+ webPackArgs.push( '--merge' );
103
+
104
+ let unknown = false;
105
+ let unkownArgs = [];
106
+
107
+ // we have to filter out unknown args to avoid webpack errors
108
+ webPackArgs = webPackArgs.filter( (e) => {
109
+
110
+ if( e.startsWith('--') ){
111
+ // set unknown flag
112
+ unknown = ! webpackAllowedFlags.includes(e);
113
+
114
+ // save unknown flag
115
+ if( unknown ){
116
+ unkownArgs.push(e);
117
+ }
118
+
119
+ // return if known flag
120
+ return webpackAllowedFlags.includes(e);
121
+ }else{
122
+ // save unknown args
123
+ if( unknown ){
124
+ unkownArgs.push(e);
125
+ }
126
+
127
+ // if flag was known return the value, else false
128
+ return ! unknown ? e : false;
129
+ }
130
+ }
131
+ );
132
+
66
133
  // run the webpackCommand command.
67
134
  await runCmd(
68
135
  'webpack',
@@ -72,7 +139,7 @@ export default async function webpack({
72
139
  ],
73
140
  {
74
141
  stdio: 'inherit',
75
- argv0: process.argv.join(' ')
142
+ argv0: unkownArgs.join(' ')
76
143
  }
77
144
  );
78
145
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.15.2",
3
+ "version": "1.15.4",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",