solid-optimizer 1.1.0 → 1.1.1

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.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as readModuleConstants, t as compile } from "./compile-D2f8eXFk.mjs";
1
+ import { n as readModuleConstants, t as compile } from "./compile-DAmk1J8f.mjs";
2
2
  export { compile, readModuleConstants };
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.mts","names":["SolidPluginOptions"],"sources":["../src/vite/report.ts","../src/vite/index.ts"],"mappings":";;;;;UAUiB;;WAEN;WACA,gBAAgB;;;;iBC0CV,yBAAyB,KACxC;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;;EASA,qBAAqB,QAAQ;;;;;;;;;;EAU7B;;iBAKe,gBAAgB,QAAQA;;EAEvC,YAAY;;wBAoPU,eAAe,UAAS,UAAe"}
1
+ {"version":3,"file":"vite.d.mts","names":["SolidPluginOptions"],"sources":["../src/vite/report.ts","../src/vite/index.ts"],"mappings":";;;;;UAUiB;;WAEN;WACA,gBAAgB;;;;iBC4CV,yBAAyB,KACxC;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;;EASA,qBAAqB,QAAQ;;;;;;;;;;EAU7B;;iBAKe,gBAAgB,QAAQA;;EAEvC,YAAY;;wBAoPU,eAAe,UAAS,UAAe"}
package/dist/vite.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import { a as analyzeScopes, c as collectParents, d as parse, f as unwrap, i as runtimeImportSources, l as forEachChild, n as readModuleConstants, o as lookup, r as CONTEXT_SAFE_PRIMITIVES, s as scopeAt, t as compile, u as isIntrinsicTag } from "./compile-D2f8eXFk.mjs";
1
+ import { a as analyzeScopes, c as collectParents, d as parse, f as unwrap, i as runtimeImportSources, l as forEachChild, n as readModuleConstants, o as lookup, r as CONTEXT_SAFE_PRIMITIVES, s as scopeAt, t as compile, u as isIntrinsicTag } from "./compile-DAmk1J8f.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import remapping from "@jridgewell/remapping";
4
4
  import { parseSync } from "oxc-parser";
5
5
  import MagicString from "magic-string";
6
- import { readFile } from "node:fs/promises";
6
+ import { access, readFile } from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import { gzipSync } from "node:zlib";
9
9
  import solidPlugin from "@solidjs/vite-plugin";
10
- import { createFilter, minifySync, transformWithOxc } from "vite";
10
+ import { createFilter, createIdResolver, minifySync, transformWithOxc } from "vite";
11
11
  //#region src/vite/globals.ts
12
12
  /**
13
13
  * The `define` entries and `import.meta.env` values that are the same in
@@ -1184,6 +1184,7 @@ function solidOptimizer(options = {}) {
1184
1184
  skips.set(environment, entries);
1185
1185
  };
1186
1186
  let config;
1187
+ let idResolver;
1187
1188
  /** The `define` entries and `import.meta.env` values every environment shares. */
1188
1189
  let globals = {};
1189
1190
  let compiler;
