Skip to content

Fix publicDirPrefix and the S3 Secret Store setup, and deprecate --public-dir and publicDirPrefix - #100

Merged
harmony7 merged 6 commits into
mainfrom
fix/scaffold-public-dir-prefix
Oct 21, 2026
Merged

harmony7 merged 6 commits into
mainfrom
fix/scaffold-public-dir-prefix

Conversation

@harmony7

@harmony7 harmony7 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR fixes three bugs in the scaffolder, and deprecates --public-dir and server.publicDirPrefix.

publicDirPrefix was always empty

If --public-dir is under --root-dir, the scaffolder must set server.publicDirPrefix to the path of the public directory, relative to the root directory (for example /public). The code sliced rootDir and not publicDir, so the value was always ''.

publish-content makes the asset keys relative to the root directory (for example /public/index.html). The server looks up publicDirPrefix + pathname (/index.html). Thus the server returned 404 for all requests.

The server already uses staticItems relative to the public directory, and spaFile and notFoundPageFile as asset keys. These values are correct, and they do not change.

The v7 branch has the same bug. I will port the fix to v7 after this PR merges.

Deprecate --public-dir

v4.0.0 separated --root-dir and --public-dir for 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-dir under --root-dir did not work in any version from v4 to v8.

This PR marks --public-dir as deprecated in the help text and in the CLI options section of README.md, and the scaffolder shows a warning if it is used. A future version will remove it.

server.publicDirPrefix exists only for this option, so it is deprecated too:

  • PublisherServerConfig.publicDirPrefix has a @deprecated tag.
  • 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.

#101 marks the setting as deprecated in README.md.

MIGRATING.md has a new section in the v7 to v8 guide, "Stop using publicDirPrefix (deprecated)", with the steps to move the files and change publish-content.config.js. The CHANGELOG entry and the publish-content warning refer to it.

Closing instructions referred to a script that does not exist

The scaffolder showed npm run fastly:start at the end. The scaffolded package.json does not have this script. The instructions now show npm run fastly:deploy. For the KV Store, they show fastly:deploy before fastly:publish, because the deploy creates the KV Store. This is the same order as the README.

S3: the Secret Store keys in fastly.toml were ignored

The scaffolder declared the keys of the S3_CREDENTIALS Secret Store under [setup.secret_stores.S3_CREDENTIALS.items.*]. The Fastly CLI reads them only from entries (see SetupSecretStore in pkg/manifest/setup.go of 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. The v7 branch 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

  • New end-to-end test in test/e2e/local.test.js: it scaffolds with --root-dir ./site --public-dir ./site/public, publishes with --local, and runs checkServedContent(). Without the fix, 9 of 13 tests fail (404). With the fix, all pass.
  • scaffoldApp() has a new rootDir option (default ./public).
  • New end-to-end test test/e2e/scaffold-s3.test.js: it scaffolds an S3 app and checks the [setup] section of fastly.toml. It needs no credentials. It fails without the fix.
  • I did not do a real first deploy, because it creates a new Fastly service. The prompt behavior comes from the Fastly CLI source (pkg/commands/compute/setup/secret_store.go).
  • test/e2e/local.test.js also checks that a default scaffold does not write publicDirPrefix.
  • Checked both deprecation warnings and the generated config by hand.
  • Did steps 2 and 4 of the migration on a scaffolded app with --local: the new index has /index.html, the stored publicDirPrefix is "", and publish-content shows no warning.
  • npm test: 72 pass.

🤖 Generated with Claude Code

harmony7 and others added 2 commits October 17, 2026 16:39
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>
@harmony7 harmony7 changed the title Fix publicDirPrefix and the closing instructions of the scaffolder Fix publicDirPrefix, the S3 Secret Store setup, and the closing instructions of the scaffolder Oct 17, 2026
@harmony7 harmony7 mentioned this pull request Oct 17, 2026
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>
@harmony7 harmony7 changed the title Fix publicDirPrefix, the S3 Secret Store setup, and the closing instructions of the scaffolder Fix publicDirPrefix and the S3 Secret Store setup, and deprecate --public-dir Oct 17, 2026
@harmony7
harmony7 requested review from a team and kpfleming and removed request for a team October 17, 2026 07:55
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>
@harmony7 harmony7 changed the title Fix publicDirPrefix and the S3 Secret Store setup, and deprecate --public-dir Fix publicDirPrefix and the S3 Secret Store setup, and deprecate --public-dir and publicDirPrefix Oct 17, 2026
harmony7 added a commit that referenced this pull request Oct 17, 2026
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>
Comment thread test/e2e/scaffold-s3.test.js Outdated
Comment on lines +38 to +39
// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/cli/commands/scaffold/index.ts Outdated
npm run fastly:start
npm run fastly:deploy

When it creates a new service, the Fastly CLI creates a Secret Store named S3_CREDENTIALS,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@harmony7
harmony7 requested a review from kpfleming October 20, 2026 05:16

@kpfleming kpfleming left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@harmony7
harmony7 merged commit 6dcf57f into main Oct 21, 2026
5 checks passed
@harmony7
harmony7 deleted the fix/scaffold-public-dir-prefix branch October 21, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants