Safer way to determine whether node or browser
This commit is contained in:
Родитель
1865c2979d
Коммит
692656799a
|
@ -12,10 +12,10 @@ const withBrowserDefaults = require('../shared.webpack.config').browser;
|
|||
const config = withBrowserDefaults({
|
||||
context: __dirname,
|
||||
entry: {
|
||||
extension: './src/ipynbMain.ts'
|
||||
extension: './src/ipynbMain.browser.ts'
|
||||
},
|
||||
output: {
|
||||
filename: 'ipynbMain.js'
|
||||
filename: 'ipynbMain.browser.js'
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -13,11 +13,10 @@ const path = require('path');
|
|||
module.exports = withDefaults({
|
||||
context: __dirname,
|
||||
entry: {
|
||||
ipynbMain: './src/ipynbMain.ts',
|
||||
['ipynbMain.node']: './src/ipynbMain.node.ts',
|
||||
notebookSerializerWorker: './src/notebookSerializerWorker.ts',
|
||||
},
|
||||
output: {
|
||||
// filename: 'ipynbMain.js'
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: '[name].js'
|
||||
},
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
"workspace",
|
||||
"ui"
|
||||
],
|
||||
"main": "./out/ipynbMain.js",
|
||||
"browser": "./dist/browser/ipynbMain.js",
|
||||
"main": "./out/ipynbMain.node.js",
|
||||
"browser": "./dist/browser/ipynbMain.browser.js",
|
||||
"capabilities": {
|
||||
"virtualWorkspaces": true,
|
||||
"untrustedWorkspaces": {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as main from './ipynbMain';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
return main.activate(context, true);
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
return main.deactivate();
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as main from './ipynbMain';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
return main.activate(context, false);
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
return main.deactivate();
|
||||
}
|
|
@ -29,8 +29,8 @@ type NotebookMetadata = {
|
|||
[propName: string]: unknown;
|
||||
};
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const serializer = new NotebookSerializer(context);
|
||||
export function activate(context: vscode.ExtensionContext, isBrowser: boolean) {
|
||||
const serializer = new NotebookSerializer(context, isBrowser);
|
||||
keepNotebookModelStoreInSync(context);
|
||||
context.subscriptions.push(vscode.workspace.registerNotebookSerializer('jupyter-notebook', serializer, {
|
||||
transientOutputs: false,
|
||||
|
|
|
@ -17,7 +17,7 @@ export class NotebookSerializer extends vscode.Disposable implements vscode.Note
|
|||
private worker?: import('node:worker_threads').Worker;
|
||||
private tasks = new Map<string, DeferredPromise<Uint8Array>>();
|
||||
|
||||
constructor(readonly context: vscode.ExtensionContext) {
|
||||
constructor(readonly context: vscode.ExtensionContext, private readonly isBrowser: boolean) {
|
||||
super(() => { });
|
||||
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
|
||||
if (e.affectsConfiguration('ipynb.experimental.serialization')) {
|
||||
|
@ -96,7 +96,7 @@ export class NotebookSerializer extends vscode.Disposable implements vscode.Note
|
|||
return new Uint8Array(0);
|
||||
}
|
||||
|
||||
if (this.experimentalSave) {
|
||||
if (this.experimentalSave && !this.isBrowser) {
|
||||
return this.serializeViaWorker2(data);
|
||||
}
|
||||
const serialized = serializeNotebookToString(data);
|
||||
|
|
Загрузка…
Ссылка в новой задаче