UNPKG

@google-cloud/storage-control

Version:
86 lines (84 loc) 3.52 kB
"use strict"; // Copyright 2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.fixIndexFile = fixIndexFile; exports.fixV2Index = fixV2Index; const fs = require("fs"); const path = require("path"); /** * Fixes the content of an index file by overwriting it with a predefined correct content. * This function is specifically designed to correct `synthtool`-generated index files * to ensure the proper export of `v2`, `StorageControlClient`, and `protos`. * * @param filePath The path to the index file to fix, relative to the project root. */ function fixIndexFile(filePath) { const fullPath = path.join(__dirname, '..', '..', filePath); const correctContent = `// Copyright 2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // ** This file is automatically generated by synthtool. ** // ** https://github.com/googleapis/synthtool ** // ** All changes to this file may be overwritten. ** import * as v2 from './v2'; import {StorageControlClient} from './storage_control_client'; export {v2, StorageControlClient}; export default {v2, StorageControlClient}; import * as protos from '../protos/protos'; export {protos}; `; try { fs.writeFileSync(fullPath, correctContent, 'utf8'); console.log(`Successfully fixed: ${fullPath}`); } catch (err) { console.error(`Error writing to file ${fullPath}:`, err); } } /** * Fixes the v2 index file by ensuring the `StorageClient` is exported. * If the export statement is missing, it appends it to the file. * * @param filePath The path to the v2 index file to fix, relative to the current directory. */ function fixV2Index(filePath) { // TODO: this function can be removed when the nodejs_gapic_combined_pkg correctly exports from both libraries. const fullPath = path.join(__dirname, '..', filePath); if (fs.existsSync(fullPath)) { try { const data = fs.readFileSync(fullPath, 'utf8'); if (!data.includes("export {StorageClient} from './storage_client';")) { const result = data + "\nexport {StorageClient} from './storage_client';"; fs.writeFileSync(fullPath, result, 'utf8'); console.log(`Successfully fixed: ${fullPath}`); } } catch (err) { console.error(`Error processing file ${fullPath}:`, err); } } } //# sourceMappingURL=index_fix_utils.js.map