which-webstorm 3.2.2 → 4.0.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/package.json CHANGED
@@ -1,49 +1,72 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package.json",
2
3
  "name": "which-webstorm",
3
- "version": "3.2.2",
4
+ "version": "4.0.0",
4
5
  "description": "Find WebStorm binary",
6
+ "license": "MIT",
7
+ "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/oliversalzburg/which-webstorm.git"
11
+ },
12
+ "type": "module",
5
13
  "main": "index.js",
6
- "types": "index.d.ts",
7
14
  "bin": {
8
- "wstorm": "bin/webstorm.js",
9
- "which-webstorm": "index.js"
15
+ "which-webstorm": "index.js",
16
+ "wstorm": "bin/webstorm.js"
10
17
  },
11
18
  "scripts": {
19
+ "build": "node build.js",
20
+ "clean": "rm -rf ./output",
21
+ "lint": "yarn run lint:all",
22
+ "lint:all": "yarn run lint:eslint && yarn run lint:prettier && yarn run lint:tsc",
23
+ "lint:eslint": "eslint .",
24
+ "lint:prettier": "prettier --check .",
25
+ "lint:tsc": "tsc --noEmit",
12
26
  "npm:publish": "npm publish",
27
+ "npm:publish:major": "npm version major && npm publish",
13
28
  "npm:publish:minor": "npm version minor && npm publish",
14
29
  "npm:publish:patch": "npm version patch && npm publish",
15
- "style:check": "prettier --check .",
16
- "style:write": "prettier --write .",
17
- "test": "nyc mocha"
30
+ "test": "tsc && node $(yarn bin mocha) output/*.test.js",
31
+ "test:coverage": "tsc && c8 --reporter=html-spa node $(yarn bin mocha) output/*.test.js"
18
32
  },
19
- "keywords": [
20
- "webstorm"
21
- ],
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/oliversalzburg/which-webstorm.git"
25
- },
26
- "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
27
- "license": "MIT",
33
+ "types": "index.d.ts",
28
34
  "dependencies": {
35
+ "@oliversalzburg/js-utils": "0.0.28",
29
36
  "execa": "8.0.1",
30
- "semver": "7.5.4",
37
+ "semver": "7.6.0",
31
38
  "which": "4.0.0"
32
39
  },
33
40
  "devDependencies": {
34
- "@jsdevtools/chai-exec": "2.1.1",
35
- "@types/node": "20.8.7",
36
- "chai": "4.3.10",
37
- "chai-as-promised": "7.1.1",
38
- "mocha": "10.2.0",
41
+ "@eslint/js": "9.1.1",
42
+ "@types/chai": "4.3.14",
43
+ "@types/eslint": "8.56.10",
44
+ "@types/mocha": "10.0.6",
45
+ "@types/mock-fs": "4.13.4",
46
+ "@types/node": "20.12.7",
47
+ "@types/which": "3.0.3",
48
+ "c8": "9.1.0",
49
+ "chai": "5.1.0",
50
+ "esbuild": "0.20.2",
51
+ "eslint": "8.57.0",
52
+ "globals": "15.0.0",
53
+ "lint-staged": "15.2.2",
54
+ "mocha": "10.4.0",
39
55
  "mock-fs": "5.2.0",
40
- "nyc": "15.1.0",
41
- "prettier": "3.0.3"
56
+ "prettier": "3.2.5",
57
+ "prettier-package-json": "2.8.0",
58
+ "prettier-plugin-organize-imports": "3.2.4",
59
+ "typescript": "5.4.5",
60
+ "typescript-eslint": "7.7.1"
61
+ },
62
+ "keywords": [
63
+ "webstorm"
64
+ ],
65
+ "engines": {
66
+ "node": ">= 18"
42
67
  },
43
68
  "publishConfig": {
44
69
  "registry": "https://registry.npmjs.org"
45
70
  },
46
- "engines": {
47
- "node": ">=12"
48
- }
71
+ "packageManager": "yarn@4.1.1"
49
72
  }
