@startupjs/bundler 0.56.0-alpha.4 → 0.56.0-alpha.40

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.
@@ -2,9 +2,9 @@
2
2
  const babel = require('@babel/core')
3
3
  const { isStartupjsPluginEcosystemFile, CONFIG_FILENAME_REGEX } = require('./utils')
4
4
 
5
- const PLUGIN_KEYS = ['name', 'for']
5
+ const PLUGIN_KEYS = ['name', 'for', 'order', 'enabled']
6
6
  const PROJECT_KEYS = ['plugins', 'modules']
7
- const ALL_ENVS = ['client', 'isomorphic', 'server', 'build']
7
+ const ALL_ENVS = ['features', 'isomorphic', 'client', 'server', 'build']
8
8
  const MAGIC_IMPORTS = ['startupjs/registry', '@startupjs/registry']
9
9
 
10
10
  module.exports = function eliminatorLoader (source) {
@@ -14,7 +14,9 @@ module.exports = function eliminatorLoader (source) {
14
14
  if (!(isStartupjsPluginEcosystemFile(filename))) return source
15
15
 
16
16
  const envs = this.query.envs
17
- if (!envs) throw Error("eliminatorLoader: envs not provided (for example ['client', 'isomorphic'])")
17
+ if (!envs) throw Error("eliminatorLoader: envs not provided (for example ['features', 'isomorphic', 'client'])")
18
+
19
+ const useRequireContext = this.query.useRequireContext
18
20
 
19
21
  let code = source
20
22
 
@@ -37,7 +39,7 @@ module.exports = function eliminatorLoader (source) {
37
39
  }],
38
40
  // traverse "exports" of package.json and all dependencies to find all startupjs plugins
39
41
  // and automatically import them in the main startupjs.config.js file
40
- require('@startupjs/babel-plugin-startupjs-plugins')
42
+ [require('@startupjs/babel-plugin-startupjs-plugins'), { useRequireContext }]
41
43
  ]
42
44
  }).code
43
45
 
