From f22adfdd4448b4d07de53ea52461cf53867d079e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 1 Jun 2021 18:56:56 -0500 Subject: [PATCH 1/5] fix: build hydrogen using parcel --- .github/workflows/CI.yml | 1 + .npmrc | 1 - babel.config.json | 6 ++++++ package.json | 36 ++++++++++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 babel.config.json diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index afc1288e3..dc1153fdd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -27,6 +27,7 @@ jobs: - name: Install dependencies and build run: | apm install + npm run tsc || echo done npm run build - name: Run tests 👩🏾‍💻 diff --git a/.npmrc b/.npmrc index ac5613f69..9eccfb6c8 100644 --- a/.npmrc +++ b/.npmrc @@ -1,4 +1,3 @@ public-hoist-pattern[]=* -package-lock=false lockfile=true prefer-frozen-lockfile=false diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 000000000..469e76ee6 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + ["@babel/plugin-proposal-decorators", { "legacy": true }], + ["@babel/plugin-proposal-class-properties", { "loose": true }] + ] +} diff --git a/package.json b/package.json index d74c024f8..e87d2eef2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Hydrogen", - "main": "./dist/main", + "main": "./dist/main.js", "version": "2.16.3", "description": "Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.", "author": "nteract contributors", @@ -43,13 +43,13 @@ "test": "echo 'test without rebuilding' && atom --test spec", "clean": "shx rm -rf dist", "clean.prod": "shx rm -rf ./dist/**/*.d.ts ./dist/tsconfig.tsbuildinfo", - "dev": "npm run clean && tsc -p lib/tsconfig.json --watch", "tsc": "tsc -p lib/tsconfig.json || echo done", - "build": "npm run clean && npm run tsc && npm run clean.prod", + "dev": "npm run tsc -- --watch", + "build": "cross-env NODE_ENV=production parcel build ./lib/main.ts --detailed-report", "build:services-docs": "markdox lib/services/index.js -o lib/services/README.md", "build:plugin-docs": "markdox lib/plugin-api/hydrogen-provider.js lib/plugin-api/hydrogen-kernel.js -o docs/PluginAPI.md", "build:docs": "npm run build:plugin-docs && npm run build:services-docs", - "build-commit": "build-commit -o dist", + "build-commit": "npm run clean && build-commit -o dist", "prepare": "npm run build" }, "atomTestRunner": "atom-jasmine3-test-runner", @@ -113,6 +113,8 @@ } }, "devDependencies": { + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/plugin-proposal-decorators": "^7.14.2", "@nteract/types": "^7.1.7", "@types/atom": "^1.40.10", "@types/enzyme": "^3.10.8", @@ -128,15 +130,41 @@ "@types/ws": "^7.4.1", "atom-jasmine3-test-runner": "^5.2.5", "build-commit": "^0.1.4", + "cross-env": "^7.0.3", "electron": "^6", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.6", "eslint-config-atomic": "^1.14.4", "eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0", "markdox": "^0.1.10", + "parcel": "^2.0.0-beta.3.1", "prettier-config-atomic": "^2.0.5", "react-test-renderer": "^17.0.2", "shx": "^0.3.3", "typescript": "^4.2.4" + }, + "targets": { + "main": { + "context": "electron-renderer", + "engines": { + "electron": ">=6.x" + }, + "includeNodeModules": { + "atom": false, + "electron": false, + "@aminya/zeromq": false, + "canvas": false, + "react": false, + "react-dom": false, + "react-refresh": false, + "mobx-react": false, + "@nteract/plotly": false, + "refractor": false + }, + "isLibrary": true + } + }, + "alias": { + "moment": "moment/src/moment.js" } } From 16996e29b7faa665ae12a8675ffe6d3e0faa6fd7 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 2 Jun 2021 01:46:56 -0500 Subject: [PATCH 2/5] ci: build and test in separate jobs --- .github/workflows/CI.yml | 53 ++++++++++++++++++++++++++++++++-------- package.json | 3 +-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dc1153fdd..490321be7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -6,8 +6,40 @@ on: # - master jobs: + Build: + if: "!contains(github.event.head_commit.message, '[skip ci]')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + atom_channel: + - stable + steps: + - uses: actions/checkout@v2 + - uses: atom-community/action-setup-atom@v1 + with: + channel: ${{ matrix.atom_channel }} + + - name: Install dependencies and build + run: | + apm install + + npm run clean + npm run tsc || echo done + + npm run build + + - name: Upload built files + uses: actions/upload-artifact@v2 + with: + path: | + ./dist + Test: if: "!contains(github.event.head_commit.message, '[skip ci]')" + needs: Build name: ${{ matrix.os }} - Atom ${{ matrix.atom_channel }} runs-on: ${{ matrix.os }} strategy: @@ -24,11 +56,19 @@ jobs: with: channel: ${{ matrix.atom_channel }} - - name: Install dependencies and build + - name: Download articats + uses: actions/download-artifact@v2 + - name: Place artifacts + shell: bash + run: | + rm -rf ./dist + mkdir ./dist + cp -r ./artifact/* ./dist + rm -rf ./artifact + + - name: Install dependencies run: | apm install - npm run tsc || echo done - npm run build - name: Run tests 👩🏾‍💻 run: npm run test @@ -55,10 +95,3 @@ jobs: - name: Lint ✨ run: npm run test.lint - - Skip: - if: contains(github.event.head_commit.message, '[skip ci]') - runs-on: ubuntu-latest - steps: - - name: Skip CI 🚫 - run: echo skip ci diff --git a/package.json b/package.json index e87d2eef2..3ab53eb84 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,7 @@ "build:services-docs": "markdox lib/services/index.js -o lib/services/README.md", "build:plugin-docs": "markdox lib/plugin-api/hydrogen-provider.js lib/plugin-api/hydrogen-kernel.js -o docs/PluginAPI.md", "build:docs": "npm run build:plugin-docs && npm run build:services-docs", - "build-commit": "npm run clean && build-commit -o dist", - "prepare": "npm run build" + "build-commit": "npm run clean && build-commit -o dist" }, "atomTestRunner": "atom-jasmine3-test-runner", "repository": "https://github.com/nteract/hydrogen", From 5e019c81a8fd7cca483919693b92bca4828478ea Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 2 Jun 2021 02:49:56 -0500 Subject: [PATCH 3/5] fix: add more module aliases to use esm - externalize highlight.js --- package.json | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3ab53eb84..c11acf23e 100644 --- a/package.json +++ b/package.json @@ -158,12 +158,21 @@ "react-refresh": false, "mobx-react": false, "@nteract/plotly": false, - "refractor": false + "refractor": false, + "highlight.js": false }, "isLibrary": true } }, "alias": { - "moment": "moment/src/moment.js" + "async": "async/index.js", + "moment": "moment/src/moment.js", + "mobx": "mobx/lib/mobx.module.js", + "immutable": "immutable/dist/immutable.es.js", + "@emotion/stylis": "@emotion/stylis/dist/stylis.esm.js", + "re-resizable": "re-resizable/lib/index.js", + "react-syntax-highlighter": "react-syntax-highlighter/dist/esm/index.js", + "react-syntax-highlighter/dist/cjs/styles/prism/vs": "react-syntax-highlighter/dist/esm/styles/prism/vs.js", + "react-syntax-highlighter/dist/cjs/styles/prism/xonokai": "react-syntax-highlighter/dist/esm/styles/prism/xonokai.js" } } From a31e633de70d0991d4b5eaf1dc06b16644956967 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 2 Jun 2021 05:08:01 -0500 Subject: [PATCH 4/5] fix: lazy-load xmlhttprequest --- lib/ws-kernel-picker.ts | 5 +++-- package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ws-kernel-picker.ts b/lib/ws-kernel-picker.ts index a8ae1f3cd..230fa347f 100644 --- a/lib/ws-kernel-picker.ts +++ b/lib/ws-kernel-picker.ts @@ -5,7 +5,6 @@ import isEmpty from "lodash/isEmpty"; import tildify from "tildify"; import { v4 } from "uuid"; import ws from "ws"; -import { XMLHttpRequest as NodeXMLHttpRequest } from "xmlhttprequest"; // TODO use @aminya/xmlhttprequest import { URL } from "url"; import { Kernel, Session, ServerConnection } from "@jupyterlab/services"; import Config from "./config"; @@ -198,7 +197,9 @@ export default class WSKernelPicker { options.requestHeaders.Cookie = cookie; options.xhrFactory = () => { - const request = new NodeXMLHttpRequest(); + // we use xmlhttprequest because it allows disabling header protection + const { XMLHttpRequest } = require("xmlhttprequest"); // TODO use @aminya/xmlhttprequest + const request = new XMLHttpRequest(); // Disable protections against setting the Cookie header request.setDisableHeaderCheck(true); return request as XMLHttpRequest; // TODO fix the types diff --git a/package.json b/package.json index c11acf23e..3f81cf03e 100644 --- a/package.json +++ b/package.json @@ -159,7 +159,8 @@ "mobx-react": false, "@nteract/plotly": false, "refractor": false, - "highlight.js": false + "highlight.js": false, + "xmlhttprequest": false }, "isLibrary": true } From e1bbb7e67334517dc853f98dd61029fd65b2c55e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 2 Jun 2021 05:11:55 -0500 Subject: [PATCH 5/5] fix: do not bundle mathjax-electron --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3f81cf03e..8a4a2f1bf 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,7 @@ "@nteract/plotly": false, "refractor": false, "highlight.js": false, + "mathjax-electron": false, "xmlhttprequest": false }, "isLibrary": true