@plotdb/registry 0.0.9 → 0.0.11
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/CHANGELOG.md +41 -0
- package/README.md +102 -5
- package/config.ngx +1 -1
- package/designate.js +60 -0
- package/index.js +5 -2
- package/ngxgen.js +1 -0
- package/package.json +1 -1
- package/provider.js +175 -29
- package/providers/github.js +1 -0
- package/providers/index.js +1 -0
- package/providers/npm.js +1 -0
- package/route.js +18 -9
- package/unbox.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.11
|
|
4
|
+
|
|
5
|
+
- bug fix:
|
|
6
|
+
- ngx config: the `internal` location ( target of `X-Accel-Redirect` ) was missing the
|
|
7
|
+
`pub` prefix in its `index.min.js` fallback -- it resolved to `<root>/<pkg>/index.min.js`
|
|
8
|
+
instead of `<root>/<pub>/<pkg>/index.min.js`, so that fallback never matched. a package
|
|
9
|
+
whose entry is only `index.min.js` ( no `index.js` / `index.html` ) 404'd on the request
|
|
10
|
+
that triggered the fetch, then succeeded on the next one ( served by the `pub` location,
|
|
11
|
+
whose fallback was already correct ) -- an intermittent first-hit 404. the two locations
|
|
12
|
+
now use the same three fallbacks.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## v0.0.10
|
|
16
|
+
|
|
17
|
+
- features:
|
|
18
|
+
- split `main` / `latest` semantics ( previously aliases ):
|
|
19
|
+
- `latest` always tracks the upstream newest ( npm dist-tag convention ) and is
|
|
20
|
+
302-redirect-resolved like ranges -- never materialized on disk. resolution cached
|
|
21
|
+
per provider in `<pkg>/.reg.latest.<provider>` with cachetime expiry.
|
|
22
|
+
- `main` is the admin-designated version: a symlink pointing at a specific version
|
|
23
|
+
dir, served from disk with no redirect hop. frozen until an admin decision --
|
|
24
|
+
`force` fetch re-designates to upstream latest ( existing flush routes keep working
|
|
25
|
+
unchanged ), `designate` pins a chosen version. first touch auto-designates to
|
|
26
|
+
the latest at that moment.
|
|
27
|
+
- add `provider.designate` and a `registry.designate` admin route factory
|
|
28
|
+
( recommended mount: `/staff/registry/designate/*`, aligned with
|
|
29
|
+
`/staff/registry/flush/*` ).
|
|
30
|
+
- protect manually-placed `main`: a preinstalled real dir or a manual symlink
|
|
31
|
+
( e.g. pointing at a dev working copy ) is never touched by normal requests, and a
|
|
32
|
+
symlink's target is never deleted -- force / designate only replaces the link itself.
|
|
33
|
+
- tweaks:
|
|
34
|
+
- `main` / `latest` no longer create `.reg.404` marker files; negative results are
|
|
35
|
+
absorbed by the nginx proxy cache instead.
|
|
36
|
+
- dev ( no-nginx ) behavior of `main` now matches production: frozen, no TTL refetch.
|
|
37
|
+
- doc:
|
|
38
|
+
- add "Caching Model" section in README: cache layers, version-type behaviors,
|
|
39
|
+
query-string ( cachestamp ) reach, and deliberate choices ( headerless 302,
|
|
40
|
+
Set-Cookie handling, chain-order resolution ). all claims verified against
|
|
41
|
+
a local nginx + backend setup.
|
|
42
|
+
|
|
43
|
+
|
|
3
44
|
## v0.0.9
|
|
4
45
|
|
|
5
46
|
- features:
|
package/README.md
CHANGED
|
@@ -75,6 +75,92 @@ where the config file ( `myconfig.yaml` above ) should contains following fields
|
|
|
75
75
|
Check `sample/config.ngx` and `sample/config.yaml` for a reference of nginx config file and corresponding config yaml.
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
### Admin Routes
|
|
79
|
+
|
|
80
|
+
Two admin operations are expected, mounted under a guarded prefix
|
|
81
|
+
( recommended naming: `/staff/registry/<operation>/` ):
|
|
82
|
+
|
|
83
|
+
# flush: force re-fetch. for `main`, this re-designates to the upstream latest.
|
|
84
|
+
app.get("/staff/registry/flush/*", isAdmin, registry.route({
|
|
85
|
+
provider: myprovider,
|
|
86
|
+
opt: function() { return {force: true}; },
|
|
87
|
+
root: {pub: "/staff/registry/flush/", fs: "...", internal: "/ilib/"}
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
# designate: pin `main` of a package to a chosen version.
|
|
91
|
+
# url format: <name>/<version>; trailing path segments are ignored,
|
|
92
|
+
# so a public asset url can be pasted with only the prefix swapped.
|
|
93
|
+
app.get("/staff/registry/designate/*", isAdmin, registry.designate({
|
|
94
|
+
provider: myprovider,
|
|
95
|
+
root: {pub: "/staff/registry/designate/", fs: "..."}
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
## Caching Model
|
|
100
|
+
|
|
101
|
+
Four cache layers are involved when serving a package file. From the client inward:
|
|
102
|
+
|
|
103
|
+
1. **browser cache**: keyed by full URL including query string.
|
|
104
|
+
2. **nginx `proxy_cache`**: caches backend responses ( 200 / 302 / 400 / 404, for `cache.period` ).
|
|
105
|
+
the default `proxy_cache_key` includes `$request_uri`, **query string included**.
|
|
106
|
+
3. **nginx `try_files` ( disk )**: files materialized under `fs` root are served directly;
|
|
107
|
+
matching is done on `$uri`, **query string excluded**. requests never reach the backend
|
|
108
|
+
once the file exists on disk.
|
|
109
|
+
4. **registry backend internal caches**: version-list cache ( `.reg.versions.<provider>` ),
|
|
110
|
+
negative cache ( `.reg.404` ) and `main` staleness check, all expired by
|
|
111
|
+
file mtime + `cachetime`. the backend strips query strings entirely.
|
|
112
|
+
|
|
113
|
+
How each version type travels through these layers:
|
|
114
|
+
|
|
115
|
+
- **specific version** ( `1.2.3` ): immutable by definition. the first request falls through
|
|
116
|
+
to the backend, which downloads and unpacks the package, then replies with
|
|
117
|
+
`X-Accel-Redirect`; every later request is served from disk by `try_files` ( layer 3 )
|
|
118
|
+
without touching the backend. this is correct exactly because the content never changes.
|
|
119
|
+
- **range version** ( `~1.2.3` / `^1.2.3`, `^` arrives url-encoded as `%5E` ): never
|
|
120
|
+
materialized on disk, so `try_files` always misses and the request reaches the backend,
|
|
121
|
+
which 302-redirects to the resolved specific version. effective staleness bound for
|
|
122
|
+
seeing a newly released version = `cache.period` ( layer 2, caches the 302 )
|
|
123
|
+
+ `cachetime` ( layer 4, caches the version list ).
|
|
124
|
+
- **`latest`**: always tracks the upstream newest ( github latest release / npm dist-tag
|
|
125
|
+
`latest` -- the keyword follows the npm dist-tag convention ). handled exactly like a
|
|
126
|
+
range: never on disk, 302-redirected, same staleness bound.
|
|
127
|
+
- **`main`**: the admin-designated version, kept as a **symlink** pointing at a specific
|
|
128
|
+
version dir, served from disk by layer 3 ( no redirect hop ). frozen semantics: nothing
|
|
129
|
+
updates `main` automatically -- not on requests, not on upstream releases. it changes only
|
|
130
|
+
through a `force` fetch ( re-designate to upstream latest, e.g. an admin flush route ),
|
|
131
|
+
an explicit `designate` call ( pin to a chosen version ), or manual placement:
|
|
132
|
+
a real ( non-symlink ) dir at `main` is treated as preinstalled and never touched by
|
|
133
|
+
normal requests; a manual symlink ( e.g. pointing at a dev working copy ) likewise
|
|
134
|
+
survives everything except an explicit force / designate, and even then only the link
|
|
135
|
+
is replaced -- its target is never deleted. first touch of a package with nothing at
|
|
136
|
+
`main` auto-designates to the upstream latest at that moment.
|
|
137
|
+
|
|
138
|
+
Query-string cache busting ( e.g. a `cachestamp` param ) therefore only goes so deep:
|
|
139
|
+
it always busts layer 1 and layer 2 ( new query = new cache key, the request reaches the
|
|
140
|
+
backend ), but never layer 3 ( disk files, including `main` ) nor layer 4 ( backend TTLs ).
|
|
141
|
+
a bumped cachestamp on a range URL yields a fresh 302, but the resolved version may still
|
|
142
|
+
come from the version-list cache until `cachetime` expires.
|
|
143
|
+
|
|
144
|
+
Some deliberate choices worth knowing before changing them:
|
|
145
|
+
|
|
146
|
+
- **the 302 carries no cache headers on purpose.** browsers do not cache a redirect
|
|
147
|
+
without freshness info ( heuristic caching needs `Last-Modified`, which we do not send ),
|
|
148
|
+
so clients re-request the range URL every time, while nginx still absorbs the load via
|
|
149
|
+
`proxy_cache_valid`. do NOT add `Cache-Control: no-cache` to make browser behavior
|
|
150
|
+
"explicit": upstream `Cache-Control` overrides `proxy_cache_valid`, which would disable
|
|
151
|
+
the nginx 302 cache as well ( unless you also add `proxy_ignore_headers Cache-Control` ).
|
|
152
|
+
- **`Set-Cookie` must be ignored and hidden in the backend proxy location.** session
|
|
153
|
+
middleware sets a cookie on every response, which by default prevents nginx from caching
|
|
154
|
+
anything at all. the generated config includes `proxy_ignore_headers Set-Cookie` +
|
|
155
|
+
`proxy_hide_header Set-Cookie`; the latter is required, otherwise a cached response
|
|
156
|
+
would replay one user's session cookie to other users.
|
|
157
|
+
- **range resolution follows chain order, not the union of providers.** the first provider
|
|
158
|
+
with any satisfying version wins ( consistent with how `fetch` falls through on 404 ).
|
|
159
|
+
if a package has github releases, github is the source of truth for ranges: a newer
|
|
160
|
+
version published only to npm stays invisible. keep github releases and npm publishes
|
|
161
|
+
in sync for packages available on both.
|
|
162
|
+
|
|
163
|
+
|
|
78
164
|
## Registry Provider Specification
|
|
79
165
|
|
|
80
166
|
Registry providers are used to access a requested resource which is defined by its `namespace`, `name`, `version`, `path` and optionally `type`.
|
|
@@ -130,12 +216,13 @@ A provider provides following APIs:
|
|
|
130
216
|
- `opt` is an object with following fields:
|
|
131
217
|
- `root`: root directory for keeping cached files.
|
|
132
218
|
- `name`: package name. scope is possible, such as `@plotdb/block`.
|
|
133
|
-
- `version`: package version. should always in semver format (e.g., `1.0.0`) or
|
|
134
|
-
-
|
|
135
|
-
|
|
219
|
+
- `version`: package version. should always in semver format (e.g., `1.0.0`) or `main`.
|
|
220
|
+
- `main` is the designated ( locked ) version: frozen once set, updated only by
|
|
221
|
+
`force` ( re-designate to upstream latest ) or `designate()`. see "Caching Model".
|
|
136
222
|
- in github, tags is used for fetching release. tags should be in format `vx.y.z`. e.g., `v1.0.0`.
|
|
137
|
-
- range
|
|
138
|
-
to a specific version with `resolve()` first,
|
|
223
|
+
- range ( e.g. `^1.2.3` ) and `latest` versions are rejected with 400: they should be
|
|
224
|
+
resolved to a specific version with `resolve()` / `resolveLatest()` first,
|
|
225
|
+
so their dirs never land on disk.
|
|
139
226
|
- `force`: default false. when true, ignore cache / 404 status and always try fetching package again.
|
|
140
227
|
- `cachetime`: default 3600 seconds. cache for how long (in seconds) since the last fetch attempts.
|
|
141
228
|
- return value: a Promise, resolves if package is found and downloaded. reject `e` in following situation:
|
|
@@ -158,6 +245,16 @@ A provider provides following APIs:
|
|
|
158
245
|
specific version url ( `^` arrives url-encoded as `%5E`; `~` needs no encoding ),
|
|
159
246
|
so content urls stay immutable and the redirect ttl is governed by nginx
|
|
160
247
|
`proxy_cache_valid 302`.
|
|
248
|
+
- `resolveLatest(opt)`: resolve what `latest` currently means ( github latest release /
|
|
249
|
+
npm dist-tag ), walking the provider chain. results are cached per provider in
|
|
250
|
+
`<pkg>/.reg.latest.<provider>` with `cachetime` expiry. `registry.route` uses this
|
|
251
|
+
to serve `latest` urls as a 302 redirect, same as ranges.
|
|
252
|
+
- `designate(opt)`: point `main` at a specific version.
|
|
253
|
+
- `opt`: `root` / `name` / `version` ( must be specific ) / `cachetime`.
|
|
254
|
+
- ensures the version is cached ( via the provider chain ), then atomically repoints
|
|
255
|
+
the `main` symlink ( relative link, tmp + rename ). a real dir at `main`
|
|
256
|
+
( preinstalled / legacy ) is replaced only here; a symlink's target is never deleted.
|
|
257
|
+
- return value: a Promise resolving `{name, version}`.
|
|
161
258
|
- `check({name, version})`: call the `check()` function provided in constructor.
|
|
162
259
|
- `chain(providers)`: chain given `providers` in this provider.
|
|
163
260
|
- `providers`: either another provider, or a list of other providers.
|
package/config.ngx
CHANGED
package/designate.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Generated by LiveScript 1.6.0
|
|
2
|
+
(function(){
|
|
3
|
+
var pthk, lderror, designate;
|
|
4
|
+
pthk = require('pthk');
|
|
5
|
+
lderror = require('lderror');
|
|
6
|
+
designate = function(arg$){
|
|
7
|
+
var provider, root, opt;
|
|
8
|
+
provider = arg$.provider, root = arg$.root, opt = arg$.opt;
|
|
9
|
+
if (!root.pub.endsWith('/')) {
|
|
10
|
+
root.pub = root.pub + "/";
|
|
11
|
+
}
|
|
12
|
+
return function(req, res){
|
|
13
|
+
var url, id, _o;
|
|
14
|
+
url = req.originalUrl;
|
|
15
|
+
id = pthk.rectify(url.replace(root.pub, '').replace(/[#?].*$/, ''));
|
|
16
|
+
_o = !opt
|
|
17
|
+
? {}
|
|
18
|
+
: typeof opt === 'function' ? opt(req, res) : opt;
|
|
19
|
+
return Promise.resolve().then(function(){
|
|
20
|
+
var ids, ref$, name, version;
|
|
21
|
+
if (!(id && /^[-_a-zA-Z0-9@./]+$/.exec(id))) {
|
|
22
|
+
return lderror.reject(404);
|
|
23
|
+
}
|
|
24
|
+
ids = id.split('/');
|
|
25
|
+
ref$ = (ids[0] || '')[0] === '@'
|
|
26
|
+
? [ids[0] + "/" + ids[1], ids[2]]
|
|
27
|
+
: [ids[0], ids[1]], name = ref$[0], version = ref$[1];
|
|
28
|
+
if (!(name && version)) {
|
|
29
|
+
return lderror.reject(404);
|
|
30
|
+
}
|
|
31
|
+
return provider.designate(import$({
|
|
32
|
+
root: root.fs,
|
|
33
|
+
name: name,
|
|
34
|
+
version: version
|
|
35
|
+
}, _o));
|
|
36
|
+
}).then(function(arg$){
|
|
37
|
+
var name, version;
|
|
38
|
+
name = arg$.name, version = arg$.version;
|
|
39
|
+
return res.status(200).json({
|
|
40
|
+
name: name,
|
|
41
|
+
version: version
|
|
42
|
+
});
|
|
43
|
+
})['catch'](function(e){
|
|
44
|
+
var code;
|
|
45
|
+
code = lderror.id(e);
|
|
46
|
+
if (code === 400 || code === 404) {
|
|
47
|
+
return res.status(code).send();
|
|
48
|
+
}
|
|
49
|
+
console.log(e);
|
|
50
|
+
return res.status(500).send();
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
module.exports = designate;
|
|
55
|
+
function import$(obj, src){
|
|
56
|
+
var own = {}.hasOwnProperty;
|
|
57
|
+
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
|
58
|
+
return obj;
|
|
59
|
+
}
|
|
60
|
+
}).call(this);
|
package/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
// Generated by LiveScript 1.6.0
|
|
1
2
|
(function(){
|
|
2
|
-
var route, provider, providers;
|
|
3
|
+
var route, provider, providers, designate;
|
|
3
4
|
route = require('./route');
|
|
4
5
|
provider = require('./provider');
|
|
5
6
|
providers = require('./providers');
|
|
7
|
+
designate = require('./designate');
|
|
6
8
|
module.exports = {
|
|
7
9
|
route: route,
|
|
8
10
|
provider: provider,
|
|
9
|
-
providers: providers
|
|
11
|
+
providers: providers,
|
|
12
|
+
designate: designate
|
|
10
13
|
};
|
|
11
14
|
}).call(this);
|
package/ngxgen.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/registry","license":"MIT","description":"registry","version":"0.0.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/registry","license":"MIT","description":"registry","version":"0.0.11","main":"index.js","homepage":"https://github.com/plotdb/registry","repository":{"type":"git","url":"https://github.com/plotdb/registry"},"engines":{"node":">=18","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","server":"cd web; ../node_modules/.bin/lsc server.ls","build":"lsc -c -o dist src/index.ls src/route.ls src/provider.ls src/designate.ls src/unbox.ls src/ngxgen.ls && lsc -c -o dist/providers src/providers/index.ls src/providers/github.ls src/providers/npm.ls && cp src/config.ngx dist/config.ngx","test":"lsc test/index.ls"},"bin":{"registry-ngx":"./bin/ngxgen"},"dependencies":{"@plotdb/guides":"github:plotdb/guides#master","@plotdb/semver":"^0.0.4","@zbryikt/template":"^2.4.2","fs-extra":"^8.1.0","js-yaml":"^4.1.1","lderror":"^2.4.6","livescript":"^1.6.0","node-fetch":"^2.6.7","pthk":"^0.0.1","tar":"^7.5.21","template-text":"^0.2.0","yargs":"^17.6.0","yauzl":"^2.10.0"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.6","@plotdb/block":"^5.6.3","@plotdb/csscope":"^5.0.4","@plotdb/rescope":"^5.0.17","bootstrap":"^4.6.1","bootstrap.native":"^3.0.14","fedep":"^1.7.6","ldcover":"^3.5.6","ldloader":"^3.0.3","ldview":"^1.7.0","proxise":"^1.0.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["@loadingio/bootstrap.ext","@loadingio/debounce.js","@loadingio/ldquery","bootstrap","bootstrap.native","@plotdb/block","@plotdb/csscope","@plotdb/rescope","@plotdb/semver","ldcover","ldloader","ldview","proxise"]}}
|
package/provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Generated by LiveScript 1.6.0
|
|
1
2
|
(function(){
|
|
2
3
|
var nodeFetch, lderror, yauzl, pthk, tar, semver, fs, fetch, getVersionType, provider, ref$;
|
|
3
4
|
nodeFetch = require('node-fetch');
|
|
@@ -9,7 +10,9 @@
|
|
|
9
10
|
fs = require("fs-extra");
|
|
10
11
|
fetch = nodeFetch;
|
|
11
12
|
getVersionType = function(v){
|
|
12
|
-
if (v === '
|
|
13
|
+
if (v === 'main') {
|
|
14
|
+
return 'main';
|
|
15
|
+
} else if (v === 'latest') {
|
|
13
16
|
return 'latest';
|
|
14
17
|
} else if (/^\d+\.\d+\.\d+$/.test(v)) {
|
|
15
18
|
return 'specific';
|
|
@@ -55,8 +58,8 @@
|
|
|
55
58
|
if (!versionType) {
|
|
56
59
|
return lderror.reject(400, "incorrect version-type when accessing " + name + "@" + version);
|
|
57
60
|
}
|
|
58
|
-
if (versionType === 'range') {
|
|
59
|
-
return lderror.reject(400, "
|
|
61
|
+
if (versionType === 'range' || versionType === 'latest') {
|
|
62
|
+
return lderror.reject(400, versionType + " version should be resolved before fetch");
|
|
60
63
|
}
|
|
61
64
|
if ((name + "").length > 128 || (version + "").length > 40) {
|
|
62
65
|
return lderror.reject(998);
|
|
@@ -77,6 +80,9 @@
|
|
|
77
80
|
path.base.version = pthk.join(path.base.pkg, version);
|
|
78
81
|
path.version = pthk.join(path.base.version, '.reg.version');
|
|
79
82
|
path[404] = pthk.join(path.base.version, '.reg.404');
|
|
83
|
+
if (versionType === 'main') {
|
|
84
|
+
return this$._fetchMain(params);
|
|
85
|
+
}
|
|
80
86
|
_ = function(idx){
|
|
81
87
|
var pr, p;
|
|
82
88
|
idx == null && (idx = -1);
|
|
@@ -139,6 +145,172 @@
|
|
|
139
145
|
return this._ps.splice.apply(this._ps, [0, 0].concat(Array.isArray(ps)
|
|
140
146
|
? ps
|
|
141
147
|
: [ps]));
|
|
148
|
+
}, ref$._fetchMain = function(arg$){
|
|
149
|
+
var root, name, version, force, cachetime, path, this$ = this;
|
|
150
|
+
root = arg$.root, name = arg$.name, version = arg$.version, force = arg$.force, cachetime = arg$.cachetime, path = arg$.path;
|
|
151
|
+
return Promise.resolve().then(function(){
|
|
152
|
+
return fs.lstat(path.base.version)['catch'](function(){
|
|
153
|
+
return null;
|
|
154
|
+
});
|
|
155
|
+
}).then(function(s){
|
|
156
|
+
if (s && !force) {
|
|
157
|
+
return lderror.reject(998);
|
|
158
|
+
}
|
|
159
|
+
return this$.resolveLatest({
|
|
160
|
+
root: root,
|
|
161
|
+
name: name,
|
|
162
|
+
cachetime: cachetime,
|
|
163
|
+
force: force
|
|
164
|
+
}).then(function(v){
|
|
165
|
+
return this$.designate({
|
|
166
|
+
root: root,
|
|
167
|
+
name: name,
|
|
168
|
+
version: v,
|
|
169
|
+
cachetime: cachetime
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}, ref$.resolveLatest = function(o){
|
|
174
|
+
var this$ = this;
|
|
175
|
+
o == null && (o = {});
|
|
176
|
+
return Promise.resolve().then(function(){
|
|
177
|
+
var root, name, force, cachetime, base, peek, _;
|
|
178
|
+
root = o.root, name = o.name, force = o.force, cachetime = o.cachetime;
|
|
179
|
+
cachetime = cachetime || 60 * 60;
|
|
180
|
+
if ((name + "").length > 128) {
|
|
181
|
+
return lderror.reject(404);
|
|
182
|
+
}
|
|
183
|
+
if (!/^(?:@[0-9a-z._-]+\/)?[0-9a-z._-]+$/.test(name)) {
|
|
184
|
+
return lderror.reject(400);
|
|
185
|
+
}
|
|
186
|
+
base = pthk.join(root, pthk.rectify(name));
|
|
187
|
+
peek = function(pvd){
|
|
188
|
+
var file;
|
|
189
|
+
if (!pvd._fetchRealVersion) {
|
|
190
|
+
return lderror.reject(404);
|
|
191
|
+
}
|
|
192
|
+
file = pthk.join(base, ".reg.latest." + pvd._name);
|
|
193
|
+
return Promise.resolve().then(function(){
|
|
194
|
+
if (force) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return fs.exists(file).then(function(isExisted){
|
|
198
|
+
if (!isExisted) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
return fs.stat(file).then(function(s){
|
|
202
|
+
if (Date.now() > s.mtime.getTime() + cachetime * 1000) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
return fs.readFile(file).then(function(r){
|
|
206
|
+
return JSON.parse(r);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}).then(function(cached){
|
|
211
|
+
if (cached) {
|
|
212
|
+
return cached.version;
|
|
213
|
+
}
|
|
214
|
+
return pvd._fetchRealVersion({
|
|
215
|
+
root: root,
|
|
216
|
+
name: name,
|
|
217
|
+
cachetime: cachetime,
|
|
218
|
+
version: 'latest',
|
|
219
|
+
versionType: 'latest'
|
|
220
|
+
}).then(function(info){
|
|
221
|
+
return fs.ensureDir(base).then(function(){
|
|
222
|
+
return fs.writeFile(file, JSON.stringify({
|
|
223
|
+
version: info.version
|
|
224
|
+
}));
|
|
225
|
+
}).then(function(){
|
|
226
|
+
return info.version;
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
_ = function(idx){
|
|
232
|
+
var pvd;
|
|
233
|
+
idx == null && (idx = -1);
|
|
234
|
+
pvd = idx < 0
|
|
235
|
+
? this$
|
|
236
|
+
: this$._ps[idx];
|
|
237
|
+
if (!pvd) {
|
|
238
|
+
return lderror.reject(404);
|
|
239
|
+
}
|
|
240
|
+
return pvd.check({
|
|
241
|
+
name: name,
|
|
242
|
+
version: 'latest'
|
|
243
|
+
}).then(function(){
|
|
244
|
+
return peek(pvd);
|
|
245
|
+
})['catch'](function(e){
|
|
246
|
+
if (lderror.id(e) !== 404) {
|
|
247
|
+
return Promise.reject(e);
|
|
248
|
+
} else {
|
|
249
|
+
return _(idx + 1);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
return _()['catch'](function(e){
|
|
254
|
+
if (lderror.id(e) === 403) {
|
|
255
|
+
return lderror.reject(404);
|
|
256
|
+
} else {
|
|
257
|
+
return Promise.reject(e);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}, ref$.designate = function(o){
|
|
262
|
+
var this$ = this;
|
|
263
|
+
o == null && (o = {});
|
|
264
|
+
return Promise.resolve().then(function(){
|
|
265
|
+
var root, name, version, cachetime, base, ref$, mainPath, tmp;
|
|
266
|
+
root = o.root, name = o.name, version = o.version, cachetime = o.cachetime;
|
|
267
|
+
if (getVersionType(version) !== 'specific') {
|
|
268
|
+
return lderror.reject(400, "designate requires a specific version");
|
|
269
|
+
}
|
|
270
|
+
if ((name + "").length > 128 || (version + "").length > 40) {
|
|
271
|
+
return lderror.reject(404);
|
|
272
|
+
}
|
|
273
|
+
if (!/^(?:@[0-9a-z._-]+\/)?[0-9a-z._-]+$/.test(name)) {
|
|
274
|
+
return lderror.reject(400);
|
|
275
|
+
}
|
|
276
|
+
base = pthk.join(root, pthk.rectify(name));
|
|
277
|
+
ref$ = [pthk.join(base, 'main'), pthk.join(base, ".main." + process.pid + ".tmp")], mainPath = ref$[0], tmp = ref$[1];
|
|
278
|
+
return Promise.resolve().then(function(){
|
|
279
|
+
return fs.exists(pthk.join(base, version, '.reg.version')).then(function(isExisted){
|
|
280
|
+
if (isExisted) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
return this$.fetch({
|
|
284
|
+
root: root,
|
|
285
|
+
name: name,
|
|
286
|
+
version: version,
|
|
287
|
+
force: false,
|
|
288
|
+
cachetime: cachetime
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}).then(function(){
|
|
292
|
+
return fs.lstat(mainPath)['catch'](function(){
|
|
293
|
+
return null;
|
|
294
|
+
});
|
|
295
|
+
}).then(function(s){
|
|
296
|
+
return Promise.resolve().then(function(){
|
|
297
|
+
if (s && !s.isSymbolicLink()) {
|
|
298
|
+
return fs.remove(mainPath);
|
|
299
|
+
}
|
|
300
|
+
}).then(function(){
|
|
301
|
+
return fs.remove(tmp);
|
|
302
|
+
}).then(function(){
|
|
303
|
+
return fs.symlink(version, tmp);
|
|
304
|
+
}).then(function(){
|
|
305
|
+
return fs.rename(tmp, mainPath);
|
|
306
|
+
});
|
|
307
|
+
}).then(function(){
|
|
308
|
+
return {
|
|
309
|
+
name: name,
|
|
310
|
+
version: version
|
|
311
|
+
};
|
|
312
|
+
});
|
|
313
|
+
});
|
|
142
314
|
}, ref$.resolve = function(o){
|
|
143
315
|
var this$ = this;
|
|
144
316
|
o == null && (o = {});
|
|
@@ -262,14 +434,6 @@
|
|
|
262
434
|
});
|
|
263
435
|
});
|
|
264
436
|
}
|
|
265
|
-
if (versionType === 'specific') {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
if (versionType === 'latest') {
|
|
269
|
-
return fs.stat(path.version).then(function(s){
|
|
270
|
-
return Date.now() > s.mtime.getTime() + cachetime * 1000;
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
437
|
return false;
|
|
274
438
|
}).then(function(isDirty){
|
|
275
439
|
if (!isDirty) {
|
|
@@ -279,24 +443,6 @@
|
|
|
279
443
|
}).then(function(){
|
|
280
444
|
return this$._fetchRealVersion(params).then(function(remoteInfo){
|
|
281
445
|
return Promise.resolve().then(function(){
|
|
282
|
-
if (force || versionType === 'specific') {
|
|
283
|
-
return remoteInfo;
|
|
284
|
-
}
|
|
285
|
-
return fs.exists(path.version).then(function(isExisted){
|
|
286
|
-
if (!isExisted) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
return fs.readFile(path.version).then(function(r){
|
|
290
|
-
var now;
|
|
291
|
-
if (remoteInfo.version > JSON.parse(r).version) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
now = new Date();
|
|
295
|
-
fs.utimes(path.version, now, now);
|
|
296
|
-
return lderror.reject(998);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
}).then(function(){
|
|
300
446
|
return fs.remove(path.base.version);
|
|
301
447
|
}).then(function(){
|
|
302
448
|
return fs.ensureDir(path.base.version);
|
package/providers/github.js
CHANGED
package/providers/index.js
CHANGED
package/providers/npm.js
CHANGED
package/route.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Generated by LiveScript 1.6.0
|
|
1
2
|
(function(){
|
|
2
3
|
var pthk, lderror, fs, versionType, handle, route;
|
|
3
4
|
pthk = require('pthk');
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
}
|
|
13
14
|
ref$ = [{}, {}, pthk.rectify(id)], paths = ref$[0], obj = ref$[1], id = ref$[2];
|
|
14
15
|
return Promise.resolve().then(function(){
|
|
15
|
-
var ids, e;
|
|
16
|
+
var ids, e, vt, p;
|
|
16
17
|
if (!/^[-_a-zA-Z0-9@./~^%]+$/.exec(id)) {
|
|
17
18
|
return lderror.reject(404);
|
|
18
19
|
}
|
|
@@ -37,14 +38,22 @@
|
|
|
37
38
|
e = e$;
|
|
38
39
|
return lderror.reject(404);
|
|
39
40
|
}
|
|
40
|
-
if (versionType(obj.version) === 'range') {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
if ((vt = versionType(obj.version)) === 'range' || vt === 'latest') {
|
|
42
|
+
p = vt === 'range'
|
|
43
|
+
? provider.resolve(import$({
|
|
44
|
+
root: root.fs,
|
|
45
|
+
name: obj.name,
|
|
46
|
+
version: obj.version,
|
|
47
|
+
force: false,
|
|
48
|
+
cachetime: 60 * 60
|
|
49
|
+
}, opt))
|
|
50
|
+
: provider.resolveLatest(import$({
|
|
51
|
+
root: root.fs,
|
|
52
|
+
name: obj.name,
|
|
53
|
+
force: false,
|
|
54
|
+
cachetime: 60 * 60
|
|
55
|
+
}, opt));
|
|
56
|
+
return p.then(function(v){
|
|
48
57
|
return {
|
|
49
58
|
redirect: pthk.join(root.pub, obj.name, v, obj.path)
|
|
50
59
|
};
|
package/unbox.js
CHANGED