@quilted/rollup 0.1.0 → 0.1.2

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/build/cjs/app.cjs +85 -15
  3. package/build/cjs/env.cjs +21 -16
  4. package/build/cjs/request-router.cjs +2 -1
  5. package/build/cjs/shared/magic-module.cjs +0 -12
  6. package/build/cjs/shared/rollup.cjs +37 -0
  7. package/build/esm/app.mjs +65 -14
  8. package/build/esm/env.mjs +21 -17
  9. package/build/esm/request-router.mjs +4 -3
  10. package/build/esm/shared/magic-module.mjs +1 -12
  11. package/build/esm/shared/rollup.mjs +33 -0
  12. package/build/esnext/app.esnext +65 -14
  13. package/build/esnext/env.esnext +21 -17
  14. package/build/esnext/request-router.esnext +4 -3
  15. package/build/esnext/shared/magic-module.esnext +1 -12
  16. package/build/esnext/shared/rollup.esnext +33 -0
  17. package/build/tsconfig.tsbuildinfo +1 -1
  18. package/build/typescript/app.d.ts +32 -10
  19. package/build/typescript/app.d.ts.map +1 -1
  20. package/build/typescript/env.d.ts +4 -0
  21. package/build/typescript/env.d.ts.map +1 -1
  22. package/build/typescript/request-router.d.ts.map +1 -1
  23. package/build/typescript/shared/magic-module.d.ts +0 -13
  24. package/build/typescript/shared/magic-module.d.ts.map +1 -1
  25. package/build/typescript/shared/rollup.d.ts +7 -0
  26. package/build/typescript/shared/rollup.d.ts.map +1 -0
  27. package/package.json +10 -2
  28. package/source/app.ts +85 -41
  29. package/source/env.ts +25 -2
  30. package/source/request-router.ts +4 -3
  31. package/source/shared/magic-module.ts +0 -11
  32. package/source/shared/rollup.ts +68 -0
  33. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.cjs +0 -168
  34. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.cjs +0 -8
  35. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.cjs +0 -8
  36. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.cjs +0 -8
  37. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.cjs +0 -10
  38. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineArrayTransformer/inlineArrayTransformer.cjs +0 -48
  39. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.cjs +0 -8
  40. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.cjs +0 -7
  41. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.cjs +0 -8
  42. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.cjs +0 -8
  43. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.cjs +0 -8
  44. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.cjs +0 -8
  45. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.cjs +0 -7
  46. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.cjs +0 -23
  47. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceResultTransformer/replaceResultTransformer.cjs +0 -22
  48. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceSubstitutionTransformer/replaceSubstitutionTransformer.cjs +0 -22
  49. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.cjs +0 -10
  50. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/splitStringTransformer/splitStringTransformer.cjs +0 -20
  51. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.cjs +0 -11
  52. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndentTransformer/stripIndentTransformer.cjs +0 -37
  53. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.cjs +0 -7
  54. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/trimResultTransformer/trimResultTransformer.cjs +0 -33
  55. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.mjs +0 -164
  56. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.mjs +0 -6
  57. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.mjs +0 -6
  58. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.mjs +0 -6
  59. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.mjs +0 -8
  60. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineArrayTransformer/inlineArrayTransformer.mjs +0 -44
  61. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.mjs +0 -6
  62. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.mjs +0 -5
  63. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.mjs +0 -6
  64. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.mjs +0 -6
  65. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.mjs +0 -6
  66. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.mjs +0 -6
  67. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.mjs +0 -5
  68. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.mjs +0 -19
  69. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceResultTransformer/replaceResultTransformer.mjs +0 -18
  70. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceSubstitutionTransformer/replaceSubstitutionTransformer.mjs +0 -18
  71. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.mjs +0 -8
  72. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/splitStringTransformer/splitStringTransformer.mjs +0 -16
  73. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.mjs +0 -7
  74. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndentTransformer/stripIndentTransformer.mjs +0 -33
  75. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.mjs +0 -5
  76. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/trimResultTransformer/trimResultTransformer.mjs +0 -29
  77. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.esnext +0 -164
  78. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.esnext +0 -6
  79. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.esnext +0 -6
  80. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.esnext +0 -6
  81. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.esnext +0 -8
  82. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineArrayTransformer/inlineArrayTransformer.esnext +0 -44
  83. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.esnext +0 -6
  84. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.esnext +0 -5
  85. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.esnext +0 -6
  86. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.esnext +0 -6
  87. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.esnext +0 -6
  88. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.esnext +0 -6
  89. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.esnext +0 -5
  90. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.esnext +0 -19
  91. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceResultTransformer/replaceResultTransformer.esnext +0 -18
  92. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceSubstitutionTransformer/replaceSubstitutionTransformer.esnext +0 -18
  93. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.esnext +0 -8
  94. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/splitStringTransformer/splitStringTransformer.esnext +0 -16
  95. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.esnext +0 -7
  96. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndentTransformer/stripIndentTransformer.esnext +0 -33
  97. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.esnext +0 -5
  98. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/trimResultTransformer/trimResultTransformer.esnext +0 -29
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "access": "public",
7
7
  "@quilted/registry": "https://registry.npmjs.org"
