@quilted/rollup 0.2.38 → 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,24 @@
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
+
16
+ ## 0.2.39
17
+
18
+ ### Patch Changes
19
+
20
+ - [#803](https://github.com/lemonmade/quilt/pull/803) [`3af36eb`](https://github.com/lemonmade/quilt/commit/3af36ebb90db5506d311d77c0621b79cc5485c9d) Thanks [@lemonmade](https://github.com/lemonmade)! - Add manifest entries for all async modules
21
+
3
22
  ## 0.2.38
4
23
 
5
24
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -259,8 +259,8 @@ 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
265
  priority: assets?.priority
266
266
  }),
@@ -280,17 +280,34 @@ function quiltAppBrowserInput({
280
280
  root,
281
281
  entry
282
282
  } = {}) {
283
+ const MODULES_TO_ENTRIES = /* @__PURE__ */ new Map();
283
284
  return {
284
285
  name: "@quilted/app-browser/input",
285
286
  async options(options) {
286
287
  const finalEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppBrowser({ entry, root }) ?? MAGIC_MODULE_ENTRY;
287
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
+ }
288
296
  return {
289
297
  ...options,
290
298
  // If we are using the "magic entry", give it an explicit name of `browser`.
291
299
  // Otherwise, Rollup will use the file name as the output name.
292
- input: typeof finalEntry === "string" ? { [finalEntryName]: finalEntry } : finalEntry
300
+ input: typeof finalEntry === "string" ? { ...additionalEntries, [finalEntryName]: finalEntry } : Array.isArray(finalEntry) ? finalEntry : { ...additionalEntries, ...finalEntry }
293
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
+ );
294
311
  }
295
312
  };
296
313
  }
