@samual/rolldown-config 0.0.1-e2f7c4c → 0.0.1-f348d0f

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/LICENSE +1 -1
  2. package/default.js +90 -64
  3. package/package.json +9 -15
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Samual Norman
3
+ Copyright (c) 2026 Samual Norman
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/default.js CHANGED
@@ -1,19 +1,26 @@
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 } = {}) => {
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 ({
17
+ sourcePath = "src",
18
+ rolldownOptions,
19
+ babelOptions,
20
+ terserOptions,
21
+ prettierOptions,
22
+ experimental
23
+ } = {}) => {
17
24
  prettierOptions = defu(prettierOptions, {
18
25
  parser: "espree",
19
26
  useTabs: !0,
@@ -22,63 +29,82 @@ const rolldownConfig = async ({ sourcePath = "src", rolldownOptions, babelOption
22
29
  printWidth: 120,
23
30
  semi: !1,
24
31
  trailingComma: "none"
25
- });
32
+ })
26
33
  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
+ external: source => !(Path.isAbsolute(source) || source.startsWith(".")),
35
+ input: Object.fromEntries(
36
+ (await readdir(sourcePath, { withFileTypes: !0, recursive: !0 }))
37
+ .filter(dirent => dirent.isFile())
38
+ .map(dirent => Path.join(dirent.parentPath, dirent.name))
39
+ .filter(
40
+ path =>
41
+ (path.endsWith(".js") && !path.endsWith(".test.js")) ||
42
+ (path.endsWith(".ts") && !path.endsWith(".d.ts") && !path.endsWith(".test.ts"))
43
+ )
44
+ .map(path => [path.slice(sourcePath.length + 1, -3), path])
45
+ ),
32
46
  output: { dir: "dist" },
33
47
  plugins: [
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
- })),
48
+ babel(
49
+ defu(babelOptions, {
50
+ babelHelpers: "bundled",
51
+ extensions: [".ts"],
52
+ presets: [
53
+ [babelPresetEnv, { targets: { node: "22.12" } }],
54
+ [babelPresetTypescript, { allowDeclareFields: !0, optimizeConstEnums: !0 }]
55
+ ],
56
+ plugins: [babelPluginHere(), babelPluginVitest()]
57
+ })
58
+ ),
59
+ terser(
60
+ defu(terserOptions, {
61
+ compress: { passes: Infinity, unsafe: !0, sequences: !1, keep_infinity: !0 },
62
+ maxWorkers: Math.floor(cpus().length / 2),
63
+ mangle: !1,
64
+ ecma: 2020
65
+ })
66
+ ),
54
67
  experimental?.noSideEffects && {
55
68
  name: "no-side-effects",
56
69
  async renderChunk(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;
70
+ const ast = expect(
71
+ await parseAsync(code, { plugins: [babelPluginSyntaxTypescript] }),
72
+ "src/default.ts:153:95"
73
+ ),
74
+ indexes = []
75
+ traverse(ast, {
76
+ Function(path) {
77
+ !path.node.loc ||
78
+ path.node.type.endsWith("Method") ||
79
+ (path.isExpression() && "VariableDeclarator" != path.parentPath.node.type) ||
80
+ !path.isPure() ||
81
+ indexes.push(path.node.loc.start.index)
82
+ }
83
+ })
84
+ indexes.sort((a, b) => b - a)
85
+ for (const index of indexes)
86
+ code = `${code.slice(0, index)}/*@__NO_SIDE_EFFECTS__*/${code.slice(index)}`
87
+ return code
64
88
  }
65
89
  },
66
90
  experimental?.disablePrettier ? void 0 : prettier(prettierOptions)
67
91
  ],
68
92
  preserveEntrySignatures: "strict",
69
93
  treeshake: { moduleSideEffects: !1 }
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 };
94
+ })
95
+ return experimental?.dts
96
+ ? [
97
+ config,
98
+ {
99
+ external: config.external,
100
+ input: config.input,
101
+ output: config.output,
102
+ plugins: [
103
+ dts({ oxc: !0, emitDtsOnly: !0 }),
104
+ experimental.disablePrettier ? void 0 : prettier({ ...prettierOptions, parser: "babel-ts" })
105
+ ]
106
+ }
107
+ ]
108
+ : config
109
+ }
110
+ export { rolldownConfig }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samual/rolldown-config",
3
- "version": "0.0.1-e2f7c4c",
3
+ "version": "0.0.1-f348d0f",
4
4
  "type": "module",
5
5
  "description": "My Rolldown config",
6
6
  "keywords": [
@@ -25,22 +25,16 @@
25
25
  "@babel/preset-typescript": "^7",
26
26
  "@rollup/plugin-babel": "^7",
27
27
  "@rollup/plugin-terser": "^1.0.0",
28
- "@samual/assert": "0.0.1-da0fbad",
29
- "@samual/types": "0.0.2-23ffc7f",
30
- "babel-plugin-here": "1.0.3-0e10245",
31
- "babel-plugin-vitest": "0.0.1-7dc1dde",
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.10",
34
- "rolldown-plugin-dts": "^0.22.5",
35
- "rolldown-plugin-prettier": "0.0.1-a.BTUGCVCcG.TGFCcZ"
36
- },
37
- "pnpm": {
38
- "patchedDependencies": {
39
- "defu": "patches/defu.patch",
40
- "@types/node": "patches/@types__node.patch"
41
- }
33
+ "rolldown": "1.0.0-rc.15",
34
+ "rolldown-plugin-dts": "^0.23.2",
35
+ "rolldown-plugin-prettier": "0.0.2-a.BTUSLDAcU.DbYQZf"
42
36
  },
43
37
  "engines": {
44
- "node": "^20.10 || ^22 || >=24"
38
+ "node": "^22.12 || >=24"
45
39
  }
46
40
  }