Skip to content

Commit

Permalink
fix(marko): prevent loading main entry by default
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed May 19, 2020
1 parent a08b55a commit 61c954e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
25 changes: 0 additions & 25 deletions packages/marko/src/index.js
@@ -1,29 +1,4 @@
"use strict";

function fixFlush() {
try {
var OutgoingMessage = require("http").OutgoingMessage;
if (
OutgoingMessage.prototype.flush &&
OutgoingMessage.prototype.flush.toString().indexOf("deprecated") !== -1
) {
// Yes, we are monkey-patching http. This method should never have been added and it was introduced on
// the iojs fork. It was quickly deprecated and I'm 99% sure no one is actually using it.
// See:
// - https://github.com/marko-js/async-writer/issues/3
// - https://github.com/nodejs/node/issues/2920
//
// This method causes problems since marko looks for the flush method and calls it found.
// The `res.flush()` method is introduced by the [compression](https://www.npmjs.com/package/compression)
// middleware, but, otherwise, it should typically not exist.
delete require("http").OutgoingMessage.prototype.flush;
}
} catch (e) {
/* ignore error */
}
}

fixFlush();

exports.createOut = require("./runtime/createOut");
exports.load = require("./loader");
3 changes: 1 addition & 2 deletions packages/marko/src/loader/index.js
Expand Up @@ -3,8 +3,7 @@
var nodePath = require("path");
var fs = require("fs");
var Module = require("module").Module;
var compilerPath = nodePath.join(__dirname, "../compiler");
var markoCompiler = require(compilerPath);
var markoCompiler = require("../compiler");
var cwd = process.cwd();
var fsOptions = { encoding: "utf8" };

Expand Down
18 changes: 14 additions & 4 deletions packages/marko/src/runtime/html/index.js
@@ -1,6 +1,18 @@
"use strict";

var Template;
var OutgoingMessageProto = require("http").OutgoingMessage.prototype;
if (String(OutgoingMessageProto.flush).indexOf("deprecated") !== -1) {
// Yes, we are monkey-patching http. This method should never have been added and it was introduced on
// the iojs fork. It was quickly deprecated and I'm 99% sure no one is actually using it.
// See:
// - https://github.com/marko-js/async-writer/issues/3
// - https://github.com/nodejs/node/issues/2920
//
// This method causes problems since marko looks for the flush method and calls it found.
// The `res.flush()` method is introduced by the [compression](https://www.npmjs.com/package/compression)
// middleware, but, otherwise, it should typically not exist.
delete OutgoingMessageProto.flush;
}

/**
* Method is for internal usage only. This method
Expand All @@ -12,10 +24,8 @@ exports.t = function createTemplate(path) {
return new Template(path);
};

require("../../");

var AsyncStream = require("./AsyncStream");
Template = require("./Template");
var Template = require("./Template");

function createOut(globalData, parent, state, buffer) {
return new AsyncStream(globalData, parent, state, buffer);
Expand Down
1 change: 0 additions & 1 deletion packages/marko/src/runtime/vdom/index.js
@@ -1,5 +1,4 @@
"use strict";
require("../../");

// helpers provide a core set of various utility methods
// that are available in every template
Expand Down

0 comments on commit 61c954e

Please sign in to comment.