|
2 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
3 | 3 | import * as path from "path"; |
4 | 4 | import * as net from "net"; |
| 5 | +import * as fs from "fs"; |
5 | 6 | import stripJsonComments = require("strip-json-comments"); |
6 | 7 | import { logger } from "@vscode/debugadapter"; |
7 | 8 | import { Address4, Address6 } from "ip-address"; |
8 | 9 | import { ChildProcess } from "./node/childProcess"; |
9 | 10 | import { HostPlatform } from "./hostPlatform"; |
| 11 | +import { FileSystem } from "./node/fileSystem"; |
10 | 12 | import customRequire from "./customRequire"; |
11 | 13 |
|
12 | 14 | // eslint-disable-next-line @typescript-eslint/no-var-requires |
@@ -124,3 +126,57 @@ export function ipToBuffer(ip: string): Buffer { |
124 | 126 | } |
125 | 127 | throw new Error("Invalid IP address format."); |
126 | 128 | } |
| 129 | + |
| 130 | +export async function switchBundleOptions(projectRootPath: string, flag: boolean) { |
| 131 | + const splitBundleOptionsPath = path.resolve( |
| 132 | + projectRootPath, |
| 133 | + "node_modules", |
| 134 | + "metro", |
| 135 | + "src", |
| 136 | + "lib", |
| 137 | + "splitBundleOptions.js", |
| 138 | + ); |
| 139 | + const splitBundleOptionsContent = fs.readFileSync(splitBundleOptionsPath, "utf-8"); |
| 140 | + let modifiedData; |
| 141 | + if (flag) { |
| 142 | + modifiedData = splitBundleOptionsContent.replace( |
| 143 | + /excludeSource:\s*options\.excludeSource/, |
| 144 | + "excludeSource: false", |
| 145 | + ); |
| 146 | + |
| 147 | + modifiedData = modifiedData.replace( |
| 148 | + /sourcePaths:\s*options\.sourcePaths/, |
| 149 | + 'sourcePaths: "absolute"', |
| 150 | + ); |
| 151 | + } else { |
| 152 | + modifiedData = splitBundleOptionsContent.replace( |
| 153 | + /excludeSource:\s*false/, |
| 154 | + "excludeSource: options.excludeSource", |
| 155 | + ); |
| 156 | + |
| 157 | + modifiedData = modifiedData.replace( |
| 158 | + /sourcePaths:\s*"absolute"/, |
| 159 | + "sourcePaths: options.sourcePaths", |
| 160 | + ); |
| 161 | + } |
| 162 | + const nodeFileSystem = new FileSystem(); |
| 163 | + await nodeFileSystem.writeFile(splitBundleOptionsPath, modifiedData); |
| 164 | +} |
| 165 | + |
| 166 | +export function checkBundleOptions(projectRootPath: string): boolean { |
| 167 | + const splitBundleOptionsPath = path.resolve( |
| 168 | + projectRootPath, |
| 169 | + "node_modules", |
| 170 | + "metro", |
| 171 | + "src", |
| 172 | + "lib", |
| 173 | + "splitBundleOptions.js", |
| 174 | + ); |
| 175 | + |
| 176 | + const splitBundleOptionsContent = fs.readFileSync(splitBundleOptionsPath, "utf-8"); |
| 177 | + |
| 178 | + const excludeSourceRegex = /excludeSource\s*:\s*false/.test(splitBundleOptionsContent); |
| 179 | + const sourcePathsRegex = /sourcePaths\s*:\s*"absolute"/.test(splitBundleOptionsContent); |
| 180 | + |
| 181 | + return excludeSourceRegex && sourcePathsRegex; |
| 182 | +} |
0 commit comments