Skip to content

Commit

Permalink
prevent use of Array as import name to solve bundler issues (#2555)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Apr 18, 2024
1 parent 76277cb commit 8edacca
Show file tree
Hide file tree
Showing 56 changed files with 742 additions and 728 deletions.
14 changes: 14 additions & 0 deletions .changeset/witty-taxis-smell.md
@@ -0,0 +1,14 @@
---
"@effect/opentelemetry": patch
"@effect/experimental": patch
"@effect/printer-ansi": patch
"@effect/platform": patch
"@effect/printer": patch
"effect": patch
"@effect/schema": patch
"@effect/cli": patch
"@effect/rpc": patch
"@effect/sql": patch
---

prevent use of `Array` as import name to solve bundler issues
20 changes: 10 additions & 10 deletions packages/cli/examples/naval-fate/store.ts
@@ -1,6 +1,6 @@
import * as KeyValueStore from "@effect/platform/KeyValueStore"
import * as Schema from "@effect/schema/Schema"
import * as Array from "effect/Array"
import * as Arr from "effect/Array"
import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import { pipe } from "effect/Function"
Expand Down Expand Up @@ -67,16 +67,16 @@ export const make = Effect.gen(function*($) {
return yield* $(Effect.fail(new ShipNotFoundError({ name, x, y })))
}
const shipAtCoords = pipe(
Array.fromIterable(oldShips.values()),
Array.findFirst((ship) => ship.hasCoordinates(x, y))
Arr.fromIterable(oldShips.values()),
Arr.findFirst((ship) => ship.hasCoordinates(x, y))
)
if (Option.isSome(shipAtCoords)) {
return yield* $(Effect.fail(
new CoordinatesOccupiedError({ name: shipAtCoords.value.name, x, y })
))
}
const mines = yield* $(getMines)
const mineAtCoords = Array.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
const mineAtCoords = Arr.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
const ship = Option.isSome(mineAtCoords)
? foundShip.value.move(x, y).destroy()
: foundShip.value.move(x, y)
Expand All @@ -89,8 +89,8 @@ export const make = Effect.gen(function*($) {
Effect.gen(function*($) {
const oldShips = yield* $(getShips)
const shipAtCoords = pipe(
Array.fromIterable(oldShips.values()),
Array.findFirst((ship) => ship.hasCoordinates(x, y))
Arr.fromIterable(oldShips.values()),
Arr.findFirst((ship) => ship.hasCoordinates(x, y))
)
if (Option.isSome(shipAtCoords)) {
const ship = shipAtCoords.value.destroy()
Expand All @@ -102,20 +102,20 @@ export const make = Effect.gen(function*($) {
const setMine: NavalFateStore["setMine"] = (x, y) =>
Effect.gen(function*($) {
const mines = yield* $(getMines)
const mineAtCoords = Array.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
const mineAtCoords = Arr.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
if (Option.isNone(mineAtCoords)) {
const mine = Mine.create(x, y)
const newMines = Array.append(mines, mine)
const newMines = Arr.append(mines, mine)
yield* $(setMines(newMines))
}
})

const removeMine: NavalFateStore["removeMine"] = (x, y) =>
Effect.gen(function*($) {
const mines = yield* $(getMines)
const mineAtCoords = Array.findFirstIndex(mines, (mine) => mine.hasCoordinates(x, y))
const mineAtCoords = Arr.findFirstIndex(mines, (mine) => mine.hasCoordinates(x, y))
if (Option.isSome(mineAtCoords)) {
const newMines = Array.remove(mines, mineAtCoords.value)
const newMines = Arr.remove(mines, mineAtCoords.value)
yield* $(setMines(newMines))
}
})
Expand Down
66 changes: 33 additions & 33 deletions packages/cli/src/internal/args.ts
Expand Up @@ -3,7 +3,7 @@ import type * as Path from "@effect/platform/Path"
import type * as Terminal from "@effect/platform/Terminal"
import * as Schema from "@effect/schema/Schema"
import * as TreeFormatter from "@effect/schema/TreeFormatter"
import * as Array from "effect/Array"
import * as Arr from "effect/Array"
import type * as Config from "effect/Config"
import * as Console from "effect/Console"
import * as Effect from "effect/Effect"
Expand Down Expand Up @@ -160,7 +160,7 @@ export const all: <
if (arguments.length === 1) {
if (isArgs(arguments[0])) {
return map(arguments[0], (x) => [x]) as any
} else if (Array.isArray(arguments[0])) {
} else if (Arr.isArray(arguments[0])) {
return allTupled(arguments[0] as Array<any>) as any
} else {
const entries = Object.entries(arguments[0] as Readonly<{ [K: string]: Args.Args<any> }>)
Expand Down Expand Up @@ -283,11 +283,11 @@ export const text = (config?: Args.Args.BaseArgsConfig): Args.Args<string> =>
export const atLeast = dual<
{
(times: 0): <A>(self: Args.Args<A>) => Args.Args<Array<A>>
(times: number): <A>(self: Args.Args<A>) => Args.Args<Array.NonEmptyArray<A>>
(times: number): <A>(self: Args.Args<A>) => Args.Args<Arr.NonEmptyArray<A>>
},
{
<A>(self: Args.Args<A>, times: 0): Args.Args<Array<A>>
<A>(self: Args.Args<A>, times: number): Args.Args<Array.NonEmptyArray<A>>
<A>(self: Args.Args<A>, times: number): Args.Args<Arr.NonEmptyArray<A>>
}
>(2, (self, times) => makeVariadic(self, Option.some(times), Option.none()) as any)

Expand All @@ -304,15 +304,15 @@ export const between = dual<
(
min: number,
max: number
): <A>(self: Args.Args<A>) => Args.Args<Array.NonEmptyArray<A>>
): <A>(self: Args.Args<A>) => Args.Args<Arr.NonEmptyArray<A>>
},
{
<A>(self: Args.Args<A>, min: 0, max: number): Args.Args<Array<A>>
<A>(
self: Args.Args<A>,
min: number,
max: number
): Args.Args<Array.NonEmptyArray<A>>
): Args.Args<Arr.NonEmptyArray<A>>
}
>(3, (self, min, max) => makeVariadic(self, Option.some(min), Option.some(max)) as any)

Expand Down Expand Up @@ -568,13 +568,13 @@ const getIdentifierInternal = (self: Instruction): Option.Option<string> => {
return getIdentifierInternal(self.args as Instruction)
}
case "Both": {
const ids = Array.getSomes([
const ids = Arr.getSomes([
getIdentifierInternal(self.left as Instruction),
getIdentifierInternal(self.right as Instruction)
])
return Array.match(ids, {
return Arr.match(ids, {
onEmpty: () => Option.none(),
onNonEmpty: (ids) => Option.some(Array.join(ids, ", "))
onNonEmpty: (ids) => Option.some(Arr.join(ids, ", "))
})
}
}
Expand Down Expand Up @@ -637,7 +637,7 @@ const getUsageInternal = (self: Instruction): Usage.Usage => {
}
case "Single": {
return InternalUsage.named(
Array.of(self.name),
Arr.of(self.name),
InternalPrimitive.getChoices(self.primitiveType)
)
}
Expand Down Expand Up @@ -743,7 +743,7 @@ const validateInternal = (
}
case "Single": {
return Effect.suspend(() => {
return Array.matchLeft(args, {
return Arr.matchLeft(args, {
onEmpty: () => {
const choices = InternalPrimitive.getChoices(self.primitiveType)
if (Option.isSome(self.pseudoName) && Option.isSome(choices)) {
Expand Down Expand Up @@ -810,13 +810,13 @@ const validateInternal = (
}
return validateInternal(self.args as Instruction, args, config).pipe(Effect.matchEffect({
onFailure: (failure) =>
acc.length >= min1 && Array.isEmptyReadonlyArray(args)
acc.length >= min1 && Arr.isEmptyReadonlyArray(args)
? Effect.succeed([args, acc])
: Effect.fail(failure),
onSuccess: ([args, a]) => loop(args, Array.append(acc, a))
onSuccess: ([args, a]) => loop(args, Arr.append(acc, a))
}))
}
return loop(args, Array.empty()).pipe(
return loop(args, Arr.empty()).pipe(
Effect.map(([args, acc]) => [args as Array<string>, acc])
)
}
Expand Down Expand Up @@ -888,14 +888,14 @@ const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.
> => {
switch (self._tag) {
case "Empty": {
return Effect.succeed(Array.empty())
return Effect.succeed(Arr.empty())
}
case "Single": {
const help = getHelpInternal(self)
return InternalPrimitive.wizard(self.primitiveType, help).pipe(
Effect.zipLeft(Console.log()),
Effect.flatMap((input) => {
const args = Array.of(input as string)
const args = Arr.of(input as string)
return validateInternal(self, args, config).pipe(Effect.as(args))
})
)
Expand All @@ -909,7 +909,7 @@ const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.
return Effect.zipWith(
wizardInternal(self.left as Instruction, config),
wizardInternal(self.right as Instruction, config),
(left, right) => Array.appendAll(left, right)
(left, right) => Arr.appendAll(left, right)
).pipe(Effect.tap((args) => validateInternal(self, args, config)))
}
case "Variadic": {
Expand All @@ -928,11 +928,11 @@ const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.
Effect.zipLeft(Console.log()),
Effect.flatMap((n) =>
n <= 0
? Effect.succeed(Array.empty<string>())
: Ref.make(Array.empty<string>()).pipe(
? Effect.succeed(Arr.empty<string>())
: Ref.make(Arr.empty<string>()).pipe(
Effect.flatMap((ref) =>
wizardInternal(self.args as Instruction, config).pipe(
Effect.flatMap((args) => Ref.update(ref, Array.appendAll(args))),
Effect.flatMap((args) => Ref.update(ref, Arr.appendAll(args))),
Effect.repeatN(n - 1),
Effect.zipRight(Ref.get(ref)),
Effect.tap((args) => validateInternal(self, args, config))
Expand All @@ -958,7 +958,7 @@ const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.
Effect.zipLeft(Console.log()),
Effect.flatMap((useFallback) =>
useFallback
? Effect.succeed(Array.empty())
? Effect.succeed(Arr.empty())
: wizardInternal(self.args as Instruction, config)
)
)
Expand All @@ -979,7 +979,7 @@ const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.
Effect.zipLeft(Console.log()),
Effect.flatMap((useFallback) =>
useFallback
? Effect.succeed(Array.empty())
? Effect.succeed(Arr.empty())
: wizardInternal(self.args as Instruction, config)
)
)
Expand Down Expand Up @@ -1013,27 +1013,27 @@ const getShortDescription = (self: Instruction): string => {
export const getFishCompletions = (self: Instruction): Array<string> => {
switch (self._tag) {
case "Empty": {
return Array.empty()
return Arr.empty()
}
case "Single": {
const description = getShortDescription(self)
return pipe(
InternalPrimitive.getFishCompletions(
self.primitiveType as InternalPrimitive.Instruction
),
Array.appendAll(
Arr.appendAll(
description.length === 0
? Array.empty()
: Array.of(`-d '${description}'`)
? Arr.empty()
: Arr.of(`-d '${description}'`)
),
Array.join(" "),
Array.of
Arr.join(" "),
Arr.of
)
}
case "Both": {
return pipe(
getFishCompletions(self.left as Instruction),
Array.appendAll(getFishCompletions(self.right as Instruction))
Arr.appendAll(getFishCompletions(self.right as Instruction))
)
}
case "Map":
Expand All @@ -1056,7 +1056,7 @@ export const getZshCompletions = (
): Array<string> => {
switch (self._tag) {
case "Empty": {
return Array.empty()
return Arr.empty()
}
case "Single": {
const multiple = state.multiple ? "*" : ""
Expand All @@ -1067,16 +1067,16 @@ export const getZshCompletions = (
self.primitiveType as InternalPrimitive.Instruction
)
return possibleValues.length === 0
? Array.empty()
: Array.of(`${multiple}${optional}${self.name}${description}${possibleValues}`)
? Arr.empty()
: Arr.of(`${multiple}${optional}${self.name}${description}${possibleValues}`)
}
case "Map": {
return getZshCompletions(self.args as Instruction, state)
}
case "Both": {
const left = getZshCompletions(self.left as Instruction, state)
const right = getZshCompletions(self.right as Instruction, state)
return Array.appendAll(left, right)
return Arr.appendAll(left, right)
}
case "Variadic": {
return Option.isSome(self.max) && self.max.value > 1
Expand Down

0 comments on commit 8edacca

Please sign in to comment.