@startupjs/bundler 0.55.4 → 0.55.8

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,57 @@
1
+ const babel = require('@babel/core')
2
+
3
+ const PLUGIN_KEYS = ['name', 'for']
4
+ const ALL_ENVS = ['client', 'isomorphic', 'server', 'build']
5
+
6
+ module.exports = function eliminatorLoader (source) {
7
+ const envs = this.query.envs
8
+ if (!envs) throw Error("getEliminatorLoader: envs not provided (for example ['client', 'isomorphic'])")
9
+ const filename = this.resourcePath
10
+
11
+ let code = source
12
+
13
+ // first we need to transform pug to jsx
14
+ // so that eliminator doesn't think that there are unused variables
15
+ code = babel.transformSync(code, {
16
+ filename,
17
+ babelrc: false,
18
+ configFile: false,
19
+ plugins: [
20
+ require('@babel/plugin-syntax-jsx'),
21
+ [require('babel-plugin-transform-react-pug'), {
22
+ classAttribute: 'styleName'
23
+ }],
24
+ [require('@startupjs/babel-plugin-react-pug-classnames'), {
25
+ classAttribute: 'styleName'
26
+ }],
27
+ require('@startupjs/babel-plugin-startupjs-plugins')
28
+ ]
29
+ }).code
30
+
31
+ // then we run the actual eliminator to remove env-specific stuff
32
+ code = babel.transformSync(code, {
33
+ filename,
34
+ babelrc: false,
35
+ configFile: false,
36
+ plugins: [
37
+ require('@babel/plugin-syntax-jsx'),
38
+ [require('@startupjs/babel-plugin-eliminator'), {
39
+ keepObjectKeysOfFunction: {
40
+ createProject: {
41
+ magicImports: ['startupjs/registry', 'startupjs/registry.js', '@startupjs/registry', '@startupjs/registry.js'],
42
+ targetObjectJsonPath: '$.plugins.*',
43
+ ensureOnlyKeys: ['client', 'isomorphic', 'server', 'build'],
44
+ keepKeys: envs
45
+ },
46
+ createPlugin: {
47
+ magicImports: ['startupjs/registry', 'startupjs/registry.js', '@startupjs/registry', '@startupjs/registry.js'],
48
+ ensureOnlyKeys: [...PLUGIN_KEYS, ...ALL_ENVS],
49
+ keepKeys: [...PLUGIN_KEYS, ...envs]
50
+ }
51
+ }
52
+ }]
53
+ ]
54
+ }).code
55
+
56
+ return code
57
+ }
@@ -7,6 +7,7 @@ const stylusToCssLoader = require('./stylusToCssLoader')
7
7
  const cssToReactNativeLoader = require('./cssToReactNativeLoader')
8
8
  const mdxExamplesLoader = require('./mdxExamplesLoader')
9
9
  const getMDXLoader = require('./getMDXLoader')
10
+ const eliminatorLoader = require('./eliminatorLoader')
10
11
  const callLoader = require('./callLoader')
11
12
 
