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(bundle): change bundling configuration #5

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions .configs/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as esbuild from 'esbuild';
import readPkg from 'read-pkg';

const pkg = readPkg.sync();

if (process.env.FORMAT !== 'cjs' && process.env.FORMAT !== 'esm') {
console.log(`support "cjs" or "esm"`);
console.log(`eg. FORMAT=cjs node esbuild.mjs`);

process.exit(1);
}

console.log('esbuild start bundling');
console.log(`version: ${pkg.version}`);
console.log(`FORMAT: ${process.env.FORMAT}`);
console.log(`MINIFY: ${process.env.FORMAT}`);

console.log('external: ');

await esbuild.build({
entryPoints: ['src/index.ts'],
target: 'es2021',
bundle: true,
sourcemap: true,
platform: 'node',
minify: process.env.MINIFY === 'true',
outfile: process.env.FORMAT === 'cjs' ? 'dist/cjs/index.cjs' : 'dist/esm/index.mjs',
format: process.env.FORMAT,
external: [
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.devDependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
],
});
1 change: 0 additions & 1 deletion .configs/jest.setup.cjs

This file was deleted.

35 changes: 0 additions & 35 deletions .configs/rollup.config.dev.ts

This file was deleted.

28 changes: 28 additions & 0 deletions .configs/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import readPackage from 'read-pkg';
import { dts } from 'rollup-plugin-dts';

const pkg = readPackage.sync();

const resolveOnly = (module) => {
return (
pkg?.dependencies?.[module] != null &&
pkg?.devDependencies?.[module] != null &&
pkg?.peerDependencies?.[module] != null
);
};

const config = [
{
input: 'dist/types/origin/index.d.ts',
output: [{ file: 'dist/types/index.d.ts', format: 'esm' }],
plugins: [
nodeResolve({ resolveOnly }),
dts({
tsconfig: './tsconfig.dts.json',
}),
],
},
];

export default config;
79 changes: 0 additions & 79 deletions .configs/rollup.config.prod.ts

This file was deleted.

72 changes: 48 additions & 24 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
env: {
es6: true,
node: true,
browser: true,
},
ignorePatterns: ['__test__/*', '__tests__/*', 'examples/*', 'coverage/*', 'dist/*'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.eslint.json'],
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
},
extends: [
Expand All @@ -22,6 +22,31 @@ module.exports = {
],
plugins: ['@typescript-eslint', 'prettier', 'import'],
rules: {
// ----------------------------------------------------------------------------------------------------------
// eslint
// ----------------------------------------------------------------------------------------------------------
'max-len': [
'error',
{
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreComments: true,
ignoreTrailingComments: true,
code: 120,
},
],
'no-underscore-dangle': ['error', { allowAfterThis: true }],
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration:not([const=true])',
message: "Don't declare non-const enums",
},
],
// ----------------------------------------------------------------------------------------------------------
// @typescript-eslint
// ----------------------------------------------------------------------------------------------------------
'@typescript-eslint/naming-convention': [
'error',
{
Expand Down Expand Up @@ -61,54 +86,53 @@ module.exports = {
argsIgnorePattern: '^_.+$',
},
],
'max-len': [
'error',
{
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreComments: true,
ignoreTrailingComments: true,
code: 120,
},
],
'no-underscore-dangle': ['error', { allowAfterThis: true }],
'no-restricted-syntax': [
'@typescript-eslint/consistent-type-imports': [
'error',
{
selector: 'TSEnumDeclaration:not([const=true])',
message: "Don't declare non-const enums",
prefer: 'type-imports',
},
],
// ----------------------------------------------------------------------------------------------------------
// eslint-plugin-import
// ----------------------------------------------------------------------------------------------------------
'import/prefer-default-export': ['off'],
'import/no-default-export': ['error'],
},
overrides: [
{
files: ['scripts/**/*.ts', 'scripts/**/*.cjs', 'jest.config.cjs'],
files: ['**/scripts/*.js'],
rules: {
'import/no-extraneous-dependencies': ['off'],
'@typescript-eslint/no-unsafe-assignment': ['off'],
'no-console': ['off'],
},
},
{
files: ['src/configs/config.ts', 'src/tools/i18n/i18n.ts'],
files: ['**/CE_*.ts'],
rules: {
'@typescript-eslint/no-unsafe-assignment': ['off'],
'@typescript-eslint/no-redeclare': ['off'],
'@typescript-eslint/naming-convention': ['off'],
},
},
{
files: ['**/__tests__/*.ts'],
rules: {
'@typescript-eslint/no-unsafe-assignment': ['off'],
'@typescript-eslint/no-unsafe-argument': ['off'],
'@typescript-eslint/no-unsafe-member-access': ['off'],
'@typescript-eslint/ban-ts-comment': ['off'],
'no-console': ['off'],
},
},
{
files: ['vitest.config.ts'],
rules: {
'import/no-extraneous-dependencies': ['off'],
'import/no-default-export': ['off'],
},
},
],
settings: {
'import/resolver': {
typescript: {
// always try to resolve types under `<root>@types` directory even it doesn't contain any source code,
// like `@types/unist`
alwaysTryTypes: true,
project: 'tsconfig.eslint.json',
},
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm test
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm run clean
- run: pnpm run test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6 changes: 3 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ yellow='\033[0;33m'
no_color='\033[0m'

echo -e "\n ${yellow}* code lint start.${no_color}"
npm run lint-staged
pnpm run lint-staged
echo -e "\n ${yellow}* code lint end.${no_color}"

echo -e "\n ${yellow}* code build start.${no_color}"
npm run build
pnpm run build
echo -e "\n ${yellow}* code build end.${no_color}"

echo -e "\n ${yellow}* code build start.${no_color}"
npm run test
pnpm run test
echo -e "\n ${yellow}* code build end.${no_color}"

echo -e "\n ${green}* pre-commit hook was SUCCESSFUL${no_color} \n"
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.20.0
18.20.2
14 changes: 4 additions & 10 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"printWidth": 120,
"arrowParens": "always",
"parser": "typescript",
"plugins": ["prettier-plugin-organize-imports"],
"endOfLine": "lf",
"overrides": [
{
Expand All @@ -12,17 +13,10 @@
"parser": "markdown"
}
},
{
"files": ".tjsclirc",
"options": {
"parser": "json5"
}
},
{
"files": [
".vscode/launch.json",
".vscode/settings.json",
"tsconfig.prod.json",
".vscode/**/*.json",
"tsconfig.*.json",
"tsconfig.json"
],
"options": {
Expand Down
Loading
Loading