@unlockable/vite-plugin-unlock 0.1.5 → 0.1.6
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/index.cjs +143 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +143 -61
- package/dist/index.js.map +1 -1
- package/dist/medusa.cjs +5 -1
- package/dist/medusa.cjs.map +1 -1
- package/dist/medusa.d.cts +18 -1
- package/dist/medusa.d.ts +18 -1
- package/dist/medusa.js +5 -1
- package/dist/medusa.js.map +1 -1
- package/dist/{types-C3wWFKIK.d.cts → types-CWhwMUG3.d.cts} +22 -0
- package/dist/{types-C3wWFKIK.d.ts → types-CWhwMUG3.d.ts} +22 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,12 +35,12 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
37
|
// src/plugin.ts
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
39
|
+
var import_fs5 = __toESM(require("fs"), 1);
|
|
40
40
|
|
|
41
41
|
// src/config.ts
|
|
42
|
-
var
|
|
43
|
-
var
|
|
42
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
43
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
44
44
|
var import_module = require("module");
|
|
45
45
|
|
|
46
46
|
// src/constants.ts
|
|
@@ -60,6 +60,8 @@ var MAX_SCAN_DEPTH = 20;
|
|
|
60
60
|
var PLUGIN_NAME = "vite-plugin-unlock";
|
|
61
61
|
|
|
62
62
|
// src/utils.ts
|
|
63
|
+
var import_path = __toESM(require("path"), 1);
|
|
64
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
63
65
|
var PREFIX = `[${PLUGIN_NAME}]`;
|
|
64
66
|
function createLogger(debug) {
|
|
65
67
|
return {
|
|
@@ -85,35 +87,85 @@ function generateAlias(packageName) {
|
|
|
85
87
|
const lastPart = parts[parts.length - 1];
|
|
86
88
|
return `~${lastPart}`;
|
|
87
89
|
}
|
|
90
|
+
function collectCjsDeps(packageDir) {
|
|
91
|
+
const pkgJsonPath = import_path.default.join(packageDir, "package.json");
|
|
92
|
+
if (!import_fs.default.existsSync(pkgJsonPath)) return [];
|
|
93
|
+
let pkgJson;
|
|
94
|
+
try {
|
|
95
|
+
pkgJson = JSON.parse(import_fs.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
96
|
+
} catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
const deps = pkgJson.dependencies;
|
|
100
|
+
if (!deps) return [];
|
|
101
|
+
const cjsDeps = [];
|
|
102
|
+
for (const depName of Object.keys(deps)) {
|
|
103
|
+
if (depName.startsWith("@types/")) continue;
|
|
104
|
+
const depParts = depName.startsWith("@") ? depName.split("/") : [depName];
|
|
105
|
+
const candidates = [
|
|
106
|
+
import_path.default.join(packageDir, "node_modules", ...depParts, "package.json"),
|
|
107
|
+
import_path.default.join(process.cwd(), "node_modules", ...depParts, "package.json")
|
|
108
|
+
];
|
|
109
|
+
let depPkgJson = null;
|
|
110
|
+
for (const candidate of candidates) {
|
|
111
|
+
if (import_fs.default.existsSync(candidate)) {
|
|
112
|
+
try {
|
|
113
|
+
depPkgJson = JSON.parse(import_fs.default.readFileSync(candidate, "utf-8"));
|
|
114
|
+
} catch {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!depPkgJson) continue;
|
|
121
|
+
if (depPkgJson.type === "module") continue;
|
|
122
|
+
if (!hasRootEntry(depPkgJson)) continue;
|
|
123
|
+
cjsDeps.push(depName);
|
|
124
|
+
}
|
|
125
|
+
return cjsDeps;
|
|
126
|
+
}
|
|
127
|
+
function hasRootEntry(pkgJson) {
|
|
128
|
+
const exports2 = pkgJson.exports;
|
|
129
|
+
if (exports2 !== void 0) {
|
|
130
|
+
if (exports2 === null) return false;
|
|
131
|
+
if (typeof exports2 === "string") return true;
|
|
132
|
+
if (typeof exports2 === "object" && !Array.isArray(exports2)) {
|
|
133
|
+
return "." in exports2;
|
|
134
|
+
}
|
|
135
|
+
return Array.isArray(exports2);
|
|
136
|
+
}
|
|
137
|
+
if (pkgJson.main || pkgJson.module) return true;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
88
140
|
|
|
89
141
|
// src/config.ts
|
|
90
142
|
function findPackageSrcPath(packageName, srcDir) {
|
|
91
143
|
const cwd = process.cwd();
|
|
92
144
|
try {
|
|
93
|
-
const req = (0, import_module.createRequire)(
|
|
94
|
-
const pkgJsonPath =
|
|
145
|
+
const req = (0, import_module.createRequire)(import_path2.default.join(cwd, "package.json"));
|
|
146
|
+
const pkgJsonPath = import_fs2.default.realpathSync(
|
|
95
147
|
req.resolve(`${packageName}/package.json`)
|
|
96
148
|
);
|
|
97
|
-
const pkgRoot =
|
|
98
|
-
const srcPath =
|
|
99
|
-
if (
|
|
149
|
+
const pkgRoot = import_path2.default.dirname(pkgJsonPath);
|
|
150
|
+
const srcPath = import_path2.default.join(pkgRoot, srcDir);
|
|
151
|
+
if (import_fs2.default.existsSync(srcPath)) return srcPath;
|
|
100
152
|
return pkgRoot;
|
|
101
153
|
} catch {
|
|
102
154
|
}
|
|
103
155
|
const parts = packageName.startsWith("@") ? packageName.split("/") : [packageName];
|
|
104
156
|
const candidates = [
|
|
105
|
-
|
|
106
|
-
|
|
157
|
+
import_path2.default.join(cwd, "node_modules", ...parts, srcDir),
|
|
158
|
+
import_path2.default.join(cwd, ".yalc", ...parts, srcDir)
|
|
107
159
|
];
|
|
108
160
|
for (const dir of candidates) {
|
|
109
|
-
if (
|
|
161
|
+
if (import_fs2.default.existsSync(dir)) return import_fs2.default.realpathSync(dir);
|
|
110
162
|
}
|
|
111
163
|
const rootCandidates = [
|
|
112
|
-
|
|
113
|
-
|
|
164
|
+
import_path2.default.join(cwd, "node_modules", ...parts),
|
|
165
|
+
import_path2.default.join(cwd, ".yalc", ...parts)
|
|
114
166
|
];
|
|
115
167
|
for (const dir of rootCandidates) {
|
|
116
|
-
if (
|
|
168
|
+
if (import_fs2.default.existsSync(dir)) return import_fs2.default.realpathSync(dir);
|
|
117
169
|
}
|
|
118
170
|
return null;
|
|
119
171
|
}
|
|
@@ -122,22 +174,24 @@ function resolveTarget(input) {
|
|
|
122
174
|
package: input,
|
|
123
175
|
alias: generateAlias(input),
|
|
124
176
|
srcDir: DEFAULT_SRC_DIR,
|
|
125
|
-
srcPath: ""
|
|
177
|
+
srcPath: "",
|
|
178
|
+
packageDir: ""
|
|
126
179
|
} : {
|
|
127
180
|
package: input.package,
|
|
128
181
|
alias: input.alias ?? generateAlias(input.package),
|
|
129
182
|
srcDir: input.srcDir ?? DEFAULT_SRC_DIR,
|
|
130
183
|
srcPath: "",
|
|
184
|
+
packageDir: "",
|
|
131
185
|
entryRedirect: input.entryRedirect,
|
|
132
186
|
hmr: input.hmr
|
|
133
187
|
};
|
|
134
188
|
const srcPath = findPackageSrcPath(target.package, target.srcDir);
|
|
135
189
|
if (!srcPath) return null;
|
|
136
190
|
target.srcPath = srcPath;
|
|
191
|
+
target.packageDir = srcPath.endsWith(import_path2.default.sep + target.srcDir) ? import_path2.default.resolve(srcPath, "..") : srcPath;
|
|
137
192
|
if (target.entryRedirect && target.hmr) {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
if (import_fs.default.existsSync(entryFile)) {
|
|
193
|
+
const entryFile = import_path2.default.resolve(target.packageDir, target.entryRedirect.to);
|
|
194
|
+
if (import_fs2.default.existsSync(entryFile)) {
|
|
141
195
|
target.entryFilePath = entryFile;
|
|
142
196
|
}
|
|
143
197
|
}
|
|
@@ -147,8 +201,8 @@ var CONFIG_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
|
147
201
|
function findConfigFile(basename, overrideDirs) {
|
|
148
202
|
for (const dir of overrideDirs) {
|
|
149
203
|
for (const ext of CONFIG_EXTENSIONS) {
|
|
150
|
-
const p =
|
|
151
|
-
if (
|
|
204
|
+
const p = import_path2.default.resolve(dir, `${basename}${ext}`);
|
|
205
|
+
if (import_fs2.default.existsSync(p)) return p;
|
|
152
206
|
}
|
|
153
207
|
}
|
|
154
208
|
return null;
|
|
@@ -156,7 +210,7 @@ function findConfigFile(basename, overrideDirs) {
|
|
|
156
210
|
function resolveOptions(options) {
|
|
157
211
|
const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
158
212
|
const overrideInput = options.overrides ?? DEFAULT_OVERRIDE_DIR;
|
|
159
|
-
const overrideDirs = (Array.isArray(overrideInput) ? overrideInput : [overrideInput]).map((dir) =>
|
|
213
|
+
const overrideDirs = (Array.isArray(overrideInput) ? overrideInput : [overrideInput]).map((dir) => import_path2.default.resolve(process.cwd(), dir));
|
|
160
214
|
const targets = [];
|
|
161
215
|
for (const input of options.targets) {
|
|
162
216
|
const resolved = resolveTarget(input);
|
|
@@ -179,29 +233,33 @@ function resolveOptions(options) {
|
|
|
179
233
|
extensions,
|
|
180
234
|
extensionSet: new Set(extensions),
|
|
181
235
|
patches,
|
|
182
|
-
hmrBoundaries: options.hmrBoundaries ?? []
|
|
236
|
+
hmrBoundaries: options.hmrBoundaries ?? [],
|
|
237
|
+
optimizeDeps: {
|
|
238
|
+
include: options.optimizeDeps?.include ?? []
|
|
239
|
+
},
|
|
240
|
+
autoOptimizeDeps: options.autoOptimizeDeps ?? true
|
|
183
241
|
};
|
|
184
242
|
}
|
|
185
243
|
|
|
186
244
|
// src/scanner.ts
|
|
187
|
-
var
|
|
188
|
-
var
|
|
245
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
246
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
189
247
|
function collectFiles(dir, extensionSet, depth = 0) {
|
|
190
248
|
if (depth > MAX_SCAN_DEPTH) return [];
|
|
191
249
|
const results = [];
|
|
192
250
|
let entries;
|
|
193
251
|
try {
|
|
194
|
-
entries =
|
|
252
|
+
entries = import_fs3.default.readdirSync(dir, { withFileTypes: true });
|
|
195
253
|
} catch {
|
|
196
254
|
return results;
|
|
197
255
|
}
|
|
198
256
|
for (const entry of entries) {
|
|
199
257
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
200
|
-
const fullPath =
|
|
258
|
+
const fullPath = import_path3.default.resolve(dir, entry.name);
|
|
201
259
|
if (entry.isDirectory()) {
|
|
202
260
|
results.push(...collectFiles(fullPath, extensionSet, depth + 1));
|
|
203
261
|
} else if (entry.isFile()) {
|
|
204
|
-
const ext =
|
|
262
|
+
const ext = import_path3.default.extname(entry.name);
|
|
205
263
|
if (extensionSet.has(ext)) {
|
|
206
264
|
results.push(fullPath);
|
|
207
265
|
}
|
|
@@ -219,7 +277,7 @@ function getOverrideKey(filePath, baseDir, match) {
|
|
|
219
277
|
if (match === "path") {
|
|
220
278
|
const normalizedBase = normalizePath(baseDir);
|
|
221
279
|
const relative = normalizePath(
|
|
222
|
-
|
|
280
|
+
import_path3.default.relative(normalizedBase, normalized)
|
|
223
281
|
);
|
|
224
282
|
return stripExtension(relative);
|
|
225
283
|
}
|
|
@@ -250,7 +308,7 @@ function scanAllTargets(opts, logger) {
|
|
|
250
308
|
return combined;
|
|
251
309
|
}
|
|
252
310
|
function detectNamespace(filePath, overrideDir) {
|
|
253
|
-
const relative = normalizePath(
|
|
311
|
+
const relative = normalizePath(import_path3.default.relative(overrideDir, filePath));
|
|
254
312
|
const scopedMatch = relative.match(/^(@[^/]+\/[^/]+)\//);
|
|
255
313
|
if (scopedMatch) return scopedMatch[1];
|
|
256
314
|
return null;
|
|
@@ -260,13 +318,13 @@ function scanOverrides(opts, logger) {
|
|
|
260
318
|
const namespaced = /* @__PURE__ */ new Map();
|
|
261
319
|
const targetPackages = new Set(opts.targets.map((t) => t.package));
|
|
262
320
|
for (const dir of opts.overrideDirs) {
|
|
263
|
-
if (!
|
|
321
|
+
if (!import_fs3.default.existsSync(dir)) continue;
|
|
264
322
|
for (const fullPath of collectFiles(dir, opts.extensionSet).sort()) {
|
|
265
|
-
const relative = normalizePath(
|
|
323
|
+
const relative = normalizePath(import_path3.default.relative(dir, fullPath));
|
|
266
324
|
if (relative.split("/").some((part) => part.startsWith("_"))) continue;
|
|
267
325
|
const ns = detectNamespace(fullPath, dir);
|
|
268
326
|
if (ns && targetPackages.has(ns)) {
|
|
269
|
-
const nsDir =
|
|
327
|
+
const nsDir = import_path3.default.join(dir, ns);
|
|
270
328
|
const key = getOverrideKey(fullPath, nsDir, opts.match);
|
|
271
329
|
if (key && key !== "index") {
|
|
272
330
|
if (!namespaced.has(ns)) namespaced.set(ns, /* @__PURE__ */ new Map());
|
|
@@ -286,8 +344,8 @@ function scanOverrides(opts, logger) {
|
|
|
286
344
|
}
|
|
287
345
|
|
|
288
346
|
// src/resolver.ts
|
|
289
|
-
var
|
|
290
|
-
var
|
|
347
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
348
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
291
349
|
function findImporterTarget(importer, opts) {
|
|
292
350
|
const norm = normalizePath(importer);
|
|
293
351
|
for (const target of opts.targets) {
|
|
@@ -295,7 +353,7 @@ function findImporterTarget(importer, opts) {
|
|
|
295
353
|
if (norm.startsWith(normSrc + "/") || norm === normSrc) {
|
|
296
354
|
return target;
|
|
297
355
|
}
|
|
298
|
-
const pkgDir = normalizePath(
|
|
356
|
+
const pkgDir = normalizePath(import_path4.default.dirname(target.srcPath));
|
|
299
357
|
if (norm.startsWith(pkgDir + "/")) {
|
|
300
358
|
return target;
|
|
301
359
|
}
|
|
@@ -308,11 +366,11 @@ function resolveEntryRedirect(resolvedId, opts, logger) {
|
|
|
308
366
|
if (target.entryRedirect) {
|
|
309
367
|
const fromPattern = normalizePath(target.entryRedirect.from);
|
|
310
368
|
if (norm.endsWith(`/${fromPattern}`) || norm.includes(`/${fromPattern}`)) {
|
|
311
|
-
const pkgDir =
|
|
312
|
-
const srcEntry =
|
|
313
|
-
if (
|
|
369
|
+
const pkgDir = import_path4.default.dirname(target.srcPath);
|
|
370
|
+
const srcEntry = import_path4.default.join(pkgDir, target.entryRedirect.to);
|
|
371
|
+
if (import_fs4.default.existsSync(srcEntry)) {
|
|
314
372
|
logger.info(
|
|
315
|
-
`Entry redirect: ${
|
|
373
|
+
`Entry redirect: ${import_path4.default.basename(resolvedId)} -> ${target.entryRedirect.to}`
|
|
316
374
|
);
|
|
317
375
|
return srcEntry;
|
|
318
376
|
}
|
|
@@ -326,7 +384,7 @@ function resolveEntryRedirect(resolvedId, opts, logger) {
|
|
|
326
384
|
/\/dist\/app\.(mjs|js)$/,
|
|
327
385
|
"/src/app.tsx"
|
|
328
386
|
);
|
|
329
|
-
if (
|
|
387
|
+
if (import_fs4.default.existsSync(srcEntry)) {
|
|
330
388
|
logger.info(`Entry redirect (auto): dist/app -> src/app.tsx`);
|
|
331
389
|
return srcEntry;
|
|
332
390
|
}
|
|
@@ -337,11 +395,11 @@ function resolveEntryRedirect(resolvedId, opts, logger) {
|
|
|
337
395
|
}
|
|
338
396
|
|
|
339
397
|
// src/watcher.ts
|
|
340
|
-
var
|
|
398
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
341
399
|
function setupWatcher(server, state, opts, logger) {
|
|
342
400
|
let debounceTimer = null;
|
|
343
401
|
const handleStructuralChange = (filePath) => {
|
|
344
|
-
const ext =
|
|
402
|
+
const ext = import_path5.default.extname(filePath);
|
|
345
403
|
if (!opts.extensionSet.has(ext)) return;
|
|
346
404
|
const normFile = normalizePath(filePath);
|
|
347
405
|
const isOverrideFile = opts.overrideDirs.some(
|
|
@@ -407,14 +465,14 @@ function setupWatcher(server, state, opts, logger) {
|
|
|
407
465
|
server.watcher.on("add", handleStructuralChange);
|
|
408
466
|
server.watcher.on("unlink", handleStructuralChange);
|
|
409
467
|
server.watcher.on("change", (filePath) => {
|
|
410
|
-
const ext =
|
|
468
|
+
const ext = import_path5.default.extname(filePath);
|
|
411
469
|
if (!opts.extensionSet.has(ext)) return;
|
|
412
470
|
const normFile = normalizePath(filePath);
|
|
413
471
|
const isOverrideFile = opts.overrideDirs.some(
|
|
414
472
|
(dir) => normFile.startsWith(normalizePath(dir) + "/")
|
|
415
473
|
);
|
|
416
474
|
if (!isOverrideFile) return;
|
|
417
|
-
const basename = stripExtension(
|
|
475
|
+
const basename = stripExtension(import_path5.default.basename(filePath));
|
|
418
476
|
if (!basename) return;
|
|
419
477
|
const isTrackedOverride = state.flatOverrides.has(basename) || [...state.namespacedOverrides.values()].some((m) => m.has(basename));
|
|
420
478
|
if (!isTrackedOverride) return;
|
|
@@ -436,7 +494,7 @@ function setupWatcher(server, state, opts, logger) {
|
|
|
436
494
|
});
|
|
437
495
|
if (opts.patches.length > 0) {
|
|
438
496
|
const handlePatchConfigStructural = (filePath) => {
|
|
439
|
-
const basename = stripExtension(
|
|
497
|
+
const basename = stripExtension(import_path5.default.basename(filePath));
|
|
440
498
|
if (!basename) return;
|
|
441
499
|
const normFile = normalizePath(filePath);
|
|
442
500
|
const isOverrideFile = opts.overrideDirs.some(
|
|
@@ -484,7 +542,7 @@ function invalidatePatchTarget(patch, server, logger) {
|
|
|
484
542
|
if (mod.file && patch.target.test(normalizePath(mod.file))) {
|
|
485
543
|
moduleGraph.invalidateModule(mod, /* @__PURE__ */ new Set(), timestamp, true);
|
|
486
544
|
roots.add(mod);
|
|
487
|
-
logger.info(`Invalidated patch target: ${
|
|
545
|
+
logger.info(`Invalidated patch target: ${import_path5.default.basename(mod.file)}`);
|
|
488
546
|
}
|
|
489
547
|
}
|
|
490
548
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -602,7 +660,7 @@ function unlock(userOptions) {
|
|
|
602
660
|
config.server.fs = config.server.fs || {};
|
|
603
661
|
config.server.fs.allow = config.server.fs.allow || [];
|
|
604
662
|
for (const dir of opts.overrideDirs) {
|
|
605
|
-
config.server.fs.allow.push(
|
|
663
|
+
config.server.fs.allow.push(import_path6.default.resolve(dir));
|
|
606
664
|
}
|
|
607
665
|
config.optimizeDeps = config.optimizeDeps || {};
|
|
608
666
|
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
@@ -614,6 +672,30 @@ function unlock(userOptions) {
|
|
|
614
672
|
);
|
|
615
673
|
}
|
|
616
674
|
}
|
|
675
|
+
if (opts.autoOptimizeDeps) {
|
|
676
|
+
const autoDeps = [];
|
|
677
|
+
for (const target of opts.targets) {
|
|
678
|
+
const cjsDeps = collectCjsDeps(target.packageDir);
|
|
679
|
+
for (const dep of cjsDeps) {
|
|
680
|
+
if (opts.targets.some((t) => t.package === dep)) continue;
|
|
681
|
+
if (!autoDeps.includes(dep)) autoDeps.push(dep);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (autoDeps.length > 0) {
|
|
685
|
+
config.optimizeDeps.include = config.optimizeDeps.include || [];
|
|
686
|
+
config.optimizeDeps.include.push(...autoDeps);
|
|
687
|
+
logger.info(
|
|
688
|
+
`Auto-included ${autoDeps.length} CJS deps for pre-bundling`
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (opts.optimizeDeps.include.length > 0) {
|
|
693
|
+
config.optimizeDeps.include = config.optimizeDeps.include || [];
|
|
694
|
+
config.optimizeDeps.include.push(...opts.optimizeDeps.include);
|
|
695
|
+
}
|
|
696
|
+
if (config.optimizeDeps.include) {
|
|
697
|
+
config.optimizeDeps.include = [...new Set(config.optimizeDeps.include)];
|
|
698
|
+
}
|
|
617
699
|
config.resolve = config.resolve || {};
|
|
618
700
|
config.resolve.alias = config.resolve.alias || {};
|
|
619
701
|
for (const target of opts.targets) {
|
|
@@ -628,8 +710,8 @@ function unlock(userOptions) {
|
|
|
628
710
|
}
|
|
629
711
|
}
|
|
630
712
|
for (const target of opts.targets) {
|
|
631
|
-
const entryFile =
|
|
632
|
-
if (
|
|
713
|
+
const entryFile = import_path6.default.join(target.srcPath, "app.tsx");
|
|
714
|
+
if (import_fs5.default.existsSync(entryFile)) {
|
|
633
715
|
const existing = config.optimizeDeps.entries;
|
|
634
716
|
if (Array.isArray(existing)) {
|
|
635
717
|
existing.push(entryFile);
|
|
@@ -656,19 +738,19 @@ function unlock(userOptions) {
|
|
|
656
738
|
return null;
|
|
657
739
|
const target = findImporterTarget(importer, opts);
|
|
658
740
|
if (target) {
|
|
659
|
-
const basename = stripExtension(
|
|
741
|
+
const basename = stripExtension(import_path6.default.basename(source));
|
|
660
742
|
if (basename && basename !== "index") {
|
|
661
743
|
const nsOverrides = state.namespacedOverrides.get(target.package);
|
|
662
744
|
if (nsOverrides?.has(basename)) {
|
|
663
745
|
const p = nsOverrides.get(basename);
|
|
664
746
|
logger.info(
|
|
665
|
-
`Override [${target.package}]: ${basename} -> ${
|
|
747
|
+
`Override [${target.package}]: ${basename} -> ${import_path6.default.basename(p)}`
|
|
666
748
|
);
|
|
667
749
|
return p;
|
|
668
750
|
}
|
|
669
751
|
if (state.flatOverrides.has(basename)) {
|
|
670
752
|
const p = state.flatOverrides.get(basename);
|
|
671
|
-
logger.info(`Override: ${basename} -> ${
|
|
753
|
+
logger.info(`Override: ${basename} -> ${import_path6.default.basename(p)}`);
|
|
672
754
|
return p;
|
|
673
755
|
}
|
|
674
756
|
}
|
|
@@ -703,15 +785,15 @@ function unlock(userOptions) {
|
|
|
703
785
|
load(id) {
|
|
704
786
|
const target = findImporterTarget(id, opts);
|
|
705
787
|
if (!target) return null;
|
|
706
|
-
const basename = stripExtension(
|
|
788
|
+
const basename = stripExtension(import_path6.default.basename(id));
|
|
707
789
|
if (!basename || basename === "index") return null;
|
|
708
790
|
const nsOverrides = state.namespacedOverrides.get(target.package);
|
|
709
791
|
const overridePath = nsOverrides?.get(basename) ?? state.flatOverrides.get(basename);
|
|
710
|
-
if (overridePath &&
|
|
792
|
+
if (overridePath && import_fs5.default.existsSync(overridePath)) {
|
|
711
793
|
this.addWatchFile(overridePath);
|
|
712
794
|
const normalizedPath = normalizePath(overridePath).replace(/"/g, '\\"');
|
|
713
795
|
logger.info(
|
|
714
|
-
`Load override: ${basename} -> ${
|
|
796
|
+
`Load override: ${basename} -> ${import_path6.default.basename(overridePath)}`
|
|
715
797
|
);
|
|
716
798
|
return `export { default } from "${normalizedPath}"
|
|
717
799
|
export * from "${normalizedPath}"`;
|
|
@@ -719,18 +801,18 @@ export * from "${normalizedPath}"`;
|
|
|
719
801
|
const normalizedId = normalizePath(id);
|
|
720
802
|
for (const patch of opts.patches) {
|
|
721
803
|
if (!patch.target.test(normalizedId)) continue;
|
|
722
|
-
if (!patch.configPath || !
|
|
804
|
+
if (!patch.configPath || !import_fs5.default.existsSync(patch.configPath)) continue;
|
|
723
805
|
this.addWatchFile(patch.configPath);
|
|
724
806
|
let original;
|
|
725
807
|
try {
|
|
726
|
-
original =
|
|
808
|
+
original = import_fs5.default.readFileSync(id, "utf-8");
|
|
727
809
|
} catch (err) {
|
|
728
810
|
logger.error(`Failed to read file for patching: ${id}`);
|
|
729
811
|
return null;
|
|
730
812
|
}
|
|
731
813
|
const patched = patch.apply(original, patch.configPath);
|
|
732
814
|
logger.info(
|
|
733
|
-
`Patch applied: ${
|
|
815
|
+
`Patch applied: ${import_path6.default.basename(id)} via ${patch.configFile}`
|
|
734
816
|
);
|
|
735
817
|
return { code: patched, map: null };
|
|
736
818
|
}
|
|
@@ -769,7 +851,7 @@ export * from "${normalizedPath}"`;
|
|
|
769
851
|
);
|
|
770
852
|
if (needsBoundary) {
|
|
771
853
|
logger.info(
|
|
772
|
-
`HMR boundary injected: ${
|
|
854
|
+
`HMR boundary injected: ${import_path6.default.basename(id)}`
|
|
773
855
|
);
|
|
774
856
|
return {
|
|
775
857
|
code: code + "\nif (import.meta.hot) { import.meta.hot.accept() }",
|
|
@@ -784,7 +866,7 @@ export * from "${normalizedPath}"`;
|
|
|
784
866
|
const fsConfig = server.config.server?.fs;
|
|
785
867
|
if (fsConfig && Array.isArray(fsConfig.allow)) {
|
|
786
868
|
for (const dir of opts.overrideDirs) {
|
|
787
|
-
const resolved =
|
|
869
|
+
const resolved = import_path6.default.resolve(dir);
|
|
788
870
|
if (!fsConfig.allow.includes(resolved)) {
|
|
789
871
|
fsConfig.allow.push(resolved);
|
|
790
872
|
}
|