(
ctx: Rollup.PluginContext,
code: string,
id: string,
transformOpts = {} as Parameters<Extract<Plugin['transform'], Function>>[2]
)
| 671 | |
| 672 | let transformCount = 0; |
| 673 | const transform = async function ( |
| 674 | ctx: Rollup.PluginContext, |
| 675 | code: string, |
| 676 | id: string, |
| 677 | transformOpts = {} as Parameters<Extract<Plugin['transform'], Function>>[2] |
| 678 | ): Promise<Rollup.TransformResult> { |
| 679 | if (id.startsWith('\0')) { |
| 680 | return; |
| 681 | } |
| 682 | const count = transformCount++; |
| 683 | const isServer = getIsServer(transformOpts); |
| 684 | const currentOutputs = isServer ? serverTransformedOutputs : clientTransformedOutputs; |
| 685 | if (currentOutputs.has(id)) { |
| 686 | // This is a QRL segment, and we don't need to process it any further |
| 687 | return; |
| 688 | } |
| 689 | |
| 690 | const optimizer = getOptimizer(); |
| 691 | const path = getPath(); |
| 692 | |
| 693 | const { pathId } = parseId(id); |
| 694 | const parsedPathId = path.parse(pathId); |
| 695 | const dir = parsedPathId.dir; |
| 696 | const base = parsedPathId.base; |
| 697 | const ext = parsedPathId.ext.toLowerCase(); |
| 698 | if (ext in TRANSFORM_EXTS || TRANSFORM_REGEX.test(pathId)) { |
| 699 | /** Strip client|server code from qwik server|client, but not in lib/test */ |
| 700 | const strip = opts.target === 'client' || opts.target === 'ssr'; |
| 701 | debug( |
| 702 | `transform(${count})`, |
| 703 | `Transforming ${id} (for: ${isServer ? 'server' : 'client'}${strip ? ', strip' : ''})` |
| 704 | ); |
| 705 | |
| 706 | const mode = |
| 707 | opts.target === 'lib' ? 'lib' : opts.buildMode === 'development' ? 'dev' : 'prod'; |
| 708 | |
| 709 | if (mode !== 'lib') { |
| 710 | // this messes a bit with the source map, but it's ok for if statements |
| 711 | code = code.replaceAll(/__EXPERIMENTAL__\.(\w+)/g, (_, feature) => { |
| 712 | if (opts.experimental?.[feature as ExperimentalFeatures]) { |
| 713 | return 'true'; |
| 714 | } |
| 715 | return 'false'; |
| 716 | }); |
| 717 | } |
| 718 | |
| 719 | let filePath = base; |
| 720 | if (opts.srcDir) { |
| 721 | filePath = path.relative(opts.srcDir, pathId); |
| 722 | } |
| 723 | filePath = normalizePath(filePath); |
| 724 | const srcDir = opts.srcDir ? opts.srcDir : normalizePath(dir); |
| 725 | const entryStrategy: EntryStrategy = opts.entryStrategy; |
| 726 | let devPath: string | undefined; |
| 727 | if (devServer) { |
| 728 | devPath = devServer.moduleGraph.getModuleById(pathId)?.url; |
| 729 | } |
| 730 | const transformOpts: TransformModulesOptions = { |
nothing calls this directly
no test coverage detected