Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Created June 7, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonLaster/f6faf2d9a9e3c185804ad85791ca59a8 to your computer and use it in GitHub Desktop.
Save jasonLaster/f6faf2d9a9e3c185804ad85791ca59a8 to your computer and use it in GitHub Desktop.
diff --git a/devtools/client/debugger/src/components/App.js b/devtools/client/debugger/src/components/App.js
index b72eba05a0f3..d138e8ee014a 100644
--- a/devtools/client/debugger/src/components/App.js
+++ b/devtools/client/debugger/src/components/App.js
@@ -51,7 +51,7 @@ import "./shared/menu.css";
import "./shared/reps.css";
import SplitBox from "devtools-splitter";
-import ProjectSearch from "./ProjectSearch";
+// import ProjectSearch from "./ProjectSearch";
import PrimaryPanes from "./PrimaryPanes";
import Editor from "./Editor";
import SecondaryPanes from "./SecondaryPanes";
@@ -104,7 +104,7 @@ class App extends Component<Props, State> {
return { shortcuts, l10n: L10N };
};
- componentDidMount() {
+ async componentDidMount() {
horizontalLayoutBreakpoint.addListener(this.onLayoutChange);
verticalLayoutBreakpoint.addListener(this.onLayoutChange);
this.setOrientation();
@@ -125,6 +125,8 @@ class App extends Component<Props, State> {
shortcuts.on("Escape", this.onEscape);
shortcuts.on("Cmd+/", this.onCommandSlash);
+
+ this.ProjectSearch = await import("./ProjectSearch");
}
componentWillUnmount() {
@@ -251,7 +253,6 @@ class App extends Component<Props, State> {
/>
) : null}
<EditorFooter horizontal={horizontal} />
- <ProjectSearch />
</div>
</div>
);
diff --git a/devtools/client/shared/build/build-debugger.js b/devtools/client/shared/build/build-debugger.js
index 2baed1a3785e..4a4c13166519 100644
--- a/devtools/client/shared/build/build-debugger.js
+++ b/devtools/client/shared/build/build-debugger.js
@@ -115,6 +115,58 @@ function shouldLazyLoad(value) {
);
}
+function transformImports({ template, types: t }) {
+ const buildImport = template("Promise.resolve().then(() => MODULE)");
+
+ return {
+ // NOTE: Once we drop support for Babel <= v6 we should
+ // update this to import from @babel/plugin-syntax-dynamic-import.
+ // https://www.npmjs.com/package/@babel/plugin-syntax-dynamic-import
+ manipulateOptions(opts, parserOpts) {
+ console.log(`> oh hi opts`);
+ parserOpts.plugins.push("dynamicImport");
+ },
+
+ visitor: {
+ Import(path) {
+ console.log(`> oh hi`);
+ // const importArguments = path.parentPath.node.arguments;
+ // const [importPath] = importArguments;
+ // const isString =
+ // t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
+ // if (isString) {
+ // t.removeComments(importPath);
+ // }
+ // const SOURCE = isString
+ // ? importArguments
+ // : t.templateLiteral(
+ // [
+ // t.templateElement({ raw: "", cooked: "" }),
+ // t.templateElement({ raw: "", cooked: "" }, true),
+ // ],
+ // importArguments
+ // );
+ // const requireCall = t.callExpression(
+ // t.identifier("require"),
+ // [].concat(SOURCE)
+ // );
+
+ // const { noInterop = false } = this.opts;
+ // const MODULE =
+ // noInterop === true
+ // ? requireCall
+ // : t.callExpression(this.addHelper("interopRequireWildcard"), [
+ // requireCall,
+ // ]);
+ // const newImport = buildImport({
+ // MODULE,
+ // });
+ path.parentPath.replaceWith(t.identifier("require"));
+ },
+ },
+ };
+}
+
/**
* This Babel plugin is used to transpile a single Debugger module into a module that
* can be loaded in Firefox via the regular DevTools loader.
@@ -258,9 +310,11 @@ function transformMC({ types: t }) {
}
Babel.registerPlugin("transform-mc", transformMC);
+Babel.registerPlugin("transform-imports", transformImports);
module.exports = function(filePath) {
return [
+ ["transform-imports"],
"transform-flow-strip-types",
"syntax-trailing-function-commas",
"transform-class-properties",
diff --git a/devtools/client/shared/build/build.js b/devtools/client/shared/build/build.js
index 5a45d535b2d4..0cbbe26e5933 100644
--- a/devtools/client/shared/build/build.js
+++ b/devtools/client/shared/build/build.js
@@ -16,10 +16,8 @@ const defaultPlugins = [
];
function transform(filePath) {
-// Use the extra plugins only for the debugger
- const plugins = filePath.includes("devtools/client/debugger")
- ? require("./build-debugger")(filePath)
- : defaultPlugins;
+ // Use the extra plugins only for the debugger
+ const plugins = true ? require("./build-debugger")(filePath) : defaultPlugins;
const doc = fs.readFileSync(filePath, "utf8");
const out = Babel.transform(doc, { plugins });
@@ -27,16 +25,14 @@ function transform(filePath) {
return out.code;
}
-const deps = [
- __filename,
- _path.resolve(__dirname, "babel.js"),
-];
+const deps = [__filename, _path.resolve(__dirname, "babel.js")];
for (let i = 2; i < process.argv.length; i++) {
const srcPath = process.argv[i];
const code = transform(srcPath);
const filePath = _path.basename(srcPath);
- fs.writeFileSync(filePath, code);
+ // fs.writeFileSync(filePath, code);
+ console.log(code);
deps.push(srcPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment