@vesk/compiler 0.2.50-canary.2 → 0.2.50-canary.4

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.
@@ -74,6 +74,31 @@ export declare function resolveImportPath(spec: string, fromDir: string): string
74
74
  * `node_modules`) share one cache entry and one module instance.
75
75
  */
76
76
  export declare function resolveSsrModule(specifier: string, fromDir: string): string | null;
77
+ /**
78
+ * Resolve a subpath through a package's `exports` map.
79
+ *
80
+ * This is what makes a Vesk app work inside an existing pnpm/npm/yarn
81
+ * workspace. A modern workspace package declares `exports` and often NO `main`
82
+ * (or points `main` at a CJS build while the app imports ESM), and subpath
83
+ * imports (`@acme/ui/button`) resolve through the map rather than through the
84
+ * directory layout. Without this, such a package simply does not resolve, and
85
+ * the app has to vendor it.
86
+ *
87
+ * Conditions are tried in import order: `import`, `module`, `node`, `default`.
88
+ * A pattern (`./dist/*.js`) is matched with the single `*` capture.
89
+ */
90
+ export declare function resolveExports(exportsField: unknown, subpath: string): string | null;
91
+ /**
92
+ * Resolve a bare specifier through a package's `module` field (the ESM entry
93
+ * in a package that also has a CJS `main`).
94
+ */
95
+ export declare function resolveViaPackageModuleField(specifier: string, fromDir: string): string | null;
96
+ /**
97
+ * Resolve a bare specifier through its package's `exports` map, walking
98
+ * node_modules upwards. Returns null when the package has no map, does not
99
+ * export the subpath, or cannot be read.
100
+ */
101
+ export declare function resolveViaPackageExports(specifier: string, fromDir: string): string | null;
77
102
  /** Rewrites an ESM program body (imports/exports removed) into CJS statements. */
