How can I omit slice component booting?

We are using Hanami 2.
We have both a not-slice component and a slice component in our codebase.
We would like to know how to boot only the not-slice component.

For example, even if our codebase contains both the not-slice component and the slice component, we want to boot only the not-slice component.
How can we achieve this?

We have tried setting HANAMI_SLICES=“” in the environment, but we encountered an error because even though our codebase has a slice component, the HANAMI_SLICES environment variable is empty.

Setting an empty HANAMI_SLICES will do this, see for instance my CI make target:

.PHONY: ci
ci: export HANAMI_ENV := test
ci: ## setup database and run test suite
	$(RAKE) db:test:prepare
	HANAMI_SLICES= $(RSPEC) --tag ~slice
	HANAMI_SLICES=ciam $(RSPEC) --tag slice
	HANAMI_SLICES=oauth $(RSPEC) --tag slice
	HANAMI_SLICES=scim $(RSPEC) --tag slice

Can you provide some more detail about how your components are structured, and what is going wrong exactly?

Thank you for your fast reply!

And I’m sorry for my ambiguous question.

I want to talk about not test, but normal booting.

root/
 ├ app/
 │ └ actions/
 │ └ actions.rb
 ├ config/
 │ └ app.rb
 │ └ routes.rb
 ├ lib/
 ├ slices/
 │ └ admin/
 │   └ actions/

module Bookshelf
  class Routes < Hanami::Routes
    scope "v1" do
      use Rack::Auth::Basic
      get "/page" do
        "Some restricted content"
      end
    end

    slice :admin, at: "/admin" do
      use Rack::Auth::Basic

      get "/books", to: "books.index"
    end
  end
end
export HANAMI_SLICES=

When we access /v1/page, we got the following error.(We don’t get the error just after booting my app.)

Hanami::SliceLoadError: Slice 'admin' not found
bundle exec hanami c
> config.slices
=> []

Ah yes, you are running into this problem.

This is a reminder that I need to make the time to work on a resolution for this. In the meantime, you can follow the mitigation I used:

require "hanami/slice/router"

class RouteResolver < Hanami::Slice::Routing::Resolver
  def excluding?(slice_name)
    if slices && slice_dirs.include?(slice_name)
      slice_name = slice_name.to_s
      slices.none? { _1 == slice_name }
    else
      false
    end
  end

  private

  def slices = slice.config.slices

  def slice_dirs
    @_slice_dirs ||=
      Dir[slice.root / "slices" / "*"]
      .select { |path| File.directory?(path) }
      .map { |path| File.basename(path).to_sym }
  end
end

module SliceRouting
  def slice(slice_name, ...)
    return if @resolver.excluding?(slice_name)

    super
  end
end

Hanami::Slice::Router.prepend SliceRouting

class App < Hanami::App
  config.router.resolver = RouteResolver
end

@alassek

That’s right!

Thank you for your kind guidance.

I’ll wait for the fix!!