Skip to content

Commit

Permalink
Merge pull request #46 from distributed-lab/fix/tree-shaking
Browse files Browse the repository at this point in the history
Fix @distributedlab/w3p tree-shaking, next.js ESModules compatibility
  • Loading branch information
napalmpapalam authored Feb 28, 2024
2 parents 9b071b6 + e18d72f commit 857108a
Show file tree
Hide file tree
Showing 42 changed files with 445 additions and 655 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ node_modules/
.yarn/
scripts/*.js
.eslintrc.js
rollup.config.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packages/*/coverage
# Editor directories and files
.idea
.vscode/*
!.vscode/settings.json
*.suo
*.ntvs*
*.njsproj
Expand Down
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
"typescript"
],
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"[markdown]": {
"editor.formatOnSave": false
}
}
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0-rc.11] - 2024-02-28
### Changed
- `all`
- Output ESM files with `.mjs` extension
- Updated `swc` dependencies versions to the latest

### Fixed
- `@distributedlab/w3p` - Tree-shaking issues related to sub-dependencies

### Removed
- `all` - Creating extra `package.json` files in the dist folder for resolving ESM and CommonJS modules
- `all,root` - postbuild script
- `all` - CDN distributives support

## [1.0.0-rc.10] - 2024-01-18
### Fixed
- `@distributedlab/jac` - possibility to throw custom error on request
Expand Down Expand Up @@ -348,7 +362,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[old repo]: https://github.com/distributed-lab/web-kit-old

[Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.10...HEAD
[Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.11...HEAD
[1.0.0-rc.11]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.10...1.0.0-rc.11
[1.0.0-rc.10]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.9...1.0.0-rc.10
[1.0.0-rc.9]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.8...1.0.0-rc.9
[1.0.0-rc.8]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.7...1.0.0-rc.8
Expand Down
5 changes: 0 additions & 5 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const baseConfig = require('./jest.config.base')
const fs = require('fs')
const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))

module.exports = {
...baseConfig,
Expand All @@ -9,9 +7,6 @@ module.exports = {
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|tests|test).+(ts|tsx|js)',
],
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, swcrc: false, exclude: [] }],
},
moduleNameMapper: {
'^@/(.*)': '<rootDir>/src/$1',
},
Expand Down
21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
"pre-push": "yarn test && yarn rsc"
},
"scripts": {
"build": "yarn workspaces foreach -pv --topological-dev run build && yarn build:browser",
"build:browser": "rollup -c --bundleConfigAsCjs",
"build": "yarn workspaces foreach -pv --topological-dev run build",
"build:jac": "yarn workspace @distributedlab/jac build",
"build:fetcher": "yarn workspace @distributedlab/fetcher build",
"build:tools": "yarn workspace @distributedlab/tools build",
"build:reactivity": "yarn workspace @distributedlab/reactivity build",
"build:w3p": "yarn workspace @rarimo/w3p build",
"build:w3p": "yarn workspace @distributedlab/w3p build",
"docs": "typedoc --options typedoc.json",
"lint": "eslint . --ext .ts --fix --cache --max-warnings=0 && yarn workspaces foreach -pv --no-private run typecheck",
"test": "yarn workspaces foreach -pv --no-private run test",
Expand All @@ -41,16 +40,9 @@
"apply-version": "node scripts/version.js"
},
"devDependencies": {
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.53",
"@swc/jest": "^0.2.26",
"@swc/cli": "^0.3.9",
"@swc/core": "^1.4.2",
"@swc/jest": "^0.2.36",
"@types/eslint": "^8",
"@types/jest": "^29.5.1",
"@types/prettier": "^2",
Expand All @@ -63,8 +55,7 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"jest": "^29.5.0",
"prettier": "^2.8.4",
"rollup": "^3.18.0",
"rollup-plugin-polyfill-node": "^0.12.0",
"tsc-alias": "^1.8.2",
"typedoc": "^0.23.26",
"typescript": "^5.0.4",
"yorkie": "^2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/fetcher/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/src/tests/
src/**/*.test.ts
jest.config.js
tsconfig.json
tsconfig.build.json
postbuild.js
/src/tests
.swcrc
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/fetcher/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const fs = require('fs')
const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))

