Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remap ESModule imports at link time in mdoc #883

Merged
merged 96 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
0438cb7
Remap ES Modules at link time
Quafadas Jul 11, 2024
0e0e859
remap esmodules at link time
Quafadas Jul 11, 2024
54b015f
.
Quafadas Jul 11, 2024
dfde131
.
Quafadas Jul 11, 2024
e823704
Fix line no
Quafadas Jul 11, 2024
2cc6eda
remove only
Quafadas Jul 11, 2024
1b1f096
So close...
Quafadas Jul 11, 2024
7729ef0
Try snapshot
Quafadas Jul 12, 2024
fca69ab
fmt
Quafadas Jul 12, 2024
f382b3e
Pretty please work with a cherry on top
Quafadas Jul 12, 2024
c67a83a
.
Quafadas Jul 12, 2024
2e8ae38
fmt
Quafadas Jul 12, 2024
9006060
.
Quafadas Jul 12, 2024
eaa4c16
.
Quafadas Jul 12, 2024
5376abb
.
Quafadas Jul 12, 2024
57d3710
windows paths
Quafadas Jul 12, 2024
eb88458
windows, finally?
Quafadas Jul 12, 2024
16e794b
Update mdoc-js/src/main/scala/mdoc/modifiers/JsModifier.scala
Quafadas Jul 16, 2024
b89da7f
Update mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
Quafadas Jul 16, 2024
e94ffcc
Update cli/src/main/scala/mdoc/internal/cli/Settings.scala
Quafadas Jul 16, 2024
ba8056d
Per feedback - tidy naming. Add cli args test
Quafadas Jul 16, 2024
4198a0f
Feedback: Update test
Quafadas Jul 16, 2024
6adc334
fmt
Quafadas Jul 16, 2024
533b8b5
Rename mapping function
Quafadas Jul 16, 2024
b2206d7
.
Quafadas Jul 16, 2024
0a1fc9b
Update scalameta, testkit to 4.9.8
scalameta-bot Jul 22, 2024
ff78365
Update sbt, scripted-plugin to 1.10.1
scalameta-bot Jul 22, 2024
aca5269
.
Quafadas Jul 22, 2024
23c082f
JS docs
Quafadas Jul 22, 2024
cf59660
.
Quafadas Jul 22, 2024
9962de3
too much... put back jsdocs project
Quafadas Jul 22, 2024
6ca3b32
EvaluatedMarkdownDocument interface
keynmol Feb 2, 2024
9e4c5e9
Add basic test
keynmol Jul 26, 2024
6f30481
Huh
keynmol Jul 26, 2024
1291803
Initialise map differently
keynmol Jul 26, 2024
832424a
Update docs/js.md
Quafadas Aug 14, 2024
480b1ed
Update docs/js.md
Quafadas Aug 14, 2024
28b2e1b
Update docs/js.md
Quafadas Aug 14, 2024
50b86fe
revert
Quafadas Aug 14, 2024
39b12a5
organise imports
Quafadas Aug 14, 2024
95bd8f6
.
Quafadas Aug 14, 2024
bedebef
remove commented references
Quafadas Aug 14, 2024
64b7748
Update slf4j-api to 2.0.16
scalameta-bot Aug 23, 2024
f3ed917
Update scalameta, testkit to 4.9.9
scalameta-bot Aug 23, 2024
41b8231
Update scalafmt-core to 3.8.3
scalameta-bot Aug 23, 2024
4511c9d
Update munit to 1.0.1
scalameta-bot Aug 23, 2024
4fa3cd9
Update sbt-ci-release to 1.6.1
scalameta-bot Aug 23, 2024
c7e3519
Update metaconfig-typesafe-config to 0.13.0
scalameta-bot Aug 26, 2024
64ee2f1
some feedback
Quafadas Aug 30, 2024
432cdda
Parse from stream
Quafadas Aug 30, 2024
b63b588
remove semicolon
Quafadas Aug 30, 2024
7ad139a
synatz
Quafadas Aug 30, 2024
2505970
Remap ES Modules at link time
Quafadas Jul 11, 2024
cc9a3c9
remap esmodules at link time
Quafadas Jul 11, 2024
93e3440
.
Quafadas Jul 11, 2024
58349ce
.
Quafadas Jul 11, 2024
27806fb
Fix line no
Quafadas Jul 11, 2024
596d7c0
remove only
Quafadas Jul 11, 2024
96dabd0
So close...
Quafadas Jul 11, 2024
c4ebc98
Try snapshot
Quafadas Jul 12, 2024
eb73393
fmt
Quafadas Jul 12, 2024
a7f4f02
Pretty please work with a cherry on top
Quafadas Jul 12, 2024
2872fb9
.
Quafadas Jul 12, 2024
0d2ed3a
fmt
Quafadas Jul 12, 2024
33e3f31
.
Quafadas Jul 12, 2024
a1f5559
.
Quafadas Jul 12, 2024
dc9b6ef
.
Quafadas Jul 12, 2024
6df4338
windows paths
Quafadas Jul 12, 2024
3a4765c
windows, finally?
Quafadas Jul 12, 2024
cb1e50c
Update mdoc-js/src/main/scala/mdoc/modifiers/JsModifier.scala
Quafadas Jul 16, 2024
316f741
Update mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
Quafadas Jul 16, 2024
682b5b8
Update cli/src/main/scala/mdoc/internal/cli/Settings.scala
Quafadas Jul 16, 2024
f3363c8
Per feedback - tidy naming. Add cli args test
Quafadas Jul 16, 2024
6c6f6da
Feedback: Update test
Quafadas Jul 16, 2024
cf3ef94
fmt
Quafadas Jul 16, 2024
7e76eb9
Rename mapping function
Quafadas Jul 16, 2024
7e97011
.
Quafadas Jul 16, 2024
e7b140e
.
Quafadas Jul 22, 2024
03ea40e
JS docs
Quafadas Jul 22, 2024
bc0b4a8
.
Quafadas Jul 22, 2024
11f882d
too much... put back jsdocs project
Quafadas Jul 22, 2024
6afbc6d
Update docs/js.md
Quafadas Aug 14, 2024
1089279
Update docs/js.md
Quafadas Aug 14, 2024
81bfd41
Update docs/js.md
Quafadas Aug 14, 2024
2675800
revert
Quafadas Aug 14, 2024
8957145
organise imports
Quafadas Aug 14, 2024
225e92b
.
Quafadas Aug 14, 2024
fbd4a98
remove commented references
Quafadas Aug 14, 2024
62038db
some feedback
Quafadas Aug 30, 2024
2a79c0e
Parse from stream
Quafadas Aug 30, 2024
007f494
remove semicolon
Quafadas Aug 30, 2024
12cdf90
synatz
Quafadas Aug 30, 2024
84bf280
Merge branch 'remap2' of https://github.com/Quafadas/mdoc into remap2
Quafadas Sep 10, 2024
fefb8f6
Remove DS_Store, resolve more feedback.
Quafadas Sep 16, 2024
b40cabb
Update docs/js.md
Quafadas Sep 16, 2024
0301afa
Update docs/js.md
Quafadas Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
38 changes: 33 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def isScala212(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exis
def isScala213(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 13)
def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3)

