Skip to content

Commit 8124eed

Browse files
refactor(global): migrate rollup build to tsup (#25)
* feat(configs)!: rollup replaced with tsup for speed and simplicity * refactor(global): migrate rollup build to tsup * chore(global): sync yarn.lock * chore(commit-analyzer): remove redundant rollup file * chore(mono-pub): removed declarationsDir from ts config * chore(mono-pub): fixed semgrep issues
1 parent 54d9f82 commit 8124eed

21 files changed

+1012
-511
lines changed

packages/commit-analyzer/package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"lint": "eslint src && prettier --check src",
12-
"build": "rollup -c"
12+
"build": "tsup"
1313
},
1414
"author": {
1515
"name": "Matthew Savelev",
@@ -20,9 +20,13 @@
2020
"files": [
2121
"dist"
2222
],
23-
"main": "./dist/index.cjs",
24-
"module": "./dist/index.mjs",
25-
"types": "./dist/index.d.ts",
23+
"exports": {
24+
".": {
25+
"types": "./dist/index.d.ts",
26+
"require": "./dist/index.js",
27+
"import": "./dist/index.mjs"
28+
}
29+
},
2630
"peerDependencies": {
2731
"mono-pub": "1.x"
2832
},
@@ -31,7 +35,7 @@
3135
"@types/conventional-commits-parser": "^3.0.3",
3236
"eslint": "^9.16.0",
3337
"mono-pub": "workspace:^",
34-
"rollup": "^3.29.5",
38+
"tsup": "^8.3.5",
3539
"typescript": "^5.7.2"
3640
},
3741
"dependencies": {

packages/commit-analyzer/rollup.config.mjs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createRequire } from 'node:module'
2+
import { createBuildPipeline } from '@mono-pub/configs/tsup'
3+
4+
const require = createRequire(import.meta.url)
5+
const pkg = require('./package.json')
6+
7+
export default createBuildPipeline(pkg.exports)

packages/configs/package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,26 @@
88
"directory": "packages/configs"
99
},
1010
"files": [
11-
"eslint.js",
12-
"rollup.js",
11+
"eslint.config.mjs",
12+
"tsup.mjs",
1313
"tsconfig.json"
1414
],
1515
"exports": {
1616
"./tsconfig": "./tsconfig.json",
1717
"./eslint": "./eslint.config.mjs",
18-
"./rollup": "./rollup.js"
18+
"./tsup": "./tsup.mjs"
1919
},
2020
"peerDependencies": {
21-
"jest": "*"
21+
"jest": "*",
22+
"tsup": "^8"
2223
},
2324
"devDependencies": {
2425
"@eslint/js": "^9.16.0",
25-
"@rollup/plugin-alias": "^5.0.0",
26-
"@rollup/plugin-json": "^6.0.0",
27-
"@rollup/plugin-typescript": "^11.1.0",
2826
"eslint": "^9.16.0",
2927
"eslint-import-resolver-typescript": "^3.7.0",
3028
"eslint-plugin-import": "^2.31.0",
3129
"eslint-plugin-jest": "^28.9.0",
32-
"rollup-plugin-delete": "^2.0.0",
33-
"rollup-plugin-dts": "^5.3.0",
34-
"rollup-plugin-node-externals": "^5.1.2",
35-
"rollup-plugin-sourcemaps": "^0.6.3",
30+
"tsup": "^8.3.5",
3631
"typescript": "^5.7.2",
3732
"typescript-eslint": "^8.17.0"
3833
},

packages/configs/rollup.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

packages/configs/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Base",
44
"compilerOptions": {
5-
"target": "ES6",
6-
"module": "Node16",
5+
"target": "ES2022",
6+
"module": "NodeNext",
77
"allowSyntheticDefaultImports": true,
88
"declaration": true,
99
"declarationMap": true,
@@ -12,7 +12,7 @@
1212
"inlineSources": false,
1313
"importHelpers": true,
1414
"isolatedModules": true,
15-
"moduleResolution": "Node16",
15+
"moduleResolution": "NodeNext",
1616
"noUnusedLocals": true,
1717
"noUnusedParameters": true,
1818
"preserveWatchOutput": true,

packages/configs/tsup.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import path from 'path'
2+
import { lstatSync, existsSync } from 'fs'
3+
import { defineConfig } from 'tsup'
4+
5+
const ALLOWED_EXTENSIONS = ['.ts']
6+
7+
function _getInputs(exports) {
8+
return Object.keys(exports).map((relativeImport) => {
9+
// NOTE: path utils are expected and part of logic here
10+
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
11+
const srcPath = path.join('src', relativeImport)
12+
const isDirectory = existsSync(srcPath) && lstatSync(srcPath).isDirectory()
13+
14+
// NOTE: path utils are expected and part of logic here
15+
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
16+
const pathToFile = isDirectory ? path.join(srcPath, 'index') : srcPath
17+
18+
const ext = ALLOWED_EXTENSIONS.find((extension) => existsSync(`${pathToFile}${extension}`))
19+
if (!ext) throw new Error(`No allowed extensions found for file: ${relativeImport}`)
20+
21+
return `${pathToFile}${ext}`
22+
})
23+
}
24+
25+
export function createBuildPipeline(exports) {
26+
return defineConfig({
27+
entry: _getInputs(exports),
28+
clean: true,
29+
dts: true,
30+
sourcemap: true,
31+
format: ['cjs', 'esm'],
32+
target: 'node16',
33+
minify: true,
34+
splitting: false,
35+
})
36+
}

packages/git/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"lint": "eslint src && prettier --check src",
12-
"build": "rollup -c"
12+
"build": "tsup"
1313
},
1414
"author": {
1515
"name": "Matthew Savelev",
@@ -32,14 +32,14 @@
3232
},
3333
"exports": {
3434
".": {
35-
"require": "./dist/index.cjs",
36-
"import": "./dist/index.mjs",
37-
"types": "./dist/index.d.ts"
35+
"types": "./dist/index.d.ts",
36+
"require": "./dist/index.js",
37+
"import": "./dist/index.mjs"
3838
},
3939
"./utils": {
40-
"require": "./dist/utils.cjs",
41-
"import": "./dist/utils.mjs",
42-
"types": "./dist/utils.d.ts"
40+
"types": "./dist/utils/index.d.ts",
41+
"require": "./dist/utils/index.js",
42+
"import": "./dist/utils/index.mjs"
4343
}
4444
},
4545
"peerDependencies": {
@@ -49,8 +49,8 @@
4949
"@mono-pub/configs": "workspace:^",
5050
"eslint": "^9.16.0",
5151
"mono-pub": "workspace:^",
52-
"rollup": "^3.29.5",
5352
"tmp": "^0.2.1",
53+
"tsup": "^8.3.5",
5454
"typescript": "^5.0.4"
5555
},
5656
"dependencies": {

packages/git/rollup.config.mjs

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/git/tsup.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createRequire } from 'node:module'
2+
import { createBuildPipeline } from '@mono-pub/configs/tsup'
3+
4+
const require = createRequire(import.meta.url)
5+
const pkg = require('./package.json')
6+
7+
export default createBuildPipeline(pkg.exports)

0 commit comments

Comments
 (0)