@wix/astro 1.0.10 → 1.0.12

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/build/index.js CHANGED
@@ -12430,6 +12430,26 @@ var SRC_DIR = "src";
12430
12430
  var GIT_IGNORED_DIR = ".wix";
12431
12431
  var EXTENSIONS_DIR = join(SRC_DIR, "extensions");
12432
12432
 
12433
+ // src/plugins/patchAstroInlineScripts.ts
12434
+ init_esm_shims();
12435
+ function patchAstroInlineScripts() {
12436
+ return {
12437
+ name: "patch-astro-inline-scripts",
12438
+ transform(code, id) {
12439
+ const [_filename, rawQuery] = id.split(`?`, 2);
12440
+ const query = Object.fromEntries(new URLSearchParams(rawQuery).entries());
12441
+ if (query.astro == null || query.type !== "script" || query["lang.ts"] == null || code === "") {
12442
+ return null;
12443
+ }
12444
+ return defaultOutdent`
12445
+ import 'astro:scripts/page.js';
12446
+
12447
+ ${code}
12448
+ `;
12449
+ }
12450
+ };
12451
+ }
12452
+
12433
12453
  // src/plugins/patchGlobal.ts
12434
12454
  init_esm_shims();
12435
12455
  var define = { global: "window" };
@@ -17752,10 +17772,13 @@ function loadEnvVars(rootDir, logger) {
17752
17772
  async function createProjectModel(logger) {
17753
17773
  const rootDir = cwd();
17754
17774
  const { appId, env: env2 } = loadEnvVars(rootDir, logger);
17755
- const componentsPaths = await globby(join2(EXTENSIONS_DIR, "*"), {
17756
- cwd: rootDir,
17757
- onlyDirectories: true
17758
- });
17775
+ const componentsPaths = await globby(
17776
+ pathToGlobby(join2(EXTENSIONS_DIR, "*")),
17777
+ {
17778
+ cwd: rootDir,
17779
+ onlyDirectories: true
17780
+ }
17781
+ );
17759
17782
  const components = [];
17760
17783
  const unknownComponents = [];
17761
17784
  for (const componentPath of componentsPaths) {
@@ -17781,6 +17804,9 @@ async function createProjectModel(logger) {
17781
17804
  unknownComponents
17782
17805
  };
17783
17806
  }
17807
+ function pathToGlobby(path2) {
17808
+ return path2.replaceAll("\\", "/");
17809
+ }
17784
17810
  function createComponent(manifest, directory) {
17785
17811
  switch (manifest.compType) {
17786
17812
  case "BACK_OFFICE_EXTENSION_MENU_ITEM":
@@ -18244,7 +18270,7 @@ var createIntegration = () => {
18244
18270
  model ??= await createProjectModel(logger);
18245
18271
  const appManifest = generateAppManifest(model);
18246
18272
  const outDir = fileURLToPath3(_config.outDir);
18247
- const rootDir = fileURLToPath3(_config.outDir);
18273
+ const rootDir = fileURLToPath3(_config.root);
18248
18274
  const appManifestPath = join6(outDir, "_wix/app-manifest.json");
18249
18275
  await writeJson(appManifestPath, appManifest, { spaces: 2 });
18250
18276
  await writeJson(
@@ -18273,56 +18299,15 @@ var createIntegration = () => {
18273
18299
  injectScript(
18274
18300
  "before-hydration",
18275
18301
  defaultOutdent`
18276
- import { WIX_CLIENT_ID } from 'astro:env/client';
18277
- import { createClient } from '@wix/sdk';
18278
- import { SiteSessionAuth } from '@wix/sdk/auth/site-session';
18279
- import { dashboard } from '@wix/dashboard';
18280
-
18281
- const isBackofficeExtension = location.pathname.startsWith(
18282
- '/_wix/extensions/backoffice'
18283
- );
18284
-
18285
- function getCookieAsJson(name) {
18286
- const cookies = document.cookie.split('; ');
18287
- const cookie = cookies.find((row) => row.startsWith(\`\${name}=\`));
18288
-
18289
- if (!cookie) {
18290
- return null;
18291
- }
18292
-
18293
- try {
18294
- const jsonString = decodeURIComponent(cookie.split('=')[1]);
18295
- return JSON.parse(jsonString);
18296
- } catch (error) {
18297
- console.error('Error parsing cookie JSON:', error);
18298
- return null;
18299
- }
18300
- }
18301
-
18302
- function getSessionClient() {
18303
- return createClient({
18304
- auth: SiteSessionAuth({
18305
- clientId: WIX_CLIENT_ID,
18306
- tokens: getCookieAsJson("wixSession")?.tokens,
18307
- }),
18308
- });
18309
- }
18310
-
18311
- function getBackofficeClient() {
18312
- return createClient({
18313
- host: dashboard.host(),
18314
- auth: dashboard.auth(),
18315
- modules: {
18316
- dashboard,
18317
- },
18318
- });
18319
- }
18320
-
18321
- const client = isBackofficeExtension
18322
- ? getBackofficeClient()
18323
- : getSessionClient();
18324
-
18325
- client.enableContext('global');
18302
+ import { setup } from '@wix/astro/context/before-hydration';
18303
+ setup();
18304
+ `
18305
+ );
18306
+ injectScript(
18307
+ "page",
18308
+ defaultOutdent`
18309
+ import { setup } from '@wix/astro/context/page';
18310
+ setup();
18326
18311
  `
18327
18312
  );
18328
18313
  addMiddleware({
@@ -18358,7 +18343,7 @@ var createIntegration = () => {
18358
18343
  service: passthroughImageService()
18359
18344
  },
18360
18345
  vite: {
18361
- plugins: [patchGlobal()]
18346
+ plugins: [patchGlobal(), patchAstroInlineScripts()]
18362
18347
  }
18363
18348
  });
18364
18349
  const webhookCodegenDir = join6(codegenDir, "extensions/webhooks");