Repository navigation
Fix publicDirPrefix and the S3 Secret Store setup, and deprecate --public-dir and publicDirPrefix - #100
Conversation
If --public-dir was under --root-dir, the scaffolder set publicDirPrefix to an empty string, because it sliced rootDir and not publicDir. The asset keys are relative to the root dir, so the server returned 404 for all requests. Add an end-to-end test that scaffolds with a public dir under the root dir and checks the served content. The closing instructions referred to "npm run fastly:start", which does not exist. Show "npm run fastly:deploy". For the KV Store, show it before "npm run fastly:publish". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The Fastly CLI reads the keys of a Secret Store in [setup] from "entries". The scaffolder wrote them under "items", which the CLI ignores. Thus, on the first deploy, the CLI created the S3_CREDENTIALS Secret Store with no keys and did not prompt for the credentials. The closing instructions told the user to create the Secret Store before the deploy. Then the first deploy finds a store with that name. Now they tell the user that the first deploy prompts for the values, and that an existing service needs the Secret Store before the deploy. Add an end-to-end test that scaffolds an S3 app and checks the [setup] section of fastly.toml. It needs no credentials. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
v4.0.0 added --public-dir under --root-dir for module assets, which this package no longer supports. Since then, the scaffolder always wrote an empty publicDirPrefix, so the option did not work in any version. Mark it as deprecated in the help text and in README.md, and show a warning if it is used. A future version will remove it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
server.publicDirPrefix exists only for --public-dir, which is deprecated. A future version will remove both. - Mark the setting as deprecated in PublisherServerConfig. - publish-content shows a warning if the setting is not empty. - The scaffolder writes the setting only if it is not empty, that is, only with --public-dir. The server still uses the setting, because collections that are in storage can have it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Remove it from the example publish-content.config.js, because the scaffolder no longer writes it (see #100). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Add a section to the v7 to v8 guide, and refer to it from the CHANGELOG.md entry and from the warning of publish-content. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| // The Fastly CLI reads the keys of a Secret Store from "entries". It ignores | ||
| // other names, and then creates the Secret Store with no keys. |
There was a problem hiding this comment.
The second sentence of this comment is misleading; it described the situation before this PR, for an example in the setup guide. It should not be here. Please be more careful when reviewing LLM-generated code and in particular tell the LLM to never generate code comments which describe why a change was made or how the code worked before it was changed. These comments are not useful and could be misleading.
| npm run fastly:start | ||
| npm run fastly:deploy | ||
|
|
||
| When it creates a new service, the Fastly CLI creates a Secret Store named S3_CREDENTIALS, |
There was a problem hiding this comment.
This is not appropriate to fix in this PR, but all of the references to/discussion of Secret Store naming in this section (and possibly other places) are wrong. The name of the Secret Store is not relevant except in local testing; in production, what matters is the name of the resource link which connects the Compute service to the Secret Store. While those names can be the same, they are not required to be the same, and a user should be informed about the existence of both names and understand that they do not need to name their Secret Store S3_CREDENTIALS (doing so in a CID with lots of services and Secret Stores would result in a name which doesn't provide sufficient meaning to know what it is used for).
There was a problem hiding this comment.
In a future update to the CLI, the setup and local_server sections should make this apparent by having resource_links, but that's also a topic for elsewhere.
There was a problem hiding this comment.
I'm going to fix the wording where I can here in this PR because it has to do with S3 Secret Store setup, and this is a new feature for v8.
Summary
This PR fixes three bugs in the scaffolder, and deprecates
--public-dirandserver.publicDirPrefix.publicDirPrefixwas always emptyIf
--public-diris under--root-dir, the scaffolder must setserver.publicDirPrefixto the path of the public directory, relative to the root directory (for example/public). The code slicedrootDirand notpublicDir, so the value was always''.publish-contentmakes the asset keys relative to the root directory (for example/public/index.html). The server looks uppublicDirPrefix + pathname(/index.html). Thus the server returned 404 for all requests.The server already uses
staticItemsrelative to the public directory, andspaFileandnotFoundPageFileas asset keys. These values are correct, and they do not change.The
v7branch has the same bug. I will port the fix tov7after this PR merges.Deprecate
--public-dirv4.0.0 separated
--root-dirand--public-dirfor module assets: files under the root dir but not under the public dir were published, but requests could not get them. This package no longer supports module assets. The scaffolder bug above was in the first commit of this change, so--public-dirunder--root-dirdid not work in any version from v4 to v8.This PR marks
--public-diras deprecated in the help text and in the CLI options section ofREADME.md, and the scaffolder shows a warning if it is used. A future version will remove it.server.publicDirPrefixexists only for this option, so it is deprecated too:PublisherServerConfig.publicDirPrefixhas a@deprecatedtag.publish-contentshows a warning if the setting is not empty.--public-dir.#101 marks the setting as deprecated in
README.md.MIGRATING.mdhas a new section in the v7 to v8 guide, "Stop usingpublicDirPrefix(deprecated)", with the steps to move the files and changepublish-content.config.js. The CHANGELOG entry and thepublish-contentwarning refer to it.Closing instructions referred to a script that does not exist
The scaffolder showed
npm run fastly:startat the end. The scaffoldedpackage.jsondoes not have this script. The instructions now shownpm run fastly:deploy. For the KV Store, they showfastly:deploybeforefastly:publish, because the deploy creates the KV Store. This is the same order as the README.S3: the Secret Store keys in
fastly.tomlwere ignoredThe scaffolder declared the keys of the
S3_CREDENTIALSSecret Store under[setup.secret_stores.S3_CREDENTIALS.items.*]. The Fastly CLI reads them only fromentries(seeSetupSecretStoreinpkg/manifest/setup.goof the Fastly CLI). Thus, on the first deploy, the CLI created and linked a Secret Store with no keys, and it did not prompt for the credentials. The server then could not read from the bucket. Thev7branch does not have S3 support, so it does not have this bug.The closing instructions also told the user to create the Secret Store before the deploy. With
[setup]working, the first deploy then finds a store with that name and asks for a different name. Now the instructions say that the first deploy prompts for the values, and that an existing service needs the Secret Store before the deploy.Tests
test/e2e/local.test.js: it scaffolds with--root-dir ./site --public-dir ./site/public, publishes with--local, and runscheckServedContent(). Without the fix, 9 of 13 tests fail (404). With the fix, all pass.scaffoldApp()has a newrootDiroption (default./public).test/e2e/scaffold-s3.test.js: it scaffolds an S3 app and checks the[setup]section offastly.toml. It needs no credentials. It fails without the fix.pkg/commands/compute/setup/secret_store.go).test/e2e/local.test.jsalso checks that a default scaffold does not writepublicDirPrefix.--local: the new index has/index.html, the storedpublicDirPrefixis"", andpublish-contentshows no warning.npm test: 72 pass.🤖 Generated with Claude Code