diff --git a/.gitignore b/.gitignore index cde6275..402c5c6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /dist/ docs-dist/ .exrc +*Mount.js* diff --git a/export-mounts.js b/export-mounts.js new file mode 100755 index 0000000..095738e --- /dev/null +++ b/export-mounts.js @@ -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') diff --git a/index.ts b/index.ts index 6ed9ff9..ac6051a 100644 --- a/index.ts +++ b/index.ts @@ -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, } diff --git a/lib/HyperdomMount.ts b/lib/HyperdomMount.ts index 2d7f7c9..19cf114 100644 --- a/lib/HyperdomMount.ts +++ b/lib/HyperdomMount.ts @@ -1,4 +1,5 @@ import Mount from './Mount' +import hyperdom from 'hyperdom' import extend from 'lowscore/extend' export default class HyperdomMount extends Mount { @@ -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)) } } diff --git a/lib/ReactMount.ts b/lib/ReactMount.ts index 485c801..3aa5f41 100644 --- a/lib/ReactMount.ts +++ b/lib/ReactMount.ts @@ -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) } } diff --git a/package.json b/package.json index 15b7917..c4410c8 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "dist/*", "lib/*", "test/*", - "index.ts" + "index.ts", + "*Mount.js*" ], "scripts": { "test": "yarn test-electron-mocha && eslint .", @@ -15,7 +16,7 @@ "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", diff --git a/test/mountSpec.ts b/test/mountSpec.ts index 3f4a079..4137ecb 100644 --- a/test/mountSpec.ts +++ b/test/mountSpec.ts @@ -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', () => { diff --git a/tsconfig.build.json b/tsconfig.build.json index 68e8e6a..b19d631 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,7 +1,9 @@ { "extends": "./tsconfig.json", "files": [ - "index.ts" + "index.ts", + "lib/ReactMount.ts", + "lib/HyperdomMount.ts" ], "include": ["lib/**/*"], "compilerOptions": {