@quilted/rollup 0.2.5 → 0.2.7

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,23 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.2.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6c7371f7`](https://github.com/lemonmade/quilt/commit/6c7371f7a34ce89383adec9501ca31db5ce4d3c7) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix asset references during development
8
+
9
+ - [`807b8e66`](https://github.com/lemonmade/quilt/commit/807b8e6644ef79d00dc631da4633647d119f0cd6) Thanks [@lemonmade](https://github.com/lemonmade)! - Add support for multi-entry modules
10
+
11
+ - [`274e09ea`](https://github.com/lemonmade/quilt/commit/274e09eaf9ecd0626298941a68a9984b6ca6f488) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix monorepo aliases plugin
12
+
13
+ - [`85c21b4f`](https://github.com/lemonmade/quilt/commit/85c21b4f35b1b7949fe445f25b25282f326d4833) Thanks [@lemonmade](https://github.com/lemonmade)! - Clean up internal imports in apps and packages
14
+
15
+ ## 0.2.6
16
+
17
+ ### Patch Changes
18
+
19
+ - [`e77a644c`](https://github.com/lemonmade/quilt/commit/e77a644cfaf528cd635f4bc26814c7ccb654e515) Thanks [@lemonmade](https://github.com/lemonmade)! - Add more development features to Vite plugin
20
+
3
21
  ## 0.2.5
4
22
 
5
23
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -85,7 +85,8 @@ async function quiltAppBrowserOptions(options = {}) {
85
85
  assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
86
86
  chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
87
87
  manualChunks: createManualChunksSorter(),
88
- generatedCode
88
+ generatedCode,
89
+ minifyInternalExports: true
89
90
  }
90
91
  };
91
92
  }
@@ -142,6 +143,8 @@ async function quiltAppBrowser({
142
143
  systemJS({ minify }),
143
144
  replaceProcessEnv({ mode }),
144
145
  magicModuleEnv({ ...resolveEnvOption(env), mode }),
146
+ magicModuleAppComponent({ entry: app, root: project.root }),
147
+ magicModuleAppBrowserEntry(module),
145
148
  sourceCode({
146
149
  mode,
147
150
  targets: browserGroup.browsers,
@@ -197,11 +200,6 @@ async function quiltAppBrowser({
197
200
  })
198
201
  );
199
202
  }
200
- const appEntry = await resolveAppEntry(app, project);
201
- if (appEntry) {
202
- plugins.push(magicModuleAppComponent({ entry: appEntry }));
203
- }
204
- plugins.push(magicModuleAppBrowserEntry(module));
205
203
  if (graphql) {
206
204
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
207
205
  plugins.push(
@@ -239,17 +237,13 @@ async function quiltAppBrowser({
239
237
  return plugins;
240
238
  }
241
239
  function quiltAppBrowserInput({
242
- root = process.cwd(),
240
+ root,
243
241
  entry
244
242
  } = {}) {
245
- const project = Project.load(root);
246
243
  return {
247
244
  name: "@quilted/app-browser/input",
248
245
  async options(options) {
249
- const finalEntry = normalizeRollupInput(options.input) ?? (entry ? project.resolve(entry) : await project.glob("{browser,client,web}.{ts,tsx,mjs,js,jsx}", {
250
- nodir: true,
251
- absolute: true
252
- }).then((files) => files[0])) ?? MAGIC_MODULE_ENTRY;
246
+ const finalEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppBrowser({ entry, root }) ?? MAGIC_MODULE_ENTRY;
253
247
  return {
254
248
  ...options,
255
249
  // If we are using the "magic entry", give it an explicit name of `browser`.
@@ -323,6 +317,12 @@ async function quiltAppServer({
323
317
  ...nodePlugins,
324
318
  replaceProcessEnv({ mode }),
325
319
  magicModuleEnv({ ...resolveEnvOption(env), mode }),
320
+ magicModuleAppComponent({ entry: app, root: project.root }),
321
+ magicModuleAppServerEntry({
322
+ assets: { baseURL }
323
+ }),
324
+ magicModuleAppRequestRouter({ entry, root: project.root }),
325
+ magicModuleAppAssetManifests(),
326
326
  sourceCode({
327
327
  mode,
328
328
  targets: ["current node"],
@@ -360,21 +360,6 @@ async function quiltAppServer({
360
360
  tsconfigAliases({ root: project.root }),
361
361
  monorepoPackageAliases({ root: project.root })
362
362
  ];
363
- const appEntry = await resolveAppEntry(app, project);
364
- if (appEntry) {
365
- plugins.push(magicModuleAppComponent({ entry: appEntry }));
366
- }
367
- const serverEntry = entry ? project.resolve(entry) : await project.glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
368
- nodir: true,
369
- absolute: true
370
- }).then((files) => files[0]);
371
- plugins.push(
372
- magicModuleAppServerEntry({
373
- assets: { baseURL }
374
- }),
375
- magicModuleAppRequestRouter({ entry: serverEntry }),
376
- magicModuleAppAssetManifests()
377
- );
378
363
  if (graphql) {
379
364
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
380
365
  plugins.push(graphql2({ manifest: false }));
@@ -419,48 +404,80 @@ function quiltAppServerInput({
419
404
  }
420
405
  };
421
406
  }
422
- function magicModuleAppComponent({ entry }) {
407
+ function magicModuleAppComponent({
408
+ entry,
409
+ root = process.cwd()
410
+ }) {
423
411
  return createMagicModulePlugin({
424
412
  name: "@quilted/magic-module/app",
425
413
  module: MAGIC_MODULE_APP_COMPONENT,
426
- alias: entry
414
+ alias: entry ?? async function magicModuleApp() {
415
+ const project = Project.load(root);
416
+ const { packageJSON } = project;
417
+ if (typeof packageJSON.raw.main === "string") {
418
+ return project.resolve(packageJSON.raw.main);
419
+ }
420
+ const rootEntry = packageJSON.raw.exports?.["."];
421
+ if (typeof rootEntry === "string") {
422
+ return project.resolve(rootEntry);
423
+ }
424
+ const globbed = await project.glob(
425
+ "{App,app,index}.{ts,tsx,mjs,js,jsx}",
426
+ {
427
+ nodir: true,
428
+ absolute: true
429
+ }
430
+ );
431
+ return globbed[0];
432
+ }
427
433
  });
428
434
  }
429
435
  function magicModuleAppRequestRouter({
430
- entry
436
+ entry,
437
+ root = process.cwd()
431
438
  } = {}) {
432
439
  return createMagicModulePlugin({
433
440
  name: "@quilted/magic-module/app-request-router",
434
441
  module: MAGIC_MODULE_REQUEST_ROUTER,
435
- alias: entry,
436
- source: entry ? void 0 : async function source() {
442
+ alias: entry ?? async function magicModuleRequestRouter() {
443
+ const project = Project.load(root);
444
+ const globbed = await project.glob(
445
+ "{server,service,backend}.{ts,tsx,mjs,js,jsx}",
446
+ {
447
+ nodir: true,
448
+ absolute: true
449
+ }
450
+ );
451
+ return globbed[0];
452
+ },
453
+ async source() {
437
454
  return multiline`
