Skip to content

Commit

Permalink
[js] Support for out load time dependency detecting CompUnit::Repo sc…
Browse files Browse the repository at this point in the history
…heme
  • Loading branch information
pmurias committed Nov 7, 2018
1 parent 9df074b commit 78389aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/vm/js/make-release.js
Expand Up @@ -74,6 +74,7 @@ fs.writeFileSync(path.join(releaseDir, 'package.json'), JSON.stringify({
"dependencies": { "dependencies": {
"nqp-runtime": version, "nqp-runtime": version,
"perl6-runtime": version, "perl6-runtime": version,
"nqp-js-on-js": version "nqp-js-on-js": version,
"tmp": "0.0.33"
} }
}, null, 2)); }, null, 2));
32 changes: 25 additions & 7 deletions src/vm/js/rakudo-library.js
@@ -1,3 +1,6 @@
const fs = require('fs');
const tmp = require('tmp');

const nqp = require('nqp-runtime'); const nqp = require('nqp-runtime');
const oldRun = nqp.run; const oldRun = nqp.run;


Expand All @@ -19,20 +22,35 @@ nqp.args = function(calledFrom) {


const code = require('./rakudo.js'); const code = require('./rakudo.js');



const core = require('nqp-runtime/core.js'); const core = require('nqp-runtime/core.js');


module.exports = function(source) { module.exports = function(source) {
passedArgs = ['perl6-js', '--target=js', source]; const tmpFile = tmp.tmpNameSync();

passedArgs = ['perl6-js', '--output', tmpFile, '--target=js', source];


const oldWritefh = nqp.op.getstdout().constructor.prototype.$$writefh; const oldWritefh = nqp.op.getstdout().constructor.prototype.$$writefh;
let output; const output = [];
nqp.op.getstdout().constructor.prototype.$$writefh = function(buf) { nqp.op.getstdout().constructor.prototype.$$writefh = function(buf) {
output = core.toRawBuffer(buf).toString(); output.push(core.toRawBuffer(buf));
} }

code(); code();

nqp.op.getstdout().constructor.prototype.$$writefh = oldWritefh; nqp.op.getstdout().constructor.prototype.$$writefh = oldWritefh;
return output; const lines = Buffer.concat(output).toString().split(/\n/);
};



const loaded = [];

for (const line of lines) {
let match;
if (/^[A-Z0-9]{40}\0/.test(line)) {
} else if (match = line.match(/^load-unit: (.+)/)) {
loaded.push(match[1]);
} else {
}
}


return {js: fs.readFileSync(tmpFile, 'utf8'), loaded: loaded};
};

0 comments on commit 78389aa

Please sign in to comment.