Skip to content

Commit 877815b

Browse files
committed
Convert index.js into typescript
1 parent 3cca434 commit 877815b

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

packages/voila/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@voila-dashboards/voila",
3-
"version": "0.4.0-beta.0",
3+
"version": "0.4.0-rc.0",
44
"description": "The Voilà Frontend",
55
"author": "Voilà contributors",
66
"license": "BSD-3-Clause",

packages/voila/src/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import('./main.js');

packages/voila/src/global.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*eslint no-var: 0*/
2+
3+
declare function __webpack_init_sharing__(arg: any);
4+
declare var _JUPYTERLAB;
5+
declare var __webpack_share_scopes__: any;
6+
declare var jupyterapp: any;

packages/voila/index.js renamed to packages/voila/src/main.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import './style.css';
1616

1717
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
1818

19-
import { VoilaApp } from '@voila-dashboards/voila';
19+
import { VoilaApp } from './app';
20+
import { VoilaShell } from './shell';
2021

21-
function loadScript(url) {
22+
function loadScript(url: string): Promise<any> {
2223
return new Promise((resolve, reject) => {
2324
const newScript = document.createElement('script');
2425
newScript.onerror = reject;
@@ -28,7 +29,7 @@ function loadScript(url) {
2829
newScript.src = url;
2930
});
3031
}
31-
async function loadComponent(url, scope) {
32+
async function loadComponent(url: string, scope: string): Promise<void> {
3233
await loadScript(url);
3334

3435
// From MIT-licensed https://github.com/module-federation/module-federation-examples/blob/af043acd6be1718ee195b2511adf6011fba4233c/advanced-api/dynamic-remotes/app1/src/App.js#L6-L12
@@ -40,7 +41,7 @@ async function loadComponent(url, scope) {
4041
await container.init(__webpack_share_scopes__.default);
4142
}
4243

43-
async function createModule(scope, module) {
44+
async function createModule(scope: string, module: string) {
4445
try {
4546
const factory = await window._JUPYTERLAB[scope].get(module);
4647
return factory();
@@ -58,7 +59,7 @@ const disabled = ['@jupyter-widgets/jupyterlab-manager'];
5859
* The main function
5960
*/
6061
async function main() {
61-
let mods = [
62+
const mods = [
6263
// @jupyterlab plugins
6364
require('@jupyterlab/markdownviewer-extension'),
6465
require('@jupyterlab/mathjax2-extension'),
@@ -78,7 +79,7 @@ async function main() {
7879
* #### Notes
7980
* This also populates the disabled
8081
*/
81-
function* activePlugins(extension) {
82+
function* activePlugins(extension: any) {
8283
// Handle commonjs or es2015 modules
8384
let exports;
8485
if (Object.prototype.hasOwnProperty.call(extension, '__esModule')) {
@@ -88,8 +89,8 @@ async function main() {
8889
exports = extension;
8990
}
9091

91-
let plugins = Array.isArray(exports) ? exports : [exports];
92-
for (let plugin of plugins) {
92+
const plugins = Array.isArray(exports) ? exports : [exports];
93+
for (const plugin of plugins) {
9394
if (
9495
PageConfig.Extension.isDisabled(plugin.id) ||
9596
disabled.includes(plugin.id) ||
@@ -101,13 +102,13 @@ async function main() {
101102
}
102103
}
103104

104-
const extensionData = JSON.parse(
105+
const extensionData: any[] = JSON.parse(
105106
PageConfig.getOption('federated_extensions')
106107
);
107108

108-
const federatedExtensionPromises = [];
109-
const federatedMimeExtensionPromises = [];
110-
const federatedStylePromises = [];
109+
const federatedExtensionPromises: Promise<any>[] = [];
110+
const federatedMimeExtensionPromises: Promise<any>[] = [];
111+
const federatedStylePromises: Promise<any>[] = [];
111112

112113
const extensions = await Promise.allSettled(
113114
extensionData.map(async data => {
@@ -150,7 +151,7 @@ async function main() {
150151
);
151152
federatedExtensions.forEach(p => {
152153
if (p.status === 'fulfilled') {
153-
for (let plugin of activePlugins(p.value)) {
154+
for (const plugin of activePlugins(p.value)) {
154155
mods.push(plugin);
155156
}
156157
} else {
@@ -164,7 +165,7 @@ async function main() {
164165
);
165166
federatedMimeExtensions.forEach(p => {
166167
if (p.status === 'fulfilled') {
167-
for (let plugin of activePlugins(p.value)) {
168+
for (const plugin of activePlugins(p.value)) {
168169
mimeExtensions.push(plugin);
169170
}
170171
} else {
@@ -175,11 +176,11 @@ async function main() {
175176
// Load all federated component styles and log errors for any that do not
176177
(await Promise.allSettled(federatedStylePromises))
177178
.filter(({ status }) => status === 'rejected')
178-
.forEach(({ reason }) => {
179-
console.error(reason);
179+
.forEach(p => {
180+
console.error((p as PromiseRejectedResult).reason);
180181
});
181182

182-
const app = new VoilaApp({ mimeExtensions });
183+
const app = new VoilaApp({ mimeExtensions, shell: new VoilaShell() });
183184
app.registerPluginModules(mods);
184185
await app.start();
185186

packages/voila/webpack.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ fs.ensureDirSync(buildDir);
2727

2828
// Copy files to the build directory
2929
const libDir = path.resolve(__dirname, 'lib');
30-
const index = path.resolve(__dirname, 'index.js');
3130
const style = path.resolve(__dirname, 'style.css');
3231
fs.copySync(libDir, buildDir);
33-
fs.copySync(index, path.resolve(buildDir, 'index.js'));
3432
fs.copySync(style, path.resolve(buildDir, 'style.css'));
3533

3634
const extras = Build.ensureAssets({
@@ -40,8 +38,6 @@ const extras = Build.ensureAssets({
4038

4139
// Make a bootstrap entrypoint
4240
const entryPoint = path.join(buildDir, 'bootstrap.js');
43-
const bootstrap = 'import("./index.js");';
44-
fs.writeFileSync(entryPoint, bootstrap);
4541

4642
if (process.env.NODE_ENV === 'production') {
4743
baseConfig.mode = 'production';

0 commit comments

Comments
 (0)