def jsoniter = List(
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.13.5.2",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.13.5.2"
)

val isScala212 = Def.setting {
VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("2.12.x"))
}
Expand Down Expand Up @@ -129,6 +134,7 @@ val V = new {
val fs2 = "3.10.2"

val metaconfig = "0.12.0"

}

lazy val interfaces = project
Expand Down Expand Up @@ -250,7 +256,7 @@ lazy val mdoc = project
"com.geirsson" %% "metaconfig-typesafe-config" % V.metaconfig,
"com.lihaoyi" %% "fansi" % V.fansi,
"com.lihaoyi" %% "pprint" % V.pprint
)
) ++ jsoniter
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
)
.dependsOn(parser, runtime, cli)
.enablePlugins(BuildInfoPlugin)
Expand Down Expand Up @@ -304,6 +310,22 @@ val jsdocs = project
)
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)

val jswebsitedocs = project
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
.in(file("tests/websiteJs"))
.settings(
sharedSettings,
publish / skip := true,
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
},
libraryDependencies ++= List(
"org.scala-js" %%% "scalajs-dom" % scalajsDom
// "com.raquo" %%% "laminar" % "0.17.0",
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
// "com.raquo" %%% "laminar-shoelace" % "0.1.0" // once this project moves to scala 3.
)
)
.enablePlugins(ScalaJSPlugin)

