@@ -4,6 +4,7 @@ import { Instance } from "../../src/project/instance"
44import { tmpdir } from "../fixture/fixture"
55import path from "path"
66import fs from "fs/promises"
7+ import { pathToFileURL } from "url"
78
89test ( "loads config with defaults when no files exist" , async ( ) => {
910 await using tmp = await tmpdir ( )
@@ -350,3 +351,59 @@ test("gets config directories", async () => {
350351 } ,
351352 } )
352353} )
354+
355+ test ( "resolves scoped npm plugins in config" , async ( ) => {
356+ await using tmp = await tmpdir ( {
357+ init : async ( dir ) => {
358+ const pluginDir = path . join ( dir , "node_modules" , "@scope" , "plugin" )
359+ await fs . mkdir ( pluginDir , { recursive : true } )
360+
361+ await Bun . write (
362+ path . join ( dir , "package.json" ) ,
363+ JSON . stringify ( { name : "config-fixture" , version : "1.0.0" , type : "module" } , null , 2 ) ,
364+ )
365+
366+ await Bun . write (
367+ path . join ( pluginDir , "package.json" ) ,
368+ JSON . stringify (
369+ {
370+ name : "@scope/plugin" ,
371+ version : "1.0.0" ,
372+ type : "module" ,
373+ main : "./index.js" ,
374+ } ,
375+ null ,
376+ 2 ,
377+ ) ,
378+ )
379+
380+ await Bun . write ( path . join ( pluginDir , "index.js" ) , "export default {}\n" )
381+
382+ await Bun . write (
383+ path . join ( dir , "opencode.json" ) ,
384+ JSON . stringify (
385+ { $schema : "https://opencode.ai/config.json" , plugin : [ "@scope/plugin" ] } ,
386+ null ,
387+ 2 ,
388+ ) ,
389+ )
390+ } ,
391+ } )
392+
393+ await Instance . provide ( {
394+ directory : tmp . path ,
395+ fn : async ( ) => {
396+ const config = await Config . get ( )
397+ const pluginEntries = config . plugin ?? [ ]
398+
399+ const baseUrl = pathToFileURL ( path . join ( tmp . path , "opencode.json" ) ) . href
400+ const expected = import . meta. resolve ( "@scope/plugin" , baseUrl )
401+
402+ expect ( pluginEntries . includes ( expected ) ) . toBe ( true )
403+
404+ const scopedEntry = pluginEntries . find ( ( entry ) => entry === expected )
405+ expect ( scopedEntry ) . toBeDefined ( )
406+ expect ( scopedEntry ?. includes ( "/node_modules/@scope/plugin/" ) ) . toBe ( true )
407+ } ,
408+ } )
409+ } )
0 commit comments