pnpm 6.17.2 → 6.20.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/README.md +26 -24
- package/dist/node_modules/make-fetch-happen/{agent.js → lib/agent.js} +14 -29
- package/dist/node_modules/make-fetch-happen/lib/cache/entry.js +460 -0
- package/dist/node_modules/make-fetch-happen/lib/cache/errors.js +10 -0
- package/dist/node_modules/make-fetch-happen/lib/cache/index.js +45 -0
- package/dist/node_modules/make-fetch-happen/lib/cache/key.js +17 -0
- package/dist/node_modules/make-fetch-happen/lib/cache/policy.js +161 -0
- package/dist/node_modules/make-fetch-happen/lib/fetch.js +100 -0
- package/dist/node_modules/make-fetch-happen/lib/index.js +40 -0
- package/dist/node_modules/make-fetch-happen/lib/options.js +44 -0
- package/dist/node_modules/make-fetch-happen/lib/remote.js +102 -0
- package/dist/node_modules/make-fetch-happen/package.json +21 -17
- package/dist/node_modules/negotiator/LICENSE +24 -0
- package/dist/node_modules/negotiator/index.js +124 -0
- package/dist/node_modules/negotiator/lib/charset.js +169 -0
- package/dist/node_modules/negotiator/lib/encoding.js +184 -0
- package/dist/node_modules/negotiator/lib/language.js +179 -0
- package/dist/node_modules/negotiator/lib/mediaType.js +294 -0
- package/dist/node_modules/negotiator/package.json +42 -0
- package/dist/node_modules/node-gyp/.github/workflows/tests.yml +1 -1
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +16 -1
- package/dist/node_modules/node-gyp/gyp/setup.py +1 -1
- package/dist/node_modules/node-gyp/lib/configure.js +5 -97
- package/dist/node_modules/node-gyp/lib/create-config-gypi.js +119 -0
- package/dist/node_modules/node-gyp/package.json +2 -2
- package/dist/node_modules/socks-proxy-agent/dist/agent.js +4 -3
- package/dist/node_modules/socks-proxy-agent/dist/agent.js.map +1 -1
- package/dist/node_modules/socks-proxy-agent/dist/index.js.map +1 -1
- package/dist/node_modules/socks-proxy-agent/package.json +20 -20
- package/dist/pnpm.cjs +13490 -13531
- package/dist/pnpmrc +2 -0
- package/dist/pnpx.cjs +6 -4
- package/package.json +34 -33
- package/dist/node_modules/make-fetch-happen/cache.js +0 -260
- package/dist/node_modules/make-fetch-happen/index.js +0 -457
- package/dist/node_modules/make-fetch-happen/utils/configure-options.js +0 -32
- package/dist/node_modules/make-fetch-happen/utils/initialize-cache.js +0 -26
- package/dist/node_modules/make-fetch-happen/utils/is-header-conditional.js +0 -17
- package/dist/node_modules/make-fetch-happen/utils/iterable-to-object.js +0 -9
- package/dist/node_modules/make-fetch-happen/utils/make-policy.js +0 -19
- package/dist/node_modules/make-fetch-happen/warning.js +0 -24
package/dist/pnpmrc
ADDED
package/dist/pnpx.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var __reflectGet = Reflect.get;
|
|
2
|
+
var __reflectSet = Reflect.set;
|
|
1
3
|
var __commonJS = (cb, mod) => function __require() {
|
|
2
4
|
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3
5
|
};
|
|
@@ -369,7 +371,7 @@ var require_lib2 = __commonJS({
|
|
|
369
371
|
async function findWorkspaceDir(cwd) {
|
|
370
372
|
var _a;
|
|
371
373
|
const workspaceManifestDirEnvVar = (_a = process.env[WORKSPACE_DIR_ENV_VAR]) !== null && _a !== void 0 ? _a : process.env[WORKSPACE_DIR_ENV_VAR.toLowerCase()];
|
|
372
|
-
const workspaceManifestLocation = workspaceManifestDirEnvVar ? path_12.default.join(workspaceManifestDirEnvVar, "pnpm-workspace.yaml") : await find_up_1.default([WORKSPACE_MANIFEST_FILENAME, "pnpm-workspace.yml"], { cwd });
|
|
374
|
+
const workspaceManifestLocation = workspaceManifestDirEnvVar ? path_12.default.join(workspaceManifestDirEnvVar, "pnpm-workspace.yaml") : await (0, find_up_1.default)([WORKSPACE_MANIFEST_FILENAME, "pnpm-workspace.yml"], { cwd });
|
|
373
375
|
if (workspaceManifestLocation === null || workspaceManifestLocation === void 0 ? void 0 : workspaceManifestLocation.endsWith(".yml")) {
|
|
374
376
|
throw new error_1.default("BAD_WORKSPACE_MANIFEST_NAME", `The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${workspaceManifestLocation}`);
|
|
375
377
|
}
|
|
@@ -15343,13 +15345,13 @@ var path_name_1 = __importDefault(require_path_name());
|
|
|
15343
15345
|
var PNPM_PATH = path_1.default.join(__dirname, "pnpm.cjs");
|
|
15344
15346
|
(async () => {
|
|
15345
15347
|
var _a;
|
|
15346
|
-
const workspaceRoot = await find_workspace_dir_1.default(process.cwd());
|
|
15348
|
+
const workspaceRoot = await (0, find_workspace_dir_1.default)(process.cwd());
|
|
15347
15349
|
if (workspaceRoot) {
|
|
15348
15350
|
process.env[path_name_1.default] = `${path_1.default.join(workspaceRoot, "node_modules/.bin")}${path_1.default.delimiter}${(_a = process.env[path_name_1.default]) !== null && _a !== void 0 ? _a : ""}`;
|
|
15349
15351
|
}
|
|
15350
|
-
index_1.default({
|
|
15352
|
+
(0, index_1.default)({
|
|
15351
15353
|
...index_1.default.parseArgs(process.argv, PNPM_PATH),
|
|
15352
|
-
cache: path_1.default.join(await store_path_1.default(process.cwd(), "~/.pnpm-store"), "tmp"),
|
|
15354
|
+
cache: path_1.default.join(await (0, store_path_1.default)(process.cwd(), "~/.pnpm-store"), "tmp"),
|
|
15353
15355
|
installerStdio: "inherit"
|
|
15354
15356
|
});
|
|
15355
15357
|
})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pnpm",
|
|
3
3
|
"description": "Fast, disk space efficient package manager",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.20.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"pnpm": "bin/pnpm.cjs",
|
|
7
7
|
"pnpx": "bin/pnpx.cjs"
|
|
@@ -20,50 +20,52 @@
|
|
|
20
20
|
},
|
|
21
21
|
"__devDependencies": {
|
|
22
22
|
"@pnpm/assert-project": "workspace:*",
|
|
23
|
+
"@pnpm/byline": "^1.0.0",
|
|
23
24
|
"@pnpm/cli-meta": "workspace:2.0.0",
|
|
24
|
-
"@pnpm/cli-utils": "workspace:0.6.
|
|
25
|
-
"@pnpm/client": "workspace:
|
|
25
|
+
"@pnpm/cli-utils": "workspace:0.6.29",
|
|
26
|
+
"@pnpm/client": "workspace:6.0.0",
|
|
26
27
|
"@pnpm/command": "workspace:2.0.0",
|
|
27
28
|
"@pnpm/common-cli-options-help": "workspace:0.7.1",
|
|
28
|
-
"@pnpm/config": "workspace:13.
|
|
29
|
+
"@pnpm/config": "workspace:13.4.1",
|
|
29
30
|
"@pnpm/constants": "workspace:5.0.0",
|
|
30
|
-
"@pnpm/core-loggers": "workspace:6.0.
|
|
31
|
-
"@pnpm/default-reporter": "workspace:8.3.
|
|
31
|
+
"@pnpm/core-loggers": "workspace:6.0.5",
|
|
32
|
+
"@pnpm/default-reporter": "workspace:8.3.5",
|
|
32
33
|
"@pnpm/file-reporter": "workspace:2.0.0",
|
|
33
|
-
"@pnpm/filter-workspace-packages": "workspace:4.
|
|
34
|
+
"@pnpm/filter-workspace-packages": "workspace:4.4.1",
|
|
34
35
|
"@pnpm/find-workspace-dir": "workspace:3.0.1",
|
|
35
|
-
"@pnpm/find-workspace-packages": "workspace:3.1.
|
|
36
|
-
"@pnpm/lockfile-types": "workspace:3.
|
|
36
|
+
"@pnpm/find-workspace-packages": "workspace:3.1.21",
|
|
37
|
+
"@pnpm/lockfile-types": "workspace:3.1.0",
|
|
37
38
|
"@pnpm/logger": "^4.0.0",
|
|
38
|
-
"@pnpm/modules-yaml": "workspace:9.0.
|
|
39
|
+
"@pnpm/modules-yaml": "workspace:9.0.5",
|
|
39
40
|
"@pnpm/nopt": "^0.2.1",
|
|
40
41
|
"@pnpm/parse-cli-args": "workspace:4.3.0",
|
|
41
|
-
"@pnpm/pick-registry-for-package": "workspace:2.0.
|
|
42
|
-
"@pnpm/plugin-commands-audit": "workspace:5.1.
|
|
43
|
-
"@pnpm/plugin-commands-env": "workspace:1.
|
|
44
|
-
"@pnpm/plugin-commands-import": "workspace:3.1.
|
|
45
|
-
"@pnpm/plugin-commands-installation": "workspace:7.0
|
|
46
|
-
"@pnpm/plugin-commands-listing": "workspace:4.0.
|
|
47
|
-
"@pnpm/plugin-commands-outdated": "workspace:5.0.
|
|
48
|
-
"@pnpm/plugin-commands-publishing": "workspace:4.2.
|
|
49
|
-
"@pnpm/plugin-commands-rebuild": "workspace:5.
|
|
50
|
-
"@pnpm/plugin-commands-script-runners": "workspace:4.3.
|
|
51
|
-
"@pnpm/plugin-commands-server": "workspace:3.0.
|
|
52
|
-
"@pnpm/plugin-commands-setup": "workspace:1.1.
|
|
53
|
-
"@pnpm/plugin-commands-store": "workspace:4.0.
|
|
54
|
-
"@pnpm/prepare": "workspace:0.0.
|
|
55
|
-
"@pnpm/read-package-json": "workspace:5.0.
|
|
56
|
-
"@pnpm/read-project-manifest": "workspace:2.0.
|
|
42
|
+
"@pnpm/pick-registry-for-package": "workspace:2.0.5",
|
|
43
|
+
"@pnpm/plugin-commands-audit": "workspace:5.1.19",
|
|
44
|
+
"@pnpm/plugin-commands-env": "workspace:1.2.3",
|
|
45
|
+
"@pnpm/plugin-commands-import": "workspace:3.1.17",
|
|
46
|
+
"@pnpm/plugin-commands-installation": "workspace:7.1.0",
|
|
47
|
+
"@pnpm/plugin-commands-listing": "workspace:4.0.20",
|
|
48
|
+
"@pnpm/plugin-commands-outdated": "workspace:5.0.25",
|
|
49
|
+
"@pnpm/plugin-commands-publishing": "workspace:4.2.21",
|
|
50
|
+
"@pnpm/plugin-commands-rebuild": "workspace:5.2.0",
|
|
51
|
+
"@pnpm/plugin-commands-script-runners": "workspace:4.3.5",
|
|
52
|
+
"@pnpm/plugin-commands-server": "workspace:3.0.42",
|
|
53
|
+
"@pnpm/plugin-commands-setup": "workspace:1.1.13",
|
|
54
|
+
"@pnpm/plugin-commands-store": "workspace:4.0.26",
|
|
55
|
+
"@pnpm/prepare": "workspace:0.0.27",
|
|
56
|
+
"@pnpm/read-package-json": "workspace:5.0.5",
|
|
57
|
+
"@pnpm/read-project-manifest": "workspace:2.0.6",
|
|
57
58
|
"@pnpm/run-npm": "workspace:3.1.0",
|
|
58
59
|
"@pnpm/store-path": "^5.0.0",
|
|
59
60
|
"@pnpm/tabtab": "^0.1.2",
|
|
60
|
-
"@pnpm/
|
|
61
|
-
"@pnpm/
|
|
62
|
-
"@
|
|
61
|
+
"@pnpm/ts-execution-runtime": "workspace:1.0.0",
|
|
62
|
+
"@pnpm/types": "workspace:7.5.0",
|
|
63
|
+
"@pnpm/write-project-manifest": "workspace:2.0.5",
|
|
63
64
|
"@types/cross-spawn": "^6.0.2",
|
|
64
65
|
"@types/is-ci": "^3.0.0",
|
|
65
66
|
"@types/is-windows": "^1.0.0",
|
|
66
67
|
"@types/ncp": "^2.0.4",
|
|
68
|
+
"@types/pnpm__byline": "npm:@types/byline@^4.2.32",
|
|
67
69
|
"@types/ramda": "0.27.39",
|
|
68
70
|
"@types/semver": "^7.3.4",
|
|
69
71
|
"@types/which": "^2.0.0",
|
|
@@ -71,14 +73,13 @@
|
|
|
71
73
|
"@zkochan/retry": "^0.2.0",
|
|
72
74
|
"@zkochan/rimraf": "^2.1.1",
|
|
73
75
|
"anonymous-npm-registry-client": "0.1.2",
|
|
74
|
-
"byline": "5.0.0",
|
|
75
76
|
"chalk": "^4.1.0",
|
|
76
77
|
"cross-spawn": "^7.0.3",
|
|
77
78
|
"cross-var-no-babel": "^1.2.0",
|
|
78
79
|
"deep-require-cwd": "1.0.0",
|
|
79
80
|
"delay": "^5.0.0",
|
|
80
81
|
"dir-is-case-sensitive": "^2.0.0",
|
|
81
|
-
"esbuild": "^0.
|
|
82
|
+
"esbuild": "^0.13.7",
|
|
82
83
|
"execa": "npm:safe-execa@^0.1.1",
|
|
83
84
|
"exists-link": "2.0.0",
|
|
84
85
|
"is-ci": "^3.0.0",
|
|
@@ -161,13 +162,13 @@
|
|
|
161
162
|
"bundle:pnpx": "esbuild lib/pnpx.js --bundle --platform=node --outfile=dist/pnpx.cjs",
|
|
162
163
|
"bundle": "pnpm bundle:pnpm && pnpm bundle:pnpx",
|
|
163
164
|
"start": "pnpm tsc --watch",
|
|
164
|
-
"lint": "eslint
|
|
165
|
+
"lint": "eslint src/**/*.ts test/**/*.ts",
|
|
165
166
|
"registry-mock": "registry-mock",
|
|
166
167
|
"test:jest": "jest",
|
|
167
168
|
"pretest:e2e": "rimraf node_modules/.bin/pnpm",
|
|
168
169
|
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
|
|
169
170
|
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7781 pnpm run test:e2e",
|
|
170
171
|
"test": "pnpm run compile && pnpm run _test",
|
|
171
|
-
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix && rimraf dist bin/nodes && pnpm run bundle && shx cp -r node-gyp-bin dist/node-gyp-bin && shx cp -r node_modules/@pnpm/tabtab/lib/scripts dist/scripts && shx cp -r node_modules/ps-list/vendor dist/vendor"
|
|
172
|
+
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix && rimraf dist bin/nodes && pnpm run bundle && shx cp -r node-gyp-bin dist/node-gyp-bin && shx cp -r node_modules/@pnpm/tabtab/lib/scripts dist/scripts && shx cp -r node_modules/ps-list/vendor dist/vendor && shx cp pnpmrc dist/pnpmrc"
|
|
172
173
|
}
|
|
173
174
|
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fetch = require('minipass-fetch')
|
|
4
|
-
const cacache = require('cacache')
|
|
5
|
-
const ssri = require('ssri')
|
|
6
|
-
const url = require('url')
|
|
7
|
-
|
|
8
|
-
const Minipass = require('minipass')
|
|
9
|
-
const MinipassFlush = require('minipass-flush')
|
|
10
|
-
const MinipassCollect = require('minipass-collect')
|
|
11
|
-
const MinipassPipeline = require('minipass-pipeline')
|
|
12
|
-
|
|
13
|
-
const MAX_MEM_SIZE = 5 * 1024 * 1024 // 5MB
|
|
14
|
-
|
|
15
|
-
// some headers should never be stored in the cache, either because
|
|
16
|
-
// they're a security footgun to leave lying around, or because we
|
|
17
|
-
// just don't need them taking up space.
|
|
18
|
-
// set to undefined so they're omitted from the JSON.stringify
|
|
19
|
-
const pruneHeaders = {
|
|
20
|
-
authorization: undefined,
|
|
21
|
-
'npm-session': undefined,
|
|
22
|
-
'set-cookie': undefined,
|
|
23
|
-
'cf-ray': undefined,
|
|
24
|
-
'cf-cache-status': undefined,
|
|
25
|
-
'cf-request-id': undefined,
|
|
26
|
-
'x-fetch-attempts': undefined,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function cacheKey (req) {
|
|
30
|
-
const parsed = new url.URL(req.url)
|
|
31
|
-
return `make-fetch-happen:request-cache:${
|
|
32
|
-
url.format({
|
|
33
|
-
protocol: parsed.protocol,
|
|
34
|
-
slashes: true,
|
|
35
|
-
port: parsed.port,
|
|
36
|
-
hostname: parsed.hostname,
|
|
37
|
-
pathname: parsed.pathname,
|
|
38
|
-
search: parsed.search,
|
|
39
|
-
})
|
|
40
|
-
}`
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// This is a cacache-based implementation of the Cache standard,
|
|
44
|
-
// using node-fetch.
|
|
45
|
-
// docs: https://developer.mozilla.org/en-US/docs/Web/API/Cache
|
|
46
|
-
//
|
|
47
|
-
module.exports = class Cache {
|
|
48
|
-
constructor (path, opts) {
|
|
49
|
-
this._path = path
|
|
50
|
-
this.Promise = (opts && opts.Promise) || Promise
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static get pruneHeaders () {
|
|
54
|
-
// exposed for testing, not modifiable
|
|
55
|
-
return { ...pruneHeaders }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Returns a Promise that resolves to the response associated with the first
|
|
59
|
-
// matching request in the Cache object.
|
|
60
|
-
match (req, opts) {
|
|
61
|
-
const key = cacheKey(req)
|
|
62
|
-
return cacache.get.info(this._path, key).then(info => {
|
|
63
|
-
return info && cacache.get.hasContent(
|
|
64
|
-
this._path, info.integrity, opts
|
|
65
|
-
).then(exists => exists && info)
|
|
66
|
-
}).then(info => {
|
|
67
|
-
if (info && info.metadata && matchDetails(req, {
|
|
68
|
-
url: info.metadata.url,
|
|
69
|
-
reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
|
|
70
|
-
resHeaders: new fetch.Headers(info.metadata.resHeaders),
|
|
71
|
-
cacheIntegrity: info.integrity,
|
|
72
|
-
integrity: opts && opts.integrity,
|
|
73
|
-
})) {
|
|
74
|
-
const resHeaders = new fetch.Headers(info.metadata.resHeaders)
|
|
75
|
-
addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
|
|
76
|
-
if (req.method === 'HEAD') {
|
|
77
|
-
return new fetch.Response(null, {
|
|
78
|
-
url: req.url,
|
|
79
|
-
headers: resHeaders,
|
|
80
|
-
status: 200,
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
const cachePath = this._path
|
|
84
|
-
// avoid opening cache file handles until a user actually tries to
|
|
85
|
-
// read from it.
|
|
86
|
-
const body = new Minipass()
|
|
87
|
-
const fitInMemory = info.size < MAX_MEM_SIZE
|
|
88
|
-
const removeOnResume = () => body.removeListener('resume', onResume)
|
|
89
|
-
const onResume =
|
|
90
|
-
opts.memoize !== false && fitInMemory
|
|
91
|
-
? () => {
|
|
92
|
-
const c = cacache.get.stream.byDigest(cachePath, info.integrity, {
|
|
93
|
-
memoize: opts.memoize,
|
|
94
|
-
})
|
|
95
|
-
c.on('error', /* istanbul ignore next */ err => {
|
|
96
|
-
body.emit('error', err)
|
|
97
|
-
})
|
|
98
|
-
c.pipe(body)
|
|
99
|
-
}
|
|
100
|
-
: () => {
|
|
101
|
-
removeOnResume()
|
|
102
|
-
cacache.get.byDigest(cachePath, info.integrity, {
|
|
103
|
-
memoize: opts.memoize,
|
|
104
|
-
})
|
|
105
|
-
.then(data => body.end(data))
|
|
106
|
-
.catch(/* istanbul ignore next */ err => {
|
|
107
|
-
body.emit('error', err)
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
body.once('resume', onResume)
|
|
111
|
-
body.once('end', () => removeOnResume)
|
|
112
|
-
return this.Promise.resolve(new fetch.Response(body, {
|
|
113
|
-
url: req.url,
|
|
114
|
-
headers: resHeaders,
|
|
115
|
-
status: 200,
|
|
116
|
-
size: info.size,
|
|
117
|
-
}))
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Takes both a request and its response and adds it to the given cache.
|
|
123
|
-
put (req, response, opts) {
|
|
124
|
-
opts = opts || {}
|
|
125
|
-
const size = response.headers.get('content-length')
|
|
126
|
-
const fitInMemory = !!size && opts.memoize !== false && size < MAX_MEM_SIZE
|
|
127
|
-
const ckey = cacheKey(req)
|
|
128
|
-
const cacheOpts = {
|
|
129
|
-
algorithms: opts.algorithms,
|
|
130
|
-
metadata: {
|
|
131
|
-
url: req.url,
|
|
132
|
-
reqHeaders: {
|
|
133
|
-
...req.headers.raw(),
|
|
134
|
-
...pruneHeaders,
|
|
135
|
-
},
|
|
136
|
-
resHeaders: {
|
|
137
|
-
...response.headers.raw(),
|
|
138
|
-
...pruneHeaders,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
size,
|
|
142
|
-
memoize: fitInMemory && opts.memoize,
|
|
143
|
-
}
|
|
144
|
-
if (req.method === 'HEAD' || response.status === 304) {
|
|
145
|
-
// Update metadata without writing
|
|
146
|
-
return cacache.get.info(this._path, ckey).then(info => {
|
|
147
|
-
// Providing these will bypass content write
|
|
148
|
-
cacheOpts.integrity = info.integrity
|
|
149
|
-
addCacheHeaders(
|
|
150
|
-
response.headers, this._path, ckey, info.integrity, info.time
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
return new MinipassPipeline(
|
|
154
|
-
cacache.get.stream.byDigest(this._path, info.integrity, cacheOpts),
|
|
155
|
-
cacache.put.stream(this._path, ckey, cacheOpts)
|
|
156
|
-
).promise().then(() => {
|
|
157
|
-
return response
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
const oldBody = response.body
|
|
162
|
-
// the flush is the last thing in the pipeline. Build the pipeline
|
|
163
|
-
// back-to-front so we don't consume the data before we use it!
|
|
164
|
-
// We unshift in either a tee-stream to the cache put stream,
|
|
165
|
-
// or a collecter that dumps it to cache in one go, then the
|
|
166
|
-
// old body to bring in the data.
|
|
167
|
-
const newBody = new MinipassPipeline(new MinipassFlush({
|
|
168
|
-
flush () {
|
|
169
|
-
return cacheWritePromise
|
|
170
|
-
},
|
|
171
|
-
}))
|
|
172
|
-
|
|
173
|
-
let cacheWriteResolve, cacheWriteReject
|
|
174
|
-
const cacheWritePromise = new Promise((resolve, reject) => {
|
|
175
|
-
cacheWriteResolve = resolve
|
|
176
|
-
cacheWriteReject = reject
|
|
177
|
-
})
|
|
178
|
-
const cachePath = this._path
|
|
179
|
-
|
|
180
|
-
if (fitInMemory) {
|
|
181
|
-
const collecter = new MinipassCollect.PassThrough()
|
|
182
|
-
collecter.on('collect', data => {
|
|
183
|
-
cacache.put(
|
|
184
|
-
cachePath,
|
|
185
|
-
ckey,
|
|
186
|
-
data,
|
|
187
|
-
cacheOpts
|
|
188
|
-
).then(cacheWriteResolve, cacheWriteReject)
|
|
189
|
-
})
|
|
190
|
-
newBody.unshift(collecter)
|
|
191
|
-
} else {
|
|
192
|
-
const tee = new Minipass()
|
|
193
|
-
const cacheStream = cacache.put.stream(
|
|
194
|
-
cachePath,
|
|
195
|
-
ckey,
|
|
196
|
-
cacheOpts
|
|
197
|
-
)
|
|
198
|
-
tee.pipe(cacheStream)
|
|
199
|
-
cacheStream.promise().then(cacheWriteResolve, cacheWriteReject)
|
|
200
|
-
newBody.unshift(tee)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
newBody.unshift(oldBody)
|
|
204
|
-
return Promise.resolve(new fetch.Response(newBody, response))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Finds the Cache entry whose key is the request, and if found, deletes the
|
|
208
|
-
// Cache entry and returns a Promise that resolves to true. If no Cache entry
|
|
209
|
-
// is found, it returns false.
|
|
210
|
-
'delete' (req, opts) {
|
|
211
|
-
opts = opts || {}
|
|
212
|
-
if (typeof opts.memoize === 'object') {
|
|
213
|
-
if (opts.memoize.reset)
|
|
214
|
-
opts.memoize.reset()
|
|
215
|
-
else if (opts.memoize.clear)
|
|
216
|
-
opts.memoize.clear()
|
|
217
|
-
else {
|
|
218
|
-
Object.keys(opts.memoize).forEach(k => {
|
|
219
|
-
opts.memoize[k] = null
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return cacache.rm.entry(
|
|
224
|
-
this._path,
|
|
225
|
-
cacheKey(req)
|
|
226
|
-
// TODO - true/false
|
|
227
|
-
).then(() => false)
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function matchDetails (req, cached) {
|
|
232
|
-
const reqUrl = new url.URL(req.url)
|
|
233
|
-
const cacheUrl = new url.URL(cached.url)
|
|
234
|
-
const vary = cached.resHeaders.get('Vary')
|
|
235
|
-
// https://tools.ietf.org/html/rfc7234#section-4.1
|
|
236
|
-
if (vary) {
|
|
237
|
-
if (vary.match(/\*/))
|
|
238
|
-
return false
|
|
239
|
-
else {
|
|
240
|
-
const fieldsMatch = vary.split(/\s*,\s*/).every(field => {
|
|
241
|
-
return cached.reqHeaders.get(field) === req.headers.get(field)
|
|
242
|
-
})
|
|
243
|
-
if (!fieldsMatch)
|
|
244
|
-
return false
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (cached.integrity)
|
|
248
|
-
return ssri.parse(cached.integrity).match(cached.cacheIntegrity)
|
|
249
|
-
|
|
250
|
-
reqUrl.hash = null
|
|
251
|
-
cacheUrl.hash = null
|
|
252
|
-
return url.format(reqUrl) === url.format(cacheUrl)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function addCacheHeaders (resHeaders, path, key, hash, time) {
|
|
256
|
-
resHeaders.set('X-Local-Cache', encodeURIComponent(path))
|
|
257
|
-
resHeaders.set('X-Local-Cache-Key', encodeURIComponent(key))
|
|
258
|
-
resHeaders.set('X-Local-Cache-Hash', encodeURIComponent(hash))
|
|
259
|
-
resHeaders.set('X-Local-Cache-Time', new Date(time).toUTCString())
|
|
260
|
-
}
|