@serwist/cli 9.5.7 → 9.5.8
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/dist/bin.d.mts +10 -0
- package/dist/bin.d.mts.map +1 -0
- package/dist/bin.mjs +280 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/chunks/constants-DptMolAX.js +67 -0
- package/dist/chunks/constants-DptMolAX.js.map +1 -0
- package/dist/chunks/errors-MXE2_2kj.js +139 -0
- package/dist/chunks/errors-MXE2_2kj.js.map +1 -0
- package/dist/chunks/schema-Bboy6FnP.js +29 -0
- package/dist/chunks/schema-Bboy6FnP.js.map +1 -0
- package/dist/chunks/types-Zr8JQZBi.d.ts +34 -0
- package/dist/chunks/types-Zr8JQZBi.d.ts.map +1 -0
- package/dist/chunks/validation-BIte-nSt.js +15 -0
- package/dist/chunks/validation-BIte-nSt.js.map +1 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.schema.d.mts +87 -0
- package/dist/index.schema.d.mts.map +1 -0
- package/dist/index.schema.mjs +3 -0
- package/package.json +16 -17
- package/dist/app.d.ts +0 -4
- package/dist/app.d.ts.map +0 -1
- package/dist/bin.d.ts +0 -6
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -339
- package/dist/chunks/constants.js +0 -84
- package/dist/chunks/errors.js +0 -153
- package/dist/chunks/schema.js +0 -13
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -11
- package/dist/index.schema.d.ts +0 -3
- package/dist/index.schema.d.ts.map +0 -1
- package/dist/index.schema.js +0 -4
- package/dist/lib/ask-questions.d.ts +0 -9
- package/dist/lib/ask-questions.d.ts.map +0 -1
- package/dist/lib/build.d.ts +0 -18
- package/dist/lib/build.d.ts.map +0 -1
- package/dist/lib/cleanup-stack-trace.d.ts +0 -2
- package/dist/lib/cleanup-stack-trace.d.ts.map +0 -1
- package/dist/lib/constants.d.ts +0 -7
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/errors.d.ts +0 -17
- package/dist/lib/errors.d.ts.map +0 -1
- package/dist/lib/help-text.d.ts +0 -2
- package/dist/lib/help-text.d.ts.map +0 -1
- package/dist/lib/logger.d.ts +0 -7
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/read-config.d.ts +0 -3
- package/dist/lib/read-config.d.ts.map +0 -1
- package/dist/lib/run-wizard.d.ts +0 -2
- package/dist/lib/run-wizard.d.ts.map +0 -1
- package/dist/lib/schema.d.ts +0 -79
- package/dist/lib/schema.d.ts.map +0 -1
- package/dist/lib/validation.d.ts +0 -3
- package/dist/lib/validation.d.ts.map +0 -1
- package/dist/types.d.ts +0 -23
- package/dist/types.d.ts.map +0 -1
package/dist/bin.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as AnyFlags, r as BooleanFlag } from "./chunks/types-Zr8JQZBi.js";
|
|
2
|
+
|
|
3
|
+
//#region src/bin.d.ts
|
|
4
|
+
interface SupportedFlags extends AnyFlags {
|
|
5
|
+
debug: BooleanFlag;
|
|
6
|
+
watch: BooleanFlag;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { SupportedFlags };
|
|
10
|
+
//# sourceMappingURL=bin.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.mts","names":[],"sources":["../src/bin.ts"],"mappings":";;;UAiBiB,cAAA,SAAuB,QAAA;EACtC,KAAA,EAAO,WAAA;EACP,KAAA,EAAO,WAAA;AAAA"}
|
package/dist/bin.mjs
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { i as logger, n as runBuildCommand, r as runInjectManifestCommand, t as errors } from "./chunks/errors-MXE2_2kj.js";
|
|
2
|
+
import { n as constants } from "./chunks/constants-DptMolAX.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import chokidar from "chokidar";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
import meow from "meow";
|
|
7
|
+
import updateNotifier from "update-notifier";
|
|
8
|
+
import assert from "node:assert";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { statSync, writeFileSync } from "node:fs";
|
|
11
|
+
import stringifyObject from "stringify-object";
|
|
12
|
+
import { Separator, checkbox, input, select } from "@inquirer/prompts";
|
|
13
|
+
import { toUnix } from "@serwist/utils";
|
|
14
|
+
//#region src/lib/read-config.ts
|
|
15
|
+
const readConfig = async (configFile) => {
|
|
16
|
+
return (await import(configFile)).default;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/lib/ask-questions.ts
|
|
20
|
+
/**
|
|
21
|
+
* @returns The subdirectories of the current
|
|
22
|
+
* working directory, with hidden and ignored ones filtered out.
|
|
23
|
+
*/
|
|
24
|
+
const getSubdirectories = async () => {
|
|
25
|
+
return await glob("*/", { ignore: constants.ignoredDirectories.map((directory) => `${directory}/`) });
|
|
26
|
+
};
|
|
27
|
+
const askRootOfWebApp = async () => {
|
|
28
|
+
const subdirectories = await getSubdirectories();
|
|
29
|
+
const { globDirectory, manualDirectoryInput } = await (async () => {
|
|
30
|
+
if (subdirectories.length > 0) {
|
|
31
|
+
const manualEntryChoice = "Manually enter path";
|
|
32
|
+
const globDirectory = await select({
|
|
33
|
+
message: "What is the root of your web app (i.e. which directory do you deploy)?",
|
|
34
|
+
choices: [
|
|
35
|
+
...subdirectories.map((dir) => ({ value: dir })),
|
|
36
|
+
new Separator(),
|
|
37
|
+
{ value: manualEntryChoice }
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
let manualDirectoryInput;
|
|
41
|
+
if (globDirectory === manualEntryChoice) manualDirectoryInput = await input({ message: "Please enter the path to the root of your web app:" });
|
|
42
|
+
return {
|
|
43
|
+
globDirectory,
|
|
44
|
+
manualDirectoryInput
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
globDirectory: await input({
|
|
49
|
+
message: "Please enter the path to the root of your web app:",
|
|
50
|
+
default: "."
|
|
51
|
+
}),
|
|
52
|
+
manualDirectoryInput: void 0
|
|
53
|
+
};
|
|
54
|
+
})();
|
|
55
|
+
assert(statSync(manualDirectoryInput || globDirectory).isDirectory(), errors["glob-directory-invalid"]);
|
|
56
|
+
return manualDirectoryInput || globDirectory;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @param globDirectory The directory used for the root of globbing.
|
|
60
|
+
* @returns The unique file extensions corresponding
|
|
61
|
+
* to all of the files under globDirectory.
|
|
62
|
+
*/
|
|
63
|
+
const getAllFileExtensions = async (globDirectory) => {
|
|
64
|
+
const files = await glob("**/*.*", {
|
|
65
|
+
cwd: globDirectory,
|
|
66
|
+
nodir: true,
|
|
67
|
+
ignore: [...constants.ignoredDirectories.map((directory) => `**/${directory}/**`), ...constants.ignoredFileExtensions.map((extension) => `**/*.${extension}`)]
|
|
68
|
+
});
|
|
69
|
+
const extensions = /* @__PURE__ */ new Set();
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const extension = path.extname(file);
|
|
72
|
+
if (extension) extensions.add(extension.replace(/^\./, ""));
|
|
73
|
+
}
|
|
74
|
+
return [...extensions];
|
|
75
|
+
};
|
|
76
|
+
const askQuestions = async () => {
|
|
77
|
+
const globDirectory = await askRootOfWebApp();
|
|
78
|
+
const fileExtensions = await getAllFileExtensions(globDirectory);
|
|
79
|
+
assert(fileExtensions.length > 0, errors["no-file-extensions-found"]);
|
|
80
|
+
const swSrc = await input({
|
|
81
|
+
message: "Where's your existing service worker file? To be used with 'injectManifest', it should include a call to 'self.__SW_MANIFEST'",
|
|
82
|
+
validate(input) {
|
|
83
|
+
if (typeof input !== "string") return "You must provide a valid 'swSrc'!";
|
|
84
|
+
if (!statSync(input, { throwIfNoEntry: false })?.isFile()) return "'swSrc' must point to a valid file!";
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const swDest = await input({
|
|
89
|
+
message: "Where would you like your service worker file to be saved?",
|
|
90
|
+
default: toUnix(path.join(globDirectory, "sw.js")),
|
|
91
|
+
validate(input) {
|
|
92
|
+
if (typeof input !== "string") return "You must provide a valid 'swDest'!";
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
const selectedExtensions = await checkbox({
|
|
97
|
+
message: "Which file types would you like to precache?",
|
|
98
|
+
choices: fileExtensions.map((ext) => ({
|
|
99
|
+
value: ext,
|
|
100
|
+
checked: true
|
|
101
|
+
})),
|
|
102
|
+
validate(input) {
|
|
103
|
+
if (!Array.isArray(input)) return "'selectedExtensions' is not an array. This is most likely a bug.";
|
|
104
|
+
if (input.length === 0) return errors["no-file-extensions-selected"];
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const configLocation = await input({
|
|
109
|
+
message: "Where would you like to save these configuration options?",
|
|
110
|
+
default: constants.defaultConfigFile,
|
|
111
|
+
validate(input) {
|
|
112
|
+
if (typeof input !== "string") return "You must provide a valid location!";
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
config: {
|
|
118
|
+
globDirectory,
|
|
119
|
+
globPatterns: [`**/*.${selectedExtensions.length === 1 ? selectedExtensions[0] : `{${selectedExtensions.join(",")}}`}`],
|
|
120
|
+
swSrc,
|
|
121
|
+
swDest
|
|
122
|
+
},
|
|
123
|
+
configLocation
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/lib/run-wizard.ts
|
|
128
|
+
async function runWizard() {
|
|
129
|
+
const { configLocation, config } = await askQuestions();
|
|
130
|
+
writeFileSync(configLocation, `/** @type {import("@serwist/build").InjectManifestOptions} */\nexport default ${stringifyObject(config)};`);
|
|
131
|
+
logger.log(`To build your service worker, run
|
|
132
|
+
|
|
133
|
+
serwist inject-manifest ${configLocation}
|
|
134
|
+
|
|
135
|
+
as part of a build process.`);
|
|
136
|
+
logger.log(`You can further customize your service worker by making changes to ${configLocation}. See https://serwist.pages.dev/docs/build/configuring for details.`);
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/app.ts
|
|
140
|
+
const app = async (params) => {
|
|
141
|
+
assert(params && Array.isArray(params.input), errors["missing-input"]);
|
|
142
|
+
const [command = "help", option] = params.input;
|
|
143
|
+
process.env.SERWIST_ENV = params.flags.watch ? "watch" : "build";
|
|
144
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = params.flags.watch ? "development" : "production";
|
|
145
|
+
switch (command) {
|
|
146
|
+
case "wizard":
|
|
147
|
+
await runWizard();
|
|
148
|
+
break;
|
|
149
|
+
case "build": {
|
|
150
|
+
const configPath = path.resolve(process.cwd(), option || constants.defaultConfigFile);
|
|
151
|
+
const configUrl = pathToFileURL(configPath).href;
|
|
152
|
+
let config;
|
|
153
|
+
try {
|
|
154
|
+
config = await readConfig(configUrl);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
config = null;
|
|
157
|
+
if (error instanceof Error) {
|
|
158
|
+
logger.error(errors["invalid-common-js-module"]);
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (config === null) throw logger.error(errors["invalid-config-location"]);
|
|
163
|
+
logger.log(`Using configuration from ${configPath}.`);
|
|
164
|
+
await runBuildCommand({
|
|
165
|
+
config,
|
|
166
|
+
watch: !!params.flags.watch
|
|
167
|
+
});
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case "inject-manifest": {
|
|
171
|
+
const configPath = path.resolve(process.cwd(), option || constants.defaultConfigFile);
|
|
172
|
+
const configUrl = pathToFileURL(configPath).href;
|
|
173
|
+
let config;
|
|
174
|
+
try {
|
|
175
|
+
config = await readConfig(configUrl);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
config = null;
|
|
178
|
+
if (error instanceof Error) {
|
|
179
|
+
logger.error(errors["invalid-common-js-module"]);
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (config === null) throw logger.error(errors["invalid-config-location"]);
|
|
184
|
+
logger.log(`Using configuration from ${configPath}.`);
|
|
185
|
+
if (params.flags.watch) {
|
|
186
|
+
if (config.globPatterns) chokidar.watch(await glob(config.globPatterns, {
|
|
187
|
+
cwd: config.globDirectory,
|
|
188
|
+
follow: config.globFollow,
|
|
189
|
+
ignore: config.globIgnores
|
|
190
|
+
}), {
|
|
191
|
+
ignoreInitial: true,
|
|
192
|
+
cwd: config.globDirectory
|
|
193
|
+
}).on("all", async () => {
|
|
194
|
+
if (config === null) return;
|
|
195
|
+
await runInjectManifestCommand({
|
|
196
|
+
config,
|
|
197
|
+
watch: true
|
|
198
|
+
});
|
|
199
|
+
}).on("ready", async () => {
|
|
200
|
+
if (config === null) return;
|
|
201
|
+
await runInjectManifestCommand({
|
|
202
|
+
config,
|
|
203
|
+
watch: true
|
|
204
|
+
});
|
|
205
|
+
}).on("error", (err) => {
|
|
206
|
+
logger.error(err instanceof Error ? err.toString() : "Unknown error");
|
|
207
|
+
});
|
|
208
|
+
} else await runInjectManifestCommand({
|
|
209
|
+
config,
|
|
210
|
+
watch: false
|
|
211
|
+
});
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case "help": params.showHelp();
|
|
215
|
+
default: throw new Error(`${errors["unknown-command"]} ${command}`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/lib/cleanup-stack-trace.ts
|
|
220
|
+
const cleanupStackTrace = (error, moduleName) => {
|
|
221
|
+
if (!error.stack) return "";
|
|
222
|
+
const frames = error.stack.split("\n");
|
|
223
|
+
let startFrame;
|
|
224
|
+
let lastFrame = 0;
|
|
225
|
+
frames.forEach((frame, index) => {
|
|
226
|
+
if (startFrame === void 0 && frame.includes(" at ")) startFrame = index;
|
|
227
|
+
if (frame.includes(`${moduleName}:`)) lastFrame = index;
|
|
228
|
+
});
|
|
229
|
+
return frames.slice(startFrame, lastFrame + 1).join("\n");
|
|
230
|
+
};
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/lib/help-text.ts
|
|
233
|
+
const helpText = `Usage:
|
|
234
|
+
$ serwist <command> [options]
|
|
235
|
+
|
|
236
|
+
Commands:
|
|
237
|
+
wizard
|
|
238
|
+
Runs the configuration wizard, which will generate a
|
|
239
|
+
config file based on answers to questions.
|
|
240
|
+
|
|
241
|
+
inject-manifest [<path/to/config.js>] [--watch]
|
|
242
|
+
Takes an existing service worker file and creates a
|
|
243
|
+
copy of it with a precache manifest injected. The precache
|
|
244
|
+
manifest is generated based on the options in the config file
|
|
245
|
+
(defaults to 'serwist.config.js'). If '--watch' is provided, the
|
|
246
|
+
CLI will stay running and rebuild the service worker each
|
|
247
|
+
time a file in the precache manifest changes. See
|
|
248
|
+
https://serwist.pages.dev/docs/cli for more information.
|
|
249
|
+
|
|
250
|
+
Configuration file:
|
|
251
|
+
The 'inject-manifest' command expects the configuration
|
|
252
|
+
file to be a JavaScript file. By default, it is assumed
|
|
253
|
+
to be named 'serwist.config.js' and located in the current
|
|
254
|
+
directory, but this can be overridden.
|
|
255
|
+
|
|
256
|
+
Examples:
|
|
257
|
+
$ serwist wizard
|
|
258
|
+
$ serwist inject-manifest configs/serwist-config.js
|
|
259
|
+
`;
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/bin.ts
|
|
262
|
+
(async () => {
|
|
263
|
+
const params = meow(helpText, { importMeta: import.meta });
|
|
264
|
+
updateNotifier({ pkg: params.pkg }).notify();
|
|
265
|
+
try {
|
|
266
|
+
await app(params);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
if (error instanceof Error) if (params.flags.debug) {
|
|
269
|
+
if (error.stack) logger.error(`\n${error.stack}`);
|
|
270
|
+
} else {
|
|
271
|
+
logger.error(`\n${error.message}`);
|
|
272
|
+
logger.debug(`${cleanupStackTrace(error, "app.js")}\n`);
|
|
273
|
+
}
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
})();
|
|
277
|
+
//#endregion
|
|
278
|
+
export {};
|
|
279
|
+
|
|
280
|
+
//# sourceMappingURL=bin.mjs.map
|
package/dist/bin.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.mjs","names":[],"sources":["../src/lib/read-config.ts","../src/lib/ask-questions.ts","../src/lib/run-wizard.ts","../src/app.ts","../src/lib/cleanup-stack-trace.ts","../src/lib/help-text.ts","../src/bin.ts"],"sourcesContent":["/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport type { InjectManifestOptions } from \"@serwist/build\";\n\nexport const readConfig = async <T extends InjectManifestOptions = InjectManifestOptions>(configFile: string): Promise<T> => {\n return (await import(configFile)).default as T | Promise<T>;\n};\n","import assert from \"node:assert\";\nimport { statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { checkbox, input, Separator, select } from \"@inquirer/prompts\";\nimport type { InjectManifestOptions } from \"@serwist/build\";\nimport { toUnix } from \"@serwist/utils\";\nimport { glob } from \"glob\";\nimport { constants } from \"./constants.js\";\nimport { errors } from \"./errors.js\";\n\n/**\n * @returns The subdirectories of the current\n * working directory, with hidden and ignored ones filtered out.\n */\nconst getSubdirectories = async (): Promise<string[]> => {\n return await glob(\"*/\", {\n ignore: constants.ignoredDirectories.map((directory) => `${directory}/`),\n });\n};\n\nconst askRootOfWebApp = async (): Promise<string> => {\n const subdirectories = await getSubdirectories();\n\n const { globDirectory, manualDirectoryInput } = await (async () => {\n if (subdirectories.length > 0) {\n const manualEntryChoice = \"Manually enter path\";\n const globDirectory = await select({\n message: \"What is the root of your web app (i.e. which directory do you deploy)?\",\n choices: [...subdirectories.map((dir) => ({ value: dir })), new Separator(), { value: manualEntryChoice }],\n });\n let manualDirectoryInput: string | undefined;\n if (globDirectory === manualEntryChoice) {\n manualDirectoryInput = await input({ message: \"Please enter the path to the root of your web app:\" });\n }\n return {\n globDirectory,\n manualDirectoryInput,\n };\n }\n\n const globDirectory = await input({ message: \"Please enter the path to the root of your web app:\", default: \".\" });\n\n return {\n globDirectory,\n manualDirectoryInput: undefined,\n };\n })();\n\n const stat = statSync(manualDirectoryInput || globDirectory);\n\n assert(stat.isDirectory(), errors[\"glob-directory-invalid\"]);\n\n return manualDirectoryInput || globDirectory;\n};\n\n/**\n * @param globDirectory The directory used for the root of globbing.\n * @returns The unique file extensions corresponding\n * to all of the files under globDirectory.\n */\nconst getAllFileExtensions = async (globDirectory: string) => {\n // Use a pattern to match any file that contains a '.', since that signifies\n // the presence of a file extension.\n const files: string[] = await glob(\"**/*.*\", {\n cwd: globDirectory,\n nodir: true,\n ignore: [\n ...constants.ignoredDirectories.map((directory) => `**/${directory}/**`),\n ...constants.ignoredFileExtensions.map((extension) => `**/*.${extension}`),\n ],\n });\n\n const extensions: Set<string> = new Set();\n for (const file of files) {\n const extension = path.extname(file);\n if (extension) {\n // Get rid of the leading . character.\n extensions.add(extension.replace(/^\\./, \"\"));\n }\n }\n\n return [...extensions];\n};\n\ninterface ConfigWithConfigLocation {\n config: {\n [key: string]: any;\n };\n configLocation: string;\n}\n\nexport const askQuestions = async (): Promise<ConfigWithConfigLocation> => {\n const globDirectory = await askRootOfWebApp();\n\n const fileExtensions = await getAllFileExtensions(globDirectory);\n\n assert(fileExtensions.length > 0, errors[\"no-file-extensions-found\"]);\n\n const swSrc = await input({\n message: \"Where's your existing service worker file? To be used with 'injectManifest', it should include a call to 'self.__SW_MANIFEST'\",\n validate(input) {\n if (typeof input !== \"string\") {\n return \"You must provide a valid 'swSrc'!\";\n }\n if (!statSync(input, { throwIfNoEntry: false })?.isFile()) {\n return \"'swSrc' must point to a valid file!\";\n }\n return true;\n },\n });\n\n const swDest = await input({\n message: \"Where would you like your service worker file to be saved?\",\n default: toUnix(path.join(globDirectory, \"sw.js\")),\n validate(input) {\n if (typeof input !== \"string\") {\n return \"You must provide a valid 'swDest'!\";\n }\n return true;\n },\n });\n\n const selectedExtensions = await checkbox({\n message: \"Which file types would you like to precache?\",\n choices: fileExtensions.map((ext) => ({ value: ext, checked: true })),\n validate(input) {\n if (!Array.isArray(input)) {\n return \"'selectedExtensions' is not an array. This is most likely a bug.\";\n }\n if (input.length === 0) {\n return errors[\"no-file-extensions-selected\"];\n }\n return true;\n },\n });\n\n const configLocation = await input({\n message: \"Where would you like to save these configuration options?\",\n default: constants.defaultConfigFile,\n validate(input) {\n if (typeof input !== \"string\") {\n return \"You must provide a valid location!\";\n }\n return true;\n },\n });\n\n // glob isn't happy with a single option inside of a {} group, so use a\n // pattern without a {} group when there's only one extension.\n const globPatterns = [`**/*.${selectedExtensions.length === 1 ? selectedExtensions[0] : `{${selectedExtensions.join(\",\")}}`}`];\n\n const config = {\n globDirectory,\n globPatterns,\n swSrc,\n swDest,\n } satisfies InjectManifestOptions;\n\n return {\n config,\n configLocation,\n };\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { writeFileSync } from \"node:fs\";\nimport stringifyObject from \"stringify-object\";\n\nimport { askQuestions } from \"./ask-questions.js\";\nimport { logger } from \"./logger.js\";\n\nexport async function runWizard(): Promise<void> {\n const { configLocation, config } = await askQuestions();\n\n const contents = `/** @type {import(\"@serwist/build\").InjectManifestOptions} */\\nexport default ${stringifyObject(config)};`;\n\n writeFileSync(configLocation, contents);\n\n logger.log(`To build your service worker, run\n\n serwist inject-manifest ${configLocation}\n\nas part of a build process.`);\n\n logger.log(\n `You can further customize your service worker by making changes to ${configLocation}. See https://serwist.pages.dev/docs/build/configuring for details.`,\n );\n}\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { InjectManifestOptions } from \"@serwist/build\";\nimport chokidar from \"chokidar\";\nimport { glob } from \"glob\";\nimport type { Result as MeowResult } from \"meow\";\n\nimport type { SupportedFlags } from \"./bin.js\";\nimport { runBuildCommand, runInjectManifestCommand } from \"./lib/build.js\";\nimport { constants } from \"./lib/constants.js\";\nimport { errors } from \"./lib/errors.js\";\nimport { logger } from \"./lib/logger.js\";\nimport { readConfig } from \"./lib/read-config.js\";\nimport { runWizard } from \"./lib/run-wizard.js\";\nimport type { BuildOptions } from \"./types.js\";\n\nexport const app = async (params: MeowResult<SupportedFlags>): Promise<void> => {\n // This should not be a user-visible error, unless meow() messes something up.\n assert(params && Array.isArray(params.input), errors[\"missing-input\"]);\n\n // Default to showing the help message if there's no command provided.\n const [command = \"help\", option] = params.input;\n\n process.env.SERWIST_ENV = params.flags.watch ? \"watch\" : \"build\";\n\n if (!process.env.NODE_ENV) {\n process.env.NODE_ENV = params.flags.watch ? \"development\" : \"production\";\n }\n\n switch (command) {\n case \"wizard\": {\n await runWizard();\n break;\n }\n\n case \"build\": {\n const configPath = path.resolve(process.cwd(), option || constants.defaultConfigFile);\n const configUrl = pathToFileURL(configPath).href;\n\n let config: BuildOptions | null;\n try {\n config = await readConfig<BuildOptions>(configUrl);\n } catch (error) {\n config = null;\n if (error instanceof Error) {\n logger.error(errors[\"invalid-common-js-module\"]);\n throw error;\n }\n }\n\n if (config === null) {\n throw logger.error(errors[\"invalid-config-location\"]);\n }\n\n logger.log(`Using configuration from ${configPath}.`);\n\n await runBuildCommand({ config, watch: !!params.flags.watch });\n\n break;\n }\n\n case \"inject-manifest\": {\n const configPath = path.resolve(process.cwd(), option || constants.defaultConfigFile);\n const configUrl = pathToFileURL(configPath).href;\n\n let config: InjectManifestOptions | null;\n try {\n config = await readConfig(configUrl);\n } catch (error) {\n config = null;\n if (error instanceof Error) {\n logger.error(errors[\"invalid-common-js-module\"]);\n throw error;\n }\n }\n\n if (config === null) {\n throw logger.error(errors[\"invalid-config-location\"]);\n }\n\n logger.log(`Using configuration from ${configPath}.`);\n\n // Determine whether we're in --watch mode, or one-off mode.\n if (params.flags.watch) {\n if (config.globPatterns) {\n chokidar\n .watch(\n await glob(config.globPatterns, {\n cwd: config.globDirectory,\n follow: config.globFollow,\n ignore: config.globIgnores,\n }),\n {\n ignoreInitial: true,\n cwd: config.globDirectory,\n },\n )\n .on(\"all\", async () => {\n if (config === null) return;\n await runInjectManifestCommand({\n config,\n watch: true,\n });\n })\n .on(\"ready\", async () => {\n if (config === null) return;\n await runInjectManifestCommand({\n config,\n watch: true,\n });\n })\n .on(\"error\", (err) => {\n logger.error(err instanceof Error ? err.toString() : \"Unknown error\");\n });\n }\n } else {\n await runInjectManifestCommand({ config, watch: false });\n }\n break;\n }\n\n // biome-ignore lint/suspicious/noFallthroughSwitchClause: Biome.js doesn't handle functions that return `never`... yet.\n case \"help\": {\n params.showHelp();\n }\n\n default: {\n throw new Error(`${errors[\"unknown-command\"]} ${command}`);\n }\n }\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\n// Helper to parse out less relevant info from an Error's stack trace.\n// Removes the initial portion, since that's obtained from error.message.\n// Removes every stack frame earlier than the last instance of moduleName,\n// since that's just frames related to the Node runtime/loader.\nexport const cleanupStackTrace = (error: Error, moduleName: string): string => {\n if (!error.stack) {\n return \"\";\n }\n const frames = error.stack.split(\"\\n\");\n let startFrame: number | undefined;\n let lastFrame = 0;\n frames.forEach((frame, index) => {\n if (startFrame === undefined && frame.includes(\" at \")) {\n startFrame = index;\n }\n\n if (frame.includes(`${moduleName}:`)) {\n lastFrame = index;\n }\n });\n return frames.slice(startFrame, lastFrame + 1).join(\"\\n\");\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nexport const helpText = `Usage:\n$ serwist <command> [options]\n\nCommands:\n wizard\n Runs the configuration wizard, which will generate a\n config file based on answers to questions.\n\n inject-manifest [<path/to/config.js>] [--watch]\n Takes an existing service worker file and creates a\n copy of it with a precache manifest injected. The precache \n manifest is generated based on the options in the config file \n (defaults to 'serwist.config.js'). If '--watch' is provided, the \n CLI will stay running and rebuild the service worker each \n time a file in the precache manifest changes. See \n https://serwist.pages.dev/docs/cli for more information.\n\nConfiguration file:\n The 'inject-manifest' command expects the configuration \n file to be a JavaScript file. By default, it is assumed \n to be named 'serwist.config.js' and located in the current\n directory, but this can be overridden.\n\nExamples:\n $ serwist wizard\n $ serwist inject-manifest configs/serwist-config.js\n`;\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { Result as MeowResult } from \"meow\";\nimport meow from \"meow\";\nimport updateNotifier, { type Package } from \"update-notifier\";\nimport { app } from \"./app.js\";\nimport { cleanupStackTrace } from \"./lib/cleanup-stack-trace.js\";\nimport { helpText } from \"./lib/help-text.js\";\nimport { logger } from \"./lib/logger.js\";\nimport type { AnyFlags, BooleanFlag } from \"./types.js\";\n\nexport interface SupportedFlags extends AnyFlags {\n debug: BooleanFlag;\n watch: BooleanFlag;\n}\n\nvoid (async () => {\n const params: MeowResult<any> = meow(helpText, {\n importMeta: import.meta,\n });\n\n updateNotifier({ pkg: params.pkg as Package }).notify();\n\n try {\n await app(params);\n } catch (error) {\n if (error instanceof Error) {\n // Show the full error and stack trace if we're run with --debug.\n if (params.flags.debug) {\n if (error.stack) {\n logger.error(`\\n${error.stack}`);\n }\n } else {\n logger.error(`\\n${error.message}`);\n logger.debug(`${cleanupStackTrace(error, \"app.js\")}\\n`);\n }\n }\n\n process.exit(1);\n }\n})();\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,aAAa,OAAgE,eAAmC;AAC3H,SAAQ,MAAM,OAAO,aAAa;;;;;;;;ACIpC,MAAM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AK,MAAM,QAAQ;SAE7B;AACL,UAAO,MAAM,KAAK,MAAM,UAAU;AAClC,UAAO,MAAM,GAAG,kBAAkB,OAAO,SAAS,CAAC,IAAI;;AAI3D,UAAQ,KAAK,EAAE;;IAEf"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/lib/constants.ts
|
|
2
|
+
const constants = {
|
|
3
|
+
defaultConfigFile: "serwist.config.js",
|
|
4
|
+
ignoredDirectories: ["node_modules"],
|
|
5
|
+
ignoredFileExtensions: ["map"]
|
|
6
|
+
};
|
|
7
|
+
const SUPPORTED_ESBUILD_OPTIONS = [
|
|
8
|
+
"sourcemap",
|
|
9
|
+
"legalComments",
|
|
10
|
+
"sourceRoot",
|
|
11
|
+
"sourcesContent",
|
|
12
|
+
"format",
|
|
13
|
+
"globalName",
|
|
14
|
+
"target",
|
|
15
|
+
"supported",
|
|
16
|
+
"define",
|
|
17
|
+
"treeShaking",
|
|
18
|
+
"minify",
|
|
19
|
+
"mangleProps",
|
|
20
|
+
"reserveProps",
|
|
21
|
+
"mangleQuoted",
|
|
22
|
+
"mangleCache",
|
|
23
|
+
"drop",
|
|
24
|
+
"dropLabels",
|
|
25
|
+
"minifyWhitespace",
|
|
26
|
+
"minifyIdentifiers",
|
|
27
|
+
"minifySyntax",
|
|
28
|
+
"lineLimit",
|
|
29
|
+
"charset",
|
|
30
|
+
"ignoreAnnotations",
|
|
31
|
+
"jsx",
|
|
32
|
+
"jsxFactory",
|
|
33
|
+
"jsxFragment",
|
|
34
|
+
"jsxImportSource",
|
|
35
|
+
"jsxDev",
|
|
36
|
+
"jsxSideEffects",
|
|
37
|
+
"pure",
|
|
38
|
+
"keepNames",
|
|
39
|
+
"absPaths",
|
|
40
|
+
"color",
|
|
41
|
+
"logLevel",
|
|
42
|
+
"logLimit",
|
|
43
|
+
"logOverride",
|
|
44
|
+
"tsconfigRaw",
|
|
45
|
+
"bundle",
|
|
46
|
+
"splitting",
|
|
47
|
+
"preserveSymlinks",
|
|
48
|
+
"external",
|
|
49
|
+
"packages",
|
|
50
|
+
"alias",
|
|
51
|
+
"loader",
|
|
52
|
+
"resolveExtensions",
|
|
53
|
+
"mainFields",
|
|
54
|
+
"conditions",
|
|
55
|
+
"allowOverwrite",
|
|
56
|
+
"tsconfig",
|
|
57
|
+
"outExtension",
|
|
58
|
+
"publicPath",
|
|
59
|
+
"inject",
|
|
60
|
+
"banner",
|
|
61
|
+
"footer",
|
|
62
|
+
"plugins"
|
|
63
|
+
];
|
|
64
|
+
//#endregion
|
|
65
|
+
export { constants as n, SUPPORTED_ESBUILD_OPTIONS as t };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=constants-DptMolAX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-DptMolAX.js","names":[],"sources":["../../src/lib/constants.ts"],"sourcesContent":["/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport type { BuildOptions } from \"esbuild\";\n\nexport const constants = {\n defaultConfigFile: \"serwist.config.js\",\n ignoredDirectories: [\"node_modules\"],\n ignoredFileExtensions: [\"map\"],\n};\n\nexport const SUPPORTED_ESBUILD_OPTIONS = [\n // CommonOptions\n \"sourcemap\",\n \"legalComments\",\n \"sourceRoot\",\n \"sourcesContent\",\n \"format\",\n \"globalName\",\n \"target\",\n \"supported\",\n \"define\",\n \"treeShaking\",\n \"minify\",\n \"mangleProps\",\n \"reserveProps\",\n \"mangleQuoted\",\n \"mangleCache\",\n \"drop\",\n \"dropLabels\",\n \"minifyWhitespace\",\n \"minifyIdentifiers\",\n \"minifySyntax\",\n \"lineLimit\",\n \"charset\",\n \"ignoreAnnotations\",\n \"jsx\",\n \"jsxFactory\",\n \"jsxFragment\",\n \"jsxImportSource\",\n \"jsxDev\",\n \"jsxSideEffects\",\n \"pure\",\n \"keepNames\",\n \"absPaths\",\n \"color\",\n \"logLevel\",\n \"logLimit\",\n \"logOverride\",\n \"tsconfigRaw\",\n // BuildOptions\n \"bundle\",\n \"splitting\",\n \"preserveSymlinks\",\n \"external\",\n \"packages\",\n \"alias\",\n \"loader\",\n \"resolveExtensions\",\n \"mainFields\",\n \"conditions\",\n \"allowOverwrite\",\n \"tsconfig\",\n \"outExtension\",\n \"publicPath\",\n \"inject\",\n \"banner\",\n \"footer\",\n \"plugins\",\n] as const satisfies readonly (keyof BuildOptions)[];\n"],"mappings":";AASA,MAAa,YAAY;CACvB,mBAAmB;CACnB,oBAAoB,CAAC,eAAe;CACpC,uBAAuB,CAAC,MAAM;CAC/B;AAED,MAAa,4BAA4B;CAEvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { t as validateBuildOptions } from "./validation-BIte-nSt.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getFileManifestEntries, injectManifest } from "@serwist/build";
|
|
4
|
+
import chokidar from "chokidar";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
import prettyBytes from "pretty-bytes";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { oneLine } from "common-tags";
|
|
9
|
+
//#region src/lib/logger.ts
|
|
10
|
+
const logger = {
|
|
11
|
+
debug: (...args) => console.log(chalk.gray(...args)),
|
|
12
|
+
log: (...args) => console.log(...args),
|
|
13
|
+
warn: (...args) => console.warn(chalk.yellow(...args)),
|
|
14
|
+
error: (...args) => console.error(chalk.red.bold(...args))
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/lib/build.ts
|
|
18
|
+
/**
|
|
19
|
+
* Runs the specified build command with the provided configuration.
|
|
20
|
+
*
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
const runInjectManifestCommand = async ({ config, watch }) => {
|
|
24
|
+
const { count, filePaths, size, warnings } = await injectManifest(config);
|
|
25
|
+
for (const warning of warnings) logger.warn(warning);
|
|
26
|
+
if (filePaths.length === 1) logger.log(`The service worker file was written to ${config.swDest}.`);
|
|
27
|
+
else {
|
|
28
|
+
const message = filePaths.sort().map((filePath) => ` • ${filePath}`).join("\n");
|
|
29
|
+
logger.log(`The service worker files were written to:\n${message}`);
|
|
30
|
+
}
|
|
31
|
+
if (count > 0) logger.log(`The service worker will precache ${count} URLs, totaling ${prettyBytes(size)}.`);
|
|
32
|
+
if (watch) logger.log("\nWatching for changes...");
|
|
33
|
+
};
|
|
34
|
+
const runBuildCommand = async ({ config, watch }) => {
|
|
35
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
36
|
+
const options = await validateBuildOptions(config);
|
|
37
|
+
const { count, manifestEntries, size, warnings } = await getFileManifestEntries(options);
|
|
38
|
+
for (const warning of warnings) logger.warn(warning);
|
|
39
|
+
const manifestString = manifestEntries === void 0 ? "undefined" : JSON.stringify(manifestEntries, null, 2);
|
|
40
|
+
let esbuild;
|
|
41
|
+
try {
|
|
42
|
+
esbuild = await import("esbuild");
|
|
43
|
+
} catch (err) {
|
|
44
|
+
throw logger.error(`${err}\nThis command needs esbuild. Install it using "npm i esbuild".`);
|
|
45
|
+
}
|
|
46
|
+
const parsedDest = path.parse(config.swDest);
|
|
47
|
+
const esbuildContext = await esbuild.context({
|
|
48
|
+
metafile: true,
|
|
49
|
+
sourcemap: isDev,
|
|
50
|
+
format: "esm",
|
|
51
|
+
target: [
|
|
52
|
+
"chrome64",
|
|
53
|
+
"edge79",
|
|
54
|
+
"firefox67",
|
|
55
|
+
"opera51",
|
|
56
|
+
"safari12"
|
|
57
|
+
],
|
|
58
|
+
treeShaking: true,
|
|
59
|
+
minify: !isDev,
|
|
60
|
+
bundle: true,
|
|
61
|
+
...options.esbuildOptions,
|
|
62
|
+
platform: "browser",
|
|
63
|
+
define: {
|
|
64
|
+
...options.esbuildOptions.define,
|
|
65
|
+
...options.injectionPoint ? { [options.injectionPoint]: manifestString } : {}
|
|
66
|
+
},
|
|
67
|
+
outdir: parsedDest.dir,
|
|
68
|
+
entryNames: "[name]",
|
|
69
|
+
assetNames: "[name]-[hash]",
|
|
70
|
+
chunkNames: "[name]-[hash]",
|
|
71
|
+
entryPoints: [{
|
|
72
|
+
in: config.swSrc,
|
|
73
|
+
out: parsedDest.name
|
|
74
|
+
}]
|
|
75
|
+
});
|
|
76
|
+
const rebuild = async () => {
|
|
77
|
+
const result = await esbuildContext.rebuild();
|
|
78
|
+
const filePaths = Object.keys(result.metafile.outputs);
|
|
79
|
+
if (filePaths.length === 1) logger.log(`The service worker file was written to ${config.swDest}.`);
|
|
80
|
+
else {
|
|
81
|
+
const message = filePaths.sort().map((filePath) => ` • ${filePath}`).join("\n");
|
|
82
|
+
logger.log(`The service worker files were written to:\n${message}`);
|
|
83
|
+
}
|
|
84
|
+
if (count > 0) logger.log(`The service worker will precache ${count} URLs, totaling ${prettyBytes(size)}.`);
|
|
85
|
+
if (watch) logger.log("\nWatching for changes...");
|
|
86
|
+
};
|
|
87
|
+
if (watch) {
|
|
88
|
+
if (config.globPatterns) chokidar.watch([config.swSrc, ...config.disablePrecacheManifest ? [] : await glob(config.globPatterns, {
|
|
89
|
+
cwd: config.globDirectory,
|
|
90
|
+
follow: config.globFollow,
|
|
91
|
+
ignore: config.globIgnores
|
|
92
|
+
})], {
|
|
93
|
+
ignoreInitial: true,
|
|
94
|
+
cwd: config.globDirectory
|
|
95
|
+
}).on("all", async () => {
|
|
96
|
+
if (config === null) return;
|
|
97
|
+
await rebuild();
|
|
98
|
+
}).on("ready", async () => {
|
|
99
|
+
if (config === null) return;
|
|
100
|
+
await rebuild();
|
|
101
|
+
}).on("error", (err) => {
|
|
102
|
+
logger.error(err instanceof Error ? err.toString() : "Unknown error");
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
await rebuild();
|
|
106
|
+
await esbuildContext.dispose();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/lib/errors.ts
|
|
111
|
+
const errors = {
|
|
112
|
+
"missing-input": "params.input value was not set properly.",
|
|
113
|
+
"missing-dest-dir-param": oneLine`Please provide the path to a directory in which
|
|
114
|
+
the libraries will be copied.`,
|
|
115
|
+
"invalid-common-js-module": oneLine`Please pass in a valid module that
|
|
116
|
+
exports your configuration.`,
|
|
117
|
+
"config-validation-failed": "Your configuration is invalid:",
|
|
118
|
+
"serwist-build-runtime-error": "Service worker generation failed:",
|
|
119
|
+
"unknown-command": "Unknown command:",
|
|
120
|
+
"no-file-extensions-found": oneLine`No files could be found that are suitable for
|
|
121
|
+
caching.`,
|
|
122
|
+
"no-file-extensions-selected": "Please select at least one file extension.",
|
|
123
|
+
"invalid-sw-dest": oneLine`Please enter a valid path to use for the service worker
|
|
124
|
+
file that's created.`,
|
|
125
|
+
"glob-directory-invalid": oneLine`The path you entered isn't a valid directory.`,
|
|
126
|
+
"invalid-config-location": oneLine`Please enter a valid path to use for the saved
|
|
127
|
+
configuration file.`,
|
|
128
|
+
"sw-src-missing-injection-point": oneLine`That is not a valid source service worker
|
|
129
|
+
file. Please try again with a file containing
|
|
130
|
+
'self.__SW_MANIFEST'.`,
|
|
131
|
+
"no-search-parameters-supplied": oneLine`Please provide the url search param(s)
|
|
132
|
+
you would like to ignore.`,
|
|
133
|
+
"invalid-search-parameters-supplied": oneLine`Please provide the valid URL search parameter(s)
|
|
134
|
+
without the leading '/' or '?' (i.e. source,version,language).`
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
export { logger as i, runBuildCommand as n, runInjectManifestCommand as r, errors as t };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=errors-MXE2_2kj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-MXE2_2kj.js","names":[],"sources":["../../src/lib/logger.ts","../../src/lib/build.ts","../../src/lib/errors.ts"],"sourcesContent":["/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport chalk from \"chalk\";\n\nexport const logger = {\n debug: (...args: string[]): void => console.log(chalk.gray(...args)),\n log: (...args: string[]): void => console.log(...args),\n warn: (...args: string[]): void => console.warn(chalk.yellow(...args)),\n error: (...args: string[]): void => console.error(chalk.red.bold(...args)),\n};\n","import path from \"node:path\";\nimport { getFileManifestEntries, type InjectManifestOptions, injectManifest } from \"@serwist/build\";\nimport chokidar from \"chokidar\";\nimport { glob } from \"glob\";\nimport prettyBytes from \"pretty-bytes\";\n\nimport type { BuildOptions } from \"../types.js\";\nimport { logger } from \"./logger.js\";\nimport { validateBuildOptions } from \"./validation.js\";\n\nexport interface InjectManifestCommand {\n watch: boolean;\n config: InjectManifestOptions;\n}\n\n/**\n * Runs the specified build command with the provided configuration.\n *\n * @param options\n */\nexport const runInjectManifestCommand = async ({ config, watch }: InjectManifestCommand) => {\n const { count, filePaths, size, warnings } = await injectManifest(config);\n\n for (const warning of warnings) {\n logger.warn(warning);\n }\n\n if (filePaths.length === 1) {\n logger.log(`The service worker file was written to ${config.swDest}.`);\n } else {\n const message = filePaths\n .sort()\n .map((filePath) => ` • ${filePath}`)\n .join(\"\\n\");\n logger.log(`The service worker files were written to:\\n${message}`);\n }\n\n if (count > 0) {\n logger.log(`The service worker will precache ${count} URLs, ` + `totaling ${prettyBytes(size)}.`);\n }\n\n if (watch) {\n logger.log(\"\\nWatching for changes...\");\n }\n};\n\nexport interface BuildCommand {\n config: BuildOptions;\n watch: boolean;\n}\n\nexport const runBuildCommand = async ({ config, watch }: BuildCommand) => {\n const isDev = process.env.NODE_ENV === \"development\";\n const options = await validateBuildOptions(config);\n const { count, manifestEntries, size, warnings } = await getFileManifestEntries(options);\n\n for (const warning of warnings) {\n logger.warn(warning);\n }\n\n const manifestString = manifestEntries === undefined ? \"undefined\" : JSON.stringify(manifestEntries, null, 2);\n\n let esbuild: typeof import(\"esbuild\");\n try {\n esbuild = await import(\"esbuild\");\n } catch (err) {\n throw logger.error(`${err}\\nThis command needs esbuild. Install it using \"npm i esbuild\".`);\n }\n\n const parsedDest = path.parse(config.swDest);\n\n const esbuildContext = await esbuild.context({\n metafile: true,\n sourcemap: isDev,\n format: \"esm\",\n target: [\"chrome64\", \"edge79\", \"firefox67\", \"opera51\", \"safari12\"],\n treeShaking: true,\n // `minify` would also automatically set `NODE_ENV` to `\"production\"` when true.\n minify: !isDev,\n bundle: true,\n ...options.esbuildOptions,\n platform: \"browser\",\n define: {\n ...options.esbuildOptions.define,\n ...(options.injectionPoint ? { [options.injectionPoint]: manifestString } : {}),\n },\n outdir: parsedDest.dir,\n entryNames: \"[name]\",\n // Asset and chunk names must be at the top, as our path is `/serwist/[path]`,\n // not `/serwist/[...path]`, meaning that we can't resolve paths deeper\n // than one level.\n assetNames: \"[name]-[hash]\",\n chunkNames: \"[name]-[hash]\",\n entryPoints: [{ in: config.swSrc, out: parsedDest.name }],\n });\n\n const rebuild = async () => {\n const result = await esbuildContext.rebuild();\n\n const filePaths = Object.keys(result.metafile.outputs);\n\n if (filePaths.length === 1) {\n logger.log(`The service worker file was written to ${config.swDest}.`);\n } else {\n const message = filePaths\n .sort()\n .map((filePath) => ` • ${filePath}`)\n .join(\"\\n\");\n logger.log(`The service worker files were written to:\\n${message}`);\n }\n\n if (count > 0) {\n logger.log(`The service worker will precache ${count} URLs, ` + `totaling ${prettyBytes(size)}.`);\n }\n\n if (watch) {\n logger.log(\"\\nWatching for changes...\");\n }\n };\n\n if (watch) {\n if (config.globPatterns) {\n chokidar\n .watch(\n [\n config.swSrc,\n ...(config.disablePrecacheManifest\n ? []\n : await glob(config.globPatterns, {\n cwd: config.globDirectory,\n follow: config.globFollow,\n ignore: config.globIgnores,\n })),\n ],\n {\n ignoreInitial: true,\n cwd: config.globDirectory,\n },\n )\n .on(\"all\", async () => {\n if (config === null) return;\n await rebuild();\n })\n .on(\"ready\", async () => {\n if (config === null) return;\n await rebuild();\n })\n .on(\"error\", (err) => {\n logger.error(err instanceof Error ? err.toString() : \"Unknown error\");\n });\n }\n } else {\n await rebuild();\n await esbuildContext.dispose();\n }\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { oneLine as ol } from \"common-tags\";\n\nexport const errors = {\n \"missing-input\": \"params.input value was not set properly.\",\n \"missing-dest-dir-param\": ol`Please provide the path to a directory in which\n the libraries will be copied.`,\n \"invalid-common-js-module\": ol`Please pass in a valid module that\n exports your configuration.`,\n \"config-validation-failed\": \"Your configuration is invalid:\",\n \"serwist-build-runtime-error\": \"Service worker generation failed:\",\n \"unknown-command\": \"Unknown command:\",\n \"no-file-extensions-found\": ol`No files could be found that are suitable for\n caching.`,\n \"no-file-extensions-selected\": \"Please select at least one file extension.\",\n \"invalid-sw-dest\": ol`Please enter a valid path to use for the service worker\n file that's created.`,\n \"glob-directory-invalid\": ol`The path you entered isn't a valid directory.`,\n \"invalid-config-location\": ol`Please enter a valid path to use for the saved\n configuration file.`,\n \"sw-src-missing-injection-point\": ol`That is not a valid source service worker\n file. Please try again with a file containing\n 'self.__SW_MANIFEST'.`,\n \"no-search-parameters-supplied\": ol`Please provide the url search param(s)\n you would like to ignore.`,\n \"invalid-search-parameters-supplied\": ol`Please provide the valid URL search parameter(s)\n without the leading '/' or '?' (i.e. source,version,language).`,\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,SAAS;CACpB,QAAQ,GAAG,SAAyB,QAAQ,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC;CACpE,MAAM,GAAG,SAAyB,QAAQ,IAAI,GAAG,KAAK;CACtD,OAAO,GAAG,SAAyB,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AAiB;CACjB,0BAA0B,OAAE;;CAE5B,4BAA4B,OAAE;;CAE9B,4BAA4B;CAC5B,+BAA+B;CAC/B,mBAAmB;CACnB,4BAA4B,OAAE;;CAE9B,+BAA+B;CAC/B,mBAAmB,OAAE;;CAErB,0BAA0B,OAAE;CAC5B,2BAA2B,OAAE;;CAE7B,kCAAkC,OAAE;;;CAGpC,iCAAiC,OAAE;;CAEnC,sCAAsC,OAAE;;CAEzC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as SUPPORTED_ESBUILD_OPTIONS } from "./constants-DptMolAX.js";
|
|
2
|
+
import { injectManifestOptions } from "@serwist/build/schema";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __exportAll = (all, no_symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/lib/schema.ts
|
|
17
|
+
var schema_exports = /* @__PURE__ */ __exportAll({
|
|
18
|
+
buildOptions: () => buildOptions,
|
|
19
|
+
buildPartial: () => buildPartial
|
|
20
|
+
});
|
|
21
|
+
const buildPartial = z.strictObject({ esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({}) });
|
|
22
|
+
const buildOptions = z.strictObject({
|
|
23
|
+
...injectManifestOptions.shape,
|
|
24
|
+
...buildPartial.shape
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { buildPartial as n, schema_exports as r, buildOptions as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=schema-Bboy6FnP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-Bboy6FnP.js","names":[],"sources":["../../src/lib/schema.ts"],"sourcesContent":["import { injectManifestOptions } from \"@serwist/build/schema\";\nimport z from \"zod\";\nimport { SUPPORTED_ESBUILD_OPTIONS } from \"./constants.js\";\n\nexport const buildPartial = z.strictObject({\n esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({}),\n});\n\nexport const buildOptions = z.strictObject({\n ...injectManifestOptions.shape,\n ...buildPartial.shape,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,MAAa,eAAe,EAAE,aAAa,EACzC,gBAAgB,EAAE,cAAc,EAAE,QAAQ,0BAA0B,EAAE,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC,EAC5F,CAAC;AAEF,MAAa,eAAe,EAAE,aAAa;CACzC,GAAG,sBAAsB;CACzB,GAAG,aAAa;CACjB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { InjectManifestOptions, InjectManifestOptionsComplete } from "@serwist/build";
|
|
2
|
+
import { Flag } from "meow";
|
|
3
|
+
import { Prettify, Require } from "@serwist/utils";
|
|
4
|
+
import { BuildOptions } from "esbuild";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/constants.d.ts
|
|
7
|
+
declare const constants: {
|
|
8
|
+
defaultConfigFile: string;
|
|
9
|
+
ignoredDirectories: string[];
|
|
10
|
+
ignoredFileExtensions: string[];
|
|
11
|
+
};
|
|
12
|
+
declare const SUPPORTED_ESBUILD_OPTIONS: readonly ["sourcemap", "legalComments", "sourceRoot", "sourcesContent", "format", "globalName", "target", "supported", "define", "treeShaking", "minify", "mangleProps", "reserveProps", "mangleQuoted", "mangleCache", "drop", "dropLabels", "minifyWhitespace", "minifyIdentifiers", "minifySyntax", "lineLimit", "charset", "ignoreAnnotations", "jsx", "jsxFactory", "jsxFragment", "jsxImportSource", "jsxDev", "jsxSideEffects", "pure", "keepNames", "absPaths", "color", "logLevel", "logLimit", "logOverride", "tsconfigRaw", "bundle", "splitting", "preserveSymlinks", "external", "packages", "alias", "loader", "resolveExtensions", "mainFields", "conditions", "allowOverwrite", "tsconfig", "outExtension", "publicPath", "inject", "banner", "footer", "plugins"];
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/types.d.ts
|
|
15
|
+
type StringFlag = Flag<"string", string> | Flag<"string", string[], true>;
|
|
16
|
+
type BooleanFlag = Flag<"boolean", boolean> | Flag<"boolean", boolean[], true>;
|
|
17
|
+
type NumberFlag = Flag<"number", number> | Flag<"number", number[], true>;
|
|
18
|
+
type AnyFlag = StringFlag | BooleanFlag | NumberFlag;
|
|
19
|
+
type AnyFlags = Record<string, AnyFlag>;
|
|
20
|
+
type EsbuildSupportedOptions = (typeof SUPPORTED_ESBUILD_OPTIONS)[number];
|
|
21
|
+
type EsbuildOptions = Pick<BuildOptions, EsbuildSupportedOptions>;
|
|
22
|
+
interface BuildPartial {
|
|
23
|
+
/**
|
|
24
|
+
* Options to configure the esbuild instance used to bundle
|
|
25
|
+
* the service worker.
|
|
26
|
+
*/
|
|
27
|
+
esbuildOptions?: EsbuildOptions;
|
|
28
|
+
}
|
|
29
|
+
type BuildResolved = Require<BuildPartial, "esbuildOptions">;
|
|
30
|
+
type BuildOptions$1 = Prettify<InjectManifestOptions & BuildPartial>;
|
|
31
|
+
type BuildOptionsComplete = Prettify<InjectManifestOptionsComplete & BuildResolved>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { BuildOptionsComplete as a, EsbuildOptions as c, StringFlag as d, SUPPORTED_ESBUILD_OPTIONS as f, BuildOptions$1 as i, EsbuildSupportedOptions as l, AnyFlags as n, BuildPartial as o, constants as p, BooleanFlag as r, BuildResolved as s, AnyFlag as t, NumberFlag as u };
|
|
34
|
+
//# sourceMappingURL=types-Zr8JQZBi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-Zr8JQZBi.d.ts","names":[],"sources":["../../src/lib/constants.ts","../../src/types.ts"],"mappings":";;;;;;cASa,SAAA;;;;;cAMA,yBAAA;;;KCTD,UAAA,GAAa,IAAA,qBAAyB,IAAA;AAAA,KACtC,WAAA,GAAc,IAAA,uBAA2B,IAAA;AAAA,KACzC,UAAA,GAAa,IAAA,qBAAyB,IAAA;AAAA,KACtC,OAAA,GAAU,UAAA,GAAa,WAAA,GAAc,UAAA;AAAA,KACrC,QAAA,GAAW,MAAA,SAAe,OAAA;AAAA,KAE1B,uBAAA,WAAkC,yBAAA;AAAA,KAElC,cAAA,GAAiB,IAAA,CAAK,YAAA,EAAoB,uBAAA;AAAA,UAErC,YAAA;;;ADDjB;;ECME,cAAA,GAAiB,cAAA;AAAA;AAAA,KAGP,aAAA,GAAgB,OAAA,CAAQ,YAAA;AAAA,KAExB,cAAA,GAAe,QAAA,CAAS,qBAAA,GAAwB,YAAA;AAAA,KAEhD,oBAAA,GAAuB,QAAA,CAAS,6BAAA,GAAgC,aAAA"}
|