Skip to content

set engineStrict config when package manager is pnpm - #1344

Open
pluxain wants to merge 21 commits into
sveltejs:mainfrom
pluxain:f/engine-strict-pnpm
Open

pluxain wants to merge 21 commits into
sveltejs:mainfrom
pluxain:f/engine-strict-pnpm

Conversation

@pluxain

@pluxain pluxain commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Closes #1341

Description

Following the allowBuilds approach, we add the engineStrict config to the pnpm-workspace.yml if it is not already set.

Checklist

  • Update snapshots (if applicable)
  • Add a changeset (if applicable)
  • Allow maintainers to edit this PR
  • I care about what I'm doing, no matter the tool I use (Notepad, Sublime, VSCode, AI...)

@pkg-svelte-dev

pkg-svelte-dev Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Install the latest version of sv from cdf5b97:

pnx https://pkg.svelte.dev/sv/c/cdf5b97d30801144fcec6b82ad3c2a94416e00f0 create

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/cli/pr/1344

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cdf5b97

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sv Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pluxain

pluxain commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi, this is my first attempt to contribute to the project. I followed what was done for allowBuilds.

I miss some things though: for instance I could not run the branch locally to see if the generated project output was correct.

I also do not know if I should regenerate the snapshots or the changeset.

Any guidance is welcome! Cheers!

Comment thread packages/sv/src/cli/create.ts Outdated
@pluxain
pluxain marked this pull request as draft September 30, 2026 07:27
@sacrosanctic

sacrosanctic commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

allowBuilds is public because add-on developers would use it for their own app. But I don't see why this needs to be public. It's just for scaffolding brand now templates.

As an aside, I didn't want to fix it cause the whole create logic should be rewritten which would make this a no brainer fix.

@manuel3108

Copy link
Copy Markdown
Member

Hi, this is my first attempt to contribute to the project

Thanks for helping out!

I miss some things though: for instance I could not run the branch locally to see if the generated project output was correct.

What exactly was not working? Im pretty sure we are just missing something CONTRIBUTING.md

Snapshots should indeed be regenerated. Also a changeset is required here, since this is a public facing change, otherwise no new release will be triggered.

@pluxain

pluxain commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

What exactly was not working? Im pretty sure we are just missing something CONTRIBUTING.md

CONTRIBUTING.md says:

## Build and run

To build the project and all packages. Run the 'build' script:

```sh
# from root of project
pnpm build
```

This outputs into /packages/PACKAGE/dist/.

Run the 'cli' package:

```sh
pnpm sv
pnpm sv create
pnpm sv add
pnpm sv migrate
pnpm sv check
pnpm sv help
```

So I thought I should buid the project locally and run pnpm sv create but then I get this output:

[ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL] Command "sv" not found

@pluxain

pluxain commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Also, when I try to regenerate the snapshots, using this (taken from the CONTRIBUTING.md file again):

pnpm build && pnpm test --project cli --update all

I receive this output and it runs forever:

$ vitest run --silent --project cli --update all

 RUN  v4.1.8 /home/calou/dev/@sveltejs/cli

│
■  The --tasks values all and prerequisite cannot be combined with other tasks.
│
└  Operation failed.

│
■  The --tasks values all and prerequisite cannot be combined with other tasks.
│
└  Operation failed.

│
■  Unknown migration task: missing
│  Available tasks: svelte-config, env-vars
│
└  Operation failed.

 ✓  cli  tests/migrate.ts (13 tests) 19ms

 ❯  cli  tests/cli.ts 2/5

 Test Files 1 passed (2)
      Tests 15 passed (18)
   Start at 14:55:24
   Duration 138.01s

@sacrosanctic

Copy link
Copy Markdown
Contributor

That's a visual bug. I fixed it in the other PR.

@sacrosanctic

Copy link
Copy Markdown
Contributor

[ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL] Command "sv" not found

This should work. What version of pnpm are you on and what folder did you run it in. Should be pnpm 11 and root respectively.

@pluxain

pluxain commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

run at the root of the project:

 pnpm --version

gives

11.27.1

