solid-optimizer 1.0.0-next.6 → 1.0.0-next.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"compile-X_SMDFr2.d.mts","names":[],"sources":["../src/value.ts","../src/context.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;;KAUY;;;;KC4DA;;;;;UAMK;WACN,MAAM;;WAEN;;WAEA;;;;;;;;KC9DC,oBAAoB,SAAS,eAAe,SAAS,eAAe;;;UCD/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;EAQA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,kBAAkB,SAAS,eAAe;;;;;;EAM1C,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;EAMA;;;;;;;;EAQA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAqGI,QAAQ,cAAc,UAAS,iBAAsB;UAiFpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,wEACb"}
1
+ {"version":3,"file":"compile-X_SMDFr2.d.mts","names":[],"sources":["../src/value.ts","../src/context.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;;KAUY;;;;KC4DA;;;;;UAMK;WACN,MAAM;;WAEN;;WAEA;;;;;;;;KC9DC,oBAAoB,SAAS,eAAe,SAAS,eAAe;;;UCC/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;EAQA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,kBAAkB,SAAS,eAAe;;;;;;EAM1C,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;EAMA;;;;;;;;EAQA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAqGI,QAAQ,cAAc,UAAS,iBAAsB;UAwHpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,wEACb"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as readModuleConstants, t as compile } from "./compile-DnfP-Quf.mjs";
1
+ import { n as readModuleConstants, t as compile } from "./compile-O1Z60VsW.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;;;;iBCyCV,yBAAyB,KACxC;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;;EASA,qBAAqB,QAAQ;;;;;;;;;;EAU7B;;iBAKe,gBAAgB,QAAQA;;EAEvC,YAAY;;wBAiNU,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;;;;iBC0CV,yBAAyB,KACxC;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;;EASA,qBAAqB,QAAQ;;;;;;;;;;EAU7B;;iBAKe,gBAAgB,QAAQA;;EAEvC,YAAY;;wBAiNU,eAAe,UAAS,UAAe"}
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as lookup, c as forEachChild, d as unwrap, i as analyzeScopes, l as isIntrinsicTag, n as readModuleConstants, o as scopeAt, r as CONTEXT_SAFE_PRIMITIVES, s as collectParents, t as compile, u as parse } from "./compile-DnfP-Quf.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-O1Z60VsW.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import remapping from "@jridgewell/remapping";
4
4
  import MagicString from "magic-string";