438
- import '@quilted/quilt/globals';
455
+ import '@quilted/quilt/globals';
439
456
 
440
- import {jsx} from 'react/jsx-runtime';
441
- import {RequestRouter} from '@quilted/quilt/request-router';
442
- import {renderToResponse} from '@quilted/quilt/server';
457
+ import {jsx} from 'react/jsx-runtime';
458
+ import {RequestRouter} from '@quilted/quilt/request-router';
459
+ import {renderToResponse} from '@quilted/quilt/server';
443
460
 
444
- import App from ${JSON.stringify(MAGIC_MODULE_APP_COMPONENT)};
445
- import {BrowserAssets} from ${JSON.stringify(
461
+ import App from ${JSON.stringify(MAGIC_MODULE_APP_COMPONENT)};
462
+ import {BrowserAssets} from ${JSON.stringify(
446
463
  MAGIC_MODULE_BROWSER_ASSETS
447
464
  )};
448
465
 
449
- const router = new RequestRouter();
450
- const assets = new BrowserAssets();
466
+ const router = new RequestRouter();
467
+ const assets = new BrowserAssets();
451
468
 
452
- // For all GET requests, render our React application.
453
- router.get(async (request) => {
454
- const response = await renderToResponse(jsx(App), {
455
- request,
456
- assets,
457
- });
469
+ // For all GET requests, render our React application.
470
+ router.get(async (request) => {
471
+ const response = await renderToResponse(jsx(App), {
472
+ request,
473
+ assets,
474
+ });
458
475
 
459
- return response;
460
- });
476
+ return response;
477
+ });
461
478
 
462
- export default router;
463
- `;
479
+ export default router;
480
+ `;
464
481
  }
465
482
  });
