- writing out types for vue virtual modules #97

This commit is contained in:
Eugene Zolenko 2018-07-17 15:33:52 -06:00
parent 54570f6a8c
commit 433c8fad6b
6 changed files with 79 additions and 82 deletions

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,cAAc,EAAkB,MAAM,WAAW,CAAC;AAE3E,OAAO,EAA8B,WAAW,EAAqB,MAAM,WAAW,CAAC;AAKvF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,CAAC,OAAO,qBAAqB,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC;;;;;;;;EAyU7D"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,cAAc,EAAkB,MAAM,WAAW,CAAC;AAE3E,OAAO,EAA8B,WAAW,EAAqB,MAAM,WAAW,CAAC;AAKvF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,CAAC,OAAO,qBAAqB,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC;;;;;;;;EAwU7D"}

View File

@ -20168,31 +20168,30 @@ function typescript(options) {
declarations[key] = { type: out.dts, map: out.dtsmap };
});
const bundleFile = file ? file : dest; // rollup 0.48+ has 'file' https://github.com/rollup/rollup/issues/1479
const writeDeclaration = (key, extension, entry) => {
if (!entry)
return;
let fileName = entry.name;
if (fileName.includes("?")) // HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.ts'
fileName = fileName.split("?", 1) + extension;
let writeToPath;
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
// use the path provided by Typescript's LanguageService.
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
writeToPath = fileName;
else {
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = path.dirname(bundleFile);
const destDirectory = path.isAbsolute(destDirname) ? destDirname : path.join(process.cwd(), destDirname);
writeToPath = path.join(destDirectory, path.relative(process.cwd(), fileName));
}
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, entry.text, entry.writeByteOrderMark);
};
lodash_2(declarations, ({ type, map }, key) => {
lodash_2([type, map], (e) => {
if (!e)
return;
let writeToPath;
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
// use the path provided by Typescript's LanguageService.
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
writeToPath = e.name;
else {
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = path.dirname(bundleFile);
const destDirectory = path.isAbsolute(destDirname) ? destDirname : path.join(process.cwd(), destDirname);
writeToPath = path.join(destDirectory, path.relative(process.cwd(), e.name));
}
if (writeToPath.includes("?")) {
// HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.d.ts'
context.debug(() => `${safe_4("skipping declarations")} for '${key}', invalid file path`);
}
else {
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
}
});
writeDeclaration(key, ".d.ts", type);
writeDeclaration(key, ".map.d.ts", map);
});
}
},

File diff suppressed because one or more lines are too long

View File

@ -20164,31 +20164,30 @@ function typescript(options) {
declarations[key] = { type: out.dts, map: out.dtsmap };
});
const bundleFile = file ? file : dest; // rollup 0.48+ has 'file' https://github.com/rollup/rollup/issues/1479
const writeDeclaration = (key, extension, entry) => {
if (!entry)
return;
let fileName = entry.name;
if (fileName.includes("?")) // HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.ts'
fileName = fileName.split("?", 1) + extension;
let writeToPath;
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
// use the path provided by Typescript's LanguageService.
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
writeToPath = fileName;
else {
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = dirname(bundleFile);
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(process.cwd(), fileName));
}
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, entry.text, entry.writeByteOrderMark);
};
lodash_2(declarations, ({ type, map }, key) => {
lodash_2([type, map], (e) => {
if (!e)
return;
let writeToPath;
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
// use the path provided by Typescript's LanguageService.
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
writeToPath = e.name;
else {
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = dirname(bundleFile);
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(process.cwd(), e.name));
}
if (writeToPath.includes("?")) {
// HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.d.ts'
context.debug(() => `${safe_4("skipping declarations")} for '${key}', invalid file path`);
}
else {
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
}
});
writeDeclaration(key, ".d.ts", type);
writeDeclaration(key, ".map.d.ts", map);
});
}
},

File diff suppressed because one or more lines are too long

View File

@ -308,39 +308,38 @@ export default function typescript(options?: Partial<IOptions>)
const bundleFile = file ? file : dest; // rollup 0.48+ has 'file' https://github.com/rollup/rollup/issues/1479
const writeDeclaration = (key: string, extension: string, entry?: tsTypes.OutputFile) =>
{
if (!entry)
return;
let fileName = entry.name;
if (fileName.includes("?")) // HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.ts'
fileName = fileName.split("?", 1) + extension;
let writeToPath: string;
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
// use the path provided by Typescript's LanguageService.
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
writeToPath = fileName;
else
{
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = dirname(bundleFile);
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(process.cwd(), fileName));
}
context.debug(() => `${blue("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, entry.text, entry.writeByteOrderMark);
};
_.each(declarations, ({ type, map }, key) =>
{
_.each([type, map], (e) =>
{
if (!e)
return;
let writeToPath: string;
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
// use the path provided by Typescript's LanguageService.
if (!bundleFile || pluginOptions.useTsconfigDeclarationDir)
writeToPath = e.name;
else
{
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = dirname(bundleFile);
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(process.cwd(), e.name));
}
if (writeToPath.includes("?"))
{
// HACK for rollup-plugin-vue, it creates virtual modules in form 'file.vue?rollup-plugin-vue=script.d.ts'
context.debug(() => `${yellow("skipping declarations")} for '${key}', invalid file path`);
}
else
{
context.debug(() => `${blue("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
}
});
writeDeclaration(key, ".d.ts", type);
writeDeclaration(key, ".map.d.ts", map);
});
}
},