{"id":"vocksel/import","name":"import","scope":"vocksel","platform":"roblox","description":"Import modules with paths like the filesystem","version":"2.0.0","latest":"2.0.0","versions":["1.2.0","2.0.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"bfa146380029954df97c64c6485c301b0877c7775956b92144451515533ba4ce","likes":0,"downloads":0,"install":"forest install vocksel/import","url":"https://forest.dev/p/roblox/vocksel/import","files":"https://api.forest.dev/ai/package/roblox/vocksel/import/files","readme":"# import\n\n[![CI](https://github.com/vocksel/import/actions/workflows/ci.yml/badge.svg)](https://github.com/vocksel/import/actions/workflows/ci.yml)\n\nThis module allows you to write paths for Roblox instances like you do on the filesystem.\n\nHaving to constantly type `script.Parent` with varying levels of `.Parent` is tedious and can produce excessively long lines. This module aims to fix this by providing a concise syntax for writing import paths that closely resembles what's used on the filesystem.\n\n## Download\n\nDownload the latest version from the [releases page](https://github.com/vocksel/import/releases) or from the [asset library](https://www.roblox.com/library/7218303036/import)\n\n## Usage\n\n```lua\nlocal import = require(game.ReplicatedStorage.Import)\n\nlocal module = import(\"./ModuleScript\")\n-- local module = require(script.Parent.ModuleScript)\n\nlocal module = import(\"./Folder/ModuleScript)\"\n-- local module = require(script.Parent.Folder.ModuleScript)\n\nlocal module = import(\"../ModuleScript\")\n-- local module = require(script.Parent.Parent.ModuleScript)\n\nlocal module = import(\"../../ModuleScript\")\n-- local module = require(script.Parent.Parent.Parent.ModuleScript)\n```\n\nTo get easy access to the children of Roblox services, you can use absolute paths by starting a path with a slash `/`.\n\n```lua\nlocal module = import(\"/ReplicatedStorage/ModuleScript\")\n-- local module = require(game.ReplicatedStorage.ModuleScript)\n```\n\nThe import function also provides a destructuring syntax that allows you to import individual members of a module.\n\n```lua\nlocal foo = import(\"./ModuleScript\", { \"foo\" })\n-- local foo = require(script.Parent.ModuleScript).foo\n\nlocal foo, bar = import(\"./ModuleScript\", { \"foo\", \"bar\" })\n-- local module = require(script.Parent.ModuleScript)\n-- local foo = module.foo\n-- local bar = module.bar\n```\n\nAnd this function isn't just for ModuleScripts! You can import any Instance with the path syntax.\n\n```lua\nlocal sound = import(\"./Sound\")\n-- local sound = script.Parent.Sound\n\nlocal part = import(\"./Part\")\n-- local part = script.Parent.Part\n```\n\n## Aliases\n\nAliases are a powerful method of defining custom starting points for paths.\n\nA common usecase for this is to define entrypoints to your server, client, and shared code. For example:\n\n```lua\nlocal import = require(game.ReplicatedStorage.import)\n\nimport.setAliases({\n\tserver = game.ServerScriptService.ServerModules,\n\tclient = game.StarterPlayer.StarterPlayerScripts.ClientModules,\n\tshared = game.ReplicatedStorage.SharedModules,\n})\n\nlocal module = import(\"shared/ModuleScript\")\n-- local module = require(game.ReplicatedStorage.SharedModules.ModuleScript)\n```\n\nThere is also a built-in `script` alias that allows you to import the descendants of the script that is calling `import()`.\n\n```lua\nlocal module = import(\"script/ModuleScript\")\n-- local module = require(script.ModuleScript)\n```\n\n## Config\n\nThere are several configuration values you can customize to fit your needs.\n\nName | Description | Default\n:-- | :-- | :--\n`root` | Controls the root Instance for absolute paths. This is especially helpful when using this module in a package or plugin | `game`\n`useWaitForChild` | By default, FindFirstChild is used when traversing the hierarchy. Set to `true` to use WaitForChild instead | false\n`waitForChildTimeout` | When `useWaitForChild` is set to `true`, this controls how long (in seconds) to yield before resolving | 1\n`scriptAlias` | Controls the name of the alias that is reserved for the current script | `\"script\"`\n```lua\nlocal import = require(game.ReplicatedStorage.import)\n\nimport.setConfig({\n\tuseWaitForChild = true,\n\tscriptAlias = \"@\",\n})\n\nlocal module = import(\"@/ModuleScript\")\n-- local module = require(script:WaitForChild(\"ModuleScript\"))\n```\n\n## Development\n\nYou will need [Rust](https://www.rust-lang.org/) 1.41.0+ and the [Rojo plugin](https://www.roblox.com/library/4048317704/Rojo-6). If you use VS Code, you can install the [Rojo extension](https://marketplace.visualstudio.com/items?itemName=evaera.vscode-rojo) which manages the plugin for you and makes it easier to serve the project.\n\nIt is also recommended that you add `~/.foreman/bin` to your `PATH` to make the tools that Foreman installs for you accessible on your system.\n\n```sh\n# Cargo is Rust's package manager, Foreman is our toolchain manager\ncargo install foreman\n\n# Install Rojo and other tools we use\nforeman install\n\n# Install dependencies\nwally install\n\n# Serve the project. Use the Rojo plugin in Roblox Studio to connect\nrojo serve dev.project.json\n\n# Or build the project. Drag and drop into Roblox Studio to insert it\nrojo build -o import.rbxmx\n```\n\n## License\n\nMIT\n","readmeTruncated":false}