@sveltejs/vite-plugin-svelte 1.0.0-next.37 → 1.0.0-next.40
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 +41 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -38
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +10 -34
- 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/options.ts +23 -7
- package/src/utils/resolve.ts +0 -2
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.
|
|
52
|
+
// ../../node_modules/.pnpm/tsup@5.12.1_typescript@4.6.2/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
|
|
@@ -1185,7 +1194,7 @@ function enforceOptionsForProduction(options) {
|
|
|
1185
1194
|
function resolveViteRoot(viteConfig) {
|
|
1186
1195
|
return (0, import_vite3.normalizePath)(viteConfig.root ? import_path3.default.resolve(viteConfig.root) : process.cwd());
|
|
1187
1196
|
}
|
|
1188
|
-
function buildExtraViteConfig(options, config
|
|
1197
|
+
function buildExtraViteConfig(options, config) {
|
|
1189
1198
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1190
1199
|
const extraViteConfig = {
|
|
1191
1200
|
resolve: {
|
|
@@ -1193,10 +1202,10 @@ function buildExtraViteConfig(options, config, configEnv) {
|
|
|
1193
1202
|
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS]
|
|
1194
1203
|
}
|
|
1195
1204
|
};
|
|
1196
|
-
if (
|
|
1205
|
+
if (options.isServe) {
|
|
1197
1206
|
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
|
|
1198
1207
|
}
|
|
1199
|
-
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config);
|
|
1208
|
+
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1200
1209
|
return extraViteConfig;
|
|
1201
1210
|
}
|
|
1202
1211
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps2) {
|
|
@@ -1259,9 +1268,16 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
|
1259
1268
|
var _a2, _b2, _c2, _d;
|
|
1260
1269
|
return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x)) && !((_d = (_c2 = config.optimizeDeps) == null ? void 0 : _c2.include) == null ? void 0 : _d.includes(x));
|
|
1261
1270
|
}));
|
|
1262
|
-
|
|
1271
|
+
const ssr = {
|
|
1263
1272
|
noExternal
|
|
1264
1273
|
};
|
|
1274
|
+
if (options.isServe) {
|
|
1275
|
+
ssr.external = Array.from(new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))).filter((dep) => {
|
|
1276
|
+
var _a2, _b2, _c2, _d;
|
|
1277
|
+
return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.noExternal) == null ? void 0 : _b2.includes(dep)) && !((_d = (_c2 = config.ssr) == null ? void 0 : _c2.external) == null ? void 0 : _d.includes(dep));
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
return ssr;
|
|
1265
1281
|
}
|
|
1266
1282
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1267
1283
|
var _a, _b;
|
|
@@ -1448,8 +1464,6 @@ function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
|
1448
1464
|
cache.setResolvedSvelteField(importee, importer, result);
|
|
1449
1465
|
return result;
|
|
1450
1466
|
}
|
|
1451
|
-
} else {
|
|
1452
|
-
throw new Error(`failed to resolve package.json of ${importee} imported by ${importer}`);
|
|
1453
1467
|
}
|
|
1454
1468
|
}
|
|
1455
1469
|
}
|
|
@@ -1486,10 +1500,10 @@ var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
|
1486
1500
|
async function handleOptimizeDeps(options, viteConfig) {
|
|
1487
1501
|
if (!options.experimental.prebundleSvelteLibraries || !viteConfig.cacheDir)
|
|
1488
1502
|
return;
|
|
1489
|
-
const viteMetadataPath =
|
|
1490
|
-
if (!
|
|
1503
|
+
const viteMetadataPath = findViteMetadataPath(viteConfig.cacheDir);
|
|
1504
|
+
if (!viteMetadataPath)
|
|
1491
1505
|
return;
|
|
1492
|
-
const svelteMetadataPath = import_path6.default.resolve(
|
|
1506
|
+
const svelteMetadataPath = import_path6.default.resolve(viteMetadataPath, "../_svelte_metadata.json");
|
|
1493
1507
|
const currentSvelteMetadata = JSON.stringify(generateSvelteMetadata(options), (_, value) => {
|
|
1494
1508
|
return typeof value === "function" ? value.toString() : value;
|
|
1495
1509
|
});
|
|
@@ -1508,6 +1522,14 @@ function generateSvelteMetadata(options) {
|
|
|
1508
1522
|
}
|
|
1509
1523
|
return metadata;
|
|
1510
1524
|
}
|
|
1525
|
+
function findViteMetadataPath(cacheDir) {
|
|
1526
|
+
const metadataPaths = ["_metadata.json", "deps/_metadata.json"];
|
|
1527
|
+
for (const metadataPath of metadataPaths) {
|
|
1528
|
+
const viteMetadataPath = import_path6.default.resolve(cacheDir, metadataPath);
|
|
1529
|
+
if (import_fs5.default.existsSync(viteMetadataPath))
|
|
1530
|
+
return viteMetadataPath;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1511
1533
|
|
|
1512
1534
|
// src/index.ts
|
|
1513
1535
|
function svelte(inlineOptions) {
|
|
@@ -1516,7 +1538,6 @@ function svelte(inlineOptions) {
|
|
|
1516
1538
|
}
|
|
1517
1539
|
validateInlineOptions(inlineOptions);
|
|
1518
1540
|
const cache = new VitePluginSvelteCache();
|
|
1519
|
-
const pkg_resolve_errors = /* @__PURE__ */ new Set();
|
|
1520
1541
|
let requestParser;
|
|
1521
1542
|
let options;
|
|
1522
1543
|
let viteConfig;
|
|
@@ -1532,7 +1553,7 @@ function svelte(inlineOptions) {
|
|
|
1532
1553
|
log.setLevel(config.logLevel);
|
|
1533
1554
|
}
|
|
1534
1555
|
options = await preResolveOptions(inlineOptions, config, configEnv);
|
|
1535
|
-
const extraViteConfig = buildExtraViteConfig(options, config
|
|
1556
|
+
const extraViteConfig = buildExtraViteConfig(options, config);
|
|
1536
1557
|
log.debug("additional vite config", extraViteConfig);
|
|
1537
1558
|
return extraViteConfig;
|
|
1538
1559
|
},
|
|
@@ -1598,29 +1619,17 @@ function svelte(inlineOptions) {
|
|
|
1598
1619
|
log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
|
|
1599
1620
|
return resolved;
|
|
1600
1621
|
}
|
|
1601
|
-
} catch (
|
|
1602
|
-
|
|
1622
|
+
} catch (e) {
|
|
1623
|
+
log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
|
|
1603
1624
|
}
|
|
1604
1625
|
},
|
|
1605
1626
|
async transform(code, id, opts) {
|
|
1606
1627
|
var _a;
|
|
1607
1628
|
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1608
1629
|
const svelteRequest = requestParser(id, ssr);
|
|
1609
|
-
if (!svelteRequest) {
|
|
1630
|
+
if (!svelteRequest || svelteRequest.query.svelte) {
|
|
1610
1631
|
return;
|
|
1611
1632
|
}
|
|
1612
|
-
const { filename, query } = svelteRequest;
|
|
1613
|
-
if (query.svelte) {
|
|
1614
|
-
if (query.type === "style") {
|
|
1615
|
-
const css = cache.getCSS(svelteRequest);
|
|
1616
|
-
if (css) {
|
|
1617
|
-
log.debug(`transform returns css for ${filename}`);
|
|
1618
|
-
return css;
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
log.error("failed to transform tagged svelte request", svelteRequest);
|
|
1622
|
-
throw new Error(`failed to transform tagged svelte request for id ${id}`);
|
|
1623
|
-
}
|
|
1624
1633
|
let compileData;
|
|
1625
1634
|
try {
|
|
1626
1635
|
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
@@ -1634,7 +1643,7 @@ function svelte(inlineOptions) {
|
|
|
1634
1643
|
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1635
1644
|
});
|
|
1636
1645
|
}
|
|
1637
|
-
log.debug(`transform returns compiled js for ${filename}`);
|
|
1646
|
+
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
1638
1647
|
return compileData.compiled.js;
|
|
1639
1648
|
},
|
|
1640
1649
|
handleHotUpdate(ctx) {
|
|
@@ -1645,13 +1654,6 @@ function svelte(inlineOptions) {
|
|
|
1645
1654
|
if (svelteRequest) {
|
|
1646
1655
|
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1647
1656
|
}
|
|
1648
|
-
},
|
|
1649
|
-
buildEnd() {
|
|
1650
|
-
if (pkg_resolve_errors.size > 0) {
|
|
1651
|
-
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.
|
|
1652
|
-
If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
|
|
1653
|
-
${Array.from(pkg_resolve_errors, (s) => `- ${s}`).join("\n")}`.replace(/\t/g, ""));
|
|
1654
|
-
}
|
|
1655
1657
|
}
|
|
1656
1658
|
};
|
|
1657
1659
|
}
|