@illumine/npm-diff 0.1.0 → 0.2.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/README.md +6 -5
- package/lib/index.cjs +33 -7
- package/lib/index.js +33 -8
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -14,11 +14,12 @@ extension, so a `code` CLI on your `PATH` is required.
|
|
|
14
14
|
|
|
15
15
|
## Options
|
|
16
16
|
|
|
17
|
-
| Option | Description
|
|
18
|
-
| ----------------- |
|
|
19
|
-
| `-r, --registry` | npm registry to query.
|
|
20
|
-
| `-w, --workspace` | Directory to place the two versions.
|
|
21
|
-
| `-u, --unminify` | Unminify sources before diffing.
|
|
17
|
+
| Option | Description | Default |
|
|
18
|
+
| ----------------- | ---------------------------------------------- | ----------------------------- |
|
|
19
|
+
| `-r, --registry` | npm registry to query. | `https://registry.npmjs.org` |
|
|
20
|
+
| `-w, --workspace` | Directory to place the two versions. | a temp dir, removed on exit |
|
|
21
|
+
| `-u, --unminify` | Unminify sources before diffing. | off |
|
|
22
|
+
| `-p, --pattern` | Compare only files matching this glob (repeat for more). | all files |
|
|
22
23
|
|
|
23
24
|
## License
|
|
24
25
|
|
package/lib/index.cjs
CHANGED
|
@@ -5,15 +5,17 @@ var extraTypings = require('@commander-js/extra-typings');
|
|
|
5
5
|
var zx = require('zx');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var semver = require('semver');
|
|
8
|
-
var tar = require('tar');
|
|
9
8
|
var prompts = require('@inquirer/prompts');
|
|
10
9
|
var promises = require('fs/promises');
|
|
11
10
|
var unminify = require('@illumine/unminify');
|
|
12
11
|
var oxfmt = require('oxfmt');
|
|
12
|
+
var picomatch = require('picomatch');
|
|
13
|
+
var tar = require('tar');
|
|
13
14
|
|
|
14
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
|
|
16
17
|
var semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
18
|
+
var picomatch__default = /*#__PURE__*/_interopDefault(picomatch);
|
|
17
19
|
|
|
18
20
|
// src/error.ts
|
|
19
21
|
var CliError = class extends Error {
|
|
@@ -76,6 +78,27 @@ async function formatTree(dir) {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
}
|
|
81
|
+
async function unpack(tarball, dir, patterns) {
|
|
82
|
+
const isMatch = compilePattern(patterns);
|
|
83
|
+
const filter = isMatch ? (path) => {
|
|
84
|
+
const rel = path.split("/").slice(1).join("/");
|
|
85
|
+
return rel !== "" && isMatch(rel);
|
|
86
|
+
} : void 0;
|
|
87
|
+
await tar.extract({ file: tarball, cwd: dir, strip: 1, filter });
|
|
88
|
+
await promises.rm(tarball);
|
|
89
|
+
}
|
|
90
|
+
function compilePattern(patterns) {
|
|
91
|
+
if (patterns.length === 0) return void 0;
|
|
92
|
+
const include = [];
|
|
93
|
+
const ignore = [];
|
|
94
|
+
for (const pattern of patterns) {
|
|
95
|
+
const negated = pattern.startsWith("!");
|
|
96
|
+
const base = (negated ? pattern.slice(1) : pattern).replace(/\/+$/, "");
|
|
97
|
+
const target = negated ? ignore : include;
|
|
98
|
+
target.push(base, `${base}/**`);
|
|
99
|
+
}
|
|
100
|
+
return picomatch__default.default(include.length ? include : "**", { dot: true, ignore });
|
|
101
|
+
}
|
|
79
102
|
var EXTENSION_ID = "moshfeu.compare-folders";
|
|
80
103
|
async function ensureVscode() {
|
|
81
104
|
const code = await zx.which("code", { nothrow: true });
|
|
@@ -111,6 +134,7 @@ var NpmDiff = class {
|
|
|
111
134
|
this.workdir = options.workspace ? path.resolve(options.workspace) : zx.tmpdir("npmdiff-");
|
|
112
135
|
this.clean = options.workspace === void 0;
|
|
113
136
|
this.unminify = options.unminify ?? false;
|
|
137
|
+
this.patterns = options.pattern ?? [];
|
|
114
138
|
}
|
|
115
139
|
pkg;
|
|
116
140
|
packument;
|
|
@@ -118,6 +142,7 @@ var NpmDiff = class {
|
|
|
118
142
|
workdir;
|
|
119
143
|
clean;
|
|
120
144
|
unminify;
|
|
145
|
+
patterns;
|
|
121
146
|
async run(specA, specB) {
|
|
122
147
|
await ensureVscode();
|
|
123
148
|
this.packument = await zx.spinner(
|
|
@@ -167,7 +192,7 @@ var NpmDiff = class {
|
|
|
167
192
|
const dir = path.join(this.workdir, version);
|
|
168
193
|
await zx.fs.mkdirp(dir);
|
|
169
194
|
const tarball = await zx.spinner(`Downloading ${label}`, () => this.download(version, dir));
|
|
170
|
-
await zx.spinner(`Unpacking ${label}`, () =>
|
|
195
|
+
await zx.spinner(`Unpacking ${label}`, () => unpack(tarball, dir, this.patterns));
|
|
171
196
|
if (this.unminify) await zx.spinner(`Unminifying ${label}`, () => unminifyTree(dir));
|
|
172
197
|
await zx.spinner(`Formatting ${label}`, () => formatTree(dir));
|
|
173
198
|
return dir;
|
|
@@ -177,10 +202,6 @@ var NpmDiff = class {
|
|
|
177
202
|
const [{ filename }] = JSON.parse(stdout);
|
|
178
203
|
return path.join(dir, filename);
|
|
179
204
|
}
|
|
180
|
-
async unpack(tarball, dir) {
|
|
181
|
-
await tar.extract({ file: tarball, cwd: dir, strip: 1 });
|
|
182
|
-
await zx.fs.remove(tarball);
|
|
183
|
-
}
|
|
184
205
|
};
|
|
185
206
|
|
|
186
207
|
// src/index.ts
|
|
@@ -189,7 +210,12 @@ var program = new extraTypings.Command();
|
|
|
189
210
|
program.name("npmdiff").description("Diff two versions of an npm package in VS Code, unminified and formatted").argument("<pkgname>", "npm package name (scoped names supported)").argument("[spec-a]", "a version or dist-tag").argument("[spec-b]", "a version or dist-tag").option("-r, --registry <url>", "npm registry to query", DEFAULT_REGISTRY).option(
|
|
190
211
|
"-w, --workspace <dir>",
|
|
191
212
|
"directory to place the two versions; kept instead of auto-cleaned when set"
|
|
192
|
-
).option("-u, --unminify", "unminify sources before diffing", false).
|
|
213
|
+
).option("-u, --unminify", "unminify sources before diffing", false).option(
|
|
214
|
+
"-p, --pattern <glob>",
|
|
215
|
+
"compare only files matching this glob; repeat for more",
|
|
216
|
+
(value, previous) => [...previous, value],
|
|
217
|
+
[]
|
|
218
|
+
).action((pkgname, specA, specB, options) => new NpmDiff(pkgname, options).run(specA, specB));
|
|
193
219
|
program.parseAsync().catch((error) => {
|
|
194
220
|
if (error instanceof CliError) {
|
|
195
221
|
console.error(zx.chalk.red(error.message));
|
package/lib/index.js
CHANGED
|
@@ -3,11 +3,12 @@ import { Command } from '@commander-js/extra-typings';
|
|
|
3
3
|
import { $, chalk, tmpdir, spinner, fs, which, glob } from 'zx';
|
|
4
4
|
import { resolve, join, basename } from 'path';
|
|
5
5
|
import semver from 'semver';
|
|
6
|
-
import { extract } from 'tar';
|
|
7
6
|
import { confirm, search } from '@inquirer/prompts';
|
|
8
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
7
|
+
import { rm, readFile, writeFile } from 'fs/promises';
|
|
9
8
|
import { unminify } from '@illumine/unminify';
|
|
10
9
|
import { format } from 'oxfmt';
|
|
10
|
+
import picomatch from 'picomatch';
|
|
11
|
+
import { extract } from 'tar';
|
|
11
12
|
|
|
12
13
|
// src/error.ts
|
|
13
14
|
var CliError = class extends Error {
|
|
@@ -70,6 +71,27 @@ async function formatTree(dir) {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
74
|
+
async function unpack(tarball, dir, patterns) {
|
|
75
|
+
const isMatch = compilePattern(patterns);
|
|
76
|
+
const filter = isMatch ? (path) => {
|
|
77
|
+
const rel = path.split("/").slice(1).join("/");
|
|
78
|
+
return rel !== "" && isMatch(rel);
|
|
79
|
+
} : void 0;
|
|
80
|
+
await extract({ file: tarball, cwd: dir, strip: 1, filter });
|
|
81
|
+
await rm(tarball);
|
|
82
|
+
}
|
|
83
|
+
function compilePattern(patterns) {
|
|
84
|
+
if (patterns.length === 0) return void 0;
|
|
85
|
+
const include = [];
|
|
86
|
+
const ignore = [];
|
|
87
|
+
for (const pattern of patterns) {
|
|
88
|
+
const negated = pattern.startsWith("!");
|
|
89
|
+
const base = (negated ? pattern.slice(1) : pattern).replace(/\/+$/, "");
|
|
90
|
+
const target = negated ? ignore : include;
|
|
91
|
+
target.push(base, `${base}/**`);
|
|
92
|
+
}
|
|
93
|
+
return picomatch(include.length ? include : "**", { dot: true, ignore });
|
|
94
|
+
}
|
|
73
95
|
var EXTENSION_ID = "moshfeu.compare-folders";
|
|
74
96
|
async function ensureVscode() {
|
|
75
97
|
const code = await which("code", { nothrow: true });
|
|
@@ -105,6 +127,7 @@ var NpmDiff = class {
|
|
|
105
127
|
this.workdir = options.workspace ? resolve(options.workspace) : tmpdir("npmdiff-");
|
|
106
128
|
this.clean = options.workspace === void 0;
|
|
107
129
|
this.unminify = options.unminify ?? false;
|
|
130
|
+
this.patterns = options.pattern ?? [];
|
|
108
131
|
}
|
|
109
132
|
pkg;
|
|
110
133
|
packument;
|
|
@@ -112,6 +135,7 @@ var NpmDiff = class {
|
|
|
112
135
|
workdir;
|
|
113
136
|
clean;
|
|
114
137
|
unminify;
|
|
138
|
+
patterns;
|
|
115
139
|
async run(specA, specB) {
|
|
116
140
|
await ensureVscode();
|
|
117
141
|
this.packument = await spinner(
|
|
@@ -161,7 +185,7 @@ var NpmDiff = class {
|
|
|
161
185
|
const dir = join(this.workdir, version);
|
|
162
186
|
await fs.mkdirp(dir);
|
|
163
187
|
const tarball = await spinner(`Downloading ${label}`, () => this.download(version, dir));
|
|
164
|
-
await spinner(`Unpacking ${label}`, () =>
|
|
188
|
+
await spinner(`Unpacking ${label}`, () => unpack(tarball, dir, this.patterns));
|
|
165
189
|
if (this.unminify) await spinner(`Unminifying ${label}`, () => unminifyTree(dir));
|
|
166
190
|
await spinner(`Formatting ${label}`, () => formatTree(dir));
|
|
167
191
|
return dir;
|
|
@@ -171,10 +195,6 @@ var NpmDiff = class {
|
|
|
171
195
|
const [{ filename }] = JSON.parse(stdout);
|
|
172
196
|
return join(dir, filename);
|
|
173
197
|
}
|
|
174
|
-
async unpack(tarball, dir) {
|
|
175
|
-
await extract({ file: tarball, cwd: dir, strip: 1 });
|
|
176
|
-
await fs.remove(tarball);
|
|
177
|
-
}
|
|
178
198
|
};
|
|
179
199
|
|
|
180
200
|
// src/index.ts
|
|
@@ -183,7 +203,12 @@ var program = new Command();
|
|
|
183
203
|
program.name("npmdiff").description("Diff two versions of an npm package in VS Code, unminified and formatted").argument("<pkgname>", "npm package name (scoped names supported)").argument("[spec-a]", "a version or dist-tag").argument("[spec-b]", "a version or dist-tag").option("-r, --registry <url>", "npm registry to query", DEFAULT_REGISTRY).option(
|
|
184
204
|
"-w, --workspace <dir>",
|
|
185
205
|
"directory to place the two versions; kept instead of auto-cleaned when set"
|
|
186
|
-
).option("-u, --unminify", "unminify sources before diffing", false).
|
|
206
|
+
).option("-u, --unminify", "unminify sources before diffing", false).option(
|
|
207
|
+
"-p, --pattern <glob>",
|
|
208
|
+
"compare only files matching this glob; repeat for more",
|
|
209
|
+
(value, previous) => [...previous, value],
|
|
210
|
+
[]
|
|
211
|
+
).action((pkgname, specA, specB, options) => new NpmDiff(pkgname, options).run(specA, specB));
|
|
187
212
|
program.parseAsync().catch((error) => {
|
|
188
213
|
if (error instanceof CliError) {
|
|
189
214
|
console.error(chalk.red(error.message));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@illumine/npm-diff",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Diff two versions of an npm package in VS Code, unminified and formatted",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@commander-js/extra-typings": "^15.0.0",
|
|
37
37
|
"commander": "^15.0.0",
|
|
38
38
|
"oxfmt": "~0.53.0",
|
|
39
|
+
"picomatch": "^4.0.5",
|
|
39
40
|
"semver": "^7.8.5",
|
|
40
41
|
"tar": "^7.5.19",
|
|
41
42
|
"zx": "^8.8.5",
|