@quilted/rollup 0.2.32 → 0.2.34

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.34
4
+
5
+ ### Patch Changes
6
+
7
+ - [`087943b`](https://github.com/lemonmade/quilt/commit/087943b0dc93ed23617711f1527a45772177b182) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix errors when `.esnext` dependencies have tsconfig files
8
+
9
+ ## 0.2.33
10
+
11
+ ### Patch Changes
12
+
13
+ - [`5ba0530`](https://github.com/lemonmade/quilt/commit/5ba053056ed3b8a0f012fbce74e86227468b60df) Thanks [@lemonmade](https://github.com/lemonmade)! - Add basic service worker plugin
14
+
3
15
  ## 0.2.32
4
16
 
5
17
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -17,7 +17,8 @@ async function quiltApp({
17
17
  graphql,
18
18
  assets,
19
19
  browser: browserOptions,
20
- server: serverOptions,
20
+ server: serverOptions = true,
21
+ serviceWorker: serviceWorkerOptions = false,
21
22
  runtime
22
23
  } = {}) {
23
24
  const project = Project.load(root);
@@ -49,20 +50,39 @@ async function quiltApp({
49
50
  })
50
51
  );
51
52
  });
52
- optionPromises.push(
53
- quiltAppServer({
54
- root: project.root,
55
- app,
56
- graphql,
57
- runtime: runtime?.server,
58
- ...serverOptions,
59
- env: {
60
- ...resolveEnvOption(env),
61
- ...resolveEnvOption(serverOptions?.env)
62
- },
63
- assets: { ...assets, ...serverOptions?.assets }
64
- })
65
- );
53
+ if (serverOptions) {
54
+ const serverOptionsObject = typeof serverOptions === "object" ? serverOptions : {};
55
+ optionPromises.push(
56
+ quiltAppServer({
57
+ root: project.root,
58
+ app,
59
+ graphql,
60
+ runtime: runtime?.server,
61
+ ...serverOptionsObject,
62
+ env: {
63
+ ...resolveEnvOption(env),
64
+ ...resolveEnvOption(serverOptionsObject?.env)
65
+ },
66
+ assets: { ...assets, ...serverOptionsObject?.assets }
67
+ })
68
+ );
69
+ }
70
+ if (serviceWorkerOptions) {
71
+ const serviceWorkerOptionsObject = typeof serviceWorkerOptions === "object" ? serviceWorkerOptions : {};
72
+ optionPromises.push(
73
+ quiltAppServiceWorker({
74
+ root: project.root,
75
+ app,
76
+ graphql,
77
+ ...serviceWorkerOptionsObject,
78
+ env: {
79
+ ...resolveEnvOption(env),
80
+ ...resolveEnvOption(serviceWorkerOptionsObject?.env)
81
+ },
82
+ assets: { ...assets, ...serviceWorkerOptionsObject?.assets }
83
+ })
84
+ );
85
+ }
66
86
  return Promise.all(optionPromises);
67
87
  }
68
88
  async function quiltAppBrowser(options = {}) {
@@ -438,6 +458,163 @@ function quiltAppServerInput({
438
458
  }
439
459
  };
440
460
  }
