* Copies a file from src to the TestSandbox. If copying a `.js` file which * has an accompanying `.js.map` file in the src file location, the dest file * will have its sourceMappingURL updated to point to the original file as * an absolute path so you don't need to copy the map file. *
(
src: string,
dest?: string,
transform?: (content: string) => string,
)
| 135 | * @param transform - Optional. A function to transform the file content. |
| 136 | */ |
| 137 | async copyFile( |
| 138 | src: string, |
| 139 | dest?: string, |
| 140 | transform?: (content: string) => string, |
| 141 | ): Promise<void> { |
| 142 | dest = dest |
| 143 | ? resolve(this.path, dest) |
| 144 | : resolve(this.path, parse(src).base); |
| 145 | |
| 146 | if (transform == null) { |
| 147 | await copy(src, dest); |
| 148 | } else { |
| 149 | let content = await readFile(src, 'utf-8'); |
| 150 | content = transform(content); |
| 151 | await outputFile(dest, content, {encoding: 'utf-8'}); |
| 152 | } |
| 153 | |
| 154 | if (parse(src).ext === '.js' && (await pathExists(src + '.map'))) { |
| 155 | const srcMap = src + '.map'; |
| 156 | await appendFile(dest, `\n//# sourceMappingURL=${srcMap}`); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Creates a new file and writes the given data serialized as JSON. |