diff --git a/examples/react/src/index.tsx b/examples/react/src/index.tsx index b6b8e16e2a..5b983234db 100644 --- a/examples/react/src/index.tsx +++ b/examples/react/src/index.tsx @@ -15,7 +15,7 @@ import "@finos/perspective-viewer"; import "@finos/perspective-viewer-datagrid"; import "@finos/perspective-viewer-d3fc"; import { - HTMLPerspectiveViewerConfig, + PerspectiveViewerConfig, HTMLPerspectiveViewerElement, } from "@finos/perspective-viewer"; @@ -30,7 +30,7 @@ const getTable = async (): Promise => { return await worker.table(buffer as any); }; -const config: HTMLPerspectiveViewerConfig = { +const config: PerspectiveViewerConfig = { row_pivots: ["State"], }; diff --git a/packages/perspective-webpack-plugin/index.js b/packages/perspective-webpack-plugin/index.js index 2330e47839..449b951377 100644 --- a/packages/perspective-webpack-plugin/index.js +++ b/packages/perspective-webpack-plugin/index.js @@ -68,22 +68,6 @@ class PerspectiveWebpackPlugin { if (this.options.inline || this.options.inlineWorker) { rules[rules.length - 2].use.options.inline = "no-fallback"; rules[rules.length - 1].use.options.inline = "no-fallback"; - } else { - rules.push({ - test: /\.js$/, - include: path.dirname( - require.resolve("@finos/perspective-viewer/package.json") - ), - use: [ - { - loader: require.resolve("string-replace-loader"), - options: { - search: /webpackMode:\s*?"eager"/g, - replace: "", - }, - }, - ], - }); } if (!(this.options.inline || this.options.inlineWasm)) { diff --git a/packages/perspective/src/js/perspective.node.js b/packages/perspective/src/js/perspective.node.js index a87ead46e1..710fbb1940 100644 --- a/packages/perspective/src/js/perspective.node.js +++ b/packages/perspective/src/js/perspective.node.js @@ -219,6 +219,7 @@ const websocket = (url) => { module.exports.get_type_config = get_type_config; module.exports.get_config = get_config; module.exports.worker = () => module.exports; +module.exports.shared_worker = () => module.exports; module.exports.websocket = websocket; module.exports.perspective_assets = perspective_assets; module.exports.WebSocketServer = WebSocketServer; diff --git a/rust/perspective-viewer/build.js b/rust/perspective-viewer/build.js index 1ff97035b3..93ee2d2e82 100644 --- a/rust/perspective-viewer/build.js +++ b/rust/perspective-viewer/build.js @@ -1,5 +1,7 @@ const {lessLoader} = require("esbuild-plugin-less"); const {execSync} = require("child_process"); +const util = require("util"); +const exec = util.promisify(require("child_process").exec); const fs = require("fs"); const {IgnoreCSSPlugin} = require("@finos/perspective-build/ignore_css"); @@ -10,6 +12,18 @@ const {NodeModulesExternal} = require("@finos/perspective-build/external"); const {ReplacePlugin} = require("@finos/perspective-build/replace"); const {build} = require("@finos/perspective-build/build"); +function _compile(fileNames) { + const ts = require("typescript"); + const path = require.resolve("@finos/perspective-viewer/tsconfig.json"); + const {compilerOptions} = JSON.parse(fs.readFileSync(path).toString()); + const {options} = ts.convertCompilerOptionsFromJson(compilerOptions, ""); + const host = ts.createCompilerHost(options); + fs.mkdirSync("dist/esm", {recursive: true}); + host.writeFile = (path, contents) => fs.writeFileSync(path, contents); + const program = ts.createProgram(fileNames, options, host); + program.emit(); +} + const PREBUILD = [ { entryPoints: [ @@ -93,6 +107,12 @@ const POSTBUILD = [ ]; async function build_all() { + // generate declaration in parallel because tsc is sloooow. + let tsc; + if (fs.existsSync("dist/pkg/perspective_viewer.js")) { + tsc = exec("yarn tsc --emitDeclarationOnly --outDir dist/esm"); + } + await Promise.all(PREBUILD.map(build)).catch(() => process.exit(1)); const debug = process.env.PSP_DEBUG ? "--debug" : ""; @@ -104,11 +124,18 @@ async function build_all() { } ); + if (typeof tsc === "undefined") { + tsc = exec("yarn tsc --emitDeclarationOnly --outDir dist/esm"); + } + await Promise.all(BUILD.map(build)).catch(() => process.exit(1)); await Promise.all(POSTBUILD.map(build)).catch(() => process.exit(1)); // legacy compat execSync("cpy dist/css/* dist/umd"); + + const {stdout} = await tsc; + console.log(stdout); } build_all(); diff --git a/rust/perspective-viewer/package.json b/rust/perspective-viewer/package.json index 9aaeee503b..20511dbaa6 100644 --- a/rust/perspective-viewer/package.json +++ b/rust/perspective-viewer/package.json @@ -20,13 +20,14 @@ "./umd/": "./dist/umd/", "./pkg/": "./dist/pkg/", "./src/": "./src/", - "./package.json": "./package.json" + "./package.json": "./package.json", + "./tsconfig.json": "./tsconfig.json" }, "files": [ "dist/**/*", "src/**/*" ], - "types": "dist/esm/index.d.ts", + "types": "dist/esm/perspective-viewer.d.ts", "scripts": { "build": "node ./build.js", "clean": "rimraf dist && rimraf pkg && rimraf build", diff --git a/rust/perspective-viewer/src/rust/js/monaco.rs b/rust/perspective-viewer/src/rust/js/monaco.rs index 74fc139138..19e01d7252 100644 --- a/rust/perspective-viewer/src/rust/js/monaco.rs +++ b/rust/perspective-viewer/src/rust/js/monaco.rs @@ -23,11 +23,15 @@ pub enum KeyCode { #[cfg_attr( not(test), - wasm_bindgen(module = "monaco-editor/esm/vs/editor/editor.worker.js") + wasm_bindgen(inline_js = " + import monaco from 'monaco-editor/esm/vs/editor/editor.worker.js'; + export default async function () { + return await monaco(); + } +") )] #[cfg_attr(test, wasm_bindgen(inline_js = "export default async function() {}"))] extern "C" { - #[wasm_bindgen(js_name = "default")] pub async fn new_worker() -> JsValue; } @@ -36,9 +40,8 @@ extern "C" { not(test), wasm_bindgen(inline_js = " export async function monaco_module() { - return import( + return await import( /* webpackChunkName: \"monaco\" */ - /* webpackMode: \"eager\" */ 'monaco-editor/esm/vs/editor/edcore.main.js' ); } diff --git a/rust/perspective-viewer/tsconfig.json b/rust/perspective-viewer/tsconfig.json index c384857ffb..1a871fec16 100644 --- a/rust/perspective-viewer/tsconfig.json +++ b/rust/perspective-viewer/tsconfig.json @@ -3,6 +3,7 @@ "module": "esnext", "target": "es2018", "declaration": true, + "emitDeclarationOnly": true, "outDir": "dist/esm", "rootDir": "src/ts", "allowSyntheticDefaultImports": true,