@wordpress/build 0.5.0 → 0.5.1-next.79a2f3cdd.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/CHANGELOG.md +0 -2
- package/LICENSE.md +1 -1
- package/README.md +47 -5
- 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 +216 -97
- package/src/dependency-graph.mjs +36 -110
- package/src/package-utils.mjs +45 -10
- package/src/php-generator.mjs +5 -6
- package/src/route-utils.mjs +13 -4
- package/src/wordpress-externals-plugin.mjs +77 -15
- 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 +68 -28
- package/templates/page.php.template +13 -4
- 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/build.mjs
CHANGED
|
@@ -43,7 +43,7 @@ const ROOT_DIR = process.cwd();
|
|
|
43
43
|
const PACKAGES_DIR = path.join( ROOT_DIR, 'packages' );
|
|
44
44
|
const BUILD_DIR = path.join( ROOT_DIR, 'build' );
|
|
45
45
|
|
|
46
|
-
const SOURCE_EXTENSIONS = '{js,ts,tsx}';
|
|
46
|
+
const SOURCE_EXTENSIONS = '{js,mjs,ts,tsx}';
|
|
47
47
|
const ASSET_EXTENSIONS = 'json';
|
|
48
48
|
const IGNORE_PATTERNS = [
|
|
49
49
|
'**/benchmark/**',
|
|
@@ -344,14 +344,7 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
344
344
|
};
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
const
|
|
348
|
-
momentTimezoneAliasPlugin(),
|
|
349
|
-
wordpressExternalsPlugin(
|
|
350
|
-
'index.min',
|
|
351
|
-
'iife',
|
|
352
|
-
packageJson.wpScriptExtraDependencies || []
|
|
353
|
-
),
|
|
354
|
-
];
|
|
347
|
+
const baseBundlePlugins = [ momentTimezoneAliasPlugin() ];
|
|
355
348
|
|
|
356
349
|
builds.push(
|
|
357
350
|
esbuild.build( {
|
|
@@ -359,14 +352,30 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
359
352
|
outfile: path.join( outputDir, 'index.min.js' ),
|
|
360
353
|
minify: true,
|
|
361
354
|
define: getDefine( false ),
|
|
362
|
-
plugins:
|
|
355
|
+
plugins: [
|
|
356
|
+
...baseBundlePlugins,
|
|
357
|
+
wordpressExternalsPlugin(
|
|
358
|
+
'index.min',
|
|
359
|
+
'iife',
|
|
360
|
+
packageJson.wpScriptExtraDependencies || [],
|
|
361
|
+
true // Generate asset file for minified build
|
|
362
|
+
),
|
|
363
|
+
],
|
|
363
364
|
} ),
|
|
364
365
|
esbuild.build( {
|
|
365
366
|
...baseConfig,
|
|
366
367
|
outfile: path.join( outputDir, 'index.js' ),
|
|
367
368
|
minify: false,
|
|
368
369
|
define: getDefine( true ),
|
|
369
|
-
plugins:
|
|
370
|
+
plugins: [
|
|
371
|
+
...baseBundlePlugins,
|
|
372
|
+
wordpressExternalsPlugin(
|
|
373
|
+
'index.min',
|
|
374
|
+
'iife',
|
|
375
|
+
packageJson.wpScriptExtraDependencies || [],
|
|
376
|
+
false // Skip asset file for non-minified build
|
|
377
|
+
),
|
|
378
|
+
],
|
|
370
379
|
} )
|
|
371
380
|
);
|
|
372
381
|
|
|
@@ -397,9 +406,6 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
397
406
|
: exportName.replace( /^\.\//, '' );
|
|
398
407
|
const entryPoint = path.join( packageDir, exportPath );
|
|
399
408
|
const baseFileName = path.basename( fileName );
|
|
400
|
-
const modulePlugins = [
|
|
401
|
-
wordpressExternalsPlugin( `${ baseFileName }.min`, 'esm' ),
|
|
402
|
-
];
|
|
403
409
|
|
|
404
410
|
builds.push(
|
|
405
411
|
esbuild.build( {
|
|
@@ -415,7 +421,14 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
415
421
|
platform: 'browser',
|
|
416
422
|
minify: true,
|
|
417
423
|
define: getDefine( false ),
|
|
418
|
-
plugins:
|
|
424
|
+
plugins: [
|
|
425
|
+
wordpressExternalsPlugin(
|
|
426
|
+
`${ baseFileName }.min`,
|
|
427
|
+
'esm',
|
|
428
|
+
[],
|
|
429
|
+
true // Generate asset file for minified build
|
|
430
|
+
),
|
|
431
|
+
],
|
|
419
432
|
} ),
|
|
420
433
|
esbuild.build( {
|
|
421
434
|
entryPoints: [ entryPoint ],
|
|
@@ -430,14 +443,21 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
430
443
|
platform: 'browser',
|
|
431
444
|
minify: false,
|
|
432
445
|
define: getDefine( true ),
|
|
433
|
-
plugins:
|
|
446
|
+
plugins: [
|
|
447
|
+
wordpressExternalsPlugin(
|
|
448
|
+
`${ baseFileName }.min`,
|
|
449
|
+
'esm',
|
|
450
|
+
[],
|
|
451
|
+
false // Skip asset file for non-minified build
|
|
452
|
+
),
|
|
453
|
+
],
|
|
434
454
|
} )
|
|
435
455
|
);
|
|
436
456
|
|
|
437
457
|
const scriptModuleId =
|
|
438
458
|
exportName === '.'
|
|
439
|
-
?
|
|
440
|
-
:
|
|
459
|
+
? `@${ packageNamespace }/${ packageName }`
|
|
460
|
+
: `@${ packageNamespace }/${ packageName }/${ fileName }`;
|
|
441
461
|
|
|
442
462
|
builtModules.push( {
|
|
443
463
|
id: scriptModuleId,
|
|
@@ -451,7 +471,6 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
451
471
|
if ( packageJson.wpScript ) {
|
|
452
472
|
const buildStyleDir = path.join( packageDir, 'build-style' );
|
|
453
473
|
const outputDir = path.join( BUILD_DIR, 'styles', packageName );
|
|
454
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
455
474
|
|
|
456
475
|
const cssFiles = await glob(
|
|
457
476
|
normalizePath( path.join( buildStyleDir, '**/*.css' ) )
|
|
@@ -467,36 +486,39 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
467
486
|
hasMainStyle = true;
|
|
468
487
|
}
|
|
469
488
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
489
|
+
// Generate minified path: style.css -> style.min.css, style-rtl.css -> style-rtl.min.css
|
|
490
|
+
const minifiedPath = destPath.replace( /\.css$/, '.min.css' );
|
|
491
|
+
|
|
492
|
+
// Always produce both versions (like JavaScript does):
|
|
493
|
+
// 1. Non-minified version (for SCRIPT_DEBUG=true)
|
|
494
|
+
// 2. Minified version (for SCRIPT_DEBUG=false)
|
|
495
|
+
builds.push(
|
|
496
|
+
( async () => {
|
|
497
|
+
await mkdir( destDir, { recursive: true } );
|
|
498
|
+
const content = await readFile( cssFile, 'utf8' );
|
|
499
|
+
|
|
500
|
+
// Write non-minified version
|
|
501
|
+
await writeFile( destPath, content );
|
|
502
|
+
|
|
503
|
+
// Write minified version
|
|
504
|
+
const result = await postcss( [
|
|
505
|
+
cssnano( {
|
|
506
|
+
preset: [
|
|
507
|
+
'default',
|
|
508
|
+
{
|
|
509
|
+
discardComments: {
|
|
510
|
+
removeAll: true,
|
|
483
511
|
},
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
)
|
|
493
|
-
|
|
494
|
-
builds.push(
|
|
495
|
-
mkdir( destDir, { recursive: true } ).then( () =>
|
|
496
|
-
copyFile( cssFile, destPath )
|
|
497
|
-
)
|
|
498
|
-
);
|
|
499
|
-
}
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
} ),
|
|
515
|
+
] ).process( content, {
|
|
516
|
+
from: cssFile,
|
|
517
|
+
to: minifiedPath,
|
|
518
|
+
} );
|
|
519
|
+
await writeFile( minifiedPath, result.css );
|
|
520
|
+
} )()
|
|
521
|
+
);
|
|
500
522
|
}
|
|
501
523
|
}
|
|
502
524
|
|
|
@@ -603,7 +625,10 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
603
625
|
?.map( ( d ) => d.replace( /'/g, '' ) ) || [];
|
|
604
626
|
}
|
|
605
627
|
|
|
606
|
-
const styleDeps = await inferStyleDependencies(
|
|
628
|
+
const styleDeps = await inferStyleDependencies(
|
|
629
|
+
scriptDependencies,
|
|
630
|
+
packageName
|
|
631
|
+
);
|
|
607
632
|
|
|
608
633
|
builtStyles.push( {
|
|
609
634
|
handle: `${ handlePrefix }-${ packageName }`,
|
|
@@ -627,14 +652,17 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
627
652
|
* 3. Actually have a built style.css file
|
|
628
653
|
*
|
|
629
654
|
* @param {string[]} scriptDependencies Array of script handles from asset file.
|
|
655
|
+
* @param {string} packageName Package name (short name) being bundled, for context-aware resolution.
|
|
630
656
|
* @return {Promise<string[]>} Array of style handles to depend on.
|
|
631
657
|
*/
|
|
632
|
-
async function inferStyleDependencies( scriptDependencies ) {
|
|
658
|
+
async function inferStyleDependencies( scriptDependencies, packageName ) {
|
|
633
659
|
if ( ! scriptDependencies || scriptDependencies.length === 0 ) {
|
|
634
660
|
return [];
|
|
635
661
|
}
|
|
636
662
|
|
|
637
663
|
const styleDeps = [];
|
|
664
|
+
// Get the resolve directory for context-aware package resolution
|
|
665
|
+
const resolveDir = path.join( PACKAGES_DIR, packageName );
|
|
638
666
|
|
|
639
667
|
for ( const scriptHandle of scriptDependencies ) {
|
|
640
668
|
// Skip non-package dependencies (like 'react', 'lodash', etc.)
|
|
@@ -642,13 +670,13 @@ async function inferStyleDependencies( scriptDependencies ) {
|
|
|
642
670
|
continue;
|
|
643
671
|
}
|
|
644
672
|
|
|
645
|
-
// Convert handle to package name: 'wp-components' → 'components'
|
|
673
|
+
// Convert handle to package name: 'wp-components' → '@wordpress/components'
|
|
646
674
|
const shortName = scriptHandle.replace( 'wp-', '' );
|
|
647
675
|
const depPackageName = `@wordpress/${ shortName }`;
|
|
648
676
|
|
|
649
|
-
// Read the dependency's package.json
|
|
677
|
+
// Read the dependency's package.json with context-aware resolution
|
|
650
678
|
try {
|
|
651
|
-
const depPackageJson = getPackageInfo( depPackageName );
|
|
679
|
+
const depPackageJson = getPackageInfo( depPackageName, resolveDir );
|
|
652
680
|
|
|
653
681
|
if ( ! depPackageJson ) {
|
|
654
682
|
continue;
|
|
@@ -746,14 +774,14 @@ async function generateScriptRegistrationPhp( scripts, replacements ) {
|
|
|
746
774
|
}
|
|
747
775
|
|
|
748
776
|
/**
|
|
749
|
-
* Generate PHP file for version
|
|
777
|
+
* Generate PHP file for constants (version and build URL).
|
|
750
778
|
*
|
|
751
779
|
* @param {Record<string, string>} replacements PHP template replacements.
|
|
752
780
|
*/
|
|
753
|
-
async function
|
|
781
|
+
async function generateConstantsPhp( replacements ) {
|
|
754
782
|
await generatePhpFromTemplate(
|
|
755
|
-
'
|
|
756
|
-
path.join( BUILD_DIR, '
|
|
783
|
+
'constants.php.template',
|
|
784
|
+
path.join( BUILD_DIR, 'constants.php' ),
|
|
757
785
|
replacements
|
|
758
786
|
);
|
|
759
787
|
}
|
|
@@ -1002,7 +1030,12 @@ async function transpilePackage( packageName ) {
|
|
|
1002
1030
|
name: 'externalize-except-css',
|
|
1003
1031
|
setup( build ) {
|
|
1004
1032
|
// Externalize all non-CSS imports
|
|
1005
|
-
build.onResolve( { filter: /.*/ }, ( args ) => {
|
|
1033
|
+
build.onResolve( { filter: /.*/ }, async ( args ) => {
|
|
1034
|
+
// Skip recursive calls.
|
|
1035
|
+
if ( args.pluginData?.__fromExternalize ) {
|
|
1036
|
+
return null;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1006
1039
|
// Skip entry points
|
|
1007
1040
|
if ( args.kind === 'entry-point' ) {
|
|
1008
1041
|
return null;
|
|
@@ -1013,6 +1046,44 @@ async function transpilePackage( packageName ) {
|
|
|
1013
1046
|
return null;
|
|
1014
1047
|
}
|
|
1015
1048
|
|
|
1049
|
+
// Fully resolve local dependencies without file extension
|
|
1050
|
+
// and replace the extension with the target extension.
|
|
1051
|
+
if ( args.path.startsWith( '.' ) ) {
|
|
1052
|
+
const resolved = await build.resolve( args.path, {
|
|
1053
|
+
namespace: args.namespace,
|
|
1054
|
+
importer: args.importer,
|
|
1055
|
+
kind: args.kind,
|
|
1056
|
+
resolveDir: args.resolveDir,
|
|
1057
|
+
with: args.with,
|
|
1058
|
+
pluginData: {
|
|
1059
|
+
...args.pluginData,
|
|
1060
|
+
__fromExternalize: true,
|
|
1061
|
+
},
|
|
1062
|
+
} );
|
|
1063
|
+
|
|
1064
|
+
if ( resolved.errors.length > 0 ) {
|
|
1065
|
+
return resolved;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// Relativize path: make it relative to resolveDir with leading ./
|
|
1069
|
+
let relativePath = normalizePath(
|
|
1070
|
+
path.relative( args.resolveDir, resolved.path )
|
|
1071
|
+
);
|
|
1072
|
+
if ( ! relativePath.startsWith( '.' ) ) {
|
|
1073
|
+
relativePath = './' + relativePath;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// Replace extension: make sure that file extension is always `.mjs` or `.cjs`.
|
|
1077
|
+
const newExt =
|
|
1078
|
+
build.initialOptions.format === 'cjs' ? '.cjs' : '.mjs';
|
|
1079
|
+
relativePath = relativePath.replace( /\.[jt]sx?$/, newExt );
|
|
1080
|
+
|
|
1081
|
+
return {
|
|
1082
|
+
path: relativePath,
|
|
1083
|
+
external: true,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1016
1087
|
// Externalize everything else (keep imports as-is)
|
|
1017
1088
|
return { path: args.path, external: true };
|
|
1018
1089
|
} );
|
|
@@ -1030,6 +1101,7 @@ async function transpilePackage( packageName ) {
|
|
|
1030
1101
|
entryPoints: srcFiles,
|
|
1031
1102
|
outdir: buildDir,
|
|
1032
1103
|
outbase: srcDir,
|
|
1104
|
+
outExtension: { '.js': '.cjs' },
|
|
1033
1105
|
bundle: true,
|
|
1034
1106
|
platform: 'node',
|
|
1035
1107
|
format: 'cjs',
|
|
@@ -1037,9 +1109,7 @@ async function transpilePackage( packageName ) {
|
|
|
1037
1109
|
target,
|
|
1038
1110
|
jsx: 'automatic',
|
|
1039
1111
|
jsxImportSource: 'react',
|
|
1040
|
-
loader: {
|
|
1041
|
-
'.js': 'jsx',
|
|
1042
|
-
},
|
|
1112
|
+
loader: { '.js': 'jsx' },
|
|
1043
1113
|
plugins,
|
|
1044
1114
|
} )
|
|
1045
1115
|
);
|
|
@@ -1062,6 +1132,7 @@ async function transpilePackage( packageName ) {
|
|
|
1062
1132
|
entryPoints: srcFiles,
|
|
1063
1133
|
outdir: buildModuleDir,
|
|
1064
1134
|
outbase: srcDir,
|
|
1135
|
+
outExtension: { '.js': '.mjs' },
|
|
1065
1136
|
bundle: true,
|
|
1066
1137
|
platform: 'neutral',
|
|
1067
1138
|
format: 'esm',
|
|
@@ -1069,9 +1140,7 @@ async function transpilePackage( packageName ) {
|
|
|
1069
1140
|
target,
|
|
1070
1141
|
jsx: 'automatic',
|
|
1071
1142
|
jsxImportSource: 'react',
|
|
1072
|
-
loader: {
|
|
1073
|
-
'.js': 'jsx',
|
|
1074
|
-
},
|
|
1143
|
+
loader: { '.js': 'jsx' },
|
|
1075
1144
|
plugins,
|
|
1076
1145
|
} )
|
|
1077
1146
|
);
|
|
@@ -1279,10 +1348,6 @@ async function buildRoute( routeName ) {
|
|
|
1279
1348
|
} );
|
|
1280
1349
|
|
|
1281
1350
|
if ( routeEntryPoints.length > 0 ) {
|
|
1282
|
-
const routePlugins = [
|
|
1283
|
-
wordpressExternalsPlugin( 'route.min', 'esm' ),
|
|
1284
|
-
];
|
|
1285
|
-
|
|
1286
1351
|
// Build both minified and non-minified versions in parallel
|
|
1287
1352
|
await Promise.all( [
|
|
1288
1353
|
esbuild.build( {
|
|
@@ -1293,7 +1358,14 @@ async function buildRoute( routeName ) {
|
|
|
1293
1358
|
target: browserslistToEsbuild(),
|
|
1294
1359
|
minify: true,
|
|
1295
1360
|
define: getDefine( false ),
|
|
1296
|
-
plugins:
|
|
1361
|
+
plugins: [
|
|
1362
|
+
wordpressExternalsPlugin(
|
|
1363
|
+
'route.min',
|
|
1364
|
+
'esm',
|
|
1365
|
+
[],
|
|
1366
|
+
true // Generate asset file for minified build
|
|
1367
|
+
),
|
|
1368
|
+
],
|
|
1297
1369
|
} ),
|
|
1298
1370
|
esbuild.build( {
|
|
1299
1371
|
entryPoints: routeEntryPoints,
|
|
@@ -1303,7 +1375,14 @@ async function buildRoute( routeName ) {
|
|
|
1303
1375
|
target: browserslistToEsbuild(),
|
|
1304
1376
|
minify: false,
|
|
1305
1377
|
define: getDefine( true ),
|
|
1306
|
-
plugins:
|
|
1378
|
+
plugins: [
|
|
1379
|
+
wordpressExternalsPlugin(
|
|
1380
|
+
'route.min',
|
|
1381
|
+
'esm',
|
|
1382
|
+
[],
|
|
1383
|
+
false // Skip asset file for non-minified build
|
|
1384
|
+
),
|
|
1385
|
+
],
|
|
1307
1386
|
} ),
|
|
1308
1387
|
] );
|
|
1309
1388
|
}
|
|
@@ -1318,11 +1397,6 @@ async function buildRoute( routeName ) {
|
|
|
1318
1397
|
// Write temporary entry file
|
|
1319
1398
|
await writeFile( tempEntryPath, syntheticEntry );
|
|
1320
1399
|
|
|
1321
|
-
const contentPlugins = [
|
|
1322
|
-
wordpressExternalsPlugin( 'content.min', 'esm' ),
|
|
1323
|
-
...styleBundlingPlugins,
|
|
1324
|
-
];
|
|
1325
|
-
|
|
1326
1400
|
// Build both minified and non-minified versions in parallel
|
|
1327
1401
|
await Promise.all( [
|
|
1328
1402
|
esbuild.build( {
|
|
@@ -1333,7 +1407,15 @@ async function buildRoute( routeName ) {
|
|
|
1333
1407
|
target: browserslistToEsbuild(),
|
|
1334
1408
|
minify: true,
|
|
1335
1409
|
define: getDefine( false ),
|
|
1336
|
-
plugins:
|
|
1410
|
+
plugins: [
|
|
1411
|
+
wordpressExternalsPlugin(
|
|
1412
|
+
'content.min',
|
|
1413
|
+
'esm',
|
|
1414
|
+
[],
|
|
1415
|
+
true // Generate asset file for minified build
|
|
1416
|
+
),
|
|
1417
|
+
...styleBundlingPlugins,
|
|
1418
|
+
],
|
|
1337
1419
|
} ),
|
|
1338
1420
|
esbuild.build( {
|
|
1339
1421
|
entryPoints: [ tempEntryPath ],
|
|
@@ -1343,7 +1425,15 @@ async function buildRoute( routeName ) {
|
|
|
1343
1425
|
target: browserslistToEsbuild(),
|
|
1344
1426
|
minify: false,
|
|
1345
1427
|
define: getDefine( true ),
|
|
1346
|
-
plugins:
|
|
1428
|
+
plugins: [
|
|
1429
|
+
wordpressExternalsPlugin(
|
|
1430
|
+
'content.min',
|
|
1431
|
+
'esm',
|
|
1432
|
+
[],
|
|
1433
|
+
false // Skip asset file for non-minified build
|
|
1434
|
+
),
|
|
1435
|
+
...styleBundlingPlugins,
|
|
1436
|
+
],
|
|
1347
1437
|
} ),
|
|
1348
1438
|
] );
|
|
1349
1439
|
|
|
@@ -1380,24 +1470,28 @@ async function buildAllRoutes() {
|
|
|
1380
1470
|
|
|
1381
1471
|
/**
|
|
1382
1472
|
* Main build function.
|
|
1473
|
+
*
|
|
1474
|
+
* @param {string?} baseUrlExpression
|
|
1383
1475
|
*/
|
|
1384
|
-
async function buildAll() {
|
|
1476
|
+
async function buildAll( baseUrlExpression ) {
|
|
1385
1477
|
console.log( '🔨 Building packages...\n' );
|
|
1386
1478
|
|
|
1387
1479
|
const startTime = Date.now();
|
|
1388
1480
|
|
|
1389
|
-
// Build maps: short name ↔ full name from package.json
|
|
1481
|
+
// Build maps: short name ↔ full name ↔ package.json from package.json files
|
|
1390
1482
|
const shortToFull = new Map();
|
|
1391
1483
|
const fullToShort = new Map();
|
|
1484
|
+
const fullToPackageJson = new Map();
|
|
1392
1485
|
for ( const pkg of PACKAGES ) {
|
|
1393
1486
|
const packageJson = getPackageInfoFromFile(
|
|
1394
1487
|
path.join( PACKAGES_DIR, pkg, 'package.json' )
|
|
1395
1488
|
);
|
|
1396
1489
|
shortToFull.set( pkg, packageJson.name );
|
|
1397
1490
|
fullToShort.set( packageJson.name, pkg );
|
|
1491
|
+
fullToPackageJson.set( packageJson.name, packageJson );
|
|
1398
1492
|
}
|
|
1399
1493
|
|
|
1400
|
-
const levels = groupByDepth(
|
|
1494
|
+
const levels = groupByDepth( fullToPackageJson );
|
|
1401
1495
|
|
|
1402
1496
|
console.log( '📝 Phase 1: Transpiling packages...\n' );
|
|
1403
1497
|
|
|
@@ -1444,26 +1538,40 @@ async function buildAll() {
|
|
|
1444
1538
|
await buildAllRoutes();
|
|
1445
1539
|
|
|
1446
1540
|
// Collect route and page data for PHP generation
|
|
1447
|
-
|
|
1541
|
+
// Use flatMap to expand routes with multiple pages into separate entries
|
|
1542
|
+
const routes = getAllRoutes( ROOT_DIR ).flatMap( ( routeName ) => {
|
|
1448
1543
|
const metadata = getRouteMetadata( ROOT_DIR, routeName );
|
|
1544
|
+
|
|
1545
|
+
// Skip routes without pages
|
|
1546
|
+
if ( ! metadata || ! metadata.pages || metadata.pages.length === 0 ) {
|
|
1547
|
+
return [];
|
|
1548
|
+
}
|
|
1449
1549
|
const routeFiles = getRouteFiles(
|
|
1450
1550
|
path.join( ROOT_DIR, 'routes', routeName )
|
|
1451
1551
|
);
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1552
|
+
|
|
1553
|
+
// Create a route entry for each page
|
|
1554
|
+
return metadata.pages.map( ( page ) => {
|
|
1555
|
+
return {
|
|
1556
|
+
name: routeName,
|
|
1557
|
+
path: metadata.path,
|
|
1558
|
+
page,
|
|
1559
|
+
hasRoute: routeFiles.hasRoute,
|
|
1560
|
+
hasContent: routeFiles.hasStage || routeFiles.hasInspector,
|
|
1561
|
+
};
|
|
1562
|
+
} );
|
|
1459
1563
|
} );
|
|
1460
1564
|
|
|
1461
1565
|
// Normalize PAGES config to support both string and object formats
|
|
1462
1566
|
const normalizedPages = PAGES.map( ( page ) => {
|
|
1463
1567
|
if ( typeof page === 'string' ) {
|
|
1464
|
-
return { id: page, init: [] };
|
|
1568
|
+
return { id: page, init: [], title: undefined };
|
|
1465
1569
|
}
|
|
1466
|
-
return {
|
|
1570
|
+
return {
|
|
1571
|
+
id: page.id,
|
|
1572
|
+
init: page.init || [],
|
|
1573
|
+
title: page.title || undefined,
|
|
1574
|
+
};
|
|
1467
1575
|
} );
|
|
1468
1576
|
|
|
1469
1577
|
const pageData = normalizedPages.map( ( page ) => {
|
|
@@ -1472,6 +1580,7 @@ async function buildAll() {
|
|
|
1472
1580
|
slug: page.id,
|
|
1473
1581
|
routes: pageRoutes,
|
|
1474
1582
|
initModules: page.init,
|
|
1583
|
+
title: page.title,
|
|
1475
1584
|
};
|
|
1476
1585
|
} );
|
|
1477
1586
|
|
|
@@ -1521,13 +1630,16 @@ async function buildAll() {
|
|
|
1521
1630
|
}
|
|
1522
1631
|
|
|
1523
1632
|
console.log( '\n📄 Generating PHP registration files...\n' );
|
|
1524
|
-
const phpReplacements = await getPhpReplacements(
|
|
1633
|
+
const phpReplacements = await getPhpReplacements(
|
|
1634
|
+
ROOT_DIR,
|
|
1635
|
+
baseUrlExpression
|
|
1636
|
+
);
|
|
1525
1637
|
await Promise.all( [
|
|
1526
1638
|
generateMainIndexPhp( phpReplacements ),
|
|
1527
1639
|
generateModuleRegistrationPhp( modules, phpReplacements ),
|
|
1528
1640
|
generateScriptRegistrationPhp( scripts, phpReplacements ),
|
|
1529
1641
|
generateStyleRegistrationPhp( styles, phpReplacements ),
|
|
1530
|
-
|
|
1642
|
+
generateConstantsPhp( phpReplacements ),
|
|
1531
1643
|
generateRoutesRegistry( routes, phpReplacements ),
|
|
1532
1644
|
generateRoutesPhp( routes, phpReplacements ),
|
|
1533
1645
|
generatePagesPhp( pageData, phpReplacements ),
|
|
@@ -1566,17 +1678,18 @@ async function watchMode() {
|
|
|
1566
1678
|
let isRebuilding = false;
|
|
1567
1679
|
const needsRebuild = new Set();
|
|
1568
1680
|
|
|
1569
|
-
// Build maps: short name ↔ full name from package.json (once)
|
|
1681
|
+
// Build maps: short name ↔ full name ↔ package.json from package.json files (once)
|
|
1570
1682
|
const shortToFull = new Map();
|
|
1571
1683
|
const fullToShort = new Map();
|
|
1684
|
+
const fullToPackageJson = new Map();
|
|
1572
1685
|
for ( const pkg of PACKAGES ) {
|
|
1573
1686
|
const packageJson = getPackageInfoFromFile(
|
|
1574
1687
|
path.join( PACKAGES_DIR, pkg, 'package.json' )
|
|
1575
1688
|
);
|
|
1576
1689
|
shortToFull.set( pkg, packageJson.name );
|
|
1577
1690
|
fullToShort.set( packageJson.name, pkg );
|
|
1691
|
+
fullToPackageJson.set( packageJson.name, packageJson );
|
|
1578
1692
|
}
|
|
1579
|
-
const allFullNames = Array.from( shortToFull.values() );
|
|
1580
1693
|
|
|
1581
1694
|
// Get all routes for dependency tracking
|
|
1582
1695
|
const allRoutes = getAllRoutes( ROOT_DIR );
|
|
@@ -1599,7 +1712,7 @@ async function watchMode() {
|
|
|
1599
1712
|
const fullName = shortToFull.get( packageName );
|
|
1600
1713
|
const affectedScripts = findScriptsToRebundle(
|
|
1601
1714
|
fullName,
|
|
1602
|
-
|
|
1715
|
+
fullToPackageJson
|
|
1603
1716
|
);
|
|
1604
1717
|
|
|
1605
1718
|
for ( const fullScript of affectedScripts ) {
|
|
@@ -1622,7 +1735,7 @@ async function watchMode() {
|
|
|
1622
1735
|
// Find and rebuild affected routes
|
|
1623
1736
|
const affectedRoutes = findRoutesToRebuild(
|
|
1624
1737
|
fullName,
|
|
1625
|
-
|
|
1738
|
+
fullToPackageJson,
|
|
1626
1739
|
ROOT_DIR,
|
|
1627
1740
|
allRoutes
|
|
1628
1741
|
);
|
|
@@ -1815,10 +1928,16 @@ async function main() {
|
|
|
1815
1928
|
short: 'w',
|
|
1816
1929
|
default: false,
|
|
1817
1930
|
},
|
|
1931
|
+
'base-url': {
|
|
1932
|
+
type: 'string',
|
|
1933
|
+
default: 'plugin_dir_url( __FILE__ )',
|
|
1934
|
+
},
|
|
1818
1935
|
},
|
|
1819
1936
|
} );
|
|
1820
1937
|
|
|
1821
|
-
|
|
1938
|
+
const baseUrlExpression = values[ 'base-url' ];
|
|
1939
|
+
|
|
1940
|
+
await buildAll( baseUrlExpression );
|
|
1822
1941
|
|
|
1823
1942
|
if ( values.watch ) {
|
|
1824
1943
|
console.log( '\n👀 Watching for changes...\n' );
|