@quilted/rollup 0.2.17 → 0.2.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.2.19
4
+
5
+ ### Patch Changes
6
+
7
+ - [#675](https://github.com/lemonmade/quilt/pull/675) [`e7115258`](https://github.com/lemonmade/quilt/commit/e7115258241d9e049280224d205e2c40bb31d3ca) Thanks [@lemonmade](https://github.com/lemonmade)! - Improve output directories and names
8
+
9
+ ## 0.2.18
10
+
11
+ ### Patch Changes
12
+
13
+ - [`4ddf0b91`](https://github.com/lemonmade/quilt/commit/4ddf0b9150024bed06e76ad1c126c0eba5d3366d) Thanks [@lemonmade](https://github.com/lemonmade)! - Allow server runtimes to declare a default `bundle` option
14
+
3
15
  ## 0.2.17
4
16
 
5
17
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -109,6 +109,9 @@ async function quiltAppBrowserPlugins({
109
109
  const minify = assets?.minify ?? mode === "production";
110
110
  const baseURL = assets?.baseURL ?? "/assets/";
111
111
  const assetsInline = assets?.inline ?? true;
112
+ const assetsDirectory = project.resolve("build/assets");
113
+ const reportsDirectory = path.join(assetsDirectory, "../reports");
114
+ const manifestsDirectory = path.join(assetsDirectory, "../manifests");
112
115
  const browserGroup = await getBrowserGroupTargetDetails(assets?.targets, {
113
116
  root: project.root
114
117
  });
@@ -190,7 +193,7 @@ async function quiltAppBrowserPlugins({
190
193
  baseURL,
191
194
  format: supportsModuleWorkers ? "module" : "classic",
192
195
  outputOptions: {
193
- dir: project.resolve(`build/assets`),
196
+ dir: assetsDirectory,
194
197
  entryFileNames: `[name]${targetFilenamePart}.[hash].js`,
195
198
  assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
196
199
  chunkFileNames: `[name]${targetFilenamePart}.[hash].js`
@@ -201,17 +204,21 @@ async function quiltAppBrowserPlugins({
201
204
  ];
202
205
  if (assets?.clean ?? true) {
203
206
  plugins.push(
204
- removeBuildFiles(["build/assets", "build/manifests", "build/reports"], {
205
- root: project.root
206
- })
207
+ removeBuildFiles(
208
+ [assetsDirectory, manifestsDirectory, reportsDirectory],
209
+ {
210
+ root: project.root
211
+ }
212
+ )
207
213
  );
208
214
  }
209
215
  if (graphql) {
210
216
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
211
217
  plugins.push(
212
218
  graphql2({
213
- manifest: project.resolve(
214
- `build/manifests/graphql${targetFilenamePart}.json`
219
+ manifest: path.join(
220
+ manifestsDirectory,
221
+ `graphql${targetFilenamePart}.json`
215
222
  )
216
223
  })
217
224
  );
@@ -228,15 +235,16 @@ async function quiltAppBrowserPlugins({
228
235
  assetManifest({
229
236
  baseURL,
230
237
  cacheKey,
231
- file: project.resolve(`build/manifests/assets${targetFilenamePart}.json`),
238
+ file: path.join(manifestsDirectory, `assets${targetFilenamePart}.json`),
232
239
  priority: assets?.priority
233
240
  }),
234
241
  visualizer({
235
242
  template: "treemap",
236
243
  open: false,
237
244
  brotliSize: true,
238
- filename: project.resolve(
239
- `build/reports/bundle-visualizer${targetFilenamePart}.html`
245
+ filename: path.join(
246
+ reportsDirectory,
247
+ `bundle-visualizer${targetFilenamePart}.html`
240
248
  )
241
249
  })
242
250
  );
@@ -250,11 +258,12 @@ function quiltAppBrowserInput({
250
258
  name: "@quilted/app-browser/input",
251
259
  async options(options) {
252
260
  const finalEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppBrowser({ entry, root }) ?? MAGIC_MODULE_ENTRY;
261
+ const finalEntryName = typeof finalEntry === "string" && finalEntry !== MAGIC_MODULE_ENTRY ? path.basename(finalEntry).split(".").slice(0, -1).join(".") : "browser";
253
262
  return {
254
263
  ...options,
255
264
  // If we are using the "magic entry", give it an explicit name of `browser`.
256
265
  // Otherwise, Rollup will use the file name as the output name.
257
- input: finalEntry === MAGIC_MODULE_ENTRY ? { browser: finalEntry } : finalEntry
266
+ input: typeof finalEntry === "string" ? { [finalEntryName]: finalEntry } : finalEntry
258
267
  };
259
268
  }
260
269
  };
@@ -290,13 +299,15 @@ async function quiltAppServerPlugins({
290
299
  graphql = true,
291
300
  assets,
292
301
  output,
293
- runtime
302
+ runtime = nodeAppServerRuntime()
294
303
  } = {}) {
295
304
  const project = Project.load(root);
296
305
  const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
297
306
  const baseURL = assets?.baseURL ?? "/assets/";
298
307
  const assetsInline = assets?.inline ?? true;
299
- const bundle = output?.bundle;
308
+ const outputDirectory = project.resolve("build/server");
309
+ const reportsDirectory = path.resolve(outputDirectory, "../reports");
310
+ const bundle = output?.bundle ?? runtime.output?.bundle;
300
311
  const minify = output?.minify ?? false;
301
312
  const [
302
313
  { visualizer },
@@ -328,7 +339,7 @@ async function quiltAppServerPlugins({
328
339
  ...nodePlugins,
329
340
  replaceProcessEnv({ mode }),
330
341
  magicModuleEnv({
331
- runtime: runtime?.env,
342
+ runtime: runtime.env,
332
343
  ...resolveEnvOption(env),
333
344
  mode,
334
345
  root: project.root
@@ -340,7 +351,7 @@ async function quiltAppServerPlugins({
340
351
  module: MAGIC_MODULE_ENTRY,
341
352
  source() {
342
353
  const options = { assets: { baseURL } };
343
- return runtime?.requestRouter?.(options) ?? nodeAppServerRuntime().requestRouter(options);
354
+ return runtime.requestRouter?.(options) ?? nodeAppServerRuntime().requestRouter(options);
344
355
  }
345
356
  }),
346
357
  magicModuleAppRequestRouter({ entry, root: project.root }),
@@ -378,7 +389,7 @@ async function quiltAppServerPlugins({
378
389
  preload: false,
379
390
  moduleID: ({ imported }) => path.relative(project.root, imported)
380
391
  }),
381
- removeBuildFiles(["build/server"], { root: project.root }),
392
+ removeBuildFiles([outputDirectory], { root: project.root }),
382
393
  tsconfigAliases({ root: project.root }),
383
394
  monorepoPackageAliases({ root: project.root })
384
395
  ];
@@ -395,7 +406,7 @@ async function quiltAppServerPlugins({
395
406
  template: "treemap",
396
407
  open: false,
397
408
  brotliSize: false,
398
- filename: project.resolve(`build/reports/bundle-visualizer.server.html`)
409
+ filename: path.join(reportsDirectory, `bundle-visualizer.server.html`)
399
410
  })
400
411
  );
401
412
  return plugins;
@@ -405,23 +416,15 @@ function quiltAppServerInput({
405
416
  entry,
406
417
  format = "request-router"
407
418
  } = {}) {
408
- const project = Project.load(root);
409
419
  return {
410
420
  name: "@quilted/app-server/input",
411
421
  async options(options) {
412
- let finalEntry = normalizeRollupInput(options.input);
413
- if (!finalEntry) {
414
- const serverEntry = entry ? project.resolve(entry) : await project.glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
415
- nodir: true,
416
- absolute: true
417
- }).then((files) => files[0]);
418
- finalEntry = format === "request-router" ? MAGIC_MODULE_ENTRY : serverEntry ?? MAGIC_MODULE_ENTRY;
419
- }
422
+ const serverEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppServer({ entry, root });
423
+ const finalEntry = format === "request-router" ? MAGIC_MODULE_ENTRY : serverEntry ?? MAGIC_MODULE_ENTRY;
424
+ const finalEntryName = typeof serverEntry === "string" ? path.basename(serverEntry).split(".").slice(0, -1).join(".") : "server";
420
425
  return {
421
426
  ...options,
422
- // If we are using the "magic entry", give it an explicit name of `server`.
423
- // Otherwise, Rollup will use the file name as the output name.
424
- input: finalEntry === MAGIC_MODULE_ENTRY ? { server: finalEntry } : finalEntry
427
+ input: typeof finalEntry === "string" ? { [finalEntryName]: finalEntry } : finalEntry
425
428
  };
426
429
  }
427
430
  };
@@ -655,6 +658,24 @@ async function sourceEntryForAppBrowser({
655
658
  return files[0];
656
659
  }
657
660
  }
661
+ async function sourceEntryForAppServer({
662
+ entry,
663
+ root = process.cwd()
664
+ }) {
665
+ const project = Project.load(root);
666
+ if (entry) {
667
+ return project.resolve(entry);
668
+ } else {
669
+ const files = await project.glob(
670
+ "{server,service,backend}.{ts,tsx,mjs,js,jsx}",
671
+ {
672
+ nodir: true,
673
+ absolute: true
674
+ }
675
+ );
676
+ return files[0];
677
+ }
678
+ }
658
679
  const FRAMEWORK_CHUNK_NAME = "framework";
659
680
  const POLYFILLS_CHUNK_NAME = "polyfills";
660
681
  const VENDOR_CHUNK_NAME = "vendor";
@@ -731,4 +752,4 @@ function createManualChunksSorter() {
731
752
  };
732
753
  }
733
754
 
734
- export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, nodeAppServerRuntime, quiltApp, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserPlugins, quiltAppServer, quiltAppServerInput, quiltAppServerPlugins, sourceEntryForAppBrowser };
755
+ export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, nodeAppServerRuntime, quiltApp, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserPlugins, quiltAppServer, quiltAppServerInput, quiltAppServerPlugins, sourceEntryForAppBrowser, sourceEntryForAppServer };
@@ -1,3 +1,4 @@
1
+ import * as path from 'node:path';
1
2
  import { Project, sourceEntriesForProject } from './shared/project.mjs';
2
3
  import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
3
4
  import { getBrowserGroupTargetDetails, rollupGenerateOptionsForBrowsers } from './shared/browserslist.mjs';
@@ -12,7 +13,8 @@ async function quiltModule({
12
13
  } = {}) {
13
14
  const project = Project.load(root);
14
15
  const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
15
- const outputDirectory = project.resolve("build/assets");
16
+ const outputDirectory = project.resolve("build/output");
17
+ const reportDirectory = path.join(outputDirectory, "../reports");
16
18
  const minify = assets?.minify ?? true;
17
19
  const hash = assets?.hash ?? "async-only";
18
20
  const bundle = assets?.bundle ?? true;
@@ -60,7 +62,7 @@ async function quiltModule({
60
62
  }
61
63
  if (assets?.clean ?? true) {
62
64
  plugins.push(
63
- removeBuildFiles(["build/assets", "build/reports"], {
65
+ removeBuildFiles([outputDirectory, reportDirectory], {
64
66
  root: project.root
65
67
  })
66
68
  );
@@ -70,8 +72,9 @@ async function quiltModule({
70
72
  template: "treemap",
71
73
  open: false,
72
74
  brotliSize: true,
73
- filename: project.resolve(
74
- `build/reports/bundle-visualizer${targetFilenamePart}.html`
75
+ filename: path.join(
76
+ reportDirectory,
77
+ `bundle-visualizer${targetFilenamePart}.html`
75
78
  )
76
79
  })
77
80
  );
@@ -1,8 +1,9 @@
1
+ import * as path from 'node:path';
1
2
  import { Project } from './shared/project.mjs';
2
3
  import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
3
4
  import { multiline } from './shared/strings.mjs';
4
5
  import { resolveEnvOption } from './features/env.mjs';
5
- import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER } from './constants.mjs';
6
+ import { MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_ENTRY } from './constants.mjs';
6
7
  import { createMagicModulePlugin } from './shared/magic-module.mjs';
7
8
 
8
9
  async function quiltServer({
@@ -17,10 +18,11 @@ async function quiltServer({
17
18
  const project = Project.load(rootPath);
18
19
  const mode = (typeof env === "object" ? env?.mode : void 0) ?? "production";
19
20
  const outputDirectory = project.resolve(
20
- output?.directory ?? runtime.output?.directory ?? "build/server"
21
+ output?.directory ?? runtime.output?.directory ?? "build/output"
21
22
  );
23
+ const reportDirectory = path.resolve(outputDirectory, "../reports");
22
24
  const minify = output?.minify ?? false;
23
- const bundle = output?.bundle;
25
+ const bundle = output?.bundle ?? runtime.output?.bundle;
24
26
  const hash = output?.hash ?? "async-only";
25
27
  const [
26
28
  { visualizer },
@@ -43,6 +45,7 @@ async function quiltServer({
43
45
  ]);
44
46
  const serverEntry = entry ? project.resolve(entry) : await sourceForServer(project);
45
47
  const finalEntry = format === "request-router" ? MAGIC_MODULE_ENTRY : serverEntry ?? MAGIC_MODULE_ENTRY;
48
+ const finalEntryName = serverEntry ? path.basename(serverEntry).split(".").slice(0, -1).join(".") : "server";
46
49
  const plugins = [
47
50
  ...nodePlugins,
48
51
  replaceProcessEnv({ mode }),
@@ -57,7 +60,7 @@ async function quiltServer({
57
60
  monorepoPackageAliases({ root: project.root }),
58
61
  react(),
59
62
  esnext({ mode, targets: ["current node"] }),
60
- removeBuildFiles(["build/server", "build/reports"], { root: project.root })
63
+ removeBuildFiles([outputDirectory, reportDirectory], { root: project.root })
61
64
  ];
62
65
  if (format === "request-router") {
63
66
  plugins.push(
@@ -89,11 +92,11 @@ async function quiltServer({
89
92
  template: "treemap",
90
93
  open: false,
91
94
  brotliSize: true,
92
- filename: project.resolve(`build/reports/bundle-visualizer.html`)
95
+ filename: path.join(reportDirectory, "bundle-visualizer.html")
93
96
  })
94
97
  );
95
98
  return {
96
- input: finalEntry === MAGIC_MODULE_ENTRY ? { server: finalEntry } : finalEntry,
99
+ input: { [finalEntryName]: finalEntry },
97
100
  plugins,
98
101
  output: {
99
102
  format: "esm",