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

Remove underscore #11869

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
12da0ed
Move underscore and underscore-tests to deprecated directory
harryadel Jan 13, 2022
91e646f
Remove underscore from tinytest
harryadel Jan 15, 2022
bcc5096
Remove underscore from facts-ui
harryadel Jan 15, 2022
bbd27c8
Remove underscore from twitter-oauth
harryadel Jan 15, 2022
8db7551
Remove underscore from constraint-solver
harryadel Jan 15, 2022
e8a79e2
Set `deprecated: true` to underscore & underscore-tests
harryadel Jan 15, 2022
7f62e44
Remove underscore from geojson-utils
harryadel Jan 15, 2022
f044b1b
Remove underscore from test-helpers
harryadel Jan 18, 2022
b6f173b
Remove underscore from ecmascript
harryadel Jan 18, 2022
287116e
Remove underscore from webapp-hashing
harryadel Jan 18, 2022
283d9d9
Remove underscore from test-in-console
harryadel Jan 18, 2022
596efb7
Remove underscore from package-version-parser
harryadel Jan 18, 2022
f587a68
Remove underscore from test-server-tests-in-console-once
harryadel Jan 18, 2022
6dcb5c2
Remove underscore from reload-safetybelt
harryadel Jan 18, 2022
d174454
Remove underscore from boilerplate-generator
harryadel Jan 18, 2022
dd72753
Remove underscore from diff-sequence
harryadel Jan 18, 2022
c096abb
Remove underscore from mongo
harryadel Jan 18, 2022
2878f30
Remove underscore from logic-solver
harryadel Jan 18, 2022
3bb9e32
Remove underscore from browser policy
harryadel Jan 18, 2022
69b1a06
Remove underscore from browser-policy-content
harryadel Jan 18, 2022
582f1fe
Remove underscore from browser-policy-framing
harryadel Jan 18, 2022
abd2205
Remove underscore from socket-stream-client
harryadel Jan 18, 2022
4894707
Remove underscore from ddp-rate-limiter
harryadel Jan 18, 2022
60450ba
Remove underscore from ddp-client
harryadel Jan 18, 2022
4809a55
Remove underscore from ddp-server
harryadel Jan 18, 2022
dfd3d87
Remove underscore from meteor
harryadel Jan 18, 2022
8cea140
Remove underscore from webapp
harryadel Jan 18, 2022
69be593
Remove underscore from driver.js in test-in-browser
harryadel Jan 18, 2022
531b318
Fix test-in-browser
harryadel Jan 18, 2022
48ad2a0
Add lodash.isstring and lodash.isobject to constraint-solver
harryadel Jan 19, 2022
4062b56
Fix data.forEach
harryadel Jan 19, 2022
943cd62
Add missing packages for browser-policy-content
harryadel Jan 19, 2022
adc4a31
Add missing lodash packages for dpp-client
harryadel Jan 19, 2022
a66f7ed
Fix ddp-server name.forEach
harryadel Jan 19, 2022
40ed0d8
Fix logic-solver tests
harryadel Jan 20, 2022
7978481
Fix test-in-browser
harryadel Jan 20, 2022
c0db941
Make details assignation dynamic
harryadel Jan 20, 2022
da60135
Fix constraint-solver tests
harryadel Jan 20, 2022
9b7d9a1
Fix typo
harryadel Jan 20, 2022
5ec3f6d
Fix webapp tests
harryadel Jan 21, 2022
2bf7bb4
Fix browser-policy tests
harryadel Jan 21, 2022
5986c2d
Fix ddp-client tests
harryadel Jan 22, 2022
988932b
Fix ddp-server tests
harryadel Jan 22, 2022
17cbe59
dynamically get property in filter
harryadel Jan 22, 2022
7c60970
Use npm.require instead of import
harryadel Jan 22, 2022
3af2921
Remove underscore from boilerplate-generator-tests
harryadel Jan 22, 2022
119374f
Fix getSortedVersionRecords
harryadel Jan 22, 2022
6b9eb3d
Use createHash directly
harryadel Jan 22, 2022
d81f80e
Remove underscore from docs
harryadel Jan 22, 2022
ecabc20
Add guarding for writes
harryadel Jan 22, 2022
07a47b7
Remove underscore reference in meteor-base README
harryadel Jan 22, 2022
51d9208
Upate blaze submodule
harryadel Jan 22, 2022
1f24594
converts paths value to an array
harryadel Jan 22, 2022
47d0892
Merge branch 'devel' into remove-underscore
harryadel Jan 22, 2022
3d329b3
Replace .indexOf check with .includes
harryadel Jan 25, 2022
c90380f
Blaze 2.6
StorytellerCZ Apr 9, 2022
45cc549
Merge branch 'devel' of github.com:harryadel/meteor into remove-under…
harryadel Apr 9, 2022
553b464
Merge branch 'devel' into remove-underscore
harryadel Apr 9, 2022
67b83cd
Merge branch 'devel' into remove-underscore
harryadel Apr 13, 2022
1054662
Update blaze to the latest commit
harryadel Apr 13, 2022
bf46455
Update blaze-html-templates version
harryadel Apr 14, 2022
d87043d
Remove blaze-html-templates version contrainsts in dynamic-import app
harryadel Apr 14, 2022
3f2319a
Merge branch 'devel' into remove-underscore
harryadel Jun 9, 2022
ed5cb4f
Update non-core blaze submodule
harryadel Sep 22, 2022
5695939
Update blaze non core submodules
harryadel Sep 22, 2022
e25c339
Merge branch 'devel' into remove-underscore
harryadel Sep 22, 2022
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ jobs:
path: ./tmp/results
- persist_to_workspace:
root: .
paths: ./tmp/results/junit
paths: [./tmp/results/junit]
- store_artifacts:
path: ./tmp/results
- store_artifacts:
Expand Down
1 change: 0 additions & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ sidebar_categories:
- packages/random
- packages/server-render
- packages/spacebars
- packages/underscore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for docs you will also need to replace underscore in the Meteor theme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I don't understand. Replace underscore as in some config file or Meteor theme code?

