@samual/rolldown-config 0.0.1-1456cd7 → 0.0.1-17fd9d5

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 +79 -77
  2. package/default.js +74 -82
  3. package/package.json +10 -8
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
3
  import type { LaxPartial } from "@samual/types";
4
- import type { RolldownOptions } from "rolldown";
5
- import { type Options as PrettierOptions } from "rollup-plugin-prettier";
4
+ import type { ConfigExport, RolldownOptions } from "rolldown";
5
+ import { type Options as PrettierOptions } from "rolldown-plugin-prettier";
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
@@ -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 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 readdir(sourcePath, { withFileTypes: !0, recursive: !0 }))
27
- .filter(dirent => dirent.isFile())
28
- .map(dirent => Path.join((dirent => dirent.parentPath ?? dirent.path)(dirent), dirent.name))
29
- .filter(
30
- path =>
31
- (path.endsWith(".js") && !path.endsWith(".test.js")) ||
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
- defu(babelOptions, {
40
- babelHelpers: "bundled",
41
- extensions: [".ts"],
42
- presets: [
43
- [babelPresetEnv, { targets: { node: "20.10" } }],
44
- [babelPresetTypescript, { allowDeclareFields: !0, optimizeConstEnums: !0 }]
45
- ],
46
- plugins: [babelPluginHere(), babelPluginVitest()]
47
- })
48
- ),
49
- terser(
50
- defu(terserOptions, {
51
- compress: { passes: 1 / 0, unsafe: !0, sequences: !1 },
52
- maxWorkers: Math.floor(cpus().length / 2),
53
- mangle: !1,
54
- ecma: 2020
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
- indexes = []
62
- traverse(ast, {
63
- Function(path) {
64
- !path.node.loc ||
65
- path.node.type.endsWith("Method") ||
66
- (path.isExpression() && "VariableDeclarator" != path.parentPath.node.type) ||
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
- export { rolldownConfig }
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-1456cd7",
3
+ "version": "0.0.1-17fd9d5",
4
4
  "type": "module",
5
5
  "description": "My Rolldown config",
6
6
  "keywords": [
@@ -19,23 +19,25 @@
19
19
  },
20
20
  "repository": "github:samualtnorman/rolldown-config",
21
21
  "dependencies": {
22
- "@babel/core": "^7",
22
+ "@babel/core": "^7.19",
23
23
  "@babel/plugin-syntax-typescript": "^7",
24
24
  "@babel/preset-env": "^7",
25
25
  "@babel/preset-typescript": "^7",
26
- "@rollup/plugin-babel": "^6",
27
- "@rollup/plugin-terser": "^0.4.4",
28
- "@samual/assert": "0.0.1-fc7f76d",
26
+ "@rollup/plugin-babel": "^7",
27
+ "@rollup/plugin-terser": "^1.0.0",
28
+ "@samual/assert": "0.0.1-da0fbad",
29
29
  "@samual/types": "0.0.2-23ffc7f",
30
30
  "babel-plugin-here": "1.0.3-0e10245",
31
31
  "babel-plugin-vitest": "0.0.1-7dc1dde",
32
32
  "defu": "^6",
33
- "rolldown": "1.0.0-beta.55",
34
- "rollup-plugin-prettier": "^4"
33
+ "rolldown": "1.0.0-rc.11",
34
+ "rolldown-plugin-dts": "^0.22.5",
35
+ "rolldown-plugin-prettier": "0.0.1-a.BTUQLDdaH.SOfPdb"
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": {