Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] typescript support #1614

Merged
merged 152 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
ca3f4b3
feat(packages/sui-bundler): add support to typescript
kikoruiz Jun 21, 2023
2e43455
feat(packages/sui-lint): add support to typescript
kikoruiz Jun 21, 2023
a4eb7ca
feat(packages/sui-react-context): add support to typescript
kikoruiz Jun 21, 2023
486ff09
feat(packages/sui-studio): add support to typescript
kikoruiz Jun 21, 2023
a39c57e
chore(packages/sui-bundler): set new beta version
kikoruiz Jun 26, 2023
c599db5
chore(packages/sui-lint): set new ts tag
kikoruiz Jun 26, 2023
505be81
chore(packages/sui-react-context): set new ts tag
kikoruiz Jun 26, 2023
cc743be
chore(packages/sui-studio): set new ts tag
kikoruiz Jun 26, 2023
9350421
Merge branch 'master' of github.com:SUI-Components/sui into typescrip…
carlosvillu Jun 29, 2023
12224a5
feat(packages/sui-bundler): Add TS support for dev and build
carlosvillu Jul 17, 2023
dbfded8
feat(packages/sui-helpers): Add dynamicPackage
carlosvillu Jul 17, 2023
a5c8730
feat(packages/sui-lint): Add support to parse TS files
carlosvillu Jul 17, 2023
75d6882
feat(packages/sui-studio): Use MAGIC_STRING to support sui-bundler wi…
carlosvillu Jul 17, 2023
4d8160d
feat(packages/sui-typescript-config): Create package
carlosvillu Jul 17, 2023
ee16293
Merge branch 'typescript-support' of github.com:SUI-Components/sui in…
carlosvillu Jul 17, 2023
0c1bed6
Merge branch 'master' of github.com:SUI-Components/sui into typescrip…
carlosvillu Jul 18, 2023
b4cd94c
fix(packages/sui-studio): fix require globals.js
carlosvillu Jul 20, 2023
914e20b
Merge branch 'master' of github.com:SUI-Components/sui into typescrip…
carlosvillu Jul 25, 2023
0bc9fd5
feat(packages/sui-bundler): add more support to typescript
kikoruiz Aug 9, 2023
5397da9
test(packages/sui-react-head): fix some tests
kikoruiz Aug 9, 2023
a502a65
chore(Root): execute all server tests
kikoruiz Aug 9, 2023
e8780da
feat(packages/sui-helpers): add more support to typescript
kikoruiz Aug 9, 2023
bbc4336
feat(packages/sui-js-compiler): add more support to typescript
kikoruiz Aug 9, 2023
b3616de
feat(packages/sui-lint): add more support to typescript
kikoruiz Aug 9, 2023
c75a1f2
feat(packages/sui-studio): add more support to typescript
kikoruiz Aug 9, 2023
9c84adb
feat(packages/sui-test): add more support to typescript
kikoruiz Aug 9, 2023
2096ebb
feat(packages/sui-typescript-config): add more support to typescript
kikoruiz Aug 9, 2023
e7a5b35
fix(packages/sui-typescript-config): fix config
kikoruiz Aug 9, 2023
db77a2f
fix(packages/sui-test): add proper loader to karma
kikoruiz Aug 9, 2023
793641e
chore(packages/sui-js-compiler): bump test version
kikoruiz Aug 9, 2023
fcdcf94
chore(Root): fix npm options
kikoruiz Aug 9, 2023
b53ee39
fix(packages/sui-bundler): add some fixes
kikoruiz Aug 10, 2023
f4fa3af
fix(packages/sui-helpers): add some fixes
kikoruiz Aug 10, 2023
7001874
fix(packages/sui-js-compiler): add some fixes
kikoruiz Aug 10, 2023
09a6949
fix(packages/sui-studio): add some fixes
kikoruiz Aug 10, 2023
d407c02
feat(packages/sui-bundler): add more changes
kikoruiz Aug 10, 2023
0af1a4f
feat(packages/sui-compiler-config): add more changes
kikoruiz Aug 10, 2023
c80bcf3
feat(packages/sui-js-compiler): add more changes
kikoruiz Aug 10, 2023
7024520
feat(packages/sui-test): add more changes
kikoruiz Aug 10, 2023
c7cd349
feat(Root): remove package
kikoruiz Aug 10, 2023
0b2e9b6
feat(packages/sui-bundler): restore original versions
kikoruiz Aug 10, 2023
80db5eb
feat(packages/sui-compiler-config): restore original versions
kikoruiz Aug 10, 2023
0961a23
feat(packages/sui-helpers): restore original versions
kikoruiz Aug 10, 2023
8dd8cd1
feat(packages/sui-js-compiler): restore original versions
kikoruiz Aug 10, 2023
015daf5
feat(packages/sui-lint): restore original versions
kikoruiz Aug 10, 2023
48c3efc
feat(packages/sui-react-context): restore original versions
kikoruiz Aug 10, 2023
60e1b77
feat(packages/sui-studio): restore original versions
kikoruiz Aug 10, 2023
d3081eb
feat(packages/sui-test): restore original versions
kikoruiz Aug 10, 2023
f6c4f96
feat(packages/sui-bundler): rename module rules
kikoruiz Aug 11, 2023
eb68ce2
feat(packages/sui-hoc): remove type module
kikoruiz Aug 11, 2023
c5facd5
test(packages/sui-js-compiler): log errors
kikoruiz Aug 18, 2023
b2487ab
fix(packages/sui-bundler): fix plugin extension
kikoruiz Oct 17, 2023
9374272
Merge branch 'master' into typescript-support
kikoruiz Oct 17, 2023
561bca9
feat(packages/sui-mock): sync typescript versions
kikoruiz Oct 17, 2023
5c75ada
feat(packages/sui-test-contract): sync typescript versions
kikoruiz Oct 17, 2023
ebf4b6e
Merge branch 'master' into typescript-support
kikoruiz Oct 25, 2023
bfd4f8c
chore(Root): upgrade ts versio
kikoruiz Oct 30, 2023
1a3585b
feat(packages/sui-test): sync ts version
kikoruiz Oct 30, 2023
b2d8f66
feat(packages/sui-js-compiler): install ts by default
kikoruiz Oct 30, 2023
6db9f33
feat(packages/sui-helpers): remove not needed function
kikoruiz Oct 30, 2023
6cab6ff
feat(packages/sui-bundler): remove dynamic import
kikoruiz Oct 31, 2023
5cacd3e
chore(Root): fix ts version
kikoruiz Oct 31, 2023
c7f0a06
test(packages/sui-js-compiler): fix test
kikoruiz Oct 31, 2023
27cce44
test(Root): debug test
kikoruiz Oct 31, 2023
ba9fd99
test(packages/sui-js-compiler): remove only
kikoruiz Oct 31, 2023
d733a17
test(packages/sui-js-compiler): remove logs
kikoruiz Oct 31, 2023
c6eb1ee
test(packages/sui-js-compiler): increase timeout
kikoruiz Oct 31, 2023
bbcdf12
test(packages/sui-js-compiler): restore timeout value
kikoruiz Nov 6, 2023
1b8233f
Merge branch 'master' into typescript-support
kikoruiz Nov 6, 2023
96683af
test(packages/sui-js-compiler): skip some tests
kikoruiz Nov 7, 2023
9863c61
Merge branch 'master' into typescript-support
kikoruiz Nov 8, 2023
7fea970
chore(Root): change script
kikoruiz Nov 13, 2023
95153a8
chore(packages/sui-consents): fix deps
kikoruiz Nov 13, 2023
6bde899
chore(Root): put some logs in ci scripts
kikoruiz Nov 13, 2023
2d9830a
chore(Root): execute only one more server test
kikoruiz Nov 21, 2023
aa7d38b
feat(packages/sui-bundler): add autoload support for MSW
carlosvillu Nov 29, 2023
dcac529
feat(packages/sui-studio): Use relative paths for monorepos
carlosvillu Nov 29, 2023
c09ccc2
feat(packages/sui-test): use relative paths for monorepos
carlosvillu Nov 29, 2023
d667c96
Merge branch 'master' into typescript-support
kikoruiz Dec 18, 2023
1b4541b
fix(packages/sui-consents): fix linting issues
kikoruiz Dec 18, 2023
547c28b
fix(packages/sui-react-context): fix linting issues
kikoruiz Dec 18, 2023
99d0af8
fix(packages/sui-react-head): fix linting issues
kikoruiz Dec 18, 2023
19c9633
fix(packages/sui-react-initial-props): fix linting issues
kikoruiz Dec 18, 2023
1904ca2
fix(packages/sui-studio): fix linting issues
kikoruiz Dec 18, 2023
37213c0
fix(packages/sui-theme): fix linting issues
kikoruiz Dec 18, 2023
06139b3
test(packages/sui-consents): fix some imports
kikoruiz Dec 18, 2023
ff382d9
Merge branch 'typescript-support' of github.com:SUI-Components/sui in…
kikoruiz Dec 18, 2023
ea9a885
chore(Root): remove logs
kikoruiz Dec 18, 2023
e022570
feat(packages/sui-studio): restore package version
kikoruiz Dec 18, 2023
b185cc8
fix(packages/sui-react-initial-props): fix ts config
kikoruiz Dec 18, 2023
c28e283
fix(packages/sui-js-compiler): fix types
kikoruiz Dec 18, 2023
e9e73e7
chore(Root): add type checking
kikoruiz Dec 18, 2023
887e808
chore(Root): fix cache option
kikoruiz Dec 18, 2023
931c7ef
chore(Root): remove cache
kikoruiz Dec 18, 2023
9acc197
chore(Root): modify case
kikoruiz Dec 20, 2023
bff1ca4
Merge branch 'master' into typescript-support
kikoruiz Jan 8, 2024
82d90d3
Merge branch 'master' into typescript-support
kikoruiz Jan 22, 2024
f142e81
test(packages/sui-js-compiler): remove clean
kikoruiz Jan 22, 2024
9f2c30c
chore(Root): check pr workflow
kikoruiz Jan 22, 2024
d7fdf6a
chore(Root): change script command
kikoruiz Jan 22, 2024
71fcce1
chore(Root): change script execution
kikoruiz Jan 22, 2024
d8a7720
chore(Root): add missing checkout
kikoruiz Jan 22, 2024
8e5184a
chore(Root): add install step
kikoruiz Jan 22, 2024
13a3fa2
chore(Root): fix some stuff
kikoruiz Jan 22, 2024
29c0b79
chore(Root): fix more things
kikoruiz Jan 22, 2024
136dff7
chore(Root): fix some other things
kikoruiz Jan 22, 2024
2da1cb3
chore(Root): fix import
kikoruiz Jan 22, 2024
0d97137
chore(Root): update script for tagging releases in prs
kikoruiz Jan 26, 2024
698c932
feat(packages/sui-bundler): use latest version of swc
kikoruiz Jan 26, 2024
018c890
feat(packages/sui-consents): use latest version of swc
kikoruiz Jan 26, 2024
9986b23
feat(packages/sui-decorators): use latest version of swc
kikoruiz Jan 26, 2024
e574610
feat(packages/sui-domain): use latest version of swc
kikoruiz Jan 26, 2024
820adf5
feat(packages/sui-hoc): use latest version of swc
kikoruiz Jan 26, 2024
ea25581
feat(packages/sui-jest): use latest version of swc
kikoruiz Jan 26, 2024
b1a0c16
feat(packages/sui-js-compiler): use latest version of swc
kikoruiz Jan 26, 2024
4b7de4b
feat(packages/sui-mock): use latest version of swc
kikoruiz Jan 26, 2024
dbb8c88
feat(packages/sui-react-context): use latest version of swc
kikoruiz Jan 26, 2024
c56495d
feat(packages/sui-react-head): use latest version of swc
kikoruiz Jan 26, 2024
3e1a7df
feat(packages/sui-react-initial-props): use latest version of swc
kikoruiz Jan 26, 2024
a133bd7
feat(packages/sui-test-contract): use latest version of swc
kikoruiz Jan 26, 2024
18b3783
feat(packages/sui-test): use latest version of swc
kikoruiz Jan 26, 2024
5191739
chore(Root): uncomment script and fix dev dep version
kikoruiz Jan 26, 2024
63d95f9
Merge branch 'master' into typescript-support
kikoruiz Jan 29, 2024
5385616
Merge branch 'master' into typescript-support
kikoruiz Feb 2, 2024
e7eabfd
fix(packages/sui-consents): fix linting issues
kikoruiz Feb 5, 2024
6b639a8
fix(packages/sui-domain): fix linting issues
kikoruiz Feb 5, 2024
5c199d4
fix(packages/sui-react-context): fix linting issues
kikoruiz Feb 5, 2024
7f84666
fix(packages/sui-react-head): fix linting issues
kikoruiz Feb 5, 2024
d580498
fix(packages/sui-react-initial-props): fix linting issues
kikoruiz Feb 5, 2024
60569df
chore(Root): add condition to workflow and modify script
kikoruiz Feb 5, 2024
d2ddc9e
Merge branch 'master' into typescript-support
kikoruiz Feb 6, 2024
4abd3a4
Merge branch 'master' into typescript-support
kikoruiz Feb 12, 2024
72ba122
fix(packages/sui-bundler): downgrade swc versions
kikoruiz Feb 12, 2024
20ed77b
fix(packages/sui-js-compiler): downgrade swc versions
kikoruiz Feb 12, 2024
f875b65
fix(packages/sui-test): downgrade swc versions
kikoruiz Feb 12, 2024
02b592c
fix(packages/sui-consents): update deps
kikoruiz Feb 13, 2024
038cfef
fix(packages/sui-decorators): update deps
kikoruiz Feb 13, 2024
f57199f
fix(packages/sui-domain): update deps
kikoruiz Feb 13, 2024
a9d5998
fix(packages/sui-hoc): update deps
kikoruiz Feb 13, 2024
b670cc2
fix(packages/sui-js-compiler): update deps
kikoruiz Feb 13, 2024
d9e7f35
fix(packages/sui-mock): update deps
kikoruiz Feb 13, 2024
3788e5e
fix(packages/sui-react-context): update deps
kikoruiz Feb 13, 2024
cf7992d
fix(packages/sui-react-head): update deps
kikoruiz Feb 13, 2024
d55aabc
fix(packages/sui-react-initial-props): update deps
kikoruiz Feb 13, 2024
abb824b
fix(packages/sui-test-contract): update deps
kikoruiz Feb 13, 2024
2e05a91
fix(packages/sui-react-head): fix type
kikoruiz Feb 13, 2024
d58414c
chore(Root): modify workflow execution condition
kikoruiz Feb 13, 2024
173221d
fix(packages/sui-bundler): fix resolve alias
kikoruiz Feb 21, 2024
6d57665
fix(packages/sui-test): support new project structure
kikoruiz Feb 22, 2024
c15b8ee
Merge branch 'master' into typescript-support
kikoruiz Apr 29, 2024
b35b308
Update packages/sui-jest/package.json
carlosvillu Apr 29, 2024
7952850
Merge branch 'master' of github.com:SUI-Components/sui into typescrip…
kikoruiz May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
checks:
name: Checks
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Redundant Builds
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version-file: '.nvmrc'

