@quilted/rollup 0.1.9 → 0.1.11
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 +16 -0
- package/build/cjs/app.cjs +43 -13
- package/build/cjs/index.cjs +2 -0
- package/build/cjs/package.cjs +112 -0
- package/build/cjs/shared/package-json.cjs +31 -0
- package/build/cjs/shared/rollup.cjs +39 -0
- package/build/esm/app.mjs +44 -14
- package/build/esm/index.mjs +1 -0
- package/build/esm/package.mjs +91 -0
- package/build/esm/shared/package-json.mjs +10 -0
- package/build/esm/shared/rollup.mjs +20 -1
- package/build/esnext/app.esnext +44 -14
- package/build/esnext/index.esnext +1 -0
- package/build/esnext/package.esnext +91 -0
- package/build/esnext/shared/package-json.esnext +10 -0
- package/build/esnext/shared/rollup.esnext +20 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +10 -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/build/typescript/shared/rollup.d.ts +9 -3
- package/build/typescript/shared/rollup.d.ts.map +1 -1
- package/package.json +2 -1
- package/source/app.ts +69 -14
- package/source/index.ts +1 -0
- package/source/package.ts +143 -0
- package/source/shared/package-json.ts +17 -0
- package/source/shared/rollup.ts +23 -1
package/build/esnext/app.esnext
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import { glob } from 'glob';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.esnext';
|
|
5
6
|
import { multiline } from './shared/strings.esnext';
|
|
6
|
-
import { getNodePlugins } from './shared/rollup.esnext';
|
|
7
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
7
8
|
import { createMagicModulePlugin } from './shared/magic-module.esnext';
|
|
8
9
|
|
|
9
10
|
async function quiltAppBrowser({
|
|
11
|
+
root: rootPath = process.cwd(),
|
|
10
12
|
app,
|
|
11
13
|
entry,
|
|
12
14
|
env,
|
|
@@ -14,10 +16,25 @@ async function quiltAppBrowser({
|
|
|
14
16
|
module,
|
|
15
17
|
graphql = true
|
|
16
18
|
} = {}) {
|
|
17
|
-
const root =
|
|
19
|
+
const root = fileURLToPath(rootPath);
|
|
18
20
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
19
21
|
const minify = assets?.minify ?? mode === 'production';
|
|
20
22
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
23
|
+
const assetTargets = assets?.targets ?? {};
|
|
24
|
+
const targets = Array.isArray(assetTargets) ? {
|
|
25
|
+
browsers: assetTargets
|
|
26
|
+
} : assetTargets;
|
|
27
|
+
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
28
|
+
const {
|
|
29
|
+
default: browserslist
|
|
30
|
+
} = await import('browserslist');
|
|
31
|
+
const config = browserslist.findConfig(root);
|
|
32
|
+
if (config == null) return ['defaults'];
|
|
33
|
+
const targetName = targets.name ?? 'defaults';
|
|
34
|
+
return config[targetName] ?? ['defaults'];
|
|
35
|
+
})());
|
|
36
|
+
const normalizedTargetName = targets.name === 'defaults' ? 'default' : targets.name;
|
|
37
|
+
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
21
38
|
const [{
|
|
22
39
|
visualizer
|
|
23
40
|
}, {
|
|
@@ -37,13 +54,16 @@ async function quiltAppBrowser({
|
|
|
37
54
|
const plugins = [...nodePlugins, systemJS({
|
|
38
55
|
minify
|
|
39
56
|
}), sourceCode({
|
|
40
|
-
mode
|
|
57
|
+
mode,
|
|
58
|
+
targets: targetBrowsers
|
|
41
59
|
}), css({
|
|
42
60
|
minify,
|
|
43
61
|
emit: true
|
|
44
62
|
}), rawAssets(), staticAssets({
|
|
45
63
|
baseURL,
|
|
46
64
|
emit: true
|
|
65
|
+
}), removeBuildFiles(['build/assets', 'build/manifests', 'build/reports'], {
|
|
66
|
+
root
|
|
47
67
|
})];
|
|
48
68
|
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
49
69
|
if (tsconfigAliases) {
|
|
@@ -86,7 +106,7 @@ async function quiltAppBrowser({
|
|
|
86
106
|
graphql
|
|
87
107
|
} = await import('./features/graphql.esnext');
|
|
88
108
|
plugins.push(graphql({
|
|
89
|
-
manifest: path.resolve(`manifests/graphql.json`)
|
|
109
|
+
manifest: path.resolve(`manifests/graphql${targetFilenamePart}.json`)
|
|
90
110
|
}));
|
|
91
111
|
}
|
|
92
112
|
if (minify) {
|
|
@@ -95,18 +115,25 @@ async function quiltAppBrowser({
|
|
|
95
115
|
} = await import('rollup-plugin-esbuild');
|
|
96
116
|
plugins.push(minify());
|
|
97
117
|
}
|
|
118
|
+
const cacheKey = targets.name ? {
|
|
119
|
+
browserTarget: targets.name
|
|
120
|
+
} : undefined;
|
|
121
|
+
const id = targets.name ? targets.name : undefined;
|
|
98
122
|
plugins.push(
|
|
99
123
|
// @ts-expect-error The plugin still depends on Rollup 3
|
|
100
124
|
assetManifest({
|
|
125
|
+
id,
|
|
126
|
+
cacheKey,
|
|
101
127
|
baseUrl: baseURL,
|
|
102
|
-
path: path.resolve(`build/manifests/assets.json`)
|
|
128
|
+
path: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
129
|
+
priority: assets?.priority
|
|
103
130
|
}), visualizer({
|
|
104
131
|
template: 'treemap',
|
|
105
132
|
open: false,
|
|
106
133
|
brotliSize: true,
|
|
107
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
134
|
+
filename: path.resolve(`build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
108
135
|
}));
|
|
109
|
-
const finalEntry = entry ?? (await glob('browser.{ts,tsx,mjs,js,jsx}', {
|
|
136
|
+
const finalEntry = entry ?? (await glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
|
|
110
137
|
cwd: root,
|
|
111
138
|
nodir: true,
|
|
112
139
|
absolute: true
|
|
@@ -126,9 +153,9 @@ async function quiltAppBrowser({
|
|
|
126
153
|
// format: isESM ? 'esm' : 'systemjs',
|
|
127
154
|
format: 'esm',
|
|
128
155
|
dir: path.resolve(`build/assets`),
|
|
129
|
-
entryFileNames: `app.[hash].js`,
|
|
130
|
-
assetFileNames: `[name].[hash].[ext]`,
|
|
131
|
-
chunkFileNames: `[name].[hash].js`,
|
|
156
|
+
entryFileNames: `app${targetFilenamePart}.[hash].js`,
|
|
157
|
+
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
158
|
+
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
132
159
|
manualChunks: createManualChunksSorter()
|
|
133
160
|
}
|
|
134
161
|
};
|
|
@@ -157,12 +184,15 @@ async function quiltAppServer({
|
|
|
157
184
|
magicModuleRequestRouterEntry
|
|
158
185
|
}, 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()]);
|
|
159
186
|
const plugins = [...nodePlugins, sourceCode({
|
|
160
|
-
mode
|
|
187
|
+
mode,
|
|
188
|
+
targets: ['current node']
|
|
161
189
|
}), css({
|
|
162
190
|
emit: false,
|
|
163
191
|
minify
|
|
164
192
|
}), rawAssets(), staticAssets({
|
|
165
193
|
emit: false
|
|
194
|
+
}), removeBuildFiles(['build/server'], {
|
|
195
|
+
root
|
|
166
196
|
})];
|
|
167
197
|
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
168
198
|
if (tsconfigAliases) {
|
|
@@ -221,10 +251,10 @@ async function quiltAppServer({
|
|
|
221
251
|
plugins.push(visualizer({
|
|
222
252
|
template: 'treemap',
|
|
223
253
|
open: false,
|
|
224
|
-
brotliSize:
|
|
225
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
254
|
+
brotliSize: false,
|
|
255
|
+
filename: path.resolve(`build/reports/bundle-visualizer.server.html`)
|
|
226
256
|
}));
|
|
227
|
-
const finalEntry = entry ?? (await glob('server.{ts,tsx,mjs,js,jsx}', {
|
|
257
|
+
const finalEntry = entry ?? (await glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
|
|
228
258
|
cwd: root,
|
|
229
259
|
nodir: true,
|
|
230
260
|
absolute: true
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { glob } from 'glob';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
5
|
+
import { loadPackageJSON } from './shared/package-json.esnext';
|
|
6
|
+
|
|
7
|
+
async function quiltPackageESModules({
|
|
8
|
+
root: rootPath = process.cwd()
|
|
9
|
+
} = {}) {
|
|
10
|
+
const root = fileURLToPath(rootPath);
|
|
11
|
+
const outputDirectory = path.join(root, 'build/esm');
|
|
12
|
+
const [{
|
|
13
|
+
sourceCode
|
|
14
|
+
}, nodePlugins, packageJSON] = await Promise.all([import('./features/source-code.esnext'), getNodePlugins(), loadPackageJSON(root)]);
|
|
15
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
16
|
+
let sourceRoot = root;
|
|
17
|
+
for (const entry of Object.values(entries)) {
|
|
18
|
+
if (!entry.startsWith(root)) continue;
|
|
19
|
+
sourceRoot = path.resolve(root, path.relative(root, entry).split(path.sep)[0] ?? '.');
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
const plugins = [...nodePlugins, sourceCode({
|
|
23
|
+
mode: 'production'
|
|
24
|
+
}), removeBuildFiles(['build/esm'], {
|
|
25
|
+
root
|
|
26
|
+
})];
|
|
27
|
+
return {
|
|
28
|
+
input: entries,
|
|
29
|
+
plugins,
|
|
30
|
+
onwarn(warning, defaultWarn) {
|
|
31
|
+
// Removes annoying warnings for React-focused libraries that
|
|
32
|
+
// include 'use client' directives.
|
|
33
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
defaultWarn(warning);
|
|
37
|
+
},
|
|
38
|
+
output: {
|
|
39
|
+
preserveModules: true,
|
|
40
|
+
preserveModulesRoot: sourceRoot,
|
|
41
|
+
format: 'esm',
|
|
42
|
+
dir: outputDirectory,
|
|
43
|
+
entryFileNames: `[name].mjs`,
|
|
44
|
+
assetFileNames: `[name].[ext]`
|
|
45
|
+
// chunkFileNames: createChunkNamer({
|
|
46
|
+
// extension: ESM_EXTENSION,
|
|
47
|
+
// sourceRoot: sourceRootDirectory,
|
|
48
|
+
// }),
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
54
|
+
const {
|
|
55
|
+
main,
|
|
56
|
+
exports
|
|
57
|
+
} = packageJSON;
|
|
58
|
+
const entries = {};
|
|
59
|
+
if (typeof main === 'string') {
|
|
60
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
61
|
+
}
|
|
62
|
+
if (typeof exports === 'string') {
|
|
63
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
64
|
+
return entries;
|
|
65
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
66
|
+
return entries;
|
|
67
|
+
}
|
|
68
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
69
|
+
let targetFile = null;
|
|
70
|
+
if (exportCondition == null) continue;
|
|
71
|
+
if (typeof exportCondition === 'string') {
|
|
72
|
+
targetFile = exportCondition;
|
|
73
|
+
} else {
|
|
74
|
+
targetFile ??= exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/'));
|
|
75
|
+
}
|
|
76
|
+
if (targetFile == null) continue;
|
|
77
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
78
|
+
entries[exportPath] = sourceFile;
|
|
79
|
+
}
|
|
80
|
+
return entries;
|
|
81
|
+
}
|
|
82
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
83
|
+
const sourceFile = file.includes('/build/') ? (await glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
84
|
+
cwd: root,
|
|
85
|
+
absolute: true,
|
|
86
|
+
ignore: [path.resolve(root, file)]
|
|
87
|
+
}))[0] : path.resolve(root, file);
|
|
88
|
+
return sourceFile;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { quiltPackageESModules };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
async function loadPackageJSON(root) {
|
|
6
|
+
const file = await readFile(path.join(fileURLToPath(root), 'package.json'), 'utf8');
|
|
7
|
+
return JSON.parse(file);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { loadPackageJSON };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import { glob } from 'glob';
|
|
1
3
|
import replace from '@rollup/plugin-replace';
|
|
2
4
|
|
|
3
5
|
function smartReplace(values, options) {
|
|
@@ -9,6 +11,23 @@ function smartReplace(values, options) {
|
|
|
9
11
|
values
|
|
10
12
|
});
|
|
11
13
|
}
|
|
14
|
+
function removeBuildFiles(patterns, {
|
|
15
|
+
root = process.cwd()
|
|
16
|
+
} = {}) {
|
|
17
|
+
return {
|
|
18
|
+
name: '@quilt/remove-build-files',
|
|
19
|
+
async buildStart() {
|
|
20
|
+
const matches = await glob(patterns, {
|
|
21
|
+
cwd: root,
|
|
22
|
+
absolute: true
|
|
23
|
+
});
|
|
24
|
+
await Promise.all(matches.map(file => fs.rm(file, {
|
|
25
|
+
recursive: true,
|
|
26
|
+
force: true
|
|
27
|
+
})));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
12
31
|
async function getNodePlugins() {
|
|
13
32
|
const [{
|
|
14
33
|
default: commonjs
|
|
@@ -27,4 +46,4 @@ async function getNodePlugins() {
|
|
|
27
46
|
}), commonjs(), json()];
|
|
28
47
|
}
|
|
29
48
|
|
|
30
|
-
export { getNodePlugins, smartReplace };
|
|
49
|
+
export { getNodePlugins, removeBuildFiles, smartReplace };
|