@@ -32,7 +32,10 @@ module.exports.transform = async function startupjsMetroBabelTransform ({
32
32
 
33
33
  // js transformations
34
34
  if (/\.[mc]?[jt]sx?$/.test(filename)) {
35
- src = callLoader(eliminatorLoader, src, filename, { envs: ['client', 'isomorphic'] })
35
+ src = callLoader(eliminatorLoader, src, filename, {
36
+ envs: ['features', 'isomorphic', 'client'],
37
+ useRequireContext: true
38
+ })
36
39
  }
37
40
  if ((/\.mdx?$/.test(filename) || /\.[mc]?[jt]sx?$/.test(filename)) && /['"](?:startupjs|@env)['"]/.test(src)) {
38
41
  src = callLoader(startupjsLoader, src, filename, { platform })
package/metro-config.js CHANGED
@@ -1,39 +1,75 @@
1
+ const { getFeatures } = require('@startupjs/babel-plugin-startupjs-plugins/loader')
1
2
  const connect = require('connect')
3
+ const { readFileSync } = require('fs')
4
+ const { join, resolve } = require('path')
2
5
 
3
6
  // To pass existing config for modification, pass it as 'upstreamConfig' in options:
4
7
  // config = getDefaultConfig(__dirname, { upstreamConfig })
5
8
  exports.getDefaultConfig = function getDefaultConfig (projectRoot, { upstreamConfig } = {}) {
9
+ let packageJson = {}
10
+ try {
11
+ packageJson = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'))
12
+ } catch (err) {}
13
+ const features = getFeatures(projectRoot)
6
14
  upstreamConfig ??= getUpstreamConfig(projectRoot)
7
15
  const isExpo = checkIfExpo(upstreamConfig)
8
- return {
16
+
17
+ const config = {
9
18
  ...upstreamConfig,
10
19
  transformer: {
11
20
  ...upstreamConfig.transformer,
12
- babelTransformerPath: require.resolve('./metro-babel-transformer.js')
21
+ babelTransformerPath: require.resolve('./metro-babel-transformer.js'),
22
+ unstable_allowRequireContext: true
13
23
  },
14
24
  resolver: {
15
25
  ...upstreamConfig.resolver,
16
26
  assetExts: upstreamConfig.resolver.assetExts.filter(ext => ext !== 'svg'),
17
- sourceExts: Array.from(new Set([
27
+ sourceExts: [...new Set([
18
28
  ...(isExpo ? ['expo.ts', 'expo.tsx', 'expo.js', 'expo.jsx', 'expo.mjs', 'expo.cjs'] : []),
19
29
  ...(upstreamConfig.resolver.sourceExts || []),
20
30
  ...['mjs', 'cjs', 'md', 'mdx', 'css', 'styl', 'svg']
21
- ])),
31
+ ])],
22
32
  unstable_enablePackageExports: true
23
- },
24
- server: {
25
- ...upstreamConfig.server,
26
- // TODO: implement a simple parsing of startupjs.config.js
27
- // to figure out whether we need to load 'server' and 'isomorphic'
28
- // envs or only the 'build' one.
29
- // If $.isomorphic.server is turned off then we don't need the enhanceMiddleware at all
30
- enhanceMiddleware: metroMiddleware => {
31
- return connect()
32
- .use(metroMiddleware)
33
- .use(getStartupjsMiddleware())
34
- }
35
33
  }
36
34
  }
35
+
36
+ // Add startupjs server middleware
37
+ if (features.enableServer) addServer(config)
38
+
39
+ // Support Yarn's `resolutions` field from doing `yarn link`
40
+ if (packageJson.resolutions) addYarnLink(config, { packageJson, projectRoot })
41
+
42
+ return config
43
+ }
44
+
45
+ function addServer (config) {
46
+ config.server ??= {}
47
+ config.server.enhanceMiddleware = metroMiddleware =>
48
+ connect()
49
+ .use(metroMiddleware)
50
+ .use(getStartupjsMiddleware())
51
+ }
52
+
53
+ function addYarnLink (config, { packageJson, projectRoot }) {
54
+ // `yarn link` adds paths with a prefix 'portal:' so we handle only those
55
+ const linkPaths = Object.values(packageJson.resolutions)
56
+ .filter(path => path.startsWith('portal:'))
57
+ .map(path => path.replace(/^portal:/, ''))
58
+ // paths might be relative to the project root
59
+ .map(path => resolve(projectRoot, path))
60
+ if (linkPaths.length === 0) return
61
+
62
+ config.watchFolders = [...new Set([
63
+ ...(config.watchFolders || []),
64
+ projectRoot,
65
+ ...linkPaths
66
+ ])]
67
+ config.resolver.nodeModulesPaths = [...new Set([
68
+ ...(config.resolver.nodeModulesPaths || []),
69
+ // this is supposed to be the default behavior of Metro, but after changing
70
+ // the watchFolders it stops working for some reason
71
+ resolve(projectRoot, 'node_modules')
72
+ ])]
37
73
  }
38
74
 
39
75
  function getUpstreamConfig (projectRoot) {
@@ -69,9 +105,6 @@ function checkIfExpo (upstreamConfig) {
69
105
  function getStartupjsMiddleware () {
70
106
  const middlewarePromise = (async () => {
71
107
  await import('./nodeRegister.mjs')
72
- await import('@startupjs/registry/loadStartupjsConfig.auto')
73
- const { ROOT_MODULE: MODULE } = await import('@startupjs/registry')
74
- if (!MODULE.options.server) return
75
108
  const { createMiddleware } = await import('@startupjs/server')
76
109
  return (await createMiddleware()).middleware
77
110
  })()
package/nodeLoader.mjs CHANGED
@@ -37,7 +37,7 @@ export async function load (url, context, nextLoad) {
37
37
  if (isStartupjsPluginEcosystemFile(url)) {
38
38
  const filePath = fileURLToPath(url)
39
39
  let source = await readFile(filePath, 'utf8')
40
- source = callLoader(eliminatorLoader, source, filePath, { envs: ['server', 'isomorphic'] })
40
+ source = callLoader(eliminatorLoader, source, filePath, { envs: ['features', 'isomorphic', 'server'] })
41
41
  return {
42
42
  format: 'module',
43
43
  shortCircuit: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startupjs/bundler",
3
- "version": "0.56.0-alpha.4",
3
+ "version": "0.56.0-alpha.40",
4
4
  "description": "Opinionated scripts and configs to develop a react-native-web project",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -24,12 +24,11 @@
24
24
  "@startupjs/babel-plugin-eliminator": "^0.56.0-alpha.1",
25
25
  "@startupjs/babel-plugin-react-css-modules": "^6.5.4-1",
26
26
  "@startupjs/babel-plugin-react-pug-classnames": "^0.56.0-alpha.0",
27
- "@startupjs/babel-plugin-startupjs-plugins": "^0.56.0-alpha.1",
27
+ "@startupjs/babel-plugin-startupjs-plugins": "^0.56.0-alpha.40",
28
28
  "@startupjs/babel-plugin-transform-react-pug": "^7.0.1-0",
29
29
  "@startupjs/css-to-react-native-transform": "^1.9.0-2",
30
30
  "@startupjs/plugin": "^0.56.0-alpha.0",
31
- "@startupjs/registry": "^0.56.0-alpha.2",
32
- "@startupjs/server": "^0.56.0-alpha.3",
31
+ "@startupjs/server": "^0.56.0-alpha.40",
33
32
  "@svgr/core": "^8.1.0",
34
33
  "@svgr/plugin-jsx": "^8.1.0",
35
34
  "@svgr/plugin-svgo": "^8.1.0",
@@ -37,7 +36,7 @@
37
36
  "assets-webpack-plugin": "^7.1.1",
38
37
  "autoprefixer": "^10.4.0",
39
38
  "babel-loader": "^8.2.3",
40
- "babel-preset-startupjs": "^0.56.0-alpha.4",
39
+ "babel-preset-startupjs": "^0.56.0-alpha.40",
41
40
  "connect": "^3.7.0",
42
41
  "css-loader": "^6.5.0",
43
42
  "css-minimizer-webpack-plugin": "^5.0.0",
@@ -61,5 +60,5 @@
61
60
  "peerDependencies": {
62
61
  "react-native-svg": "*"
63
62
  },
64
- "gitHead": "c0ecc933d28d52cf2e269b390f692ad87216ec23"
63
+ "gitHead": "5cc104689190f938f95fffefa3563555a2506778"
65
64
  }