@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.
Files changed (3) hide show
  1. package/default.d.ts +5 -3
  2. package/default.js +74 -82
  3. 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 "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
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: ({ sourcePath, rolldownOptions, babelOptions, terserOptions, prettierOptions, experimental }?: Options) => Promise<RolldownOptions>;
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-ad87f81",
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": "^6",
27
- "@rollup/plugin-terser": "^0.4.4",
28
- "@samual/assert": "0.0.1-fc7f76d",
29
- "@samual/types": "0.0.2-23ffc7f",
30
- "babel-plugin-here": "1.0.3-0e10245",
31
- "babel-plugin-vitest": "0.0.1-7dc1dde",
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.3",
34
- "rollup-plugin-prettier": "^4"
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": {