@quilted/rollup 0.2.39 → 0.2.40

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,18 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.2.40
4
+
5
+ ### Patch Changes
6
+
7
+ - [#805](https://github.com/lemonmade/quilt/pull/805) [`4995757`](https://github.com/lemonmade/quilt/commit/49957579a4811a1c310635f5dcdb4e67668ec22e) Thanks [@lemonmade](https://github.com/lemonmade)! - Allow server entry from `exports`
8
+
9
+ - [#805](https://github.com/lemonmade/quilt/pull/805) [`4995757`](https://github.com/lemonmade/quilt/commit/49957579a4811a1c310635f5dcdb4e67668ec22e) Thanks [@lemonmade](https://github.com/lemonmade)! - Compress built asset manifest and allow multiple named entries
10
+
11
+ - [#805](https://github.com/lemonmade/quilt/pull/805) [`4995757`](https://github.com/lemonmade/quilt/commit/49957579a4811a1c310635f5dcdb4e67668ec22e) Thanks [@lemonmade](https://github.com/lemonmade)! - Use more `package.json` for browser entrypoint
12
+
13
+ - Updated dependencies [[`4995757`](https://github.com/lemonmade/quilt/commit/49957579a4811a1c310635f5dcdb4e67668ec22e)]:
14
+ - @quilted/assets@0.1.3
15
+
3
16
  ## 0.2.39
4
17
 
5
18
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -259,11 +259,10 @@ async function quiltAppBrowserPlugins({
259
259
  }
260
260
  plugins.push(
261
261
  assetManifest({
262
- baseURL,
263
- cacheKey,
262
+ key: cacheKey,
263
+ base: baseURL,
264
264
  file: path.join(manifestsDirectory, `assets${targetFilenamePart}.json`),
265
- priority: assets?.priority,
266
- moduleID: ({ imported }) => path.relative(project.root, imported)
265
+ priority: assets?.priority
267
266
  }),
268
267
  visualizer({
269
268
  template: "treemap",
@@ -281,17 +280,34 @@ function quiltAppBrowserInput({
281
280
  root,
282
281
  entry
283
282
  } = {}) {
283
+ const MODULES_TO_ENTRIES = /* @__PURE__ */ new Map();
284
284
  return {
285
285
  name: "@quilted/app-browser/input",
286
286
  async options(options) {
287
287
  const finalEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppBrowser({ entry, root }) ?? MAGIC_MODULE_ENTRY;
288
288
  const finalEntryName = typeof finalEntry === "string" && finalEntry !== MAGIC_MODULE_ENTRY ? path.basename(finalEntry).split(".").slice(0, -1).join(".") : "browser";
289
+ const additionalEntries = await additionalEntriesForAppBrowser({ root });
290
+ if (typeof finalEntry === "string") {
291
+ MODULES_TO_ENTRIES.set(finalEntry, ".");
292
+ }
293
+ for (const [name, entry2] of Object.entries(additionalEntries)) {
294
+ MODULES_TO_ENTRIES.set(entry2, `./${name}`);
295
+ }
289
296
  return {
290
297
  ...options,
291
298
  // If we are using the "magic entry", give it an explicit name of `browser`.
292
299
  // Otherwise, Rollup will use the file name as the output name.
293
- input: typeof finalEntry === "string" ? { [finalEntryName]: finalEntry } : finalEntry
300
+ input: typeof finalEntry === "string" ? { ...additionalEntries, [finalEntryName]: finalEntry } : Array.isArray(finalEntry) ? finalEntry : { ...additionalEntries, ...finalEntry }
294
301
  };
302
+ },
303
+ resolveId(source, importer, options) {
304
+ const entry2 = MODULES_TO_ENTRIES.get(source);
305
+ if (entry2 == null) return null;
306
+ return this.resolve(source, importer, { ...options, skipSelf: true }).then(
307
+ (resolved) => {
308
+ return resolved ? { ...resolved, meta: { ...resolved.meta, quilt: { entry: entry2 } } } : resolved;
309
+ }
310
+ );
295
311
  }
296
312
  };
297
313
  }
@@ -680,14 +696,6 @@ function magicModuleAppComponent({
680
696
  module: MAGIC_MODULE_APP_COMPONENT,
681
697
  alias: entry ?? async function magicModuleApp() {
682
698
  const project = Project.load(root);
683
- const { packageJSON } = project;
684
- if (typeof packageJSON.raw.main === "string") {
685
- return project.resolve(packageJSON.raw.main);
686
- }
687
- const rootEntry = packageJSON.raw.exports?.["."];
688
- if (typeof rootEntry === "string") {
689
- return project.resolve(rootEntry);
690
- }
691
699
  const globbed = await project.glob(
692
700
  "{App,app,index}.{ts,tsx,mjs,js,jsx}",
693
701
  {
@@ -706,7 +714,7 @@ function magicModuleAppRequestRouter({
706
714
  return createMagicModulePlugin({
707
715
  name: "@quilted/magic-module/app-request-router",
708
716
  module: MAGIC_MODULE_REQUEST_ROUTER,
709
- alias: () => appServerEntry({ entry, root }),
717
+ alias: () => sourceEntryForAppServer({ entry, root }),
710
718
  async source() {
711
719
  return multiline`
712
720
  import '@quilted/quilt/globals';
@@ -738,21 +746,6 @@ function magicModuleAppRequestRouter({
738
746
  }
739
747
  });
740
748
  }
741
- async function appServerEntry({
742
- entry,
743
- root = process.cwd()
744
- } = {}) {
745
- if (entry) return entry;
746
- const project = Project.load(root);
747
- const globbed = await project.glob(
748
- "{server,service,backend}.{ts,tsx,mjs,js,jsx}",
749
- {
750
- nodir: true,
751
- absolute: true
752
- }
753
- );
754
- return globbed[0];
755
- }
756
749
  function magicModuleAppBrowserEntry({
757
750
  hydrate = true,
758
751
  selector = "#app"
@@ -846,6 +839,27 @@ async function sourceEntryForAppBrowser({
846
839
  if (entry) {
847
840
  return project.resolve(entry);
848
841
  } else {
842
+ const { packageJSON } = project;
843
+ if (typeof packageJSON.raw.main === "string") {
844
+ return project.resolve(packageJSON.raw.main);
845
+ }
846
+ if (typeof packageJSON.raw.browser === "string") {
847
+ return project.resolve(packageJSON.raw.browser);
848
+ }
849
+ let currentEntry = packageJSON.raw.exports;
850
+ let resolvedEntryFromExports = resolveExportsField(
851
+ project,
852
+ currentEntry,
853
+ BROWSER_EXPORT_CONDITIONS
854
+ );
855
+ if (resolvedEntryFromExports) return resolvedEntryFromExports;
856
+ currentEntry = currentEntry?.["."];
857
+ resolvedEntryFromExports = resolveExportsField(
858
+ project,
859
+ currentEntry,
860
+ BROWSER_EXPORT_CONDITIONS
861
+ );
862
+ if (resolvedEntryFromExports) return resolvedEntryFromExports;
849
863
  const files = await project.glob(
850
864
  "{browser,client,web}.{ts,tsx,mjs,js,jsx}",
851
865
  {
@@ -856,6 +870,51 @@ async function sourceEntryForAppBrowser({
856
870
  return files[0];
857
871
  }
858
872
  }
873
+ const BROWSER_EXPORT_CONDITIONS = /* @__PURE__ */ new Set([
874
+ "browser",
875
+ "source",
876
+ "quilt:source",
877
+ "default"
878
+ ]);
879
+ const SERVER_EXPORT_CONDITIONS = /* @__PURE__ */ new Set([
880
+ "server",
881
+ "source",
882
+ "quilt:source",
883
+ "default"
884
+ ]);
885
+ async function additionalEntriesForAppBrowser({
886
+ root = process.cwd()
887
+ }) {
888
+ const additionalEntries = {};
889
+ const project = Project.load(root);
890
+ const exports = project.packageJSON.raw.exports;
891
+ if (typeof exports === "object" && exports != null) {
892
+ for (const [key, value] of Object.entries(exports)) {
893
+ if (!key.startsWith(".")) continue;
894
+ if (key === ".") continue;
895
+ const resolvedEntry = resolveExportsField(
896
+ project,
897
+ value,
898
+ BROWSER_EXPORT_CONDITIONS
899
+ );
900
+ if (resolvedEntry) {
901
+ additionalEntries[key.slice(2)] = resolvedEntry;
902
+ }
903
+ }
904
+ }
905
+ return additionalEntries;
906
+ }
907
+ function resolveExportsField(project, entry, conditions) {
908
+ if (typeof entry === "string") {
909
+ return project.resolve(entry);
910
+ } else if (typeof entry === "object" && entry != null) {
911
+ for (const [condition, value] of Object.entries(entry)) {
912
+ if (conditions.has(condition) && typeof value === "string") {
913
+ return project.resolve(value);
914
+ }
915
+ }
916
+ }
917
+ }
859
918
  async function sourceEntryForAppServer({
860
919
  entry,
861
920
  root = process.cwd()
@@ -863,7 +922,16 @@ async function sourceEntryForAppServer({
863
922
  const project = Project.load(root);
864
923
  if (entry) {
865
924
  return project.resolve(entry);
866
- } else {
925
+ }
926
+ {
927
+ const { packageJSON } = project;
928
+ const exports = packageJSON.raw.exports;
929
+ const resolvedFromRootServerEntry = resolveExportsField(
930
+ project,
931
+ exports?.["server"] ?? exports?.["."]?.["server"],
932
+ SERVER_EXPORT_CONDITIONS
933
+ );
934
+ if (resolvedFromRootServerEntry) return resolvedFromRootServerEntry;
867
935
  const files = await project.glob(
868
936
  "{server,service,backend}.{ts,tsx,mjs,js,jsx}",
869
937
  {
@@ -968,4 +1036,4 @@ function createManualChunksSorter() {
968
1036
  };
969
1037
  }
970
1038
 
971
- 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 };
1039
+ 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, quiltAppServiceWorker, quiltAppServiceWorkerInput, quiltAppServiceWorkerPlugins, sourceEntryForAppBrowser, sourceEntryForAppServer, sourceEntryForAppServiceWorker };
@@ -13,8 +13,8 @@ function assetManifest(manifestOptions) {
13
13
  }
14
14
  async function writeManifestForBundle(bundle, {
15
15
  file,
16
- baseURL,
17
- cacheKey,
16
+ base,
17
+ key,
18
18
  priority,
19
19
  moduleID: getModuleID = defaultModuleID
20
20
  }, { format }) {
@@ -25,7 +25,6 @@ async function writeManifestForBundle(bundle, {
25
25
  if (entries.length === 0) {
26
26
  throw new Error(`Could not find any entries in your rollup bundle...`);
27
27
  }
28
- const entryChunk = entries[0];
29
28
  const dependencyMap = /* @__PURE__ */ new Map();
30
29
  for (const output of outputs) {
31
30
  if (output.type !== "chunk") continue;
@@ -36,32 +35,35 @@ async function writeManifestForBundle(bundle, {
36
35
  function getAssetId(file2) {
37
36
  let id = assetIdMap.get(file2);
38
37
  if (id == null) {
39
- assets.push(`${baseURL}${file2}`);
38
+ assets.push([file2.endsWith(".css") ? 1 : 2, file2]);
40
39
  id = assets.length - 1;
41
40
  assetIdMap.set(file2, id);
42
41
  }
43
42
  return id;
44
43
  }
45
44
  const manifest = {
45
+ key: key && key.size > 0 ? key.toString() : void 0,
46
+ base,
46
47
  priority,
47
- cacheKey: cacheKey && cacheKey.size > 0 ? cacheKey.toString() : void 0,
48
48
  assets,
49
- attributes: format === "es" ? { scripts: { type: "module" } } : void 0,
50
- entries: {
51
- default: createAssetsEntry([...entryChunk.imports, entryChunk.fileName], {
52
- dependencyMap,
53
- getAssetId
54
- })
55
- },
49
+ attributes: format === "es" ? { 2: { type: "module" } } : void 0,
50
+ entries: {},
56
51
  modules: {}
57
52
  };
58
53
  for (const output of outputs) {
59
- if (output.type !== "chunk" || !output.isDynamicEntry) continue;
54
+ if (output.type !== "chunk" || !output.isDynamicEntry && !output.isEntry) {
55
+ continue;
56
+ }
60
57
  const rollupModuleID = output.facadeModuleId ?? output.moduleIds.at(-1);
61
58
  if (rollupModuleID == null) continue;
62
- const imported = this.getModuleInfo(rollupModuleID)?.meta?.quilt?.module ?? rollupModuleID;
59
+ const moduleInfo = this.getModuleInfo(rollupModuleID);
60
+ const imported = moduleInfo?.meta?.quilt?.module ?? rollupModuleID;
63
61
  const moduleID = getModuleID({ imported });
64
62
  if (moduleID == null) continue;
63
+ if (output.isEntry) {
64
+ const entry = moduleInfo?.meta?.quilt?.entry ?? moduleID;
65
+ manifest.entries[entry] = moduleID;
66
+ }
65
67
  manifest.modules[moduleID] = createAssetsEntry(
66
68
  [...output.imports, output.fileName],
67
69
  { dependencyMap, getAssetId }
@@ -71,14 +73,13 @@ async function writeManifestForBundle(bundle, {
71
73
  await fs.writeFile(file, JSON.stringify(manifest, null, 2));
72
74
  }
73
75
  function defaultModuleID({ imported }) {
74
- return path.relative(process.cwd(), imported).replace(/[\\/]/g, "-");
76
+ return imported.startsWith("/") ? path.relative(process.cwd(), imported) : imported.startsWith("\0") ? imported.replace("\0", "") : imported;
75
77
  }
76
78
  function createAssetsEntry(files, {
77
79
  dependencyMap,
78
80
  getAssetId
79
81
  }) {
80
- const styles = [];
81
- const scripts = [];
82
+ const assets = [];
82
83
  const allFiles = /* @__PURE__ */ new Set();
83
84
  const addFile = (file) => {
84
85
  if (allFiles.has(file)) return;
@@ -91,13 +92,9 @@ function createAssetsEntry(files, {
91
92
  addFile(file);
92
93
  }
93
94
  for (const file of allFiles) {
94
- if (file.endsWith(".css")) {
95
- styles.push(getAssetId(file));
96
- } else {
97
- scripts.push(getAssetId(file));
98
- }
95
+ assets.push(getAssetId(file));
99
96
  }
100
- return { scripts, styles };
97
+ return assets;
101
98
  }
102
99
  const QUERY_PATTERN = /\?.*$/s;
103
100
  const HASH_PATTERN = /#.*$/s;