Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Fix critical bug in Sift.Dictionary.update (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reselim authored Sep 29, 2022
1 parent e1d8a67 commit 4767957
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 121 deletions.
46 changes: 12 additions & 34 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,36 @@
name: Publish Package

# env:
# ASSET_ID_STABLE: 6573728888

on:
workflow_dispatch:
release:
types: [published]

jobs:
publish-public:
publish-package:
if: ${{ github.events.release.prerelease == false }}
runs-on: ubuntu-latest
timeout-minutes: 8
timeout-minutes: 5

steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.release.tag_name }}

# - name: Test Roblox Login Tokens
# shell: bash
# run: |
# if [ -z "${{ secrets.ROBLOSECURITY }}" ]; then
# echo "No cookie found. Please set the ROBLOSECURITY secret."
# exit 1
# fi

# RBX_USERNAME=$(curl -s -X GET -H "Cookie: .ROBLOSECURITY=${{ secrets.ROBLOSECURITY }}" https://users.roblox.com/v1/users/authenticated | jq -r ".name")

# if [ -z "$RBX_USERNAME" ]; then
# echo "ROBLOSECURITY is invalid or expired. Please reset the ROBLOSECURITY secret."
# exit 1
# fi

# echo "Logged in as $RBX_USERNAME."
- name: Setup Aftman
uses: ok-nick/setup-aftman@v0.3.0

- name: Setup Node LTS
uses: actions/setup-node@v2
with:
node-version: lts/*

- name: Setup Toolchain
uses: Roblox/setup-foreman@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Report Tool Versions
run: |
foreman list
npm -v
aftman -V
aftman list
node -v
npm -v
- name: Install Dependencies
run: |
Expand All @@ -60,21 +42,17 @@ jobs:
find . -name "*.spec.lua" -delete
# - name: Publish to Roblox
# if: ${{ github.event.release.prerelease == false }}
# shell: bash
# run: rojo upload default.project.json --asset_id $ASSET_ID_STABLE --cookie "${{ secrets.ROBLOSECURITY }}"
# run: rojo upload default.project.json --asset_id "${{ secrets.ASSET_ID }}" --cookie "${{ secrets.ROBLOSECURITY }}"

- name: Publish to Wally
if: ${{ github.event.release.prerelease == false }}
env:
WALLY_TOKEN: ${{ secrets.WALLY_TOKEN }}
run: |
mkdir =p ~/.wally
mkdir -p ~/.wally
printf "[tokens]\n\"https://api.wally.run/\" = \"%s\"" "$WALLY_TOKEN" >> ~/.wally/auth.toml
wally publish
- name: Publish to NPM
if: ${{ github.event.release.prerelease == false }}
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
72 changes: 0 additions & 72 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
*.env
*.tsbuildinfo

roblox.toml

packages/
node_modules/
out/
include/
build/
2 changes: 1 addition & 1 deletion .vscode/scripts/run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $FILE_NAME = ".\test-place.rbxl"
$TEST_PROJ = ".\test.project.json"
$TEST_RUNR = ".\TestRunner.server.lua"

foreman install
aftman install
rojo build "$TEST_PROJ" -o "$FILE_NAME"
run-in-roblox --place "$FILE_NAME" --script "$TEST_RUNR"
Remove-Item "$FILE_NAME" -Force -ErrorAction SilentlyContinue
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.0.3]

### Changed

- If `update` is called with a key that doesn't exist in the specified dictionary, the key's value is **set to the key itself**. Fix by [@reselim](https://github.com/Reselim) in [PR #7](https://github.com/csqrl/sift/pull/7).
- Added `aftman.toml` and switched GitHub workflows over to use aftman.

## [0.0.2]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Wally is a CLI package manager (much like NPM, Yarn or Cargo) for Roblox by @Upl
# wally.toml

[dependencies]
Sift = "csqrl/sift@=0.0.2"
Sift = "csqrl/sift@0.0.3"
```

```shell
Expand Down
6 changes: 6 additions & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tools]
rojo = "rojo-rbx/rojo@7.2.1"
run-in-roblox = "rojo-rbx/run-in-roblox@0.3.0"
wally = "upliftgames/wally@0.3.1"
stylua = "johnnymorganz/stylua@0.15.1"
selene = "kampfkarren/selene@0.21.1"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbxts/sift",
"version": "0.0.2",
"version": "0.0.3",
"description": "Immutable data library for Luau",
"main": "out/init.lua",
"types": "out/index.d.ts",
Expand Down
15 changes: 6 additions & 9 deletions src/Dictionary/update.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
--!strict
local Sift = script.Parent.Parent

local Util = require(Sift.Util)
local copy = require(script.Parent.copy)

type Callback<K, V> = (key: K) -> V
Expand Down Expand Up @@ -47,14 +44,14 @@ local function update<K, V, U, C>(
): { [K]: V & U & C }
local result = copy(dictionary)

updater = if type(updater) == "function" then updater else Util.func.returned

callback = if type(callback) == "function" then callback else Util.func.returned

if result[key] ~= nil then
result[key] = updater(result[key], key)
if updater then
result[key] = updater(result[key], key)
end
else
result[key] = call(callback, key)
if callback then
result[key] = call(callback, key)
end
end

return result
Expand Down
10 changes: 10 additions & 0 deletions src/Dictionary/update.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ return function()
expect(new.cats).to.equal(2)
expect(new.dogs).to.equal(1)
end)

it("should not create a key if it doesn't exist and no callback is specified", function()
local dictionary = { cats = 2 }

local new = Update(dictionary, "dogs", function()
return 1
end)

expect(new.dogs).to.equal(nil)
end)
end
53 changes: 53 additions & 0 deletions testez.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
globals:
FIXME:
args:
- required: false
type: string
FOCUS:
args: []
SKIP:
args: []
afterAll:
args:
- type: function
afterEach:
args:
- type: function
beforeAll:
args:
- type: function
beforeEach:
args:
- type: function
describe:
args:
- type: string
- type: function
describeFOCUS:
args:
- type: string
- type: function
describeSKIP:
args:
- type: string
- type: function
expect:
args:
- type: any
it:
args:
- type: string
- type: function
itFIXME:
args:
- type: string
- type: function
itFOCUS:
args:
- type: string
- type: function
itSKIP:
args:
- type: string
- type: function
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "csqrl/sift"
description = "Immutable data library for Luau"
version = "0.0.2"
version = "0.0.3"
license = "MIT"
author = "csqrl (https://csqrl.dev)"
registry = "https://github.com/upliftgames/wally-index"
Expand Down

0 comments on commit 4767957

Please sign in to comment.