MCPcopy Index your code
hub / github.com/rollup/plugins / emitFile

Function emitFile

packages/typescript/src/outputFile.ts:100–130  ·  view source on GitHub ↗
(
  { dir }: OutputOptions,
  outputToFilesystem: boolean | undefined,
  context: PluginContext,
  filePath: string,
  fileSource: string
)

Source from the content-addressed store, hash-verified

98}
99
100export 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}

Callers 1

generateBundleFunction · 0.90

Calls 1

normalizePathFunction · 0.70

Tested by

no test coverage detected