Skip to content

Commit

Permalink
Export *Mount separately
Browse files Browse the repository at this point in the history
Otherwise, using browser-monkey with webpack requires hyperdom and react
to be installed.
  • Loading branch information
artemave committed Mar 8, 2021
1 parent 155f899 commit ba86884
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/dist/
docs-dist/
.exrc
*Mount.js*
18 changes: 18 additions & 0 deletions export-mounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
const fs = require('fs')

function moveFileAndUpdateImports(path) {
fs.copyFileSync(`./dist/lib/${path}`, `./${path}`)
fs.copyFileSync(`./dist/lib/${path}.map`, `./${path}.map`)

const jsFile = fs.readFileSync(`./${path}`, {encoding: 'utf-8'})
const newJsFile = jsFile.replace(/require\("\.\//, 'require("./dist/lib/')
fs.writeFileSync(`./${path}`, newJsFile)

const mapFile = fs.readFileSync(`./${path}.map`, {encoding: 'utf-8'})
const newMapFile = mapFile.replace('../..', '.')
fs.writeFileSync(`./${path}.map`, newMapFile)
}

moveFileAndUpdateImports('HyperdomMount.js')
moveFileAndUpdateImports('ReactMount.js')
4 changes: 0 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {Query} from './lib/Query'
import IFrameMount from './lib/IFrameMount'
import Mount from './lib/Mount'
import ReactMount from './lib/ReactMount'
import HyperdomMount from './lib/HyperdomMount'
import * as matchers from './lib/matchers'

export {
Query,
IFrameMount,
Mount,
ReactMount,
HyperdomMount,
matchers,
}
2 changes: 1 addition & 1 deletion lib/HyperdomMount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Mount from './Mount'
import hyperdom from 'hyperdom'
import extend from 'lowscore/extend'

export default class HyperdomMount extends Mount {
Expand All @@ -12,7 +13,6 @@ export default class HyperdomMount extends Mount {
if (options && (options.hash || options.url) && options.router) {
options.router.push(options.url || options.hash)
}
const hyperdom = require('hyperdom')
hyperdom.append(testDiv, app, extend({ requestRender: setTimeout }, options))
}
}
2 changes: 1 addition & 1 deletion lib/ReactMount.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Mount from './Mount'
import ReactDOM from 'react-dom'

export default class ReactMount extends Mount {
public constructor (vdom: any) {
super()
const div = this.containerElement()

const ReactDOM = require('react-dom')
ReactDOM.render(vdom, div)
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"dist/*",
"lib/*",
"test/*",
"index.ts"
"index.ts",
"*Mount.js*"
],
"scripts": {
"test": "yarn test-electron-mocha && eslint .",
"test-karma": "karma start --single-run",
"test-electron-mocha": "yarn electron-mocha test/**/*Spec.{js,ts}",
"electron-mocha": "electron-mocha --disable-site-isolation-trials --full-trace --color --main electron/foreignIframe.js -r ts-node/register --renderer",
"mocha": "mocha -r test/register.js",
"prepare": "tsc -p tsconfig.build.json",
"prepare": "tsc -p tsconfig.build.json && ./export-mounts.js && node -r ./HyperdomMount.js -r ./ReactMount.js -e '1'",
"docs": "yarn build-docs && docsify serve --no-open --port 3003 ./docs-dist",
"watch-docs": "ls docs/*.md | entr yarn build-docs",
"build-docs": "rm -rf ./docs-dist && cp -r ./docs ./docs-dist && codesandbox-example-links --output-dir=./docs-dist ./docs/*.md",
Expand Down
4 changes: 2 additions & 2 deletions test/mountSpec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Query} from '../lib/Query'
import {DomAssembly} from './assemblies/DomAssembly'
import {ReactMount} from '..'
import ReactMount from '../lib/ReactMount'
import IFrameMount from '../lib/IFrameMount'
import Mount from '../lib/Mount'
import ReactApp from './app/react'
import React from 'react'
import {HyperdomMount} from '..'
import HyperdomMount from '../lib/HyperdomMount'
import HyperdomApp from './app/hyperdom'

describe('mount', () => {
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "./tsconfig.json",
"files": [
"index.ts"
"index.ts",
"lib/ReactMount.ts",
"lib/HyperdomMount.ts"
],
"include": ["lib/**/*"],
"compilerOptions": {
Expand Down

0 comments on commit ba86884

Please sign in to comment.