@samual/rolldown-config 0.0.1-4c44901

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Samual Norman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/default.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ import { type RollupBabelInputPluginOptions } from "@rollup/plugin-babel";
2
+ import { type Options as TerserOptions } from "@rollup/plugin-terser";
3
+ import type { LaxPartial } from "@samual/lib";
4
+ import type { RolldownOptions } from "rolldown";
5
+ import { type Options as PrettierOptions } from "rollup-plugin-prettier";
6
+ type Options = LaxPartial<{
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
+ }>;
52
+ }>;
53
+ /**
54
+ * Construct a {@linkcode RollupOptions} object.
55
+ *
56
+ * Compiles all `.js` and `.ts` files (excludes `.test.js`, `.test.ts`, and `.d.ts`) found in the
57
+ * {@linkcode Options.sourcePath sourcePath}.
58
+ *
59
+ * @see {@linkcode Options}
60
+ *
61
+ * @example
62
+ * ```text
63
+ * src/
64
+ * env.d.ts
65
+ * foo.ts
66
+ * bar/
67
+ * baz.ts
68
+ * baz.test.ts
69
+ * dist/
70
+ * foo.js
71
+ * bar/
72
+ * baz.js
73
+ * ```
74
+ *
75
+ * @example
76
+ * ```js
77
+ * // rolldown.config.js
78
+ * import { rolldownConfig } from "@samual/rolldown-config"
79
+ *
80
+ * export default rolldownConfig()
81
+ * ```
82
+ */
83
+ export declare const rolldownConfig: ({ sourcePath, rolldownOptions, babelOptions, terserOptions, prettierOptions, experimental }?: Options) => Promise<RolldownOptions>;
84
+ export {};
package/default.js ADDED
@@ -0,0 +1,90 @@
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 { ensure } from "@samual/lib/assert"
8
+ import { findFiles } from "@samual/lib/findFiles"
9
+ import { babelPluginHere } from "babel-plugin-here"
10
+ import { babelPluginVitest } from "babel-plugin-vitest"
11
+ import { defu } from "defu"
12
+ import { cpus } from "os"
13
+ import * as Path from "path"
14
+ import prettier from "rollup-plugin-prettier"
15
+ const rolldownConfig = async ({
16
+ sourcePath = "src",
17
+ rolldownOptions,
18
+ babelOptions,
19
+ terserOptions,
20
+ prettierOptions,
21
+ experimental
22
+ } = {}) =>
23
+ defu(rolldownOptions, {
24
+ external: source => !(Path.isAbsolute(source) || source.startsWith(".")),
25
+ input: Object.fromEntries(
26
+ (await findFiles(sourcePath))
27
+ .filter(
28
+ path =>
29
+ (path.endsWith(".js") && !path.endsWith(".test.js")) ||
30
+ (path.endsWith(".ts") && !path.endsWith(".d.ts") && !path.endsWith(".test.ts"))
31
+ )
32
+ .map(path => [path.slice(sourcePath.length + 1, -3), path])
33
+ ),
34
+ output: { dir: "dist" },
35
+ plugins: [
36
+ babel(
37
+ defu(babelOptions, {
38
+ babelHelpers: "bundled",
39
+ extensions: [".ts"],
40
+ presets: [
41
+ [babelPresetEnv, { targets: { node: "20.10" } }],
42
+ [babelPresetTypescript, { allowDeclareFields: !0, optimizeConstEnums: !0 }]
43
+ ],
44
+ plugins: [babelPluginHere(), babelPluginVitest()]
45
+ })
46
+ ),
47
+ terser(
48
+ defu(terserOptions, {
49
+ compress: { passes: 1 / 0, unsafe: !0, sequences: !1 },
50
+ maxWorkers: Math.floor(cpus().length / 2),
51
+ mangle: !1,
52
+ ecma: 2020
53
+ })
54
+ ),
55
+ experimental?.noSideEffects && {
56
+ name: "no-side-effects",
57
+ async renderChunk(code) {
58
+ const ast = ensure(await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] })),
59
+ indexes = []
60
+ traverse(ast, {
61
+ Function(path) {
62
+ !path.node.loc ||
63
+ path.node.type.endsWith("Method") ||
64
+ (path.isExpression() && "VariableDeclarator" != path.parentPath.node.type) ||
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
73
+ }
74
+ },
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
+ )
86
+ ],
87
+ preserveEntrySignatures: "strict",
88
+ treeshake: { moduleSideEffects: !1 }
89
+ })
90
+ export { rolldownConfig }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@samual/rolldown-config",
3
+ "version": "0.0.1-4c44901",
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.27.1",
23
+ "@babel/plugin-syntax-typescript": "^7.27.1",
24
+ "@babel/preset-env": "^7.0.0",
25
+ "@babel/preset-typescript": "^7.0.0",
26
+ "@rollup/plugin-babel": "^6.0.0",
27
+ "@rollup/plugin-terser": "^0.4.0",
28
+ "@samual/lib": "0.13.1-4031e7a",
29
+ "babel-plugin-here": "1.0.3-ac850f7",
30
+ "babel-plugin-vitest": "0.0.1-7dc1dde",
31
+ "defu": "^6.0.0",
32
+ "rollup-plugin-prettier": "^4.0.0"
33
+ },
34
+ "engines": {
35
+ "node": "^20.10 || ^22 || >=24"
36
+ }
37
+ }
package/readme.md ADDED
@@ -0,0 +1,21 @@
1
+ # Samual's Rolldown Config
2
+ An opinionated Rolldown config.
3
+
4
+ Requires Node.js 20.10+, 22.0+, or above.
5
+
6
+ ## Install
7
+ ```sh
8
+ npm install @samual/cookie
9
+ ```
10
+
11
+ ## Usage
12
+ Put this in your `rolldown.config.js`:
13
+ ```js
14
+ import { rolldownConfig } from "@samual/rolldown-config"
15
+
16
+ export default rolldownConfig()
17
+ ```
18
+
19
+ By default, this config finds source files in `src` and emits them to `dist`.
20
+ You can override the source path with `rolldownConfig({ sourcePath: "source" })` and you can override the out path with
21
+ `rolldownConfig({ rolldownOptions: { output: { dir: "build" } } })`.