Skip to content

Commit 7d48ab9

Browse files
committed
fix: add getTerserrc function and fix the tests
1 parent c7f79ff commit 7d48ab9

6 files changed

Lines changed: 53 additions & 71 deletions

File tree

__tests__/index.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import { requireFresh } from "requirefresh"
21
import assert from "assert"
3-
import * as path from "path"
4-
5-
type Terserrc = typeof import("../src/.terserrc")
6-
function requireTerserrc(): Terserrc {
7-
return requireFresh(path.join(path.dirname(__dirname), "src", ".terserrc.js"))
8-
}
2+
import { getTerserrc } from "../src/get-terserrc.js"
93

104
describe("Terser-Config-Atomic", () => {
115
it("production", () => {
12-
process.env.NODE_ENV = "production"
13-
14-
const TerserOptions = requireTerserrc()
6+
const TerserOptions = getTerserrc("production", undefined)
157

168
expect(typeof TerserOptions).toBe("object")
179
assert(typeof TerserOptions.compress === "object")
@@ -28,7 +20,7 @@ describe("Terser-Config-Atomic", () => {
2820
it("development", () => {
2921
process.env.NODE_ENV = "development"
3022

31-
const TerserOptions = requireTerserrc()
23+
const TerserOptions = getTerserrc("development", undefined)
3224

3325
expect(typeof TerserOptions).toBe("object")
3426
expect(TerserOptions.compress).toBe(false)
@@ -38,7 +30,7 @@ describe("Terser-Config-Atomic", () => {
3830
it("test", () => {
3931
process.env.NODE_ENV = "test"
4032

41-
const TerserOptions = requireTerserrc()
33+
const TerserOptions = getTerserrc("test", undefined)
4234

4335
expect(typeof TerserOptions).toBe("object")
4436
assert(typeof TerserOptions.compress === "object")

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"jest": "^29.6.4",
3333
"prettier": "^3.0.3",
3434
"prettier-config-atomic": "^3.1.0",
35-
"requirefresh": "^5.4.0",
3635
"ts-node": "^10.9.1"
3736
}
3837
}

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.terserrc.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,2 @@
1-
const isDev = process.env.NODE_ENV === "development"
2-
const isTest = process.env.NODE_ENV === "test"
3-
const isReadable = isDev || isTest
4-
5-
const ProductionCompress = {
6-
global_defs: {
7-
// remove dev and test specific code for production
8-
"process.env.NODE_ENV": process.env.NODE_ENV || "production",
9-
"process.env.BABEL_ENV": process.env.BABEL_ENV || process.env.NODE_ENV || "production",
10-
"@atom.inSpecMode": !isTest ? "() => false" : "() => true",
11-
"@atom.inDevMode": !isDev ? "() => false" : "() => true",
12-
},
13-
ecma: "2018",
14-
toplevel: true,
15-
hoist_vars: false,
16-
hoist_funs: true,
17-
pure_getters: true,
18-
unsafe: true,
19-
unsafe_arrows: true,
20-
unsafe_comps: true,
21-
unsafe_Function: true,
22-
unsafe_math: true,
23-
unsafe_symbols: true,
24-
unsafe_methods: true,
25-
unsafe_proto: true,
26-
unsafe_regexp: true,
27-
unsafe_undefined: true,
28-
passes: 3,
29-
}
30-
31-
const TerserOptions = {
32-
// "module": false, // controlled by Parcel
33-
compress: isDev ? false : ProductionCompress,
34-
parse: {
35-
ecma: 2020,
36-
},
37-
mangle: isReadable ? false : true,
38-
format: {
39-
beautify: isReadable,
40-
},
41-
}
42-
module.exports = TerserOptions
1+
const { getTerserRc } = require("./get-terserrc.js")
2+
module.exports = getTerserRc(process.env.NODE_ENV, process.env.BABEL_ENV)

src/get-terserrc.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function getTerserrc(NODE_ENV, BABEL_ENV) {
2+
const isDev = NODE_ENV === "development"
3+
const isTest = NODE_ENV === "test"
4+
const isReadable = isDev || isTest
5+
6+
const ProductionCompress = {
7+
global_defs: {
8+
// remove dev and test specific code for production
9+
"process.env.NODE_ENV": NODE_ENV || "production",
10+
"process.env.BABEL_ENV": BABEL_ENV || NODE_ENV || "production",
11+
"@atom.inSpecMode": !isTest ? "() => false" : "() => true",
12+
"@atom.inDevMode": !isDev ? "() => false" : "() => true",
13+
},
14+
ecma: "2018",
15+
toplevel: true,
16+
hoist_vars: false,
17+
hoist_funs: true,
18+
pure_getters: true,
19+
unsafe: true,
20+
unsafe_arrows: true,
21+
unsafe_comps: true,
22+
unsafe_Function: true,
23+
unsafe_math: true,
24+
unsafe_symbols: true,
25+
unsafe_methods: true,
26+
unsafe_proto: true,
27+
unsafe_regexp: true,
28+
unsafe_undefined: true,
29+
passes: 3,
30+
}
31+
32+
const TerserOptions = {
33+
// "module": false, // controlled by Parcel
34+
compress: isDev ? false : ProductionCompress,
35+
parse: {
36+
ecma: 2020,
37+
},
38+
mangle: isReadable ? false : true,
39+
format: {
40+
beautify: isReadable,
41+
},
42+
}
43+
return TerserOptions
44+
}
45+
exports.getTerserrc = getTerserrc

tsconfig.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"preserveSymlinks": true,
1818
"removeComments": false,
1919
"skipLibCheck": true,
20-
"lib": [
21-
"ES2021",
22-
],
20+
"lib": ["ES2021"],
2321
"target": "ES2021",
2422
"allowJs": true,
2523
"esModuleInterop": true,
@@ -30,9 +28,5 @@
3028
"outDir": "./dist"
3129
},
3230
"compileOnSave": false,
33-
"include": [
34-
"./src",
35-
"./jest.config.ts",
36-
"./__tests__"
37-
]
31+
"include": ["./src", "./jest.config.ts", "./__tests__"]
3832
}

0 commit comments

Comments
 (0)