466
483
  }
@@ -593,6 +610,24 @@ function magicModuleAppAssetManifests() {
593
610
  }
594
611
  });
595
612
  }
613
+ async function sourceEntryForAppBrowser({
614
+ entry,
615
+ root = process.cwd()
616
+ }) {
617
+ const project = Project.load(root);
618
+ if (entry) {
619
+ return project.resolve(entry);
620
+ } else {
621
+ const files = await project.glob(
622
+ "{browser,client,web}.{ts,tsx,mjs,js,jsx}",
623
+ {
624
+ nodir: true,
625
+ absolute: true
626
+ }
627
+ );
628
+ return files[0];
629
+ }
630
+ }
596
631
  const FRAMEWORK_CHUNK_NAME = "framework";
597
632
  const POLYFILLS_CHUNK_NAME = "polyfills";
598
633
  const VENDOR_CHUNK_NAME = "vendor";
@@ -668,23 +703,5 @@ function createManualChunksSorter() {
668
703
  return `${bundleBaseName}-${relativeId.split(path.sep)[0]?.split(".")[0]}`;
669
704
  };
670
705
  }
671
- async function resolveAppEntry(entry, project) {
672
- if (entry) {
673
- return project.resolve(entry);
674
- }
675
- const { packageJSON } = project;
676
- if (typeof packageJSON.raw.main === "string") {
677
- return project.resolve(packageJSON.raw.main);
678
- }
679
- const rootEntry = packageJSON.raw.exports?.["."];
680
- if (typeof rootEntry === "string") {
681
- return project.resolve(rootEntry);
682
- }
683
- const globbed = await project.glob("{App,app,index}.{ts,tsx,mjs,js,jsx}", {
684
- nodir: true,
685
- absolute: true
686
- });
687
- return globbed[0];
688
- }
689
706
 