- name: Setup Chrome
uses: browser-actions/setup-chrome@latest

- name: Install
run: |
sudo apt-get install xvfb
npm install --no-save --no-fund --no-audit --legacy-peer-deps
npx -y ultra-runner --raw --recursive prepublishOnly

- name: Lint
run: npm run lint

- name: Type Checking
run: npm run types:check

- name: Tests
run: |
npm run test:server:ci
xvfb-run --auto-servernum npm run test:client:ci

publish:
name: Publish
needs: checks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version-file: '.nvmrc'

- name: Publish Packages
if: github.ref == 'refs/heads/master'
run: |
npx -p ./packages/sui-mono sui-mono check
npx -p ./packages/sui-ci sui-ci release
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
GITHUB_EMAIL: [email protected]
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }}
GITHUB_USER: sui-bot
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-tagged-packages:
name: Publish Tagged Packages to NPM
needs: checks
if: github.ref != 'refs/heads/master' && contains(github.event.pull_request.labels.*.name, 'feature')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version-file: '.nvmrc'

- name: Install
run: npm install -D commander execa prettier

- name: Get Files
id: files
uses: jitterbit/get-changed-files@v1
with:
format: 'json'

- name: Publish Packages
run: npm run publish-tagged-packages -- --tag '${{ github.event.pull_request.head.ref }}' --files '${{ steps.files.outputs.added_modified }}'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
59 changes: 0 additions & 59 deletions .github/workflows/node.js.yml

