Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build/webpack/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ exports.nodeModulesToExternalize = [
'node-stream-zip',
'xml2js',
'vsls/vscode',
'pdfkit',
'crypto-js',
'fontkit',
'linebreak',
'png-js'
];
exports.nodeModulesToReplacePaths = [
...exports.nodeModulesToExternalize
Expand Down
7 changes: 6 additions & 1 deletion build/webpack/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ export const nodeModulesToExternalize = [
'node-stream-zip',
'xml2js',
'vsls/vscode',
'pdfkit',
'crypto-js',
'fontkit',
'linebreak',
'png-js'
];

export const nodeModulesToReplacePaths = [
...nodeModulesToExternalize
]
];

export function getDefaultPlugins(name: 'extension' | 'debugger' | 'dependencies' | 'datascience-ui') {
const plugins = [];
Expand Down
15 changes: 15 additions & 0 deletions build/webpack/pdfkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

/*
This file is only used when using webpack for bundling.
We have a dummy file so that webpack doesn't fall over when trying to bundle pdfkit.
Just point it to a dummy file (this file).
Once webpack is done, we override the pdfkit.js file in the externalized node modules directory
with the actual source of pdfkit that needs to be used by nodejs (our extension code).
*/

class PDFDocument {}
module.exports = PDFDocument;
27 changes: 23 additions & 4 deletions build/webpack/webpack.extension.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const configFileName = path.join(constants_1.ExtensionRootDir, 'tsconfig.extensi
// Some modules will be pre-genearted and stored in out/.. dir and they'll be referenced via NormalModuleReplacementPlugin
// We need to ensure they do not get bundled into the output (as they are large).
const existingModulesInOutDir = common_1.getListOfExistingModulesInOutDir();
// tslint:disable-next-line:no-var-requires no-require-imports
const FileManagerPlugin = require('filemanager-webpack-plugin');
const config = {
mode: 'production',
target: 'node',
Expand Down Expand Up @@ -49,9 +51,9 @@ const config = {
}
]
},
{enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: "transform-loader?brfs"},
{enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: "transform-loader?brfs"},
{enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: "transform-loader?brfs"}
{ enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs' },
{ enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs' },
{ enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs' }
]
},
externals: [
Expand All @@ -60,9 +62,26 @@ const config = {
...existingModulesInOutDir
],
plugins: [
...common_1.getDefaultPlugins('extension')
...common_1.getDefaultPlugins('extension'),
// Copy pdfkit bits after extension builds. webpack can't handle pdfkit.
new FileManagerPlugin({
onEnd: [
{
copy: [
{ source: './node_modules/pdfkit/js/data/*.*', destination: './out/client/node_modules/data' },
{ source: './node_modules/pdfkit/js/pdfkit.js', destination: './out/client/node_modules/' }
]
}
]
})
],
resolve: {
alias:{
// Pointing pdfkit to a dummy js file so webpack doesn't fall over.
// Since pdfkit has been externalized (it gets updated with the valid code by copying the pdfkit files
// into the right destination).
'pdfkit':path.resolve(__dirname, 'pdfkit.js')
},
extensions: ['.ts', '.js'],
plugins: [
new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({ configFile: configFileName })
Expand Down
22 changes: 20 additions & 2 deletions build/webpack/webpack.extension.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const configFileName = path.join(ExtensionRootDir, 'tsconfig.extension.json');
// We need to ensure they do not get bundled into the output (as they are large).
const existingModulesInOutDir = getListOfExistingModulesInOutDir();

// tslint:disable-next-line:no-var-requires no-require-imports
const FileManagerPlugin = require('filemanager-webpack-plugin');

const config: Configuration = {
mode: 'production',
target: 'node',
Expand Down Expand Up @@ -53,7 +56,11 @@ const config: Configuration = {
loader: 'ts-loader'
}
]
}
},
{enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs'},
{enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs'},
{enforce: 'post', test: /pdfkit[\\\/]js[\\\/].*js$/, loader: 'transform-loader?brfs'},
{enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs'}
]
},
externals: [
Expand All @@ -62,7 +69,18 @@ const config: Configuration = {
...existingModulesInOutDir
],
plugins: [
...getDefaultPlugins('extension')
...getDefaultPlugins('extension'),
// Copy pdfkit bits after extension builds. webpack can't handle pdfkit.
new FileManagerPlugin({
onEnd: [
{
copy: [
{ source: './node_modules/pdfkit/js/data/*.*', destination: './out/client/node_modules/data' },
{ source: './node_modules/pdfkit/js/pdfkit.js', destination: './out/client/node_modules/' }
]
}
]
})
],
resolve: {
extensions: ['.ts', '.js'],
Expand Down
14 changes: 12 additions & 2 deletions build/webpack/webpack.extension.dependencies.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Licensed under the MIT License.
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable-next-line: no-require-imports
const copyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const constants_1 = require("../constants");
const common_1 = require("./common");
const copyWebpackPlugin = require("copy-webpack-plugin");
const entryItems = {};
common_1.nodeModulesToExternalize.forEach(moduleName => {
entryItems[`node_modules/${moduleName}`] = `./node_modules/${moduleName}`;
Expand All @@ -28,7 +29,10 @@ const config = {
loader: path.join(__dirname, 'loaders', 'fixEvalRequire.js')
}
]
}
},
{ enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs' },
{ enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs' },
{ enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs' }
]
},
externals: [
Expand All @@ -48,6 +52,12 @@ const config = {
])
],
resolve: {
alias:{
// Pointing pdfkit to a dummy js file so webpack doesn't fall over.
// Since pdfkit has been externalized (it gets updated with the valid code by copying the pdfkit files
// into the right destination).
'pdfkit':path.resolve(__dirname, 'pdfkit.js')
},
extensions: ['.js']
},
output: {
Expand Down
9 changes: 7 additions & 2 deletions build/webpack/webpack.extension.dependencies.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

'use strict';

// tslint:disable-next-line: no-require-imports
import copyWebpackPlugin = require('copy-webpack-plugin');
import * as path from 'path';
import * as webpack from 'webpack';
import { ExtensionRootDir } from '../constants';
import { getDefaultPlugins, nodeModulesToExternalize } from './common';
import copyWebpackPlugin = require('copy-webpack-plugin');

const entryItems: Record<string, string> = {};
nodeModulesToExternalize.forEach(moduleName => {
Expand All @@ -32,7 +33,11 @@ const config: webpack.Configuration = {
loader: path.join(__dirname, 'loaders', 'fixEvalRequire.js')
}
]
}
},
{enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs'},
{enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs'},
{enforce: 'post', test: /pdfkit[\\\/]js[\\\/].*js$/, loader: 'transform-loader?brfs'},
{enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs'}
]
},
externals: [
Expand Down
1 change: 1 addition & 0 deletions news/2 Fixes/6277.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pdf export in release bits.
Loading