@@ -679,14 +696,6 @@ function magicModuleAppComponent({
679
696
  module: MAGIC_MODULE_APP_COMPONENT,
680
697
  alias: entry ?? async function magicModuleApp() {
681
698
  const project = Project.load(root);
682
- const { packageJSON } = project;
683
- if (typeof packageJSON.raw.main === "string") {
684
- return project.resolve(packageJSON.raw.main);
685
- }
686
- const rootEntry = packageJSON.raw.exports?.["."];
687
- if (typeof rootEntry === "string") {
688
- return project.resolve(rootEntry);
689
- }
690
699
  const globbed = await project.glob(
691
700
  "{App,app,index}.{ts,tsx,mjs,js,jsx}",
692
701
  {
@@ -705,7 +714,7 @@ function magicModuleAppRequestRouter({
705
714
  return createMagicModulePlugin({
706
715
  name: "@quilted/magic-module/app-request-router",
707
716
  module: MAGIC_MODULE_REQUEST_ROUTER,
708
- alias: () => appServerEntry({ entry, root }),
717
+ alias: () => sourceEntryForAppServer({ entry, root }),
709
718
  async source() {
710
719
  return multiline`
711
720
  import '@quilted/quilt/globals';
@@ -737,21 +746,6 @@ function magicModuleAppRequestRouter({
737
746
  }
738
747
  });
739
748
  }
740
- async function appServerEntry({
741
- entry,
742
- root = process.cwd()
743
- } = {}) {
744
- if (entry) return entry;
745
- const project = Project.load(root);
746
- const globbed = await project.glob(
747
- "{server,service,backend}.{ts,tsx,mjs,js,jsx}",
748
- {
749
- nodir: true,
750
- absolute: true
751
- }
752
- );
753
- return globbed[0];
754
- }
755
749
  function magicModuleAppBrowserEntry({
756
750
  hydrate = true,
757
751
  selector = "#app"
@@ -845,6 +839,27 @@ async function sourceEntryForAppBrowser({
845
839
  if (entry) {
846
840
  return project.resolve(entry);
847
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;
848
863
  const files = await project.glob(
849
864
  "{browser,client,web}.{ts,tsx,mjs,js,jsx}",
850
865
  {
@@ -855,6 +870,51 @@ async function sourceEntryForAppBrowser({
855
870
  return files[0];
856
871
  }
857
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
+ }
858
918
  async function sourceEntryForAppServer({
859
919
  entry,
860
920
  root = process.cwd()
@@ -862,7 +922,16 @@ async function sourceEntryForAppServer({
862
922
  const project = Project.load(root);
863
923
  if (entry) {
864
924
  return project.resolve(entry);
865
- } 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;
866
935
  const files = await project.glob(
867
936
  "{server,service,backend}.{ts,tsx,mjs,js,jsx}",
868
937
  {
@@ -967,4 +1036,4 @@ function createManualChunksSorter() {
967
1036
  };
968
1037
  }
969
1038
 
970
- 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 };
@@ -11,7 +11,13 @@ function assetManifest(manifestOptions) {
11
11
  }
12
12
  };
13
13
  }
14
- async function writeManifestForBundle(bundle, { file, baseURL, cacheKey, priority }, { format }) {
14
+ async function writeManifestForBundle(bundle, {
15
+ file,
16
+ base,
17
+ key,
18
+ priority,
19
+ moduleID: getModuleID = defaultModuleID
20
+ }, { format }) {
15
21
  const outputs = Object.values(bundle);
16
22
  const entries = outputs.filter(
17
23
  (output) => output.type === "chunk" && output.isEntry
@@ -19,7 +25,6 @@ async function writeManifestForBundle(bundle, { file, baseURL, cacheKey, priorit
19
25
  if (entries.length === 0) {
20
26
  throw new Error(`Could not find any entries in your rollup bundle...`);
21
27
  }
22
- const entryChunk = entries[0];
23
28
  const dependencyMap = /* @__PURE__ */ new Map();
24
29
  for (const output of outputs) {
25
30
  if (output.type !== "chunk") continue;
@@ -30,32 +35,36 @@ async function writeManifestForBundle(bundle, { file, baseURL, cacheKey, priorit
30
35
  function getAssetId(file2) {
31
36
  let id = assetIdMap.get(file2);
32
37
  if (id == null) {
33
- assets.push(`${baseURL}${file2}`);
38
+ assets.push([file2.endsWith(".css") ? 1 : 2, file2]);
34
39
  id = assets.length - 1;
35
40
  assetIdMap.set(file2, id);
36
41
  }
37
42
  return id;
38
43
  }
39
44
  const manifest = {
45
+ key: key && key.size > 0 ? key.toString() : void 0,
46
+ base,
40
47
  priority,
41
- cacheKey: cacheKey && cacheKey.size > 0 ? cacheKey.toString() : void 0,
42
48
  assets,
43
- attributes: format === "es" ? { scripts: { type: "module" } } : void 0,
44
- entries: {
45
- default: createAssetsEntry([...entryChunk.imports, entryChunk.fileName], {
46
- dependencyMap,
47
- getAssetId
48
- })
49
- },
49
+ attributes: format === "es" ? { 2: { type: "module" } } : void 0,
50
+ entries: {},
50
51
  modules: {}
51
52
  };
52
53
  for (const output of outputs) {
53
- if (output.type !== "chunk") continue;
54
- const originalModuleId = output.facadeModuleId ?? output.moduleIds[output.moduleIds.length - 1];
55
- if (originalModuleId == null) continue;
56
- const moduleId = this.getModuleInfo(originalModuleId)?.meta.quilt?.moduleID;
57
- if (moduleId == null) continue;
58
- manifest.modules[moduleId] = createAssetsEntry(
54
+ if (output.type !== "chunk" || !output.isDynamicEntry && !output.isEntry) {
55
+ continue;
56
+ }
57
+ const rollupModuleID = output.facadeModuleId ?? output.moduleIds.at(-1);
58
+ if (rollupModuleID == null) continue;
59
+ const moduleInfo = this.getModuleInfo(rollupModuleID);
60
+ const imported = moduleInfo?.meta?.quilt?.module ?? rollupModuleID;
61
+ const moduleID = getModuleID({ imported });
62
+ if (moduleID == null) continue;
63
+ if (output.isEntry) {
64
+ const entry = moduleInfo?.meta?.quilt?.entry ?? moduleID;
65
+ manifest.entries[entry] = moduleID;
66
+ }
67
+ manifest.modules[moduleID] = createAssetsEntry(
59
68
  [...output.imports, output.fileName],
60
69
  { dependencyMap, getAssetId }
61
70
  );
@@ -63,12 +72,14 @@ async function writeManifestForBundle(bundle, { file, baseURL, cacheKey, priorit
63
72
  await fs.mkdir(path.dirname(file), { recursive: true });
64
73
  await fs.writeFile(file, JSON.stringify(manifest, null, 2));
65
74
  }
75
+ function defaultModuleID({ imported }) {
76
+ return imported.startsWith("/") ? path.relative(process.cwd(), imported) : imported.startsWith("\0") ? imported.replace("\0", "") : imported;
77
+ }
66
78
  function createAssetsEntry(files, {
67
79
  dependencyMap,
68
80
  getAssetId
69
81
  }) {
70
- const styles = [];
71
- const scripts = [];
82
+ const assets = [];
72
83
  const allFiles = /* @__PURE__ */ new Set();
73
84
  const addFile = (file) => {
74
85
  if (allFiles.has(file)) return;
@@ -81,13 +92,9 @@ function createAssetsEntry(files, {
81
92
  addFile(file);
82
93
  }
83
94
  for (const file of allFiles) {
84
- if (file.endsWith(".css")) {
85
- styles.push(getAssetId(file));
86
- } else {
87
- scripts.push(getAssetId(file));
88
- }
95
+ assets.push(getAssetId(file));
89
96
  }
90
- return { scripts, styles };
97
+ return assets;
91
98
  }
92
99
  const QUERY_PATTERN = /\?.*$/s;
93
100
  const HASH_PATTERN = /#.*$/s;
@@ -1,5 +1,4 @@
1
- import { createHash } from 'node:crypto';
2
- import { sep, posix } from 'node:path';
1
+ import * as path from 'node:path';
3
2
  import { multiline } from '../shared/strings.mjs';
4
3
  import MagicString from 'magic-string';
5
4
 
@@ -54,7 +53,7 @@ function asyncModules({
54
53
  return {
55
54
  code,
56
55
  meta: {
57
- quilt: { moduleID }
56
+ quilt: { module: imported, moduleID }
58
57
  }
59
58
  };
60
59
  }
@@ -78,9 +77,7 @@ function asyncModules({
78
77
  };
79
78
  }
80
79
  function defaultModuleID({ imported }) {
81
- const name = imported.split(sep).pop().split(".")[0];
82
- const hash = createHash("sha256").update(imported).digest("hex").substring(0, 8);
83
- return `${name}_${hash}`;
80
+ return path.relative(process.cwd(), imported).replace(/[\\/]/g, "-");
84
81
  }
85
82
  async function preloadAsyncAssetsInESMBundle(bundle) {
86
83
  const { parse: parseImports } = await import('es-module-lexer');
@@ -145,7 +142,10 @@ function getDependenciesForImport(imported, chunk, bundle) {
145
142
  const originalFilename = chunk.fileName;
146
143
  const dependencies = /* @__PURE__ */ new Set();
147
144
  const analyzed = /* @__PURE__ */ new Set();
148
- const normalizedFile = posix.join(posix.dirname(originalFilename), imported);
145
+ const normalizedFile = path.posix.join(
146
+ path.posix.dirname(originalFilename),
147
+ imported
148
+ );
149
149
  const addDependencies = (filename) => {
150
150
  if (filename === originalFilename) return;
151
151
  if (analyzed.has(filename)) return;
@@ -162,4 +162,4 @@ function getDependenciesForImport(imported, chunk, bundle) {
162
162
  return dependencies;
163
163
  }
164
164
 
165
- export { asyncModules };
165
+ export { IMPORT_PREFIX, asyncModules };