зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1583533 - Remove unused webpack helpers from DevTools codebase r=Honza
Differential Revision: https://phabricator.services.mozilla.com/D47037 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0fda1a24d1
Коммит
e50bf68b2f
|
@ -18,7 +18,6 @@ DIRS += [
|
|||
'source-map',
|
||||
'sourceeditor',
|
||||
'vendor',
|
||||
'webpack',
|
||||
'widgets',
|
||||
]
|
||||
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
# Webpack Support
|
||||
This directory contains modules intended to support and customize
|
||||
DevTools source bundling.
|
||||
|
||||
DevTools use Webpack to generate bundles for individual tools,
|
||||
which allow e.g. running them on top of the Launchpad (within
|
||||
a browser tab).
|
||||
|
||||
Custom loaders implemented in this directory are mostly used to
|
||||
rewrite existing code, so it's understandable for Webpack.
|
||||
|
||||
For example:
|
||||
|
||||
The following piece of code is using `lazyRequireGetter` that
|
||||
is unknown to Webpack.
|
||||
|
||||
```
|
||||
loader.lazyRequireGetter(this, "EventEmitter",
|
||||
"devtools/shared/event-emitter");
|
||||
```
|
||||
|
||||
In order to properly bundle `devtools/shared/event-emitter` module
|
||||
the code needs to be translated into:
|
||||
|
||||
```
|
||||
let EventEmitter = require("devtools/shared/event-emitter");
|
||||
```
|
||||
|
||||
See more in `rewrite-lazy-require`
|
|
@ -1,9 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DIRS += [
|
||||
'shims',
|
||||
]
|
|
@ -1,12 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Replace all occurrences of "this.browserRequire(" by "require(".
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
return content.replace(/this\.browserRequire\(/g, "require(");
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
|
||||
return content.replace(
|
||||
'loader.lazyImporter(this, "findCssSelector", "resource://gre/modules/css-selector.js");',
|
||||
"let findCssSelector = function () {};"
|
||||
);
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Remove the header code from event-emitter.js. This code confuses
|
||||
// webpack.
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
|
||||
const lines = content.split("\n");
|
||||
let ignoring = false;
|
||||
const newLines = [];
|
||||
for (const line of lines) {
|
||||
if (/function \(factory\)/.test(line)) {
|
||||
ignoring = true;
|
||||
} else if (/call\(this, function /.test(line)) {
|
||||
ignoring = false;
|
||||
} else if (!ignoring && line !== "});") {
|
||||
newLines.push(line);
|
||||
}
|
||||
}
|
||||
return newLines.join("\n");
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
|
||||
return content.replace(
|
||||
/loader.lazyGetter\(this,\s*"([^"]+)"\s*,\s*(function\s*\(\)\s*\{[\s\S]*?\})\);/g,
|
||||
"let $1 = ($2)();"
|
||||
);
|
||||
};
|
|
@ -1,20 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
|
||||
// taking care of "named" depedencies.
|
||||
const res = content.replace(
|
||||
/loader.lazyRequireGetter\(this,\s*"([^"]+)",[^"]*"([^"]+)", true\);/g,
|
||||
'let { $1 } = require("$2")'
|
||||
);
|
||||
// And then of direct ones.
|
||||
return res.replace(
|
||||
/loader.lazyRequireGetter\(this,\s*"([^"]+)",[^"]*"([^"]+)"(, false)?\);/g,
|
||||
'let $1 = require("$2")'
|
||||
);
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Remove the "raw!" prefix used in some require which confuses webpack.
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
return content.replace(/raw\!/g, "");
|
||||
};
|
|
@ -1,19 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
|
||||
return content
|
||||
.replace(
|
||||
"require(REACT_PATH)",
|
||||
'require("devtools/client/shared/vendor/react")'
|
||||
)
|
||||
.replace(
|
||||
"require(REDUX_PATH)",
|
||||
'require("devtools/client/shared/vendor/redux")'
|
||||
);
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function(content) {
|
||||
this.cacheable && this.cacheable();
|
||||
return content.replace(
|
||||
/lazyRequire\(this,\s*([^,]+),\s*"([^"]+)"\);/g,
|
||||
"let { $2 } = require($1)"
|
||||
);
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
// Extend from the devtools eslintrc.
|
||||
"extends": "../../../../.eslintrc.js",
|
||||
|
||||
"rules": {
|
||||
// All code in this directory must be content-clean.
|
||||
"mozilla/reject-some-requires": ["error", "^(chrome|chrome:.*|resource:.*|devtools/server/.*|.*\\.jsm|devtools/shared/platform/(chome|content)/.*)$"],
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
var platform = "";
|
||||
|
||||
if (/Mac OS X/.test(window.navigator.userAgent)) {
|
||||
platform = "macosx";
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AppConstants: {
|
||||
platform,
|
||||
},
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* DevTools is a class that represents a set of developer tools, it holds a
|
||||
* set of tools and keeps track of open toolboxes in the browser.
|
||||
*/
|
||||
const DevTools = {
|
||||
chromeWindowType: "navigator:browser",
|
||||
getToolbox: function() {
|
||||
return {};
|
||||
},
|
||||
};
|
||||
|
||||
exports.gDevTools = DevTools;
|
|
@ -1,16 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DevToolsModules(
|
||||
'platform-clipboard-stub.js',
|
||||
'platform-stack-stub.js',
|
||||
)
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini']
|
||||
|
||||
MOCHITEST_MANIFESTS += [
|
||||
'test/mochitest.ini',
|
||||
]
|
|
@ -1,28 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Helpers for clipboard handling.
|
||||
|
||||
/* globals document */
|
||||
|
||||
"use strict";
|
||||
|
||||
function copyString(string) {
|
||||
const doCopy = function(e) {
|
||||
e.clipboardData.setData("text/plain", string);
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
document.addEventListener("copy", doCopy);
|
||||
document.execCommand("copy", false, null);
|
||||
document.removeEventListener("copy", doCopy);
|
||||
}
|
||||
|
||||
function getText() {
|
||||
// See bug 1295692.
|
||||
return null;
|
||||
}
|
||||
|
||||
exports.copyString = copyString;
|
||||
exports.getText = getText;
|
|
@ -1,53 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// A few wrappers for stack-manipulation. This version of the module
|
||||
// is used in content code. Note that this particular copy of the
|
||||
// file can only be loaded via require(), because Cu.import doesn't
|
||||
// exist in the content case. So, we don't need the code to handle
|
||||
// both require and import here.
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Looks like Cu.callFunctionWithAsyncStack, but just calls the callee.
|
||||
*/
|
||||
function callFunctionWithAsyncStack(callee, stack, id) {
|
||||
return callee();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Nth path from the stack excluding substr.
|
||||
*
|
||||
* @param {Number}
|
||||
* n the Nth path from the stack to describe.
|
||||
* @param {String} substr
|
||||
* A segment of the path that should be excluded.
|
||||
*/
|
||||
function getNthPathExcluding(n, substr) {
|
||||
if (isWorker) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let stack = new Error().stack.split("\n");
|
||||
stack = stack.filter(line => {
|
||||
return line && !line.includes(substr);
|
||||
});
|
||||
return stack[n + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a stack object that can be serialized and, when
|
||||
* deserialized, passed to callFunctionWithAsyncStack.
|
||||
*/
|
||||
function getStack() {
|
||||
// There's no reason for this to do anything fancy, since it's only
|
||||
// used to pass back into callFunctionWithAsyncStack, which we can't
|
||||
// implement.
|
||||
return null;
|
||||
}
|
||||
|
||||
exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack;
|
||||
exports.getNthPathExcluding = getNthPathExcluding;
|
||||
exports.getStack = getStack;
|
|
@ -1,6 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
// Extend from the common devtools xpcshell eslintrc config.
|
||||
"extends": "../../../../../.eslintrc.xpcshell.js"
|
||||
};
|
|
@ -1,7 +0,0 @@
|
|||
[DEFAULT]
|
||||
support-files =
|
||||
|
||||
[test_clipboard.html]
|
||||
tags = clipboard
|
||||
subsuite = devtools
|
||||
skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
|
|
@ -1,68 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1290230
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 1290230 - clipboard helpers</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
var exports = {}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="pre_do_tests()">
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
|
||||
const RESULT = "lark bunting";
|
||||
|
||||
function doCopy(e) {
|
||||
console.log(e.isTrusted);
|
||||
copyString(RESULT);
|
||||
}
|
||||
|
||||
async function pre_do_tests() {
|
||||
// Temporarily allow content to access all resource:// URIs.
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["security.all_resource_uri_content_accessible", true]
|
||||
]
|
||||
});
|
||||
|
||||
// Load script.
|
||||
await (() => new Promise((resolve) => {
|
||||
var script = document.createElement("script");
|
||||
script.onload = resolve;
|
||||
script.src = "resource://devtools/client/shared/webpack/shims/platform-clipboard-stub.js";
|
||||
document.head.appendChild(script);
|
||||
}))();
|
||||
|
||||
do_tests();
|
||||
}
|
||||
|
||||
function do_tests() {
|
||||
let elt = document.querySelector("#key");
|
||||
elt.addEventListener("keydown", doCopy);
|
||||
|
||||
// Set the clipboard to something other than what we expect.
|
||||
SpecialPowers.clipboardCopyString("snowy owl");
|
||||
|
||||
elt.focus();
|
||||
sendString("x");
|
||||
|
||||
is(SpecialPowers.getClipboardData("text/unicode"), RESULT, "clipboard copying worked");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
<div id="key" tabindex="-1">Type Here</div>
|
||||
</body>
|
|
@ -1,44 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// There isn't really very much about the content stack.js that we can
|
||||
// test, but we'll do what we can.
|
||||
|
||||
"use strict";
|
||||
|
||||
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
|
||||
|
||||
const {
|
||||
callFunctionWithAsyncStack,
|
||||
getStack,
|
||||
getNthPathExcluding,
|
||||
} = require("devtools/client/shared/webpack/shims/platform-stack-stub");
|
||||
|
||||
function f3() {
|
||||
return getNthPathExcluding(2);
|
||||
}
|
||||
|
||||
function f2() {
|
||||
return f3();
|
||||
}
|
||||
|
||||
function f1() {
|
||||
return f2();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
let value = 7;
|
||||
|
||||
const changeValue = () => {
|
||||
value = 9;
|
||||
};
|
||||
|
||||
callFunctionWithAsyncStack(changeValue, getStack(), "test_stack");
|
||||
equal(value, 9, "callFunctionWithAsyncStack worked");
|
||||
|
||||
const stack = getStack();
|
||||
equal(JSON.parse(JSON.stringify(stack)), stack, "stack is serializable");
|
||||
|
||||
const desc = f1();
|
||||
ok(desc.includes("f1"), "stack description includes f1");
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
[DEFAULT]
|
||||
tags = devtools
|
||||
head =
|
||||
firefox-appdir = browser
|
||||
|
||||
[test_stack.js]
|
|
@ -1,29 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
|
||||
/**
|
||||
* Make sure that content of the file is loaded as a text
|
||||
* (no parsing by other loaders)
|
||||
*
|
||||
* Used e.g. for runtime access to colors defined in variables.css
|
||||
*/
|
||||
module.exports.pitch = function(remainingRequest, precedingRequest, data) {
|
||||
if (this.cacheable) {
|
||||
this.cacheable();
|
||||
}
|
||||
|
||||
const request = remainingRequest.split("!");
|
||||
const rawUrl = request[request.length - 1];
|
||||
let content = fs.readFileSync(rawUrl, "utf8");
|
||||
|
||||
// Avoid mix of single & double quotes in a string
|
||||
// (use only double quotes), so we can stringify.
|
||||
content = content.replace("'", '"');
|
||||
|
||||
return "module.exports = " + JSON.stringify(content) + ";";
|
||||
};
|
Загрузка…
Ссылка в новой задаче