-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to fall back on regex parsing to splitAddress1 #281
Conversation
4a91ae4
to
7cd3b5f
Compare
67847ed
to
4162f5f
Compare
lang/typescript/src/extended-address/splitAddress1WithFallback.test.ts
Outdated
Show resolved
Hide resolved
lang/typescript/src/extended-address/splitAddress1WithFallback.ts
Outdated
Show resolved
Hide resolved
lang/typescript/CHANGELOG.md
Outdated
## 0.7.0-next.0 | ||
|
||
### Minor Changes | ||
|
||
- 1f5d405: Add optional experimentalRegexFallback param to splitAddress1 function to attempt splitting address lines that do not contain the reserved delimiter | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you follow these docs to generate the prerelease? https://github.com/changesets/changesets/blob/main/docs/prereleases.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it was but I don't see the package published as a prerelease on NPM so might have to change something in the GH Actions to actually do it https://www.npmjs.com/package/@shopify/worldwide?activeTab=versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I skipped the publish step for now - wasn't sure if that should happen after this PR merges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to read the prerelease again but I though they recommended not merging something in prerelease mode to the main/default branch and rather just have it deploy from a separate branch, then exit prerelease mode before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yeah changesets does recommend using a second branch when doing prereleases just so the main branch isn't locked up in prerelease mode. Given we don't make that many changes to this library and we won't be in prerelease for long thats probably still fine to just lock up the main branch but I'd rather not if we don't have to so main
stays in a releasable state that reflects the latest version.
We can try to run the publish on this branch, we'll need to modify the GH action to also run on this branch though so the job that handles publishing will run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 If we want to do the prerelease I still recommend trying to publish the prerelease from this branch instead of merging though as the changesets docs recommend.
lang/typescript/.changeset/pre.json
Outdated
"mode": "pre", | ||
"tag": "next", | ||
"initialVersions": { | ||
"@shopify/worldwide": "0.6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "0.7.0"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is the initial version before the pre-release. I looked at the tests in changesets, you can see they've set up the initial package versions here, and this is the version that appears in the release plan's initialVesrions
https://github.com/changesets/changesets/blob/c867f32d0c25cfb2a6b518bc1f9880f758beb157/packages/assemble-release-plan/src/index.test.ts#L908
@@ -192,6 +192,21 @@ class RegionYmlConsistencyTest < ActiveSupport::TestCase | |||
end | |||
end | |||
|
|||
test "address1_regex capture groups must belong to a limited set of allowed names" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👨🍳 👌
test('creates an address object from string matching one of the defined regexes', () => { | ||
const fieldDefinition: FieldConcatenationRule[] = [ | ||
{key: 'streetName'}, | ||
{key: 'streetNumber'}, | ||
]; | ||
const regexPatterns = [ | ||
new RegExp('^(?<streetName>[^\\d]+) (?<streetNumber>\\d+)$'), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you update this test to have 2 regexPatterns, with the first not a match and the second a match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, Gaby! Left a couple comments, non-blocking.
76d8165
to
7829478
Compare
The pre-release is now published as v0.7.0-next.0. Next steps:
|
5222d46
to
ed6edce
Compare
- bbacde1: Add address1 regex for BE, BR, CL, ES, IL, MX | ||
- b6e1c7f: Add address1 regex for DE | ||
- ee7b7a9: Add optional tryRegexFallback param to splitAddress1 function to attempt splitting address lines that do not contain the reserved delimiter | ||
|
||
## 0.7.0-next.2 | ||
|
||
### Minor Changes | ||
|
||
- 3bfb56a: Add address1 regex for DE | ||
|
||
## 0.7.0-next.1 | ||
|
||
### Minor Changes | ||
|
||
- Add address1 regex for BE, BR, CL, ES, IL, MX | ||
|
||
## 0.7.0-next.0 | ||
|
||
### Minor Changes | ||
|
||
- 1f5d405: Add optional tryRegexFallback param to splitAddress1 function to attempt splitting address lines that do not contain the reserved delimiter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove the pre-releases, since we are no longer publishing a pre-release in favour of a minor version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pre-releases are published and available in npm, so although 0.7.0 includes the same content I think it's worth including this bit of documentation on the pre-release versions. I see it left in in some other shopify repos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pre-releases are published and available in npm
Ah thank you for clarifying.
edc19bf
to
ba7c69f
Compare
f433fc9
to
b95457f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
What are you trying to accomplish?
Resolves https://github.com/Shopify/address/issues/2726
When there is no reserved delimiter present in an address line (i.e. any address that was created before the release of additional address fields), we want to attempt to split the additional fields out using regex. The regex patterns will have to be strict in order to minimize incorrect captures.
What approach did you choose and why?
2. Adds asplitAddress1WithFallback
function to the TS library that uses the regex as a fallback if splitting on the delimiter is not possibletryRegexFallback
to the existingsplitAddress1
function in the TS library. When true, and when the input string does not contain the reserved delimiter, we attempt to parse using regex.This way, checkout web still only has one function to call for splitting.
The following PRs have been merged into this one:
See PR comments for debate on the following pros and cons
Our options for where to implement this new behaviour:
splitAddress1
function, controlled by a new optional paramChecklist