Move our internal module into the main package path

I originally put cc.import in a separate directory from the main
modules. This means that programs must extend the package path in order
to import these modules.

However, this ends up being a mixed blessing: while it makes it much
harder for users to accidentally require user code, it also means we
can't expose a public interface which wraps a private module.

Instead, cc.import now lives on the main package path, but lives under
the cc.internal namespace and is not documented anywhere. Hopefully this
should be enough of a clue that one shouldn't use it :p.
This commit is contained in:
Jonathan Coates 2023-01-05 21:55:08 +00:00
parent bdecb88cca
commit 34a31abd9c
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
4 changed files with 14 additions and 8 deletions

View File

@ -51,7 +51,7 @@ fabric-loom = "1.0-SNAPSHOT"
forgeGradle = "5.1.+"
githubRelease = "2.2.12"
ideaExt = "1.1.6"
illuaminate = "0.1.0-7-g2a5a89c"
illuaminate = "0.1.0-12-ga03e9cd"
librarian = "1.+"
minotaur = "2.+"
mixinGradle = "0.7.+"

View File

@ -1,8 +1,16 @@
-- Internal module for handling file uploads. This has NO stability guarantees,
-- and so SHOULD NOT be relyed on in user code.
--[[- Upload a list of files, as received by the @{event!file_transfer} event.
:::warning
This is an internal module and SHOULD NOT be used in your own code. It may
be removed or changed at any time.
:::
@local
]]
local completion = require "cc.completion"
--- @tparam { file_transfer.TransferredFile ...} files The files to upload.
return function(files)
local overwrite = {}
for _, file in pairs(files) do

View File

@ -18,7 +18,5 @@ if #files == 0 then
return
end
package.path = package.path .. ";/rom/modules/internal/?.lua"
local ok, err = require("cc.import")(files)
local ok, err = require("cc.internal.import")(files)
if not ok and err then printError(err) end

View File

@ -37,7 +37,7 @@ end
-- Set up a dummy require based on the current shell, for loading some of our internal dependencies.
local require
do
local env = setmetatable(createShellEnv("/rom/modules/internal"), { __index = _ENV })
local env = setmetatable(createShellEnv("/rom/programs"), { __index = _ENV })
require = env.require
end
local expect = require("cc.expect").expect
@ -655,7 +655,7 @@ else
term.setCursorBlink(false)
-- Run the import script with the provided files
local ok, err = require("cc.import")(event[2].getFiles())
local ok, err = require("cc.internal.import")(event[2].getFiles())
if not ok and err then printError(err) end
-- And attempt to restore the prompt.