@mikode13/cross-platform 0.1.0
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 +44 -0
- package/README.md +69 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -0
- package/dist/clean.d.ts +2 -0
- package/dist/clean.d.ts.map +1 -0
- package/dist/clean.js +8 -0
- package/dist/clean.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +24 -0
- package/dist/cli.js.map +1 -0
- package/dist/cliClean.d.ts +3 -0
- package/dist/cliClean.d.ts.map +1 -0
- package/dist/cliClean.js +24 -0
- package/dist/cliClean.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"Commons Clause" License Condition v1.0
|
|
2
|
+
|
|
3
|
+
The Software is provided to you by the Licensor under the License, as defined below,
|
|
4
|
+
subject to the following condition.
|
|
5
|
+
|
|
6
|
+
Without limiting other conditions in the License, the grant of rights under the License
|
|
7
|
+
will not include, and the License does not grant to you, the right to Sell the Software.
|
|
8
|
+
|
|
9
|
+
For purposes of the foregoing, "Sell" means practicing any or all of the rights granted
|
|
10
|
+
to you under the License to provide to third parties, for a fee or other consideration
|
|
11
|
+
(including without limitation fees for hosting or consulting/support services related
|
|
12
|
+
to the Software), a product or service whose value derives, entirely or substantially,
|
|
13
|
+
from the functionality of the Software.
|
|
14
|
+
|
|
15
|
+
Any license notice or attribution required by the License must also include this
|
|
16
|
+
Commons Clause License Condition notice.
|
|
17
|
+
|
|
18
|
+
Software: @mikode13/cross-platform
|
|
19
|
+
License: MIT License
|
|
20
|
+
Licensor: MiKode13
|
|
21
|
+
|
|
22
|
+
MIT License
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2026 MiKode13
|
|
25
|
+
|
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
27
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
28
|
+
in the Software without restriction, including without limitation the rights
|
|
29
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
30
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
31
|
+
furnished to do so, subject to the Commons Clause License Condition above
|
|
32
|
+
and the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice, this permission notice, and the Commons Clause
|
|
35
|
+
License Condition notice shall be included in all copies or substantial
|
|
36
|
+
portions of the Software.
|
|
37
|
+
|
|
38
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
39
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
40
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
41
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
42
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
43
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
44
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @mikode13/cross-platform
|
|
2
|
+
|
|
3
|
+
Cross-platform utilities for MiKode `package.json` build and maintenance scripts.
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
Some operations a build script needs — for example deleting a stale output directory
|
|
8
|
+
before recompiling — have no single command that works unmodified on every platform.
|
|
9
|
+
`rm -rf dist` fails under native Windows `cmd.exe`, which is what `npm`/`pnpm` invoke by
|
|
10
|
+
default there, even though it works on macOS, Linux, and Windows under Git Bash, WSL, or
|
|
11
|
+
PowerShell with an alias.
|
|
12
|
+
|
|
13
|
+
This package centralizes that kind of operation in one MiKode-owned place, so a
|
|
14
|
+
repository depends on a single first-party package instead of independently picking a
|
|
15
|
+
third-party tool or hand-rolling a platform-specific command each time the same problem
|
|
16
|
+
appears.
|
|
17
|
+
|
|
18
|
+
See [ADR 0016](https://github.com/Mikode13/engineering/blob/main/adr/0016-centralize-cross-platform-script-utilities.md)
|
|
19
|
+
and the [cross-platform script utilities standard](https://github.com/Mikode13/engineering/blob/main/standards/cross-platform-script-utilities.md)
|
|
20
|
+
in `mikode-engineering` for the decision and usage policy this package implements. The
|
|
21
|
+
ADR is `Accepted`.
|
|
22
|
+
|
|
23
|
+
## Status
|
|
24
|
+
|
|
25
|
+
The first (and currently only) capability, `clean`, is implemented: cross-platform-safe
|
|
26
|
+
removal of a directory using Node's built-in `node:fs/promises`, exposed both as a
|
|
27
|
+
function and as a CLI for `package.json` scripts.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pnpm add @mikode13/cross-platform
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
As a function:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { clean } from '@mikode13/cross-platform';
|
|
41
|
+
|
|
42
|
+
await clean('dist');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
From a `package.json` script, in place of `rm -rf`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "mikode-scripts clean dist && tsc -p tsconfig.build.json"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The CLI rejects an empty path, the root of the filesystem, and the current working
|
|
56
|
+
directory. It does not restrict the target to be inside the current working directory
|
|
57
|
+
(for example `../other-dir` is allowed).
|
|
58
|
+
|
|
59
|
+
## Tests
|
|
60
|
+
|
|
61
|
+
`pnpm test` runs the unit suite.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
This project is source-available under the MIT License with the
|
|
66
|
+
[Commons Clause License Condition v1.0](https://commonsclause.com/). See
|
|
67
|
+
[LICENSE](./LICENSE) for the complete text. It is not OSI open source: the Commons
|
|
68
|
+
Clause restricts selling the software or a service whose value derives substantially
|
|
69
|
+
from it.
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
package/dist/clean.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../src/clean.ts"],"names":[],"mappings":"AAEA,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKvD"}
|
package/dist/clean.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../src/clean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,IAAY;IACvC,MAAM,EAAE,CAAC,IAAI,EAAE;QACd,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,IAAI;KACX,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgBtE;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvE"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { clean } from "./clean.js";
|
|
3
|
+
export function resolveCleanTarget(target, cwd) {
|
|
4
|
+
if (!target.trim()) {
|
|
5
|
+
throw new Error('A path is required');
|
|
6
|
+
}
|
|
7
|
+
const resolved = path.resolve(cwd, target);
|
|
8
|
+
if (resolved === path.parse(resolved).root) {
|
|
9
|
+
throw new Error('Cannot clean a filesystem root');
|
|
10
|
+
}
|
|
11
|
+
if (resolved === path.resolve(cwd)) {
|
|
12
|
+
throw new Error('Cannot clean the current working directory');
|
|
13
|
+
}
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
export async function runCli(argv, cwd) {
|
|
17
|
+
const [command, target] = argv;
|
|
18
|
+
if (command !== 'clean') {
|
|
19
|
+
throw new Error(`Unrecognized command: "${command ?? ''}". The only supported command is "clean".`);
|
|
20
|
+
}
|
|
21
|
+
const resolved = resolveCleanTarget(target ?? '', cwd);
|
|
22
|
+
await clean(resolved);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,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,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvE"}
|
package/dist/cliClean.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { clean } from "./clean.js";
|
|
3
|
+
export function resolveCleanTarget(target, cwd) {
|
|
4
|
+
if (!target.trim()) {
|
|
5
|
+
throw new Error('A path is required');
|
|
6
|
+
}
|
|
7
|
+
const resolved = path.resolve(cwd, target);
|
|
8
|
+
if (resolved === path.parse(resolved).root) {
|
|
9
|
+
throw new Error('Cannot clean a filesystem root');
|
|
10
|
+
}
|
|
11
|
+
if (resolved === path.resolve(cwd)) {
|
|
12
|
+
throw new Error('Cannot clean the current working directory');
|
|
13
|
+
}
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
export async function runCli(argv, cwd) {
|
|
17
|
+
const [command, target] = argv;
|
|
18
|
+
if (command !== 'clean') {
|
|
19
|
+
throw new Error(`Unrecognized command: "${command ?? ''}". The only supported command is "clean".`);
|
|
20
|
+
}
|
|
21
|
+
const resolved = resolveCleanTarget(target ?? '', cwd);
|
|
22
|
+
await clean(resolved);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=cliClean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliClean.js","sourceRoot":"","sources":["../src/cliClean.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,GAAW;IAC7D,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAE3C,IAAI,QAAQ,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,QAAQ,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAc,EAAE,GAAW;IACvD,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAE/B,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACd,0BAA0B,OAAO,IAAI,EAAE,2CAA2C,CAClF,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;IACvD,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mikode13/cross-platform",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cross-platform utilities for MiKode build and maintenance scripts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mikode13/cross-platform.git"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": "^22.13.0 || ^24.0.0"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"mikode-scripts": "./dist/bin.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@mikode13/code-quality": "0.1.0",
|
|
30
|
+
"@mikode13/code-style": "0.1.0",
|
|
31
|
+
"@mikode13/git-hooks": "0.1.0",
|
|
32
|
+
"@mikode13/tsconfig": "0.1.0",
|
|
33
|
+
"@types/node": "^26.1.2",
|
|
34
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
35
|
+
"eslint": "^10.8.0",
|
|
36
|
+
"prettier": "^3.9.6",
|
|
37
|
+
"typescript": "^6.0.3",
|
|
38
|
+
"vitest": "^4.1.11"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.build.json",
|
|
42
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tests",
|
|
43
|
+
"format": "prettier . --write",
|
|
44
|
+
"format:check": "prettier . --check",
|
|
45
|
+
"lint": "eslint . --max-warnings 0",
|
|
46
|
+
"lint:fix": "eslint . --fix",
|
|
47
|
+
"test": "vitest run --project unit",
|
|
48
|
+
"test:unit": "vitest run --project unit",
|
|
49
|
+
"test:unit:watch": "vitest --project unit",
|
|
50
|
+
"test:coverage": "vitest run --project unit --coverage",
|
|
51
|
+
"pack:check": "pnpm pack --dry-run",
|
|
52
|
+
"check": "pnpm run format:check && pnpm run lint && pnpm run typecheck"
|
|
53
|
+
}
|
|
54
|
+
}
|