solid-optimizer 1.0.0-next.7 → 1.0.0-next.9
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/README.md +4 -2
- package/dist/{compile-BuPR3pVT.mjs → compile-DptOANJi.mjs} +283 -23
- package/dist/compile-DptOANJi.mjs.map +1 -0
- package/dist/compile-X_SMDFr2.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +59 -32
- package/dist/vite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/compile.ts +21 -1
- package/src/constants.ts +22 -0
- package/src/fold.ts +104 -0
- package/src/inline.ts +168 -12
- package/src/scope.ts +115 -9
- package/src/terminate.ts +66 -0
- package/src/vite/index.ts +83 -47
- package/dist/compile-BuPR3pVT.mjs.map +0 -1
|
@@ -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;;;
|
|
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-
|
|
1
|
+
import { n as readModuleConstants, t as compile } from "./compile-DptOANJi.mjs";
|
|
2
2
|
export { compile, readModuleConstants };
|
package/dist/vite.d.mts.map
CHANGED
|
@@ -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;;;;
|
|
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
|
|
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-DptOANJi.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
|
-
/**
|
|
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
|
|
1420
|
-
*
|
|
1421
|
-
*
|
|
1422
|
-
*
|
|
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
|
-
|
|
1429
|
-
|
|
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)
|
|
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
|
|
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 &&
|
|
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
|
|
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
|
-
|
|
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) {
|