@quilted/rollup 0.1.10 → 0.1.12
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 +14 -0
- package/build/cjs/app.cjs +13 -9
- package/build/cjs/index.cjs +2 -0
- package/build/cjs/package.cjs +108 -0
- package/build/cjs/shared/package-json.cjs +31 -0
- package/build/esm/app.mjs +13 -9
- package/build/esm/index.mjs +1 -0
- package/build/esm/package.mjs +87 -0
- package/build/esm/shared/package-json.mjs +10 -0
- package/build/esnext/app.esnext +13 -9
- package/build/esnext/index.esnext +1 -0
- package/build/esnext/package.esnext +87 -0
- package/build/esnext/shared/package-json.esnext +10 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +5 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/index.d.ts +1 -0
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/package.d.ts +21 -0
- package/build/typescript/package.d.ts.map +1 -0
- package/build/typescript/shared/package-json.d.ts +6 -0
- package/build/typescript/shared/package-json.d.ts.map +1 -0
- package/package.json +1 -1
- package/source/app.ts +29 -9
- package/source/index.ts +1 -0
- package/source/package.ts +142 -0
- package/source/shared/package-json.ts +20 -0
package/package.json
CHANGED
package/source/app.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import {glob} from 'glob';
|
|
4
|
+
import {fileURLToPath} from 'url';
|
|
4
5
|
|
|
5
6
|
import type {Plugin, RollupOptions, GetManualChunk} from 'rollup';
|
|
6
7
|
import type {AssetsBuildManifest} from '@quilted/assets';
|
|
@@ -18,6 +19,11 @@ import {getNodePlugins, removeBuildFiles} from './shared/rollup.ts';
|
|
|
18
19
|
import {createMagicModulePlugin} from './shared/magic-module.ts';
|
|
19
20
|
|
|
20
21
|
export interface AppOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The root directory containing the source code for your application.
|
|
24
|
+
*/
|
|
25
|
+
root?: string | URL;
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* The entry module for this app. This should be an absolute path, or relative
|
|
23
29
|
* path from the root directory containing your project. This entry should just be
|
|
@@ -106,6 +112,7 @@ export interface AppBrowserAssetsOptions {
|
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
export async function quiltAppBrowser({
|
|
115
|
+
root: rootPath = process.cwd(),
|
|
109
116
|
app,
|
|
110
117
|
entry,
|
|
111
118
|
env,
|
|
@@ -113,7 +120,7 @@ export async function quiltAppBrowser({
|
|
|
113
120
|
module,
|
|
114
121
|
graphql = true,
|
|
115
122
|
}: AppBrowserOptions = {}) {
|
|
116
|
-
const root =
|
|
123
|
+
const root = fileURLToPath(rootPath);
|
|
117
124
|
const mode =
|
|
118
125
|
(typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
119
126
|
const minify = assets?.minify ?? mode === 'production';
|
|
@@ -136,6 +143,11 @@ export async function quiltAppBrowser({
|
|
|
136
143
|
const targetName = targets.name ?? 'defaults';
|
|
137
144
|
return config[targetName] ?? ['defaults'];
|
|
138
145
|
})());
|
|
146
|
+
const normalizedTargetName =
|
|
147
|
+
targets.name === 'defaults' ? 'default' : targets.name;
|
|
148
|
+
const targetFilenamePart = normalizedTargetName
|
|
149
|
+
? `.${normalizedTargetName}`
|
|
150
|
+
: '';
|
|
139
151
|
|
|
140
152
|
const [
|
|
141
153
|
{visualizer},
|
|
@@ -205,11 +217,17 @@ export async function quiltAppBrowser({
|
|
|
205
217
|
|
|
206
218
|
if (graphql) {
|
|
207
219
|
const {graphql} = await import('./features/graphql.ts');
|
|
208
|
-
|
|
220
|
+
|
|
221
|
+
plugins.push(
|
|
222
|
+
graphql({
|
|
223
|
+
manifest: path.resolve(`manifests/graphql${targetFilenamePart}.json`),
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
209
226
|
}
|
|
210
227
|
|
|
211
228
|
if (minify) {
|
|
212
229
|
const {minify} = await import('rollup-plugin-esbuild');
|
|
230
|
+
|
|
213
231
|
plugins.push(minify());
|
|
214
232
|
}
|
|
215
233
|
|
|
@@ -222,14 +240,16 @@ export async function quiltAppBrowser({
|
|
|
222
240
|
id,
|
|
223
241
|
cacheKey,
|
|
224
242
|
baseUrl: baseURL,
|
|
225
|
-
path: path.resolve(`build/manifests/assets.json`),
|
|
243
|
+
path: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
226
244
|
priority: assets?.priority,
|
|
227
245
|
}),
|
|
228
246
|
visualizer({
|
|
229
247
|
template: 'treemap',
|
|
230
248
|
open: false,
|
|
231
249
|
brotliSize: true,
|
|
232
|
-
filename: path.resolve(
|
|
250
|
+
filename: path.resolve(
|
|
251
|
+
`build/reports/bundle-visualizer${targetFilenamePart}.html`,
|
|
252
|
+
),
|
|
233
253
|
}),
|
|
234
254
|
);
|
|
235
255
|
|
|
@@ -261,9 +281,9 @@ export async function quiltAppBrowser({
|
|
|
261
281
|
// format: isESM ? 'esm' : 'systemjs',
|
|
262
282
|
format: 'esm',
|
|
263
283
|
dir: path.resolve(`build/assets`),
|
|
264
|
-
entryFileNames: `app.[hash].js`,
|
|
265
|
-
assetFileNames: `[name].[hash].[ext]`,
|
|
266
|
-
chunkFileNames: `[name].[hash].js`,
|
|
284
|
+
entryFileNames: `app${targetFilenamePart}.[hash].js`,
|
|
285
|
+
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
286
|
+
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
267
287
|
manualChunks: createManualChunksSorter(),
|
|
268
288
|
},
|
|
269
289
|
} satisfies RollupOptions;
|
|
@@ -373,8 +393,8 @@ export async function quiltAppServer({
|
|
|
373
393
|
visualizer({
|
|
374
394
|
template: 'treemap',
|
|
375
395
|
open: false,
|
|
376
|
-
brotliSize:
|
|
377
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`),
|
|
396
|
+
brotliSize: false,
|
|
397
|
+
filename: path.resolve(`build/reports/bundle-visualizer.server.html`),
|
|
378
398
|
}),
|
|
379
399
|
);
|
|
380
400
|
|
package/source/index.ts
CHANGED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import {Plugin, type RollupOptions} from 'rollup';
|
|
3
|
+
import {glob} from 'glob';
|
|
4
|
+
import {fileURLToPath} from 'url';
|
|
5
|
+
|
|
6
|
+
import {getNodePlugins, removeBuildFiles} from './shared/rollup.ts';
|
|
7
|
+
import {loadPackageJSON, type PackageJSON} from './shared/package-json.ts';
|
|
8
|
+
|
|
9
|
+
export interface PackageOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The root directory containing the source code for your application.
|
|
12
|
+
*/
|
|
13
|
+
root?: string | URL;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function quiltPackageESModules({
|
|
17
|
+
root: rootPath = process.cwd(),
|
|
18
|
+
}: PackageOptions = {}) {
|
|
19
|
+
const root =
|
|
20
|
+
typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
21
|
+
const outputDirectory = path.join(root, 'build/esm');
|
|
22
|
+
|
|
23
|
+
const [{sourceCode}, nodePlugins, packageJSON] = await Promise.all([
|
|
24
|
+
import('./features/source-code.ts'),
|
|
25
|
+
getNodePlugins(),
|
|
26
|
+
loadPackageJSON(root),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const [entries] = await Promise.all([
|
|
30
|
+
sourceEntriesForPackage(root, packageJSON),
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
let sourceRoot = root;
|
|
34
|
+
|
|
35
|
+
const sourceEntryFiles = Object.values(entries);
|
|
36
|
+
|
|
37
|
+
for (const entry of sourceEntryFiles) {
|
|
38
|
+
if (!entry.startsWith(root)) continue;
|
|
39
|
+
|
|
40
|
+
sourceRoot = path.resolve(
|
|
41
|
+
root,
|
|
42
|
+
path.relative(root, entry).split(path.sep)[0] ?? '.',
|
|
43
|
+
);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const plugins: Plugin[] = [
|
|
48
|
+
...nodePlugins,
|
|
49
|
+
sourceCode({mode: 'production'}),
|
|
50
|
+
removeBuildFiles(['build/esm'], {root}),
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
input: sourceEntryFiles,
|
|
55
|
+
plugins,
|
|
56
|
+
onwarn(warning, defaultWarn) {
|
|
57
|
+
// Removes annoying warnings for React-focused libraries that
|
|
58
|
+
// include 'use client' directives.
|
|
59
|
+
if (
|
|
60
|
+
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
|
|
61
|
+
/['"]use client['"]/.test(warning.message)
|
|
62
|
+
) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
defaultWarn(warning);
|
|
67
|
+
},
|
|
68
|
+
output: {
|
|
69
|
+
preserveModules: true,
|
|
70
|
+
preserveModulesRoot: sourceRoot,
|
|
71
|
+
format: 'esm',
|
|
72
|
+
dir: outputDirectory,
|
|
73
|
+
entryFileNames: `[name].mjs`,
|
|
74
|
+
assetFileNames: `[name].[ext]`,
|
|
75
|
+
},
|
|
76
|
+
} satisfies RollupOptions;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function sourceEntriesForPackage(root: string, packageJSON: PackageJSON) {
|
|
80
|
+
const {main, exports} = packageJSON;
|
|
81
|
+
|
|
82
|
+
const entries: Record<string, string> = {};
|
|
83
|
+
|
|
84
|
+
if (typeof main === 'string') {
|
|
85
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof exports === 'string') {
|
|
89
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
90
|
+
return entries;
|
|
91
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
92
|
+
return entries;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const [exportPath, exportCondition] of Object.entries(
|
|
96
|
+
exports as Record<string, null | string | Record<string, string>>,
|
|
97
|
+
)) {
|
|
98
|
+
let targetFile: string | null | undefined = null;
|
|
99
|
+
|
|
100
|
+
if (exportCondition == null) continue;
|
|
101
|
+
|
|
102
|
+
if (typeof exportCondition === 'string') {
|
|
103
|
+
targetFile = exportCondition;
|
|
104
|
+
} else {
|
|
105
|
+
targetFile ??=
|
|
106
|
+
exportCondition['source'] ??
|
|
107
|
+
exportCondition['quilt:source'] ??
|
|
108
|
+
exportCondition['quilt:esnext'] ??
|
|
109
|
+
Object.values(exportCondition).find(
|
|
110
|
+
(condition) =>
|
|
111
|
+
typeof condition === 'string' && condition.startsWith('./build/'),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (targetFile == null) continue;
|
|
116
|
+
|
|
117
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
118
|
+
|
|
119
|
+
entries[exportPath] = sourceFile;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return entries;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function resolveTargetFileAsSource(file: string, root: string) {
|
|
126
|
+
const sourceFile = file.includes('/build/')
|
|
127
|
+
? (
|
|
128
|
+
await glob(
|
|
129
|
+
file
|
|
130
|
+
.replace(/[/]build[/][^/]+[/]/, '/*/')
|
|
131
|
+
.replace(/(\.d\.ts|\.[\w]+)$/, '.*'),
|
|
132
|
+
{
|
|
133
|
+
cwd: root,
|
|
134
|
+
absolute: true,
|
|
135
|
+
ignore: [path.resolve(root, file)],
|
|
136
|
+
},
|
|
137
|
+
)
|
|
138
|
+
)[0]!
|
|
139
|
+
: path.resolve(root, file);
|
|
140
|
+
|
|
141
|
+
return sourceFile;
|
|
142
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import {fileURLToPath} from 'url';
|
|
3
|
+
import {readFile} from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
export interface PackageJSON {
|
|
6
|
+
name?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function loadPackageJSON(root: string | URL) {
|
|
11
|
+
const file = await readFile(
|
|
12
|
+
path.join(
|
|
13
|
+
typeof root === 'string' ? root : fileURLToPath(root),
|
|
14
|
+
'package.json',
|
|
15
|
+
),
|
|
16
|
+
'utf8',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return JSON.parse(file) as PackageJSON;
|
|
20
|
+
}
|