@yarnpkg/plugin-essentials 4.0.0-rc.25 → 4.0.0-rc.26

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.
@@ -0,0 +1,8 @@
1
+ import { BaseCommand } from '@yarnpkg/cli';
2
+ import { Usage } from 'clipanion';
3
+ export default class PluginCheckCommand extends BaseCommand {
4
+ static paths: string[][];
5
+ static usage: Usage;
6
+ json: boolean;
7
+ execute(): Promise<1 | 0>;
8
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_1 = require("@yarnpkg/cli");
4
+ const core_1 = require("@yarnpkg/core");
5
+ const clipanion_1 = require("clipanion");
6
+ // eslint-disable-next-line arca/no-default-export
7
+ class PluginCheckCommand extends cli_1.BaseCommand {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.json = clipanion_1.Option.Boolean(`--json`, false, {
11
+ description: `Format the output as an NDJSON stream`,
12
+ });
13
+ }
14
+ async execute() {
15
+ const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
16
+ const rcFiles = await core_1.Configuration.findRcFiles(this.context.cwd);
17
+ const report = await core_1.StreamReport.start({
18
+ configuration,
19
+ json: this.json,
20
+ stdout: this.context.stdout,
21
+ }, async (report) => {
22
+ var _a;
23
+ for (const rcFile of rcFiles) {
24
+ if (!((_a = rcFile.data) === null || _a === void 0 ? void 0 : _a.plugins))
25
+ continue;
26
+ for (const plugin of rcFile.data.plugins) {
27
+ if (!plugin.checksum)
28
+ continue;
29
+ if (!plugin.spec.match(/^https?:/))
30
+ continue;
31
+ const newBuffer = await core_1.httpUtils.get(plugin.spec, { configuration });
32
+ const newChecksum = core_1.hashUtils.makeHash(newBuffer);
33
+ if (plugin.checksum === newChecksum)
34
+ continue;
35
+ const prettyPath = core_1.formatUtils.pretty(configuration, plugin.path, core_1.formatUtils.Type.PATH);
36
+ const prettySpec = core_1.formatUtils.pretty(configuration, plugin.spec, core_1.formatUtils.Type.URL);
37
+ const prettyMessage = `${prettyPath} is different from the file provided by ${prettySpec}`;
38
+ report.reportJson({ ...plugin, newChecksum });
39
+ report.reportError(core_1.MessageName.UNNAMED, prettyMessage);
40
+ }
41
+ }
42
+ });
43
+ return report.exitCode();
44
+ }
45
+ }
46
+ exports.default = PluginCheckCommand;
47
+ PluginCheckCommand.paths = [
48
+ [`plugin`, `check`],
49
+ ];
50
+ PluginCheckCommand.usage = clipanion_1.Command.Usage({
51
+ category: `Plugin-related commands`,
52
+ description: `find all third-party plugins that differ from their own spec`,
53
+ details: `
54
+ Check only the plugins from https.
55
+
56
+ If this command detects any plugin differences in the CI environment, it will throw an error.
57
+ `,
58
+ examples: [[
59
+ `find all third-party plugins that differ from their own spec`,
60
+ `$0 plugin check`,
61
+ ]],
62
+ });
@@ -6,9 +6,11 @@ export default class PluginImportCommand extends BaseCommand {
6
6
  static paths: string[][];
7
7
  static usage: Usage;
8
8
  name: string;
9
+ checksum: boolean;
9
10
  execute(): Promise<1 | 0>;
10
11
  }
