rolldown-plugin-access-privates 0.1.0 → 0.1.1
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/README.md +184 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/rolldown-plugin-access-privates.code-workspace +8 -0
- package/src/index.ts +5 -4
package/README.md
CHANGED
|
@@ -1,2 +1,185 @@
|
|
|
1
1
|
# rolldown-plugin-access-privates
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
A [Rolldown](https://rolldown.rs/) plugin that enables access to class private
|
|
4
|
+
members (`#field`, `#method()`) during bundling by transforming matched modules.
|
|
5
|
+
This might be useful to set up a specific condition for testing (for example
|
|
6
|
+
with [vitest](https://vitest.dev/)).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
# npm
|
|
12
|
+
npm install -D rolldown-plugin-access-privates
|
|
13
|
+
# pnpm
|
|
14
|
+
pnpm add -D rolldown-plugin-access-privates
|
|
15
|
+
# yarn
|
|
16
|
+
yarn add -D rolldown-plugin-access-privates
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage with vitest
|
|
20
|
+
|
|
21
|
+
This setup ensures that the plugin is only active during testing.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// vitest.config.ts
|
|
25
|
+
import { defineConfig } from 'vitest/config';
|
|
26
|
+
import accessPrivates from 'rolldown-plugin-access-privates';
|
|
27
|
+
|
|
28
|
+
export default defineConfig(({mode}) => {
|
|
29
|
+
plugins: mode === 'test' ? [accessPrivates()] : [],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Options
|
|
34
|
+
|
|
35
|
+
An optional object to configure the plugin's behavior. All options are optional
|
|
36
|
+
and have sensible defaults.
|
|
37
|
+
|
|
38
|
+
````ts
|
|
39
|
+
type options = {
|
|
40
|
+
/**
|
|
41
|
+
* Whether to export all top-level variables, functions, and classes in the module.
|
|
42
|
+
* Can be an array of "variable", "function", and "class", or a function that will
|
|
43
|
+
* be called with the module ID and AST node of each variable, function, or class
|
|
44
|
+
* declaration.
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
exports?:
|
|
48
|
+
| ("variable" | "function" | "class")[]
|
|
49
|
+
| boolean
|
|
50
|
+
| ((
|
|
51
|
+
id: string,
|
|
52
|
+
astNode: ESTree.VariableDeclaration | ESTree.Function | ESTree.Class,
|
|
53
|
+
) => boolean)
|
|
54
|
+
| undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Which class members to generate accessors for.
|
|
57
|
+
* Can be an array of "method", "get", "set", and "property", or a function that will
|
|
58
|
+
* be called with the module ID and AST node of each method or property definition.
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
classMembers?:
|
|
62
|
+
| ("method" | "get" | "set" | "property")[]
|
|
63
|
+
| boolean
|
|
64
|
+
| ((
|
|
65
|
+
id: string,
|
|
66
|
+
astNode: ESTree.MethodDefinition | ESTree.PropertyDefinition,
|
|
67
|
+
) => boolean)
|
|
68
|
+
| undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The suffix to use for the generated accessors.
|
|
71
|
+
* For example, if you have a private field `#foo`, the plugin will generate
|
|
72
|
+
* `fooPrivate` getter and setter.
|
|
73
|
+
* @default "Private"
|
|
74
|
+
*/
|
|
75
|
+
suffix?: string | ((name: string) => string) | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Filter for which modules the plugin should apply.
|
|
78
|
+
* Can be a string, a RegExp, an array of strings and RegExps, or an object with an
|
|
79
|
+
* `include` and `exclude` property, each of which can be a string, a RegExp, or an
|
|
80
|
+
* array of strings and RegExps.
|
|
81
|
+
* The filter will be applied to the module ID.
|
|
82
|
+
* @default /\.[jt]sx?$/
|
|
83
|
+
*/
|
|
84
|
+
idFilter?: HookFilter["id"] | undefined;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* From Rolldown:
|
|
89
|
+
* A filter based on the module `id`.
|
|
90
|
+
*
|
|
91
|
+
* If the value is a string, it is treated as a glob pattern.
|
|
92
|
+
* The string type is not available for {@linkcode Plugin.resolveId | resolveId} hook.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* Include all `id`s that contain `node_modules` in the path.
|
|
96
|
+
* ```js
|
|
97
|
+
* { id: '**'+'/node_modules/**' }
|
|
98
|
+
* ```
|
|
99
|
+
* @example
|
|
100
|
+
* Include all `id`s that contain `node_modules` or `src` in the path.
|
|
101
|
+
* ```js
|
|
102
|
+
* { id: ['**'+'/node_modules/**', '**'+'/src/**'] }
|
|
103
|
+
* ```
|
|
104
|
+
* @example
|
|
105
|
+
* Include all `id`s that start with `http`
|
|
106
|
+
* ```js
|
|
107
|
+
* { id: /^http/ }
|
|
108
|
+
* ```
|
|
109
|
+
* @example
|
|
110
|
+
* Exclude all `id`s that contain `node_modules` in the path.
|
|
111
|
+
* ```js
|
|
112
|
+
* { id: { exclude: '**'+'/node_modules/**' } }
|
|
113
|
+
* ```
|
|
114
|
+
* @example
|
|
115
|
+
* Formal pattern to define includes and excludes.
|
|
116
|
+
* ```js
|
|
117
|
+
* { id : {
|
|
118
|
+
* include: ['**'+'/foo/**', /bar/],
|
|
119
|
+
* exclude: ['**'+'/baz/**', /qux/]
|
|
120
|
+
* }}
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
type GeneralHookFilter = string | RegExp | (string | RegExp)[] | {
|
|
124
|
+
include?: string | RegExp | (string | RegExp)[];
|
|
125
|
+
exclude?: string | RegExp | (string | RegExp)[];
|
|
126
|
+
};
|
|
127
|
+
````
|
|
128
|
+
|
|
129
|
+
## Example
|
|
130
|
+
|
|
131
|
+
With the default configuration, the plugin will transform code like this:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
let globalCounter = 0;
|
|
135
|
+
function reset() {
|
|
136
|
+
globalCounter = 0;
|
|
137
|
+
}
|
|
138
|
+
class Counter {
|
|
139
|
+
#value = 0;
|
|
140
|
+
#reset() {
|
|
141
|
+
this.#value = 0;
|
|
142
|
+
}
|
|
143
|
+
inc() {
|
|
144
|
+
this.#value++;
|
|
145
|
+
globalCounter++;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Into this:
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
export let globalCounter = 0;
|
|
154
|
+
export function reset() {
|
|
155
|
+
globalCounter = 0;
|
|
156
|
+
}
|
|
157
|
+
export class Counter {
|
|
158
|
+
static get #globalCounter() {
|
|
159
|
+
return globalCounter;
|
|
160
|
+
}
|
|
161
|
+
static get globalCounterPrivate() {
|
|
162
|
+
return this.#globalCounter;
|
|
163
|
+
}
|
|
164
|
+
#value = 0;
|
|
165
|
+
get valuePrivate() {
|
|
166
|
+
return this.#value;
|
|
167
|
+
}
|
|
168
|
+
set valuePrivate(value) {
|
|
169
|
+
this.#value = value;
|
|
170
|
+
}
|
|
171
|
+
#reset() {
|
|
172
|
+
this.#value = 0;
|
|
173
|
+
}
|
|
174
|
+
get resetPrivate() {
|
|
175
|
+
return this.#reset;
|
|
176
|
+
}
|
|
177
|
+
set resetPrivate(value) {
|
|
178
|
+
this.#reset = value;
|
|
179
|
+
}
|
|
180
|
+
inc() {
|
|
181
|
+
this.#value++;
|
|
182
|
+
globalCounter++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type HookFilter, type Plugin } from "rolldown";
|
|
2
2
|
import { type ESTree } from "rolldown/utils";
|
|
3
3
|
/**
|
|
4
4
|
* A Vite plugin to generate accessors for private fields to allow testing them.
|
|
@@ -11,7 +11,7 @@ import { type ESTree } from "rolldown/utils";
|
|
|
11
11
|
export default function AccessPrivates({ exports, classMembers, suffix, idFilter }?: {
|
|
12
12
|
/**
|
|
13
13
|
* Whether to export all top-level variables, functions, and classes in the module.
|
|
14
|
-
* Can be an array of "variable", "function", and "class", or a function that will be called with the module ID and AST node of each variable, function, or class declaration
|
|
14
|
+
* Can be an array of "variable", "function", and "class", or a function that will be called with the module ID and AST node of each variable, function, or class declaration.
|
|
15
15
|
* @default true
|
|
16
16
|
*/
|
|
17
17
|
exports?: ("variable" | "function" | "class")[] | boolean | ((id: string, astNode: ESTree.VariableDeclaration | ESTree.Function | ESTree.Class) => boolean) | undefined;
|
|
@@ -22,7 +22,8 @@ export default function AccessPrivates({ exports, classMembers, suffix, idFilter
|
|
|
22
22
|
*/
|
|
23
23
|
classMembers?: ("method" | "get" | "set" | "property")[] | boolean | ((id: string, astNode: ESTree.MethodDefinition | ESTree.PropertyDefinition) => boolean) | undefined;
|
|
24
24
|
/**
|
|
25
|
-
* The suffix to use for the generated accessors.
|
|
25
|
+
* The suffix to use for the generated accessors.
|
|
26
|
+
* For example, if you have a private field `#foo`, the plugin will generate `fooPrivate` getter and setter.
|
|
26
27
|
* @default "Private"
|
|
27
28
|
*/
|
|
28
29
|
suffix?: string | ((name: string) => string) | undefined;
|
|
@@ -32,6 +33,6 @@ export default function AccessPrivates({ exports, classMembers, suffix, idFilter
|
|
|
32
33
|
* The filter will be applied to the module ID.
|
|
33
34
|
* @default /\.[jt]sx?$/
|
|
34
35
|
*/
|
|
35
|
-
idFilter?:
|
|
36
|
+
idFilter?: HookFilter["id"] | undefined;
|
|
36
37
|
}): Plugin;
|
|
37
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAW,KAAK,MAAM,EAAsB,MAAM,gBAAgB,CAAC;AAS1E;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,OAAc,EACd,YAAmB,EACnB,MAAkB,EAClB,QAAuB,EACxB,GAAE;IACD;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,EAAE,GAAG,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IACxK;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,CAAC,EAAE,GAAG,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IACzK;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IACzD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;CACpC,GAAG,MAAM,CA6Fd"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,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
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type HookFilter, type Plugin } from "rolldown";
|
|
2
2
|
import { withMagicString } from "rolldown-string";
|
|
3
3
|
import { Visitor, type ESTree, type VisitorObject } from "rolldown/utils";
|
|
4
4
|
|
|
@@ -25,7 +25,7 @@ export default function AccessPrivates({
|
|
|
25
25
|
}: {
|
|
26
26
|
/**
|
|
27
27
|
* Whether to export all top-level variables, functions, and classes in the module.
|
|
28
|
-
* Can be an array of "variable", "function", and "class", or a function that will be called with the module ID and AST node of each variable, function, or class declaration
|
|
28
|
+
* Can be an array of "variable", "function", and "class", or a function that will be called with the module ID and AST node of each variable, function, or class declaration.
|
|
29
29
|
* @default true
|
|
30
30
|
*/
|
|
31
31
|
exports?: ("variable" | "function" | "class")[] | boolean | ((id: string, astNode: ESTree.VariableDeclaration | ESTree.Function | ESTree.Class) => boolean) | undefined;
|
|
@@ -36,7 +36,8 @@ export default function AccessPrivates({
|
|
|
36
36
|
*/
|
|
37
37
|
classMembers?: ("method" | "get" | "set" | "property")[] | boolean | ((id: string, astNode: ESTree.MethodDefinition | ESTree.PropertyDefinition) => boolean) | undefined;
|
|
38
38
|
/**
|
|
39
|
-
* The suffix to use for the generated accessors.
|
|
39
|
+
* The suffix to use for the generated accessors.
|
|
40
|
+
* For example, if you have a private field `#foo`, the plugin will generate `fooPrivate` getter and setter.
|
|
40
41
|
* @default "Private"
|
|
41
42
|
*/
|
|
42
43
|
suffix?: string | ((name: string) => string) | undefined;
|
|
@@ -46,7 +47,7 @@ export default function AccessPrivates({
|
|
|
46
47
|
* The filter will be applied to the module ID.
|
|
47
48
|
* @default /\.[jt]sx?$/
|
|
48
49
|
*/
|
|
49
|
-
idFilter?:
|
|
50
|
+
idFilter?: HookFilter["id"] | undefined;
|
|
50
51
|
} = {}): Plugin {
|
|
51
52
|
// Calculate which code path can be optimized.
|
|
52
53
|
const canNotExport = exports === false || (Array.isArray(exports) && exports.length === 0);
|