@serwist/cli 9.0.0-preview.0 → 9.0.0-preview.2

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.
Files changed (2) hide show
  1. package/dist/bin.js +11 -88
  2. package/package.json +5 -5
package/dist/bin.js CHANGED
@@ -15,13 +15,7 @@ import inquirer from 'inquirer';
15
15
  import { glob } from 'glob';
16
16
  import ora from 'ora';
17
17
 
18
- /*
19
- Copyright 2018 Google LLC
20
-
21
- Use of this source code is governed by an MIT-style
22
- license that can be found in the LICENSE file or at
23
- https://opensource.org/licenses/MIT.
24
- */ const constants = {
18
+ const constants = {
25
19
  defaultConfigFile: "serwist.config.js",
26
20
  ignoredDirectories: [
27
21
  "node_modules"
@@ -69,13 +63,10 @@ const logger = {
69
63
  };
70
64
 
71
65
  const require = createRequire(import.meta.url);
72
- // A really light wrapper on top of Node's require() to make it easier to stub
73
- // out reading the configuration during tests.
74
66
  function readConfig(configFile) {
75
67
  return require(configFile);
76
68
  }
77
69
 
78
- // The key used for the question/answer.
79
70
  const name$3 = "configLocation";
80
71
  const configLocationQuestion = {
81
72
  name: name$3,
@@ -83,31 +74,20 @@ const configLocationQuestion = {
83
74
  type: "input",
84
75
  default: constants.defaultConfigFile
85
76
  };
86
- /**
87
- * @returns The answers from inquirer.
88
- */ function askQuestion$5() {
77
+ function askQuestion$5() {
89
78
  return inquirer.prompt([
90
79
  configLocationQuestion
91
80
  ]);
92
81
  }
93
82
  async function askConfigLocation() {
94
83
  const answers = await askQuestion$5();
95
- // The value of the answer when the question type is 'input' is String
96
- // and it has a default value, the casting is safe.
97
84
  const configLocation = answers[name$3].trim();
98
85
  assert(configLocation, errors["invalid-config-location"]);
99
86
  return configLocation;
100
87
  }
101
88
 
102
- // The key used for the question/answer.
103
89
  const name$2 = "globPatterns";
104
- /**
105
- * @param globDirectory The directory used for the root of globbing.
106
- * @returns The unique file extensions corresponding
107
- * to all of the files under globDirectory.
108
- */ async function getAllFileExtensions(globDirectory) {
109
- // Use a pattern to match any file that contains a '.', since that signifies
110
- // the presence of a file extension.
90
+ async function getAllFileExtensions(globDirectory) {
111
91
  const files = await glob("**/*.*", {
112
92
  cwd: globDirectory,
113
93
  nodir: true,
@@ -120,7 +100,6 @@ const name$2 = "globPatterns";
120
100
  for (const file of files){
121
101
  const extension = upath.extname(file);
122
102
  if (extension) {
123
- // Get rid of the leading . character.
124
103
  extensions.add(extension.replace(/^\./, ""));
125
104
  }
126
105
  }
@@ -128,13 +107,7 @@ const name$2 = "globPatterns";
128
107
  ...extensions
129
108
  ];
130
109
  }
131
- /**
132
- * @param globDirectory The directory used for the root of globbing.
133
- * @returns The answers from inquirer.
134
- */ async function askQuestion$4(globDirectory) {
135
- // We need to get a list of extensions corresponding to files in the directory
136
- // to use when asking the next question. That could potentially take some
137
- // time, so we show a spinner and explanatory text.
110
+ async function askQuestion$4(globDirectory) {
138
111
  const spinner = ora({
139
112
  text: `Examining files in ${globDirectory}...`,
140
113
  stream: process.stdout
@@ -154,12 +127,8 @@ const name$2 = "globPatterns";
154
127
  }
155
128
  async function askExtensionsToCache(globDirectory) {
156
129
  const answers = await askQuestion$4(globDirectory);
157
- // The return value is an array of strings with the selected values
158
- // and there is a default, the casting is safe.
159
130
  const extensions = answers[name$2];
160
131
  assert(extensions.length > 0, errors["no-file-extensions-selected"]);
161
- // glob isn't happy with a single option inside of a {} group, so use a
162
- // pattern without a {} group when there's only one extension.
163
132
  const extensionsPattern = extensions.length === 1 ? extensions[0] : `{${extensions.join(",")}}`;
164
133
  return [
165
134
  `**/*.${extensionsPattern}`
@@ -167,20 +136,14 @@ async function askExtensionsToCache(globDirectory) {
167
136
  }
168
137
 
169
138
  const ROOT_PROMPT = "Please enter the path to the root of your web app:";
170
- // The keys used for the questions/answers.
171
139
  const questionRootDirectory = "globDirectory";
172
140
  const questionManualInput = "manualDirectoryInput";
173
- /**
174
- * @returns The subdirectories of the current
175
- * working directory, with hidden and ignored ones filtered out.
176
- */ async function getSubdirectories() {
141
+ async function getSubdirectories() {
177
142
  return await glob("*/", {
178
143
  ignore: constants.ignoredDirectories.map((directory)=>`${directory}/`)
179
144
  });
180
145
  }
181
- /**
182
- * @returns The answers from inquirer.
183
- */ async function askQuestion$3() {
146
+ async function askQuestion$3() {
184
147
  const subdirectories = await getSubdirectories();
185
148
  if (subdirectories.length > 0) {
186
149
  const manualEntryChoice = "Manually enter path";
@@ -222,12 +185,9 @@ async function askRootOfWebApp() {
222
185
  }
223
186
 
224
187
  const START_URL_QUERY_PARAMS_PROMPT = "Please enter the search parameter(s) that you would like to ignore (separated by comma):";
225
- // The keys used for the questions/answers.
226
188
  const question_ignoreURLParametersMatching = "ignoreURLParametersMatching";
227
189
  const question_shouldAskForIgnoreURLParametersMatching = "shouldAskForIgnoreURLParametersMatching";
228
- /**
229
- * @returns The answers from inquirer.
230
- */ async function askQuestion$2() {
190
+ async function askQuestion$2() {
231
191
  return inquirer.prompt([
232
192
  {
233
193
  name: question_shouldAskForIgnoreURLParametersMatching,
@@ -257,12 +217,8 @@ async function askQueryParametersInStartUrl(defaultIgnoredSearchParameters = con
257
217
  return defaultIgnoredSearchParameters.concat(ignoreSearchParameters.map((searchParam)=>new RegExp(`^${searchParam}`)));
258
218
  }
259
219
 
260
- // The key used for the question/answer.
261
220
  const name$1 = "swDest";
262
- /**
263
- * @param defaultDir
264
- * @returns The answers from inquirer.
265
- */ function askQuestion$1(defaultDir) {
221
+ function askQuestion$1(defaultDir) {
266
222
  return inquirer.prompt([
267
223
  {
268
224
  name: name$1,
@@ -274,18 +230,13 @@ const name$1 = "swDest";
274
230
  }
275
231
  async function askSWDest(defaultDir = ".") {
276
232
  const answers = await askQuestion$1(defaultDir);
277
- // When prompt type is input the return type is string
278
- // casting is safe
279
233
  const swDest = answers[name$1].trim();
280
234
  assert(swDest, errors["invalid-sw-dest"]);
281
235
  return swDest;
282
236
  }
283
237
 
284
- // The key used for the question/answer.
285
238
  const name = "swSrc";
286
- /**
287
- * @returns The answers from inquirer.
288
- */ function askQuestion() {
239
+ function askQuestion() {
289
240
  return inquirer.prompt([
290
241
  {
291
242
  name,
@@ -298,7 +249,6 @@ const name = "swSrc";
298
249
  }
299
250
  async function askSWSrc() {
300
251
  const answers = await askQuestion();
301
- // When prompt type is input the return is string or null
302
252
  return answers[name] ? answers[name].trim() : null;
303
253
  }
304
254
 
@@ -309,7 +259,6 @@ async function askQuestions(options = {}) {
309
259
  const swSrc = isInjectManifest ? await askSWSrc() : undefined;
310
260
  const swDest = await askSWDest(globDirectory);
311
261
  const configLocation = await askConfigLocation();
312
- // See https://github.com/GoogleChrome/workbox/issues/2985
313
262
  const ignoreURLParametersMatching = isInjectManifest ? undefined : await askQueryParametersInStartUrl();
314
263
  const config = {
315
264
  globDirectory,
@@ -330,7 +279,6 @@ async function askQuestions(options = {}) {
330
279
 
331
280
  async function runWizard(options = {}) {
332
281
  const { configLocation, config } = await askQuestions(options);
333
- // See https://github.com/GoogleChrome/workbox/issues/2796
334
282
  const contents = `module.exports = ${stringifyObject(config)};`;
335
283
  await fse.writeFile(configLocation, contents);
336
284
  logger.log(`To build your service worker, run
@@ -343,11 +291,7 @@ as part of a build process. See https://goo.gl/fdTQBf for details.`);
343
291
  to ${configLocation}. See ${configDocsURL} for details.`);
344
292
  }
345
293
 
346
- /**
347
- * Runs the specified build command with the provided configuration.
348
- *
349
- * @param options
350
- */ async function runBuildCommand({ config, watch }) {
294
+ async function runBuildCommand({ config, watch }) {
351
295
  const { count, filePaths, size, warnings } = await injectManifest(config);
352
296
  for (const warning of warnings){
353
297
  logger.warn(warning);
@@ -364,9 +308,7 @@ as part of a build process. See https://goo.gl/fdTQBf for details.`);
364
308
  }
365
309
  }
366
310
  const app = async (params)=>{
367
- // This should not be a user-visible error, unless meow() messes something up.
368
311
  assert(params && Array.isArray(params.input), errors["missing-input"]);
369
- // Default to showing the help message if there's no command provided.
370
312
  const [command = "help", option] = params.input;
371
313
  switch(command){
372
314
  case "wizard":
@@ -396,7 +338,6 @@ const app = async (params)=>{
396
338
  throw logger.error(errors["invalid-config-location"]);
397
339
  }
398
340
  logger.log(`Using configuration from ${configPath}.`);
399
- // Determine whether we're in --watch mode, or one-off mode.
400
341
  if (params?.flags?.watch) {
401
342
  const options = {
402
343
  ignoreInitial: true
@@ -432,7 +373,6 @@ const app = async (params)=>{
432
373
  }
433
374
  break;
434
375
  }
435
- // biome-ignore lint/suspicious/noFallthroughSwitchClause: Biome.js doesn't handle functions that return `never`... yet.
436
376
  case "help":
437
377
  {
438
378
  params.showHelp();
@@ -444,16 +384,6 @@ const app = async (params)=>{
444
384
  }
445
385
  };
446
386
 
447
- /*
448
- Copyright 2018 Google LLC
449
-
450
- Use of this source code is governed by an MIT-style
451
- license that can be found in the LICENSE file or at
452
- https://opensource.org/licenses/MIT.
453
- */ // Helper to parse out less relevant info from an Error's stack trace.
454
- // Removes the initial portion, since that's obtained from error.message.
455
- // Removes every stack frame earlier than the last instance of moduleName,
456
- // since that's just frames related to the Node runtime/loader.
457
387
  function cleanupStackTrace(error, moduleName) {
458
388
  if (!error.stack) {
459
389
  return "";
@@ -472,13 +402,7 @@ function cleanupStackTrace(error, moduleName) {
472
402
  return frames.slice(startFrame, lastFrame + 1).join("\n");
473
403
  }
474
404
 
475
- /*
476
- Copyright 2018 Google LLC
477
-
478
- Use of this source code is governed by an MIT-style
479
- license that can be found in the LICENSE file or at
480
- https://opensource.org/licenses/MIT.
481
- */ const helpText = `Usage:
405
+ const helpText = `Usage:
482
406
  $ serwist <command> [options]
483
407
 
484
408
  Commands:
@@ -526,7 +450,6 @@ void (async ()=>{
526
450
  await app(params);
527
451
  } catch (error) {
528
452
  if (error instanceof Error) {
529
- // Show the full error and stack trace if we're run with --debug.
530
453
  if (params.flags.debug) {
531
454
  if (error.stack) {
532
455
  logger.error(`\n${error.stack}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/cli",
3
- "version": "9.0.0-preview.0",
3
+ "version": "9.0.0-preview.2",
4
4
  "type": "module",
5
5
  "description": "@serwist/cli is the command line interface for Serwist.",
6
6
  "files": [
@@ -32,14 +32,14 @@
32
32
  "common-tags": "1.8.2",
33
33
  "fs-extra": "11.2.0",
34
34
  "glob": "10.3.10",
35
- "inquirer": "9.2.13",
35
+ "inquirer": "9.2.14",
36
36
  "meow": "13.1.0",
37
37
  "ora": "8.0.1",
38
38
  "pretty-bytes": "6.1.1",
39
39
  "stringify-object": "5.0.0",
40
40
  "upath": "2.0.1",
41
41
  "update-notifier": "7.0.0",
42
- "@serwist/build": "9.0.0-preview.0"
42
+ "@serwist/build": "9.0.0-preview.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/common-tags": "1.8.4",
@@ -48,8 +48,8 @@
48
48
  "@types/stringify-object": "4.0.5",
49
49
  "@types/update-notifier": "6.0.8",
50
50
  "rollup": "4.9.6",
51
- "typescript": "5.4.0-dev.20240203",
52
- "@serwist/constants": "9.0.0-preview.0"
51
+ "typescript": "5.4.0-dev.20240206",
52
+ "@serwist/constants": "9.0.0-preview.2"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "typescript": ">=5.0.0"