@@ -1284,6 +1285,18 @@ function solidOptimizer(options = {}) {
1284
1285
  */
1285
1286
  const moduleConstants = /* @__PURE__ */ new Map();
1286
1287
  /**
1288
+ * Whether `id` names a file in the project that does not exist. An alias can resolve a
1289
+ * Babel macro module, which a later plugin compiles away, to such a path. Loading it fails
1290
+ * the build even when the error is caught, and it has nothing to read, so it is left to the
1291
+ * bundler. A virtual module has an id that is not a project path, and is still loaded.
1292
+ */
1293
+ async function isMissingProjectFile(id) {
1294
+ const file = stripQuery(id);
1295
+ const root = config?.root ?? process.cwd();
1296
+ const relative = path.relative(root, file);
1297
+ return path.isAbsolute(file) && !relative.startsWith("..") && !path.isAbsolute(relative) && !await fileExists(file);
1298
+ }
1299
+ /**
1287
1300
  * The module an import resolves to, when its constants can be read, and
1288
1301
  * whether it has JSX. Dependencies are skipped to keep the build fast.
1289
1302
  */
@@ -1291,6 +1304,7 @@ function solidOptimizer(options = {}) {
1291
1304
  if (moduleSources.includes(specifier)) return;
1292
1305
  const resolved = await context.resolve(specifier, importer);
1293
1306
  if (!resolved || resolved.external || resolved.id.includes("/node_modules/")) return;
1307
+ if (await isMissingProjectFile(resolved.id)) return;
1294
1308
  return {
1295
1309
  id: resolved.id,
1296
1310
  jsx: isJSXModule(resolved.id)
@@ -1476,7 +1490,7 @@ function solidOptimizer(options = {}) {
1476
1490
  try {
1477
1491
  return await readFile(stripQuery(id), "utf8");
1478
1492
  } catch {
1479
- if (isJSXModule(id)) return;
1493
+ if (isJSXModule(id) || await isMissingProjectFile(id)) return;
1480
1494
  }
1481
1495
  try {
1482
1496
  return (await context.load({ id })).code ?? void 0;
@@ -1512,7 +1526,7 @@ function solidOptimizer(options = {}) {
1512
1526
  return [];
1513
1527
  }
1514
1528
  const resolving = [];
1515
- for (const source of runtimeImportSources(program)) if (!moduleSources.includes(source) && !source.startsWith("node:")) resolving.push(context.resolve(source, id));
1529
+ for (const source of runtimeImportSources(program)) if (!moduleSources.includes(source) && !source.startsWith("node:")) resolving.push(resolveForWalk(context, source, id));
1516
1530
  const resolved = await Promise.all(resolving);
1517
1531
  const local = [];
1518
1532
  for (const target of resolved) if (target && !target.external && isCopyable(target.id)) local.push(target.id);
@@ -1522,6 +1536,27 @@ function solidOptimizer(options = {}) {
1522
1536
  }
1523
1537
  return pending;
1524
1538
  }
1539
+ /**
1540
+ * Resolves an import of a file on disk, for the walks that read imports from files. The
1541
+ * import may never reach the bundler: a framework plugin can compile it away first, like
1542
+ * the server-only imports of a module whose server functions become client stubs. Other
1543
+ * plugins' `resolveId` hooks can act on every resolution they see, and TanStack Start's
1544
+ * import protection reports one of those imports as a violation. So aliases and files are
1545
+ * resolved without plugin hooks. Anything that is not a file path, like a virtual module or
1546
+ * a runtime built-in, goes through the plugins.
1547
+ */
1548
+ async function resolveForWalk(context, source, importer) {
1549
+ const environment = context.environment;
1550
+ if (config && environment) {
1551
+ idResolver ??= createIdResolver(config);
1552
+ const id = await idResolver(environment, source, importer);
1553
+ if (id !== void 0 && path.isAbsolute(stripQuery(id))) return {
1554
+ id,
1555
+ external: false
1556
+ };
1557
+ }
1558
+ return context.resolve(source, importer);
1559
+ }
1525
1560
  /** Whether `from` imports `to`, directly or through other modules. */
1526
1561
  async function reaches(context, from, to) {
1527
1562
  const seen = /* @__PURE__ */ new Set();
@@ -1614,7 +1649,7 @@ function solidOptimizer(options = {}) {
1614
1649
  }
1615
1650
  return buildUsageIndex(known ? scriptIds : [], {
1616
1651
  resolve: async (source, importer) => {
1617
- const resolved = await context.resolve(source, importer);
1652
+ const resolved = await resolveForWalk(context, source, importer);
1618
1653
  return !resolved || resolved.external || resolved.id.includes("/node_modules/") ? void 0 : resolved.id;
1619
1654
  },
1620
1655
  read: async (id) => {
@@ -1993,6 +2028,7 @@ function solidOptimizer(options = {}) {
1993
2028
  configResolved(resolved) {
1994
2029
  config = resolved;
1995
2030
  globals = sharedGlobals(resolved);
2031
+ idResolver = void 0;
1996
2032
  },
1997
2033
  buildStart() {
1998
2034
  moduleConstants.clear();
@@ -2164,6 +2200,14 @@ function solidOptimizer(options = {}) {
2164
2200
  chunkPlugin
2165
2201
  ];
2166
2202
  }
2203
+ async function fileExists(file) {
2204
+ try {
2205
+ await access(file);
2206
+ return true;
2207
+ } catch {
2208
+ return false;
2209
+ }
2210
+ }
2167
2211
  //#endregion
2168
2212
  export { solidOptimizer as default };
2169
2213