Skip to content

Commit 4bb6701

Browse files
authored
feat: perform full processing in a worker (#43)
* feat: bump all deps * refactor: lodash imports * refactor: rewrite namespace imports * feat: workerify * feat: support mergeAllOf * build: storybook * feat: computing state * revert: object utils * test: map workers * fix: rewrite lodash imports * fix: lint --fix * build(ts): set target to ES2017 * test: rename mock * chore: remove utils/index.ts * feat: make full rendering optional * fix: sort imports * build: do not compile mocks * chore: exclude dist in tsconfig + add missing deps * test: cover workers * Update jest.config.js Co-Authored-By: William Hilton <wmhilton@gmail.com> * chore: fixes * chore: screw it
1 parent 4bcd27c commit 4bb6701

28 files changed

+3392
-2734
lines changed

.storybook/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
const defaultConfig = require('@stoplight/storybook-config/webpack.config');
2+
const path = require('path');
23

34
module.exports = (baseConfig, env, config) => {
45
config = defaultConfig(baseConfig, env, config);
56

7+
config.output.globalObject = 'this';
8+
config.resolve.alias['web-worker:../workers/schema.ts'] = path.join(process.cwd(), './src/__stories__/worker.shim.ts');
9+
610
return config;
711
};

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'plugins': ['@babel/plugin-transform-modules-commonjs'],
3+
};

jest.config.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
module.exports = {
2-
preset: "@stoplight/scripts",
3-
testEnvironment: "jsdom",
4-
setupFilesAfterEnv: ["./setupTests.ts"],
5-
snapshotSerializers: ["enzyme-to-json/serializer"],
2+
rootDir: process.cwd(),
3+
testEnvironment: 'jsdom',
4+
setupFilesAfterEnv: ['./setupTests.ts'],
65
moduleNameMapper: {
7-
"\\.(css)$": "<rootDir>/__mocks__/styleMock.js"
8-
}
6+
'\\.css$': '<rootDir>/__mocks__/styleMock.js',
7+
'web-worker:\\.\\./(.+)$': '<rootDir>/src/$1'
8+
},
9+
testMatch: ['<rootDir>/src/**/__tests__/*.(ts|js)?(x)'],
10+
transformIgnorePatterns: ['/node_modules/(?!lodash-es)/'],
11+
transform: {
12+
'\\.tsx?$': 'ts-jest',
13+
'^.+\\.js$': 'babel-jest'
14+
},
15+
coveragePathIgnorePatterns: ['/node_modules/', '/__tests__/', '/__stories__/', '__mocks__/', 'types.ts'],
16+
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
17+
globals: {
18+
'ts-jest': {
19+
diagnostics: {
20+
ignoreCodes: [151001],
21+
},
22+
},
23+
},
924
};

