@yao-pkg/pkg 5.9.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/LICENSE +21 -0
- package/README.md +433 -0
- package/dictionary/angular-bridge.js +3 -0
- package/dictionary/any-promise.js +3 -0
- package/dictionary/async.js +3 -0
- package/dictionary/aws-sdk.js +7 -0
- package/dictionary/babel-core.js +3 -0
- package/dictionary/batch.js +3 -0
- package/dictionary/bcrypt.js +3 -0
- package/dictionary/better-sqlite3.js +3 -0
- package/dictionary/bignum.js +3 -0
- package/dictionary/bindings.js +3 -0
- package/dictionary/blessed.js +8 -0
- package/dictionary/body-parser.js +9 -0
- package/dictionary/browserify.js +7 -0
- package/dictionary/bson.js +3 -0
- package/dictionary/buffermaker.js +7 -0
- package/dictionary/bunyan.js +9 -0
- package/dictionary/busboy.js +7 -0
- package/dictionary/bytes.js +3 -0
- package/dictionary/callsites.js +3 -0
- package/dictionary/chokidar.js +3 -0
- package/dictionary/coffee-script.js +7 -0
- package/dictionary/colors.js +3 -0
- package/dictionary/compression.js +3 -0
- package/dictionary/compressjs.js +7 -0
- package/dictionary/connect-mongo.js +3 -0
- package/dictionary/connect-mongodb.js +3 -0
- package/dictionary/connect-redis.js +3 -0
- package/dictionary/connect.js +10 -0
- package/dictionary/consolidate.js +3 -0
- package/dictionary/cookie-parser.js +3 -0
- package/dictionary/cookie.js +3 -0
- package/dictionary/cors.js +3 -0
- package/dictionary/cron.js +3 -0
- package/dictionary/cross-env.js +11 -0
- package/dictionary/cross-spawn-async.js +3 -0
- package/dictionary/curve25519.js +3 -0
- package/dictionary/data-preflight.js +7 -0
- package/dictionary/debug.js +3 -0
- package/dictionary/denymount.js +3 -0
- package/dictionary/diff.js +3 -0
- package/dictionary/drivelist.js +22 -0
- package/dictionary/ed25519.js +3 -0
- package/dictionary/ejs.js +3 -0
- package/dictionary/elasticsearch.js +3 -0
- package/dictionary/electron.js +17 -0
- package/dictionary/emailjs.js +3 -0
- package/dictionary/engine.io.js +3 -0
- package/dictionary/epoll.js +3 -0
- package/dictionary/errorhandler.js +7 -0
- package/dictionary/errors.js +7 -0
- package/dictionary/eslint.js +7 -0
- package/dictionary/etcher-image-write.js +3 -0
- package/dictionary/exceljs.js +21 -0
- package/dictionary/exiftool.exe.js +13 -0
- package/dictionary/exiftool.pl.js +13 -0
- package/dictionary/express-load.js +12 -0
- package/dictionary/express-session.js +3 -0
- package/dictionary/express.js +14 -0
- package/dictionary/extender.js +11 -0
- package/dictionary/extsprintf.js +3 -0
- package/dictionary/faye-websocket.js +3 -0
- package/dictionary/feathers.js +3 -0
- package/dictionary/findup-sync.js +3 -0
- package/dictionary/floordate.js +3 -0
- package/dictionary/fmt.js +3 -0
- package/dictionary/formidable.js +3 -0
- package/dictionary/fs-extra.js +3 -0
- package/dictionary/fsevents.js +3 -0
- package/dictionary/geoip-lite.js +7 -0
- package/dictionary/github.js +7 -0
- package/dictionary/gm.js +3 -0
- package/dictionary/google-closure-compiler-java.js +13 -0
- package/dictionary/google-closure-compiler.js +13 -0
- package/dictionary/googleapis.js +7 -0
- package/dictionary/got.js +3 -0
- package/dictionary/graceful-fs.js +19 -0
- package/dictionary/grpc.js +11 -0
- package/dictionary/gulp.js +3 -0
- package/dictionary/hap-nodejs.js +3 -0
- package/dictionary/heapdump.js +3 -0
- package/dictionary/hoek.js +3 -0
- package/dictionary/homebridge.js +3 -0
- package/dictionary/http-proxy.js +3 -0
- package/dictionary/http-server.js +3 -0
- package/dictionary/image-size.js +3 -0
- package/dictionary/indexof.js +3 -0
- package/dictionary/inquirer.js +3 -0
- package/dictionary/j.js +16 -0
- package/dictionary/jade.js +3 -0
- package/dictionary/jsdom.js +3 -0
- package/dictionary/json-stringify-date.js +3 -0
- package/dictionary/json-stringify-safe.js +3 -0
- package/dictionary/jsonwebtoken.js +3 -0
- package/dictionary/kerberos.js +3 -0
- package/dictionary/knex.js +7 -0
- package/dictionary/later.js +7 -0
- package/dictionary/level.js +3 -0
- package/dictionary/leveldown.js +10 -0
- package/dictionary/levelup.js +3 -0
- package/dictionary/liftoff.js +12 -0
- package/dictionary/lodash.js +3 -0
- package/dictionary/log4js.js +7 -0
- package/dictionary/logform.js +7 -0
- package/dictionary/machinepack-urls.js +7 -0
- package/dictionary/markdown.js +3 -0
- package/dictionary/mdns.js +6 -0
- package/dictionary/method-override.js +3 -0
- package/dictionary/microjob.js +16 -0
- package/dictionary/mime-types.js +3 -0
- package/dictionary/mime.js +3 -0
- package/dictionary/minimatch.js +3 -0
- package/dictionary/minstache.js +3 -0
- package/dictionary/module-deps.js +3 -0
- package/dictionary/moment-timezone.js +3 -0
- package/dictionary/moment.js +7 -0
- package/dictionary/mongodb-core.js +22 -0
- package/dictionary/mongodb.js +7 -0
- package/dictionary/mongoose.js +7 -0
- package/dictionary/mongoskin.js +7 -0
- package/dictionary/ms.js +3 -0
- package/dictionary/msgpack.js +3 -0
- package/dictionary/multer.js +3 -0
- package/dictionary/muri.js +3 -0
- package/dictionary/native-or-bluebird.js +3 -0
- package/dictionary/natives.js +3 -0
- package/dictionary/nconf.js +7 -0
- package/dictionary/nedb.js +3 -0
- package/dictionary/negotiator.js +7 -0
- package/dictionary/newrelic.js +3 -0
- package/dictionary/nib.js +3 -0
- package/dictionary/nightmare.js +18 -0
- package/dictionary/node-forge.js +7 -0
- package/dictionary/node-libcurl.js +3 -0
- package/dictionary/node-notifier.js +30 -0
- package/dictionary/node-pre-gyp.js +7 -0
- package/dictionary/node-redis-pubsub.js +3 -0
- package/dictionary/node-sass.js +3 -0
- package/dictionary/node-uuid.js +3 -0
- package/dictionary/node-xlsx.js +3 -0
- package/dictionary/node-zookeeper-client.js +7 -0
- package/dictionary/nodegit.js +7 -0
- package/dictionary/nodemailer-sendmail-transport.js +3 -0
- package/dictionary/nodemailer.js +3 -0
- package/dictionary/npm-registry-client.js +7 -0
- package/dictionary/npm.js +7 -0
- package/dictionary/nssocket.js +3 -0
- package/dictionary/oauth2orize.js +7 -0
- package/dictionary/octobat.js +3 -0
- package/dictionary/open.js +13 -0
- package/dictionary/opn.js +4 -0
- package/dictionary/optimist.js +3 -0
- package/dictionary/passport-local.js +3 -0
- package/dictionary/passport.js +3 -0
- package/dictionary/pg-cursor.js +3 -0
- package/dictionary/pg-query-stream.js +3 -0
- package/dictionary/pg-types.js +7 -0
- package/dictionary/pg.js +7 -0
- package/dictionary/pg.js.js +7 -0
- package/dictionary/pgpass.js +7 -0
- package/dictionary/phantom.js +19 -0
- package/dictionary/phantomjs-prebuilt.js +16 -0
- package/dictionary/pkginfo.js +3 -0
- package/dictionary/pm2.js +7 -0
- package/dictionary/pmx.js +3 -0
- package/dictionary/pouchdb.js +3 -0
- package/dictionary/primus-emitter.js +3 -0
- package/dictionary/primus-spark-latency.js +3 -0
- package/dictionary/primus.js +3 -0
- package/dictionary/publicsuffixlist.js +15 -0
- package/dictionary/pug.js +3 -0
- package/dictionary/punt.js +3 -0
- package/dictionary/puppeteer.js +13 -0
- package/dictionary/pwd.js +3 -0
- package/dictionary/q.js +3 -0
- package/dictionary/raven.js +3 -0
- package/dictionary/rc.js +12 -0
- package/dictionary/readable-stream.js +3 -0
- package/dictionary/rechoir.js +3 -0
- package/dictionary/redis-parser.js +3 -0
- package/dictionary/redis.js +3 -0
- package/dictionary/regression.js +3 -0
- package/dictionary/reload.js +7 -0
- package/dictionary/request.js +3 -0
- package/dictionary/require-uncached.js +3 -0
- package/dictionary/require_optional.js +3 -0
- package/dictionary/s3.js +3 -0
- package/dictionary/safe_datejs.js +3 -0
- package/dictionary/sails.js +33 -0
- package/dictionary/sax.js +3 -0
- package/dictionary/scrypt.js +3 -0
- package/dictionary/semver.js +3 -0
- package/dictionary/sequelize.js +7 -0
- package/dictionary/serialport.js +3 -0
- package/dictionary/sha3.js +3 -0
- package/dictionary/sharp.js +11 -0
- package/dictionary/shelljs.js +7 -0
- package/dictionary/sinon.js +3 -0
- package/dictionary/socket.io-client.js +13 -0
- package/dictionary/socket.io.js +12 -0
- package/dictionary/sqip.js +7 -0
- package/dictionary/sqlite3.js +3 -0
- package/dictionary/steam-crypto.js +7 -0
- package/dictionary/steam-resources.js +19 -0
- package/dictionary/steam.js +3 -0
- package/dictionary/stripe-webhook-middleware.js +3 -0
- package/dictionary/stripe.js +3 -0
- package/dictionary/strong-globalize.js +3 -0
- package/dictionary/stylus.js +14 -0
- package/dictionary/supervisor.js +3 -0
- package/dictionary/svgo.js +8 -0
- package/dictionary/tabtab.js +3 -0
- package/dictionary/tesseract.js.js +7 -0
- package/dictionary/throng.js +3 -0
- package/dictionary/time.js +3 -0
- package/dictionary/tinify.js +7 -0
- package/dictionary/tiny-worker.js +7 -0
- package/dictionary/tmp.js +3 -0
- package/dictionary/transformers.js +3 -0
- package/dictionary/uglify-js.js +9 -0
- package/dictionary/umd.js +19 -0
- package/dictionary/underscore.js +3 -0
- package/dictionary/union.js +3 -0
- package/dictionary/update-notifier.js +3 -0
- package/dictionary/usage.js +7 -0
- package/dictionary/v8flags.js +13 -0
- package/dictionary/verror.js +3 -0
- package/dictionary/voc.js +3 -0
- package/dictionary/webdriverio.js +7 -0
- package/dictionary/winston-uber.js +7 -0
- package/dictionary/winston.js +7 -0
- package/dictionary/ws.js +3 -0
- package/dictionary/xlsx.js +16 -0
- package/dictionary/xml2js.js +3 -0
- package/dictionary/yargs.js +3 -0
- package/dictionary/zeromq.js +13 -0
- package/lib-es5/bin.js +19 -0
- package/lib-es5/chmod.js +15 -0
- package/lib-es5/common.js +235 -0
- package/lib-es5/compress_type.js +10 -0
- package/lib-es5/detector.js +420 -0
- package/lib-es5/fabricator.js +141 -0
- package/lib-es5/follow.js +91 -0
- package/lib-es5/help.js +53 -0
- package/lib-es5/index.d.ts +2 -0
- package/lib-es5/index.js +541 -0
- package/lib-es5/log.js +7 -0
- package/lib-es5/mach-o.js +61 -0
- package/lib-es5/packer.js +131 -0
- package/lib-es5/producer.js +343 -0
- package/lib-es5/refiner.js +87 -0
- package/lib-es5/types.js +9 -0
- package/lib-es5/walker.js +853 -0
- package/package.json +143 -0
- package/prelude/bootstrap.js +2256 -0
- package/prelude/diagnostic.js +136 -0
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable require-atomic-updates */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const assert_1 = __importDefault(require("assert"));
|
|
31
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
32
|
+
const is_core_module_1 = __importDefault(require("is-core-module"));
|
|
33
|
+
const globby_1 = __importDefault(require("globby"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
36
|
+
const common_1 = require("./common");
|
|
37
|
+
const follow_1 = require("./follow");
|
|
38
|
+
const log_1 = require("./log");
|
|
39
|
+
const detector = __importStar(require("./detector"));
|
|
40
|
+
// Note: as a developer, you can set the PKG_STRICT_VER variable.
|
|
41
|
+
// this will turn on some assertion in the walker code below
|
|
42
|
+
// to assert that each file content/state that we appending
|
|
43
|
+
// to the virtual file system applies to a real file,
|
|
44
|
+
// not a symlink.
|
|
45
|
+
// By default assertion are disabled as they can have a
|
|
46
|
+
// performance hit.
|
|
47
|
+
const strictVerify = Boolean(process.env.PKG_STRICT_VER);
|
|
48
|
+
const win32 = process.platform === 'win32';
|
|
49
|
+
function unlikelyJavascript(file) {
|
|
50
|
+
return ['.css', '.html', '.json', '.vue'].includes(path_1.default.extname(file));
|
|
51
|
+
}
|
|
52
|
+
function isPublic(config) {
|
|
53
|
+
if (config.private) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const { licenses } = config;
|
|
57
|
+
let { license } = config;
|
|
58
|
+
if (licenses) {
|
|
59
|
+
license = licenses;
|
|
60
|
+
}
|
|
61
|
+
if (license && !Array.isArray(license)) {
|
|
62
|
+
license = typeof license === 'string' ? license : license.type;
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(license)) {
|
|
65
|
+
license = license.map((c) => String(c.type || c)).join(',');
|
|
66
|
+
}
|
|
67
|
+
if (!license) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (/^\(/.test(license)) {
|
|
71
|
+
license = license.slice(1);
|
|
72
|
+
}
|
|
73
|
+
if (/\)$/.test(license)) {
|
|
74
|
+
license = license.slice(0, -1);
|
|
75
|
+
}
|
|
76
|
+
license = license.toLowerCase();
|
|
77
|
+
const allLicenses = Array.prototype.concat(license.split(' or '), license.split(' and '), license.split('/'), license.split(','));
|
|
78
|
+
let result = false;
|
|
79
|
+
const foss = [
|
|
80
|
+
'isc',
|
|
81
|
+
'mit',
|
|
82
|
+
'apache-2.0',
|
|
83
|
+
'apache 2.0',
|
|
84
|
+
'public domain',
|
|
85
|
+
'bsd',
|
|
86
|
+
'bsd-2-clause',
|
|
87
|
+
'bsd-3-clause',
|
|
88
|
+
'wtfpl',
|
|
89
|
+
'cc-by-3.0',
|
|
90
|
+
'x11',
|
|
91
|
+
'artistic-2.0',
|
|
92
|
+
'gplv3',
|
|
93
|
+
'mpl',
|
|
94
|
+
'mplv2.0',
|
|
95
|
+
'unlicense',
|
|
96
|
+
'apache license 2.0',
|
|
97
|
+
'zlib',
|
|
98
|
+
'mpl-2.0',
|
|
99
|
+
'nasa-1.3',
|
|
100
|
+
'apache license, version 2.0',
|
|
101
|
+
'lgpl-2.1+',
|
|
102
|
+
'cc0-1.0',
|
|
103
|
+
];
|
|
104
|
+
for (const c of allLicenses) {
|
|
105
|
+
result = foss.indexOf(c) >= 0;
|
|
106
|
+
if (result) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function upon(p, base) {
|
|
113
|
+
if (typeof p !== 'string') {
|
|
114
|
+
throw (0, log_1.wasReported)('Config items must be strings. See examples');
|
|
115
|
+
}
|
|
116
|
+
let negate = false;
|
|
117
|
+
if (p[0] === '!') {
|
|
118
|
+
p = p.slice(1);
|
|
119
|
+
negate = true;
|
|
120
|
+
}
|
|
121
|
+
p = path_1.default.join(base, p);
|
|
122
|
+
if (win32) {
|
|
123
|
+
p = p.replace(/\\/g, '/');
|
|
124
|
+
}
|
|
125
|
+
if (negate) {
|
|
126
|
+
p = `!${p}`;
|
|
127
|
+
}
|
|
128
|
+
return p;
|
|
129
|
+
}
|
|
130
|
+
function collect(ps) {
|
|
131
|
+
return globby_1.default.sync(ps, { dot: true });
|
|
132
|
+
}
|
|
133
|
+
function expandFiles(efs, base) {
|
|
134
|
+
if (!Array.isArray(efs)) {
|
|
135
|
+
efs = [efs];
|
|
136
|
+
}
|
|
137
|
+
efs = collect(efs.map((p) => upon(p, base)));
|
|
138
|
+
return efs;
|
|
139
|
+
}
|
|
140
|
+
async function stepRead(record) {
|
|
141
|
+
if (strictVerify) {
|
|
142
|
+
(0, assert_1.default)(record.file === (0, common_1.toNormalizedRealPath)(record.file));
|
|
143
|
+
}
|
|
144
|
+
let body;
|
|
145
|
+
try {
|
|
146
|
+
body = await fs_extra_1.default.readFile(record.file);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
const exception = error;
|
|
150
|
+
log_1.log.error(`Cannot read file, ${exception.code}`, record.file);
|
|
151
|
+
throw (0, log_1.wasReported)(exception.message);
|
|
152
|
+
}
|
|
153
|
+
record.body = body;
|
|
154
|
+
}
|
|
155
|
+
function stepStrip(record) {
|
|
156
|
+
let body = (record.body || '').toString('utf8');
|
|
157
|
+
if (/^\ufeff/.test(body)) {
|
|
158
|
+
body = body.replace(/^\ufeff/, '');
|
|
159
|
+
}
|
|
160
|
+
if (/^#!/.test(body)) {
|
|
161
|
+
body = body.replace(/^#![^\n]*\n/, '\n');
|
|
162
|
+
}
|
|
163
|
+
record.body = body;
|
|
164
|
+
}
|
|
165
|
+
function stepDetect(record, marker, derivatives) {
|
|
166
|
+
let { body = '' } = record;
|
|
167
|
+
if (body instanceof Buffer) {
|
|
168
|
+
body = body.toString();
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
detector.detect(body, (node, trying) => {
|
|
172
|
+
const { toplevel } = marker;
|
|
173
|
+
let d = detector.visitorSuccessful(node);
|
|
174
|
+
if (d) {
|
|
175
|
+
if (d.mustExclude) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
d.mayExclude = d.mayExclude || trying;
|
|
179
|
+
derivatives.push(d);
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
d = detector.visitorNonLiteral(node);
|
|
183
|
+
if (d) {
|
|
184
|
+
if (typeof d === 'object' && d.mustExclude) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
const debug = !toplevel || d.mayExclude || trying;
|
|
188
|
+
const level = debug ? 'debug' : 'warn';
|
|
189
|
+
log_1.log[level](`Cannot resolve '${d.alias}'`, [
|
|
190
|
+
record.file,
|
|
191
|
+
'Dynamic require may fail at run time, because the requested file',
|
|
192
|
+
'is unknown at compilation time and not included into executable.',
|
|
193
|
+
"Use a string literal as an argument for 'require', or leave it",
|
|
194
|
+
"as is and specify the resolved file name in 'scripts' option.",
|
|
195
|
+
]);
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
d = detector.visitorMalformed(node);
|
|
199
|
+
if (d) {
|
|
200
|
+
// there is no 'mustExclude'
|
|
201
|
+
const debug = !toplevel || trying;
|
|
202
|
+
const level = debug ? 'debug' : 'warn'; // there is no 'mayExclude'
|
|
203
|
+
log_1.log[level](`Malformed requirement for '${d.alias}'`, [record.file]);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
d = detector.visitorUseSCWD(node);
|
|
207
|
+
if (d) {
|
|
208
|
+
// there is no 'mustExclude'
|
|
209
|
+
const level = 'debug'; // there is no 'mayExclude'
|
|
210
|
+
log_1.log[level](`Path.resolve(${d.alias}) is ambiguous`, [
|
|
211
|
+
record.file,
|
|
212
|
+
"It resolves relatively to 'process.cwd' by default, however",
|
|
213
|
+
"you may want to use 'path.dirname(require.main.filename)'",
|
|
214
|
+
]);
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
return true; // can i go inside?
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
log_1.log.error(error.message, record.file);
|
|
222
|
+
throw (0, log_1.wasReported)(error.message);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function findCommonJunctionPoint(file, realFile) {
|
|
226
|
+
// find common denominator => where the link changes
|
|
227
|
+
while ((0, common_1.toNormalizedRealPath)(path_1.default.dirname(file)) === path_1.default.dirname(realFile)) {
|
|
228
|
+
file = path_1.default.dirname(file);
|
|
229
|
+
realFile = path_1.default.dirname(realFile);
|
|
230
|
+
}
|
|
231
|
+
return { file, realFile };
|
|
232
|
+
}
|
|
233
|
+
class Walker {
|
|
234
|
+
constructor() {
|
|
235
|
+
this.tasks = [];
|
|
236
|
+
this.records = {};
|
|
237
|
+
this.dictionary = {};
|
|
238
|
+
this.patches = {};
|
|
239
|
+
this.params = {};
|
|
240
|
+
this.symLinks = {};
|
|
241
|
+
}
|
|
242
|
+
appendRecord({ file, store }) {
|
|
243
|
+
if (this.records[file]) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (store === common_1.STORE_BLOB ||
|
|
247
|
+
store === common_1.STORE_CONTENT ||
|
|
248
|
+
store === common_1.STORE_LINKS) {
|
|
249
|
+
// make sure we have a real file
|
|
250
|
+
if (strictVerify) {
|
|
251
|
+
(0, assert_1.default)(file === (0, common_1.toNormalizedRealPath)(file));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
this.records[file] = { file };
|
|
255
|
+
}
|
|
256
|
+
append(task) {
|
|
257
|
+
if (strictVerify) {
|
|
258
|
+
(0, assert_1.default)(typeof task.file === 'string');
|
|
259
|
+
(0, assert_1.default)(task.file === (0, common_1.normalizePath)(task.file));
|
|
260
|
+
}
|
|
261
|
+
this.appendRecord(task);
|
|
262
|
+
this.tasks.push(task);
|
|
263
|
+
const what = {
|
|
264
|
+
[common_1.STORE_BLOB]: 'Bytecode of',
|
|
265
|
+
[common_1.STORE_CONTENT]: 'Content of',
|
|
266
|
+
[common_1.STORE_LINKS]: 'Directory',
|
|
267
|
+
[common_1.STORE_STAT]: 'Stat info of',
|
|
268
|
+
}[task.store];
|
|
269
|
+
if (task.reason) {
|
|
270
|
+
log_1.log.debug(`${what} ${task.file} is added to queue. It was required from ${task.reason}`);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
log_1.log.debug(`${what} ${task.file} is added to queue.`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
appendSymlink(file, realFile) {
|
|
277
|
+
const a = findCommonJunctionPoint(file, realFile);
|
|
278
|
+
file = a.file;
|
|
279
|
+
realFile = a.realFile;
|
|
280
|
+
if (!this.symLinks[file]) {
|
|
281
|
+
const dn = path_1.default.dirname(file);
|
|
282
|
+
this.appendFileInFolder({
|
|
283
|
+
file: dn,
|
|
284
|
+
store: common_1.STORE_LINKS,
|
|
285
|
+
data: path_1.default.basename(file),
|
|
286
|
+
});
|
|
287
|
+
log_1.log.debug(`adding symlink ${file} => ${path_1.default.relative(file, realFile)}`);
|
|
288
|
+
this.symLinks[file] = realFile;
|
|
289
|
+
this.appendStat({
|
|
290
|
+
file: realFile,
|
|
291
|
+
store: common_1.STORE_STAT,
|
|
292
|
+
});
|
|
293
|
+
this.appendStat({
|
|
294
|
+
file: dn,
|
|
295
|
+
store: common_1.STORE_STAT,
|
|
296
|
+
});
|
|
297
|
+
this.appendStat({
|
|
298
|
+
file,
|
|
299
|
+
store: common_1.STORE_STAT,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
appendStat(task) {
|
|
304
|
+
(0, assert_1.default)(task.store === common_1.STORE_STAT);
|
|
305
|
+
this.append(task);
|
|
306
|
+
}
|
|
307
|
+
appendFileInFolder(task) {
|
|
308
|
+
if (strictVerify) {
|
|
309
|
+
(0, assert_1.default)(task.store === common_1.STORE_LINKS);
|
|
310
|
+
(0, assert_1.default)(typeof task.file === 'string');
|
|
311
|
+
}
|
|
312
|
+
const realFile = (0, common_1.toNormalizedRealPath)(task.file);
|
|
313
|
+
if (realFile === task.file) {
|
|
314
|
+
this.append(task);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this.append(Object.assign(Object.assign({}, task), { file: realFile }));
|
|
318
|
+
this.appendStat({
|
|
319
|
+
file: task.file,
|
|
320
|
+
store: common_1.STORE_STAT,
|
|
321
|
+
});
|
|
322
|
+
this.appendStat({
|
|
323
|
+
file: path_1.default.dirname(task.file),
|
|
324
|
+
store: common_1.STORE_STAT,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
appendBlobOrContent(task) {
|
|
328
|
+
if (strictVerify) {
|
|
329
|
+
(0, assert_1.default)(task.file === (0, common_1.normalizePath)(task.file));
|
|
330
|
+
}
|
|
331
|
+
(0, assert_1.default)(task.store === common_1.STORE_BLOB || task.store === common_1.STORE_CONTENT);
|
|
332
|
+
(0, assert_1.default)(typeof task.file === 'string');
|
|
333
|
+
const realFile = (0, common_1.toNormalizedRealPath)(task.file);
|
|
334
|
+
if (realFile === task.file) {
|
|
335
|
+
this.append(task);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
this.append(Object.assign(Object.assign({}, task), { file: realFile }));
|
|
339
|
+
this.appendSymlink(task.file, realFile);
|
|
340
|
+
this.appendStat({
|
|
341
|
+
file: task.file,
|
|
342
|
+
store: common_1.STORE_STAT,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async appendFilesFromConfig(marker) {
|
|
346
|
+
const { config, configPath, base } = marker;
|
|
347
|
+
const pkgConfig = config === null || config === void 0 ? void 0 : config.pkg;
|
|
348
|
+
if (pkgConfig) {
|
|
349
|
+
let { scripts } = pkgConfig;
|
|
350
|
+
if (scripts) {
|
|
351
|
+
scripts = expandFiles(scripts, base);
|
|
352
|
+
for (const script of scripts) {
|
|
353
|
+
const stat = await fs_extra_1.default.stat(script);
|
|
354
|
+
if (stat.isFile()) {
|
|
355
|
+
if (!(0, common_1.isDotJS)(script) && !(0, common_1.isDotJSON)(script) && !(0, common_1.isDotNODE)(script)) {
|
|
356
|
+
log_1.log.warn("Non-javascript file is specified in 'scripts'.", [
|
|
357
|
+
'Pkg will probably fail to parse. Specify *.js in glob.',
|
|
358
|
+
script,
|
|
359
|
+
]);
|
|
360
|
+
}
|
|
361
|
+
this.appendBlobOrContent({
|
|
362
|
+
file: (0, common_1.normalizePath)(script),
|
|
363
|
+
marker,
|
|
364
|
+
store: common_1.STORE_BLOB,
|
|
365
|
+
reason: configPath,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
let { assets } = pkgConfig;
|
|
371
|
+
if (assets) {
|
|
372
|
+
assets = expandFiles(assets, base);
|
|
373
|
+
for (const asset of assets) {
|
|
374
|
+
log_1.log.debug(' Adding asset : .... ', asset);
|
|
375
|
+
const stat = await fs_extra_1.default.stat(asset);
|
|
376
|
+
if (stat.isFile()) {
|
|
377
|
+
this.appendBlobOrContent({
|
|
378
|
+
file: (0, common_1.normalizePath)(asset),
|
|
379
|
+
marker,
|
|
380
|
+
store: common_1.STORE_CONTENT,
|
|
381
|
+
reason: configPath,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else if (config) {
|
|
388
|
+
let { files } = config;
|
|
389
|
+
if (files) {
|
|
390
|
+
files = expandFiles(files, base);
|
|
391
|
+
for (let file of files) {
|
|
392
|
+
file = (0, common_1.normalizePath)(file);
|
|
393
|
+
const stat = await fs_extra_1.default.stat(file);
|
|
394
|
+
if (stat.isFile()) {
|
|
395
|
+
// 1) remove sources of top-level(!) package 'files' i.e. ship as BLOB
|
|
396
|
+
// 2) non-source (non-js) files of top-level package are shipped as CONTENT
|
|
397
|
+
// 3) parsing some js 'files' of non-top-level packages fails, hence all CONTENT
|
|
398
|
+
if (marker.toplevel) {
|
|
399
|
+
this.appendBlobOrContent({
|
|
400
|
+
file,
|
|
401
|
+
marker,
|
|
402
|
+
store: (0, common_1.isDotJS)(file) ? common_1.STORE_BLOB : common_1.STORE_CONTENT,
|
|
403
|
+
reason: configPath,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
this.appendBlobOrContent({
|
|
408
|
+
file,
|
|
409
|
+
marker,
|
|
410
|
+
store: common_1.STORE_CONTENT,
|
|
411
|
+
reason: configPath,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
async stepActivate(marker, derivatives) {
|
|
420
|
+
if (!marker) {
|
|
421
|
+
(0, assert_1.default)(false);
|
|
422
|
+
}
|
|
423
|
+
if (marker.activated) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const { config, base } = marker;
|
|
427
|
+
if (!config) {
|
|
428
|
+
(0, assert_1.default)(false);
|
|
429
|
+
}
|
|
430
|
+
const { name } = config;
|
|
431
|
+
if (name) {
|
|
432
|
+
const d = this.dictionary[name];
|
|
433
|
+
if (d) {
|
|
434
|
+
if (typeof config.dependencies === 'object' &&
|
|
435
|
+
typeof d.dependencies === 'object') {
|
|
436
|
+
Object.assign(config.dependencies, d.dependencies);
|
|
437
|
+
delete d.dependencies;
|
|
438
|
+
}
|
|
439
|
+
Object.assign(config, d);
|
|
440
|
+
marker.hasDictionary = true;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const { dependencies } = config;
|
|
444
|
+
if (typeof dependencies === 'object') {
|
|
445
|
+
for (const dependency in dependencies) {
|
|
446
|
+
// it may be `undefined` - overridden
|
|
447
|
+
// in dictionary (see publicsuffixlist)
|
|
448
|
+
if (dependencies[dependency]) {
|
|
449
|
+
derivatives.push({
|
|
450
|
+
alias: dependency,
|
|
451
|
+
aliasType: common_1.ALIAS_AS_RESOLVABLE,
|
|
452
|
+
fromDependencies: true,
|
|
453
|
+
});
|
|
454
|
+
derivatives.push({
|
|
455
|
+
alias: `${dependency}/package.json`,
|
|
456
|
+
aliasType: common_1.ALIAS_AS_RESOLVABLE,
|
|
457
|
+
fromDependencies: true,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const pkgConfig = config.pkg;
|
|
463
|
+
if (pkgConfig) {
|
|
464
|
+
const { patches } = pkgConfig;
|
|
465
|
+
if (patches) {
|
|
466
|
+
for (const key in patches) {
|
|
467
|
+
if (patches[key]) {
|
|
468
|
+
const p = path_1.default.join(base, key);
|
|
469
|
+
this.patches[p] = patches[key];
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const { deployFiles } = pkgConfig;
|
|
474
|
+
if (deployFiles) {
|
|
475
|
+
marker.hasDeployFiles = true;
|
|
476
|
+
for (const deployFile of deployFiles) {
|
|
477
|
+
const type = deployFile[2] || 'file';
|
|
478
|
+
log_1.log.warn(`Cannot include ${type} %1 into executable.`, [
|
|
479
|
+
`The ${type} must be distributed with executable as %2.`,
|
|
480
|
+
`%1: ${path_1.default.relative(process.cwd(), path_1.default.join(base, deployFile[0]))}`,
|
|
481
|
+
`%2: path-to-executable/${deployFile[1]}`,
|
|
482
|
+
]);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (pkgConfig.log) {
|
|
486
|
+
pkgConfig.log(log_1.log, { packagePath: base });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
await this.appendFilesFromConfig(marker);
|
|
490
|
+
marker.public = isPublic(config);
|
|
491
|
+
if (!marker.public && marker.toplevel) {
|
|
492
|
+
marker.public = this.params.publicToplevel;
|
|
493
|
+
}
|
|
494
|
+
if (!marker.public && !marker.toplevel && this.params.publicPackages) {
|
|
495
|
+
marker.public =
|
|
496
|
+
this.params.publicPackages[0] === '*' ||
|
|
497
|
+
(!!name && this.params.publicPackages.indexOf(name) !== -1);
|
|
498
|
+
}
|
|
499
|
+
marker.activated = true;
|
|
500
|
+
// assert no further work with config
|
|
501
|
+
delete marker.config;
|
|
502
|
+
}
|
|
503
|
+
hasPatch(record) {
|
|
504
|
+
const patch = this.patches[record.file];
|
|
505
|
+
if (!patch) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
stepPatch(record) {
|
|
511
|
+
const patch = this.patches[record.file];
|
|
512
|
+
if (!patch) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
let body = (record.body || '').toString('utf8');
|
|
516
|
+
for (let i = 0; i < patch.length; i += 2) {
|
|
517
|
+
if (typeof patch[i] === 'object') {
|
|
518
|
+
if (patch[i].do === 'erase') {
|
|
519
|
+
body = patch[i + 1];
|
|
520
|
+
}
|
|
521
|
+
else if (patch[i].do === 'prepend') {
|
|
522
|
+
body = patch[i + 1] + body;
|
|
523
|
+
}
|
|
524
|
+
else if (patch[i].do === 'append') {
|
|
525
|
+
body += patch[i + 1];
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else if (typeof patch[i] === 'string') {
|
|
529
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
530
|
+
// function escapeRegExp
|
|
531
|
+
const esc = patch[i].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
532
|
+
const regexp = new RegExp(esc, 'g');
|
|
533
|
+
body = body.replace(regexp, patch[i + 1]);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
record.body = body;
|
|
537
|
+
}
|
|
538
|
+
async stepDerivatives_ALIAS_AS_RELATIVE(record, marker, derivative) {
|
|
539
|
+
const file = (0, common_1.normalizePath)(path_1.default.join(path_1.default.dirname(record.file), derivative.alias));
|
|
540
|
+
let stat;
|
|
541
|
+
try {
|
|
542
|
+
stat = await fs_extra_1.default.stat(file);
|
|
543
|
+
}
|
|
544
|
+
catch (error) {
|
|
545
|
+
const { toplevel } = marker;
|
|
546
|
+
const exception = error;
|
|
547
|
+
const debug = !toplevel && exception.code === 'ENOENT';
|
|
548
|
+
const level = debug ? 'debug' : 'warn';
|
|
549
|
+
log_1.log[level](`Cannot stat, ${exception.code}`, [
|
|
550
|
+
file,
|
|
551
|
+
`The file was required from '${record.file}'`,
|
|
552
|
+
]);
|
|
553
|
+
}
|
|
554
|
+
if (stat && stat.isFile()) {
|
|
555
|
+
this.appendBlobOrContent({
|
|
556
|
+
file,
|
|
557
|
+
marker,
|
|
558
|
+
store: common_1.STORE_CONTENT,
|
|
559
|
+
reason: record.file,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
async stepDerivatives_ALIAS_AS_RESOLVABLE(record, marker, derivative) {
|
|
564
|
+
var _a, _b;
|
|
565
|
+
const newPackages = [];
|
|
566
|
+
const catchReadFile = (file) => {
|
|
567
|
+
(0, assert_1.default)((0, common_1.isPackageJson)(file), `walker: ${file} must be package.json`);
|
|
568
|
+
newPackages.push({ packageJson: file });
|
|
569
|
+
};
|
|
570
|
+
const catchPackageFilter = (config, base) => {
|
|
571
|
+
const newPackage = newPackages[newPackages.length - 1];
|
|
572
|
+
newPackage.marker = { config, configPath: newPackage.packageJson, base };
|
|
573
|
+
};
|
|
574
|
+
let newFile = '';
|
|
575
|
+
let failure;
|
|
576
|
+
const basedir = path_1.default.dirname(record.file);
|
|
577
|
+
try {
|
|
578
|
+
newFile = await (0, follow_1.follow)(derivative.alias, {
|
|
579
|
+
basedir,
|
|
580
|
+
// default is extensions: ['.js'], but
|
|
581
|
+
// it is not enough because 'typos.json'
|
|
582
|
+
// is not taken in require('./typos')
|
|
583
|
+
// in 'normalize-package-data/lib/fixer.js'
|
|
584
|
+
extensions: ['.js', '.json', '.node'],
|
|
585
|
+
catchReadFile,
|
|
586
|
+
catchPackageFilter,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
failure = error;
|
|
591
|
+
}
|
|
592
|
+
if (failure) {
|
|
593
|
+
const { toplevel } = marker;
|
|
594
|
+
const mainNotFound = newPackages.length > 0 && !((_b = (_a = newPackages[0].marker) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.main);
|
|
595
|
+
const debug = !toplevel ||
|
|
596
|
+
derivative.mayExclude ||
|
|
597
|
+
(mainNotFound && derivative.fromDependencies);
|
|
598
|
+
const level = debug ? 'debug' : 'warn';
|
|
599
|
+
if (mainNotFound) {
|
|
600
|
+
const message = "Entry 'main' not found in %1";
|
|
601
|
+
log_1.log[level](message, [
|
|
602
|
+
`%1: ${newPackages[0].packageJson}`,
|
|
603
|
+
`%2: ${record.file}`,
|
|
604
|
+
]);
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
log_1.log[level](`${chalk_1.default.yellow(failure.message)} in ${record.file}`);
|
|
608
|
+
}
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
let newPackageForNewRecords;
|
|
612
|
+
for (const newPackage of newPackages) {
|
|
613
|
+
let newFile2;
|
|
614
|
+
try {
|
|
615
|
+
newFile2 = await (0, follow_1.follow)(derivative.alias, {
|
|
616
|
+
basedir: path_1.default.dirname(record.file),
|
|
617
|
+
extensions: ['.js', '.json', '.node'],
|
|
618
|
+
ignoreFile: newPackage.packageJson,
|
|
619
|
+
});
|
|
620
|
+
if (strictVerify) {
|
|
621
|
+
(0, assert_1.default)(newFile2 === (0, common_1.normalizePath)(newFile2));
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
catch (_) {
|
|
625
|
+
// not setting is enough
|
|
626
|
+
}
|
|
627
|
+
if (newFile2 !== newFile) {
|
|
628
|
+
newPackageForNewRecords = newPackage;
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (newPackageForNewRecords) {
|
|
633
|
+
if (strictVerify) {
|
|
634
|
+
(0, assert_1.default)(newPackageForNewRecords.packageJson ===
|
|
635
|
+
(0, common_1.normalizePath)(newPackageForNewRecords.packageJson));
|
|
636
|
+
}
|
|
637
|
+
this.appendBlobOrContent({
|
|
638
|
+
file: newPackageForNewRecords.packageJson,
|
|
639
|
+
marker: newPackageForNewRecords.marker,
|
|
640
|
+
store: common_1.STORE_CONTENT,
|
|
641
|
+
reason: record.file,
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
this.appendBlobOrContent({
|
|
645
|
+
file: newFile,
|
|
646
|
+
marker: newPackageForNewRecords ? newPackageForNewRecords.marker : marker,
|
|
647
|
+
store: common_1.STORE_BLOB,
|
|
648
|
+
reason: record.file,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
async stepDerivatives(record, marker, derivatives) {
|
|
652
|
+
for (const derivative of derivatives) {
|
|
653
|
+
// TODO: actually use the target node version
|
|
654
|
+
if ((0, is_core_module_1.default)(derivative.alias, '99.0.0'))
|
|
655
|
+
continue;
|
|
656
|
+
switch (derivative.aliasType) {
|
|
657
|
+
case common_1.ALIAS_AS_RELATIVE:
|
|
658
|
+
await this.stepDerivatives_ALIAS_AS_RELATIVE(record, marker, derivative);
|
|
659
|
+
break;
|
|
660
|
+
case common_1.ALIAS_AS_RESOLVABLE:
|
|
661
|
+
await this.stepDerivatives_ALIAS_AS_RESOLVABLE(record, marker, derivative);
|
|
662
|
+
break;
|
|
663
|
+
default:
|
|
664
|
+
(0, assert_1.default)(false, `walker: unknown aliasType ${derivative.aliasType}`);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
async step_STORE_ANY(record, marker, store) {
|
|
669
|
+
if (strictVerify) {
|
|
670
|
+
(0, assert_1.default)(record.file === (0, common_1.toNormalizedRealPath)(record.file));
|
|
671
|
+
}
|
|
672
|
+
if (record[store] !== undefined)
|
|
673
|
+
return;
|
|
674
|
+
record[store] = false; // default is discard
|
|
675
|
+
this.appendStat({
|
|
676
|
+
file: record.file,
|
|
677
|
+
store: common_1.STORE_STAT,
|
|
678
|
+
});
|
|
679
|
+
const derivatives1 = [];
|
|
680
|
+
await this.stepActivate(marker, derivatives1);
|
|
681
|
+
await this.stepDerivatives(record, marker, derivatives1);
|
|
682
|
+
if (store === common_1.STORE_BLOB) {
|
|
683
|
+
if (unlikelyJavascript(record.file) || (0, common_1.isDotNODE)(record.file)) {
|
|
684
|
+
this.appendBlobOrContent({
|
|
685
|
+
file: record.file,
|
|
686
|
+
marker,
|
|
687
|
+
store: common_1.STORE_CONTENT,
|
|
688
|
+
});
|
|
689
|
+
return; // discard
|
|
690
|
+
}
|
|
691
|
+
if (marker.public || marker.hasDictionary) {
|
|
692
|
+
this.appendBlobOrContent({
|
|
693
|
+
file: record.file,
|
|
694
|
+
marker,
|
|
695
|
+
store: common_1.STORE_CONTENT,
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (store === common_1.STORE_BLOB || this.hasPatch(record)) {
|
|
700
|
+
if (!record.body) {
|
|
701
|
+
await stepRead(record);
|
|
702
|
+
this.stepPatch(record);
|
|
703
|
+
if (store === common_1.STORE_BLOB) {
|
|
704
|
+
stepStrip(record);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (store === common_1.STORE_BLOB) {
|
|
708
|
+
const derivatives2 = [];
|
|
709
|
+
stepDetect(record, marker, derivatives2);
|
|
710
|
+
await this.stepDerivatives(record, marker, derivatives2);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
record[store] = true;
|
|
714
|
+
}
|
|
715
|
+
step_STORE_LINKS(record, data) {
|
|
716
|
+
if (strictVerify) {
|
|
717
|
+
(0, assert_1.default)(record.file === (0, common_1.toNormalizedRealPath)(record.file), ' expecting real file !!!');
|
|
718
|
+
}
|
|
719
|
+
if (record[common_1.STORE_LINKS]) {
|
|
720
|
+
record[common_1.STORE_LINKS].push(data);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
record[common_1.STORE_LINKS] = [data];
|
|
724
|
+
if (record[common_1.STORE_STAT]) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
this.appendStat({
|
|
728
|
+
file: record.file,
|
|
729
|
+
store: common_1.STORE_STAT,
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
async step_STORE_STAT(record) {
|
|
733
|
+
if (record[common_1.STORE_STAT])
|
|
734
|
+
return;
|
|
735
|
+
const realPath = (0, common_1.toNormalizedRealPath)(record.file);
|
|
736
|
+
if (realPath !== record.file) {
|
|
737
|
+
this.appendStat({
|
|
738
|
+
file: realPath,
|
|
739
|
+
store: common_1.STORE_STAT,
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
try {
|
|
743
|
+
const valueStat = await fs_extra_1.default.stat(record.file);
|
|
744
|
+
const value = {
|
|
745
|
+
mode: valueStat.mode,
|
|
746
|
+
size: valueStat.isFile() ? valueStat.size : 0,
|
|
747
|
+
isFileValue: valueStat.isFile(),
|
|
748
|
+
isDirectoryValue: valueStat.isDirectory(),
|
|
749
|
+
isSocketValue: valueStat.isSocket(),
|
|
750
|
+
isSymbolicLinkValue: valueStat.isSymbolicLink(),
|
|
751
|
+
};
|
|
752
|
+
record[common_1.STORE_STAT] = value;
|
|
753
|
+
}
|
|
754
|
+
catch (error) {
|
|
755
|
+
const exception = error;
|
|
756
|
+
log_1.log.error(`Cannot stat, ${exception.code}`, record.file);
|
|
757
|
+
throw (0, log_1.wasReported)(exception.message);
|
|
758
|
+
}
|
|
759
|
+
if (path_1.default.dirname(record.file) !== record.file) {
|
|
760
|
+
// root directory
|
|
761
|
+
this.appendFileInFolder({
|
|
762
|
+
file: path_1.default.dirname(record.file),
|
|
763
|
+
store: common_1.STORE_LINKS,
|
|
764
|
+
data: path_1.default.basename(record.file),
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
async step(task) {
|
|
769
|
+
const { file, store, data } = task;
|
|
770
|
+
const record = this.records[file];
|
|
771
|
+
switch (store) {
|
|
772
|
+
case common_1.STORE_BLOB:
|
|
773
|
+
case common_1.STORE_CONTENT:
|
|
774
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
775
|
+
await this.step_STORE_ANY(record, task.marker, store);
|
|
776
|
+
break;
|
|
777
|
+
case common_1.STORE_LINKS:
|
|
778
|
+
this.step_STORE_LINKS(record, data);
|
|
779
|
+
break;
|
|
780
|
+
case common_1.STORE_STAT:
|
|
781
|
+
await this.step_STORE_STAT(record);
|
|
782
|
+
break;
|
|
783
|
+
default:
|
|
784
|
+
(0, assert_1.default)(false, `walker: unknown store ${store}`);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
async readDictionary(marker) {
|
|
788
|
+
var _a, _b, _c;
|
|
789
|
+
if (((_a = this.params.noDictionary) === null || _a === void 0 ? void 0 : _a[0]) === '*') {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const dd = path_1.default.join(__dirname, '../dictionary');
|
|
793
|
+
const files = await fs_extra_1.default.readdir(dd);
|
|
794
|
+
for (const file of files) {
|
|
795
|
+
if (/\.js$/.test(file)) {
|
|
796
|
+
const name = file.slice(0, -3);
|
|
797
|
+
if ((_b = this.params.noDictionary) === null || _b === void 0 ? void 0 : _b.includes(file)) {
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
|
|
801
|
+
const config = require(path_1.default.join(dd, file));
|
|
802
|
+
this.dictionary[name] = config;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const pkgConfig = (_c = marker.config) === null || _c === void 0 ? void 0 : _c.pkg;
|
|
806
|
+
if (pkgConfig) {
|
|
807
|
+
const { dictionary } = pkgConfig;
|
|
808
|
+
if (dictionary) {
|
|
809
|
+
for (const name in dictionary) {
|
|
810
|
+
if (dictionary[name]) {
|
|
811
|
+
this.dictionary[name] = { pkg: dictionary[name] };
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
async start(marker, entrypoint, addition, params) {
|
|
818
|
+
this.params = params;
|
|
819
|
+
this.symLinks = {};
|
|
820
|
+
await this.readDictionary(marker);
|
|
821
|
+
entrypoint = (0, common_1.normalizePath)(entrypoint);
|
|
822
|
+
this.appendBlobOrContent({
|
|
823
|
+
file: entrypoint,
|
|
824
|
+
marker,
|
|
825
|
+
store: common_1.STORE_BLOB,
|
|
826
|
+
});
|
|
827
|
+
if (addition) {
|
|
828
|
+
addition = (0, common_1.normalizePath)(addition);
|
|
829
|
+
this.appendBlobOrContent({
|
|
830
|
+
file: addition,
|
|
831
|
+
marker,
|
|
832
|
+
store: common_1.STORE_CONTENT,
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
const { tasks } = this;
|
|
836
|
+
for (let i = 0; i < tasks.length; i += 1) {
|
|
837
|
+
// NO MULTIPLE WORKERS! THIS WILL LEAD TO NON-DETERMINISTIC
|
|
838
|
+
// ORDER. one-by-one fifo is the only way to iterate tasks
|
|
839
|
+
await this.step(tasks[i]);
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
symLinks: this.symLinks,
|
|
843
|
+
records: this.records,
|
|
844
|
+
entrypoint: (0, common_1.normalizePath)(entrypoint),
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
async function walker(...args) {
|
|
849
|
+
const w = new Walker();
|
|
850
|
+
return w.start(...args);
|
|
851
|
+
}
|
|
852
|
+
exports.default = walker;
|
|
853
|
+
//# sourceMappingURL=walker.js.map
|