@@ -16,6 +16,7 @@ import { builders, loadFile, writeFile } from "magicast";
1616import { buildSrcPath } from "../lib/buildSrcPath" ;
1717import { rejectIfNecessary } from "../lib/rejectIfNecessary" ;
1818import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject" ;
19+ import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile" ;
1920
2021import type { PluginOptions } from "../types" ;
2122
@@ -262,6 +263,28 @@ const modifySliceMachineConfig = async ({
262263 } ) ;
263264} ;
264265
266+ const upsertSliceLibraryIndexFiles = async (
267+ context : SliceMachineContext < PluginOptions > ,
268+ ) => {
269+ // We must use the `getProject()` helper to get the latest version of
270+ // the project config. The config may have been modified in
271+ // `modifySliceMachineConfig()` and will not be relfected in
272+ // `context.project`.
273+ // TODO: Automatically update the plugin runner's in-memory `project`
274+ // object when `updateSliceMachineConfig()` is called.
275+ const project = await context . helpers . getProject ( ) ;
276+
277+ if ( ! project . config . libraries ) {
278+ return ;
279+ }
280+
281+ await Promise . all (
282+ project . config . libraries . map ( async ( libraryID ) => {
283+ await upsertSliceLibraryIndexFile ( { libraryID, ...context } ) ;
284+ } ) ,
285+ ) ;
286+ } ;
287+
265288export const projectInit : ProjectInitHook < PluginOptions > = async (
266289 { installDependencies : _installDependencies } ,
267290 context ,
@@ -275,4 +298,8 @@ export const projectInit: ProjectInitHook<PluginOptions> = async (
275298 modifySliceMachineConfig ( context ) ,
276299 ] ) ,
277300 ) ;
301+
302+ // This must happen after `modifySliceMachineConfig()` since the
303+ // location of the default Slice library may change.
304+ await upsertSliceLibraryIndexFiles ( context ) ;
278305} ;
0 commit comments