@wordpress/build 0.4.1-next.738bb1424.0 → 0.4.1-next.76cff8c98.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/.cache/tsconfig.tsbuildinfo +1 -1
- package/LICENSE.md +1 -1
- package/build-module/build.mjs +1454 -0
- package/build-module/build.mjs.map +7 -0
- package/build-module/dependency-graph.mjs +149 -0
- package/build-module/dependency-graph.mjs.map +7 -0
- package/build-module/package-utils.mjs +44 -0
- package/build-module/package-utils.mjs.map +7 -0
- package/build-module/php-generator.mjs +48 -0
- package/build-module/php-generator.mjs.map +7 -0
- package/build-module/route-utils.mjs +85 -0
- package/build-module/route-utils.mjs.map +7 -0
- package/build-module/wordpress-externals-plugin.mjs +257 -0
- package/build-module/wordpress-externals-plugin.mjs.map +7 -0
- package/package.json +4 -6
- package/src/build.mjs +62 -50
- package/src/dependency-graph.mjs +36 -110
- package/src/package-utils.mjs +45 -10
- package/src/php-generator.mjs +2 -8
- package/src/wordpress-externals-plugin.mjs +4 -1
- package/templates/constants.php.template +14 -0
- package/templates/index.php.template +0 -6
- package/templates/module-registration.php.template +3 -1
- package/templates/page-wp-admin.php.template +4 -1
- package/templates/page.php.template +12 -3
- package/templates/routes-registration.php.template +4 -2
- package/templates/script-registration.php.template +4 -2
- package/templates/style-registration.php.template +6 -2
- package/templates/version.php.template +0 -11
package/src/dependency-graph.mjs
CHANGED
|
@@ -5,30 +5,17 @@
|
|
|
5
5
|
* and determine the correct build order using topological sorting.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* External dependencies
|
|
10
|
-
*/
|
|
11
|
-
import toposort from 'toposort';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Node dependencies
|
|
15
|
-
*/
|
|
16
8
|
import path from 'path';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
import { getPackageInfo, getPackageInfoFromFile } from './package-utils.mjs';
|
|
9
|
+
import { getPackageInfoFromFile } from './package-utils.mjs';
|
|
22
10
|
|
|
23
11
|
/**
|
|
24
12
|
* Check if a package is a script or script module.
|
|
25
13
|
* A package is a script if it has wpScript or wpScriptModuleExports.
|
|
26
14
|
*
|
|
27
|
-
* @param {
|
|
15
|
+
* @param {import('./package-utils.mjs').PackageJson|null|undefined} packageJson The package.json object.
|
|
28
16
|
* @return {boolean} True if the package is a script or script module.
|
|
29
17
|
*/
|
|
30
|
-
function isScriptOrModule(
|
|
31
|
-
const packageJson = getPackageInfo( packageName );
|
|
18
|
+
function isScriptOrModule( packageJson ) {
|
|
32
19
|
if ( ! packageJson ) {
|
|
33
20
|
return false;
|
|
34
21
|
}
|
|
@@ -36,13 +23,12 @@ function isScriptOrModule( packageName ) {
|
|
|
36
23
|
}
|
|
37
24
|
|
|
38
25
|
/**
|
|
39
|
-
* Get package dependencies from a package.json
|
|
26
|
+
* Get package dependencies from a package.json object.
|
|
40
27
|
*
|
|
41
|
-
* @param {
|
|
28
|
+
* @param {import('./package-utils.mjs').PackageJson|null|undefined} packageJson The package.json object.
|
|
42
29
|
* @return {string[]} Array of package names this package depends on.
|
|
43
30
|
*/
|
|
44
|
-
function getDependencies(
|
|
45
|
-
const packageJson = getPackageInfo( packageName );
|
|
31
|
+
function getDependencies( packageJson ) {
|
|
46
32
|
if ( ! packageJson ) {
|
|
47
33
|
return [];
|
|
48
34
|
}
|
|
@@ -52,78 +38,15 @@ function getDependencies( packageName ) {
|
|
|
52
38
|
return Object.keys( deps );
|
|
53
39
|
}
|
|
54
40
|
|
|
55
|
-
/**
|
|
56
|
-
* Build a dependency graph for the given packages.
|
|
57
|
-
*
|
|
58
|
-
* @param {string[]} packages Array of full package names to analyze.
|
|
59
|
-
* @return {Array<[string, string]>} Array of [dependent, dependency] edges.
|
|
60
|
-
*/
|
|
61
|
-
function buildDependencyGraph( packages ) {
|
|
62
|
-
/** @type {Array<[string, string]>} */
|
|
63
|
-
const edges = [];
|
|
64
|
-
const packagesSet = new Set( packages );
|
|
65
|
-
|
|
66
|
-
for ( const packageName of packages ) {
|
|
67
|
-
const deps = getDependencies( packageName );
|
|
68
|
-
|
|
69
|
-
// Only include edges where both packages are in our list
|
|
70
|
-
for ( const dep of deps ) {
|
|
71
|
-
if ( packagesSet.has( dep ) ) {
|
|
72
|
-
edges.push( [ packageName, dep ] );
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// If package has no dependencies in our list, add a self-reference
|
|
77
|
-
// This ensures it appears in the sorted output
|
|
78
|
-
if ( deps.filter( ( dep ) => packagesSet.has( dep ) ).length === 0 ) {
|
|
79
|
-
edges.push( [ packageName, packageName ] );
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return edges;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Sort packages in topological order based on their dependencies.
|
|
88
|
-
*
|
|
89
|
-
* @param {string[]} packages Array of full package names to sort.
|
|
90
|
-
* @return {string[]} Sorted array where dependencies come before dependents.
|
|
91
|
-
*/
|
|
92
|
-
function topologicalSort( packages ) {
|
|
93
|
-
const edges = buildDependencyGraph( packages );
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
// toposort returns dependencies first, then dependents
|
|
97
|
-
/** @type {Array<string>} */
|
|
98
|
-
const sorted = toposort( edges );
|
|
99
|
-
|
|
100
|
-
// Filter to only include packages in our input list
|
|
101
|
-
// (toposort might include extra nodes)
|
|
102
|
-
const packagesSet = new Set( packages );
|
|
103
|
-
return sorted.filter( ( pkg ) => packagesSet.has( pkg ) );
|
|
104
|
-
} catch ( error ) {
|
|
105
|
-
if ( error instanceof Error && error.message.includes( 'cyclic' ) ) {
|
|
106
|
-
console.error(
|
|
107
|
-
'❌ Cyclic dependency detected in packages:',
|
|
108
|
-
error.message
|
|
109
|
-
);
|
|
110
|
-
throw new Error(
|
|
111
|
-
'Cannot build packages due to cyclic dependencies'
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
41
|
/**
|
|
119
42
|
* Group packages by dependency depth level.
|
|
120
43
|
* Packages at the same depth level can be built in parallel.
|
|
121
44
|
*
|
|
122
|
-
* @param {string
|
|
123
|
-
* @return {string[][]} Array of arrays, where each inner array is a depth level.
|
|
45
|
+
* @param {Map<string, import('./package-utils.mjs').PackageJson>} packages Map of package names to package.json objects.
|
|
46
|
+
* @return {string[][]} Array of arrays, where each inner array is a depth level containing package names.
|
|
124
47
|
*/
|
|
125
48
|
function groupByDepth( packages ) {
|
|
126
|
-
const packagesSet = new Set( packages );
|
|
49
|
+
const packagesSet = new Set( packages.keys() );
|
|
127
50
|
const depths = new Map();
|
|
128
51
|
const visited = new Set();
|
|
129
52
|
|
|
@@ -145,7 +68,8 @@ function groupByDepth( packages ) {
|
|
|
145
68
|
|
|
146
69
|
visited.add( packageName );
|
|
147
70
|
|
|
148
|
-
const
|
|
71
|
+
const packageJson = packages.get( packageName );
|
|
72
|
+
const deps = getDependencies( packageJson );
|
|
149
73
|
const relevantDeps = deps.filter( ( dep ) => packagesSet.has( dep ) );
|
|
150
74
|
|
|
151
75
|
if ( relevantDeps.length === 0 ) {
|
|
@@ -163,7 +87,7 @@ function groupByDepth( packages ) {
|
|
|
163
87
|
}
|
|
164
88
|
|
|
165
89
|
// Calculate depth for all packages
|
|
166
|
-
for ( const packageName of packages ) {
|
|
90
|
+
for ( const packageName of packages.keys() ) {
|
|
167
91
|
calculateDepth( packageName );
|
|
168
92
|
}
|
|
169
93
|
|
|
@@ -172,7 +96,7 @@ function groupByDepth( packages ) {
|
|
|
172
96
|
const maxDepth = Math.max( ...depths.values() );
|
|
173
97
|
|
|
174
98
|
for ( let depth = 0; depth <= maxDepth; depth++ ) {
|
|
175
|
-
const packagesAtDepth = packages.filter(
|
|
99
|
+
const packagesAtDepth = Array.from( packages.keys() ).filter(
|
|
176
100
|
( pkg ) => depths.get( pkg ) === depth
|
|
177
101
|
);
|
|
178
102
|
if ( packagesAtDepth.length > 0 ) {
|
|
@@ -186,15 +110,15 @@ function groupByDepth( packages ) {
|
|
|
186
110
|
/**
|
|
187
111
|
* Get packages that depend on a given package (reverse dependencies).
|
|
188
112
|
*
|
|
189
|
-
* @param {string}
|
|
190
|
-
* @param {string
|
|
113
|
+
* @param {string} packageName The full package name to find dependents of.
|
|
114
|
+
* @param {Map<string, import('./package-utils.mjs').PackageJson>} workspacePackages Map of workspace package names to package.json objects.
|
|
191
115
|
* @return {string[]} Array of package names that depend on the given package.
|
|
192
116
|
*/
|
|
193
|
-
function getReverseDependencies( packageName,
|
|
117
|
+
function getReverseDependencies( packageName, workspacePackages ) {
|
|
194
118
|
const dependents = [];
|
|
195
119
|
|
|
196
|
-
for ( const pkg of
|
|
197
|
-
const deps = getDependencies(
|
|
120
|
+
for ( const [ pkg, packageJson ] of workspacePackages ) {
|
|
121
|
+
const deps = getDependencies( packageJson );
|
|
198
122
|
if ( deps.includes( packageName ) ) {
|
|
199
123
|
dependents.push( pkg );
|
|
200
124
|
}
|
|
@@ -218,14 +142,15 @@ function getReverseDependencies( packageName, allPackages ) {
|
|
|
218
142
|
* - D (script) depends on C
|
|
219
143
|
* Result: Only C needs rebundling (D stops at C boundary)
|
|
220
144
|
*
|
|
221
|
-
* @param {string}
|
|
222
|
-
* @param {string
|
|
145
|
+
* @param {string} changedPackage The full package name that changed.
|
|
146
|
+
* @param {Map<string, import('./package-utils.mjs').PackageJson>} workspacePackages Map of workspace package names to package.json objects.
|
|
223
147
|
* @return {string[]} Array of script/module package names to rebundle.
|
|
224
148
|
*/
|
|
225
|
-
function findScriptsToRebundle( changedPackage,
|
|
149
|
+
function findScriptsToRebundle( changedPackage, workspacePackages ) {
|
|
226
150
|
// If the changed package itself is a script/module, no need to find others
|
|
227
151
|
// (it will be rebuilt by the regular watch logic)
|
|
228
|
-
|
|
152
|
+
const changedPackageJson = workspacePackages.get( changedPackage );
|
|
153
|
+
if ( isScriptOrModule( changedPackageJson ) ) {
|
|
229
154
|
return [];
|
|
230
155
|
}
|
|
231
156
|
|
|
@@ -244,13 +169,14 @@ function findScriptsToRebundle( changedPackage, allPackages ) {
|
|
|
244
169
|
// Get all packages that depend on the current package
|
|
245
170
|
const dependents = getReverseDependencies(
|
|
246
171
|
currentPackage,
|
|
247
|
-
|
|
172
|
+
workspacePackages
|
|
248
173
|
);
|
|
249
174
|
|
|
250
175
|
for ( const dependent of dependents ) {
|
|
251
176
|
// If this dependent is a script/module, add it to the result
|
|
252
177
|
// but don't traverse further (stop at script boundaries)
|
|
253
|
-
|
|
178
|
+
const dependentPackageJson = workspacePackages.get( dependent );
|
|
179
|
+
if ( isScriptOrModule( dependentPackageJson ) ) {
|
|
254
180
|
scriptsToRebundle.add( dependent );
|
|
255
181
|
} else if ( ! visited.has( dependent ) ) {
|
|
256
182
|
// If it's a bundled package, continue traversing
|
|
@@ -296,21 +222,22 @@ function getRouteDependencies( rootDir, routeName ) {
|
|
|
296
222
|
* - home (route) depends on B
|
|
297
223
|
* Result: Both C and home need rebuilding
|
|
298
224
|
*
|
|
299
|
-
* @param {string}
|
|
300
|
-
* @param {string
|
|
301
|
-
* @param {string}
|
|
302
|
-
* @param {string[]}
|
|
225
|
+
* @param {string} changedPackage The full package name that changed.
|
|
226
|
+
* @param {Map<string, import('./package-utils.mjs').PackageJson>} workspacePackages Map of workspace package names to package.json objects.
|
|
227
|
+
* @param {string} rootDir Root directory path.
|
|
228
|
+
* @param {string[]} allRoutes Array of all route names.
|
|
303
229
|
* @return {string[]} Array of route names to rebuild.
|
|
304
230
|
*/
|
|
305
231
|
function findRoutesToRebuild(
|
|
306
232
|
changedPackage,
|
|
307
|
-
|
|
233
|
+
workspacePackages,
|
|
308
234
|
rootDir,
|
|
309
235
|
allRoutes
|
|
310
236
|
) {
|
|
311
237
|
// If the changed package itself is a script/module, routes won't be affected
|
|
312
238
|
// (routes depend on bundled packages, not scripts/modules)
|
|
313
|
-
|
|
239
|
+
const changedPackageJson = workspacePackages.get( changedPackage );
|
|
240
|
+
if ( isScriptOrModule( changedPackageJson ) ) {
|
|
314
241
|
return [];
|
|
315
242
|
}
|
|
316
243
|
|
|
@@ -337,14 +264,15 @@ function findRoutesToRebuild(
|
|
|
337
264
|
// Get all packages that depend on the current package
|
|
338
265
|
const dependents = getReverseDependencies(
|
|
339
266
|
currentPackage,
|
|
340
|
-
|
|
267
|
+
workspacePackages
|
|
341
268
|
);
|
|
342
269
|
|
|
343
270
|
for ( const dependent of dependents ) {
|
|
344
271
|
// If this dependent is a script/module, don't traverse further
|
|
345
272
|
// (stop at script boundaries)
|
|
273
|
+
const dependentPackageJson = workspacePackages.get( dependent );
|
|
346
274
|
if (
|
|
347
|
-
! isScriptOrModule(
|
|
275
|
+
! isScriptOrModule( dependentPackageJson ) &&
|
|
348
276
|
! visited.has( dependent )
|
|
349
277
|
) {
|
|
350
278
|
// If it's a bundled package, continue traversing
|
|
@@ -358,8 +286,6 @@ function findRoutesToRebuild(
|
|
|
358
286
|
|
|
359
287
|
export {
|
|
360
288
|
getDependencies,
|
|
361
|
-
buildDependencyGraph,
|
|
362
|
-
topologicalSort,
|
|
363
289
|
groupByDepth,
|
|
364
290
|
isScriptOrModule,
|
|
365
291
|
getReverseDependencies,
|
package/src/package-utils.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
|
-
import {
|
|
4
|
+
import { readFileSync, existsSync } from 'fs';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
import path from 'path';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Shared cache for package.json files to avoid redundant reads.
|
|
@@ -40,21 +41,55 @@ const packagePathCache = new Map();
|
|
|
40
41
|
* @typedef {PackageJson & { route: { path: string; page?: string } }} RoutePackageJson
|
|
41
42
|
*/
|
|
42
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Find the nearest package root directory by walking up from the given directory.
|
|
46
|
+
* Looks for a directory containing package.json.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} startDir The directory to start searching from.
|
|
49
|
+
* @return {string} The package root directory, or the start directory if no package.json found.
|
|
50
|
+
*/
|
|
51
|
+
function findPackageRoot( startDir ) {
|
|
52
|
+
let current = startDir;
|
|
53
|
+
const root = path.parse( current ).root;
|
|
54
|
+
|
|
55
|
+
while ( current !== root ) {
|
|
56
|
+
const packageJsonPath = path.join( current, 'package.json' );
|
|
57
|
+
if ( existsSync( packageJsonPath ) ) {
|
|
58
|
+
return current;
|
|
59
|
+
}
|
|
60
|
+
current = path.dirname( current );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Fallback to the start directory if no package.json found
|
|
64
|
+
return startDir;
|
|
65
|
+
}
|
|
66
|
+
|
|
43
67
|
/**
|
|
44
68
|
* Get package.json info using Node's module resolution.
|
|
45
|
-
* Resolves the
|
|
69
|
+
* Resolves packages from the appropriate context to support both workspace packages
|
|
70
|
+
* and external dependencies in pnpm/yarn/npm workspaces.
|
|
46
71
|
*
|
|
47
|
-
* @param {string}
|
|
72
|
+
* @param {string} fullPackageName The full package name (e.g., '@wordpress/blocks').
|
|
73
|
+
* @param {string|null} resolveDir Optional directory context for resolution (from esbuild).
|
|
48
74
|
* @return {PackageJson|null} Package.json object or null if not found.
|
|
49
75
|
*/
|
|
50
|
-
export function getPackageInfo( fullPackageName ) {
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
export function getPackageInfo( fullPackageName, resolveDir = null ) {
|
|
77
|
+
// Determine the package root for cache keying
|
|
78
|
+
const packageRoot = resolveDir
|
|
79
|
+
? findPackageRoot( resolveDir )
|
|
80
|
+
: process.cwd();
|
|
81
|
+
const cacheKey = `${ fullPackageName }@${ packageRoot }`;
|
|
82
|
+
|
|
83
|
+
if ( packageJsonCache.has( cacheKey ) ) {
|
|
84
|
+
return packageJsonCache.get( cacheKey );
|
|
53
85
|
}
|
|
54
86
|
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
87
|
+
// Resolve from the package root context to get correct versions
|
|
88
|
+
const contextPath = path.join( packageRoot, 'package.json' );
|
|
89
|
+
const require = createRequire( contextPath );
|
|
90
|
+
const resolved = require.resolve( `${ fullPackageName }/package.json` );
|
|
91
|
+
const result = getPackageInfoFromFile( resolved );
|
|
92
|
+
packageJsonCache.set( cacheKey, result );
|
|
58
93
|
|
|
59
94
|
return result;
|
|
60
95
|
}
|
package/src/php-generator.mjs
CHANGED
|
@@ -17,12 +17,9 @@ const __dirname = path.dirname( fileURLToPath( import.meta.url ) );
|
|
|
17
17
|
*
|
|
18
18
|
* @param {string} rootDir Root directory path.
|
|
19
19
|
* @param {string} baseUrlExpression PHP expression for base URL (e.g. "includes_url( 'build' )").
|
|
20
|
-
* @return {Promise<Record<string, string>>} Replacements object with {{PREFIX}}, {{VERSION}}, {{
|
|
20
|
+
* @return {Promise<Record<string, string>>} Replacements object with {{PREFIX}}, {{VERSION}}, {{BASE_URL}}.
|
|
21
21
|
*/
|
|
22
|
-
export async function getPhpReplacements(
|
|
23
|
-
rootDir,
|
|
24
|
-
baseUrlExpression = "plugins_url( 'build', dirname( __FILE__ ) )"
|
|
25
|
-
) {
|
|
22
|
+
export async function getPhpReplacements( rootDir, baseUrlExpression ) {
|
|
26
23
|
const rootPackageJson = getPackageInfoFromFile(
|
|
27
24
|
path.join( rootDir, 'package.json' )
|
|
28
25
|
);
|
|
@@ -33,13 +30,10 @@ export async function getPhpReplacements(
|
|
|
33
30
|
// @ts-expect-error specific override to package.json
|
|
34
31
|
const name = rootPackageJson.wpPlugin?.name || 'gutenberg';
|
|
35
32
|
const version = rootPackageJson.version;
|
|
36
|
-
const versionConstant =
|
|
37
|
-
name.toUpperCase().replace( /-/g, '_' ) + '_VERSION';
|
|
38
33
|
|
|
39
34
|
return {
|
|
40
35
|
'{{PREFIX}}': name,
|
|
41
36
|
'{{VERSION}}': version,
|
|
42
|
-
'{{VERSION_CONSTANT}}': versionConstant,
|
|
43
37
|
'{{BASE_URL}}': baseUrlExpression,
|
|
44
38
|
};
|
|
45
39
|
}
|
|
@@ -213,7 +213,10 @@ export function createWordpressExternalsPlugin(
|
|
|
213
213
|
const shortName = parts[ 1 ];
|
|
214
214
|
const handle = `${ externalConfig.handlePrefix }-${ shortName }`;
|
|
215
215
|
|
|
216
|
-
const packageJson = getPackageInfo(
|
|
216
|
+
const packageJson = getPackageInfo(
|
|
217
|
+
packageName,
|
|
218
|
+
args.resolveDir
|
|
219
|
+
);
|
|
217
220
|
|
|
218
221
|
if ( ! packageJson ) {
|
|
219
222
|
return undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Plugin constants - Auto-generated by build process.
|
|
4
|
+
* Do not edit this file manually.
|
|
5
|
+
*
|
|
6
|
+
* Returns an array of constants for use in other templates.
|
|
7
|
+
*
|
|
8
|
+
* @package {{PREFIX}}
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
return array(
|
|
12
|
+
'version' => '{{VERSION}}',
|
|
13
|
+
'build_url' => {{BASE_URL}},
|
|
14
|
+
);
|
|
@@ -6,12 +6,6 @@
|
|
|
6
6
|
* @package {{PREFIX}}
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
// Load version constant.
|
|
10
|
-
$version_file = __DIR__ . '/version.php';
|
|
11
|
-
if ( file_exists( $version_file ) ) {
|
|
12
|
-
require_once $version_file;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
// Load script module registration.
|
|
16
10
|
$modules_file = __DIR__ . '/modules.php';
|
|
17
11
|
if ( file_exists( $modules_file ) ) {
|
|
@@ -11,6 +11,8 @@ if ( ! function_exists( '{{PREFIX}}_register_script_modules' ) ) {
|
|
|
11
11
|
* Register all script modules.
|
|
12
12
|
*/
|
|
13
13
|
function {{PREFIX}}_register_script_modules() {
|
|
14
|
+
// Load build constants
|
|
15
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
14
16
|
$modules_dir = __DIR__ . '/modules';
|
|
15
17
|
$modules_file = $modules_dir . '/index.php';
|
|
16
18
|
|
|
@@ -19,7 +21,7 @@ if ( ! function_exists( '{{PREFIX}}_register_script_modules' ) ) {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
$modules = require $modules_file;
|
|
22
|
-
$base_url =
|
|
24
|
+
$base_url = $build_constants['build_url'] . 'modules/';
|
|
23
25
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
24
26
|
|
|
25
27
|
foreach ( $modules as $module ) {
|
|
@@ -141,6 +141,9 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' ) )
|
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
// Load build constants
|
|
145
|
+
$build_constants = require __DIR__ . '/../../constants.php';
|
|
146
|
+
|
|
144
147
|
// Fire init action for extensions to register routes and menu items
|
|
145
148
|
do_action( '{{PAGE_SLUG}}-wp-admin_init' );
|
|
146
149
|
|
|
@@ -206,7 +209,7 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' ) )
|
|
|
206
209
|
// Dummy script module to ensure dependencies are loaded
|
|
207
210
|
wp_register_script_module(
|
|
208
211
|
'{{PAGE_SLUG}}-wp-admin',
|
|
209
|
-
|
|
212
|
+
$build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
|
|
210
213
|
$boot_dependencies
|
|
211
214
|
);
|
|
212
215
|
|
|
@@ -127,6 +127,9 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
127
127
|
* Call this function from add_menu_page or add_submenu_page.
|
|
128
128
|
*/
|
|
129
129
|
function {{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
130
|
+
// Load build constants
|
|
131
|
+
$build_constants = require __DIR__ . '/../../constants.php';
|
|
132
|
+
|
|
130
133
|
// Set current screen
|
|
131
134
|
set_current_screen();
|
|
132
135
|
|
|
@@ -144,6 +147,11 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
144
147
|
// Fire init action for extensions to register routes and menu items
|
|
145
148
|
do_action( '{{PAGE_SLUG}}_init' );
|
|
146
149
|
|
|
150
|
+
// Enqueue command palette assets for boot-based pages
|
|
151
|
+
if ( function_exists( 'wp_enqueue_command_palette_assets' ) ) {
|
|
152
|
+
wp_enqueue_command_palette_assets();
|
|
153
|
+
}
|
|
154
|
+
|
|
147
155
|
// Preload REST API data
|
|
148
156
|
{{PAGE_SLUG_UNDERSCORE}}_preload_data();
|
|
149
157
|
|
|
@@ -166,11 +174,12 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
166
174
|
wp_add_inline_script(
|
|
167
175
|
'{{PAGE_SLUG}}-prerequisites',
|
|
168
176
|
sprintf(
|
|
169
|
-
'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s}));',
|
|
177
|
+
'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));',
|
|
170
178
|
'{{PAGE_SLUG}}-app',
|
|
171
179
|
wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
172
180
|
wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
173
|
-
wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
|
181
|
+
wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
182
|
+
esc_url( admin_url( '/' ) )
|
|
174
183
|
)
|
|
175
184
|
);
|
|
176
185
|
|
|
@@ -213,7 +222,7 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
213
222
|
// Dummy script module to ensure dependencies are loaded
|
|
214
223
|
wp_register_script_module(
|
|
215
224
|
'{{PAGE_SLUG}}',
|
|
216
|
-
|
|
225
|
+
$build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
|
|
217
226
|
$boot_dependencies
|
|
218
227
|
);
|
|
219
228
|
|
|
@@ -28,6 +28,8 @@ foreach ( $routes as $route ) {
|
|
|
28
28
|
// Helper function to register routes for a page
|
|
29
29
|
$register_routes_callback = function ( $page_routes, $page_slug_underscore, $register_function_name ) {
|
|
30
30
|
return function () use ( $page_routes, $page_slug_underscore, $register_function_name ) {
|
|
31
|
+
// Load build constants
|
|
32
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
31
33
|
foreach ( $page_routes as $route ) {
|
|
32
34
|
$content_handle = null;
|
|
33
35
|
$route_handle = null;
|
|
@@ -41,7 +43,7 @@ $register_routes_callback = function ( $page_routes, $page_slug_underscore, $reg
|
|
|
41
43
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
42
44
|
wp_register_script_module(
|
|
43
45
|
$content_handle,
|
|
44
|
-
|
|
46
|
+
$build_constants['build_url'] . 'routes/' . $route['name'] . '/content' . $extension,
|
|
45
47
|
$content_asset['module_dependencies'] ?? array(),
|
|
46
48
|
$content_asset['version'] ?? false
|
|
47
49
|
);
|
|
@@ -57,7 +59,7 @@ $register_routes_callback = function ( $page_routes, $page_slug_underscore, $reg
|
|
|
57
59
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
58
60
|
wp_register_script_module(
|
|
59
61
|
$route_handle,
|
|
60
|
-
|
|
62
|
+
$build_constants['build_url'] . 'routes/' . $route['name'] . '/route' . $extension,
|
|
61
63
|
$route_asset['module_dependencies'] ?? array(),
|
|
62
64
|
$route_asset['version'] ?? false
|
|
63
65
|
);
|
|
@@ -53,7 +53,9 @@ if ( ! function_exists( '{{PREFIX}}_register_package_scripts' ) ) {
|
|
|
53
53
|
* Register all package scripts.
|
|
54
54
|
*/
|
|
55
55
|
function {{PREFIX}}_register_package_scripts( $scripts ) {
|
|
56
|
-
|
|
56
|
+
// Load build constants
|
|
57
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
58
|
+
$default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
|
|
57
59
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
58
60
|
|
|
59
61
|
$scripts_dir = __DIR__ . '/scripts';
|
|
@@ -75,7 +77,7 @@ if ( ! function_exists( '{{PREFIX}}_register_package_scripts' ) ) {
|
|
|
75
77
|
{{PREFIX}}_override_script(
|
|
76
78
|
$scripts,
|
|
77
79
|
$script_data['handle'],
|
|
78
|
-
|
|
80
|
+
$build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension,
|
|
79
81
|
$dependencies,
|
|
80
82
|
$version,
|
|
81
83
|
true
|
|
@@ -43,7 +43,10 @@ if ( ! function_exists( '{{PREFIX}}_register_package_styles' ) ) {
|
|
|
43
43
|
* @param WP_Styles $styles WP_Styles instance.
|
|
44
44
|
*/
|
|
45
45
|
function {{PREFIX}}_register_package_styles( $styles ) {
|
|
46
|
-
|
|
46
|
+
// Load build constants
|
|
47
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
48
|
+
$default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
|
|
49
|
+
$suffix = SCRIPT_DEBUG ? '' : '.min';
|
|
47
50
|
|
|
48
51
|
$styles_dir = __DIR__ . '/styles';
|
|
49
52
|
$styles_file = $styles_dir . '/index.php';
|
|
@@ -59,13 +62,14 @@ if ( ! function_exists( '{{PREFIX}}_register_package_styles' ) ) {
|
|
|
59
62
|
{{PREFIX}}_override_style(
|
|
60
63
|
$styles,
|
|
61
64
|
$style_data['handle'],
|
|
62
|
-
|
|
65
|
+
$build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css',
|
|
63
66
|
$style_data['dependencies'],
|
|
64
67
|
$default_version
|
|
65
68
|
);
|
|
66
69
|
|
|
67
70
|
// Enable RTL support (WordPress automatically loads -rtl.css variant)
|
|
68
71
|
$styles->add_data( $style_data['handle'], 'rtl', 'replace' );
|
|
72
|
+
$styles->add_data( $style_data['handle'], 'suffix', $suffix );
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|