@vscode/vsce 2.15.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 +18 -0
- package/README.md +105 -0
- package/ThirdPartyNotices.txt +292 -0
- package/out/api.d.ts +59 -0
- package/out/api.js +48 -0
- package/out/main.js +229 -0
- package/out/manifest.js +3 -0
- package/out/nls.js +22 -0
- package/out/npm.js +190 -0
- package/out/package.js +1326 -0
- package/out/publicgalleryapi.js +39 -0
- package/out/publish.js +186 -0
- package/out/search.js +65 -0
- package/out/show.js +71 -0
- package/out/store.js +225 -0
- package/out/util.js +165 -0
- package/out/validation.js +120 -0
- package/out/viewutils.js +73 -0
- package/out/xml.js +11 -0
- package/out/zip.js +57 -0
- package/package.json +99 -0
- package/vsce +2 -0
package/out/main.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const commander_1 = __importDefault(require("commander"));
|
|
26
|
+
const leven_1 = __importDefault(require("leven"));
|
|
27
|
+
const package_1 = require("./package");
|
|
28
|
+
const publish_1 = require("./publish");
|
|
29
|
+
const show_1 = require("./show");
|
|
30
|
+
const search_1 = require("./search");
|
|
31
|
+
const store_1 = require("./store");
|
|
32
|
+
const npm_1 = require("./npm");
|
|
33
|
+
const util_1 = require("./util");
|
|
34
|
+
const semver = __importStar(require("semver"));
|
|
35
|
+
const tty_1 = require("tty");
|
|
36
|
+
const pkg = require('../package.json');
|
|
37
|
+
function fatal(message, ...args) {
|
|
38
|
+
if (message instanceof Error) {
|
|
39
|
+
message = message.message;
|
|
40
|
+
if (/^cancell?ed$/i.test(message)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
util_1.log.error(message, ...args);
|
|
45
|
+
if (/Unauthorized\(401\)/.test(message)) {
|
|
46
|
+
util_1.log.error(`Be sure to use a Personal Access Token which has access to **all accessible accounts**.
|
|
47
|
+
See https://code.visualstudio.com/api/working-with-extensions/publishing-extension#publishing-extensions for more information.`);
|
|
48
|
+
}
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
function main(task) {
|
|
52
|
+
let latestVersion = null;
|
|
53
|
+
const token = new util_1.CancellationToken();
|
|
54
|
+
if ((0, tty_1.isatty)(1)) {
|
|
55
|
+
(0, npm_1.getLatestVersion)(pkg.name, token)
|
|
56
|
+
.then(version => (latestVersion = version))
|
|
57
|
+
.catch(_ => {
|
|
58
|
+
/* noop */
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
task.catch(fatal).then(() => {
|
|
62
|
+
if (latestVersion && semver.gt(latestVersion, pkg.version)) {
|
|
63
|
+
util_1.log.info(`\nThe latest version of ${pkg.name} is ${latestVersion} and you have ${pkg.version}.\nUpdate it now: npm install -g ${pkg.name}`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
token.cancel();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const ValidTargets = [...package_1.Targets].join(', ');
|
|
71
|
+
module.exports = function (argv) {
|
|
72
|
+
commander_1.default.version(pkg.version).usage('<command>');
|
|
73
|
+
commander_1.default
|
|
74
|
+
.command('ls')
|
|
75
|
+
.description('Lists all the files that will be published')
|
|
76
|
+
.option('--yarn', 'Use yarn instead of npm (default inferred from presence of yarn.lock or .yarnrc)')
|
|
77
|
+
.option('--no-yarn', 'Use npm instead of yarn (default inferred from lack of yarn.lock or .yarnrc)')
|
|
78
|
+
.option('--packagedDependencies <path>', 'Select packages that should be published only (includes dependencies)', (val, all) => (all ? all.concat(val) : [val]), undefined)
|
|
79
|
+
.option('--ignoreFile <path>', 'Indicate alternative .vscodeignore')
|
|
80
|
+
// default must remain undefined for dependencies or we will fail to load defaults from package.json
|
|
81
|
+
.option('--dependencies', 'Enable dependency detection via npm or yarn', undefined)
|
|
82
|
+
.option('--no-dependencies', 'Disable dependency detection via npm or yarn', undefined)
|
|
83
|
+
.action(({ yarn, packagedDependencies, ignoreFile, dependencies }) => main((0, package_1.ls)({ useYarn: yarn, packagedDependencies, ignoreFile, dependencies })));
|
|
84
|
+
commander_1.default
|
|
85
|
+
.command('package [version]')
|
|
86
|
+
.description('Packages an extension')
|
|
87
|
+
.option('-o, --out <path>', 'Output .vsix extension file to <path> location (defaults to <name>-<version>.vsix)')
|
|
88
|
+
.option('-t, --target <target>', `Target architecture. Valid targets: ${ValidTargets}`)
|
|
89
|
+
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
|
|
90
|
+
.option('--no-git-tag-version', 'Do not create a version commit and tag when calling `npm version`. Valid only when [version] is provided.')
|
|
91
|
+
.option('--no-update-package-json', 'Do not update `package.json`. Valid only when [version] is provided.')
|
|
92
|
+
.option('--githubBranch <branch>', 'The GitHub branch used to infer relative links in README.md. Can be overridden by --baseContentUrl and --baseImagesUrl.')
|
|
93
|
+
.option('--gitlabBranch <branch>', 'The GitLab branch used to infer relative links in README.md. Can be overridden by --baseContentUrl and --baseImagesUrl.')
|
|
94
|
+
.option('--no-rewrite-relative-links', 'Skip rewriting relative links.')
|
|
95
|
+
.option('--baseContentUrl <url>', 'Prepend all relative links in README.md with this url.')
|
|
96
|
+
.option('--baseImagesUrl <url>', 'Prepend all relative image links in README.md with this url.')
|
|
97
|
+
.option('--yarn', 'Use yarn instead of npm (default inferred from presence of yarn.lock or .yarnrc)')
|
|
98
|
+
.option('--no-yarn', 'Use npm instead of yarn (default inferred from lack of yarn.lock or .yarnrc)')
|
|
99
|
+
.option('--ignoreFile <path>', 'Indicate alternative .vscodeignore')
|
|
100
|
+
.option('--no-gitHubIssueLinking', 'Disable automatic expansion of GitHub-style issue syntax into links')
|
|
101
|
+
.option('--no-gitLabIssueLinking', 'Disable automatic expansion of GitLab-style issue syntax into links')
|
|
102
|
+
// default must remain undefined for dependencies or we will fail to load defaults from package.json
|
|
103
|
+
.option('--dependencies', 'Enable dependency detection via npm or yarn', undefined)
|
|
104
|
+
.option('--no-dependencies', 'Disable dependency detection via npm or yarn')
|
|
105
|
+
.option('--pre-release', 'Mark this package as a pre-release')
|
|
106
|
+
.option('--allow-star-activation', 'Allow using * in activation events')
|
|
107
|
+
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
|
|
108
|
+
.action((version, { out, target, message, gitTagVersion, updatePackageJson, githubBranch, gitlabBranch, rewriteRelativeLinks, baseContentUrl, baseImagesUrl, yarn, ignoreFile, gitHubIssueLinking, gitLabIssueLinking, dependencies, preRelease, allowStarActivation, allowMissingRepository, }) => main((0, package_1.packageCommand)({
|
|
109
|
+
packagePath: out,
|
|
110
|
+
version,
|
|
111
|
+
target,
|
|
112
|
+
commitMessage: message,
|
|
113
|
+
gitTagVersion,
|
|
114
|
+
updatePackageJson,
|
|
115
|
+
githubBranch,
|
|
116
|
+
gitlabBranch,
|
|
117
|
+
rewriteRelativeLinks,
|
|
118
|
+
baseContentUrl,
|
|
119
|
+
baseImagesUrl,
|
|
120
|
+
useYarn: yarn,
|
|
121
|
+
ignoreFile,
|
|
122
|
+
gitHubIssueLinking,
|
|
123
|
+
gitLabIssueLinking,
|
|
124
|
+
dependencies,
|
|
125
|
+
preRelease,
|
|
126
|
+
allowStarActivation,
|
|
127
|
+
allowMissingRepository,
|
|
128
|
+
})));
|
|
129
|
+
commander_1.default
|
|
130
|
+
.command('publish [version]')
|
|
131
|
+
.description('Publishes an extension')
|
|
132
|
+
.option('-p, --pat <token>', 'Personal Access Token (defaults to VSCE_PAT environment variable)', process.env['VSCE_PAT'])
|
|
133
|
+
.option('-t, --target <targets...>', `Target architectures. Valid targets: ${ValidTargets}`)
|
|
134
|
+
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
|
|
135
|
+
.option('--no-git-tag-version', 'Do not create a version commit and tag when calling `npm version`. Valid only when [version] is provided.')
|
|
136
|
+
.option('--no-update-package-json', 'Do not update `package.json`. Valid only when [version] is provided.')
|
|
137
|
+
.option('-i, --packagePath <paths...>', 'Publish the provided VSIX packages.')
|
|
138
|
+
.option('--githubBranch <branch>', 'The GitHub branch used to infer relative links in README.md. Can be overridden by --baseContentUrl and --baseImagesUrl.')
|
|
139
|
+
.option('--gitlabBranch <branch>', 'The GitLab branch used to infer relative links in README.md. Can be overridden by --baseContentUrl and --baseImagesUrl.')
|
|
140
|
+
.option('--baseContentUrl <url>', 'Prepend all relative links in README.md with this url.')
|
|
141
|
+
.option('--baseImagesUrl <url>', 'Prepend all relative image links in README.md with this url.')
|
|
142
|
+
.option('--yarn', 'Use yarn instead of npm (default inferred from presence of yarn.lock or .yarnrc)')
|
|
143
|
+
.option('--no-yarn', 'Use npm instead of yarn (default inferred from lack of yarn.lock or .yarnrc)')
|
|
144
|
+
.option('--noVerify')
|
|
145
|
+
.option('--ignoreFile <path>', 'Indicate alternative .vscodeignore')
|
|
146
|
+
// default must remain undefined for dependencies or we will fail to load defaults from package.json
|
|
147
|
+
.option('--dependencies', 'Enable dependency detection via npm or yarn', undefined)
|
|
148
|
+
.option('--no-dependencies', 'Disable dependency detection via npm or yarn', undefined)
|
|
149
|
+
.option('--pre-release', 'Mark this package as a pre-release')
|
|
150
|
+
.option('--allow-star-activation', 'Allow using * in activation events')
|
|
151
|
+
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
|
|
152
|
+
.option('--skip-duplicate', 'Fail silently if version already exists on the marketplace')
|
|
153
|
+
.action((version, { pat, target, message, gitTagVersion, updatePackageJson, packagePath, githubBranch, gitlabBranch, baseContentUrl, baseImagesUrl, yarn, noVerify, ignoreFile, dependencies, preRelease, allowStarActivation, allowMissingRepository, skipDuplicate, }) => main((0, publish_1.publish)({
|
|
154
|
+
pat,
|
|
155
|
+
version,
|
|
156
|
+
targets: target,
|
|
157
|
+
commitMessage: message,
|
|
158
|
+
gitTagVersion,
|
|
159
|
+
updatePackageJson,
|
|
160
|
+
packagePath,
|
|
161
|
+
githubBranch,
|
|
162
|
+
gitlabBranch,
|
|
163
|
+
baseContentUrl,
|
|
164
|
+
baseImagesUrl,
|
|
165
|
+
useYarn: yarn,
|
|
166
|
+
noVerify,
|
|
167
|
+
ignoreFile,
|
|
168
|
+
dependencies,
|
|
169
|
+
preRelease,
|
|
170
|
+
allowStarActivation,
|
|
171
|
+
allowMissingRepository,
|
|
172
|
+
skipDuplicate,
|
|
173
|
+
})));
|
|
174
|
+
commander_1.default
|
|
175
|
+
.command('unpublish [extensionid]')
|
|
176
|
+
.description('Unpublishes an extension. Example extension id: microsoft.csharp.')
|
|
177
|
+
.option('-p, --pat <token>', 'Personal Access Token')
|
|
178
|
+
.option('-f, --force', 'Forces Unpublished Extension')
|
|
179
|
+
.action((id, { pat, force }) => main((0, publish_1.unpublish)({ id, pat, force })));
|
|
180
|
+
commander_1.default
|
|
181
|
+
.command('ls-publishers')
|
|
182
|
+
.description('List all known publishers')
|
|
183
|
+
.action(() => main((0, store_1.listPublishers)()));
|
|
184
|
+
commander_1.default
|
|
185
|
+
.command('delete-publisher <publisher>')
|
|
186
|
+
.description('Deletes a publisher')
|
|
187
|
+
.action(publisher => main((0, store_1.deletePublisher)(publisher)));
|
|
188
|
+
commander_1.default
|
|
189
|
+
.command('login <publisher>')
|
|
190
|
+
.description('Add a publisher to the known publishers list')
|
|
191
|
+
.action(name => main((0, store_1.loginPublisher)(name)));
|
|
192
|
+
commander_1.default
|
|
193
|
+
.command('logout <publisher>')
|
|
194
|
+
.description('Remove a publisher from the known publishers list')
|
|
195
|
+
.action(name => main((0, store_1.logoutPublisher)(name)));
|
|
196
|
+
commander_1.default
|
|
197
|
+
.command('verify-pat [publisher]')
|
|
198
|
+
.option('-p, --pat <token>', 'Personal Access Token (defaults to VSCE_PAT environment variable)', process.env['VSCE_PAT'])
|
|
199
|
+
.description('Verify if the Personal Access Token has publish rights for the publisher.')
|
|
200
|
+
.action((name, { pat }) => main((0, store_1.verifyPat)(pat, name)));
|
|
201
|
+
commander_1.default
|
|
202
|
+
.command('show <extensionid>')
|
|
203
|
+
.option('--json', 'Output data in json format', false)
|
|
204
|
+
.description('Show extension metadata')
|
|
205
|
+
.action((extensionid, { json }) => main((0, show_1.show)(extensionid, json)));
|
|
206
|
+
commander_1.default
|
|
207
|
+
.command('search <text>')
|
|
208
|
+
.option('--json', 'Output result in json format', false)
|
|
209
|
+
.option('--stats', 'Shows the extension rating and download counts', false)
|
|
210
|
+
.option('-p, --pagesize [value]', 'Number of results to return', '100')
|
|
211
|
+
.description('search extension gallery')
|
|
212
|
+
.action((text, { json, pagesize, stats }) => main((0, search_1.search)(text, json, parseInt(pagesize), stats)));
|
|
213
|
+
commander_1.default.on('command:*', ([cmd]) => {
|
|
214
|
+
if (cmd === 'create-publisher') {
|
|
215
|
+
util_1.log.error(`The 'create-publisher' command is no longer available. You can create a publisher directly in the Marketplace: https://aka.ms/vscode-create-publisher`);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
commander_1.default.outputHelp(help => {
|
|
219
|
+
const availableCommands = commander_1.default.commands.map(c => c._name);
|
|
220
|
+
const suggestion = availableCommands.find(c => (0, leven_1.default)(c, cmd) < c.length * 0.4);
|
|
221
|
+
help = `${help}
|
|
222
|
+
Unknown command '${cmd}'`;
|
|
223
|
+
return suggestion ? `${help}, did you mean '${suggestion}'?\n` : `${help}.\n`;
|
|
224
|
+
});
|
|
225
|
+
process.exit(1);
|
|
226
|
+
});
|
|
227
|
+
commander_1.default.parse(argv);
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=main.js.map
|
package/out/manifest.js
ADDED
package/out/nls.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchNLS = void 0;
|
|
4
|
+
const regex = /^%([\w\d.]+)%$/i;
|
|
5
|
+
function createPatcher(translations) {
|
|
6
|
+
return (value) => {
|
|
7
|
+
if (typeof value !== 'string') {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
const match = regex.exec(value);
|
|
11
|
+
if (!match) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
return (translations[match[1]] ?? value);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function patchNLS(manifest, translations) {
|
|
18
|
+
const patcher = createPatcher(translations);
|
|
19
|
+
return JSON.parse(JSON.stringify(manifest, (_, value) => patcher(value)));
|
|
20
|
+
}
|
|
21
|
+
exports.patchNLS = patchNLS;
|
|
22
|
+
//# sourceMappingURL=nls.js.map
|
package/out/npm.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.getLatestVersion = exports.getDependencies = exports.detectYarn = void 0;
|
|
26
|
+
const path = __importStar(require("path"));
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const cp = __importStar(require("child_process"));
|
|
29
|
+
const parse_semver_1 = __importDefault(require("parse-semver"));
|
|
30
|
+
const util_1 = require("./util");
|
|
31
|
+
const exists = (file) => fs.promises.stat(file).then(_ => true, _ => false);
|
|
32
|
+
function parseStdout({ stdout }) {
|
|
33
|
+
return stdout.split(/[\r\n]/).filter(line => !!line)[0];
|
|
34
|
+
}
|
|
35
|
+
function exec(command, options = {}, cancellationToken) {
|
|
36
|
+
return new Promise((c, e) => {
|
|
37
|
+
let disposeCancellationListener = null;
|
|
38
|
+
const child = cp.exec(command, { ...options, encoding: 'utf8' }, (err, stdout, stderr) => {
|
|
39
|
+
if (disposeCancellationListener) {
|
|
40
|
+
disposeCancellationListener();
|
|
41
|
+
disposeCancellationListener = null;
|
|
42
|
+
}
|
|
43
|
+
if (err) {
|
|
44
|
+
return e(err);
|
|
45
|
+
}
|
|
46
|
+
c({ stdout, stderr });
|
|
47
|
+
});
|
|
48
|
+
if (cancellationToken) {
|
|
49
|
+
disposeCancellationListener = cancellationToken.subscribe((err) => {
|
|
50
|
+
child.kill();
|
|
51
|
+
e(err);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function checkNPM(cancellationToken) {
|
|
57
|
+
const { stdout } = await exec('npm -v', {}, cancellationToken);
|
|
58
|
+
const version = stdout.trim();
|
|
59
|
+
if (/^3\.7\.[0123]$/.test(version)) {
|
|
60
|
+
throw new Error(`npm@${version} doesn't work with vsce. Please update npm: npm install -g npm`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function getNpmDependencies(cwd) {
|
|
64
|
+
return checkNPM()
|
|
65
|
+
.then(() => exec('npm list --production --parseable --depth=99999 --loglevel=error', { cwd, maxBuffer: 5000 * 1024 }))
|
|
66
|
+
.then(({ stdout }) => stdout.split(/[\r\n]/).filter(dir => path.isAbsolute(dir)));
|
|
67
|
+
}
|
|
68
|
+
function asYarnDependency(prefix, tree, prune) {
|
|
69
|
+
if (prune && /@[\^~]/.test(tree.name)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
let name;
|
|
73
|
+
try {
|
|
74
|
+
const parseResult = (0, parse_semver_1.default)(tree.name);
|
|
75
|
+
name = parseResult.name;
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
name = tree.name.replace(/^([^@+])@.*$/, '$1');
|
|
79
|
+
}
|
|
80
|
+
const dependencyPath = path.join(prefix, name);
|
|
81
|
+
const children = [];
|
|
82
|
+
for (const child of tree.children || []) {
|
|
83
|
+
const dep = asYarnDependency(path.join(prefix, name, 'node_modules'), child, prune);
|
|
84
|
+
if (dep) {
|
|
85
|
+
children.push(dep);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { name, path: dependencyPath, children };
|
|
89
|
+
}
|
|
90
|
+
function selectYarnDependencies(deps, packagedDependencies) {
|
|
91
|
+
const index = new (class {
|
|
92
|
+
constructor() {
|
|
93
|
+
this.data = Object.create(null);
|
|
94
|
+
for (const dep of deps) {
|
|
95
|
+
if (this.data[dep.name]) {
|
|
96
|
+
throw Error(`Dependency seen more than once: ${dep.name}`);
|
|
97
|
+
}
|
|
98
|
+
this.data[dep.name] = dep;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
find(name) {
|
|
102
|
+
let result = this.data[name];
|
|
103
|
+
if (!result) {
|
|
104
|
+
throw new Error(`Could not find dependency: ${name}`);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
const reached = new (class {
|
|
110
|
+
constructor() {
|
|
111
|
+
this.values = [];
|
|
112
|
+
}
|
|
113
|
+
add(dep) {
|
|
114
|
+
if (this.values.indexOf(dep) < 0) {
|
|
115
|
+
this.values.push(dep);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
const visit = (name) => {
|
|
122
|
+
let dep = index.find(name);
|
|
123
|
+
if (!reached.add(dep)) {
|
|
124
|
+
// already seen -> done
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
for (const child of dep.children) {
|
|
128
|
+
visit(child.name);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
packagedDependencies.forEach(visit);
|
|
132
|
+
return reached.values;
|
|
133
|
+
}
|
|
134
|
+
async function getYarnProductionDependencies(cwd, packagedDependencies) {
|
|
135
|
+
const raw = await new Promise((c, e) => cp.exec('yarn list --prod --json', { cwd, encoding: 'utf8', env: { ...process.env }, maxBuffer: 5000 * 1024 }, (err, stdout) => (err ? e(err) : c(stdout))));
|
|
136
|
+
const match = /^{"type":"tree".*$/m.exec(raw);
|
|
137
|
+
if (!match || match.length !== 1) {
|
|
138
|
+
throw new Error('Could not parse result of `yarn list --json`');
|
|
139
|
+
}
|
|
140
|
+
const usingPackagedDependencies = Array.isArray(packagedDependencies);
|
|
141
|
+
const trees = JSON.parse(match[0]).data.trees;
|
|
142
|
+
let result = trees
|
|
143
|
+
.map(tree => asYarnDependency(path.join(cwd, 'node_modules'), tree, !usingPackagedDependencies))
|
|
144
|
+
.filter(util_1.nonnull);
|
|
145
|
+
if (usingPackagedDependencies) {
|
|
146
|
+
result = selectYarnDependencies(result, packagedDependencies);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
async function getYarnDependencies(cwd, packagedDependencies) {
|
|
151
|
+
const result = new Set([cwd]);
|
|
152
|
+
const deps = await getYarnProductionDependencies(cwd, packagedDependencies);
|
|
153
|
+
const flatten = (dep) => {
|
|
154
|
+
result.add(dep.path);
|
|
155
|
+
dep.children.forEach(flatten);
|
|
156
|
+
};
|
|
157
|
+
deps.forEach(flatten);
|
|
158
|
+
return [...result];
|
|
159
|
+
}
|
|
160
|
+
async function detectYarn(cwd) {
|
|
161
|
+
for (const name of ['yarn.lock', '.yarnrc', '.yarnrc.yaml', '.pnp.cjs', '.yarn']) {
|
|
162
|
+
if (await exists(path.join(cwd, name))) {
|
|
163
|
+
if (!process.env['VSCE_TESTS']) {
|
|
164
|
+
util_1.log.info(`Detected presence of ${name}. Using 'yarn' instead of 'npm' (to override this pass '--no-yarn' on the command line).`);
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
exports.detectYarn = detectYarn;
|
|
172
|
+
async function getDependencies(cwd, dependencies, packagedDependencies) {
|
|
173
|
+
if (dependencies === 'none') {
|
|
174
|
+
return [cwd];
|
|
175
|
+
}
|
|
176
|
+
else if (dependencies === 'yarn' || (dependencies === undefined && (await detectYarn(cwd)))) {
|
|
177
|
+
return await getYarnDependencies(cwd, packagedDependencies);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return await getNpmDependencies(cwd);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.getDependencies = getDependencies;
|
|
184
|
+
function getLatestVersion(name, cancellationToken) {
|
|
185
|
+
return checkNPM(cancellationToken)
|
|
186
|
+
.then(() => exec(`npm show ${name} version`, {}, cancellationToken))
|
|
187
|
+
.then(parseStdout);
|
|
188
|
+
}
|
|
189
|
+
exports.getLatestVersion = getLatestVersion;
|
|
190
|
+
//# sourceMappingURL=npm.js.map
|