(I removed the warning about packageManager and devEngines.packageManager specifying a different version.

But anywhere else on my machine:

 pnpm --version

yields

12.4.2

@jycouet

jycouet commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

TBH, I never use pnpm sv but always pnpm build && node ./packages/sv/dist/bin.mjs (from repo root).
Like this I'm using "raw node". I also had issues in the past with pnpm sv with a global installation.

Maybe we should tweak this in the readme? WDYT?

@sacrosanctic

Copy link
Copy Markdown
Contributor

pnpm bootstraps node to the correct version we pinned. Which also means pnpm sv works whether you have a different version installed in global or none installed at all.

I think pnpm 11 works a lot better so I rather triage the problem.

Comment thread packages/sv-utils/src/pnpm-internals.ts Outdated
Comment thread packages/sv-utils/src/pnpm.ts Outdated
Comment thread packages/sv/src/cli/create.ts Outdated
@pluxain

pluxain commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

allowBuilds is public because add-on developers would use it for their own app. But I don't see why this needs to be public. It's just for scaffolding brand now templates.

As an aside, I didn't want to fix it cause the whole create logic should be rewritten which would make this a no brainer fix.

Hi Scott,

Do you mean in this case everything should happen in addEngineStrictIfPnpm ?

I tried to follow the approach for allowBuilds as I wasn't sure of why it is structure like that.

As I stated in my comment, I would rather have the engineStrict added in the pnpm-workspace.yml with allowBuilds in one go to avoid writing the file over. I do not want to have a misleading name addAllowBuildsIfPnpm which also have a side effect on engineStrict config. What do you say ?

@sacrosanctic

sacrosanctic commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Do you mean in this case everything should happen in addEngineStrictIfPnpm ?

Yes, keep it private.

one go to avoid writing the file over

You can write to the same file multiple times. We do it all the time in this codebase.

@manuel3108
manuel3108 changed the base branch from version-1 to main October 3, 2026 08:04
@pluxain
pluxain force-pushed the f/engine-strict-pnpm branch from be05ed9 to ad3bd63 Compare October 5, 2026 07:25
Comment thread .changeset/early-kiwis-drum.md Outdated
Comment thread packages/sv-utils/src/pnpm-internals.ts Outdated
Comment thread packages/sv-utils/src/pnpm.ts Outdated
Comment thread packages/sv/src/core/package-manager.ts Outdated
Comment thread .changeset/early-kiwis-drum.md Outdated
@pluxain

pluxain commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

I wanted to add one test for pnpm. My guess was to add it in the cli tests like so:

{ projectName: 'create-pnpm', args: ['--no-add-ons', '--install pnpm'] }

as my understanding is that we set the package manager throught the --install arg. But this does not work as those tests already have a --no-install which makes sense.

Is there another way to set the package manager for a create command without installing dependencies ?

If not, that would be nice to be able to select a package manager on its own and still be able not to install dependencies.

@sacrosanctic

Copy link
Copy Markdown
Contributor

I'd like that too, im not sure how to current behaviour works. Can you look around and test it out. At the very least, we can document this.

@pluxain

pluxain commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

I'll have a look. In the meantime, maybe we could try to hijack the install step while in testing, running dry runs to avoid actually installing dependencies on disk. Not sure if viable and/or wanted and/or feasible.

@pluxain

pluxain commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

I looked into the testing process for the cli and I do not think that covering this PR is possible as it is unfortunately.

@sacrosanctic

Copy link
Copy Markdown
Contributor

Ok, just summarize your findings and remove the draft status.

@pluxain pluxain changed the title WIP: set engineStrict config when package manager is pnpm set engineStrict config when package manager is pnpm Oct 9, 2026
@pluxain
pluxain marked this pull request as ready for review October 9, 2026 04:55
@pluxain
pluxain force-pushed the f/engine-strict-pnpm branch from e058ed6 to 8cf1fdd Compare October 9, 2026 04:57
jycouet and others added 8 commits October 9, 2026 09:37
find.up() can walk past the project and edit e.g. ~/.npmrc or a parent
workspace. A fresh scaffold owns its root, so path.join(cwd, ...) is enough.
A function that returns a transform and is called right away adds a layer
without adding meaning. `transforms.x(fn)(content)` reads top to bottom.
upsert already skips `key=` when present. The includes() check was
redundant and would also match a commented-out line.
addEngineStrict already branches on the package manager, so the helpers
don't need to re-check it. Only the entry point is used outside this file.
The same 3 lines appeared in every helper. One place to get it right,
and each helper now only says *which* file and *what* change.
The JSDoc restated the function names. The one useful fact is why pnpm
gets a different file, so that's the comment that stays.
Users care about the result (which file gets the setting), not that
.npmrc is now written by code instead of copied from the template.
Code inprovements in general and making the approach centralized and better organized.
@sacrosanctic

Copy link
Copy Markdown
Contributor

demo template also has a .npmrc

@pluxain

pluxain commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Yes, and it was removed here

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.

Set engine-strict config in pnpm as well

4 participants