@metamask/snaps-cli 3.0.4 → 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 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.5]
10
+ ### Fixed
11
+ - Include Snap icon in allowed server paths ([#2003](https://github.com/MetaMask/snaps/pull/2003))
12
+
9
13
  ## [3.0.4]
10
14
  ### Fixed
11
15
  - Only serve Snap files from CLI ([#1979](https://github.com/MetaMask/snaps/pull/1979))
@@ -82,7 +86,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
82
86
  - The version of the package no longer needs to match the version of all other
83
87
  MetaMask Snaps packages.
84
88
 
85
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.4...HEAD
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
86
91
  [3.0.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.3...@metamask/snaps-cli@3.0.4
87
92
  [3.0.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.2...@metamask/snaps-cli@3.0.3
88
93
  [3.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.1...@metamask/snaps-cli@3.0.2
@@ -40,11 +40,15 @@ function _interop_require_default(obj) {
40
40
  function getAllowedPaths(config, manifest) {
41
41
  const auxiliaryFiles = manifest.source.files?.map((file)=>getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, file))) ?? [];
42
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
+ ] : [];
43
46
  return [
44
47
  getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, config.output.path, config.output.filename)),
45
48
  getRelativePath(config.server.root, (0, _path.resolve)(config.server.root, _snapsutils.NpmSnapFileNames.Manifest)),
46
49
  ...auxiliaryFiles,
47
- ...localizationFiles
50
+ ...localizationFiles,
51
+ ...otherFiles
48
52
  ];
49
53
  }
50
54
  function getServer(config) {
@@ -1 +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,aAA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AO3C,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
+ {"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":";;;;;;;;;;;IAoCgBA,eAAe;eAAfA;;IA8DAC,SAAS;eAATA;;;4BA7FT;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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ACZP,SAASU,UAAU,GAAG;YACtBV,SAASW,GAAG;YACZ;QACF;QAEA,MAAMC,IAAAA,qBAAe,EAACb,SAASC,UAAU;YACvCa,QAAQrC,OAAOO,MAAM,CAACC,IAAI;YAC1B8B,kBAAkB;YAClBC,SAAS;gBACP;oBACEpC,QAAQ;oBACRoC,SAAS;wBACP;4BACEC,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH;IACF;IAEA,MAAMlC,SAASmC,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,OAAO/C,OAAOO,MAAM,CAACwC,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACC,SAASC;YACX,IAAI;gBACF3C,OAAOuC,MAAM,CAACC,MAAM;oBAClB,MAAMI,QAAQ;wBACZ,MAAM,IAAIH,QAAc,CAACI,cAAcC;4BACrC9C,OAAO4C,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAUhD,OAAOgD,OAAO;oBAC9BN,QAAQ;wBAAEF,MAAMQ,QAAQR,IAAI;wBAAExC;wBAAQ4C;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAEV;IAAO;AAClB"}
@@ -24,11 +24,15 @@ import serveMiddleware from 'serve-handler';
24
24
  */ export function getAllowedPaths(config, manifest) {
25
25
  const auxiliaryFiles = manifest.source.files?.map((file)=>getRelativePath(config.server.root, resolvePath(config.server.root, file))) ?? [];
26
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
+ ] : [];
27
30
  return [
28
31
  getRelativePath(config.server.root, resolvePath(config.server.root, config.output.path, config.output.filename)),
29
32
  getRelativePath(config.server.root, resolvePath(config.server.root, NpmSnapFileNames.Manifest)),
30
33
  ...auxiliaryFiles,
31
- ...localizationFiles
34
+ ...localizationFiles,
35
+ ...otherFiles
32
36
  ];
33
37
  }
34
38
  /**
@@ -1 +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":"AACA,SACEA,QAAQ,EACRC,gBAAgB,EAChBC,YAAY,QACP,wBAAwB;AAE/B,SAASC,YAAY,QAAQ,OAAO;AAEpC,SAASC,IAAI,EAAEC,QAAQ,EAAEC,WAAWC,WAAW,EAAEC,GAAG,EAAEC,KAAK,QAAQ,OAAO;AAC1E,OAAOC,qBAAqB,gBAAgB;AAI5C;;;;;;;;;CASC,GACD,SAASC,gBAAgBC,IAAY,EAAEC,EAAU;IAC/C,OAAOR,SAASO,MAAMC,IAAIC,KAAK,CAACN,KAAKJ,IAAI,CAACK,MAAMD,GAAG;AACrD;AAEA;;;;;;;CAOC,GACD,OAAO,SAASO,gBACdC,MAAuB,EACvBC,QAAsB;IAEtB,MAAMC,iBACJD,SAASE,MAAM,CAACC,KAAK,EAAEC,IAAI,CAACC,OAC1BX,gBACEK,OAAOO,MAAM,CAACC,IAAI,EAClBjB,YAAYS,OAAOO,MAAM,CAACC,IAAI,EAAEF,WAE/B,EAAE;IAET,MAAMG,oBACJR,SAASE,MAAM,CAACO,OAAO,EAAEL,IAAI,CAACM,eAC5BhB,gBACEK,OAAOO,MAAM,CAACC,IAAI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U,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMQ,SAAS,OAAOC,OAAOtC,OAAOO,MAAM,CAAC+B,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACjD,SAASkD;YACX,IAAI;gBACFjC,OAAO8B,MAAM,CAACC,MAAM;oBAClB,MAAMG,QAAQ;wBACZ,MAAM,IAAIF,QAAc,CAACG,cAAcC;4BACrCpC,OAAOkC,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAUtC,OAAOsC,OAAO;oBAC9BvD,QAAQ;wBAAEgD,MAAMO,QAAQP,IAAI;wBAAE/B;wBAAQkC;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAET;IAAO;AAClB"}
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":"AACA,SACEA,QAAQ,EACRC,gBAAgB,EAChBC,YAAY,QACP,wBAAwB;AAE/B,SAASC,YAAY,QAAQ,OAAO;AAEpC,SAASC,IAAI,EAAEC,QAAQ,EAAEC,WAAWC,WAAW,EAAEC,GAAG,EAAEC,KAAK,QAAQ,OAAO;AAC1E,OAAOC,qBAAqB,gBAAgB;AAI5C;;;;;;;;;CASC,GACD,SAASC,gBAAgBC,IAAY,EAAEC,EAAU;IAC/C,OAAOR,SAASO,MAAMC,IAAIC,KAAK,CAACN,KAAKJ,IAAI,CAACK,MAAMD,GAAG;AACrD;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MR,OAAOK,QAAQK,GAAG,EAAEC,MAAM;QAChC,MAAMC,UAAUH,aAAaI,IAAI,CAAC,CAACC,cAAgBd,SAASc;QAE5D,IAAI,CAACF,SAAS;YACZN,SAASS,UAAU,GAAG;YACtBT,SAASU,GAAG;YACZ;QACF;QAEA,MAAMvC,gBAAgB4B,SAASC,UAAU;YACvCW,QAAQlC,OAAOO,MAAM,CAACC,IAAI;YAC1B2B,kBAAkB;YAClBC,SAAS;gBACP;oBACEjC,QAAQ;oBACRiC,SAAS;wBACP;4BACEC,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH;IACF;IAEA,MAAM/B,SAASpB,aAAa,CAACmC,SAASC;QACpCF,YAAYC,SAASC,UAAUgB,KAAK,CAClC,wBAAwB,GACxB,CAACC;YACCxD,SAASwD;YACTjB,SAASS,UAAU,GAAG;YACtBT,SAASU,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMQ,SAAS,OAAOC,OAAO1C,OAAOO,MAAM,CAACmC,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACrD,SAASsD;YACX,IAAI;gBACFrC,OAAOkC,MAAM,CAACC,MAAM;oBAClB,MAAMG,QAAQ;wBACZ,MAAM,IAAIF,QAAc,CAACG,cAAcC;4BACrCxC,OAAOsC,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAU1C,OAAO0C,OAAO;oBAC9B3D,QAAQ;wBAAEoD,MAAMO,QAAQP,IAAI;wBAAEnC;wBAAQsC;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAET;IAAO;AAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",