@quilted/rollup 0.1.8 → 0.1.9

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,13 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`afadefe6`](https://github.com/lemonmade/quilt/commit/afadefe6d6fc6b62c17bbc318f9c13c50ef50b7b) Thanks [@lemonmade](https://github.com/lemonmade)! - Add automatic detection of entrypoints
8
+
9
+ - [`36751497`](https://github.com/lemonmade/quilt/commit/36751497d36fd9bea227c2baf55a302d54468863) Thanks [@lemonmade](https://github.com/lemonmade)! - Add tsconfig aliases plugin
10
+
3
11
  ## 0.1.8
4
12
 
5
13
  ### Patch Changes
package/build/cjs/app.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var path = require('node:path');
4
4
  var fs = require('node:fs/promises');
5
+ var glob = require('glob');
5
6
  var constants = require('./constants.cjs');
6
7
  var strings = require('./shared/strings.cjs');
7
8
  var rollup = require('./shared/rollup.cjs');
@@ -29,12 +30,13 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
29
30
 
30
31
  async function quiltAppBrowser({
31
32
  app,
32
- entry = constants.MAGIC_MODULE_ENTRY,
33
+ entry,
33
34
  env,
34
35
  assets,
35
36
  module,
36
37
  graphql = true
37
38
  } = {}) {
39
+ const root = process.cwd();
38
40
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
39
41
  const minify = assets?.minify ?? mode === 'production';
40
42
  const baseURL = assets?.baseURL ?? '/assets/';
@@ -44,6 +46,8 @@ async function quiltAppBrowser({
44
46
  assetManifest
45
47
  }, {
46
48
  sourceCode
49
+ }, {
50
+ createTSConfigAliasPlugin
47
51
  }, {
48
52
  css
49
53
  }, {
@@ -51,7 +55,7 @@ async function quiltAppBrowser({
51
55
  staticAssets
52
56
  }, {
53
57
  systemJS
54
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/system-js.cjs'); }), rollup.getNodePlugins()]);
58
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/system-js.cjs'); }), rollup.getNodePlugins()]);
55
59
  const plugins = [...nodePlugins, systemJS({
56
60
  minify
57
61
  }), sourceCode({
@@ -63,6 +67,10 @@ async function quiltAppBrowser({
63
67
  baseURL,
64
68
  emit: true
65
69
  })];
70
+ const tsconfigAliases = await createTSConfigAliasPlugin();
71
+ if (tsconfigAliases) {
72
+ plugins.push(tsconfigAliases);
73
+ }
66
74
  if (env) {
67
75
  const {
68
76
  magicModuleEnv,
@@ -84,9 +92,14 @@ async function quiltAppBrowser({
84
92
  }));
85
93
  }
86
94
  }
87
- if (app) {
95
+ const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
96
+ cwd: root,
97
+ nodir: true,
98
+ absolute: true
99
+ }).then(files => files[0]));
100
+ if (appEntry) {
88
101
  plugins.push(magicModuleAppComponent({
89
- entry: app
102
+ entry: appEntry
90
103
  }));
91
104
  }
92
105
  plugins.push(magicModuleAppBrowserEntry(module));
@@ -115,8 +128,13 @@ async function quiltAppBrowser({
115
128
  brotliSize: true,
116
129
  filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
117
130
  }));
131
+ const finalEntry = entry ?? (await glob.glob('browser.{ts,tsx,mjs,js,jsx}', {
132
+ cwd: root,
133
+ nodir: true,
134
+ absolute: true
135
+ }).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
118
136
  return {
119
- input: entry,
137
+ input: finalEntry,
120
138
  plugins,
121
139
  onwarn(warning, defaultWarn) {
122
140
  // Removes annoying warnings for React-focused libraries that
@@ -140,15 +158,18 @@ async function quiltAppBrowser({
140
158
  async function quiltAppServer({
141
159
  app,
142
160
  env,
161
+ entry,
143
162
  graphql = true,
144
- entry = constants.MAGIC_MODULE_ENTRY,
145
163
  minify = false
146
164
  } = {}) {
165
+ const root = process.cwd();
147
166
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
148
167
  const [{
149
168
  visualizer
150
169
  }, {
151
170
  sourceCode
171
+ }, {
172
+ createTSConfigAliasPlugin
152
173
  }, {
153
174
  css
154
175
  }, {
@@ -156,7 +177,7 @@ async function quiltAppServer({
156
177
  staticAssets
157
178
  }, {
158
179
  magicModuleRequestRouterEntry
159
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/request-router.cjs'); }), rollup.getNodePlugins()]);
180
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/request-router.cjs'); }), rollup.getNodePlugins()]);
160
181
  const plugins = [...nodePlugins, sourceCode({
161
182
  mode
162
183
  }), css({
@@ -165,6 +186,10 @@ async function quiltAppServer({
165
186
  }), rawAssets(), staticAssets({
166
187
  emit: false
167
188
  })];
189
+ const tsconfigAliases = await createTSConfigAliasPlugin();
190
+ if (tsconfigAliases) {
191
+ plugins.push(tsconfigAliases);
192
+ }
168
193
  if (env) {
169
194
  const {
170
195
  magicModuleEnv,
@@ -186,9 +211,14 @@ async function quiltAppServer({
186
211
  }));
187
212
  }
188
213
  }
189
- if (app) {
214
+ const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
215
+ cwd: root,
216
+ nodir: true,
217
+ absolute: true
218
+ }).then(files => files[0]));
219
+ if (appEntry) {
190
220
  plugins.push(magicModuleAppComponent({
191
- entry: app
221
+ entry: appEntry
192
222
  }));
193
223
  }
194
224
  plugins.push(magicModuleRequestRouterEntry());
@@ -216,8 +246,13 @@ async function quiltAppServer({
216
246
  brotliSize: true,
217
247
  filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
218
248
  }));
249
+ const finalEntry = entry ?? (await glob.glob('server.{ts,tsx,mjs,js,jsx}', {
250
+ cwd: root,
251
+ nodir: true,
252
+ absolute: true
253
+ }).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
219
254
  return {
220
- input: entry,
255
+ input: finalEntry,
221
256
  plugins,
222
257
  onwarn(warning, defaultWarn) {
223
258
  // Removes annoying warnings for React-focused libraries that
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var fs = require('node:fs');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n["default"] = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
24
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
25
+
26
+ async function createTSConfigAliasPlugin({
27
+ root = process.cwd()
28
+ } = {}) {
29
+ const [{
30
+ default: alias
31
+ }, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
32
+ const tsconfigPaths = tsconfig?.compilerOptions?.paths;
33
+ if (tsconfigPaths == null) return undefined;
34
+ return alias({
35
+ entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
36
+ return {
37
+ find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
38
+ replacement: aliases[0].replace('*', '$1')
39
+ };
40
+ })
41
+ });
42
+ }
43
+ async function getTSConfig(root) {
44
+ const tsconfigPath = path__namespace.join(root, 'tsconfig.json');
45
+ if (!fs__namespace.existsSync(tsconfigPath)) {
46
+ return undefined;
47
+ }
48
+ try {
49
+ const tsconfig = JSON.parse(await fs__namespace.promises.readFile(tsconfigPath, 'utf8'));
50
+ return tsconfig;
51
+ } catch {
52
+ // intentional noop
53
+ }
54
+ }
55
+
56
+ exports.createTSConfigAliasPlugin = createTSConfigAliasPlugin;
package/build/esm/app.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as path from 'node:path';
2
2
  import * as fs from 'node:fs/promises';
3
+ import { glob } from 'glob';
3
4
  import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
4
5
  import { multiline } from './shared/strings.mjs';
5
6
  import { getNodePlugins } from './shared/rollup.mjs';
@@ -7,12 +8,13 @@ import { createMagicModulePlugin } from './shared/magic-module.mjs';
7
8
 
8
9
  async function quiltAppBrowser({
9
10
  app,
10
- entry = MAGIC_MODULE_ENTRY,
11
+ entry,
11
12
  env,
12
13
  assets,
13
14
  module,
14
15
  graphql = true
15
16
  } = {}) {
17
+ const root = process.cwd();
16
18
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
17
19
  const minify = assets?.minify ?? mode === 'production';
18
20
  const baseURL = assets?.baseURL ?? '/assets/';
@@ -22,6 +24,8 @@ async function quiltAppBrowser({
22
24
  assetManifest
23
25
  }, {
24
26
  sourceCode
27
+ }, {
28
+ createTSConfigAliasPlugin
25
29
  }, {
26
30
  css
27
31
  }, {
@@ -29,7 +33,7 @@ async function quiltAppBrowser({
29
33
  staticAssets
30
34
  }, {
31
35
  systemJS
32
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
36
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
33
37
  const plugins = [...nodePlugins, systemJS({
34
38
  minify
35
39
  }), sourceCode({
@@ -41,6 +45,10 @@ async function quiltAppBrowser({
41
45
  baseURL,
42
46
  emit: true
43
47
  })];
48
+ const tsconfigAliases = await createTSConfigAliasPlugin();
49
+ if (tsconfigAliases) {
50
+ plugins.push(tsconfigAliases);
51
+ }
44
52
  if (env) {
45
53
  const {
46
54
  magicModuleEnv,
@@ -62,9 +70,14 @@ async function quiltAppBrowser({
62
70
  }));
63
71
  }
64
72
  }
65
- if (app) {
73
+ const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
74
+ cwd: root,
75
+ nodir: true,
76
+ absolute: true
77
+ }).then(files => files[0]));
78
+ if (appEntry) {
66
79
  plugins.push(magicModuleAppComponent({
67
- entry: app
80
+ entry: appEntry
68
81
  }));
69
82
  }
70
83
  plugins.push(magicModuleAppBrowserEntry(module));
@@ -93,8 +106,13 @@ async function quiltAppBrowser({
93
106
  brotliSize: true,
94
107
  filename: path.resolve(`build/reports/bundle-visualizer.html`)
95
108
  }));
109
+ const finalEntry = entry ?? (await glob('browser.{ts,tsx,mjs,js,jsx}', {
110
+ cwd: root,
111
+ nodir: true,
112
+ absolute: true
113
+ }).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
96
114
  return {
97
- input: entry,
115
+ input: finalEntry,
98
116
  plugins,
99
117
  onwarn(warning, defaultWarn) {
100
118
  // Removes annoying warnings for React-focused libraries that
@@ -118,15 +136,18 @@ async function quiltAppBrowser({
118
136
  async function quiltAppServer({
119
137
  app,
120
138
  env,
139
+ entry,
121
140
  graphql = true,
122
- entry = MAGIC_MODULE_ENTRY,
123
141
  minify = false
124
142
  } = {}) {
143
+ const root = process.cwd();
125
144
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
126
145
  const [{
127
146
  visualizer
128
147
  }, {
129
148
  sourceCode
149
+ }, {
150
+ createTSConfigAliasPlugin
130
151
  }, {
131
152
  css
132
153
  }, {
@@ -134,7 +155,7 @@ async function quiltAppServer({
134
155
  staticAssets
135
156
  }, {
136
157
  magicModuleRequestRouterEntry
137
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
158
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
138
159
  const plugins = [...nodePlugins, sourceCode({
139
160
  mode
140
161
  }), css({
@@ -143,6 +164,10 @@ async function quiltAppServer({
143
164
  }), rawAssets(), staticAssets({
144
165
  emit: false
145
166
  })];
167
+ const tsconfigAliases = await createTSConfigAliasPlugin();
168
+ if (tsconfigAliases) {
169
+ plugins.push(tsconfigAliases);
170
+ }
146
171
  if (env) {
147
172
  const {
148
173
  magicModuleEnv,
@@ -164,9 +189,14 @@ async function quiltAppServer({
164
189
  }));
165
190
  }
166
191
  }
167
- if (app) {
192
+ const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
193
+ cwd: root,
194
+ nodir: true,
195
+ absolute: true
196
+ }).then(files => files[0]));
197
+ if (appEntry) {
168
198
  plugins.push(magicModuleAppComponent({
169
- entry: app
199
+ entry: appEntry
170
200
  }));
171
201
  }
172
202
  plugins.push(magicModuleRequestRouterEntry());
@@ -194,8 +224,13 @@ async function quiltAppServer({
194
224
  brotliSize: true,
195
225
  filename: path.resolve(`build/reports/bundle-visualizer.html`)
196
226
  }));
227
+ const finalEntry = entry ?? (await glob('server.{ts,tsx,mjs,js,jsx}', {
228
+ cwd: root,
229
+ nodir: true,
230
+ absolute: true
231
+ }).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
197
232
  return {
198
- input: entry,
233
+ input: finalEntry,
199
234
  plugins,
200
235
  onwarn(warning, defaultWarn) {
201
236
  // Removes annoying warnings for React-focused libraries that
@@ -0,0 +1,34 @@
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+
4
+ async function createTSConfigAliasPlugin({
5
+ root = process.cwd()
6
+ } = {}) {
7
+ const [{
8
+ default: alias
9
+ }, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
10
+ const tsconfigPaths = tsconfig?.compilerOptions?.paths;
11
+ if (tsconfigPaths == null) return undefined;
12
+ return alias({
13
+ entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
14
+ return {
15
+ find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
16
+ replacement: aliases[0].replace('*', '$1')
17
+ };
18
+ })
19
+ });
20
+ }
21
+ async function getTSConfig(root) {
22
+ const tsconfigPath = path.join(root, 'tsconfig.json');
23
+ if (!fs.existsSync(tsconfigPath)) {
24
+ return undefined;
25
+ }
26
+ try {
27
+ const tsconfig = JSON.parse(await fs.promises.readFile(tsconfigPath, 'utf8'));
28
+ return tsconfig;
29
+ } catch {
30
+ // intentional noop
31
+ }
32
+ }
33
+
34
+ export { createTSConfigAliasPlugin };
@@ -1,5 +1,6 @@
1
1
  import * as path from 'node:path';
2
2
  import * as fs from 'node:fs/promises';
3
+ import { glob } from 'glob';
3
4
  import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.esnext';
4
5
  import { multiline } from './shared/strings.esnext';
5
6
  import { getNodePlugins } from './shared/rollup.esnext';
@@ -7,12 +8,13 @@ import { createMagicModulePlugin } from './shared/magic-module.esnext';
7
8
 
8
9
  async function quiltAppBrowser({
9
10
  app,
10
- entry = MAGIC_MODULE_ENTRY,
11
+ entry,
11
12
  env,
12
13
  assets,
13
14
  module,
14
15
  graphql = true
15
16
  } = {}) {
17
+ const root = process.cwd();
16
18
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
17
19
  const minify = assets?.minify ?? mode === 'production';
18
20
  const baseURL = assets?.baseURL ?? '/assets/';
@@ -22,6 +24,8 @@ async function quiltAppBrowser({
22
24
  assetManifest
23
25
  }, {
24
26
  sourceCode
27
+ }, {
28
+ createTSConfigAliasPlugin
25
29
  }, {
26
30
  css
27
31
  }, {
@@ -29,7 +33,7 @@ async function quiltAppBrowser({
29
33
  staticAssets
30
34
  }, {
31
35
  systemJS
32
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/system-js.esnext'), getNodePlugins()]);
36
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.esnext'), import('./features/typescript.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/system-js.esnext'), getNodePlugins()]);
33
37
  const plugins = [...nodePlugins, systemJS({
34
38
  minify
35
39
  }), sourceCode({
@@ -41,6 +45,10 @@ async function quiltAppBrowser({
41
45
  baseURL,
42
46
  emit: true
43
47
  })];
48
+ const tsconfigAliases = await createTSConfigAliasPlugin();
49
+ if (tsconfigAliases) {
50
+ plugins.push(tsconfigAliases);
51
+ }
44
52
  if (env) {
45
53
  const {
46
54
  magicModuleEnv,
@@ -62,9 +70,14 @@ async function quiltAppBrowser({
62
70
  }));
63
71
  }
64
72
  }
65
- if (app) {
73
+ const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
74
+ cwd: root,
75
+ nodir: true,
76
+ absolute: true
77
+ }).then(files => files[0]));
78
+ if (appEntry) {
66
79
  plugins.push(magicModuleAppComponent({
67
- entry: app
80
+ entry: appEntry
68
81
  }));
69
82
  }
70
83
  plugins.push(magicModuleAppBrowserEntry(module));
@@ -93,8 +106,13 @@ async function quiltAppBrowser({
93
106
  brotliSize: true,
94
107
  filename: path.resolve(`build/reports/bundle-visualizer.html`)
95
108
  }));
109
+ const finalEntry = entry ?? (await glob('browser.{ts,tsx,mjs,js,jsx}', {
110
+ cwd: root,
111
+ nodir: true,
112
+ absolute: true
113
+ }).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
96
114
  return {
97
- input: entry,
115
+ input: finalEntry,
98
116
  plugins,
99
117
  onwarn(warning, defaultWarn) {
100
118
  // Removes annoying warnings for React-focused libraries that
@@ -118,15 +136,18 @@ async function quiltAppBrowser({
118
136
  async function quiltAppServer({
119
137
  app,
120
138
  env,
139
+ entry,
121
140
  graphql = true,
122
- entry = MAGIC_MODULE_ENTRY,
123
141
  minify = false
124
142
  } = {}) {
143
+ const root = process.cwd();
125
144
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
126
145
  const [{
127
146
  visualizer
128
147
  }, {
129
148
  sourceCode
149
+ }, {
150
+ createTSConfigAliasPlugin
130
151
  }, {
131
152
  css
132
153
  }, {
@@ -134,7 +155,7 @@ async function quiltAppServer({
134
155
  staticAssets
135
156
  }, {
136
157
  magicModuleRequestRouterEntry
137
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/request-router.esnext'), getNodePlugins()]);
158
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.esnext'), import('./features/typescript.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/request-router.esnext'), getNodePlugins()]);
138
159
  const plugins = [...nodePlugins, sourceCode({
139
160
  mode
140
161
  }), css({
@@ -143,6 +164,10 @@ async function quiltAppServer({
143
164
  }), rawAssets(), staticAssets({
144
165
  emit: false
145
166
  })];
167
+ const tsconfigAliases = await createTSConfigAliasPlugin();
168
+ if (tsconfigAliases) {
169
+ plugins.push(tsconfigAliases);
170
+ }
146
171
  if (env) {
147
172
  const {
148
173
  magicModuleEnv,
@@ -164,9 +189,14 @@ async function quiltAppServer({
164
189
  }));
165
190
  }
166
191
  }
167
- if (app) {
192
+ const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
193
+ cwd: root,
194
+ nodir: true,
195
+ absolute: true
196
+ }).then(files => files[0]));
197
+ if (appEntry) {
168
198
  plugins.push(magicModuleAppComponent({
169
- entry: app
199
+ entry: appEntry
170
200
  }));
171
201
  }
172
202
  plugins.push(magicModuleRequestRouterEntry());
@@ -194,8 +224,13 @@ async function quiltAppServer({
194
224
  brotliSize: true,
195
225
  filename: path.resolve(`build/reports/bundle-visualizer.html`)
196
226
  }));
227
+ const finalEntry = entry ?? (await glob('server.{ts,tsx,mjs,js,jsx}', {
228
+ cwd: root,
229
+ nodir: true,
230
+ absolute: true
231
+ }).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
197
232
  return {
198
- input: entry,
233
+ input: finalEntry,
199
234
  plugins,
200
235
  onwarn(warning, defaultWarn) {
201
236
  // Removes annoying warnings for React-focused libraries that
@@ -0,0 +1,34 @@
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+
4
+ async function createTSConfigAliasPlugin({
5
+ root = process.cwd()
6
+ } = {}) {
7
+ const [{
8
+ default: alias
9
+ }, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
10
+ const tsconfigPaths = tsconfig?.compilerOptions?.paths;
11
+ if (tsconfigPaths == null) return undefined;
12
+ return alias({
13
+ entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
14
+ return {
15
+ find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
16
+ replacement: aliases[0].replace('*', '$1')
17
+ };
18
+ })
19
+ });
20
+ }
21
+ async function getTSConfig(root) {
22
+ const tsconfigPath = path.join(root, 'tsconfig.json');
23
+ if (!fs.existsSync(tsconfigPath)) {
24
+ return undefined;
25
+ }
26
+ try {
27
+ const tsconfig = JSON.parse(await fs.promises.readFile(tsconfigPath, 'utf8'));
28
+ return tsconfig;
29
+ } catch {
30
+ // intentional noop
31
+ }
32
+ }
33
+
34
+ export { createTSConfigAliasPlugin };