@absolutejs/absolute 0.19.0-beta.283 → 0.19.0-beta.284

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/vue/index.js CHANGED
@@ -29813,226 +29813,6 @@ var init_svelteServerModule = __esm(() => {
29813
29813
  });
29814
29814
  });
29815
29815
 
29816
- // src/build/resolvePackageImport.ts
29817
- import { resolve as resolve4, join as join3 } from "path";
29818
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
29819
- var resolveExportPath = (entry, conditions) => {
29820
- if (typeof entry === "string")
29821
- return entry;
29822
- if (!entry || typeof entry !== "object")
29823
- return null;
29824
- for (const condition of conditions) {
29825
- const target = Reflect.get(entry, condition);
29826
- if (typeof target === "string") {
29827
- return target;
29828
- }
29829
- }
29830
- return null;
29831
- }, resolvePackageImport = (specifier, conditions = ["import"]) => {
29832
- if (specifier.startsWith(".") || specifier.startsWith("/"))
29833
- return null;
29834
- const parts = specifier.split("/");
29835
- const isScoped = specifier.startsWith("@");
29836
- const packageName = isScoped ? `${parts[0]}/${parts[1]}` : parts[0];
29837
- const subpath = isScoped ? parts.slice(2).join("/") : parts.slice(1).join("/");
29838
- const exportKey = subpath ? `./${subpath}` : ".";
29839
- const packageDir = resolve4(process.cwd(), "node_modules", packageName ?? "");
29840
- const packageJsonPath = join3(packageDir, "package.json");
29841
- if (!existsSync3(packageJsonPath))
29842
- return null;
29843
- try {
29844
- const packageJson = JSON.parse(readFileSync2(packageJsonPath, "utf-8"));
29845
- const { exports } = packageJson;
29846
- if (!exports)
29847
- return null;
29848
- const entry = exports[exportKey];
29849
- if (!entry)
29850
- return null;
29851
- const importPath = resolveExportPath(entry, conditions);
29852
- if (!importPath)
29853
- return null;
29854
- const resolved = resolve4(packageDir, importPath);
29855
- return existsSync3(resolved) ? resolved : null;
29856
- } catch {
29857
- return null;
29858
- }
29859
- };
29860
- var init_resolvePackageImport = () => {};
29861
-
29862
- // src/core/vueServerModule.ts
29863
- import { mkdir as mkdir2 } from "fs/promises";
29864
- import { dirname as dirname3, extname as extname2, join as join4, relative as relative2, resolve as resolve5 } from "path";
29865
- var {Transpiler } = globalThis.Bun;
29866
- var serverCacheRoot2, compiledModuleCache2, transpiler2, toJs = (filePath) => {
29867
- if (filePath.endsWith(".vue"))
29868
- return filePath.replace(/\.vue$/, ".js");
29869
- if (filePath.endsWith(".ts"))
29870
- return filePath.replace(/\.ts$/, ".js");
29871
- return `${filePath}.js`;
29872
- }, stripExports = (code) => code.replace(/export\s+default/, "const script =").replace(/^export\s+/gm, ""), mergeVueImports = (code) => {
29873
- const lines = code.split(`
29874
- `);
29875
- const specifierSet = new Set;
29876
- const vueImportRegex = /^import\s+{([^}]+)}\s+from\s+['"]vue['"];?$/;
29877
- lines.forEach((line) => {
29878
- const match = line.match(vueImportRegex);
29879
- if (!match?.[1])
29880
- return;
29881
- match[1].split(",").forEach((specifier) => specifierSet.add(specifier.trim()));
29882
- });
29883
- const nonVueLines = lines.filter((line) => !vueImportRegex.test(line));
29884
- if (specifierSet.size === 0) {
29885
- return nonVueLines.join(`
29886
- `);
29887
- }
29888
- return [
29889
- `import { ${[...specifierSet].join(", ")} } from "vue";`,
29890
- ...nonVueLines
29891
- ].join(`
29892
- `);
29893
- }, ensureRelativeImportPath2 = (from, to) => {
29894
- const importPath = relative2(dirname3(from), to).replace(/\\/g, "/");
29895
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
29896
- }, resolveRelativeModule2 = async (spec, from) => {
29897
- if (!spec.startsWith(".")) {
29898
- return null;
29899
- }
29900
- const basePath = resolve5(dirname3(from), spec);
29901
- const candidates = [
29902
- basePath,
29903
- `${basePath}.ts`,
29904
- `${basePath}.js`,
29905
- `${basePath}.mjs`,
29906
- `${basePath}.cjs`,
29907
- `${basePath}.json`,
29908
- join4(basePath, "index.ts"),
29909
- join4(basePath, "index.js"),
29910
- join4(basePath, "index.mjs"),
29911
- join4(basePath, "index.cjs"),
29912
- join4(basePath, "index.json")
29913
- ];
29914
- for (const candidate of candidates) {
29915
- if (await Bun.file(candidate).exists() === true) {
29916
- return candidate;
29917
- }
29918
- }
29919
- return null;
29920
- }, getCachedModulePath2 = (sourcePath) => {
29921
- const relativeSourcePath = relative2(process.cwd(), sourcePath).replace(/\\/g, "/");
29922
- const normalizedSourcePath = relativeSourcePath.startsWith("..") ? sourcePath.replace(/[:\\/]/g, "_") : relativeSourcePath;
29923
- return join4(serverCacheRoot2, `${normalizedSourcePath}.server.js`);
29924
- }, resolveVueImport = async (spec, from) => {
29925
- if (spec.startsWith("/")) {
29926
- return spec;
29927
- }
29928
- if (spec.startsWith(".")) {
29929
- const explicitPath = resolve5(dirname3(from), spec);
29930
- if (extname2(explicitPath) === ".vue") {
29931
- return explicitPath;
29932
- }
29933
- const candidate = `${explicitPath}.vue`;
29934
- if (await Bun.file(candidate).exists() === true) {
29935
- return candidate;
29936
- }
29937
- return null;
29938
- }
29939
- const resolvedPath = resolvePackageImport(spec);
29940
- if (resolvedPath?.endsWith(".vue")) {
29941
- return resolvedPath;
29942
- }
29943
- return null;
29944
- }, writeIfChanged2 = async (path, content) => {
29945
- const targetFile = Bun.file(path);
29946
- if (await targetFile.exists() === true) {
29947
- const currentContent = await targetFile.text();
29948
- if (currentContent === content) {
29949
- return;
29950
- }
29951
- }
29952
- await Bun.write(path, content);
29953
- }, compileVueServerModule = async (sourcePath) => {
29954
- const cachedModulePath = compiledModuleCache2.get(sourcePath);
29955
- if (cachedModulePath) {
29956
- return cachedModulePath;
29957
- }
29958
- const compiler = await import("@vue/compiler-sfc");
29959
- const source = await Bun.file(sourcePath).text();
29960
- const { descriptor } = compiler.parse(source, {
29961
- filename: sourcePath
29962
- });
29963
- const componentId = Bun.hash(sourcePath).toString(36);
29964
- const scriptSource = descriptor.scriptSetup?.content ?? descriptor.script?.content ?? "";
29965
- const importSpecs = Array.from(scriptSource.matchAll(/import\s+[\s\S]+?['"]([^'"]+)['"]/g)).map((match) => match[1]).filter((value) => value !== undefined);
29966
- const resolvedVueImports = await Promise.all(importSpecs.map((spec) => resolveVueImport(spec, sourcePath)));
29967
- const resolvedModuleImports = await Promise.all(importSpecs.map((spec) => resolveRelativeModule2(spec, sourcePath)));
29968
- const childModulePaths = new Map;
29969
- const rewrittenModulePaths = new Map;
29970
- for (let index = 0;index < importSpecs.length; index += 1) {
29971
- const spec = importSpecs[index];
29972
- const resolvedChild = resolvedVueImports[index];
29973
- if (!spec || !resolvedChild)
29974
- continue;
29975
- const compiledChildPath = await compileVueServerModule(resolvedChild);
29976
- childModulePaths.set(spec, compiledChildPath);
29977
- }
29978
- for (let index = 0;index < importSpecs.length; index += 1) {
29979
- const spec = importSpecs[index];
29980
- const resolvedModuleImport = resolvedModuleImports[index];
29981
- if (!spec || !resolvedModuleImport)
29982
- continue;
29983
- if (resolvedVueImports[index])
29984
- continue;
29985
- rewrittenModulePaths.set(spec, ensureRelativeImportPath2(getCachedModulePath2(sourcePath), resolvedModuleImport));
29986
- }
29987
- const hasScript = descriptor.script || descriptor.scriptSetup;
29988
- const compiledScript = hasScript ? compiler.compileScript(descriptor, {
29989
- id: componentId,
29990
- inlineTemplate: false
29991
- }) : { bindings: {}, content: "export default {};" };
29992
- const strippedScript = stripExports(compiledScript.content);
29993
- const transpiledScript = transpiler2.transformSync(strippedScript).replace(/(['"])(\.{1,2}\/[^'"]+)(['"])/g, (_, quoteStart, relativeImport, quoteEnd) => `${quoteStart}${toJs(relativeImport)}${quoteEnd}`);
29994
- const ssrRenderCode = compiler.compileTemplate({
29995
- compilerOptions: {
29996
- bindingMetadata: compiledScript.bindings,
29997
- prefixIdentifiers: true
29998
- },
29999
- filename: sourcePath,
30000
- id: componentId,
30001
- scoped: descriptor.styles.some((styleBlock) => styleBlock.scoped),
30002
- source: descriptor.template?.content ?? "",
30003
- ssr: true,
30004
- ssrCssVars: descriptor.cssVars
30005
- }).code.replace(/(['"])(\.{1,2}\/[^'"]+)(['"])/g, (_, quoteStart, relativeImport, quoteEnd) => `${quoteStart}${toJs(relativeImport)}${quoteEnd}`);
30006
- let serverCode = mergeVueImports([
30007
- transpiledScript,
30008
- ssrRenderCode,
30009
- "script.ssrRender = ssrRender;",
30010
- descriptor.styles.some((styleBlock) => styleBlock.scoped) ? `script.__scopeId = "data-v-${componentId}";` : "",
30011
- "export default script;"
30012
- ].filter(Boolean).join(`
30013
- `));
30014
- for (const [spec, compiledChildPath] of childModulePaths) {
30015
- serverCode = serverCode.replaceAll(spec, ensureRelativeImportPath2(getCachedModulePath2(sourcePath), compiledChildPath));
30016
- }
30017
- for (const [spec, resolvedModuleImport] of rewrittenModulePaths) {
30018
- serverCode = serverCode.replaceAll(spec, resolvedModuleImport);
30019
- }
30020
- const compiledModulePath = getCachedModulePath2(sourcePath);
30021
- await mkdir2(dirname3(compiledModulePath), { recursive: true });
30022
- await writeIfChanged2(compiledModulePath, serverCode);
30023
- compiledModuleCache2.set(sourcePath, compiledModulePath);
30024
- return compiledModulePath;
30025
- };
30026
- var init_vueServerModule = __esm(() => {
30027
- init_resolvePackageImport();
30028
- serverCacheRoot2 = join4(process.cwd(), ".absolutejs", "islands", "vue");
30029
- compiledModuleCache2 = new Map;
30030
- transpiler2 = new Transpiler({
30031
- loader: "ts",
30032
- target: "browser"
30033
- });
30034
- });
30035
-
30036
29816
  // src/utils/ssrErrorPage.ts
