Skip to content

Commit 433c8fa

Browse files
committed
- writing out types for vue virtual modules #97
1 parent 54570f6 commit 433c8fa

6 files changed

+77
-80
lines changed

dist/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rollup-plugin-typescript2.cjs.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20168,31 +20168,30 @@ function typescript(options) {
2016820168
declarations[key] = { type: out.dts, map: out.dtsmap };
2016920169
});
2017020170
const bundleFile = file ? file : dest; // rollup 0.48+ has 'file' https://github.com/rollup/rollup/issues/1479
20171+
const writeDeclaration = (key, extension, entry) => {
20172+
if (!entry)
20173+
return;
20174+
let fileName = entry.name;
20175+
if (fileName.includes("?")) // HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.ts'
20176+
fileName = fileName.split("?", 1) + extension;
20177+
let writeToPath;
20178+
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
20179+
// use the path provided by Typescript's LanguageService.
20180+
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
20181+
writeToPath = fileName;
20182+
else {
20183+
// Otherwise, take the directory name from the path and make sure it is absolute.
20184+
const destDirname = path.dirname(bundleFile);
20185+
const destDirectory = path.isAbsolute(destDirname) ? destDirname : path.join(process.cwd(), destDirname);
20186+
writeToPath = path.join(destDirectory, path.relative(process.cwd(), fileName));
20187+
}
20188+
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
20189+
// Write the declaration file to disk.
20190+
tsModule.sys.writeFile(writeToPath, entry.text, entry.writeByteOrderMark);
20191+
};
2017120192
lodash_2(declarations, ({ type, map }, key) => {
20172-
lodash_2([type, map], (e) => {
20173-
if (!e)
20174-
return;
20175-
let writeToPath;
20176-
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
20177-
// use the path provided by Typescript's LanguageService.
20178-
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
20179-
writeToPath = e.name;
20180-
else {
20181-
// Otherwise, take the directory name from the path and make sure it is absolute.
20182-
const destDirname = path.dirname(bundleFile);
20183-
const destDirectory = path.isAbsolute(destDirname) ? destDirname : path.join(process.cwd(), destDirname);
20184-
writeToPath = path.join(destDirectory, path.relative(process.cwd(), e.name));
20185-
}
20186-
if (writeToPath.includes("?")) {
20187-
// HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.d.ts'
20188-
context.debug(() => `${safe_4("skipping declarations")} for '${key}', invalid file path`);
20189-
}
20190-
else {
20191-
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
20192-
// Write the declaration file to disk.
20193-
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
20194-
}
20195-
});
20193+
writeDeclaration(key, ".d.ts", type);
20194+
writeDeclaration(key, ".map.d.ts", map);
2019620195
});
2019720196
}
2019820197
},

dist/rollup-plugin-typescript2.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rollup-plugin-typescript2.es.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20164,31 +20164,30 @@ function typescript(options) {
2016420164
declarations[key] = { type: out.dts, map: out.dtsmap };
2016520165
});
2016620166
const bundleFile = file ? file : dest; // rollup 0.48+ has 'file' https://github.com/rollup/rollup/issues/1479
20167+
const writeDeclaration = (key, extension, entry) => {
20168+
if (!entry)
20169+
return;
20170+
let fileName = entry.name;
20171+
if (fileName.includes("?")) // HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.ts'
20172+
fileName = fileName.split("?", 1) + extension;
20173+
let writeToPath;
20174+
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
20175+
// use the path provided by Typescript's LanguageService.
20176+
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
20177+
writeToPath = fileName;
20178+
else {
20179+
// Otherwise, take the directory name from the path and make sure it is absolute.
20180+
const destDirname = dirname(bundleFile);
20181+
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
20182+
writeToPath = join(destDirectory, relative(process.cwd(), fileName));
20183+
}
20184+
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
20185+
// Write the declaration file to disk.
20186+
tsModule.sys.writeFile(writeToPath, entry.text, entry.writeByteOrderMark);
20187+
};
2016720188
lodash_2(declarations, ({ type, map }, key) => {
20168-
lodash_2([type, map], (e) => {
20169-
if (!e)
20170-
return;
20171-
let writeToPath;
20172-
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
20173-
// use the path provided by Typescript's LanguageService.
20174-
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
20175-
writeToPath = e.name;
20176-
else {
20177-
// Otherwise, take the directory name from the path and make sure it is absolute.
20178-
const destDirname = dirname(bundleFile);
20179-
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
20180-
writeToPath = join(destDirectory, relative(process.cwd(), e.name));
20181-
}
20182-
if (writeToPath.includes("?")) {
20183-
// HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.d.ts'
20184-
context.debug(() => `${safe_4("skipping declarations")} for '${key}', invalid file path`);
20185-
}
20186-
else {
20187-
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
20188-
// Write the declaration file to disk.
20189-
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
20190-
}
20191-
});
20189+
writeDeclaration(key, ".d.ts", type);
20190+
writeDeclaration(key, ".map.d.ts", map);
2019220191
});
2019320192
}
2019420193
},

dist/rollup-plugin-typescript2.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -308,39 +308,38 @@ export default function typescript(options?: Partial<IOptions>)
308308

309309
const bundleFile = file ? file : dest; // rollup 0.48+ has 'file' https://github.com/rollup/rollup/issues/1479
310310

311-
_.each(declarations, ({ type, map }, key) =>
311+
const writeDeclaration = (key: string, extension: string, entry?: tsTypes.OutputFile) =>
312312
{
313-
_.each([type, map], (e) =>
313+
if (!entry)
314+
return;
315+
316+
let fileName = entry.name;
317+
if (fileName.includes("?")) // HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.ts'
318+
fileName = fileName.split("?", 1) + extension;
319+
320+
let writeToPath: string;
321+
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
322+
// use the path provided by Typescript's LanguageService.
323+
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
324+
writeToPath = fileName;
325+
else
314326
{
315-
if (!e)
316-
return;
317-
318-
let writeToPath: string;
319-
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
320-
// use the path provided by Typescript's LanguageService.
321-
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
322-
writeToPath = e.name;
323-
else
324-
{
325-
// Otherwise, take the directory name from the path and make sure it is absolute.
326-
const destDirname = dirname(bundleFile);
327-
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
328-
writeToPath = join(destDirectory, relative(process.cwd(), e.name));
329-
}
327+
// Otherwise, take the directory name from the path and make sure it is absolute.
328+
const destDirname = dirname(bundleFile);
329+
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
330+
writeToPath = join(destDirectory, relative(process.cwd(), fileName));
331+
}
330332

331-
if (writeToPath.includes("?"))
332-
{
333-
// HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.d.ts'
334-
context.debug(() => `${yellow("skipping declarations")} for '${key}', invalid file path`);
335-
}
336-
else
337-
{
338-
context.debug(() => `${blue("writing declarations")} for '${key}' to '${writeToPath}'`);
333+
context.debug(() => `${blue("writing declarations")} for '${key}' to '${writeToPath}'`);
339334

340-
// Write the declaration file to disk.
341-
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
342-
}
343-
});
335+
// Write the declaration file to disk.
336+
tsModule.sys.writeFile(writeToPath, entry.text, entry.writeByteOrderMark);
337+
};
338+
339+
_.each(declarations, ({ type, map }, key) =>
340+
{
341+
writeDeclaration(key, ".d.ts", type);
342+
writeDeclaration(key, ".map.d.ts", map);
344343
});
345344
}
346345
},

0 commit comments

Comments
 (0)