|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import * as fs from 'fs-extra'; |
| 5 | +import * as path from 'path'; |
| 6 | +import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../constants'; |
| 7 | +/** |
| 8 | + * Modify package.json to ensure VSC Notebooks have been setup so tests can run. |
| 9 | + * This is required because we modify package.json during runtime, hence we need to do the same thing for tests. |
| 10 | + */ |
| 11 | + |
| 12 | +const packageJsonFile = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'package.json'); |
| 13 | +const content = JSON.parse(fs.readFileSync(packageJsonFile).toString()); |
| 14 | + |
| 15 | +// This code is temporary. |
| 16 | +if ( |
| 17 | + !content.enableProposedApi || |
| 18 | + !Array.isArray(content.contributes.notebookOutputRenderer) || |
| 19 | + !Array.isArray(content.contributes.notebookProvider) |
| 20 | +) { |
| 21 | + content.enableProposedApi = true; |
| 22 | + content.contributes.notebookOutputRenderer = [ |
| 23 | + { |
| 24 | + viewType: 'jupyter-notebook-renderer', |
| 25 | + displayName: 'Jupyter Notebook Renderer', |
| 26 | + mimeTypes: [ |
| 27 | + 'application/geo+json', |
| 28 | + 'application/vdom.v1+json', |
| 29 | + 'application/vnd.dataresource+json', |
| 30 | + 'application/vnd.plotly.v1+json', |
| 31 | + 'application/vnd.vega.v2+json', |
| 32 | + 'application/vnd.vega.v3+json', |
| 33 | + 'application/vnd.vega.v4+json', |
| 34 | + 'application/vnd.vega.v5+json', |
| 35 | + 'application/vnd.vegalite.v1+json', |
| 36 | + 'application/vnd.vegalite.v2+json', |
| 37 | + 'application/vnd.vegalite.v3+json', |
| 38 | + 'application/vnd.vegalite.v4+json', |
| 39 | + 'application/x-nteract-model-debug+json', |
| 40 | + 'image/gif', |
| 41 | + 'text/latex', |
| 42 | + 'text/vnd.plotly.v1+html' |
| 43 | + ] |
| 44 | + } |
| 45 | + ]; |
| 46 | + content.contributes.notebookProvider = [ |
| 47 | + { |
| 48 | + viewType: 'jupyter-notebook', |
| 49 | + displayName: 'Jupyter Notebook', |
| 50 | + selector: [ |
| 51 | + { |
| 52 | + filenamePattern: '*.ipynb' |
| 53 | + } |
| 54 | + ] |
| 55 | + } |
| 56 | + ]; |
| 57 | +} |
| 58 | + |
| 59 | +// Update package.json to pick experiments from our custom settings.json file. |
| 60 | +content.contributes.configuration.properties['python.experiments.optInto'].scope = 'resource'; |
| 61 | + |
| 62 | +fs.writeFileSync(packageJsonFile, JSON.stringify(content, undefined, 4)); |
0 commit comments