- packages/url
- packages/webapp
Command Line:
Expand Down
1 change: 0 additions & 1 deletion packages/boilerplate-generator-tests/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Npm.depends({
Package.onTest(function (api) {
api.use('ecmascript');
api.use([
'underscore',
'tinytest',
'boilerplate-generator'
], 'server');
Expand Down
6 changes: 1 addition & 5 deletions packages/boilerplate-generator-tests/web.browser-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse, serialize } from 'parse5';
import { generateHTMLForArch } from './test-lib';
import { _ } from 'meteor/underscore';


Tinytest.addAsync(
"boilerplate-generator-tests - web.browser - basic output",
Expand Down Expand Up @@ -66,10 +66,6 @@ Tinytest.addAsync(
async function (test) {
const newHtml = await generateHTMLForArch("web.browser", false);

_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};

test.matches(newHtml, /foo="foobar"/);
test.matches(newHtml, /<link[^<>]*href="[^<>]*bootstrap[^<>]*">/);
test.matches(newHtml, /<script[^<>]*src="[^<>]*templating[^<>]*">/);
Expand Down
5 changes: 1 addition & 4 deletions packages/boilerplate-generator-tests/web.cordova-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse, serialize } from 'parse5';
import { generateHTMLForArch } from './test-lib';
import { _ } from 'meteor/underscore';


Tinytest.addAsync(
"boilerplate-generator-tests - web.cordova - basic output",
Expand Down Expand Up @@ -60,9 +60,6 @@ Tinytest.addAsync(
async function (test) {
const newHtml = await generateHTMLForArch('web.cordova', false);

_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};
test.matches(newHtml, /<link[^<>]*href="[^<>]*bootstrap[^<>]*">/);
test.matches(newHtml, /<script[^<>]*src="[^<>]*templating[^<>]*">/);
test.matches(newHtml, /<script>var a/);
Expand Down
4 changes: 2 additions & 2 deletions packages/boilerplate-generator/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Package.describe({
});

Npm.depends({
"combined-stream2": "1.1.2"
"combined-stream2": "1.1.2",
"lodash.escape": "4.0.1"
});

Package.onUse(api => {
api.use('ecmascript');
api.use('underscore', 'server');
api.mainModule('generator.js', 'server');
api.export('Boilerplate', 'server');
});
98 changes: 94 additions & 4 deletions packages/boilerplate-generator/template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,94 @@
import { _ } from 'meteor/underscore';
import escape from "lodash.escape";

const _ = {};

_.escape = escape;

_.templateSettings = {
evaluate: /<%([\s\S]+?)%>/g,
interpolate: /<%=([\s\S]+?)%>/g,
escape: /<%-([\s\S]+?)%>/g
};

// When customizing `templateSettings`, if you don't want to define an
// interpolation, evaluation or escaping regex, we need one that is
// guaranteed not to match.
var noMatch = /(.)^/;

// Certain characters need to be escaped so that they can be put into a
// string literal.
var escapes = {
"'": "'",
'\\': '\\',
'\r': 'r',
'\n': 'n',
'\t': 't',
'\u2028': 'u2028',
'\u2029': 'u2029'
};

var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;

// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
_.template = function (text, data, settings) {
var render;
settings = Object.assign({}, settings, _.templateSettings);

// Combine delimiters into one regular expression via alternation.
var matcher = new RegExp([
(settings.escape || noMatch).source,
(settings.interpolate || noMatch).source,
(settings.evaluate || noMatch).source
].join('|') + '|$', 'g');

// Compile the template source, escaping string literals appropriately.
var index = 0;
var source = "__p+='";
text.replace(matcher, function (match, escape, interpolate, evaluate, offset) {
source += text.slice(index, offset)
.replace(escaper, function (match) { return '\\' + escapes[match]; });

if (escape) {
source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
}
if (interpolate) {
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
}
if (evaluate) {
source += "';\n" + evaluate + "\n__p+='";
}
index = offset + match.length;
return match;
});
source += "';\n";

// If a variable is not specified, place data values in local scope.
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';

source = "var __t,__p='',__j=Array.prototype.join," +
"print=function(){__p+=__j.call(arguments,'');};\n" +
source + "return __p;\n";

try {
render = new Function(settings.variable || 'obj', '_', source);
} catch (e) {
e.source = source;
throw e;
}

if (data) return render(data, _);
var template = function (data) {
return render.call(this, data, _);
};

// Provide the compiled function source as a convenience for precompilation.
template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';

return template;
};


// As identified in issue #9149, when an application overrides the default
// _.template settings using _.templateSettings, those new settings are
Expand All @@ -7,8 +97,8 @@ import { _ } from 'meteor/underscore';
// been verified to work are overridden here on each _.template call.
export default function template(text) {
return _.template(text, null, {
evaluate : /<%([\s\S]+?)%>/g,
interpolate : /<%=([\s\S]+?)%>/g,
escape : /<%-([\s\S]+?)%>/g,
evaluate: /<%([\s\S]+?)%>/g,
interpolate: /<%=([\s\S]+?)%>/g,
escape: /<%-([\s\S]+?)%>/g,
});
};
48 changes: 27 additions & 21 deletions packages/browser-policy-content/browser-policy-content.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const isEmpty = Npm.require('lodash.isempty');
const has = Npm.require('lodash.has');
const union = Npm.require('lodash.union');

// By adding this package, you get the following default policy:
// No eval or other string-to-code, and content can only be loaded from the
// same origin as the app (except for XHRs and websocket connections, which can
Expand Down Expand Up @@ -56,12 +60,12 @@ BrowserPolicy.content = {};
var parseCsp = function (csp) {
var policies = csp.split("; ");
cspSrcs = {};
_.each(policies, function (policy) {
policies.forEach(function (policy) {
if (policy[policy.length - 1] === ";")
policy = policy.substring(0, policy.length - 1);
var srcs = policy.split(" ");
var directive = srcs[0];
if (_.indexOf(srcs, keywords.none) !== -1)
if (srcs.indexOf(keywords.none) !== -1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use includes here. Should be a tiny bit faster as includes returns boolean.

cspSrcs[directive] = null;
else
cspSrcs[directive] = srcs.slice(1);
Expand All @@ -72,22 +76,24 @@ var parseCsp = function (csp) {
"browser-policy must specify a default-src.");

// Copy default-src sources to other directives.
_.each(cspSrcs, function (sources, directive) {
cspSrcs[directive] = _.union(sources || [], cspSrcs["default-src"] || []);
Object.entries(cspSrcs).forEach(function ([directive, sources]) {
cspSrcs[directive] = union(sources || [], cspSrcs["default-src"] || []);
});
};

var removeCspSrc = function (directive, src) {
cspSrcs[directive] = _.without(cspSrcs[directive] || [], src);
cspSrcs[directive] = (cspSrcs[directive] || []).filter(function(value) {
return value !== src;
});
};

// Prepare for a change to cspSrcs. Ensure that we have a key in the dictionary
// and clear any cached CSP.
var prepareForCspDirective = function (directive) {
cspSrcs = cspSrcs || {};
cachedCsp = null;
if (! _.has(cspSrcs, directive))
cspSrcs[directive] = _.clone(cspSrcs["default-src"]);
if (!has(cspSrcs, directive))
cspSrcs[directive] = [...cspSrcs["default-src"]];
};

// Add `src` to the list of allowed sources for `directive`, with the
Expand All @@ -100,7 +106,7 @@ var prepareForCspDirective = function (directive) {
// - Trim trailing slashes from `src`, since some browsers interpret
// "foo.com/" as "foo.com" and some don't.
var addSourceForDirective = function (directive, src) {
if (_.contains(_.values(keywords), src)) {
if (Object.values(keywords).includes(src)) {
cspSrcs[directive].push(src);
} else {
var toAdd = [];
Expand All @@ -123,7 +129,7 @@ var addSourceForDirective = function (directive, src) {
}
}

_.each(toAdd, function (s) {
toAdd.forEach(function (s) {
cspSrcs[directive].push(s);
});
}
Expand All @@ -148,23 +154,23 @@ var setWebAppInlineScripts = function (value) {
WebAppInternals.setInlineScriptsAllowed(value);
};

_.extend(BrowserPolicy.content, {
Object.assign(BrowserPolicy.content, {
allowContentTypeSniffing: function () {
contentSniffingAllowed = true;
},
// Exported for tests and browser-policy-common.
_constructCsp: function () {
if (! cspSrcs || _.isEmpty(cspSrcs))
if (! cspSrcs || isEmpty(cspSrcs))
return null;

if (cachedCsp)
return cachedCsp;

var header = _.map(cspSrcs, function (srcs, directive) {
var header = Object.entries(cspSrcs).map(function ([directive, srcs]) {
srcs = srcs || [];
if (_.isEmpty(srcs))
if (isEmpty(srcs))
srcs = [keywords.none];
var directiveCsp = _.uniq(srcs).join(" ");
var directiveCsp = [...new Set(srcs)].join(" ");
return directive + " " + directiveCsp + ";";
});

Expand All @@ -187,7 +193,7 @@ _.extend(BrowserPolicy.content, {

_keywordAllowed: function (directive, keyword) {
return (cspSrcs[directive] &&
_.indexOf(cspSrcs[directive], keyword) !== -1);
cspSrcs[directive].indexOf(keyword) !== -1);
},

// Helpers for creating content security policies
Expand Down Expand Up @@ -228,7 +234,7 @@ _.extend(BrowserPolicy.content, {
},
allowOriginForAll: function (origin) {
prepareForCspDirective("default-src");
_.each(_.keys(cspSrcs), function (directive) {
Object.keys(cspSrcs).forEach(function (directive) {
addSourceForDirective(directive, origin);
});
},
Expand Down Expand Up @@ -260,12 +266,12 @@ var resources = [
{ methodResource: "Frame", directive: "frame-src" },
{ methodResource: "FrameAncestors", directive: "frame-ancestors" }
];
_.each(resources,
 function (resource) {
var directive = resource.directive;
var methodResource = resource.methodResource;
resources.forEach(function (resource) {
var directive = resource.directive;
var methodResource = resource.methodResource;
var allowMethodName = "allow" + methodResource + "Origin";
var disallowMethodName = "disallow" + methodResource;
var allowDataMethodName = "allow" + methodResource + "DataUrl";
var allowDataMethodName = "allow" + methodResource + "DataUrl";
var allowBlobMethodName = "allow" + methodResource + "BlobUrl";
var allowSelfMethodName = "allow" + methodResource + "SameOrigin";

Expand Down Expand Up @@ -302,4 +308,4 @@ _.each(resources,
 function (resource) {

setDefaultPolicy();

exports.BrowserPolicy = BrowserPolicy;
exports.BrowserPolicy = BrowserPolicy;
8 changes: 7 additions & 1 deletion packages/browser-policy-content/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ Package.describe({
version: "1.1.1"
});

Npm.depends({
'lodash.isempty': '4.4.0',
'lodash.has': '4.5.2',
'lodash.union': '4.6.0'
})

Package.onUse(function (api) {
api.use("modules");
api.use(["underscore", "browser-policy-common", "webapp"], "server");
api.use(["browser-policy-common", "webapp"], "server");
api.imply(["browser-policy-common"], "server");
api.mainModule("browser-policy-content.js", "server");
});
2 changes: 1 addition & 1 deletion packages/browser-policy-framing/browser-policy-framing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var xFrameOptions = defaultXFrameOptions;
const BrowserPolicy = require("meteor/browser-policy-common").BrowserPolicy;
BrowserPolicy.framing = {};

_.extend(BrowserPolicy.framing, {
Object.assign(BrowserPolicy.framing, {
// Exported for tests and browser-policy-common.
_constructXFrameOptions: function () {
return xFrameOptions;
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-policy-framing/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Package.describe({

Package.onUse(function (api) {
api.use("modules");
api.use(["underscore", "browser-policy-common"], "server");
api.use(["browser-policy-common"], "server");
api.imply(["browser-policy-common"], "server");
api.mainModule("browser-policy-framing.js", "server");
});
Loading