@vltpkg/cli-sdk 1.0.0-rc.30 → 1.0.0-rc.32

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.
@@ -133,6 +133,7 @@ const listTokens = async (rc, registry, identity, alias) => {
133
133
  export const command = async (conf) => {
134
134
  const reg = normalizeRegistryKey(conf.options.registry);
135
135
  switch (conf.positionals[0]) {
136
+ case 'ls':
136
137
  case 'list': {
137
138
  const rc = new RegistryClient(conf.options);
138
139
  const identity = conf.options.identity;
@@ -171,6 +172,7 @@ export const command = async (conf) => {
171
172
  await setToken(reg, `Bearer ${await readPassword('Paste bearer token: ')}`, conf.options.identity);
172
173
  break;
173
174
  }
175
+ case 'remove':
174
176
  case 'rm': {
175
177
  await deleteToken(reg, conf.options.identity);
176
178
  break;
@@ -178,7 +180,7 @@ export const command = async (conf) => {
178
180
  default: {
179
181
  throw error('Invalid token subcommand', {
180
182
  found: conf.positionals[0],
181
- validOptions: ['list', 'add', 'rm'],
183
+ validOptions: ['list', 'ls', 'add', 'rm', 'remove'],
182
184
  code: 'EUSAGE',
183
185
  });
184
186
  }
@@ -1,6 +1,7 @@
1
1
  import { asDependency } from '@vltpkg/graph';
2
- import { joinDepIDTuple } from '@vltpkg/dep-id';
2
+ import { joinDepIDTuple, splitDepID } from '@vltpkg/dep-id';
3
3
  import { Spec } from '@vltpkg/spec';
4
+ import { isAbsolute, relative, resolve } from 'node:path';
4
5
  const rootDepID = joinDepIDTuple(['file', '.']);
5
6
  /**
6
7
  * Compute a DepID for the current working directory relative to the project
@@ -45,6 +46,36 @@ class AddImportersDependenciesMapImpl extends Map {
45
46
  class RemoveImportersDependenciesMapImpl extends Map {
46
47
  modifiedDependencies = false;
47
48
  }
49
+ /**
50
+ * Rebase a file: spec's relative path from process.cwd() to the
51
+ * importer's location. CLI positional args are relative to cwd,
52
+ * but the graph resolver resolves file: paths relative to the
53
+ * importer node's location. When these differ (e.g. `-w` flag),
54
+ * the path must be rebased.
55
+ *
56
+ * Also detects when the target path is a workspace and converts
57
+ * the spec to `workspace:*`.
58
+ */
59
+ const rebaseFileSpec = (spec, importerPath, scurryCwd, specOptions, monorepo) => {
60
+ if (spec.type !== 'file' || !spec.file || isAbsolute(spec.file)) {
61
+ return spec;
62
+ }
63
+ const targetAbs = resolve(process.cwd(), spec.file);
64
+ if (monorepo) {
65
+ for (const ws of monorepo.values()) {
66
+ if (ws.fullpath === targetAbs) {
67
+ return Spec.parse(ws.name, 'workspace:*', specOptions);
68
+ }
69
+ }
70
+ }
71
+ const importerAbs = resolve(scurryCwd, importerPath);
72
+ const rebasedPath = relative(importerAbs, targetAbs)
73
+ .split('\\')
74
+ .join('/');
75
+ if (rebasedPath === spec.file)
76
+ return spec;
77
+ return Spec.parseArgs(rebasedPath, specOptions);
78
+ };
48
79
  /**
49
80
  * Parses the positional arguments into {@link AddImportersDependenciesMap}.
50
81
  */
@@ -53,7 +84,6 @@ export const parseAddArgs = (config, scurry, monorepo) => {
53
84
  const items = config.positionals;
54
85
  const type = getType(config.values);
55
86
  const importers = getWorkspaceImporters(config.values, monorepo);
56
- const newDependencies = new Map();
57
87
  const specOptions = config.options;
58
88
  // nameless spec definitions will need to use their full
59
89
  // stringified spec result instead of their name in order
@@ -61,21 +91,45 @@ export const parseAddArgs = (config, scurry, monorepo) => {
61
91
  const getName = (s) => s.name === '(unknown)' ? s.spec : s.name;
62
92
  // parses each positional argument into a Spec and
63
93
  // adds it to the new dependencies Map
94
+ const parsedItems = [];
95
+ let hasFileSpecs = false;
64
96
  for (const item of items) {
65
97
  const spec = Spec.parseArgs(item, specOptions);
66
- newDependencies.set(getName(spec), asDependency({ spec, type }));
98
+ parsedItems.push({ spec, type });
99
+ if (spec.type === 'file')
100
+ hasFileSpecs = true;
67
101
  add.modifiedDependencies = true;
68
102
  }
69
103
  // assigns the new dependencies to each selected workspace importer
70
- for (const importer of importers) {
71
- add.set(importer, newDependencies);
104
+ // file: specs need per-importer rebasing since CLI paths are relative
105
+ // to process.cwd() but get resolved relative to the importer's location
106
+ if (hasFileSpecs && importers.size) {
107
+ const scurryCwd = scurry.cwd.fullpath();
108
+ for (const importer of importers) {
109
+ const [, importerPath] = splitDepID(importer);
110
+ const importerDeps = new Map();
111
+ for (const { spec, type: depType } of parsedItems) {
112
+ const rebased = rebaseFileSpec(spec, importerPath, scurryCwd, specOptions, monorepo);
113
+ importerDeps.set(getName(rebased), asDependency({ spec: rebased, type: depType }));
114
+ }
115
+ add.set(importer, importerDeps);
116
+ }
72
117
  }
73
- // if no workspaces were selected, default to the cwd importer which
74
- // can be either the root or a nested folder in case the user is installing
75
- // from a subfolder that is also a file: type dependency
76
- if (!importers.size) {
77
- const cwdDepID = getCwdDepID(scurry);
78
- add.set(cwdDepID, newDependencies);
118
+ else {
119
+ const newDependencies = new Map();
120
+ for (const { spec, type: depType } of parsedItems) {
121
+ newDependencies.set(getName(spec), asDependency({ spec, type: depType }));
122
+ }
123
+ for (const importer of importers) {
124
+ add.set(importer, newDependencies);
125
+ }
126
+ // if no workspaces were selected, default to the cwd importer which
127
+ // can be either the root or a nested folder in case the user is installing
128
+ // from a subfolder that is also a file: type dependency
129
+ if (!importers.size) {
130
+ const cwdDepID = getCwdDepID(scurry);
131
+ add.set(cwdDepID, newDependencies);
132
+ }
79
133
  }
80
134
  return {
81
135
  add,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/cli-sdk",
3
3
  "description": "The source for the vlt CLI",
4
- "version": "1.0.0-rc.30",
4
+ "version": "1.0.0-rc.32",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -14,30 +14,30 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@resvg/resvg-wasm": "^2.6.2",
17
- "@vltpkg/config": "1.0.0-rc.30",
18
- "@vltpkg/dep-id": "1.0.0-rc.30",
19
- "@vltpkg/dot-prop": "1.0.0-rc.30",
20
- "@vltpkg/error-cause": "1.0.0-rc.30",
21
- "@vltpkg/git": "1.0.0-rc.30",
22
- "@vltpkg/graph": "1.0.0-rc.30",
23
- "@vltpkg/graph-run": "1.0.0-rc.30",
24
- "@vltpkg/init": "1.0.0-rc.30",
25
- "@vltpkg/output": "1.0.0-rc.30",
26
- "@vltpkg/package-info": "1.0.0-rc.30",
27
- "@vltpkg/package-json": "1.0.0-rc.30",
28
- "@vltpkg/promise-spawn": "1.0.0-rc.30",
29
- "@vltpkg/query": "1.0.0-rc.30",
30
- "@vltpkg/registry-client": "1.0.0-rc.30",
31
- "@vltpkg/rollback-remove": "1.0.0-rc.30",
32
- "@vltpkg/run": "1.0.0-rc.30",
33
- "@vltpkg/security-archive": "1.0.0-rc.30",
34
- "@vltpkg/spec": "1.0.0-rc.30",
35
- "@vltpkg/types": "1.0.0-rc.30",
36
- "@vltpkg/url-open": "1.0.0-rc.30",
37
- "@vltpkg/vlt-json": "1.0.0-rc.30",
38
- "@vltpkg/vlx": "1.0.0-rc.30",
39
- "@vltpkg/workspaces": "1.0.0-rc.30",
40
- "@vltpkg/xdg": "1.0.0-rc.30",
17
+ "@vltpkg/config": "1.0.0-rc.32",
18
+ "@vltpkg/dep-id": "1.0.0-rc.32",
19
+ "@vltpkg/dot-prop": "1.0.0-rc.32",
20
+ "@vltpkg/error-cause": "1.0.0-rc.32",
21
+ "@vltpkg/git": "1.0.0-rc.32",
22
+ "@vltpkg/graph": "1.0.0-rc.32",
23
+ "@vltpkg/graph-run": "1.0.0-rc.32",
24
+ "@vltpkg/init": "1.0.0-rc.32",
25
+ "@vltpkg/output": "1.0.0-rc.32",
26
+ "@vltpkg/package-info": "1.0.0-rc.32",
27
+ "@vltpkg/package-json": "1.0.0-rc.32",
28
+ "@vltpkg/promise-spawn": "1.0.0-rc.32",
29
+ "@vltpkg/query": "1.0.0-rc.32",
30
+ "@vltpkg/registry-client": "1.0.0-rc.32",
31
+ "@vltpkg/rollback-remove": "1.0.0-rc.32",
32
+ "@vltpkg/run": "1.0.0-rc.32",
33
+ "@vltpkg/security-archive": "1.0.0-rc.32",
34
+ "@vltpkg/spec": "1.0.0-rc.32",
35
+ "@vltpkg/types": "1.0.0-rc.32",
36
+ "@vltpkg/url-open": "1.0.0-rc.32",
37
+ "@vltpkg/vlt-json": "1.0.0-rc.32",
38
+ "@vltpkg/vlx": "1.0.0-rc.32",
39
+ "@vltpkg/workspaces": "1.0.0-rc.32",
40
+ "@vltpkg/xdg": "1.0.0-rc.32",
41
41
  "ansi-to-pre": "^1.0.6",
42
42
  "beautiful-mermaid": "^1.1.3",
43
43
  "chalk": "^5.6.2",