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

removed lodash #2034

Open
wants to merge 3 commits into
base: build-output
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions packages/browser-sync/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/dist/*
/dist_backup/*
/modularize
1 change: 1 addition & 0 deletions packages/browser-sync/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lib/underbar.js
29 changes: 29 additions & 0 deletions packages/browser-sync/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require("esbuild").buildSync({
entryPoints: ["./lib/index.js"],
bundle: true,
platform: "node",
packages: "external",
outfile: "dist/index.js",
sourcemap: "inline"
});

require("esbuild").buildSync({
entryPoints: ["./lib/bin.js"],
bundle: true,
platform: "node",
packages: "external",
outfile: "dist/bin.js",
sourcemap: "inline"
});

// require("esbuild").buildSync({
// entryPoints: ["./lodash.custom.js"],
// bundle: true,
// platform: "node",
// format: "esm",
// packages: "external",
// outfile: "lib/underbar.js",
// banner: {
// js: "// @ts-nocheck"
// }
// });
95 changes: 39 additions & 56 deletions packages/browser-sync/lib/async.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// @ts-check

"use strict";

var _ = require("./lodash.custom");
var Immutable = require("immutable");
import pluginUtils from "./plugins";
import isUndefined from "../modularize/isUndefined.js";
import connectUtils from "./connect-utils";
import chalk from "chalk";
import * as utils from "./utils";

var utils = require("./utils");
var pluginUtils = require("./plugins");
var connectUtils = require("./connect-utils");
var chalk = require("chalk");
import Immutable from "immutable";

module.exports = {
/**
* BrowserSync needs at least 1 free port.
* It will check the one provided in config
* and keep incrementing until an available one is found.
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
getEmptyPort: function(bs, done) {
Expand Down Expand Up @@ -63,38 +65,30 @@ module.exports = {
socketPort = bs.options.getIn(["socket", "port"]);
}

utils.getPort(
bs.options.get("listen", "localhost"),
socketPort,
null,
function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
done(null, {
optionsIn: [
{
path: ["socket", "port"],
value: port
}
]
});
utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
);
done(null, {
optionsIn: [
{
path: ["socket", "port"],
value: port
}
]
});
});
},
/**
* Some features require an internet connection.
* If the user did not provide either `true` or `false`
* for the online option, we will attempt to resolve www.google.com
* as a way of determining network connectivity
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
getOnlineStatus: function(bs, done) {
if (
_.isUndefined(bs.options.get("online")) &&
_.isUndefined(process.env.TESTING)
) {
if (isUndefined(bs.options.get("online")) && isUndefined(process.env.TESTING)) {
require("dns").resolve("www.google.com", function(err) {
var online = false;
if (err) {
Expand All @@ -103,10 +97,7 @@ module.exports = {
chalk.magenta("online: false")
);
} else {
bs.debug(
"Resolved www.google.com, setting %s",
chalk.magenta("online: true")
);
bs.debug("Resolved www.google.com, setting %s", chalk.magenta("online: true"));
online = true;
}
done(null, {
Expand All @@ -121,7 +112,7 @@ module.exports = {
},
/**
* Try to load plugins that were given in options
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
resolveInlineUserPlugins: function(bs, done) {
Expand All @@ -148,7 +139,7 @@ module.exports = {
},
/**
*
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
setOptions: function(bs, done) {
Expand All @@ -158,9 +149,7 @@ module.exports = {
snippet: connectUtils.enabled(bs.options)
? connectUtils.scriptTags(bs.options)
: false,
scriptPaths: Immutable.fromJS(
connectUtils.clientScript(bs.options, true)
),
scriptPaths: Immutable.fromJS(connectUtils.clientScript(bs.options, true)),
files: bs.pluginManager.hook(
"files:watch",
bs.options.get("files"),
Expand All @@ -170,15 +159,15 @@ module.exports = {
});
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
setInternalEvents: function(bs, done) {
require("./internal-events")(bs);
done();
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
setFileWatchers: function(bs, done) {
Expand All @@ -189,21 +178,18 @@ module.exports = {
});
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
mergeMiddlewares: function(bs, done) {
done(null, {
options: {
middleware: bs.pluginManager.hook(
"server:middleware",
bs.options.get("middleware")
)
middleware: bs.pluginManager.hook("server:middleware", bs.options.get("middleware"))
}
});
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
startServer: function(bs, done) {
Expand All @@ -217,12 +203,13 @@ module.exports = {
});
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
startTunnel: function(bs, done) {
if (bs.options.get("tunnel") && bs.options.get("online")) {
var localTunnel = require("./tunnel");
// @ts-expect-error
localTunnel(bs, function(err, tunnel) {
if (err) {
return done(err);
Expand All @@ -245,7 +232,7 @@ module.exports = {
}
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
startSockets: function(bs, done) {
Expand All @@ -268,7 +255,7 @@ module.exports = {
},
/**
*
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
startUi: function(bs, done) {
Expand All @@ -289,11 +276,7 @@ module.exports = {
) {
uiOpts = bs.options
.get("ui")
.mergeDeep(
Immutable.fromJS(
bs.pluginManager.pluginOptions[PLUGIN_NAME]
)
);
.mergeDeep(Immutable.fromJS(bs.pluginManager.pluginOptions[PLUGIN_NAME]));
}

/**
Expand All @@ -319,7 +302,7 @@ module.exports = {
});
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
mergeUiSettings: function(bs, done) {
Expand All @@ -334,7 +317,7 @@ module.exports = {
});
},
/**
* @param {BrowserSync} bs
* @param {import("./browser-sync").default} bs
* @param {Function} done
*/
initUserPlugins: function(bs, done) {
Expand Down
27 changes: 14 additions & 13 deletions packages/browser-sync/lib/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const startOpts = require("../cli-options/opts.start.json");
const reloadOpts = require("../cli-options/opts.reload.json");
const recipeOpts = require("../cli-options/opts.recipe.json");
const chalk = require("chalk");
const chalk = require("chalk");
const pkg = require("../package.json");
import * as utils from "./utils";
import { resolve } from "path";
Expand Down Expand Up @@ -38,7 +38,7 @@ if (!module.parent) {
}

function freshYargs() {
return require("yargs")(process.argv.slice(2));
return require("yargs")(process.argv.slice(2));
}

function runFromCli() {
Expand Down Expand Up @@ -132,9 +132,7 @@ function handleNoCommand(argv, input, yargs) {
.filter(item => item.isUrl === false)
.map(item => item.resolved);

const urls = withoutErrors
.filter(item => item.isUrl === true)
.map(item => item.userInput);
const urls = withoutErrors.filter(item => item.isUrl === true).map(item => item.userInput);

/**
* If a URL was given, switch to proxy mode and use
Expand Down Expand Up @@ -168,8 +166,14 @@ function handleNoCommand(argv, input, yargs) {
*/
function handleCli(opts) {
opts.cb = opts.cb || utils.defaultCallback;
const m = require(`./cli/command.${opts.cli.input[0]}`);
if (m.default) {
const mapping = {
init: () => require("./cli/command.init.js"),
recipe: () => require("./cli/command.recipe.js"),
reload: () => require("./cli/command.reload.js"),
start: () => require("./cli/command.start.js")
};
const m = mapping[opts.cli.input[0]]?.();
if (m?.default) {
return m.default(opts);
}
return m(opts);
Expand All @@ -183,8 +187,7 @@ function processStart(yargs) {
.options(startOpts)
.example("$0 start -s app", "- Use the App directory to serve files")
.example("$0 start -p www.bbc.co.uk", "- Proxy an existing website")
.default("cwd", () => process.cwd())
.argv;
.default("cwd", () => process.cwd()).argv;
}

/**
Expand All @@ -210,17 +213,15 @@ function handleIncoming(command, yargs) {
.options(reloadOpts)
.example("$0 reload")
.example("$0 reload --port 4000")
.default("cwd", () => process.cwd())
.argv;
.default("cwd", () => process.cwd()).argv;
}
if (command === "recipe") {
out = yargs
.usage("Usage: $0 recipe <recipe-name>")
.option(recipeOpts)
.example("$0 recipe ls", "list the recipes")
.example("$0 recipe gulp.sass", "use the gulp.sass recipe")
.default("cwd", () => process.cwd())
.argv;
.default("cwd", () => process.cwd()).argv;
}

if (out.help) {
Expand Down
Loading