Skip to content

Commit 1a5e98a

Browse files
committed
Fix pdf export in release bits (#6291)
* Fix pdf export in release bits * Review feedback * Fixes * Add comments
1 parent afe33ea commit 1a5e98a

File tree

13 files changed

+734
-36
lines changed

13 files changed

+734
-36
lines changed

build/webpack/common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ exports.nodeModulesToExternalize = [
2727
'node-stream-zip',
2828
'xml2js',
2929
'vsls/vscode',
30+
'pdfkit',
31+
'crypto-js',
32+
'fontkit',
33+
'linebreak',
34+
'png-js'
3035
];
3136
exports.nodeModulesToReplacePaths = [
3237
...exports.nodeModulesToExternalize

build/webpack/common.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ export const nodeModulesToExternalize = [
2929
'node-stream-zip',
3030
'xml2js',
3131
'vsls/vscode',
32+
'pdfkit',
33+
'crypto-js',
34+
'fontkit',
35+
'linebreak',
36+
'png-js'
3237
];
3338

3439
export const nodeModulesToReplacePaths = [
3540
...nodeModulesToExternalize
36-
]
41+
];
3742

3843
export function getDefaultPlugins(name: 'extension' | 'debugger' | 'dependencies' | 'datascience-ui') {
3944
const plugins = [];

build/webpack/pdfkit.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
/*
7+
This file is only used when using webpack for bundling.
8+
We have a dummy file so that webpack doesn't fall over when trying to bundle pdfkit.
9+
Just point it to a dummy file (this file).
10+
Once webpack is done, we override the pdfkit.js file in the externalized node modules directory
11+
with the actual source of pdfkit that needs to be used by nodejs (our extension code).
12+
*/
13+
14+
class PDFDocument {}
15+
module.exports = PDFDocument;

build/webpack/webpack.extension.config.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const configFileName = path.join(constants_1.ExtensionRootDir, 'tsconfig.extensi
1111
// Some modules will be pre-genearted and stored in out/.. dir and they'll be referenced via NormalModuleReplacementPlugin
1212
// We need to ensure they do not get bundled into the output (as they are large).
1313
const existingModulesInOutDir = common_1.getListOfExistingModulesInOutDir();
14+
// tslint:disable-next-line:no-var-requires no-require-imports
15+
const FileManagerPlugin = require('filemanager-webpack-plugin');
1416
const config = {
1517
mode: 'production',
1618
target: 'node',
@@ -49,9 +51,9 @@ const config = {
4951
}
5052
]
5153
},
52-
{enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: "transform-loader?brfs"},
53-
{enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: "transform-loader?brfs"},
54-
{enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: "transform-loader?brfs"}
54+
{ enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs' },
55+
{ enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs' },
56+
{ enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs' }
5557
]
5658
},
5759
externals: [
@@ -60,9 +62,26 @@ const config = {
6062
...existingModulesInOutDir
6163
],
6264
plugins: [
63-
...common_1.getDefaultPlugins('extension')
65+
...common_1.getDefaultPlugins('extension'),
66+
// Copy pdfkit bits after extension builds. webpack can't handle pdfkit.
67+
new FileManagerPlugin({
68+
onEnd: [
69+
{
70+
copy: [
71+
{ source: './node_modules/pdfkit/js/data/*.*', destination: './out/client/node_modules/data' },
72+
{ source: './node_modules/pdfkit/js/pdfkit.js', destination: './out/client/node_modules/' }
73+
]
74+
}
75+
]
76+
})
6477
],
6578
resolve: {
79+
alias:{
80+
// Pointing pdfkit to a dummy js file so webpack doesn't fall over.
81+
// Since pdfkit has been externalized (it gets updated with the valid code by copying the pdfkit files
82+
// into the right destination).
83+
'pdfkit':path.resolve(__dirname, 'pdfkit.js')
84+
},
6685
extensions: ['.ts', '.js'],
6786
plugins: [
6887
new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({ configFile: configFileName })

build/webpack/webpack.extension.config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const configFileName = path.join(ExtensionRootDir, 'tsconfig.extension.json');
1616
// We need to ensure they do not get bundled into the output (as they are large).
1717
const existingModulesInOutDir = getListOfExistingModulesInOutDir();
1818

19+
// tslint:disable-next-line:no-var-requires no-require-imports
20+
const FileManagerPlugin = require('filemanager-webpack-plugin');
21+
1922
const config: Configuration = {
2023
mode: 'production',
2124
target: 'node',
@@ -53,7 +56,11 @@ const config: Configuration = {
5356
loader: 'ts-loader'
5457
}
5558
]
56-
}
59+
},
60+
{enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs'},
61+
{enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs'},
62+
{enforce: 'post', test: /pdfkit[\\\/]js[\\\/].*js$/, loader: 'transform-loader?brfs'},
63+
{enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs'}
5764
]
5865
},
5966
externals: [
@@ -62,7 +69,18 @@ const config: Configuration = {
6269
...existingModulesInOutDir
6370
],
6471
plugins: [
65-
...getDefaultPlugins('extension')
72+
...getDefaultPlugins('extension'),
73+
// Copy pdfkit bits after extension builds. webpack can't handle pdfkit.
74+
new FileManagerPlugin({
75+
onEnd: [
76+
{
77+
copy: [
78+
{ source: './node_modules/pdfkit/js/data/*.*', destination: './out/client/node_modules/data' },
79+
{ source: './node_modules/pdfkit/js/pdfkit.js', destination: './out/client/node_modules/' }
80+
]
81+
}
82+
]
83+
})
6684
],
6785
resolve: {
6886
extensions: ['.ts', '.js'],

build/webpack/webpack.extension.dependencies.config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// Licensed under the MIT License.
33
'use strict';
44
Object.defineProperty(exports, "__esModule", { value: true });
5+
// tslint:disable-next-line: no-require-imports
6+
const copyWebpackPlugin = require("copy-webpack-plugin");
57
const path = require("path");
68
const constants_1 = require("../constants");
79
const common_1 = require("./common");
8-
const copyWebpackPlugin = require("copy-webpack-plugin");
910
const entryItems = {};
1011
common_1.nodeModulesToExternalize.forEach(moduleName => {
1112
entryItems[`node_modules/${moduleName}`] = `./node_modules/${moduleName}`;
@@ -28,7 +29,10 @@ const config = {
2829
loader: path.join(__dirname, 'loaders', 'fixEvalRequire.js')
2930
}
3031
]
31-
}
32+
},
33+
{ enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs' },
34+
{ enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs' },
35+
{ enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs' }
3236
]
3337
},
3438
externals: [
@@ -48,6 +52,12 @@ const config = {
4852
])
4953
],
5054
resolve: {
55+
alias:{
56+
// Pointing pdfkit to a dummy js file so webpack doesn't fall over.
57+
// Since pdfkit has been externalized (it gets updated with the valid code by copying the pdfkit files
58+
// into the right destination).
59+
'pdfkit':path.resolve(__dirname, 'pdfkit.js')
60+
},
5161
extensions: ['.js']
5262
},
5363
output: {

build/webpack/webpack.extension.dependencies.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
'use strict';
55

6+
// tslint:disable-next-line: no-require-imports
7+
import copyWebpackPlugin = require('copy-webpack-plugin');
68
import * as path from 'path';
79
import * as webpack from 'webpack';
810
import { ExtensionRootDir } from '../constants';
911
import { getDefaultPlugins, nodeModulesToExternalize } from './common';
10-
import copyWebpackPlugin = require('copy-webpack-plugin');
1112

1213
const entryItems: Record<string, string> = {};
1314
nodeModulesToExternalize.forEach(moduleName => {
@@ -32,7 +33,11 @@ const config: webpack.Configuration = {
3233
loader: path.join(__dirname, 'loaders', 'fixEvalRequire.js')
3334
}
3435
]
35-
}
36+
},
37+
{enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs'},
38+
{enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs'},
39+
{enforce: 'post', test: /pdfkit[\\\/]js[\\\/].*js$/, loader: 'transform-loader?brfs'},
40+
{enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs'}
3641
]
3742
},
3843
externals: [

news/2 Fixes/6277.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix pdf export in release bits.

0 commit comments

Comments
 (0)