@vltpkg/spec 0.0.0-0.1730239248325

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 ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (c) vlt technology, Inc.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
+ Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
8
+
9
+ (a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
10
+ (b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
11
+ Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
12
+
13
+ DISCLAIMER
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # `@vltpkg/spec`
2
+
3
+ This is a library for parsing **package specifiers**.
4
+
5
+ Specifiers are primarily used in the following cases:
6
+
7
+ - On the command line, like `vlt add foo@1.x`
8
+ - In manifests (such as `package.json`) where dependencies are
9
+ listed, like `"dependencies": { "foo": "1.x" }`
10
+ - Internally within vlt, such as lockfiles and so on.
11
+
12
+ ## Named vs Unnamed
13
+
14
+ A "named" specifier is one with the full name included, separated
15
+ from the specifier by a `@` character, such as
16
+ `foo@1.x` or `@vltpkg/spec@1.0.0`. The `name` in these cases
17
+ would be `foo` and `@vltpkg/spec`, respectively.
18
+
19
+ Note that it does _not_ always correspond to the `"name"` in the
20
+ manifest of the resolved package! For example,
21
+ `foo@npm:react@latest` would resolve to the latest version of
22
+ `react`, but would be named `foo` in the dependency graph, and
23
+ loaded as `import('foo')`.
24
+
25
+ ## Types of Specifiers
26
+
27
+ The following specifier types are supported:
28
+
29
+ - `workspace:...` - Provide a semver range, or one of `~`, `*`,
30
+ or `^` to match against a dependency that exists in a workspace
31
+ project of a monorepo. The package name _must_ exist as a
32
+ workspace project in the monorepo. If a semver range is
33
+ provided, then it must match the referenced workspace package
34
+ version. Otherwise:
35
+
36
+ - `*` - Fill in whatever version is in the workspace, without
37
+ any prefix. So, if `./packages/foo` depends on
38
+ `bar@workspace*`, and `bar` is version `1.2.3`, then `foo`
39
+ will be published with `{ "dependencies": { "bar": "1.2.3" }}`
40
+ - `~` or `^` - Publish with the version found in the
41
+ monorepo, prefixed by the character. So in the example
42
+ above, it'd be `bar@~1.2.3` or `bar@^1.2.3`, respectively.
43
+
44
+ - `semver range` - A valid semver range (including the empty
45
+ string or a single semver version). This is resolved against
46
+ the default registry. If the spec is a valid semver range, then
47
+ no further parsing is done.
48
+
49
+ - `git+ssh://<url>[selector]` or `git+https://<url>[selector]` -
50
+ A `git+ssh` or `git+https` url will be checked out by git. If
51
+ no 'git selector' is provided, then it will attempt to install
52
+ from the default version. The git selector can be:
53
+
54
+ - `#committish` Any valid `committish` value will be checked
55
+ out. So, shasum, branch, tag, etc., would all work.
56
+ - `#semver:<range>` If a semver range is provided, it will
57
+ select over all the tags that are valid semver versions, and
58
+ pick the highest version number that satisfies the range.
59
+ - Additional fields can be specified by a `::`-separated series
60
+ of `key:value` pairs. Currently only `path:<path in repo>` is
61
+ supported, for referencing packages living below the root of
62
+ the repository, as in a monorepo. For example,
63
+ `tcompare@github:tapjs/tapjs#bf457f24::path:src/tcompare`
64
+
65
+ - `https://some-host.com/path/to/file.tgz` - An https or http URL
66
+ to a tarball will resolve to itself.
67
+
68
+ - `file:///path/to/file` - A file URL will resolve to itself. If
69
+ it is a directory, it will be reified as a symbolic link to the
70
+ folder specified. If it is a file, it will be treated as a
71
+ tarball that gets unpacked into place. Relative paths are
72
+ resolved from the package with the dependency.
73
+
74
+ - `registry:<registry url>#<name>[@version range or dist-tag]` -
75
+ This will use the specified registry url, and look up the name
76
+ and version on that registry.
77
+
78
+ - If a registry shorthand is defined in the options, then you can
79
+ use it as an alias for that registry. Currently, the only
80
+ shorthand that is enabled by default is
81
+ `npm:<name>[@version-range]` as a shorthand for
82
+ `registry:https://registry.npmjs.org/#<name>[@version-range]`.
83
+
84
+ - If a git repository shorthand is defined in the options, then
85
+ you can use that shorthand prefix as an alias for that git
86
+ host. Currently, `github:`, `bitbucket:`, `gitlab:`, and
87
+ `gist:` are supported by default.
88
+
89
+ - Anything else will be treated as a `dist-tag` in the registry
90
+ packument. For example, `foo@latest` or `blah@legacy-v2`
91
+
92
+ ## USAGE
93
+
94
+ ```js
95
+ import { Spec, type SpecOptions } from '@vltpkg/spec'
96
+
97
+ // optional: create some registry shorthands
98
+ const opts: SpecOptions = {
99
+ registries: {
100
+ // internal company registry or something
101
+ acmereg: 'https://dev.acme.internal/npm',
102
+ },
103
+ gitHosts: {
104
+ github: 'git+ssh://git@github.com:$1/$2',
105
+ // the $# pieces here are replaced by the path-separated
106
+ // portions, so eg `github:user/project#whatever
107
+ acmegit: 'git+ssh://git@dev.acme.internal/git/$1/$2/$3',
108
+ }
109
+ }
110
+
111
+ const lodash = Spec.parse('lodash@latest')
112
+ // which is the same as:
113
+ const lodash = Spec.parse('lodash@npm:lodash@latest')
114
+ // which is the same as:
115
+ const lodash = Spec.parse(
116
+ 'lodash@registry:https://registry.npmjs.org/#lodash@latest'
117
+ )
118
+
119
+ // pull from github
120
+ const ghProject = Spec.parse('abbrev@github:npm/abbrev-js#main', opts)
121
+
122
+ // pull from our internal hosts using the acme shorthand names
123
+ const fooFromAcmeReg = Spec.parse('foo@acmereg:foo@1.2', opts)
124
+ const fooFromAcmeReg = Spec.parse(
125
+ 'foo@acmegit:department/team/monorepo#main;directory:packages/foo',
126
+ opts,
127
+ )
128
+ ```
129
+
130
+ ## Properties
131
+
132
+ - type - the type of spec that this is. One of `'registry'`,
133
+ `'git'`, `'file'`, or `'remote'`.
134
+ - spec - the full named specifier passed to the constructor
135
+ - options - options passed to the constructor, plus defaults
136
+ - name - the name portion, so `foo` in `foo@1.x`
137
+ - bareSpec - just the part AFTER the name, so `1.x` in `foo@1.x`
138
+ - when `type` === `'git'`:
139
+ - gitRemote - git remote url
140
+ - gitSelector - the `::`-separated set of `key:value` fields
141
+ - gitSelectorParsed - the `gitSelector` parsed into a Record
142
+ object
143
+ - gitCommittish - the commit sha, branch, or tag
144
+ - namedGitHost - `github`, `gitlab`, `bitbucket`, etc.
145
+ - remoteURL - when using a named git host with an archive url
146
+ template, and a committish is provided, this is the url to
147
+ download a tarball archive
148
+ - semver - the semver range, if provided in the gitSelector
149
+ - range - the parsed semver range, if valid
150
+ - when `type` === `'registry'`:
151
+ - registry - the registry to look up data from
152
+ - namedRegistry - in the case of alias specs, the named
153
+ registry
154
+ - registrySpec - the semver range or dist-tag
155
+ - semver - the semver range, if valid
156
+ - range - the parsed semver range, if valid
157
+ - distTag - the registrySpec when it is not a semver range
158
+ - subspec - the parsed spec to to be resolved against the
159
+ registry in question, if the spec is a named registry like
160
+ `npm:x@2.x` or an explicit registry url like
161
+ `registry:https://registry.npmjs.org#x@2.x`.
162
+ - when `type` === `'file'`:
163
+ - file - the path on disk to find the package
164
+ - when `type` === `'remote'`:
165
+ - remoteURL - the url to the remote archive
@@ -0,0 +1,113 @@
1
+ import { type Range } from '@vltpkg/semver';
2
+ export * from './types.js';
3
+ import type { GitSelectorParsed, Scope, SpecLike, SpecOptions, SpecOptionsFilled } from './types.js';
4
+ export declare const kCustomInspect: unique symbol;
5
+ export declare const defaultRegistry = "https://registry.npmjs.org/";
6
+ export declare const defaultRegistries: {
7
+ npm: string;
8
+ };
9
+ export declare const defaultGitHosts: {
10
+ github: string;
11
+ bitbucket: string;
12
+ gitlab: string;
13
+ gist: string;
14
+ };
15
+ export declare const defaultGitHostArchives: {
16
+ github: string;
17
+ bitbucket: string;
18
+ gist: string;
19
+ gitlab: string;
20
+ };
21
+ /**
22
+ * These are just for legacy support of urls that are supported by npm
23
+ * and observed in the wild.
24
+ *
25
+ * Not configurable, because no more will be added. If you wish to define
26
+ * custom git hosts, use it with the `'git-hosts'` and `'git-host-archives'`
27
+ * options.
28
+ */
29
+ export declare const gitHostWebsites: {
30
+ github: string;
31
+ bitbucket: string;
32
+ gist: string;
33
+ gitlab: string;
34
+ };
35
+ export declare const defaultScopeRegistries: {};
36
+ export declare const getOptions: (options?: SpecOptions) => SpecOptionsFilled;
37
+ /**
38
+ * Injects the Node.js dependencies into the Spec class.
39
+ */
40
+ export type NodeJSDependenciesOptions = {
41
+ homedir: typeof import('os').homedir;
42
+ isAbsolute: typeof import('node:path').isAbsolute;
43
+ join: typeof import('node:path').join;
44
+ resolve: typeof import('node:path').resolve;
45
+ winPath: typeof import('node:path').win32;
46
+ };
47
+ /**
48
+ * The base, isomorphic Spec implementation.
49
+ */
50
+ export declare class Spec implements SpecLike<Spec> {
51
+ #private;
52
+ /**
53
+ * Create a Spec object from a full spec, name+bareSpec, or Spec object
54
+ *
55
+ * Note: If a Spec object is provided, it is returned as-is, without
56
+ * investigating whether the options match.
57
+ */
58
+ static parse(name: string, bareSpec: string, options?: SpecOptions): Spec;
59
+ static parse(spec: string, options?: SpecOptions): Spec;
60
+ static parse(spec: Spec, options?: SpecOptions): Spec;
61
+ static parseArgs(specOrBareSpec: string, opts?: SpecOptions): Spec;
62
+ static nodejsDependencies?: NodeJSDependenciesOptions;
63
+ type: 'file' | 'git' | 'registry' | 'remote' | 'workspace';
64
+ spec: string;
65
+ options: SpecOptionsFilled;
66
+ name: string;
67
+ scope?: Scope;
68
+ scopeRegistry?: string;
69
+ bareSpec: string;
70
+ gitRemote?: string;
71
+ gitSelector?: string;
72
+ gitSelectorParsed?: GitSelectorParsed;
73
+ gitCommittish?: string;
74
+ namedGitHost?: string;
75
+ namedGitHostPath?: string;
76
+ workspaceSpec?: string;
77
+ workspace?: string;
78
+ namedRegistry?: string;
79
+ registry?: string;
80
+ registrySpec?: string;
81
+ conventionalRegistryTarball?: string;
82
+ semver?: string;
83
+ range?: Range;
84
+ distTag?: string;
85
+ remoteURL?: string;
86
+ file?: string;
87
+ subspec?: Spec;
88
+ /**
89
+ * Return the final entry in the chain of subspecs
90
+ * When deciding which thing to actually fetch, spec.final is the thing
91
+ * to look at.
92
+ */
93
+ get final(): Spec;
94
+ /**
95
+ * Normally, the string value of a Spec is just the string passed in to
96
+ * be parsed. However, in the case of a chain of subspecs, like
97
+ * `foo@npm:bar@npm:baz@npm:quux@latest`, this simplifies out the middle
98
+ * parts of the chain, returning just `foo@npm:quux@latest`
99
+ */
100
+ toString(): string;
101
+ ['constructor']: typeof Spec;
102
+ constructor(name: string, bareSpec: string, options?: SpecOptions);
103
+ constructor(spec: string, options?: SpecOptions);
104
+ constructor(spec: Spec | string, bareOrOptions?: SpecOptions | string, options?: SpecOptions);
105
+ [kCustomInspect](): string;
106
+ /**
107
+ * Should only ever be called with the bit that comes AFTER the #
108
+ * in the git remote url.
109
+ */
110
+ static parseGitSelector(selector: string, spec?: Spec): [parsed: GitSelectorParsed, committish?: string, range?: Range];
111
+ }
112
+ export declare const getNormalizeFile: (opts?: NodeJSDependenciesOptions) => (bareSpec: string, spec: Spec) => [path: string, uri: string];
113
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACvD,cAAc,YAAY,CAAA;AAC1B,OAAO,KAAK,EACV,iBAAiB,EACjB,KAAK,EACL,QAAQ,EACR,WAAW,EACX,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,cAAc,eAA2C,CAAA;AAEtE,eAAO,MAAM,eAAe,gCAAgC,CAAA;AAE5D,eAAO,MAAM,iBAAiB;;CAE7B,CAAA;AAED,eAAO,MAAM,eAAe;;;;;CAK3B,CAAA;AAED,eAAO,MAAM,sBAAsB;;;;;CAMlC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;;;;;CAK3B,CAAA;AAED,eAAO,MAAM,sBAAsB,IAAK,CAAA;AAExC,eAAO,MAAM,UAAU,aACX,WAAW,KACpB,iBAyBD,CAAA;AAsDF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,cAAc,IAAI,EAAE,OAAO,CAAA;IACpC,UAAU,EAAE,cAAc,WAAW,EAAE,UAAU,CAAA;IACjD,IAAI,EAAE,cAAc,WAAW,EAAE,IAAI,CAAA;IACrC,OAAO,EAAE,cA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