Skip to content

refactor: init now expects templates to have react-native version set - #2422

Merged
blakef merged 2 commits into
mainfrom
feat/target-minor-template
Jun 21, 2024
Merged

refactor: init now expects templates to have react-native version set#2422
blakef merged 2 commits into
mainfrom
feat/target-minor-template

Conversation

@blakef

@blakefblakef commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

Summary:

This will take advantage of changes coming in the way we publish the template: react-native-community/template/pull/30

refactor: init now expects templates to have react-native version set
For 0.75's previous RCs, we didn't have the infrastructure in place to
tag @react-native-community/templates 0.75-stable branch correctly, as
well as publishing the corresponding version to npm.
For example:
If @react-native-community/template@0.75.1 is the latest version
published, and I specified --version next: I'd expect 0.75.1 of the
template to be used with 0.75.1 of react-native.
The downside of this approach is, if you init an older version then
things might not work. You'd have to specify the matching template
using --template @react-native-community/template@<some version>. Given
that init is intended for new projects this isn't a concern for most
users.
We could look at abusing the `scripts` field to expose the corresponding
version of react native in the npm registry:
https://registry.npmjs.org/@react-native-community/template
Something like: "scripts": { "version": "0.75.1-rc.2" }

Test Plan:

TODO: Run each of the combinations of the update table in the code. Might be difficult to do with unpublished @react-native-community/template npm packages published.

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@blakefblakef changed the title fix: only show warning about --template & --version when necessaryrefactor: init now expects templates to have react-native version setJun 20, 2024
@cortinico

Copy link
Copy Markdown
Member

@blakef let's make the CI green? 👍

@blakef
blakefforce-pushed the feat/target-minor-template branch from dc419de to d709c04CompareJune 21, 2024 10:15
Comment threadpackages/cli/src/commands/init/init.ts Outdated
@blakef
blakefforce-pushed the feat/target-minor-template branch from d709c04 to d55f6f9CompareJune 21, 2024 10:36
Comment threadpackages/cli/src/commands/init/init.ts Outdated
@blakef
blakefforce-pushed the feat/target-minor-template branch from d55f6f9 to 315dc0aCompareJune 21, 2024 12:44
@blakef

Copy link
Copy Markdown
ContributorAuthor

I've made the changes requested and tested against:

TestOutcomeNotes
node ./packages/cli/build/bin.js init TestInit --skip-install --version next❌ but expectedUses the 0.75.0-rc.0 version of the template which has the node modules issue
node ./packages/cli/build/bin.js init TestInit --skip-install --version 0.75.0-rc.0❌ but expectedUses the 0.75.0-rc.0 version of the template which has the node modules issue
node ./packages/cli/build/bin.js init TestInit --skip-install --version next --template @react-native-community/template@0.0.4It won't build, but the project generates correctly - React Native is 1000.0.0
node ./packages/cli/build/bin.js init TestInit --skip-install --template @react-native-community/template@0.0.4It won't build, but the project generates correctly - React Native is 1000.0.0

The depends on react-native-community/template#30 having published artefacts.

blakef added a commit to react-native-community/template that referenced this pull request Jun 21, 2024
)
There was a discussion on Discord, where we looked at implementing what was originally proposed. This is that implementation. It'll need to land with a [cli](react-native-community/cli#2422) change to use the update template + tagging.
- feat: add mutating react-native & @react-native/ packages
Support for doing this on nightly and release workflows
- feat: added node ./scripts/updateReactNativeVersion.js <version>
Sets the version of react-native and the @react-native/ scoped packages.
It will also normalize tags to concrete versions. E.g. latest -> 0.74.2
- refactor: move scripts into a ./scripts folder
cortinico pushed a commit to react-native-community/template that referenced this pull request Jun 21, 2024
)
There was a discussion on Discord, where we looked at implementing what was originally proposed. This is that implementation. It'll need to land with a [cli](react-native-community/cli#2422) change to use the update template + tagging.
- feat: add mutating react-native & @react-native/ packages
Support for doing this on nightly and release workflows
- feat: added node ./scripts/updateReactNativeVersion.js <version>
Sets the version of react-native and the @react-native/ scoped packages.
It will also normalize tags to concrete versions. E.g. latest -> 0.74.2
- refactor: move scripts into a ./scripts folder
// all version before 0.75. The 1st release candidate is the minimal version that has no template.
const useLegacyTemplate = semver.lt(
version,
TEMPLATE_COMMUNITY_REACT_NATIVE_VERSION,

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.

This is 0.75.0-rc.0 so I'm unsure how this will work out with lt.
Should we just instead compare the minor from semver and do <= 74?

// Suppose react-native 0.75.0 was released, and 0.74.8 was the previous version. If I ran
// `init --version 0.74.8` it would be guaranteed to work with the latest version of the template
// matching the MAJOR.MINOR, e.g. 0.74.21.
return `${TEMPLATE_PACKAGE_COMMUNITY}@~${version}`;

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.

Here you should recompose the version no?

As what's going to happen if version is 0.75.0-rc.0?
What will ~0.75.0-rc.0 resolve? It should be ~0.75.0 instead.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm adding a branch for nightly which is the only tag that doesn't play nicely with ~.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I've made the changes requested and tested against:

TestOutcomeNotes
node ./packages/cli/build/bin.js init TestInit --skip-install --version nightly
node ./packages/cli/build/bin.js init TestInit --skip-install --version next❌ but expectedUses the 0.75.0-rc.0 version of the template which has the node modules issue
node ./packages/cli/build/bin.js init TestInit --skip-install --version 0.75.0-rc.0❌ but expectedUses the 0.75.0-rc.0 version of the template which has the node modules issue
node ./packages/cli/build/bin.js init TestInit --skip-install --version next --template @react-native-community/template@0.0.4It won't build, but the project generates correctly - React Native is 1000.0.0
node ./packages/cli/build/bin.js init TestInit --skip-install --template @react-native-community/template@0.0.4It won't build, but the project generates correctly - React Native is 1000.0.0

The depends on react-native-community/template#30 having published artefacts.

blakef added 2 commits June 21, 2024 15:46
For 0.75's previous RCs, we didn't have the infrastructure in place to
tag @react-native-community/templates 0.75-stable branch correctly, as
well as publishing the corresponding version to npm.
For example:
If @react-native-community/template@0.75.1 is the latest version
published, and I specified --version next: I'd expect 0.75.1 of the
template to be used with 0.75.0-rc.1 of react-native.
The downside of this approach is, if you init an older version then
things might not work. You'd have to specify the matching template
using --template @react-native-community/template@<some version>. Given
that init is intended for new projects this isn't a concern for most
users.
We could look at abusing the `scripts` field to expose the corresponding
version of react native in the npm registry:
https://registry.npmjs.org/@react-native-community/template
Something like: "scripts": { "version": "0.75.1-rc.2" }
Useful to see the error message instead of swallowing it if the user
enables `--verbose`.
@blakef
blakefforce-pushed the feat/target-minor-template branch from 315dc0a to 9ac0e05CompareJune 21, 2024 14:46
@blakef
blakef marked this pull request as ready for review June 21, 2024 14:59
@blakef
blakef merged commit 2f4d63b into mainJun 21, 2024
@blakef
blakef deleted the feat/target-minor-template branch June 21, 2024 14:59
Sign up for freeto 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.

3 participants

@blakef@cortinico@cipolleschi