@metamask/snaps-cli 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders.d.ts +0 -1
- package/dist/builders.js +0 -6
- package/dist/builders.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +7 -6
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.js +6 -11
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/index.js +0 -1
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/build/utils.js +1 -1
- package/dist/cmds/build/utils.js.map +1 -1
- package/dist/cmds/eval/evalHandler.d.ts +1 -1
- package/dist/cmds/eval/evalHandler.js +8 -9
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/eval/index.js +1 -1
- package/dist/cmds/eval/index.js.map +1 -1
- package/dist/cmds/init/index.js +1 -5
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +1 -1
- package/dist/cmds/init/initHandler.js +9 -10
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +1 -1
- package/dist/cmds/init/initUtils.js +12 -12
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/index.js +1 -1
- package/dist/cmds/manifest/index.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +1 -10
- package/dist/cmds/manifest/manifestHandler.js +23 -180
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/serveHandler.js +6 -2
- package/dist/cmds/serve/serveHandler.js.map +1 -1
- package/dist/cmds/watch/index.js +0 -1
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +6 -5
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/tsconfig.json +6 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/misc.d.ts +0 -1
- package/dist/utils/misc.js +1 -3
- package/dist/utils/misc.js.map +1 -1
- package/package.json +4 -5
- package/dist/cmds/eval/eval-worker.d.ts +0 -1
- package/dist/cmds/eval/eval-worker.js +0 -40
- package/dist/cmds/eval/eval-worker.js.map +0 -1
- package/dist/cmds/eval/mock.d.ts +0 -14
- package/dist/cmds/eval/mock.js +0 -98
- package/dist/cmds/eval/mock.js.map +0 -1
- package/dist/cmds/eval/workerEval.d.ts +0 -8
- package/dist/cmds/eval/workerEval.js +0 -37
- package/dist/cmds/eval/workerEval.js.map +0 -1
- package/dist/utils/fs.d.ts +0 -24
- package/dist/utils/fs.js +0 -66
- package/dist/utils/fs.js.map +0 -1
- package/dist/utils/snap-config.__GENERATED__.d.ts +0 -2
- package/dist/utils/snap-config.__GENERATED__.js +0 -18
- package/dist/utils/snap-config.__GENERATED__.js.map +0 -1
- package/dist/utils/validate-fs.d.ts +0 -35
- package/dist/utils/validate-fs.js +0 -69
- package/dist/utils/validate-fs.js.map +0 -1
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,2CAA8C;
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,2CAA8C;AAGjC,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW,GAAG,gBAAgB,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GA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,CAAC;SACvC;KACF;IAAC,OAAO,WAAW,EAAE;QACpB,QAAQ,CAAC,GAAG,eAAe,gCAAgC,EAAE,WAAW,CAAC,CAAC;KAC3E;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,uEAAuE;QACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AA1BD,gCA0BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${value}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message.\n * @param err - The original error.\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message.\n * @param error - The original error.\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param msg - The error message.\n * @param err - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-skunkworks/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
47
47
|
"@babel/preset-env": "^7.16.7",
|
|
48
48
|
"@babel/preset-typescript": "^7.16.7",
|
|
49
|
-
"@metamask/snap-
|
|
50
|
-
"@metamask/snaps-browserify-plugin": "^0.
|
|
49
|
+
"@metamask/snap-utils": "^0.19.0",
|
|
50
|
+
"@metamask/snaps-browserify-plugin": "^0.19.0",
|
|
51
51
|
"@metamask/utils": "^2.0.0",
|
|
52
52
|
"babelify": "^10.0.0",
|
|
53
53
|
"browserify": "^17.0.0",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"init-package-json": "^1.10.3",
|
|
56
56
|
"is-url": "^1.2.4",
|
|
57
57
|
"mkdirp": "^1.0.4",
|
|
58
|
-
"rfdc": "^1.3.0",
|
|
59
58
|
"serve-handler": "^6.1.1",
|
|
60
59
|
"ses": "^0.15.15",
|
|
61
60
|
"slash": "^3.0.0",
|
|
@@ -97,7 +96,7 @@
|
|
|
97
96
|
"rimraf": "^3.0.2",
|
|
98
97
|
"ts-auto-guard": "^2.3.0",
|
|
99
98
|
"ts-jest": "^27.1.5",
|
|
100
|
-
"ts-node": "^
|
|
99
|
+
"ts-node": "^10.7.0",
|
|
101
100
|
"tsc-watch": "^4.5.0",
|
|
102
101
|
"typescript": "^4.4.0"
|
|
103
102
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'ses/lockdown';
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs_1 = require("fs");
|
|
4
|
-
// eslint-disable-next-line import/no-unassigned-import
|
|
5
|
-
require("ses/lockdown");
|
|
6
|
-
const mock_1 = require("./mock");
|
|
7
|
-
lockdown({
|
|
8
|
-
consoleTaming: 'unsafe',
|
|
9
|
-
errorTaming: 'unsafe',
|
|
10
|
-
mathTaming: 'unsafe',
|
|
11
|
-
dateTaming: 'unsafe',
|
|
12
|
-
overrideTaming: 'severe',
|
|
13
|
-
});
|
|
14
|
-
/**
|
|
15
|
-
* Get mock endowments that don't do anything. This is useful for running the
|
|
16
|
-
* eval, for snaps that try to communicate with the extension on initialisation,
|
|
17
|
-
* for example.
|
|
18
|
-
*
|
|
19
|
-
* @returns The mock endowments.
|
|
20
|
-
*/
|
|
21
|
-
function getMockEndowments() {
|
|
22
|
-
const endowments = (0, mock_1.generateMockEndowments)();
|
|
23
|
-
return {
|
|
24
|
-
...endowments,
|
|
25
|
-
window: endowments,
|
|
26
|
-
self: endowments,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const snapFilePath = process.argv[2];
|
|
30
|
-
const snapModule = { exports: {} };
|
|
31
|
-
new Compartment({
|
|
32
|
-
...getMockEndowments(),
|
|
33
|
-
module: snapModule,
|
|
34
|
-
exports: snapModule.exports,
|
|
35
|
-
}).evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
|
|
36
|
-
if (!snapModule.exports?.onRpcRequest) {
|
|
37
|
-
console.warn(`The Snap doesn't have an "onRpcRequest" export defined.`);
|
|
38
|
-
}
|
|
39
|
-
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
|
40
|
-
//# sourceMappingURL=eval-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;AAAA,2BAAkC;AAClC,uDAAuD;AACvD,wBAAsB;AACtB,iCAAgD;AAIhD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;CACzB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,CAAC;IACd,GAAG,iBAAiB,EAAE;IACtB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU,CAAC,OAAO;CAC5B,CAAC,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE;IACrC,OAAO,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;CACzE;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["import { readFileSync } from 'fs';\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nif (!snapModule.exports?.onRpcRequest) {\n console.warn(`The Snap doesn't have an \"onRpcRequest\" export defined.`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
package/dist/cmds/eval/mock.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const ALL_APIS: string[];
|
|
2
|
-
/**
|
|
3
|
-
* Check if a value is a constructor.
|
|
4
|
-
*
|
|
5
|
-
* @param value - The value to check.
|
|
6
|
-
* @returns `true` if the value is a constructor, or `false` otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export declare const isConstructor: (value: any) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.
|
|
11
|
-
*
|
|
12
|
-
* @returns A map of endowments.
|
|
13
|
-
*/
|
|
14
|
-
export declare const generateMockEndowments: () => Record<string, any>;
|
package/dist/cmds/eval/mock.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateMockEndowments = exports.isConstructor = exports.ALL_APIS = void 0;
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
const snap_controllers_1 = require("@metamask/snap-controllers");
|
|
10
|
-
const NETWORK_APIS = ['fetch', 'WebSocket'];
|
|
11
|
-
exports.ALL_APIS = [...snap_controllers_1.DEFAULT_ENDOWMENTS, ...NETWORK_APIS];
|
|
12
|
-
/**
|
|
13
|
-
* Get a mock snap provider, that always returns `true` for requests.
|
|
14
|
-
*
|
|
15
|
-
* @returns A mocked snap provider.
|
|
16
|
-
*/
|
|
17
|
-
function getMockSnapProvider() {
|
|
18
|
-
const mockProvider = new events_1.default();
|
|
19
|
-
mockProvider.request = async () => true;
|
|
20
|
-
return mockProvider;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Check if a value is a constructor.
|
|
24
|
-
*
|
|
25
|
-
* @param value - The value to check.
|
|
26
|
-
* @returns `true` if the value is a constructor, or `false` otherwise.
|
|
27
|
-
*/
|
|
28
|
-
const isConstructor = (value) => Boolean(typeof value?.prototype?.constructor?.name === 'string');
|
|
29
|
-
exports.isConstructor = isConstructor;
|
|
30
|
-
/**
|
|
31
|
-
* A function that always returns `true`.
|
|
32
|
-
*
|
|
33
|
-
* @returns `true`.
|
|
34
|
-
*/
|
|
35
|
-
const mockFunction = () => true;
|
|
36
|
-
class MockClass {
|
|
37
|
-
}
|
|
38
|
-
const handler = {
|
|
39
|
-
construct(Target, args) {
|
|
40
|
-
return new Proxy(new Target(...args), handler);
|
|
41
|
-
},
|
|
42
|
-
get(_target, _prop) {
|
|
43
|
-
return mockFunction;
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Generate a mock class for a given value. The value is wrapped in a Proxy, and
|
|
48
|
-
* all methods are replaced with a mock function.
|
|
49
|
-
*
|
|
50
|
-
* @param value - The value to mock.
|
|
51
|
-
* @returns A mock class.
|
|
52
|
-
*/
|
|
53
|
-
const generateMockClass = (value) => {
|
|
54
|
-
return new Proxy(value, handler);
|
|
55
|
-
};
|
|
56
|
-
// Things not currently auto-mocked because of NodeJS, by adding them here we have types for them and can use that to generate mocks if needed
|
|
57
|
-
const mockWindow = {
|
|
58
|
-
WebSocket: MockClass,
|
|
59
|
-
crypto: crypto_1.default,
|
|
60
|
-
SubtleCrypto: MockClass,
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Generate a mock endowment for a certain class or function on the `globalThis`
|
|
64
|
-
* object.
|
|
65
|
-
*
|
|
66
|
-
* @param key - The key to generate the mock endowment for.
|
|
67
|
-
* @returns A mocked class or function. If the key is part of the default
|
|
68
|
-
* endowments, the original value is returned.
|
|
69
|
-
*/
|
|
70
|
-
const generateMockEndowment = (key) => {
|
|
71
|
-
const globalValue = globalThis[key];
|
|
72
|
-
// Default exposed APIs don't need to be mocked
|
|
73
|
-
if (globalValue && snap_controllers_1.DEFAULT_ENDOWMENTS.includes(key)) {
|
|
74
|
-
return globalValue;
|
|
75
|
-
}
|
|
76
|
-
// Fall back to mockWindow for certain APIs not exposed in global in Node.JS
|
|
77
|
-
const globalOrMocked = globalValue ?? mockWindow[key];
|
|
78
|
-
const type = typeof globalOrMocked;
|
|
79
|
-
const isFunction = type === 'function';
|
|
80
|
-
if (isFunction && (0, exports.isConstructor)(globalOrMocked)) {
|
|
81
|
-
return generateMockClass(globalOrMocked);
|
|
82
|
-
}
|
|
83
|
-
else if (isFunction || !globalOrMocked) {
|
|
84
|
-
// Fall back to function mock for now
|
|
85
|
-
return mockFunction;
|
|
86
|
-
}
|
|
87
|
-
return globalOrMocked;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.
|
|
91
|
-
*
|
|
92
|
-
* @returns A map of endowments.
|
|
93
|
-
*/
|
|
94
|
-
const generateMockEndowments = () => {
|
|
95
|
-
return exports.ALL_APIS.reduce((acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }), { wallet: getMockSnapProvider() });
|
|
96
|
-
};
|
|
97
|
-
exports.generateMockEndowments = generateMockEndowments;
|
|
98
|
-
//# sourceMappingURL=mock.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../src/cmds/eval/mock.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAkC;AAClC,oDAA4B;AAC5B,iEAAgE;AAEhE,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAE/B,QAAA,QAAQ,GAAa,CAAC,GAAG,qCAAkB,EAAE,GAAG,YAAY,CAAC,CAAC;AAM3E;;;;GAIG;AACH,SAAS,mBAAmB;IAC1B,MAAM,YAAY,GAAG,IAAI,gBAAY,EAA+B,CAAC;IACrE,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAgC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,KAAU,EAAE,EAAE,CAC1C,OAAO,CAAC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC;AADtD,QAAA,aAAa,iBACyC;AAEnE;;;;GAIG;AACH,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAChC,MAAM,SAAS;CAAG;AAElB,MAAM,OAAO,GAAG;IACd,SAAS,CAAC,MAAW,EAAE,IAAW;QAChC,OAAO,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IACD,GAAG,CAAC,OAAY,EAAE,KAAU;QAC1B,OAAO,YAAY,CAAC;IACtB,CAAC;CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAE,EAAE;IACvC,OAAO,IAAI,KAAK,CAAC,KAAK,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controllers';\n\nconst NETWORK_APIS = ['fetch', 'WebSocket'];\n\nexport const ALL_APIS: string[] = [...DEFAULT_ENDOWMENTS, ...NETWORK_APIS];\n\ntype MockSnapProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap provider, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we have types for them and can use that to generate mocks if needed\nconst mockWindow = {\n WebSocket: MockClass,\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? (mockWindow as any)[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { wallet: getMockSnapProvider() },\n );\n};\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Spawn a new worker thread to run the provided bundle in.
|
|
3
|
-
*
|
|
4
|
-
* @param bundlePath - The path to the bundle to run.
|
|
5
|
-
* @returns `null` if the worker ran successfully.
|
|
6
|
-
* @throws If the worker failed to run successfully.
|
|
7
|
-
*/
|
|
8
|
-
export declare function workerEval(bundlePath: string): Promise<null>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.workerEval = void 0;
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
/**
|
|
10
|
-
* Spawn a new worker thread to run the provided bundle in.
|
|
11
|
-
*
|
|
12
|
-
* @param bundlePath - The path to the bundle to run.
|
|
13
|
-
* @returns `null` if the worker ran successfully.
|
|
14
|
-
* @throws If the worker failed to run successfully.
|
|
15
|
-
*/
|
|
16
|
-
function workerEval(bundlePath) {
|
|
17
|
-
return new Promise((resolve) => {
|
|
18
|
-
(0, child_process_1.fork)(getEvalWorkerPath(), [bundlePath]).on('exit', (exitCode) => {
|
|
19
|
-
if (exitCode === 0) {
|
|
20
|
-
resolve(null);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
throw new Error(`Worker exited abnormally! Code: ${exitCode}`);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.workerEval = workerEval;
|
|
29
|
-
/**
|
|
30
|
-
* Get the path to the eval worker file.
|
|
31
|
-
*
|
|
32
|
-
* @returns The path to the eval worker file.
|
|
33
|
-
*/
|
|
34
|
-
function getEvalWorkerPath() {
|
|
35
|
-
return path_1.default.join(__dirname, 'eval-worker.js');
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=workerEval.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workerEval.js","sourceRoot":"","sources":["../../../src/cmds/eval/workerEval.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAqC;AACrC,gDAA6B;AAE7B;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,UAAkB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAA,oBAAI,EAAC,iBAAiB,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACtE,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,CAAC,IAAI,CAAC,CAAC;aACf;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;aAChE;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,gCAUC;AAED;;;;GAIG;AACH,SAAS,iBAAiB;IACxB,OAAO,cAAS,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { fork } from 'child_process';\nimport pathUtils from 'path';\n\n/**\n * Spawn a new worker thread to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport function workerEval(bundlePath: string): Promise<null> {\n return new Promise((resolve) => {\n fork(getEvalWorkerPath(), [bundlePath]).on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n resolve(null);\n } else {\n throw new Error(`Worker exited abnormally! Code: ${exitCode}`);\n }\n });\n });\n}\n\n/**\n * Get the path to the eval worker file.\n *\n * @returns The path to the eval worker file.\n */\nfunction getEvalWorkerPath(): string {\n return pathUtils.join(__dirname, 'eval-worker.js');\n}\n"]}
|
package/dist/utils/fs.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Json } from '@metamask/snap-controllers';
|
|
2
|
-
/**
|
|
3
|
-
* Checks whether the given path string resolves to an existing directory, and
|
|
4
|
-
* optionally creates the directory if it doesn't exist.
|
|
5
|
-
*
|
|
6
|
-
* @param pathString - The path string to check.
|
|
7
|
-
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
8
|
-
* @returns Whether the given path is an existing directory.
|
|
9
|
-
*/
|
|
10
|
-
export declare function isDirectory(pathString: string, createDir: boolean): Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Checks whether the given path string resolves to an existing file.
|
|
13
|
-
*
|
|
14
|
-
* @param pathString - The path string to check.
|
|
15
|
-
* @returns Whether the given path is an existing file.
|
|
16
|
-
*/
|
|
17
|
-
export declare function isFile(pathString: string): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Reads a `.json` file, parses its contents, and returns them.
|
|
20
|
-
*
|
|
21
|
-
* @param pathString - The path to the JSON file.
|
|
22
|
-
* @returns The parsed contents of the JSON file.
|
|
23
|
-
*/
|
|
24
|
-
export declare function readJsonFile(pathString: string): Promise<Json>;
|
package/dist/utils/fs.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readJsonFile = exports.isFile = exports.isDirectory = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const misc_1 = require("./misc");
|
|
6
|
-
/**
|
|
7
|
-
* Checks whether the given path string resolves to an existing directory, and
|
|
8
|
-
* optionally creates the directory if it doesn't exist.
|
|
9
|
-
*
|
|
10
|
-
* @param pathString - The path string to check.
|
|
11
|
-
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
12
|
-
* @returns Whether the given path is an existing directory.
|
|
13
|
-
*/
|
|
14
|
-
async function isDirectory(pathString, createDir) {
|
|
15
|
-
try {
|
|
16
|
-
const stats = await fs_1.promises.stat(pathString);
|
|
17
|
-
return stats.isDirectory();
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
if (error.code === 'ENOENT') {
|
|
21
|
-
if (!createDir) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
await fs_1.promises.mkdir(pathString);
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
catch (mkdirError) {
|
|
29
|
-
(0, misc_1.logError)(`Directory '${pathString}' could not be created.`, mkdirError);
|
|
30
|
-
throw mkdirError;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.isDirectory = isDirectory;
|
|
37
|
-
/**
|
|
38
|
-
* Checks whether the given path string resolves to an existing file.
|
|
39
|
-
*
|
|
40
|
-
* @param pathString - The path string to check.
|
|
41
|
-
* @returns Whether the given path is an existing file.
|
|
42
|
-
*/
|
|
43
|
-
async function isFile(pathString) {
|
|
44
|
-
try {
|
|
45
|
-
const stats = await fs_1.promises.stat(pathString);
|
|
46
|
-
return stats.isFile();
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.isFile = isFile;
|
|
53
|
-
/**
|
|
54
|
-
* Reads a `.json` file, parses its contents, and returns them.
|
|
55
|
-
*
|
|
56
|
-
* @param pathString - The path to the JSON file.
|
|
57
|
-
* @returns The parsed contents of the JSON file.
|
|
58
|
-
*/
|
|
59
|
-
async function readJsonFile(pathString) {
|
|
60
|
-
if (!pathString.endsWith('.json')) {
|
|
61
|
-
throw new Error('The specified file must be a ".json" file.');
|
|
62
|
-
}
|
|
63
|
-
return JSON.parse(await fs_1.promises.readFile(pathString, 'utf8'));
|
|
64
|
-
}
|
|
65
|
-
exports.readJsonFile = readJsonFile;
|
|
66
|
-
//# sourceMappingURL=fs.js.map
|
package/dist/utils/fs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAEpC,iCAAkC;AAElC;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC3B,IAAI,CAAC,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,IAAI;gBACF,MAAM,aAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC3B,OAAO,IAAI,CAAC;aACb;YAAC,OAAO,UAAU,EAAE;gBACnB,IAAA,eAAQ,EAAC,cAAc,UAAU,yBAAyB,EAAE,UAAU,CAAC,CAAC;gBACxE,MAAM,UAAU,CAAC;aAClB;SACF;QACD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAvBD,kCAuBC;AAED;;;;;GAKG;AACI,KAAK,UAAU,MAAM,CAAC,UAAkB;IAC7C,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;KACvB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wBAOC;AAED;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAAC,UAAkB;IACnD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,aAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC;AAND,oCAMC","sourcesContent":["import { promises as fs } from 'fs';\nimport type { Json } from '@metamask/snap-controllers';\nimport { logError } from './misc';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n try {\n await fs.mkdir(pathString);\n return true;\n } catch (mkdirError) {\n logError(`Directory '${pathString}' could not be created.`, mkdirError);\n throw mkdirError;\n }\n }\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile(pathString: string): Promise<Json> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n return JSON.parse(await fs.readFile(pathString, 'utf8'));\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSnapConfig = void 0;
|
|
4
|
-
function isSnapConfig(obj, _argumentName) {
|
|
5
|
-
return ((obj !== null &&
|
|
6
|
-
typeof obj === "object" ||
|
|
7
|
-
typeof obj === "function") &&
|
|
8
|
-
(typeof obj.cliOptions === "undefined" ||
|
|
9
|
-
(obj.cliOptions !== null &&
|
|
10
|
-
typeof obj.cliOptions === "object" ||
|
|
11
|
-
typeof obj.cliOptions === "function") &&
|
|
12
|
-
Object.entries(obj.cliOptions)
|
|
13
|
-
.every(([key, _value]) => (typeof key === "string"))) &&
|
|
14
|
-
(typeof obj.bundlerCustomizer === "undefined" ||
|
|
15
|
-
typeof obj.bundlerCustomizer === "function"));
|
|
16
|
-
}
|
|
17
|
-
exports.isSnapConfig = isSnapConfig;
|
|
18
|
-
//# sourceMappingURL=snap-config.__GENERATED__.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snap-config.__GENERATED__.js","sourceRoot":"","sources":["../../src/utils/snap-config.__GENERATED__.ts"],"names":[],"mappings":";;;AAMA,SAAgB,YAAY,CAAC,GAAQ,EAAE,aAAsB;IACzD,OAAO,CACH,CAAC,GAAG,KAAK,IAAI;QACT,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,KAAK,UAAU,CAAC;QAC9B,CAAC,OAAO,GAAG,CAAC,UAAU,KAAK,WAAW;YAClC,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI;gBACpB,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ;gBAClC,OAAO,GAAG,CAAC,UAAU,KAAK,UAAU,CAAC;gBACzC,MAAM,CAAC,OAAO,CAAM,GAAG,CAAC,UAAU,CAAC;qBAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAC7D,CAAC,OAAO,GAAG,CAAC,iBAAiB,KAAK,WAAW;YACzC,OAAO,GAAG,CAAC,iBAAiB,KAAK,UAAU,CAAC,CACnD,CAAA;AACL,CAAC;AAdD,oCAcC","sourcesContent":["/*\n * Generated type guards for \"snap-config.ts\".\n * WARNING: Do not manually change this file.\n */\nimport { SnapConfig } from \"./snap-config\";\n\nexport function isSnapConfig(obj: any, _argumentName?: string): obj is SnapConfig {\n return (\n (obj !== null &&\n typeof obj === \"object\" ||\n typeof obj === \"function\") &&\n (typeof obj.cliOptions === \"undefined\" ||\n (obj.cliOptions !== null &&\n typeof obj.cliOptions === \"object\" ||\n typeof obj.cliOptions === \"function\") &&\n Object.entries<any>(obj.cliOptions)\n .every(([key, _value]) => (typeof key === \"string\"))) &&\n (typeof obj.bundlerCustomizer === \"undefined\" ||\n typeof obj.bundlerCustomizer === \"function\")\n )\n}\n"]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the complete out file path from an output file name and parent
|
|
3
|
-
* directory path.
|
|
4
|
-
*
|
|
5
|
-
* @param outDir - The path to the out file's parent directory.
|
|
6
|
-
* @param outFileName - The out file's name.
|
|
7
|
-
* @returns The complete path to the out file.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getOutfilePath(outDir: string, outFileName: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Ensures that the outfile name is just a `.js` file name.
|
|
12
|
-
* Throws on validation failure.
|
|
13
|
-
*
|
|
14
|
-
* @param filename - The file name to validate.
|
|
15
|
-
* @returns `true` if validation succeeded.
|
|
16
|
-
* @throws If the file name is invalid.
|
|
17
|
-
*/
|
|
18
|
-
export declare function validateOutfileName(filename: string): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Validates a file path. Throws on validation failure.
|
|
21
|
-
*
|
|
22
|
-
* @param filePath - The file path to validate.
|
|
23
|
-
* @returns `true` if validation succeeded.
|
|
24
|
-
* @throws If the path does not resolve to a file.
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateFilePath(filePath: string): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Validates a directory path. Throws on validation failure.
|
|
29
|
-
*
|
|
30
|
-
* @param dirPath - The directory path to validate.
|
|
31
|
-
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
32
|
-
* @returns `true` if validation succeeded or the directory was created.
|
|
33
|
-
* @throws If the directory does not exist or could not be created.
|
|
34
|
-
*/
|
|
35
|
-
export declare function validateDirPath(dirPath: string, createDir: boolean): Promise<boolean>;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = require("./fs");
|
|
9
|
-
/**
|
|
10
|
-
* Gets the complete out file path from an output file name and parent
|
|
11
|
-
* directory path.
|
|
12
|
-
*
|
|
13
|
-
* @param outDir - The path to the out file's parent directory.
|
|
14
|
-
* @param outFileName - The out file's name.
|
|
15
|
-
* @returns The complete path to the out file.
|
|
16
|
-
*/
|
|
17
|
-
function getOutfilePath(outDir, outFileName) {
|
|
18
|
-
return path_1.default.join(outDir, outFileName || 'bundle.js');
|
|
19
|
-
}
|
|
20
|
-
exports.getOutfilePath = getOutfilePath;
|
|
21
|
-
/**
|
|
22
|
-
* Ensures that the outfile name is just a `.js` file name.
|
|
23
|
-
* Throws on validation failure.
|
|
24
|
-
*
|
|
25
|
-
* @param filename - The file name to validate.
|
|
26
|
-
* @returns `true` if validation succeeded.
|
|
27
|
-
* @throws If the file name is invalid.
|
|
28
|
-
*/
|
|
29
|
-
function validateOutfileName(filename) {
|
|
30
|
-
if (!filename.endsWith('.js') ||
|
|
31
|
-
filename === '.js' ||
|
|
32
|
-
filename.indexOf('/') !== -1) {
|
|
33
|
-
throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
exports.validateOutfileName = validateOutfileName;
|
|
38
|
-
/**
|
|
39
|
-
* Validates a file path. Throws on validation failure.
|
|
40
|
-
*
|
|
41
|
-
* @param filePath - The file path to validate.
|
|
42
|
-
* @returns `true` if validation succeeded.
|
|
43
|
-
* @throws If the path does not resolve to a file.
|
|
44
|
-
*/
|
|
45
|
-
async function validateFilePath(filePath) {
|
|
46
|
-
const exists = await (0, fs_1.isFile)(filePath);
|
|
47
|
-
if (!exists) {
|
|
48
|
-
throw new Error(`Invalid params: '${filePath}' is not a file or does not exist.`);
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
exports.validateFilePath = validateFilePath;
|
|
53
|
-
/**
|
|
54
|
-
* Validates a directory path. Throws on validation failure.
|
|
55
|
-
*
|
|
56
|
-
* @param dirPath - The directory path to validate.
|
|
57
|
-
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
58
|
-
* @returns `true` if validation succeeded or the directory was created.
|
|
59
|
-
* @throws If the directory does not exist or could not be created.
|
|
60
|
-
*/
|
|
61
|
-
async function validateDirPath(dirPath, createDir) {
|
|
62
|
-
const exists = await (0, fs_1.isDirectory)(dirPath, createDir);
|
|
63
|
-
if (!exists) {
|
|
64
|
-
throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
exports.validateDirPath = validateDirPath;
|
|
69
|
-
//# sourceMappingURL=validate-fs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,QAAQ,KAAK,KAAK;QAClB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC5B;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,sBAAsB,CAAC,CAAC;KAC1E;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AATD,kDASC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,QAAQ,oCAAoC,CACjE,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4CAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAW,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC","sourcesContent":["import pathUtils from 'path';\nimport { isFile, isDirectory } from './fs';\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n filename.indexOf('/') !== -1\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}
|