package.json

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"node": ">=8.3.0"
2121
},
2222
"scripts": {
23-
"build": "sl-scripts build",
23+
"build": "sl-scripts build --sourcemap",
2424
"build.docs": "build-storybook -c .storybook -o docs-auto",
2525
"commit": "git-cz",
26-
"lint": "tslint -c tslint.json 'src/**/*.ts?'",
26+
"lint": "tslint -c tslint.json -p tsconfig.json 'src/**/*.ts?'",
2727
"lint.fix": "yarn lint --fix",
2828
"release": "sl-scripts release",
2929
"release.docs": "sl-scripts release:docs",
@@ -38,48 +38,57 @@
3838
"@stoplight/markdown-viewer": "3.x.x",
3939
"@stoplight/tree-list": "4.x.x",
4040
"@stoplight/ui-kit": "2.x.x",
41-
"lodash": "4.x.x",
4241
"mobx": "5.x.x",
4342
"react": ">=16.8",
4443
"react-dom": ">=16.8"
4544
},
4645
"dependencies": {
47-
"@stoplight/json": "1.9.x",
46+
"@stoplight/json": "3.0.3",
4847
"classnames": "^2.2.6",
4948
"json-schema-merge-allof": "https://github.com/stoplightio/json-schema-merge-allof",
50-
"mobx-react-lite": "^1.3.1",
51-
"pluralize": "^7.0.0"
49+
"lodash-es": "^4.17.15",
50+
"mobx-react-lite": "^1.4.1",
51+
"pluralize": "^8.0.0"
5252
},
5353
"devDependencies": {
54-
"@sambego/storybook-state": "^1.3.4",
55-
"@stoplight/markdown-viewer": "^3.0.0",
56-
"@stoplight/scripts": "5.1.0",
57-
"@stoplight/storybook-config": "^2.0.2",
58-
"@stoplight/tree-list": "^4.0.0",
59-
"@stoplight/types": "4.1.0",
60-
"@stoplight/ui-kit": "^2.4.0",
61-
"@types/classnames": "^2.2.7",
62-
"@types/enzyme": "3.9.1",
63-
"@types/jest": "^24.0.12",
54+
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
55+
"@emotion/core": "^10.0.16",
56+
"@emotion/styled": "^10.0.15",
57+
"@sambego/storybook-state": "^1.3.6",
58+
"@stoplight/markdown-viewer": "^3.5.5",
59+
"@stoplight/scripts": "7.0.3",
60+
"@stoplight/storybook-config": "^2.0.4",
61+
"@stoplight/tree-list": "^4.8.0",
62+
"@stoplight/types": "11.0.0",
63+
"@stoplight/ui-kit": "^2.10.0",
64+
"@types/classnames": "^2.2.9",
65+
"@types/enzyme": "3.10.3",
66+
"@types/jest": "^24.0.18",
6467
"@types/json-schema": "^7.0.3",
65-
"@types/node": "^11.13.8",
68+
"@types/lodash-es": "^4.17.3",
69+
"@types/node": "^12.7.2",
6670
"@types/pluralize": "^0.0.29",
67-
"@types/react": "16.8.12",
68-
"@types/react-dom": "16.8.3",
69-
"copyfiles": "^2.1.0",
70-
"enzyme": "3.9.0",
71-
"enzyme-adapter-react-16": "1.12.1",
72-
"enzyme-to-json": "3.x.x",
73-
"jest": "^24.7.1",
74-
"jest-enzyme": "7.0.2",
75-
"lodash": "^4.17.11",
76-
"mobx": "^5.9.4",
77-
"react": "16.8.6",
78-
"react-dom": "16.8.6",
71+
"@types/react": "16.9.2",
72+
"@types/react-dom": "16.9.0",
73+
"babel-jest": "^24.9.0",
74+
"copyfiles": "^2.1.1",
75+
"emotion-theming": "^10.0.14",
76+
"enzyme": "3.10.0",
77+
"enzyme-adapter-react-16": "1.14.0",
78+
"enzyme-to-json": "3.4.0",
79+
"jest": "^24.9.0",
80+
"jest-enzyme": "7.1.0",
81+
"mobx": "^5.13.0",
82+
"react": "16.9.0",
83+
"react-dom": "16.9.0",
84+
"rollup-plugin-commonjs": "^10.0.2",
85+
"rollup-plugin-node-resolve": "^5.2.0",
86+
"rollup-plugin-web-worker-loader": "p0lip/rollup-plugin-web-worker-loader",
7987
"ts-jest": "^24.0.2",
80-
"tslint": "^5.16.0",
88+
"tslint": "^5.19.0",
8189
"tslint-config-stoplight": "^1.2.0",
82-
"typescript": "3.4.5"
90+
"typescript": "3.5.3",
91+
"worker-loader": "^2.0.0"
8392
},
8493
"lint-staged": {
8594
"*.{ts,tsx}$": [

rollup.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import config from '@stoplight/scripts/rollup.config';
2+
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
3+
import resolve from 'rollup-plugin-node-resolve';
4+
import commonjs from 'rollup-plugin-commonjs';
5+
6+
config.plugins.push(
7+
commonjs(),
8+
resolve({
9+
only: ['json-schema-merge-allof', /lodash(?:-es)?\/?.*/],
10+
}),
11+
webWorkerLoader({
12+
inline: true,
13+
}),
14+
);
15+
16+
export default config;

src/__stories__/JsonSchemaViewer.tsx

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import { action } from '@storybook/addon-actions';
66
import { boolean, number, object, select, text, withKnobs } from '@storybook/addon-knobs';
77
import { storiesOf } from '@storybook/react';
88
import { JSONSchema4 } from 'json-schema';
9-
import { JsonSchemaViewer, SchemaRow } from '../components';
9+
import { JsonSchemaViewer, RowRenderer, SchemaRow } from '../';
1010

11-
import * as allOfSchemaResolved from '../__fixtures__/allOf/allOf-resolved.json';
12-
import * as allOfSchema from '../__fixtures__/allOf/allOf-schema.json';
13-
import * as schema from '../__fixtures__/default-schema.json';
14-
import * as schemaWithRefs from '../__fixtures__/ref/original.json';
15-
import * as dereferencedSchema from '../__fixtures__/ref/resolved.json';
16-
import * as stressSchema from '../__fixtures__/stress-schema.json';
17-
import { RowRenderer } from '../types';
11+
const allOfSchemaResolved = require('../__fixtures__/allOf/allOf-resolved.json');
12+
const allOfSchema = require('../__fixtures__/allOf/allOf-schema.json');
13+
const schema = require('../__fixtures__/default-schema.json');
14+
const schemaWithRefs = require('../__fixtures__/ref/original.json');
15+
const dereferencedSchema = require('../__fixtures__/ref/resolved.json');
16+
const stressSchema = require('../__fixtures__/stress-schema.json');
1817
import { Wrapper } from './utils/Wrapper';
1918

2019
storiesOf('JsonSchemaViewer', module)
@@ -88,16 +87,32 @@ storiesOf('JsonSchemaViewer', module)
8887
);
8988
})
9089
.add('stress-test schema', () => (
91-
<JsonSchemaViewer
92-
name={text('name', 'my stress schema')}
93-
schema={stressSchema as JSONSchema4}
94-
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
95-
expanded={boolean('expanded', false)}
96-
hideTopBar={boolean('hideTopBar', false)}
97-
onGoToRef={action('onGoToRef')}
98-
maxRows={number('maxRows', 10)}
99-
mergeAllOf={boolean('mergeAllOf', true)}
100-
/>
90+
<>
91+
<div style={{ height: 345 }}>
92+
<JsonSchemaViewer
93+
name={text('name', 'my stress schema')}
94+
schema={stressSchema as JSONSchema4}
95+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
96+
expanded={boolean('expanded', false)}
97+
hideTopBar={boolean('hideTopBar', false)}
98+
onGoToRef={action('onGoToRef')}
99+
maxRows={number('maxRows', 10)}
100+
mergeAllOf={boolean('mergeAllOf', true)}
101+
/>
102+
</div>
103+
<div style={{ height: 345 }}>
104+
<JsonSchemaViewer
105+
name={text('name', 'my stress schema 2')}
106+
schema={stressSchema as JSONSchema4}
107+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
108+
expanded={boolean('expanded', false)}
109+
hideTopBar={boolean('hideTopBar', false)}
110+
onGoToRef={action('onGoToRef')}
111+
maxRows={number('maxRows', 10)}
112+
mergeAllOf={boolean('mergeAllOf', true)}
113+
/>
114+
</div>
115+
</>
101116
))
102117
.add('allOf-schema', () => (
103118
<JsonSchemaViewer

src/__stories__/worker.shim.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Worker from 'worker-loader!../workers/schema.ts';
2+
3+
export default Worker;

0 commit comments

Comments
 (0)