@dcoder-x/vite 0.1.10 → 0.1.11
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/dist/ClippyVitePlugin.js +12 -4
- package/package.json +2 -2
package/dist/ClippyVitePlugin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'path';
|
|
1
2
|
import { RouteExtractor } from '@dcoder-x/plugin-shared/extractors/RouteExtractor';
|
|
2
3
|
import { ComponentExtractor } from '@dcoder-x/plugin-shared/extractors/ComponentExtractor';
|
|
3
4
|
import { SelectorGenerator } from '@dcoder-x/plugin-shared/extractors/SelectorGenerator';
|
|
@@ -6,6 +7,10 @@ import { PackageBuilder } from '@dcoder-x/plugin-shared/upload/PackageBuilder';
|
|
|
6
7
|
import { PackageWriter } from '@dcoder-x/plugin-shared/upload/PackageWriter';
|
|
7
8
|
import { Uploader } from '@dcoder-x/plugin-shared/upload/Uploader';
|
|
8
9
|
import { injectClippyIds, deriveBuildId, performUpload, inferRouteFromFilePath } from '@dcoder-x/plugin-shared';
|
|
10
|
+
/** Convert any absolute or backslash path to a forward-slash path relative to cwd. */
|
|
11
|
+
function toRelKey(absPath) {
|
|
12
|
+
return path.relative(process.cwd(), absPath).replace(/\\/g, '/');
|
|
13
|
+
}
|
|
9
14
|
export function clippyVitePlugin(options) {
|
|
10
15
|
const moduleGraph = new Map();
|
|
11
16
|
const injectedMap = new Map();
|
|
@@ -17,9 +22,11 @@ export function clippyVitePlugin(options) {
|
|
|
17
22
|
enforce: 'pre',
|
|
18
23
|
moduleParsed(moduleInfo) {
|
|
19
24
|
if (moduleInfo.id && !moduleInfo.id.includes('node_modules')) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
const relId = toRelKey(moduleInfo.id.split('?')[0]);
|
|
26
|
+
moduleGraph.set(relId, {
|
|
27
|
+
id: relId,
|
|
28
|
+
// importedIds come from Vite as absolute paths; normalise them too
|
|
29
|
+
importedIds: moduleInfo.importedIds.map((imp) => imp.includes('node_modules') ? imp : toRelKey(imp.split('?')[0])),
|
|
23
30
|
});
|
|
24
31
|
}
|
|
25
32
|
},
|
|
@@ -31,8 +38,9 @@ export function clippyVitePlugin(options) {
|
|
|
31
38
|
const result = injectClippyIds(source, cleanId, routePath);
|
|
32
39
|
if (result.injectedCount === 0)
|
|
33
40
|
return null;
|
|
41
|
+
// Store under the relative key so it matches ComponentExtractor's filePath values
|
|
34
42
|
if (result.injected && result.injected.length)
|
|
35
|
-
injectedMap.set(cleanId, result.injected);
|
|
43
|
+
injectedMap.set(toRelKey(cleanId), result.injected);
|
|
36
44
|
return {
|
|
37
45
|
code: result.source,
|
|
38
46
|
map: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcoder-x/vite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dcoder-x/plugin-shared": "^0.1.
|
|
21
|
+
"@dcoder-x/plugin-shared": "^0.1.11"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"vite": ">=4.0.0",
|