@samual/rolldown-config 0.0.1-ace4984 → 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 +80 -78
- package/default.js +74 -80
- package/package.json +44 -36
- package/readme.md +0 -2
package/default.d.ts
CHANGED
|
@@ -1,84 +1,86 @@
|
|
|
1
1
|
import { type RollupBabelInputPluginOptions } from "@rollup/plugin-babel";
|
|
2
2
|
import { type Options as TerserOptions } from "@rollup/plugin-terser";
|
|
3
|
-
import type { LaxPartial } from "@samual/
|
|
4
|
-
import type { RolldownOptions } from "rolldown";
|
|
5
|
-
import { type Options as PrettierOptions } from "
|
|
3
|
+
import type { LaxPartial } from "@samual/types";
|
|
4
|
+
import type { ConfigExport, RolldownOptions } from "rolldown";
|
|
5
|
+
import { type Options as PrettierOptions } from "rolldown-plugin-prettier";
|
|
6
6
|
type Options = LaxPartial<{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Override the source folder.
|
|
9
|
+
* @default "src"
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* // rolldown.config.js
|
|
14
|
+
* import { rolldownConfig } from "@samual/rolldown-config"
|
|
15
|
+
*
|
|
16
|
+
* export default rolldownConfig({ sourcePath: "source" })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
sourcePath: string;
|
|
20
|
+
/**
|
|
21
|
+
* Override any Rolldown options.
|
|
22
|
+
* @see [Official Rolldown docs.](https://rolldown.rs/reference/config-options)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // rolldown.config.js
|
|
27
|
+
* import { rolldownConfig } from "@samual/rolldown-config"
|
|
28
|
+
*
|
|
29
|
+
* // You can override the output folder like so:
|
|
30
|
+
* export default rolldownConfig({ rolldownOptions: { output: { dir: "build" } } })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
rolldownOptions: RolldownOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Override any Babel options.
|
|
36
|
+
* @see [Official Babel docs.](https://babeljs.io/docs/options)
|
|
37
|
+
*/
|
|
38
|
+
babelOptions: RollupBabelInputPluginOptions;
|
|
39
|
+
/**
|
|
40
|
+
* Override any Terser options.
|
|
41
|
+
* @see [Official Terser docs.](https://terser.org/docs/options/)
|
|
42
|
+
*/
|
|
43
|
+
terserOptions: TerserOptions;
|
|
44
|
+
/**
|
|
45
|
+
* Override any Prettier options.
|
|
46
|
+
* @see [Official Prettier docs.](https://prettier.io/docs/en/options)
|
|
47
|
+
*/
|
|
48
|
+
prettierOptions: PrettierOptions;
|
|
49
|
+
experimental: LaxPartial<{
|
|
50
|
+
noSideEffects: boolean;
|
|
51
|
+
disablePrettier: boolean;
|
|
52
|
+
dts: boolean;
|
|
53
|
+
}>;
|
|
52
54
|
}>;
|
|
53
55
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export declare const rolldownConfig: (
|
|
56
|
+
* Construct a {@linkcode RollupOptions} object.
|
|
57
|
+
*
|
|
58
|
+
* Compiles all `.js` and `.ts` files (excludes `.test.js`, `.test.ts`, and `.d.ts`) found in the
|
|
59
|
+
* {@linkcode Options.sourcePath sourcePath}.
|
|
60
|
+
*
|
|
61
|
+
* @see {@linkcode Options}
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```text
|
|
65
|
+
* src/
|
|
66
|
+
* env.d.ts
|
|
67
|
+
* foo.ts
|
|
68
|
+
* bar/
|
|
69
|
+
* baz.ts
|
|
70
|
+
* baz.test.ts
|
|
71
|
+
* dist/
|
|
72
|
+
* foo.js
|
|
73
|
+
* bar/
|
|
74
|
+
* baz.js
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* // rolldown.config.js
|
|
80
|
+
* import { rolldownConfig } from "@samual/rolldown-config"
|
|
81
|
+
*
|
|
82
|
+
* export default rolldownConfig()
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare const rolldownConfig: (options?: Options) => ConfigExport | Promise<ConfigExport>;
|
|
84
86
|
export {};
|
package/default.js
CHANGED
|
@@ -1,90 +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 {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
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
|
-
.map(path => [path.slice(sourcePath.length + 1, -3), path])
|
|
33
|
-
),
|
|
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])),
|
|
34
32
|
output: { dir: "dist" },
|
|
35
33
|
plugins: [
|
|
36
|
-
babel(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
})),
|
|
55
54
|
experimental?.noSideEffects && {
|
|
56
55
|
name: "no-side-effects",
|
|
57
56
|
async renderChunk(code) {
|
|
58
|
-
const ast =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
!path.isPure() ||
|
|
66
|
-
indexes.push(path.node.loc.start.index)
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
indexes.sort((a, b) => b - a)
|
|
70
|
-
for (const index of indexes)
|
|
71
|
-
code = `${code.slice(0, index)}/*@__NO_SIDE_EFFECTS__*/${code.slice(index)}`
|
|
72
|
-
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;
|
|
73
64
|
}
|
|
74
65
|
},
|
|
75
|
-
prettier(
|
|
76
|
-
defu(prettierOptions, {
|
|
77
|
-
parser: "espree",
|
|
78
|
-
useTabs: !0,
|
|
79
|
-
tabWidth: 4,
|
|
80
|
-
arrowParens: "avoid",
|
|
81
|
-
printWidth: 120,
|
|
82
|
-
semi: !1,
|
|
83
|
-
trailingComma: "none"
|
|
84
|
-
})
|
|
85
|
-
)
|
|
66
|
+
experimental?.disablePrettier ? void 0 : prettier(prettierOptions)
|
|
86
67
|
],
|
|
87
68
|
preserveEntrySignatures: "strict",
|
|
88
69
|
treeshake: { moduleSideEffects: !1 }
|
|
89
|
-
})
|
|
90
|
-
|
|
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,38 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
2
|
+
"name": "@samual/rolldown-config",
|
|
3
|
+
"version": "0.0.1-aead861",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "My Rolldown config",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"rolldown",
|
|
8
|
+
"config"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/samualtnorman/rolldown-config#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/samualtnorman/rolldown-config/issues",
|
|
13
|
+
"email": "me@samual.uk"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Samual Norman <me@samual.uk> (https://samual.uk/)",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./default.js"
|
|
19
|
+
},
|
|
20
|
+
"repository": "github:samualtnorman/rolldown-config",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@babel/core": "^7.19",
|
|
23
|
+
"@babel/plugin-syntax-typescript": "^7",
|
|
24
|
+
"@babel/preset-env": "^7",
|
|
25
|
+
"@babel/preset-typescript": "^7",
|
|
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
|
+
"defu": "^6",
|
|
33
|
+
"rolldown": "1.0.0-rc.15",
|
|
34
|
+
"rolldown-plugin-dts": "^0.23.2",
|
|
35
|
+
"rolldown-plugin-prettier": "0.0.2-a.BTUSLDAcU.DbYQZf"
|
|
36
|
+
},
|
|
37
|
+
"pnpm": {
|
|
38
|
+
"patchedDependencies": {
|
|
39
|
+
"defu": "patches/defu.patch",
|
|
40
|
+
"@types/node": "patches/@types__node.patch"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "^20.10 || ^22 || >=24"
|
|
45
|
+
}
|
|
38
46
|
}
|