Skip to content

Commit

Permalink
fix: preserve morphs on some piped properties (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimava authored Oct 12, 2024
1 parent 6052e66 commit 7adbaf6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
4 changes: 3 additions & 1 deletion ark/attest/tsVersioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const forTypeScriptVersions = (
const nodeModules = join(assertPackageRoot(process.cwd()), "node_modules")
const tsPrimaryPath = join(nodeModules, "typescript")
const tsTemporaryPath = join(nodeModules, "typescript-temp")
if (existsSync(tsTemporaryPath)) unlinkSync(tsTemporaryPath)
if (existsSync(tsPrimaryPath)) renameSync(tsPrimaryPath, tsTemporaryPath)

try {
Expand All @@ -41,7 +42,7 @@ export const forTypeScriptVersions = (
try {
if (existsSync(tsPrimaryPath)) unlinkSync(tsPrimaryPath)

symlinkSync(targetPath, tsPrimaryPath)
symlinkSync(targetPath, tsPrimaryPath, "junction")
fn(version)
passedVersions.push(version)
} catch (e) {
Expand All @@ -65,6 +66,7 @@ export const forTypeScriptVersions = (
} finally {
if (existsSync(tsTemporaryPath)) {
console.log(`⏮️ Restoring your original TypeScript version...`)
unlinkSync(tsPrimaryPath)
renameSync(tsTemporaryPath, tsPrimaryPath)
}
}
Expand Down
6 changes: 3 additions & 3 deletions ark/repo/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { symlinkSync } from "fs"
import { copyFileSync } from "fs"
import { join } from "path"
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { fromCwd, fromHere, rmRf, shell, writeJson } from "../fs/index.ts"
Expand All @@ -15,10 +15,10 @@ const buildCurrentProject = () =>
try {
rmRf(outDir)
rmRf("tsconfig.build.json")
symlinkSync(`../repo/tsconfig.${buildKind}.json`, "tsconfig.build.json")
copyFileSync(`../repo/tsconfig.${buildKind}.json`, "tsconfig.build.json")
buildCurrentProject()
rmRf("tsconfig.build.json")
symlinkSync(`../repo/tsconfig.dts.json`, "tsconfig.build.json")
copyFileSync(`../repo/tsconfig.dts.json`, "tsconfig.build.json")
buildCurrentProject()
if (buildKind === "cjs")
writeJson(join(outDir, "package.json"), { type: "commonjs" })
Expand Down
24 changes: 12 additions & 12 deletions ark/repo/scratch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { type } from "arktype"

const AorB = type({
"+": "reject",
something: "'A'"
}).or({
"+": "reject",
something: "'B'",
somethingelse: "number"
})

console.log(AorB.internal.assertHasKind("union").discriminantJson)

const out2 = AorB({ something: "A" }) //?
console.log(
type({
foo: type("string").pipe(() => 123)
})
.pipe(c => c)
.to({
foo: "123"
})({
foo: "bar"
}) + ""
)
// foo must be 123 (was "bar")
2 changes: 1 addition & 1 deletion ark/schema/shared/intersections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const _pipeMorphed = (

return ctx.$.node("morph", {
morphs,
in: from.in
in: from.inner.in as any
})
}

Expand Down
11 changes: 11 additions & 0 deletions ark/type/__tests__/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,15 @@ Right: { foo: (In: string) => Out<{ [string]: $jsonObject | number | string | $j

attest(appendSeparatedLengths("a")).snap("a12|45")
})

it("doesn't lose input prop morphs", () => {
const T = type({
foo: type("string").pipe(s => s.length)
})
.pipe(o => o)
.to({
foo: "number"
})
attest(T({ foo: "bar" })).snap({ foo: 3 })
})
})

0 comments on commit 7adbaf6

Please sign in to comment.