@startupjs/bundler 0.60.0-canary.7 → 0.61.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.
@@ -0,0 +1,42 @@
1
+ const remarkGfm = require('remark-gfm').default
2
+ const { compileSync } = require('@mdx-js/mdx')
3
+ const { readFileSync } = require('fs')
4
+ const path = require('path')
5
+
6
+ const OLD_MDX_IMPORT = '@startupjs/mdx/useMDXComponents'
7
+ const MDX_IMPORT = '@startupjs-ui/mdx'
8
+
9
+ module.exports = function getMDXLoader (source) {
10
+ try {
11
+ source = compileSync(source, {
12
+ providerImportSource: getMDXComponentsImport(),
13
+ remarkPlugins: [remarkGfm],
14
+ jsx: true
15
+ }).value
16
+ } catch (err) {
17
+ if (err) {
18
+ console.log('>> mdx compile error', err)
19
+ throw err
20
+ }
21
+ }
22
+ return source
23
+ }
24
+
25
+ let mdxComponentsImport
26
+ // check if the project's package.json has an old @startupjs/ui dependency
27
+ // and use old mdx library in this case for backward compatibility
28
+ function getMDXComponentsImport () {
29
+ if (mdxComponentsImport) return mdxComponentsImport
30
+ let hasOldStartupUi = false
31
+ try {
32
+ const projectPkgPath = path.join(process.cwd(), 'package.json')
33
+ const packageJson = readFileSync(projectPkgPath, 'utf8')
34
+ if (/"@startupjs\/ui"/.test(packageJson)) hasOldStartupUi = true
35
+ } catch (err) {}
36
+ if (hasOldStartupUi) {
37
+ mdxComponentsImport = OLD_MDX_IMPORT
38
+ } else {
39
+ mdxComponentsImport = MDX_IMPORT
40
+ }
41
+ return mdxComponentsImport
42
+ }
@@ -1,7 +1,7 @@
1
1
  const stylusToCssLoader = require('cssxjs/loaders/stylusToCssLoader')
2
2
  const cssToReactNativeLoader = require('cssxjs/loaders/cssToReactNativeLoader')
3
3
  const mdxExamplesLoader = require('./lib/mdxExamplesLoader')
4
- const getMDXLoader = require('./lib/getMDXLoader')
4
+ const mdxLoader = require('./lib/mdxLoader')
5
5
  const callLoader = require('./lib/callLoader')
6
6
  const asyncSvgLoader = require('./lib/asyncSvgLoader')
7
7
 
@@ -20,7 +20,6 @@ module.exports.transform = async function startupjsMetroBabelTransform ({
20
20
  } else if (/\.svg$/.test(filename)) {
21
21
  src = await callLoader(asyncSvgLoader, src, filename)
22
22
  } else if (/\.mdx?$/.test(filename)) {
23
- const mdxLoader = await getMDXLoader()
24
23
  src = callLoader(mdxExamplesLoader, src, filename)
25
24
  src = callLoader(mdxLoader, src, filename)
26
25
  }
package/metro-config.js CHANGED
@@ -48,7 +48,12 @@ exports.getDefaultConfig = function getDefaultConfig (projectRoot, {
48
48
  }
49
49
 
50
50
  function isBuild () {
51
- return process.env.IS_BUILD || process.env.CI || process.env.EAS_BUILD
51
+ return (
52
+ process.env.IS_BUILD ||
53
+ process.env.CI ||
54
+ process.env.EAS_BUILD ||
55
+ (process.env.NODE_ENV === 'production' && !process.env.FORCE_SERVER)
56
+ )
52
57
  }
53
58
 
54
59
  function addServer (config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startupjs/bundler",
3
- "version": "0.60.0-canary.7",
3
+ "version": "0.61.0",
4
4
  "description": "Opinionated scripts and configs to develop a react-native-web project",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -17,21 +17,21 @@
17
17
  "dependencies": {
18
18
  "@babel/core": "^7.9.0",
19
19
  "@babel/plugin-syntax-jsx": "^7.0.0",
20
- "@mdx-js/mdx": "^2.3.0",
21
- "@startupjs/babel-plugin-eliminator": "^0.60.0-canary.7",
22
- "@startupjs/babel-plugin-startupjs-plugins": "^0.60.0-canary.7",
23
- "@startupjs/server": "^0.60.0-canary.7",
20
+ "@mdx-js/mdx": "^3.0.0",
21
+ "@startupjs/babel-plugin-eliminator": "^0.61.0",
22
+ "@startupjs/babel-plugin-startupjs-plugins": "^0.61.0",
23
+ "@startupjs/server": "^0.61.0",
24
24
  "@svgr/core": "^8.1.0",
25
25
  "@svgr/plugin-jsx": "^8.1.0",
26
26
  "@svgr/plugin-svgo": "^8.1.0",
27
- "babel-preset-startupjs": "^0.60.0-canary.7",
27
+ "babel-preset-startupjs": "^0.61.0",
28
28
  "connect": "^3.7.0",
29
29
  "lodash": "^4.17.20",
30
- "remark-gfm": "^1.0.0"
30
+ "remark-gfm": "4.0.1"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "cssxjs": "*",
34
34
  "react-native-svg": "*"
35
35
  },
36
- "gitHead": "68c5c8e9757e263133c36a24f46ba35efc9b87b8"
36
+ "gitHead": "a891da7cd48b032bdcfd8164c1466e1eef7ed780"
37
37
  }
@@ -1,23 +0,0 @@
1
- const DEFAULT_MDX_RENDERER = `
2
- import { mdx } from '@mdx-js/react'
3
- `
4
- const remarkGfm = require('remark-gfm')
5
-
6
- module.exports = async function getMDXLoader () {
7
- const mdx = await import('@mdx-js/mdx')
8
-
9
- return (source) => {
10
- source = mdx.compileSync(source, {
11
- providerImportSource: '@startupjs/mdx/client/MDXProvider/index.js',
12
- remarkPlugins: [remarkGfm]
13
- })
14
- source = DEFAULT_MDX_RENDERER + '\n' + source
15
- // To make mdx works, we should remove somehow the \n character child
16
- // from the children of MDXContent in the output source.
17
- // MDX v2 has made some changes in how it handles newlines and whitespace
18
- // compared to MDX v1. In MDX v1 newline are not inclided in the output,
19
- // but in MDX v2 it included.
20
- // console.log(source)
21
- return source
22
- }
23
- }
@@ -1,27 +0,0 @@
1
- // Only used for React Native
2
- const babel = require('@babel/core')
3
-
4
- module.exports = function startupjsLoader (source) {
5
- const filename = this.resourcePath
6
- const platform = this.query.platform
7
-
8
- // There is a bug in metro when BABEL_ENV is a string "undefined".
9
- // We have to workaround it and use NODE_ENV.
10
- const env = (process.env.BABEL_ENV !== 'undefined' && process.env.BABEL_ENV) || process.env.NODE_ENV
11
-
12
- return babel.transformSync(source, {
13
- filename,
14
- babelrc: false,
15
- configFile: false,
16
- presets: [
17
- [require('babel-preset-startupjs'), {
18
- // in Program: state.file.opts.caller.platform when used in metro
19
- // when used in metro - state.file.opts.caller.bundler === 'metro'
20
- platform,
21
- // in Program: state.file.opts.envName when used in metro
22
- env
23
- }],
24
- [require('cssxjs/babel'), { platform }]
25
- ]
26
- }).code
27
- }