package-json-scripts-portability 0.0.3 → 0.0.4
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/README.md +2 -0
- package/dist/analyze-script.d.mts +7 -0
- package/dist/analyze-script.mjs +7 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -158,6 +158,7 @@ Whatever runs the scripts, the commands that package managers run are checked to
|
|
|
158
158
|
|
|
159
159
|
Pass several runners to report what breaks with any of them, e.g. `runner: ['npm', 'pnpm']`.
|
|
160
160
|
Each issue lists the runners that have it in `runners`, and is on the platforms where any of them has it.
|
|
161
|
+
With the `platforms` option, both only take those platforms into account.
|
|
161
162
|
Unknown runners are ignored, and without known ones the scripts are checked as npm runs them.
|
|
162
163
|
|
|
163
164
|
### Runner-agnostic scripts
|
|
@@ -188,6 +189,7 @@ Runner-agnostic scripts aren't checked with `node --run`, since it doesn't insta
|
|
|
188
189
|
| ----------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
189
190
|
| `dependencies` | `[]` | Names of the package's dependencies. With [`del-cli`][del-cli], `del` is reported as cmd.exe's builtin, which takes precedence on Windows outside Yarn's shell. |
|
|
190
191
|
| `ignoreCommands` | `[]` | Commands not to report, e.g. ones that you install on every platform. The commands that they run are still checked. |
|
|
192
|
+
| `platforms` | All platforms | Platforms that the scripts need to work on. Issues on other platforms aren't reported. |
|
|
191
193
|
| `runner` | `'npm'` | What runs the scripts, or a list of runners, see [Package managers](#package-managers). |
|
|
192
194
|
| `runnerAgnosticScripts` | Install scripts and `prepare` | Scripts that are checked with all package managers, see [Runner-agnostic scripts](#runner-agnostic-scripts). |
|
|
193
195
|
| `scriptName` | None | The script's name in `package.json`, e.g. `postinstall`, to tell whether it's runner-agnostic. |
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Platform } from "./platforms.mjs";
|
|
1
2
|
import { ScriptIssue } from "./reporter.mjs";
|
|
2
3
|
import { Runner } from "./runners.mjs";
|
|
3
4
|
import { MaybeReadonlyArray } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/types/maybe-readonly-array.mjs";
|
|
@@ -6,6 +7,12 @@ export interface AnalyzeScriptOptions {
|
|
|
6
7
|
dependencies?: readonly string[];
|
|
7
8
|
/** Commands that shouldn't be reported */
|
|
8
9
|
ignoreCommands?: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* Platforms that the script needs to work on.
|
|
12
|
+
* Issues are only reported on them, with the runners that have the issue on them.
|
|
13
|
+
* Defaults to all platforms
|
|
14
|
+
*/
|
|
15
|
+
platforms?: readonly Platform[];
|
|
9
16
|
/**
|
|
10
17
|
* What runs the script: a package manager, or `node` for `node --run`.
|
|
11
18
|
* It decides e.g. which shell runs the script and which environment variables it gets.
|
package/dist/analyze-script.mjs
CHANGED
|
@@ -14,24 +14,28 @@ const COMMENT_LINES = /^\s*#[^\n]*(?:\n\s*#[^\n]*)*$/;
|
|
|
14
14
|
* A merged issue is on the platforms where any of the runners has it, and keeps its fix only if
|
|
15
15
|
* all of them suggest the same one.
|
|
16
16
|
* @param issuesByRunner The issues found with each runner, by their keys
|
|
17
|
+
* @param platforms The platforms to report the issues on
|
|
17
18
|
* @returns The merged issues
|
|
18
19
|
*/
|
|
19
|
-
const mergeIssues = (issuesByRunner) => {
|
|
20
|
+
const mergeIssues = (issuesByRunner, platforms) => {
|
|
20
21
|
const merged = /* @__PURE__ */ new Map();
|
|
21
22
|
const mergedIssues = /* @__PURE__ */ new Set();
|
|
22
23
|
issuesByRunner.forEach((issues, runner) => {
|
|
23
24
|
const isMerged = mergedIssues.has(issues);
|
|
24
25
|
mergedIssues.add(issues);
|
|
25
26
|
issues.forEach((issue, key) => {
|
|
27
|
+
const issuePlatforms = arrayIntersection(issue.platforms, platforms);
|
|
28
|
+
if (issuePlatforms.length === 0) return;
|
|
26
29
|
const existing = merged.get(key);
|
|
27
30
|
if (existing) {
|
|
28
31
|
existing.runners.push(runner);
|
|
29
32
|
if (!isMerged) {
|
|
30
|
-
existing.platforms = arrayIntersection(PLATFORMS, [...existing.platforms, ...
|
|
33
|
+
existing.platforms = arrayIntersection(PLATFORMS, [...existing.platforms, ...issuePlatforms]);
|
|
31
34
|
if (!isEqual(existing.fix, issue.fix)) existing.fix = void 0;
|
|
32
35
|
}
|
|
33
36
|
} else merged.set(key, {
|
|
34
37
|
...issue,
|
|
38
|
+
platforms: issuePlatforms,
|
|
35
39
|
runners: [runner]
|
|
36
40
|
});
|
|
37
41
|
});
|
|
@@ -48,6 +52,6 @@ const analyzeScript = (script, options) => {
|
|
|
48
52
|
if (COMMENT_LINES.test(script.trimEnd())) return [];
|
|
49
53
|
const analysisOptions = options || {};
|
|
50
54
|
const runners = isRunnerAgnosticScript(analysisOptions.scriptName, analysisOptions.runnerAgnosticScripts) ? PACKAGE_MANAGER_RUNNERS : arrayify(analysisOptions.runner).filter((runner) => KNOWN_RUNNERS.has(runner));
|
|
51
|
-
return mergeIssues(analyzeWithRunners(script, analysisOptions, runners.length > 0 ? runners : DEFAULT_RUNNERS));
|
|
55
|
+
return mergeIssues(analyzeWithRunners(script, analysisOptions, runners.length > 0 ? runners : DEFAULT_RUNNERS), analysisOptions.platforms || PLATFORMS);
|
|
52
56
|
};
|
|
53
57
|
export { analyzeScript };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "package-json-scripts-portability",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Finds package.json scripts that don't work the same on Windows, macOS and Linux with npm, pnpm, Yarn, aube, upm or node --run, and suggests fixes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"npm-scripts",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@andreww2012/npm-check-updates-config": "0.1.1",
|
|
44
44
|
"@antfu/ni": "30.6.0",
|
|
45
45
|
"@arethetypeswrong/core": "0.18.5",
|
|
46
|
-
"@changesets/changelog-github": "
|
|
47
|
-
"@changesets/cli": "3.0
|
|
46
|
+
"@changesets/changelog-github": "2.0.0",
|
|
47
|
+
"@changesets/cli": "3.1.0",
|
|
48
48
|
"@commitlint/cli": "21.2.4",
|
|
49
49
|
"@eslint/config-inspector": "3.5.0",
|
|
50
50
|
"@types/node": "22.20.7",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"@vitest/eslint-plugin": "1.6.28",
|
|
53
53
|
"@vitest/ui": "5.1.2",
|
|
54
54
|
"actions-up": "2.1.0",
|
|
55
|
-
"cspell": "10.
|
|
56
|
-
"eslint": "10.
|
|
55
|
+
"cspell": "10.6.0",
|
|
56
|
+
"eslint": "10.16.0",
|
|
57
57
|
"eslint-config-un": "1.0.0-rc.8",
|
|
58
58
|
"eslint-plugin-github-action": "0.5.0",
|
|
59
59
|
"eslint-plugin-sentences-per-line": "0.1.6",
|
|
60
60
|
"eslint-plugin-sonarjs": "4.2.3",
|
|
61
|
-
"knip": "6.
|
|
61
|
+
"knip": "6.49.0",
|
|
62
62
|
"lefthook": "2.2.4",
|
|
63
63
|
"npm-check-updates": "23.1.1",
|
|
64
64
|
"oxfmt": "0.80.0",
|