690
- export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, magicModuleAppServerEntry, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserOptions, quiltAppOptions, quiltAppServer, quiltAppServerInput, quiltAppServerOptions };
707
+ export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, magicModuleAppServerEntry, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserOptions, quiltAppOptions, quiltAppServer, quiltAppServerInput, quiltAppServerOptions, sourceEntryForAppBrowser };
@@ -42,7 +42,7 @@ async function monorepoPackageAliases({
42
42
  for (const { project: project2, entries } of projectsWithEntries) {
43
43
  const { name } = project2;
44
44
  for (const [entry, source] of Object.entries(entries)) {
45
- const entryName = entry === "." ? name : `${name}/${entry}`;
45
+ const entryName = entry === "." ? name : `${name}/${entry.startsWith("./") ? entry.slice(2) : entry}`;
46
46
  aliases.push({
47
47
  find: new RegExp(`^${entryName}$`),
48
48
  replacement: source
@@ -1,4 +1,4 @@
1
- import { Project } from './shared/project.mjs';
1
+ import { Project, sourceEntriesForProject } from './shared/project.mjs';
2
2
  import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
3
3
  import { getBrowserGroupTargetDetails, rollupGenerateOptionsForBrowsers } from './shared/browserslist.mjs';
4
4
  import { resolveEnvOption } from './features/env.mjs';
@@ -48,8 +48,7 @@ async function quiltModule({
48
48
  tsconfigAliases({ root: project.root }),
49
49
  monorepoPackageAliases({ root: project.root }),
50
50
  esnext({ mode, targets: browserGroup.browsers }),
51
- react(),
52
- removeBuildFiles(["build/assets", "build/reports"], { root: project.root })
51
+ react()
53
52
  ];
54
53
  if (graphql) {
55
54
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
@@ -59,6 +58,13 @@ async function quiltModule({
59
58
  const { minify: minify2 } = await import('rollup-plugin-esbuild');
60
59
  plugins.push(minify2());
61
60
  }
61
+ if (assets?.clean ?? true) {
62
+ plugins.push(
63
+ removeBuildFiles(["build/assets", "build/reports"], {
64
+ root: project.root
65
+ })
66
+ );
67
+ }
62
68
  plugins.push(
63
69
  visualizer({
64
70
  template: "treemap",
@@ -80,27 +86,40 @@ async function quiltModule({
80
86
  assetFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ""}.[ext]`,
81
87
  generatedCode: await rollupGenerateOptionsForBrowsers(
82
88
  browserGroup.browsers
83
- )
89
+ ),
90
+ minifyInternalExports: minify
84
91
  }
85
92
  };
86
93
  }
87
94
  async function resolveModuleEntry(entry, project) {
88
95
  if (entry) {
89
- return project.resolve(entry);
96
+ if (typeof entry === "string") {
97
+ const absolutePath = project.resolve(entry);
98
+ return { [project.relative(absolutePath)]: absolutePath };
99
+ } else {
100
+ return Object.fromEntries(
101
+ Object.entries(entry).map(([key, value]) => [
102
+ normalizeEntryName(key),
103
+ project.resolve(value)
104
+ ])
105
+ );
106
+ }
90
107
  }
91
- const { main, exports } = project.packageJSON.raw;
92
- const entryFromPackageJSON = main ?? exports?.["."];
93
- if (entryFromPackageJSON) {
94
- return project.resolve(entryFromPackageJSON);
108
+ const entries = await sourceEntriesForProject(project);
109
+ const entryArray = Object.entries(entries);
110
+ if (entryArray.length > 0) {
111
+ return Object.fromEntries(
112
+ entryArray.map(([key, value]) => [normalizeEntryName(key), value])
113
+ );
95
114
  }
96
- const possibleSourceFiles = await project.glob(
97
- "{index,module,entry,input}.{ts,tsx,mjs,js,jsx}",
98
- {
99
- nodir: true,
100
- absolute: true
101
- }
102
- );
103
- return possibleSourceFiles[0];
115
+ const sourceFile = (await project.glob("{index,module,entry,input}.{ts,tsx,mjs,js,jsx}", {
116
+ nodir: true,
117
+ absolute: true
118
+ }))[0];
119
+ return { [normalizeEntryName(project.relative(sourceFile))]: sourceFile };
120
+ }
121
+ function normalizeEntryName(name) {
122
+ return name === "." ? "index" : name.startsWith("./") ? name.slice(2) : name;
104
123
  }
105
124
 
106
125
  export { quiltModule };
@@ -102,6 +102,7 @@ async function quiltPackageESModules({
102
102
  entryFileNames: `[name].mjs`,
103
103
  assetFileNames: `[name].[ext]`,
104
104
  generatedCode,
105
+ minifyInternalExports: false,
105
106
  // We only want to preserve the original directory structure if there
106
107
  // are actual package entries.
107
108
  ...hasEntries ? {
@@ -118,7 +119,8 @@ async function quiltPackageESModules({
118
119
  assetFileNames: `[name].[ext]`,
119
120
  preserveModules: true,
120
121
  preserveModulesRoot: source.root,
121
- generatedCode
122
+ generatedCode,
123
+ minifyInternalExports: false
122
124
  });
123
125
  }
124
126
  const options = {
@@ -7,18 +7,20 @@ function createMagicModulePlugin({
7
7
  source: getSource,
8
8
  sideEffects = false
9
9
  }) {
10
+ const virtualModuleAlias = `${VIRTUAL_MODULE_PREFIX}${module}${VIRTUAL_MODULE_POSTFIX}`;
10
11
  return {
11
12
  name,
12
- resolveId(id) {
13
+ async resolveId(id) {
13
14
  if (id !== module)
14
15
  return null;
16
+ const resolved = (typeof alias === "function" ? await alias() : alias) ?? virtualModuleAlias;
15
17
  return {
16
- id: alias,
18
+ id: resolved,
17
19
  moduleSideEffects: sideEffects ? "no-treeshake" : void 0
18
20
  };
19
21
  },
20
22
  load: getSource ? async function load(source) {
21
- if (source !== alias)
23
+ if (source !== virtualModuleAlias)
22
24
  return null;
23
25
  const code = await getSource.call(this);
24
26
  return {
@@ -32,6 +32,9 @@ class Project {
32
32
  resolve(...segments) {
33
33
  return path.resolve(this.root, ...segments);
34
34
  }
35
+ relative(to) {
36
+ return path.relative(this.root, to);
37
+ }
35
38
  glob(pattern, options) {
36
39
  return glob(pattern, {
37
40
  ...options,