@fastly/compute-js-static-publish 6.0.0-beta.0 → 6.0.0-beta.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.
package/README.md CHANGED
@@ -108,11 +108,12 @@ Any relative file and directory paths passed at the command line are handled as
108
108
 
109
109
  ### Publishing options:
110
110
 
111
- | Option | Default | Description |
112
- |------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
113
- | `preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators). |
114
- | `output` | `./compute-js` | The directory in which to create the Compute application. |
115
- | `root-dir` | (None) | **Required**. The root of the directory that contains the files to include in the publishing. All files you wish to include must reside under this root. |
111
+ | Option | Default | Description |
112
+ |---------------------------|------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
113
+ | `preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators). |
114
+ | `output` | `./compute-js` | The directory in which to create the Compute application. |
115
+ | `static-content-root-dir` | (output directory) + `/static-publisher` | The directory under the Compute application where static asset and metadata are written. |
116
+ | `root-dir` | (None) | **Required**. The root of the directory that contains the files to include in the publishing. All files you wish to include must reside under this root. |
116
117
 
117
118
  ### Server options:
118
119
 
@@ -308,6 +309,9 @@ And that's it! It should be possible to run this task to clean up once in a whil
308
309
  except for those that are excluded using some of the following features. Files outside this root cannot be
309
310
  included in the publishing.
310
311
 
312
+ * `staticContentRootDir` - Static asset loader and metadata files are created under this directory.
313
+ For legacy compatibility, if not provided, defaults to `'./src'`.
314
+
311
315
  * `kvStoreName` - Set this value to the _name_ of an existing KV Store to enable uploading of content assets