11
- export declare function savePlugin(pluginSpec: string, pluginBuffer: Buffer, { project, report }: {
12
+ export declare function savePlugin(pluginSpec: string, pluginBuffer: Buffer, { checksum, project, report }: {
13
+ checksum?: boolean;
12
14
  project: Project;
13
15
  report: Report;
14
16
  }): Promise<void>;
@@ -16,6 +16,9 @@ class PluginImportCommand extends cli_1.BaseCommand {
16
16
  constructor() {
17
17
  super(...arguments);
18
18
  this.name = clipanion_1.Option.String();
19
+ this.checksum = clipanion_1.Option.Boolean(`--checksum`, true, {
20
+ description: `Whether to care if this plugin is modified`,
21
+ });
19
22
  }
20
23
  async execute() {
21
24
  const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
@@ -70,7 +73,7 @@ class PluginImportCommand extends cli_1.BaseCommand {
70
73
  report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, pluginUrl, `green`)}`);
71
74
  pluginBuffer = await core_2.httpUtils.get(pluginUrl, { configuration });
72
75
  }
73
- await savePlugin(pluginSpec, pluginBuffer, { project, report });
76
+ await savePlugin(pluginSpec, pluginBuffer, { checksum: this.checksum, project, report });
74
77
  });
75
78
  return report.exitCode();
76
79
  }
@@ -91,6 +94,8 @@ PluginImportCommand.usage = clipanion_1.Command.Usage({
91
94
  - Third-party plugins can be referenced directly through their public urls.
92
95
  - Local plugins can be referenced by their path on the disk.
93
96
 
97
+ If the \`--no-checksum\` option is set, Yarn will no longer care if the plugin is modified.
98
+
94
99
  Plugins cannot be downloaded from the npm registry, and aren't allowed to have dependencies (they need to be bundled into a single file, possibly thanks to the \`@yarnpkg/builder\` package).
95
100
  `,
96
101
  examples: [[
@@ -107,7 +112,7 @@ PluginImportCommand.usage = clipanion_1.Command.Usage({
107
112
  `$0 plugin import ./path/to/plugin.js`,
108
113
  ]],
109
114
  });
110
- async function savePlugin(pluginSpec, pluginBuffer, { project, report }) {
115
+ async function savePlugin(pluginSpec, pluginBuffer, { checksum = true, project, report }) {
111
116
  const { configuration } = project;
112
117
  const vmExports = {};
113
118
  const vmModule = { exports: vmExports };
@@ -125,26 +130,8 @@ async function savePlugin(pluginSpec, pluginBuffer, { project, report }) {
125
130
  path: relativePath,
126
131
  spec: pluginSpec,
127
132
  };
128
- await core_1.Configuration.updateConfiguration(project.cwd, (current) => {
129
- const plugins = [];
130
- let hasBeenReplaced = false;
131
- for (const entry of current.plugins || []) {
132
- const userProvidedPath = typeof entry !== `string`
133
- ? entry.path
134
- : entry;
135
- const pluginPath = fslib_1.ppath.resolve(project.cwd, fslib_1.npath.toPortablePath(userProvidedPath));
136
- const { name } = core_1.miscUtils.dynamicRequire(pluginPath);
137
- if (name !== pluginName) {
138
- plugins.push(entry);
139
- }
140
- else {
141
- plugins.push(pluginMeta);
142
- hasBeenReplaced = true;
143
- }
144
- }
145
- if (!hasBeenReplaced)
146
- plugins.push(pluginMeta);
147
- return { ...current, plugins };
148
- });
133
+ if (checksum)
134
+ pluginMeta.checksum = core_2.hashUtils.makeHash(pluginBuffer);
135
+ await core_1.Configuration.addPlugin(project.cwd, [pluginMeta]);
149
136
  }
150
137
  exports.savePlugin = savePlugin;
package/lib/index.d.ts CHANGED
@@ -19,6 +19,7 @@ import InfoCommand from './commands/info';
19
19
  import YarnCommand from './commands/install';
20
20
  import LinkCommand from './commands/link';
21
21
  import NodeCommand from './commands/node';
22
+ import PluginCheckCommand from './commands/plugin/check';
22
23
  import PluginImportSourcesCommand from './commands/plugin/import/sources';
23
24
  import PluginImportCommand from './commands/plugin/import';
24
25
  import PluginListCommand from './commands/plugin/list';
@@ -58,6 +59,7 @@ export { YarnCommand };
58
59
  export { LinkCommand };
59
60
  export { NodeCommand };
60
61
  export { PluginImportSourcesCommand };
62
+ export { PluginCheckCommand };
61
63
  export { PluginImportCommand };
62
64
  export { PluginListCommand };
63
65
  export { PluginRemoveCommand };
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.suggestUtils = exports.dedupeUtils = exports.WorkspaceCommand = exports.WorkspacesListCommand = exports.WhyCommand = exports.UpCommand = exports.UnlinkCommand = exports.SetVersionCommand = exports.SetVersionSourcesCommand = exports.SetResolutionCommand = exports.RunCommand = exports.RunIndexCommand = exports.RemoveCommand = exports.RebuildCommand = exports.PluginRuntimeCommand = exports.PluginRemoveCommand = exports.PluginListCommand = exports.PluginImportCommand = exports.PluginImportSourcesCommand = exports.NodeCommand = exports.LinkCommand = exports.YarnCommand = exports.InfoCommand = exports.ExplainCommand = exports.ExplainPeerRequirementsCommand = exports.ExecCommand = exports.VersionCommand = exports.EntryCommand = exports.HelpCommand = exports.ClipanionCommand = exports.DedupeCommand = exports.ConfigCommand = exports.ConfigUnsetCommand = exports.ConfigSetCommand = exports.ConfigGetCommand = exports.CacheCleanCommand = exports.BinCommand = exports.AddCommand = void 0;
3
+ exports.suggestUtils = exports.dedupeUtils = exports.WorkspaceCommand = exports.WorkspacesListCommand = exports.WhyCommand = exports.UpCommand = exports.UnlinkCommand = exports.SetVersionCommand = exports.SetVersionSourcesCommand = exports.SetResolutionCommand = exports.RunCommand = exports.RunIndexCommand = exports.RemoveCommand = exports.RebuildCommand = exports.PluginRuntimeCommand = exports.PluginRemoveCommand = exports.PluginListCommand = exports.PluginImportCommand = exports.PluginCheckCommand = exports.PluginImportSourcesCommand = exports.NodeCommand = exports.LinkCommand = exports.YarnCommand = exports.InfoCommand = exports.ExplainCommand = exports.ExplainPeerRequirementsCommand = exports.ExecCommand = exports.VersionCommand = exports.EntryCommand = exports.HelpCommand = exports.ClipanionCommand = exports.DedupeCommand = exports.ConfigCommand = exports.ConfigUnsetCommand = exports.ConfigSetCommand = exports.ConfigGetCommand = exports.CacheCleanCommand = exports.BinCommand = exports.AddCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@yarnpkg/core");
6
6
  const ci_info_1 = require("ci-info");
@@ -42,6 +42,8 @@ const link_1 = tslib_1.__importDefault(require("./commands/link"));
42
42
  exports.LinkCommand = link_1.default;
43
43
  const node_1 = tslib_1.__importDefault(require("./commands/node"));
44
44
  exports.NodeCommand = node_1.default;
45
+ const check_1 = tslib_1.__importDefault(require("./commands/plugin/check"));
46
+ exports.PluginCheckCommand = check_1.default;
45
47
  const sources_1 = tslib_1.__importDefault(require("./commands/plugin/import/sources"));
46
48
  exports.PluginImportSourcesCommand = sources_1.default;
47
49
  const import_1 = tslib_1.__importDefault(require("./commands/plugin/import"));
@@ -124,6 +126,7 @@ const plugin = {
124
126
  link_1.default,
125
127
  unlink_1.default,
126
128
  node_1.default,
129
+ check_1.default,
127
130
  sources_1.default,
128
131
  import_1.default,
129
132
  remove_1.default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarnpkg/plugin-essentials",
3
- "version": "4.0.0-rc.25",
3
+ "version": "4.0.0-rc.26",
4
4
  "stableVersion": "3.2.3",
5
5
  "license": "BSD-2-Clause",
6
6
  "main": "./lib/index.js",
@@ -9,8 +9,8 @@
9
9
  "./package.json": "./package.json"
10
10
  },
11
11
  "dependencies": {
12
- "@yarnpkg/fslib": "^3.0.0-rc.25",
13
- "@yarnpkg/parsers": "^3.0.0-rc.25",
12
+ "@yarnpkg/fslib": "^3.0.0-rc.26",
13
+ "@yarnpkg/parsers": "^3.0.0-rc.26",
14
14
  "ci-info": "^3.2.0",
15
15
  "clipanion": "^3.2.0-rc.10",
16
16
  "enquirer": "^2.3.6",
@@ -21,17 +21,17 @@
21
21
  "typanion": "^3.3.0"
22
22
  },
23
23
  "peerDependencies": {
24
- "@yarnpkg/cli": "^4.0.0-rc.25",
25
- "@yarnpkg/core": "^4.0.0-rc.25",
26
- "@yarnpkg/plugin-git": "^3.0.0-rc.25"
24
+ "@yarnpkg/cli": "^4.0.0-rc.26",
25
+ "@yarnpkg/core": "^4.0.0-rc.26",
26
+ "@yarnpkg/plugin-git": "^3.0.0-rc.26"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/lodash": "^4.14.136",
30
30
  "@types/micromatch": "^4.0.1",
31
31
  "@types/semver": "^7.1.0",
32
- "@yarnpkg/cli": "^4.0.0-rc.25",
33
- "@yarnpkg/core": "^4.0.0-rc.25",
34
- "@yarnpkg/plugin-git": "^3.0.0-rc.25"
32
+ "@yarnpkg/cli": "^4.0.0-rc.26",
33
+ "@yarnpkg/core": "^4.0.0-rc.26",
34
+ "@yarnpkg/plugin-git": "^3.0.0-rc.26"
35
35
  },
36
36
  "repository": {
37
37
  "type": "git",