11#!/usr/bin/env node
22
33const { execSync } = require ( 'child_process' ) ;
4+ const fs = require ( 'fs' ) ;
45const os = require ( 'os' ) ;
56const chalk = require ( 'chalk' ) ;
67const minimist = require ( 'minimist' ) ;
@@ -106,13 +107,58 @@ const runCmd = (command, options = {}) => {
106107const getCurrentBranch = ( ) =>
107108 execSync ( 'git rev-parse --abbrev-ref HEAD' ) . toString ( ) . trim ( ) ;
108109
110+ /**
111+ * Builds print bundles under each element package's module directory (same as scripts/build sharedBuild).
112+ * Only packages that both declare a ./print export and appear in pslb/pslb.config.js `packages` get pslb
113+ * (blacklisted dirs like math-inline, select-text are excluded there).
114+ */
115+ const buildPrintModules = ( ) => {
116+ // eslint-disable-next-line global-require, import/no-dynamic-require
117+ const pslbConfig = require ( resolve ( CWD , 'pslb/pslb.config.js' ) ) ;
118+ const pslbAllowed = new Set ( pslbConfig . packages || [ ] ) ;
119+
120+ const packagesRoot = resolve ( CWD , 'packages' ) ;
121+ const dirNames = fs . readdirSync ( packagesRoot ) ;
122+ const withPrintExport = [ ] ;
123+
124+ for ( const d of dirNames ) {
125+ const pkgPath = resolve ( packagesRoot , d , 'package.json' ) ;
126+ if ( ! fs . existsSync ( pkgPath ) ) {
127+ continue ;
128+ }
129+ const pkg = JSON . parse ( fs . readFileSync ( pkgPath , 'utf8' ) ) ;
130+ if ( pkg . exports && pkg . exports [ './print' ] ) {
131+ withPrintExport . push ( pkg . name ) ;
132+ }
133+ }
134+
135+ const printPkgNames = withPrintExport . filter ( ( n ) => pslbAllowed . has ( n ) ) ;
136+ const skipped = withPrintExport . filter ( ( n ) => ! pslbAllowed . has ( n ) ) ;
137+ if ( skipped . length > 0 ) {
138+ warn (
139+ 'Skipping pslb for packages with ./print but not in pslb.config.js packages list:' ,
140+ skipped . join ( ', ' ) ,
141+ ) ;
142+ }
143+
144+ if ( printPkgNames . length === 0 ) {
145+ warn ( 'No pslb-eligible packages with ./print export; skipping pslb' ) ;
146+ return ;
147+ }
148+
149+ log ( 'print packages for pslb:' , printPkgNames . join ( ', ' ) ) ;
150+ const pkgFlags = printPkgNames . map ( ( n ) => `--package ${ n } ` ) . join ( ' ' ) ;
151+ runCmd ( `yarn pslb --config pslb/pslb.config.js ${ pkgFlags } --logLevel silly` ) ;
152+ } ;
153+
109154/**
110155 * Executes the build process, which consists of multiple sequential steps including:
111156 *
112157 * 1. Cleanup: Removes generated `lib` directories for all packages in the repository.
113158 * 2. Linting: Runs ESLint across specified source files with defined extensions.
114159 * 3. Transpilation: Uses Babel to build the code from source to output directories (`lib`)
115160 * while generating source maps and respecting defined ignore rules.
161+ * 4. Print modules: Runs pslb for packages with ./print that are listed in pslb.config.js (matches yarn build).
116162 */
117163const build = ( ) => {
118164 log ( chalk . magenta ( '--- STEP 1: CLEANUP ---' ) ) ;
@@ -129,6 +175,9 @@ const build = () => {
129175 runCmd (
130176 `${ binary ( `lerna` ) } exec -- ${ binary ( 'babel' ) } --ignore \'**/__test__/**\',\'**/__tests__/**\' src -d lib --source-maps --root-mode upward` ,
131177 ) ;
178+
179+ log ( chalk . magenta ( '--- STEP 4: PRINT MODULES (pslb) ---' ) ) ;
180+ buildPrintModules ( ) ;
132181} ;
133182
134183/**
0 commit comments