@s-ui/bundler 9.54.0-typescript-support.1 → 9.54.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.
@@ -57,7 +57,7 @@ if (!module.parent) {
57
57
  const start = async ({config = webpackConfig, packagesToLink = program.opts().linkPackage || []} = {}) => {
58
58
  clearConsole()
59
59
  // Warn and crash if required files are missing
60
- if (!checkRequiredFiles([path.join(config.context, 'index.html')])) {
60
+ if (!checkRequiredFiles([path.join(config.context, 'index.html'), path.join(config.context, 'app.js')])) {
61
61
  log.error(`✖ Required files are missing, create and index.html and app.js inside your src folder.`)
62
62
  process.exit(1)
63
63
  }
@@ -38,6 +38,10 @@ module.exports = config => ({
38
38
  {
39
39
  directory: 'public',
40
40
  watch: getWatchOptions(config)
41
+ },
42
+ {
43
+ directory: 'resources',
44
+ watch: getWatchOptions(config)
41
45
  }
42
46
  ],
43
47
  hot: true,
@@ -43,7 +43,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
43
43
  * if neccesary
44
44
  */
45
45
  const linkLoader = {
46
- test: /\.(jsx?|tsx?|scss)$/,
46
+ test: /\.(jsx?|scss)$/,
47
47
  enforce: 'pre', // this will ensure is execute before transformations
48
48
  use: {
49
49
  loader: require.resolve('./LinkLoader'),
package/package.json CHANGED
@@ -1 +1,57 @@
1
- {"name":"@s-ui/bundler","version":"9.54.0-typescript-support.1","description":"Config-free bundler for ES6 React apps.","bin":{"sui-bundler":"./bin/sui-bundler.js"},"main":"./bin/sui-bundler.js","scripts":{"postinstall":"node ./scripts/postinstall.js","test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"MIT","repository":{"type":"git","url":"git+https://github.com/SUI-Components/sui.git"},"bugs":{"url":"https://github.com/SUI-Components/sui/issues"},"homepage":"https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme","dependencies":{"@babel/core":"7.21.8","@s-ui/compiler-config":"1","@s-ui/helpers":"1","@s-ui/sass-loader":"1","@swc/core":"1.3.14","@swc/helpers":"0.4.12","address":"1.2.2","autoprefixer":"10.4.8","babel-loader":"8.2.5","babel-preset-sui":"3","buffer":"6.0.3","commander":"8.3.0","css-loader":"6.7.1","css-minimizer-webpack-plugin":"4.0.0","esbuild":"0.15.5","escape-string-regexp":"4.0.0","fast-glob":"3.2.12","find-free-ports":"3.0.0","html-webpack-plugin":"5.5.0","https-browserify":"1.0.0","mini-css-extract-plugin":"2.7.7","postcss":"8.4.31","postcss-loader":"7.3.4","process":"0.11.10","sass":"1.54.5","stream-http":"3.2.0","strip-ansi":"6.0.1","style-loader":"3.3.1","swc-loader":"0.2.1","url":"0.11.0","webpack":"5.82.1","webpack-dev-server":"4.10.0","webpack-manifest-plugin":"5.0.0","webpack-node-externals":"3.0.0","@pmmmwh/react-refresh-webpack-plugin":"0.5.10","react-refresh":"0.14.0"}}
1
+ {
2
+ "name": "@s-ui/bundler",
3
+ "version": "9.54.0",
4
+ "description": "Config-free bundler for ES6 React apps.",
5
+ "bin": {
6
+ "sui-bundler": "./bin/sui-bundler.js"
7
+ },
8
+ "main": "./bin/sui-bundler.js",
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/SUI-Components/sui.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/SUI-Components/sui/issues"
21
+ },
22
+ "homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme",
23
+ "dependencies": {
24
+ "@babel/core": "7.18.10",
25
+ "@s-ui/helpers": "1",
26
+ "@s-ui/sass-loader": "1",
27
+ "address": "1.2.2",
28
+ "autoprefixer": "10.4.8",
29
+ "babel-loader": "8.2.5",
30
+ "babel-preset-sui": "3",
31
+ "buffer": "6.0.3",
32
+ "commander": "8.3.0",
33
+ "css-loader": "6.7.1",
34
+ "css-minimizer-webpack-plugin": "4.0.0",
35
+ "esbuild": "0.15.5",
36
+ "escape-string-regexp": "4.0.0",
37
+ "fast-glob": "3.2.11",
38
+ "find-free-ports": "3.0.0",
39
+ "html-webpack-plugin": "5.5.0",
40
+ "https-browserify": "1.0.0",
41
+ "mini-css-extract-plugin": "2.7.7",
42
+ "postcss": "8.4.31",
43
+ "postcss-loader": "7.3.4",
44
+ "process": "0.11.10",
45
+ "sass": "1.54.5",
46
+ "stream-http": "3.2.0",
47
+ "strip-ansi": "6.0.1",
48
+ "style-loader": "3.3.1",
49
+ "url": "0.11.0",
50
+ "webpack": "5.82.1",
51
+ "webpack-dev-server": "4.10.0",
52
+ "webpack-manifest-plugin": "5.0.0",
53
+ "webpack-node-externals": "3.0.0",
54
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
55
+ "react-refresh": "0.14.0"
56
+ }
57
+ }
package/shared/define.js CHANGED
@@ -6,23 +6,9 @@ if (process.platform === 'win32') {
6
6
  process.env.PWD = process.cwd()
7
7
  }
8
8
 
9
- const {MAGIC_STRINGS = '{}'} = process.env
10
-
11
- let magic
12
- try {
13
- magic = JSON.parse(MAGIC_STRINGS)
14
- } catch (err) {
15
- magic = {}
16
- }
17
-
18
- module.exports = (vars = {}) => {
19
- const definitions = {
9
+ module.exports = (vars = {}) =>
10
+ new webpack.DefinePlugin({
20
11
  __DEV__: false,
21
12
  __BASE_DIR__: JSON.stringify(process.env.PWD),
22
- __MOCKS_API_PATH__: JSON.stringify(process.env.MOCKS_API_PATH || process.env.PWD + '/mocks/routes'),
23
- ...vars,
24
- ...Object.fromEntries(Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)]))
25
- }
26
-
27
- return new webpack.DefinePlugin(definitions)
28
- }
13
+ ...vars
14
+ })
package/shared/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const {config} = require('./config.js')
2
2
 
3
- exports.MAIN_ENTRY_POINT = './app'
3
+ exports.MAIN_ENTRY_POINT = './app.js'
4
4
  exports.config = config
5
5
 
6
6
  exports.cleanList = list => list.filter(Boolean)
@@ -0,0 +1,33 @@
1
+ const path = require('path')
2
+ const {config} = require('./index.js')
3
+
4
+ const EXCLUDED_FOLDERS_REGEXP = new RegExp(
5
+ `node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
6
+ )
7
+
8
+ module.exports = ({isServer = false, isDevelopment = false, supportLegacyBrowsers = true} = {}) => ({
9
+ test: /\.jsx?$/,
10
+ exclude: EXCLUDED_FOLDERS_REGEXP,
11
+ use: [
12
+ {
13
+ loader: require.resolve('babel-loader'),
14
+ options: {
15
+ cacheDirectory: true,
16
+ cacheCompression: false,
17
+ babelrc: false,
18
+ compact: true,
19
+ plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
20
+ presets: [
21
+ [
22
+ require.resolve('babel-preset-sui'),
23
+ {
24
+ isServer,
25
+ isModern: !supportLegacyBrowsers,
26
+ targets: config.targets
27
+ }
28
+ ]
29
+ ]
30
+ }
31
+ }
32
+ ]
33
+ })
@@ -1,6 +1,5 @@
1
1
  const path = require('path')
2
2
  const {config} = require('./config.js')
3
- const fs = require('fs')
4
3
 
5
4
  const {PWD} = process.env
6
5
 
@@ -10,33 +9,16 @@ const {PWD} = process.env
10
9
  * So you should use the exact same imported file from node_modules, and the linked package
11
10
  * would try to use another different from its own node_modules. This will prevent that.
12
11
  */
13
- const defaultPackagesToAlias = [
14
- 'react',
15
- 'react-dom',
16
- 'react-router-dom',
17
- 'react/jsx-dev-runtime',
18
- 'react/jsx-runtime',
19
- '@s-ui/pde',
20
- '@s-ui/react-context',
21
- '@s-ui/react-router'
22
- ]
12
+ const defaultPackagesToAlias = ['react', 'react-router-dom', '@s-ui/pde', '@s-ui/react-context', '@s-ui/react-router']
23
13
 
24
- const createAliasPath = pkgName => {
25
- const PWDNodeModules = path.join(PWD, './node_modules')
26
- if (fs.existsSync(PWDNodeModules)) return path.resolve(path.join(PWDNodeModules, pkgName))
14
+ const createAliasPath = pkgName => path.resolve(path.join(PWD, `./node_modules/${pkgName}`))
27
15
 
28
- try {
29
- return require.resolve(pkgName).replace(/\/index\.js$/, '')
30
- } catch (e) {
31
- return ''
32
- }
16
+ const mustPackagesToAlias = {
17
+ 'react/jsx-dev-runtime': 'react/jsx-dev-runtime.js',
18
+ 'react/jsx-runtime': 'react/jsx-runtime.js'
33
19
  }
34
20
 
35
- const mustPackagesToAlias = {}
36
-
37
- exports.defaultAlias = Object.fromEntries(
38
- defaultPackagesToAlias.map(pkgName => [pkgName, createAliasPath(pkgName)]).filter(([, path]) => path)
39
- )
21
+ exports.defaultAlias = Object.fromEntries(defaultPackagesToAlias.map(pkgName => [pkgName, createAliasPath(pkgName)]))
40
22
 
41
23
  const aliasFromConfig = config.alias
42
24
  ? Object.entries(config.alias).reduce(
@@ -12,7 +12,7 @@ const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
12
12
  const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
13
13
 
14
14
  const {resolveLoader} = require('./shared/resolve-loader.js')
15
- const createCompilerRules = require('./shared/module-rules-compiler.js')
15
+ const createBabelRules = require('./shared/module-rules-babel.js')
16
16
 
17
17
  const outputPath = path.join(process.cwd(), 'dist')
18
18
 
@@ -42,7 +42,7 @@ const webpackConfig = {
42
42
  timers: false
43
43
  },
44
44
  modules: ['node_modules', path.resolve(process.cwd())],
45
- extensions: ['.js', '.tsx', '.ts', '.json']
45
+ extensions: ['.js', '.json']
46
46
  },
47
47
  stats: 'errors-only',
48
48
  entry: {
@@ -87,7 +87,7 @@ const webpackConfig = {
87
87
  resolveLoader,
88
88
  module: {
89
89
  rules: cleanList([
90
- createCompilerRules({supportLegacyBrowsers, isDevelopment: true}),
90
+ createBabelRules({supportLegacyBrowsers, isDevelopment: true}),
91
91
  {
92
92
  test: /(\.css|\.scss)$/,
93
93
  use: cleanList([
@@ -4,7 +4,7 @@ const {cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index.j
4
4
  const path = require('path')
5
5
  const minifyJs = require('./shared/minify-js.js')
6
6
  const definePlugin = require('./shared/define.js')
7
- const createCompilerRules = require('./shared/module-rules-compiler.js')
7
+ const createBabelRules = require('./shared/module-rules-babel.js')
8
8
  const sassRules = require('./shared/module-rules-sass.js')
9
9
  const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
10
10
  const {aliasFromConfig} = require('./shared/resolve-alias.js')
@@ -45,7 +45,7 @@ module.exports = {
45
45
  },
46
46
  plugins: cleanList([
47
47
  new webpack.ProvidePlugin({
48
- process: 'process/browser.js'
48
+ process: 'process/browser'
49
49
  }),
50
50
  new MiniCssExtractPlugin({
51
51
  filename: cssFileName,
@@ -58,6 +58,6 @@ module.exports = {
58
58
  definePlugin()
59
59
  ]),
60
60
  module: {
61
- rules: [createCompilerRules({supportLegacyBrowsers}), sassRules]
61
+ rules: [createBabelRules({supportLegacyBrowsers}), sassRules]
62
62
  }
63
63
  }
@@ -13,7 +13,7 @@ const {when, cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/i
13
13
  const {aliasFromConfig} = require('./shared/resolve-alias.js')
14
14
  const {extractComments, sourceMap, supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
15
15
  const {resolveLoader} = require('./shared/resolve-loader.js')
16
- const createCompilerRules = require('./shared/module-rules-compiler.js')
16
+ const createBabelRules = require('./shared/module-rules-babel.js')
17
17
  const sassRules = require('./shared/module-rules-sass.js')
18
18
  const definePlugin = require('./shared/define.js')
19
19
  const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
@@ -41,7 +41,7 @@ const webpackConfig = {
41
41
  context: path.resolve(CWD, 'src'),
42
42
  resolve: {
43
43
  alias: {...aliasFromConfig},
44
- extensions: ['.js', '.json', '.ts', '.tsx'],
44
+ extensions: ['.js', '.json'],
45
45
  modules: ['node_modules', path.resolve(CWD)],
46
46
  fallback: {
47
47
  assert: false,
@@ -74,7 +74,7 @@ const webpackConfig = {
74
74
  },
75
75
  plugins: cleanList([
76
76
  new webpack.ProvidePlugin({
77
- process: 'process/browser.js'
77
+ process: 'process/browser'
78
78
  }),
79
79
  new webpack.ids.HashedModuleIdsPlugin(),
80
80
  new webpack.EnvironmentPlugin(envVars(config.env)),
@@ -104,7 +104,7 @@ const webpackConfig = {
104
104
  ]),
105
105
  module: {
106
106
  rules: cleanList([
107
- createCompilerRules({supportLegacyBrowsers}),
107
+ createBabelRules({supportLegacyBrowsers}),
108
108
  sassRules,
109
109
  when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
110
110
  ])
@@ -4,7 +4,7 @@ const path = require('path')
4
4
 
5
5
  const {config, when, cleanList} = require('./shared/index.js')
6
6
  const {cacheDirectory} = require('./shared/config.js')
7
- const createCompilerRules = require('./shared/module-rules-compiler.js')
7
+ const createBabelRules = require('./shared/module-rules-babel.js')
8
8
  const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
9
9
  const {aliasFromConfig} = require('./shared/resolve-alias.js')
10
10
  const {resolveLoader} = require('./shared/resolve-loader.js')
@@ -22,7 +22,7 @@ const webpackConfig = {
22
22
  mode: isProduction ? 'production' : 'development',
23
23
  resolve: {
24
24
  alias: {...aliasFromConfig},
25
- extensions: ['.js', '.json', '.ts', '.tsx'],
25
+ extensions: ['.js', '.json'],
26
26
  modules: ['node_modules', path.resolve(process.cwd())]
27
27
  },
28
28
  entry: './server.js',
@@ -48,7 +48,7 @@ const webpackConfig = {
48
48
  resolveLoader,
49
49
  module: {
50
50
  rules: cleanList([
51
- createCompilerRules({isServer: true}),
51
+ createBabelRules({isServer: true}),
52
52
  {
53
53
  // ignore css/scss/svg require/imports files in the server
54
54
  test: /(\.svg|\.s?css)$/,
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
-
4
- const crypto = require('crypto')
5
- const fs = require('fs-extra')
6
- const path = require('path')
7
- const {writeFile} = require('@s-ui/helpers/file.js')
8
-
9
- const {INIT_CWD} = process.env
10
- const tsConfigTemplate = `\
11
- {
12
- "extends": "@s-ui/bundler/tsconfig.json",
13
- "compilerOptions": {
14
- "rootDir": "./"
15
- },
16
- "include": ["src", "domain", "components"]
17
- }`
18
-
19
- const md5 = str => crypto.createHash('md5').update(str).digest('hex')
20
- const TS_CONFIG_PATH = path.join(INIT_CWD, 'tsconfig.json')
21
- const PACKAGE_JSON_CONFIG_PATH = path.join(INIT_CWD, 'package.json')
22
-
23
- const config = require(PACKAGE_JSON_CONFIG_PATH)?.config?.['sui-bundler'] || {}
24
-
25
- const shouldGenerateTSConfig = () => {
26
- try {
27
- if (!config?.type || config?.type !== 'typescript') return false
28
-
29
- if (!fs.existsSync(TS_CONFIG_PATH)) return true
30
-
31
- const tsConfigLocal = fs.readFileSync(TS_CONFIG_PATH, {encoding: 'utf8'})
32
- return md5(tsConfigLocal) !== md5(tsConfigTemplate)
33
- } catch (err) {
34
- return true
35
- }
36
- }
37
-
38
- async function main() {
39
- console.log('🔍 [sui-bundler postinstall] Checking if tsconfig.json is up to date...')
40
- if (!shouldGenerateTSConfig()) {
41
- console.log('✅ [sui-bundler postinstall] tsconfig.json is up to date')
42
- process.exit(0)
43
- }
44
- await writeFile(TS_CONFIG_PATH, tsConfigTemplate)
45
- console.log('❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it')
46
- }
47
-
48
- main()
@@ -1,69 +0,0 @@
1
- /* eslint-disable no-console */
2
- const fs = require('fs-extra')
3
- const path = require('path')
4
- const {config} = require('./index.js')
5
- const {getSWCConfig} = require('@s-ui/compiler-config')
6
-
7
- const EXCLUDED_FOLDERS_REGEXP = new RegExp(
8
- `node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
9
- )
10
-
11
- const getTSConfig = () => {
12
- // Get TS config from the package dir.
13
- const tsConfigPath = path.join(process.cwd(), 'tsconfig.json')
14
- let tsConfig
15
-
16
- try {
17
- if (fs.existsSync(tsConfigPath)) {
18
- tsConfig = JSON.parse(fs.readFileSync(tsConfigPath, {encoding: 'utf8'}))
19
- }
20
- } catch (err) {
21
- console.error(err)
22
- }
23
-
24
- return tsConfig
25
- }
26
-
27
- module.exports = ({isServer = false, isDevelopment = false, supportLegacyBrowsers = true} = {}) => {
28
- const tsConfig = getTSConfig()
29
- // If TS config exists in root dir, set TypeScript as enabled.
30
- const isTypeScriptEnabled = Boolean(tsConfig)
31
-
32
- return isTypeScriptEnabled
33
- ? {
34
- test: /\.(js|ts)x?$/,
35
- exclude: EXCLUDED_FOLDERS_REGEXP,
36
- use: [
37
- {
38
- loader: require.resolve('swc-loader'),
39
- options: getSWCConfig({isModern: false, isTypeScript: true})
40
- }
41
- ]
42
- }
43
- : {
44
- test: /\.jsx?$/,
45
- exclude: EXCLUDED_FOLDERS_REGEXP,
46
- use: [
47
- {
48
- loader: require.resolve('babel-loader'),
49
- options: {
50
- cacheDirectory: true,
51
- cacheCompression: false,
52
- babelrc: false,
53
- compact: true,
54
- plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
55
- presets: [
56
- [
57
- require.resolve('babel-preset-sui'),
58
- {
59
- isServer,
60
- isModern: !supportLegacyBrowsers,
61
- targets: config.targets
62
- }
63
- ]
64
- ]
65
- }
66
- }
67
- ]
68
- }
69
- }
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "@s-ui/compiler-config/tsconfig.json"
3
- }