@@ -1413,47 +1413,75 @@ function solidOptimizer(options = {}) {
1413
1413
  * copies components from it.
1414
1414
  */
1415
1415
  const recorded = /* @__PURE__ */ new Map();
1416
- /** The modules of the project each module imports, read from its file. */
1416
+ /**
1417
+ * Whether components can be copied from a module: one of the app's, or
1418
+ * one of a package listed in `optimizer.packages`.
1419
+ */
1420
+ const isCopyable = (id) => {
1421
+ const file = stripQuery(id).replaceAll("\\", "/");
1422
+ if (!file.includes("/node_modules/")) return true;
1423
+ for (const name of optimizer.packages ?? []) if (file.includes(`/node_modules/${name}/`)) return true;
1424
+ return false;
1425
+ };
1426
+ /** The modules each module imports, read from its file. */
1417
1427
  const localImports = /* @__PURE__ */ new Map();
1418
1428
  /**
1419
- * The modules of the project a module imports, leaving out dependencies.
1420
- * They come from the file on disk, so they do not depend on the order
1421
- * modules are transformed in. Modules without JSX count too, since reading
1422
- * their constants can load a module with JSX.
1429
+ * The code of a module as its file holds it. A module with no file, like
1430
+ * a virtual module a plugin generates, is loaded instead, unless it has
1431
+ * JSX: this plugin transforms such a module, so loading it could wait for
1432
+ * the transform that asks. Its imports are then not followed.
1433
+ */
1434
+ async function readModuleCode(context, id) {
1435
+ try {
1436
+ return await readFile(stripQuery(id), "utf8");
1437
+ } catch {
1438
+ if (isJSXModule(id)) return;
1439
+ }
1440
+ try {
1441
+ return (await context.load({ id })).code ?? void 0;
1442
+ } catch {
1443
+ return;
1444
+ }
1445
+ }
1446
+ /**
1447
+ * The modules a module imports at runtime that a transform can wait for:
1448
+ * the app's, those of packages listed in `optimizer.packages`, and virtual
1449
+ * modules. A transform only waits for a module it copies from, and it only
1450
+ * copies from those, so a module of another package is never in a loop of
1451
+ * transforms that wait for each other. A virtual module can re-export the
1452
+ * app, so a listed package can import the app back through one, like a
1453
+ * docs framework that imports its theme's layout.
1454
+ *
1455
+ * Imports only used as types are left out, since TypeScript drops them,
1456
+ * and so are Solid's own modules and Node's built-ins. The imports come
1457
+ * from the file on disk, so they do not depend on the order modules are
1458
+ * transformed in. Modules without JSX count too, since reading their
1459
+ * constants can load a module with JSX.
1423
1460
  */
1424
1461
  async function findLocalImports(context, id) {
1425
1462
  let pending = localImports.get(id);
1426
1463
  if (!pending) {
1427
1464
  pending = (async () => {
1428
- let code;
1429
- try {
1430
- code = await readFile(stripQuery(id), "utf8");
1431
- } catch {
1432
- return [];
1433
- }
1465
+ const code = await readModuleCode(context, id);
1466
+ if (code === void 0) return [];
1434
1467
  let program;
1435
1468
  try {
1436
- program = parse(stripQuery(id), code);
1469
+ program = parse(/\.[cm]?[jt]sx?$/.test(stripQuery(id)) ? stripQuery(id) : `${id}.js`, code);
1437
1470
  } catch {
1438
1471
  return [];
1439
1472
  }
1440
- const sources = /* @__PURE__ */ new Set();
1441
- for (const statement of program.body) if (statement.type === "ImportDeclaration" && statement.importKind !== "type" || (statement.type === "ExportNamedDeclaration" || statement.type === "ExportAllDeclaration") && statement.source && statement.exportKind !== "type") {
1442
- const value = statement.source?.value;
1443
- if (value !== void 0 && !moduleSources.includes(value)) sources.add(value);
1444
- }
1445
1473
  const resolving = [];
1446
- for (const source of sources) resolving.push(context.resolve(source, id));
1474
+ for (const source of runtimeImportSources(program)) if (!moduleSources.includes(source) && !source.startsWith("node:")) resolving.push(context.resolve(source, id));
1447
1475
  const resolved = await Promise.all(resolving);
1448
1476
  const local = [];
1449
- for (const target of resolved) if (target && !target.external && !target.id.includes("/node_modules/")) local.push(target.id);
1477
+ for (const target of resolved) if (target && !target.external && isCopyable(target.id)) local.push(target.id);
1450
1478
  return local;
1451
1479
  })();
1452
1480
  localImports.set(id, pending);
1453
1481
  }
1454
1482
  return pending;
1455
1483
  }
1456
- /** Whether `from` imports `to`, directly or through other modules of the project. */
1484
+ /** Whether `from` imports `to`, directly or through other modules. */
1457
1485
  async function reaches(context, from, to) {
1458
1486
  const seen = /* @__PURE__ */ new Set();
1459
1487
  let frontier = [from];
@@ -1570,16 +1598,6 @@ function solidOptimizer(options = {}) {
1570
1598
  if (imported === "default") return `import ${local} from ${from};`;
1571
1599
  return `import { ${imported} as ${local} } from ${from};`;
1572
1600
  }
1573
- /**
1574
- * Whether components can be copied from a module: one of the app's, or
1575
- * one of a package listed in `optimizer.packages`.
1576
- */
1577
- const isCopyable = (id) => {
1578
- const file = stripQuery(id).replaceAll("\\", "/");
1579
- if (!file.includes("/node_modules/")) return true;
1580
- for (const name of optimizer.packages ?? []) if (file.includes(`/node_modules/${name}/`)) return true;
1581
- return false;
1582
- };
1583
1601
  /** The listed packages already warned about, by environment. */
1584
1602
  const warnedPackages = /* @__PURE__ */ new Set();
1585
1603
  /**
@@ -1665,7 +1683,16 @@ function solidOptimizer(options = {}) {
1665
1683
  skip("copy-external");
1666
1684
  return;
1667
1685
  }
1668
- targets.set(dependency.source, target.external ? dependency.source : target.id);
1686
+ if (!target.id.startsWith("\0")) {
1687
+ targets.set(dependency.source, target.external ? dependency.source : target.id);
1688
+ continue;
1689
+ }
1690
+ if ((await context.resolve(dependency.source, id))?.id !== target.id) {
1691
+ state.excluded.add(key);
1692
+ skip("copy-virtual");
1693
+ return;
1694
+ }
1695
+ targets.set(dependency.source, dependency.source);
1669
1696
  }
1670
1697
  const rename = /* @__PURE__ */ new Map();
1671
1698
  for (const [local, dependency] of component.dependencies) {