@metamask/snaps-cli 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/dist/cjs/webpack/compiler.js +3 -80
- package/dist/cjs/webpack/compiler.js.map +1 -1
- package/dist/cjs/webpack/index.js +1 -0
- package/dist/cjs/webpack/index.js.map +1 -1
- package/dist/cjs/webpack/server.js +139 -0
- package/dist/cjs/webpack/server.js.map +1 -0
- package/dist/esm/webpack/compiler.js +0 -74
- package/dist/esm/webpack/compiler.js.map +1 -1
- package/dist/esm/webpack/index.js +1 -0
- package/dist/esm/webpack/index.js.map +1 -1
- package/dist/esm/webpack/server.js +133 -0
- package/dist/esm/webpack/server.js.map +1 -0
- package/dist/types/webpack/compiler.d.ts +1 -20
- package/dist/types/webpack/index.d.ts +1 -0
- package/dist/types/webpack/server.d.ts +30 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.0.5]
|
|
10
|
+
### Fixed
|
|
11
|
+
- Include Snap icon in allowed server paths ([#2003](https://github.com/MetaMask/snaps/pull/2003))
|
|
12
|
+
|
|
13
|
+
## [3.0.4]
|
|
14
|
+
### Fixed
|
|
15
|
+
- Only serve Snap files from CLI ([#1979](https://github.com/MetaMask/snaps/pull/1979))
|
|
16
|
+
|
|
9
17
|
## [3.0.3]
|
|
10
18
|
### Changed
|
|
11
19
|
- Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
|
|
@@ -78,7 +86,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
78
86
|
- The version of the package no longer needs to match the version of all other
|
|
79
87
|
MetaMask Snaps packages.
|
|
80
88
|
|
|
81
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.
|
|
89
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.5...HEAD
|
|
90
|
+
[3.0.5]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.4...@metamask/snaps-cli@3.0.5
|
|
91
|
+
[3.0.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.3...@metamask/snaps-cli@3.0.4
|
|
82
92
|
[3.0.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.2...@metamask/snaps-cli@3.0.3
|
|
83
93
|
[3.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.1...@metamask/snaps-cli@3.0.2
|
|
84
94
|
[3.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.0...@metamask/snaps-cli@3.0.1
|
|
@@ -2,95 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
getCompiler: function() {
|
|
5
|
+
Object.defineProperty(exports, "getCompiler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
13
8
|
return getCompiler;
|
|
14
|
-
},
|
|
15
|
-
getServer: function() {
|
|
16
|
-
return getServer;
|
|
17
9
|
}
|
|
18
10
|
});
|
|
19
|
-
const _http = require("http");
|
|
20
|
-
const _servehandler = /*#__PURE__*/ _interop_require_default(require("serve-handler"));
|
|
21
11
|
const _webpack = require("webpack");
|
|
22
12
|
const _config = require("./config");
|
|
23
|
-
function _interop_require_default(obj) {
|
|
24
|
-
return obj && obj.__esModule ? obj : {
|
|
25
|
-
default: obj
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
13
|
async function getCompiler(config, options) {
|
|
29
14
|
const baseWebpackConfig = await (0, _config.getDefaultConfiguration)(config, options);
|
|
30
15
|
const webpackConfig = config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;
|
|
31
16
|
return (0, _webpack.webpack)(webpackConfig);
|
|
32
17
|
}
|
|
33
|
-
function getServer(config) {
|
|
34
|
-
const server = (0, _http.createServer)((request, response)=>{
|
|
35
|
-
(0, _servehandler.default)(request, response, {
|
|
36
|
-
public: config.server.root,
|
|
37
|
-
headers: [
|
|
38
|
-
{
|
|
39
|
-
source: '**/*',
|
|
40
|
-
headers: [
|
|
41
|
-
{
|
|
42
|
-
key: 'Cache-Control',
|
|
43
|
-
value: 'no-cache'
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
key: 'Access-Control-Allow-Origin',
|
|
47
|
-
value: '*'
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
})?.catch(/* istanbul ignore next */ ()=>{
|
|
53
|
-
response.statusCode = 500;
|
|
54
|
-
response.end();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
/**
|
|
58
|
-
* Start the server on the port specified in the config.
|
|
59
|
-
*
|
|
60
|
-
* @param port - The port to listen on.
|
|
61
|
-
* @returns A promise that resolves when the server is listening. The promise
|
|
62
|
-
* resolves to an object with the port and the server instance. Note that if
|
|
63
|
-
* the `config.server.port` is `0`, the OS will choose a random port for us,
|
|
64
|
-
* so we need to get the port from the server after it starts.
|
|
65
|
-
*/ const listen = async (port = config.server.port)=>{
|
|
66
|
-
return new Promise((resolve, reject)=>{
|
|
67
|
-
try {
|
|
68
|
-
server.listen(port, ()=>{
|
|
69
|
-
const close = async ()=>{
|
|
70
|
-
await new Promise((resolveClose, rejectClose)=>{
|
|
71
|
-
server.close((closeError)=>{
|
|
72
|
-
if (closeError) {
|
|
73
|
-
return rejectClose(closeError);
|
|
74
|
-
}
|
|
75
|
-
return resolveClose();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
const address = server.address();
|
|
80
|
-
resolve({
|
|
81
|
-
port: address.port,
|
|
82
|
-
server,
|
|
83
|
-
close
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
} catch (listenError) {
|
|
87
|
-
reject(listenError);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
listen
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
18
|
|
|
96
19
|
//# sourceMappingURL=compiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/compiler.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/compiler.ts"],"sourcesContent":["import { webpack } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"],"names":["getCompiler","config","options","baseWebpackConfig","getDefaultConfiguration","webpackConfig","customizeWebpackConfig","webpack"],"mappings":";;;;+BAasBA;;;eAAAA;;;yBAbE;wBAIgB;AASjC,eAAeA,YACpBC,MAA8B,EAC9BC,OAAwB;IAExB,MAAMC,oBAAoB,MAAMC,IAAAA,+BAAuB,EAACH,QAAQC;IAChE,MAAMG,gBACJJ,OAAOK,sBAAsB,GAAGH,sBAAsBA;IAExD,OAAOI,IAAAA,gBAAO,EAACF;AACjB"}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
_export_star(require("./compiler"), exports);
|
|
6
6
|
_export_star(require("./config"), exports);
|
|
7
7
|
_export_star(require("./plugins"), exports);
|
|
8
|
+
_export_star(require("./server"), exports);
|
|
8
9
|
function _export_star(from, to) {
|
|
9
10
|
Object.keys(from).forEach(function(k) {
|
|
10
11
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/index.ts"],"sourcesContent":["export * from './compiler';\nexport * from './config';\nexport * from './plugins';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/index.ts"],"sourcesContent":["export * from './compiler';\nexport * from './config';\nexport * from './plugins';\nexport * from './server';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getAllowedPaths: function() {
|
|
13
|
+
return getAllowedPaths;
|
|
14
|
+
},
|
|
15
|
+
getServer: function() {
|
|
16
|
+
return getServer;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
20
|
+
const _http = require("http");
|
|
21
|
+
const _path = require("path");
|
|
22
|
+
const _servehandler = /*#__PURE__*/ _interop_require_default(require("serve-handler"));
|
|
23
|
+
function _interop_require_default(obj) {
|
|
24
|
+
return obj && obj.__esModule ? obj : {
|
|
25
|
+
default: obj
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the relative path from one path to another.
|
|
30
|
+
*
|
|
31
|
+
* Note: This is a modified version of `path.relative` that uses Posix
|
|
32
|
+
* separators for URL-compatibility.
|
|
33
|
+
*
|
|
34
|
+
* @param from - The path to start from.
|
|
35
|
+
* @param to - The path to end at.
|
|
36
|
+
* @returns The relative path.
|
|
37
|
+
*/ function getRelativePath(from, to) {
|
|
38
|
+
return (0, _path.relative)(from, to).split(_path.sep).join(_path.posix.sep);
|
|
39
|
+
}
|
|
40
|
+
function getAllowedPaths(config, manifest) {
|
|
41
|
+
const auxiliaryFiles = manifest.source.files?.map((file)=>getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, file))) ?? [];
|
|
42
|
+
const localizationFiles = manifest.source.locales?.map((localization)=>getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, localization))) ?? [];
|
|
43
|
+
const otherFiles = manifest.source.location.npm.iconPath ? [
|
|
44
|
+
getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, manifest.source.location.npm.iconPath))
|
|
45
|
+
] : [];
|
|
46
|
+
return [
|
|
47
|
+
getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, config.output.path, config.output.filename)),
|
|
48
|
+
getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, _snapsutils.NpmSnapFileNames.Manifest)),
|
|
49
|
+
...auxiliaryFiles,
|
|
50
|
+
...localizationFiles,
|
|
51
|
+
...otherFiles
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
function getServer(config) {
|
|
55
|
+
/**
|
|
56
|
+
* Get the response for a request. This is extracted into a function so that
|
|
57
|
+
* we can easily catch errors and send a 500 response.
|
|
58
|
+
*
|
|
59
|
+
* @param request - The request.
|
|
60
|
+
* @param response - The response.
|
|
61
|
+
* @returns A promise that resolves when the response is sent.
|
|
62
|
+
*/ async function getResponse(request, response) {
|
|
63
|
+
const manifestPath = (0, _path.join)(config.server.root, _snapsutils.NpmSnapFileNames.Manifest);
|
|
64
|
+
const { result } = await (0, _snapsutils.readJsonFile)(manifestPath);
|
|
65
|
+
const allowedPaths = getAllowedPaths(config, result);
|
|
66
|
+
const path = request.url?.slice(1);
|
|
67
|
+
const allowed = allowedPaths.some((allowedPath)=>path === allowedPath);
|
|
68
|
+
if (!allowed) {
|
|
69
|
+
response.statusCode = 404;
|
|
70
|
+
response.end();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
await (0, _servehandler.default)(request, response, {
|
|
74
|
+
public: config.server.root,
|
|
75
|
+
directoryListing: false,
|
|
76
|
+
headers: [
|
|
77
|
+
{
|
|
78
|
+
source: '**/*',
|
|
79
|
+
headers: [
|
|
80
|
+
{
|
|
81
|
+
key: 'Cache-Control',
|
|
82
|
+
value: 'no-cache'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: 'Access-Control-Allow-Origin',
|
|
86
|
+
value: '*'
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const server = (0, _http.createServer)((request, response)=>{
|
|
94
|
+
getResponse(request, response).catch(/* istanbul ignore next */ (error)=>{
|
|
95
|
+
(0, _snapsutils.logError)(error);
|
|
96
|
+
response.statusCode = 500;
|
|
97
|
+
response.end();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Start the server on the port specified in the config.
|
|
102
|
+
*
|
|
103
|
+
* @param port - The port to listen on.
|
|
104
|
+
* @returns A promise that resolves when the server is listening. The promise
|
|
105
|
+
* resolves to an object with the port and the server instance. Note that if
|
|
106
|
+
* the `config.server.port` is `0`, the OS will choose a random port for us,
|
|
107
|
+
* so we need to get the port from the server after it starts.
|
|
108
|
+
*/ const listen = async (port = config.server.port)=>{
|
|
109
|
+
return new Promise((resolve, reject)=>{
|
|
110
|
+
try {
|
|
111
|
+
server.listen(port, ()=>{
|
|
112
|
+
const close = async ()=>{
|
|
113
|
+
await new Promise((resolveClose, rejectClose)=>{
|
|
114
|
+
server.close((closeError)=>{
|
|
115
|
+
if (closeError) {
|
|
116
|
+
return rejectClose(closeError);
|
|
117
|
+
}
|
|
118
|
+
return resolveClose();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const address = server.address();
|
|
123
|
+
resolve({
|
|
124
|
+
port: address.port,
|
|
125
|
+
server,
|
|
126
|
+
close
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
} catch (listenError) {
|
|
130
|
+
reject(listenError);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
listen
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/server.ts"],"sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n logError,\n NpmSnapFileNames,\n readJsonFile,\n} from '@metamask/snaps-utils';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport { join, relative, resolve as resolvePath, sep, posix } from 'path';\nimport serveMiddleware from 'serve-handler';\n\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get the relative path from one path to another.\n *\n * Note: This is a modified version of `path.relative` that uses Posix\n * separators for URL-compatibility.\n *\n * @param from - The path to start from.\n * @param to - The path to end at.\n * @returns The relative path.\n */\nfunction getRelativePath(from: string, to: string) {\n return relative(from, to).split(sep).join(posix.sep);\n}\n\n/**\n * Get the allowed paths for the static server. This includes the output file,\n * the manifest file, and any auxiliary/localization files.\n *\n * @param config - The config object.\n * @param manifest - The Snap manifest object.\n * @returns An array of allowed paths.\n */\nexport function getAllowedPaths(\n config: ProcessedConfig,\n manifest: SnapManifest,\n) {\n const auxiliaryFiles =\n manifest.source.files?.map((file) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, file),\n ),\n ) ?? [];\n\n const localizationFiles =\n manifest.source.locales?.map((localization) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, localization),\n ),\n ) ?? [];\n\n const otherFiles = manifest.source.location.npm.iconPath\n ? [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n manifest.source.location.npm.iconPath,\n ),\n ),\n ]\n : [];\n\n return [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n config.output.path,\n config.output.filename,\n ),\n ),\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, NpmSnapFileNames.Manifest),\n ),\n ...auxiliaryFiles,\n ...localizationFiles,\n ...otherFiles,\n ];\n}\n\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n /**\n * Get the response for a request. This is extracted into a function so that\n * we can easily catch errors and send a 500 response.\n *\n * @param request - The request.\n * @param response - The response.\n * @returns A promise that resolves when the response is sent.\n */\n async function getResponse(\n request: IncomingMessage,\n response: ServerResponse,\n ) {\n const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);\n const { result } = await readJsonFile<SnapManifest>(manifestPath);\n const allowedPaths = getAllowedPaths(config, result);\n\n const path = request.url?.slice(1);\n const allowed = allowedPaths.some((allowedPath) => path === allowedPath);\n\n if (!allowed) {\n response.statusCode = 404;\n response.end();\n return;\n }\n\n await serveMiddleware(request, response, {\n public: config.server.root,\n directoryListing: false,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n });\n }\n\n const server = createServer((request, response) => {\n getResponse(request, response).catch(\n /* istanbul ignore next */\n (error) => {\n logError(error);\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"],"names":["getAllowedPaths","getServer","getRelativePath","from","to","relative","split","sep","join","posix","config","manifest","auxiliaryFiles","source","files","map","file","server","root","resolvePath","localizationFiles","locales","localization","otherFiles","location","npm","iconPath","output","path","filename","NpmSnapFileNames","Manifest","getResponse","request","response","manifestPath","result","readJsonFile","allowedPaths","url","slice","allowed","some","allowedPath","statusCode","end","serveMiddleware","public","directoryListing","headers","key","value","createServer","catch","error","logError","listen","port","Promise","resolve","reject","close","resolveClose","rejectClose","closeError","address","listenError"],"mappings":"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"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { createServer } from 'http';
|
|
2
|
-
import serveMiddleware from 'serve-handler';
|
|
3
1
|
import { webpack } from 'webpack';
|
|
4
2
|
import { getDefaultConfiguration } from './config';
|
|
5
3
|
/**
|
|
@@ -13,77 +11,5 @@ import { getDefaultConfiguration } from './config';
|
|
|
13
11
|
const webpackConfig = config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;
|
|
14
12
|
return webpack(webpackConfig);
|
|
15
13
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Get a static server for development purposes.
|
|
18
|
-
*
|
|
19
|
-
* Note: We're intentionally not using `webpack-dev-server` here because it
|
|
20
|
-
* adds a lot of extra stuff to the output that we don't need, and it's
|
|
21
|
-
* difficult to customize.
|
|
22
|
-
*
|
|
23
|
-
* @param config - The config object.
|
|
24
|
-
* @returns An object with a `listen` method that returns a promise that
|
|
25
|
-
* resolves when the server is listening.
|
|
26
|
-
*/ export function getServer(config) {
|
|
27
|
-
const server = createServer((request, response)=>{
|
|
28
|
-
serveMiddleware(request, response, {
|
|
29
|
-
public: config.server.root,
|
|
30
|
-
headers: [
|
|
31
|
-
{
|
|
32
|
-
source: '**/*',
|
|
33
|
-
headers: [
|
|
34
|
-
{
|
|
35
|
-
key: 'Cache-Control',
|
|
36
|
-
value: 'no-cache'
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
key: 'Access-Control-Allow-Origin',
|
|
40
|
-
value: '*'
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
})?.catch(/* istanbul ignore next */ ()=>{
|
|
46
|
-
response.statusCode = 500;
|
|
47
|
-
response.end();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* Start the server on the port specified in the config.
|
|
52
|
-
*
|
|
53
|
-
* @param port - The port to listen on.
|
|
54
|
-
* @returns A promise that resolves when the server is listening. The promise
|
|
55
|
-
* resolves to an object with the port and the server instance. Note that if
|
|
56
|
-
* the `config.server.port` is `0`, the OS will choose a random port for us,
|
|
57
|
-
* so we need to get the port from the server after it starts.
|
|
58
|
-
*/ const listen = async (port = config.server.port)=>{
|
|
59
|
-
return new Promise((resolve, reject)=>{
|
|
60
|
-
try {
|
|
61
|
-
server.listen(port, ()=>{
|
|
62
|
-
const close = async ()=>{
|
|
63
|
-
await new Promise((resolveClose, rejectClose)=>{
|
|
64
|
-
server.close((closeError)=>{
|
|
65
|
-
if (closeError) {
|
|
66
|
-
return rejectClose(closeError);
|
|
67
|
-
}
|
|
68
|
-
return resolveClose();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const address = server.address();
|
|
73
|
-
resolve({
|
|
74
|
-
port: address.port,
|
|
75
|
-
server,
|
|
76
|
-
close
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
} catch (listenError) {
|
|
80
|
-
reject(listenError);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
listen
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
14
|
|
|
89
15
|
//# sourceMappingURL=compiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/compiler.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/compiler.ts"],"sourcesContent":["import { webpack } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"],"names":["webpack","getDefaultConfiguration","getCompiler","config","options","baseWebpackConfig","webpackConfig","customizeWebpackConfig"],"mappings":"AAAA,SAASA,OAAO,QAAQ,UAAU;AAIlC,SAASC,uBAAuB,QAAQ,WAAW;AAEnD;;;;;;CAMC,GACD,OAAO,eAAeC,YACpBC,MAA8B,EAC9BC,OAAwB;IAExB,MAAMC,oBAAoB,MAAMJ,wBAAwBE,QAAQC;IAChE,MAAME,gBACJH,OAAOI,sBAAsB,GAAGF,sBAAsBA;IAExD,OAAOL,QAAQM;AACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/index.ts"],"sourcesContent":["export * from './compiler';\nexport * from './config';\nexport * from './plugins';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,YAAY"}
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/index.ts"],"sourcesContent":["export * from './compiler';\nexport * from './config';\nexport * from './plugins';\nexport * from './server';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,WAAW"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { logError, NpmSnapFileNames, readJsonFile } from '@metamask/snaps-utils';
|
|
2
|
+
import { createServer } from 'http';
|
|
3
|
+
import { join, relative, resolve as resolvePath, sep, posix } from 'path';
|
|
4
|
+
import serveMiddleware from 'serve-handler';
|
|
5
|
+
/**
|
|
6
|
+
* Get the relative path from one path to another.
|
|
7
|
+
*
|
|
8
|
+
* Note: This is a modified version of `path.relative` that uses Posix
|
|
9
|
+
* separators for URL-compatibility.
|
|
10
|
+
*
|
|
11
|
+
* @param from - The path to start from.
|
|
12
|
+
* @param to - The path to end at.
|
|
13
|
+
* @returns The relative path.
|
|
14
|
+
*/ function getRelativePath(from, to) {
|
|
15
|
+
return relative(from, to).split(sep).join(posix.sep);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the allowed paths for the static server. This includes the output file,
|
|
19
|
+
* the manifest file, and any auxiliary/localization files.
|
|
20
|
+
*
|
|
21
|
+
* @param config - The config object.
|
|
22
|
+
* @param manifest - The Snap manifest object.
|
|
23
|
+
* @returns An array of allowed paths.
|
|
24
|
+
*/ export function getAllowedPaths(config, manifest) {
|
|
25
|
+
const auxiliaryFiles = manifest.source.files?.map((file)=>getRelativePath(config.server.root, resolvePath(config.server.root, file))) ?? [];
|
|
26
|
+
const localizationFiles = manifest.source.locales?.map((localization)=>getRelativePath(config.server.root, resolvePath(config.server.root, localization))) ?? [];
|
|
27
|
+
const otherFiles = manifest.source.location.npm.iconPath ? [
|
|
28
|
+
getRelativePath(config.server.root, resolvePath(config.server.root, manifest.source.location.npm.iconPath))
|
|
29
|
+
] : [];
|
|
30
|
+
return [
|
|
31
|
+
getRelativePath(config.server.root, resolvePath(config.server.root, config.output.path, config.output.filename)),
|
|
32
|
+
getRelativePath(config.server.root, resolvePath(config.server.root, NpmSnapFileNames.Manifest)),
|
|
33
|
+
...auxiliaryFiles,
|
|
34
|
+
...localizationFiles,
|
|
35
|
+
...otherFiles
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get a static server for development purposes.
|
|
40
|
+
*
|
|
41
|
+
* Note: We're intentionally not using `webpack-dev-server` here because it
|
|
42
|
+
* adds a lot of extra stuff to the output that we don't need, and it's
|
|
43
|
+
* difficult to customize.
|
|
44
|
+
*
|
|
45
|
+
* @param config - The config object.
|
|
46
|
+
* @returns An object with a `listen` method that returns a promise that
|
|
47
|
+
* resolves when the server is listening.
|
|
48
|
+
*/ export function getServer(config) {
|
|
49
|
+
/**
|
|
50
|
+
* Get the response for a request. This is extracted into a function so that
|
|
51
|
+
* we can easily catch errors and send a 500 response.
|
|
52
|
+
*
|
|
53
|
+
* @param request - The request.
|
|
54
|
+
* @param response - The response.
|
|
55
|
+
* @returns A promise that resolves when the response is sent.
|
|
56
|
+
*/ async function getResponse(request, response) {
|
|
57
|
+
const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);
|
|
58
|
+
const { result } = await readJsonFile(manifestPath);
|
|
59
|
+
const allowedPaths = getAllowedPaths(config, result);
|
|
60
|
+
const path = request.url?.slice(1);
|
|
61
|
+
const allowed = allowedPaths.some((allowedPath)=>path === allowedPath);
|
|
62
|
+
if (!allowed) {
|
|
63
|
+
response.statusCode = 404;
|
|
64
|
+
response.end();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
await serveMiddleware(request, response, {
|
|
68
|
+
public: config.server.root,
|
|
69
|
+
directoryListing: false,
|
|
70
|
+
headers: [
|
|
71
|
+
{
|
|
72
|
+
source: '**/*',
|
|
73
|
+
headers: [
|
|
74
|
+
{
|
|
75
|
+
key: 'Cache-Control',
|
|
76
|
+
value: 'no-cache'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: 'Access-Control-Allow-Origin',
|
|
80
|
+
value: '*'
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const server = createServer((request, response)=>{
|
|
88
|
+
getResponse(request, response).catch(/* istanbul ignore next */ (error)=>{
|
|
89
|
+
logError(error);
|
|
90
|
+
response.statusCode = 500;
|
|
91
|
+
response.end();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Start the server on the port specified in the config.
|
|
96
|
+
*
|
|
97
|
+
* @param port - The port to listen on.
|
|
98
|
+
* @returns A promise that resolves when the server is listening. The promise
|
|
99
|
+
* resolves to an object with the port and the server instance. Note that if
|
|
100
|
+
* the `config.server.port` is `0`, the OS will choose a random port for us,
|
|
101
|
+
* so we need to get the port from the server after it starts.
|
|
102
|
+
*/ const listen = async (port = config.server.port)=>{
|
|
103
|
+
return new Promise((resolve, reject)=>{
|
|
104
|
+
try {
|
|
105
|
+
server.listen(port, ()=>{
|
|
106
|
+
const close = async ()=>{
|
|
107
|
+
await new Promise((resolveClose, rejectClose)=>{
|
|
108
|
+
server.close((closeError)=>{
|
|
109
|
+
if (closeError) {
|
|
110
|
+
return rejectClose(closeError);
|
|
111
|
+
}
|
|
112
|
+
return resolveClose();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const address = server.address();
|
|
117
|
+
resolve({
|
|
118
|
+
port: address.port,
|
|
119
|
+
server,
|
|
120
|
+
close
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
} catch (listenError) {
|
|
124
|
+
reject(listenError);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
listen
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/server.ts"],"sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n logError,\n NpmSnapFileNames,\n readJsonFile,\n} from '@metamask/snaps-utils';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport { join, relative, resolve as resolvePath, sep, posix } from 'path';\nimport serveMiddleware from 'serve-handler';\n\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get the relative path from one path to another.\n *\n * Note: This is a modified version of `path.relative` that uses Posix\n * separators for URL-compatibility.\n *\n * @param from - The path to start from.\n * @param to - The path to end at.\n * @returns The relative path.\n */\nfunction getRelativePath(from: string, to: string) {\n return relative(from, to).split(sep).join(posix.sep);\n}\n\n/**\n * Get the allowed paths for the static server. This includes the output file,\n * the manifest file, and any auxiliary/localization files.\n *\n * @param config - The config object.\n * @param manifest - The Snap manifest object.\n * @returns An array of allowed paths.\n */\nexport function getAllowedPaths(\n config: ProcessedConfig,\n manifest: SnapManifest,\n) {\n const auxiliaryFiles =\n manifest.source.files?.map((file) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, file),\n ),\n ) ?? [];\n\n const localizationFiles =\n manifest.source.locales?.map((localization) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, localization),\n ),\n ) ?? [];\n\n const otherFiles = manifest.source.location.npm.iconPath\n ? [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n manifest.source.location.npm.iconPath,\n ),\n ),\n ]\n : [];\n\n return [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n config.output.path,\n config.output.filename,\n ),\n ),\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, NpmSnapFileNames.Manifest),\n ),\n ...auxiliaryFiles,\n ...localizationFiles,\n ...otherFiles,\n ];\n}\n\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n /**\n * Get the response for a request. This is extracted into a function so that\n * we can easily catch errors and send a 500 response.\n *\n * @param request - The request.\n * @param response - The response.\n * @returns A promise that resolves when the response is sent.\n */\n async function getResponse(\n request: IncomingMessage,\n response: ServerResponse,\n ) {\n const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);\n const { result } = await readJsonFile<SnapManifest>(manifestPath);\n const allowedPaths = getAllowedPaths(config, result);\n\n const path = request.url?.slice(1);\n const allowed = allowedPaths.some((allowedPath) => path === allowedPath);\n\n if (!allowed) {\n response.statusCode = 404;\n response.end();\n return;\n }\n\n await serveMiddleware(request, response, {\n public: config.server.root,\n directoryListing: false,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n });\n }\n\n const server = createServer((request, response) => {\n getResponse(request, response).catch(\n /* istanbul ignore next */\n (error) => {\n logError(error);\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"],"names":["logError","NpmSnapFileNames","readJsonFile","createServer","join","relative","resolve","resolvePath","sep","posix","serveMiddleware","getRelativePath","from","to","split","getAllowedPaths","config","manifest","auxiliaryFiles","source","files","map","file","server","root","localizationFiles","locales","localization","otherFiles","location","npm","iconPath","output","path","filename","Manifest","getServer","getResponse","request","response","manifestPath","result","allowedPaths","url","slice","allowed","some","allowedPath","statusCode","end","public","directoryListing","headers","key","value","catch","error","listen","port","Promise","reject","close","resolveClose","rejectClose","closeError","address","listenError"],"mappings":"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"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ProcessedConfig, ProcessedWebpackConfig } from '../config';
|
|
1
|
+
import type { ProcessedWebpackConfig } from '../config';
|
|
3
2
|
import type { WebpackOptions } from './config';
|
|
4
3
|
/**
|
|
5
4
|
* Get a Webpack compiler for the given config.
|
|
@@ -9,21 +8,3 @@ import type { WebpackOptions } from './config';
|
|
|
9
8
|
* @returns The Webpack compiler.
|
|
10
9
|
*/
|
|
11
10
|
export declare function getCompiler(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
|
|
12
|
-
/**
|
|
13
|
-
* Get a static server for development purposes.
|
|
14
|
-
*
|
|
15
|
-
* Note: We're intentionally not using `webpack-dev-server` here because it
|
|
16
|
-
* adds a lot of extra stuff to the output that we don't need, and it's
|
|
17
|
-
* difficult to customize.
|
|
18
|
-
*
|
|
19
|
-
* @param config - The config object.
|
|
20
|
-
* @returns An object with a `listen` method that returns a promise that
|
|
21
|
-
* resolves when the server is listening.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getServer(config: ProcessedConfig): {
|
|
24
|
-
listen: (port?: number) => Promise<{
|
|
25
|
-
port: number;
|
|
26
|
-
server: Server;
|
|
27
|
-
close: () => Promise<void>;
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SnapManifest } from '@metamask/snaps-utils';
|
|
2
|
+
import type { Server } from 'http';
|
|
3
|
+
import type { ProcessedConfig } from '../config';
|
|
4
|
+
/**
|
|
5
|
+
* Get the allowed paths for the static server. This includes the output file,
|
|
6
|
+
* the manifest file, and any auxiliary/localization files.
|
|
7
|
+
*
|
|
8
|
+
* @param config - The config object.
|
|
9
|
+
* @param manifest - The Snap manifest object.
|
|
10
|
+
* @returns An array of allowed paths.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getAllowedPaths(config: ProcessedConfig, manifest: SnapManifest): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Get a static server for development purposes.
|
|
15
|
+
*
|
|
16
|
+
* Note: We're intentionally not using `webpack-dev-server` here because it
|
|
17
|
+
* adds a lot of extra stuff to the output that we don't need, and it's
|
|
18
|
+
* difficult to customize.
|
|
19
|
+
*
|
|
20
|
+
* @param config - The config object.
|
|
21
|
+
* @returns An object with a `listen` method that returns a promise that
|
|
22
|
+
* resolves when the server is listening.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getServer(config: ProcessedConfig): {
|
|
25
|
+
listen: (port?: number) => Promise<{
|
|
26
|
+
port: number;
|
|
27
|
+
server: Server;
|
|
28
|
+
close: () => Promise<void>;
|
|
29
|
+
}>;
|
|
30
|
+
};
|