Skip to content

Commit

Permalink
chore: rewrite package to esmodules (#1442)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The package won't support CJS anymore
  • Loading branch information
dziraf authored Mar 20, 2023
1 parent 59aac8d commit c811f2e
Show file tree
Hide file tree
Showing 388 changed files with 5,886 additions and 5,913 deletions.
12 changes: 7 additions & 5 deletions .babelrc → .babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
"@babel/preset-react",
["@babel/preset-env", {
"targets": {
"node": "16"
}
"node": "18"
},
"loose": true,
"modules": false
}],
"@babel/preset-typescript"
["@babel/preset-typescript"]
],
"plugins": ["babel-plugin-styled-components"],
"plugins": ["babel-plugin-styled-components", "@babel/plugin-syntax-import-assertions"],
"only": ["src/", "spec/"],
"ignore": [
"src/frontend/assets/scripts/app-bundle.development.js",
"src/frontend/assets/scripts/app-bundle.production.js",
"src/frontend/assets/scripts/global-bundle.development.js",
"src/frontend/assets/scripts/global-bundle.production.js"
]
}
}
19 changes: 16 additions & 3 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = {
node: true,
mocha: true,
},
extends: ['airbnb', 'plugin:@typescript-eslint/recommended', 'plugin:mocha/recommended'],
extends: ['airbnb', 'plugin:@typescript-eslint/recommended', 'plugin:mocha/recommended', 'plugin:import/typescript'],
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: 'module',
},
rules: {
Expand All @@ -29,7 +29,7 @@ module.exports = {
'no-restricted-syntax': 'off',
'no-await-in-loop': 'off',
'object-curly-newline': 'off',
'import/extensions': 'off',
'import/extensions': [2, 'ignorePackages'],
'mocha/no-hooks-for-single-case': 'off',
'no-param-reassign': 'off',
'default-param-last': 'off',
Expand Down Expand Up @@ -72,6 +72,12 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
{
files: ['*.cjs'],
rules: {
'import/no-commonjs': 'off',
},
},
{
files: ['*.tsx'],
rules: {
Expand All @@ -87,6 +93,13 @@ module.exports = {
},
},
],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
globals: {
expect: true,
factory: true,
Expand Down
45 changes: 16 additions & 29 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '18'
cache: 'yarn'
- name: Install
run: yarn install --frozen-lockfile
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Setup
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '18'
cache: 'yarn'
- name: Install
run: yarn install
Expand All @@ -38,53 +38,43 @@ jobs:
key: assets-${{ hashFiles('**/src/frontend/global-entry.js') }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/bin/bundle-globals.js') }}
restore-keys: |
assets-
- name: build
run: yarn build
- name: types
run: yarn types
- name: bundle globals production
if: steps.assets-cache.outputs.cache-hit != 'true'
run: NODE_ENV=production yarn bundle:globals
- name: bundle globals dev
if: steps.assets-cache.outputs.cache-hit != 'true'
run: NODE_ENV=dev yarn bundle:globals

- name: bundle production
run: NODE_ENV=production ONCE=true yarn bundle
- name: bundle dev
run: ONCE=true yarn bundle
- name: build
run: yarn build
- name: types
run: yarn types
- name: Upload Build
if: |
contains(github.ref, 'refs/heads/next')
|| contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/next-major')
contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/beta-v7')
|| contains(github.ref, 'refs/heads/beta')
|| contains(github.ref, 'refs/heads/alpha')
|| contains(github.ref, 'refs/heads/dev')
uses: actions/upload-artifact@v3
with:
name: lib
path: lib
- name: Upload Types
if: |
contains(github.ref, 'refs/heads/next')
|| contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/next-major')
contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/beta-v7')
|| contains(github.ref, 'refs/heads/beta')
|| contains(github.ref, 'refs/heads/alpha')
|| contains(github.ref, 'refs/heads/dev')
uses: actions/upload-artifact@v3
with:
name: types
path: types
- name: Upload Bundle
if: |
contains(github.ref, 'refs/heads/next')
|| contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/next-major')
contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/beta-v7')
|| contains(github.ref, 'refs/heads/beta')
|| contains(github.ref, 'refs/heads/alpha')
|| contains(github.ref, 'refs/heads/dev')
uses: actions/upload-artifact@v3
with:
name: bundle
Expand All @@ -100,7 +90,7 @@ jobs:
- name: Setup
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '18'
cache: 'yarn'
- name: Install
run: yarn install
Expand All @@ -125,12 +115,9 @@ jobs:
if: |
github.event_name == 'push'
&& (
contains(github.ref, 'refs/heads/next')
|| contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/next-major')
contains(github.ref, 'refs/heads/master')
|| contains(github.ref, 'refs/heads/beta-v7')
|| contains(github.ref, 'refs/heads/beta')
|| contains(github.ref, 'refs/heads/alpha')
|| contains(github.ref, 'refs/heads/dev')
)
needs:
- test
Expand All @@ -147,7 +134,7 @@ jobs:
- name: Setup
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '18'
cache: 'yarn'
- name: Install
run: yarn install
Expand Down
16 changes: 1 addition & 15 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "dev",
"prerelease": true
},
{
"name": "alpha",
"name": "beta-v7",
"prerelease": true
}
],
Expand All @@ -31,14 +25,6 @@
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git",
["semantic-release-jira-releases-sb", {
"projectId": "AB",
"releaseNameTemplate": "v${version}",
"jiraHost": "kmpgroup.atlassian.net",
"ticketPrefixes": [ "AB" ],
"released": true,
"setReleaseDate": true
}],
[
"semantic-release-slack-bot",
{
Expand Down
36 changes: 16 additions & 20 deletions bin/bundle-globals.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-extraneous-dependencies */
/**
* @private
* @fileoverview
* This script runs process, which bundles all globals like React or ReactDOM
* to the `global-bundle.js`.
*/
import path from 'path'
import { rollup } from 'rollup'
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import json from '@rollup/plugin-json'
import polyfills from 'rollup-plugin-polyfill-node'
import terser from '@rollup/plugin-terser'
import * as url from 'url'

const { rollup } = require('rollup')
const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve')
const commonjs = require('@rollup/plugin-commonjs')
const replace = require('@rollup/plugin-replace')
const json = require('@rollup/plugin-json')
const builtins = require('rollup-plugin-node-builtins')
const globals = require('rollup-plugin-node-globals')
const { terser } = require('rollup-plugin-terser')
import env from '../lib/backend/bundler/bundler-env.js'

const env = require('../src/backend/bundler/bundler-env')
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

const run = async () => {
const inputOptions = {
input: `${__dirname}/../src/frontend/global-entry.js`,
input: path.join(__dirname, '../lib/frontend/global-entry.js'),
plugins: [
resolve({
extensions: ['.mjs', '.js', '.jsx', '.json', '.scss'],
extensions: ['.mjs', '.js', '.cjs', '.mjs', '.jsx', '.json', '.scss'],
mainFields: ['browser'],
preferBuiltins: false,
browser: true,
Expand All @@ -40,15 +36,15 @@ const run = async () => {
include: ['node_modules/**', env === 'development' ? '../../node_modules/**' : ''],
ignoreGlobal: true,
}),
globals(),
builtins(),
polyfills(),
...(env === 'production' ? [terser()] : []),
],
}
const bundle = await rollup(inputOptions)

return bundle.write({
format: 'iife',
interop: 'auto',
name: 'globals',
globals: {
react: 'React',
Expand All @@ -63,7 +59,7 @@ const run = async () => {
'react-router': 'ReactRouter',
'react-router-dom': 'ReactRouterDOM',
},
file: `${__dirname}/../src/frontend/assets/scripts/global-bundle.${env}.js`,
file: path.join(__dirname, `../lib/frontend/assets/scripts/global-bundle.${env}.js`),
})
}

Expand Down
35 changes: 16 additions & 19 deletions bin/watch-dev.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
/**
* @private
* @fileoverview
* This script runs process, which bundles all frontend files to `app.bundle.js`.
* It reruns whenever user changes something.
*/
import * as url from 'url'
import runtime from '@babel/plugin-transform-runtime'
import styled from 'babel-plugin-styled-components'
import importAssertions from '@babel/plugin-syntax-import-assertions'

const { default: runtime } = require('@babel/plugin-transform-runtime')
const { default: styled } = require('babel-plugin-styled-components')
const bundler = require('../src/backend/bundler/bundler')
const env = require('../src/backend/bundler/bundler-env')
import bundler from '../src/backend/bundler/bundler.js'
import env from '../src/backend/bundler/bundler-env.js'

const once = !!process.env.ONCE
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

async function build() {
return bundler({
name: 'AdminJS',
input: `${__dirname}/../src/frontend/bundle-entry.jsx`,
file: `${__dirname}/../src/frontend/assets/scripts/app-bundle.${env}.js`,
input: `${__dirname}/../lib/frontend/bundle-entry.js`,
file: `${__dirname}/../lib/frontend/assets/scripts/app-bundle.${env}.js`,
minify: env === 'production',
watch: !once,
babelConfig: {
plugins: [runtime, styled],
plugins: [runtime, importAssertions, styled],
babelHelpers: 'runtime',
include: [
'src/frontend/**',
'src/locale/*',
'src/utils/**',
'src/backend/utils/view-helpers/view-helpers.ts',
'src/backend/utils/filter/filter.ts',
'src/backend/decorators/**',
'lib/frontend/**',
'lib/locale/*',
'lib/utils/**',
'lib/backend/utils/view-helpers/view-helpers.js',
'lib/backend/utils/filter/filter.js',
'lib/backend/decorators/**',
],
},
})
Expand Down
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node
// eslint-disable-next-line
require('./lib/cli').default
import('./lib/cli')
9 changes: 4 additions & 5 deletions cy/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/**
* @module cy
* @load ./cypress.doc.md
* @new in version 3.3
*/

require('./commands/ab-login')
require('./commands/ab-login-api')
require('./commands/ab-keep-logged-in')
require('./commands/ab-get-property')
import './commands/ab-login.js'
import './commands/ab-login-api.js'
import './commands/ab-keep-logged-in.js'
import './commands/ab-get-property.js'
Binary file removed docs/anim.gif
Binary file not shown.
Loading

0 comments on commit c811f2e

Please sign in to comment.