@dcoder-x/plugin-shared 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.
@@ -97,8 +97,13 @@ class ComponentExtractor {
97
97
  return this.walkRollupGraph(entryFilePath, this.source.moduleGraph);
98
98
  }
99
99
  walkWebpackGraph(entryFilePath, compilation) {
100
+ // Normalise to relative forward-slash paths so visited keys and injectedMap
101
+ // keys are consistent across macOS and Windows.
102
+ const toRelFwd = (p) => path_1.default.isAbsolute(p)
103
+ ? path_1.default.relative(process.cwd(), p).replace(/\\/g, '/')
104
+ : p.replace(/\\/g, '/');
100
105
  const visited = new Set();
101
- const queue = [entryFilePath];
106
+ const queue = [toRelFwd(entryFilePath)];
102
107
  while (queue.length > 0) {
103
108
  const current = queue.shift();
104
109
  if (visited.has(current))
@@ -109,26 +114,31 @@ class ComponentExtractor {
109
114
  if (mod) {
110
115
  for (const depPath of this.getWebpackDependencyPaths(compilation, mod)) {
111
116
  if (depPath && !depPath.includes('node_modules')) {
112
- queue.push(depPath);
117
+ queue.push(toRelFwd(depPath));
113
118
  queuedFromWebpackGraph = true;
114
119
  }
115
120
  }
116
121
  }
117
122
  // Fallback for webpack variants where moduleGraph helpers are unavailable.
118
123
  if (!queuedFromWebpackGraph) {
124
+ // getFileImportPaths resolves to absolute paths via resolveImportFile;
125
+ // normalise them before queuing.
119
126
  for (const depPath of this.getFileImportPaths(current)) {
120
127
  if (depPath && !depPath.includes('node_modules')) {
121
- queue.push(depPath);
128
+ queue.push(toRelFwd(depPath));
122
129
  }
123
130
  }
124
131
  }
125
132
  }
126
133
  return Array.from(visited);
127
134
  }
128
- findWebpackModule(compilation, filePath) {
135
+ findWebpackModule(compilation, relFilePath) {
136
+ // relFilePath is already a relative forward-slash path; convert to the
137
+ // absolute path that webpack stores so its graph lookup succeeds.
138
+ const absFilePath = path_1.default.resolve(process.cwd(), relFilePath);
129
139
  const graph = compilation?.moduleGraph;
130
140
  if (graph?.getModuleByIdentifier) {
131
- const byIdentifier = graph.getModuleByIdentifier(filePath);
141
+ const byIdentifier = graph.getModuleByIdentifier(absFilePath);
132
142
  if (byIdentifier)
133
143
  return byIdentifier;
134
144
  }
@@ -139,10 +149,10 @@ class ComponentExtractor {
139
149
  : [];
140
150
  for (const mod of modules) {
141
151
  const resource = normalizeModulePath(mod?.resource || mod?.userRequest);
142
- if (resource === filePath)
152
+ if (resource === absFilePath)
143
153
  return mod;
144
154
  const id = normalizeModulePath(typeof mod?.identifier === 'function' ? mod.identifier() : mod?.id);
145
- if (id === filePath)
155
+ if (id === absFilePath)
146
156
  return mod;
147
157
  }
148
158
  return null;
@@ -226,8 +236,13 @@ class ComponentExtractor {
226
236
  return resolved;
227
237
  }
228
238
  walkRollupGraph(entryFilePath, graph) {
239
+ // Normalise the entry to a relative forward-slash path so it matches the
240
+ // keys stored by ClippyVitePlugin (which also normalises to relative).
241
+ const toRelFwd = (p) => path_1.default.isAbsolute(p)
242
+ ? path_1.default.relative(process.cwd(), p).replace(/\\/g, '/')
243
+ : p.replace(/\\/g, '/');
229
244
  const visited = new Set();
230
- const queue = [entryFilePath];
245
+ const queue = [toRelFwd(entryFilePath)];
231
246
  while (queue.length > 0) {
232
247
  const current = queue.shift();
233
248
  if (visited.has(current))
@@ -237,9 +252,9 @@ class ComponentExtractor {
237
252
  if (!mod)
238
253
  continue;
239
254
  for (const importId of mod.importedIds) {
240
- const importPath = normalizeModulePath(importId, current);
241
- if (importPath && !importPath.includes('node_modules')) {
242
- queue.push(importPath);
255
+ // importedIds are already relative keys after the vite plugin normalised them
256
+ if (importId && !importId.includes('node_modules')) {
257
+ queue.push(toRelFwd(importId));
243
258
  }
244
259
  }
245
260
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcoder-x/plugin-shared",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",