Skip to content

Commit

Permalink
Support Notebook Renderers with VS Code Notebooks (disabled) (#11999)
Browse files Browse the repository at this point in the history
Note: It is disabled to ensure we do not ship/bundle these things with official VS Code release (not yet).

For #10496

Add notebook renderers
Please note there's a big hack in this code (its to get around a VS Code issue).
Apart from that the rest should be ok
  • Loading branch information
DonJayamanne authored May 28, 2020
1 parent 3603966 commit cc93436
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 80 deletions.
39 changes: 26 additions & 13 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"smartStep": true,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*"
"${workspaceFolder}/out/**/*",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand Down Expand Up @@ -43,7 +44,8 @@
"smartStep": true,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*"
"${workspaceFolder}/out/**/*",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Inject DS WebBrowser UI",
"env": {
Expand All @@ -66,7 +68,8 @@
"smartStep": true,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*"
"${workspaceFolder}/out/**/*",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile"
},
Expand Down Expand Up @@ -99,7 +102,8 @@
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/client/**/*.js"
"${workspaceFolder}/out/client/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Compile",
Expand All @@ -122,7 +126,8 @@
"sourceMaps": true,
"smartStep": true,
"outFiles": [
"${workspaceFolder}/out/**/*"
"${workspaceFolder}/out/**/*",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"env": {
Expand Down Expand Up @@ -151,7 +156,8 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand All @@ -175,7 +181,8 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand All @@ -202,7 +209,8 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand All @@ -224,7 +232,8 @@
"sourceMaps": true,
"smartStep": true,
"outFiles": [
"${workspaceFolder}/out/**/*"
"${workspaceFolder}/out/**/*",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand All @@ -248,7 +257,8 @@
"--timeout=300000"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand All @@ -273,7 +283,8 @@
"--fast"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand Down Expand Up @@ -309,7 +320,8 @@
"XDEBUGPY_LOG_DIR": "${workspaceRoot}/tmp/Debug_Output"
},
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand Down Expand Up @@ -344,7 +356,8 @@
"XCI_PYTHON_PATH": "<Python Path>"
},
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/out/**/*.js",
"!${workspaceFolder}/**/node_modules**/*"
],
"preLaunchTask": "Compile",
"skipFiles": [
Expand Down
7 changes: 7 additions & 0 deletions build/webpack/webpack.datascience-ui-renderers.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

const builder = require('./webpack.datascience-ui.config.builder');
module.exports = [builder.renderers];
156 changes: 92 additions & 64 deletions build/webpack/webpack.datascience-ui.config.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// Any build on the CI is considered production mode.
const isProdBuild = constants.isCI || process.argv.includes('--mode');

function getEntry(isNotebook) {
if (isNotebook) {
return {
nativeEditor: ['babel-polyfill', `./src/datascience-ui/native-editor/index.tsx`],
interactiveWindow: ['babel-polyfill', `./src/datascience-ui/history-react/index.tsx`]
};
function getEntry(bundle) {
switch (bundle) {
case 'notebook':
return {
nativeEditor: ['babel-polyfill', `./src/datascience-ui/native-editor/index.tsx`],
interactiveWindow: ['babel-polyfill', `./src/datascience-ui/history-react/index.tsx`]
};
case 'renderers':
return {
renderers: ['babel-polyfill', `./src/datascience-ui/renderers/index.tsx`]
};
case 'viewers':
return {
plotViewer: ['babel-polyfill', `./src/datascience-ui/plot/index.tsx`],
dataExplorer: ['babel-polyfill', `./src/datascience-ui/data-explorer/index.tsx`]
};
default:
throw new Error(`Bundle not supported ${bundle}`);
}

return {
plotViewer: ['babel-polyfill', `./src/datascience-ui/plot/index.tsx`],
dataExplorer: ['babel-polyfill', `./src/datascience-ui/data-explorer/index.tsx`]
};
}

function getPlugins(isNotebook) {
function getPlugins(bundle) {
const plugins = [
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
Expand All @@ -44,64 +51,79 @@ function getPlugins(isNotebook) {
})
];
if (isProdBuild) {
plugins.push(...common.getDefaultPlugins(isNotebook ? 'notebook' : 'viewers'));
plugins.push(...common.getDefaultPlugins(bundle));
}

if (isNotebook) {
plugins.push(
new MonacoWebpackPlugin({
languages: [] // force to empty so onigasm will be used
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, '/nativeOrInteractivePicker.html'),
chunks: [],
filename: 'index.html'
}),
new HtmlWebpackPlugin({
template: 'src/datascience-ui/native-editor/index.html',
chunks: ['monaco', 'commons', 'nativeEditor'],
filename: 'index.nativeEditor.html'
}),
new HtmlWebpackPlugin({
template: 'src/datascience-ui/history-react/index.html',
chunks: ['monaco', 'commons', 'interactiveWindow'],
filename: 'index.interactiveWindow.html'
})
);
} else {
const definePlugin = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
});

plugins.push(
...(isProdBuild ? [definePlugin] : []),
...[
switch (bundle) {
case 'notebook':
plugins.push(
new MonacoWebpackPlugin({
languages: [] // force to empty so onigasm will be used
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, '/nativeOrInteractivePicker.html'),
chunks: [],
filename: 'index.html'
}),
new HtmlWebpackPlugin({
template: 'src/datascience-ui/plot/index.html',
indexUrl: `${constants.ExtensionRootDir}/out/1`,
chunks: ['commons', 'plotViewer'],
filename: 'index.plotViewer.html'
template: 'src/datascience-ui/native-editor/index.html',
chunks: ['monaco', 'commons', 'nativeEditor'],
filename: 'index.nativeEditor.html'
}),
new HtmlWebpackPlugin({
template: 'src/datascience-ui/data-explorer/index.html',
indexUrl: `${constants.ExtensionRootDir}/out/1`,
chunks: ['commons', 'dataExplorer'],
filename: 'index.dataExplorer.html'
template: 'src/datascience-ui/history-react/index.html',
chunks: ['monaco', 'commons', 'interactiveWindow'],
filename: 'index.interactiveWindow.html'
})
]
);
);
break;
case 'renderers': {
const definePlugin = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
});

plugins.push(...(isProdBuild ? [definePlugin] : []));
break;
}
case 'viewers': {
const definePlugin = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
});

