• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 14284237390

05 Apr 2025 05:33PM UTC coverage: 63.158% (+31.8%) from 31.375%
14284237390

push

github

web-flow
Merge pull request #2248 from alerque/class-warfare

Normalize module layout across all module types

257 of 350 new or added lines in 14 files covered. (73.43%)

71 existing lines in 11 files now uncovered.

13670 of 21644 relevant lines covered (63.16%)

3070.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/core/require.lua
1
local function require_ (dependency, pathprefix, deprecation_ack)
2
   if pathprefix and not deprecation_ack then
114✔
NEW
3
      local notice = string.format(
×
NEW
4
         [[
×
5
  Please don't use the path prefix mechanism; it was intended to provide
6
  alternate paths to override core components but never worked well and is
7
  causing portability problems. Just use Lua idiomatic module loading:
8
      SILE.require("%s", "%s") → SILE.require("%s.%s")]],
9
         dependency,
10
         pathprefix,
11
         pathprefix,
12
         dependency
13
      )
NEW
14
      SU.deprecated("SILE.require", "SILE.require", "0.13.0", nil, notice)
×
15
   end
16
   dependency = dependency:gsub(".lua$", "")
114✔
17
   local status, lib
18
   if pathprefix then
114✔
19
      -- Note this is not a *path*, it is a module identifier:
20
      -- https://github.com/sile-typesetter/sile/issues/1861
21
      status, lib = pcall(require, pl.stringx.join(".", { pathprefix, dependency }))
228✔
22
   end
23
   if not status then
114✔
NEW
24
      local prefixederror = lib
×
NEW
25
      status, lib = pcall(require, dependency)
×
NEW
26
      if not status then
×
NEW
27
         SU.error(
×
NEW
28
            ("Unable to find module '%s'%s"):format(
×
29
               dependency,
NEW
30
               SILE.traceback and ((pathprefix and "\n  " .. prefixederror or "") .. "\n  " .. lib) or ""
×
31
            )
32
         )
33
      end
34
   end
35
   local class = SILE.documentState.documentClass
114✔
36
   if not class and not deprecation_ack then
114✔
NEW
37
      SU.warn(string.format(
×
NEW
38
         [[
×
39
            SILE.require() is only supported in documents, packages, or class init
40

41
            It will not function fully before the class is instantiated. Please just use
42
            the Lua require() function directly:
43

44
              SILE.require("%s") → require("%s")
45
         ]],
46
         dependency,
47
         dependency
48
      ))
49
   end
50
   if type(lib) == "table" and class then
114✔
NEW
51
      if lib.type == "package" then
×
NEW
52
         lib(class)
×
53
      else
NEW
54
         class:initPackage(lib)
×
55
      end
56
   end
57
   return lib
114✔
58
end
59

60
local function resolveFile (filename, pathprefix)
61
   local candidates = {}
117✔
62
   -- Start with the raw file name as given prefixed with a path if requested
63
   if pathprefix then
117✔
NEW
64
      candidates[#candidates + 1] = pl.path.join(pathprefix, "?")
×
65
   end
66
   -- Also check the raw file name without a path
67
   candidates[#candidates + 1] = "?"
117✔
68
   -- Iterate through the directory of the master file, the SILE_PATH variable, and the current directory
69
   -- Check for prefixed paths first, then the plain path in that fails
70
   if SILE.masterDir then
117✔
71
      for path in SU.gtoke(SILE.masterDir .. ";" .. tostring(os.getenv("SILE_PATH")), ";") do
1,053✔
72
         if path.string and path.string ~= "nil" then
819✔
73
            if pathprefix then
468✔
NEW
74
               candidates[#candidates + 1] = pl.path.join(path.string, pathprefix, "?")
×
75
            end
76
            candidates[#candidates + 1] = pl.path.join(path.string, "?")
936✔
77
         end
78
      end
79
   end
80
   -- Return the first candidate that exists, also checking the .sil suffix
81
   local path = table.concat(candidates, ";")
117✔
82
   local resolved, err = package.searchpath(filename, path, "/")
117✔
83
   if resolved then
117✔
84
      if SILE.makeDeps then
117✔
85
         SILE.makeDeps:add(resolved)
117✔
86
      end
NEW
87
   elseif SU.debugging("paths") then
×
NEW
88
      SU.debug("paths", ("Unable to find file '%s': %s"):format(filename, err))
×
89
   end
90
   return resolved
117✔
91
end
92

93
return {
223✔
94
   require = require_,
223✔
95
   resolveFile = resolveFile,
223✔
96
}
223✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc