Skip to content

Commit 4a9ea2c

Browse files
committed
#97 prepare ketcher for publishing to npm
- update .babelrc - update rollup config - mark dependencies as external
1 parent a0dfc23 commit 4a9ea2c

File tree

9 files changed

+485
-349
lines changed

9 files changed

+485
-349
lines changed

.babelrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"presets": ["@babel/env", "@babel/react", "@babel/typescript"],
33
"plugins": [
4+
"@babel/plugin-transform-runtime",
45
"@babel/proposal-class-properties",
56
"@babel/proposal-object-rest-spread"
67
]

example/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import Editor from '@ketcher/react'
3+
import { Editor } from '@ketcher/react'
44
import '@ketcher/react/dist/index.css'
55

66
const App = () => {

example/yarn.lock

+6-20
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@
11021102
dependencies:
11031103
regenerator-runtime "^0.13.4"
11041104

1105-
"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.12.1", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.1", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4":
1105+
"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.1", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4":
11061106
version "7.12.5"
11071107
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
11081108
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
@@ -9100,15 +9100,6 @@ query-string@^4.1.0:
91009100
object-assign "^4.1.0"
91019101
strict-uri-encode "^1.0.0"
91029102

9103-
query-string@^6.13.6:
9104-
version "6.13.6"
9105-
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.13.6.tgz#e5ac7c74f2a5da43fbca0b883b4f0bafba439966"
9106-
integrity sha512-/WWZ7d9na6s2wMEGdVCVgKWE9Rt7nYyNIf7k8xmHXcesPMlEzicWo3lbYwHyA4wBktI2KrXxxZeACLbE84hvSQ==
9107-
dependencies:
9108-
decode-uri-component "^0.2.0"
9109-
split-on-first "^1.0.0"
9110-
strict-uri-encode "^2.0.0"
9111-
91129103
querystring-es3@^0.2.0:
91139104
version "0.2.1"
91149105
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
@@ -10325,11 +10316,6 @@ spdy@^4.0.2:
1032510316
select-hose "^2.0.0"
1032610317
spdy-transport "^3.0.0"
1032710318

10328-
split-on-first@^1.0.0:
10329-
version "1.1.0"
10330-
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
10331-
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
10332-
1033310319
split-string@^3.0.1, split-string@^3.0.2:
1033410320
version "3.1.0"
1033510321
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
@@ -10437,11 +10423,6 @@ strict-uri-encode@^1.0.0:
1043710423
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
1043810424
integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=
1043910425

10440-
strict-uri-encode@^2.0.0:
10441-
version "2.0.0"
10442-
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
10443-
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
10444-
1044510426
string-length@^2.0.0:
1044610427
version "2.0.0"
1044710428
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"
@@ -11126,6 +11107,11 @@ url-parse@^1.4.3:
1112611107
querystringify "^2.1.1"
1112711108
requires-port "^1.0.0"
1112811109

11110+
url-search-params-polyfill@^8.1.0:
11111+
version "8.1.0"
11112+
resolved "https://registry.yarnpkg.com/url-search-params-polyfill/-/url-search-params-polyfill-8.1.0.tgz#5c15b69687165bfd4f6c7d8a161d70d85385885b"
11113+
integrity sha512-MRG3vzXyG20BJ2fox50/9ZRoe+2h3RM7DIudVD2u/GY9MtayO1Dkrna76IUOak+uoUPVWbyR0pHCzxctP/eDYQ==
11114+
1112911115
url@^0.11.0:
1113011116
version "0.11.0"
1113111117
resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1"

package.json

+15-9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"node": ">=10"
2828
},
2929
"scripts": {
30-
"build": "rollup -c -m true",
31-
"start": "rollup -c -w -m true",
30+
"build": "cross-env NODE_ENV=production rollup -c -m true --silent",
31+
"start": "cross-env NODE_ENV=development rollup -c -m true -w",
3232
"test": "run-s test:unit test:lint prettier stylelint test:build",
3333
"test:build": "run-s build",
3434
"test:lint": "eslint src --ext .ts,.tsx,.js,.jsx",
@@ -41,36 +41,42 @@
4141
"predeploy": "cd example && yarn install && yarn build",
4242
"deploy": "gh-pages -d example/build"
4343
},
44+
"peerDependencies": {
45+
"react": "^16.13.0",
46+
"react-dom": "^16.13.0"
47+
},
4448
"dependencies": {
49+
"@babel/runtime": "^7.12.5",
4550
"classnames": "^2.2.6",
4651
"core-js": "^3.6.5",
4752
"file-saver": "^2.0.2",
4853
"font-face-observer": "^1.0.0",
54+
"hoist-non-react-statics": "^3.3.2",
4955
"jsonschema": "^1.4.0",
5056
"lodash": "^4.17.20",
5157
"normalize.css": "^8.0.1",
52-
"query-string": "^6.13.6",
58+
"prop-types": "^15.7.2",
5359
"raphael": "^2.3.0",
60+
"react-is": "^17.0.1",
5461
"react-markdown": "^5.0.2",
5562
"react-redux": "^7.2.1",
5663
"redux": "^4.0.5",
5764
"redux-logger": "^3.0.6",
5865
"redux-thunk": "^2.3.0",
5966
"regenerator-runtime": "^0.13.7",
67+
"remark-parse": "^9.0.0",
6068
"replace": "^1.2.0",
6169
"reselect": "^4.0.0",
6270
"subscription": "^3.0.0",
71+
"url-search-params-polyfill": "^8.1.0",
6372
"w3c-keyname": "^2.2.4",
6473
"whatwg-fetch": "^3.4.1"
6574
},
66-
"peerDependencies": {
67-
"react": "^16.13.0",
68-
"react-dom": "^16.13.0"
69-
},
7075
"devDependencies": {
7176
"@babel/core": "^7.12.3",
7277
"@babel/plugin-proposal-class-properties": "^7.12.1",
7378
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
79+
"@babel/plugin-transform-runtime": "^7.12.1",
7480
"@babel/preset-env": "^7.12.1",
7581
"@babel/preset-react": "^7.12.5",
7682
"@babel/preset-typescript": "^7.12.1",
@@ -79,6 +85,7 @@
7985
"@rollup/plugin-json": "^4.1.0",
8086
"@rollup/plugin-node-resolve": "^10.0.0",
8187
"@rollup/plugin-replace": "^2.3.4",
88+
"@rollup/plugin-strip": "^2.0.0",
8289
"@svgr/rollup": "^5.4.0",
8390
"@testing-library/jest-dom": "^4.2.4",
8491
"@testing-library/react": "^9.5.0",
@@ -114,9 +121,8 @@
114121
"rollup-plugin-cleanup": "^3.2.1",
115122
"rollup-plugin-copy": "^3.3.0",
116123
"rollup-plugin-delete": "^2.0.0",
117-
"rollup-plugin-less": "^1.1.2",
118124
"rollup-plugin-peer-deps-external": "^2.2.4",
119-
"rollup-plugin-string": "^3.0.0",
125+
"rollup-plugin-postcss": "^3.1.8",
120126
"rollup-plugin-typescript2": "^0.29.0",
121127
"rollup-plugin-visualizer": "^4.2.0",
122128
"stylelint": "^13.7.2",

rollup.config.js

+37-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1+
import path from 'path'
12
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
23
import babel from '@rollup/plugin-babel'
34
import replace from '@rollup/plugin-replace'
4-
import { string } from 'rollup-plugin-string'
55
import copy from 'rollup-plugin-copy'
66
import resolve from '@rollup/plugin-node-resolve'
77
import commonjs from '@rollup/plugin-commonjs'
88
import typescript from 'rollup-plugin-typescript2'
9-
import less from 'rollup-plugin-less'
9+
import postcss from 'rollup-plugin-postcss'
1010
import json from '@rollup/plugin-json'
1111
import svgr from '@svgr/rollup'
1212
import del from 'rollup-plugin-delete'
1313
import cleanup from 'rollup-plugin-cleanup'
14+
import strip from '@rollup/plugin-strip'
1415
import pkg from './package.json'
1516

17+
const mode = {
18+
PRODUCTION: 'production',
19+
DEVELOPMENT: 'development'
20+
}
21+
1622
const extensions = ['.js', '.jsx', '.ts', '.tsx']
23+
const isProduction = process.env.NODE_ENV === mode.PRODUCTION
1724

1825
const config = {
1926
input: pkg.source,
@@ -29,46 +36,61 @@ const config = {
2936
format: 'es'
3037
}
3138
],
39+
external: [
40+
'url',
41+
/@babel\/runtime/,
42+
'remark-parse',
43+
'unified',
44+
'asap',
45+
'object-assign',
46+
'unist-util-visit',
47+
'unist-util-visit-parents',
48+
'xtend'
49+
],
3250
plugins: [
3351
del({
3452
targets: 'dist/*',
3553
runOnce: true
3654
}),
37-
peerDepsExternal(),
38-
typescript(),
39-
string({
40-
// Required to be specified
41-
include: 'src/**/*.{sdf,md}'
42-
}),
55+
peerDepsExternal({ includeDependencies: true }),
4356
commonjs(),
57+
resolve({ extensions, preferBuiltins: true }),
58+
59+
typescript(),
4460
replace(
4561
{
62+
'process.env.NODE_ENV': JSON.stringify(
63+
isProduction ? mode.PRODUCTION : mode.DEVELOPMENT
64+
),
4665
'process.env.VERSION': JSON.stringify(pkg.version),
4766
'process.env.BUILD_DATE': JSON.stringify(
4867
new Date().toISOString().slice(0, 19)
4968
),
69+
//TODO: add logic to init BUILD_NUMBER
5070
'process.env.BUILD_NUMBER': JSON.stringify(undefined)
5171
},
5272
{
53-
include: 'src/**/*.{js,jsx,ts,tsx}',
54-
verbose: true
73+
include: 'src/**/*.{js,jsx,ts,tsx}'
5574
}
5675
),
57-
resolve({ extensions, preferBuiltins: true }),
5876

5977
json(),
6078
babel({
6179
extensions,
62-
babelHelpers: 'bundled',
80+
babelHelpers: 'runtime',
6381
include: ['src/**/*']
6482
}),
65-
less({ output: 'dist/index.css' }),
66-
83+
postcss({
84+
extract: path.resolve('dist/index.css'),
85+
minimize: isProduction,
86+
sourceMap: true
87+
}),
6788
svgr(),
6889
copy({
6990
targets: [{ src: 'src/style/*.svg', dest: 'dist' }]
7091
}),
71-
cleanup({ extensions })
92+
cleanup({ extensions, comments: 'none' }),
93+
...(isProduction ? [strip()] : [])
7294
]
7395
}
7496

