1- // scripts/patch-azure-sdk.js
1+ /**
2+ * Azure SDK ESM Import Compatibility Patch Script
3+ *
4+ * This script addresses an issue with unsupported ESM import paths in the Azure SDK module by replacing them
5+ * with compatible paths. This ensures that the module can be correctly resolved and executed in environments
6+ * that do not fully support ESM imports.
7+ *
8+ * The script performs the following actions:
9+ * - Checks if the target file exists in the specified path.
10+ * - Reads the file content and searches for the unsupported ESM import statement.
11+ * - Replaces the unsupported import with a compatible one if found.
12+ * - Logs the status of the patch process, indicating success, already patched, or if the target file is missing.
13+ * - Exits with an error code if the patching process encounters an error.
14+ *
15+ * Common error before patching:
16+ * ERROR Failed to compile with 1 error 5:12:59 PM
17+ *
18+ * This dependency was not found:
19+ *
20+ * * @ai -sdk/openai/internal in ./node_modules/@ai-sdk/azure/dist/index.mjs
21+ *
22+ * To install it, you can run: npm install --save @ai-sdk/openai/internal
23+ * No type errors found
24+ * Version: typescript 4.9.5
25+ * Time: 4294ms
26+ */
27+
228const fs = require ( 'fs' )
329const path = require ( 'path' )
430
@@ -14,12 +40,12 @@ try {
1440 if ( content . includes ( incorrectImport ) ) {
1541 content = content . replace ( incorrectImport , correctImport )
1642 fs . writeFileSync ( targetFilePath , content , 'utf8' )
17- console . log ( `✅ Successfully patched ${ targetFilePath } with correct import path.` )
43+ console . log ( `✅ Successfully patched ${ targetFilePath } with compatible import path.` )
1844 } else if ( content . includes ( correctImport ) ) {
19- console . log ( `☑️ File already patched or has correct import: ${ targetFilePath } . Skipping.` )
45+ console . log ( `☑️ File already patched or has compatible import: ${ targetFilePath } . Skipping.` )
2046 } else {
2147 console . warn (
22- `⚠️ Could not find the expected incorrect import statement in ${ targetFilePath } . Patch script might need an update.` ,
48+ `⚠️ Could not find the expected unsupported import statement in ${ targetFilePath } . Patch script might need an update.` ,
2349 )
2450 }
2551 } else {
2854 console . log ( '🎉 Azure SDK patch process completed.' )
2955} catch ( error ) {
3056 console . error ( `❌ Error during Azure SDK patch process for ${ targetFilePath } :` , error )
57+ console . error ( `📄 Error details: ${ error . message } ` )
3158 process . exit ( 1 ) // Exit with error code if patching fails
3259}
0 commit comments