Skip to content

Commit aed323b

Browse files
authored
Merge pull request #8 from atom-community/update
2 parents faf1777 + 476f522 commit aed323b

File tree

17 files changed

+4635
-1775
lines changed

17 files changed

+4635
-1775
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "eslint-config-atomic",
3-
"ignorePatterns": ["dist/", "node_modules/"]
3+
"ignorePatterns": ["dist/", "node_modules/", "coverage/"]
44
}

.github/workflows/CI.yml

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,87 @@
11
name: CI
22
on:
3-
- push
4-
- pull_request
3+
push:
4+
branches:
5+
- master
6+
pull_request:
57

68
jobs:
79
Test:
8-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
9-
name: ${{ matrix.os }} - Atom ${{ matrix.atom_channel }}
10-
runs-on: ${{ matrix.os }}
10+
runs-on: ubuntu-22.04
11+
name: Build
12+
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
1113
strategy:
1214
fail-fast: false
1315
matrix:
1416
os:
15-
- ubuntu-latest
16-
# - macos-latest
17-
# - windows-latest
18-
atom_channel: [stable, beta]
17+
- ubuntu-22.04
18+
node:
19+
- 18
20+
pnpm:
21+
- 8
1922
steps:
2023
- uses: actions/checkout@v3
21-
- uses: UziTech/action-setup-atom@v1
22-
with:
23-
channel: ${{ matrix.atom_channel }}
2424

25-
- name: Install APM dependencies
26-
run: apm install
25+
- name: Cache
26+
uses: actions/cache@v3
27+
with:
28+
path: |
29+
~/.pnpm-store
30+
D:\.pnpm-store
31+
./node_modules
32+
./.parcel-cache
33+
key: "cache-OS:${{ matrix.os }}-node:${{ matrix.node }}-pnpm:${{ matrix.pnpm }}-${{ hashFiles('./.npmrc') }}-deps:${{ hashFiles('./package.json') }}"
34+
restore-keys: |
35+
"cache-OS:${{ matrix.os }}-"
2736
28-
- name: Tests
29-
run: npm run test
37+
- name: Setup Node
38+
uses: actions/setup-node@v3
39+
with:
40+
node-version: ${{ matrix.node }}
3041

31-
Lint:
32-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
33-
runs-on: ubuntu-latest
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
steps:
37-
- uses: actions/checkout@v3
42+
- name: Setup Pnpm
43+
uses: pnpm/action-setup@v2
3844
with:
39-
fetch-depth: 0
40-
- name: Commit lint ✨
41-
uses: wagoid/commitlint-github-action@v5
45+
version: ${{ matrix.pnpm }}
4246

43-
- name: Install dependencies
44-
run: npm install
47+
- name: Install
48+
run: |
49+
pnpm install
4550
46-
# - name: Format ✨
47-
# run: npm run test.format
51+
- name: Build
52+
run: |
53+
pnpm build
4854
49-
- name: Lint ✨
50-
run: npm run test.lint
55+
- name: Lint
56+
run: |
57+
pnpm run test.lint
58+
pnpm run test.format
59+
60+
- name: Test
61+
run: |
62+
pnpm run test
5163
5264
Release:
53-
needs: [Test, Lint]
65+
needs: [Test]
5466
if: github.ref == 'refs/heads/master' &&
5567
github.event.repository.fork == false
5668
runs-on: ubuntu-latest
5769
steps:
5870
- uses: actions/checkout@v3
59-
- uses: UziTech/action-setup-atom@v1
60-
- uses: actions/setup-node@v3
6171

62-
- name: NPM install
63-
run: npm install
72+
- name: Setup Node
73+
uses: actions/setup-node@v3
74+
with:
75+
node-version: 18
76+
77+
- name: Setup Pnpm
78+
uses: pnpm/action-setup@v2
79+
with:
80+
version: 8
81+
82+
- name: Install
83+
run: |
84+
pnpm install
6485
6586
- name: Release 🎉
6687
uses: cycjimmy/semantic-release-action@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ package-lock.json
1111

1212
# Build directories
1313
dist
14+
coverage/

.npmrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
public-hoist-pattern[]=*
21
package-lock=false
32
lockfile=true
4-
prefer-frozen-lockfile=false

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ The config is adapted based on `NODE_ENV`, so make sure to run your scripts with
4343