src/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Editor from '.'
1+
import { Editor } from '.'
22

33
describe('Editor', () => {
44
it('is truthy', () => {

src/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useEffect, useRef } from 'react'
2+
import 'url-search-params-polyfill'
23
import init from './script'
34
import './index.less'
45

@@ -7,7 +8,7 @@ interface EditorProps {
78
apiPath?: string
89
}
910

10-
export default function Editor({ staticResourcesUrl, apiPath }: EditorProps) {
11+
export function Editor({ staticResourcesUrl, apiPath }: EditorProps) {
1112
const rootElRef = useRef(null)
1213
useEffect(() => {
1314
init(rootElRef.current, staticResourcesUrl, apiPath)

src/script/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import 'core-js/stable'
1818
import 'regenerator-runtime/runtime'
1919
import 'whatwg-fetch'
20-
import queryString from 'query-string'
2120

2221
import api from './api'
2322
import molfile from './chem/molfile'
@@ -81,8 +80,8 @@ function showMolfile(clientArea, molString, options) {
8180
// to start early
8281
export default function init(el, staticResourcesUrl, apiPath) {
8382
ketcher.apiPath = apiPath
84-
const params = queryString.parse(document.location.search)
85-
if (params.api_path) ketcher.apiPath = params.api_path
83+
const params = new URLSearchParams(document.location.search)
84+
if (params.has('api_path')) ketcher.apiPath = params.get('api_path')
8685
ketcher.server = api(ketcher.apiPath, {
8786
'smart-layout': true,
8887
'ignore-stereochemistry-errors': true,

0 commit comments

Comments
 (0)