@@ -440,12 +440,18 @@ export default defineConfig({
440440
441441 /**
442442 * Add a new assembler hook
443+ * The format `thunk` write `() => import(path)`.
443444 *
444445 * @param type - The type of hook to add
445- * @param path - The path to the hook file
446+ * @param value - The path to the hook file or value to write
447+ * @param raw - Wether to write a thunk import or as raw value
446448 * @returns This RcFileTransformer instance for method chaining
447449 */
448- addAssemblerHook ( type : keyof Exclude < AssemblerRcFile [ 'hooks' ] , undefined > , path : string ) {
450+ addAssemblerHook (
451+ type : keyof Exclude < AssemblerRcFile [ 'hooks' ] , undefined > ,
452+ value : string ,
453+ raw : boolean = false
454+ ) {
449455 const hooksProperty = this . #getPropertyAssignmentInDefineConfigCall( 'hooks' , '{}' )
450456
451457 const hooks = hooksProperty . getInitializerIfKindOrThrow ( SyntaxKind . ObjectLiteralExpression )
@@ -456,12 +462,53 @@ export default defineConfig({
456462 }
457463
458464 const hooksArray = hookArray . getInitializerIfKindOrThrow ( SyntaxKind . ArrayLiteralExpression )
459- const existingHooks = this . #extractModulesFromArray( hooksArray )
460- if ( existingHooks . includes ( path ) ) {
461- return this
465+
466+ if ( raw ) {
467+ hooksArray . addElement ( value )
468+ } else {
469+ const existingHooks = this . #extractModulesFromArray( hooksArray )
470+ if ( existingHooks . includes ( value ) ) {
471+ return this
472+ }
473+
474+ hooksArray . addElement ( `() => import('${ value } ')` )
462475 }
463476
464- hooksArray . addElement ( `() => import('${ path } ')` )
477+ return this
478+ }
479+
480+ /**
481+ * Add a named import
482+ *
483+ * @param specifier - The module specifier to import
484+ * @param names - Names to import from the module
485+ * @returns This RcFileTransformer instance for method chaining
486+ */
487+ addNamedImport ( specifier : string , names : string [ ] ) {
488+ const file = this . #getRcFileOrThrow( )
489+
490+ file . addImportDeclaration ( {
491+ moduleSpecifier : specifier ,
492+ namedImports : names ,
493+ } )
494+
495+ return this
496+ }
497+
498+ /**
499+ * Add a default import
500+ *
501+ * @param specifier - The module specifier to import
502+ * @param name - Name of the default import
503+ * @returns This RcFileTransformer instance for method chaining
504+ */
505+ addDefaultImport ( specifier : string , name : string ) {
506+ const file = this . #getRcFileOrThrow( )
507+
508+ file . addImportDeclaration ( {
509+ moduleSpecifier : specifier ,
510+ defaultImport : name ,
511+ } )
465512
466513 return this
467514 }
0 commit comments