- fixed bug in compiler (rare)
- added lyng.io.fs (multiplatform) - CLI tools now have access to the filesystem
This commit is contained in:
1 parent
41746f22e5
commit
438e48959e
28 files changed
+2137
-6
No files matched your search
@@ -57,6 +57,9 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-common"))
|
||||
implementation(project(":lynglib"))
|
||||
// Provide Lyng FS module to the CLI tool so it can install
|
||||
// filesystem access into the execution Scope by default.
|
||||
implementation(project(":lyngio"))
|
||||
implementation(libs.okio)
|
||||
implementation(libs.clikt)
|
||||
implementation(kotlin("stdlib-common"))
|
||||
@@ -72,6 +75,12 @@ kotlin {
|
||||
implementation(libs.okio.fakefilesystem)
|
||||
}
|
||||
}
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test"))
|
||||
implementation(kotlin("test-junit"))
|
||||
}
|
||||
}
|
||||
// val nativeMain by getting {
|
||||
// dependencies {
|
||||
// implementation(kotlin("stdlib-common"))
|
||||
|
||||
@@ -30,7 +30,9 @@ import net.sergeych.lyng.LyngVersion
|
||||
import net.sergeych.lyng.Script
|
||||
import net.sergeych.lyng.ScriptError
|
||||
import net.sergeych.lyng.Source
|
||||
import net.sergeych.lyng.io.fs.createFs
|
||||
import net.sergeych.lyng.obj.*
|
||||
import net.sergeych.lyngio.fs.security.PermitAllAccessPolicy
|
||||
import net.sergeych.mp_tools.globalDefer
|
||||
import okio.FileSystem
|
||||
import okio.Path.Companion.toPath
|
||||
@@ -62,6 +64,9 @@ val baseScopeDefer = globalDefer {
|
||||
exit(requireOnlyArg<ObjInt>().toInt())
|
||||
ObjVoid
|
||||
}
|
||||
// Install lyng.io.fs module with full access by default for the CLI tool's Scope.
|
||||
// Scripts still need to `import lyng.io.fs` to use Path API.
|
||||
createFs(PermitAllAccessPolicy, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package net.sergeych.lyng_cli
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.sergeych.baseScopeDefer
|
||||
import org.junit.Test
|
||||
import kotlin.io.path.createTempDirectory
|
||||
|
||||
class FsIntegrationJvmTest {
|
||||
|
||||
@Test
|
||||
fun scopeHasFsModuleInstalled() {
|
||||
runBlocking {
|
||||
val scope = baseScopeDefer.await()
|
||||
// Ensure we can import the FS module and use Path bindings from Lyng script
|
||||
val dir = createTempDirectory("lyng_cli_fs_test_")
|
||||
try {
|
||||
val file = dir.resolve("hello.txt")
|
||||
// Drive the operation via Lyng code to validate bindings end-to-end
|
||||
scope.eval(
|
||||
"""
|
||||
import lyng.io.fs
|
||||
val p = Path("${'$'}{file}")
|
||||
p.writeUtf8("hello from cli test")
|
||||
assertEquals(true, p.exists())
|
||||
assertEquals("hello from cli test", p.readUtf8())
|
||||
""".trimIndent()
|
||||
)
|
||||
} finally {
|
||||
dir.toFile().deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun scopeHasFsSeesRealFs() {
|
||||
runBlocking {
|
||||
val scope = baseScopeDefer.await()
|
||||
// Drive the operation via Lyng code to validate bindings end-to-end
|
||||
scope.eval(
|
||||
"""
|
||||
import lyng.io.fs
|
||||
// list current folder files
|
||||
println( Path(".").list().toList() )
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user