Skip to content

Commit ee78bec

Browse files
committed
feat: enhance project configuration with modern setup
1 parent 0432aa2 commit ee78bec

17 files changed

+4647
-659
lines changed

.babelrc

-6
This file was deleted.

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
dist
3+
node_modules

.eslintrc

-8
This file was deleted.

.eslintrc.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
extends: 'eslint:recommended',
3+
parser: '@babel/eslint-parser',
4+
env: {
5+
browser: true,
6+
node: true,
7+
jest: true,
8+
},
9+
plugins: [
10+
'@babel',
11+
],
12+
rules: {
13+
},
14+
};

.github/workflows/ci.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- v2
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node-version: [20.x]
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
- run: yarn
26+
- run: |
27+
yarn run eslint
28+
yarn run build
29+
yarn run test
30+
- uses: codecov/codecov-action@v4
31+
env:
32+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
node_modules
2-
/.nyc_output
1+
/build
32
/coverage
43
/dist
5-
/lib
4+
node_modules

.npmignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
/.nyc_output
2-
/coverage
3-
/dist
1+
package-lock.json
2+
yarn.lock

.travis.yml

-32
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017 Cheton Wu
3+
Copyright (c) 2017-present Cheton Wu
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# cncjs-controller [![build status](https://travis-ci.org/cncjs/cncjs-controller.svg?branch=master)](https://travis-ci.org/cncjs/cncjs-controller) [![Coverage Status](https://coveralls.io/repos/github/cncjs/cncjs-controller/badge.svg?branch=master)](https://coveralls.io/github/cncjs/cncjs-controller?branch=master)
1+
# cncjs-controller
22

33
[![NPM](https://nodei.co/npm/cncjs-controller.png?downloads=true&stars=true)](https://www.npmjs.com/package/cncjs-controller)
44

babel.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
extends: '@trendmicro/babel-config',
3+
presets: [
4+
'@babel/preset-env',
5+
],
6+
};

package.json

+46-35
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
{
22
"name": "cncjs-controller",
3-
"version": "2.0.0-alpha.2",
3+
"version": "2.0.0-alpha.3",
44
"description": "A controller library for event-based communication between client and CNCjs server.",
5-
"main": "lib/index.js",
6-
"scripts": {
7-
"prepublish": "npm run eslint && npm test && npm run clean && npm run build && npm run dist",
8-
"build": "babel --out-dir ./lib ./src",
9-
"dist": "webpack",
10-
"clean": "rm -rf lib/* dist/*",
11-
"eslint": "eslint ./src",
12-
"test": "tap test/*.js --node-arg=--require --node-arg=babel-register --node-arg=--require --node-arg=babel-polyfill",
13-
"coveralls": "tap test/*.js --coverage --coverage-report=text-lcov --nyc-arg=--require --nyc-arg=babel-register --nyc-arg=--require --nyc-arg=babel-polyfill | coveralls"
14-
},
15-
"author": "Cheton Wu <cheton@gmail.com>",
16-
"contributors": [
17-
{
18-
"name": "Cheton Wu",
19-
"email": "cheton@gmail.com",
20-
"url": "https://github.com/cheton"
21-
}
22-
],
5+
"author": "Cheton Wu",
236
"license": "MIT",
247
"repository": {
258
"type": "git",
@@ -33,25 +16,53 @@
3316
"events",
3417
"client"
3518
],
19+
"scripts": {
20+
"build": "cross-env rollup --config rollup.config.mjs",
21+
"clean": "del build coverage dist",
22+
"eslint": "eslint --ext .js,.jsx,.mjs .",
23+
"pre-push": "bash -c 'echo -e \"=> \\e[1;33m$npm_package_name\\e[0m\"' && yarn run build && yarn run eslint && yarn run test",
24+
"prepublish": "yarn run build",
25+
"test": "jest --maxWorkers=2"
26+
},
27+
"sideEffects": false,
28+
"main": "dist/cjs/index.js",
29+
"module": "dist/esm/index.js",
30+
"files": [
31+
"dist"
32+
],
3633
"dependencies": {},
3734
"devDependencies": {
38-
"babel-cli": "~6.24.1",
39-
"babel-core": "~6.24.1",
40-
"babel-eslint": "~7.2.3",
41-
"babel-preset-es2015": "~6.24.1",
42-
"babel-preset-stage-0": "~6.24.1",
43-
"coveralls": "~2.13.1",
44-
"eslint": "~3.19.0",
45-
"eslint-config-trendmicro": "~0.5.1",
46-
"eslint-plugin-import": "~2.2.0",
47-
"eslint-plugin-jsx-a11y": "~2.2.3",
48-
"eslint-plugin-react": "~6.10.0",
49-
"tap": "~10.3.2",
50-
"webpack": "~3.5.6"
35+
"@babel/cli": "^7.0.0",
36+
"@babel/core": "^7.0.0",
37+
"@babel/eslint-parser": "^7.0.0",
38+
"@babel/eslint-plugin": "^7.0.0",
39+
"@babel/plugin-transform-runtime": "^7.0.0",
40+
"@babel/preset-env": "^7.0.0",
41+
"@rollup/plugin-babel": "^6.0.0",
42+
"@rollup/plugin-node-resolve": "^15.0.0",
43+
"@trendmicro/babel-config": "^1.0.2",
44+
"cross-env": "^7.0.3",
45+
"del-cli": "^5.0.0",
46+
"eslint": "^8.25.0",
47+
"jest": "^29.0.0",
48+
"rollup": "^3"
5149
},
52-
"nyc": {
53-
"exclude": [
54-
"test/index.js"
50+
"jest": {
51+
"collectCoverage": true,
52+
"collectCoverageFrom": [
53+
"<rootDir>/src/**/*.js"
54+
],
55+
"coverageReporters": [
56+
"lcov",
57+
"text",
58+
"html"
59+
],
60+
"modulePathIgnorePatterns": [],
61+
"setupFiles": [],
62+
"setupFilesAfterEnv": [],
63+
"testEnvironment": "node",
64+
"testMatch": [
65+
"<rootDir>/**/__tests__/**/*.test.js"
5566
]
5667
}
5768
}

rollup.config.mjs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
import { babel } from '@rollup/plugin-babel';
4+
import { nodeResolve } from '@rollup/plugin-node-resolve';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const input = path.resolve(__dirname, 'src', 'index.js');
10+
const cjsOutputDirectory = path.resolve(__dirname, 'dist', 'cjs');
11+
const esmOutputDirectory = path.resolve(__dirname, 'dist', 'esm');
12+
const isExternal = id => !id.startsWith('.') && !id.startsWith('/');
13+
14+
export default [
15+
{
16+
input,
17+
output: {
18+
dir: cjsOutputDirectory,
19+
format: 'cjs',
20+
21+
// https://rollupjs.org/guide/en/#changed-defaults
22+
// https://rollupjs.org/guide/en/#outputinterop
23+
interop: 'auto',
24+
preserveModules: true,
25+
},
26+
external: isExternal,
27+
plugins: [
28+
nodeResolve(),
29+
babel({ babelHelpers: 'bundled' }),
30+
],
31+
},
32+
{
33+
input,
34+
output: {
35+
dir: esmOutputDirectory,
36+
format: 'esm',
37+
preserveModules: true,
38+
},
39+
external: isExternal,
40+
plugins: [
41+
nodeResolve(),
42+
babel({ babelHelpers: 'bundled' }),
43+
],
44+
}
45+
];

0 commit comments

Comments
 (0)