Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

[WIP] Extension chain #58

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ lib
dist
tsconfig.tsbuildinfo
.vscode
.wrapper
11 changes: 9 additions & 2 deletions md_package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { PathExt } from '@jupyterlab/coreutils';

declare var require: any;
const IMiddleToken = require('@jupyterlab/example-federated-middle').IMiddleToken as any;


/**
* The command IDs used by the markdownviewer plugin.
*/
Expand All @@ -43,7 +47,7 @@ const FACTORY = 'Markdown Preview (Federated)';
const plugin: JupyterFrontEndPlugin<void> = {
activate,
id: '@jupyterlab/example-federated-md:plugin',
requires: [ILayoutRestorer, IRenderMimeRegistry, ISettingRegistry],
requires: [ILayoutRestorer, IRenderMimeRegistry, ISettingRegistry, IMiddleToken],
autoStart: true
};

Expand All @@ -54,8 +58,11 @@ function activate(
app: JupyterFrontEnd,
restorer: ILayoutRestorer,
rendermime: IRenderMimeRegistry,
settingRegistry: ISettingRegistry
settingRegistry: ISettingRegistry,
middleToken: typeof IMiddleToken
): void {
console.log('got middle token', middleToken);

const { commands, docRegistry } = app;

// Add the markdown renderer factory.
Expand Down
30 changes: 25 additions & 5 deletions webpack.config.ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ outputPath = path.join(packagePath, outputPath);
let extEntry = data.jupyterlab.extension || data.jupyterlab.mimeExtension;
const index = require.resolve(packagePath);
const exposes = {
'./index': index,
'./extension': index
}

// TODO
// Try and wrap the export so we're exposing something in our own package

let extensionImport = data['name'];
if (extEntry !== true) {
exposes['./extension'] = path.join(packagePath, extEntry);
extensionImport = path.join(extensionImport, extEntry);
}

const coreData = require('./core_package/package.json');
Expand All @@ -60,6 +64,9 @@ Object.keys(data.dependencies).forEach((element) => {
shared[element].requiredVersion = data.dependencies[element];
});

// Add the package itself.
shared[data.name] = { requiredVersion: '~' + data.version };

// Remove non-shared.
(data.jupyterlab.nonSharedPackages || []).forEach((element) => {
delete shared[element];
Expand Down Expand Up @@ -99,13 +106,26 @@ const extras = Build.ensureAssets({
output: outputPath
});

fs.copyFileSync(path.join(packagePath, 'package.json'), path.join(outputPath, 'package.orig.json'))
fs.copyFileSync(path.join(packagePath, 'package.json'), path.join(outputPath, 'package.orig.json'));

// Create the wrapper package
const wrapper = path.join(packagePath, '.wrapper');
if (fs.existsSync(wrapper)) {
fs.rmdirSync(wrapper, { recursive: true });
}
fs.mkdirSync(wrapper);

// Make a bootstrap entrypoint
const entryPoint = path.join(outputPath, 'bootstrap.js');
const bootstrap = 'import("' + exposes['./extension'] + '");'
// Make a bootstrap entrypoint file
const entryPoint = path.join(wrapper, 'bootstrap.js');
const bootstrap = 'import("' + extensionImport + '");'
fs.writeFileSync(entryPoint, bootstrap);

const dummyPackage = {
name: 'dummy'
}
fs.writeFileSync(path.join(wrapper, 'package.json'), JSON.stringify(dummyPackage));


module.exports = [
merge(baseConfig, {
entry: entryPoint,
Expand Down