@samual/rolldown-config 0.0.1-1055660 → 0.0.1-19646a0

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.
Files changed (3) hide show
  1. package/default.d.ts +80 -78
  2. package/default.js +36 -19
  3. package/package.json +44 -36
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/lib";
4
- import type { RolldownOptions } from "rolldown";
5
- import { type Options as PrettierOptions } from "rollup-plugin-prettier";
3
+ import { type Options as PrettierOptions } from "@samual/rolldown-plugin-prettier";
4
+ import type { LaxPartial } from "@samual/types";
5
+ import type { ConfigExport, RolldownOptions } from "rolldown";
6
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
- }>;
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
- * 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>;
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
@@ -4,14 +4,15 @@ import babelPresetEnv from "@babel/preset-env"
4
4
  import babelPresetTypescript from "@babel/preset-typescript"
5
5
  import { babel } from "@rollup/plugin-babel"
6
6
  import terser from "@rollup/plugin-terser"
7
- import { ensure } from "@samual/lib/assert"
8
- import { findFiles } from "@samual/lib/findFiles"
7
+ import { expect } from "@samual/assert"
8
+ import prettier from "@samual/rolldown-plugin-prettier"
9
9
  import { babelPluginHere } from "babel-plugin-here"
10
10
  import { babelPluginVitest } from "babel-plugin-vitest"
11
11
  import { defu } from "defu"
12
+ import { readdir } from "fs/promises"
12
13
  import { cpus } from "os"
13
14
  import * as Path from "path"
14
- import prettier from "rollup-plugin-prettier"
15
+ import { dts } from "rolldown-plugin-dts"
15
16
  const rolldownConfig = async ({
16
17
  sourcePath = "src",
17
18
  rolldownOptions,
@@ -19,11 +20,22 @@ const rolldownConfig = async ({
19
20
  terserOptions,
20
21
  prettierOptions,
21
22
  experimental
22
- } = {}) =>
23
- defu(rolldownOptions, {
23
+ } = {}) => {
24
+ prettierOptions = defu(prettierOptions, {
25
+ parser: "espree",
26
+ useTabs: !0,
27
+ tabWidth: 4,
28
+ arrowParens: "avoid",
29
+ printWidth: 120,
30
+ semi: !1,
31
+ trailingComma: "none"
32
+ })
33
+ const config = defu(rolldownOptions, {
24
34
  external: source => !(Path.isAbsolute(source) || source.startsWith(".")),
25
35
  input: Object.fromEntries(
26
- (await findFiles(sourcePath))
36
+ (await readdir(sourcePath, { withFileTypes: !0, recursive: !0 }))
37
+ .filter(dirent => dirent.isFile())
38
+ .map(dirent => Path.join((dirent => expect(dirent.parentPath ?? dirent.path))(dirent), dirent.name))
27
39
  .filter(
28
40
  path =>
29
41
  (path.endsWith(".js") && !path.endsWith(".test.js")) ||
@@ -46,7 +58,7 @@ const rolldownConfig = async ({
46
58
  ),
47
59
  terser(
48
60
  defu(terserOptions, {
49
- compress: { passes: 1 / 0, unsafe: !0, sequences: !1 },
61
+ compress: { passes: Infinity, unsafe: !0, sequences: !1, keep_infinity: !0 },
50
62
  maxWorkers: Math.floor(cpus().length / 2),
51
63
  mangle: !1,
52
64
  ecma: 2020
@@ -55,7 +67,7 @@ const rolldownConfig = async ({
55
67
  experimental?.noSideEffects && {
56
68
  name: "no-side-effects",
57
69
  async renderChunk(code) {
58
- const ast = ensure(await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] })),
70
+ const ast = expect(await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] })),
59
71
  indexes = []
60
72
  traverse(ast, {
61
73
  Function(path) {
@@ -72,19 +84,24 @@ const rolldownConfig = async ({
72
84
  return code
73
85
  }
74
86
  },
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
- )
87
+ experimental?.disablePrettier ? void 0 : prettier(prettierOptions)
86
88
  ],
87
89
  preserveEntrySignatures: "strict",
88
90
  treeshake: { moduleSideEffects: !1 }
89
91
  })
92
+ return experimental?.dts
93
+ ? [
94
+ config,
95
+ {
96
+ external: config.external,
97
+ input: config.input,
98
+ output: config.output,
99
+ plugins: [
100
+ dts({ oxc: !0, emitDtsOnly: !0 }),
101
+ experimental.disablePrettier ? void 0 : prettier({ ...prettierOptions, parser: "babel-ts" })
102
+ ]
103
+ }
104
+ ]
105
+ : config
106
+ }
90
107
  export { rolldownConfig }
package/package.json CHANGED
@@ -1,38 +1,46 @@
1
1
  {
2
- "name": "@samual/rolldown-config",
3
- "version": "0.0.1-1055660",
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.28.4",
23
- "@babel/plugin-syntax-typescript": "^7.27.1",
24
- "@babel/preset-env": "^7.28.3",
25
- "@babel/preset-typescript": "^7.27.1",
26
- "@rollup/plugin-babel": "^6.1.0",
27
- "@rollup/plugin-terser": "^0.4.4",
28
- "@samual/lib": "0.13.1-5f3d742",
29
- "babel-plugin-here": "1.0.3-e0fc72f",
30
- "babel-plugin-vitest": "0.0.1-7dc1dde",
31
- "defu": "^6.1.4",
32
- "rolldown": "1.0.0-beta.43",
33
- "rollup-plugin-prettier": "^4.1.2"
34
- },
35
- "engines": {
36
- "node": "^20.10 || ^22 || >=24"
37
- }
2
+ "name": "@samual/rolldown-config",
3
+ "version": "0.0.1-19646a0",
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": "^0.4.4",
28
+ "@samual/assert": "0.0.1-da0fbad",
29
+ "@samual/rolldown-plugin-prettier": "0.0.1-7fd8404",
30
+ "@samual/types": "0.0.2-23ffc7f",
31
+ "babel-plugin-here": "1.0.3-0e10245",
32
+ "babel-plugin-vitest": "0.0.1-7dc1dde",
33
+ "defu": "^6",
34
+ "rolldown": "1.0.0-rc.6",
35
+ "rolldown-plugin-dts": "^0.22.2"
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
  }