diff --git a/CHANGELOG.md b/CHANGELOG.md index a49058b3ce26..d75a80ae6e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,7 +100,8 @@ ([#11151](https://github.com/Microsoft/vscode-python/issues/11151)) 1. Fix CTRL+Z and Z for undo on notebooks. ([#11160](https://github.com/Microsoft/vscode-python/issues/11160)) - +1. Fix saving to PDF for viewed plots. + ([#11157](https://github.com/Microsoft/vscode-python/issues/11157)) ### Code Health diff --git a/build/webpack/common.js b/build/webpack/common.js index b06643759d39..53ee36a6077d 100644 --- a/build/webpack/common.js +++ b/build/webpack/common.js @@ -27,7 +27,7 @@ exports.nodeModulesToExternalize = [ 'node-stream-zip', 'xml2js', 'vsls/vscode', - 'pdfkit', + 'pdfkit/js/pdfkit.standalone', 'crypto-js', 'fontkit', 'linebreak', diff --git a/build/webpack/webpack.extension.config.js b/build/webpack/webpack.extension.config.js index 26ba0fb968d3..48f8d6683d29 100644 --- a/build/webpack/webpack.extension.config.js +++ b/build/webpack/webpack.extension.config.js @@ -67,18 +67,16 @@ const config = { externals: ['vscode', 'commonjs', ...ppaPackageList, ...existingModulesInOutDir], plugins: [ ...common.getDefaultPlugins('extension'), - // Copy pdfkit bits after extension builds. webpack can't handle pdfkit. - new FileManagerPlugin({ - onEnd: [ - { - copy: [ - { source: './node_modules/fontkit/*.trie', destination: './out/client/node_modules' }, - { source: './node_modules/pdfkit/js/data/*.*', destination: './out/client/node_modules/data' }, - { source: './node_modules/pdfkit/js/pdfkit.js', destination: './out/client/node_modules/' } - ] - } - ] + // Copy pdfkit after extension builds. webpack can't handle pdfkit. + new removeFilesWebpackPlugin({ + after: { include: ['./out/client/node_modules/pdfkit/js/pdfkit.standalone.*'] } }), + new copyWebpackPlugin([ + { + from: './node_modules/pdfkit/js/pdfkit.standalone.js', + to: './node_modules/pdfkit/js/pdfkit.standalone.js' + } + ]), // ZMQ requires prebuilds to be in our node_modules directory. So recreate the ZMQ structure. // However we don't webpack to manage this, so it was part of the excluded modules. Delete it from there // so at runtime we pick up the original structure. diff --git a/src/client/datascience/plotting/plotViewer.ts b/src/client/datascience/plotting/plotViewer.ts index 986079ff467e..5d9f64926c69 100644 --- a/src/client/datascience/plotting/plotViewer.ts +++ b/src/client/datascience/plotting/plotViewer.ts @@ -147,7 +147,7 @@ export class PlotViewer extends WebViewHost implements IPlot const SVGtoPDF = require('svg-to-pdfkit'); const deferred = createDeferred(); // tslint:disable-next-line: no-require-imports - const pdfkit = require('pdfkit') as typeof import('pdfkit'); + const pdfkit = require('pdfkit/js/pdfkit.standalone') as typeof import('pdfkit'); const doc = new pdfkit(); const ws = this.fileSystem.createWriteStream(file.fsPath); traceInfo(`Writing pdf to ${file.fsPath}`);