@quilted/rollup 0.1.19 → 0.2.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.
Files changed (126) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/esm/app.mjs +443 -219
  3. package/build/esm/constants.mjs +5 -5
  4. package/build/esm/features/assets.mjs +93 -81
  5. package/build/esm/features/async.mjs +186 -0
  6. package/build/esm/features/css.mjs +26 -39
  7. package/build/esm/features/env.mjs +47 -44
  8. package/build/esm/features/esnext.mjs +57 -0
  9. package/build/esm/features/graphql/transform.mjs +60 -56
  10. package/build/esm/features/graphql.mjs +65 -47
  11. package/build/esm/features/request-router.mjs +6 -4
  12. package/build/esm/features/source-code.mjs +54 -28
  13. package/build/esm/features/system-js.mjs +13 -18
  14. package/build/esm/features/typescript.mjs +13 -10
  15. package/build/esm/features/workers.mjs +173 -0
  16. package/build/esm/index.mjs +3 -2
  17. package/build/esm/module.mjs +69 -62
  18. package/build/esm/package.mjs +275 -84
  19. package/build/esm/server.mjs +118 -0
  20. package/build/esm/shared/browserslist.mjs +141 -16
  21. package/build/esm/shared/magic-module.mjs +9 -7
  22. package/build/esm/shared/package-json.mjs +7 -1
  23. package/build/esm/shared/path.mjs +7 -0
  24. package/build/esm/shared/rollup.mjs +89 -25
  25. package/build/esm/shared/strings.mjs +7 -6
  26. package/build/tsconfig.tsbuildinfo +1 -1
  27. package/build/typescript/app.d.ts +126 -27
  28. package/build/typescript/app.d.ts.map +1 -1
  29. package/build/typescript/features/assets.d.ts +1 -2
  30. package/build/typescript/features/assets.d.ts.map +1 -1
  31. package/build/typescript/features/async.d.ts +10 -0
  32. package/build/typescript/features/async.d.ts.map +1 -0
  33. package/build/typescript/features/css.d.ts +2 -1
  34. package/build/typescript/features/css.d.ts.map +1 -1
  35. package/build/typescript/features/env.d.ts +1 -0
  36. package/build/typescript/features/env.d.ts.map +1 -1
  37. package/build/typescript/features/esnext.d.ts +9 -0
  38. package/build/typescript/features/esnext.d.ts.map +1 -0
  39. package/build/typescript/features/graphql.d.ts +2 -2
  40. package/build/typescript/features/graphql.d.ts.map +1 -1
  41. package/build/typescript/features/source-code.d.ts +9 -3
  42. package/build/typescript/features/source-code.d.ts.map +1 -1
  43. package/build/typescript/features/workers.d.ts +52 -0
  44. package/build/typescript/features/workers.d.ts.map +1 -0
  45. package/build/typescript/index.d.ts +3 -2
  46. package/build/typescript/index.d.ts.map +1 -1
  47. package/build/typescript/module.d.ts +24 -6
  48. package/build/typescript/module.d.ts.map +1 -1
  49. package/build/typescript/package.d.ts +196 -4
  50. package/build/typescript/package.d.ts.map +1 -1
  51. package/build/typescript/server.d.ts +98 -0
  52. package/build/typescript/server.d.ts.map +1 -0
  53. package/build/typescript/shared/browserslist.d.ts +20 -3
  54. package/build/typescript/shared/browserslist.d.ts.map +1 -1
  55. package/build/typescript/shared/path.d.ts +2 -0
  56. package/build/typescript/shared/path.d.ts.map +1 -0
  57. package/build/typescript/shared/rollup.d.ts +27 -1
  58. package/build/typescript/shared/rollup.d.ts.map +1 -1
  59. package/configuration/rollup.config.js +40 -0
  60. package/package.json +61 -8
  61. package/source/app.ts +466 -96
  62. package/source/features/assets.ts +5 -7
  63. package/source/features/async.ts +249 -0
  64. package/source/features/css.ts +4 -2
  65. package/source/features/env.ts +6 -0
  66. package/source/features/esnext.ts +70 -0
  67. package/source/features/graphql.ts +4 -2
  68. package/source/features/source-code.ts +26 -8
  69. package/source/features/workers.ts +292 -0
  70. package/source/index.ts +4 -0
  71. package/source/module.ts +45 -19
  72. package/source/package.ts +394 -36
  73. package/source/server.ts +245 -0
  74. package/source/shared/browserslist.ts +208 -18
  75. package/source/shared/path.ts +5 -0
  76. package/source/shared/rollup.ts +102 -4
  77. package/tsconfig.json +6 -2
  78. package/build/cjs/app.cjs +0 -441
  79. package/build/cjs/constants.cjs +0 -13
  80. package/build/cjs/features/assets.cjs +0 -240
  81. package/build/cjs/features/css.cjs +0 -71
  82. package/build/cjs/features/env.cjs +0 -135
  83. package/build/cjs/features/graphql/transform.cjs +0 -186
  84. package/build/cjs/features/graphql.cjs +0 -86
  85. package/build/cjs/features/request-router.cjs +0 -31
  86. package/build/cjs/features/source-code.cjs +0 -54
  87. package/build/cjs/features/system-js.cjs +0 -36
  88. package/build/cjs/features/typescript.cjs +0 -56
  89. package/build/cjs/index.cjs +0 -13
  90. package/build/cjs/module.cjs +0 -121
  91. package/build/cjs/package.cjs +0 -170
  92. package/build/cjs/shared/browserslist.cjs +0 -25
  93. package/build/cjs/shared/magic-module.cjs +0 -32
  94. package/build/cjs/shared/package-json.cjs +0 -31
  95. package/build/cjs/shared/rollup.cjs +0 -72
  96. package/build/cjs/shared/strings.cjs +0 -16
  97. package/build/esnext/app.esnext +0 -414
  98. package/build/esnext/constants.esnext +0 -7
  99. package/build/esnext/features/assets.esnext +0 -215
  100. package/build/esnext/features/css.esnext +0 -69
  101. package/build/esnext/features/env.esnext +0 -112
  102. package/build/esnext/features/graphql/transform.esnext +0 -181
  103. package/build/esnext/features/graphql.esnext +0 -84
  104. package/build/esnext/features/request-router.esnext +0 -29
  105. package/build/esnext/features/source-code.esnext +0 -51
  106. package/build/esnext/features/system-js.esnext +0 -33
  107. package/build/esnext/features/typescript.esnext +0 -34
  108. package/build/esnext/index.esnext +0 -3
  109. package/build/esnext/module.esnext +0 -100
  110. package/build/esnext/package.esnext +0 -148
  111. package/build/esnext/shared/browserslist.esnext +0 -23
  112. package/build/esnext/shared/magic-module.esnext +0 -30
  113. package/build/esnext/shared/package-json.esnext +0 -10
  114. package/build/esnext/shared/rollup.esnext +0 -49
  115. package/build/esnext/shared/strings.esnext +0 -14
  116. package/build/typescript/env.d.ts +0 -55
  117. package/build/typescript/env.d.ts.map +0 -1
  118. package/build/typescript/graphql/transform.d.ts +0 -17
  119. package/build/typescript/graphql/transform.d.ts.map +0 -1
  120. package/build/typescript/graphql.d.ts +0 -6
  121. package/build/typescript/graphql.d.ts.map +0 -1
  122. package/build/typescript/request-router.d.ts +0 -15
  123. package/build/typescript/request-router.d.ts.map +0 -1
  124. package/build/typescript/shared/source-code.d.ts +0 -5
  125. package/build/typescript/shared/source-code.d.ts.map +0 -1
  126. package/quilt.project.ts +0 -5