plugins.push(
...(isProdBuild ? [definePlugin] : []),
...[
new HtmlWebpackPlugin({
template: 'src/datascience-ui/plot/index.html',
indexUrl: `${constants.ExtensionRootDir}/out/1`,
chunks: ['commons', 'plotViewer'],
filename: 'index.plotViewer.html'
}),
new HtmlWebpackPlugin({
template: 'src/datascience-ui/data-explorer/index.html',
indexUrl: `${constants.ExtensionRootDir}/out/1`,
chunks: ['commons', 'dataExplorer'],
filename: 'index.dataExplorer.html'
})
]
);
break;
}
default:
throw new Error(`Bundle not supported ${bundle}`);
}

return plugins;
}

function buildConfiguration(isNotebook) {
function buildConfiguration(bundle) {
// Folder inside `datascience-ui` that will be created and where the files will be dumped.
const bundleFolder = isNotebook ? 'notebook' : 'viewers';
const bundleFolder = bundle;
const filesToCopy = [];
if (isNotebook) {
if (bundle === 'notebook') {
// Include files only for notebooks.
filesToCopy.push(
...[
Expand All @@ -116,9 +138,9 @@ function buildConfiguration(isNotebook) {
]
);
}
return {
const config = {
context: constants.ExtensionRootDir,
entry: getEntry(isNotebook),
entry: getEntry(bundle),
output: {
path: path.join(constants.ExtensionRootDir, 'out', 'datascience-ui', bundleFolder),
filename: '[name].js',
Expand All @@ -140,7 +162,7 @@ function buildConfiguration(isNotebook) {
commons: {
name: 'commons',
chunks: 'initial',
minChunks: isNotebook ? 2 : 1, // We want at least one shared bundle (2 for notebooks, as we want monago split into another).
minChunks: bundle === 'notebook' ? 2 : 1, // We want at least one shared bundle (2 for notebooks, as we want monago split into another).
filename: '[name].initial.bundle.js'
},
// Even though nteract has been split up, some of them are large as nteract alone is large.
Expand Down Expand Up @@ -218,7 +240,7 @@ function buildConfiguration(isNotebook) {
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 100
}),
...getPlugins(isNotebook)
...getPlugins(bundle)
],
externals: ['log4js'],
resolve: {
Expand Down Expand Up @@ -298,7 +320,13 @@ function buildConfiguration(isNotebook) {
]
}
};

if (bundle === 'renderers') {
delete config.optimization;
}
return config;
}

exports.notebooks = buildConfiguration(true);
exports.viewers = buildConfiguration(false);
exports.notebooks = buildConfiguration('notebook');
exports.viewers = buildConfiguration('viewers');
exports.renderers = buildConfiguration('renderers');
4 changes: 4 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ gulp.task('compile-notebooks', async () => {
await buildWebPackForDevOrProduction('./build/webpack/webpack.datascience-ui-notebooks.config.js');
});

gulp.task('compile-renderers', async () => {
await buildWebPackForDevOrProduction('./build/webpack/webpack.datascience-ui-renderers.config.js');
});

gulp.task('compile-viewers', async () => {
await buildWebPackForDevOrProduction('./build/webpack/webpack.datascience-ui-viewers.config.js');
});
Expand Down
3 changes: 2 additions & 1 deletion src/client/datascience/notebook/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ export function notebookModelToVSCNotebookData(model: INotebookModel): NotebookD
'application/x-nteract-model-debug+json',
'text/html',
'application/javascript',
'image/gif',
'text/latex',
'text/markdown',
'application/json',
'image/svg+xml',
'image/png',
'image/jpeg',
'application/json',
'text/plain'
]
}
Expand Down
Loading

0 comments on commit cc93436

Please sign in to comment.