@rolldown/pluginutils 1.0.0-beta.14-commit.12b8061 → 1.0.0-beta.16
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/dist/index.cjs +24 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +24 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -197,6 +197,18 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
197
197
|
*
|
|
198
198
|
* @param str the string to match.
|
|
199
199
|
* @param flags flags for the RegExp.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
204
|
+
* const plugin = {
|
|
205
|
+
* name: 'plugin',
|
|
206
|
+
* resolveId: {
|
|
207
|
+
* filter: { id: exactRegex('foo') },
|
|
208
|
+
* handler(id) {} // will only be called for `foo`
|
|
209
|
+
* }
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
200
212
|
*/
|
|
201
213
|
function exactRegex(str, flags) {
|
|
202
214
|
return new RegExp(`^${escapeRegex(str)}$`, flags);
|
|
@@ -208,6 +220,18 @@ function exactRegex(str, flags) {
|
|
|
208
220
|
*
|
|
209
221
|
* @param str the string to match.
|
|
210
222
|
* @param flags flags for the RegExp.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { prefixRegex } from '@rolldown/pluginutils';
|
|
227
|
+
* const plugin = {
|
|
228
|
+
* name: 'plugin',
|
|
229
|
+
* resolveId: {
|
|
230
|
+
* filter: { id: prefixRegex('foo') },
|
|
231
|
+
* handler(id) {} // will only be called for IDs starting with `foo`
|
|
232
|
+
* }
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
211
235
|
*/
|
|
212
236
|
function prefixRegex(str, flags) {
|
|
213
237
|
return new RegExp(`^${escapeRegex(str)}`, flags);
|
package/dist/index.d.cts
CHANGED
|
@@ -99,6 +99,18 @@ declare function exprInterpreter(expr: FilterExpression, code?: string, id?: str
|
|
|
99
99
|
*
|
|
100
100
|
* @param str the string to match.
|
|
101
101
|
* @param flags flags for the RegExp.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
106
|
+
* const plugin = {
|
|
107
|
+
* name: 'plugin',
|
|
108
|
+
* resolveId: {
|
|
109
|
+
* filter: { id: exactRegex('foo') },
|
|
110
|
+
* handler(id) {} // will only be called for `foo`
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
102
114
|
*/
|
|
103
115
|
declare function exactRegex(str: string, flags?: string): RegExp;
|
|
104
116
|
/**
|
|
@@ -108,6 +120,18 @@ declare function exactRegex(str: string, flags?: string): RegExp;
|
|
|
108
120
|
*
|
|
109
121
|
* @param str the string to match.
|
|
110
122
|
* @param flags flags for the RegExp.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { prefixRegex } from '@rolldown/pluginutils';
|
|
127
|
+
* const plugin = {
|
|
128
|
+
* name: 'plugin',
|
|
129
|
+
* resolveId: {
|
|
130
|
+
* filter: { id: prefixRegex('foo') },
|
|
131
|
+
* handler(id) {} // will only be called for IDs starting with `foo`
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
111
135
|
*/
|
|
112
136
|
declare function prefixRegex(str: string, flags?: string): RegExp;
|
|
113
137
|
type WidenString<T> = T extends string ? string : T;
|
|
@@ -115,6 +139,25 @@ type WidenString<T> = T extends string ? string : T;
|
|
|
115
139
|
* Converts a id filter to match with an id with a query.
|
|
116
140
|
*
|
|
117
141
|
* @param input the id filters to convert.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils';
|
|
146
|
+
* const plugin = {
|
|
147
|
+
* name: 'plugin',
|
|
148
|
+
* transform: {
|
|
149
|
+
* filter: { id: makeIdFiltersToMatchWithQuery(['**' + '/*.js', /\.ts$/]) },
|
|
150
|
+
* // The handler will be called for IDs like:
|
|
151
|
+
* // - foo.js
|
|
152
|
+
* // - foo.js?foo
|
|
153
|
+
* // - foo.txt?foo.js
|
|
154
|
+
* // - foo.ts
|
|
155
|
+
* // - foo.ts?foo
|
|
156
|
+
* // - foo.txt?foo.ts
|
|
157
|
+
* handler(code, id) {}
|
|
158
|
+
* }
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
118
161
|
*/
|
|
119
162
|
declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: T): WidenString<T>;
|
|
120
163
|
declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[];
|
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,18 @@ declare function exprInterpreter(expr: FilterExpression, code?: string, id?: str
|
|
|
99
99
|
*
|
|
100
100
|
* @param str the string to match.
|
|
101
101
|
* @param flags flags for the RegExp.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
106
|
+
* const plugin = {
|
|
107
|
+
* name: 'plugin',
|
|
108
|
+
* resolveId: {
|
|
109
|
+
* filter: { id: exactRegex('foo') },
|
|
110
|
+
* handler(id) {} // will only be called for `foo`
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
102
114
|
*/
|
|
103
115
|
declare function exactRegex(str: string, flags?: string): RegExp;
|
|
104
116
|
/**
|
|
@@ -108,6 +120,18 @@ declare function exactRegex(str: string, flags?: string): RegExp;
|
|
|
108
120
|
*
|
|
109
121
|
* @param str the string to match.
|
|
110
122
|
* @param flags flags for the RegExp.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { prefixRegex } from '@rolldown/pluginutils';
|
|
127
|
+
* const plugin = {
|
|
128
|
+
* name: 'plugin',
|
|
129
|
+
* resolveId: {
|
|
130
|
+
* filter: { id: prefixRegex('foo') },
|
|
131
|
+
* handler(id) {} // will only be called for IDs starting with `foo`
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
111
135
|
*/
|
|
112
136
|
declare function prefixRegex(str: string, flags?: string): RegExp;
|
|
113
137
|
type WidenString<T> = T extends string ? string : T;
|
|
@@ -115,6 +139,25 @@ type WidenString<T> = T extends string ? string : T;
|
|
|
115
139
|
* Converts a id filter to match with an id with a query.
|
|
116
140
|
*
|
|
117
141
|
* @param input the id filters to convert.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils';
|
|
146
|
+
* const plugin = {
|
|
147
|
+
* name: 'plugin',
|
|
148
|
+
* transform: {
|
|
149
|
+
* filter: { id: makeIdFiltersToMatchWithQuery(['**' + '/*.js', /\.ts$/]) },
|
|
150
|
+
* // The handler will be called for IDs like:
|
|
151
|
+
* // - foo.js
|
|
152
|
+
* // - foo.js?foo
|
|
153
|
+
* // - foo.txt?foo.js
|
|
154
|
+
* // - foo.ts
|
|
155
|
+
* // - foo.ts?foo
|
|
156
|
+
* // - foo.txt?foo.ts
|
|
157
|
+
* handler(code, id) {}
|
|
158
|
+
* }
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
118
161
|
*/
|
|
119
162
|
declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: T): WidenString<T>;
|
|
120
163
|
declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[];
|
package/dist/index.js
CHANGED
|
@@ -196,6 +196,18 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
196
196
|
*
|
|
197
197
|
* @param str the string to match.
|
|
198
198
|
* @param flags flags for the RegExp.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
203
|
+
* const plugin = {
|
|
204
|
+
* name: 'plugin',
|
|
205
|
+
* resolveId: {
|
|
206
|
+
* filter: { id: exactRegex('foo') },
|
|
207
|
+
* handler(id) {} // will only be called for `foo`
|
|
208
|
+
* }
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
199
211
|
*/
|
|
200
212
|
function exactRegex(str, flags) {
|
|
201
213
|
return new RegExp(`^${escapeRegex(str)}$`, flags);
|
|
@@ -207,6 +219,18 @@ function exactRegex(str, flags) {
|
|
|
207
219
|
*
|
|
208
220
|
* @param str the string to match.
|
|
209
221
|
* @param flags flags for the RegExp.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* import { prefixRegex } from '@rolldown/pluginutils';
|
|
226
|
+
* const plugin = {
|
|
227
|
+
* name: 'plugin',
|
|
228
|
+
* resolveId: {
|
|
229
|
+
* filter: { id: prefixRegex('foo') },
|
|
230
|
+
* handler(id) {} // will only be called for IDs starting with `foo`
|
|
231
|
+
* }
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
210
234
|
*/
|
|
211
235
|
function prefixRegex(str, flags) {
|
|
212
236
|
return new RegExp(`^${escapeRegex(str)}`, flags);
|