Skip to content

Commit

Permalink
- fix for attempting to write declarations for virtual modules genera…
Browse files Browse the repository at this point in the history
…ted by rollup-plugin-vue #97
  • Loading branch information
ezolenko committed Jul 9, 2018
1 parent 9843cfb commit f0e466c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions dist/rollup-plugin-typescript2.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20179,9 +20179,15 @@ function typescript(options) {
const destDirectory = path.isAbsolute(destDirname) ? destDirname : path.join(process.cwd(), destDirname);
writeToPath = path.join(destDirectory, path.relative(process.cwd(), e.name));
}
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
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);
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.cjs.js.map

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions dist/rollup-plugin-typescript2.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -20175,9 +20175,15 @@ function typescript(options) {
const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(process.cwd(), e.name));
}
context.debug(() => `${safe_5("writing declarations")} for '${key}' to '${writeToPath}'`);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
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);
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.es.js.map

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export default function typescript(options?: Partial<IOptions>)
{
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.
Expand All @@ -327,10 +328,18 @@ export default function typescript(options?: Partial<IOptions>)
writeToPath = join(destDirectory, relative(process.cwd(), e.name));
}

context.debug(() => `${blue("writing declarations")} for '${key}' to '${writeToPath}'`);
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);
// Write the declaration file to disk.
tsModule.sys.writeFile(writeToPath, e.text, e.writeByteOrderMark);
}
});
});
}
Expand Down

0 comments on commit f0e466c

Please sign in to comment.