Skip to content
Permalink
Browse files

[js] Add a basic form of use Foo:from<node.js>

  • Loading branch information...
pmurias committed Jun 20, 2019
1 parent 07f6ccc commit 88712199119a8e3cd409702d35a3ea597befeae8
@@ -12,6 +12,7 @@ class CompUnit::Repository::Java { ... }

#?if js
class CompUnit::Repository::FileSystemWithRecording { ... }
class CompUnit::Repository::NodeJs { ... }
#?endif

class CompUnit::RepositoryRegistry {
@@ -351,6 +352,9 @@ class CompUnit::RepositoryRegistry {
'ap', CompUnit::Repository::AbsolutePath,
'nqp', CompUnit::Repository::NQP,
'perl5', CompUnit::Repository::Perl5,
#?if js
'nodejs', CompUnit::Repository::NodeJs,
#?endif
#?if jvm
'javart', CompUnit::Repository::JavaRuntime,
'java', CompUnit::Repository::Java,
@@ -0,0 +1,60 @@
my class CompUnit::Repository::NodeJs does CompUnit::Repository does CompUnit::Repository::Locally {
method need(
CompUnit::DependencySpecification $spec,
CompUnit::PrecompilationRepository $precomp = self.precomp-repository(),
)
returns CompUnit:D

This comment has been minimized.

Copy link
@ugexe

ugexe Jun 20, 2019

Member

We use the --> Type:D form of return typing in core

{

if $spec.from eq 'node.js' {
my $module = nqp::getcomp('JavaScript').eval(
'return function(name, prefix) {return require(require.resolve(name, {paths: [prefix]}))}'
)($spec.short-name, $.prefix.Str);


my $stash = Stash.new();

my sub export {
Map.new($spec.short-name, $module);
}

my $handle = (CompUnit::Handle.from-unit($stash) does my role :: {
has &!EXPORT;
submethod with-export(&EXPORT) {
&!EXPORT := &EXPORT;
self
}
method export-package() returns Stash {
Stash.new
}
method export-sub() returns Callable {
&!EXPORT
}
}).with-export(&export);

return CompUnit.new(
:short-name($spec.short-name),
:$handle,
:repo(self),
:repo-id($spec.short-name),
:from($spec.from),
);
}


return self.next-repo.need($spec, $precomp) if self.next-repo;
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
}

method loaded() {
[]
}

method id() {
'Node.js'
}

method short-id {
'nodejs'
}
}
@@ -207,6 +207,7 @@ src/core/CompUnit/Repository/NQP.pm6
src/core/CompUnit/Repository/Perl5.pm6
src/core/CompUnit/Repository/Unknown.pm6
src/vm/js/CompUnit/Repository/FileSystemWithRecording.pm6
src/vm/js/CompUnit/Repository/NodeJs.pm6
src/core/Argfiles.pm6
src/core/Process.pm6
src/core/Slang.pm6

0 comments on commit 8871219

Please sign in to comment.
You can’t perform that action at this time.