sweepi 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/chunk-TSXPWQWE.js +132 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +50 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +8 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jenna Smith (@jjenzz)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# sweepi
|
|
2
|
+
|
|
3
|
+
Run Sweepit lint rules against a project without changing that project's dependencies.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx sweepi <project-dir>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
If `~/.sweepi` has not been initialized yet, Sweepi will initialize it first.
|
|
12
|
+
|
|
13
|
+
## Explicit initialization
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx sweepi init
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This creates `~/.sweepi`, writes `~/.sweepi/eslint.config.mjs`, and installs:
|
|
20
|
+
|
|
21
|
+
- `eslint@^9`
|
|
22
|
+
- `eslint-plugin-sweepit@latest`
|
|
23
|
+
|
|
24
|
+
## How lint runs
|
|
25
|
+
|
|
26
|
+
Sweepi executes ESLint from the private toolchain directory:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
~/.sweepi/node_modules/.bin/eslint --config ~/.sweepi/eslint.config.mjs <project-dir>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This keeps project dependencies and lockfiles untouched.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/toolchain.ts
|
|
2
|
+
import * as childProcess from "child_process";
|
|
3
|
+
import * as fs from "fs/promises";
|
|
4
|
+
import * as os from "os";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
var TOOLCHAIN_DIR_NAME = ".sweepi";
|
|
7
|
+
var TOOLCHAIN_PACKAGE_JSON_NAME = "package.json";
|
|
8
|
+
var TOOLCHAIN_CONFIG_NAME = "eslint.config.mjs";
|
|
9
|
+
var TOOLCHAIN_INSTALL_ARGUMENTS = [
|
|
10
|
+
"install",
|
|
11
|
+
"--no-save",
|
|
12
|
+
"--no-audit",
|
|
13
|
+
"--no-fund",
|
|
14
|
+
"eslint@^9.0.0",
|
|
15
|
+
"eslint-plugin-sweepit@latest"
|
|
16
|
+
];
|
|
17
|
+
var TOOLCHAIN_PACKAGE_JSON_CONTENT = JSON.stringify(
|
|
18
|
+
{
|
|
19
|
+
name: "sweepi-toolchain",
|
|
20
|
+
private: true
|
|
21
|
+
},
|
|
22
|
+
null,
|
|
23
|
+
2
|
|
24
|
+
);
|
|
25
|
+
var TOOLCHAIN_CONFIG_CONTENT = `import sweepitPlugin from 'eslint-plugin-sweepit';
|
|
26
|
+
|
|
27
|
+
export default [...sweepitPlugin.configs.core, ...sweepitPlugin.configs.react];
|
|
28
|
+
`;
|
|
29
|
+
async function initializeToolchain(options = {}) {
|
|
30
|
+
const homeDirectory = options.homeDirectory ?? os.homedir();
|
|
31
|
+
const toolchainDirectory = path.join(homeDirectory, TOOLCHAIN_DIR_NAME);
|
|
32
|
+
const packageJsonPath = path.join(toolchainDirectory, TOOLCHAIN_PACKAGE_JSON_NAME);
|
|
33
|
+
const configPath = path.join(toolchainDirectory, TOOLCHAIN_CONFIG_NAME);
|
|
34
|
+
await fs.mkdir(toolchainDirectory, { recursive: true });
|
|
35
|
+
await ensureFile(packageJsonPath, TOOLCHAIN_PACKAGE_JSON_CONTENT);
|
|
36
|
+
await ensureFile(configPath, TOOLCHAIN_CONFIG_CONTENT);
|
|
37
|
+
const eslintBinaryPath = path.join(toolchainDirectory, "node_modules", ".bin", "eslint");
|
|
38
|
+
const pluginPackagePath = path.join(
|
|
39
|
+
toolchainDirectory,
|
|
40
|
+
"node_modules",
|
|
41
|
+
"eslint-plugin-sweepit",
|
|
42
|
+
"package.json"
|
|
43
|
+
);
|
|
44
|
+
const eslintInstalled = await pathExists(eslintBinaryPath);
|
|
45
|
+
const pluginInstalled = await pathExists(pluginPackagePath);
|
|
46
|
+
const installRequired = !eslintInstalled || !pluginInstalled;
|
|
47
|
+
if (installRequired) {
|
|
48
|
+
const runInstallCommand = options.runInstallCommand ?? runInstallCommandWithNpm;
|
|
49
|
+
await runInstallCommand("npm", TOOLCHAIN_INSTALL_ARGUMENTS, toolchainDirectory);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
toolchainDirectory,
|
|
53
|
+
installedDependencies: installRequired
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async function runSweepi(projectDirectory, options = {}) {
|
|
57
|
+
const resolvedProjectDirectory = path.resolve(projectDirectory);
|
|
58
|
+
const projectDirectoryStats = await fs.stat(resolvedProjectDirectory).catch(() => null);
|
|
59
|
+
if (projectDirectoryStats === null || !projectDirectoryStats.isDirectory()) {
|
|
60
|
+
throw new Error(`Project directory does not exist: ${resolvedProjectDirectory}`);
|
|
61
|
+
}
|
|
62
|
+
const initialization = await initializeToolchain({
|
|
63
|
+
homeDirectory: options.homeDirectory,
|
|
64
|
+
runInstallCommand: options.runInstallCommand
|
|
65
|
+
});
|
|
66
|
+
const eslintBinaryPath = path.join(
|
|
67
|
+
initialization.toolchainDirectory,
|
|
68
|
+
"node_modules",
|
|
69
|
+
".bin",
|
|
70
|
+
"eslint"
|
|
71
|
+
);
|
|
72
|
+
const configPath = path.join(initialization.toolchainDirectory, TOOLCHAIN_CONFIG_NAME);
|
|
73
|
+
const runLintCommand = options.runLintCommand ?? runLintCommandWithExecutable;
|
|
74
|
+
return runLintCommand(
|
|
75
|
+
eslintBinaryPath,
|
|
76
|
+
["--config", configPath, resolvedProjectDirectory],
|
|
77
|
+
resolvedProjectDirectory
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
async function ensureFile(filePath, content) {
|
|
81
|
+
const exists = await pathExists(filePath);
|
|
82
|
+
if (!exists) {
|
|
83
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function pathExists(filePath) {
|
|
87
|
+
try {
|
|
88
|
+
await fs.access(filePath);
|
|
89
|
+
return true;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function runInstallCommandWithNpm(command, args, cwd) {
|
|
95
|
+
await new Promise((resolve2, reject) => {
|
|
96
|
+
const child = childProcess.spawn(command, args, {
|
|
97
|
+
cwd,
|
|
98
|
+
stdio: "inherit",
|
|
99
|
+
env: process.env
|
|
100
|
+
});
|
|
101
|
+
child.on("error", (error) => {
|
|
102
|
+
reject(error);
|
|
103
|
+
});
|
|
104
|
+
child.on("exit", (code) => {
|
|
105
|
+
if (code === 0) {
|
|
106
|
+
resolve2();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
reject(new Error(`Failed to initialize Sweepi toolchain (exit code ${String(code)}).`));
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function runLintCommandWithExecutable(command, args, cwd) {
|
|
114
|
+
return new Promise((resolve2, reject) => {
|
|
115
|
+
const child = childProcess.spawn(command, args, {
|
|
116
|
+
cwd,
|
|
117
|
+
stdio: "inherit",
|
|
118
|
+
env: process.env
|
|
119
|
+
});
|
|
120
|
+
child.on("error", (error) => {
|
|
121
|
+
reject(error);
|
|
122
|
+
});
|
|
123
|
+
child.on("exit", (code) => {
|
|
124
|
+
resolve2(code ?? 1);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
initializeToolchain,
|
|
131
|
+
runSweepi
|
|
132
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
initializeToolchain,
|
|
4
|
+
runSweepi
|
|
5
|
+
} from "./chunk-TSXPWQWE.js";
|
|
6
|
+
|
|
7
|
+
// src/cli.ts
|
|
8
|
+
async function run() {
|
|
9
|
+
const command = process.argv[2];
|
|
10
|
+
if (command === void 0 || command === "--help" || command === "-h") {
|
|
11
|
+
printHelp();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (command === "init") {
|
|
15
|
+
const initialization = await initializeToolchain();
|
|
16
|
+
if (initialization.installedDependencies) {
|
|
17
|
+
process.stdout.write(
|
|
18
|
+
`Initialized Sweepi toolchain in ${initialization.toolchainDirectory}
|
|
19
|
+
`
|
|
20
|
+
);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
process.stdout.write(
|
|
24
|
+
`Sweepi toolchain already initialized in ${initialization.toolchainDirectory}
|
|
25
|
+
`
|
|
26
|
+
);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (command.startsWith("-")) {
|
|
30
|
+
throw new Error(`Unknown flag "${command}". Try "sweepi --help".`);
|
|
31
|
+
}
|
|
32
|
+
const lintExitCode = await runSweepi(command);
|
|
33
|
+
process.exitCode = lintExitCode;
|
|
34
|
+
}
|
|
35
|
+
function printHelp() {
|
|
36
|
+
process.stdout.write(`Usage:
|
|
37
|
+
sweepi <project-dir>
|
|
38
|
+
sweepi init
|
|
39
|
+
|
|
40
|
+
Commands:
|
|
41
|
+
<project-dir> Initialize if required, then run eslint using ~/.sweepi
|
|
42
|
+
init Create ~/.sweepi and install rules
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
45
|
+
run().catch((error) => {
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
+
process.stderr.write(`${message}
|
|
48
|
+
`);
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface InitializeToolchainOptions {
|
|
2
|
+
homeDirectory?: string;
|
|
3
|
+
runInstallCommand?: (command: string, args: string[], cwd: string) => Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
interface InitializeToolchainResult {
|
|
6
|
+
toolchainDirectory: string;
|
|
7
|
+
installedDependencies: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface RunSweepiOptions {
|
|
10
|
+
homeDirectory?: string;
|
|
11
|
+
runInstallCommand?: (command: string, args: string[], cwd: string) => Promise<void>;
|
|
12
|
+
runLintCommand?: (command: string, args: string[], cwd: string) => Promise<number>;
|
|
13
|
+
}
|
|
14
|
+
declare function initializeToolchain(options?: InitializeToolchainOptions): Promise<InitializeToolchainResult>;
|
|
15
|
+
declare function runSweepi(projectDirectory: string, options?: RunSweepiOptions): Promise<number>;
|
|
16
|
+
|
|
17
|
+
export { type InitializeToolchainOptions, type InitializeToolchainResult, type RunSweepiOptions, initializeToolchain, runSweepi };
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sweepi",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Run Sweepit lint rules without modifying project dependencies.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"sweepi": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"prepack": "npm run build",
|
|
23
|
+
"build": "tsup src/index.ts src/cli.ts --format esm --dts --out-dir dist --clean",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"typecheck": "tsc --noEmit"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^24.3.0",
|
|
29
|
+
"tsup": "^8.5.0",
|
|
30
|
+
"typescript": "^5.9.2",
|
|
31
|
+
"vitest": "^2.1.3"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "046082f22ae7eb53f784ece9379e729e73e2d7e2"
|
|
34
|
+
}
|