@vscode/rollup-plugin-esm-url 1.0.1-0

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 ADDED
@@ -0,0 +1,88 @@
1
+ # @vscode/rollup-plugin-esm-url
2
+
3
+ Rollup plugin for handling `?esm` URL imports.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vscode/rollup-plugin-esm-url --save-dev
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ // rollup.config.js
15
+ import { esmUrlPlugin } from '@vscode/rollup-plugin-esm-url';
16
+
17
+ export default {
18
+ input: 'src/index.js',
19
+ output: {
20
+ dir: 'dist',
21
+ format: 'es',
22
+ },
23
+ plugins: [esmUrlPlugin()],
24
+ };
25
+ ```
26
+
27
+ ## How it works
28
+
29
+ The plugin detects `new URL('./path?esm', import.meta.url)` patterns and:
30
+
31
+ 1. Emits the referenced file as a separate chunk
32
+ 2. Bundles it with all its dependencies
33
+ 3. Replaces the URL with the output filename
34
+
35
+ ## Features
36
+
37
+ - Works with TypeScript (via @rollup/plugin-typescript)
38
+ - Handles multiple workers with the same filename in different directories
39
+ - Compatible with Rollup 3.x and 4.x
40
+ - **Also works with Vite** (which uses Rollup under the hood)
41
+
42
+ ## Usage with Vite
43
+
44
+ ```js
45
+ // vite.config.js
46
+ import { defineConfig } from 'vite';
47
+ import { esmUrlPlugin } from '@vscode/rollup-plugin-esm-url';
48
+
49
+ export default defineConfig({
50
+ plugins: [esmUrlPlugin()],
51
+ });
52
+ ```
53
+
54
+ ## Options
55
+
56
+ ```typescript
57
+ interface EsmUrlPluginOptions {
58
+ /**
59
+ * When true, each ?esm referenced module is built in its own isolated rollup step.
60
+ * This ensures complete isolation between worker bundles but may be slower.
61
+ * When false (default), workers are emitted as chunks in the main build and
62
+ * only recompiled as ESM if the main output format is non-ESM.
63
+ */
64
+ bundleModulesIsolated?: boolean;
65
+
66
+ /**
67
+ * When true, strips the ?esm query parameter from output URLs.
68
+ * When false (default), preserves ?esm for re-bundling scenarios.
69
+ */
70
+ stripEsmQuery?: boolean;
71
+
72
+ /**
73
+ * Custom function to generate output file names for worker/module files.
74
+ * Receives the file path and suggested name, should return the desired name (without extension).
75
+ */
76
+ getOutputFileName?: (info: { filePath: string; suggestedName: string }) => string;
77
+ }
78
+ ```
79
+
80
+ ### Example with options
81
+
82
+ ```js
83
+ esmUrlPlugin({
84
+ bundleModulesIsolated: true,
85
+ stripEsmQuery: true,
86
+ getOutputFileName: ({ suggestedName }) => `worker-${suggestedName}`,
87
+ })
88
+ ```
@@ -0,0 +1,25 @@
1
+ import type { Plugin } from 'rollup';
2
+ import { type OutputFileNameInfo } from '@vscode/esm-url-plugin-common';
3
+ export type { OutputFileNameInfo };
4
+ interface EsmUrlPluginOptions {
5
+ /**
6
+ * When true, each ?esm referenced module is built in its own isolated rollup step.
7
+ * This ensures complete isolation between worker bundles but may be slower.
8
+ * When false (default), workers are emitted as chunks in the main build and
9
+ * only recompiled as ESM if the main output format is non-ESM.
10
+ */
11
+ bundleModulesIsolated?: boolean;
12
+ /**
13
+ * When true, strips the ?esm query parameter from output URLs.
14
+ * When false (default), preserves ?esm for re-bundling scenarios.
15
+ */
16
+ stripEsmQuery?: boolean;
17
+ /**
18
+ * Custom function to generate output file names for worker/module files.
19
+ * Receives the file path and suggested name, should return the desired name (without extension).
20
+ */
21
+ getOutputFileName?: (info: OutputFileNameInfo) => string;
22
+ }
23
+ export declare function esmUrlPlugin(options?: EsmUrlPluginOptions): Plugin;
24
+ export { esmUrlPlugin as rollupEsmUrlPlugin };
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAKL,KAAK,kBAAkB,EAExB,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAKnC,UAAU,mBAAmB;IAC3B;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,MAAM,CAAC;CAC1D;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CA8QtE;AAED,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,327 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var rollup = require('rollup');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
25
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
26
+
27
+ /**
28
+ * Strips only the 'esm' parameter from a query string, preserving other parameters.
29
+ * @param queryString The full query string (e.g., '?esm&foo=true' or '?foo=true&esm&bar=1')
30
+ * @returns The query string without the 'esm' parameter, or empty string if no params remain
31
+ */
32
+ function stripEsmFromQuery(queryString) {
33
+ if (queryString === '?esm')
34
+ return '';
35
+ const params = new URLSearchParams(queryString.startsWith('?') ? queryString.slice(1) : queryString);
36
+ params.delete('esm');
37
+ const result = params.toString();
38
+ return result ? '?' + result : '';
39
+ }
40
+
41
+ /**
42
+ * Generates a bundle entry name from a file path relative to a context directory.
43
+ *
44
+ * @param absolutePath - Absolute path to the worker/module file
45
+ * @param contextDir - Context directory to compute relative path from
46
+ * @returns A sanitized entry name suitable for use as a bundle filename
47
+ */
48
+ function generateEntryName(absolutePath, contextDir) {
49
+ let relativePath = path__namespace.relative(contextDir, absolutePath);
50
+ // Handle cross-drive paths on Windows: path.relative() returns absolute path
51
+ // when paths are on different drives (e.g., C: vs D:)
52
+ if (path__namespace.isAbsolute(relativePath)) {
53
+ // Strip drive letter (e.g., "D:" or "D:\") on Windows
54
+ relativePath = relativePath.replace(/^[a-zA-Z]:[\\\/]?/, '');
55
+ }
56
+ return relativePath
57
+ .replace(/\.[^/.]+$/, '') // Remove extension
58
+ .replace(/\\/g, '/') // Normalize Windows slashes
59
+ .replace(/^(\.\.\/)+/g, '') // Remove leading ../ segments
60
+ .replace(/^\.\//, '') // Remove leading ./
61
+ .replace(/\//g, '-') // Replace slashes with dashes
62
+ .replace(/^\.+/, ''); // Remove any remaining leading dots
63
+ }
64
+
65
+ const ESM_QUERY = '?esm';
66
+ /**
67
+ * Finds `new URL('...?esm...', import.meta.url)` patterns using regex.
68
+ * May have false positives in comments or strings, but this is rare in practice.
69
+ */
70
+ function findMatches(code) {
71
+ const urlPattern = /new\s+URL\s*\(\s*(['"`])([^'"`]+\?esm[^'"`]*)\1\s*,\s*import\.meta\.url\s*\)/g;
72
+ const matches = [];
73
+ let match;
74
+ while ((match = urlPattern.exec(code)) !== null) {
75
+ const urlString = match[2];
76
+ if (urlString.includes(ESM_QUERY)) {
77
+ matches.push({
78
+ urlString,
79
+ start: match.index,
80
+ end: match.index + match[0].length,
81
+ });
82
+ }
83
+ }
84
+ return matches;
85
+ }
86
+
87
+ /** Prefix for virtual module IDs */
88
+ const VIRTUAL_PREFIX = '\0esm-url:';
89
+ function esmUrlPlugin(options = {}) {
90
+ const { bundleModulesIsolated = false, stripEsmQuery = false, getOutputFileName } = options;
91
+ // State variables - reset in buildStart to support multiple builds
92
+ let workerEntries; // absolutePath -> entryName
93
+ let emittedChunks; // entryName -> { referenceId, originalQuery }
94
+ let referenceIdToQuery; // referenceId -> originalQuery
95
+ // For isolated builds: referenceId -> build info (emitted as assets, built separately)
96
+ let pendingIsolatedBuilds;
97
+ // For non-isolated builds with non-ESM output: referenceId -> build info (emitted as chunks, need recompilation)
98
+ let pendingRecompilation;
99
+ // Additional assets to emit (for multi-chunk isolated workers)
100
+ let additionalAssets;
101
+ // Track our emitted reference IDs
102
+ let ourReferenceIds;
103
+ let outputFormat = 'es';
104
+ return {
105
+ name: 'esm-url-plugin',
106
+ buildStart() {
107
+ // Reset all state for new build
108
+ workerEntries = new Map();
109
+ emittedChunks = new Map();
110
+ referenceIdToQuery = new Map();
111
+ pendingIsolatedBuilds = new Map();
112
+ pendingRecompilation = new Map();
113
+ additionalAssets = [];
114
+ ourReferenceIds = new Set();
115
+ outputFormat = 'es';
116
+ },
117
+ outputOptions(outputOpts) {
118
+ outputFormat = outputOpts.format || 'es';
119
+ outputOpts.dir || (outputOpts.file ? path__namespace.dirname(outputOpts.file) : undefined);
120
+ return null;
121
+ },
122
+ resolveFileUrl({ referenceId, fileName, relativePath }) {
123
+ // Only customize resolution for files we emitted
124
+ if (!ourReferenceIds.has(referenceId)) {
125
+ return null; // Let other plugins or default handling take over
126
+ }
127
+ // Return the relative path, optionally with ?esm preserved for re-bundling
128
+ const originalQuery = referenceIdToQuery.get(referenceId) || ESM_QUERY;
129
+ const suffix = stripEsmQuery ? stripEsmFromQuery(originalQuery) : originalQuery;
130
+ return `'${relativePath}${suffix}'`;
131
+ },
132
+ async resolveId(source, importer) {
133
+ // Handle virtual worker entry points
134
+ if (source.startsWith(VIRTUAL_PREFIX)) {
135
+ return source;
136
+ }
137
+ return null;
138
+ },
139
+ async load(id) {
140
+ // Load virtual worker entry points
141
+ if (id.startsWith(VIRTUAL_PREFIX)) {
142
+ const actualPath = id.slice(VIRTUAL_PREFIX.length);
143
+ // Re-export from the actual file
144
+ return `export * from ${JSON.stringify(actualPath)};`;
145
+ }
146
+ return null;
147
+ },
148
+ async renderStart() {
149
+ // Build isolated workers and set their asset sources before rendering
150
+ for (const [referenceId, buildInfo] of pendingIsolatedBuilds) {
151
+ const esmBundle = await rollup.rollup({
152
+ input: buildInfo.filePath,
153
+ onwarn: (warning, warn) => {
154
+ if (warning.code === 'UNRESOLVED_IMPORT')
155
+ return;
156
+ warn(warning);
157
+ },
158
+ });
159
+ const { output } = await esmBundle.generate({
160
+ format: 'es',
161
+ entryFileNames: '[name].js',
162
+ chunkFileNames: '[name]-[hash].js',
163
+ });
164
+ await esmBundle.close();
165
+ // Set the asset source to the built ESM code
166
+ const entryChunk = output.find(o => o.type === 'chunk' && o.isEntry);
167
+ if (entryChunk && entryChunk.type === 'chunk') {
168
+ this.setAssetSource(referenceId, entryChunk.code);
169
+ }
170
+ // Store additional chunks to emit later in generateBundle
171
+ for (const chunk of output) {
172
+ if (chunk.type === 'chunk' && !chunk.isEntry) {
173
+ additionalAssets.push({ fileName: chunk.fileName, source: chunk.code });
174
+ }
175
+ }
176
+ }
177
+ pendingIsolatedBuilds.clear();
178
+ },
179
+ async transform(code, id) {
180
+ // Skip non-JS files
181
+ if (!/\.[jt]sx?$/.test(id)) {
182
+ return null;
183
+ }
184
+ // Quick check: skip files that don't contain ?esm
185
+ if (!code.includes(ESM_QUERY)) {
186
+ return null;
187
+ }
188
+ const rawMatches = findMatches(code);
189
+ if (rawMatches.length === 0) {
190
+ return null;
191
+ }
192
+ // Convert raw matches to full matches with resolved paths
193
+ const contextDir = process.cwd();
194
+ const matches = [];
195
+ for (const raw of rawMatches) {
196
+ const [workerPath, ...queryParts] = raw.urlString.split('?');
197
+ const originalQuery = queryParts.length > 0 ? '?' + queryParts.join('?') : '';
198
+ const importerDir = path__namespace.dirname(id);
199
+ const absolutePath = path__namespace.resolve(importerDir, workerPath);
200
+ // Check that the file exists
201
+ if (!fs__namespace.existsSync(absolutePath)) {
202
+ const lines = code.slice(0, raw.start).split('\n');
203
+ const line = lines.length;
204
+ const column = lines[lines.length - 1].length;
205
+ this.error({
206
+ message: `File not found: '${workerPath}' resolved to '${absolutePath}'. Check that the path in new URL('${raw.urlString}', import.meta.url) points to an existing file.`,
207
+ id,
208
+ loc: { line, column },
209
+ });
210
+ }
211
+ let entryName = generateEntryName(absolutePath, contextDir);
212
+ // Apply custom output file name if provided
213
+ if (getOutputFileName) {
214
+ entryName = getOutputFileName({ filePath: absolutePath, suggestedName: entryName });
215
+ }
216
+ workerEntries.set(absolutePath, entryName);
217
+ matches.push({
218
+ filePath: absolutePath,
219
+ entryName,
220
+ originalQuery,
221
+ start: raw.start,
222
+ end: raw.end,
223
+ });
224
+ }
225
+ // Replace matches in reverse order to preserve positions
226
+ let newCode = code;
227
+ for (const m of matches.reverse()) {
228
+ let referenceId;
229
+ if (bundleModulesIsolated) {
230
+ // Emit as asset - will be built separately, not part of main module graph
231
+ referenceId = this.emitFile({
232
+ type: 'asset',
233
+ name: `${m.entryName}.js`,
234
+ });
235
+ pendingIsolatedBuilds.set(referenceId, { filePath: m.filePath, entryName: m.entryName });
236
+ }
237
+ else {
238
+ // Emit as chunk - part of main module graph, may share code with main bundle
239
+ referenceId = this.emitFile({
240
+ type: 'chunk',
241
+ id: m.filePath,
242
+ name: m.entryName,
243
+ });
244
+ pendingRecompilation.set(referenceId, { filePath: m.filePath, entryName: m.entryName });
245
+ }
246
+ ourReferenceIds.add(referenceId);
247
+ referenceIdToQuery.set(referenceId, m.originalQuery);
248
+ emittedChunks.set(m.entryName, { referenceId, originalQuery: m.originalQuery });
249
+ // Replace with new URL using the resolved file URL
250
+ // import.meta.ROLLUP_FILE_URL_<referenceId> will be replaced by resolveFileUrl hook
251
+ const replacement = `new URL(import.meta.ROLLUP_FILE_URL_${referenceId}, import.meta.url)`;
252
+ newCode = newCode.slice(0, m.start) + replacement + newCode.slice(m.end);
253
+ }
254
+ return {
255
+ code: newCode,
256
+ map: null, // TODO: Generate proper source map
257
+ };
258
+ },
259
+ async generateBundle(outputOpts, bundle) {
260
+ const isEsmOutput = outputFormat === 'es' || outputFormat === 'esm';
261
+ // Emit additional assets from isolated worker builds (multi-chunk workers)
262
+ for (const asset of additionalAssets) {
263
+ this.emitFile({
264
+ type: 'asset',
265
+ fileName: asset.fileName,
266
+ source: asset.source,
267
+ });
268
+ }
269
+ additionalAssets.length = 0;
270
+ // Handle non-isolated builds with non-ESM output - recompile chunks as ESM
271
+ if (!isEsmOutput) {
272
+ for (const [referenceId, buildInfo] of pendingRecompilation) {
273
+ const fileName = this.getFileName(referenceId);
274
+ const originalChunk = bundle[fileName];
275
+ if (!originalChunk || originalChunk.type !== 'chunk') {
276
+ continue;
277
+ }
278
+ // Build the worker as ESM using a separate rollup instance
279
+ const esmBundle = await rollup.rollup({
280
+ input: buildInfo.filePath,
281
+ onwarn: (warning, warn) => {
282
+ if (warning.code === 'UNRESOLVED_IMPORT')
283
+ return;
284
+ warn(warning);
285
+ },
286
+ });
287
+ const { output } = await esmBundle.generate({
288
+ format: 'es',
289
+ entryFileNames: '[name].js',
290
+ chunkFileNames: '[name]-[hash].js',
291
+ });
292
+ await esmBundle.close();
293
+ // Replace the chunk content with ESM
294
+ if (output.length === 1 && output[0].type === 'chunk') {
295
+ originalChunk.code = output[0].code;
296
+ if (output[0].map) {
297
+ originalChunk.map = output[0].map;
298
+ }
299
+ }
300
+ else {
301
+ const entryChunk = output.find(o => o.type === 'chunk' && o.isEntry);
302
+ if (entryChunk && entryChunk.type === 'chunk') {
303
+ originalChunk.code = entryChunk.code;
304
+ if (entryChunk.map) {
305
+ originalChunk.map = entryChunk.map;
306
+ }
307
+ }
308
+ for (const chunk of output) {
309
+ if (chunk.type === 'chunk' && !chunk.isEntry) {
310
+ this.emitFile({
311
+ type: 'asset',
312
+ fileName: chunk.fileName,
313
+ source: chunk.code,
314
+ });
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+ pendingRecompilation.clear();
321
+ },
322
+ };
323
+ }
324
+
325
+ exports.esmUrlPlugin = esmUrlPlugin;
326
+ exports.rollupEsmUrlPlugin = esmUrlPlugin;
327
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../common/dist/esm/index.js","../../../src/index.ts"],"sourcesContent":["import * as path from 'path';\n\n/**\n * Strips only the 'esm' parameter from a query string, preserving other parameters.\n * @param queryString The full query string (e.g., '?esm&foo=true' or '?foo=true&esm&bar=1')\n * @returns The query string without the 'esm' parameter, or empty string if no params remain\n */\nfunction stripEsmFromQuery(queryString) {\n if (!queryString || queryString === '?esm')\n return '';\n const params = new URLSearchParams(queryString.startsWith('?') ? queryString.slice(1) : queryString);\n params.delete('esm');\n const result = params.toString();\n return result ? '?' + result : '';\n}\n\n/**\n * Generates a bundle entry name from a file path relative to a context directory.\n *\n * @param absolutePath - Absolute path to the worker/module file\n * @param contextDir - Context directory to compute relative path from\n * @returns A sanitized entry name suitable for use as a bundle filename\n */\nfunction generateEntryName(absolutePath, contextDir) {\n let relativePath = path.relative(contextDir, absolutePath);\n // Handle cross-drive paths on Windows: path.relative() returns absolute path\n // when paths are on different drives (e.g., C: vs D:)\n if (path.isAbsolute(relativePath)) {\n // Strip drive letter (e.g., \"D:\" or \"D:\\\") on Windows\n relativePath = relativePath.replace(/^[a-zA-Z]:[\\\\\\/]?/, '');\n }\n return relativePath\n .replace(/\\.[^/.]+$/, '') // Remove extension\n .replace(/\\\\/g, '/') // Normalize Windows slashes\n .replace(/^(\\.\\.\\/)+/g, '') // Remove leading ../ segments\n .replace(/^\\.\\//, '') // Remove leading ./\n .replace(/\\//g, '-') // Replace slashes with dashes\n .replace(/^\\.+/, ''); // Remove any remaining leading dots\n}\n\nconst ESM_QUERY = '?esm';\n/**\n * Finds `new URL('...?esm...', import.meta.url)` patterns using regex.\n * May have false positives in comments or strings, but this is rare in practice.\n */\nfunction findMatches(code) {\n const urlPattern = /new\\s+URL\\s*\\(\\s*(['\"`])([^'\"`]+\\?esm[^'\"`]*)\\1\\s*,\\s*import\\.meta\\.url\\s*\\)/g;\n const matches = [];\n let match;\n while ((match = urlPattern.exec(code)) !== null) {\n const urlString = match[2];\n if (urlString.includes(ESM_QUERY)) {\n matches.push({\n urlString,\n start: match.index,\n end: match.index + match[0].length,\n });\n }\n }\n return matches;\n}\n\nexport { ESM_QUERY, findMatches, generateEntryName, stripEsmFromQuery };\n//# sourceMappingURL=index.js.map\n",null],"names":["path","rollup","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,WAAW,EAAE;AACxC,IAAI,IAAoB,WAAW,KAAK,MAAM;AAC9C,QAAQ,OAAO,EAAE;AACjB,IAAI,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AACxG,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;AACxB,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;AACpC,IAAI,OAAO,MAAM,GAAG,GAAG,GAAG,MAAM,GAAG,EAAE;AACrC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,YAAY,EAAE,UAAU,EAAE;AACrD,IAAI,IAAI,YAAY,GAAGA,eAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;AAC9D;AACA;AACA,IAAI,IAAIA,eAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;AACvC;AACA,QAAQ,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;AACpE,IAAI;AACJ,IAAI,OAAO;AACX,SAAS,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AACjC,SAAS,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC5B,SAAS,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;AACnC,SAAS,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AAC7B,SAAS,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AAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC;wBACpE,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE;AAC7C,4BAAA,aAAa,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI;AACpC,4BAAA,IAAI,UAAU,CAAC,GAAG,EAAE;AAClB,gCAAA,aAAa,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG;4BACpC;wBACF;AAEA,wBAAA,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;4BAC1B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;gCAC5C,IAAI,CAAC,QAAQ,CAAC;AACZ,oCAAA,IAAI,EAAE,OAAO;oCACb,QAAQ,EAAE,KAAK,CAAC,QAAQ;oCACxB,MAAM,EAAE,KAAK,CAAC,IAAI;AACnB,iCAAA,CAAC;4BACJ;wBACF;oBACF;gBACF;YACF;YACA,oBAAoB,CAAC,KAAK,EAAE;QAC9B,CAAC;KACF;AACH;;;;;"}
@@ -0,0 +1,25 @@
1
+ import type { Plugin } from 'rollup';
2
+ import { type OutputFileNameInfo } from '@vscode/esm-url-plugin-common';
3
+ export type { OutputFileNameInfo };
4
+ interface EsmUrlPluginOptions {
5
+ /**
6
+ * When true, each ?esm referenced module is built in its own isolated rollup step.
7
+ * This ensures complete isolation between worker bundles but may be slower.
8
+ * When false (default), workers are emitted as chunks in the main build and
9
+ * only recompiled as ESM if the main output format is non-ESM.
10
+ */
11
+ bundleModulesIsolated?: boolean;
12
+ /**
13
+ * When true, strips the ?esm query parameter from output URLs.
14
+ * When false (default), preserves ?esm for re-bundling scenarios.
15
+ */
16
+ stripEsmQuery?: boolean;
17
+ /**
18
+ * Custom function to generate output file names for worker/module files.
19
+ * Receives the file path and suggested name, should return the desired name (without extension).
20
+ */
21
+ getOutputFileName?: (info: OutputFileNameInfo) => string;
22
+ }
23
+ export declare function esmUrlPlugin(options?: EsmUrlPluginOptions): Plugin;
24
+ export { esmUrlPlugin as rollupEsmUrlPlugin };
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAKL,KAAK,kBAAkB,EAExB,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAKnC,UAAU,mBAAmB;IAC3B;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,MAAM,CAAC;CAC1D;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CA8QtE;AAED,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,304 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+ import { rollup } from 'rollup';
4
+
5
+ /**
6
+ * Strips only the 'esm' parameter from a query string, preserving other parameters.
7
+ * @param queryString The full query string (e.g., '?esm&foo=true' or '?foo=true&esm&bar=1')
8
+ * @returns The query string without the 'esm' parameter, or empty string if no params remain
9
+ */
10
+ function stripEsmFromQuery(queryString) {
11
+ if (queryString === '?esm')
12
+ return '';
13
+ const params = new URLSearchParams(queryString.startsWith('?') ? queryString.slice(1) : queryString);
14
+ params.delete('esm');
15
+ const result = params.toString();
16
+ return result ? '?' + result : '';
17
+ }
18
+
19
+ /**
20
+ * Generates a bundle entry name from a file path relative to a context directory.
21
+ *
22
+ * @param absolutePath - Absolute path to the worker/module file
23
+ * @param contextDir - Context directory to compute relative path from
24
+ * @returns A sanitized entry name suitable for use as a bundle filename
25
+ */
26
+ function generateEntryName(absolutePath, contextDir) {
27
+ let relativePath = path.relative(contextDir, absolutePath);
28
+ // Handle cross-drive paths on Windows: path.relative() returns absolute path
29
+ // when paths are on different drives (e.g., C: vs D:)
30
+ if (path.isAbsolute(relativePath)) {
31
+ // Strip drive letter (e.g., "D:" or "D:\") on Windows
32
+ relativePath = relativePath.replace(/^[a-zA-Z]:[\\\/]?/, '');
33
+ }
34
+ return relativePath
35
+ .replace(/\.[^/.]+$/, '') // Remove extension
36
+ .replace(/\\/g, '/') // Normalize Windows slashes
37
+ .replace(/^(\.\.\/)+/g, '') // Remove leading ../ segments
38
+ .replace(/^\.\//, '') // Remove leading ./
39
+ .replace(/\//g, '-') // Replace slashes with dashes
40
+ .replace(/^\.+/, ''); // Remove any remaining leading dots
41
+ }
42
+
43
+ const ESM_QUERY = '?esm';
44
+ /**
45
+ * Finds `new URL('...?esm...', import.meta.url)` patterns using regex.
46
+ * May have false positives in comments or strings, but this is rare in practice.
47
+ */
48
+ function findMatches(code) {
49
+ const urlPattern = /new\s+URL\s*\(\s*(['"`])([^'"`]+\?esm[^'"`]*)\1\s*,\s*import\.meta\.url\s*\)/g;
50
+ const matches = [];
51
+ let match;
52
+ while ((match = urlPattern.exec(code)) !== null) {
53
+ const urlString = match[2];
54
+ if (urlString.includes(ESM_QUERY)) {
55
+ matches.push({
56
+ urlString,
57
+ start: match.index,
58
+ end: match.index + match[0].length,
59
+ });
60
+ }
61
+ }
62
+ return matches;
63
+ }
64
+
65
+ /** Prefix for virtual module IDs */
66
+ const VIRTUAL_PREFIX = '\0esm-url:';
67
+ function esmUrlPlugin(options = {}) {
68
+ const { bundleModulesIsolated = false, stripEsmQuery = false, getOutputFileName } = options;
69
+ // State variables - reset in buildStart to support multiple builds
70
+ let workerEntries; // absolutePath -> entryName
71
+ let emittedChunks; // entryName -> { referenceId, originalQuery }
72
+ let referenceIdToQuery; // referenceId -> originalQuery
73
+ // For isolated builds: referenceId -> build info (emitted as assets, built separately)
74
+ let pendingIsolatedBuilds;
75
+ // For non-isolated builds with non-ESM output: referenceId -> build info (emitted as chunks, need recompilation)
76
+ let pendingRecompilation;
77
+ // Additional assets to emit (for multi-chunk isolated workers)
78
+ let additionalAssets;
79
+ // Track our emitted reference IDs
80
+ let ourReferenceIds;
81
+ let outputFormat = 'es';
82
+ return {
83
+ name: 'esm-url-plugin',
84
+ buildStart() {
85
+ // Reset all state for new build
86
+ workerEntries = new Map();
87
+ emittedChunks = new Map();
88
+ referenceIdToQuery = new Map();
89
+ pendingIsolatedBuilds = new Map();
90
+ pendingRecompilation = new Map();
91
+ additionalAssets = [];
92
+ ourReferenceIds = new Set();
93
+ outputFormat = 'es';
94
+ },
95
+ outputOptions(outputOpts) {
96
+ outputFormat = outputOpts.format || 'es';
97
+ outputOpts.dir || (outputOpts.file ? path.dirname(outputOpts.file) : undefined);
98
+ return null;
99
+ },
100
+ resolveFileUrl({ referenceId, fileName, relativePath }) {
101
+ // Only customize resolution for files we emitted
102
+ if (!ourReferenceIds.has(referenceId)) {
103
+ return null; // Let other plugins or default handling take over
104
+ }
105
+ // Return the relative path, optionally with ?esm preserved for re-bundling
106
+ const originalQuery = referenceIdToQuery.get(referenceId) || ESM_QUERY;
107
+ const suffix = stripEsmQuery ? stripEsmFromQuery(originalQuery) : originalQuery;
108
+ return `'${relativePath}${suffix}'`;
109
+ },
110
+ async resolveId(source, importer) {
111
+ // Handle virtual worker entry points
112
+ if (source.startsWith(VIRTUAL_PREFIX)) {
113
+ return source;
114
+ }
115
+ return null;
116
+ },
117
+ async load(id) {
118
+ // Load virtual worker entry points
119
+ if (id.startsWith(VIRTUAL_PREFIX)) {
120
+ const actualPath = id.slice(VIRTUAL_PREFIX.length);
121
+ // Re-export from the actual file
122
+ return `export * from ${JSON.stringify(actualPath)};`;
123
+ }
124
+ return null;
125
+ },
126
+ async renderStart() {
127
+ // Build isolated workers and set their asset sources before rendering
128
+ for (const [referenceId, buildInfo] of pendingIsolatedBuilds) {
129
+ const esmBundle = await rollup({
130
+ input: buildInfo.filePath,
131
+ onwarn: (warning, warn) => {
132
+ if (warning.code === 'UNRESOLVED_IMPORT')
133
+ return;
134
+ warn(warning);
135
+ },
136
+ });
137
+ const { output } = await esmBundle.generate({
138
+ format: 'es',
139
+ entryFileNames: '[name].js',
140
+ chunkFileNames: '[name]-[hash].js',
141
+ });
142
+ await esmBundle.close();
143
+ // Set the asset source to the built ESM code
144
+ const entryChunk = output.find(o => o.type === 'chunk' && o.isEntry);
145
+ if (entryChunk && entryChunk.type === 'chunk') {
146
+ this.setAssetSource(referenceId, entryChunk.code);
147
+ }
148
+ // Store additional chunks to emit later in generateBundle
149
+ for (const chunk of output) {
150
+ if (chunk.type === 'chunk' && !chunk.isEntry) {
151
+ additionalAssets.push({ fileName: chunk.fileName, source: chunk.code });
152
+ }
153
+ }
154
+ }
155
+ pendingIsolatedBuilds.clear();
156
+ },
157
+ async transform(code, id) {
158
+ // Skip non-JS files
159
+ if (!/\.[jt]sx?$/.test(id)) {
160
+ return null;
161
+ }
162
+ // Quick check: skip files that don't contain ?esm
163
+ if (!code.includes(ESM_QUERY)) {
164
+ return null;
165
+ }
166
+ const rawMatches = findMatches(code);
167
+ if (rawMatches.length === 0) {
168
+ return null;
169
+ }
170
+ // Convert raw matches to full matches with resolved paths
171
+ const contextDir = process.cwd();
172
+ const matches = [];
173
+ for (const raw of rawMatches) {
174
+ const [workerPath, ...queryParts] = raw.urlString.split('?');
175
+ const originalQuery = queryParts.length > 0 ? '?' + queryParts.join('?') : '';
176
+ const importerDir = path.dirname(id);
177
+ const absolutePath = path.resolve(importerDir, workerPath);
178
+ // Check that the file exists
179
+ if (!fs.existsSync(absolutePath)) {
180
+ const lines = code.slice(0, raw.start).split('\n');
181
+ const line = lines.length;
182
+ const column = lines[lines.length - 1].length;
183
+ this.error({
184
+ message: `File not found: '${workerPath}' resolved to '${absolutePath}'. Check that the path in new URL('${raw.urlString}', import.meta.url) points to an existing file.`,
185
+ id,
186
+ loc: { line, column },
187
+ });
188
+ }
189
+ let entryName = generateEntryName(absolutePath, contextDir);
190
+ // Apply custom output file name if provided
191
+ if (getOutputFileName) {
192
+ entryName = getOutputFileName({ filePath: absolutePath, suggestedName: entryName });
193
+ }
194
+ workerEntries.set(absolutePath, entryName);
195
+ matches.push({
196
+ filePath: absolutePath,
197
+ entryName,
198
+ originalQuery,
199
+ start: raw.start,
200
+ end: raw.end,
201
+ });
202
+ }
203
+ // Replace matches in reverse order to preserve positions
204
+ let newCode = code;
205
+ for (const m of matches.reverse()) {
206
+ let referenceId;
207
+ if (bundleModulesIsolated) {
208
+ // Emit as asset - will be built separately, not part of main module graph
209
+ referenceId = this.emitFile({
210
+ type: 'asset',
211
+ name: `${m.entryName}.js`,
212
+ });
213
+ pendingIsolatedBuilds.set(referenceId, { filePath: m.filePath, entryName: m.entryName });
214
+ }
215
+ else {
216
+ // Emit as chunk - part of main module graph, may share code with main bundle
217
+ referenceId = this.emitFile({
218
+ type: 'chunk',
219
+ id: m.filePath,
220
+ name: m.entryName,
221
+ });
222
+ pendingRecompilation.set(referenceId, { filePath: m.filePath, entryName: m.entryName });
223
+ }
224
+ ourReferenceIds.add(referenceId);
225
+ referenceIdToQuery.set(referenceId, m.originalQuery);
226
+ emittedChunks.set(m.entryName, { referenceId, originalQuery: m.originalQuery });
227
+ // Replace with new URL using the resolved file URL
228
+ // import.meta.ROLLUP_FILE_URL_<referenceId> will be replaced by resolveFileUrl hook
229
+ const replacement = `new URL(import.meta.ROLLUP_FILE_URL_${referenceId}, import.meta.url)`;
230
+ newCode = newCode.slice(0, m.start) + replacement + newCode.slice(m.end);
231
+ }
232
+ return {
233
+ code: newCode,
234
+ map: null, // TODO: Generate proper source map
235
+ };
236
+ },
237
+ async generateBundle(outputOpts, bundle) {
238
+ const isEsmOutput = outputFormat === 'es' || outputFormat === 'esm';
239
+ // Emit additional assets from isolated worker builds (multi-chunk workers)
240
+ for (const asset of additionalAssets) {
241
+ this.emitFile({
242
+ type: 'asset',
243
+ fileName: asset.fileName,
244
+ source: asset.source,
245
+ });
246
+ }
247
+ additionalAssets.length = 0;
248
+ // Handle non-isolated builds with non-ESM output - recompile chunks as ESM
249
+ if (!isEsmOutput) {
250
+ for (const [referenceId, buildInfo] of pendingRecompilation) {
251
+ const fileName = this.getFileName(referenceId);
252
+ const originalChunk = bundle[fileName];
253
+ if (!originalChunk || originalChunk.type !== 'chunk') {
254
+ continue;
255
+ }
256
+ // Build the worker as ESM using a separate rollup instance
257
+ const esmBundle = await rollup({
258
+ input: buildInfo.filePath,
259
+ onwarn: (warning, warn) => {
260
+ if (warning.code === 'UNRESOLVED_IMPORT')
261
+ return;
262
+ warn(warning);
263
+ },
264
+ });
265
+ const { output } = await esmBundle.generate({
266
+ format: 'es',
267
+ entryFileNames: '[name].js',
268
+ chunkFileNames: '[name]-[hash].js',
269
+ });
270
+ await esmBundle.close();
271
+ // Replace the chunk content with ESM
272
+ if (output.length === 1 && output[0].type === 'chunk') {
273
+ originalChunk.code = output[0].code;
274
+ if (output[0].map) {
275
+ originalChunk.map = output[0].map;
276
+ }
277
+ }
278
+ else {
279
+ const entryChunk = output.find(o => o.type === 'chunk' && o.isEntry);
280
+ if (entryChunk && entryChunk.type === 'chunk') {
281
+ originalChunk.code = entryChunk.code;
282
+ if (entryChunk.map) {
283
+ originalChunk.map = entryChunk.map;
284
+ }
285
+ }
286
+ for (const chunk of output) {
287
+ if (chunk.type === 'chunk' && !chunk.isEntry) {
288
+ this.emitFile({
289
+ type: 'asset',
290
+ fileName: chunk.fileName,
291
+ source: chunk.code,
292
+ });
293
+ }
294
+ }
295
+ }
296
+ }
297
+ }
298
+ pendingRecompilation.clear();
299
+ },
300
+ };
301
+ }
302
+
303
+ export { esmUrlPlugin, esmUrlPlugin as rollupEsmUrlPlugin };
304
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../common/dist/esm/index.js","../../../src/index.ts"],"sourcesContent":["import * as path from 'path';\n\n/**\n * Strips only the 'esm' parameter from a query string, preserving other parameters.\n * @param queryString The full query string (e.g., '?esm&foo=true' or '?foo=true&esm&bar=1')\n * @returns The query string without the 'esm' parameter, or empty string if no params remain\n */\nfunction stripEsmFromQuery(queryString) {\n if (!queryString || queryString === '?esm')\n return '';\n const params = new URLSearchParams(queryString.startsWith('?') ? queryString.slice(1) : queryString);\n params.delete('esm');\n const result = params.toString();\n return result ? '?' + result : '';\n}\n\n/**\n * Generates a bundle entry name from a file path relative to a context directory.\n *\n * @param absolutePath - Absolute path to the worker/module file\n * @param contextDir - Context directory to compute relative path from\n * @returns A sanitized entry name suitable for use as a bundle filename\n */\nfunction generateEntryName(absolutePath, contextDir) {\n let relativePath = path.relative(contextDir, absolutePath);\n // Handle cross-drive paths on Windows: path.relative() returns absolute path\n // when paths are on different drives (e.g., C: vs D:)\n if (path.isAbsolute(relativePath)) {\n // Strip drive letter (e.g., \"D:\" or \"D:\\\") on Windows\n relativePath = relativePath.replace(/^[a-zA-Z]:[\\\\\\/]?/, '');\n }\n return relativePath\n .replace(/\\.[^/.]+$/, '') // Remove extension\n .replace(/\\\\/g, '/') // Normalize Windows slashes\n .replace(/^(\\.\\.\\/)+/g, '') // Remove leading ../ segments\n .replace(/^\\.\\//, '') // Remove leading ./\n .replace(/\\//g, '-') // Replace slashes with dashes\n .replace(/^\\.+/, ''); // Remove any remaining leading dots\n}\n\nconst ESM_QUERY = '?esm';\n/**\n * Finds `new URL('...?esm...', import.meta.url)` patterns using regex.\n * May have false positives in comments or strings, but this is rare in practice.\n */\nfunction findMatches(code) {\n const urlPattern = /new\\s+URL\\s*\\(\\s*(['\"`])([^'\"`]+\\?esm[^'\"`]*)\\1\\s*,\\s*import\\.meta\\.url\\s*\\)/g;\n const matches = [];\n let match;\n while ((match = urlPattern.exec(code)) !== null) {\n const urlString = match[2];\n if (urlString.includes(ESM_QUERY)) {\n matches.push({\n urlString,\n start: match.index,\n end: match.index + match[0].length,\n });\n }\n }\n return matches;\n}\n\nexport { ESM_QUERY, findMatches, generateEntryName, stripEsmFromQuery };\n//# sourceMappingURL=index.js.map\n",null],"names":[],"mappings":";;;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,WAAW,EAAE;AACxC,IAAI,IAAoB,WAAW,KAAK,MAAM;AAC9C,QAAQ,OAAO,EAAE;AACjB,IAAI,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AACxG,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;AACxB,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;AACpC,IAAI,OAAO,MAAM,GAAG,GAAG,GAAG,MAAM,GAAG,EAAE;AACrC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,YAAY,EAAE,UAAU,EAAE;AACrD,IAAI,IAAI,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;AAC9D;AACA;AACA,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;AACvC;AACA,QAAQ,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;AACpE,IAAI;AACJ,IAAI,OAAO;AACX,SAAS,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AACjC,SAAS,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC5B,SAAS,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;AACnC,SAAS,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AAC7B,SAAS,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC5B,SAAS,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7B;;AAEA,MAAM,SAAS,GA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UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE;AAC7C,4BAAA,aAAa,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI;AACpC,4BAAA,IAAI,UAAU,CAAC,GAAG,EAAE;AAClB,gCAAA,aAAa,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG;4BACpC;wBACF;AAEA,wBAAA,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;4BAC1B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;gCAC5C,IAAI,CAAC,QAAQ,CAAC;AACZ,oCAAA,IAAI,EAAE,OAAO;oCACb,QAAQ,EAAE,KAAK,CAAC,QAAQ;oCACxB,MAAM,EAAE,KAAK,CAAC,IAAI;AACnB,iCAAA,CAAC;4BACJ;wBACF;oBACF;gBACF;YACF;YACA,oBAAoB,CAAC,KAAK,EAAE;QAC9B,CAAC;KACF;AACH;;;;"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@vscode/rollup-plugin-esm-url",
3
+ "version": "1.0.1-0",
4
+ "description": "Rollup plugin for handling ?esm URL imports",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.js",
7
+ "types": "./dist/cjs/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "default": "./dist/esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/cjs/index.d.ts",
16
+ "default": "./dist/cjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "rollup -c rollup.config.mjs",
25
+ "clean": "rimraf dist"
26
+ },
27
+ "devDependencies": {
28
+ "@vscode/esm-url-plugin-common": "*",
29
+ "rollup": "^4.0.0"
30
+ },
31
+ "peerDependencies": {
32
+ "rollup": "^3.0.0 || ^4.0.0"
33
+ },
34
+ "license": "MIT"
35
+ }