@plaudit/webpack-extensions 2.86.0 → 2.87.1
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.
- package/CHANGELOG.md +67 -0
- package/USER-GUIDE.md +7 -2
- package/build/plugins/EnhancedBlockJSONPlugin.d.ts +1 -0
- package/build/plugins/EnhancedBlockJSONPlugin.js +15 -2
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +7 -3
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +74 -10
- package/build/shared.d.ts +38 -8
- package/build/shared.js +46 -4
- package/build/utils/entrypoint-resolution-logic.d.ts +10 -0
- package/build/utils/entrypoint-resolution-logic.js +84 -0
- package/build/utils/location-encoding-filename-parser.d.ts +2 -1
- package/build/utils/location-encoding-filename-parser.js +9 -5
- package/build/wordpress-scripts-wrapper.js +58 -87
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,73 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.3.0] - 2026-03-16
|
|
9
|
+
### Added
|
|
10
|
+
- A few helper methods for tools that reference this package and care about the entrypoint resolution logic
|
|
11
|
+
|
|
12
|
+
## [3.2.2] - 2026-03-16
|
|
13
|
+
### Changed
|
|
14
|
+
- Exposed additional aspects of the entrypoint resolution logic to tools that reference this package
|
|
15
|
+
|
|
16
|
+
## [3.2.1] - 2026-03-16
|
|
17
|
+
### Added
|
|
18
|
+
- A function to expose standard flag sets to tools that reference this package
|
|
19
|
+
|
|
20
|
+
## [3.2.0] - 2026-03-16
|
|
21
|
+
### Added
|
|
22
|
+
- Support for `Location-Encoding Filenames`
|
|
23
|
+
- This comes from version `2.86.0`
|
|
24
|
+
- Support for standardized flag sets
|
|
25
|
+
- This comes from version `2.86.0`
|
|
26
|
+
|
|
27
|
+
## [3.1.2] - 2026-03-06
|
|
28
|
+
### Fixed
|
|
29
|
+
- `defer` and `async` not being supported strategies in some pipelines
|
|
30
|
+
- This comes from version `2.85.3`
|
|
31
|
+
|
|
32
|
+
## [3.1.1] - 2026-03-06
|
|
33
|
+
### Fixed
|
|
34
|
+
- Inlined scripts without any other path query parameters not being placed in the footer by default
|
|
35
|
+
- This comes from version `2.85.2`
|
|
36
|
+
|
|
37
|
+
## [3.1.0] - 2026-03-05
|
|
38
|
+
### Added
|
|
39
|
+
- Support for inlining (and otherwise controlling the enqueuing of) assets
|
|
40
|
+
- This only applies to plain entrypoints and assets declared within block.json files at present
|
|
41
|
+
- This comes from version `2.85.0`
|
|
42
|
+
|
|
43
|
+
## [3.0.1] - 2026-02-12
|
|
44
|
+
### Added
|
|
45
|
+
- Release version!
|
|
46
|
+
|
|
47
|
+
## [3.0.0-rc.3] - 2026-02-12
|
|
48
|
+
### Fixed
|
|
49
|
+
- A missing dependency
|
|
50
|
+
|
|
51
|
+
## [3.0.0-rc.2] - 2026-02-12
|
|
52
|
+
### Fixed
|
|
53
|
+
- A missing dependency
|
|
54
|
+
|
|
55
|
+
## [3.0.0-rc.1] - 2026-02-12
|
|
56
|
+
### Changed
|
|
57
|
+
- Updated all postcss plugins to their latest available versions
|
|
58
|
+
|
|
59
|
+
### Removed
|
|
60
|
+
- Legacy PostCSS features that have been integrated into modern CSS
|
|
61
|
+
- `@extends` support
|
|
62
|
+
|
|
63
|
+
## [2.87.1] - 2026-03-17
|
|
64
|
+
### Changed
|
|
65
|
+
- The `blockdir-loader.php` generation logic to use static wp_register_* calls like `plain-entrypoints-loader.php`
|
|
66
|
+
|
|
67
|
+
## [2.87.0] - 2026-03-16
|
|
68
|
+
### Added
|
|
69
|
+
- Support for a directory-based `extensions` layout
|
|
70
|
+
- This only applies to sites using extensions v2 and higher
|
|
71
|
+
|
|
72
|
+
### Internals
|
|
73
|
+
- Backported the features from `3.2.x` and `3.3.0`
|
|
74
|
+
|
|
8
75
|
## [2.86.0] - 2026-03-16
|
|
9
76
|
### Added
|
|
10
77
|
- Support for `Location-Encoding Filenames`
|
package/USER-GUIDE.md
CHANGED
|
@@ -501,8 +501,10 @@ This is used to associate additional assets with blocks that are not in control
|
|
|
501
501
|
[Specially named files](#file-naming) in a single subdirectory of `src`
|
|
502
502
|
```
|
|
503
503
|
src/extensions/
|
|
504
|
-
|
|
505
|
-
|
|
504
|
+
├─ core/paragraph/
|
|
505
|
+
│ ├─ view.ts
|
|
506
|
+
│ └─ editor.pcss
|
|
507
|
+
└─ plaudit/block-library/accordion/style.pcss
|
|
506
508
|
```
|
|
507
509
|
|
|
508
510
|
#### File Naming
|
|
@@ -513,6 +515,9 @@ Filenames **must** follow the pattern: `{kebab-case-block-name}-{type}.{ext}`
|
|
|
513
515
|
- `script-module`, `view-script-module`
|
|
514
516
|
- `setup` (this allows for PHP code to be loaded only when certain blocks are enabled and is intended for use in plugins, not themes)
|
|
515
517
|
- `ext` **must** be for a [supported file type](#supported-file-types) and **should** correspond with the extension type (basically, don't enqueue a `.css` file as a script)
|
|
518
|
+
- For convenience, everything before the `{type}` can be split into directories on the hyphens
|
|
519
|
+
- When using this format, the filenames must be [Location-Encoding Filenames](#location-encoding-filenames) or `setup.php`
|
|
520
|
+
- This is only available in extensions v2 and up
|
|
516
521
|
|
|
517
522
|
#### Notes
|
|
518
523
|
- In order to have a directory be treated as `extensions`, the config **must** include `directoryLayout: 'extensions'`
|
|
@@ -22,6 +22,7 @@ export declare class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEnt
|
|
|
22
22
|
constructor(config: VerifiedPlauditWordpressWebpackConfig, dest: VerifiedAdvancedOutputConfig, webpackRemoveEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin, context: string, entry: EntryProvider<BlockEntrypointInfo>);
|
|
23
23
|
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): Promise<void>;
|
|
24
24
|
private emitBlockLoaderFile;
|
|
25
|
+
private callRegisterFunction;
|
|
25
26
|
private transformBlocks;
|
|
26
27
|
private static extractAssetSource;
|
|
27
28
|
private static convertToScriptHandles;
|
|
@@ -136,15 +136,23 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
136
136
|
const finalizedMetadata = Object.fromEntries(Object.entries(metadata)
|
|
137
137
|
.map(([key, value]) => {
|
|
138
138
|
if (key === 'scriptHandles') {
|
|
139
|
-
return [key,
|
|
139
|
+
return [key, []];
|
|
140
140
|
}
|
|
141
141
|
if (key === 'styleHandles') {
|
|
142
|
-
return [key,
|
|
142
|
+
return [key, []];
|
|
143
|
+
}
|
|
144
|
+
if (key === 'scriptModuleHandles') {
|
|
145
|
+
return [key, []];
|
|
143
146
|
}
|
|
144
147
|
return [key, value];
|
|
145
148
|
}));
|
|
146
149
|
const writer = new php_writer_1.PHPWriter()
|
|
147
150
|
.action("init", writer => {
|
|
151
|
+
const baseUriVar = new expressions_1.Var("base_uri");
|
|
152
|
+
writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
|
|
153
|
+
this.callRegisterFunction('script', writer, baseUriVar, Object.entries(finalizedScriptHandles));
|
|
154
|
+
this.callRegisterFunction('style', writer, baseUriVar, Object.entries(finalizedStyleHandles));
|
|
155
|
+
this.callRegisterFunction('script_module', writer, baseUriVar, Object.entries(metadata.scriptModuleHandles));
|
|
148
156
|
writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [
|
|
149
157
|
expressions_1.Constants.__DIR__, // string $dir
|
|
150
158
|
new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")), // array $blockdirConfig
|
|
@@ -165,6 +173,11 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
|
|
|
165
173
|
compilation.emitAsset(node_path_1.default.join(this.dest.destination, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockDirConfig, true)));
|
|
166
174
|
}
|
|
167
175
|
}
|
|
176
|
+
callRegisterFunction(type, writer, baseUriVar, handles) {
|
|
177
|
+
for (const [name, { src, rest }] of handles) {
|
|
178
|
+
writer.call(`wp_register_${type}`, [name, src === false ? false : expressions_1.Op.concat(baseUriVar, src), ...rest]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
168
181
|
transformBlocks(compilation, collatedWorkableBlockInfo, emittingWpmlXml) {
|
|
169
182
|
const handleData = Object.values(collatedWorkableBlockInfo)
|
|
170
183
|
.flatMap(bi => bi.workableBlockEntrypointsInfo)
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
|
|
2
|
-
import { ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
|
|
2
|
+
import { MinimumViableMetadata, ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
|
|
3
3
|
import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
|
|
4
4
|
import { Compilation, type Compiler } from "webpack";
|
|
5
|
-
export
|
|
5
|
+
export type ExtensionConfigFileGeneratorMetadata = MinimumViableMetadata & {
|
|
6
|
+
extensionId: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<ExtensionConfigFileGeneratorMetadata> {
|
|
6
9
|
private readonly extensionsSrcPath;
|
|
7
10
|
private readonly dest;
|
|
8
11
|
private static readonly semaphore;
|
|
9
12
|
private setupFiles;
|
|
10
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider);
|
|
13
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, extensionsSrcPath: string, dest: VerifiedAdvancedOutputConfig, context: string, entry: EntryProvider<ExtensionConfigFileGeneratorMetadata>);
|
|
11
14
|
get extensionsDestPath(): string;
|
|
12
15
|
apply(compiler: Compiler): void;
|
|
16
|
+
private walkSubtreeForMetaInfo;
|
|
13
17
|
private generateVersionThreeConfigFile;
|
|
14
18
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
15
19
|
protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
|
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
36
|
exports.ExtensionsConfigFileGeneratorPlugin = void 0;
|
|
7
|
-
const promises_1 =
|
|
8
|
-
const node_path_1 =
|
|
37
|
+
const promises_1 = require("node:fs/promises");
|
|
38
|
+
const node_path_1 = __importStar(require("node:path"));
|
|
9
39
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
10
40
|
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
11
41
|
const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
|
|
@@ -34,24 +64,49 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
34
64
|
compilation.contextDependencies.add(this.extensionsSrcPath);
|
|
35
65
|
}
|
|
36
66
|
const emissionPromises = [];
|
|
37
|
-
for await (const { name: setupFilePath } of await promises_1.
|
|
67
|
+
for await (const { name: setupFilePath } of await (0, promises_1.opendir)(this.extensionsSrcPath, { encoding: 'utf-8' })) {
|
|
38
68
|
if (setupFilePath.endsWith("-setup.php")) {
|
|
39
69
|
const setupFileSourcePath = node_path_1.default.join(this.extensionsSrcPath, setupFilePath);
|
|
40
70
|
compilation.fileDependencies.add(setupFileSourcePath);
|
|
41
|
-
emissionPromises.push(promises_1.
|
|
71
|
+
emissionPromises.push((0, promises_1.readFile)(setupFileSourcePath).then(contents => {
|
|
42
72
|
compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
43
73
|
const blockSlug = /^(.+?)-setup.php$/i.exec(setupFilePath)?.[1];
|
|
44
74
|
return [blockSlug, setupFilePath];
|
|
45
75
|
}));
|
|
46
76
|
}
|
|
47
77
|
}
|
|
78
|
+
await this.walkSubtreeForMetaInfo(compilation, this.extensionsSrcPath, this.dest, [], emissionPromises);
|
|
48
79
|
this.setupFiles = (await Promise.all(emissionPromises))
|
|
49
80
|
.filter((item) => item[0] !== undefined).sort((a, b) => a[0].localeCompare(b[0]));
|
|
50
81
|
});
|
|
51
82
|
}
|
|
83
|
+
async walkSubtreeForMetaInfo(compilation, srcRoot, dest, parents, emissionPromises) {
|
|
84
|
+
if (!compilation.contextDependencies.has(srcRoot)) {
|
|
85
|
+
compilation.contextDependencies.add(srcRoot);
|
|
86
|
+
}
|
|
87
|
+
for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
|
|
88
|
+
if (dirent.name.startsWith("~")) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (dirent.isFile()) {
|
|
92
|
+
if (dirent.name === "setup.php") {
|
|
93
|
+
const setupFilePath = (0, node_path_1.join)(...parents, dirent.name);
|
|
94
|
+
const setupFileSourcePath = node_path_1.default.join(this.extensionsSrcPath, setupFilePath);
|
|
95
|
+
compilation.fileDependencies.add(setupFileSourcePath);
|
|
96
|
+
emissionPromises.push((0, promises_1.readFile)(setupFileSourcePath).then(contents => {
|
|
97
|
+
compilation.emitAsset(node_path_1.default.join(this.dest.destination, setupFilePath), new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
|
|
98
|
+
return [parents.join("-") /* blockSlug */, setupFilePath];
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (dirent.isDirectory()) {
|
|
103
|
+
await this.walkSubtreeForMetaInfo(compilation, (0, node_path_1.join)(srcRoot, dirent.name), dest, [...parents, dirent.name], emissionPromises);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
52
107
|
generateVersionThreeConfigFile(compilation, relevantAssetData, setupFilePaths) {
|
|
53
108
|
const handlePrefix = `${this.config.targetHandlePrefix}_block-extensions`;
|
|
54
|
-
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))
|
|
109
|
+
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))$/i;
|
|
55
110
|
const blockExtensionsConfig = {
|
|
56
111
|
metadata: { version: this.config.extensionsVersion }, scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {}
|
|
57
112
|
};
|
|
@@ -62,7 +117,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
62
117
|
return [assetPath, entry[1]];
|
|
63
118
|
});
|
|
64
119
|
for (const [assetPath, assetData] of normalizedAssetData) {
|
|
65
|
-
const match = regex.exec(
|
|
120
|
+
const match = regex.exec(assetData.extensionId);
|
|
66
121
|
if (!match) {
|
|
67
122
|
continue;
|
|
68
123
|
}
|
|
@@ -127,7 +182,16 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
|
|
|
127
182
|
});
|
|
128
183
|
}
|
|
129
184
|
processAssets(compilation, parsedAssetJsonProvider) {
|
|
130
|
-
const relevantAssetData = this.
|
|
185
|
+
const relevantAssetData = Object.fromEntries(this.getRelevantEntrypoints(compilation)
|
|
186
|
+
.map(({ entrypoint, metadata, srcPath }) => {
|
|
187
|
+
const providedData = parsedAssetJsonProvider(entrypoint, metadata);
|
|
188
|
+
if (providedData === undefined) {
|
|
189
|
+
compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
return [providedData.assetName, { ...providedData.assetData, extensionId: metadata.extensionId }];
|
|
193
|
+
})
|
|
194
|
+
.filter(item => item !== undefined));
|
|
131
195
|
const staticallyLoadedEntrypoints = Object.keys(relevantAssetData);
|
|
132
196
|
const generateLoader = (writer) => {
|
|
133
197
|
writer.require(this.extensionsDestPath + "extensions-loader.php", { dirRelative: true, once: true });
|
package/build/shared.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { PHPWriter } from "@plaudit/php-writer";
|
|
2
2
|
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
3
3
|
import { AssetInfo, Compilation, Configuration, Entrypoint, WebpackError, Compiler } from "webpack";
|
|
4
|
+
import { SourceType } from "./utils/entrypoint-resolution-logic";
|
|
4
5
|
import type { NormalizedEnqueuingControlFlags } from "./utils/path-query-and-related-helpers";
|
|
6
|
+
export * from "./utils/entrypoint-resolution-logic";
|
|
5
7
|
export type ParsedAssetsJson = Record<string, {
|
|
6
8
|
dependencies: string[];
|
|
7
9
|
version: string;
|
|
@@ -83,12 +85,6 @@ export declare function constantKeys<K extends string, V>(object: {
|
|
|
83
85
|
export declare function constantEntries<K extends string, V>(object: {
|
|
84
86
|
[k in K]: V;
|
|
85
87
|
}): [K, V][];
|
|
86
|
-
export declare const enum SourceType {
|
|
87
|
-
blocks = "blocks",
|
|
88
|
-
extensions = "extensions",
|
|
89
|
-
plain = "plain"
|
|
90
|
-
}
|
|
91
|
-
export declare function isSourceType(str: string): str is SourceType;
|
|
92
88
|
export declare function determineCurrentSourceType(dest: string | AdvancedOutputConfig, srcIsDirectory: boolean): SourceType;
|
|
93
89
|
export interface WebpackPlugin {
|
|
94
90
|
apply(compiler: Compiler): void;
|
|
@@ -146,6 +142,41 @@ export type PlauditWordpressWebpackConfig = {
|
|
|
146
142
|
omitDistDev?: boolean;
|
|
147
143
|
onlyRunPostCSSOnPCSS?: boolean;
|
|
148
144
|
};
|
|
145
|
+
export declare function applyStandards(config: PlauditWordpressWebpackConfig): {
|
|
146
|
+
readonly standard?: "2026-03-13";
|
|
147
|
+
readonly standaloneBlocks?: boolean;
|
|
148
|
+
readonly variables?: Record<string, any>;
|
|
149
|
+
readonly verbose?: boolean;
|
|
150
|
+
readonly src?: string[] | SourcesObject;
|
|
151
|
+
readonly stats?: Configuration["stats"];
|
|
152
|
+
readonly postcss?: {
|
|
153
|
+
functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions["functions"];
|
|
154
|
+
};
|
|
155
|
+
readonly externals?: Externals;
|
|
156
|
+
readonly assumeGlobalizedPlauditLibraries?: boolean;
|
|
157
|
+
readonly processTranslationConfigs?: boolean;
|
|
158
|
+
readonly combineAssetMetadata?: boolean;
|
|
159
|
+
useWebpackResourceFiltering?: boolean;
|
|
160
|
+
outputDir?: string;
|
|
161
|
+
extensionsVersion?: 1 | 2 | 3;
|
|
162
|
+
readonly targetHandlePrefix?: string;
|
|
163
|
+
plainEntrypointsVersion?: 1 | 2;
|
|
164
|
+
srcDir?: string;
|
|
165
|
+
readonly srcPrefixes?: string[];
|
|
166
|
+
useUnifiedLoader?: boolean;
|
|
167
|
+
readonly includePostInitFallback?: boolean;
|
|
168
|
+
readonly omitDistDev?: boolean;
|
|
169
|
+
onlyRunPostCSSOnPCSS?: boolean;
|
|
170
|
+
};
|
|
171
|
+
export declare function resolveStandard(standard: PlauditWordpressWebpackConfig['standard']): {
|
|
172
|
+
readonly useWebpackResourceFiltering: true;
|
|
173
|
+
readonly extensionsVersion: 3;
|
|
174
|
+
readonly plainEntrypointsVersion: 2;
|
|
175
|
+
readonly srcDir: "src";
|
|
176
|
+
readonly outputDir: "dist";
|
|
177
|
+
readonly useUnifiedLoader: true;
|
|
178
|
+
readonly onlyRunPostCSSOnPCSS: true;
|
|
179
|
+
} | undefined;
|
|
149
180
|
export type FileSegmentBlockEntrypointInfo = {
|
|
150
181
|
blockJsonOrigin: string;
|
|
151
182
|
entrypointField: EntrypointFields[number];
|
|
@@ -178,7 +209,7 @@ export declare const scriptExtension: RegExp;
|
|
|
178
209
|
export declare const scriptWithoutModuleExtension: RegExp;
|
|
179
210
|
export declare const scriptWithModuleExtension: RegExp;
|
|
180
211
|
export declare const styleExtension: RegExp;
|
|
181
|
-
export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "
|
|
212
|
+
export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "script" | "style" | "";
|
|
182
213
|
export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
|
|
183
214
|
export declare function isScriptModuleField(field: string): field is 'viewScriptModule';
|
|
184
215
|
export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
|
|
@@ -217,4 +248,3 @@ export declare function resolveLegacyBlockScriptsInFolder(folder: string): strin
|
|
|
217
248
|
* @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
|
|
218
249
|
*/
|
|
219
250
|
export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module', inlinedAsset: InlinedAsset, handleData: HandleData, file: string): void;
|
|
220
|
-
export {};
|
package/build/shared.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
@@ -10,8 +24,9 @@ exports.isRegisterScriptArgsShorthandName = isRegisterScriptArgsShorthandName;
|
|
|
10
24
|
exports.isNormalizedUsageLocations = isNormalizedUsageLocations;
|
|
11
25
|
exports.constantKeys = constantKeys;
|
|
12
26
|
exports.constantEntries = constantEntries;
|
|
13
|
-
exports.isSourceType = isSourceType;
|
|
14
27
|
exports.determineCurrentSourceType = determineCurrentSourceType;
|
|
28
|
+
exports.applyStandards = applyStandards;
|
|
29
|
+
exports.resolveStandard = resolveStandard;
|
|
15
30
|
exports.convertUsageLocationsHandleToEmittableHandle = convertUsageLocationsHandleToEmittableHandle;
|
|
16
31
|
exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
|
|
17
32
|
exports.convertEntrypointFieldForAssetType = convertEntrypointFieldForAssetType;
|
|
@@ -40,6 +55,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
40
55
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
41
56
|
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
42
57
|
const webpack_1 = require("webpack");
|
|
58
|
+
__exportStar(require("./utils/entrypoint-resolution-logic"), exports);
|
|
43
59
|
function isParsedAssetsJson(thing) {
|
|
44
60
|
if (!thing || typeof thing !== 'object') {
|
|
45
61
|
return false;
|
|
@@ -77,9 +93,6 @@ function constantKeys(object) {
|
|
|
77
93
|
function constantEntries(object) {
|
|
78
94
|
return Object.entries(object);
|
|
79
95
|
}
|
|
80
|
-
function isSourceType(str) {
|
|
81
|
-
return str === "blocks" /* SourceType.blocks */ || str === "extensions" /* SourceType.extensions */ || str === "plain" /* SourceType.plain */;
|
|
82
|
-
}
|
|
83
96
|
function determineCurrentSourceType(dest, srcIsDirectory) {
|
|
84
97
|
if (typeof dest === 'string') {
|
|
85
98
|
return srcIsDirectory ? "blocks" /* SourceType.blocks */ : "plain" /* SourceType.plain */;
|
|
@@ -96,6 +109,35 @@ function determineCurrentSourceType(dest, srcIsDirectory) {
|
|
|
96
109
|
return dest.directoryLayout;
|
|
97
110
|
}
|
|
98
111
|
}
|
|
112
|
+
function applyStandards(config) {
|
|
113
|
+
switch (config.standard) {
|
|
114
|
+
case '2026-03-13':
|
|
115
|
+
return {
|
|
116
|
+
...resolveStandard('2026-03-13'),
|
|
117
|
+
...config
|
|
118
|
+
};
|
|
119
|
+
case undefined:
|
|
120
|
+
return config;
|
|
121
|
+
default:
|
|
122
|
+
throw `Invalid standard: ${config.standard}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function resolveStandard(standard) {
|
|
126
|
+
switch (standard) {
|
|
127
|
+
case "2026-03-13":
|
|
128
|
+
return {
|
|
129
|
+
useWebpackResourceFiltering: true,
|
|
130
|
+
extensionsVersion: 3,
|
|
131
|
+
plainEntrypointsVersion: 2,
|
|
132
|
+
srcDir: "src",
|
|
133
|
+
outputDir: "dist",
|
|
134
|
+
useUnifiedLoader: true,
|
|
135
|
+
onlyRunPostCSSOnPCSS: true,
|
|
136
|
+
};
|
|
137
|
+
default:
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
99
141
|
function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
|
|
100
142
|
const emittableHandle = typeof handle === 'string' ? handle : handle?.(generatedHandle) ?? generatedHandle;
|
|
101
143
|
return emittableHandle.replaceAll("{basename}", generatedHandle);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AdvancedOutputConfig, PlauditWordpressWebpackConfig } from "../shared";
|
|
2
|
+
export declare const enum SourceType {
|
|
3
|
+
blocks = "blocks",
|
|
4
|
+
extensions = "extensions",
|
|
5
|
+
plain = "plain"
|
|
6
|
+
}
|
|
7
|
+
export declare function isSourceType(str: string): str is SourceType;
|
|
8
|
+
type Entrypoints = [string, AdvancedOutputConfig][];
|
|
9
|
+
export declare function resolveAllConfigLevelEntrypoints(config: PlauditWordpressWebpackConfig, projectRoot?: string): Record<'staticEntrypoints' | 'dynamicEntrypoints', Entrypoints>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSourceType = isSourceType;
|
|
4
|
+
exports.resolveAllConfigLevelEntrypoints = resolveAllConfigLevelEntrypoints;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const location_encoding_filename_parser_1 = require("./location-encoding-filename-parser");
|
|
8
|
+
const path_query_and_related_helpers_1 = require("./path-query-and-related-helpers");
|
|
9
|
+
function isSourceType(str) {
|
|
10
|
+
return str === "blocks" /* SourceType.blocks */ || str === "extensions" /* SourceType.extensions */ || str === "plain" /* SourceType.plain */;
|
|
11
|
+
}
|
|
12
|
+
function resolveAllConfigLevelEntrypoints(config, projectRoot = process.cwd()) {
|
|
13
|
+
const srcDir = config.srcDir ?? "";
|
|
14
|
+
const normalizeSrcAndDestination = ([rawSrc, dest]) => {
|
|
15
|
+
let [src, pathQueryParameters] = (0, path_query_and_related_helpers_1.unpackPotentiallyPrefixedFilePath)(rawSrc);
|
|
16
|
+
if (srcDir) {
|
|
17
|
+
src = (0, node_path_1.join)(srcDir, src);
|
|
18
|
+
}
|
|
19
|
+
src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(projectRoot, src) : src;
|
|
20
|
+
let resultObject;
|
|
21
|
+
if (dest.destination !== undefined && (0, node_path_1.isAbsolute)(dest.destination)) {
|
|
22
|
+
resultObject = { ...dest, destination: (0, node_path_1.relative)(projectRoot, dest.destination) };
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
resultObject = { ...dest };
|
|
26
|
+
}
|
|
27
|
+
return [src, pathQueryParameters ? { ...resultObject, pathQueryParameters } : resultObject];
|
|
28
|
+
};
|
|
29
|
+
if (Array.isArray(config.src)) {
|
|
30
|
+
return {
|
|
31
|
+
staticEntrypoints: config.src.map(s => normalizeSrcAndDestination([s, { destination: s }])),
|
|
32
|
+
dynamicEntrypoints: []
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const configSrc = config.src ?? {};
|
|
37
|
+
// We check for files with location-encoding filenames and add the pertinent ones to the sources
|
|
38
|
+
const dynamicallyIncludedEntrypoints = [];
|
|
39
|
+
if (srcDir) { // This will only work if we have a unified src root
|
|
40
|
+
const dynamicallyIncludedEntrypointsRoot = (0, node_path_1.isAbsolute)(srcDir) ? srcDir : (0, node_path_1.join)(projectRoot, srcDir);
|
|
41
|
+
using dir = (0, node_fs_1.opendirSync)(dynamicallyIncludedEntrypointsRoot);
|
|
42
|
+
for (let dirent; (dirent = dir.readSync()) !== null;) {
|
|
43
|
+
if (dirent.name in configSrc || `./${dirent.name}` in configSrc) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (dirent.isDirectory()) {
|
|
47
|
+
// If it's a directory that does not have an existing config entry, but does correspond to one of the non-plain SourceTypes, assume that it matches that source type
|
|
48
|
+
if (isSourceType(dirent.name) && dirent.name !== "plain" /* SourceType.plain */) {
|
|
49
|
+
dynamicallyIncludedEntrypoints.push([dirent.name, { directoryLayout: dirent.name }]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
using nestedDir = (0, node_fs_1.opendirSync)((0, node_path_1.join)(dynamicallyIncludedEntrypointsRoot, dirent.name));
|
|
53
|
+
for (let nestedDirent; (nestedDirent = nestedDir.readSync()) !== null;) {
|
|
54
|
+
if (!nestedDirent.isFile()) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const cfgName = (0, node_path_1.join)(dirent.name, nestedDirent.name);
|
|
58
|
+
if (cfgName in configSrc || `./${cfgName}` in configSrc) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(cfgName);
|
|
62
|
+
if (parsedFilename === undefined) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
dynamicallyIncludedEntrypoints.push([cfgName, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (dirent.isFile()) {
|
|
69
|
+
const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
|
|
70
|
+
if (parsedFilename === undefined) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
dynamicallyIncludedEntrypoints.push([dirent.name, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
staticEntrypoints: Object.entries(configSrc).map(([k, v]) => {
|
|
79
|
+
return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
|
|
80
|
+
}),
|
|
81
|
+
dynamicEntrypoints: dynamicallyIncludedEntrypoints.map(normalizeSrcAndDestination)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -6,9 +6,10 @@ export type ParsedLocationEncodingFilename = {
|
|
|
6
6
|
register?: boolean | number;
|
|
7
7
|
};
|
|
8
8
|
flags: NormalizedEnqueuingControlFlags;
|
|
9
|
+
niceName?: string;
|
|
9
10
|
};
|
|
10
11
|
export declare function parseLocationEncodingFilename(filename: string): ParsedLocationEncodingFilename | undefined;
|
|
11
|
-
export declare function parseLocationEncodingFilenameForBlock(filename: string): Omit<ParsedLocationEncodingFilename, 'locations'> & {
|
|
12
|
+
export declare function parseLocationEncodingFilenameForBlock(filename: string, errorBuilder?: (message: string, filename: string) => unknown): Omit<ParsedLocationEncodingFilename, 'locations'> & {
|
|
12
13
|
locations: Pick<RealUsageLocations, 'clientEditor' | 'clientView'>;
|
|
13
14
|
} | undefined;
|
|
14
15
|
/**
|
|
@@ -19,13 +19,14 @@ function parseLocationEncodingFilename(filename) {
|
|
|
19
19
|
const nameSegments = name.split("."); //Split always returns at least one string
|
|
20
20
|
const typeOverrideMatch = /^(?<enqueuePosition>.+)-(?<typeOverride>script|style|script-module)$|^(?<typeOverride>script|style|script-module)$/.exec(nameSegments[0]);
|
|
21
21
|
if (typeOverrideMatch) {
|
|
22
|
-
nameSegments[0] = typeOverrideMatch.groups?.["enqueuePosition"] ?? "both"; // We override the first segment with the version without
|
|
22
|
+
nameSegments[0] = typeOverrideMatch.groups?.["enqueuePosition"] ?? "both"; // We override the first segment with the version without the type override
|
|
23
23
|
type = typeOverrideMatch.groups?.["typeOverride"];
|
|
24
24
|
}
|
|
25
25
|
const inlinePattern = /^(?<inline>inline)(?:[-=](?<position>before|after))?$|^strategy[-=](?<inline>inline)(?:-(?<position>before|after))?$/;
|
|
26
26
|
const strategyPattern = /^strategy[-=](?<strategy>eager|lazy|defer|async)$|^(?<strategy>lazy|eager)$/;
|
|
27
27
|
const fetchpriorityPattern = /^fetchpriority[-=](auto|low|high)$/;
|
|
28
28
|
const bothViewAndEditorLocationPattern = /^(?:client-)?(?<both>both)(?:[-=](?<priority>-?\d+))?$/;
|
|
29
|
+
let niceName = undefined;
|
|
29
30
|
for (const segment of nameSegments) {
|
|
30
31
|
const { locationName, priority } = extractLocationFromPropertyEncodingFilenameSegment(segment);
|
|
31
32
|
if (locationName) {
|
|
@@ -67,6 +68,9 @@ function parseLocationEncodingFilename(filename) {
|
|
|
67
68
|
flags.in_footer = false;
|
|
68
69
|
break;
|
|
69
70
|
default:
|
|
71
|
+
if (niceName === undefined) {
|
|
72
|
+
niceName = segment;
|
|
73
|
+
}
|
|
70
74
|
break;
|
|
71
75
|
}
|
|
72
76
|
}
|
|
@@ -74,16 +78,16 @@ function parseLocationEncodingFilename(filename) {
|
|
|
74
78
|
if (Object.values(locations).length === 0) {
|
|
75
79
|
return undefined;
|
|
76
80
|
}
|
|
77
|
-
return { type, locations, flags };
|
|
81
|
+
return { type, locations, flags, niceName };
|
|
78
82
|
}
|
|
79
|
-
function parseLocationEncodingFilenameForBlock(filename) {
|
|
83
|
+
function parseLocationEncodingFilenameForBlock(filename, errorBuilder = shared_1.newWebpackErrorForFile) {
|
|
80
84
|
const parsedFilename = parseLocationEncodingFilename(filename);
|
|
81
85
|
if (parsedFilename !== undefined) {
|
|
82
86
|
if ((0, shared_1.constantKeys)(parsedFilename.locations).some(value => value !== 'clientView' && value !== 'clientEditor')) {
|
|
83
|
-
throw (
|
|
87
|
+
throw errorBuilder(`Block assets cannot be enqueued anywhere other than view, editor, or both. Saw: ${(0, shared_1.constantKeys)(parsedFilename).join(", ")}`, filename);
|
|
84
88
|
}
|
|
85
89
|
if (Object.values(parsedFilename.locations).some(value => typeof value === 'number')) {
|
|
86
|
-
throw (
|
|
90
|
+
throw errorBuilder(`Block assets cannot be enqueued with a priority`, filename);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
return parsedFilename;
|
|
@@ -6,8 +6,8 @@ const node_fs_1 = require("node:fs");
|
|
|
6
6
|
const promises_1 = require("node:fs/promises");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
8
|
const shared_1 = require("./shared");
|
|
9
|
+
const entrypoint_resolution_logic_1 = require("./utils/entrypoint-resolution-logic");
|
|
9
10
|
const common_config_helpers_1 = require("./utils/common-config-helpers");
|
|
10
|
-
const location_encoding_filename_parser_1 = require("./utils/location-encoding-filename-parser");
|
|
11
11
|
const path_query_and_related_helpers_1 = require("./utils/path-query-and-related-helpers");
|
|
12
12
|
const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
|
|
13
13
|
const BrowserSyncPlugin_1 = require("./plugins/BrowserSyncPlugin");
|
|
@@ -27,6 +27,7 @@ const UnifiedLoaderGenerator_1 = require("./plugins/UnifiedLoaderGenerator");
|
|
|
27
27
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
28
28
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
29
29
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
30
|
+
const location_encoding_filename_parser_1 = require("./utils/location-encoding-filename-parser");
|
|
30
31
|
function testForDuplicatedEntryPaths(sources) {
|
|
31
32
|
const seenPaths = (0, common_config_helpers_1.groupEntrypointsByAssetFile)(Array.isArray(sources)
|
|
32
33
|
? sources.map(s => typeof s === 'string' ? s : s[1].destination)
|
|
@@ -165,7 +166,7 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
function buildVerifiedConfig(config) {
|
|
168
|
-
config = applyStandards(config);
|
|
169
|
+
config = (0, shared_1.applyStandards)(config);
|
|
169
170
|
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false, omitDistDev = false, onlyRunPostCSSOnPCSS = false } = config;
|
|
170
171
|
let outputDir = config.outputDir ?? "";
|
|
171
172
|
if (outputDir && useUnifiedLoader && !omitDistDev && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
@@ -191,68 +192,8 @@ function buildVerifiedConfig(config) {
|
|
|
191
192
|
throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
if (srcDir) {
|
|
197
|
-
src = (0, node_path_1.join)(srcDir, src);
|
|
198
|
-
}
|
|
199
|
-
src = (0, node_path_1.isAbsolute)(src) ? (0, node_path_1.relative)(process.cwd(), src) : src;
|
|
200
|
-
if (dest.destination !== undefined && (0, node_path_1.isAbsolute)(dest.destination)) {
|
|
201
|
-
return [src, { ...dest, destination: (0, node_path_1.relative)(process.cwd(), dest.destination), pathQueryParameters }];
|
|
202
|
-
}
|
|
203
|
-
return [src, { ...dest, pathQueryParameters }];
|
|
204
|
-
};
|
|
205
|
-
let rawSources;
|
|
206
|
-
if (Array.isArray(config.src)) {
|
|
207
|
-
rawSources = config.src.map(s => normalizeSrcAndDestination([s, { destination: s }]));
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
const configSrc = config.src ?? {};
|
|
211
|
-
// We check for files with location-encoding filenames and add the pertinent ones to the sources
|
|
212
|
-
const dynamicallyIncludedEntrypoints = [];
|
|
213
|
-
if (srcDir) { // This will only work if we have a unified src root
|
|
214
|
-
const dynamicallyIncludedEntrypointsRoot = (0, node_path_1.isAbsolute)(srcDir) ? srcDir : (0, node_path_1.join)(process.cwd(), srcDir);
|
|
215
|
-
using dir = (0, node_fs_1.opendirSync)(dynamicallyIncludedEntrypointsRoot);
|
|
216
|
-
for (let dirent; (dirent = dir.readSync()) !== null;) {
|
|
217
|
-
if (dirent.name in configSrc || `./${dirent.name}` in configSrc) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (dirent.isDirectory()) {
|
|
221
|
-
// If it's a directory that does not have an existing config entry, but does correspond to one of the non-plain SourceTypes, assume that it matches that source type
|
|
222
|
-
if ((0, shared_1.isSourceType)(dirent.name) && dirent.name !== "plain" /* SourceType.plain */) {
|
|
223
|
-
dynamicallyIncludedEntrypoints.push([dirent.name, { directoryLayout: dirent.name }]);
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
using nestedDir = (0, node_fs_1.opendirSync)((0, node_path_1.join)(dynamicallyIncludedEntrypointsRoot, dirent.name));
|
|
227
|
-
for (let nestedDirent; (nestedDirent = nestedDir.readSync()) !== null;) {
|
|
228
|
-
if (!nestedDirent.isFile()) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const cfgName = (0, node_path_1.join)(dirent.name, nestedDirent.name);
|
|
232
|
-
if (cfgName in configSrc || `./${cfgName}` in configSrc) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(cfgName);
|
|
236
|
-
if (parsedFilename === undefined) {
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
dynamicallyIncludedEntrypoints.push([cfgName, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
else if (dirent.isFile()) {
|
|
243
|
-
const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
|
|
244
|
-
if (parsedFilename === undefined) {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
dynamicallyIncludedEntrypoints.push([dirent.name, { locations: parsedFilename.locations, enqueuingFlags: parsedFilename.flags }]);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
rawSources = [...Object.entries(configSrc), ...dynamicallyIncludedEntrypoints]
|
|
252
|
-
.map(([k, v]) => {
|
|
253
|
-
return normalizeSrcAndDestination([k, typeof v === 'boolean' ? {} : (typeof v === 'string' ? { destination: v } : v)]);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
195
|
+
const { staticEntrypoints, dynamicEntrypoints } = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(config);
|
|
196
|
+
const rawSources = [...staticEntrypoints, ...dynamicEntrypoints];
|
|
256
197
|
let variablesFilePath = undefined;
|
|
257
198
|
const currentVariables = rawVariables ?? {};
|
|
258
199
|
if (!rawVariables) {
|
|
@@ -302,25 +243,6 @@ function buildVerifiedConfig(config) {
|
|
|
302
243
|
testForDuplicatedEntryPaths(sources);
|
|
303
244
|
return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
|
|
304
245
|
}
|
|
305
|
-
function applyStandards(config) {
|
|
306
|
-
switch (config.standard) {
|
|
307
|
-
case '2026-03-13':
|
|
308
|
-
return {
|
|
309
|
-
useWebpackResourceFiltering: true,
|
|
310
|
-
extensionsVersion: 3,
|
|
311
|
-
plainEntrypointsVersion: 2,
|
|
312
|
-
srcDir: "src",
|
|
313
|
-
outputDir: "dist",
|
|
314
|
-
useUnifiedLoader: true,
|
|
315
|
-
onlyRunPostCSSOnPCSS: true,
|
|
316
|
-
...config
|
|
317
|
-
};
|
|
318
|
-
case undefined:
|
|
319
|
-
return config;
|
|
320
|
-
default:
|
|
321
|
-
throw `Invalid standard: ${config.standard}`;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
246
|
function toEffectiveWebpackDestination(destination) {
|
|
325
247
|
const pathParts = (0, node_path_1.parse)(destination);
|
|
326
248
|
return (0, node_path_1.join)(pathParts.dir, pathParts.name);
|
|
@@ -585,12 +507,22 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
585
507
|
const entry = async () => {
|
|
586
508
|
const rawEntrypoints = [];
|
|
587
509
|
for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
|
|
588
|
-
if (dirent.
|
|
589
|
-
|
|
510
|
+
if (dirent.name.startsWith("~")) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
if (dirent.isFile()) {
|
|
514
|
+
if ((commonConfig.scriptExtension.test(dirent.name) || shared_1.styleExtension.test(dirent.name))) {
|
|
590
515
|
const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
591
|
-
|
|
516
|
+
const extensionId = (0, node_path_1.parse)(dirent.name).name;
|
|
517
|
+
rawEntrypoints.push([(0, node_path_1.join)(dest.destination, (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc))), {
|
|
518
|
+
import: [absoluteSrc],
|
|
519
|
+
plauditMetadata: { dest, absoluteSrc, extensionId }
|
|
520
|
+
}]);
|
|
592
521
|
}
|
|
593
522
|
}
|
|
523
|
+
else if (dirent.isDirectory()) {
|
|
524
|
+
rawEntrypoints.push(...await walkExtensionsTree((0, node_path_1.join)(srcRoot, dirent.name), dest, [dirent.name]));
|
|
525
|
+
}
|
|
594
526
|
}
|
|
595
527
|
return Object.fromEntries(rawEntrypoints);
|
|
596
528
|
};
|
|
@@ -631,7 +563,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
631
563
|
if (canCopyFiles) {
|
|
632
564
|
plugins.push(new copy_webpack_plugin_1.default({
|
|
633
565
|
patterns: [{
|
|
634
|
-
from: config.standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)',
|
|
566
|
+
from: config.standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)', //TODO: I'm pretty sure that the dots need proper escaping
|
|
635
567
|
to: dest.destination,
|
|
636
568
|
context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */, noErrorOnMissing: true
|
|
637
569
|
}]
|
|
@@ -642,6 +574,45 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
|
|
|
642
574
|
return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, externalize, plugins, canClean && batches.length < 2);
|
|
643
575
|
}).filter(cfg => cfg !== undefined);
|
|
644
576
|
}
|
|
577
|
+
async function walkExtensionsTree(srcRoot, dest, parents) {
|
|
578
|
+
const res = [];
|
|
579
|
+
for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
|
|
580
|
+
if (dirent.name.startsWith("~")) {
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
if (dirent.isFile()) {
|
|
584
|
+
const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
|
|
585
|
+
if (parsedFilename === undefined) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
|
|
589
|
+
let destFile;
|
|
590
|
+
if (Object.keys(parsedFilename.locations).length === 1) {
|
|
591
|
+
if (parsedFilename.locations.clientView) {
|
|
592
|
+
destFile = `view-${parsedFilename.type}`;
|
|
593
|
+
}
|
|
594
|
+
else if (parsedFilename.locations.clientEditor) {
|
|
595
|
+
destFile = `editor-${parsedFilename.type}`;
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
destFile = (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc));
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
destFile = (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc));
|
|
603
|
+
}
|
|
604
|
+
const extensionId = parents.join("-") + "-" + destFile;
|
|
605
|
+
res.push([(0, node_path_1.join)(dest.destination, ...parents, destFile), {
|
|
606
|
+
import: [absoluteSrc],
|
|
607
|
+
plauditMetadata: { dest, absoluteSrc, extensionId }
|
|
608
|
+
}]);
|
|
609
|
+
}
|
|
610
|
+
else if (dirent.isDirectory()) {
|
|
611
|
+
res.push(...await walkExtensionsTree((0, node_path_1.join)(srcRoot, dirent.name), dest, [...parents, dirent.name]));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return res;
|
|
615
|
+
}
|
|
645
616
|
function stripExtension(filepath) {
|
|
646
617
|
return (0, node_path_1.join)((0, node_path_1.dirname)(filepath), (0, node_path_1.basename)(filepath, (0, node_path_1.extname)(filepath)));
|
|
647
618
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.87.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"exports": {
|
|
13
13
|
"./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js",
|
|
14
|
+
"./location-encoding-filename-parser": "./build/utils/location-encoding-filename-parser.js",
|
|
14
15
|
"./shared": "./build/shared.js"
|
|
15
16
|
},
|
|
16
17
|
"typesVersions": {
|
|
@@ -18,6 +19,9 @@
|
|
|
18
19
|
"wordpress-scripts-wrapper": [
|
|
19
20
|
"build/wordpress-scripts-wrapper.d.ts"
|
|
20
21
|
],
|
|
22
|
+
"location-encoding-filename-parser": [
|
|
23
|
+
"build/location-encoding-filename-parser.d.ts"
|
|
24
|
+
],
|
|
21
25
|
"shared": [
|
|
22
26
|
"build/shared.d.ts"
|
|
23
27
|
]
|