@samual/rolldown-config 0.0.1-ad87f81 → 0.0.1-aead861
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/default.d.ts +5 -3
- package/default.js +74 -82
- package/package.json +12 -10
package/default.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type RollupBabelInputPluginOptions } from "@rollup/plugin-babel";
|
|
2
2
|
import { type Options as TerserOptions } from "@rollup/plugin-terser";
|
|
3
3
|
import type { LaxPartial } from "@samual/types";
|
|
4
|
-
import type { RolldownOptions } from "rolldown";
|
|
5
|
-
import { type Options as PrettierOptions } from "
|
|
4
|
+
import type { ConfigExport, RolldownOptions } from "rolldown";
|
|
5
|
+
import { type Options as PrettierOptions } from "rolldown-plugin-prettier";
|
|
6
6
|
type Options = LaxPartial<{
|
|
7
7
|
/**
|
|
8
8
|
* Override the source folder.
|
|
@@ -48,6 +48,8 @@ type Options = LaxPartial<{
|
|
|
48
48
|
prettierOptions: PrettierOptions;
|
|
49
49
|
experimental: LaxPartial<{
|
|
50
50
|
noSideEffects: boolean;
|
|
51
|
+
disablePrettier: boolean;
|
|
52
|
+
dts: boolean;
|
|
51
53
|
}>;
|
|
52
54
|
}>;
|
|
53
55
|
/**
|
|
@@ -80,5 +82,5 @@ type Options = LaxPartial<{
|
|
|
80
82
|
* export default rolldownConfig()
|
|
81
83
|
* ```
|
|
82
84
|
*/
|
|
83
|
-
export declare const rolldownConfig: (
|
|
85
|
+
export declare const rolldownConfig: (options?: Options) => ConfigExport | Promise<ConfigExport>;
|
|
84
86
|
export {};
|
package/default.js
CHANGED
|
@@ -1,92 +1,84 @@
|
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(path.endsWith(".ts") && !path.endsWith(".d.ts") && !path.endsWith(".test.ts"))
|
|
33
|
-
)
|
|
34
|
-
.map(path => [path.slice(sourcePath.length + 1, -3), path])
|
|
35
|
-
),
|
|
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 ({ sourcePath = "src", rolldownOptions, babelOptions, terserOptions, prettierOptions, experimental } = {}) => {
|
|
17
|
+
prettierOptions = defu(prettierOptions, {
|
|
18
|
+
parser: "espree",
|
|
19
|
+
useTabs: !0,
|
|
20
|
+
tabWidth: 4,
|
|
21
|
+
arrowParens: "avoid",
|
|
22
|
+
printWidth: 120,
|
|
23
|
+
semi: !1,
|
|
24
|
+
trailingComma: "none"
|
|
25
|
+
});
|
|
26
|
+
const config = defu(rolldownOptions, {
|
|
27
|
+
external: (source) => !(Path.isAbsolute(source) || source.startsWith(".")),
|
|
28
|
+
input: Object.fromEntries((await readdir(sourcePath, {
|
|
29
|
+
withFileTypes: !0,
|
|
30
|
+
recursive: !0
|
|
31
|
+
})).filter((dirent) => dirent.isFile()).map((dirent) => Path.join(((dirent) => expect(dirent.parentPath ?? dirent.path, "src/default.ts:71:98"))(dirent), dirent.name)).filter((path) => path.endsWith(".js") && !path.endsWith(".test.js") || path.endsWith(".ts") && !path.endsWith(".d.ts") && !path.endsWith(".test.ts")).map((path) => [path.slice(sourcePath.length + 1, -3), path])),
|
|
36
32
|
output: { dir: "dist" },
|
|
37
33
|
plugins: [
|
|
38
|
-
babel(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
34
|
+
babel(defu(babelOptions, {
|
|
35
|
+
babelHelpers: "bundled",
|
|
36
|
+
extensions: [".ts"],
|
|
37
|
+
presets: [[babelPresetEnv, { targets: { node: "20.10" } }], [babelPresetTypescript, {
|
|
38
|
+
allowDeclareFields: !0,
|
|
39
|
+
optimizeConstEnums: !0
|
|
40
|
+
}]],
|
|
41
|
+
plugins: [babelPluginHere(), babelPluginVitest()]
|
|
42
|
+
})),
|
|
43
|
+
terser(defu(terserOptions, {
|
|
44
|
+
compress: {
|
|
45
|
+
passes: Infinity,
|
|
46
|
+
unsafe: !0,
|
|
47
|
+
sequences: !1,
|
|
48
|
+
keep_infinity: !0
|
|
49
|
+
},
|
|
50
|
+
maxWorkers: Math.floor(cpus().length / 2),
|
|
51
|
+
mangle: !1,
|
|
52
|
+
ecma: 2020
|
|
53
|
+
})),
|
|
57
54
|
experimental?.noSideEffects && {
|
|
58
55
|
name: "no-side-effects",
|
|
59
56
|
async renderChunk(code) {
|
|
60
|
-
const ast = expect(await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] })),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
!path.isPure() ||
|
|
68
|
-
indexes.push(path.node.loc.start.index)
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
indexes.sort((a, b) => b - a)
|
|
72
|
-
for (const index of indexes)
|
|
73
|
-
code = `${code.slice(0, index)}/*@__NO_SIDE_EFFECTS__*/${code.slice(index)}`
|
|
74
|
-
return code
|
|
57
|
+
const ast = expect(await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] }), "src/default.ts:156:95"), indexes = [];
|
|
58
|
+
traverse(ast, { Function(path) {
|
|
59
|
+
!path.node.loc || path.node.type.endsWith("Method") || path.isExpression() && "VariableDeclarator" != path.parentPath.node.type || !path.isPure() || indexes.push(path.node.loc.start.index);
|
|
60
|
+
} });
|
|
61
|
+
indexes.sort((a, b) => b - a);
|
|
62
|
+
for (const index of indexes) code = `${code.slice(0, index)}/*@__NO_SIDE_EFFECTS__*/${code.slice(index)}`;
|
|
63
|
+
return code;
|
|
75
64
|
}
|
|
76
65
|
},
|
|
77
|
-
prettier(
|
|
78
|
-
defu(prettierOptions, {
|
|
79
|
-
parser: "espree",
|
|
80
|
-
useTabs: !0,
|
|
81
|
-
tabWidth: 4,
|
|
82
|
-
arrowParens: "avoid",
|
|
83
|
-
printWidth: 120,
|
|
84
|
-
semi: !1,
|
|
85
|
-
trailingComma: "none"
|
|
86
|
-
})
|
|
87
|
-
)
|
|
66
|
+
experimental?.disablePrettier ? void 0 : prettier(prettierOptions)
|
|
88
67
|
],
|
|
89
68
|
preserveEntrySignatures: "strict",
|
|
90
69
|
treeshake: { moduleSideEffects: !1 }
|
|
91
|
-
})
|
|
92
|
-
|
|
70
|
+
});
|
|
71
|
+
return experimental?.dts ? [config, {
|
|
72
|
+
external: config.external,
|
|
73
|
+
input: config.input,
|
|
74
|
+
output: config.output,
|
|
75
|
+
plugins: [dts({
|
|
76
|
+
oxc: !0,
|
|
77
|
+
emitDtsOnly: !0
|
|
78
|
+
}), experimental.disablePrettier ? void 0 : prettier({
|
|
79
|
+
...prettierOptions,
|
|
80
|
+
parser: "babel-ts"
|
|
81
|
+
})]
|
|
82
|
+
}] : config;
|
|
83
|
+
};
|
|
84
|
+
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-aead861",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "My Rolldown config",
|
|
6
6
|
"keywords": [
|
|
@@ -23,19 +23,21 @@
|
|
|
23
23
|
"@babel/plugin-syntax-typescript": "^7",
|
|
24
24
|
"@babel/preset-env": "^7",
|
|
25
25
|
"@babel/preset-typescript": "^7",
|
|
26
|
-
"@rollup/plugin-babel": "^
|
|
27
|
-
"@rollup/plugin-terser": "^0.
|
|
28
|
-
"@samual/assert": "0.0.1
|
|
29
|
-
"@samual/types": "0.0.2
|
|
30
|
-
"babel-plugin-here": "1.0.3-
|
|
31
|
-
"babel-plugin-vitest": "0.0.1-
|
|
26
|
+
"@rollup/plugin-babel": "^7",
|
|
27
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
28
|
+
"@samual/assert": "^0.0.1",
|
|
29
|
+
"@samual/types": "^0.0.2",
|
|
30
|
+
"babel-plugin-here": "1.0.3-9f222fd",
|
|
31
|
+
"babel-plugin-vitest": "0.0.1-bdec539",
|
|
32
32
|
"defu": "^6",
|
|
33
|
-
"rolldown": "1.0.0-rc.
|
|
34
|
-
"
|
|
33
|
+
"rolldown": "1.0.0-rc.15",
|
|
34
|
+
"rolldown-plugin-dts": "^0.23.2",
|
|
35
|
+
"rolldown-plugin-prettier": "0.0.2-a.BTUSLDAcU.DbYQZf"
|
|
35
36
|
},
|
|
36
37
|
"pnpm": {
|
|
37
38
|
"patchedDependencies": {
|
|
38
|
-
"defu": "patches/defu.patch"
|
|
39
|
+
"defu": "patches/defu.patch",
|
|
40
|
+
"@types/node": "patches/@types__node.patch"
|
|
39
41
|
}
|
|
40
42
|
},
|
|
41
43
|
"engines": {
|