12
13
  module.exports.transform = async function ({ src, filename, options = {} }) {
@@ -22,7 +23,13 @@ module.exports.transform = async function ({ src, filename, options = {} }) {
22
23
  return upstreamTransformer.transform({ src, filename, options })
23
24
  } else if (/\.svg$/.test(filename)) {
24
25
  return svgTransformer.transform({ src, filename, options })
26
+ } else if (/(?:[./]plugin\.[mc]?[jt]sx?|startupjs\.config\.js)$/.test(filename)) {
27
+ src = callLoader(eliminatorLoader, src, filename, { envs: ['client', 'isomorphic'] })
28
+ return upstreamTransformer.transform({ src, filename, options })
25
29
  } else if (/\.[cm]?jsx?$/.test(filename) && /['"]startupjs['"]/.test(src)) {
30
+ // TODO: This particular check and transform is probably not needed anymore since default one
31
+ // will handle all .js files anyways no matter whether 'startupjs' library
32
+ // is used inside or not.
26
33
  return upstreamTransformer.transform({ src, filename, options })
27
34
  } else if (/\.mdx?$/.test(filename)) {
28
35
  const mdxLoader = await getMDXLoader()
@@ -0,0 +1,6 @@
1
+ const yaml = require('js-yaml')
2
+
3
+ module.exports = function mdxExamplesLoader (source) {
4
+ const yamlData = yaml.load(source)
5
+ return `export default ${JSON.stringify(yamlData)};`
6
+ }
package/nodeLoader.mjs ADDED
@@ -0,0 +1,49 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import { fileURLToPath } from 'node:url'
3
+ import callLoader from './lib/callLoader.js'
4
+ import yamlLoader from './lib/yamlLoader.js'
5
+ import eliminatorLoader from './lib/eliminatorLoader.js'
6
+
7
+ export function resolve (specifier, context, nextResolve) {
8
+ const { parentURL = null } = context
9
+
10
+ // Handling YAML files
11
+ if (specifier.endsWith('.yaml')) {
12
+ return {
13
+ shortCircuit: true,
14
+ url: new URL(specifier, parentURL).href
15
+ }
16
+ }
17
+
18
+ // Let Node.js handle all other specifiers.
19
+ return nextResolve(specifier, context, nextResolve)
20
+ }
21
+
22
+ export async function load (url, context, nextLoad) {
23
+ // If it's a YAML file, read it, parse it and return it as JavaScript source code
24
+ if (/\.yaml$/.test(url)) {
25
+ const filePath = fileURLToPath(url)
26
+ let source = await readFile(filePath, 'utf8')
27
+ source = callLoader(yamlLoader, source, filePath)
28
+ return {
29
+ format: 'module',
30
+ shortCircuit: true,
31
+ source
32
+ }
33
+ }
34
+
35
+ // process code elimination of other envs for *.plugin.js and startupjs.config.js
36
+ if (/(?:[./]plugin\.[mc]?[jt]sx?|startupjs\.config\.js)$/.test(url)) {
37
+ const filePath = fileURLToPath(url)
38
+ let source = await readFile(filePath, 'utf8')
39
+ source = callLoader(eliminatorLoader, source, filePath, { envs: ['server', 'isomorphic'] })
40
+ return {
41
+ format: 'module',
42
+ shortCircuit: true,
43
+ source
44
+ }
45
+ }
46
+
47
+ // Let Node.js handle all other URLs.
48
+ return nextLoad(url, context, nextLoad)
49
+ }
@@ -0,0 +1,5 @@
1
+ // Register the node loader which actually processes custom file extensions
2
+ // and pre-processes .js source code
3
+ import { register } from 'node:module'
4
+
5
+ register('./nodeLoader.mjs', import.meta.url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startupjs/bundler",
3
- "version": "0.55.4",
3
+ "version": "0.55.8",
4
4
  "description": "Opinionated scripts and configs to develop a react-native-web project",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -15,18 +15,23 @@
15
15
  },
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
+ "@babel/core": "^7.9.0",
19
+ "@babel/plugin-syntax-jsx": "^7.0.0",
18
20
  "@babel/polyfill": "^7.8.0",
19
21
  "@mdx-js/loader": "^2.3.0",
20
22
  "@mdx-js/mdx": "^2.3.0",
21
23
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
22
24
  "@startupjs/babel-plugin-react-css-modules": "^6.5.4-1",
25
+ "@startupjs/babel-plugin-react-pug-classnames": "^0.55.8",
26
+ "@startupjs/babel-plugin-startupjs-plugins": "^0.55.8",
23
27
  "@startupjs/css-to-react-native-transform": "^1.9.0-2",
24
- "@startupjs/plugin": "^0.55.1",
28
+ "@startupjs/plugin": "^0.55.8",
25
29
  "@svgr/webpack": "~7.0.0",
26
30
  "assets-webpack-plugin": "^7.1.1",
27
31
  "autoprefixer": "^10.4.0",
28
32
  "babel-loader": "^8.2.3",
29
- "babel-preset-startupjs": "^0.55.4",
33
+ "babel-plugin-transform-react-pug": "^7.0.1",
34
+ "babel-preset-startupjs": "^0.55.8",
30
35
  "css-loader": "^6.5.0",
31
36
  "css-minimizer-webpack-plugin": "^5.0.0",
32
37
  "file-loader": "^6.2.0",
@@ -50,5 +55,5 @@
50
55
  "peerDependencies": {
51
56
  "react-native-svg": "*"
52
57
  },
53
- "gitHead": "6ad2cc77b50d4e45abc6383e135689e0c313af3b"
58
+ "gitHead": "75f57690644950055f8c8cb9afa265eb44f594fd"
54
59
  }
@@ -205,22 +205,35 @@ module.exports = function getConfig (env, {
205
205
  rules: [
206
206
  {
207
207
  test: /\.[mc]?[jt]sx?$/,
208
- resolve: {
209
- fullySpecified: false
210
- },
211
- exclude: /node_modules/,
212
- use: [
213
- { loader: 'babel-loader' }
214
- ]
215
- },
216
- {
217
- test: /\.[mc]?[jt]sx?$/,
218
- resolve: {
219
- fullySpecified: false
220
- },
221
- include: forceCompileModulesExpression,
222
- use: [
223
- { loader: 'babel-loader' }
208
+ oneOf: [
209
+ {
210
+ // process code elimination of other envs for *.plugin.js and startupjs.config.js
211
+ test: /(?:[./]plugin\.[mc]?[jt]sx?|startupjs\.config\.js)$/,
212
+ resolve: { fullySpecified: false },
213
+ use: [
214
+ { loader: 'babel-loader' },
215
+ {
216
+ loader: require.resolve('./lib/eliminatorLoader.js'),
217
+ options: {
218
+ envs: ['client', 'isomorphic']
219
+ }
220
+ }
221
+ ]
222
+ },
223
+ {
224
+ exclude: /node_modules/,
225
+ resolve: { fullySpecified: false },
226
+ use: [
227
+ { loader: 'babel-loader' }
228
+ ]
229
+ },
230
+ {
231
+ include: forceCompileModulesExpression,
232
+ resolve: { fullySpecified: false },
233
+ use: [
234
+ { loader: 'babel-loader' }
235
+ ]
236
+ }
224
237
  ]
225
238
  },
226
239
  {