@plaudit/webpack-extensions 2.56.2 → 2.56.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.
@@ -166,7 +166,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
166
166
  PlainEntrypointsConfigFileGeneratorPlugin.emitResolveBaseUriFunction(writer);
167
167
  for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleLists.register)) {
168
168
  writer.action("init", writer => {
169
- writer.call("plaudit_webpack_extensions__resolve_base_uri", [], { assignTo: "$base_uri" });
169
+ writer.call("plaudit_webpack_extensions__resolve_base_uri", [new php_writer_1.Expr('__DIR__')], { assignTo: "$base_uri" });
170
170
  for (const { handle, type, data } of prioritizedHandleList) {
171
171
  writer.call(`wp_register_${type}`, [handle, new php_writer_1.Expr(`$base_uri.${php_writer_1.Expr.jsonToPHPConverter(node_path_1.default.relative(emitDir, data.src))}`), ...data.rest]);
172
172
  }
@@ -245,18 +245,20 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
245
245
  * The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
246
246
  */
247
247
  static emitResolveBaseUriFunction(writer) {
248
- writer.function("plaudit_webpack_extensions__resolve_base_uri", [], () => {
248
+ writer.function("plaudit_webpack_extensions__resolve_base_uri", ["$dir"], () => {
249
249
  writer
250
- .static("$base_uri", { withTest: 'chainable' })
251
- .elseIf("str_starts_with(__DIR__, ABSPATH)")
252
- .append("$path = ltrim(substr(__DIR__, strlen(ABSPATH)), '/');")
253
- .elseIf("str_starts_with(__DIR__, '/workspace/website')")
254
- .append("$path = ltrim(substr(__DIR__, 18), '/');")
250
+ .static("$base_uris", { initializer: [] })
251
+ .if("isset($base_uris[$dir])")
252
+ .return("$base_uris[$dir]")
253
+ .elseIf("str_starts_with($dir, ABSPATH)")
254
+ .append("$path = ltrim(substr($dir, strlen(ABSPATH)), '/');")
255
+ .elseIf("str_starts_with($dir, '/workspace/website')")
256
+ .append("$path = ltrim(substr($dir, 18), '/');")
255
257
  .else()
256
258
  .call("error_log", ["UNABLE TO FIGURE OUT WHAT THE RELATIVE PATH TO THE BUILT FILES DIRECTORY SHOULD BE"])
257
259
  .append("$path = '';")
258
260
  .endIf()
259
- .append("return $base_uri = trailingslashit(home_url($path));");
261
+ .return("$base_uris[$dir] = trailingslashit(home_url($path))");
260
262
  }, { returnType: "string", includeExistenceCheck: true });
261
263
  }
262
264
  }
@@ -86,7 +86,7 @@ class SpecialAssetHandlingPlugin {
86
86
  }
87
87
  PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin.emitResolveBaseUriFunction(writer);
88
88
  writer.action("wp_head", writer => {
89
- writer.call("plaudit_webpack_extensions__resolve_base_uri", [], { assignTo: "$base_uri" }).closePHP();
89
+ writer.call("plaudit_webpack_extensions__resolve_base_uri", [new php_writer_1.Expr('__DIR__')], { assignTo: "$base_uri" }).closePHP();
90
90
  for (let [filename, { preload, fetchpriority, crossorigin }] of preloadedAssets) {
91
91
  if (!preload) {
92
92
  continue;
@@ -267,6 +267,7 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
267
267
  : (srcIsDirectory
268
268
  ? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
269
269
  : plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin'));
270
+ const extensions = processingModules ? ['.mjsx', '.mjs', '.mtsx', '.mts', '...'] : ['.jsx', '.tsx', '.ts', '...'];
270
271
  return {
271
272
  ...webpackConfig,
272
273
  devtool: 'source-map',
@@ -307,7 +308,7 @@ function commonMakeWebpackConfig(config, commonConfig, webpackConfig, srcIsDirec
307
308
  resolve: {
308
309
  ...webpackConfig.resolve,
309
310
  roots: viableRoots,
310
- extensions: ['.mjsx', '.mjs', '.mtsx', '.mts', '.jsx', '.tsx', '.ts', '...']
311
+ extensions
311
312
  },
312
313
  stats: config.stats,
313
314
  plugins: config.outputDir ? possiblePlugins : possiblePlugins.filter(plugin => plugin.constructor.name !== 'CleanWebpackPlugin'),
@@ -28,8 +28,9 @@ export declare class PHPWriter {
28
28
  indent(): this;
29
29
  outdent(): this;
30
30
  append(...lines: (string | Expr)[]): this;
31
+ return(line: string | Expr): this;
31
32
  static(variable: string, opts?: {
32
- initializer?: string | Expr;
33
+ initializer?: unknown | Expr;
33
34
  withTest?: boolean | 'chainable';
34
35
  }): this;
35
36
  linebreak(): this;
@@ -44,6 +44,9 @@ class PHPWriter {
44
44
  }
45
45
  return this;
46
46
  }
47
+ return(line) {
48
+ return this.append(`return ${line};`);
49
+ }
47
50
  static(variable, opts = {}) {
48
51
  const initializer = opts.initializer ? Expr.convertJsonToPHP(opts.initializer) : "null";
49
52
  this.append(`static ${variable} = ${initializer};`);
@@ -442,12 +442,17 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
442
442
  return makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins);
443
443
  }
444
444
  case "plain" /* SourceType.plain */:
445
- if (config.plainEntrypointsVersion > 1) {
446
- // plainEntrypoints.push({dest, src, srcRoot});
447
- // return undefined;
448
- return makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, srcIsDirectory);
445
+ if (!srcIsDirectory) {
446
+ //TODO: We need to filter this when in directory mode as well
447
+ const primarySrcRoot = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
448
+ if (!scriptExtension.test(primarySrcRoot) && !shared_1.styleExtension.test(primarySrcRoot)) {
449
+ return undefined;
450
+ }
449
451
  }
450
452
  const { plugins } = buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest, config, "plain" /* SourceType.plain */);
453
+ if (config.plainEntrypointsVersion > 1) {
454
+ return makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory);
455
+ }
451
456
  return makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory);
452
457
  }
453
458
  }).filter(cfg => cfg !== undefined);
@@ -484,8 +489,7 @@ function makePlainV1WebpackConfig(config, commonConfig, webpackConfig, dest, src
484
489
  : () => ({ [baseDest]: srcRoot });
485
490
  return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, srcIsDirectory, dest, src, srcRoot, entry, plugins);
486
491
  }
487
- function makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, srcIsDirectory) {
488
- const { plugins } = buildCommonPluginConfig(srcRoot, commonConfig.scriptExtension, webpackConfig, dest, config, "extensions" /* SourceType.extensions */);
492
+ function makePlainV2WebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins, srcIsDirectory) {
489
493
  plugins.push(new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(process.cwd(), config.outputDir, dest.locations ?? {}, config.plainEntrypointsHandlePrefix));
490
494
  const baseDest = stripExtension(dest.destination);
491
495
  const entry = srcIsDirectory // This being true implies that srcRoot is not an array
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.56.2",
3
+ "version": "2.56.4",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "/build"
@@ -18,7 +18,7 @@
18
18
  "devDependencies": {
19
19
  "@plaudit/gutenberg-api-extensions": "^2.75.0",
20
20
  "@types/browser-sync-webpack-plugin": "^2.2.5",
21
- "@types/node": "^22.17.0",
21
+ "@types/node": "^22.17.1",
22
22
  "@types/postcss-functions": "^4.0.4",
23
23
  "@types/tapable": "^2.2.7",
24
24
  "@types/webpack": "^5.28.5",
@@ -35,8 +35,8 @@
35
35
  "@plaudit/postcss-silent-extend": "^3.0.0",
36
36
  "@plaudit/postcss-strip-units": "^3.0.0",
37
37
  "@plaudit/postcss-variables": "^1.1.0",
38
- "@wordpress/dependency-extraction-webpack-plugin": "^6.27.0",
39
- "@wordpress/scripts": "^30.20.0",
38
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.28.0",
39
+ "@wordpress/scripts": "^30.21.0",
40
40
  "autoprefixer": "^10.4.21",
41
41
  "browser-sync": "^3.0.4",
42
42
  "clean-webpack-plugin": "^4.0.0",