lazy val worksheets = project
.in(file("tests/worksheets"))
.settings(
Expand Down Expand Up @@ -432,7 +454,10 @@ lazy val jsWorker =
.settings(
sharedSettings,
moduleName := "mdoc-js-worker",
libraryDependencies += ("org.scala-js" %% "scalajs-linker" % scalaJSVersion % Provided) cross CrossVersion.for3Use2_13
libraryDependencies ++= Seq(
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
"org.scala-js" %% "scalajs-linker" % scalaJSVersion % Provided cross CrossVersion.for3Use2_13,
"com.armanbilge" %% "scalajs-importmap" % "0.1.1" cross CrossVersion.for3Use2_13
)
)

lazy val js = project
Expand All @@ -441,7 +466,8 @@ lazy val js = project
.settings(
sharedSettings,
moduleName := "mdoc-js",
Compile / unmanagedSourceDirectories ++= multiScalaDirectories("js").value
Compile / unmanagedSourceDirectories ++= multiScalaDirectories("js").value,
libraryDependencies ++= jsoniter
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
)
.dependsOn(mdoc)

Expand All @@ -463,8 +489,10 @@ lazy val docs = project
watchSources += (ThisBuild / baseDirectory).value / "docs",
Global / cancelable := true,
MdocPlugin.autoImport.mdoc := (Compile / run).evaluated,
mdocJS := Some(jsdocs),
mdocJSLibraries := (jsdocs / Compile / fullOptJS / webpack).value,
mdocJS := Some(jswebsitedocs),
// mdocJSLibraries := (jsdocs / Compile / fullOptJS).outputFiles.map { path =>
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
// Attributed.blank(path.toFile)
// },
MdocPlugin.mdocJSWorkerClasspath := {
val _ = (jsWorker / Compile / compile).value

Expand Down
3 changes: 1 addition & 2 deletions cli/src/main/scala/mdoc/internal/cli/MdocProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ object MdocProperties {
out = getPath("out")
)
}
def default(cwd: AbsolutePath): MdocProperties = {
val path = "mdoc.properties"
def default(cwd: AbsolutePath, path: String): MdocProperties = {
Option(this.getClass.getClassLoader.getResourceAsStream(path)) match {
case Some(resource) =>
val props = new java.util.Properties()
Expand Down
27 changes: 21 additions & 6 deletions cli/src/main/scala/mdoc/internal/cli/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import mdoc.internal.markdown.{GitHubIdGenerator, ReplVariablePrinter}
import mdoc.internal.cli.CliEnrichments._
import pprint.TPrint
import pprint.TPrintColors
import java.nio.file.Path
Quafadas marked this conversation as resolved.
Show resolved Hide resolved

class Section(val name: String) extends StaticAnnotation

Expand Down Expand Up @@ -155,7 +156,15 @@ case class Settings(
variablePrinter: Variable => String = ReplVariablePrinter,
@Hidden()
@Description("The Coursier logger used to report progress bars when downloading dependencies")
coursierLogger: coursierapi.Logger = coursierapi.Logger.progressBars()
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
coursierLogger: coursierapi.Logger = coursierapi.Logger.progressBars(),
@Description(
"The absolute path to a file containing an import map file in this format; https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap"
)
importMapPath: Option[AbsolutePath] = None,
@Description(
"Defaults to mdoc.properties. This is the name of the properties file the CLI will read. It is assumed to be a resource on the classpath. Use the --extra-jars flag to customise the directory it is found in"
)
propertyFileName: String = "mdoc.properties"
) extends mdoc.parser.ParserSettings {

val isMarkdownFileExtension = markdownExtensions.toSet
Expand Down Expand Up @@ -261,9 +270,9 @@ object Settings { // extends MetaconfigScalametaImplicits with Decoders with Set
cwd = cwd
)
}
def default(cwd: AbsolutePath): Settings = {
def default(cwd: AbsolutePath, filename: String): Settings = {
val base = baseDefault(cwd)
val props = MdocProperties.default(cwd)
val props = MdocProperties.default(cwd, filename)
base.withProperties(props)
}

Expand Down Expand Up @@ -294,14 +303,20 @@ object Settings { // extends MetaconfigScalametaImplicits with Decoders with Set
generic.deriveDecoder[Settings](base)
}

def fromCliArgs(args: List[String], base: Settings): Configured[Settings] = {
def fromCliArgs(args: List[String], workingDirectory: Path): Configured[Settings] = {
Conf
.parseCliArgs[Settings](args)
.andThen(conf => {
val base =
Settings.default(
AbsolutePath(workingDirectory),
conf.get[String]("propertyFileName").getOrElse("mdoc.properties")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you used "mdoc.properties" above, line 167, please create a constant and use in both places.

Copy link
Contributor Author

@Quafadas Quafadas Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be I'm missing something, but as far as I can tell, this would require the constant to be moved outside of the Settings class - it would essentially become a global variable in mdoc.internal.cli

Is this what you intend? It would not be my choice.

)
val cwd = conf.get[String]("cwd").map(AbsolutePath(_)(base.cwd)).getOrElse(base.cwd)
conf.as[Settings](decoder(base.copy(cwd = cwd)))
conf
.as[Settings](decoder(base.copy(cwd = cwd)))
.map(_.addSite(base.site))
})
.map(_.addSite(base.site))
Quafadas marked this conversation as resolved.
Show resolved Hide resolved
}

def write(set: Settings) = ConfEncoder[Settings].write(set)
Expand Down
Loading