@quilted/rollup 0.1.14 → 0.1.16
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 +19 -0
- package/build/cjs/app.cjs +21 -47
- package/build/cjs/features/assets.cjs +112 -2
- package/build/cjs/features/source-code.cjs +3 -2
- package/build/cjs/features/system-js.cjs +2 -1
- package/build/cjs/index.cjs +2 -0
- package/build/cjs/module.cjs +155 -0
- package/build/cjs/package.cjs +20 -2
- package/build/cjs/shared/browserslist.cjs +25 -0
- package/build/esm/app.mjs +21 -47
- package/build/esm/features/assets.mjs +112 -4
- package/build/esm/features/source-code.mjs +1 -1
- package/build/esm/index.mjs +1 -0
- package/build/esm/module.mjs +134 -0
- package/build/esm/package.mjs +20 -2
- package/build/esm/shared/browserslist.mjs +23 -0
- package/build/esnext/app.esnext +21 -47
- package/build/esnext/features/assets.esnext +112 -4
- package/build/esnext/features/source-code.esnext +1 -1
- package/build/esnext/index.esnext +1 -0
- package/build/esnext/module.esnext +134 -0
- package/build/esnext/package.esnext +20 -2
- package/build/esnext/shared/browserslist.esnext +23 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +4 -6
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/assets.d.ts +10 -2
- package/build/typescript/features/assets.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/module.d.ts +45 -0
- package/build/typescript/module.d.ts.map +1 -0
- package/build/typescript/package.d.ts +8 -2
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/shared/browserslist.d.ts +11 -0
- package/build/typescript/shared/browserslist.d.ts.map +1 -0
- package/package.json +18 -5
- package/source/app.ts +21 -53
- package/source/features/assets.ts +152 -4
- package/source/features/source-code.ts +1 -1
- package/source/index.ts +1 -0
- package/source/module.ts +223 -0
- package/source/package.ts +19 -0
- package/source/shared/browserslist.ts +32 -0
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
import { getBrowserTargetDetails } from './shared/browserslist.esnext';
|
|
7
|
+
|
|
8
|
+
async function quiltModule({
|
|
9
|
+
root: rootPath = process.cwd(),
|
|
10
|
+
env,
|
|
11
|
+
assets,
|
|
12
|
+
graphql = true
|
|
13
|
+
} = {}) {
|
|
14
|
+
const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
15
|
+
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
16
|
+
const outputDirectory = path.join(root, 'build/assets');
|
|
17
|
+
const minify = assets?.minify ?? true;
|
|
18
|
+
const hash = assets?.hash ?? true;
|
|
19
|
+
const hashFilenamePart = hash ? '.[hash]' : '';
|
|
20
|
+
const browserTarget = await getBrowserTargetDetails(assets?.targets, {
|
|
21
|
+
root
|
|
22
|
+
});
|
|
23
|
+
const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
|
|
24
|
+
const [{
|
|
25
|
+
visualizer
|
|
26
|
+
}, {
|
|
27
|
+
magicModuleEnv,
|
|
28
|
+
replaceProcessEnv
|
|
29
|
+
}, {
|
|
30
|
+
sourceCode
|
|
31
|
+
}, nodePlugins, packageJSON] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/env.esnext'), import('./features/source-code.esnext'), getNodePlugins(), loadPackageJSON(root)]);
|
|
32
|
+
const source = await sourceForPackage(root, packageJSON);
|
|
33
|
+
const plugins = [...nodePlugins, replaceProcessEnv({
|
|
34
|
+
mode
|
|
35
|
+
}), magicModuleEnv({
|
|
36
|
+
...env,
|
|
37
|
+
mode
|
|
38
|
+
}), sourceCode({
|
|
39
|
+
mode: 'production'
|
|
40
|
+
}), removeBuildFiles(['build/assets', 'build/reports'], {
|
|
41
|
+
root
|
|
42
|
+
})];
|
|
43
|
+
if (graphql) {
|
|
44
|
+
const {
|
|
45
|
+
graphql
|
|
46
|
+
} = await import('./features/graphql.esnext');
|
|
47
|
+
plugins.push(graphql({
|
|
48
|
+
manifest: false
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
if (minify) {
|
|
52
|
+
const {
|
|
53
|
+
minify
|
|
54
|
+
} = await import('rollup-plugin-esbuild');
|
|
55
|
+
plugins.push(minify());
|
|
56
|
+
}
|
|
57
|
+
plugins.push(visualizer({
|
|
58
|
+
template: 'treemap',
|
|
59
|
+
open: false,
|
|
60
|
+
brotliSize: true,
|
|
61
|
+
filename: path.resolve(root, `build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
62
|
+
}));
|
|
63
|
+
return {
|
|
64
|
+
input: source.files,
|
|
65
|
+
plugins,
|
|
66
|
+
onwarn(warning, defaultWarn) {
|
|
67
|
+
// Removes annoying warnings for React-focused libraries that
|
|
68
|
+
// include 'use client' directives.
|
|
69
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
defaultWarn(warning);
|
|
73
|
+
},
|
|
74
|
+
output: {
|
|
75
|
+
format: 'esm',
|
|
76
|
+
dir: outputDirectory,
|
|
77
|
+
entryFileNames: `[name]${targetFilenamePart}${hashFilenamePart}.js`,
|
|
78
|
+
assetFileNames: `[name]${targetFilenamePart}${hashFilenamePart}.[ext]`
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async function sourceForPackage(root, packageJSON) {
|
|
83
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
84
|
+
let sourceRoot = root;
|
|
85
|
+
const sourceEntryFiles = Object.values(entries);
|
|
86
|
+
for (const entry of sourceEntryFiles) {
|
|
87
|
+
if (!entry.startsWith(root)) continue;
|
|
88
|
+
sourceRoot = path.resolve(root, path.relative(root, entry).split(path.sep)[0] ?? '.');
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
root: sourceRoot,
|
|
93
|
+
files: sourceEntryFiles
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
97
|
+
const {
|
|
98
|
+
main,
|
|
99
|
+
exports
|
|
100
|
+
} = packageJSON;
|
|
101
|
+
const entries = {};
|
|
102
|
+
if (typeof main === 'string') {
|
|
103
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
104
|
+
}
|
|
105
|
+
if (typeof exports === 'string') {
|
|
106
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
107
|
+
return entries;
|
|
108
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
109
|
+
return entries;
|
|
110
|
+
}
|
|
111
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
112
|
+
let targetFile = null;
|
|
113
|
+
if (exportCondition == null) continue;
|
|
114
|
+
if (typeof exportCondition === 'string') {
|
|
115
|
+
targetFile = exportCondition;
|
|
116
|
+
} else {
|
|
117
|
+
targetFile ??= exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/'));
|
|
118
|
+
}
|
|
119
|
+
if (targetFile == null) continue;
|
|
120
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
121
|
+
entries[exportPath] = sourceFile;
|
|
122
|
+
}
|
|
123
|
+
return entries;
|
|
124
|
+
}
|
|
125
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
126
|
+
const sourceFile = file.includes('/build/') ? (await glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
127
|
+
cwd: root,
|
|
128
|
+
absolute: true,
|
|
129
|
+
ignore: [path.resolve(root, file)]
|
|
130
|
+
}))[0] : path.resolve(root, file);
|
|
131
|
+
return sourceFile;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { quiltModule };
|
|
@@ -5,7 +5,8 @@ import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
|
5
5
|
import { loadPackageJSON } from './shared/package-json.esnext';
|
|
6
6
|
|
|
7
7
|
async function quiltPackageESModules({
|
|
8
|
-
root: rootPath = process.cwd()
|
|
8
|
+
root: rootPath = process.cwd(),
|
|
9
|
+
graphql = true
|
|
9
10
|
} = {}) {
|
|
10
11
|
const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
11
12
|
const outputDirectory = path.join(root, 'build/esm');
|
|
@@ -18,6 +19,14 @@ async function quiltPackageESModules({
|
|
|
18
19
|
}), removeBuildFiles(['build/esm'], {
|
|
19
20
|
root
|
|
20
21
|
})];
|
|
22
|
+
if (graphql) {
|
|
23
|
+
const {
|
|
24
|
+
graphql
|
|
25
|
+
} = await import('./features/graphql.esnext');
|
|
26
|
+
plugins.push(graphql({
|
|
27
|
+
manifest: false
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
21
30
|
return {
|
|
22
31
|
input: source.files,
|
|
23
32
|
plugins,
|
|
@@ -40,7 +49,8 @@ async function quiltPackageESModules({
|
|
|
40
49
|
};
|
|
41
50
|
}
|
|
42
51
|
async function quiltPackageESNext({
|
|
43
|
-
root: rootPath = process.cwd()
|
|
52
|
+
root: rootPath = process.cwd(),
|
|
53
|
+
graphql = true
|
|
44
54
|
} = {}) {
|
|
45
55
|
const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
46
56
|
const outputDirectory = path.join(root, 'build/esnext');
|
|
@@ -54,6 +64,14 @@ async function quiltPackageESNext({
|
|
|
54
64
|
}), removeBuildFiles(['build/esnext'], {
|
|
55
65
|
root
|
|
56
66
|
})];
|
|
67
|
+
if (graphql) {
|
|
68
|
+
const {
|
|
69
|
+
graphql
|
|
70
|
+
} = await import('./features/graphql.esnext');
|
|
71
|
+
plugins.push(graphql({
|
|
72
|
+
manifest: false
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
57
75
|
return {
|
|
58
76
|
input: source.files,
|
|
59
77
|
plugins,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
async function getBrowserTargetDetails(targetSelection = {}, {
|
|
2
|
+
root
|
|
3
|
+
} = {}) {
|
|
4
|
+
const targets = Array.isArray(targetSelection) ? {
|
|
5
|
+
browsers: targetSelection
|
|
6
|
+
} : targetSelection;
|
|
7
|
+
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
8
|
+
const {
|
|
9
|
+
default: browserslist
|
|
10
|
+
} = await import('browserslist');
|
|
11
|
+
const config = browserslist.findConfig(root);
|
|
12
|
+
if (config == null) return ['defaults'];
|
|
13
|
+
const targetName = targets.name ?? 'defaults';
|
|
14
|
+
return config[targetName] ?? ['defaults'];
|
|
15
|
+
})());
|
|
16
|
+
const name = targets.name === 'defaults' ? 'default' : targets.name;
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
browsers: targetBrowsers
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getBrowserTargetDetails };
|