@embeddable.com/sdk-core 3.4.1 → 3.5.0

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.
@@ -32,6 +32,7 @@ declare const _default: ({ plugins, pushBaseUrl, audienceUrl, authDomain, authCl
32
32
  stencilBuild: string;
33
33
  archiveFile: string;
34
34
  errorFallbackComponent: string | undefined;
35
+ bundleHash: undefined;
35
36
  };
36
37
  outputOptions: {
37
38
  typesEntryPointFilename: string;
package/lib/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as fs$1 from 'node:fs/promises';
2
- import fs__default, { readdir, lstat } from 'node:fs/promises';
2
+ import { readdir, lstat } from 'node:fs/promises';
3
3
  import * as path$1 from 'node:path';
4
4
  import path__default, { join } from 'node:path';
5
5
  import * as vite from 'vite';
@@ -12,14 +12,14 @@ import { loadConfig, createCompiler } from '@stencil/core/compiler';
12
12
  import * as os$1 from 'node:os';
13
13
  import * as YAML from 'yaml';
14
14
  import * as url$2 from 'node:url';
15
- import * as path$2 from 'path';
16
- import path__default$1, { basename } from 'path';
17
15
  import require$$4$1 from 'util';
18
16
  import require$$1 from 'os';
19
17
  import require$$3 from 'http';
20
18
  import require$$4 from 'https';
21
19
  import require$$0$1 from 'url';
22
20
  import require$$2$1, { createReadStream } from 'fs';
21
+ import * as path$2 from 'path';
22
+ import path__default$1, { basename } from 'path';
23
23
  import axios from 'axios';
24
24
  import * as archiver from 'archiver';
25
25
  import { WebSocketServer } from 'ws';
@@ -431,6 +431,8 @@ async function createComponentDir(dir) {
431
431
  const sorcery = require("sorcery");
432
432
  const STYLE_IMPORTS_TOKEN = "{{STYLES_IMPORT}}";
433
433
  const RENDER_IMPORT_TOKEN = "{{RENDER_IMPORT}}";
434
+ // stencil doesn't support dynamic component tag name, so we need to replace it manually
435
+ const COMPONENT_TAG_TOKEN = "replace-this-with-component-name";
434
436
  var generate = async (ctx, pluginName) => {
435
437
  await injectCSS(ctx, pluginName);
436
438
  await injectBundleRender(ctx, pluginName);
@@ -449,9 +451,30 @@ async function injectCSS(ctx, pluginName) {
449
451
  }
450
452
  async function injectBundleRender(ctx, pluginName) {
451
453
  const importStr = `import render from '../${ctx[pluginName].outputOptions.buildName}/${ctx[pluginName].outputOptions.fileName}';`;
452
- const content = await fs$1.readFile(path$1.resolve(ctx.core.templatesDir, "component.tsx.template"), "utf8");
454
+ let content = await fs$1.readFile(path$1.resolve(ctx.core.templatesDir, "component.tsx.template"), "utf8");
455
+ if (!!ctx.dev) {
456
+ content = content.replace(COMPONENT_TAG_TOKEN, "embeddable-component");
457
+ }
453
458
  await fs$1.writeFile(path$1.resolve(ctx.client.componentDir, "component.tsx"), content.replace(RENDER_IMPORT_TOKEN, importStr));
454
459
  }
460
+ async function addComponentTagName(filePath, bundleHash) {
461
+ // find entry file with a name *.entry.js
462
+ const entryFiles = await findFiles(path$1.dirname(filePath), /.*\.entry\.js/);
463
+ if (!entryFiles.length) {
464
+ return;
465
+ }
466
+ const entryFileName = entryFiles[0];
467
+ const [entryFileContent, fileContent] = await Promise.all([
468
+ fs$1.readFile(entryFileName[1], "utf8"),
469
+ fs$1.readFile(filePath, "utf8"),
470
+ ]);
471
+ const newFileContent = fileContent.replace(COMPONENT_TAG_TOKEN, `embeddable-component-${bundleHash}`);
472
+ const newEntryFileContent = entryFileContent.replace(COMPONENT_TAG_TOKEN.replaceAll("-", "_"), `embeddable_component_${bundleHash}`);
473
+ await Promise.all([
474
+ fs$1.writeFile(filePath, newFileContent),
475
+ fs$1.writeFile(entryFileName[1], newEntryFileContent),
476
+ ]);
477
+ }
455
478
  async function runStencil(ctx) {
456
479
  var _a, _b, _c;
457
480
  const logger = ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.logger) || createNodeLogger({ process });
@@ -485,6 +508,8 @@ async function runStencil(ctx) {
485
508
  const entryFileContent = await fs$1.readFile(entryFilePath, "utf8");
486
509
  const fileHash = getContentHash(entryFileContent);
487
510
  fileName = `embeddable-wrapper.esm-${fileHash}.js`;
511
+ ctx.client.bundleHash = fileHash;
512
+ await addComponentTagName(entryFilePath, ctx.client.bundleHash);
488
513
  }
489
514
  await fs$1.rename(entryFilePath, path$1.resolve(ctx.client.stencilBuild, fileName));
490
515
  await compiler.destroy();
@@ -643,6 +668,7 @@ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFil
643
668
  metadata: {
644
669
  nodeVersion: process.version,
645
670
  platform: process.platform,
671
+ bundleHash: ctx.client.bundleHash,
646
672
  sdkVersions,
647
673
  packageManager,
648
674
  packageManagerVersion,
@@ -20327,29 +20353,31 @@ const reportErrorToRollbar = async (error) => {
20327
20353
 
20328
20354
  const userData = await getUserData();
20329
20355
 
20356
+ const sdkPackageVersion = await getSdkPackageVersionInfo(config);
20357
+
20330
20358
  rollbar.configure({
20331
20359
  payload: {
20332
- person: {
20333
- id: userData.globalUserId
20334
- }
20335
- }
20360
+ person: {
20361
+ id: userData.globalUserId,
20362
+ },
20363
+ },
20336
20364
  });
20337
20365
 
20338
- rollbar.error(error, {
20366
+ return rollbar.error(error, {
20339
20367
  custom: {
20340
- code_version: getSdkPackageVersionInfo(config)
20368
+ code_version: sdkPackageVersion,
20341
20369
  },
20342
20370
  });
20343
20371
  };
20344
20372
 
20345
- const getSdkPackageVersionInfo = (config) => {
20373
+ const getSdkPackageVersionInfo = async (config) => {
20346
20374
  try {
20347
- const packageJsonFilePath = path$2.resolve(
20375
+ const packageJsonFilePath = path$1.resolve(
20348
20376
  config.client.rootDir,
20349
20377
  "package.json",
20350
20378
  );
20351
20379
 
20352
- const packageJson = require(packageJsonFilePath);
20380
+ const packageJson = await import(packageJsonFilePath);
20353
20381
  const devDependencies = packageJson.devDependencies;
20354
20382
  const dependencies = packageJson.dependencies;
20355
20383
 
@@ -20358,10 +20386,26 @@ const getSdkPackageVersionInfo = (config) => {
20358
20386
  };
20359
20387
 
20360
20388
  const packageVersionInfo = {
20361
- core: getDependencyVersion("@embeddable.com/core", dependencies, devDependencies),
20362
- sdk_core: getDependencyVersion("@embeddable.com/sdk-core", dependencies, devDependencies),
20363
- react: getDependencyVersion("@embeddable.com/react", dependencies, devDependencies),
20364
- sdk_react: getDependencyVersion("@embeddable.com/sdk-react", dependencies, devDependencies),
20389
+ core: getDependencyVersion(
20390
+ "@embeddable.com/core",
20391
+ dependencies,
20392
+ devDependencies,
20393
+ ),
20394
+ sdk_core: getDependencyVersion(
20395
+ "@embeddable.com/sdk-core",
20396
+ dependencies,
20397
+ devDependencies,
20398
+ ),
20399
+ react: getDependencyVersion(
20400
+ "@embeddable.com/react",
20401
+ dependencies,
20402
+ devDependencies,
20403
+ ),
20404
+ sdk_react: getDependencyVersion(
20405
+ "@embeddable.com/sdk-react",
20406
+ dependencies,
20407
+ devDependencies,
20408
+ ),
20365
20409
  };
20366
20410
 
20367
20411
  return JSON.stringify(packageVersionInfo);
@@ -20373,9 +20417,9 @@ const getSdkPackageVersionInfo = (config) => {
20373
20417
 
20374
20418
  async function getUserData() {
20375
20419
  try {
20376
- const token = await fs__default
20377
- .readFile(CREDENTIALS_FILE)
20378
- .then((data) => JSON.parse(data.toString()));
20420
+ const token = await fs$1
20421
+ .readFile(CREDENTIALS_FILE)
20422
+ .then((data) => JSON.parse(data.toString()));
20379
20423
 
20380
20424
  const decodedToken = jwtDecode(token.access_token);
20381
20425
 
@@ -20839,7 +20883,7 @@ const sendDataModelsAndSecurityContextsChanges = async (ctx) => {
20839
20883
  if (isValid) {
20840
20884
  const token = await getToken();
20841
20885
  const sending = ora("Synchronising data models and/or security contexts...").start();
20842
- const filesList = await findFiles(ctx.client.srcDir, YAML_OR_JS_FILES);
20886
+ const filesList = await findFiles(ctx.client.modelsSrc || ctx.client.srcDir, YAML_OR_JS_FILES);
20843
20887
  await archive(ctx, filesList, false);
20844
20888
  await sendBuild(ctx, { workspaceId: previewWorkspace, token });
20845
20889
  sending.succeed(`Data models and/or security context synchronized`);
@@ -20924,6 +20968,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
20924
20968
  errorFallbackComponent: errorFallbackComponent
20925
20969
  ? path$1.resolve(clientRoot, errorFallbackComponent)
20926
20970
  : undefined,
20971
+ bundleHash: undefined, // This will be set by the build process
20927
20972
  },
20928
20973
  outputOptions: {
20929
20974
  typesEntryPointFilename: "embeddable-types-entry-point.js",
@@ -20940,7 +20985,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
20940
20985
  };
20941
20986
 
20942
20987
  var name = "@embeddable.com/sdk-core";
20943
- var version = "3.4.1";
20988
+ var version = "3.5.0";
20944
20989
  var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
20945
20990
  var keywords = [
20946
20991
  "embeddable",