@startupjs/bundler 0.51.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,28 @@
1
- const REGEX = /(```jsx +example[\s\S]*?\n)([\s\S]*?)(```)/g
2
- const PURE_REGEX = /(```jsx +pure-example[\s\S]*?\n)([\s\S]*?)(```)/g
1
+ const REGEX = /(```jsx +(?:example|pure-example)[\s\S]*?\n)([\s\S]*?)(```)/g
3
2
 
4
- const EXAMPLE_FLAGS = [
5
- 'noscroll'
3
+ const FLAGS = [
4
+ 'example',
5
+ 'noscroll',
6
+ 'pure-example'
6
7
  ]
7
8
 
9
+ const DEFAULT_MDX_RENDERER = `
10
+ import React from 'react'
11
+ import { observer as __observer } from 'startupjs'
12
+ `
13
+
8
14
  module.exports = function mdxExamplesLoader (source) {
9
- const observer = "import { observer as __observer } from 'startupjs'"
10
- // NOTE: Two line breaks prevent crashing docs without imports
11
- // when the text starts from the first line
12
- return observer + '\n\n' + source.replace(REGEX, replacer).replace(PURE_REGEX, pureReplacer)
15
+ return DEFAULT_MDX_RENDERER + '\n' + source.replace(REGEX, replacer)
13
16
  }
14
17
 
15
18
  function replacer (match, p1, p2, p3) {
16
19
  const parts = p1.trim().split(' ')
17
- const sectionParts = []
18
20
  const p1Parts = []
21
+ const flags = {}
19
22
 
20
23
  for (const part of parts) {
21
- if (EXAMPLE_FLAGS.includes(part)) {
22
- sectionParts.push(part)
24
+ if (FLAGS.includes(part)) {
25
+ flags[part] = true
23
26
  continue
24
27
  }
25
28
  p1Parts.push(part)
@@ -27,42 +30,22 @@ function replacer (match, p1, p2, p3) {
27
30
 
28
31
  p1 = p1Parts.join(' ')
29
32
 
30
- const code = `\n\n${p1}\n${p2}${p3}`
31
-
32
- p2 = p2.trim().replace(/\n+/g, '\n')
33
- if (/^</.test(p2)) p2 = 'return (<React.Fragment>' + p2 + '</React.Fragment>)'
34
-
35
- return (
36
- `<section ${sectionParts.join(' ')}>
37
- <React.Fragment>
38
- {React.createElement(__observer(function Example () {
39
- ${p2}
40
- }))}
41
- </React.Fragment>
42
- </section>` + code
43
- )
44
- }
45
-
46
- function pureReplacer (match, p1, p2, p3) {
47
- const parts = p1.trim().split(' ')
48
- const sectionParts = []
49
-
50
- for (const part of parts) {
51
- if (EXAMPLE_FLAGS.includes(part)) {
52
- sectionParts.push(part)
53
- }
54
- }
33
+ const code = flags['pure-example']
34
+ ? ''
35
+ : `\n\n${p1}\n[HACK EXAMPLE CODE]${p2}${p3}`
55
36
 
56
37
  p2 = p2.trim().replace(/\n+/g, '\n')
57
38
  if (/^</.test(p2)) p2 = 'return (<React.Fragment>' + p2 + '</React.Fragment>)'
58
39
 
59
40
  return (
60
- `<section ${sectionParts.join(' ')}>
61
- <React.Fragment>
62
- {React.createElement(__observer(function Example () {
63
- ${p2}
64
- }))}
65
- </React.Fragment>
66
- </section>`
41
+ `{React.createElement(
42
+ _components.section,
43
+ ${JSON.stringify(flags)},
44
+ <React.Fragment>
45
+ {React.createElement(__observer(function Example () {
46
+ ${p2}
47
+ }))}
48
+ </React.Fragment>
49
+ )}` + code
67
50
  )
68
51
  }
package/lib/mdxLoader.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const mdx = require('@mdx-js/mdx')
2
2
 
3
3
  const DEFAULT_MDX_RENDERER = `
4
- import React from 'react'
5
4
  import { mdx } from '@mdx-js/react'
6
5
  `
7
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startupjs/bundler",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "Opinionated scripts and configs to develop a react-native-web project",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -16,17 +16,17 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "@babel/polyfill": "^7.8.0",
19
- "@mdx-js/loader": "^1.6.22",
20
- "@mdx-js/mdx": "^1.6.22",
19
+ "@mdx-js/loader": "^2.3.0",
20
+ "@mdx-js/mdx": "^2.3.0",
21
21
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
22
22
  "@startupjs/babel-plugin-react-css-modules": "^6.5.4-1",
23
23
  "@startupjs/css-to-react-native-transform": "^1.9.0-1",
24
- "@startupjs/plugin": "^0.51.0",
24
+ "@startupjs/plugin": "^0.52.0",
25
25
  "@svgr/webpack": "~7.0.0",
26
26
  "assets-webpack-plugin": "^7.1.1",
27
27
  "autoprefixer": "^10.4.0",
28
28
  "babel-loader": "^8.2.3",
29
- "babel-preset-startupjs": "^0.51.0",
29
+ "babel-preset-startupjs": "^0.52.0",
30
30
  "css-loader": "^6.5.0",
31
31
  "css-minimizer-webpack-plugin": "^5.0.0",
32
32
  "file-loader": "^6.2.0",
@@ -40,6 +40,7 @@
40
40
  "process": "^0.11.10",
41
41
  "react-native-svg-transformer": "0.20.0",
42
42
  "react-refresh": "^0.10.0",
43
+ "remark-gfm": "^1.0.0",
43
44
  "style-loader": "^3.3.1",
44
45
  "stylus": "0.54.7",
45
46
  "stylus-loader": "^6.2.0",
@@ -49,5 +50,5 @@
49
50
  "peerDependencies": {
50
51
  "react-native-svg": ">= 12.1.0"
51
52
  },
52
- "gitHead": "c5a82f52ce1671b272e216ebd860e93734f561f0"
53
+ "gitHead": "257155ad428542785e4d3536b77cd624425ef14a"
53
54
  }
@@ -18,6 +18,7 @@ const BUILD_PATH = path.join(process.cwd(), BUILD_DIR)
18
18
  const BUNDLE_NAME = 'main'
19
19
  const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
20
20
  const webpack = require('webpack')
21
+ const remarkGfm = require('remark-gfm')
21
22
  const DEFAULT_MODE = 'react-native'
22
23
  const PLUGINS = getPluginConfigs()
23
24
 
@@ -228,7 +229,11 @@ module.exports = function getConfig (env, {
228
229
  use: [
229
230
  { loader: 'babel-loader' },
230
231
  {
231
- loader: '@mdx-js/loader'
232
+ loader: '@mdx-js/loader',
233
+ options: {
234
+ providerImportSource: '@startupjs/mdx/client/MDXProvider/index.js',
235
+ remarkPlugins: [remarkGfm]
236
+ }
232
237
  },
233
238
  {
234
239
  loader: require.resolve('./lib/mdxExamplesLoader.js')