format: prettify entire project
This commit is contained in:
27
node_modules/pkg/lib-es5/bin.js
generated
vendored
27
node_modules/pkg/lib-es5/bin.js
generated
vendored
@ -1,19 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const index_1 = require("./index");
|
||||
const log_1 = require("./log");
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
const index_1 = require('./index');
|
||||
const log_1 = require('./log');
|
||||
async function main() {
|
||||
if (process.env.CHDIR && process.env.CHDIR !== process.cwd()) {
|
||||
// allow to override cwd by CHDIR env var
|
||||
// https://github.com/resin-io/etcher/pull/1713
|
||||
process.chdir(process.env.CHDIR);
|
||||
}
|
||||
await (0, index_1.exec)(process.argv.slice(2));
|
||||
if (process.env.CHDIR && process.env.CHDIR !== process.cwd()) {
|
||||
// allow to override cwd by CHDIR env var
|
||||
// https://github.com/resin-io/etcher/pull/1713
|
||||
process.chdir(process.env.CHDIR);
|
||||
}
|
||||
await (0, index_1.exec)(process.argv.slice(2));
|
||||
}
|
||||
main().catch((error) => {
|
||||
if (!error.wasReported)
|
||||
log_1.log.error(error);
|
||||
process.exit(2);
|
||||
if (!error.wasReported) log_1.log.error(error);
|
||||
process.exit(2);
|
||||
});
|
||||
//# sourceMappingURL=bin.js.map
|
||||
//# sourceMappingURL=bin.js.map
|
||||
|
22
node_modules/pkg/lib-es5/chmod.js
generated
vendored
22
node_modules/pkg/lib-es5/chmod.js
generated
vendored
@ -1,15 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.plusx = void 0;
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const fs_extra_1 = require('fs-extra');
|
||||
async function plusx(file) {
|
||||
const s = await (0, fs_extra_1.stat)(file);
|
||||
const newMode = s.mode | 64 | 8 | 1;
|
||||
if (s.mode === newMode) {
|
||||
return;
|
||||
}
|
||||
const base8 = newMode.toString(8).slice(-3);
|
||||
await (0, fs_extra_1.chmod)(file, base8);
|
||||
const s = await (0, fs_extra_1.stat)(file);
|
||||
const newMode = s.mode | 64 | 8 | 1;
|
||||
if (s.mode === newMode) {
|
||||
return;
|
||||
}
|
||||
const base8 = newMode.toString(8).slice(-3);
|
||||
await (0, fs_extra_1.chmod)(file, base8);
|
||||
}
|
||||
exports.plusx = plusx;
|
||||
//# sourceMappingURL=chmod.js.map
|
||||
//# sourceMappingURL=chmod.js.map
|
||||
|
343
node_modules/pkg/lib-es5/common.js
generated
vendored
343
node_modules/pkg/lib-es5/common.js
generated
vendored
@ -1,12 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toNormalizedRealPath = exports.removeUplevels = exports.stripSnapshot = exports.insideSnapshot = exports.snapshotify = exports.substituteDenominator = exports.retrieveDenominator = exports.isDotNODE = exports.isDotJSON = exports.isDotJS = exports.isPackageJson = exports.normalizePath = exports.isRootPath = exports.ALIAS_AS_RESOLVABLE = exports.ALIAS_AS_RELATIVE = exports.STORE_STAT = exports.STORE_LINKS = exports.STORE_CONTENT = exports.STORE_BLOB = void 0;
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
'use strict';
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.toNormalizedRealPath =
|
||||
exports.removeUplevels =
|
||||
exports.stripSnapshot =
|
||||
exports.insideSnapshot =
|
||||
exports.snapshotify =
|
||||
exports.substituteDenominator =
|
||||
exports.retrieveDenominator =
|
||||
exports.isDotNODE =
|
||||
exports.isDotJSON =
|
||||
exports.isDotJS =
|
||||
exports.isPackageJson =
|
||||
exports.normalizePath =
|
||||
exports.isRootPath =
|
||||
exports.ALIAS_AS_RESOLVABLE =
|
||||
exports.ALIAS_AS_RELATIVE =
|
||||
exports.STORE_STAT =
|
||||
exports.STORE_LINKS =
|
||||
exports.STORE_CONTENT =
|
||||
exports.STORE_BLOB =
|
||||
void 0;
|
||||
const assert_1 = __importDefault(require('assert'));
|
||||
const fs_1 = __importDefault(require('fs'));
|
||||
const path_1 = __importDefault(require('path'));
|
||||
exports.STORE_BLOB = 0;
|
||||
exports.STORE_CONTENT = 1;
|
||||
exports.STORE_LINKS = 2;
|
||||
@ -16,220 +37,214 @@ exports.ALIAS_AS_RESOLVABLE = 1; // require("package")
|
||||
const win32 = process.platform === 'win32';
|
||||
const hasURL = typeof URL !== 'undefined';
|
||||
function uppercaseDriveLetter(f) {
|
||||
if (f.slice(1, 3) !== ':\\')
|
||||
return f;
|
||||
return f[0].toUpperCase() + f.slice(1);
|
||||
if (f.slice(1, 3) !== ':\\') return f;
|
||||
return f[0].toUpperCase() + f.slice(1);
|
||||
}
|
||||
function removeTrailingSlashes(f) {
|
||||
if (f === '/') {
|
||||
return f; // dont remove from "/"
|
||||
if (f === '/') {
|
||||
return f; // dont remove from "/"
|
||||
}
|
||||
if (f.slice(1) === ':\\') {
|
||||
return f; // dont remove from "D:\"
|
||||
}
|
||||
let last = f.length - 1;
|
||||
while (true) {
|
||||
const char = f.charAt(last);
|
||||
if (char === '\\') {
|
||||
f = f.slice(0, -1);
|
||||
last -= 1;
|
||||
} else if (char === '/') {
|
||||
f = f.slice(0, -1);
|
||||
last -= 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (f.slice(1) === ':\\') {
|
||||
return f; // dont remove from "D:\"
|
||||
}
|
||||
let last = f.length - 1;
|
||||
while (true) {
|
||||
const char = f.charAt(last);
|
||||
if (char === '\\') {
|
||||
f = f.slice(0, -1);
|
||||
last -= 1;
|
||||
}
|
||||
else if (char === '/') {
|
||||
f = f.slice(0, -1);
|
||||
last -= 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
const isUrl = (p) => hasURL && p instanceof URL;
|
||||
function pathToString(p, win) {
|
||||
let result;
|
||||
if (Buffer.isBuffer(p)) {
|
||||
result = p.toString();
|
||||
}
|
||||
else if (isUrl(p)) {
|
||||
result = win ? p.pathname.replace(/^\//, '') : p.pathname;
|
||||
}
|
||||
else {
|
||||
result = p;
|
||||
}
|
||||
return result;
|
||||
let result;
|
||||
if (Buffer.isBuffer(p)) {
|
||||
result = p.toString();
|
||||
} else if (isUrl(p)) {
|
||||
result = win ? p.pathname.replace(/^\//, '') : p.pathname;
|
||||
} else {
|
||||
result = p;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function isRootPath(p) {
|
||||
let file = pathToString(p, false);
|
||||
if (file === '.') {
|
||||
file = path_1.default.resolve(file);
|
||||
}
|
||||
return path_1.default.dirname(file) === p;
|
||||
let file = pathToString(p, false);
|
||||
if (file === '.') {
|
||||
file = path_1.default.resolve(file);
|
||||
}
|
||||
return path_1.default.dirname(file) === p;
|
||||
}
|
||||
exports.isRootPath = isRootPath;
|
||||
function normalizePath(f) {
|
||||
let file = pathToString(f, win32);
|
||||
if (!/^.:$/.test(file)) {
|
||||
file = path_1.default.normalize(file);
|
||||
} // 'c:' -> 'c:.'
|
||||
if (win32) {
|
||||
file = uppercaseDriveLetter(file);
|
||||
}
|
||||
return removeTrailingSlashes(file);
|
||||
let file = pathToString(f, win32);
|
||||
if (!/^.:$/.test(file)) {
|
||||
file = path_1.default.normalize(file);
|
||||
} // 'c:' -> 'c:.'
|
||||
if (win32) {
|
||||
file = uppercaseDriveLetter(file);
|
||||
}
|
||||
return removeTrailingSlashes(file);
|
||||
}
|
||||
exports.normalizePath = normalizePath;
|
||||
function isPackageJson(file) {
|
||||
return path_1.default.basename(file) === 'package.json';
|
||||
return path_1.default.basename(file) === 'package.json';
|
||||
}
|
||||
exports.isPackageJson = isPackageJson;
|
||||
function isDotJS(file) {
|
||||
return path_1.default.extname(file) === '.js';
|
||||
return path_1.default.extname(file) === '.js';
|
||||
}
|
||||
exports.isDotJS = isDotJS;
|
||||
function isDotJSON(file) {
|
||||
return path_1.default.extname(file) === '.json';
|
||||
return path_1.default.extname(file) === '.json';
|
||||
}
|
||||
exports.isDotJSON = isDotJSON;
|
||||
function isDotNODE(file) {
|
||||
return path_1.default.extname(file) === '.node';
|
||||
return path_1.default.extname(file) === '.node';
|
||||
}
|
||||
exports.isDotNODE = isDotNODE;
|
||||
function replaceSlashes(file, slash) {
|
||||
if (/^.:\\/.test(file)) {
|
||||
if (slash === '/') {
|
||||
return file.slice(2).replace(/\\/g, '/');
|
||||
}
|
||||
if (/^.:\\/.test(file)) {
|
||||
if (slash === '/') {
|
||||
return file.slice(2).replace(/\\/g, '/');
|
||||
}
|
||||
else if (/^\//.test(file)) {
|
||||
if (slash === '\\') {
|
||||
return `C:${file.replace(/\//g, '\\')}`;
|
||||
}
|
||||
} else if (/^\//.test(file)) {
|
||||
if (slash === '\\') {
|
||||
return `C:${file.replace(/\//g, '\\')}`;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
function injectSnapshot(file) {
|
||||
if (/^.:\\/.test(file)) {
|
||||
// C:\path\to
|
||||
if (file.length === 3) {
|
||||
// C:\
|
||||
file = file.slice(0, -1);
|
||||
}
|
||||
// by convention, on windows we use C:\\snapshot
|
||||
return `C:\\snapshot${file.slice(2)}`;
|
||||
if (/^.:\\/.test(file)) {
|
||||
// C:\path\to
|
||||
if (file.length === 3) {
|
||||
// C:\
|
||||
file = file.slice(0, -1);
|
||||
}
|
||||
if (/^\//.test(file)) {
|
||||
// /home/user/project
|
||||
if (file.length === 1) {
|
||||
// /
|
||||
file = file.slice(0, -1);
|
||||
}
|
||||
return `/snapshot${file}`;
|
||||
// by convention, on windows we use C:\\snapshot
|
||||
return `C:\\snapshot${file.slice(2)}`;
|
||||
}
|
||||
if (/^\//.test(file)) {
|
||||
// /home/user/project
|
||||
if (file.length === 1) {
|
||||
// /
|
||||
file = file.slice(0, -1);
|
||||
}
|
||||
return file;
|
||||
return `/snapshot${file}`;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
function longestCommonLength(s1, s2) {
|
||||
const length = Math.min(s1.length, s2.length);
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
if (s1.charCodeAt(i) !== s2.charCodeAt(i)) {
|
||||
return i;
|
||||
}
|
||||
const length = Math.min(s1.length, s2.length);
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
if (s1.charCodeAt(i) !== s2.charCodeAt(i)) {
|
||||
return i;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
function withoutNodeModules(file) {
|
||||
return file.split(`${path_1.default.sep}node_modules${path_1.default.sep}`)[0];
|
||||
return file.split(
|
||||
`${path_1.default.sep}node_modules${path_1.default.sep}`
|
||||
)[0];
|
||||
}
|
||||
function retrieveDenominator(files) {
|
||||
(0, assert_1.default)(files.length > 0);
|
||||
let s1 = withoutNodeModules(files[0]) + path_1.default.sep;
|
||||
for (let i = 1; i < files.length; i += 1) {
|
||||
const s2 = withoutNodeModules(files[i]) + path_1.default.sep;
|
||||
s1 = s1.slice(0, longestCommonLength(s1, s2));
|
||||
}
|
||||
if (s1 === '') {
|
||||
return win32 ? 2 : 0;
|
||||
}
|
||||
return s1.lastIndexOf(path_1.default.sep);
|
||||
(0, assert_1.default)(files.length > 0);
|
||||
let s1 = withoutNodeModules(files[0]) + path_1.default.sep;
|
||||
for (let i = 1; i < files.length; i += 1) {
|
||||
const s2 = withoutNodeModules(files[i]) + path_1.default.sep;
|
||||
s1 = s1.slice(0, longestCommonLength(s1, s2));
|
||||
}
|
||||
if (s1 === '') {
|
||||
return win32 ? 2 : 0;
|
||||
}
|
||||
return s1.lastIndexOf(path_1.default.sep);
|
||||
}
|
||||
exports.retrieveDenominator = retrieveDenominator;
|
||||
function substituteDenominator(f, denominator) {
|
||||
const rootLength = win32 ? 2 : 0;
|
||||
return f.slice(0, rootLength) + f.slice(denominator);
|
||||
const rootLength = win32 ? 2 : 0;
|
||||
return f.slice(0, rootLength) + f.slice(denominator);
|
||||
}
|
||||
exports.substituteDenominator = substituteDenominator;
|
||||
function snapshotify(file, slash) {
|
||||
return injectSnapshot(replaceSlashes(file, slash));
|
||||
return injectSnapshot(replaceSlashes(file, slash));
|
||||
}
|
||||
exports.snapshotify = snapshotify;
|
||||
function insideSnapshot(f) {
|
||||
f = pathToString(f, win32);
|
||||
if (typeof f !== 'string') {
|
||||
return false;
|
||||
}
|
||||
if (win32) {
|
||||
const slice112 = f.slice(1, 12);
|
||||
return (slice112 === ':\\snapshot\\' ||
|
||||
slice112 === ':/snapshot\\' ||
|
||||
slice112 === ':\\snapshot/' ||
|
||||
slice112 === ':/snapshot/' ||
|
||||
slice112 === ':\\snapshot' ||
|
||||
slice112 === ':/snapshot');
|
||||
}
|
||||
const slice010 = f.slice(0, 10);
|
||||
return slice010 === '/snapshot/' || slice010 === '/snapshot';
|
||||
f = pathToString(f, win32);
|
||||
if (typeof f !== 'string') {
|
||||
return false;
|
||||
}
|
||||
if (win32) {
|
||||
const slice112 = f.slice(1, 12);
|
||||
return (
|
||||
slice112 === ':\\snapshot\\' ||
|
||||
slice112 === ':/snapshot\\' ||
|
||||
slice112 === ':\\snapshot/' ||
|
||||
slice112 === ':/snapshot/' ||
|
||||
slice112 === ':\\snapshot' ||
|
||||
slice112 === ':/snapshot'
|
||||
);
|
||||
}
|
||||
const slice010 = f.slice(0, 10);
|
||||
return slice010 === '/snapshot/' || slice010 === '/snapshot';
|
||||
}
|
||||
exports.insideSnapshot = insideSnapshot;
|
||||
function stripSnapshot(f) {
|
||||
const file = normalizePath(f);
|
||||
if (/^.:\\snapshot$/.test(file)) {
|
||||
return `${file[0]}:\\**\\`;
|
||||
}
|
||||
if (/^.:\\snapshot\\/.test(file)) {
|
||||
return `${file[0]}:\\**${file.slice(11)}`;
|
||||
}
|
||||
if (/^\/snapshot$/.test(file)) {
|
||||
return '/**/';
|
||||
}
|
||||
if (/^\/snapshot\//.test(file)) {
|
||||
return `/**${file.slice(9)}`;
|
||||
}
|
||||
return f; // not inside
|
||||
const file = normalizePath(f);
|
||||
if (/^.:\\snapshot$/.test(file)) {
|
||||
return `${file[0]}:\\**\\`;
|
||||
}
|
||||
if (/^.:\\snapshot\\/.test(file)) {
|
||||
return `${file[0]}:\\**${file.slice(11)}`;
|
||||
}
|
||||
if (/^\/snapshot$/.test(file)) {
|
||||
return '/**/';
|
||||
}
|
||||
if (/^\/snapshot\//.test(file)) {
|
||||
return `/**${file.slice(9)}`;
|
||||
}
|
||||
return f; // not inside
|
||||
}
|
||||
exports.stripSnapshot = stripSnapshot;
|
||||
function removeUplevels(f) {
|
||||
if (win32) {
|
||||
while (true) {
|
||||
if (f.slice(0, 3) === '..\\') {
|
||||
f = f.slice(3);
|
||||
}
|
||||
else if (f === '..') {
|
||||
f = '.';
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
if (win32) {
|
||||
while (true) {
|
||||
if (f.slice(0, 3) === '../') {
|
||||
f = f.slice(3);
|
||||
}
|
||||
else if (f === '..') {
|
||||
f = '.';
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
if (f.slice(0, 3) === '..\\') {
|
||||
f = f.slice(3);
|
||||
} else if (f === '..') {
|
||||
f = '.';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
while (true) {
|
||||
if (f.slice(0, 3) === '../') {
|
||||
f = f.slice(3);
|
||||
} else if (f === '..') {
|
||||
f = '.';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
exports.removeUplevels = removeUplevels;
|
||||
function toNormalizedRealPath(requestPath) {
|
||||
const file = normalizePath(requestPath);
|
||||
if (fs_1.default.existsSync(file)) {
|
||||
return fs_1.default.realpathSync(file);
|
||||
}
|
||||
return file;
|
||||
const file = normalizePath(requestPath);
|
||||
if (fs_1.default.existsSync(file)) {
|
||||
return fs_1.default.realpathSync(file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
exports.toNormalizedRealPath = toNormalizedRealPath;
|
||||
//# sourceMappingURL=common.js.map
|
||||
//# sourceMappingURL=common.js.map
|
||||
|
14
node_modules/pkg/lib-es5/compress_type.js
generated
vendored
14
node_modules/pkg/lib-es5/compress_type.js
generated
vendored
@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.CompressType = void 0;
|
||||
var CompressType;
|
||||
(function (CompressType) {
|
||||
CompressType[CompressType["None"] = 0] = "None";
|
||||
CompressType[CompressType["GZip"] = 1] = "GZip";
|
||||
CompressType[CompressType["Brotli"] = 2] = "Brotli";
|
||||
})(CompressType = exports.CompressType || (exports.CompressType = {}));
|
||||
//# sourceMappingURL=compress_type.js.map
|
||||
CompressType[(CompressType['None'] = 0)] = 'None';
|
||||
CompressType[(CompressType['GZip'] = 1)] = 'GZip';
|
||||
CompressType[(CompressType['Brotli'] = 2)] = 'Brotli';
|
||||
})((CompressType = exports.CompressType || (exports.CompressType = {})));
|
||||
//# sourceMappingURL=compress_type.js.map
|
||||
|
753
node_modules/pkg/lib-es5/detector.js
generated
vendored
753
node_modules/pkg/lib-es5/detector.js
generated
vendored
@ -1,420 +1,463 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
'use strict';
|
||||
var __createBinding =
|
||||
(this && this.__createBinding) ||
|
||||
(Object.create ?
|
||||
function (o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (
|
||||
!desc ||
|
||||
('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
|
||||
) {
|
||||
desc = {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return m[k];
|
||||
},
|
||||
};
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
: function (o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
});
|
||||
var __setModuleDefault =
|
||||
(this && this.__setModuleDefault) ||
|
||||
(Object.create ?
|
||||
function (o, v) {
|
||||
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
||||
}
|
||||
: function (o, v) {
|
||||
o['default'] = v;
|
||||
});
|
||||
var __importStar =
|
||||
(this && this.__importStar) ||
|
||||
function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
if (mod != null)
|
||||
for (var k in mod)
|
||||
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
||||
__createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.detect = exports.parse = exports.visitorUseSCWD = exports.visitorMalformed = exports.visitorNonLiteral = exports.visitorSuccessful = void 0;
|
||||
const babelTypes = __importStar(require("@babel/types"));
|
||||
const babel = __importStar(require("@babel/parser"));
|
||||
const generator_1 = __importDefault(require("@babel/generator"));
|
||||
const log_1 = require("./log");
|
||||
const common_1 = require("./common");
|
||||
};
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.detect =
|
||||
exports.parse =
|
||||
exports.visitorUseSCWD =
|
||||
exports.visitorMalformed =
|
||||
exports.visitorNonLiteral =
|
||||
exports.visitorSuccessful =
|
||||
void 0;
|
||||
const babelTypes = __importStar(require('@babel/types'));
|
||||
const babel = __importStar(require('@babel/parser'));
|
||||
const generator_1 = __importDefault(require('@babel/generator'));
|
||||
const log_1 = require('./log');
|
||||
const common_1 = require('./common');
|
||||
function isLiteral(node) {
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
if (!node.type.endsWith('Literal')) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === 'TemplateLiteral' && node.expressions.length !== 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
if (!node.type.endsWith('Literal')) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === 'TemplateLiteral' && node.expressions.length !== 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getLiteralValue(node) {
|
||||
if (node.type === 'TemplateLiteral') {
|
||||
return node.quasis[0].value.raw;
|
||||
}
|
||||
if (node.type === 'NullLiteral') {
|
||||
throw new Error('Unexpected null in require expression');
|
||||
}
|
||||
if (node.type === 'RegExpLiteral') {
|
||||
throw new Error('Unexpected regexp in require expression');
|
||||
}
|
||||
return node.value;
|
||||
if (node.type === 'TemplateLiteral') {
|
||||
return node.quasis[0].value.raw;
|
||||
}
|
||||
if (node.type === 'NullLiteral') {
|
||||
throw new Error('Unexpected null in require expression');
|
||||
}
|
||||
if (node.type === 'RegExpLiteral') {
|
||||
throw new Error('Unexpected regexp in require expression');
|
||||
}
|
||||
return node.value;
|
||||
}
|
||||
function reconstructSpecifiers(specs) {
|
||||
if (!specs || !specs.length) {
|
||||
return '';
|
||||
if (!specs || !specs.length) {
|
||||
return '';
|
||||
}
|
||||
const defaults = [];
|
||||
for (const spec of specs) {
|
||||
if (babelTypes.isImportDefaultSpecifier(spec)) {
|
||||
defaults.push(spec.local.name);
|
||||
}
|
||||
const defaults = [];
|
||||
for (const spec of specs) {
|
||||
if (babelTypes.isImportDefaultSpecifier(spec)) {
|
||||
defaults.push(spec.local.name);
|
||||
}
|
||||
}
|
||||
const nonDefaults = [];
|
||||
for (const spec of specs) {
|
||||
if (babelTypes.isImportSpecifier(spec)) {
|
||||
const importedName =
|
||||
babelTypes.isIdentifier(spec.imported) ?
|
||||
spec.imported.name
|
||||
: spec.imported.value;
|
||||
if (spec.local.name === importedName) {
|
||||
nonDefaults.push(spec.local.name);
|
||||
} else {
|
||||
nonDefaults.push(`${importedName} as ${spec.local.name}`);
|
||||
}
|
||||
}
|
||||
const nonDefaults = [];
|
||||
for (const spec of specs) {
|
||||
if (babelTypes.isImportSpecifier(spec)) {
|
||||
const importedName = babelTypes.isIdentifier(spec.imported)
|
||||
? spec.imported.name
|
||||
: spec.imported.value;
|
||||
if (spec.local.name === importedName) {
|
||||
nonDefaults.push(spec.local.name);
|
||||
}
|
||||
else {
|
||||
nonDefaults.push(`${importedName} as ${spec.local.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nonDefaults.length) {
|
||||
defaults.push(`{ ${nonDefaults.join(', ')} }`);
|
||||
}
|
||||
return defaults.join(', ');
|
||||
}
|
||||
if (nonDefaults.length) {
|
||||
defaults.push(`{ ${nonDefaults.join(', ')} }`);
|
||||
}
|
||||
return defaults.join(', ');
|
||||
}
|
||||
function reconstruct(node) {
|
||||
let v = (0, generator_1.default)(node, { comments: false }).code.replace(/\n/g, '');
|
||||
let v2;
|
||||
while (true) {
|
||||
v2 = v.replace(/\[ /g, '[').replace(/ \]/g, ']').replace(/ {2}/g, ' ');
|
||||
if (v2 === v) {
|
||||
break;
|
||||
}
|
||||
v = v2;
|
||||
let v = (0, generator_1.default)(node, { comments: false }).code.replace(
|
||||
/\n/g,
|
||||
''
|
||||
);
|
||||
let v2;
|
||||
while (true) {
|
||||
v2 = v.replace(/\[ /g, '[').replace(/ \]/g, ']').replace(/ {2}/g, ' ');
|
||||
if (v2 === v) {
|
||||
break;
|
||||
}
|
||||
return v2;
|
||||
v = v2;
|
||||
}
|
||||
return v2;
|
||||
}
|
||||
function forge(pattern, was) {
|
||||
return pattern
|
||||
.replace('{c1}', ', ')
|
||||
.replace('{v1}', `"${was.v1}"`)
|
||||
.replace('{c2}', was.v2 ? ', ' : '')
|
||||
.replace('{v2}', was.v2 ? `"${was.v2}"` : '')
|
||||
.replace('{c3}', was.v3 ? ' from ' : '')
|
||||
.replace('{v3}', was.v3 ? was.v3 : '');
|
||||
return pattern
|
||||
.replace('{c1}', ', ')
|
||||
.replace('{v1}', `"${was.v1}"`)
|
||||
.replace('{c2}', was.v2 ? ', ' : '')
|
||||
.replace('{v2}', was.v2 ? `"${was.v2}"` : '')
|
||||
.replace('{c3}', was.v3 ? ' from ' : '')
|
||||
.replace('{v3}', was.v3 ? was.v3 : '');
|
||||
}
|
||||
function valid2(v2) {
|
||||
return (v2 === undefined ||
|
||||
v2 === null ||
|
||||
v2 === 'must-exclude' ||
|
||||
v2 === 'may-exclude');
|
||||
return (
|
||||
v2 === undefined ||
|
||||
v2 === null ||
|
||||
v2 === 'must-exclude' ||
|
||||
v2 === 'may-exclude'
|
||||
);
|
||||
}
|
||||
function visitorRequireResolve(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci = n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'require' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
if (!n.arguments || !isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: getLiteralValue(n.arguments[0]),
|
||||
v2: isLiteral(n.arguments[1]) ? getLiteralValue(n.arguments[1]) : null,
|
||||
};
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci =
|
||||
n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'require' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
if (!n.arguments || !isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: getLiteralValue(n.arguments[0]),
|
||||
v2: isLiteral(n.arguments[1]) ? getLiteralValue(n.arguments[1]) : null,
|
||||
};
|
||||
}
|
||||
function visitorRequire(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isIdentifier(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
if (n.callee.name !== 'require') {
|
||||
return null;
|
||||
}
|
||||
if (!n.arguments || !isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: getLiteralValue(n.arguments[0]),
|
||||
v2: isLiteral(n.arguments[1]) ? getLiteralValue(n.arguments[1]) : null,
|
||||
};
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isIdentifier(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
if (n.callee.name !== 'require') {
|
||||
return null;
|
||||
}
|
||||
if (!n.arguments || !isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: getLiteralValue(n.arguments[0]),
|
||||
v2: isLiteral(n.arguments[1]) ? getLiteralValue(n.arguments[1]) : null,
|
||||
};
|
||||
}
|
||||
function visitorImport(n) {
|
||||
if (!babelTypes.isImportDeclaration(n)) {
|
||||
return null;
|
||||
}
|
||||
return { v1: n.source.value, v3: reconstructSpecifiers(n.specifiers) };
|
||||
if (!babelTypes.isImportDeclaration(n)) {
|
||||
return null;
|
||||
}
|
||||
return { v1: n.source.value, v3: reconstructSpecifiers(n.specifiers) };
|
||||
}
|
||||
function visitorPathJoin(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci = n.callee.object &&
|
||||
n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'path' &&
|
||||
n.callee.property &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'join';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
const dn = n.arguments[0] &&
|
||||
n.arguments[0].type === 'Identifier' &&
|
||||
n.arguments[0].name === '__dirname';
|
||||
if (!dn) {
|
||||
return null;
|
||||
}
|
||||
const f = n.arguments && isLiteral(n.arguments[1]) && n.arguments.length === 2; // TODO concat them
|
||||
if (!f) {
|
||||
return null;
|
||||
}
|
||||
return { v1: getLiteralValue(n.arguments[1]) };
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci =
|
||||
n.callee.object &&
|
||||
n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'path' &&
|
||||
n.callee.property &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'join';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
const dn =
|
||||
n.arguments[0] &&
|
||||
n.arguments[0].type === 'Identifier' &&
|
||||
n.arguments[0].name === '__dirname';
|
||||
if (!dn) {
|
||||
return null;
|
||||
}
|
||||
const f =
|
||||
n.arguments && isLiteral(n.arguments[1]) && n.arguments.length === 2; // TODO concat them
|
||||
if (!f) {
|
||||
return null;
|
||||
}
|
||||
return { v1: getLiteralValue(n.arguments[1]) };
|
||||
}
|
||||
function visitorSuccessful(node, test = false) {
|
||||
let was = visitorRequireResolve(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('require.resolve({v1}{c2}{v2})', was);
|
||||
}
|
||||
if (!valid2(was.v2)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
alias: was.v1,
|
||||
aliasType: common_1.ALIAS_AS_RESOLVABLE,
|
||||
mustExclude: was.v2 === 'must-exclude',
|
||||
mayExclude: was.v2 === 'may-exclude',
|
||||
};
|
||||
let was = visitorRequireResolve(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('require.resolve({v1}{c2}{v2})', was);
|
||||
}
|
||||
was = visitorRequire(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('require({v1}{c2}{v2})', was);
|
||||
}
|
||||
if (!valid2(was.v2)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
alias: was.v1,
|
||||
aliasType: common_1.ALIAS_AS_RESOLVABLE,
|
||||
mustExclude: was.v2 === 'must-exclude',
|
||||
mayExclude: was.v2 === 'may-exclude',
|
||||
};
|
||||
if (!valid2(was.v2)) {
|
||||
return null;
|
||||
}
|
||||
was = visitorImport(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('import {v3}{c3}{v1}', was);
|
||||
}
|
||||
return { alias: was.v1, aliasType: common_1.ALIAS_AS_RESOLVABLE };
|
||||
return {
|
||||
alias: was.v1,
|
||||
aliasType: common_1.ALIAS_AS_RESOLVABLE,
|
||||
mustExclude: was.v2 === 'must-exclude',
|
||||
mayExclude: was.v2 === 'may-exclude',
|
||||
};
|
||||
}
|
||||
was = visitorRequire(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('require({v1}{c2}{v2})', was);
|
||||
}
|
||||
was = visitorPathJoin(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('path.join(__dirname{c1}{v1})', was);
|
||||
}
|
||||
return { alias: was.v1, aliasType: common_1.ALIAS_AS_RELATIVE, mayExclude: false };
|
||||
if (!valid2(was.v2)) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return {
|
||||
alias: was.v1,
|
||||
aliasType: common_1.ALIAS_AS_RESOLVABLE,
|
||||
mustExclude: was.v2 === 'must-exclude',
|
||||
mayExclude: was.v2 === 'may-exclude',
|
||||
};
|
||||
}
|
||||
was = visitorImport(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('import {v3}{c3}{v1}', was);
|
||||
}
|
||||
return { alias: was.v1, aliasType: common_1.ALIAS_AS_RESOLVABLE };
|
||||
}
|
||||
was = visitorPathJoin(node);
|
||||
if (was) {
|
||||
if (test) {
|
||||
return forge('path.join(__dirname{c1}{v1})', was);
|
||||
}
|
||||
return {
|
||||
alias: was.v1,
|
||||
aliasType: common_1.ALIAS_AS_RELATIVE,
|
||||
mayExclude: false,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.visitorSuccessful = visitorSuccessful;
|
||||
function nonLiteralRequireResolve(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci = n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'require' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
if (isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
const m = n.arguments[1];
|
||||
if (!m) {
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
}
|
||||
if (!isLiteral(n.arguments[1])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: reconstruct(n.arguments[0]),
|
||||
v2: getLiteralValue(n.arguments[1]),
|
||||
};
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci =
|
||||
n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'require' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
if (isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
const m = n.arguments[1];
|
||||
if (!m) {
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
}
|
||||
if (!isLiteral(n.arguments[1])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: reconstruct(n.arguments[0]),
|
||||
v2: getLiteralValue(n.arguments[1]),
|
||||
};
|
||||
}
|
||||
function nonLiteralRequire(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isIdentifier(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
if (n.callee.name !== 'require') {
|
||||
return null;
|
||||
}
|
||||
if (isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
const m = n.arguments[1];
|
||||
if (!m) {
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
}
|
||||
if (!isLiteral(n.arguments[1])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: reconstruct(n.arguments[0]),
|
||||
v2: getLiteralValue(n.arguments[1]),
|
||||
};
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isIdentifier(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
if (n.callee.name !== 'require') {
|
||||
return null;
|
||||
}
|
||||
if (isLiteral(n.arguments[0])) {
|
||||
return null;
|
||||
}
|
||||
const m = n.arguments[1];
|
||||
if (!m) {
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
}
|
||||
if (!isLiteral(n.arguments[1])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
v1: reconstruct(n.arguments[0]),
|
||||
v2: getLiteralValue(n.arguments[1]),
|
||||
};
|
||||
}
|
||||
function visitorNonLiteral(n) {
|
||||
const was = nonLiteralRequireResolve(n) || nonLiteralRequire(n);
|
||||
if (was) {
|
||||
if (!valid2(was.v2)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
alias: was.v1,
|
||||
mustExclude: was.v2 === 'must-exclude',
|
||||
mayExclude: was.v2 === 'may-exclude',
|
||||
};
|
||||
const was = nonLiteralRequireResolve(n) || nonLiteralRequire(n);
|
||||
if (was) {
|
||||
if (!valid2(was.v2)) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return {
|
||||
alias: was.v1,
|
||||
mustExclude: was.v2 === 'must-exclude',
|
||||
mayExclude: was.v2 === 'may-exclude',
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.visitorNonLiteral = visitorNonLiteral;
|
||||
function isRequire(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isIdentifier(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
if (n.callee.name !== 'require') {
|
||||
return null;
|
||||
}
|
||||
const f = n.arguments && n.arguments[0];
|
||||
if (!f) {
|
||||
return null;
|
||||
}
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isIdentifier(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
if (n.callee.name !== 'require') {
|
||||
return null;
|
||||
}
|
||||
const f = n.arguments && n.arguments[0];
|
||||
if (!f) {
|
||||
return null;
|
||||
}
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
}
|
||||
function isRequireResolve(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci = n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'require' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
const f = n.type === 'CallExpression' && n.arguments && n.arguments[0];
|
||||
if (!f) {
|
||||
return null;
|
||||
}
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci =
|
||||
n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'require' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
const f = n.type === 'CallExpression' && n.arguments && n.arguments[0];
|
||||
if (!f) {
|
||||
return null;
|
||||
}
|
||||
return { v1: reconstruct(n.arguments[0]) };
|
||||
}
|
||||
function visitorMalformed(n) {
|
||||
const was = isRequireResolve(n) || isRequire(n);
|
||||
if (was) {
|
||||
return { alias: was.v1 };
|
||||
}
|
||||
return null;
|
||||
const was = isRequireResolve(n) || isRequire(n);
|
||||
if (was) {
|
||||
return { alias: was.v1 };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.visitorMalformed = visitorMalformed;
|
||||
function visitorUseSCWD(n) {
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci = n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'path' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
const was = { v1: n.arguments.map(reconstruct).join(', ') };
|
||||
if (was) {
|
||||
return { alias: was.v1 };
|
||||
}
|
||||
if (!babelTypes.isCallExpression(n)) {
|
||||
return null;
|
||||
}
|
||||
if (!babelTypes.isMemberExpression(n.callee)) {
|
||||
return null;
|
||||
}
|
||||
const ci =
|
||||
n.callee.object.type === 'Identifier' &&
|
||||
n.callee.object.name === 'path' &&
|
||||
n.callee.property.type === 'Identifier' &&
|
||||
n.callee.property.name === 'resolve';
|
||||
if (!ci) {
|
||||
return null;
|
||||
}
|
||||
const was = { v1: n.arguments.map(reconstruct).join(', ') };
|
||||
if (was) {
|
||||
return { alias: was.v1 };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.visitorUseSCWD = visitorUseSCWD;
|
||||
function traverse(ast, visitor) {
|
||||
// modified esprima-walk to support
|
||||
// visitor return value and "trying" flag
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const stack = [[ast, false]];
|
||||
for (let i = 0; i < stack.length; i += 1) {
|
||||
const item = stack[i];
|
||||
const [node] = item;
|
||||
if (node) {
|
||||
const trying = item[1] || babelTypes.isTryStatement(node);
|
||||
if (visitor(node, trying)) {
|
||||
for (const key in node) {
|
||||
if (node[key]) {
|
||||
const child = node[key];
|
||||
if (child instanceof Array) {
|
||||
for (let j = 0; j < child.length; j += 1) {
|
||||
stack.push([child[j], trying]);
|
||||
}
|
||||
}
|
||||
else if (child && typeof child.type === 'string') {
|
||||
stack.push([child, trying]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// modified esprima-walk to support
|
||||
// visitor return value and "trying" flag
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const stack = [[ast, false]];
|
||||
for (let i = 0; i < stack.length; i += 1) {
|
||||
const item = stack[i];
|
||||
const [node] = item;
|
||||
if (node) {
|
||||
const trying = item[1] || babelTypes.isTryStatement(node);
|
||||
if (visitor(node, trying)) {
|
||||
for (const key in node) {
|
||||
if (node[key]) {
|
||||
const child = node[key];
|
||||
if (child instanceof Array) {
|
||||
for (let j = 0; j < child.length; j += 1) {
|
||||
stack.push([child[j], trying]);
|
||||
}
|
||||
} else if (child && typeof child.type === 'string') {
|
||||
stack.push([child, trying]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function parse(body) {
|
||||
return babel.parse(body, {
|
||||
allowImportExportEverywhere: true,
|
||||
allowReturnOutsideFunction: true,
|
||||
});
|
||||
return babel.parse(body, {
|
||||
allowImportExportEverywhere: true,
|
||||
allowReturnOutsideFunction: true,
|
||||
});
|
||||
}
|
||||
exports.parse = parse;
|
||||
function detect(body, visitor) {
|
||||
let json;
|
||||
try {
|
||||
json = parse(body);
|
||||
}
|
||||
catch (error) {
|
||||
log_1.log.warn(`Babel parse has failed: ${error.message}`);
|
||||
}
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
traverse(json, visitor);
|
||||
let json;
|
||||
try {
|
||||
json = parse(body);
|
||||
} catch (error) {
|
||||
log_1.log.warn(`Babel parse has failed: ${error.message}`);
|
||||
}
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
traverse(json, visitor);
|
||||
}
|
||||
exports.detect = detect;
|
||||
//# sourceMappingURL=detector.js.map
|
||||
//# sourceMappingURL=detector.js.map
|
||||
|
189
node_modules/pkg/lib-es5/fabricator.js
generated
vendored
189
node_modules/pkg/lib-es5/fabricator.js
generated
vendored
@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.shutdown = exports.fabricateTwice = exports.fabricate = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const log_1 = require("./log");
|
||||
const child_process_1 = require('child_process');
|
||||
const log_1 = require('./log');
|
||||
const script = `
|
||||
var vm = require('vm');
|
||||
var module = require('module');
|
||||
@ -42,100 +42,113 @@ const script = `
|
||||
`;
|
||||
const children = {};
|
||||
function fabricate(bakes, fabricator, snap, body, cb) {
|
||||
const activeBakes = bakes.filter((bake) => {
|
||||
// list of bakes that don't influence the bytecode
|
||||
const bake2 = bake.replace(/_/g, '-');
|
||||
return !['--prof', '--v8-options', '--trace-opt', '--trace-deopt'].includes(bake2);
|
||||
});
|
||||
const cmd = fabricator.binaryPath;
|
||||
const key = JSON.stringify([cmd, activeBakes]);
|
||||
let child = children[key];
|
||||
if (!child) {
|
||||
const stderr = log_1.log.debugMode ? process.stdout : 'ignore';
|
||||
children[key] = (0, child_process_1.spawn)(cmd, activeBakes.concat('-e', script), {
|
||||
stdio: ['pipe', 'pipe', stderr],
|
||||
env: { PKG_EXECPATH: 'PKG_INVOKE_NODEJS' },
|
||||
});
|
||||
child = children[key];
|
||||
const activeBakes = bakes.filter((bake) => {
|
||||
// list of bakes that don't influence the bytecode
|
||||
const bake2 = bake.replace(/_/g, '-');
|
||||
return !['--prof', '--v8-options', '--trace-opt', '--trace-deopt'].includes(
|
||||
bake2
|
||||
);
|
||||
});
|
||||
const cmd = fabricator.binaryPath;
|
||||
const key = JSON.stringify([cmd, activeBakes]);
|
||||
let child = children[key];
|
||||
if (!child) {
|
||||
const stderr = log_1.log.debugMode ? process.stdout : 'ignore';
|
||||
children[key] = (0, child_process_1.spawn)(
|
||||
cmd,
|
||||
activeBakes.concat('-e', script),
|
||||
{
|
||||
stdio: ['pipe', 'pipe', stderr],
|
||||
env: { PKG_EXECPATH: 'PKG_INVOKE_NODEJS' },
|
||||
}
|
||||
);
|
||||
child = children[key];
|
||||
}
|
||||
function kill() {
|
||||
delete children[key];
|
||||
child.kill();
|
||||
}
|
||||
let stdout = Buffer.alloc(0);
|
||||
function onError(error) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
removeListeners();
|
||||
kill();
|
||||
cb(
|
||||
new Error(
|
||||
`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap} error (${error.message})`
|
||||
)
|
||||
);
|
||||
}
|
||||
function onClose(code) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
removeListeners();
|
||||
kill();
|
||||
if (code !== 0) {
|
||||
return cb(
|
||||
new Error(
|
||||
`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap}`
|
||||
)
|
||||
);
|
||||
}
|
||||
function kill() {
|
||||
delete children[key];
|
||||
child.kill();
|
||||
}
|
||||
let stdout = Buffer.alloc(0);
|
||||
function onError(error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(stdout.toString());
|
||||
return cb(new Error(`${cmd} closed unexpectedly`));
|
||||
}
|
||||
function onData(data) {
|
||||
stdout = Buffer.concat([stdout, data]);
|
||||
if (stdout.length >= 4) {
|
||||
const sizeOfBlob = stdout.readInt32LE(0);
|
||||
if (stdout.length >= 4 + sizeOfBlob) {
|
||||
const blob = Buffer.alloc(sizeOfBlob);
|
||||
stdout.copy(blob, 0, 4, 4 + sizeOfBlob);
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
removeListeners();
|
||||
kill();
|
||||
cb(new Error(`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap} error (${error.message})`));
|
||||
return cb(undefined, blob);
|
||||
}
|
||||
}
|
||||
function onClose(code) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
removeListeners();
|
||||
kill();
|
||||
if (code !== 0) {
|
||||
return cb(new Error(`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap}`));
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(stdout.toString());
|
||||
return cb(new Error(`${cmd} closed unexpectedly`));
|
||||
}
|
||||
function onData(data) {
|
||||
stdout = Buffer.concat([stdout, data]);
|
||||
if (stdout.length >= 4) {
|
||||
const sizeOfBlob = stdout.readInt32LE(0);
|
||||
if (stdout.length >= 4 + sizeOfBlob) {
|
||||
const blob = Buffer.alloc(sizeOfBlob);
|
||||
stdout.copy(blob, 0, 4, 4 + sizeOfBlob);
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
removeListeners();
|
||||
return cb(undefined, blob);
|
||||
}
|
||||
}
|
||||
}
|
||||
function removeListeners() {
|
||||
child.removeListener('error', onError);
|
||||
child.removeListener('close', onClose);
|
||||
child.stdin.removeListener('error', onError);
|
||||
child.stdout.removeListener('error', onError);
|
||||
child.stdout.removeListener('data', onData);
|
||||
}
|
||||
child.on('error', onError);
|
||||
child.on('close', onClose);
|
||||
child.stdin.on('error', onError);
|
||||
child.stdout.on('error', onError);
|
||||
child.stdout.on('data', onData);
|
||||
const h = Buffer.alloc(4);
|
||||
let b = Buffer.from(snap);
|
||||
h.writeInt32LE(b.length, 0);
|
||||
child.stdin.write(h);
|
||||
child.stdin.write(b);
|
||||
b = body;
|
||||
h.writeInt32LE(b.length, 0);
|
||||
child.stdin.write(h);
|
||||
child.stdin.write(b);
|
||||
}
|
||||
function removeListeners() {
|
||||
child.removeListener('error', onError);
|
||||
child.removeListener('close', onClose);
|
||||
child.stdin.removeListener('error', onError);
|
||||
child.stdout.removeListener('error', onError);
|
||||
child.stdout.removeListener('data', onData);
|
||||
}
|
||||
child.on('error', onError);
|
||||
child.on('close', onClose);
|
||||
child.stdin.on('error', onError);
|
||||
child.stdout.on('error', onError);
|
||||
child.stdout.on('data', onData);
|
||||
const h = Buffer.alloc(4);
|
||||
let b = Buffer.from(snap);
|
||||
h.writeInt32LE(b.length, 0);
|
||||
child.stdin.write(h);
|
||||
child.stdin.write(b);
|
||||
b = body;
|
||||
h.writeInt32LE(b.length, 0);
|
||||
child.stdin.write(h);
|
||||
child.stdin.write(b);
|
||||
}
|
||||
exports.fabricate = fabricate;
|
||||
function fabricateTwice(bakes, fabricator, snap, body, cb) {
|
||||
fabricate(bakes, fabricator, snap, body, (error, buffer) => {
|
||||
// node0 can not produce second time, even if first time produced fine,
|
||||
// probably because of 'filename' cache. also, there are weird cases
|
||||
// when node4 can not compile as well, for example file 'lib/js-yaml/dumper.js'
|
||||
// of package js-yaml@3.9.0 does not get bytecode second time on node4-win-x64
|
||||
if (error)
|
||||
return fabricate(bakes, fabricator, snap, body, cb);
|
||||
cb(undefined, buffer);
|
||||
});
|
||||
fabricate(bakes, fabricator, snap, body, (error, buffer) => {
|
||||
// node0 can not produce second time, even if first time produced fine,
|
||||
// probably because of 'filename' cache. also, there are weird cases
|
||||
// when node4 can not compile as well, for example file 'lib/js-yaml/dumper.js'
|
||||
// of package js-yaml@3.9.0 does not get bytecode second time on node4-win-x64
|
||||
if (error) return fabricate(bakes, fabricator, snap, body, cb);
|
||||
cb(undefined, buffer);
|
||||
});
|
||||
}
|
||||
exports.fabricateTwice = fabricateTwice;
|
||||
function shutdown() {
|
||||
for (const key in children) {
|
||||
if (children[key]) {
|
||||
const child = children[key];
|
||||
delete children[key];
|
||||
child.kill();
|
||||
}
|
||||
for (const key in children) {
|
||||
if (children[key]) {
|
||||
const child = children[key];
|
||||
delete children[key];
|
||||
child.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.shutdown = shutdown;
|
||||
//# sourceMappingURL=fabricator.js.map
|
||||
//# sourceMappingURL=fabricator.js.map
|
||||
|
175
node_modules/pkg/lib-es5/follow.js
generated
vendored
175
node_modules/pkg/lib-es5/follow.js
generated
vendored
@ -1,91 +1,100 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.follow = void 0;
|
||||
const resolve_1 = require("resolve");
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const common_1 = require("./common");
|
||||
const resolve_1 = require('resolve');
|
||||
const fs_1 = __importDefault(require('fs'));
|
||||
const path_1 = __importDefault(require('path'));
|
||||
const common_1 = require('./common');
|
||||
const PROOF = 'a-proof-that-main-is-captured.js';
|
||||
function parentDirectoriesContain(parent, directory) {
|
||||
let currentParent = parent;
|
||||
while (true) {
|
||||
if (currentParent === directory) {
|
||||
return true;
|
||||
}
|
||||
const newParent = path_1.default.dirname(currentParent);
|
||||
if (newParent === currentParent) {
|
||||
return false;
|
||||
}
|
||||
currentParent = newParent;
|
||||
let currentParent = parent;
|
||||
while (true) {
|
||||
if (currentParent === directory) {
|
||||
return true;
|
||||
}
|
||||
const newParent = path_1.default.dirname(currentParent);
|
||||
if (newParent === currentParent) {
|
||||
return false;
|
||||
}
|
||||
currentParent = newParent;
|
||||
}
|
||||
}
|
||||
function follow(x, opts) {
|
||||
// TODO async version
|
||||
return new Promise((resolve) => {
|
||||
resolve((0, resolve_1.sync)(x, {
|
||||
basedir: opts.basedir,
|
||||
extensions: opts.extensions,
|
||||
isFile: (file) => {
|
||||
if (opts.ignoreFile &&
|
||||
path_1.default.join(path_1.default.dirname(opts.ignoreFile), PROOF) === file) {
|
||||
return true;
|
||||
}
|
||||
let stat;
|
||||
try {
|
||||
stat = fs_1.default.statSync(file);
|
||||
}
|
||||
catch (e) {
|
||||
const ex = e;
|
||||
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR'))
|
||||
return false;
|
||||
throw ex;
|
||||
}
|
||||
return stat.isFile() || stat.isFIFO();
|
||||
},
|
||||
isDirectory: (directory) => {
|
||||
if (opts.ignoreFile &&
|
||||
parentDirectoriesContain(opts.ignoreFile, directory)) {
|
||||
return false;
|
||||
}
|
||||
let stat;
|
||||
try {
|
||||
stat = fs_1.default.statSync(directory);
|
||||
}
|
||||
catch (e) {
|
||||
const ex = e;
|
||||
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR')) {
|
||||
return false;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
return stat.isDirectory();
|
||||
},
|
||||
readFileSync: (file) => {
|
||||
if (opts.ignoreFile && opts.ignoreFile === file) {
|
||||
return Buffer.from(`{"main":"${PROOF}"}`);
|
||||
}
|
||||
if (opts.catchReadFile) {
|
||||
opts.catchReadFile(file);
|
||||
}
|
||||
return fs_1.default.readFileSync(file);
|
||||
},
|
||||
packageFilter: (config, base, dir) => {
|
||||
if (opts.catchPackageFilter) {
|
||||
opts.catchPackageFilter(config, base, dir);
|
||||
}
|
||||
return config;
|
||||
},
|
||||
/** function to synchronously resolve a potential symlink to its real path */
|
||||
// realpathSync?: (file: string) => string;
|
||||
realpathSync: (file) => {
|
||||
const file2 = (0, common_1.toNormalizedRealPath)(file);
|
||||
return file2;
|
||||
},
|
||||
}));
|
||||
});
|
||||
// TODO async version
|
||||
return new Promise((resolve) => {
|
||||
resolve(
|
||||
(0, resolve_1.sync)(x, {
|
||||
basedir: opts.basedir,
|
||||
extensions: opts.extensions,
|
||||
isFile: (file) => {
|
||||
if (
|
||||
opts.ignoreFile &&
|
||||
path_1.default.join(
|
||||
path_1.default.dirname(opts.ignoreFile),
|
||||
PROOF
|
||||
) === file
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
let stat;
|
||||
try {
|
||||
stat = fs_1.default.statSync(file);
|
||||
} catch (e) {
|
||||
const ex = e;
|
||||
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR'))
|
||||
return false;
|
||||
throw ex;
|
||||
}
|
||||
return stat.isFile() || stat.isFIFO();
|
||||
},
|
||||
isDirectory: (directory) => {
|
||||
if (
|
||||
opts.ignoreFile &&
|
||||
parentDirectoriesContain(opts.ignoreFile, directory)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
let stat;
|
||||
try {
|
||||
stat = fs_1.default.statSync(directory);
|
||||
} catch (e) {
|
||||
const ex = e;
|
||||
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR')) {
|
||||
return false;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
return stat.isDirectory();
|
||||
},
|
||||
readFileSync: (file) => {
|
||||
if (opts.ignoreFile && opts.ignoreFile === file) {
|
||||
return Buffer.from(`{"main":"${PROOF}"}`);
|
||||
}
|
||||
if (opts.catchReadFile) {
|
||||
opts.catchReadFile(file);
|
||||
}
|
||||
return fs_1.default.readFileSync(file);
|
||||
},
|
||||
packageFilter: (config, base, dir) => {
|
||||
if (opts.catchPackageFilter) {
|
||||
opts.catchPackageFilter(config, base, dir);
|
||||
}
|
||||
return config;
|
||||
},
|
||||
/** function to synchronously resolve a potential symlink to its real path */
|
||||
// realpathSync?: (file: string) => string;
|
||||
realpathSync: (file) => {
|
||||
const file2 = (0, common_1.toNormalizedRealPath)(file);
|
||||
return file2;
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
exports.follow = follow;
|
||||
//# sourceMappingURL=follow.js.map
|
||||
//# sourceMappingURL=follow.js.map
|
||||
|
20
node_modules/pkg/lib-es5/help.js
generated
vendored
20
node_modules/pkg/lib-es5/help.js
generated
vendored
@ -1,12 +1,14 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
'use strict';
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
const chalk_1 = __importDefault(require('chalk'));
|
||||
function help() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`
|
||||
${chalk_1.default.bold('pkg')} [options] <input>
|
||||
|
||||
${chalk_1.default.dim('Options:')}
|
||||
@ -50,4 +52,4 @@ function help() {
|
||||
`);
|
||||
}
|
||||
exports.default = help;
|
||||
//# sourceMappingURL=help.js.map
|
||||
//# sourceMappingURL=help.js.map
|
||||
|
2
node_modules/pkg/lib-es5/index.d.ts
generated
vendored
2
node_modules/pkg/lib-es5/index.d.ts
generated
vendored
@ -1,2 +1,2 @@
|
||||
export declare function exec(argv2: string[]): Promise<void>;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
|
1034
node_modules/pkg/lib-es5/index.js
generated
vendored
1034
node_modules/pkg/lib-es5/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
22
node_modules/pkg/lib-es5/log.js
generated
vendored
22
node_modules/pkg/lib-es5/log.js
generated
vendored
@ -1,7 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.wasReported = exports.log = void 0;
|
||||
var log_1 = require("pkg-fetch/lib-es5/log");
|
||||
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return log_1.log; } });
|
||||
Object.defineProperty(exports, "wasReported", { enumerable: true, get: function () { return log_1.wasReported; } });
|
||||
//# sourceMappingURL=log.js.map
|
||||
var log_1 = require('pkg-fetch/lib-es5/log');
|
||||
Object.defineProperty(exports, 'log', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return log_1.log;
|
||||
},
|
||||
});
|
||||
Object.defineProperty(exports, 'wasReported', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return log_1.wasReported;
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=log.js.map
|
||||
|
99
node_modules/pkg/lib-es5/mach-o.js
generated
vendored
99
node_modules/pkg/lib-es5/mach-o.js
generated
vendored
@ -1,61 +1,66 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.signMachOExecutable = exports.patchMachOExecutable = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const child_process_1 = require('child_process');
|
||||
function parseCStr(buf) {
|
||||
for (let i = 0; i < buf.length; i += 1) {
|
||||
if (buf[i] === 0) {
|
||||
return buf.slice(0, i).toString();
|
||||
}
|
||||
for (let i = 0; i < buf.length; i += 1) {
|
||||
if (buf[i] === 0) {
|
||||
return buf.slice(0, i).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
function patchCommand(type, buf, file) {
|
||||
// segment_64
|
||||
if (type === 0x19) {
|
||||
const name = parseCStr(buf.slice(0, 16));
|
||||
if (name === '__LINKEDIT') {
|
||||
const fileoff = buf.readBigUInt64LE(32);
|
||||
const vmsizePatched = BigInt(file.length) - fileoff;
|
||||
const filesizePatched = vmsizePatched;
|
||||
buf.writeBigUInt64LE(vmsizePatched, 24);
|
||||
buf.writeBigUInt64LE(filesizePatched, 40);
|
||||
}
|
||||
}
|
||||
// symtab
|
||||
if (type === 0x2) {
|
||||
const stroff = buf.readUInt32LE(8);
|
||||
const strsizePatched = file.length - stroff;
|
||||
buf.writeUInt32LE(strsizePatched, 12);
|
||||
// segment_64
|
||||
if (type === 0x19) {
|
||||
const name = parseCStr(buf.slice(0, 16));
|
||||
if (name === '__LINKEDIT') {
|
||||
const fileoff = buf.readBigUInt64LE(32);
|
||||
const vmsizePatched = BigInt(file.length) - fileoff;
|
||||
const filesizePatched = vmsizePatched;
|
||||
buf.writeBigUInt64LE(vmsizePatched, 24);
|
||||
buf.writeBigUInt64LE(filesizePatched, 40);
|
||||
}
|
||||
}
|
||||
// symtab
|
||||
if (type === 0x2) {
|
||||
const stroff = buf.readUInt32LE(8);
|
||||
const strsizePatched = file.length - stroff;
|
||||
buf.writeUInt32LE(strsizePatched, 12);
|
||||
}
|
||||
}
|
||||
function patchMachOExecutable(file) {
|
||||
const align = 8;
|
||||
const hsize = 32;
|
||||
const ncmds = file.readUInt32LE(16);
|
||||
const buf = file.slice(hsize);
|
||||
for (let offset = 0, i = 0; i < ncmds; i += 1) {
|
||||
const type = buf.readUInt32LE(offset);
|
||||
offset += 4;
|
||||
const size = buf.readUInt32LE(offset) - 8;
|
||||
offset += 4;
|
||||
patchCommand(type, buf.slice(offset, offset + size), file);
|
||||
offset += size;
|
||||
if (offset & align) {
|
||||
offset += align - (offset & align);
|
||||
}
|
||||
const align = 8;
|
||||
const hsize = 32;
|
||||
const ncmds = file.readUInt32LE(16);
|
||||
const buf = file.slice(hsize);
|
||||
for (let offset = 0, i = 0; i < ncmds; i += 1) {
|
||||
const type = buf.readUInt32LE(offset);
|
||||
offset += 4;
|
||||
const size = buf.readUInt32LE(offset) - 8;
|
||||
offset += 4;
|
||||
patchCommand(type, buf.slice(offset, offset + size), file);
|
||||
offset += size;
|
||||
if (offset & align) {
|
||||
offset += align - (offset & align);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
exports.patchMachOExecutable = patchMachOExecutable;
|
||||
function signMachOExecutable(executable) {
|
||||
try {
|
||||
(0, child_process_1.execFileSync)('codesign', ['-f', '--sign', '-', executable], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
catch (_a) {
|
||||
(0, child_process_1.execFileSync)('ldid', ['-Cadhoc', '-S', executable], { stdio: 'inherit' });
|
||||
}
|
||||
try {
|
||||
(0, child_process_1.execFileSync)(
|
||||
'codesign',
|
||||
['-f', '--sign', '-', executable],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
} catch (_a) {
|
||||
(0, child_process_1.execFileSync)('ldid', ['-Cadhoc', '-S', executable], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.signMachOExecutable = signMachOExecutable;
|
||||
//# sourceMappingURL=mach-o.js.map
|
||||
//# sourceMappingURL=mach-o.js.map
|
||||
|
270
node_modules/pkg/lib-es5/packer.js
generated
vendored
270
node_modules/pkg/lib-es5/packer.js
generated
vendored
@ -1,131 +1,161 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
/* eslint-disable complexity */
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const common_1 = require("./common");
|
||||
const log_1 = require("./log");
|
||||
const { version } = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../package.json'), 'utf-8'));
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
const assert_1 = __importDefault(require('assert'));
|
||||
const fs_extra_1 = __importDefault(require('fs-extra'));
|
||||
const path_1 = __importDefault(require('path'));
|
||||
const common_1 = require('./common');
|
||||
const log_1 = require('./log');
|
||||
const { version } = JSON.parse(
|
||||
fs_extra_1.default.readFileSync(
|
||||
path_1.default.join(__dirname, '../package.json'),
|
||||
'utf-8'
|
||||
)
|
||||
);
|
||||
const bootstrapText = fs_extra_1.default
|
||||
.readFileSync(require.resolve('../prelude/bootstrap.js'), 'utf8')
|
||||
.replace('%VERSION%', version);
|
||||
const commonText = fs_extra_1.default.readFileSync(require.resolve('./common'), 'utf8');
|
||||
const diagnosticText = fs_extra_1.default.readFileSync(require.resolve('../prelude/diagnostic.js'), 'utf8');
|
||||
.readFileSync(require.resolve('../prelude/bootstrap.js'), 'utf8')
|
||||
.replace('%VERSION%', version);
|
||||
const commonText = fs_extra_1.default.readFileSync(
|
||||
require.resolve('./common'),
|
||||
'utf8'
|
||||
);
|
||||
const diagnosticText = fs_extra_1.default.readFileSync(
|
||||
require.resolve('../prelude/diagnostic.js'),
|
||||
'utf8'
|
||||
);
|
||||
function itemsToText(items) {
|
||||
const len = items.length;
|
||||
return len.toString() + (len % 10 === 1 ? ' item' : ' items');
|
||||
const len = items.length;
|
||||
return len.toString() + (len % 10 === 1 ? ' item' : ' items');
|
||||
}
|
||||
function hasAnyStore(record) {
|
||||
// discarded records like native addons
|
||||
for (const store of [common_1.STORE_BLOB, common_1.STORE_CONTENT, common_1.STORE_LINKS, common_1.STORE_STAT]) {
|
||||
if (record[store])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// discarded records like native addons
|
||||
for (const store of [
|
||||
common_1.STORE_BLOB,
|
||||
common_1.STORE_CONTENT,
|
||||
common_1.STORE_LINKS,
|
||||
common_1.STORE_STAT,
|
||||
]) {
|
||||
if (record[store]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function packer({ records, entrypoint, bytecode, }) {
|
||||
const stripes = [];
|
||||
for (const snap in records) {
|
||||
if (records[snap]) {
|
||||
const record = records[snap];
|
||||
const { file } = record;
|
||||
if (!hasAnyStore(record)) {
|
||||
continue;
|
||||
}
|
||||
(0, assert_1.default)(record[common_1.STORE_STAT], 'packer: no STORE_STAT');
|
||||
(0, assert_1.default)(record[common_1.STORE_BLOB] ||
|
||||
record[common_1.STORE_CONTENT] ||
|
||||
record[common_1.STORE_LINKS] ||
|
||||
record[common_1.STORE_STAT]);
|
||||
if (record[common_1.STORE_BLOB] && !bytecode) {
|
||||
delete record[common_1.STORE_BLOB];
|
||||
if (!record[common_1.STORE_CONTENT]) {
|
||||
// TODO make a test for it?
|
||||
throw (0, log_1.wasReported)('--no-bytecode and no source breaks final executable', [
|
||||
file,
|
||||
'Please run with "-d" and without "--no-bytecode" first, and make',
|
||||
'sure that debug log does not contain "was included as bytecode".',
|
||||
]);
|
||||
}
|
||||
}
|
||||
for (const store of [
|
||||
common_1.STORE_BLOB,
|
||||
common_1.STORE_CONTENT,
|
||||
common_1.STORE_LINKS,
|
||||
common_1.STORE_STAT,
|
||||
]) {
|
||||
const value = record[store];
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
if (store === common_1.STORE_BLOB || store === common_1.STORE_CONTENT) {
|
||||
if (record.body === undefined) {
|
||||
stripes.push({ snap, store, file });
|
||||
}
|
||||
else if (Buffer.isBuffer(record.body)) {
|
||||
stripes.push({ snap, store, buffer: record.body });
|
||||
}
|
||||
else if (typeof record.body === 'string') {
|
||||
stripes.push({ snap, store, buffer: Buffer.from(record.body) });
|
||||
}
|
||||
else {
|
||||
(0, assert_1.default)(false, 'packer: bad STORE_BLOB/STORE_CONTENT');
|
||||
}
|
||||
}
|
||||
else if (store === common_1.STORE_LINKS) {
|
||||
if (Array.isArray(value)) {
|
||||
const dedupedValue = [...new Set(value)];
|
||||
log_1.log.debug('files & folders deduped = ', dedupedValue);
|
||||
const buffer = Buffer.from(JSON.stringify(dedupedValue));
|
||||
stripes.push({ snap, store, buffer });
|
||||
}
|
||||
else {
|
||||
(0, assert_1.default)(false, 'packer: bad STORE_LINKS');
|
||||
}
|
||||
}
|
||||
else if (store === common_1.STORE_STAT) {
|
||||
if (typeof value === 'object') {
|
||||
const newStat = Object.assign({}, value);
|
||||
const buffer = Buffer.from(JSON.stringify(newStat));
|
||||
stripes.push({ snap, store, buffer });
|
||||
}
|
||||
else {
|
||||
(0, assert_1.default)(false, 'packer: unknown store');
|
||||
}
|
||||
}
|
||||
if (record[common_1.STORE_CONTENT]) {
|
||||
const disclosed = (0, common_1.isDotJS)(file) || (0, common_1.isDotJSON)(file);
|
||||
log_1.log.debug(disclosed
|
||||
? 'The file was included as DISCLOSED code (with sources)'
|
||||
: 'The file was included as asset content', file);
|
||||
}
|
||||
else if (record[common_1.STORE_BLOB]) {
|
||||
log_1.log.debug('The file was included as bytecode (no sources)', file);
|
||||
}
|
||||
else if (record[common_1.STORE_LINKS]) {
|
||||
const link = record[common_1.STORE_LINKS];
|
||||
log_1.log.debug(`The directory files list was included (${itemsToText(link)})`, file);
|
||||
}
|
||||
}
|
||||
function packer({ records, entrypoint, bytecode }) {
|
||||
const stripes = [];
|
||||
for (const snap in records) {
|
||||
if (records[snap]) {
|
||||
const record = records[snap];
|
||||
const { file } = record;
|
||||
if (!hasAnyStore(record)) {
|
||||
continue;
|
||||
}
|
||||
(0, assert_1.default)(
|
||||
record[common_1.STORE_STAT],
|
||||
'packer: no STORE_STAT'
|
||||
);
|
||||
(0, assert_1.default)(
|
||||
record[common_1.STORE_BLOB] ||
|
||||
record[common_1.STORE_CONTENT] ||
|
||||
record[common_1.STORE_LINKS] ||
|
||||
record[common_1.STORE_STAT]
|
||||
);
|
||||
if (record[common_1.STORE_BLOB] && !bytecode) {
|
||||
delete record[common_1.STORE_BLOB];
|
||||
if (!record[common_1.STORE_CONTENT]) {
|
||||
// TODO make a test for it?
|
||||
throw (0, log_1.wasReported)(
|
||||
'--no-bytecode and no source breaks final executable',
|
||||
[
|
||||
file,
|
||||
'Please run with "-d" and without "--no-bytecode" first, and make',
|
||||
'sure that debug log does not contain "was included as bytecode".',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const store of [
|
||||
common_1.STORE_BLOB,
|
||||
common_1.STORE_CONTENT,
|
||||
common_1.STORE_LINKS,
|
||||
common_1.STORE_STAT,
|
||||
]) {
|
||||
const value = record[store];
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
if (store === common_1.STORE_BLOB || store === common_1.STORE_CONTENT) {
|
||||
if (record.body === undefined) {
|
||||
stripes.push({ snap, store, file });
|
||||
} else if (Buffer.isBuffer(record.body)) {
|
||||
stripes.push({ snap, store, buffer: record.body });
|
||||
} else if (typeof record.body === 'string') {
|
||||
stripes.push({ snap, store, buffer: Buffer.from(record.body) });
|
||||
} else {
|
||||
(0, assert_1.default)(
|
||||
false,
|
||||
'packer: bad STORE_BLOB/STORE_CONTENT'
|
||||
);
|
||||
}
|
||||
} else if (store === common_1.STORE_LINKS) {
|
||||
if (Array.isArray(value)) {
|
||||
const dedupedValue = [...new Set(value)];
|
||||
log_1.log.debug('files & folders deduped = ', dedupedValue);
|
||||
const buffer = Buffer.from(JSON.stringify(dedupedValue));
|
||||
stripes.push({ snap, store, buffer });
|
||||
} else {
|
||||
(0, assert_1.default)(false, 'packer: bad STORE_LINKS');
|
||||
}
|
||||
} else if (store === common_1.STORE_STAT) {
|
||||
if (typeof value === 'object') {
|
||||
const newStat = Object.assign({}, value);
|
||||
const buffer = Buffer.from(JSON.stringify(newStat));
|
||||
stripes.push({ snap, store, buffer });
|
||||
} else {
|
||||
(0, assert_1.default)(false, 'packer: unknown store');
|
||||
}
|
||||
}
|
||||
if (record[common_1.STORE_CONTENT]) {
|
||||
const disclosed =
|
||||
(0, common_1.isDotJS)(file) || (0, common_1.isDotJSON)(file);
|
||||
log_1.log.debug(
|
||||
disclosed ?
|
||||
'The file was included as DISCLOSED code (with sources)'
|
||||
: 'The file was included as asset content',
|
||||
file
|
||||
);
|
||||
} else if (record[common_1.STORE_BLOB]) {
|
||||
log_1.log.debug(
|
||||
'The file was included as bytecode (no sources)',
|
||||
file
|
||||
);
|
||||
} else if (record[common_1.STORE_LINKS]) {
|
||||
const link = record[common_1.STORE_LINKS];
|
||||
log_1.log.debug(
|
||||
`The directory files list was included (${itemsToText(link)})`,
|
||||
file
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
const prelude = `return (function (REQUIRE_COMMON, VIRTUAL_FILESYSTEM, DEFAULT_ENTRYPOINT, SYMLINKS, DICT, DOCOMPRESS) {
|
||||
}
|
||||
const prelude =
|
||||
`return (function (REQUIRE_COMMON, VIRTUAL_FILESYSTEM, DEFAULT_ENTRYPOINT, SYMLINKS, DICT, DOCOMPRESS) {
|
||||
${bootstrapText}${log_1.log.debugMode ? diagnosticText : ''}\n})(function (exports) {\n${commonText}\n},\n` +
|
||||
`%VIRTUAL_FILESYSTEM%` +
|
||||
`\n,\n` +
|
||||
`%DEFAULT_ENTRYPOINT%` +
|
||||
`\n,\n` +
|
||||
`%SYMLINKS%` +
|
||||
'\n,\n' +
|
||||
'%DICT%' +
|
||||
'\n,\n' +
|
||||
'%DOCOMPRESS%' +
|
||||
`\n);`;
|
||||
return { prelude, entrypoint, stripes };
|
||||
`%VIRTUAL_FILESYSTEM%` +
|
||||
`\n,\n` +
|
||||
`%DEFAULT_ENTRYPOINT%` +
|
||||
`\n,\n` +
|
||||
`%SYMLINKS%` +
|
||||
'\n,\n' +
|
||||
'%DICT%' +
|
||||
'\n,\n' +
|
||||
'%DOCOMPRESS%' +
|
||||
`\n);`;
|
||||
return { prelude, entrypoint, stripes };
|
||||
}
|
||||
exports.default = packer;
|
||||
//# sourceMappingURL=packer.js.map
|
||||
//# sourceMappingURL=packer.js.map
|
||||
|
684
node_modules/pkg/lib-es5/producer.js
generated
vendored
684
node_modules/pkg/lib-es5/producer.js
generated
vendored
@ -1,146 +1,206 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const zlib_1 = require("zlib");
|
||||
const multistream_1 = __importDefault(require("multistream"));
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const into_stream_1 = __importDefault(require("into-stream"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const stream_meter_1 = __importDefault(require("stream-meter"));
|
||||
const common_1 = require("./common");
|
||||
const log_1 = require("./log");
|
||||
const fabricator_1 = require("./fabricator");
|
||||
const types_1 = require("./types");
|
||||
const compress_type_1 = require("./compress_type");
|
||||
'use strict';
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
const zlib_1 = require('zlib');
|
||||
const multistream_1 = __importDefault(require('multistream'));
|
||||
const assert_1 = __importDefault(require('assert'));
|
||||
const child_process_1 = require('child_process');
|
||||
const fs_extra_1 = __importDefault(require('fs-extra'));
|
||||
const into_stream_1 = __importDefault(require('into-stream'));
|
||||
const path_1 = __importDefault(require('path'));
|
||||
const stream_meter_1 = __importDefault(require('stream-meter'));
|
||||
const common_1 = require('./common');
|
||||
const log_1 = require('./log');
|
||||
const fabricator_1 = require('./fabricator');
|
||||
const types_1 = require('./types');
|
||||
const compress_type_1 = require('./compress_type');
|
||||
function discoverPlaceholder(binaryBuffer, searchString, padder) {
|
||||
const placeholder = Buffer.from(searchString);
|
||||
const position = binaryBuffer.indexOf(placeholder);
|
||||
if (position === -1) {
|
||||
return { notFound: true };
|
||||
}
|
||||
return { position, size: placeholder.length, padder };
|
||||
const placeholder = Buffer.from(searchString);
|
||||
const position = binaryBuffer.indexOf(placeholder);
|
||||
if (position === -1) {
|
||||
return { notFound: true };
|
||||
}
|
||||
return { position, size: placeholder.length, padder };
|
||||
}
|
||||
function injectPlaceholder(fd, placeholder, value, cb) {
|
||||
if ('notFound' in placeholder) {
|
||||
(0, assert_1.default)(false, 'Placeholder for not found');
|
||||
}
|
||||
const { position, size, padder } = placeholder;
|
||||
let stringValue = Buffer.from('');
|
||||
if (typeof value === 'number') {
|
||||
stringValue = Buffer.from(value.toString());
|
||||
}
|
||||
else if (typeof value === 'string') {
|
||||
stringValue = Buffer.from(value);
|
||||
}
|
||||
else {
|
||||
stringValue = value;
|
||||
}
|
||||
const padding = Buffer.from(padder.repeat(size - stringValue.length));
|
||||
stringValue = Buffer.concat([stringValue, padding]);
|
||||
fs_extra_1.default.write(fd, stringValue, 0, stringValue.length, position, cb);
|
||||
if ('notFound' in placeholder) {
|
||||
(0, assert_1.default)(false, 'Placeholder for not found');
|
||||
}
|
||||
const { position, size, padder } = placeholder;
|
||||
let stringValue = Buffer.from('');
|
||||
if (typeof value === 'number') {
|
||||
stringValue = Buffer.from(value.toString());
|
||||
} else if (typeof value === 'string') {
|
||||
stringValue = Buffer.from(value);
|
||||
} else {
|
||||
stringValue = value;
|
||||
}
|
||||
const padding = Buffer.from(padder.repeat(size - stringValue.length));
|
||||
stringValue = Buffer.concat([stringValue, padding]);
|
||||
fs_extra_1.default.write(
|
||||
fd,
|
||||
stringValue,
|
||||
0,
|
||||
stringValue.length,
|
||||
position,
|
||||
cb
|
||||
);
|
||||
}
|
||||
function discoverPlaceholders(binaryBuffer) {
|
||||
return {
|
||||
BAKERY: discoverPlaceholder(binaryBuffer, `\0${'// BAKERY '.repeat(20)}`, '\0'),
|
||||
PAYLOAD_POSITION: discoverPlaceholder(binaryBuffer, '// PAYLOAD_POSITION //', ' '),
|
||||
PAYLOAD_SIZE: discoverPlaceholder(binaryBuffer, '// PAYLOAD_SIZE //', ' '),
|
||||
PRELUDE_POSITION: discoverPlaceholder(binaryBuffer, '// PRELUDE_POSITION //', ' '),
|
||||
PRELUDE_SIZE: discoverPlaceholder(binaryBuffer, '// PRELUDE_SIZE //', ' '),
|
||||
};
|
||||
return {
|
||||
BAKERY: discoverPlaceholder(
|
||||
binaryBuffer,
|
||||
`\0${'// BAKERY '.repeat(20)}`,
|
||||
'\0'
|
||||
),
|
||||
PAYLOAD_POSITION: discoverPlaceholder(
|
||||
binaryBuffer,
|
||||
'// PAYLOAD_POSITION //',
|
||||
' '
|
||||
),
|
||||
PAYLOAD_SIZE: discoverPlaceholder(binaryBuffer, '// PAYLOAD_SIZE //', ' '),
|
||||
PRELUDE_POSITION: discoverPlaceholder(
|
||||
binaryBuffer,
|
||||
'// PRELUDE_POSITION //',
|
||||
' '
|
||||
),
|
||||
PRELUDE_SIZE: discoverPlaceholder(binaryBuffer, '// PRELUDE_SIZE //', ' '),
|
||||
};
|
||||
}
|
||||
function injectPlaceholders(fd, placeholders, values, cb) {
|
||||
injectPlaceholder(fd, placeholders.BAKERY, values.BAKERY, (error) => {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
injectPlaceholder(fd, placeholders.BAKERY, values.BAKERY, (error) => {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
injectPlaceholder(
|
||||
fd,
|
||||
placeholders.PAYLOAD_POSITION,
|
||||
values.PAYLOAD_POSITION,
|
||||
(error2) => {
|
||||
if (error2) {
|
||||
return cb(error2);
|
||||
}
|
||||
injectPlaceholder(fd, placeholders.PAYLOAD_POSITION, values.PAYLOAD_POSITION, (error2) => {
|
||||
if (error2) {
|
||||
return cb(error2);
|
||||
injectPlaceholder(
|
||||
fd,
|
||||
placeholders.PAYLOAD_SIZE,
|
||||
values.PAYLOAD_SIZE,
|
||||
(error3) => {
|
||||
if (error3) {
|
||||
return cb(error3);
|
||||
}
|
||||
injectPlaceholder(fd, placeholders.PAYLOAD_SIZE, values.PAYLOAD_SIZE, (error3) => {
|
||||
if (error3) {
|
||||
return cb(error3);
|
||||
injectPlaceholder(
|
||||
fd,
|
||||
placeholders.PRELUDE_POSITION,
|
||||
values.PRELUDE_POSITION,
|
||||
(error4) => {
|
||||
if (error4) {
|
||||
return cb(error4);
|
||||
}
|
||||
injectPlaceholder(fd, placeholders.PRELUDE_POSITION, values.PRELUDE_POSITION, (error4) => {
|
||||
if (error4) {
|
||||
return cb(error4);
|
||||
}
|
||||
injectPlaceholder(fd, placeholders.PRELUDE_SIZE, values.PRELUDE_SIZE, cb);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
injectPlaceholder(
|
||||
fd,
|
||||
placeholders.PRELUDE_SIZE,
|
||||
values.PRELUDE_SIZE,
|
||||
cb
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
function makeBakeryValueFromBakes(bakes) {
|
||||
const parts = [];
|
||||
if (bakes.length) {
|
||||
for (let i = 0; i < bakes.length; i += 1) {
|
||||
parts.push(Buffer.from(bakes[i]));
|
||||
parts.push(Buffer.alloc(1));
|
||||
}
|
||||
parts.push(Buffer.alloc(1));
|
||||
const parts = [];
|
||||
if (bakes.length) {
|
||||
for (let i = 0; i < bakes.length; i += 1) {
|
||||
parts.push(Buffer.from(bakes[i]));
|
||||
parts.push(Buffer.alloc(1));
|
||||
}
|
||||
return Buffer.concat(parts);
|
||||
parts.push(Buffer.alloc(1));
|
||||
}
|
||||
return Buffer.concat(parts);
|
||||
}
|
||||
function replaceDollarWise(s, sf, st) {
|
||||
return s.replace(sf, () => st);
|
||||
return s.replace(sf, () => st);
|
||||
}
|
||||
function makePreludeBufferFromPrelude(prelude) {
|
||||
return Buffer.from(`(function(process, require, console, EXECPATH_FD, PAYLOAD_POSITION, PAYLOAD_SIZE) { ${prelude}\n})` // dont remove \n
|
||||
);
|
||||
return Buffer.from(
|
||||
`(function(process, require, console, EXECPATH_FD, PAYLOAD_POSITION, PAYLOAD_SIZE) { ${prelude}\n})` // dont remove \n
|
||||
);
|
||||
}
|
||||
function findPackageJson(nodeFile) {
|
||||
let dir = nodeFile;
|
||||
while (dir !== '/') {
|
||||
dir = path_1.default.dirname(dir);
|
||||
if (fs_extra_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
|
||||
break;
|
||||
}
|
||||
let dir = nodeFile;
|
||||
while (dir !== '/') {
|
||||
dir = path_1.default.dirname(dir);
|
||||
if (
|
||||
fs_extra_1.default.existsSync(path_1.default.join(dir, 'package.json'))
|
||||
) {
|
||||
break;
|
||||
}
|
||||
if (dir === '/') {
|
||||
throw new Error(`package.json not found for "${nodeFile}"`);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
if (dir === '/') {
|
||||
throw new Error(`package.json not found for "${nodeFile}"`);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
function nativePrebuildInstall(target, nodeFile) {
|
||||
var _a, _b;
|
||||
const prebuildInstall = path_1.default.join(__dirname, '../node_modules/.bin/prebuild-install');
|
||||
const dir = findPackageJson(nodeFile);
|
||||
// parse the target node version from the binaryPath
|
||||
const nodeVersion = path_1.default.basename(target.binaryPath).split('-')[1];
|
||||
if (!/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(nodeVersion)) {
|
||||
throw new Error(`Couldn't find node version, instead got: ${nodeVersion}`);
|
||||
}
|
||||
const nativeFile = `${nodeFile}.${target.platform}.${nodeVersion}`;
|
||||
if (fs_extra_1.default.existsSync(nativeFile)) {
|
||||
return nativeFile;
|
||||
}
|
||||
// prebuild-install will overwrite the target .node file, so take a backup
|
||||
if (!fs_extra_1.default.existsSync(`${nodeFile}.bak`)) {
|
||||
fs_extra_1.default.copyFileSync(nodeFile, `${nodeFile}.bak`);
|
||||
}
|
||||
const napiVersions = (_b = (_a = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(dir, 'package.json'), { encoding: 'utf-8' }))) === null || _a === void 0 ? void 0 : _a.binary) === null || _b === void 0 ? void 0 : _b.napi_versions;
|
||||
const options = [
|
||||
'--platform',
|
||||
types_1.platform[target.platform],
|
||||
'--arch',
|
||||
target.arch,
|
||||
];
|
||||
if (napiVersions == null) {
|
||||
// TODO: consider target node version and supported n-api version
|
||||
options.push('--target', nodeVersion);
|
||||
}
|
||||
// run prebuild
|
||||
(0, child_process_1.execFileSync)(prebuildInstall, options, { cwd: dir });
|
||||
// move the prebuild to a new name with a platform/version extension
|
||||
fs_extra_1.default.copyFileSync(nodeFile, nativeFile);
|
||||
// put the backed up file back
|
||||
fs_extra_1.default.moveSync(`${nodeFile}.bak`, nodeFile, { overwrite: true });
|
||||
var _a, _b;
|
||||
const prebuildInstall = path_1.default.join(
|
||||
__dirname,
|
||||
'../node_modules/.bin/prebuild-install'
|
||||
);
|
||||
const dir = findPackageJson(nodeFile);
|
||||
// parse the target node version from the binaryPath
|
||||
const nodeVersion = path_1.default.basename(target.binaryPath).split('-')[1];
|
||||
if (!/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(nodeVersion)) {
|
||||
throw new Error(`Couldn't find node version, instead got: ${nodeVersion}`);
|
||||
}
|
||||
const nativeFile = `${nodeFile}.${target.platform}.${nodeVersion}`;
|
||||
if (fs_extra_1.default.existsSync(nativeFile)) {
|
||||
return nativeFile;
|
||||
}
|
||||
// prebuild-install will overwrite the target .node file, so take a backup
|
||||
if (!fs_extra_1.default.existsSync(`${nodeFile}.bak`)) {
|
||||
fs_extra_1.default.copyFileSync(nodeFile, `${nodeFile}.bak`);
|
||||
}
|
||||
const napiVersions =
|
||||
(
|
||||
(_b =
|
||||
(
|
||||
(_a = JSON.parse(
|
||||
fs_extra_1.default.readFileSync(
|
||||
path_1.default.join(dir, 'package.json'),
|
||||
{ encoding: 'utf-8' }
|
||||
)
|
||||
)) === null || _a === void 0
|
||||
) ?
|
||||
void 0
|
||||
: _a.binary) === null || _b === void 0
|
||||
) ?
|
||||
void 0
|
||||
: _b.napi_versions;
|
||||
const options = [
|
||||
'--platform',
|
||||
types_1.platform[target.platform],
|
||||
'--arch',
|
||||
target.arch,
|
||||
];
|
||||
if (napiVersions == null) {
|
||||
// TODO: consider target node version and supported n-api version
|
||||
options.push('--target', nodeVersion);
|
||||
}
|
||||
// run prebuild
|
||||
(0, child_process_1.execFileSync)(prebuildInstall, options, { cwd: dir });
|
||||
// move the prebuild to a new name with a platform/version extension
|
||||
fs_extra_1.default.copyFileSync(nodeFile, nativeFile);
|
||||
// put the backed up file back
|
||||
fs_extra_1.default.moveSync(`${nodeFile}.bak`, nodeFile, { overwrite: true });
|
||||
return nativeFile;
|
||||
}
|
||||
/**
|
||||
* instead of creating a vfs dicionnary with actual path as key
|
||||
@ -176,169 +236,243 @@ function nativePrebuildInstall(target, nodeFile) {
|
||||
const fileDictionary = {};
|
||||
let counter = 0;
|
||||
function getOrCreateHash(fileOrFolderName) {
|
||||
let existingKey = fileDictionary[fileOrFolderName];
|
||||
if (!existingKey) {
|
||||
const newkey = counter;
|
||||
counter += 1;
|
||||
existingKey = newkey.toString(36);
|
||||
fileDictionary[fileOrFolderName] = existingKey;
|
||||
}
|
||||
return existingKey;
|
||||
let existingKey = fileDictionary[fileOrFolderName];
|
||||
if (!existingKey) {
|
||||
const newkey = counter;
|
||||
counter += 1;
|
||||
existingKey = newkey.toString(36);
|
||||
fileDictionary[fileOrFolderName] = existingKey;
|
||||
}
|
||||
return existingKey;
|
||||
}
|
||||
const separator = '/';
|
||||
function makeKey(doCompression, fullpath, slash) {
|
||||
if (doCompression === compress_type_1.CompressType.None)
|
||||
return fullpath;
|
||||
return fullpath.split(slash).map(getOrCreateHash).join(separator);
|
||||
if (doCompression === compress_type_1.CompressType.None) return fullpath;
|
||||
return fullpath.split(slash).map(getOrCreateHash).join(separator);
|
||||
}
|
||||
function producer({ backpack, bakes, slash, target, symLinks, doCompress, nativeBuild, }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!Buffer.alloc) {
|
||||
throw (0, log_1.wasReported)('Your node.js does not have Buffer.alloc. Please upgrade!');
|
||||
function producer({
|
||||
backpack,
|
||||
bakes,
|
||||
slash,
|
||||
target,
|
||||
symLinks,
|
||||
doCompress,
|
||||
nativeBuild,
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!Buffer.alloc) {
|
||||
throw (0, log_1.wasReported)(
|
||||
'Your node.js does not have Buffer.alloc. Please upgrade!'
|
||||
);
|
||||
}
|
||||
const { prelude } = backpack;
|
||||
let { entrypoint, stripes } = backpack;
|
||||
entrypoint = (0, common_1.snapshotify)(entrypoint, slash);
|
||||
stripes = stripes.slice();
|
||||
const vfs = {};
|
||||
for (const stripe of stripes) {
|
||||
let { snap } = stripe;
|
||||
snap = (0, common_1.snapshotify)(snap, slash);
|
||||
const vfsKey = makeKey(doCompress, snap, slash);
|
||||
if (!vfs[vfsKey]) vfs[vfsKey] = {};
|
||||
}
|
||||
const snapshotSymLinks = {};
|
||||
for (const [key, value] of Object.entries(symLinks)) {
|
||||
const k = (0, common_1.snapshotify)(key, slash);
|
||||
const v = (0, common_1.snapshotify)(value, slash);
|
||||
const vfsKey = makeKey(doCompress, k, slash);
|
||||
snapshotSymLinks[vfsKey] = makeKey(doCompress, v, slash);
|
||||
}
|
||||
let meter;
|
||||
let count = 0;
|
||||
function pipeToNewMeter(s) {
|
||||
meter = (0, stream_meter_1.default)();
|
||||
return s.pipe(meter);
|
||||
}
|
||||
function pipeMayCompressToNewMeter(s) {
|
||||
if (doCompress === compress_type_1.CompressType.GZip) {
|
||||
return pipeToNewMeter(s.pipe((0, zlib_1.createGzip)()));
|
||||
}
|
||||
if (doCompress === compress_type_1.CompressType.Brotli) {
|
||||
return pipeToNewMeter(s.pipe((0, zlib_1.createBrotliCompress)()));
|
||||
}
|
||||
return pipeToNewMeter(s);
|
||||
}
|
||||
function next(s) {
|
||||
count += 1;
|
||||
return pipeToNewMeter(s);
|
||||
}
|
||||
const binaryBuffer = fs_extra_1.default.readFileSync(target.binaryPath);
|
||||
const placeholders = discoverPlaceholders(binaryBuffer);
|
||||
let track = 0;
|
||||
let prevStripe;
|
||||
let payloadPosition;
|
||||
let payloadSize;
|
||||
let preludePosition;
|
||||
let preludeSize;
|
||||
new multistream_1.default((cb) => {
|
||||
if (count === 0) {
|
||||
return cb(null, next((0, into_stream_1.default)(binaryBuffer)));
|
||||
}
|
||||
if (count === 1) {
|
||||
payloadPosition = meter.bytes;
|
||||
return cb(null, next((0, into_stream_1.default)(Buffer.alloc(0))));
|
||||
}
|
||||
if (count === 2) {
|
||||
if (prevStripe && !prevStripe.skip) {
|
||||
const { store } = prevStripe;
|
||||
let { snap } = prevStripe;
|
||||
snap = (0, common_1.snapshotify)(snap, slash);
|
||||
const vfsKey = makeKey(doCompress, snap, slash);
|
||||
vfs[vfsKey][store] = [track, meter.bytes];
|
||||
track += meter.bytes;
|
||||
}
|
||||
const { prelude } = backpack;
|
||||
let { entrypoint, stripes } = backpack;
|
||||
entrypoint = (0, common_1.snapshotify)(entrypoint, slash);
|
||||
stripes = stripes.slice();
|
||||
const vfs = {};
|
||||
for (const stripe of stripes) {
|
||||
let { snap } = stripe;
|
||||
snap = (0, common_1.snapshotify)(snap, slash);
|
||||
const vfsKey = makeKey(doCompress, snap, slash);
|
||||
if (!vfs[vfsKey])
|
||||
vfs[vfsKey] = {};
|
||||
}
|
||||
const snapshotSymLinks = {};
|
||||
for (const [key, value] of Object.entries(symLinks)) {
|
||||
const k = (0, common_1.snapshotify)(key, slash);
|
||||
const v = (0, common_1.snapshotify)(value, slash);
|
||||
const vfsKey = makeKey(doCompress, k, slash);
|
||||
snapshotSymLinks[vfsKey] = makeKey(doCompress, v, slash);
|
||||
}
|
||||
let meter;
|
||||
let count = 0;
|
||||
function pipeToNewMeter(s) {
|
||||
meter = (0, stream_meter_1.default)();
|
||||
return s.pipe(meter);
|
||||
}
|
||||
function pipeMayCompressToNewMeter(s) {
|
||||
if (doCompress === compress_type_1.CompressType.GZip) {
|
||||
return pipeToNewMeter(s.pipe((0, zlib_1.createGzip)()));
|
||||
}
|
||||
if (doCompress === compress_type_1.CompressType.Brotli) {
|
||||
return pipeToNewMeter(s.pipe((0, zlib_1.createBrotliCompress)()));
|
||||
}
|
||||
return pipeToNewMeter(s);
|
||||
}
|
||||
function next(s) {
|
||||
count += 1;
|
||||
return pipeToNewMeter(s);
|
||||
}
|
||||
const binaryBuffer = fs_extra_1.default.readFileSync(target.binaryPath);
|
||||
const placeholders = discoverPlaceholders(binaryBuffer);
|
||||
let track = 0;
|
||||
let prevStripe;
|
||||
let payloadPosition;
|
||||
let payloadSize;
|
||||
let preludePosition;
|
||||
let preludeSize;
|
||||
new multistream_1.default((cb) => {
|
||||
if (count === 0) {
|
||||
return cb(null, next((0, into_stream_1.default)(binaryBuffer)));
|
||||
}
|
||||
if (count === 1) {
|
||||
payloadPosition = meter.bytes;
|
||||
return cb(null, next((0, into_stream_1.default)(Buffer.alloc(0))));
|
||||
}
|
||||
if (count === 2) {
|
||||
if (prevStripe && !prevStripe.skip) {
|
||||
const { store } = prevStripe;
|
||||
let { snap } = prevStripe;
|
||||
snap = (0, common_1.snapshotify)(snap, slash);
|
||||
const vfsKey = makeKey(doCompress, snap, slash);
|
||||
vfs[vfsKey][store] = [track, meter.bytes];
|
||||
track += meter.bytes;
|
||||
}
|
||||
if (stripes.length) {
|
||||
// clone to prevent 'skip' propagate
|
||||
// to other targets, since same stripe
|
||||
// is used for several targets
|
||||
const stripe = Object.assign({}, stripes.shift());
|
||||
prevStripe = stripe;
|
||||
if (stripe.buffer) {
|
||||
if (stripe.store === common_1.STORE_BLOB) {
|
||||
const snap = (0, common_1.snapshotify)(stripe.snap, slash);
|
||||
return (0, fabricator_1.fabricateTwice)(bakes, target.fabricator, snap, stripe.buffer, (error, buffer) => {
|
||||
if (error) {
|
||||
log_1.log.warn(error.message);
|
||||
stripe.skip = true;
|
||||
return cb(null, (0, into_stream_1.default)(Buffer.alloc(0)));
|
||||
}
|
||||
cb(null, pipeMayCompressToNewMeter((0, into_stream_1.default)(buffer || Buffer.from(''))));
|
||||
});
|
||||
}
|
||||
return cb(null, pipeMayCompressToNewMeter((0, into_stream_1.default)(stripe.buffer)));
|
||||
}
|
||||
if (stripe.file) {
|
||||
if (stripe.file === target.output) {
|
||||
return cb((0, log_1.wasReported)('Trying to take executable into executable', stripe.file), null);
|
||||
}
|
||||
assert_1.default.strictEqual(stripe.store, common_1.STORE_CONTENT); // others must be buffers from walker
|
||||
if ((0, common_1.isDotNODE)(stripe.file) && nativeBuild) {
|
||||
try {
|
||||
const platformFile = nativePrebuildInstall(target, stripe.file);
|
||||
if (fs_extra_1.default.existsSync(platformFile)) {
|
||||
return cb(null, pipeMayCompressToNewMeter(fs_extra_1.default.createReadStream(platformFile)));
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
log_1.log.debug(`prebuild-install failed[${stripe.file}]:`, err.message);
|
||||
}
|
||||
}
|
||||
return cb(null, pipeMayCompressToNewMeter(fs_extra_1.default.createReadStream(stripe.file)));
|
||||
}
|
||||
(0, assert_1.default)(false, 'producer: bad stripe');
|
||||
}
|
||||
else {
|
||||
payloadSize = track;
|
||||
preludePosition = payloadPosition + payloadSize;
|
||||
return cb(null, next((0, into_stream_1.default)(makePreludeBufferFromPrelude(replaceDollarWise(replaceDollarWise(replaceDollarWise(replaceDollarWise(replaceDollarWise(prelude, '%VIRTUAL_FILESYSTEM%', JSON.stringify(vfs)), '%DEFAULT_ENTRYPOINT%', JSON.stringify(entrypoint)), '%SYMLINKS%', JSON.stringify(snapshotSymLinks)), '%DICT%', JSON.stringify(fileDictionary)), '%DOCOMPRESS%', JSON.stringify(doCompress))))));
|
||||
if (stripes.length) {
|
||||
// clone to prevent 'skip' propagate
|
||||
// to other targets, since same stripe
|
||||
// is used for several targets
|
||||
const stripe = Object.assign({}, stripes.shift());
|
||||
prevStripe = stripe;
|
||||
if (stripe.buffer) {
|
||||
if (stripe.store === common_1.STORE_BLOB) {
|
||||
const snap = (0, common_1.snapshotify)(stripe.snap, slash);
|
||||
return (0, fabricator_1.fabricateTwice)(
|
||||
bakes,
|
||||
target.fabricator,
|
||||
snap,
|
||||
stripe.buffer,
|
||||
(error, buffer) => {
|
||||
if (error) {
|
||||
log_1.log.warn(error.message);
|
||||
stripe.skip = true;
|
||||
return cb(
|
||||
null,
|
||||
(0, into_stream_1.default)(Buffer.alloc(0))
|
||||
);
|
||||
}
|
||||
cb(
|
||||
null,
|
||||
pipeMayCompressToNewMeter(
|
||||
(0, into_stream_1.default)(buffer || Buffer.from(''))
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
return cb(null, null);
|
||||
return cb(
|
||||
null,
|
||||
pipeMayCompressToNewMeter(
|
||||
(0, into_stream_1.default)(stripe.buffer)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (stripe.file) {
|
||||
if (stripe.file === target.output) {
|
||||
return cb(
|
||||
(0, log_1.wasReported)(
|
||||
'Trying to take executable into executable',
|
||||
stripe.file
|
||||
),
|
||||
null
|
||||
);
|
||||
}
|
||||
})
|
||||
.on('error', (error) => {
|
||||
reject(error);
|
||||
})
|
||||
.pipe(fs_extra_1.default.createWriteStream(target.output))
|
||||
.on('error', (error) => {
|
||||
reject(error);
|
||||
})
|
||||
.on('close', () => {
|
||||
preludeSize = meter.bytes;
|
||||
fs_extra_1.default.open(target.output, 'r+', (error, fd) => {
|
||||
if (error)
|
||||
return reject(error);
|
||||
injectPlaceholders(fd, placeholders, {
|
||||
BAKERY: makeBakeryValueFromBakes(bakes),
|
||||
PAYLOAD_POSITION: payloadPosition,
|
||||
PAYLOAD_SIZE: payloadSize,
|
||||
PRELUDE_POSITION: preludePosition,
|
||||
PRELUDE_SIZE: preludeSize,
|
||||
}, (error2) => {
|
||||
if (error2)
|
||||
return reject(error2);
|
||||
fs_extra_1.default.close(fd, (error3) => {
|
||||
if (error3)
|
||||
return reject(error3);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
assert_1.default.strictEqual(stripe.store, common_1.STORE_CONTENT); // others must be buffers from walker
|
||||
if ((0, common_1.isDotNODE)(stripe.file) && nativeBuild) {
|
||||
try {
|
||||
const platformFile = nativePrebuildInstall(target, stripe.file);
|
||||
if (fs_extra_1.default.existsSync(platformFile)) {
|
||||
return cb(
|
||||
null,
|
||||
pipeMayCompressToNewMeter(
|
||||
fs_extra_1.default.createReadStream(platformFile)
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
log_1.log.debug(
|
||||
`prebuild-install failed[${stripe.file}]:`,
|
||||
err.message
|
||||
);
|
||||
}
|
||||
}
|
||||
return cb(
|
||||
null,
|
||||
pipeMayCompressToNewMeter(
|
||||
fs_extra_1.default.createReadStream(stripe.file)
|
||||
)
|
||||
);
|
||||
}
|
||||
(0, assert_1.default)(false, 'producer: bad stripe');
|
||||
} else {
|
||||
payloadSize = track;
|
||||
preludePosition = payloadPosition + payloadSize;
|
||||
return cb(
|
||||
null,
|
||||
next(
|
||||
(0, into_stream_1.default)(
|
||||
makePreludeBufferFromPrelude(
|
||||
replaceDollarWise(
|
||||
replaceDollarWise(
|
||||
replaceDollarWise(
|
||||
replaceDollarWise(
|
||||
replaceDollarWise(
|
||||
prelude,
|
||||
'%VIRTUAL_FILESYSTEM%',
|
||||
JSON.stringify(vfs)
|
||||
),
|
||||
'%DEFAULT_ENTRYPOINT%',
|
||||
JSON.stringify(entrypoint)
|
||||
),
|
||||
'%SYMLINKS%',
|
||||
JSON.stringify(snapshotSymLinks)
|
||||
),
|
||||
'%DICT%',
|
||||
JSON.stringify(fileDictionary)
|
||||
),
|
||||
'%DOCOMPRESS%',
|
||||
JSON.stringify(doCompress)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return cb(null, null);
|
||||
}
|
||||
})
|
||||
.on('error', (error) => {
|
||||
reject(error);
|
||||
})
|
||||
.pipe(fs_extra_1.default.createWriteStream(target.output))
|
||||
.on('error', (error) => {
|
||||
reject(error);
|
||||
})
|
||||
.on('close', () => {
|
||||
preludeSize = meter.bytes;
|
||||
fs_extra_1.default.open(target.output, 'r+', (error, fd) => {
|
||||
if (error) return reject(error);
|
||||
injectPlaceholders(
|
||||
fd,
|
||||
placeholders,
|
||||
{
|
||||
BAKERY: makeBakeryValueFromBakes(bakes),
|
||||
PAYLOAD_POSITION: payloadPosition,
|
||||
PAYLOAD_SIZE: payloadSize,
|
||||
PRELUDE_POSITION: preludePosition,
|
||||
PRELUDE_SIZE: preludeSize,
|
||||
},
|
||||
(error2) => {
|
||||
if (error2) return reject(error2);
|
||||
fs_extra_1.default.close(fd, (error3) => {
|
||||
if (error3) return reject(error3);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = producer;
|
||||
//# sourceMappingURL=producer.js.map
|
||||
//# sourceMappingURL=producer.js.map
|
||||
|
145
node_modules/pkg/lib-es5/refiner.js
generated
vendored
145
node_modules/pkg/lib-es5/refiner.js
generated
vendored
@ -1,87 +1,88 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
const common_1 = require("./common");
|
||||
const log_1 = require("./log");
|
||||
'use strict';
|
||||
var __importDefault =
|
||||
(this && this.__importDefault) ||
|
||||
function (mod) {
|
||||
return mod && mod.__esModule ? mod : { default: mod };
|
||||
};
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
const path_1 = __importDefault(require('path'));
|
||||
const chalk_1 = __importDefault(require('chalk'));
|
||||
const common_1 = require('./common');
|
||||
const log_1 = require('./log');
|
||||
const win32 = process.platform === 'win32';
|
||||
function hasParent(file, records) {
|
||||
const dirname = path_1.default.dirname(file);
|
||||
// root directory
|
||||
if (dirname === file) {
|
||||
return false;
|
||||
}
|
||||
return Boolean(records[dirname]);
|
||||
const dirname = path_1.default.dirname(file);
|
||||
// root directory
|
||||
if (dirname === file) {
|
||||
return false;
|
||||
}
|
||||
return Boolean(records[dirname]);
|
||||
}
|
||||
function purgeTopDirectories(records) {
|
||||
while (true) {
|
||||
let found = false;
|
||||
for (const file in records) {
|
||||
if (records[file]) {
|
||||
const record = records[file];
|
||||
const links = record[common_1.STORE_LINKS];
|
||||
if (links && links.length === 1) {
|
||||
if (!hasParent(file, records)) {
|
||||
const file2 = path_1.default.join(file, links[0]);
|
||||
const record2 = records[file2];
|
||||
const links2 = record2[common_1.STORE_LINKS];
|
||||
if (links2 && links2.length === 1) {
|
||||
const file3 = path_1.default.join(file2, links2[0]);
|
||||
const record3 = records[file3];
|
||||
const links3 = record3[common_1.STORE_LINKS];
|
||||
if (links3) {
|
||||
delete records[file];
|
||||
log_1.log.debug(chalk_1.default.cyan('Deleting record file :', file));
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
let found = false;
|
||||
for (const file in records) {
|
||||
if (records[file]) {
|
||||
const record = records[file];
|
||||
const links = record[common_1.STORE_LINKS];
|
||||
if (links && links.length === 1) {
|
||||
if (!hasParent(file, records)) {
|
||||
const file2 = path_1.default.join(file, links[0]);
|
||||
const record2 = records[file2];
|
||||
const links2 = record2[common_1.STORE_LINKS];
|
||||
if (links2 && links2.length === 1) {
|
||||
const file3 = path_1.default.join(file2, links2[0]);
|
||||
const record3 = records[file3];
|
||||
const links3 = record3[common_1.STORE_LINKS];
|
||||
if (links3) {
|
||||
delete records[file];
|
||||
log_1.log.debug(
|
||||
chalk_1.default.cyan('Deleting record file :', file)
|
||||
);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) break;
|
||||
}
|
||||
}
|
||||
function denominate(records, entrypoint, denominator, symLinks) {
|
||||
const newRecords = {};
|
||||
const makeSnap = (file) => {
|
||||
let snap = (0, common_1.substituteDenominator)(file, denominator);
|
||||
if (win32) {
|
||||
if (snap.slice(1) === ':')
|
||||
snap += '\\';
|
||||
}
|
||||
else if (snap === '') {
|
||||
snap = '/';
|
||||
}
|
||||
return snap;
|
||||
};
|
||||
for (const file in records) {
|
||||
if (records[file]) {
|
||||
const snap = makeSnap(file);
|
||||
newRecords[snap] = records[file];
|
||||
}
|
||||
const newRecords = {};
|
||||
const makeSnap = (file) => {
|
||||
let snap = (0, common_1.substituteDenominator)(file, denominator);
|
||||
if (win32) {
|
||||
if (snap.slice(1) === ':') snap += '\\';
|
||||
} else if (snap === '') {
|
||||
snap = '/';
|
||||
}
|
||||
const tmpSymLinks = symLinks;
|
||||
symLinks = {};
|
||||
for (const [key, value] of Object.entries(tmpSymLinks)) {
|
||||
const key1 = makeSnap(key);
|
||||
const value1 = makeSnap(value);
|
||||
symLinks[key1] = value1;
|
||||
return snap;
|
||||
};
|
||||
for (const file in records) {
|
||||
if (records[file]) {
|
||||
const snap = makeSnap(file);
|
||||
newRecords[snap] = records[file];
|
||||
}
|
||||
return {
|
||||
records: newRecords,
|
||||
entrypoint: (0, common_1.substituteDenominator)(entrypoint, denominator),
|
||||
symLinks,
|
||||
};
|
||||
}
|
||||
const tmpSymLinks = symLinks;
|
||||
symLinks = {};
|
||||
for (const [key, value] of Object.entries(tmpSymLinks)) {
|
||||
const key1 = makeSnap(key);
|
||||
const value1 = makeSnap(value);
|
||||
symLinks[key1] = value1;
|
||||
}
|
||||
return {
|
||||
records: newRecords,
|
||||
entrypoint: (0, common_1.substituteDenominator)(entrypoint, denominator),
|
||||
symLinks,
|
||||
};
|
||||
}
|
||||
function refiner(records, entrypoint, symLinks) {
|
||||
purgeTopDirectories(records);
|
||||
const denominator = (0, common_1.retrieveDenominator)(Object.keys(records));
|
||||
return denominate(records, entrypoint, denominator, symLinks);
|
||||
purgeTopDirectories(records);
|
||||
const denominator = (0, common_1.retrieveDenominator)(Object.keys(records));
|
||||
return denominate(records, entrypoint, denominator, symLinks);
|
||||
}
|
||||
exports.default = refiner;
|
||||
//# sourceMappingURL=refiner.js.map
|
||||
//# sourceMappingURL=refiner.js.map
|
||||
|
12
node_modules/pkg/lib-es5/types.js
generated
vendored
12
node_modules/pkg/lib-es5/types.js
generated
vendored
@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
exports.platform = void 0;
|
||||
exports.platform = {
|
||||
macos: 'darwin',
|
||||
win: 'win32',
|
||||
linux: 'linux',
|
||||
macos: 'darwin',
|
||||
win: 'win32',
|
||||
linux: 'linux',
|
||||
};
|
||||
//# sourceMappingURL=types.js.map
|
||||
//# sourceMappingURL=types.js.map
|
||||
|
1667
node_modules/pkg/lib-es5/walker.js
generated
vendored
1667
node_modules/pkg/lib-es5/walker.js
generated
vendored
File diff suppressed because it is too large
Load Diff
9
node_modules/pkg/prelude/bootstrap.js
generated
vendored
9
node_modules/pkg/prelude/bootstrap.js
generated
vendored
@ -1825,8 +1825,8 @@ function payloadFileSync(pointer) {
|
||||
if (!entityContent) {
|
||||
return returnArray ? [undefined, false] : undefined;
|
||||
}
|
||||
return returnArray
|
||||
? [payloadFileSync(entityContent).toString(), true]
|
||||
return returnArray ?
|
||||
[payloadFileSync(entityContent).toString(), true]
|
||||
: payloadFileSync(entityContent).toString();
|
||||
};
|
||||
|
||||
@ -1912,9 +1912,8 @@ function payloadFileSync(pointer) {
|
||||
sourceless: !entityContent,
|
||||
};
|
||||
|
||||
const code = entityContent
|
||||
? Module.wrap(payloadFileSync(entityContent))
|
||||
: undefined;
|
||||
const code =
|
||||
entityContent ? Module.wrap(payloadFileSync(entityContent)) : undefined;
|
||||
|
||||
const script = new Script(code, options);
|
||||
const wrapper = script.runInThisContext(options);
|
||||
|
Reference in New Issue
Block a user