@startupjs/bundler 0.60.0-canary.2 → 0.60.0-canary.25
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.
- package/lib/mdxLoader.js +42 -0
- package/metro-babel-transformer.js +1 -2
- package/metro-config.js +18 -5
- package/package.json +8 -8
- package/lib/getMDXLoader.js +0 -23
- package/lib/startupjsLoader.js +0 -27
package/lib/mdxLoader.js
ADDED
|
@@ -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
|
|
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
|
|
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) {
|
|
@@ -150,9 +155,15 @@ function getMonorepoRootPackageJson (projectRoot) {
|
|
|
150
155
|
|
|
151
156
|
function _checkStartupjsBabel (projectRoot) {
|
|
152
157
|
const babelConfigPath = join(projectRoot, 'babel.config.cjs')
|
|
153
|
-
if (!existsSync(babelConfigPath))
|
|
158
|
+
if (!existsSync(babelConfigPath)) {
|
|
159
|
+
console.error('ERROR:', ERRORS.missingBabelConfig)
|
|
160
|
+
throw Error(ERRORS.missingBabelConfig)
|
|
161
|
+
}
|
|
154
162
|
const babelConfig = readFileSync(join(projectRoot, 'babel.config.cjs'), 'utf8')
|
|
155
|
-
if (!babelConfig.includes('startupjs/babel'))
|
|
163
|
+
if (!babelConfig.includes('startupjs/babel')) {
|
|
164
|
+
console.error('ERROR:', ERRORS.noStartupjsBabelPreset)
|
|
165
|
+
throw Error(ERRORS.noStartupjsBabelPreset)
|
|
166
|
+
}
|
|
156
167
|
}
|
|
157
168
|
|
|
158
169
|
const ERRORS = {
|
|
@@ -161,14 +172,16 @@ const ERRORS = {
|
|
|
161
172
|
Please create babel.config.cjs following the instructions from Expo (or pure React Native) documentation,
|
|
162
173
|
and add 'startupjs/babel' as the LAST item in the 'presets' array.
|
|
163
174
|
|
|
164
|
-
To ignore this error
|
|
175
|
+
To ignore this error (if you want to use a custom babel preset to transform startupjs code),
|
|
176
|
+
you can pass the option 'checkStartupjsBabel: false'
|
|
165
177
|
when calling 'getDefaultConfig(projectRoot, options)' from 'metro.config.cjs'.
|
|
166
178
|
`,
|
|
167
179
|
noStartupjsBabelPreset: `
|
|
168
180
|
Your babel.config.cjs is missing 'startupjs/babel' preset.
|
|
169
181
|
Please add 'startupjs/babel' as the LAST item in the 'presets' array of your babel.config.cjs.
|
|
170
182
|
|
|
171
|
-
To ignore this error
|
|
183
|
+
To ignore this error (if you want to use a custom babel preset to transform startupjs code),
|
|
184
|
+
you can pass the option 'checkStartupjsBabel: false'
|
|
172
185
|
when calling 'getDefaultConfig(projectRoot, options)' from 'metro.config.cjs'.
|
|
173
186
|
`
|
|
174
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startupjs/bundler",
|
|
3
|
-
"version": "0.60.0-canary.
|
|
3
|
+
"version": "0.60.0-canary.25",
|
|
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": "^
|
|
21
|
-
"@startupjs/babel-plugin-eliminator": "^0.60.0-canary.
|
|
22
|
-
"@startupjs/babel-plugin-startupjs-plugins": "^0.60.0-canary.
|
|
23
|
-
"@startupjs/server": "^0.60.0-canary.
|
|
20
|
+
"@mdx-js/mdx": "^3.0.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",
|
|
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.
|
|
27
|
+
"babel-preset-startupjs": "^0.60.0-canary.18",
|
|
28
28
|
"connect": "^3.7.0",
|
|
29
29
|
"lodash": "^4.17.20",
|
|
30
|
-
"remark-gfm": "
|
|
30
|
+
"remark-gfm": "4.0.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"cssxjs": "*",
|
|
34
34
|
"react-native-svg": "*"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "ba95fc7ae8c34cf70de204049501e47963824e43"
|
|
37
37
|
}
|
package/lib/getMDXLoader.js
DELETED
|
@@ -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
|
-
}
|
package/lib/startupjsLoader.js
DELETED
|
@@ -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
|
-
}
|