@sveltejs/vite-plugin-svelte 1.0.0-next.36 → 1.0.0-next.39
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 +33 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -35
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +9 -33
- package/src/utils/__tests__/dependencies.spec.ts +14 -3
- package/src/utils/dependencies.ts +17 -6
- package/src/utils/optimizer.ts +11 -4
- package/src/utils/resolve.ts +11 -4
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,7 @@ __export(src_exports, {
|
|
|
49
49
|
svelte: () => svelte
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
// ../../node_modules/.pnpm/tsup@5.11.
|
|
52
|
+
// ../../node_modules/.pnpm/tsup@5.11.13_typescript@4.5.5/node_modules/tsup/assets/cjs_shims.js
|
|
53
53
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
54
54
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
55
55
|
|
|
@@ -710,11 +710,20 @@ function needsOptimization(dep, localRequire) {
|
|
|
710
710
|
if (!depData)
|
|
711
711
|
return false;
|
|
712
712
|
const pkg = depData.pkg;
|
|
713
|
-
const
|
|
714
|
-
if (
|
|
713
|
+
const hasEsmFields = pkg.module || pkg.exports;
|
|
714
|
+
if (hasEsmFields)
|
|
715
715
|
return false;
|
|
716
|
-
|
|
717
|
-
|
|
716
|
+
if (pkg.main) {
|
|
717
|
+
const entryExt = import_path2.default.extname(pkg.main);
|
|
718
|
+
return !entryExt || entryExt === ".js" || entryExt === ".cjs";
|
|
719
|
+
} else {
|
|
720
|
+
try {
|
|
721
|
+
localRequire.resolve(`${dep}/index.js`);
|
|
722
|
+
return true;
|
|
723
|
+
} catch {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
718
727
|
}
|
|
719
728
|
|
|
720
729
|
// src/utils/options.ts
|
|
@@ -1434,7 +1443,7 @@ function ensureWatchedFile(watcher, file, root) {
|
|
|
1434
1443
|
var import_path5 = __toESM(require("path"), 1);
|
|
1435
1444
|
var import_module4 = require("module");
|
|
1436
1445
|
function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
1437
|
-
if (importer && isBareImport(importee) && !is_common_without_svelte_field(importee)) {
|
|
1446
|
+
if (importer && isBareImport(importee) && !isNodeInternal(importee) && !is_common_without_svelte_field(importee)) {
|
|
1438
1447
|
const cached = cache.getResolvedSvelteField(importee, importer);
|
|
1439
1448
|
if (cached) {
|
|
1440
1449
|
return cached;
|
|
@@ -1448,11 +1457,12 @@ function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
|
1448
1457
|
cache.setResolvedSvelteField(importee, importer, result);
|
|
1449
1458
|
return result;
|
|
1450
1459
|
}
|
|
1451
|
-
} else {
|
|
1452
|
-
throw new Error(`failed to resolve package.json of ${importee} imported by ${importer}`);
|
|
1453
1460
|
}
|
|
1454
1461
|
}
|
|
1455
1462
|
}
|
|
1463
|
+
function isNodeInternal(importee) {
|
|
1464
|
+
return importee.startsWith("node:") || import_module4.builtinModules.includes(importee);
|
|
1465
|
+
}
|
|
1456
1466
|
function isBareImport(importee) {
|
|
1457
1467
|
if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") || import_path5.default.isAbsolute(importee)) {
|
|
1458
1468
|
return false;
|
|
@@ -1483,10 +1493,10 @@ var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
|
1483
1493
|
async function handleOptimizeDeps(options, viteConfig) {
|
|
1484
1494
|
if (!options.experimental.prebundleSvelteLibraries || !viteConfig.cacheDir)
|
|
1485
1495
|
return;
|
|
1486
|
-
const viteMetadataPath =
|
|
1487
|
-
if (!
|
|
1496
|
+
const viteMetadataPath = findViteMetadataPath(viteConfig.cacheDir);
|
|
1497
|
+
if (!viteMetadataPath)
|
|
1488
1498
|
return;
|
|
1489
|
-
const svelteMetadataPath = import_path6.default.resolve(
|
|
1499
|
+
const svelteMetadataPath = import_path6.default.resolve(viteMetadataPath, "../_svelte_metadata.json");
|
|
1490
1500
|
const currentSvelteMetadata = JSON.stringify(generateSvelteMetadata(options), (_, value) => {
|
|
1491
1501
|
return typeof value === "function" ? value.toString() : value;
|
|
1492
1502
|
});
|
|
@@ -1505,6 +1515,14 @@ function generateSvelteMetadata(options) {
|
|
|
1505
1515
|
}
|
|
1506
1516
|
return metadata;
|
|
1507
1517
|
}
|
|
1518
|
+
function findViteMetadataPath(cacheDir) {
|
|
1519
|
+
const metadataPaths = ["_metadata.json", "deps/_metadata.json"];
|
|
1520
|
+
for (const metadataPath of metadataPaths) {
|
|
1521
|
+
const viteMetadataPath = import_path6.default.resolve(cacheDir, metadataPath);
|
|
1522
|
+
if (import_fs5.default.existsSync(viteMetadataPath))
|
|
1523
|
+
return viteMetadataPath;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1508
1526
|
|
|
1509
1527
|
// src/index.ts
|
|
1510
1528
|
function svelte(inlineOptions) {
|
|
@@ -1513,7 +1531,6 @@ function svelte(inlineOptions) {
|
|
|
1513
1531
|
}
|
|
1514
1532
|
validateInlineOptions(inlineOptions);
|
|
1515
1533
|
const cache = new VitePluginSvelteCache();
|
|
1516
|
-
const pkg_resolve_errors = /* @__PURE__ */ new Set();
|
|
1517
1534
|
let requestParser;
|
|
1518
1535
|
let options;
|
|
1519
1536
|
let viteConfig;
|
|
@@ -1595,29 +1612,17 @@ function svelte(inlineOptions) {
|
|
|
1595
1612
|
log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
|
|
1596
1613
|
return resolved;
|
|
1597
1614
|
}
|
|
1598
|
-
} catch (
|
|
1599
|
-
|
|
1615
|
+
} catch (e) {
|
|
1616
|
+
log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
|
|
1600
1617
|
}
|
|
1601
1618
|
},
|
|
1602
1619
|
async transform(code, id, opts) {
|
|
1603
1620
|
var _a;
|
|
1604
1621
|
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1605
1622
|
const svelteRequest = requestParser(id, ssr);
|
|
1606
|
-
if (!svelteRequest) {
|
|
1623
|
+
if (!svelteRequest || svelteRequest.query.svelte) {
|
|
1607
1624
|
return;
|
|
1608
1625
|
}
|
|
1609
|
-
const { filename, query } = svelteRequest;
|
|
1610
|
-
if (query.svelte) {
|
|
1611
|
-
if (query.type === "style") {
|
|
1612
|
-
const css = cache.getCSS(svelteRequest);
|
|
1613
|
-
if (css) {
|
|
1614
|
-
log.debug(`transform returns css for ${filename}`);
|
|
1615
|
-
return css;
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
log.error("failed to transform tagged svelte request", svelteRequest);
|
|
1619
|
-
throw new Error(`failed to transform tagged svelte request for id ${id}`);
|
|
1620
|
-
}
|
|
1621
1626
|
let compileData;
|
|
1622
1627
|
try {
|
|
1623
1628
|
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
@@ -1631,7 +1636,7 @@ function svelte(inlineOptions) {
|
|
|
1631
1636
|
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1632
1637
|
});
|
|
1633
1638
|
}
|
|
1634
|
-
log.debug(`transform returns compiled js for ${filename}`);
|
|
1639
|
+
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
1635
1640
|
return compileData.compiled.js;
|
|
1636
1641
|
},
|
|
1637
1642
|
handleHotUpdate(ctx) {
|
|
@@ -1642,13 +1647,6 @@ function svelte(inlineOptions) {
|
|
|
1642
1647
|
if (svelteRequest) {
|
|
1643
1648
|
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1644
1649
|
}
|
|
1645
|
-
},
|
|
1646
|
-
buildEnd() {
|
|
1647
|
-
if (pkg_resolve_errors.size > 0) {
|
|
1648
|
-
log.warn(`vite-plugin-svelte was unable to find package.json of the following packages and wasn't able to resolve via their "svelte" field.
|
|
1649
|
-
If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
|
|
1650
|
-
${Array.from(pkg_resolve_errors, (s) => `- ${s}`).join("\n")}`.replace(/\t/g, ""));
|
|
1651
|
-
}
|
|
1652
1650
|
}
|
|
1653
1651
|
};
|
|
1654
1652
|
}
|