(
{ dir }: OutputOptions,
outputToFilesystem: boolean | undefined,
context: PluginContext,
filePath: string,
fileSource: string
)
| 98 | } |
| 99 | |
| 100 | export async function emitFile( |
| 101 | { dir }: OutputOptions, |
| 102 | outputToFilesystem: boolean | undefined, |
| 103 | context: PluginContext, |
| 104 | filePath: string, |
| 105 | fileSource: string |
| 106 | ) { |
| 107 | const normalizedFilePath = normalizePath(filePath); |
| 108 | // const normalizedPath = normalizePath(filePath); |
| 109 | // Note: `dir` can be a value like `dist` in which case, `path.relative` could result in a value |
| 110 | // of something like `'../.tsbuildinfo'. Our else-case below needs to mimic `path.relative` |
| 111 | // returning a dot-notated relative path, so the first if-then branch is entered into |
| 112 | const relativePath = dir ? path.relative(dir, normalizedFilePath) : '..'; |
| 113 | |
| 114 | // legal paths do not start with . nor .. : https://github.com/rollup/rollup/issues/3507#issuecomment-616495912 |
| 115 | if (relativePath.startsWith('..')) { |
| 116 | if (outputToFilesystem == null) { |
| 117 | context.warn(`@rollup/plugin-typescript: outputToFilesystem option is defaulting to true.`); |
| 118 | } |
| 119 | if (outputToFilesystem !== false) { |
| 120 | await fs.mkdir(path.dirname(normalizedFilePath), { recursive: true }); |
| 121 | await fs.writeFile(normalizedFilePath, fileSource); |
| 122 | } |
| 123 | } else { |
| 124 | context.emitFile({ |
| 125 | type: 'asset', |
| 126 | fileName: relativePath, |
| 127 | source: fileSource |
| 128 | }); |
| 129 | } |
| 130 | } |
no test coverage detected