@plaudit/webpack-extensions 2.53.1 → 2.55.0
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/build/{wordpress-scripts-wrapper → plugins}/AdditionalDependencyInjectorPlugin.js +3 -3
- package/build/{wordpress-scripts-wrapper → plugins}/BlockJSONManagingPlugin.d.ts +5 -5
- package/build/{wordpress-scripts-wrapper → plugins}/BlockJSONManagingPlugin.js +17 -33
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +13 -0
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +173 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +24 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +244 -0
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +12 -0
- package/build/plugins/SpecialAssetHandlingPlugin.js +135 -0
- package/build/{wordpress-scripts-wrapper → plugins}/VariablesJSMonitorPlugin.js +1 -1
- package/build/{wordpress-scripts-wrapper → plugins}/WPMLConfigBuilder.d.ts +3 -2
- package/build/{wordpress-scripts-wrapper → plugins}/WPMLConfigBuilder.js +7 -3
- package/build/{wordpress-scripts-wrapper → plugins}/dependency-extraction-webpack-plugin-config-builder.d.ts +1 -7
- package/build/shared.d.ts +86 -9
- package/build/shared.js +70 -0
- package/build/utils/common-config-helpers.d.ts +26 -0
- package/build/utils/common-config-helpers.js +336 -0
- package/build/{wordpress-scripts-wrapper → utils}/php-serializer.d.ts +1 -1
- package/build/{wordpress-scripts-wrapper → utils}/php-serializer.js +1 -1
- package/build/utils/php-writer.d.ts +54 -0
- package/build/utils/php-writer.js +191 -0
- package/build/utils/pseduo-semaphore.d.ts +13 -0
- package/build/utils/pseduo-semaphore.js +63 -0
- package/build/wordpress-scripts-wrapper.d.ts +1 -27
- package/build/wordpress-scripts-wrapper.js +233 -441
- package/package.json +4 -4
- package/build/wordpress-scripts-wrapper/ExtensionsConfigFileGeneratorPlugin.d.ts +0 -6
- package/build/wordpress-scripts-wrapper/ExtensionsConfigFileGeneratorPlugin.js +0 -52
- package/build/wordpress-scripts-wrapper/SpecialAssetHandlingPlugin.d.ts +0 -7
- package/build/wordpress-scripts-wrapper/SpecialAssetHandlingPlugin.js +0 -107
- /package/build/{wordpress-scripts-wrapper → plugins}/AdditionalDependencyInjectorPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/BrowserSyncPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/BrowserSyncPlugin.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/MiniCSSExtractPluginErrorCleaner.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/MiniCSSExtractPluginErrorCleaner.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/PackageConfigSanityChecker.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/PackageConfigSanityChecker.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/VariablesJSMonitorPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/dependency-extraction-webpack-plugin-config-builder.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/static-configs.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/static-configs.js +0 -0
- /package/build/{wordpress-scripts-wrapper → utils}/json-to-php-but-with-__-injection.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → utils}/json-to-php-but-with-__-injection.js +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from "webpack";
|
|
2
|
+
export declare class SpecialAssetHandlingPlugin implements WebpackPluginInstance {
|
|
3
|
+
private readonly outputDir;
|
|
4
|
+
private static readonly semaphore;
|
|
5
|
+
private static readonly previouslyIncludedFilenames;
|
|
6
|
+
private static hasAttachedAssetCollatorForCurrentBatch;
|
|
7
|
+
private static validPathname?;
|
|
8
|
+
private readonly id;
|
|
9
|
+
constructor(outputDir: string);
|
|
10
|
+
apply(compiler: Compiler): void;
|
|
11
|
+
private collateAssets;
|
|
12
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SpecialAssetHandlingPlugin = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./PlainEntrypointsConfigFileGeneratorPlugin");
|
|
9
|
+
const php_writer_1 = require("../utils/php-writer");
|
|
10
|
+
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
11
|
+
class SpecialAssetHandlingPlugin {
|
|
12
|
+
outputDir;
|
|
13
|
+
static semaphore = new pseduo_semaphore_1.PseudoSemaphore({});
|
|
14
|
+
static previouslyIncludedFilenames = new Set(); // This allows us to ensure that assets that were previously being preloaded can be removed
|
|
15
|
+
static hasAttachedAssetCollatorForCurrentBatch = false;
|
|
16
|
+
static validPathname = undefined;
|
|
17
|
+
id;
|
|
18
|
+
constructor(outputDir) {
|
|
19
|
+
this.outputDir = outputDir;
|
|
20
|
+
this.id = Math.random().toString();
|
|
21
|
+
SpecialAssetHandlingPlugin.semaphore.register(this.id);
|
|
22
|
+
}
|
|
23
|
+
apply(compiler) {
|
|
24
|
+
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
25
|
+
SpecialAssetHandlingPlugin.hasAttachedAssetCollatorForCurrentBatch = false;
|
|
26
|
+
SpecialAssetHandlingPlugin.semaphore.reset(this.id);
|
|
27
|
+
compilation.hooks.processAssets.tapPromise(this.constructor.name, async (assets) => {
|
|
28
|
+
try {
|
|
29
|
+
const specialAssetData = {};
|
|
30
|
+
for (const pathname of Object.keys(assets)) {
|
|
31
|
+
if (!SpecialAssetHandlingPlugin.validPathname) {
|
|
32
|
+
SpecialAssetHandlingPlugin.validPathname = pathname;
|
|
33
|
+
}
|
|
34
|
+
const assetInfo = compilation.assetsInfo.get(pathname);
|
|
35
|
+
if (!assetInfo?.sourceFilename) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const filename = node_path_1.default.join(node_path_1.default.basename(node_path_1.default.dirname(pathname)), node_path_1.default.basename(pathname));
|
|
39
|
+
const queryStart = assetInfo.sourceFilename.indexOf('?');
|
|
40
|
+
if (queryStart < 0) {
|
|
41
|
+
if (SpecialAssetHandlingPlugin.previouslyIncludedFilenames.has(filename)) {
|
|
42
|
+
specialAssetData[filename] = {
|
|
43
|
+
preload: false,
|
|
44
|
+
fetchpriority: null,
|
|
45
|
+
crossorigin: null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const params = new URLSearchParams(assetInfo.sourceFilename.substring(queryStart + 1)
|
|
51
|
+
.replace(/(?:fetchPriority|crossOrigin)=/gi, str => str.toLowerCase()) //This ensures consistent capitalization of the fetchPriority parameter
|
|
52
|
+
);
|
|
53
|
+
if (params.has("preload")) {
|
|
54
|
+
SpecialAssetHandlingPlugin.validPathname = pathname;
|
|
55
|
+
specialAssetData[filename] = {
|
|
56
|
+
preload: true,
|
|
57
|
+
fetchpriority: params.get("fetchpriority"),
|
|
58
|
+
crossorigin: params.get("crossorigin")
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
|
|
63
|
+
if (!SpecialAssetHandlingPlugin.hasAttachedAssetCollatorForCurrentBatch) {
|
|
64
|
+
SpecialAssetHandlingPlugin.hasAttachedAssetCollatorForCurrentBatch = true;
|
|
65
|
+
const collatedSpecialAssetData = (await SpecialAssetHandlingPlugin.semaphore.wait())
|
|
66
|
+
.reduce((collector, current) => ({ ...collector, ...current }), {});
|
|
67
|
+
this.collateAssets(compilation, collatedSpecialAssetData);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
SpecialAssetHandlingPlugin.semaphore.reject(this.id);
|
|
72
|
+
throw e;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
collateAssets(compilation, collatedSpecialAssetData) {
|
|
78
|
+
const preloadedAssets = Object.entries(collatedSpecialAssetData)
|
|
79
|
+
.filter(([_, { preload }]) => preload)
|
|
80
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
81
|
+
const outputFile = this.outputDir ? "special-assets.php" : node_path_1.default.join(node_path_1.default.dirname(node_path_1.default.dirname(SpecialAssetHandlingPlugin.validPathname)), "special-assets.php");
|
|
82
|
+
const writer = new php_writer_1.PHPWriter();
|
|
83
|
+
if (!preloadedAssets.length) {
|
|
84
|
+
writer.emitAsset(compilation, outputFile);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin.emitResolveBaseUriFunction(writer);
|
|
88
|
+
writer.action("wp_head", writer => {
|
|
89
|
+
writer.call("plaudit_webpack_extensions__resolve_base_uri", [], { assignTo: "$base_uri" }).closePHP();
|
|
90
|
+
for (let [filename, { preload, fetchpriority, crossorigin }] of preloadedAssets) {
|
|
91
|
+
if (!preload) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let fileExtension = node_path_1.default.extname(filename);
|
|
95
|
+
if (fileExtension.startsWith(".")) {
|
|
96
|
+
fileExtension = fileExtension.substring(1).toLowerCase();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
fileExtension = fileExtension.toLowerCase();
|
|
100
|
+
}
|
|
101
|
+
const attributes = [];
|
|
102
|
+
if (["woff", "woff2", "ttf", "otf", "eot"].includes(fileExtension)) {
|
|
103
|
+
if (!crossorigin) {
|
|
104
|
+
crossorigin = "anonymous";
|
|
105
|
+
}
|
|
106
|
+
attributes.push(["as", "font"], ["type", `font/${fileExtension}`]);
|
|
107
|
+
}
|
|
108
|
+
else if (fileExtension === "svg") {
|
|
109
|
+
attributes.push(["as", "image"], ["type", `image/svg+xml`]);
|
|
110
|
+
}
|
|
111
|
+
else if (fileExtension === "jpeg" || fileExtension === "jpg") {
|
|
112
|
+
attributes.push(["as", "image"], ["type", `image/jpeg`]);
|
|
113
|
+
}
|
|
114
|
+
else if (["png", "webp", "avif", "gif", "bmp"].includes(fileExtension)) {
|
|
115
|
+
attributes.push(["as", "image"], ["type", `image/${fileExtension}`]);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
compilation.errors.push(new Error(`Encountered preloading markup on an unsupported file extension (${fileExtension})`));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (fetchpriority && fetchpriority !== 'auto') {
|
|
122
|
+
attributes.push(["fetchpriority", fetchpriority]);
|
|
123
|
+
}
|
|
124
|
+
if (crossorigin || crossorigin === "") {
|
|
125
|
+
attributes.push(["crossorigin", crossorigin]);
|
|
126
|
+
}
|
|
127
|
+
const dynamicAttrs = attributes.map(([k, v]) => v ? `${k}="${v}"` : k).join(" ");
|
|
128
|
+
writer.append(`<link rel="preload" href="<?= esc_url($base_uri.'${filename}') ?>" ${dynamicAttrs}>`);
|
|
129
|
+
}
|
|
130
|
+
writer.openPHP();
|
|
131
|
+
});
|
|
132
|
+
writer.emitAsset(compilation, outputFile);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.SpecialAssetHandlingPlugin = SpecialAssetHandlingPlugin;
|
|
@@ -7,7 +7,7 @@ class VariablesJSMonitorPlugin {
|
|
|
7
7
|
this.variablesFilePath = variablesFilePath;
|
|
8
8
|
}
|
|
9
9
|
apply(compiler) {
|
|
10
|
-
compiler.hooks.make.tap(
|
|
10
|
+
compiler.hooks.make.tap(this.constructor.name, compilation => {
|
|
11
11
|
if (!compilation.fileDependencies.has(this.variablesFilePath)) {
|
|
12
12
|
compilation.fileDependencies.add(this.variablesFilePath);
|
|
13
13
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
1
|
import { BlockJSONManagingPlugin } from "./BlockJSONManagingPlugin";
|
|
2
|
+
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
3
3
|
export declare class WPMLConfigBuilderPlugin implements WebpackPluginInstance {
|
|
4
4
|
private readonly blockJSONManagingPlugin;
|
|
5
|
+
private readonly destDir;
|
|
5
6
|
private static jsdomInstance?;
|
|
6
7
|
private static domParser?;
|
|
7
8
|
private static xmlSerializer?;
|
|
8
9
|
private readonly parsedDocumentsCache;
|
|
9
|
-
constructor(blockJSONManagingPlugin: BlockJSONManagingPlugin);
|
|
10
|
+
constructor(blockJSONManagingPlugin: BlockJSONManagingPlugin, destDir: string);
|
|
10
11
|
apply(compiler: Compiler): void;
|
|
11
12
|
private static getJSDOMInstance;
|
|
12
13
|
private static getDOMParser;
|
|
@@ -5,17 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.WPMLConfigBuilderPlugin = void 0;
|
|
7
7
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const jsdom_1 = require("jsdom");
|
|
9
10
|
const webpack_1 = require("webpack");
|
|
10
11
|
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
11
12
|
class WPMLConfigBuilderPlugin {
|
|
12
13
|
blockJSONManagingPlugin;
|
|
14
|
+
destDir;
|
|
13
15
|
static jsdomInstance;
|
|
14
16
|
static domParser;
|
|
15
17
|
static xmlSerializer;
|
|
16
18
|
parsedDocumentsCache = new Map();
|
|
17
|
-
constructor(blockJSONManagingPlugin) {
|
|
19
|
+
constructor(blockJSONManagingPlugin, destDir) {
|
|
18
20
|
this.blockJSONManagingPlugin = blockJSONManagingPlugin;
|
|
21
|
+
this.destDir = destDir;
|
|
19
22
|
}
|
|
20
23
|
apply(compiler) {
|
|
21
24
|
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
@@ -30,8 +33,9 @@ class WPMLConfigBuilderPlugin {
|
|
|
30
33
|
Promise.all(entrypoint.origins.map(origin => origin.request).filter(request => request.endsWith("block.json"))
|
|
31
34
|
.map(async (request) => JSON.parse(await promises_1.default.readFile(request, 'utf8'))))
|
|
32
35
|
]);
|
|
36
|
+
const wpmlEmitPath = node_path_1.default.join(this.destDir, "wpml-config.xml");
|
|
33
37
|
for (const name of Object.keys(assets)) {
|
|
34
|
-
if (name.startsWith("wpml-config.xml")) {
|
|
38
|
+
if (name.startsWith("wpml-config.xml") || name.startsWith(wpmlEmitPath)) {
|
|
35
39
|
compilation.deleteAsset(name);
|
|
36
40
|
}
|
|
37
41
|
}
|
|
@@ -141,7 +145,7 @@ class WPMLConfigBuilderPlugin {
|
|
|
141
145
|
appendNamedElementsListToConfig("shortcodes", mergedConfig.shortcodes, config);
|
|
142
146
|
appendNamedElementsListToConfig("taxonomies", mergedConfig.taxonomies, config);
|
|
143
147
|
this.blockJSONManagingPlugin.additionalMetadata.set("wpml-config", true);
|
|
144
|
-
compilation[
|
|
148
|
+
compilation[wpmlEmitPath in compilation.assets ? 'updateAsset' : 'emitAsset'](wpmlEmitPath, new webpack_1.sources.RawSource(WPMLConfigBuilderPlugin.prettyPrintXML(config)));
|
|
145
149
|
});
|
|
146
150
|
});
|
|
147
151
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
2
|
+
import type { Externals } from "../shared";
|
|
2
3
|
import type { Configuration } from "webpack";
|
|
3
|
-
export type IndividualExternalDepConfig = string | {
|
|
4
|
-
import?: string | [string, ...string[]];
|
|
5
|
-
handle: string;
|
|
6
|
-
};
|
|
7
|
-
export type Externals = {
|
|
8
|
-
[dep: string]: IndividualExternalDepConfig;
|
|
9
|
-
};
|
|
10
4
|
export declare function makeDependencyExtractionPlugin(externals: Externals | undefined, assumeGlobalizedPlauditLibraries: boolean, wantsGroupedDepData: boolean, externalizing: Required<Configuration>['output']['library']): {
|
|
11
5
|
instance: DependencyExtractionWebpackPlugin;
|
|
12
6
|
addExternalizedDep: (dep: string) => void;
|
package/build/shared.d.ts
CHANGED
|
@@ -1,11 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
2
|
+
import type { Configuration } from "webpack";
|
|
3
|
+
export type RawAssetData = Record<string, {
|
|
4
|
+
dependencies: string[];
|
|
5
|
+
version: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function isRawAssetData(thing: any): thing is RawAssetData;
|
|
8
|
+
type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
|
|
9
|
+
export type HandleData = {
|
|
10
|
+
src: string;
|
|
11
|
+
rest: BaseRestType | [...BaseRestType, {
|
|
12
|
+
strategy?: 'defer' | 'async';
|
|
13
|
+
in_footer?: boolean;
|
|
14
|
+
} | boolean];
|
|
15
|
+
};
|
|
16
|
+
export declare const standardLocationNames: readonly ["clientView", "clientEditor", "admin", "login", "customizer", "analytics"];
|
|
17
|
+
export type StandardLocationNames = typeof standardLocationNames[number];
|
|
18
|
+
export type UsageLocations = {
|
|
19
|
+
[K in StandardLocationNames]?: boolean | number;
|
|
20
|
+
} & {
|
|
21
|
+
register?: boolean | number;
|
|
22
|
+
handle?: string;
|
|
23
|
+
registerScriptArgs?: {
|
|
24
|
+
strategy?: 'defer' | 'async';
|
|
25
|
+
in_footer?: boolean;
|
|
26
|
+
} | boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare const enum SourceType {
|
|
29
|
+
blocks = "blocks",
|
|
30
|
+
extensions = "extensions",
|
|
31
|
+
plain = "plain"
|
|
32
|
+
}
|
|
33
|
+
export declare function determineCurrentSourceType(dest: string | AdvancedOutputConfig, srcIsDirectory: boolean): SourceType;
|
|
34
|
+
export type IndividualExternalDepConfig = string | {
|
|
35
|
+
import?: string | [string, ...string[]];
|
|
36
|
+
handle: string;
|
|
37
|
+
};
|
|
38
|
+
export type Externals = {
|
|
39
|
+
[dep: string]: IndividualExternalDepConfig;
|
|
40
|
+
};
|
|
41
|
+
export type AdvancedOutputConfig = {
|
|
42
|
+
destination: string;
|
|
43
|
+
withLegacyBlocksIn?: string | undefined;
|
|
44
|
+
additionalDependencies?: string[];
|
|
45
|
+
directoryLayout?: SourceType;
|
|
46
|
+
assumeGlobalizedPlauditLibraries?: boolean;
|
|
47
|
+
externalize?: Required<Configuration>['output']['library'];
|
|
48
|
+
bundleAnalyzer?: boolean;
|
|
49
|
+
locations?: UsageLocations;
|
|
50
|
+
};
|
|
51
|
+
export type PlauditWordpressWebpackConfig = {
|
|
52
|
+
standaloneBlocks?: boolean;
|
|
53
|
+
variables?: Record<string, any>;
|
|
54
|
+
verbose?: boolean;
|
|
55
|
+
src: string[] | Record<string, string | AdvancedOutputConfig>;
|
|
56
|
+
stats?: Configuration['stats'];
|
|
57
|
+
postcss?: {
|
|
58
|
+
functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions['functions'];
|
|
10
59
|
};
|
|
60
|
+
externals?: Externals;
|
|
61
|
+
assumeGlobalizedPlauditLibraries?: boolean;
|
|
62
|
+
processTranslationConfigs?: boolean;
|
|
63
|
+
combineAssetMetadata?: boolean;
|
|
64
|
+
useWebpackResourceFiltering?: boolean;
|
|
65
|
+
outputDir?: string;
|
|
66
|
+
extensionsVersion?: 1 | 2;
|
|
67
|
+
plainEntrypointsHandlePrefix?: string;
|
|
68
|
+
plainEntrypointsVersion?: 1 | 2;
|
|
69
|
+
srcDir?: string;
|
|
70
|
+
};
|
|
71
|
+
export declare function makeEmittableConfigPHP(data: any): string;
|
|
72
|
+
export type Sync<V> = {
|
|
73
|
+
sync: Promise<V>;
|
|
74
|
+
resolve(v: V): void;
|
|
75
|
+
reject(): void;
|
|
76
|
+
done: boolean;
|
|
77
|
+
};
|
|
78
|
+
type Readiness<V> = {
|
|
79
|
+
nonModule: Sync<V>;
|
|
80
|
+
module: Sync<V>;
|
|
11
81
|
};
|
|
82
|
+
export declare class SyncsManager<V> {
|
|
83
|
+
private readonly readinessMapping;
|
|
84
|
+
get(name: string): Readiness<V>;
|
|
85
|
+
private makeSync;
|
|
86
|
+
}
|
|
87
|
+
export declare function leadingSlashIt(pathOrSomething: string): string;
|
|
88
|
+
export {};
|
package/build/shared.js
CHANGED
|
@@ -1,2 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SyncsManager = exports.standardLocationNames = void 0;
|
|
7
|
+
exports.isRawAssetData = isRawAssetData;
|
|
8
|
+
exports.determineCurrentSourceType = determineCurrentSourceType;
|
|
9
|
+
exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
|
|
10
|
+
exports.leadingSlashIt = leadingSlashIt;
|
|
11
|
+
const json_to_php_but_with____injection_1 = __importDefault(require("./utils/json-to-php-but-with-__-injection"));
|
|
12
|
+
function isRawAssetData(thing) {
|
|
13
|
+
if (!thing || typeof thing !== 'object') {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
for (const value of Object.values(thing)) {
|
|
17
|
+
if ((!value || typeof value !== 'object') ||
|
|
18
|
+
(!('dependencies' in value) || !Array.isArray(value.dependencies) || value.dependencies.some(d => typeof d !== 'string')) ||
|
|
19
|
+
(!('version' in value) || !value.version || typeof value.version !== 'string')) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
exports.standardLocationNames = ['clientView', 'clientEditor', 'admin', 'login', 'customizer', 'analytics'];
|
|
26
|
+
function determineCurrentSourceType(dest, srcIsDirectory) {
|
|
27
|
+
if (typeof dest === 'string') {
|
|
28
|
+
return srcIsDirectory ? "blocks" /* SourceType.blocks */ : "plain" /* SourceType.plain */;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (dest.directoryLayout === undefined) {
|
|
32
|
+
return srcIsDirectory ? "blocks" /* SourceType.blocks */ : "plain" /* SourceType.plain */;
|
|
33
|
+
}
|
|
34
|
+
if (dest.directoryLayout === "extensions" /* SourceType.extensions */ || dest.directoryLayout === "blocks" /* SourceType.blocks */) {
|
|
35
|
+
if (!srcIsDirectory) {
|
|
36
|
+
throw new Error(`The '${dest.directoryLayout}' source type must be associated with a directory`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return dest.directoryLayout;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function makeEmittableConfigPHP(data) {
|
|
43
|
+
return "<?php return "
|
|
44
|
+
+ json_to_php_but_with____injection_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(data, "")
|
|
45
|
+
.replaceAll(/(\n\t*)\[\s+],/gs, "$1[],")
|
|
46
|
+
.replaceAll(/\[\n\t+([^\n]+)\n\t+]/gs, (_, inner) => `[${inner.trim()}]`)
|
|
47
|
+
.replaceAll(/'rest' => \[\n\t+(\[(?:'[^']+')?]),\n\t+('[^']+')(?:,\n\t+(\[[^\n]+]))?\n\t+]/gs, (_, deps, hash, args) => `'rest' => [${[deps, hash, args].filter(value => !!value).join(", ")}]`)
|
|
48
|
+
+ ";";
|
|
49
|
+
}
|
|
50
|
+
class SyncsManager {
|
|
51
|
+
readinessMapping = new Map();
|
|
52
|
+
get(name) {
|
|
53
|
+
const res = this.readinessMapping.get(name);
|
|
54
|
+
if (res) {
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
this.readinessMapping.set(name, { nonModule: this.makeSync(), module: this.makeSync() });
|
|
58
|
+
return this.readinessMapping.get(name);
|
|
59
|
+
}
|
|
60
|
+
makeSync() {
|
|
61
|
+
const res = { done: false };
|
|
62
|
+
res.sync = new Promise((resolve, reject) => {
|
|
63
|
+
res.resolve = (v) => resolve(v);
|
|
64
|
+
res.reject = () => reject();
|
|
65
|
+
});
|
|
66
|
+
return res;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.SyncsManager = SyncsManager;
|
|
70
|
+
function leadingSlashIt(pathOrSomething) {
|
|
71
|
+
return pathOrSomething.startsWith('/') ? pathOrSomething : ('/' + pathOrSomething);
|
|
72
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AdvancedOutputConfig, PlauditWordpressWebpackConfig } from "../shared";
|
|
2
|
+
import type { Compiler, Configuration, EntryObject, WebpackPluginInstance } from "webpack";
|
|
3
|
+
import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
|
|
4
|
+
export type VerifiedPlauditWordpressWebpackConfig = Required<Omit<PlauditWordpressWebpackConfig, 'variables' | 'src' | 'externals'>> & {
|
|
5
|
+
variablesFilePath?: string;
|
|
6
|
+
currentVariables: Record<string, any>;
|
|
7
|
+
} & Pick<PlauditWordpressWebpackConfig, 'externals'>;
|
|
8
|
+
export type CommonPluginConfig = {
|
|
9
|
+
plugins: (WebpackPluginInstance | ((this: Compiler, compiler: Compiler) => void))[];
|
|
10
|
+
removeEmptyScriptsPlugin: WebpackRemoveEmptyScriptsPlugin;
|
|
11
|
+
};
|
|
12
|
+
export type CommonConfigProcessingResult = {
|
|
13
|
+
entrypointFields: string[];
|
|
14
|
+
fixedRules: NonNullable<Configuration['module']>['rules'];
|
|
15
|
+
processingModules: boolean | undefined;
|
|
16
|
+
scriptExtension: RegExp;
|
|
17
|
+
updateCurrentVariables: (value: VerifiedPlauditWordpressWebpackConfig['currentVariables']) => unknown;
|
|
18
|
+
};
|
|
19
|
+
export declare const scriptWithoutModuleExtension: RegExp;
|
|
20
|
+
export declare const scriptWithModuleExtension: RegExp;
|
|
21
|
+
export declare const styleExtension: RegExp;
|
|
22
|
+
export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "" | "script" | "style";
|
|
23
|
+
export declare function joinPossiblyAbsolutePaths(...paths: (string | undefined)[]): string;
|
|
24
|
+
export declare function groupEntrypointsByAssetFile<T>(entrypoints: T[], entrypointNameExtractor: (t: T) => string): Map<string, T[]>;
|
|
25
|
+
export declare function resolveEntryFromDirectory(commonConfig: CommonConfigProcessingResult, srcRoot: string, dest: AdvancedOutputConfig): () => Promise<EntryObject>;
|
|
26
|
+
export declare function commonMakeWebpackConfig(config: VerifiedPlauditWordpressWebpackConfig, commonConfig: CommonConfigProcessingResult, webpackConfig: Configuration, srcIsDirectory: boolean, dest: string | AdvancedOutputConfig, src: string, srcRoot: string | string[], entry: () => Promise<EntryObject> | EntryObject, plugins: CommonPluginConfig['plugins']): Configuration;
|