1- import { handlerEndowments } from '@metamask/snaps-rpc-methods' ;
2- import { checkManifest , isFile } from '@metamask/snaps-utils/node' ;
3- import { writeManifest } from '@metamask/snaps-webpack-plugin' ;
1+ import { isFile } from '@metamask/snaps-utils/node' ;
42import { assert } from '@metamask/utils' ;
5- import { red , reset , yellow } from 'chalk' ;
6- import { readFile } from 'fs/promises' ;
7- import { dirname , resolve as pathResolve } from 'path' ;
3+ import { resolve } from 'path' ;
84
95import { build } from './implementation' ;
106import { getBundleAnalyzerPort } from './utils' ;
117import type { ProcessedConfig } from '../../config' ;
128import { CommandError } from '../../errors' ;
139import type { Steps } from '../../utils' ;
14- import { error , success , executeSteps , info , warn } from '../../utils' ;
15- import { formatError } from '../../webpack/utils' ;
10+ import { info , success , executeSteps } from '../../utils' ;
1611import { evaluate } from '../eval' ;
12+ import { manifest } from '../manifest' ;
13+ import { showManifestMessage } from '../manifest/manifest' ;
1714
1815export type BuildContext = {
1916 analyze : boolean ;
2017 build : boolean ;
2118 config : ProcessedConfig ;
22- port ?: number ;
2319 exports ?: string [ ] ;
20+ port ?: number ;
2421} ;
2522
2623export const steps : Steps < BuildContext > = [
@@ -40,7 +37,9 @@ export const steps: Steps<BuildContext> = [
4037 {
4138 name : 'Building the Snap bundle.' ,
4239 condition : ( { build : enableBuild } ) => enableBuild ,
43- task : async ( { analyze, build : enableBuild , config, spinner } ) => {
40+ task : async ( context ) => {
41+ const { analyze, config, spinner } = context ;
42+
4443 // We don't evaluate the bundle here, because it's done in a separate
4544 // step.
4645 const compiler = await build ( config , {
@@ -51,10 +50,7 @@ export const steps: Steps<BuildContext> = [
5150
5251 if ( analyze ) {
5352 return {
54- analyze,
55- build : enableBuild ,
56- config,
57- spinner,
53+ ...context ,
5854 port : await getBundleAnalyzerPort ( compiler ) ,
5955 } ;
6056 }
@@ -68,7 +64,7 @@ export const steps: Steps<BuildContext> = [
6864 enableBuild && config . evaluate ,
6965 task : async ( context ) => {
7066 const { config, spinner } = context ;
71- const path = pathResolve (
67+ const path = resolve (
7268 process . cwd ( ) ,
7369 config . output . path ,
7470 config . output . filename ,
@@ -84,65 +80,18 @@ export const steps: Steps<BuildContext> = [
8480 } ;
8581 } ,
8682 } ,
87-
88- // TODO: Share this between the `build` and `manifest` commands.
8983 {
9084 name : 'Validating the Snap manifest.' ,
91- condition : ( { config } ) => config . evaluate ,
9285 task : async ( { config, exports, spinner } ) => {
93- const bundlePath = pathResolve (
94- process . cwd ( ) ,
95- config . output . path ,
96- config . output . filename ,
97- ) ;
98-
99- const { reports } = await checkManifest ( dirname ( config . manifest . path ) , {
100- updateAndWriteManifest : config . manifest . update ,
101- sourceCode : await readFile ( bundlePath , 'utf-8' ) ,
86+ const stats = await manifest (
87+ config ,
88+ config . manifest . path ,
89+ config . manifest . update ,
10290 exports ,
103- handlerEndowments,
104- writeFileFn : async ( path , data ) => {
105- return writeManifest ( path , data ) ;
106- } ,
107- } ) ;
108-
109- // TODO: Use `Object.groupBy` when available.
110- const errors = reports
111- . filter ( ( report ) => report . severity === 'error' && ! report . wasFixed )
112- . map ( ( report ) => report . message ) ;
113- const warnings = reports
114- . filter ( ( report ) => report . severity === 'warning' && ! report . wasFixed )
115- . map ( ( report ) => report . message ) ;
116- const fixed = reports
117- . filter ( ( report ) => report . wasFixed )
118- . map ( ( report ) => report . message ) ;
119-
120- if ( errors . length > 0 ) {
121- error (
122- `The following errors were found in the manifest:\n\n${ errors
123- . map ( ( value ) => formatError ( value , '' , red ) )
124- . join ( '\n\n' ) } \n`,
125- spinner ,
126- ) ;
127- }
128-
129- if ( warnings . length > 0 ) {
130- warn (
131- `The following warnings were found in the manifest:\n\n${ warnings
132- . map ( ( value ) => formatError ( value , '' , yellow ) )
133- . join ( '\n\n' ) } \n`,
134- spinner ,
135- ) ;
136- }
91+ spinner ,
92+ ) ;
13793
138- if ( fixed . length > 0 ) {
139- info (
140- `The following issues were fixed in the manifest:\n\n${ reset (
141- fixed . map ( ( value ) => formatError ( value , '' , reset ) ) . join ( '\n\n' ) ,
142- ) } \n`,
143- spinner ,
144- ) ;
145- }
94+ showManifestMessage ( stats , config . manifest . update , spinner ) ;
14695 } ,
14796 } ,
14897 {
0 commit comments