8
8
  },
9
- "version": "0.1.0",
9
+ "version": "0.1.2",
10
10
  "engines": {
11
11
  "node": ">=14.0.0"
12
12
  },
@@ -27,7 +27,15 @@
27
27
  "types": "./build/typescript/index.d.ts",
28
28
  "sideEffects": false,
29
29
  "dependencies": {
30
- "dotenv": "^16.0.0"
30
+ "@rollup/plugin-replace": "^5.0.3",
31
+ "@rollup/plugin-commonjs": "^25.0.5",
32
+ "@rollup/plugin-json": "^6.0.1",
33
+ "@rollup/plugin-node-resolve": "^15.2.3",
34
+ "dotenv": "^16.0.0",
35
+ "esbuild": "^0.19.4",
36
+ "rollup-plugin-esbuild": "^6.1.0",
37
+ "rollup-plugin-node-externals": "^6.1.2",
38
+ "rollup-plugin-visualizer": "^5.9.0"
31
39
  },
32
40
  "peerDependencies": {
33
41
  "rollup": "^4.0.0"
package/source/app.ts CHANGED
@@ -1,18 +1,18 @@
1
+ import * as path from 'path';
2
+
1
3
  import type {Plugin} from 'rollup';
2
4
 
3
5
  import {
6
+ MAGIC_MODULE_ENTRY,
4
7
  MAGIC_MODULE_APP_COMPONENT,
5
8
  MAGIC_MODULE_BROWSER_ASSETS,
6
9
  MAGIC_MODULE_REQUEST_ROUTER,
7
10
  } from './constants.ts';
8
- import {magicModuleEnv, type MagicModuleEnvOptions} from './env.ts';
9
- import {magicModuleRequestRouterEntry} from './request-router.ts';
11
+ import type {MagicModuleEnvOptions} from './env.ts';
10
12
 
11
13
  import {multiline} from './shared/strings.ts';
12
- import {
13
- createMagicModulePlugin,
14
- createMagicModuleEntryPlugin,
15
- } from './shared/magic-module.ts';
14
+ import {getNodePlugins, rollupPluginsToArray} from './shared/rollup.ts';
15
+ import {createMagicModulePlugin} from './shared/magic-module.ts';
16
16
 
17
17
  export interface AppOptions {
18
18
  /**
@@ -47,21 +47,20 @@ export interface AppOptions {
47
47
  export function quiltApp({env, entry}: AppOptions = {}) {
48
48
  return {
49
49
  name: '@quilted/app',
50
- options(originalOptions) {
51
- const newPlugins = [
52
- ...(Array.isArray(originalOptions.plugins)
53
- ? originalOptions.plugins
54
- : originalOptions.plugins
55
- ? [originalOptions.plugins]
56
- : []),
57
- ];
58
-
50
+ async options(originalOptions) {
51
+ const newPlugins = rollupPluginsToArray(originalOptions.plugins);
59
52
  const newOptions = {...originalOptions, plugins: newPlugins};
60
53
 
61
54
  if (env) {
62
- newPlugins.push(
63
- typeof env === 'boolean' ? magicModuleEnv() : magicModuleEnv(env),
64
- );
55
+ const {magicModuleEnv, replaceProcessEnv} = await import('./env.ts');
56
+
57
+ if (typeof env === 'boolean') {
58
+ newPlugins.push(replaceProcessEnv({mode: 'production'}));
59
+ newPlugins.push(magicModuleEnv({mode: 'production'}));
60
+ } else {
61
+ newPlugins.push(replaceProcessEnv({mode: env.mode ?? 'production'}));
62
+ newPlugins.push(magicModuleEnv({mode: 'production', ...env}));
63
+ }
65
64
  }
66
65
 
67
66
  if (entry) {
@@ -73,33 +72,80 @@ export function quiltApp({env, entry}: AppOptions = {}) {
73
72
  } satisfies Plugin;
74
73
  }
75
74
 
76
- export interface AppBrowserOptions {
75
+ export interface AppBrowserOptions extends AppOptions {
76
+ /**
77
+ * Customizes the magic `quilt:module/browser` entry module.
78
+ */
79
+ module?: AppBrowserModuleOptions;
80
+
81
+ /**
82
+ * Customizes the assets created for your application.
83
+ */
84
+ assets?: AppBrowserAssetsOptions;
85
+ }
86
+
87
+ export interface AppBrowserModuleOptions {
77
88
  /**
78
89
  * Whether the app should use hydration or client-side rendering.
90
+ *
91
+ * @default true
79
92
  */
80
93
  hydrate?: boolean;
81
94
 
82
95
  /**
83
96
  * The CSS selector to render or hydrate the application into.
97
+ *
98
+ * @default '#app'
84
99
  */
85
100
  selector?: string;
86
101
  }
87
102
 
88
- export function quiltAppBrowser(options: AppBrowserOptions = {}) {
103
+ export interface AppBrowserAssetsOptions {
104
+ /**
105
+ * Whether to minify assets created by Quilt.
106
+ *
107
+ * @default true
108
+ */
109
+ minify?: boolean;
110
+ }
111
+
112
+ export function quiltAppBrowser({
113
+ entry,
114
+ env,
115
+ graphql,
116
+ assets,
117
+ module,
118
+ }: AppBrowserOptions = {}) {
89
119
  return {
90
120
  name: '@quilted/app/browser',
91
- options(originalOptions) {
92
- const newPlugins = [
93
- ...(Array.isArray(originalOptions.plugins)
94
- ? originalOptions.plugins
95
- : originalOptions.plugins
96
- ? [originalOptions.plugins]
97
- : []),
98
- ];
99
-
121
+ async options(originalOptions) {
122
+ const newPlugins = rollupPluginsToArray(originalOptions.plugins);
100
123
  const newOptions = {...originalOptions, plugins: newPlugins};
101
124
 
102
- newPlugins.push(magicModuleAppBrowserEntry(options));
125
+ const [{visualizer}, nodePlugins] = await Promise.all([
126
+ import('rollup-plugin-visualizer'),
127
+ getNodePlugins(),
128
+ ]);
129
+
130
+ newPlugins.push(quiltApp({env, entry, graphql}));
131
+ newPlugins.push(...nodePlugins);
132
+ newPlugins.push(magicModuleAppBrowserEntry(module));
133
+
134
+ const minify = assets?.minify ?? true;
135
+
136
+ if (minify) {
137
+ const {minify} = await import('rollup-plugin-esbuild');
138
+ newPlugins.push(minify());
139
+ }
140
+
141
+ newPlugins.push(
142
+ visualizer({
143
+ template: 'treemap',
144
+ open: false,
145
+ brotliSize: true,
146
+ filename: path.resolve('reports', `bundle-visualizer.html`),
147
+ }),
148
+ );
103
149
 
104
150
  return newOptions;
105
151
  },
@@ -118,17 +164,14 @@ export interface AppServerOptions {
118
164
  export function quiltAppServer(options: AppServerOptions = {}) {
119
165
  return {
120
166
  name: '@quilted/app/server',
121
- options(originalOptions) {
122
- const newPlugins = [
123
- ...(Array.isArray(originalOptions.plugins)
124
- ? originalOptions.plugins
125
- : originalOptions.plugins
126
- ? [originalOptions.plugins]
127
- : []),
128
- ];
129
-
167
+ async options(originalOptions) {
168
+ const newPlugins = rollupPluginsToArray(originalOptions.plugins);
130
169
  const newOptions = {...originalOptions, plugins: newPlugins};
131
170
 
171
+ const [{magicModuleRequestRouterEntry}] = await Promise.all([
172
+ import('./request-router.ts'),
173
+ ]);
174
+
132
175
  newPlugins.push(magicModuleRequestRouterEntry());
133
176
  newPlugins.push(magicModuleAppRequestRouter(options));
134
177
 
@@ -189,9 +232,10 @@ export function magicModuleAppRequestRouter({
189
232
  export function magicModuleAppBrowserEntry({
190
233
  hydrate = true,
191
234
  selector = '#app',
192
- }: AppBrowserOptions = {}) {
193
- return createMagicModuleEntryPlugin({
235
+ }: AppBrowserModuleOptions = {}) {
236
+ return createMagicModulePlugin({
194
237
  name: '@quilted/magic-module/app-browser-entry',
238
+ module: MAGIC_MODULE_ENTRY,
195
239
  sideEffects: true,
196
240
  async source() {
197
241
  const reactRootFunction = hydrate ? 'hydrateRoot' : 'createRoot';
package/source/env.ts CHANGED
@@ -2,11 +2,34 @@ import * as path from 'path';
2
2
  import * as fs from 'fs';
3
3
 
4
4
  import type {PluginContext} from 'rollup';
5
- import {stripIndent} from 'common-tags';
6
5
 
7
6
  import {MAGIC_MODULE_ENV} from './constants.ts';
7
+ import {multiline} from './shared/strings.ts';
8
+ import {smartReplace} from './shared/rollup.ts';
8
9
  import {createMagicModulePlugin} from './shared/magic-module.ts';
9
10
 
11
+ const EMPTY_PROCESS_ENV_OBJECT = {
12
+ 'globalThis.process.env.': `({}).`,
13
+ 'global.process.env.': `({}).`,
14
+ 'process.env.': `({}).`,
15
+ };
16
+
17
+ export function replaceProcessEnv({
18
+ mode,
19
+ preserve = true,
20
+ }: {
21
+ mode: string;
22
+ preserve?: boolean;
23
+ }) {
24
+ return smartReplace({
25
+ // @see https://github.com/vitejs/vite/blob/2b1ffe86328f9d06ef9528ee117b61889893ddcc/packages/vite/src/node/plugins/define.ts#L112
26
+ 'globalThis.process.env.NODE_ENV': JSON.stringify(mode),
27
+ 'global.process.env.NODE_ENV': JSON.stringify(mode),
28
+ 'process.env.NODE_ENV': JSON.stringify(mode),
29
+ ...(preserve ? {} : EMPTY_PROCESS_ENV_OBJECT),
30
+ });
31
+ }
32
+
10
33
  export interface MagicModuleEnvOptions {
11
34
  /**
12
35
  * The runtime mode for your target environment.
@@ -76,7 +99,7 @@ export function magicModuleEnv({
76
99
  : value;
77
100
  }
78
101
 
79
- return stripIndent`
102
+ return multiline`
80
103
  const runtime = (${runtime});
81
104
  const inline = JSON.parse(${JSON.stringify(JSON.stringify(inlineEnv))});
82
105
 
@@ -1,6 +1,6 @@
1
- import {MAGIC_MODULE_REQUEST_ROUTER} from './constants.ts';
1
+ import {MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER} from './constants.ts';
2
2
 
3
- import {createMagicModuleEntryPlugin} from './shared/magic-module.ts';
3
+ import {createMagicModulePlugin} from './shared/magic-module.ts';
4
4
  import {multiline} from './shared/strings.ts';
5
5
 
6
6
  export function magicModuleRequestRouterEntry({
@@ -10,9 +10,10 @@ export function magicModuleRequestRouterEntry({
10
10
  host?: string;
11
11
  port?: number;
12
12
  } = {}) {
13
- return createMagicModuleEntryPlugin({
13
+ return createMagicModulePlugin({
14
14
  name: '@quilted/request-router',
15
15
  sideEffects: true,
16
+ module: MAGIC_MODULE_ENTRY,
16
17
  async source() {
17
18
  const initialContent = multiline`
18
19
  import requestRouter from ${JSON.stringify(
@@ -1,7 +1,5 @@
1
1
  import type {Plugin, PluginContext} from 'rollup';
2
2
 
3
- import {MAGIC_MODULE_ENTRY} from '../constants.ts';
4
-
5
3
  const VIRTUAL_MODULE_PREFIX = '\0';
6
4
  const VIRTUAL_MODULE_POSTFIX = '/module.js';
7
5
 
@@ -42,12 +40,3 @@ export function createMagicModulePlugin({
42
40
  : undefined,
43
41
  } satisfies Plugin;
44
42
  }
45
-
46
- export function createMagicModuleEntryPlugin({
47
- module = MAGIC_MODULE_ENTRY,
48
- ...options
49
- }: Omit<Parameters<typeof createMagicModulePlugin>[0], 'module' | 'alias'> & {
50
- module?: string;
51
- }) {
52
- return createMagicModulePlugin({...options, module});
53
- }
@@ -0,0 +1,68 @@
1
+ import type {InputOptions} from 'rollup';
2
+ import replace, {type RollupReplaceOptions} from '@rollup/plugin-replace';
3
+
4
+ export function smartReplace(
5
+ values: NonNullable<RollupReplaceOptions['values']>,
6
+ options?: Omit<RollupReplaceOptions, 'values'>,
7
+ ) {
8
+ return replace({
9
+ // @see https://github.com/vitejs/vite/blob/2b1ffe86328f9d06ef9528ee117b61889893ddcc/packages/vite/src/node/plugins/define.ts#L108-L119
10
+ delimiters: [
11
+ '(?<![\\p{L}\\p{N}_$]|(?<!\\.\\.)\\.)(',
12
+ ')(?:(?<=\\.)|(?![\\p{L}\\p{N}_$]|\\s*?=[^=]))',
13
+ ],
14
+ preventAssignment: true,
15
+ ...options,
16
+ values,
17
+ });
18
+ }
19
+
20
+ export async function getNodePlugins() {
21
+ const [
22
+ {default: commonjs},
23
+ {default: json},
24
+ {default: nodeResolve},
25
+ {default: nodeExternals},
26
+ ] = await Promise.all([
27
+ import('@rollup/plugin-commonjs'),
28
+ import('@rollup/plugin-json'),
29
+ import('@rollup/plugin-node-resolve'),
30
+ import('rollup-plugin-node-externals'),
31
+ ]);
32
+
33
+ return [
34
+ nodeExternals({}),
35
+ nodeResolve({
36
+ preferBuiltins: true,
37
+ dedupe: [],
38
+ // extensions,
39
+ // exportConditions,
40
+ }),
41
+ commonjs(),
42
+ json(),
43
+ ];
44
+ }
45
+
46
+ export function rollupPluginsToArray(plugins?: InputOptions['plugins']) {
47
+ return Array.isArray(plugins) ? [...plugins] : plugins ? [plugins] : [];
48
+ }
49
+
50
+ export function addRollupOnWarn(
51
+ options: InputOptions,
52
+ warn: NonNullable<InputOptions['onwarn']>,
53
+ ): InputOptions {
54
+ const {onwarn: originalOnWarn} = options;
55
+
56
+ return {
57
+ ...options,
58
+ onwarn(warning, defaultWarn) {
59
+ warn(warning, (warning) => {
60
+ if (originalOnWarn && typeof warning === 'object') {
61
+ originalOnWarn(warning, defaultWarn);
62
+ } else {
63
+ defaultWarn(warning);
64
+ }
65
+ });
66
+ },
67
+ };
68
+ }
@@ -1,168 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6
-
7
- var _templateObject = _taggedTemplateLiteral(['', ''], ['', '']);
8
-
9
- function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
10
-
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
-
13
- /**
14
- * @class TemplateTag
15
- * @classdesc Consumes a pipeline of composable transformer plugins and produces a template tag.
16
- */
17
- var TemplateTag = function () {
18
- /**
19
- * constructs a template tag
20
- * @constructs TemplateTag
21
- * @param {...Object} [...transformers] - an array or arguments list of transformers
22
- * @return {Function} - a template tag
23
- */
24
- function TemplateTag() {
25
- var _this = this;
26
-
27
- for (var _len = arguments.length, transformers = Array(_len), _key = 0; _key < _len; _key++) {
28
- transformers[_key] = arguments[_key];
29
- }
30
-
31
- _classCallCheck(this, TemplateTag);
32
-
33
- this.tag = function (strings) {
34
- for (var _len2 = arguments.length, expressions = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
35
- expressions[_key2 - 1] = arguments[_key2];
36
- }
37
-
38
- if (typeof strings === 'function') {
39
- // if the first argument passed is a function, assume it is a template tag and return
40
- // an intermediary tag that processes the template using the aforementioned tag, passing the
41
- // result to our tag
42
- return _this.interimTag.bind(_this, strings);
43
- }
44
-
45
- if (typeof strings === 'string') {
46
- // if the first argument passed is a string, just transform it
47
- return _this.transformEndResult(strings);
48
- }
49
-
50
- // else, return a transformed end result of processing the template with our tag
51
- strings = strings.map(_this.transformString.bind(_this));
52
- return _this.transformEndResult(strings.reduce(_this.processSubstitutions.bind(_this, expressions)));
53
- };
54
-
55
- // if first argument is an array, extrude it as a list of transformers
56
- if (transformers.length > 0 && Array.isArray(transformers[0])) {
57
- transformers = transformers[0];
58
- }
59
-
60
- // if any transformers are functions, this means they are not initiated - automatically initiate them
61
- this.transformers = transformers.map(function (transformer) {
62
- return typeof transformer === 'function' ? transformer() : transformer;
63
- });
64
-
65
- // return an ES2015 template tag
66
- return this.tag;
67
- }
68
-
69
- /**
70
- * Applies all transformers to a template literal tagged with this method.
71
- * If a function is passed as the first argument, assumes the function is a template tag
72
- * and applies it to the template, returning a template tag.
73
- * @param {(Function|String|Array<String>)} strings - Either a template tag or an array containing template strings separated by identifier
74
- * @param {...*} ...expressions - Optional list of substitution values.
75
- * @return {(String|Function)} - Either an intermediary tag function or the results of processing the template.
76
- */
77
-
78
-
79
- _createClass(TemplateTag, [{
80
- key: 'interimTag',
81
-
82
-
83
- /**
84
- * An intermediary template tag that receives a template tag and passes the result of calling the template with the received
85
- * template tag to our own template tag.
86
- * @param {Function} nextTag - the received template tag
87
- * @param {Array<String>} template - the template to process
88
- * @param {...*} ...substitutions - `substitutions` is an array of all substitutions in the template
89
- * @return {*} - the final processed value
90
- */
91
- value: function interimTag(previousTag, template) {
92
- for (var _len3 = arguments.length, substitutions = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
93
- substitutions[_key3 - 2] = arguments[_key3];
94
- }
95
-
96
- return this.tag(_templateObject, previousTag.apply(undefined, [template].concat(substitutions)));
97
- }
98
-
99
- /**
100
- * Performs bulk processing on the tagged template, transforming each substitution and then
101
- * concatenating the resulting values into a string.
102
- * @param {Array<*>} substitutions - an array of all remaining substitutions present in this template
103
- * @param {String} resultSoFar - this iteration's result string so far
104
- * @param {String} remainingPart - the template chunk after the current substitution
105
- * @return {String} - the result of joining this iteration's processed substitution with the result
106
- */
107
-
108
- }, {
109
- key: 'processSubstitutions',
110
- value: function processSubstitutions(substitutions, resultSoFar, remainingPart) {
111
- var substitution = this.transformSubstitution(substitutions.shift(), resultSoFar);
112
- return ''.concat(resultSoFar, substitution, remainingPart);
113
- }
114
-
115
- /**
116
- * Iterate through each transformer, applying the transformer's `onString` method to the template
117
- * strings before all substitutions are processed.
118
- * @param {String} str - The input string
119
- * @return {String} - The final results of processing each transformer
120
- */
121
-
122
- }, {
123
- key: 'transformString',
124
- value: function transformString(str) {
125
- var cb = function cb(res, transform) {
126
- return transform.onString ? transform.onString(res) : res;
127
- };
128
- return this.transformers.reduce(cb, str);
129
- }
130
-
131
- /**
132
- * When a substitution is encountered, iterates through each transformer and applies the transformer's
133
- * `onSubstitution` method to the substitution.
134
- * @param {*} substitution - The current substitution
135
- * @param {String} resultSoFar - The result up to and excluding this substitution.
136
- * @return {*} - The final result of applying all substitution transformations.
137
- */
138
-
139
- }, {
140
- key: 'transformSubstitution',
141
- value: function transformSubstitution(substitution, resultSoFar) {
142
- var cb = function cb(res, transform) {
143
- return transform.onSubstitution ? transform.onSubstitution(res, resultSoFar) : res;
144
- };
145
- return this.transformers.reduce(cb, substitution);
146
- }
147
-
148
- /**
149
- * Iterates through each transformer, applying the transformer's `onEndResult` method to the
150
- * template literal after all substitutions have finished processing.
151
- * @param {String} endResult - The processed template, just before it is returned from the tag
152
- * @return {String} - The final results of processing each transformer
153
- */
154
-
155
- }, {
156
- key: 'transformEndResult',
157
- value: function transformEndResult(endResult) {
158
- var cb = function cb(res, transform) {
159
- return transform.onEndResult ? transform.onEndResult(res) : res;
160
- };
161
- return this.transformers.reduce(cb, endResult);
162
- }
163
- }]);
164
-
165
- return TemplateTag;
166
- }();
167
-
168
- exports["default"] = TemplateTag;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
6
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
7
-
8
- new TemplateTag["default"](inlineArrayTransformer["default"]({ separator: ',' }), stripIndentTransformer["default"], trimResultTransformer["default"]);
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
6
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
7
-
8
- new TemplateTag["default"](inlineArrayTransformer["default"]({ separator: ',', conjunction: 'and' }), stripIndentTransformer["default"], trimResultTransformer["default"]);
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
6
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
7
-
8
- new TemplateTag["default"](inlineArrayTransformer["default"]({ separator: ',', conjunction: 'or' }), stripIndentTransformer["default"], trimResultTransformer["default"]);
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
6
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
7
- var splitStringTransformer = require('../splitStringTransformer/splitStringTransformer.cjs');
8
- var removeNonPrintingValuesTransformer = require('../removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.cjs');
9
-
10
- new TemplateTag["default"](splitStringTransformer["default"]('\n'), removeNonPrintingValuesTransformer["default"], inlineArrayTransformer["default"], stripIndentTransformer["default"], trimResultTransformer["default"]);
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var defaults = {
6
- separator: '',
7
- conjunction: '',
8
- serial: false
9
- };
10
-
11
- /**
12
- * Converts an array substitution to a string containing a list
13
- * @param {String} [opts.separator = ''] - the character that separates each item
14
- * @param {String} [opts.conjunction = ''] - replace the last separator with this
15
- * @param {Boolean} [opts.serial = false] - include the separator before the conjunction? (Oxford comma use-case)
16
- *
17
- * @return {Object} - a TemplateTag transformer
18
- */
19
- var inlineArrayTransformer = function inlineArrayTransformer() {
20
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaults;
21
- return {
22
- onSubstitution: function onSubstitution(substitution, resultSoFar) {
23
- // only operate on arrays
24
- if (Array.isArray(substitution)) {
25
- var arrayLength = substitution.length;
26
- var separator = opts.separator;
27
- var conjunction = opts.conjunction;
28
- var serial = opts.serial;
29
- // join each item in the array into a string where each item is separated by separator
30
- // be sure to maintain indentation
31
- var indent = resultSoFar.match(/(\n?[^\S\n]+)$/);
32
- if (indent) {
33
- substitution = substitution.join(separator + indent[1]);
34
- } else {
35
- substitution = substitution.join(separator + ' ');
36
- }
37
- // if conjunction is set, replace the last separator with conjunction, but only if there is more than one substitution
38
- if (conjunction && arrayLength > 1) {
39
- var separatorIndex = substitution.lastIndexOf(separator);
40
- substitution = substitution.slice(0, separatorIndex) + (serial ? separator : '') + ' ' + conjunction + substitution.slice(separatorIndex + 1);
41
- }
42
- }
43
- return substitution;
44
- }
45
- };
46
- };
47
-
48
- exports["default"] = inlineArrayTransformer;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
6
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
7
-
8
- new TemplateTag["default"](inlineArrayTransformer["default"], stripIndentTransformer["default"], trimResultTransformer["default"]);
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
5
- var replaceResultTransformer = require('../replaceResultTransformer/replaceResultTransformer.cjs');
6
-
7
- new TemplateTag["default"](replaceResultTransformer["default"](/(?:\n(?:\s*))+/g, ' '), trimResultTransformer["default"]);
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
5
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
6
- var replaceResultTransformer = require('../replaceResultTransformer/replaceResultTransformer.cjs');
7
-
8
- new TemplateTag["default"](inlineArrayTransformer["default"]({ separator: ',' }), replaceResultTransformer["default"](/(?:\s+)/g, ' '), trimResultTransformer["default"]);
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
- var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
5
- var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
6
- var replaceResultTransformer = require('../replaceResultTransformer/replaceResultTransformer.cjs');
7
-
8
- new TemplateTag["default"](inlineArrayTransformer["default"]({ separator: ',', conjunction: 'and' }), replaceResultTransformer["default"](/(?:\s+)/g, ' '), trimResultTransformer["default"]);