@samual/rolldown-config 0.0.1-aead861 → 0.0.1-bc3dee8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/default.js +90 -64
- package/package.json +2 -8
package/LICENSE
CHANGED
package/default.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import { parseAsync, traverse } from "@babel/core"
|
|
2
|
-
import babelPluginSyntaxTypescript from "@babel/plugin-syntax-typescript"
|
|
3
|
-
import babelPresetEnv from "@babel/preset-env"
|
|
4
|
-
import babelPresetTypescript from "@babel/preset-typescript"
|
|
5
|
-
import { babel } from "@rollup/plugin-babel"
|
|
6
|
-
import terser from "@rollup/plugin-terser"
|
|
7
|
-
import { expect } from "@samual/assert"
|
|
8
|
-
import { babelPluginHere } from "babel-plugin-here"
|
|
9
|
-
import { babelPluginVitest } from "babel-plugin-vitest"
|
|
10
|
-
import { defu } from "defu"
|
|
11
|
-
import { readdir } from "fs/promises"
|
|
12
|
-
import { cpus } from "os"
|
|
13
|
-
import * as Path from "path"
|
|
14
|
-
import { dts } from "rolldown-plugin-dts"
|
|
15
|
-
import prettier from "rolldown-plugin-prettier"
|
|
16
|
-
const rolldownConfig = async ({
|
|
1
|
+
import { parseAsync, traverse } from "@babel/core"
|
|
2
|
+
import babelPluginSyntaxTypescript from "@babel/plugin-syntax-typescript"
|
|
3
|
+
import babelPresetEnv from "@babel/preset-env"
|
|
4
|
+
import babelPresetTypescript from "@babel/preset-typescript"
|
|
5
|
+
import { babel } from "@rollup/plugin-babel"
|
|
6
|
+
import terser from "@rollup/plugin-terser"
|
|
7
|
+
import { expect } from "@samual/assert"
|
|
8
|
+
import { babelPluginHere } from "babel-plugin-here"
|
|
9
|
+
import { babelPluginVitest } from "babel-plugin-vitest"
|
|
10
|
+
import { defu } from "defu"
|
|
11
|
+
import { readdir } from "fs/promises"
|
|
12
|
+
import { cpus } from "os"
|
|
13
|
+
import * as Path from "path"
|
|
14
|
+
import { dts } from "rolldown-plugin-dts"
|
|
15
|
+
import prettier from "rolldown-plugin-prettier"
|
|
16
|
+
const rolldownConfig = async ({
|
|
17
|
+
sourcePath = "src",
|
|
18
|
+
rolldownOptions,
|
|
19
|
+
babelOptions,
|
|
20
|
+
terserOptions,
|
|
21
|
+
prettierOptions,
|
|
22
|
+
experimental
|
|
23
|
+
} = {}) => {
|
|
17
24
|
prettierOptions = defu(prettierOptions, {
|
|
18
25
|
parser: "espree",
|
|
19
26
|
useTabs: !0,
|
|
@@ -22,63 +29,82 @@ const rolldownConfig = async ({ sourcePath = "src", rolldownOptions, babelOption
|
|
|
22
29
|
printWidth: 120,
|
|
23
30
|
semi: !1,
|
|
24
31
|
trailingComma: "none"
|
|
25
|
-
})
|
|
32
|
+
})
|
|
26
33
|
const config = defu(rolldownOptions, {
|
|
27
|
-
external:
|
|
28
|
-
input: Object.fromEntries(
|
|
29
|
-
withFileTypes: !0,
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
external: source => !(Path.isAbsolute(source) || source.startsWith(".")),
|
|
35
|
+
input: Object.fromEntries(
|
|
36
|
+
(await readdir(sourcePath, { withFileTypes: !0, recursive: !0 }))
|
|
37
|
+
.filter(dirent => dirent.isFile())
|
|
38
|
+
.map(dirent => Path.join(dirent.parentPath, dirent.name))
|
|
39
|
+
.filter(
|
|
40
|
+
path =>
|
|
41
|
+
(path.endsWith(".js") && !path.endsWith(".test.js")) ||
|
|
42
|
+
(path.endsWith(".ts") && !path.endsWith(".d.ts") && !path.endsWith(".test.ts"))
|
|
43
|
+
)
|
|
44
|
+
.map(path => [path.slice(sourcePath.length + 1, -3), path])
|
|
45
|
+
),
|
|
32
46
|
output: { dir: "dist" },
|
|
33
47
|
plugins: [
|
|
34
|
-
babel(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
sequences: !1,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})),
|
|
48
|
+
babel(
|
|
49
|
+
defu(babelOptions, {
|
|
50
|
+
babelHelpers: "bundled",
|
|
51
|
+
extensions: [".ts"],
|
|
52
|
+
presets: [
|
|
53
|
+
[babelPresetEnv, { targets: { node: "22.12" } }],
|
|
54
|
+
[babelPresetTypescript, { allowDeclareFields: !0, optimizeConstEnums: !0 }]
|
|
55
|
+
],
|
|
56
|
+
plugins: [babelPluginHere(), babelPluginVitest()]
|
|
57
|
+
})
|
|
58
|
+
),
|
|
59
|
+
terser(
|
|
60
|
+
defu(terserOptions, {
|
|
61
|
+
compress: { passes: Infinity, unsafe: !0, sequences: !1, keep_infinity: !0 },
|
|
62
|
+
maxWorkers: Math.floor(cpus().length / 2),
|
|
63
|
+
mangle: !1,
|
|
64
|
+
ecma: 2020
|
|
65
|
+
})
|
|
66
|
+
),
|
|
54
67
|
experimental?.noSideEffects && {
|
|
55
68
|
name: "no-side-effects",
|
|
56
69
|
async renderChunk(code) {
|
|
57
|
-
const ast = expect(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
const ast = expect(
|
|
71
|
+
await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] }),
|
|
72
|
+
"src/default.ts:153:95"
|
|
73
|
+
),
|
|
74
|
+
indexes = []
|
|
75
|
+
traverse(ast, {
|
|
76
|
+
Function(path) {
|
|
77
|
+
!path.node.loc ||
|
|
78
|
+
path.node.type.endsWith("Method") ||
|
|
79
|
+
(path.isExpression() && "VariableDeclarator" != path.parentPath.node.type) ||
|
|
80
|
+
!path.isPure() ||
|
|
81
|
+
indexes.push(path.node.loc.start.index)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
indexes.sort((a, b) => b - a)
|
|
85
|
+
for (const index of indexes)
|
|
86
|
+
code = `${code.slice(0, index)}/*@__NO_SIDE_EFFECTS__*/${code.slice(index)}`
|
|
87
|
+
return code
|
|
64
88
|
}
|
|
65
89
|
},
|
|
66
90
|
experimental?.disablePrettier ? void 0 : prettier(prettierOptions)
|
|
67
91
|
],
|
|
68
92
|
preserveEntrySignatures: "strict",
|
|
69
93
|
treeshake: { moduleSideEffects: !1 }
|
|
70
|
-
})
|
|
71
|
-
return experimental?.dts
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
})
|
|
95
|
+
return experimental?.dts
|
|
96
|
+
? [
|
|
97
|
+
config,
|
|
98
|
+
{
|
|
99
|
+
external: config.external,
|
|
100
|
+
input: config.input,
|
|
101
|
+
output: config.output,
|
|
102
|
+
plugins: [
|
|
103
|
+
dts({ oxc: !0, emitDtsOnly: !0 }),
|
|
104
|
+
experimental.disablePrettier ? void 0 : prettier({ ...prettierOptions, parser: "babel-ts" })
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
: config
|
|
109
|
+
}
|
|
110
|
+
export { rolldownConfig }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samual/rolldown-config",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-bc3dee8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "My Rolldown config",
|
|
6
6
|
"keywords": [
|
|
@@ -34,13 +34,7 @@
|
|
|
34
34
|
"rolldown-plugin-dts": "^0.23.2",
|
|
35
35
|
"rolldown-plugin-prettier": "0.0.2-a.BTUSLDAcU.DbYQZf"
|
|
36
36
|
},
|
|
37
|
-
"pnpm": {
|
|
38
|
-
"patchedDependencies": {
|
|
39
|
-
"defu": "patches/defu.patch",
|
|
40
|
-
"@types/node": "patches/@types__node.patch"
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
37
|
"engines": {
|
|
44
|
-
"node": "^
|
|
38
|
+
"node": "^22.12 || >=24"
|
|
45
39
|
}
|
|
46
40
|
}
|