@quilted/rollup 0.2.31 → 0.2.33
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 +12 -0
- package/build/esm/app.mjs +211 -16
- package/build/esm/shared/project.mjs +22 -4
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +170 -79
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/react.d.ts +18 -18
- package/build/typescript/module.d.ts +1 -1
- package/build/typescript/package.d.ts +36 -36
- package/build/typescript/server.d.ts +41 -41
- package/build/typescript/shared/project.d.ts.map +1 -1
- package/package.json +1 -1
- package/source/app.ts +313 -17
- package/source/shared/project.ts +24 -4
- package/tsconfig.json +1 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @quilted/rollup
|
|
2
2
|
|
|
3
|
+
## 0.2.33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5ba0530`](https://github.com/lemonmade/quilt/commit/5ba053056ed3b8a0f012fbce74e86227468b60df) Thanks [@lemonmade](https://github.com/lemonmade)! - Add basic service worker plugin
|
|
8
|
+
|
|
9
|
+
## 0.2.32
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`a1f03cc`](https://github.com/lemonmade/quilt/commit/a1f03ccea00a39d8300108f9f6728db3d5ddc9ff) Thanks [@lemonmade](https://github.com/lemonmade)! - Only include JavaScript source entries in Rollup plugin
|
|
14
|
+
|
|
3
15
|
## 0.2.31
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/build/esm/app.mjs
CHANGED
|
@@ -17,7 +17,8 @@ async function quiltApp({
|
|
|
17
17
|
graphql,
|
|
18
18
|
assets,
|
|
19
19
|
browser: browserOptions,
|
|
20
|
-
server: serverOptions,
|
|
20
|
+
server: serverOptions = true,
|
|
21
|
+
serviceWorker: serviceWorkerOptions = false,
|
|
21
22
|
runtime
|
|
22
23
|
} = {}) {
|
|
23
24
|
const project = Project.load(root);
|
|
@@ -49,20 +50,39 @@ async function quiltApp({
|
|
|
49
50
|
})
|
|
50
51
|
);
|
|
51
52
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
...
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
if (serverOptions) {
|
|
54
|
+
const serverOptionsObject = typeof serverOptions === "object" ? serverOptions : {};
|
|
55
|
+
optionPromises.push(
|
|
56
|
+
quiltAppServer({
|
|
57
|
+
root: project.root,
|
|
58
|
+
app,
|
|
59
|
+
graphql,
|
|
60
|
+
runtime: runtime?.server,
|
|
61
|
+
...serverOptionsObject,
|
|
62
|
+
env: {
|
|
63
|
+
...resolveEnvOption(env),
|
|
64
|
+
...resolveEnvOption(serverOptionsObject?.env)
|
|
65
|
+
},
|
|
66
|
+
assets: { ...assets, ...serverOptionsObject?.assets }
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (serviceWorkerOptions) {
|
|
71
|
+
const serviceWorkerOptionsObject = typeof serviceWorkerOptions === "object" ? serviceWorkerOptions : {};
|
|
72
|
+
optionPromises.push(
|
|
73
|
+
quiltAppServiceWorker({
|
|
74
|
+
root: project.root,
|
|
75
|
+
app,
|
|
76
|
+
graphql,
|
|
77
|
+
...serviceWorkerOptionsObject,
|
|
78
|
+
env: {
|
|
79
|
+
...resolveEnvOption(env),
|
|
80
|
+
...resolveEnvOption(serviceWorkerOptionsObject?.env)
|
|
81
|
+
},
|
|
82
|
+
assets: { ...assets, ...serviceWorkerOptionsObject?.assets }
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
}
|
|
66
86
|
return Promise.all(optionPromises);
|
|
67
87
|
}
|
|
68
88
|
async function quiltAppBrowser(options = {}) {
|
|
@@ -438,6 +458,163 @@ function quiltAppServerInput({
|
|
|
438
458
|
}
|
|
439
459
|
};
|
|
440
460
|
}
|
|
461
|
+
async function quiltAppServiceWorker(options = {}) {
|
|
462
|
+
const { output, root = process.cwd() } = options;
|
|
463
|
+
const project = Project.load(root);
|
|
464
|
+
const hash = output?.hash ?? "async-only";
|
|
465
|
+
const plugins = await quiltAppServiceWorkerPlugins({
|
|
466
|
+
...options,
|
|
467
|
+
root
|
|
468
|
+
});
|
|
469
|
+
return {
|
|
470
|
+
plugins,
|
|
471
|
+
output: {
|
|
472
|
+
format: "iife",
|
|
473
|
+
dir: project.resolve(`build/service-worker`),
|
|
474
|
+
entryFileNames: `[name]${hash === true ? `.[hash]` : ""}.js`,
|
|
475
|
+
chunkFileNames: `[name]${hash === true || hash === "async-only" ? `.[hash]` : ""}.js`,
|
|
476
|
+
assetFileNames: `[name]${hash === true ? `.[hash]` : ""}.[ext]`,
|
|
477
|
+
generatedCode: "es2015"
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
async function quiltAppServiceWorkerPlugins({
|
|
482
|
+
root = process.cwd(),
|
|
483
|
+
app,
|
|
484
|
+
env,
|
|
485
|
+
entry,
|
|
486
|
+
graphql = true,
|
|
487
|
+
assets,
|
|
488
|
+
output
|
|
489
|
+
} = {}) {
|
|
490
|
+
const project = Project.load(root);
|
|
491
|
+
const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
|
|
492
|
+
const baseURL = assets?.baseURL ?? "/assets/";
|
|
493
|
+
const assetsInline = assets?.inline ?? true;
|
|
494
|
+
const outputDirectory = project.resolve("build/service-worker");
|
|
495
|
+
const reportsDirectory = path.resolve(outputDirectory, "../reports");
|
|
496
|
+
const bundle = output?.bundle;
|
|
497
|
+
const minify = output?.minify ?? false;
|
|
498
|
+
const [
|
|
499
|
+
{ visualizer },
|
|
500
|
+
{ magicModuleEnv, replaceProcessEnv },
|
|
501
|
+
{ sourceCode },
|
|
502
|
+
{ react },
|
|
503
|
+
{ tsconfigAliases },
|
|
504
|
+
{ monorepoPackageAliases },
|
|
505
|
+
{ css },
|
|
506
|
+
{ rawAssets, staticAssets },
|
|
507
|
+
{ asyncModules },
|
|
508
|
+
{ esnext },
|
|
509
|
+
nodePlugins
|
|
510
|
+
] = await Promise.all([
|
|
511
|
+
import('rollup-plugin-visualizer'),
|
|
512
|
+
import('./features/env.mjs'),
|
|
513
|
+
import('./features/source-code.mjs'),
|
|
514
|
+
import('./features/react.mjs'),
|
|
515
|
+
import('./features/typescript.mjs'),
|
|
516
|
+
import('./features/node.mjs'),
|
|
517
|
+
import('./features/css.mjs'),
|
|
518
|
+
import('./features/assets.mjs'),
|
|
519
|
+
import('./features/async.mjs'),
|
|
520
|
+
import('./features/esnext.mjs'),
|
|
521
|
+
getNodePlugins({
|
|
522
|
+
bundle,
|
|
523
|
+
resolve: { exportConditions: ["browser"] }
|
|
524
|
+
})
|
|
525
|
+
]);
|
|
526
|
+
const plugins = [
|
|
527
|
+
quiltAppServiceWorkerInput({ root: project.root, entry }),
|
|
528
|
+
...nodePlugins,
|
|
529
|
+
replaceProcessEnv({ mode }),
|
|
530
|
+
magicModuleEnv({
|
|
531
|
+
...resolveEnvOption(env),
|
|
532
|
+
mode,
|
|
533
|
+
root: project.root
|
|
534
|
+
}),
|
|
535
|
+
magicModuleAppComponent({ entry: app, root: project.root }),
|
|
536
|
+
magicModuleAppAssetManifests(),
|
|
537
|
+
sourceCode({
|
|
538
|
+
mode,
|
|
539
|
+
// TODO
|
|
540
|
+
targets: ["defaults and not dead"],
|
|
541
|
+
babel: {
|
|
542
|
+
options(options) {
|
|
543
|
+
return {
|
|
544
|
+
...options,
|
|
545
|
+
plugins: [
|
|
546
|
+
...options?.plugins ?? [],
|
|
547
|
+
require.resolve("@quilted/babel/async"),
|
|
548
|
+
[require.resolve("@quilted/babel/workers"), { noop: true }]
|
|
549
|
+
]
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}),
|
|
554
|
+
react(),
|
|
555
|
+
esnext({
|
|
556
|
+
mode,
|
|
557
|
+
// TODO
|
|
558
|
+
targets: ["defaults and not dead"]
|
|
559
|
+
}),
|
|
560
|
+
css({ emit: false, minify }),
|
|
561
|
+
rawAssets(),
|
|
562
|
+
staticAssets({
|
|
563
|
+
emit: false,
|
|
564
|
+
baseURL,
|
|
565
|
+
inlineLimit: assetsInline ? typeof assetsInline === "boolean" ? void 0 : assetsInline?.limit : Number.POSITIVE_INFINITY
|
|
566
|
+
}),
|
|
567
|
+
asyncModules({
|
|
568
|
+
baseURL,
|
|
569
|
+
preload: false,
|
|
570
|
+
moduleID: ({ imported }) => path.relative(project.root, imported)
|
|
571
|
+
}),
|
|
572
|
+
removeBuildFiles([outputDirectory], { root: project.root }),
|
|
573
|
+
tsconfigAliases({ root: project.root }),
|
|
574
|
+
monorepoPackageAliases({ root: project.root })
|
|
575
|
+
];
|
|
576
|
+
if (graphql) {
|
|
577
|
+
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
578
|
+
plugins.push(graphql2({ manifest: false }));
|
|
579
|
+
}
|
|
580
|
+
if (minify) {
|
|
581
|
+
const { minify: minify2 } = await import('rollup-plugin-esbuild');
|
|
582
|
+
plugins.push(minify2());
|
|
583
|
+
}
|
|
584
|
+
plugins.push(
|
|
585
|
+
visualizer({
|
|
586
|
+
template: "treemap",
|
|
587
|
+
open: false,
|
|
588
|
+
brotliSize: false,
|
|
589
|
+
filename: path.join(
|
|
590
|
+
reportsDirectory,
|
|
591
|
+
`bundle-visualizer.service-worker.html`
|
|
592
|
+
)
|
|
593
|
+
})
|
|
594
|
+
);
|
|
595
|
+
return plugins;
|
|
596
|
+
}
|
|
597
|
+
function quiltAppServiceWorkerInput({
|
|
598
|
+
root = process.cwd(),
|
|
599
|
+
entry
|
|
600
|
+
} = {}) {
|
|
601
|
+
return {
|
|
602
|
+
name: "@quilted/app-server/input",
|
|
603
|
+
async options(options) {
|
|
604
|
+
const serviceWorkerEntry = normalizeRollupInput(options.input) ?? await sourceEntryForAppServiceWorker({ entry, root });
|
|
605
|
+
if (serviceWorkerEntry == null) {
|
|
606
|
+
throw new Error(
|
|
607
|
+
`No service worker entry found. Please provide a \`service.entry\` option pointing to your service worker\u2019s source code.`
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
const finalEntryName = typeof serviceWorkerEntry === "string" ? path.basename(serviceWorkerEntry).split(".").slice(0, -1).join(".") : "service-worker";
|
|
611
|
+
return {
|
|
612
|
+
...options,
|
|
613
|
+
input: typeof serviceWorkerEntry === "string" ? { [finalEntryName]: serviceWorkerEntry } : serviceWorkerEntry
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
}
|
|
441
618
|
function nodeAppServerRuntime({
|
|
442
619
|
host,
|
|
443
620
|
port,
|
|
@@ -690,6 +867,24 @@ async function sourceEntryForAppServer({
|
|
|
690
867
|
return files[0];
|
|
691
868
|
}
|
|
692
869
|
}
|
|
870
|
+
async function sourceEntryForAppServiceWorker({
|
|
871
|
+
entry,
|
|
872
|
+
root = process.cwd()
|
|
873
|
+
}) {
|
|
874
|
+
const project = Project.load(root);
|
|
875
|
+
if (entry) {
|
|
876
|
+
return project.resolve(entry);
|
|
877
|
+
} else {
|
|
878
|
+
const files = await project.glob(
|
|
879
|
+
"{sw,service-worker}.{ts,tsx,mjs,js,jsx}",
|
|
880
|
+
{
|
|
881
|
+
nodir: true,
|
|
882
|
+
absolute: true
|
|
883
|
+
}
|
|
884
|
+
);
|
|
885
|
+
return files[0];
|
|
886
|
+
}
|
|
887
|
+
}
|
|
693
888
|
const FRAMEWORK_CHUNK_NAME = "framework";
|
|
694
889
|
const POLYFILLS_CHUNK_NAME = "polyfills";
|
|
695
890
|
const VENDOR_CHUNK_NAME = "vendor";
|
|
@@ -766,4 +961,4 @@ function createManualChunksSorter() {
|
|
|
766
961
|
};
|
|
767
962
|
}
|
|
768
963
|
|
|
769
|
-
export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, appServerEntry, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, nodeAppServerRuntime, quiltApp, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserPlugins, quiltAppServer, quiltAppServerInput, quiltAppServerPlugins, sourceEntryForAppBrowser, sourceEntryForAppServer };
|
|
964
|
+
export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, appServerEntry, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, nodeAppServerRuntime, quiltApp, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserPlugins, quiltAppServer, quiltAppServerInput, quiltAppServerPlugins, quiltAppServiceWorker, quiltAppServiceWorkerInput, quiltAppServiceWorkerPlugins, sourceEntryForAppBrowser, sourceEntryForAppServer, sourceEntryForAppServiceWorker };
|
|
@@ -61,10 +61,12 @@ async function sourceEntriesForProject(project) {
|
|
|
61
61
|
const { main, exports } = project.packageJSON.raw;
|
|
62
62
|
const entries = {};
|
|
63
63
|
if (typeof main === "string") {
|
|
64
|
-
|
|
64
|
+
const sourceFile = await resolveTargetFileAsSource(main, project);
|
|
65
|
+
if (sourceFile) entries["."] = sourceFile;
|
|
65
66
|
}
|
|
66
67
|
if (typeof exports === "string") {
|
|
67
|
-
|
|
68
|
+
const sourceFile = await resolveTargetFileAsSource(exports, project);
|
|
69
|
+
if (sourceFile) entries["."] = sourceFile;
|
|
68
70
|
return entries;
|
|
69
71
|
} else if (exports == null || typeof exports !== "object") {
|
|
70
72
|
return entries;
|
|
@@ -86,15 +88,28 @@ async function sourceEntriesForProject(project) {
|
|
|
86
88
|
for (const [condition, file] of Object.entries(targetFile)) {
|
|
87
89
|
if (typeof file !== "string") continue;
|
|
88
90
|
const entryName = condition === "default" ? exportPath : `${exportPath}#${condition}`;
|
|
89
|
-
|
|
91
|
+
const sourceFile = await resolveTargetFileAsSource(file, project);
|
|
92
|
+
if (sourceFile) entries[entryName] = sourceFile;
|
|
90
93
|
}
|
|
91
94
|
} else {
|
|
92
95
|
const sourceFile = await resolveTargetFileAsSource(targetFile, project);
|
|
93
|
-
entries[exportPath] = sourceFile;
|
|
96
|
+
if (sourceFile) entries[exportPath] = sourceFile;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
return entries;
|
|
97
100
|
}
|
|
101
|
+
const ALLOWED_SOURCE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
102
|
+
".ts",
|
|
103
|
+
".tsx",
|
|
104
|
+
".mts",
|
|
105
|
+
".cts",
|
|
106
|
+
".js",
|
|
107
|
+
".jsx",
|
|
108
|
+
".mjs",
|
|
109
|
+
".cjs",
|
|
110
|
+
".json",
|
|
111
|
+
".node"
|
|
112
|
+
]);
|
|
98
113
|
async function resolveTargetFileAsSource(file, project) {
|
|
99
114
|
const sourceFile = file.includes("/build/") ? (await project.glob(
|
|
100
115
|
file.replace(/[/]build[/][^/]+[/]/, "/*/").replace(/(\.d\.ts|\.[\w]+)$/, ".*"),
|
|
@@ -103,6 +118,9 @@ async function resolveTargetFileAsSource(file, project) {
|
|
|
103
118
|
ignore: [project.resolve(file)]
|
|
104
119
|
}
|
|
105
120
|
))[0] : project.resolve(file);
|
|
121
|
+
if (!ALLOWED_SOURCE_FILE_EXTENSIONS.has(path.extname(sourceFile))) {
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
106
124
|
return sourceFile;
|
|
107
125
|
}
|
|
108
126
|
|