(_options: DevtoolsPluginOptions = {})
| 43 | |
| 44 | // This export is used for configuration. |
| 45 | export const devtoolsPlugin = (_options: DevtoolsPluginOptions = {}): vite.PluginOption => { |
| 46 | const options = { |
| 47 | autoname: _options.autoname ?? false, |
| 48 | locator: _options.locator |
| 49 | ? { |
| 50 | targetIDE: false, |
| 51 | jsxLocation: false, |
| 52 | componentLocation: false, |
| 53 | ...(_options.locator === true ? {} : _options.locator), |
| 54 | } |
| 55 | : undefined, |
| 56 | // SDT_DEV: _options.SDT_DEV ?? false, |
| 57 | } satisfies DevtoolsPluginOptions |
| 58 | |
| 59 | const enabled_jsx_location = !!options.locator?.jsxLocation |
| 60 | const enabled_component_location = !!options.locator?.componentLocation |
| 61 | |
| 62 | const jsx_location_plugin_config: babel.JsxLocationPluginConfig | null = |
| 63 | (enabled_jsx_location || enabled_component_location) |
| 64 | ? { |
| 65 | jsx: enabled_jsx_location, |
| 66 | components: enabled_component_location, |
| 67 | } |
| 68 | : null |
| 69 | |
| 70 | let project_root = process.cwd() |
| 71 | |
| 72 | return { |
| 73 | name: 'solid-devtools', |
| 74 | enforce: 'pre', |
| 75 | configResolved(config) { |
| 76 | project_root = config.root |
| 77 | }, |
| 78 | apply(config, env) { |
| 79 | return env.command === 'serve' && env.mode !== 'production' |
| 80 | }, |
| 81 | resolveId(id) { |
| 82 | if (id === DevtoolsModule.Main) return DevtoolsModule.Main |
| 83 | }, |
| 84 | load(id) { |
| 85 | // Inject runtime debugger script |
| 86 | if (id !== DevtoolsModule.Main) return |
| 87 | |
| 88 | let code = `import "${DevtoolsModule.Setup}";` |
| 89 | |
| 90 | if (options.locator) { |
| 91 | code += `\nimport { setLocatorOptions } from "${DevtoolsModule.Setup}"; |
| 92 | setLocatorOptions(${JSON.stringify(options.locator)});` |
| 93 | } |
| 94 | |
| 95 | return code |
| 96 | }, |
| 97 | async transform(source, id, transformOptions) { |
| 98 | |
| 99 | // production and server should be disabled |
| 100 | if (transformOptions?.ssr) return |
| 101 | |
| 102 | const extname = get_extname(id) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…