diff --git a/packages/dynamic-import/client.js b/packages/dynamic-import/client.js index 2be3d7fa2c..367888c129 100644 --- a/packages/dynamic-import/client.js +++ b/packages/dynamic-import/client.js @@ -1,5 +1,7 @@ var Module = module.constructor; var cache = require("./cache.js"); +var HTTP = require("meteor/http").HTTP; +var meteorInstall = require("meteor/modules").meteorInstall; // Call module.dynamicImport(id) to fetch a module and any/all of its // dependencies that have not already been fetched, and evaluate them as @@ -111,16 +113,12 @@ function makeModuleFunction(id, source, options) { } function fetchMissing(missingTree) { - // Update lastFetchMissingPromise immediately, without waiting for - // the results to be delivered. return new Promise(function (resolve, reject) { - Meteor.call( - "__dynamicImport", - missingTree, - function (error, resultsTree) { - error ? reject(error) : resolve(resultsTree); - } - ); + HTTP.call("POST", Meteor.absoluteUrl("__dynamicImport"), { + data: missingTree + }, function (error, result) { + error ? reject(error) : resolve(result.data); + }); }); } diff --git a/packages/dynamic-import/package.js b/packages/dynamic-import/package.js index 5180e2ffb6..953d91811d 100644 --- a/packages/dynamic-import/package.js +++ b/packages/dynamic-import/package.js @@ -14,9 +14,8 @@ Package.onUse(function (api) { api.use("modules"); api.use("promise"); - api.use("ddp"); - api.use("check", "server"); - api.use("ecmascript", "server"); + api.use("webapp", "server"); + api.use("http"); api.mainModule("client.js", "client"); api.mainModule("server.js", "server"); diff --git a/packages/dynamic-import/server.js b/packages/dynamic-import/server.js index 37490c0553..82e07eb3ce 100644 --- a/packages/dynamic-import/server.js +++ b/packages/dynamic-import/server.js @@ -1,17 +1,18 @@ -import assert from "assert"; -import { readFileSync } from "fs"; -import { - join as pathJoin, - normalize as pathNormalize, -} from "path"; - -import { check } from "meteor/check"; - -import "./security.js"; -import "./client.js"; +"use strict"; +const assert = require("assert"); +const { readFileSync } = require("fs"); +const { + join: pathJoin, + normalize: pathNormalize, +} = require("path"); const hasOwn = Object.prototype.hasOwnProperty; +const { WebApp } = require("meteor/webapp"); + +require("./security.js"); +require("./client.js"); + Object.keys(dynamicImportInfo).forEach(platform => { const info = dynamicImportInfo[platform]; if (info.dynamicRoot) { @@ -19,30 +20,40 @@ Object.keys(dynamicImportInfo).forEach(platform => { } }); -Meteor.methods({ - __dynamicImport(tree) { - check(tree, Object); - this.unblock(); - - const platform = this.connection ? "web.browser" : "server"; - const pathParts = []; - - function walk(node) { - if (node && typeof node === "object") { - Object.keys(node).forEach(name => { - pathParts.push(name); - node[name] = walk(node[name]); - assert.strictEqual(pathParts.pop(), name); - }); - } else { - return read(pathParts, platform); - } - return node; - } - - return walk(tree); +WebApp.connectHandlers.use( + "/__dynamicImport", + function (request, response) { + assert.strictEqual(request.method, "POST"); + const chunks = []; + request.on("data", chunk => chunks.push(chunk)); + request.on("end", () => { + response.setHeader("Content-Type", "application/json"); + response.end(JSON.stringify(readTree( + JSON.parse(Buffer.concat(chunks)), + "web.browser" + ))); + }); } -}); +); + +function readTree(tree, platform) { + const pathParts = []; + + function walk(node) { + if (node && typeof node === "object") { + Object.keys(node).forEach(name => { + pathParts.push(name); + node[name] = walk(node[name]); + assert.strictEqual(pathParts.pop(), name); + }); + } else { + return read(pathParts, platform); + } + return node; + } + + return walk(tree); +} function read(pathParts, platform) { const { dynamicRoot } = dynamicImportInfo[platform];