@fastly/compute-js-static-publish 6.0.0-beta.1 → 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,QA0c5D"}
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"}
@@ -332,10 +332,13 @@ export function initApp(commandLineValues) {
332
332
  if (staticContentRootDir == null) {
333
333
  staticContentRootDir = path.resolve(computeJsDir, './static-publisher');
334
334
  }
335
- if (staticContentRootDir.includes('//') ||
335
+ if (!staticContentRootDir.startsWith(computeJsDir) ||
336
336
  staticContentRootDir === computeJsDir ||
337
- !staticContentRootDir.startsWith(computeJsDir)) {
338
- console.error(`❌ Specified static content root directory '${staticContentRootDir}' must be under ${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
  }
@@ -421,16 +424,21 @@ export function initApp(commandLineValues) {
421
424
  fs.mkdirSync(computeJsDir);
422
425
  fs.mkdirSync(path.resolve(computeJsDir, './src'));
423
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
+ }
424
436
  // .gitignore
425
437
  const gitIgnoreContent = `\
426
438
  /node_modules
427
439
  /bin
428
440
  /pkg
429
- ${staticContentRootDirFromRoot}/statics.js
430
- ${staticContentRootDirFromRoot}/statics.d.ts
431
- ${staticContentRootDirFromRoot}/statics-metadata.js
432
- ${staticContentRootDirFromRoot}/statics-metadata.d.ts
433
- ${staticContentRootDirFromRoot}/static-content
441
+ ${staticFiles}
434
442
  `;
435
443
  const gitIgnorePath = path.resolve(computeJsDir, '.gitignore');
436
444
  fs.writeFileSync(gitIgnorePath, gitIgnoreContent, "utf-8");
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.1",
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",