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

Add additionalRequires from require to property #682

Draft
wants to merge 3 commits into
base: development-4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ class AsciidoctorJSExtension extends AbstractAsciidoctorJSExtension {
* @Return Set of strings in a format suitable for {@code npm --require}.
*/
Set<String> getRequires() {
Set<String> reqs = [].toSet()
@SuppressWarnings('UnnecessaryGetter')
List<String> reqs = getAllAdditionalRequires().collect { asModuleVersionString(it) }

final String docbook = moduleVersion(modules.docbook)
if (docbook) {
reqs.add(packageDescriptorFor(modules.docbook).toString())
}

reqs
(reqs as Set).asImmutable()
}

/** A configuration containing all required NPM packages.
Expand All @@ -141,6 +142,10 @@ class AsciidoctorJSExtension extends AbstractAsciidoctorJSExtension {
final NodeJSDependencyFactory factory = new NodeJSDependencyFactory(project, nodejs, npm)
final List<SelfResolvingDependency> deps = [factory.createDependency(PACKAGE_ASCIIDOCTOR, getVersion())]

deps.addAll( getAllAdditionalRequires().collect {
factory.createDependency( it.packageName, it.tagName, it.scope )
})

if (docbook) {
deps.add(factory.createDependency(packageDescriptorFor(modules.docbook), docbook))
}
Expand Down Expand Up @@ -218,4 +223,18 @@ class AsciidoctorJSExtension extends AbstractAsciidoctorJSExtension {
private AsciidoctorJSExtension getExtFromProject() {
task ? (AsciidoctorJSExtension) projectExtension : this
}

private String asModuleVersionString(NpmDependency it) {
final String scope = it.scope
final String name = it.packageName
final String version = it.tagName

final String r = (scope != null && !scope.isEmpty()) ? ("@${scope}/${name}") : name

if (version != null && !version.isEmpty()) {
r + "@${version}"
} else {
r
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ class AsciidoctorJSExtensionSpec extends Specification {

then:
asciidoctorjs.modules.docbook.version == versionMap['asciidoctorjs.docbook']
}

void 'requires property contains npm modules added with require'() {
when:
asciidoctorjs.require 'my_module1', 'my_tag1'
asciidoctorjs.require 'my_scope2', 'my_module2', 'my_tag2'

then:
asciidoctorjs.requires.find {it.equals('my_module1@my_tag1')}
asciidoctorjs.requires.find {it.equals('@my_scope2/my_module2@my_tag2')}
}

void 'docbook-converter added as requires'() {
when:
asciidoctorjs.require 'my_module1', 'my_tag1'
asciidoctorjs.modules.docbook.use()

then:
asciidoctorjs.requires.find {it.equals('my_module1@my_tag1')}
asciidoctorjs.requires.find { it.contains('docbook-converter') }
}

}