@plaudit/webpack-extensions 2.78.1 → 2.80.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/plugins/AdditionalDependencyInjectorPlugin.d.ts +1 -1
- package/build/plugins/UnifiedLoaderGenerator.d.ts +2 -2
- package/build/plugins/UnifiedLoaderGenerator.js +9 -6
- package/build/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +1 -1
- package/build/plugins/dependency-extraction-webpack-plugin-config-builder.js +18 -27
- package/build/shared.d.ts +3 -1
- package/build/wordpress-scripts-wrapper.js +6 -8
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@ export declare class AdditionalDependencyInjectorPlugin extends AbstractBiPhasic
|
|
|
6
6
|
private readonly processingModules;
|
|
7
7
|
private readonly addExternalizedDep;
|
|
8
8
|
private readonly referencePlugin;
|
|
9
|
-
constructor(config: VerifiedPlauditWordpressWebpackConfig, processingModules: boolean, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
|
|
9
|
+
constructor(config: VerifiedPlauditWordpressWebpackConfig, processingModules: boolean | undefined, addExternalizedDep: (dep: string) => void, referencePlugin: AbstractBiPhasicGroupAndEntryPlugin<any>);
|
|
10
10
|
protected attachStandardPhase(compilation: Compilation): void;
|
|
11
11
|
protected attachUniquePhase(): void;
|
|
12
12
|
}
|
|
@@ -15,7 +15,7 @@ export declare class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin
|
|
|
15
15
|
constructor(config: VerifiedPlauditWordpressWebpackConfig);
|
|
16
16
|
protected attachStandardPhase(compilation: Compilation): void;
|
|
17
17
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
18
|
+
private withDistDevLoader;
|
|
19
|
+
private ensureDistExists;
|
|
20
20
|
}
|
|
21
21
|
export {};
|
|
@@ -93,11 +93,11 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
93
93
|
let writer;
|
|
94
94
|
if (compilation.outputOptions.path?.endsWith("-dev")) {
|
|
95
95
|
compilation['.gitignore' in compilation.assets ? 'updateAsset' : 'emitAsset']('.gitignore', new webpack_1.sources.RawSource('**'), { size: 2 });
|
|
96
|
-
|
|
96
|
+
this.ensureDistExists(compilation.outputOptions.path);
|
|
97
97
|
writer = new php_writer_1.PHPWriter();
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
writer =
|
|
100
|
+
writer = this.withDistDevLoader();
|
|
101
101
|
}
|
|
102
102
|
if (groupedLoaderInfo.some(wc => wc.requiresBaseURI)) {
|
|
103
103
|
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
@@ -110,7 +110,10 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
withDistDevLoader() {
|
|
114
|
+
if (this.config.omitDistDev) {
|
|
115
|
+
return new php_writer_1.PHPWriter();
|
|
116
|
+
}
|
|
114
117
|
const devLoaderPath = expressions_1.Op.concat(expressions_1.Constants.__DIR__, '-dev/unified-loader.php');
|
|
115
118
|
return new php_writer_1.PHPWriter()
|
|
116
119
|
.if(expressions_1.Op.binary(expressions_1.Op.binary(expressions_1.Expr.call('wp_get_environment_type', []), ' === ', 'development'), ' && ', expressions_1.Expr.call('file_exists', [devLoaderPath])))
|
|
@@ -118,19 +121,19 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
118
121
|
.append("return;")
|
|
119
122
|
.endIf();
|
|
120
123
|
}
|
|
121
|
-
|
|
124
|
+
async ensureDistExists(outputPath) {
|
|
122
125
|
if (outputPath.endsWith("-dev")) {
|
|
123
126
|
outputPath = outputPath.substring(0, outputPath.length - 4);
|
|
124
127
|
}
|
|
125
128
|
try {
|
|
126
129
|
const contents = await (0, promises_1.readFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), 'utf-8');
|
|
127
130
|
if (!contents.includes("-dev/unified-loader.php")) {
|
|
128
|
-
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"),
|
|
131
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), this.withDistDevLoader().toString() + contents.substring(5), 'utf-8');
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
catch {
|
|
132
135
|
await (0, promises_1.mkdir)(outputPath, { recursive: true });
|
|
133
|
-
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"),
|
|
136
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), this.withDistDevLoader().toString(), 'utf-8');
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
2
|
-
import
|
|
2
|
+
import { Externals } from "../shared";
|
|
3
3
|
import type { Configuration } from "webpack";
|
|
4
4
|
export declare function makeDependencyExtractionPlugin(externals: Externals | undefined, assumeGlobalizedPlauditLibraries: boolean, wantsGroupedDepData: boolean, externalizing: Required<Configuration>['output']['library']): {
|
|
5
5
|
instance: DependencyExtractionWebpackPlugin;
|
|
@@ -89,38 +89,29 @@ function firstLayersEqual(first, second) {
|
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
const PLAUDIT_NAMESPACE = '@plaudit/';
|
|
92
|
-
const EXTERNALIZABLE_PLAUDIT_LIBRARIES =
|
|
92
|
+
const EXTERNALIZABLE_PLAUDIT_LIBRARIES = {
|
|
93
|
+
...Object.fromEntries(['@plaudit/frontend-apis', '@plaudit/library-extensions', '@plaudit/block-supports', '@plaudit/gutenberg-api-extensions']
|
|
94
|
+
.map(req => {
|
|
95
|
+
return [req, {
|
|
96
|
+
import: ['plaudit', camelCaseDash(req.substring(PLAUDIT_NAMESPACE.length))],
|
|
97
|
+
handle: `plaudit-${req.substring(PLAUDIT_NAMESPACE.length)}`
|
|
98
|
+
}];
|
|
99
|
+
})),
|
|
100
|
+
"@plaudit/wp-consent-api": { handle: "wp-consent-api", import: ['plaudit'] },
|
|
101
|
+
"@plaudit/analytics-integrations-api": { handle: "plaudit/analytics-integrations/api", import: ['plaudit', 'analyticsIntegrations', 'api'] },
|
|
102
|
+
"google.maps": { handle: "plaudit-base/google-maps-api", import: ['google', 'maps'] }
|
|
103
|
+
};
|
|
93
104
|
function plauditRequestToExternal(ext) {
|
|
94
105
|
return function (request) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
else if (request.startsWith('@plaudit/gutenberg-api-extensions')) {
|
|
99
|
-
return handleExternalizingEqualsPossibleExternal({ import: ['plaudit', 'gutenbergApiExtensions'], handle: "" }, ext)?.import;
|
|
100
|
-
}
|
|
101
|
-
else if (request.startsWith('@plaudit/wp-consent-api')) {
|
|
102
|
-
return handleExternalizingEqualsPossibleExternal({ import: ['plaudit'], handle: "" }, ext)?.import;
|
|
103
|
-
}
|
|
104
|
-
else if (request.startsWith('@plaudit/analytics-integrations-api')) {
|
|
105
|
-
return handleExternalizingEqualsPossibleExternal({ import: ['plaudit', 'analyticsIntegrations', 'api'], handle: "" }, ext)?.import;
|
|
106
|
-
}
|
|
107
|
-
return undefined;
|
|
106
|
+
const req = EXTERNALIZABLE_PLAUDIT_LIBRARIES[normalizeRequest(request)];
|
|
107
|
+
return req ? handleExternalizingEqualsPossibleExternal(req, ext)?.import : undefined;
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
function plauditRequestToHandle(request) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return 'plaudit-gutenberg-api-extensions';
|
|
116
|
-
}
|
|
117
|
-
else if (request.startsWith('@plaudit/wp-consent-api')) {
|
|
118
|
-
return 'wp-consent-api';
|
|
119
|
-
}
|
|
120
|
-
else if (request.startsWith('@plaudit/analytics-integrations-api')) {
|
|
121
|
-
return 'plaudit/analytics-integrations/api';
|
|
122
|
-
}
|
|
123
|
-
return undefined;
|
|
111
|
+
return EXTERNALIZABLE_PLAUDIT_LIBRARIES[normalizeRequest(request)]?.handle;
|
|
112
|
+
}
|
|
113
|
+
function normalizeRequest(request) {
|
|
114
|
+
return request.startsWith("@plaudit/gutenberg-api-extensions/") ? "@plaudit/gutenberg-api-extensions" : request;
|
|
124
115
|
}
|
|
125
116
|
function curryRequestHandlers(primary, secondary) {
|
|
126
117
|
return (...args) => primary(...args) ?? secondary(...args);
|
package/build/shared.d.ts
CHANGED
|
@@ -63,10 +63,11 @@ export declare const enum SourceType {
|
|
|
63
63
|
plain = "plain"
|
|
64
64
|
}
|
|
65
65
|
export declare function determineCurrentSourceType(dest: string | AdvancedOutputConfig, srcIsDirectory: boolean): SourceType;
|
|
66
|
-
export type
|
|
66
|
+
export type ObjectIndividualExternalDepConfig = {
|
|
67
67
|
import?: string | [string, ...string[]];
|
|
68
68
|
handle: string;
|
|
69
69
|
};
|
|
70
|
+
export type IndividualExternalDepConfig = string | ObjectIndividualExternalDepConfig;
|
|
70
71
|
export type Externals = {
|
|
71
72
|
[dep: string]: IndividualExternalDepConfig;
|
|
72
73
|
};
|
|
@@ -108,6 +109,7 @@ export type PlauditWordpressWebpackConfig = {
|
|
|
108
109
|
srcPrefixes?: string[];
|
|
109
110
|
useUnifiedLoader?: boolean;
|
|
110
111
|
includePostInitFallback?: boolean;
|
|
112
|
+
omitDistDev?: boolean;
|
|
111
113
|
};
|
|
112
114
|
export type FileSegmentBlockEntrypointInfo = {
|
|
113
115
|
blockJsonOrigin: string;
|
|
@@ -105,7 +105,7 @@ function injectPostcssConfigOverrides(rules, config, variables, postcssFunctions
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the
|
|
108
|
+
if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the JavaScript and TypeScript rule
|
|
109
109
|
rule.test = /\.m?[jt]sx?$/; // This hacks in support for mjs and mts files
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -157,9 +157,9 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
function buildVerifiedConfig(config) {
|
|
160
|
-
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 } = config;
|
|
160
|
+
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 } = config;
|
|
161
161
|
let outputDir = config.outputDir ?? "";
|
|
162
|
-
if (outputDir && useUnifiedLoader && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
162
|
+
if (outputDir && useUnifiedLoader && !omitDistDev && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
163
163
|
outputDir += "-dev";
|
|
164
164
|
}
|
|
165
165
|
let srcPrefixes;
|
|
@@ -209,7 +209,7 @@ function buildVerifiedConfig(config) {
|
|
|
209
209
|
}
|
|
210
210
|
const cfg = {
|
|
211
211
|
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
|
|
212
|
-
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix, useUnifiedLoader, includePostInitFallback
|
|
212
|
+
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix, useUnifiedLoader, includePostInitFallback, omitDistDev
|
|
213
213
|
};
|
|
214
214
|
// Destination -> source map
|
|
215
215
|
const allocatedDestinations = {};
|
|
@@ -368,8 +368,6 @@ function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins)
|
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize) {
|
|
371
|
-
const { externals } = config;
|
|
372
|
-
const processingModules = webpackConfig.output?.module ?? false;
|
|
373
371
|
const plugins = webpackConfig.plugins?.filter(v => !!v)
|
|
374
372
|
.filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
|
|
375
373
|
.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
@@ -410,13 +408,13 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
|
|
|
410
408
|
console.error("Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.");
|
|
411
409
|
throw new Error("Cannot apply externals when they have been disabled via CLI flag. This will greatly increase bundle size and will likely cause the build to fail");
|
|
412
410
|
}
|
|
413
|
-
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, assumeGlobalizedPlauditLibraries, true, externalize);
|
|
411
|
+
const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(config.externals, assumeGlobalizedPlauditLibraries, true, externalize);
|
|
414
412
|
plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
|
|
415
413
|
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin());
|
|
416
414
|
return {
|
|
417
415
|
plugins, removeEmptyScriptsPlugin,
|
|
418
416
|
makeAdditionalDependencyInjectorPlugin(referencePlugin) {
|
|
419
|
-
return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(config,
|
|
417
|
+
return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(config, webpackConfig.output?.module, builtDependencyExtractionWebpackPlugin.addExternalizedDep, referencePlugin);
|
|
420
418
|
}
|
|
421
419
|
};
|
|
422
420
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.80.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build"
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"postcss-reporter": "^7.1.0",
|
|
62
62
|
"postcss-simple-vars": "^7.0.1",
|
|
63
63
|
"postcss-url": "^10.1.3",
|
|
64
|
-
"webpack": "^5.104.
|
|
64
|
+
"webpack": "^5.104.1",
|
|
65
65
|
"webpack-remove-empty-scripts": "^1.1.1",
|
|
66
66
|
"xml-formatter": "^3.6.7"
|
|
67
67
|
},
|