Skip to content

allow tutorials and examples to remove dependencies from blocksprj#11397

Open
riknoll wants to merge 3 commits into
masterfrom
dev/riknoll/microbit-markdown-remove-dependency
Open

allow tutorials and examples to remove dependencies from blocksprj#11397
riknoll wants to merge 3 commits into
masterfrom
dev/riknoll/microbit-markdown-remove-dependency

Conversation

@riknoll

@riknoll riknoll commented Jun 11, 2026

Copy link
Copy Markdown
Member

fixes microsoft/pxt-microbit#4058

for tutorials and markdown examples, dependencies specified using the package snippet are merged into the dependencies of the default project. that's usually the behavior you want unless the package you're adding happens to conflict with a dependency of the default project.

really, this only comes up in pxt-microbit where the bluetooth extension is not compatible with the default radio extension. up until now, there hasn't been any way to write a tutorial for bluetooth.

this PR fixes that issue by allowing you to remove packages from the default config like so:

```package
radio=remove
bluetooth
```

as part of this change, i also had to fix a bunch of places in the CLI where we were lazy and added blocksprj as a dependency to the config we use when compiling blocks snippets instead of doing the right thing and cloning its pxt.json.

i think i got all of the places where the package snippets are parsed in the codebase, but it's possible i could have missed one. it would be a good idea to test some docs pages just in case

@riknoll riknoll requested a review from a team June 11, 2026 00:05
Comment thread cli/cli.ts
const host = shareId ? new Host() : new SnippetHost("decl-build", { "main.ts" : "" }, { "blocksprj": "*" });
const blocksprjConfig = readBlocksprjConfig();

const host = shareId ? new Host() : new SnippetHost("decl-build", { "main.ts" : "" }, { ...blocksprjConfig.dependencies });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need some checking around this because if readBlocksprjConfig returns undefined, trying to expand blocksprjConfig will throw an error.

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.

throwing in cli on an invalid project build seems fine, though maybe an explicit exception would narrow in a bit quicker

Comment thread cli/cli.ts
.map(l => l.replace(/\s*$/, ''))
.filter(line => !!line)
.forEach(line => {
.reduce((acc, lines) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious why this was changed?

Comment thread cli/cli.ts
const host = shareId ? new Host() : new SnippetHost("decl-build", { "main.ts" : "" }, { "blocksprj": "*" });
const blocksprjConfig = readBlocksprjConfig();

const host = shareId ? new Host() : new SnippetHost("decl-build", { "main.ts" : "" }, { ...blocksprjConfig.dependencies });

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.

throwing in cli on an invalid project build seems fine, though maybe an explicit exception would narrow in a bit quicker

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.

An error about adding Bluetooth extension to tutorial project

3 participants