@metamask/snaps-cli 3.0.3 → 3.0.4

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 CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.0.4]
10
+ ### Fixed
11
+ - Only serve Snap files from CLI ([#1979](https://github.com/MetaMask/snaps/pull/1979))
12
+
9
13
  ## [3.0.3]
10
14
  ### Changed
11
15
  - Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
@@ -78,7 +82,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
78
82
  - The version of the package no longer needs to match the version of all other
79
83
  MetaMask Snaps packages.
80
84
 
81
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.3...HEAD
85
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.4...HEAD
86
+ [3.0.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.3...@metamask/snaps-cli@3.0.4
82
87
  [3.0.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.2...@metamask/snaps-cli@3.0.3
83
88
  [3.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.1...@metamask/snaps-cli@3.0.2
84
89
  [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
- 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
- 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 type { Server } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport serveMiddleware from 'serve-handler';\nimport { webpack } from 'webpack';\n\nimport type { ProcessedConfig, 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\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 const server = createServer((request, response) => {\n serveMiddleware(request, response, {\n public: config.server.root,\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 })?.catch(\n /* istanbul ignore next */ () => {\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":["getCompiler","getServer","config","options","baseWebpackConfig","getDefaultConfiguration","webpackConfig","customizeWebpackConfig","webpack","server","createServer","request","response","serveMiddleware","public","root","headers","source","key","value","catch","statusCode","end","listen","port","Promise","resolve","reject","close","resolveClose","rejectClose","closeError","address","listenError"],"mappings":";;;;;;;;;;;IAiBsBA,WAAW;eAAXA;;IAsBNC,SAAS;eAATA;;;sBAtCa;qEAED;yBACJ;wBAIgB;;;;;;AASjC,eAAeD,YACpBE,MAA8B,EAC9BC,OAAwB;IAExB,MAAMC,oBAAoB,MAAMC,IAAAA,+BAAuB,EAACH,QAAQC;IAChE,MAAMG,gBACJJ,OAAOK,sBAAsB,GAAGH,sBAAsBA;IAExD,OAAOI,IAAAA,gBAAO,EAACF;AACjB;AAaO,SAASL,UAAUC,MAAuB;IAC/C,MAAMO,SAASC,IAAAA,kBAAY,EAAC,CAACC,SAASC;QACpCC,IAAAA,qBAAe,EAACF,SAASC,UAAU;YACjCE,QAAQZ,OAAOO,MAAM,CAACM,IAAI;YAC1BC,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MACF,wBAAwB,GAAG;YACzBR,SAASS,UAAU,GAAG;YACtBT,SAASU,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMC,SAAS,OAAOC,OAAOtB,OAAOO,MAAM,CAACe,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACC,SAASC;YACX,IAAI;gBACFlB,OAAOc,MAAM,CAACC,MAAM;oBAClB,MAAMI,QAAQ;wBACZ,MAAM,IAAIH,QAAc,CAACI,cAAcC;4BACrCrB,OAAOmB,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAUvB,OAAOuB,OAAO;oBAC9BN,QAAQ;wBAAEF,MAAMQ,QAAQR,IAAI;wBAAEf;wBAAQmB;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAEV;IAAO;AAClB"}
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,135 @@
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
+ return [
44
+ getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, config.output.path, config.output.filename)),
45
+ getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, _snapsutils.NpmSnapFileNames.Manifest)),
46
+ ...auxiliaryFiles,
47
+ ...localizationFiles
48
+ ];
49
+ }
50
+ function getServer(config) {
51
+ /**
52
+ * Get the response for a request. This is extracted into a function so that
53
+ * we can easily catch errors and send a 500 response.
54
+ *
55
+ * @param request - The request.
56
+ * @param response - The response.
57
+ * @returns A promise that resolves when the response is sent.
58
+ */ async function getResponse(request, response) {
59
+ const manifestPath = (0, _path.join)(config.server.root, _snapsutils.NpmSnapFileNames.Manifest);
60
+ const { result } = await (0, _snapsutils.readJsonFile)(manifestPath);
61
+ const allowedPaths = getAllowedPaths(config, result);
62
+ const path = request.url?.slice(1);
63
+ const allowed = allowedPaths.some((allowedPath)=>path === allowedPath);
64
+ if (!allowed) {
65
+ response.statusCode = 404;
66
+ response.end();
67
+ return;
68
+ }
69
+ await (0, _servehandler.default)(request, response, {
70
+ public: config.server.root,
71
+ directoryListing: false,
72
+ headers: [
73
+ {
74
+ source: '**/*',
75
+ headers: [
76
+ {
77
+ key: 'Cache-Control',
78
+ value: 'no-cache'
79
+ },
80
+ {
81
+ key: 'Access-Control-Allow-Origin',
82
+ value: '*'
83
+ }
84
+ ]
85
+ }
86
+ ]
87
+ });
88
+ }
89
+ const server = (0, _http.createServer)((request, response)=>{
90
+ getResponse(request, response).catch(/* istanbul ignore next */ (error)=>{
91
+ (0, _snapsutils.logError)(error);
92
+ response.statusCode = 500;
93
+ response.end();
94
+ });
95
+ });
96
+ /**
97
+ * Start the server on the port specified in the config.
98
+ *
99
+ * @param port - The port to listen on.
100
+ * @returns A promise that resolves when the server is listening. The promise
101
+ * resolves to an object with the port and the server instance. Note that if
102
+ * the `config.server.port` is `0`, the OS will choose a random port for us,
103
+ * so we need to get the port from the server after it starts.
104
+ */ const listen = async (port = config.server.port)=>{
105
+ return new Promise((resolve, reject)=>{
106
+ try {
107
+ server.listen(port, ()=>{
108
+ const close = async ()=>{
109
+ await new Promise((resolveClose, rejectClose)=>{
110
+ server.close((closeError)=>{
111
+ if (closeError) {
112
+ return rejectClose(closeError);
113
+ }
114
+ return resolveClose();
115
+ });
116
+ });
117
+ };
118
+ const address = server.address();
119
+ resolve({
120
+ port: address.port,
121
+ server,
122
+ close
123
+ });
124
+ });
125
+ } catch (listenError) {
126
+ reject(listenError);
127
+ }
128
+ });
129
+ };
130
+ return {
131
+ listen
132
+ };
133
+ }
134
+
135
+ //# 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 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 ];\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","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":";;;;;;;;;;;IAoCgBA,eAAe;eAAfA;;IAiDAC,SAAS;eAATA;;;4BAhFT;sBAEsB;sBAEsC;qEACvC;;;;;;AAI5B;;;;;;;;;CASC,GACD,SAASC,gBAAgBC,IAAY,EAAEC,EAAU;IAC/C,OAAOC,IAAAA,cAAQ,EAACF,MAAMC,IAAIE,KAAK,CAACC,SAAG,EAAEC,IAAI,CAACC,WAAK,CAACF,GAAG;AACrD;AAUO,SAASP,gBACdU,MAAuB,EACvBC,QAAsB;IAEtB,MAAMC,iBACJD,SAASE,MAAM,CAACC,KAAK,EAAEC,IAAI,CAACC,OAC1Bd,gBACEQ,OAAOO,MAAM,CAACC,IAAI,EAClBC,IAAAA,aAAW,EAACT,OAAOO,MAAM,CAACC,IAAI,EAAEF,WAE/B,EAAE;IAET,MAAMI,oBACJT,SAASE,MAAM,CAACQ,OAAO,EAAEN,IAAI,CAACO,eAC5BpB,gBACEQ,OAAOO,MAAM,CAACC,IAAI,EAClBC,IAAAA,aAAW,EAACT,OAAOO,MAAM,CAACC,IAAI,EAAEI,mBAE/B,EAAE;IAET,OAAO;QACLpB,gBACEQ,OAAOO,MAAM,CAACC,IAAI,EAClBC,IAAAA,aAAW,EACTT,OAAOO,MAAM,CAACC,IAAI,EAClBR,OAAOa,MAAM,CAACC,IAAI,EAClBd,OAAOa,MAAM,CAACE,QAAQ;QAG1BvB,gBACEQ,OAAOO,MAAM,CAACC,IAAI,EAClBC,IAAAA,aAAW,EAACT,OAAOO,MAAM,CAACC,IAAI,EAAEQ,4BAAgB,CAACC,QAAQ;WAExDf;WACAQ;KACJ;AACH;AAaO,SAASnB,UAAUS,MAAuB;IAC/C;;;;;;;GAOC,GACD,eAAekB,YACbC,OAAwB,EACxBC,QAAwB;QAExB,MAAMC,eAAevB,IAAAA,UAAI,EAACE,OAAOO,MAAM,CAACC,IAAI,EAAEQ,4BAAgB,CAACC,QAAQ;QACvE,MAAM,EAAEK,MAAM,EAAE,GAAG,MAAMC,IAAAA,wBAAY,EAAeF;QACpD,MAAMG,eAAelC,gBAAgBU,QAAQsB;QAE7C,MAAMR,OAAOK,QAAQM,GAAG,EAAEC,MAAM;QAChC,MAAMC,UAAUH,aAAaI,IAAI,CAAC,CAACC,cAAgBf,SAASe;QAE5D,IAAI,CAACF,SAAS;YACZP,SAASU,UAAU,GAAG;YACtBV,SAASW,GAAG;YACZ;QACF;QAEA,MAAMC,IAAAA,qBAAe,EAACb,SAASC,UAAU;YACvCa,QAAQjC,OAAOO,MAAM,CAACC,IAAI;YAC1B0B,kBAAkB;YAClBC,SAAS;gBACP;oBACEhC,QAAQ;oBACRgC,SAAS;wBACP;4BACEC,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH;IACF;IAEA,MAAM9B,SAAS+B,IAAAA,kBAAY,EAAC,CAACnB,SAASC;QACpCF,YAAYC,SAASC,UAAUmB,KAAK,CAClC,wBAAwB,GACxB,CAACC;YACCC,IAAAA,oBAAQ,EAACD;YACTpB,SAASU,UAAU,GAAG;YACtBV,SAASW,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMW,SAAS,OAAOC,OAAO3C,OAAOO,MAAM,CAACoC,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACC,SAASC;YACX,IAAI;gBACFvC,OAAOmC,MAAM,CAACC,MAAM;oBAClB,MAAMI,QAAQ;wBACZ,MAAM,IAAIH,QAAc,CAACI,cAAcC;4BACrC1C,OAAOwC,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAU5C,OAAO4C,OAAO;oBAC9BN,QAAQ;wBAAEF,MAAMQ,QAAQR,IAAI;wBAAEpC;wBAAQwC;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAEV;IAAO;AAClB"}
@@ -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 type { Server } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport serveMiddleware from 'serve-handler';\nimport { webpack } from 'webpack';\n\nimport type { ProcessedConfig, 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\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 const server = createServer((request, response) => {\n serveMiddleware(request, response, {\n public: config.server.root,\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 })?.catch(\n /* istanbul ignore next */ () => {\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":["createServer","serveMiddleware","webpack","getDefaultConfiguration","getCompiler","config","options","baseWebpackConfig","webpackConfig","customizeWebpackConfig","getServer","server","request","response","public","root","headers","source","key","value","catch","statusCode","end","listen","port","Promise","resolve","reject","close","resolveClose","rejectClose","closeError","address","listenError"],"mappings":"AACA,SAASA,YAAY,QAAQ,OAAO;AAEpC,OAAOC,qBAAqB,gBAAgB;AAC5C,SAASC,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;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASE,UAAUL,MAAuB;IAC/C,MAAMM,SAASX,aAAa,CAACY,SAASC;QACpCZ,gBAAgBW,SAASC,UAAU;YACjCC,QAAQT,OAAOM,MAAM,CAACI,IAAI;YAC1BC,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MACF,wBAAwB,GAAG;YACzBP,SAASQ,UAAU,GAAG;YACtBR,SAASS,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMC,SAAS,OAAOC,OAAOnB,OAAOM,MAAM,CAACa,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACC,SAASC;YACX,IAAI;gBACFhB,OAAOY,MAAM,CAACC,MAAM;oBAClB,MAAMI,QAAQ;wBACZ,MAAM,IAAIH,QAAc,CAACI,cAAcC;4BACrCnB,OAAOiB,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAUrB,OAAOqB,OAAO;oBAC9BN,QAAQ;wBAAEF,MAAMQ,QAAQR,IAAI;wBAAEb;wBAAQiB;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAEV;IAAO;AAClB"}
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,5 +1,6 @@
1
1
  export * from './compiler';
2
2
  export * from './config';
3
3
  export * from './plugins';
4
+ export * from './server';
4
5
 
5
6
  //# sourceMappingURL=index.js.map
@@ -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,129 @@
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
+ return [
28
+ getRelativePath(config.server.root, resolvePath(config.server.root, config.output.path, config.output.filename)),
29
+ getRelativePath(config.server.root, resolvePath(config.server.root, NpmSnapFileNames.Manifest)),
30
+ ...auxiliaryFiles,
31
+ ...localizationFiles
32
+ ];
33
+ }
34
+ /**
35
+ * Get a static server for development purposes.
36
+ *
37
+ * Note: We're intentionally not using `webpack-dev-server` here because it
38
+ * adds a lot of extra stuff to the output that we don't need, and it's
39
+ * difficult to customize.
40
+ *
41
+ * @param config - The config object.
42
+ * @returns An object with a `listen` method that returns a promise that
43
+ * resolves when the server is listening.
44
+ */ export function getServer(config) {
45
+ /**
46
+ * Get the response for a request. This is extracted into a function so that
47
+ * we can easily catch errors and send a 500 response.
48
+ *
49
+ * @param request - The request.
50
+ * @param response - The response.
51
+ * @returns A promise that resolves when the response is sent.
52
+ */ async function getResponse(request, response) {
53
+ const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);
54
+ const { result } = await readJsonFile(manifestPath);
55
+ const allowedPaths = getAllowedPaths(config, result);
56
+ const path = request.url?.slice(1);
57
+ const allowed = allowedPaths.some((allowedPath)=>path === allowedPath);
58
+ if (!allowed) {
59
+ response.statusCode = 404;
60
+ response.end();
61
+ return;
62
+ }
63
+ await serveMiddleware(request, response, {
64
+ public: config.server.root,
65
+ directoryListing: false,
66
+ headers: [
67
+ {
68
+ source: '**/*',
69
+ headers: [
70
+ {
71
+ key: 'Cache-Control',
72
+ value: 'no-cache'
73
+ },
74
+ {
75
+ key: 'Access-Control-Allow-Origin',
76
+ value: '*'
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ });
82
+ }
83
+ const server = createServer((request, response)=>{
84
+ getResponse(request, response).catch(/* istanbul ignore next */ (error)=>{
85
+ logError(error);
86
+ response.statusCode = 500;
87
+ response.end();
88
+ });
89
+ });
90
+ /**
91
+ * Start the server on the port specified in the config.
92
+ *
93
+ * @param port - The port to listen on.
94
+ * @returns A promise that resolves when the server is listening. The promise
95
+ * resolves to an object with the port and the server instance. Note that if
96
+ * the `config.server.port` is `0`, the OS will choose a random port for us,
97
+ * so we need to get the port from the server after it starts.
98
+ */ const listen = async (port = config.server.port)=>{
99
+ return new Promise((resolve, reject)=>{
100
+ try {
101
+ server.listen(port, ()=>{
102
+ const close = async ()=>{
103
+ await new Promise((resolveClose, rejectClose)=>{
104
+ server.close((closeError)=>{
105
+ if (closeError) {
106
+ return rejectClose(closeError);
107
+ }
108
+ return resolveClose();
109
+ });
110
+ });
111
+ };
112
+ const address = server.address();
113
+ resolve({
114
+ port: address.port,
115
+ server,
116
+ close
117
+ });
118
+ });
119
+ } catch (listenError) {
120
+ reject(listenError);
121
+ }
122
+ });
123
+ };
124
+ return {
125
+ listen
126
+ };
127
+ }
128
+
129
+ //# 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 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 ];\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","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 { Server } from 'http';
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
- };
@@ -1,3 +1,4 @@
1
1
  export * from './compiler';
2
2
  export * from './config';
3
3
  export * from './plugins';
4
+ export * from './server';
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",