module.exports = {
...require('../../jest.config.base.js'),

transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, swcrc: false, exclude: [] }],
},
};
30 changes: 12 additions & 18 deletions packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/fetcher",
"version": "1.0.0-rc.10",
"version": "1.0.0-rc.11",
"description": "Fetch API wrapper with the extended functionality and simple interface",
"repository": {
"type": "git",
Expand All @@ -18,41 +18,35 @@
}
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/esm/index.js",
"module": "./dist/esm/index.mjs",
"browser": "./dist/esm/index.mjs",
"node": "./dist/cjs/index.js",
"unpkg": "./dist/index.js",
"types": "index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"node": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"default": "./dist/esm/index.js"
"import": "./dist/esm/index.mjs",
"default": "./dist/esm/index.mjs"
}
},
"scripts": {
"build": "yarn clean && yarn build:types && yarn build:cjs && yarn build:esm && node ./postbuild.js",
"build": "yarn clean && yarn build:types && yarn build:cjs && yarn build:esm && yarn build:tsc-alias",
"build:types": "tsc -p tsconfig.build.json --outDir ./dist/types --declaration --emitDeclarationOnly",
"build:cjs": "npx swc src -d ./dist/cjs --config-file ../../.swcrc -C module.type=commonjs",
"build:esm": "npx swc src -d ./dist/esm --config-file ../../.swcrc -C module.type=es6 isModule=true",
"build:cjs": "npx swc src -d ./dist/cjs --strip-leading-paths --config-file .swcrc -C module.type=commonjs",
"build:esm": "npx swc src -d ./dist/esm --strip-leading-paths --out-file-extension mjs --config-file .swcrc -C isModule=true",
"build:tsc-alias": "tsc-alias -p tsconfig.json --outDir ./dist/types",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"test": "yarn jest --verbose"
"test": "yarn jest --verbose",
"typecheck": "tsc --noEmit"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.53",
"@swc/jest": "^0.2.26",
"@types/jest": "^29.5.1",
"@types/node": "^18.14.2",
"@types/uuid": "^9",
"jest": "^29.5.0",
"tsc-alias": "^1.8.2"
"jest": "^29.5.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
Expand Down
3 changes: 0 additions & 3 deletions packages/fetcher/postbuild.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/jac/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ src/**/*.test.ts
jest.config.js
tsconfig.json
tsconfig.build.json
postbuild.js
.swcrc
31 changes: 31 additions & 0 deletions packages/jac/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": false,
"dynamicImport": false,
"privateMethod": true,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false
},
"baseUrl": ".",
"transform": null,
"target": "es2016",
"loose": false,
"externalHelpers": false,
"keepClassNames": true,
"preserveAllComments": true,
"paths": {
"@/*": ["src/*"]
}
},
"exclude": ["examples","src/tests", ".test.ts"],
"minify": false,
"sourceMaps": "inline"
}
7 changes: 7 additions & 0 deletions packages/jac/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const fs = require('fs')
const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))

module.exports = {
...require('../../jest.config.base.js'),

transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, swcrc: false, exclude: [] }],
},
};
26 changes: 10 additions & 16 deletions packages/jac/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/jac",
"version": "1.0.0-rc.10",
"version": "1.0.0-rc.11",
"description": "A library for constructing JSON-API compliant requests and responses",
"repository": {
"type": "git",
Expand All @@ -18,25 +18,25 @@
}
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/esm/index.js",
"module": "./dist/esm/index.mjs",
"browser": "./dist/esm/index.mjs",
"node": "./dist/cjs/index.js",
"unpkg": "./dist/index.js",
"types": "index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"node": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"default": "./dist/esm/index.js"
"import": "./dist/esm/index.mjs",
"default": "./dist/esm/index.mjs"
}
},
"scripts": {
"build": "yarn clean && yarn build:types && yarn build:cjs && yarn build:esm && node ./postbuild.js",
"build": "yarn clean && yarn build:types && yarn build:cjs && yarn build:esm && yarn build:tsc-alias",
"build:types": "tsc -p tsconfig.build.json --outDir ./dist/types --declaration --emitDeclarationOnly",
"build:cjs": "npx swc src -d ./dist/cjs --config-file ../../.swcrc -C module.type=commonjs",
"build:esm": "npx swc src -d ./dist/esm --config-file ../../.swcrc -C module.type=es6 isModule=true",
"build:cjs": "npx swc src -d ./dist/cjs --strip-leading-paths --config-file .swcrc -C module.type=commonjs",
"build:esm": "npx swc src -d ./dist/esm --strip-leading-paths --out-file-extension mjs --config-file .swcrc -C isModule=true",
"build:tsc-alias": "tsc-alias -p tsconfig.json --outDir ./dist/types",
"clean": "rm -rf dist",
"test": "yarn jest --verbose",
"typecheck": "tsc --noEmit"
Expand All @@ -45,14 +45,8 @@
"access": "public"
},
"devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.53",
"@swc/jest": "^0.2.26",
"@types/jest": "^29.5.1",
"@types/lodash": "^4",
"@types/node": "^18.14.2",
"jest": "^29.5.0",
"tsc-alias": "^1.8.2"
"jest": "^29.5.0"
},
"dependencies": {
"@distributedlab/fetcher": "workspace:*",
Expand Down
3 changes: 0 additions & 3 deletions packages/jac/postbuild.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/reactivity/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ src/**/*.test.ts
jest.config.js
tsconfig.json
tsconfig.build.json
postbuild.js
.swcrc
31 changes: 31 additions & 0 deletions packages/reactivity/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": false,
"dynamicImport": false,
"privateMethod": true,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false
},
"baseUrl": ".",
"transform": null,
"target": "es2016",
"loose": false,
"externalHelpers": false,
"keepClassNames": true,
"preserveAllComments": true,
"paths": {
"@/*": ["src/*"]
}
},
"exclude": ["examples","src/tests", ".test.ts"],
"minify": false,
"sourceMaps": "inline"
}
7 changes: 7 additions & 0 deletions packages/reactivity/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const fs = require('fs')
const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))

module.exports = {
...require('../../jest.config.base.js'),

transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, swcrc: false, exclude: [] }],
},
};
Loading

0 comments on commit 857108a

Please sign in to comment.