Use an external SDK root
By default builder execute runs schematics against the @pbuilder/sdk installed in the
workspace’s node_modules. An external SDK root points the run at an @pbuilder/sdk
package directory somewhere else, typically a global install, so you can run schematics
without adding the SDK to the project’s package.json.
Three sources can name that directory. They share the same validation, the same link and the same diagnostics.
| Source | Scope | Set it with |
|---|---|---|
--sdk-root=<dir> |
One run | A flag before <collection>:<schematic> |
BUILDER_SDK_ROOT |
Every run in that environment | An environment variable |
sdk.root |
Every run in that project | project-builder.json |
Choose the directory
Section titled “Choose the directory”The value is the package directory itself, the one whose package.json has the name
@pbuilder/sdk. Its dependencies must resolve from a node_modules at or above it, which
a normal install gives you.
| Install | Directory |
|---|---|
npm install -g @pbuilder/sdk |
<npm root -g>/@pbuilder/sdk |
bun add -g @pbuilder/sdk |
~/.bun/install/global/node_modules/@pbuilder/sdk |
npm install @pbuilder/sdk in a separate folder |
<folder>/node_modules/@pbuilder/sdk |
Copying only the package directory elsewhere fails, because its dependencies are left behind (see When it fails).
Name the root for one run
Section titled “Name the root for one run”-
Install the SDK outside the project, for example in a folder of its own:
Terminal window mkdir ~/sdk-0.22.0 && cd ~/sdk-0.22.0npm init -y -
Pass the package directory before the schematic:
Terminal window builder execute --sdk-root="$HOME/sdk-0.22.0/node_modules/@pbuilder/sdk" default:helloThe flag must come before
<collection>:<schematic>. After it, the run fails withinvalid_inputand exit 2 (flag --sdk-root must come before the <collection>:<schematic> positional). -
Check which SDK the run used.
executecreated one entry in the workspace, a symbolic link:Terminal window readlink node_modules/@pbuilder/sdk
A run with --dry-run writes nothing, so it creates no link and no node_modules.
Name the root for every run
Section titled “Name the root for every run”Set the variable once, in your shell profile or in the environment of your editor or agent:
export BUILDER_SDK_ROOT="$HOME/sdk-0.22.0/node_modules/@pbuilder/sdk"builder execute default:helloA shell expands ~ when you assign the variable, but a value quoted in the shell, or written
into a settings file that does not expand it, keeps the ~ literally and fails with
sdk_root_unresolvable. Write the full path there. An empty BUILDER_SDK_ROOT counts as
unset.
Every run that takes the root from the variable prints a warning that names the variable and never the path:
sdk root came from BUILDER_SDK_ROOTIn the JSON envelope the same warning is warn_sdk_root_ambient. A root named by
--sdk-root or sdk.root prints no such warning.
Name the root in the project
Section titled “Name the root in the project”Add sdk.root to project-builder.json:
{ "sdk": { "root": "/Users/me/sdk-0.22.0/node_modules/@pbuilder/sdk" }}An absolute path is used as is. A relative path resolves against the directory that holds
project-builder.json, so "../sdk-0.22.0/node_modules/@pbuilder/sdk" works too. The value
is checked when execute runs, not when the file is read.
Which source wins
Section titled “Which source wins”execute takes the SDK from the first of these that is set:
--sdk-rootBUILDER_SDK_ROOTsdk.root- The workspace’s installed
node_modules/@pbuilder/sdk
A source that is set but unusable fails the run. execute never falls back to a lower one:
with BUILDER_SDK_ROOT pointing at a missing directory and a valid sdk.root, the run
fails with sdk_root_unresolvable instead of using sdk.root.
The same order applies to builder new schematic, which needs no prior execute and creates
no link. builder info reads none of the three.
What execute changes in the workspace
Section titled “What execute changes in the workspace”When a run commits, execute creates one entry, node_modules/@pbuilder/sdk, as a symbolic
link to the canonical root. It creates node_modules/ and node_modules/@pbuilder/ when
they are missing, and writes nothing else. Running again with the same root reuses the link,
and naming another root repoints it.
Two consequences follow:
- The link is not a package-manager install, so there is no
node_modules/.bin/pbuilder-codegenshim. See Type generation. - A
--dry-runthat finds a link pointing at a different SDK than the one you named fails withexecute_dry_run_sdk_link_stale. Run without--dry-runto repoint the link, or delete it.
Go back to the workspace’s own SDK
Section titled “Go back to the workspace’s own SDK”Removing the flag, the variable or sdk.root does not remove the link. The next execute
without an external root fails with execute_manifest_path_escape (exit 3), because the
leftover link points outside the workspace. Confirm the entry is a symbolic link, never a
directory, and delete it:
test -L node_modules/@pbuilder/sdk && rm node_modules/@pbuilder/sdkIf node_modules/@pbuilder/sdk is a real installed package that differs from the root you
named, execute fails with execute_sdk_link_path_conflict and changes neither. Delete the
installed copy to use the root, or stop naming a root to use the installed one. Before you
set BUILDER_SDK_ROOT for every checkout, remove the SDK installed in each of them.
When it fails
Section titled “When it fails”Every row below was reproduced on builder v0.19.12 with @pbuilder/sdk 0.22.0. The
message names the source that supplied the value (--sdk-root, BUILDER_SDK_ROOT or
sdk.root) and never prints the path.
| Situation | Code | Reason | Exit |
|---|---|---|---|
| No source set and no installed SDK | execute_sdk_not_installed |
sdk_absent |
4 |
Directory does not exist, or ~ left literal |
execute_sdk_root_invalid |
sdk_root_unresolvable |
4 |
Directory is not @pbuilder/sdk (wrong package name, or the folder above the package) |
execute_sdk_root_invalid |
sdk_root_package_mismatch |
4 |
--sdk-root= with no value |
execute_sdk_root_invalid |
sdk_root_value_invalid |
4 |
Value starts with a URL scheme such as https:// |
execute_sdk_root_invalid |
sdk_root_unsupported_scheme |
4 |
| Package copied without its dependencies | execute_sdk_root_invalid |
sdk_root_dependencies_unresolvable |
4 |
A real, different SDK in node_modules/@pbuilder/sdk |
execute_sdk_link_path_conflict |
sdk_root_local_install_present |
4 |
--dry-run with a link to another SDK |
execute_dry_run_sdk_link_stale |
sdk_link_on_factory_path |
4 |
| Leftover link and no source set | execute_manifest_path_escape |
path_escapes_workspace |
3 |
--sdk-root after the positional |
invalid_input |
input_invalid |
2 |
For example, pointing --sdk-root at a directory whose package.json has another name
prints this in the pretty output:
✗ [SDK] the directory named by --sdk-root is not @pbuilder/sdk execute_sdk_root_invalid Fix: point --sdk-root at the package directory whose package.json name is "@pbuilder/sdk"One warning does not stop the run. If a directory above the root is writable by its group,
execute continues and prints warn_sdk_root_group_writable, for example
a directory 3 levels above --sdk-root is group-writable; anyone in that group can replace the SDK. Remove the group write bit with chmod g-w, or move the SDK under a directory
only you can write to.
Related
Section titled “Related”--sdk-rootandBUILDER_SDK_ROOTand External SDK root: the reference summary, including what the root must satisfy.- SDK diagnostics: every SDK error code and reason.
- External collections: share one set of schematics across checkouts, which usually goes together with a shared SDK root.
- Evaluate without adopting the SDK: use an SDK in a
checkout without editing
package.json.