This file was deleted.

30 changes: 15 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
node_modules/
lib/
coverage/
.DS_Store
npm-debug.log
.tern-port
package-lock.json
.idea/
.python-version
.tern-port
.vscode/

contract/logs/pact.log
coverage/
jsconfig.json
lib/
node_modules/
npm-debug.log
package-lock.json

!packages/sui-sass-loader/test/server/fixtures/**/node_modules
packages/sui-codemod/COMMANDS
sui-components-dashboard-9350df448fcd.json
.idea/
.vscode/
packages/sui-studio/test/server/integration/empty-studio/components/fake/**
packages/sui-studio/test/server/integration/empty-studio/components/fake/componentnvim
packages/sui-studio/test/server/integration/empty-studio/demo/fake/**
packages/sui-studio/test/server/integration/empty-studio/test/fake/**
packages/sui-studio/test/server/integration/sample-studio/node_modules/
packages/sui-studio/test/server/integration/sample-studio/components/atom/button/node_modules/
packages/sui-studio/test/server/integration/sample-studio/node_modules/
packages/sui-studio/test/server/integration/sample-studio/public
packages/sui-studio/test/server/integration/empty-studio/components/fake/componentnvim

!packages/sui-sass-loader/test/server/fixtures/**/node_modules

contract/logs/pact.log
.npmrc
sui-components-dashboard-9350df448fcd.json
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,33 @@
"packages/*"
],
"scripts": {
"phoenix": "npx @s-ui/mono phoenix && npx -y ultra-runner --raw --recursive prepublishOnly &>/dev/null",
"phoenix": "npx @s-ui/mono phoenix && npx -y ultra-runner --raw --recursive prepublishOnly --build &>/dev/null",
"co": "npx @s-ui/mono commit",
"lint": "sui-lint js && sui-lint sass",
"test": "npm run test:client && npm run test:server",
"test:client:ci": "npm run test:client",
"test:server:ci": "npm run test:server",
"test:client": "npx @s-ui/test browser -P 'packages/**/!(server)/*Spec.js'",
"test:client:watch": "npm run test:client -- --watch",
"test:server": "npx @s-ui/test server -P './packages/sui-test-contract/test/server/setupSpec.js'",
"test:server": "npx @s-ui/test server -P 'packages/{sui-test-contract,sui-js-compiler}/**/server/*Spec.js'",
"test:server:watch": "npm run test:server -- --watch",
"test:e2e": "node ./packages/sui-studio/test/server/integration/static-server.js ./packages/sui-studio/test/server/integration/sample-studio/public && npx @s-ui/test-e2e --baseUrl=http://localhost:1234",
"pre-commit": "sui-lint js --staged && sui-lint sass --staged",
"pre-push": "npm run test",
"commit-msg": "validate-commit-msg"
"pre-push": "npm run test && npm run types:check",
"publish-tagged-packages": "node ./scripts/publish-tagged-packages.mjs",
"commit-msg": "validate-commit-msg",
"types:check": "tsc"
},
"devDependencies": {
"@babel/cli": "7",
"@s-ui/lint": "4",
"@s-ui/precommit": "3",
"@s-ui/react-context": "1",
"chai": "4.3.6",
"pino-pretty": "10.3.1",
"react": "17",
"sinon": "10.0.0",
"typescript": "4.3.2",
"typescript": "5.0.4",
"validate-commit-msg": "2.14.0"
},
"config": {
Expand Down Expand Up @@ -79,4 +82,4 @@
"stylelint": {
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
}
}
}
2 changes: 1 addition & 1 deletion packages/sui-bundler/bin/sui-bundler-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (!module.parent) {
const start = async ({config = webpackConfig, packagesToLink = program.opts().linkPackage || []} = {}) => {
clearConsole()
// Warn and crash if required files are missing
if (!checkRequiredFiles([path.join(config.context, 'index.html'), path.join(config.context, 'app.js')])) {
if (!checkRequiredFiles([path.join(config.context, 'index.html')])) {
log.error(`✖ Required files are missing, create and index.html and app.js inside your src folder.`)
process.exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sui-bundler/loaders/linkLoaderConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
* if neccesary
*/
const linkLoader = {
test: /\.(jsx?|scss)$/,
test: /\.(jsx?|tsx?|scss)$/,
enforce: 'pre', // this will ensure is execute before transformations
use: {
loader: require.resolve('./LinkLoader'),
Expand Down
9 changes: 7 additions & 2 deletions packages/sui-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"main": "./bin/sui-bundler.js",
"scripts": {
"postinstall": "node ./scripts/postinstall.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand All @@ -21,11 +22,14 @@
},
"homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme",
"dependencies": {
"@babel/core": "7.18.10",
"@babel/core": "7.21.8",
"@builder.io/react-hydration-overlay": "0.0.8",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@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.3.0",
Expand All @@ -36,7 +40,7 @@
"css-minimizer-webpack-plugin": "4.0.0",
"esbuild": "0.15.5",
"escape-string-regexp": "4.0.0",
"fast-glob": "3.2.11",
"fast-glob": "3.2.12",
"find-free-ports": "3.0.0",
"html-webpack-inject-attributes-plugin": "1.0.6",
"html-webpack-plugin": "5.5.0",
Expand All @@ -50,6 +54,7 @@
"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-dev-server": "4.15.2",
"webpack-manifest-plugin": "5.0.0",
Expand Down
48 changes: 48 additions & 0 deletions packages/sui-bundler/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const crypto = require('crypto')
const fs = require('fs-extra')
const path = require('path')
const {writeFile} = require('@s-ui/helpers/file.js')

const {INIT_CWD} = process.env
const tsConfigTemplate = `\
{
"extends": "@s-ui/bundler/tsconfig.json",
"compilerOptions": {
"rootDir": "./"
},
"include": ["src", "domain", "components"]
}`

const md5 = str => crypto.createHash('md5').update(str).digest('hex')
const TS_CONFIG_PATH = path.join(INIT_CWD, 'tsconfig.json')
const PACKAGE_JSON_CONFIG_PATH = path.join(INIT_CWD, 'package.json')

const config = require(PACKAGE_JSON_CONFIG_PATH)?.config?.['sui-bundler'] || {}

const shouldGenerateTSConfig = () => {
try {
if (!config?.type || config?.type !== 'typescript') return false

if (!fs.existsSync(TS_CONFIG_PATH)) return true

const tsConfigLocal = fs.readFileSync(TS_CONFIG_PATH, {encoding: 'utf8'})
return md5(tsConfigLocal) !== md5(tsConfigTemplate)
} catch (err) {
return true
}
}

async function main() {
console.log('🔍 [sui-bundler postinstall] Checking if tsconfig.json is up to date...')
if (!shouldGenerateTSConfig()) {
console.log('✅ [sui-bundler postinstall] tsconfig.json is up to date')
process.exit(0)
}
await writeFile(TS_CONFIG_PATH, tsConfigTemplate)
console.log('❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it')
}

main()
14 changes: 12 additions & 2 deletions packages/sui-bundler/shared/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ if (process.platform === 'win32') {
process.env.PWD = process.cwd()
}

const {MAGIC_STRINGS = '{}'} = process.env

let magic
try {
magic = JSON.parse(MAGIC_STRINGS)
} catch (err) {
magic = {}
}

module.exports = (vars = {}) =>
new webpack.DefinePlugin({
__MOCKS_API_PATH__: JSON.stringify(process.env.MOCKS_API_PATH || process.env.PWD + '/mocks/routes'),
__DEV__: false,
__BASE_DIR__: JSON.stringify(process.env.PWD),
...vars
__MOCKS_API_PATH__: JSON.stringify(process.env.MOCKS_API_PATH || process.env.PWD + '/mocks/routes'),
...vars,
...Object.fromEntries(Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)]))
})
Loading
Loading