@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 +8 -0
- package/build/cjs/app.cjs +45 -10
- package/build/cjs/features/typescript.cjs +56 -0
- package/build/esm/app.mjs +45 -10
- package/build/esm/features/typescript.mjs +34 -0
- package/build/esnext/app.esnext +45 -10
- package/build/esnext/features/typescript.esnext +34 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +1 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/typescript.d.ts +4 -0
- package/build/typescript/features/typescript.d.ts.map +1 -0
- package/package.json +1 -1
- package/source/app.ts +61 -8
- package/source/features/typescript.ts +49 -0
package/source/app.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
|
+
import {glob} from 'glob';
|
|
3
4
|
|
|
4
5
|
import type {Plugin, RollupOptions, GetManualChunk} from 'rollup';
|
|
5
6
|
import type {AssetsBuildManifest} from '@quilted/assets';
|
|
@@ -99,12 +100,13 @@ export interface AppBrowserAssetsOptions {
|
|
|
99
100
|
|
|
100
101
|
export async function quiltAppBrowser({
|
|
101
102
|
app,
|
|
102
|
-
entry
|
|
103
|
+
entry,
|
|
103
104
|
env,
|
|
104
105
|
assets,
|
|
105
106
|
module,
|
|
106
107
|
graphql = true,
|
|
107
108
|
}: AppBrowserOptions = {}) {
|
|
109
|
+
const root = process.cwd();
|
|
108
110
|
const mode =
|
|
109
111
|
(typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
110
112
|
const minify = assets?.minify ?? mode === 'production';
|
|
@@ -114,6 +116,7 @@ export async function quiltAppBrowser({
|
|
|
114
116
|
{visualizer},
|
|
115
117
|
{assetManifest},
|
|
116
118
|
{sourceCode},
|
|
119
|
+
{createTSConfigAliasPlugin},
|
|
117
120
|
{css},
|
|
118
121
|
{rawAssets, staticAssets},
|
|
119
122
|
{systemJS},
|
|
@@ -122,6 +125,7 @@ export async function quiltAppBrowser({
|
|
|
122
125
|
import('rollup-plugin-visualizer'),
|
|
123
126
|
import('@quilted/assets/rollup'),
|
|
124
127
|
import('./features/source-code.ts'),
|
|
128
|
+
import('./features/typescript.ts'),
|
|
125
129
|
import('./features/css.ts'),
|
|
126
130
|
import('./features/assets.ts'),
|
|
127
131
|
import('./features/system-js.ts'),
|
|
@@ -137,6 +141,12 @@ export async function quiltAppBrowser({
|
|
|
137
141
|
staticAssets({baseURL, emit: true}),
|
|
138
142
|
];
|
|
139
143
|
|
|
144
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
145
|
+
|
|
146
|
+
if (tsconfigAliases) {
|
|
147
|
+
plugins.push(tsconfigAliases);
|
|
148
|
+
}
|
|
149
|
+
|
|
140
150
|
if (env) {
|
|
141
151
|
const {magicModuleEnv, replaceProcessEnv} = await import(
|
|
142
152
|
'./features/env.ts'
|
|
@@ -151,8 +161,16 @@ export async function quiltAppBrowser({
|
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
163
|
|
|
154
|
-
|
|
155
|
-
|
|
164
|
+
const appEntry =
|
|
165
|
+
app ??
|
|
166
|
+
(await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
167
|
+
cwd: root,
|
|
168
|
+
nodir: true,
|
|
169
|
+
absolute: true,
|
|
170
|
+
}).then((files) => files[0]));
|
|
171
|
+
|
|
172
|
+
if (appEntry) {
|
|
173
|
+
plugins.push(magicModuleAppComponent({entry: appEntry}));
|
|
156
174
|
}
|
|
157
175
|
|
|
158
176
|
plugins.push(magicModuleAppBrowserEntry(module));
|
|
@@ -181,8 +199,17 @@ export async function quiltAppBrowser({
|
|
|
181
199
|
}),
|
|
182
200
|
);
|
|
183
201
|
|
|
202
|
+
const finalEntry =
|
|
203
|
+
entry ??
|
|
204
|
+
(await glob('browser.{ts,tsx,mjs,js,jsx}', {
|
|
205
|
+
cwd: root,
|
|
206
|
+
nodir: true,
|
|
207
|
+
absolute: true,
|
|
208
|
+
}).then((files) => files[0])) ??
|
|
209
|
+
MAGIC_MODULE_ENTRY;
|
|
210
|
+
|
|
184
211
|
return {
|
|
185
|
-
input:
|
|
212
|
+
input: finalEntry,
|
|
186
213
|
plugins,
|
|
187
214
|
onwarn(warning, defaultWarn) {
|
|
188
215
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -227,16 +254,18 @@ export interface AppServerOptions extends AppOptions {
|
|
|
227
254
|
export async function quiltAppServer({
|
|
228
255
|
app,
|
|
229
256
|
env,
|
|
257
|
+
entry,
|
|
230
258
|
graphql = true,
|
|
231
|
-
entry = MAGIC_MODULE_ENTRY,
|
|
232
259
|
minify = false,
|
|
233
260
|
}: AppServerOptions = {}) {
|
|
261
|
+
const root = process.cwd();
|
|
234
262
|
const mode =
|
|
235
263
|
(typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
236
264
|
|
|
237
265
|
const [
|
|
238
266
|
{visualizer},
|
|
239
267
|
{sourceCode},
|
|
268
|
+
{createTSConfigAliasPlugin},
|
|
240
269
|
{css},
|
|
241
270
|
{rawAssets, staticAssets},
|
|
242
271
|
{magicModuleRequestRouterEntry},
|
|
@@ -244,6 +273,7 @@ export async function quiltAppServer({
|
|
|
244
273
|
] = await Promise.all([
|
|
245
274
|
import('rollup-plugin-visualizer'),
|
|
246
275
|
import('./features/source-code.ts'),
|
|
276
|
+
import('./features/typescript.ts'),
|
|
247
277
|
import('./features/css.ts'),
|
|
248
278
|
import('./features/assets.ts'),
|
|
249
279
|
import('./features/request-router.ts'),
|
|
@@ -258,6 +288,12 @@ export async function quiltAppServer({
|
|
|
258
288
|
staticAssets({emit: false}),
|
|
259
289
|
];
|
|
260
290
|
|
|
291
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
292
|
+
|
|
293
|
+
if (tsconfigAliases) {
|
|
294
|
+
plugins.push(tsconfigAliases);
|
|
295
|
+
}
|
|
296
|
+
|
|
261
297
|
if (env) {
|
|
262
298
|
const {magicModuleEnv, replaceProcessEnv} = await import(
|
|
263
299
|
'./features/env.ts'
|
|
@@ -272,8 +308,16 @@ export async function quiltAppServer({
|
|
|
272
308
|
}
|
|
273
309
|
}
|
|
274
310
|
|
|
275
|
-
|
|
276
|
-
|
|
311
|
+
const appEntry =
|
|
312
|
+
app ??
|
|
313
|
+
(await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
314
|
+
cwd: root,
|
|
315
|
+
nodir: true,
|
|
316
|
+
absolute: true,
|
|
317
|
+
}).then((files) => files[0]));
|
|
318
|
+
|
|
319
|
+
if (appEntry) {
|
|
320
|
+
plugins.push(magicModuleAppComponent({entry: appEntry}));
|
|
277
321
|
}
|
|
278
322
|
|
|
279
323
|
plugins.push(magicModuleRequestRouterEntry());
|
|
@@ -299,8 +343,17 @@ export async function quiltAppServer({
|
|
|
299
343
|
}),
|
|
300
344
|
);
|
|
301
345
|
|
|
346
|
+
const finalEntry =
|
|
347
|
+
entry ??
|
|
348
|
+
(await glob('server.{ts,tsx,mjs,js,jsx}', {
|
|
349
|
+
cwd: root,
|
|
350
|
+
nodir: true,
|
|
351
|
+
absolute: true,
|
|
352
|
+
}).then((files) => files[0])) ??
|
|
353
|
+
MAGIC_MODULE_ENTRY;
|
|
354
|
+
|
|
302
355
|
return {
|
|
303
|
-
input:
|
|
356
|
+
input: finalEntry,
|
|
304
357
|
plugins,
|
|
305
358
|
onwarn(warning, defaultWarn) {
|
|
306
359
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
|
|
4
|
+
export async function createTSConfigAliasPlugin({
|
|
5
|
+
root = process.cwd(),
|
|
6
|
+
}: {root?: string} = {}) {
|
|
7
|
+
const [{default: alias}, tsconfig] = await Promise.all([
|
|
8
|
+
import('@rollup/plugin-alias'),
|
|
9
|
+
getTSConfig(root),
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const tsconfigPaths = tsconfig?.compilerOptions?.paths;
|
|
13
|
+
|
|
14
|
+
if (tsconfigPaths == null) return undefined;
|
|
15
|
+
|
|
16
|
+
return alias({
|
|
17
|
+
entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
|
|
18
|
+
return {
|
|
19
|
+
find: name.includes('*')
|
|
20
|
+
? new RegExp(`^${name.replace(/\*/, '(.*)')}$`)
|
|
21
|
+
: name,
|
|
22
|
+
replacement: aliases[0]!.replace('*', '$1'),
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface TSConfig {
|
|
29
|
+
compilerOptions?: {paths?: Record<string, string[]>};
|
|
30
|
+
references?: [{path: string}];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function getTSConfig(root: string) {
|
|
34
|
+
const tsconfigPath = path.join(root, 'tsconfig.json');
|
|
35
|
+
|
|
36
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const tsconfig = JSON.parse(
|
|
42
|
+
await fs.promises.readFile(tsconfigPath, 'utf8'),
|
|
43
|
+
) as TSConfig;
|
|
44
|
+
|
|
45
|
+
return tsconfig;
|
|
46
|
+
} catch {
|
|
47
|
+
// intentional noop
|
|
48
|
+
}
|
|
49
|
+
}
|