@s-ui/bundler 9.38.0 → 9.39.0-typescript.100

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.
@@ -67,12 +67,7 @@ const start = async ({
67
67
  } = {}) => {
68
68
  clearConsole()
69
69
  // Warn and crash if required files are missing
70
- if (
71
- !checkRequiredFiles([
72
- path.join(config.context, 'index.html'),
73
- path.join(config.context, 'app.js')
74
- ])
75
- ) {
70
+ if (!checkRequiredFiles([path.join(config.context, 'index.html')])) {
76
71
  log.error(
77
72
  `✖ Required files are missing, create and index.html and app.js inside your src folder.`
78
73
  )
@@ -49,7 +49,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
49
49
  * if neccesary
50
50
  */
51
51
  const linkLoader = {
52
- test: /\.(jsx?|scss)$/,
52
+ test: /\.(jsx?|tsx?|scss)$/,
53
53
  enforce: 'pre', // this will ensure is execute before transformations
54
54
  use: {
55
55
  loader: require.resolve('./LinkLoader'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s-ui/bundler",
3
- "version": "9.38.0",
3
+ "version": "9.39.0-typescript.100",
4
4
  "description": "Config-free bundler for ES6 React apps.",
5
5
  "bin": {
6
6
  "sui-bundler": "./bin/sui-bundler.js"
@@ -21,9 +21,13 @@
21
21
  },
22
22
  "homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme",
23
23
  "dependencies": {
24
- "@babel/core": "7.18.10",
24
+ "@babel/core": "7.21.8",
25
25
  "@s-ui/helpers": "1",
26
26
  "@s-ui/sass-loader": "1",
27
+ "@swc/core": "1.3.14",
28
+ "@swc/helpers": "0.4.12",
29
+ "@tsconfig/esm": "^1.0.3",
30
+ "@tsconfig/vite-react": "^2.0.0",
27
31
  "address": "1.2.0",
28
32
  "autoprefixer": "10.4.8",
29
33
  "babel-loader": "8.2.5",
@@ -34,7 +38,7 @@
34
38
  "css-minimizer-webpack-plugin": "4.0.0",
35
39
  "esbuild": "0.15.5",
36
40
  "escape-string-regexp": "4.0.0",
37
- "fast-glob": "3.2.11",
41
+ "fast-glob": "3.2.12",
38
42
  "find-free-ports": "3.0.0",
39
43
  "html-webpack-plugin": "5.5.0",
40
44
  "https-browserify": "1.0.0",
@@ -46,8 +50,9 @@
46
50
  "stream-http": "3.2.0",
47
51
  "strip-ansi": "6.0.1",
48
52
  "style-loader": "3.3.1",
53
+ "swc-loader": "0.2.1",
49
54
  "url": "0.11.0",
50
- "webpack": "5.74.0",
55
+ "webpack": "5.82.1",
51
56
  "webpack-dev-server": "4.10.0",
52
57
  "webpack-manifest-plugin": "5.0.0",
53
58
  "webpack-node-externals": "3.0.0"
package/shared/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const {config} = require('./config.js')
2
2
 
3
- exports.MAIN_ENTRY_POINT = './app.js'
3
+ exports.MAIN_ENTRY_POINT = './app'
4
4
  exports.config = config
5
5
 
6
6
  exports.cleanList = list => list.filter(Boolean)
@@ -1,3 +1,5 @@
1
+ /* eslint-disable no-console */
2
+ const fs = require('fs-extra')
1
3
  const path = require('path')
2
4
  const {config} = require('./index.js')
3
5
 
@@ -5,28 +7,97 @@ const EXCLUDED_FOLDERS_REGEXP = new RegExp(
5
7
  `node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
6
8
  )
7
9
 
8
- module.exports = ({isServer = 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
- presets: [
20
- [
21
- require.resolve('babel-preset-sui'),
22
- {
23
- isServer,
24
- isModern: !supportLegacyBrowsers,
25
- targets: config.targets
10
+ const getTSConfig = () => {
11
+ // Get TS config from the package dir.
12
+ const tsConfigPath = path.join(process.cwd(), 'tsconfig.json')
13
+ let tsConfig
14
+
15
+ try {
16
+ if (fs.existsSync(tsConfigPath)) {
17
+ tsConfig = JSON.parse(fs.readFileSync(tsConfigPath, {encoding: 'utf8'}))
18
+ }
19
+ } catch (err) {
20
+ console.error(err)
21
+ }
22
+
23
+ return tsConfig
24
+ }
25
+
26
+ module.exports = ({isServer = false, supportLegacyBrowsers = true} = {}) => {
27
+ const tsConfig = getTSConfig()
28
+ // If TS config exists in root dir, set TypeScript as enabled.
29
+ const isTypeScriptEnabled = Boolean(tsConfig)
30
+
31
+ return isTypeScriptEnabled
32
+ ? {
33
+ test: /\.(js|ts)x?$/,
34
+ exclude: EXCLUDED_FOLDERS_REGEXP,
35
+ use: [
36
+ {
37
+ loader: require.resolve('swc-loader'),
38
+ options: {
39
+ minify: true,
40
+ jsc: {
41
+ parser: {
42
+ syntax: 'typescript',
43
+ tsx: true,
44
+ dynamicImport: true,
45
+ privateMethod: true,
46
+ functionBind: true,
47
+ exportDefaultFrom: true,
48
+ exportNamespaceFrom: true,
49
+ decorators: true,
50
+ decoratorsBeforeExport: true,
51
+ topLevelAwait: true,
52
+ importMeta: true
53
+ },
54
+ transform: {
55
+ legacyDecorator: true,
56
+ react: {
57
+ useBuiltins: true,
58
+ runtime: 'automatic'
59
+ }
60
+ },
61
+ target: 'es5',
62
+ loose: true,
63
+ externalHelpers: true
64
+ },
65
+ env: {
66
+ targets: {
67
+ ie: '11'
68
+ },
69
+ dynamicImport: true,
70
+ loose: true,
71
+ mode: 'entry',
72
+ coreJs: 3
73
+ }
26
74
  }
27
- ]
75
+ }
28
76
  ]
29
77
  }
30
- }
31
- ]
32
- })
78
+ : {
79
+ test: /\.jsx?$/,
80
+ exclude: EXCLUDED_FOLDERS_REGEXP,
81
+ use: [
82
+ {
83
+ loader: require.resolve('babel-loader'),
84
+ options: {
85
+ cacheDirectory: true,
86
+ cacheCompression: false,
87
+ babelrc: false,
88
+ compact: true,
89
+ presets: [
90
+ [
91
+ require.resolve('babel-preset-sui'),
92
+ {
93
+ isServer,
94
+ isModern: !supportLegacyBrowsers,
95
+ targets: config.targets
96
+ }
97
+ ]
98
+ ]
99
+ }
100
+ }
101
+ ]
102
+ }
103
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["@tsconfig/esm/tsconfig.json", "@tsconfig/vite-react/tsconfig.json"],
3
+ }
@@ -47,7 +47,7 @@ const webpackConfig = {
47
47
  timers: false
48
48
  },
49
49
  modules: ['node_modules', path.resolve(process.cwd())],
50
- extensions: ['.js', '.json']
50
+ extensions: ['.js', '.tsx', '.ts', '.json']
51
51
  },
52
52
  stats: 'errors-only',
53
53
  entry: cleanList([
@@ -54,7 +54,7 @@ const webpackConfig = {
54
54
  context: path.resolve(CWD, 'src'),
55
55
  resolve: {
56
56
  alias: {...aliasFromConfig},
57
- extensions: ['.js', '.json'],
57
+ extensions: ['.js', '.json', '.ts', '.tsx'],
58
58
  modules: ['node_modules', path.resolve(CWD)],
59
59
  fallback: {
60
60
  assert: false,