MCPcopy
hub / github.com/crxjs/chrome-extension-tools / chromeExtension

Function chromeExtension

src/index.ts:60–405  ·  view source on GitHub ↗
(
  pluginOptions: ChromeExtensionOptions = {},
)

Source from the content-addressed store, hash-verified

58})
59
60export const chromeExtension = (
61 pluginOptions: ChromeExtensionOptions = {},
62): Plugin => {
63 const service = interpret(machine, {
64 devTools: true,
65 })
66
67 /* Emitted file data by emitted file id*/
68 const filesByRefId = new Map<string, EmittedFile>()
69 const filesByFileName = new Map<string, EmittedFile>()
70
71 const allPlugins = new Set<InternalCrxPlugin>()
72 function setupPluginsRunner(
73 this: PluginContext,
74 hook: CrxHookType,
75 ) {
76 const plugins = Array.from(allPlugins)
77 useConfig(service, {
78 services: {
79 pluginsRunner: () => (send, onReceived) => {
80 onReceived(async (e: SharedEvent) => {
81 try {
82 const event = narrowEvent(e, 'PLUGINS_START')
83 const result = await runPlugins.call(
84 this,
85 plugins,
86 event as Asset,
87 hook,
88 )
89
90 send(model.events.PLUGINS_RESULT(result))
91 } catch (error) {
92 send(model.events.ERROR(error))
93 }
94 })
95 },
96 },
97 })
98 }
99
100 function setupFileEmitter(this: PluginContext) {
101 useConfig(service, {
102 actions: {
103 handleFile: (context, event) => {
104 try {
105 const { file: f } = narrowEvent(event, 'EMIT_FILE')
106 const file = Object.assign({}, f)
107
108 if (file.type === 'chunk')
109 file.fileName = getJsFilename(file.fileName)
110
111 const refId = this.emitFile(file)
112 service.send(
113 model.events.REF_ID({
114 id: file.id,
115 fileId: refId,
116 }),
117 )

Callers 15

rollup.config.jsFile · 0.85
vite.config.tsFile · 0.85
vite.config.tsFile · 0.85
rollup.config.jsFile · 0.85
vite.config.tsFile · 0.85
rollup.config.jsFile · 0.85
vite.config.tsFile · 0.85
vite.config.tsFile · 0.85
vite.config.tsFile · 0.85
rollup.config.jsFile · 0.85
rollup.config.jsFile · 0.85
vite.config.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected