Skip to content
Merged
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
62 changes: 45 additions & 17 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let { readConfig } = require("./config");
let { abort, repr } = require("./util");
let parseArgs = require("minimist");
let { parseArgs } = require("node:util");

let HELP = `
Usage:
Expand All @@ -27,27 +27,55 @@ Options:
serve generated files via HTTP with live reloading
`.trim();

exports.parseCLI = async function parseCLI(argv = process.argv.slice(2), help = HELP) {
argv = parseArgs(argv, {
boolean: ["watch", "fingerprint", "sourcemaps", "compact"],
alias: {
c: "config",
w: "watch",
h: "help"
exports.parseCLI = async function parseCLI() {
let { values } = parseArgs({
options: {
help: {
type: "boolean",
short: "h",
default: false
},
config: {
type: "string",
short: "c"
},
watch: {
type: "boolean",
short: "w",
default: false
},
fingerprint: {
type: "boolean",
default: false
},
sourcemaps: {
type: "boolean",
default: false
},
compact: {
type: "boolean",
default: false
},
serve: {
type: "string"
},
liveserve: {
type: "string"
}
}
});

if(argv.help) {
abort(help, 0);
if(values.help) {
abort(HELP, 0);
}

let options = {
watch: argv.watch,
fingerprint: argv.fingerprint,
sourcemaps: argv.sourcemaps,
compact: argv.compact,
serve: argv.serve,
liveserve: argv.liveserve
watch: values.watch,
fingerprint: values.fingerprint,
sourcemaps: values.sourcemaps,
compact: values.compact,
serve: values.serve,
liveserve: values.liveserve
};

if(options.watch && options.fingerprint) { // for convenience
Expand All @@ -56,6 +84,6 @@ exports.parseCLI = async function parseCLI(argv = process.argv.slice(2), help =
}

let rootDir = process.cwd();
let { referenceDir, config } = await readConfig(rootDir, argv.config);
let { referenceDir, config } = await readConfig(rootDir, values.config);
return { referenceDir, config, options };
};
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@
"faucet": "bin/faucet"
},
"scripts": {
"test": "npm-run-all --parallel lint test:unit",
"test:unit": "mocha test/test_*.js",
"lint": "eslint --cache lib bin/* test test/bin/* && echo ✓"
"test": "npm run lint && npm run test:unit",
"test:unit": "node --test ./test/test_*.js",
"lint": "eslint --cache ./lib ./bin/* ./test ./test/bin/* && echo ✓"
},
"engines": {
"node": ">= 18"
},
"dependencies": {
"browserslist": "~4.22.1",
"minimist": "~1.2.7",
"nite-owl": "~5.0.5"
},
"devDependencies": {
"eslint-config-fnd": "^1.13.0",
"mocha": "^10.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is delightful! If I'm not mistaken, this should get rid of a whopping 130 dependencies - except json5 and tsconfig-paths depend on minimist as well for some reason, so it's "just" 50 fewer dependencies.

On a related note, because both those packages appear to be transitive dependencies of eslint-config-fnd: I've recently decided not to bother upgrading the latter (which triggers deprecation warnings) because that's a major pita, plus that elaborate DIY style was never a good idea in the first place... 😬 So, uhm, apologies for sinking our ecosystem in favor of pixel perfection?

Copy link
Member Author

Choose a reason for hiding this comment

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

So... you are now using deno lint && deno format instead of eslint-config-fnd?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. It's still a risk, but less so. (Of course diff pollution seems likely either way.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Tracked as #145

"npm-run-all": "^4.1.5",
"release-util-fnd": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion test/test_manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, before, after, it */
"use strict";

let { AssetManager } = require("../lib/manager");
let { describe, it, before, after } = require("node:test");
let path = require("path");
let assert = require("assert");

Expand Down
2 changes: 1 addition & 1 deletion test/test_manifest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, before, after, it */
"use strict";

let { Manifest } = require("../lib/manifest");
let { describe, it, before, after } = require("node:test");
let path = require("path");
let assert = require("assert");

Expand Down
31 changes: 16 additions & 15 deletions test/test_plugins.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, before, after, it */
"use strict";

let { pluginsByBucket, _determinePlugins } = require("../lib/plugins");
let { describe, it, before, after } = require("node:test");
let path = require("path");
let assert = require("assert");

Expand Down Expand Up @@ -187,12 +187,12 @@ describe("plugin resolution", () => {
}));
});

it("balks at invalid package identifiers", () => {
assert.rejects(async () => {
it("balks at invalid package identifiers", async () => {
await assert.rejects(async () => {
return _determinePlugins(["faucet-pipeline-yummy"]);
}, /exit 1/);

assert.rejects(() => {
await assert.rejects(() => {
return _determinePlugins([{
// NB: local configuration must not be comprehensive to ensure
// plugin is loaded
Expand All @@ -202,8 +202,8 @@ describe("plugin resolution", () => {
}, /exit 1/);
});

it("balks at duplicate configuration keys", () => {
assert.rejects(() => {
it("balks at duplicate configuration keys", async () => {
await assert.rejects(() => {
return _determinePlugins([{
key: "dummy",
bucket: "static",
Expand All @@ -216,34 +216,35 @@ describe("plugin resolution", () => {
}, /exit 1/);
});

it("balks at invalid plugins", () => {
assert.rejects(() => {
it("balks at invalid plugins", async () => {
await assert.rejects(() => {
return _determinePlugins(["faucet-pipeline-invalid-a"]);
}, /exit 1/);

assert.rejects(() => {
await assert.rejects(() => {
return _determinePlugins(["faucet-pipeline-invalid-b"]);
}, /exit 1/);

assert.rejects(() => {
await assert.rejects(() => {
return _determinePlugins(["faucet-pipeline-invalid-c"]);
}, /exit 1/);
});

it("balks at invalid buckets", () => {
it("balks at invalid buckets", async () => {
let plugin = {
key: "dummy",
plugin: () => {}
};
["static", "scripts", "styles", "markup"].forEach(bucket => {
const buckets = ["static", "scripts", "styles", "markup"];
for(let bucket of buckets) {
plugin.bucket = bucket;
assert.doesNotReject(() => {
await assert.doesNotReject(async () => {
return _determinePlugins([plugin]);
}, /exit 1/);
});
}

plugin.bucket = "dummy";
assert.rejects(() => {
await assert.rejects(async () => {
return _determinePlugins([plugin]);
}, /exit 1/);
});
Expand Down
2 changes: 1 addition & 1 deletion test/test_runner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, it */
"use strict";

let { SerializedRunner } = require("../lib/util/runner");
let { describe, it } = require("node:test");
let { strictEqual: assertSame, deepStrictEqual: assertDeep } = require("assert");

describe("watch mode", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/test_server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, before, after, it */
"use strict";

let { _parseHost } = require("../lib/server");
let { describe, it, before, after } = require("node:test");
let assert = require("assert");

let assertSame = assert.strictEqual;
Expand Down
2 changes: 1 addition & 1 deletion test/test_util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global describe, it */
"use strict";

let { generateFingerprint } = require("../lib/util");
let { FileFinder } = require("../lib/util/files/finder");
let { describe, it } = require("node:test");
let path = require("path");
let assert = require("assert");

Expand Down
Loading