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
23 changes: 11 additions & 12 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-console, unicorn/no-process-exit */

import pathModule from 'node:path';
import { createRequire } from 'node:module';
import pathModule from 'node:path';
import chalk from 'chalk';
import { installedCheck, ROOT } from 'installed-check-core';
import { formatHelpMessage, peowly } from 'peowly';
import { messageWithCauses, stackWithCauses } from 'pony-cause';
import { installedCheck, ROOT } from 'installed-check-core';
import resolveWorkspaceRootPkg from 'resolve-workspace-root';

const { resolveWorkspaceRootAsync } = resolveWorkspaceRootPkg;
Expand Down Expand Up @@ -104,21 +104,21 @@ const fixFlags = /** @satisfies {Record<string, import('peowly').AnyFlag & { lis
});

const workspaceFlags = /** @satisfies {Record<string, import('peowly').AnyFlag & { listGroup: 'Workspace options' }>} */ ({
'no-include-workspace-root': {
'include-workspace-root': {
type: 'boolean',
'default': false,
'default': true,
description: 'Excludes the workspace root package',
listGroup: 'Workspace options',
},
'no-parent-workspace': {
'parent-workspace': {
type: 'boolean',
'default': false,
'default': true,
description: 'Disables detection and use of parent workspace root for module resolution',
listGroup: 'Workspace options',
},
'no-workspaces': {
'workspaces': {
type: 'boolean',
'default': false,
'default': true,
description: 'Excludes workspace packages',
listGroup: 'Workspace options',
},
Expand Down Expand Up @@ -182,23 +182,22 @@ const {
'engine-ignore': engineIgnore, // deprecated
'engine-no-dev': engineNoDev, // deprecated
fix,
'include-workspace-root': includeWorkspaceRoot,
'parent-workspace': parentWorkspace,
'peer-check': peerCheck,
strict,
verbose,
'version-check': versionCheck,
workspace,
'workspace-ignore': workspaceIgnore,
workspaces,
} = cli.flags;

let {
ignore,
'ignore-dev': ignoreDev,
} = cli.flags;

const includeWorkspaceRoot = !cli.flags['no-include-workspace-root'];
const parentWorkspace = !cli.flags['no-parent-workspace'];
const workspaces = !cli.flags['no-workspaces'];

// Handle deprecated flags
if (engineIgnore?.length) {
ignore = [...ignore || [], ...engineIgnore];
Expand Down
1 change: 1 addition & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "commonjs",
"name": "example-basic",
"version": "1.0.0",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions examples/monorepo/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "commonjs",
"name": "example-monorepo",
"version": "1.0.0",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions examples/monorepo/packages/workspace-a/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "commonjs",
"name": "workspace-a",
"version": "1.0.0",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions examples/monorepo/packages/workspace-b/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "commonjs",
"name": "workspace-b",
"version": "1.0.0",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"$schema": "./node_modules/knip/schema-jsonc.json",
"ignoreDependencies": [],
"ignore": ["examples/**"]
}
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
"cli.js"
],
"scripts": {
"check:lint": "eslint",
"check": "run-p check:*",
"check:installed-check": "node cli-wrapper.cjs",
"check:knip": "knip",
"check:lint": "eslint",
"check:tsc": "tsc",
"check:type-coverage": "type-coverage --detail --strict --at-least 95",
"check": "run-p check:*",
"prepare": "husky",
"test:integration": "node --test test/integration.js",
"test": "run-s check test:examples:install test:integration",
"test:examples:install": "cd examples/basic && npm install && cd ../monorepo && npm install && cd ../..",
"test-ci": "run-s test:examples:install test:integration check:installed-check",
"test": "run-s check test:examples:install test:integration"
"test:integration": "node --test test/integration.js",
"test-ci": "run-s test:examples:install test:integration check:installed-check"
},
"keywords": [
"cli",
Expand All @@ -46,21 +46,21 @@
"typescript": ">=5.9"
},
"dependencies": {
"chalk": "^5.6.2",
"installed-check-core": "^8.3.1",
"peowly": "^1.3.3",
"chalk": "^6.0.0",
"installed-check-core": "^9.0.0",
"peowly": "^2.0.1",
"pony-cause": "^2.1.10",
"resolve-workspace-root": "^2.0.1",
"version-guard": "^1.1.3"
},
"devDependencies": {
"@types/node": "^22.20.1",
"@voxpelli/eslint-config": "^23.0.0",
"@voxpelli/eslint-config": "^25.1.0",
"@voxpelli/tsconfig": "^16.2.1",
"eslint": "^9.39.2",
"eslint": "^9.39.5",
"husky": "^9.1.7",
"knip": "^5.83.1",
"npm-run-all2": "^8.0.4",
"knip": "^6.31.0",
"npm-run-all2": "^9.0.3",
"remark-parse": "^11.0.0",
"type-coverage": "^2.30.1",
"typescript": "~6.0.3",
Expand Down
20 changes: 9 additions & 11 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
*/

import assert from 'node:assert/strict';
import path from 'node:path';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
// eslint-disable-next-line unicorn/import-style
import { dirname, join } from 'node:path';
import { extractExpectedOutput, normalizeOutput } from './test-readme.js';

import { run } from './helpers.js';
import { extractExpectedOutput, normalizeOutput } from './test-readme.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const rootDir = join(__dirname, '..');
const cliPath = join(rootDir, 'cli-wrapper.cjs');
const rootDir = path.join(import.meta.dirname, '..');
const cliPath = path.join(rootDir, 'cli-wrapper.cjs');

/**
* Asserts that a CLI flag is recognised (not rejected as "Unknown option").
Expand All @@ -31,7 +29,7 @@ async function assertFlagRecognised (flag) {

describe('Basic Example', () => {
it('output matches README expected output', async () => {
const expectedOutput = await extractExpectedOutput(join(rootDir, 'examples/basic/README.md'));
const expectedOutput = await extractExpectedOutput(path.join(rootDir, 'examples/basic/README.md'));
assert.ok(expectedOutput !== undefined, 'Could not extract expected output from README');

const result = await run(`node "${cliPath}" examples/basic`, rootDir);
Expand All @@ -47,7 +45,7 @@ describe('Basic Example', () => {

describe('Monorepo Example', () => {
it('workspace-a output matches README expected output', async () => {
const expectedOutput = await extractExpectedOutput(join(rootDir, 'examples/monorepo/packages/workspace-a/README.md'));
const expectedOutput = await extractExpectedOutput(path.join(rootDir, 'examples/monorepo/packages/workspace-a/README.md'));

// If there's no expected output in README, it means the example should pass cleanly
if (expectedOutput === undefined) {
Expand All @@ -72,7 +70,7 @@ describe('Monorepo Example', () => {

it('debug output shows parent workspace detection', async () => {
const expectedDebug = await extractExpectedOutput(
join(rootDir, 'examples/monorepo/packages/workspace-a/README.md'),
path.join(rootDir, 'examples/monorepo/packages/workspace-a/README.md'),
'DEBUG OUTPUT'
);
assert.ok(expectedDebug !== undefined, 'Could not extract expected debug output from README');
Expand Down Expand Up @@ -116,7 +114,7 @@ describe('Monorepo Example', () => {

it('running from monorepo root matches README expected output', async () => {
const expectedOutput = await extractExpectedOutput(
join(rootDir, 'examples/monorepo/README.md'),
path.join(rootDir, 'examples/monorepo/README.md'),
'EXPECTED OUTPUT'
);
assert.ok(expectedOutput !== undefined, 'Could not extract expected root output from README');
Expand Down
2 changes: 1 addition & 1 deletion test/test-readme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from 'node:fs/promises';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import { unified } from 'unified';
import { visit } from 'unist-util-visit';

import { stripAnsi } from './helpers.js';
Expand Down
Loading