From 974af51465fbbcc27ddc8f82211618a3252bbcf8 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Wed, 15 Apr 2020 13:34:17 -0700 Subject: [PATCH 1/2] Fix pdf viewer so that we just ship the standalone version. (#11192) --- build/webpack/common.js | 2 +- build/webpack/webpack.extension.config.js | 20 +++++++++---------- news/2 Fixes/11157.md | 1 + src/client/datascience/plotting/plotViewer.ts | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 news/2 Fixes/11157.md 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/news/2 Fixes/11157.md b/news/2 Fixes/11157.md new file mode 100644 index 000000000000..cffa03b0eeba --- /dev/null +++ b/news/2 Fixes/11157.md @@ -0,0 +1 @@ +Fix saving to PDF for viewed plots. \ No newline at end of file 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}`); From 2f20af1952a5adaeaef00be00bddead675671a6c Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Wed, 15 Apr 2020 13:36:05 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 ++- news/2 Fixes/11157.md | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 news/2 Fixes/11157.md 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/news/2 Fixes/11157.md b/news/2 Fixes/11157.md deleted file mode 100644 index cffa03b0eeba..000000000000 --- a/news/2 Fixes/11157.md +++ /dev/null @@ -1 +0,0 @@ -Fix saving to PDF for viewed plots. \ No newline at end of file