4444
**Note**: [`cross-env`](https://www.npmjs.com/package/cross-env) is an npm package that you need to install.
4545

46+
## Options
47+
48+
You can import the builder function to create a custom config:
49+
50+
```ts
51+
import { buildTerserOptions } from "terser-config-atomic/dist/builder.js"
52+
module.exports = buildTerserOptions(process.env.NODE_ENV, process.env.BABEL_ENV)
53+
```
54+
55+
The builder function:
56+
57+
```ts
58+
/**
59+
* Get the terser options for the given environment.
60+
*
61+
* @param NODE_ENV - The Node environment (defaults to "production").
62+
* @param BABEL_ENV - The Babel environment (defaults to NODE_ENV).
63+
* @param unsafeCompress - Whether to use unsafe compression options (defaults to false).
64+
*/
65+
export function buildTerserOptions(
66+
NODE_ENV: string = "production",
67+
BABEL_ENV: string | undefined = undefined,
68+
unsafeCompress: boolean = false,
69+
)
70+
```
71+
4672
## Modifying the config
4773

4874
To change the config use the following pattern:

__tests__/index.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import assert from "assert"
2+
import { buildTerserOptions } from "../src/builder"
3+
4+
describe("Terser-Config-Atomic", () => {
5+
it("production", () => {
6+
const TerserOptions = buildTerserOptions("production", undefined)
7+
8+
expect(typeof TerserOptions).toBe("object")
9+
assert(typeof TerserOptions.compress === "object")
10+
expect(TerserOptions.compress.global_defs).toEqual({
11+
"process.env.NODE_ENV": "production",
12+
"process.env.BABEL_ENV": "production",
13+
"@atom.inSpecMode": "() => false",
14+
"@atom.inDevMode": "() => false",
15+
})
16+
expect(TerserOptions.compress.passes).toBe(2)
17+
expect(TerserOptions.mangle).toBe(true)
18+
expect(TerserOptions.format.beautify).toBe(false)
19+
})
20+
it("development", () => {
21+
process.env.NODE_ENV = "development"
22+
23+
const TerserOptions = buildTerserOptions("development", undefined)
24+
25+
expect(typeof TerserOptions).toBe("object")
26+
expect(TerserOptions.compress).toBe(false)
27+
expect(TerserOptions.mangle).toBe(false)
28+
expect(TerserOptions.format.beautify).toBe(true)
29+
})
30+
it("test", () => {
31+
process.env.NODE_ENV = "test"
32+
33+
const TerserOptions = buildTerserOptions("test", undefined)
34+
35+
expect(typeof TerserOptions).toBe("object")
36+
assert(typeof TerserOptions.compress === "object")
37+
expect(TerserOptions.compress.global_defs).toEqual({
38+
"process.env.NODE_ENV": "test",
39+
"process.env.BABEL_ENV": "test",
40+
"@atom.inSpecMode": "() => true",
41+
"@atom.inDevMode": "() => false",
42+
})
43+
expect(TerserOptions.compress.passes).toBe(2)
44+
expect(TerserOptions.mangle).toBe(false)
45+
expect(TerserOptions.format.beautify).toBe(true)
46+
})
47+
})

jest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Config } from "jest"
2+
3+
const jestConfig: Config = {
4+
testMatch: ["**/*.test.ts"],
5+
testEnvironment: "node",
6+
extensionsToTreatAsEsm: [".ts", ".tsx", ".jsx"],
7+
transformIgnorePatterns: [], // transform node_modules
8+
transform: {
9+
"^.+\\.(t|j)sx?$": "@swc/jest",
10+
},
11+
// coverage
12+
collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"],
13+
coveragePathIgnorePatterns: ["assets", ".css.d.ts"],
14+
verbose: true,
15+
}
16+
17+
export default jestConfig

package.json

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
11
{
22
"name": "terser-config-atomic",
3-
"main": "./src/.terserrc.js",
43
"version": "0.1.1",
5-
"files": [
6-
"src"
7-
],
8-
"author": "Amin Yahyaabadi",
94
"description": "The Terser configuration used in atom-community",
10-
"keywords": [
11-
"terser",
12-
"minify",
13-
"preset",
14-
"config"
15-
],
165
"repository": "https://github.com/atom-community/terser-config-atomic",
176
"license": "MIT",
7+
"author": "Amin Yahyaabadi",
8+
"main": "dist/terserrc.js",
9+
"files": [
10+
"src",
11+
"dist"
12+
],
1813
"scripts": {
14+
"build": "tsc -p tsconfig.build.json",
15+
"bump": "ncu -u",
1916
"format": "prettier --write .",
20-
"test.format": "prettier . --check",
2117
"lint": "eslint . --fix",
22-
"test.lint": "eslint .",
23-
"bump": "ncu -u",
24-
"test": "atom --test ./test/"
18+
"prepublishOnly": "npm run build",
19+
"test": "jest",
20+
"test.format": "prettier . --check",
21+
"test.lint": "eslint ."
2522
},
26-
"atomTestRunner": "./test/runner",
23+
"prettier": "prettier-config-atomic",
2724
"devDependencies": {
28-
"atom-jasmine3-test-runner": "^5.2.6",
29-
"eslint": "^7.29.0",
30-
"eslint-config-atomic": "^1.16.1",
31-
"prettier": "^2.3.1",
32-
"prettier-config-atomic": "^2.0.5",
33-
"requirefresh": "^5.1.0"
34-
}
35-
}
25+
"@swc/jest": "^0.2.29",
26+
"@types/jest": "^29.5.4",
27+
"@types/node": "^20.5.9",
28+
"eslint": "^8.48.0",
29+
"eslint-config-atomic": "^1.19.3",
30+
"jest": "^29.6.4",
31+
"prettier": "^3.0.3",
32+
"prettier-config-atomic": "^3.1.0",
33+
"ts-node": "^10.9.1",
34+
"typescript": "^5.2.2"
35+
},
36+
"keywords": [
37+
"terser",
38+
"minify",
39+
"preset",
40+
"config"
41+
]
42+
}

0 commit comments

Comments
 (0)