30037
29817
  var ssrErrorPage = (framework, error) => {
30038
29818
  const frameworkColors = {
@@ -30278,7 +30058,24 @@ var init_resolveConvention = __esm(() => {
30278
30058
  });
30279
30059
 
30280
30060
  // src/vue/pageHandler.ts
30281
- var ssrDirty = false, buildDirtyResponse = (headTag, indexPath, maybeProps) => {
30061
+ import { readdir } from "fs/promises";
30062
+ import { basename as basename2, dirname as dirname3 } from "path";
30063
+ var ssrDirty = false, resolveCurrentGeneratedVueModulePath = async (pagePath) => {
30064
+ const pageDirectory = dirname3(pagePath);
30065
+ const expectedPrefix = `${basename2(pagePath, ".js").split(".")[0]}.`;
30066
+ try {
30067
+ const pageEntries = await readdir(pageDirectory, {
30068
+ withFileTypes: true
30069
+ });
30070
+ const matchingEntry = pageEntries.find((entry) => entry.isFile() && entry.name.endsWith(".js") && (entry.name === `${expectedPrefix.slice(0, -1)}.js` || entry.name.startsWith(expectedPrefix)));
30071
+ if (!matchingEntry) {
30072
+ return pagePath;
30073
+ }
30074
+ return `${pageDirectory}/${matchingEntry.name}`;
30075
+ } catch {
30076
+ return pagePath;
30077
+ }
30078
+ }, buildDirtyResponse = (headTag, indexPath, maybeProps) => {
30282
30079
  const propsScript = `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps ?? {})};`;
30283
30080
  const dirtyFlag = "window.__SSR_DIRTY__=true;";
30284
30081
  const html = `<!DOCTYPE html><html>${headTag}<body><div id="root"></div>` + `<script>${propsScript}${dirtyFlag}</script>` + `<script type="module" src="${indexPath}"></script>` + `</body></html>`;
@@ -30296,20 +30093,9 @@ var ssrDirty = false, buildDirtyResponse = (headTag, indexPath, maybeProps) => {
30296
30093
  if (typeof passedPageComponent === "function" || typeof passedPageComponent === "object" && passedPageComponent !== null) {
30297
30094
  return _PageComponent;
30298
30095
  }
30299
- const loadCompiledSourcePath = async (sourcePath) => {
30300
- const compiledModulePath = await compileVueServerModule(sourcePath);
30301
- const loadedModule = await import(compiledModulePath);
30302
- return loadedModule.default ?? loadedModule;
30303
- };
30304
- if (typeof passedPageComponent === "string" && passedPageComponent.endsWith(".vue")) {
30305
- return loadCompiledSourcePath(passedPageComponent);
30306
- }
30307
- const importedPageModule = await import(pagePath);
30308
- const importedPageComponent = importedPageModule.default ?? importedPageModule;
30309
- if (typeof importedPageComponent === "string" && importedPageComponent.endsWith(".vue")) {
30310
- return loadCompiledSourcePath(importedPageComponent);
30311
- }
30312
- return importedPageComponent;
30096
+ const generatedPagePath = await resolveCurrentGeneratedVueModulePath(pagePath);
30097
+ const importedPageModule = await import(generatedPagePath);
30098
+ return importedPageModule.default ?? importedPageModule;
30313
30099
  };
30314
30100
  const ImportedPageComponent = await resolvePageComponent();
30315
30101
  const { createSSRApp: createSSRApp2, h: h3 } = await import("vue");
@@ -30348,7 +30134,6 @@ var ssrDirty = false, buildDirtyResponse = (headTag, indexPath, maybeProps) => {
30348
30134
  ssrDirty = true;
30349
30135
  };
30350
30136
  var init_pageHandler = __esm(() => {
30351
- init_vueServerModule();
30352
30137
  init_resolveConvention();
30353
30138
  });
30354
30139
 
@@ -30819,5 +30604,5 @@ export {
30819
30604
  createIsland
30820
30605
  };
30821
30606
 
30822
- //# debugId=665B8F9FE5E2159464756E2164756E21
30607
+ //# debugId=12FE515274BEEB8664756E2164756E21
30823
30608
  //# sourceMappingURL=index.js.map