78
103
  export declare function esmToCjs(body: Array<{
79
104
  type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"module-imports.d.ts","sourceRoot":"","sources":["../src/module-imports.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AA2ElD,gFAAgF;AAChF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAM7D;AAED,gEAAgE;AAChE,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AAE,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,MAAM,CA8DxF;AAID;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,eAAe,GACzB,iBAAiB,EAAE,CAiBrB"}
@@ -900,6 +900,21 @@ export function resolveSsrModule(specifier, fromDir) {
900
900
  const aliased = resolveAliasModule(specifier, fromDir);
901
901
  if (aliased)
902
902
  return toRealPath(aliased);
903
+ // Bare specifier. A package's `exports` map is consulted BEFORE Node's own
904
+ // resolver: `createRequire.resolve` applies the CJS conditions, so it picks
905
+ // a `.cjs` build for a package that also ships ESM — and fails outright on
906
+ // an `import`-only package. Vesk emits ESM, so the `import` condition is
907
+ // the correct one. Node's resolver stays as the fallback (builtins, exotic
908
+ // conditions), and the node_modules walk after that.
909
+ const viaExports = resolveViaPackageExports(specifier, fromDir);
910
+ if (viaExports)
911
+ return viaExports;
912
+ // Same reasoning for the legacy fields: a package declaring both `module`
913
+ // and `main` wants the ESM build (Vesk emits ESM), while `createRequire`
914
+ // would take `main` and hand us the CJS one.
915
+ const viaModuleField = resolveViaPackageModuleField(specifier, fromDir);
916
+ if (viaModuleField)
917
+ return viaModuleField;
903
918
  // Bare specifier — prefer the native resolver (exports map, conditions,
904
919
  // builtins, symlinks), then fall back to a node_modules walk-up.
905
920
  const native = nativeResolve(specifier, fromDir);
@@ -983,6 +998,145 @@ function statOrNull(p) {
983
998
  return null;
984
999
  }
985
1000
  }
1001
+ /**
1002
+ * Resolve a subpath through a package's `exports` map.
1003
+ *
1004
+ * This is what makes a Vesk app work inside an existing pnpm/npm/yarn
1005
+ * workspace. A modern workspace package declares `exports` and often NO `main`
1006
+ * (or points `main` at a CJS build while the app imports ESM), and subpath
1007
+ * imports (`@acme/ui/button`) resolve through the map rather than through the
1008
+ * directory layout. Without this, such a package simply does not resolve, and
1009
+ * the app has to vendor it.
1010
+ *
1011
+ * Conditions are tried in import order: `import`, `module`, `node`, `default`.
1012
+ * A pattern (`./dist/*.js`) is matched with the single `*` capture.
1013
+ */
1014
+ export function resolveExports(exportsField, subpath) {
1015
+ const conditions = ['import', 'module', 'node', 'default'];
1016
+ const target = (value) => {
1017
+ if (typeof value === 'string')
1018
+ return value;
1019
+ if (!value || typeof value !== 'object')
1020
+ return null;
1021
+ for (const cond of conditions) {
1022
+ if (cond in value) {
1023
+ const got = target(value[cond]);
1024
+ if (got)
1025
+ return got;
1026
+ }
1027
+ }
1028
+ return null;
1029
+ };
1030
+ if (typeof exportsField === 'string')
1031
+ return subpath === '.' ? exportsField : null;
1032
+ if (!exportsField || typeof exportsField !== 'object')
1033
+ return null;
1034
+ const map = exportsField;
1035
+ if (subpath in map) {
1036
+ const direct = target(map[subpath]);
1037
+ if (direct)
1038
+ return direct;
1039
+ return null;
1040
+ }
1041
+ // Longest-prefix match for `./*` patterns, as Node does.
1042
+ let best = null;
1043
+ for (const key of Object.keys(map)) {
1044
+ const star = key.indexOf('*');
1045
+ if (star === -1)
1046
+ continue;
1047
+ const prefix = key.slice(0, star);
1048
+ const suffix = key.slice(star + 1);
1049
+ if (!subpath.startsWith(prefix) || !subpath.endsWith(suffix))
1050
+ continue;
1051
+ if (subpath.length < prefix.length + suffix.length)
1052
+ continue;
1053
+ if (best === null || prefix.length > best.key.length) {
1054
+ best = { key: prefix, star: subpath.slice(prefix.length, subpath.length - suffix.length) };
1055
+ }
1056
+ }
1057
+ if (!best)
1058
+ return null;
1059
+ const pattern = target(map[Object.keys(map).find((k) => k.startsWith(best.key + '*') && k.endsWith(best.key.slice(0, -1)) + '*')] ?? map[`${best.key}*`]);
1060
+ if (pattern === null)
1061
+ return null;
1062
+ return pattern.split('*').join(best.star);
1063
+ }
1064
+ /**
1065
+ * Resolve a bare specifier through a package's `module` field (the ESM entry
1066
+ * in a package that also has a CJS `main`).
1067
+ */
1068
+ export function resolveViaPackageModuleField(specifier, fromDir) {
1069
+ const firstSlash = specifier.indexOf('/');
1070
+ const splitAt = specifier.startsWith('@') ? specifier.indexOf('/', firstSlash + 1) : firstSlash;
1071
+ const pkgName = splitAt > 0 ? specifier.slice(0, splitAt) : specifier;
1072
+ if (splitAt > 0)
1073
+ return null; // a subpath import needs the exports map
1074
+ let dir = fromDir;
1075
+ for (let depth = 0; depth < 64; depth++) {
1076
+ const pkgPath = join(dir, 'node_modules', pkgName, 'package.json');
1077
+ if (statOrNull(pkgPath) !== null) {
1078
+ try {
1079
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
1080
+ if (typeof pkg.module === 'string' && pkg.module.length > 0) {
1081
+ const found = probeFile(resolve(join(dir, 'node_modules', pkgName), pkg.module));
1082
+ if (found)
1083
+ return toRealPath(found);
1084
+ }
1085
+ }
1086
+ catch {
1087
+ // malformed package.json — fall through
1088
+ }
1089
+ return null;
1090
+ }
1091
+ const parent = dirname(dir);
1092
+ if (parent === dir)
1093
+ break;
1094
+ dir = parent;
1095
+ }
1096
+ return null;
1097
+ }
1098
+ /**
1099
+ * Resolve a bare specifier through its package's `exports` map, walking
1100
+ * node_modules upwards. Returns null when the package has no map, does not
1101
+ * export the subpath, or cannot be read.
1102
+ */
1103
+ export function resolveViaPackageExports(specifier, fromDir) {
1104
+ // A scoped name (`@acme/ui`) has its slash INSIDE the package name — taking
1105
+ // the first slash as the subpath separator turns it into package `@acme` +
1106
+ // subpath `./ui`, which no `exports` map matches, and the lookup silently
1107
+ // falls through to Node's resolver.
1108
+ const firstSlash = specifier.indexOf('/');
1109
+ const splitAt = specifier.startsWith('@') ? specifier.indexOf('/', firstSlash + 1) : firstSlash;
1110
+ const pkgName = splitAt > 0 ? specifier.slice(0, splitAt) : specifier;
1111
+ const subpath = splitAt > 0 ? '.' + specifier.slice(splitAt) : '.';
1112
+ let dir = fromDir;
1113
+ for (let depth = 0; depth < 64; depth++) {
1114
+ const pkgDir = join(dir, 'node_modules', pkgName);
1115
+ const pkgPath = join(pkgDir, 'package.json');
1116
+ if (statOrNull(pkgPath) !== null) {
1117
+ try {
1118
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
1119
+ if (pkg.exports !== undefined) {
1120
+ const target = resolveExports(pkg.exports, subpath);
1121
+ if (target) {
1122
+ const found = probeFile(resolve(pkgDir, target));
1123
+ if (found)
1124
+ return toRealPath(found);
1125
+ }
1126
+ }
1127
+ }
1128
+ catch {
1129
+ // malformed package.json — fall through to the resolvers below
1130
+ }
1131
+ return null;
1132
+ }
1133
+ const parent = dirname(dir);
1134
+ if (parent === dir)
1135
+ break;
1136
+ dir = parent;
1137
+ }
1138
+ return null;
1139
+ }
986
1140
  function probeFile(base) {
987
1141
  const st = statOrNull(base);
988
1142
  if (st && st.isFile())
@@ -993,10 +1147,24 @@ function probeFile(base) {
993
1147
  if (pkgSt && pkgSt.isFile()) {
994
1148
  try {
995
1149
  const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
996
- if (typeof pkg.main === 'string' && pkg.main.length > 0) {
997
- const viaMain = probeFile(resolve(base, pkg.main));
998
- if (viaMain)
999
- return viaMain;
1150
+ // `exports` first: it is what the package author intends and what a
1151
+ // workspace package usually ships. `main`/`module` are the legacy
1152
+ // fallbacks.
1153
+ if (pkg.exports !== undefined) {
1154
+ const viaExports = resolveExports(pkg.exports, '.');
1155
+ if (viaExports) {
1156
+ const found = probeFile(resolve(base, viaExports));
1157
+ if (found)
1158
+ return found;
1159
+ }
1160
+ }
1161
+ for (const field of ['module', 'main']) {
1162
+ const value = pkg[field];
1163
+ if (typeof value === 'string' && value.length > 0) {
1164
+ const found = probeFile(resolve(base, value));
1165
+ if (found)
1166
+ return found;
1167
+ }
1000
1168
  }
1001
1169
  }
1002
1170
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"server-render.d.ts","sourceRoot":"","sources":["../src/server-render.ts"],"names":[],"mappings":"AAOA,OAAO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AE,OAAO,CAAC,EAChC,QAAQ,CAAC,EAAE,kBAAkB,GAAG,IAAI,GACnC,MAAM,EAAE,CAuBV;AAED,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACnC,QAAQ,GAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAa,EAC3C,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAoHjB;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACnC,QAAQ,GAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAa,EAC3C,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAAC,MAAM,CAAC,CAkJxB"}
@@ -516,8 +516,11 @@ export async function renderFullPage(source, componentName, props = {}, registry
516
516
  const bodyHtml = prettifyHtml(rendered.body);
517
517
  const cssUrls = options.cssUrls || (options.cssUrl ? [options.cssUrl] : []);
518
518
  const cssLink = cssUrls.map(u => `\t<link rel="stylesheet" href="${u}" />\n`).join('');
519
+ // `crossorigin` is required for SRI to be enforced on a module script; a
520
+ // same-origin module is fetched in CORS mode, so the attribute is harmless
521
+ // and makes the digest meaningful.
519
522
  const clientScript = options.clientScriptUrl
520
- ? `\t<script type="module" src="${options.clientScriptUrl}"></script>\n`
523
+ ? `\t<script type="module" src="${options.clientScriptUrl}"${options.clientScriptIntegrity ? ` integrity="${options.clientScriptIntegrity}" crossorigin="anonymous"` : ''}></script>\n`
521
524
  : '';
522
525
  const dataScripts = buildDataScripts(ssrProps, ssrData, options.externalDataScript);
523
526
  const dataScriptBlock = dataScripts.length > 0 ? '\n' + dataScripts.join('\n') + '\n' : '';
@@ -675,7 +678,7 @@ export function renderPageStream(source, componentName, props = {}, registry = n
675
678
  // Mirror renderFullPage: a full document must carry the client bundle or
676
679
  // the page can never hydrate (dev-server streams hit this path).
677
680
  const clientScript = options.clientScriptUrl
678
- ? `\t<script type="module" src="${options.clientScriptUrl}"></script>\n`
681
+ ? `\t<script type="module" src="${options.clientScriptUrl}"${options.clientScriptIntegrity ? ` integrity="${options.clientScriptIntegrity}" crossorigin="anonymous"` : ''}></script>\n`
679
682
  : '';
680
683
  yield `\n</div>${dataScriptBlock}${clientScript}</body>\n</html>\n`;
681
684
  }
package/dist/types.d.ts CHANGED
@@ -9,6 +9,13 @@ export interface FullPageOptions {
9
9
  cssUrl?: string;
10
10
  cssUrls?: string[];
11
11
  clientScriptUrl?: string;
12
+ /**
13
+ * SRI digest for `clientScriptUrl` (`sha384-<base64>`). A production build
14
+ * passes the digest of the exact bundle it emitted, so the tag cannot execute
15
+ * anything but the built bytes. Omitted in dev, where the URL is rewritten on
16
+ * every edit and a digest would block it.
17
+ */
18
+ clientScriptIntegrity?: string;
12
19
  pageHead?: string;
13
20
  security?: import('@vesk/types').VeskSecurity;
14
21
  __vesk?: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,YAAY,EACV,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,OAAO,EACP,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ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,MAAM,aAAa,shBAahB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/compiler",
3
- "version": "0.2.50-canary.2",
3
+ "version": "0.2.50-canary.4",
4
4
  "type": "module",
5
5
  "description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@sveltejs/acorn-typescript": "^1.0.0",
23
- "@vesk/types": "^0.2.50-canary.2",
23
+ "@vesk/types": "^0.2.50-canary.4",
24
24
  "acorn": "^8.15.0",
25
25
  "esrap": "^2.3.0",
26
26
  "is-reference": "^3.0.0",