Skip to content

Commit

Permalink
Immer 9 security update (#4505)
Browse files Browse the repository at this point in the history
* add yarn upgrade-interactive plugin

* chore(immer): update immer to address security issue

* Add changeset
  • Loading branch information
dylans authored Sep 9, 2021
1 parent 50bb3d7 commit 269e59c
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-moose-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': patch
---

Immer 9 security update, refactor to support immer 9 API changes
363 changes: 363 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ packageExtensions:
dependencies:
prop-types: "*"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.0.1.cjs
2 changes: 1 addition & 1 deletion packages/slate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dist/"
],
"dependencies": {
"immer": "^8.0.1",
"immer": "^9.0.6",
"is-plain-object": "^5.0.0",
"tiny-warning": "^1.0.3"
},
Expand Down
8 changes: 6 additions & 2 deletions packages/slate/src/interfaces/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,22 @@ export const Path: PathInterface = {
*/

transform(
path: Path,
path: Path | null,
operation: Operation,
options: { affinity?: 'forward' | 'backward' | null } = {}
): Path | null {
return produce(path, p => {
const { affinity = 'forward' } = options

// PERF: Exit early if the operation is guaranteed not to have an effect.
if (path.length === 0) {
if (!path || path?.length === 0) {
return
}

if (p === null) {
return null
}

switch (operation.type) {
case 'insert_node': {
const { path: op } = operation
Expand Down
5 changes: 4 additions & 1 deletion packages/slate/src/interfaces/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ export const Point: PointInterface = {
*/

transform(
point: Point,
point: Point | null,
op: Operation,
options: { affinity?: 'forward' | 'backward' | null } = {}
): Point | null {
return produce(point, p => {
if (p === null) {
return null
}
const { affinity = 'forward' } = options
const { path, offset } = p

Expand Down
50 changes: 26 additions & 24 deletions packages/slate/src/interfaces/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,38 +207,40 @@ export const Range: RangeInterface = {
*/

transform(
range: Range,
range: Range | null,
op: Operation,
options: {
affinity?: 'forward' | 'backward' | 'outward' | 'inward' | null
} = {}
): Range | null {
const { affinity = 'inward' } = options
let affinityAnchor: 'forward' | 'backward' | null
let affinityFocus: 'forward' | 'backward' | null

if (affinity === 'inward') {
if (Range.isForward(range)) {
affinityAnchor = 'forward'
affinityFocus = 'backward'
} else {
affinityAnchor = 'backward'
affinityFocus = 'forward'
return produce(range, r => {
if (r === null) {
return null
}
} else if (affinity === 'outward') {
if (Range.isForward(range)) {
affinityAnchor = 'backward'
affinityFocus = 'forward'
const { affinity = 'inward' } = options
let affinityAnchor: 'forward' | 'backward' | null
let affinityFocus: 'forward' | 'backward' | null

if (affinity === 'inward') {
if (Range.isForward(r)) {
affinityAnchor = 'forward'
affinityFocus = 'backward'
} else {
affinityAnchor = 'backward'
affinityFocus = 'forward'
}
} else if (affinity === 'outward') {
if (Range.isForward(r)) {
affinityAnchor = 'backward'
affinityFocus = 'forward'
} else {
affinityAnchor = 'forward'
affinityFocus = 'backward'
}
} else {
affinityAnchor = 'forward'
affinityFocus = 'backward'
affinityAnchor = affinity
affinityFocus = affinity
}
} else {
affinityAnchor = affinity
affinityFocus = affinity
}

return produce(range, r => {
const anchor = Point.transform(r.anchor, op, { affinity: affinityAnchor })
const focus = Point.transform(r.focus, op, { affinity: affinityFocus })

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8591,10 +8591,10 @@ __metadata:
languageName: node
linkType: hard

"immer@npm:^8.0.1":
version: 8.0.4
resolution: "immer@npm:8.0.4"
checksum: 9d3b28df1ac5bf6918c611e71c15bdb136588c21a3431100448f21325fef9b055cc9a44fe8b023f0c5ecbc66a2ba38f403c9a67d581f613b49d0e4ff15564f79
"immer@npm:^9.0.6":
version: 9.0.6
resolution: "immer@npm:9.0.6"
checksum: 75da22f3b32f3f14604eb389b4f50e84a14f2e42f306f0cbe4d2969aed54ec7fda9a7e9ca42ebae2ba73ec9bb6ec1001fafbac535accaf03860054ab0f7e8388
languageName: node
linkType: hard

Expand Down Expand Up @@ -14445,7 +14445,7 @@ resolve@^2.0.0-next.3:
resolution: "slate@workspace:packages/slate"
dependencies:
"@babel/runtime": ^7.7.4
immer: ^8.0.1
immer: ^9.0.6
is-plain-object: ^5.0.0
lodash: ^4.17.21
slate-hyperscript: ^0.62.0
Expand Down

0 comments on commit 269e59c

Please sign in to comment.