package/.prettierrc.json DELETED
@@ -1 +0,0 @@
1
- {}
package/index.d.ts DELETED
@@ -1,27 +0,0 @@
1
- /// <reference types="node" />
2
- import * as fs from "fs";
3
- declare module "which-webstorm" {
4
- type findWebstormAsync = () => Promise<string>;
5
- type findWebstormSync = {
6
- sync: () => string;
7
- webstormBinary: () => string;
8
- };
9
- const findWebstorm: findWebstormAsync & findWebstormSync;
10
-
11
- type readDirResult = string[] | Buffer[] | fs.Dirent[];
12
-
13
- export class WebStormLocator {
14
- webstormBinary: () => string;
15
- findWebstorm: () => string;
16
- findWebstormAsync: () => Promise<string>;
17
- findJetbrainsProducts: () => readDirResult;
18
- findJetbrainsProductsAsync: () => Promise<readDirResult>;
19
- findManual: () => string;
20
- findManualAsync: () => string;
21
- findManualWindows: (
22
- jetbrainsProducts: readDirResult,
23
- validateSynchronously: boolean
24
- ) => string;
25
- }
26
- }
27
- export default findWebstorm;
package/index.js DELETED
@@ -1,108 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- "use strict";
4
-
5
- const fs = require("fs");
6
- const path = require("path");
7
- const which = require("which");
8
- const semver = require("semver");
9
-
10
- class WebStormLocator {
11
- webstormBinary() {
12
- return process.arch === "x64" ? "webstorm64.exe" : "webstorm.exe";
13
- }
14
-
15
- findWebstorm() {
16
- try {
17
- return which.sync(this.webstormBinary());
18
- } catch (error) {
19
- // Not found on PATH, attempt manual lookup.
20
- return this.findManual();
21
- }
22
- }
23
- async findWebstormAsync() {
24
- try {
25
- return await which(this.webstormBinary());
26
- } catch (error) {
27
- // Not found on PATH, attempt manual lookup.
28
- return this.findManual();
29
- }
30
- }
31
-
32
- findJetbrainsProducts() {
33
- return fs.readdirSync(path.join(process.env["ProgramFiles(x86)"], "JetBrains"));
34
- }
35
- findJetbrainsProductsAsync() {
36
- return fs.promises.readdir(
37
- path.join(process.env["ProgramFiles(x86)"], "JetBrains")
38
- );
39
- }
40
-
41
- findManual() {
42
- switch (process.platform) {
43
- case "win32":
44
- return this.findManualWindows(this.findJetbrainsProducts());
45
-
46
- default:
47
- throw new Error(`Platform '${process.platform}' is not supported.`);
48
- }
49
- }
50
- async findManualAsync() {
51
- switch (process.platform) {
52
- case "win32":
53
- return this.findManualWindows(await this.findJetbrainsProductsAsync());
54
-
55
- default:
56
- throw new Error(`Platform '${process.platform}' is not supported.`);
57
- }
58
- }
59
-
60
- findManualWindows(jetbrainsProducts, validateSynchronously = true) {
61
- return this._getLatest(
62
- jetbrainsProducts
63
- .filter((entry) => entry.match(/WebStorm/))
64
- .map((entry) => {
65
- return path.join(
66
- process.env["ProgramFiles(x86)"],
67
- "JetBrains",
68
- entry,
69
- "bin",
70
- this.webstormBinary()
71
- );
72
- })
73
- .filter((candidate) => fs.existsSync(candidate))
74
- .map((entry) => {
75
- const ver = entry.match(/WebStorm[^0-9]([0-9\.]+)/) || ["", ""];
76
- return {
77
- version: semver.valid(semver.coerce(ver[1])),
78
- path: entry,
79
- };
80
- })
81
- .sort(this._customSort)
82
- );
83
- }
84
-
85
- _customSort(a, b) {
86
- return semver.gt(a.version, b.version) ? -1 : 1;
87
- }
88
-
89
- _getLatest(entries) {
90
- if (!entries || !entries.length) {
91
- throw new Error("WebStorm not found");
92
- }
93
- return entries[0].path;
94
- }
95
- }
96
-
97
- if (module.parent) {
98
- const locator = new WebStormLocator();
99
-
100
- // For compatibility with older versions, export a matching interface.
101
- module.exports = locator.findWebstormAsync.bind(locator);
102
- module.exports.sync = locator.findWebstorm.bind(locator);
103
- module.exports.webstormBinary = locator.webstormBinary.bind(locator);
104
- // Also export the class itself for external consumption.
105
- module.exports.WebStormLocator = WebStormLocator;
106
- } else {
107
- new WebStormLocator().findWebstormAsync().then(console.log).catch(console.error);
108
- }
package/test/test.js DELETED
@@ -1,193 +0,0 @@
1
- "use strict";
2
-
3
- const mocha = require("mocha");
4
-
5
- const after = mocha.after;
6
- const before = mocha.before;
7
- const chai = require("chai");
8
- const chaiAsPromised = require("chai-as-promised");
9
- const chaiExec = require("@jsdevtools/chai-exec");
10
- const describe = mocha.describe;
11
- const expect = require("chai").expect;
12
- const it = mocha.it;
13
- const mockFs = require("mock-fs");
14
-
15
- chai.use(chaiAsPromised);
16
- chai.use(chaiExec);
17
-
18
- describe("which-webstorm", () => {
19
- const whichWebstorm = require("..");
20
-
21
- describe("x86", () => {
22
- let originalArch;
23
- before(() => {
24
- originalArch = process.arch;
25
- Object.defineProperty(process, "arch", {
26
- value: "x86",
27
- });
28
- });
29
- after(() => {
30
- Object.defineProperty(process, "arch", {
31
- value: originalArch,
32
- });
33
- });
34
- it("should return the x86 binary name", () => {
35
- expect(whichWebstorm.webstormBinary()).to.equal("webstorm.exe");
36
- });
37
- });
38
-
39
- describe("x64", () => {
40
- let originalArch;
41
- before(() => {
42
- originalArch = process.arch;
43
- Object.defineProperty(process, "arch", {
44
- value: "x64",
45
- });
46
- });
47
- after(() => {
48
- Object.defineProperty(process, "arch", {
49
- value: originalArch,
50
- });
51
- });
52
- it("should return the x64 binary name", () => {
53
- expect(whichWebstorm.webstormBinary()).to.equal("webstorm64.exe");
54
- });
55
- });
56
-
57
- describe("eap directory (async)", () => {
58
- let originalArch;
59
- before(() => {
60
- originalArch = process.arch;
61
- Object.defineProperty(process, "arch", {
62
- value: "x64",
63
- });
64
- });
65
- after(() => {
66
- Object.defineProperty(process, "arch", {
67
- value: originalArch,
68
- });
69
- });
70
-
71
- before(() =>
72
- mockFs({
73
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 163.9999\\bin\\webstorm64.exe":
74
- "foo",
75
- })
76
- );
77
- after(() => mockFs.restore());
78
-
79
- it("should return the webstorm binary", () => {
80
- return expect(whichWebstorm()).to.eventually.equal(
81
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 163.9999\\bin\\webstorm64.exe"
82
- );
83
- });
84
- });
85
-
86
- describe("eap directory", () => {
87
- let originalArch;
88
- before(() => {
89
- originalArch = process.arch;
90
- Object.defineProperty(process, "arch", {
91
- value: "x64",
92
- });
93
- });
94
- after(() => {
95
- Object.defineProperty(process, "arch", {
96
- value: originalArch,
97
- });
98
- });
99
-
100
- before(() =>
101
- mockFs({
102
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 163.9999\\bin\\webstorm64.exe":
103
- "foo",
104
- })
105
- );
106
- after(() => mockFs.restore());
107
-
108
- it("should return the webstorm binary", () => {
109
- return expect(whichWebstorm.sync()).to.equal(
110
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 163.9999\\bin\\webstorm64.exe"
111
- );
112
- });
113
- });
114
-
115
- describe("return latest", () => {
116
- let originalArch;
117
- before(() => {
118
- originalArch = process.arch;
119
- Object.defineProperty(process, "arch", {
120
- value: "x64",
121
- });
122
- });
123
- after(() => {
124
- Object.defineProperty(process, "arch", {
125
- value: originalArch,
126
- });
127
- });
128
-
129
- before(() =>
130
- mockFs({
131
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.1\\bin\\webstorm64.exe":
132
- "foo",
133
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 17.9.0\\bin\\webstorm64.exe":
134
- "foo",
135
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.1.4\\bin\\webstorm64.exe":
136
- "foo",
137
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.2\\bin\\webstorm64.exe":
138
- "foo",
139
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 163.9999\\bin\\webstorm64.exe":
140
- "foo",
141
- })
142
- );
143
- after(() => mockFs.restore());
144
-
145
- it("should return the LATEST webstorm binary", () => {
146
- return expect(whichWebstorm.sync()).to.equal(
147
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.2\\bin\\webstorm64.exe"
148
- );
149
- });
150
- });
151
- describe("return latest (async)", () => {
152
- let originalArch;
153
- before(() => {
154
- originalArch = process.arch;
155
- Object.defineProperty(process, "arch", {
156
- value: "x64",
157
- });
158
- });
159
- after(() => {
160
- Object.defineProperty(process, "arch", {
161
- value: originalArch,
162
- });
163
- });
164
-
165
- before(() =>
166
- mockFs({
167
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.1\\bin\\webstorm64.exe":
168
- "foo",
169
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 17.9.0\\bin\\webstorm64.exe":
170
- "foo",
171
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.1.4\\bin\\webstorm64.exe":
172
- "foo",
173
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.2\\bin\\webstorm64.exe":
174
- "foo",
175
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 163.9999\\bin\\webstorm64.exe":
176
- "foo",
177
- })
178
- );
179
- after(() => mockFs.restore());
180
-
181
- it("should return the LATEST webstorm binary", () => {
182
- return expect(whichWebstorm()).to.eventually.equal(
183
- "C:\\Program Files (x86)\\JetBrains\\WebStorm 2020.2\\bin\\webstorm64.exe"
184
- );
185
- });
186
- });
187
- describe("CLI", () => {
188
- it("should not throw when being executed", () => {
189
- const cli = chaiExec("node index.js");
190
- return expect(cli).to.exit.with.code(0);
191
- });
192
- });
193
- });