312
316
  to Fastly KV Store. See [Using the KV Store](#kv-store) for more information.
313
317
 
@@ -269,7 +269,7 @@ export async function buildStaticLoader(commandLineValues) {
269
269
  // Create "static content" dir that will be used to hold a copy of static files.
270
270
  // NOTE: This copy is created so that they can be loaded with includeBytes(), which requires
271
271
  // all files to be under the Compute project dir.
272
- const staticContentDir = staticContentRootDir + '/static-content';
272
+ const staticContentDir = `${staticContentRootDir}/static-content`;
273
273
  fs.rmSync(staticContentDir, { recursive: true, force: true });
274
274
  fs.mkdirSync(staticContentDir, { recursive: true });
275
275
  // Build content assets metadata
@@ -399,12 +399,12 @@ export async function buildStaticLoader(commandLineValues) {
399
399
  metadataFileContents += ` ${JSON.stringify(key)}: ${JSON.stringify(value)},\n`;
400
400
  }
401
401
  metadataFileContents += '};\n';
402
- fs.writeFileSync(staticContentRootDir + '/statics-metadata.js', metadataFileContents);
402
+ fs.writeFileSync(`${staticContentRootDir}/statics-metadata.js`, metadataFileContents);
403
403
  console.log(`✅ Wrote static file metadata for ${contentItems} file(s).`);
404
404
  // Copy Types file for static file loader
405
405
  try {
406
406
  const typesFile = path.resolve(__dirname, '../../../resources/statics-metadata.d.ts');
407
- fs.copyFileSync(typesFile, staticContentRootDir + '/statics-metadata.d.ts');
407
+ fs.copyFileSync(typesFile, `${staticContentRootDir}/statics-metadata.d.ts`);
408
408
  console.log("✅ Wrote content assets metadata types file statics-metadata.d.ts.");
409
409
  }
410
410
  catch {
@@ -523,12 +523,12 @@ export async function buildStaticLoader(commandLineValues) {
523
523
  '\n }' +
524
524
  '\n return server;' +
525
525
  '\n}\n';
526
- fs.writeFileSync(staticContentRootDir + '/statics.js', fileContents);
526
+ fs.writeFileSync(`${staticContentRootDir}/statics.js`, fileContents);
527
527
  console.log("✅ Wrote static file loader for " + files.length + " file(s).");
528
528
  // Copy Types file for static file loader
529
529
  try {
530
530
  const staticsTypeFile = path.resolve(__dirname, '../../../resources/statics.d.ts');
531
- fs.copyFileSync(staticsTypeFile, staticContentRootDir + '/statics.d.ts');
531
+ fs.copyFileSync(staticsTypeFile, `${staticContentRootDir}/statics.d.ts`);
532
532
  console.log(`✅ Wrote static file loader types file ${staticContentRootDir}/statics.d.ts.`);
533
533
  }
534
534
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"clean-kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean-kv-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAc5D,wBAAsB,YAAY,CAAC,iBAAiB,EAAE,kBAAkB,iBAgEvE"}
1
+ {"version":3,"file":"clean-kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean-kv-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAc5D,wBAAsB,YAAY,CAAC,iBAAiB,EAAE,kBAAkB,iBAkEvE"}
@@ -26,7 +26,8 @@ export async function cleanKVStore(commandLineValues) {
26
26
  return;
27
27
  }
28
28
  fastlyApiContext = { apiToken: apiKeyResult.apiToken };
29
- const staticsMetadata = await import(path.resolve('./src/statics-metadata.js'));
29
+ const staticContentRootDir = config.staticContentRootDir;
30
+ const staticsMetadata = await import(path.resolve(`${staticContentRootDir}/statics-metadata.js`));
30
31
  const { kvStoreName, contentAssetMetadataMap } = staticsMetadata;
31
32
  if (kvStoreName == null) {
32
33
  console.error("❌ KV Store not specified.");
@@ -1 +1 @@
1
- {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiQvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QA6c5D"}
1
+ {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiQvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAmd5D"}
@@ -330,19 +330,19 @@ export function initApp(commandLineValues) {
330
330
  // Static Content Root Dir must be under the current dir
331
331
  let staticContentRootDir = options.staticContentRootDir;
332
332
  if (staticContentRootDir == null) {
333
- staticContentRootDir = path.resolve('./static-publisher');
334
- }
335
- if (staticContentRootDir.includes('//') ||
336
- !staticContentRootDir.startsWith(process.cwd())) {
337
- console.error(`❌ Specified static content root directory '${staticContentRootDir}' must be a relative path.`);
338
- console.error(` * ${publicDir} must be under ${rootDir}`);
333
+ staticContentRootDir = path.resolve(computeJsDir, './static-publisher');
334
+ }
335
+ if (!staticContentRootDir.startsWith(computeJsDir) ||
336
+ staticContentRootDir === computeJsDir ||
337
+ staticContentRootDir === path.resolve(computeJsDir, './bin') ||
338
+ staticContentRootDir === path.resolve(computeJsDir, './pkg') ||
339
+ staticContentRootDir === path.resolve(computeJsDir, './node_modules')) {
340
+ console.error(`❌ Specified static content root directory '${staticContentRootDir}' must be under ${computeJsDir}.`);
341
+ console.error(` It also must not be bin, pkg, or node_modules.`);
339
342
  process.exitCode = 1;
340
343
  return;
341
344
  }
342
- while (staticContentRootDir.endsWith('/')) {
343
- staticContentRootDir = staticContentRootDir.slice(0, -1);
344
- }
345
- staticContentRootDir = path.relative(process.cwd(), staticContentRootDir);
345
+ staticContentRootDir = './' + path.relative(computeJsDir, staticContentRootDir);
346
346
  // SPA and Not Found are relative to the asset root dir.
347
347
  const SPA = options.spa;
348
348
  let spaFilename;
@@ -424,16 +424,21 @@ export function initApp(commandLineValues) {
424
424
  fs.mkdirSync(computeJsDir);
425
425
  fs.mkdirSync(path.resolve(computeJsDir, './src'));
426
426
  const staticContentRootDirFromRoot = staticContentRootDir.slice(1);
427
+ let staticFiles = staticContentRootDirFromRoot;
428
+ if (staticContentRootDirFromRoot === '/src') {
429
+ staticFiles = `\
430
+ ${staticContentRootDirFromRoot}/statics.js
431
+ ${staticContentRootDirFromRoot}/statics.d.ts
432
+ ${staticContentRootDirFromRoot}/statics-metadata.js
433
+ ${staticContentRootDirFromRoot}/statics-metadata.d.ts
434
+ ${staticContentRootDirFromRoot}/static-content`;
435
+ }
427
436
  // .gitignore
428
437
  const gitIgnoreContent = `\
429
438
  /node_modules
430
439
  /bin
431
440
  /pkg
432
- ${staticContentRootDirFromRoot}/statics.js
433
- ${staticContentRootDirFromRoot}/statics.d.ts
434
- ${staticContentRootDirFromRoot}/statics-metadata.js
435
- ${staticContentRootDirFromRoot}/statics-metadata.d.ts
436
- ${staticContentRootDirFromRoot}/static-content
441
+ ${staticFiles}
437
442
  `;
438
443
  const gitIgnorePath = path.resolve(computeJsDir, '.gitignore');
439
444
  fs.writeFileSync(gitIgnorePath, gitIgnoreContent, "utf-8");
@@ -25,13 +25,13 @@ const optionDefinitions = [
25
25
  // then the value of 'public-dir' is used.
26
26
  { name: 'root-dir', type: String, },
27
27
  // The 'public' directory. The Publisher Server will
28
- // resolve requests relative to this directory. Specify this as
29
- // a relative path from 'root-dir'. Defaults to './'.
28
+ // resolve requests relative to this directory. If not specified,
29
+ // defaults to the same value as 'root-dir'. See README for
30
+ // details.
30
31
  { name: 'public-dir', type: String, },
31
32
  // Directories to specify as containing 'static' files. The
32
33
  // Publisher Server will serve files from these directories
33
- // with a long TTL. Each entry should be a relative path
34
- // from 'public-dir'.
34
+ // with a long TTL.
35
35
  { name: 'static-dir', type: String, multiple: true, },
36
36
  // The 'static content root directory' where the Static Publisher
37
37
  // outputs its metadata files and loaders.
@@ -39,16 +39,14 @@ const optionDefinitions = [
39
39
  // Path to a file to be used to serve in a SPA application.
40
40
  // The Publisher Server will serve this file with a 200 status code
41
41
  // when the request doesn't match a known file, and the accept
42
- // header includes text/html. Specify this as a relative path
43
- // from 'root-dir'. You may use the '[public-dir]' token if you wish
44
- // to specify this as a relative path from the 'public-dir'.
42
+ // header includes text/html. You may use the '[public-dir]' token
43
+ // if you wish to specify this as a relative path from the 'public-dir'.
45
44
  { name: 'spa', type: String, },
46
45
  // Path to a file to be used to serve as a 404 not found page.
47
46
  // The Publisher Server will serve this file with a 404 status code
48
47
  // when the request doesn't match a known file, and the accept
49
- // header includes text/html. Specify this as a relative path
50
- // from 'root-dir'. You may use the '[public-dir]' token if you wish
51
- // to specify this as a relative path from the 'public-dir'.
48
+ // header includes text/html. You may use the '[public-dir]' token
49
+ // if you wish to specify this as a relative path from the 'public-dir'.
52
50
  { name: 'not-found-page', type: String, },
53
51
  // List of files to automatically use as index, for example, index.html,index.htm
54
52
  // If a request comes in but the route does not exist, we check the route
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "6.0.0-beta.0",
4
+ "version": "6.0.0-beta.2",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",