mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-30 12:11:32 +08:00
Switch to an explicit list of resolutions
This commit is contained in:
parent
290c242910
commit
5004ba6fa6
@ -26,6 +26,7 @@ if (Promise.allSettled === undefined) {
|
||||
}
|
||||
|
||||
require('./style.js');
|
||||
require('./extraStyle.js');
|
||||
|
||||
function loadScript(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -65,6 +66,9 @@ async function createModule(scope, module) {
|
||||
* The main function
|
||||
*/
|
||||
async function main() {
|
||||
// load extra packages
|
||||
require('@jupyterlab/celltags');
|
||||
|
||||
const App = require('@jupyterlab-classic/application').App;
|
||||
const app = new App();
|
||||
|
||||
|
114
app/package.json
114
app/package.json
@ -27,6 +27,7 @@
|
||||
"@jupyterlab-classic/ui-components": "^0.1.7",
|
||||
"@jupyterlab/apputils-extension": "^3.0.0",
|
||||
"@jupyterlab/codemirror-extension": "^3.0.0",
|
||||
"@jupyterlab/celltags": "^3.0.0",
|
||||
"@jupyterlab/completer-extension": "^3.0.0",
|
||||
"@jupyterlab/coreutils": "~5.0.0",
|
||||
"@jupyterlab/docmanager-extension": "^3.0.0",
|
||||
@ -68,5 +69,118 @@
|
||||
"webpack-cli": "^4.2.0",
|
||||
"webpack-merge": "^5.1.2",
|
||||
"whatwg-fetch": "^3.0.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"@jupyterlab-classic/application": "~0.1.7",
|
||||
"@jupyterlab-classic/application-extension": "~0.1.7",
|
||||
"@jupyterlab-classic/docmanager-extension": "~0.1.7",
|
||||
"@jupyterlab-classic/help-extension": "~0.1.7",
|
||||
"@jupyterlab-classic/notebook-extension": "~0.1.7",
|
||||
"@jupyterlab-classic/terminal-extension": "~0.1.7",
|
||||
"@jupyterlab-classic/tree-extension": "~0.1.7",
|
||||
"@jupyterlab-classic/ui-components": "~0.1.7",
|
||||
"@jupyterlab/apputils-extension": "~3.0.0",
|
||||
"@jupyterlab/codemirror-extension": "~3.0.0",
|
||||
"@jupyterlab/celltags": "~3.0.0",
|
||||
"@jupyterlab/completer-extension": "~3.0.0",
|
||||
"@jupyterlab/coreutils": "~5.0.0",
|
||||
"@jupyterlab/docmanager-extension": "~3.0.0",
|
||||
"@jupyterlab/fileeditor-extension": "~3.0.0",
|
||||
"@jupyterlab/mainmenu-extension": "~3.0.0",
|
||||
"@jupyterlab/mathjax2-extension": "~3.0.0",
|
||||
"@jupyterlab/notebook-extension": "~3.0.0",
|
||||
"@jupyterlab/observables": "~4.0.0",
|
||||
"@jupyterlab/outputarea": "~3.0.0",
|
||||
"@jupyterlab/rendermime-extension": "~3.0.0",
|
||||
"@jupyterlab/running-extension": "~3.0.0",
|
||||
"@jupyterlab/shortcuts-extension": "~3.0.0",
|
||||
"@jupyterlab/terminal-extension": "~3.0.0",
|
||||
"@jupyterlab/theme-dark-extension": "~3.0.0",
|
||||
"@jupyterlab/theme-light-extension": "~3.0.0",
|
||||
"@jupyterlab/tooltip-extension": "~3.0.0",
|
||||
"@lumino/algorithm": "^1.3.3",
|
||||
"@lumino/application": "^1.13.1",
|
||||
"@lumino/commands": "^1.12.0",
|
||||
"@lumino/coreutils": "^1.5.3",
|
||||
"@lumino/disposable": "^1.4.3",
|
||||
"@lumino/domutils": "^1.2.3",
|
||||
"@lumino/dragdrop": "^1.7.1",
|
||||
"@lumino/messaging": "^1.4.3",
|
||||
"@lumino/properties": "^1.2.3",
|
||||
"@lumino/signaling": "^1.4.3",
|
||||
"@lumino/virtualdom": "^1.8.0",
|
||||
"@lumino/widgets": "^1.18.0",
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1"
|
||||
},
|
||||
"jupyterlab": {
|
||||
"name": "JupyterLab Classic",
|
||||
"extensions": [
|
||||
"@jupyterlab-classic/application-extension",
|
||||
"@jupyterlab-classic/docmanager-extension",
|
||||
"@jupyterlab-classic/help-extension",
|
||||
"@jupyterlab-classic/notebook-extension",
|
||||
"@jupyterlab-classic/terminal-extension",
|
||||
"@jupyterlab-classic/tree-extension",
|
||||
"@jupyterlab/apputils-extension",
|
||||
"@jupyterlab/codemirror-extension",
|
||||
"@jupyterlab/completer-extension",
|
||||
"@jupyterlab/docmanager-extension",
|
||||
"@jupyterlab/fileeditor-extension",
|
||||
"@jupyterlab/mainmenu-extension",
|
||||
"@jupyterlab/mathjax2-extension",
|
||||
"@jupyterlab/notebook-extension",
|
||||
"@jupyterlab/rendermime-extension",
|
||||
"@jupyterlab/running-extension",
|
||||
"@jupyterlab/shortcuts-extension",
|
||||
"@jupyterlab/terminal-extension",
|
||||
"@jupyterlab/theme-dark-extension",
|
||||
"@jupyterlab/theme-light-extension",
|
||||
"@jupyterlab/tooltip-extension"
|
||||
],
|
||||
"singletonPackages": [
|
||||
"@jupyterlab/application",
|
||||
"@jupyterlab/apputils",
|
||||
"@jupyterlab/codeeditor",
|
||||
"@jupyterlab/completer",
|
||||
"@jupyterlab/console",
|
||||
"@jupyterlab/coreutils",
|
||||
"@jupyterlab/debugger",
|
||||
"@jupyterlab/docmanager",
|
||||
"@jupyterlab/documentsearch",
|
||||
"@jupyterlab/extensionmanager",
|
||||
"@jupyterlab/filebrowser",
|
||||
"@jupyterlab/fileeditor",
|
||||
"@jupyterlab/imageviewer",
|
||||
"@jupyterlab/inspector",
|
||||
"@jupyterlab/launcher",
|
||||
"@jupyterlab/logconsole",
|
||||
"@jupyterlab/mainmenu",
|
||||
"@jupyterlab/notebook",
|
||||
"@jupyterlab/rendermime",
|
||||
"@jupyterlab/rendermime-interfaces",
|
||||
"@jupyterlab/services",
|
||||
"@jupyterlab/settingeditor",
|
||||
"@jupyterlab/settingregistry",
|
||||
"@jupyterlab/statedb",
|
||||
"@jupyterlab/statusbar",
|
||||
"@jupyterlab/terminal",
|
||||
"@jupyterlab/tooltip",
|
||||
"@jupyterlab/ui-components",
|
||||
"@lumino/algorithm",
|
||||
"@lumino/application",
|
||||
"@lumino/commands",
|
||||
"@lumino/coreutils",
|
||||
"@lumino/disposable",
|
||||
"@lumino/domutils",
|
||||
"@lumino/dragdrop",
|
||||
"@lumino/messaging",
|
||||
"@lumino/properties",
|
||||
"@lumino/signaling",
|
||||
"@lumino/virtualdom",
|
||||
"@lumino/widgets",
|
||||
"react",
|
||||
"react-dom"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
18
app/style.js
18
app/style.js
@ -1,17 +1 @@
|
||||
import '@jupyterlab-classic/application-extension/style/index.js';
|
||||
import '@jupyterlab-classic/notebook-extension/style/index.js';
|
||||
import '@jupyterlab-classic/tree-extension/style/index.js';
|
||||
import '@jupyterlab-classic/ui-components/style/index.js';
|
||||
|
||||
import '@jupyterlab/codemirror-extension/style/index.js';
|
||||
import '@jupyterlab/completer-extension/style/index.js';
|
||||
import '@jupyterlab/docmanager-extension/style/index.js';
|
||||
import '@jupyterlab/fileeditor-extension/style/index.js';
|
||||
import '@jupyterlab/mainmenu-extension/style/index.js';
|
||||
import '@jupyterlab/notebook-extension/style/index.js';
|
||||
import '@jupyterlab/rendermime-extension/style/index.js';
|
||||
import '@jupyterlab/running-extension/style/index.js';
|
||||
import '@jupyterlab/theme-light-extension/style/index.js';
|
||||
import '@jupyterlab/theme-dark-extension/style/index.js';
|
||||
import '@jupyterlab/terminal-extension/style/index.js';
|
||||
import '@jupyterlab/tooltip-extension/style/index.js';
|
||||
import '@jupyterlab/celltags/style/index.js';
|
||||
|
@ -14,24 +14,9 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
|
||||
|
||||
const Build = require('@jupyterlab/builder').Build;
|
||||
const baseConfig = require('@jupyterlab/builder/lib/webpack.config.base');
|
||||
const buildutils = require('@jupyterlab/buildutils');
|
||||
|
||||
const data = require('./package.json');
|
||||
|
||||
// get resolutions and singletons from upstream JupyterLab
|
||||
function getJupyterLabPackageJsonPath() {
|
||||
const script = [
|
||||
'python',
|
||||
'-c',
|
||||
"\"import pkg_resources; print(pkg_resources.resource_filename('jupyterlab', 'staging/package.json'))\""
|
||||
];
|
||||
const cmd = script.join(' ');
|
||||
return buildutils.run(cmd, { stdio: 'pipe' }, true);
|
||||
}
|
||||
|
||||
const labPackagePath = getJupyterLabPackageJsonPath();
|
||||
const labJson = buildutils.readJSONFile(labPackagePath);
|
||||
|
||||
const names = Object.keys(data.dependencies).filter(name => {
|
||||
const packageData = require(path.join(name, 'package.json'));
|
||||
return packageData.jupyterlab !== undefined;
|
||||
@ -48,18 +33,112 @@ fs.ensureDirSync(buildDir);
|
||||
const index = path.resolve(__dirname, 'index.js');
|
||||
const cssImports = path.resolve(__dirname, 'style.js');
|
||||
fs.copySync(index, path.resolve(buildDir, 'index.js'));
|
||||
fs.copySync(cssImports, path.resolve(buildDir, 'style.js'));
|
||||
fs.copySync(cssImports, path.resolve(buildDir, 'extraStyle.js'));
|
||||
|
||||
const extras = Build.ensureAssets({
|
||||
packageNames: names,
|
||||
output: buildDir
|
||||
});
|
||||
|
||||
const singletons = {};
|
||||
/**
|
||||
* Create the webpack ``shared`` configuration
|
||||
*/
|
||||
function createShared(packageData) {
|
||||
// Set up module federation sharing config
|
||||
const shared = {};
|
||||
const extensionPackages = packageData.jupyterlab.extensions;
|
||||
|
||||
labJson.jupyterlab.singletonPackages.forEach(element => {
|
||||
singletons[element] = { singleton: true };
|
||||
});
|
||||
// Make sure any resolutions are shared
|
||||
for (let [pkg, requiredVersion] of Object.entries(packageData.resolutions)) {
|
||||
shared[pkg] = { requiredVersion };
|
||||
}
|
||||
|
||||
// Add any extension packages that are not in resolutions (i.e., installed from npm)
|
||||
for (let pkg of extensionPackages) {
|
||||
if (!shared[pkg]) {
|
||||
shared[pkg] = {
|
||||
requiredVersion: require(`${pkg}/package.json`).version
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Add dependencies and sharedPackage config from extension packages if they
|
||||
// are not already in the shared config. This means that if there is a
|
||||
// conflict, the resolutions package version is the one that is shared.
|
||||
const extraShared = [];
|
||||
for (let pkg of extensionPackages) {
|
||||
let pkgShared = {};
|
||||
let {
|
||||
dependencies = {},
|
||||
jupyterlab: { sharedPackages = {} } = {}
|
||||
} = require(`${pkg}/package.json`);
|
||||
for (let [dep, requiredVersion] of Object.entries(dependencies)) {
|
||||
if (!shared[dep]) {
|
||||
pkgShared[dep] = { requiredVersion };
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite automatic dependency sharing with custom sharing config
|
||||
for (let [dep, config] of Object.entries(sharedPackages)) {
|
||||
if (config === false) {
|
||||
delete pkgShared[dep];
|
||||
} else {
|
||||
if ('bundled' in config) {
|
||||
config.import = config.bundled;
|
||||
delete config.bundled;
|
||||
}
|
||||
pkgShared[dep] = config;
|
||||
}
|
||||
}
|
||||
extraShared.push(pkgShared);
|
||||
}
|
||||
|
||||
// Now merge the extra shared config
|
||||
const mergedShare = {};
|
||||
for (let sharedConfig of extraShared) {
|
||||
for (let [pkg, config] of Object.entries(sharedConfig)) {
|
||||
// Do not override the basic share config from resolutions
|
||||
if (shared[pkg]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add if we haven't seen the config before
|
||||
if (!mergedShare[pkg]) {
|
||||
mergedShare[pkg] = config;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Choose between the existing config and this new config. We do not try
|
||||
// to merge configs, which may yield a config no one wants
|
||||
let oldConfig = mergedShare[pkg];
|
||||
|
||||
// if the old one has import: false, use the new one
|
||||
if (oldConfig.import === false) {
|
||||
mergedShare[pkg] = config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(shared, mergedShare);
|
||||
|
||||
// Transform any file:// requiredVersion to the version number from the
|
||||
// imported package. This assumes (for simplicity) that the version we get
|
||||
// importing was installed from the file.
|
||||
for (let [pkg, { requiredVersion }] of Object.entries(shared)) {
|
||||
if (requiredVersion && requiredVersion.startsWith('file:')) {
|
||||
shared[pkg].requiredVersion = require(`${pkg}/package.json`).version;
|
||||
}
|
||||
}
|
||||
|
||||
// Add singleton package information
|
||||
for (let pkg of packageData.jupyterlab.singletonPackages) {
|
||||
if (shared[pkg]) {
|
||||
shared[pkg].singleton = true;
|
||||
}
|
||||
}
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
// Make a bootstrap entrypoint
|
||||
const entryPoint = path.join(buildDir, 'bootstrap.js');
|
||||
@ -93,10 +172,7 @@ module.exports = [
|
||||
name: ['_JUPYTERLAB', 'CORE_LIBRARY_FEDERATION']
|
||||
},
|
||||
name: 'CORE_FEDERATION',
|
||||
shared: {
|
||||
...labJson.resolutions,
|
||||
...singletons
|
||||
}
|
||||
shared: createShared(data)
|
||||
})
|
||||
]
|
||||
})
|
||||
|
@ -328,11 +328,12 @@ const title: JupyterFrontEndPlugin<void> = {
|
||||
widget.id = 'jp-title';
|
||||
app.shell.add(widget, 'top', { rank: 10 });
|
||||
|
||||
// TODO: this signal might not be needed if we assume there is always only
|
||||
// one notebook in the main area
|
||||
shell.currentChanged.connect(async () => {
|
||||
const addTitle = async () => {
|
||||
const current = shell.currentWidget;
|
||||
if (!(current instanceof DocumentWidget)) {
|
||||
if (!current || !(current instanceof DocumentWidget)) {
|
||||
return;
|
||||
}
|
||||
if (widget.node.children.length > 0) {
|
||||
return;
|
||||
}
|
||||
const h = document.createElement('h1');
|
||||
@ -369,7 +370,10 @@ const title: JupyterFrontEndPlugin<void> = {
|
||||
skipRouting: true
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
shell.currentChanged.connect(addTitle);
|
||||
addTitle();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user