package/build/cjs/app.cjs DELETED
@@ -1,441 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- var fs = require('node:fs/promises');
5
- var glob = require('glob');
6
- var node_url = require('node:url');
7
- var constants = require('./constants.cjs');
8
- var strings = require('./shared/strings.cjs');
9
- var rollup = require('./shared/rollup.cjs');
10
- var magicModule = require('./shared/magic-module.cjs');
11
- var browserslist = require('./shared/browserslist.cjs');
12
-
13
- function _interopNamespaceDefault(e) {
14
- var n = Object.create(null);
15
- if (e) {
16
- Object.keys(e).forEach(function (k) {
17
- if (k !== 'default') {
18
- var d = Object.getOwnPropertyDescriptor(e, k);
19
- Object.defineProperty(n, k, d.get ? d : {
20
- enumerable: true,
21
- get: function () { return e[k]; }
22
- });
23
- }
24
- });
25
- }
26
- n["default"] = e;
27
- return Object.freeze(n);
28
- }
29
-
30
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
31
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
32
-
33
- async function quiltAppBrowser({
34
- root: rootPath = process.cwd(),
35
- app,
36
- entry,
37
- env,
38
- assets,
39
- module,
40
- graphql = true
41
- } = {}) {
42
- const root = typeof rootPath === 'string' ? rootPath : node_url.fileURLToPath(rootPath);
43
- const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
44
- const minify = assets?.minify ?? mode === 'production';
45
- const baseURL = assets?.baseURL ?? '/assets/';
46
- const browserTarget = await browserslist.getBrowserTargetDetails(assets?.targets, {
47
- root
48
- });
49
- const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
50
- const [{
51
- visualizer
52
- }, {
53
- magicModuleEnv,
54
- replaceProcessEnv
55
- }, {
56
- sourceCode
57
- }, {
58
- createTSConfigAliasPlugin
59
- }, {
60
- css
61
- }, {
62
- assetManifest,
63
- rawAssets,
64
- staticAssets
65
- }, {
66
- systemJS
67
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/env.cjs'); }), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/system-js.cjs'); }), rollup.getNodePlugins()]);
68
- const plugins = [...nodePlugins, systemJS({
69
- minify
70
- }), replaceProcessEnv({
71
- mode
72
- }), magicModuleEnv({
73
- ...env,
74
- mode
75
- }), sourceCode({
76
- mode,
77
- targets: browserTarget.browsers
78
- }), css({
79
- minify,
80
- emit: true
81
- }), rawAssets(), staticAssets({
82
- baseURL,
83
- emit: true
84
- }), rollup.removeBuildFiles(['build/assets', 'build/manifests', 'build/reports'], {
85
- root
86
- })];
87
- const tsconfigAliases = await createTSConfigAliasPlugin();
88
- if (tsconfigAliases) {
89
- plugins.push(tsconfigAliases);
90
- }
91
- const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
92
- cwd: root,
93
- nodir: true,
94
- absolute: true
95
- }).then(files => files[0]));
96
- if (appEntry) {
97
- plugins.push(magicModuleAppComponent({
98
- entry: appEntry
99
- }));
100
- }
101
- plugins.push(magicModuleAppBrowserEntry(module));
102
- if (graphql) {
103
- const {
104
- graphql
105
- } = await Promise.resolve().then(function () { return require('./features/graphql.cjs'); });
106
- plugins.push(graphql({
107
- manifest: path__namespace.resolve(`manifests/graphql${targetFilenamePart}.json`)
108
- }));
109
- }
110
- if (minify) {
111
- const {
112
- minify
113
- } = await import('rollup-plugin-esbuild');
114
- plugins.push(minify());
115
- }
116
- const cacheKey = browserTarget.name ? {
117
- browserTarget: browserTarget.name
118
- } : undefined;
119
- const id = browserTarget.name ? browserTarget.name : undefined;
120
- plugins.push(assetManifest({
121
- id,
122
- cacheKey,
123
- baseURL,
124
- file: path__namespace.resolve(`build/manifests/assets${targetFilenamePart}.json`),
125
- priority: assets?.priority
126
- }), visualizer({
127
- template: 'treemap',
128
- open: false,
129
- brotliSize: true,
130
- filename: path__namespace.resolve(`build/reports/bundle-visualizer${targetFilenamePart}.html`)
131
- }));
132
- const finalEntry = entry ?? (await glob.glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
133
- cwd: root,
134
- nodir: true,
135
- absolute: true
136
- }).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
137
- return {
138
- input: finalEntry,
139
- plugins,
140
- onwarn(warning, defaultWarn) {
141
- // Removes annoying warnings for React-focused libraries that
142
- // include 'use client' directives.
143
- if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
144
- return;
145
- }
146
- defaultWarn(warning);
147
- },
148
- output: {
149
- // format: isESM ? 'esm' : 'systemjs',
150
- format: 'esm',
151
- dir: path__namespace.resolve(`build/assets`),
152
- entryFileNames: `app${targetFilenamePart}.[hash].js`,
153
- assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
154
- chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
155
- manualChunks: createManualChunksSorter()
156
- }
157
- };
158
- }
159
- async function quiltAppServer({
160
- app,
161
- env,
162
- entry,
163
- graphql = true,
164
- minify = false
165
- } = {}) {
166
- const root = process.cwd();
167
- const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
168
- const [{
169
- visualizer
170
- }, {
171
- magicModuleEnv,
172
- replaceProcessEnv
173
- }, {
174
- sourceCode
175
- }, {
176
- createTSConfigAliasPlugin
177
- }, {
178
- css
179
- }, {
180
- rawAssets,
181
- staticAssets
182
- }, {
183
- magicModuleRequestRouterEntry
184
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/env.cjs'); }), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/request-router.cjs'); }), rollup.getNodePlugins()]);
185
- const plugins = [...nodePlugins, replaceProcessEnv({
186
- mode
187
- }), magicModuleEnv({
188
- ...env,
189
- mode
190
- }), sourceCode({
191
- mode,
192
- targets: ['current node']
193
- }), css({
194
- emit: false,
195
- minify
196
- }), rawAssets(), staticAssets({
197
- emit: false
198
- }), rollup.removeBuildFiles(['build/server'], {
199
- root
200
- })];
201
- const tsconfigAliases = await createTSConfigAliasPlugin();
202
- if (tsconfigAliases) {
203
- plugins.push(tsconfigAliases);
204
- }
205
- const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
206
- cwd: root,
207
- nodir: true,
208
- absolute: true
209
- }).then(files => files[0]));
210
- if (appEntry) {
211
- plugins.push(magicModuleAppComponent({
212
- entry: appEntry
213
- }));
214
- }
215
- plugins.push(magicModuleRequestRouterEntry(), magicModuleAppRequestRouter({
216
- entry
217
- }), magicModuleAppAssetManifests());
218
- if (graphql) {
219
- const {
220
- graphql
221
- } = await Promise.resolve().then(function () { return require('./features/graphql.cjs'); });
222
- plugins.push(graphql({
223
- manifest: false
224
- }));
225
- }
226
- if (minify) {
227
- const {
228
- minify
229
- } = await import('rollup-plugin-esbuild');
230
- plugins.push(minify());
231
- }
232
- plugins.push(visualizer({
233
- template: 'treemap',
234
- open: false,
235
- brotliSize: false,
236
- filename: path__namespace.resolve(`build/reports/bundle-visualizer.server.html`)
237
- }));
238
- const finalEntry = entry ?? (await glob.glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
239
- cwd: root,
240
- nodir: true,
241
- absolute: true
242
- }).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
243
- return {
244
- input: finalEntry,
245
- plugins,
246
- onwarn(warning, defaultWarn) {
247
- // Removes annoying warnings for React-focused libraries that
248
- // include 'use client' directives.
249
- if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
250
- return;
251
- }
252
- defaultWarn(warning);
253
- },
254
- output: {
255
- // format: isESM ? 'esm' : 'systemjs',
256
- format: 'esm',
257
- dir: path__namespace.resolve(`build/server`),
258
- entryFileNames: 'server.js'
259
- }
260
- };
261
- }
262
- function magicModuleAppComponent({
263
- entry
264
- }) {
265
- return magicModule.createMagicModulePlugin({
266
- name: '@quilted/magic-module/app',
267
- module: constants.MAGIC_MODULE_APP_COMPONENT,
268
- alias: entry
269
- });
270
- }
271
- function magicModuleAppRequestRouter({
272
- entry
273
- } = {}) {
274
- return magicModule.createMagicModulePlugin({
275
- name: '@quilted/magic-module/app-request-router',
276
- module: constants.MAGIC_MODULE_REQUEST_ROUTER,
277
- alias: entry,
278
- source: entry ? undefined : async function source() {
279
- return strings.multiline`
280
- import '@quilted/quilt/globals';
281
-
282
- import {jsx} from 'react/jsx-runtime';
283
- import {RequestRouter} from '@quilted/quilt/request-router';
284
- import {renderToResponse} from '@quilted/quilt/server';
285
-
286
- import App from ${JSON.stringify(constants.MAGIC_MODULE_APP_COMPONENT)};
287
- import {BrowserAssets} from ${JSON.stringify(constants.MAGIC_MODULE_BROWSER_ASSETS)};
288
-
289
- const router = new RequestRouter();
290
- const assets = new BrowserAssets();
291
-
292
- // For all GET requests, render our React application.
293
- router.get(async (request) => {
294
- const response = await renderToResponse(jsx(App), {
295
- request,
296
- assets,
297
- });
298
-
299
- return response;
300
- });
301
-
302
- export default router;
303
- `;
304
- }
305
- });
306
- }
307
- function magicModuleAppBrowserEntry({
308
- hydrate = true,
309
- selector = '#app'
310
- } = {}) {
311
- return magicModule.createMagicModulePlugin({
312
- name: '@quilted/magic-module/app-browser-entry',
313
- module: constants.MAGIC_MODULE_ENTRY,
314
- sideEffects: true,
315
- async source() {
316
- const reactRootFunction = hydrate ? 'hydrateRoot' : 'createRoot';
317
- return strings.multiline`
318
- import '@quilted/quilt/globals';
319
-
320
- import {jsx} from 'react/jsx-runtime';
321
- import {${reactRootFunction}} from 'react-dom/client';
322
-
323
- import App from ${JSON.stringify(constants.MAGIC_MODULE_APP_COMPONENT)};
324
-
325
- const element = document.querySelector(${JSON.stringify(selector)});
326
-
327
- ${hydrate ? `${reactRootFunction}(element, jsx(App));` : `${reactRootFunction}(element).render(jsx(App));`}
328
- `;
329
- }
330
- });
331
- }
332
- function magicModuleAppAssetManifests() {
333
- return magicModule.createMagicModulePlugin({
334
- name: '@quilted/magic-module/asset-manifests',
335
- module: constants.MAGIC_MODULE_BROWSER_ASSETS,
336
- async source() {
337
- const {
338
- glob
339
- } = await import('glob');
340
- const manifestFiles = await glob('assets*.json', {
341
- nodir: true,
342
- absolute: true,
343
- cwd: path__namespace.resolve(`build/manifests`)
344
- });
345
- const manifests = await Promise.all(manifestFiles.map(async file => JSON.parse(await fs__namespace.readFile(file, 'utf8'))));
346
- manifests.sort((manifestA, manifestB) => (manifestA.priority ?? 0) - (manifestB.priority ?? 0));
347
- return strings.multiline`
348
- import {BrowserAssetsFromManifests} from '@quilted/quilt/server';
349
-
350
- export class BrowserAssets extends BrowserAssetsFromManifests {
351
- constructor() {
352
- const manifests = JSON.parse(${JSON.stringify(JSON.stringify(manifests))});
353
-
354
- // The default manifest is the last one, since it has the widest browser support.
355
- const defaultManifest = manifests.at(-1);
356
-
357
- super(manifests, {
358
- defaultManifest,
359
- cacheKey(request) {
360
- return {};
361
- },
362
- });
363
- }
364
- }
365
- `;
366
- }
367
- });
368
- }
369
- const FRAMEWORK_CHUNK_NAME = 'framework';
370
- const POLYFILLS_CHUNK_NAME = 'polyfills';
371
- const VENDOR_CHUNK_NAME = 'vendor';
372
- const INTERNALS_CHUNK_NAME = 'internals';
373
- const SHARED_CHUNK_NAME = 'shared';
374
- const PACKAGES_CHUNK_NAME = 'packages';
375
- const GLOBAL_CHUNK_NAME = 'global';
376
- const FRAMEWORK_TEST_STRINGS = ['/node_modules/preact/', '/node_modules/react/', '/node_modules/js-cookie/', '/node_modules/@quilted/quilt/', '/node_modules/@preact/signals/', '/node_modules/@preact/signals-core/',
377
- // TODO I should turn this into an allowlist
378
- /node_modules[/]@quilted[/](?!react-query|swr)/];
379
- const POLYFILL_TEST_STRINGS = ['/node_modules/@quilted/polyfills/', '/node_modules/core-js/', '/node_modules/whatwg-fetch/', '/node_modules/regenerator-runtime/', '/node_modules/abort-controller/'];
380
- const INTERNALS_TEST_STRINGS = ['\x00commonjsHelpers.js', '/node_modules/@babel/runtime/'];
381
-
382
- // When building from source, quilt packages are not in node_modules,
383
- // so we instead add their repo paths to the list of framework test strings.
384
- if (process.env.QUILT_FROM_SOURCE) {
385
- FRAMEWORK_TEST_STRINGS.push('/quilt/packages/');
386
- }
387
-
388
- // Inspired by Vite: https://github.com/vitejs/vite/blob/c69f83615292953d40f07b1178d1ed1d72abe695/packages/vite/source/node/build.ts#L567
389
- function createManualChunksSorter() {
390
- // TODO: make this more configurable, and make it so that we bundle more intelligently
391
- // for split entries
392
- const packagesPath = path__namespace.resolve('packages') + path__namespace.sep;
393
- const globalPath = path__namespace.resolve('global') + path__namespace.sep;
394
- const sharedPath = path__namespace.resolve('shared') + path__namespace.sep;
395
- return (id, {
396
- getModuleInfo
397
- }) => {
398
- if (INTERNALS_TEST_STRINGS.some(test => id.includes(test))) {
399
- return INTERNALS_CHUNK_NAME;
400
- }
401
- if (FRAMEWORK_TEST_STRINGS.some(test => typeof test === 'string' ? id.includes(test) : test.test(id))) {
402
- return FRAMEWORK_CHUNK_NAME;
403
- }
404
- if (POLYFILL_TEST_STRINGS.some(test => id.includes(test))) {
405
- return POLYFILLS_CHUNK_NAME;
406
- }
407
- let bundleBaseName;
408
- let relativeId;
409
- if (id.includes('/node_modules/')) {
410
- const moduleInfo = getModuleInfo(id);
411
-
412
- // If the only dependency is another vendor, let Rollup handle the naming
413
- if (moduleInfo == null) return;
414
- if (moduleInfo.importers.length > 0 && moduleInfo.importers.every(importer => importer.includes('/node_modules/'))) {
415
- return;
416
- }
417
- bundleBaseName = VENDOR_CHUNK_NAME;
418
- relativeId = id.replace(/^.*[/]node_modules[/]/, '');
419
- } else if (id.startsWith(packagesPath)) {
420
- bundleBaseName = PACKAGES_CHUNK_NAME;
421
- relativeId = id.replace(packagesPath, '');
422
- } else if (id.startsWith(globalPath)) {
423
- bundleBaseName = GLOBAL_CHUNK_NAME;
424
- relativeId = id.replace(globalPath, '');
425
- } else if (id.startsWith(sharedPath)) {
426
- bundleBaseName = SHARED_CHUNK_NAME;
427
- relativeId = id.replace(sharedPath, '');
428
- }
429
- if (bundleBaseName == null || relativeId == null) {
430
- return;
431
- }
432
- return `${bundleBaseName}-${relativeId.split(path__namespace.sep)[0]?.split('.')[0]}`;
433
- };
434
- }
435
-
436
- exports.magicModuleAppAssetManifests = magicModuleAppAssetManifests;
437
- exports.magicModuleAppBrowserEntry = magicModuleAppBrowserEntry;
438
- exports.magicModuleAppComponent = magicModuleAppComponent;
439
- exports.magicModuleAppRequestRouter = magicModuleAppRequestRouter;
440
- exports.quiltAppBrowser = quiltAppBrowser;
441
- exports.quiltAppServer = quiltAppServer;
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- const MAGIC_MODULE_ENV = 'quilt:module/env';
4
- const MAGIC_MODULE_ENTRY = 'quilt:module/entry';
5
- const MAGIC_MODULE_APP_COMPONENT = 'quilt:module/app';
6
- const MAGIC_MODULE_BROWSER_ASSETS = 'quilt:module/assets';
7
- const MAGIC_MODULE_REQUEST_ROUTER = 'quilt:module/request-router';
8
-
9
- exports.MAGIC_MODULE_APP_COMPONENT = MAGIC_MODULE_APP_COMPONENT;
10
- exports.MAGIC_MODULE_BROWSER_ASSETS = MAGIC_MODULE_BROWSER_ASSETS;
11
- exports.MAGIC_MODULE_ENTRY = MAGIC_MODULE_ENTRY;
12
- exports.MAGIC_MODULE_ENV = MAGIC_MODULE_ENV;
13
- exports.MAGIC_MODULE_REQUEST_ROUTER = MAGIC_MODULE_REQUEST_ROUTER;
@@ -1,240 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- var fs = require('node:fs/promises');
5
- var node_crypto = require('node:crypto');
6
- var mime = require('mrmime');
7
-
8
- function _interopNamespaceDefault(e) {
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
26
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
27
- var mime__namespace = /*#__PURE__*/_interopNamespaceDefault(mime);
28
-
29
- function assetManifest(manifestOptions) {
30
- return {
31
- name: '@quilted/asset-manifest',
32
- async generateBundle(options, bundle) {
33
- await writeManifestForBundle.call(this, bundle, manifestOptions, options);
34
- }
35
- };
36
- }
37
- async function writeManifestForBundle(bundle, {
38
- id,
39
- file,
40
- baseURL,
41
- cacheKey,
42
- priority
43
- }, {
44
- format
45
- }) {
46
- const outputs = Object.values(bundle);
47
- const entries = outputs.filter(output => output.type === 'chunk' && output.isEntry);
48
- if (entries.length === 0) {
49
- throw new Error(`Could not find any entries in your rollup bundle...`);
50
- }
51
-
52
- // We assume the first entry is the "main" one. There can be
53
- // more than one because each worker script is also listed as an
54
- // entry (though, from a separate build).
55
- const entryChunk = entries[0];
56
- const dependencyMap = new Map();
57
- for (const output of outputs) {
58
- if (output.type !== 'chunk') continue;
59
- dependencyMap.set(output.fileName, output.imports);
60
- }
61
- const assets = [];
62
- const assetIdMap = new Map();
63
- function getAssetId(file) {
64
- let id = assetIdMap.get(file);
65
- if (id == null) {
66
- assets.push(`${baseURL}${file}`);
67
- id = assets.length - 1;
68
- assetIdMap.set(file, id);
69
- }
70
- return id;
71
- }
72
- const manifest = {
73
- id,
74
- priority,
75
- cacheKey,
76
- assets,
77
- attributes: format === 'es' ? {
78
- scripts: {
79
- type: 'module'
80
- }
81
- } : undefined,
82
- entries: {
83
- default: createAssetsEntry([...entryChunk.imports, entryChunk.fileName], {
84
- dependencyMap,
85
- getAssetId
86
- })
87
- },
88
- modules: {}
89
- };
90
- for (const output of outputs) {
91
- if (output.type !== 'chunk') continue;
92
- const originalModuleId = output.facadeModuleId ?? output.moduleIds[output.moduleIds.length - 1];
93
- if (originalModuleId == null) continue;
94
-
95
- // This metadata is added by the rollup plugin for @quilted/async
96
- const moduleId = this.getModuleInfo(originalModuleId)?.meta.quilt?.moduleId;
97
- if (moduleId == null) continue;
98
- manifest.modules[moduleId] = createAssetsEntry([...output.imports, output.fileName], {
99
- dependencyMap,
100
- getAssetId
101
- });
102
- }
103
- await fs__namespace.mkdir(path__namespace.dirname(file), {
104
- recursive: true
105
- });
106
- await fs__namespace.writeFile(file, JSON.stringify(manifest, null, 2));
107
- }
108
- function createAssetsEntry(files, {
109
- dependencyMap,
110
- getAssetId
111
- }) {
112
- const styles = [];
113
- const scripts = [];
114
- const allFiles = new Set();
115
- const addFile = file => {
116
- if (allFiles.has(file)) return;
117
- allFiles.add(file);
118
- for (const dependency of dependencyMap.get(file) ?? []) {
119
- addFile(dependency);
120
- }
121
- };
122
- for (const file of files) {
123
- addFile(file);
124
- }
125
- for (const file of allFiles) {
126
- if (file.endsWith('.css')) {
127
- styles.push(getAssetId(file));
128
- } else {
129
- scripts.push(getAssetId(file));
130
- }
131
- }
132
- return {
133
- scripts,
134
- styles
135
- };
136
- }
137
- const QUERY_PATTERN = /\?.*$/s;
138
- const HASH_PATTERN = /#.*$/s;
139
- const RAW_PATTERN = /(\?|&)raw(?:&|$)/;
140
- const DEFAULT_INLINE_LIMIT = 4096;
141
- const DEFAULT_OUTPUT_PATTERN = '[name].[hash].[ext]';
142
- const DEFAULT_STATIC_ASSET_EXTENSIONS = [
143
- // images
144
- '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.webp', '.avif',
145
- // media
146
- '.mp4', '.webm', '.ogg', '.mp3', '.wav', '.flac', '.aac',
147
- // fonts
148
- '.woff', '.woff2', '.eot', '.ttf', '.otf',
149
- // other
150
- '.webmanifest', '.pdf', '.txt'];
151
- function rawAssets() {
152
- return {
153
- name: '@quilted/raw-assets',
154
- async load(id) {
155
- if (id.startsWith('\0') || !RAW_PATTERN.test(id)) {
156
- return null;
157
- }
158
- const moduleId = cleanModuleIdentifier(id);
159
- this.addWatchFile(moduleId);
160
- const file = await fs__namespace.readFile(moduleId, {
161
- encoding: 'utf-8'
162
- });
163
- return `export default ${JSON.stringify(file)}`;
164
- }
165
- };
166
- }
167
- function staticAssets({
168
- emit = true,
169
- baseURL = '/',
170
- extensions = DEFAULT_STATIC_ASSET_EXTENSIONS,
171
- inlineLimit = DEFAULT_INLINE_LIMIT,
172
- outputPattern = DEFAULT_OUTPUT_PATTERN
173
- } = {}) {
174
- const assetCache = new Map();
175
- const assetMatcher = new RegExp(`\\.(` + extensions.map(extension => extension.startsWith('.') ? extension.slice(1) : extension).join('|') + `)(\\?.*)?$`);
176
- return {
177
- name: '@quilted/static-assets',
178
- async load(id) {
179
- if (id.startsWith('\0') || !assetMatcher.test(id)) {
180
- return null;
181
- }
182
- const cached = assetCache.get(id);
183
- if (cached) {
184
- return cached;
185
- }
186
- const file = cleanModuleIdentifier(id);
187
- const content = await fs__namespace.readFile(file);
188
- let url;
189
- if (!file.endsWith('.svg') && content.length < inlineLimit) {
190
- // base64 inlined as a string
191
- url = `data:${mime__namespace.lookup(file)};base64,${content.toString('base64')}`;
192
- } else {
193
- const contentHash = getHash(content);
194
- const filename = assetFileNamesToFileName(outputPattern, file, contentHash);
195
- url = `${baseURL.endsWith('/') ? baseURL.slice(0, -1) : baseURL}/${filename}`;
196
- if (emit) {
197
- this.emitFile({
198
- name: file,
199
- type: 'asset',
200
- fileName: filename,
201
- source: content
202
- });
203
- }
204
- }
205
- const source = `export default ${JSON.stringify(url)};`;
206
- assetCache.set(id, source);
207
- return source;
208
- }
209
- };
210
- }
211
- function assetFileNamesToFileName(pattern, file, contentHash) {
212
- const basename = path__namespace.basename(file);
213
- const extname = path__namespace.extname(basename);
214
- const ext = extname.substring(1);
215
- const name = basename.slice(0, -extname.length);
216
- const hash = contentHash;
217
- return pattern.replace(/\[\w+\]/g, placeholder => {
218
- switch (placeholder) {
219
- case '[ext]':
220
- return ext;
221
- case '[extname]':
222
- return extname;
223
- case '[hash]':
224
- return hash;
225
- case '[name]':
226
- return name;
227
- }
228
- throw new Error(`invalid placeholder ${placeholder} in assetFileNames "${pattern}"`);
229
- });
230
- }
231
- function getHash(text) {
232
- return node_crypto.createHash('sha256').update(text).digest('hex').substring(0, 8);
233
- }
234
- function cleanModuleIdentifier(url) {
235
- return url.replace(HASH_PATTERN, '').replace(QUERY_PATTERN, '');
236
- }
237
-
238
- exports.assetManifest = assetManifest;
239
- exports.rawAssets = rawAssets;
240
- exports.staticAssets = staticAssets;