@harness-fe/webpack 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -0
- package/dist/loader.d.ts +36 -0
- package/dist/loader.js +54 -0
- package/dist/plugin.d.ts +44 -0
- package/dist/plugin.js +233 -0
- package/dist/shared-state.d.ts +16 -0
- package/dist/shared-state.js +25 -0
- package/dist/transform-runner.d.ts +15 -0
- package/dist/transform-runner.js +50 -0
- package/package.json +54 -0
- package/src/index.ts +29 -0
- package/src/loader-options-serializable.test.ts +106 -0
- package/src/loader.ts +93 -0
- package/src/plugin.ts +272 -0
- package/src/shared-state.test.ts +32 -0
- package/src/shared-state.ts +30 -0
- package/src/transform-runner.test.ts +70 -0
- package/src/transform-runner.ts +80 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure transform dispatcher — picks the right transform function for a
|
|
3
|
+
* given file id (.vue / .vue?type=template / .vue?other-sub-module / .tsx /
|
|
4
|
+
* .jsx) and returns the transformed source + map.
|
|
5
|
+
*
|
|
6
|
+
* The componentMap is supplied per-call so the loader can collect new
|
|
7
|
+
* locations in a temporary map and forward them via module.buildMeta to
|
|
8
|
+
* the main process (where thread-loader is not in the picture).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { relative } from 'node:path';
|
|
13
|
+
import {
|
|
14
|
+
transformJsx,
|
|
15
|
+
transformVueSFC,
|
|
16
|
+
transformVueTemplate,
|
|
17
|
+
resolveVueComponentName,
|
|
18
|
+
getTemplateLineOffset,
|
|
19
|
+
type ComponentMap,
|
|
20
|
+
type VueTransformOptions,
|
|
21
|
+
} from '@harness-fe/unplugin';
|
|
22
|
+
|
|
23
|
+
export interface RunTransformResult {
|
|
24
|
+
code: string;
|
|
25
|
+
map?: object;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function runTransform(
|
|
29
|
+
source: string,
|
|
30
|
+
resourcePath: string,
|
|
31
|
+
resourceQuery: string,
|
|
32
|
+
projectRoot: string,
|
|
33
|
+
vueOptions: VueTransformOptions,
|
|
34
|
+
componentMap: ComponentMap,
|
|
35
|
+
): RunTransformResult | null {
|
|
36
|
+
const rel = relative(projectRoot, resourcePath);
|
|
37
|
+
|
|
38
|
+
// Vue template virtual sub-module.
|
|
39
|
+
if (
|
|
40
|
+
resourcePath.endsWith('.vue') &&
|
|
41
|
+
/[?&]vue\b/.test(resourceQuery) &&
|
|
42
|
+
/[?&]type=template\b/.test(resourceQuery)
|
|
43
|
+
) {
|
|
44
|
+
let componentName: string | undefined;
|
|
45
|
+
let lineOffset = 0;
|
|
46
|
+
try {
|
|
47
|
+
const sfcSource = readFileSync(resourcePath, 'utf-8');
|
|
48
|
+
componentName = resolveVueComponentName(sfcSource, rel);
|
|
49
|
+
lineOffset = getTemplateLineOffset(sfcSource, rel);
|
|
50
|
+
} catch {
|
|
51
|
+
/* fall through with no offset / no name */
|
|
52
|
+
}
|
|
53
|
+
const out = transformVueTemplate(
|
|
54
|
+
source,
|
|
55
|
+
rel,
|
|
56
|
+
componentName,
|
|
57
|
+
componentMap,
|
|
58
|
+
lineOffset,
|
|
59
|
+
vueOptions,
|
|
60
|
+
);
|
|
61
|
+
if (!out) return null;
|
|
62
|
+
return { code: out.code, map: out.map };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Plain .vue request: full SFC transform.
|
|
66
|
+
if (resourcePath.endsWith('.vue') && !resourceQuery) {
|
|
67
|
+
const out = transformVueSFC(source, rel, componentMap, vueOptions);
|
|
68
|
+
if (!out) return null;
|
|
69
|
+
return { code: out.code, map: out.map };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Every other .vue sub-module (script / style) is a no-op — the
|
|
73
|
+
// information was already collected from the SFC and template variants.
|
|
74
|
+
if (resourcePath.endsWith('.vue')) return null;
|
|
75
|
+
|
|
76
|
+
// .jsx / .tsx
|
|
77
|
+
const out = transformJsx(source, rel, componentMap);
|
|
78
|
+
if (!out) return null;
|
|
79
|
+
return { code: out.code, map: out.map };
|
|
80
|
+
}
|