@quilted/rollup 0.1.15 → 0.1.17

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.
@@ -0,0 +1,99 @@
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 ?? 'async-only';
19
+ const browserTarget = await getBrowserTargetDetails(assets?.targets, {
20
+ root
21
+ });
22
+ const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
23
+ const [{
24
+ visualizer
25
+ }, {
26
+ magicModuleEnv,
27
+ replaceProcessEnv
28
+ }, {
29
+ sourceCode
30
+ }, nodePlugins, packageJSON] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/env.esnext'), import('./features/source-code.esnext'), getNodePlugins(), loadPackageJSON(root)]);
31
+ const source = await sourceForModule(root, packageJSON);
32
+ const plugins = [...nodePlugins, replaceProcessEnv({
33
+ mode
34
+ }), magicModuleEnv({
35
+ ...env,
36
+ mode
37
+ }), sourceCode({
38
+ mode: 'production'
39
+ }), removeBuildFiles(['build/assets', 'build/reports'], {
40
+ root
41
+ })];
42
+ if (graphql) {
43
+ const {
44
+ graphql
45
+ } = await import('./features/graphql.esnext');
46
+ plugins.push(graphql({
47
+ manifest: false
48
+ }));
49
+ }
50
+ if (minify) {
51
+ const {
52
+ minify
53
+ } = await import('rollup-plugin-esbuild');
54
+ plugins.push(minify());
55
+ }
56
+ plugins.push(visualizer({
57
+ template: 'treemap',
58
+ open: false,
59
+ brotliSize: true,
60
+ filename: path.resolve(root, `build/reports/bundle-visualizer${targetFilenamePart}.html`)
61
+ }));
62
+ return {
63
+ input: source,
64
+ plugins,
65
+ onwarn(warning, defaultWarn) {
66
+ // Removes annoying warnings for React-focused libraries that
67
+ // include 'use client' directives.
68
+ if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
69
+ return;
70
+ }
71
+ defaultWarn(warning);
72
+ },
73
+ output: {
74
+ format: 'esm',
75
+ dir: outputDirectory,
76
+ entryFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ''}.js`,
77
+ chunkFileNames: `[name]${targetFilenamePart}${hash === true || hash === 'async-only' ? `.[hash]` : ''}.js`,
78
+ assetFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ''}.[ext]`
79
+ }
80
+ };
81
+ }
82
+ async function sourceForModule(root, packageJSON) {
83
+ const {
84
+ main,
85
+ exports
86
+ } = packageJSON;
87
+ const entryFromPackageJSON = main ?? exports?.['.'];
88
+ if (entryFromPackageJSON) {
89
+ return path.resolve(root, entryFromPackageJSON);
90
+ }
91
+ const possibleSourceFiles = await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
92
+ cwd: root,
93
+ nodir: true,
94
+ absolute: true
95
+ });
96
+ return possibleSourceFiles[0];
97
+ }
98
+
99
+ export { quiltModule };
@@ -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 };