Skip to content

feat: take the template source as an fs.FS - #66

Merged
alecthomas merged 3 commits into
block:mainfrom
jvmakine:juho/scaffold-fs
Oct 22, 2026
Merged

alecthomas merged 3 commits into
block:mainfrom
jvmakine:juho/scaffold-fs

Conversation

@jvmakine

@jvmakine jvmakine commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Templates embedded in a binary with embed.FS currently have to be copied to a temporary directory before scaffolding, because the walk reads only from disk.

Scaffold now takes the template as an fs.FS. This is a breaking change:

  • Pass os.DirFS(dir) for a local directory.
  • Remote sources are fetched with the new Open(ctx, source), which returns an fs.FS and a cleanup function. It also accepts a local directory. WithContext now cancels scaffolding, since fetching takes its context from Open.
  • Config.Source() returns the fs.FS, and Exclude patterns match slash-separated paths relative to the source root.
  • The JavaScript extension reads a relative script path from the source and an absolute one from disk. The CLI passes --script relative to the template when it is inside it, so it is still left out of the output.

Symbolic links are read with fs.ReadLink, so they work for any fs.ReadLinkFS such as os.DirFS and fstest.MapFS. Files keep the permissions the source reports, so embed.FS files come out read-only unless an AfterEach changes them.

🤖 Generated with Claude Code

Templates embedded in a binary with embed.FS had to be copied to a temporary
directory before scaffolding, because the walk read only from disk.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jvmakine
jvmakine requested a review from alecthomas as a code owner October 22, 2026 04:06
Comment thread scaffolder.go
Having one source type keeps a single scaffolding path for directories,
embedded files, and fetched remote sources.

BREAKING CHANGE: Scaffold takes an fs.FS, ScaffoldFS and WithContext are
removed, remote sources are opened with Open, and Config.Source returns an
fs.FS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jvmakine jvmakine changed the title feat: scaffold from an fs.FS feat!: take the template source as an fs.FS Oct 22, 2026
Comment thread scaffolder.go
}

// WithContext sets the context for remote source fetching via getit.
func WithContext(ctx context.Context) Option {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we want to get rid of this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤖 Restored. Since fetching now takes its context from Open, WithContext cancels scaffolding itself: it's checked before each entry.

@alecthomas alecthomas changed the title feat!: take the template source as an fs.FS feat: take the template source as an fs.FS Oct 22, 2026
@jvmakine
jvmakine marked this pull request as draft October 22, 2026 04:20
Callers that already pass a context should still be able to stop a large
scaffold, now that fetching moved to Open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jvmakine
jvmakine marked this pull request as ready for review October 22, 2026 04:22
@alecthomas
alecthomas merged commit b71c883 into block:main Oct 22, 2026
6 checks passed
@jvmakine
jvmakine deleted the juho/scaffold-fs branch October 22, 2026 04:25
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