461
+ async function quiltAppServiceWorker(options = {}) {
462
+ const { output, root = process.cwd() } = options;
463
+ const project = Project.load(root);
464
+ const hash = output?.hash ?? "async-only";
465
+ const plugins = await quiltAppServiceWorkerPlugins({
466
+ ...options,
467
+ root
468
+ });
469
+ return {
470
+ plugins,
471
+ output: {
472
+ format: "iife",
473
+ dir: project.resolve(`build/service-worker`),
474
+ entryFileNames: `[name]${hash === true ? `.[hash]` : ""}.js`,
475
+ chunkFileNames: `[name]${hash === true || hash === "async-only" ? `.[hash]` : ""}.js`,
476
+ assetFileNames: `[name]${hash === true ? `.[hash]` : ""}.[ext]`,
477
+ generatedCode: "es2015"
478
+ }
479
+ };
480
+ }
481
+ async function quiltAppServiceWorkerPlugins({
482
+ root = process.cwd(),
483
+ app,
484
+ env,
485
+ entry,
486
+ graphql = true,
487
+ assets,
488
+ output
489
+ } = {}) {
490
+ const project = Project.load(root);
491
+ const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
492
+ const baseURL = assets?.baseURL ?? "/assets/";
493
+ const assetsInline = assets?.inline ?? true;
494
+ const outputDirectory = project.resolve("build/service-worker");
495
+ const reportsDirectory = path.resolve(outputDirectory, "../reports");
496
+ const bundle = output?.bundle;
497
+ const minify = output?.minify ?? false;
498
+ const [
499
+ { visualizer },
500
+ { magicModuleEnv, replaceProcessEnv },
501
+ { sourceCode },
502
+ { react },
503
+ { tsconfigAliases },
504
+ { monorepoPackageAliases },
505
+ { css },
506
+ { rawAssets, staticAssets },
507
+ { asyncModules },
508
+ { esnext },
509
+ nodePlugins
510
+ ] = await Promise.all([
511
+ import('rollup-plugin-visualizer'),
512
+ import('./features/env.mjs'),
513
+ import('./features/source-code.mjs'),
514
+ import('./features/react.mjs'),
515
+ import('./features/typescript.mjs'),
516
+ import('./features/node.mjs'),
517
+ import('./features/css.mjs'),
518
+ import('./features/assets.mjs'),
519
+ import('./features/async.mjs'),
520
+ import('./features/esnext.mjs'),
521
+ getNodePlugins({
522
+ bundle,
523
+ resolve: { exportConditions: ["browser"] }
524
+ })
525
+ ]);
526
+ const plugins = [
527
+ quiltAppServiceWorkerInput({ root: project.root, entry }),
528
+ ...nodePlugins,
529
+ replaceProcessEnv({ mode }),
530
+ magicModuleEnv({
531
+ ...resolveEnvOption(env),
532
+ mode,
533
+ root: project.root
534
+ }),
535
+ magicModuleAppComponent({ entry: app, root: project.root }),
536
+ magicModuleAppAssetManifests(),
537
+ sourceCode({
538
+ mode,
539
+ // TODO
540
+ targets: ["defaults and not dead"],
541
+ babel: {
542
+ options(options) {
543
+ return {
544
+ ...options,
545
+ plugins: [
546
+ ...options?.plugins ?? [],
547
+ require.resolve("@quilted/babel/async"),
548
+ [require.resolve("@quilted/babel/workers"), { noop: true }]
549
+ ]
550
+ };
551
+ }
552
+ }
553
+ }),
554
+ react(),
555
+ esnext({
556
+ mode,
557
+ // TODO
558
+ targets: ["defaults and not dead"]
559
+ }),
560
+ css({ emit: false, minify }),
561
+ rawAssets(),
562
+ staticAssets({
563
+ emit: false,
564
+ baseURL,
565
+ inlineLimit: assetsInline ? typeof assetsInline === "boolean" ? void 0 : assetsInline?.limit : Number.POSITIVE_INFINITY
566
+ }),
567
+ asyncModules({
568
+ baseURL,
569
+ preload: false,
570
+ moduleID: ({ imported }) => path.relative(project.root, imported)
571
+ }),
572
+ removeBuildFiles([outputDirectory], { root: project.root }),
573
+ tsconfigAliases({ root: project.root }),
574
+ monorepoPackageAliases({ root: project.root })
575
+ ];
576
+ if (graphql) {
577
+ const { graphql: graphql2 } = await import('./features/graphql.mjs');
578
+ plugins.push(graphql2({ manifest: false }));
579
+ }
580
+ if (minify) {
581
+ const { minify: minify2 } = await import('rollup-plugin-esbuild');
582
+ plugins.push(minify2());
583
+ }
584
+ plugins.push(
585
+ visualizer({
586
+ template: "treemap",
587
+ open: false,
588
+ brotliSize: false,
589
+ filename: path.join(
590
+ reportsDirectory,
591
+ `bundle-visualizer.service-worker.html`
592
+ )
593
+ })
594
+ );
595
+ return plugins;
596
+ }
597
+ function quiltAppServiceWorkerInput({
598
+ root = process.cwd(),
599
+ entry
600
+ } = {}) {
601
+ return {
602
+ name: "@quilted/app-server/input",
603
+ async options(options) {
604
+ const serviceWorkerEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppServiceWorker({ entry, root });
605
+ if (serviceWorkerEntry == null) {
606
+ throw new Error(
607
+ `No service worker entry found. Please provide a \`service.entry\` option pointing to your service worker\u2019s source code.`
608
+ );
609
+ }
610
+ const finalEntryName = typeof serviceWorkerEntry === "string" ? path.basename(serviceWorkerEntry).split(".").slice(0, -1).join(".") : "service-worker";
611
+ return {
612
+ ...options,
613
+ input: typeof serviceWorkerEntry === "string" ? { [finalEntryName]: serviceWorkerEntry } : serviceWorkerEntry
614
+ };
615
+ }
616
+ };
617
+ }
441
618
  function nodeAppServerRuntime({
442
619
  host,
443
620
  port,
@@ -690,6 +867,24 @@ async function sourceEntryForAppServer({
690
867
  return files[0];
691
868
  }
692
869
  }
870
+ async function sourceEntryForAppServiceWorker({
871
+ entry,
872
+ root = process.cwd()
873
+ }) {
874
+ const project = Project.load(root);
875
+ if (entry) {
876
+ return project.resolve(entry);
877
+ } else {
878
+ const files = await project.glob(
879
+ "{sw,service-worker}.{ts,tsx,mjs,js,jsx}",
880
+ {
881
+ nodir: true,
882
+ absolute: true
883
+ }
884
+ );
885
+ return files[0];
886
+ }
887
+ }
693
888
  const FRAMEWORK_CHUNK_NAME = "framework";
694
889
  const POLYFILLS_CHUNK_NAME = "polyfills";
695
890
  const VENDOR_CHUNK_NAME = "vendor";
@@ -766,4 +961,4 @@ function createManualChunksSorter() {
766
961
  };
767
962
  }
768
963
 
769
- export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, appServerEntry, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, nodeAppServerRuntime, quiltApp, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserPlugins, quiltAppServer, quiltAppServerInput, quiltAppServerPlugins, sourceEntryForAppBrowser, sourceEntryForAppServer };
964
+ export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, appServerEntry, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, nodeAppServerRuntime, quiltApp, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserPlugins, quiltAppServer, quiltAppServerInput, quiltAppServerPlugins, quiltAppServiceWorker, quiltAppServiceWorkerInput, quiltAppServiceWorkerPlugins, sourceEntryForAppBrowser, sourceEntryForAppServer, sourceEntryForAppServiceWorker };
@@ -15,7 +15,8 @@ function esnext({
15
15
  target: "es2022",
16
16
  loaders: {
17
17
  ".esnext": "js"
18
- }
18
+ },
19
+ tsconfig: false
19
20
  });
20
21
  }
21
22
  let babelOptions = {