-
Notifications
You must be signed in to change notification settings - Fork 1
Release v1.7.13
#467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release v1.7.13
#467
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Applies the bundled Lexical patches via patch-package. | ||
| * | ||
| * Runs in two contexts: | ||
| * 1. Local development checkout — patches apply to this package's own | ||
| * node_modules. | ||
| * 2. Installed as a dependency of a host project — npm hoists lexical to the | ||
| * host's node_modules, so patch-package must run from the host project | ||
| * root with --patch-dir pointing back at this package's patches directory. | ||
| * Running it from this package's own directory would look for | ||
| * node_modules/@bsf/force-ui/node_modules/lexical, which doesn't exist. | ||
| */ | ||
| const fs = require( 'fs' ); | ||
| const path = require( 'path' ); | ||
| const { spawnSync } = require( 'child_process' ); | ||
|
|
||
| const pkgDir = __dirname; | ||
| const patchDir = path.join( pkgDir, 'patches' ); | ||
|
|
||
| if ( ! fs.existsSync( patchDir ) ) { | ||
| process.exit( 0 ); | ||
| } | ||
|
|
||
| const segments = pkgDir.split( path.sep ); | ||
| const nmIndex = segments.lastIndexOf( 'node_modules' ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What: Validate the existence of the patch binary before attempting to execute it. Why: Directly constructing the path to the 'patch-package' binary without validating its existence increases the chance of runtime errors. This would enhance the robustness of the script. How: Add a check after defining |
||
| const appRoot = | ||
| nmIndex === -1 | ||
| ? pkgDir | ||
| : segments.slice( 0, nmIndex ).join( path.sep ) || path.sep; | ||
|
|
||
| let patchPackageBin; | ||
| try { | ||
| const manifestPath = require.resolve( 'patch-package/package.json', { | ||
| paths: [ appRoot, pkgDir ], | ||
| } ); | ||
| const manifest = JSON.parse( fs.readFileSync( manifestPath, 'utf8' ) ); | ||
| const binEntry = | ||
| typeof manifest.bin === 'string' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What: Consider using Why: Using synchronous calls might block the event loop, especially if this script is executed in a larger context, which could lead to performance bottlenecks. How: Switch to using |
||
| ? manifest.bin | ||
| : manifest.bin[ 'patch-package' ]; | ||
| patchPackageBin = path.join( path.dirname( manifestPath ), binEntry ); | ||
| } catch ( error ) { | ||
| // patch-package is unavailable; skip rather than break the host install. | ||
| process.exit( 0 ); | ||
| } | ||
|
|
||
| const result = spawnSync( | ||
| process.execPath, | ||
| [ patchPackageBin, '--patch-dir', path.relative( appRoot, patchDir ) ], | ||
| { cwd: appRoot, stdio: 'inherit' } | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What: Ensure the exit status checks are handled properly after executing the patch command. Why: While the current implementation checks the result of the command execution, it is beneficial to provide specific behavior based on different exit statuses (e.g., 0 for success, others for failure) to offer better context. How: Instead of exiting with a direct mapping to |
||
|
|
||
| process.exit( result.status === null ? 1 : result.status ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What: Consider adding error handling for filesystem operations.
Why: While the current implementation will exit gracefully if the patch directory does not exist or if 'patch-package' is unavailable, it lacks detailed feedback. Proper error handling can help in understanding the failure points during execution.
How: Use
console.error()to log specific error messages beforeprocess.exit. This can provide context on issues for future debugging.