@embeddable.com/sdk-core 3.2.2 → 3.3.1

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/lib/utils.d.ts CHANGED
@@ -19,3 +19,4 @@ export declare const removeBuildSuccessFlag: () => Promise<void>;
19
19
  * Check if the build was successful
20
20
  */
21
21
  export declare const checkBuildSuccess: () => Promise<boolean>;
22
+ export declare const getPackageVersion: (packageName: string) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-core",
3
- "version": "3.2.2",
3
+ "version": "3.3.1",
4
4
  "description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -41,7 +41,7 @@
41
41
  "@swc-node/register": "^1.9.0",
42
42
  "archiver": "^5.3.1",
43
43
  "axios": "^1.7.2",
44
- "chokidar": "^3.5.3",
44
+ "chokidar": "^3.6.0",
45
45
  "finalhandler": "^1.2.0",
46
46
  "formdata-node": "^6.0.3",
47
47
  "minimist": "^1.2.8",
package/src/buildTypes.ts CHANGED
@@ -32,14 +32,17 @@ async function generate(ctx: any) {
32
32
  .concat(optionsFiles)
33
33
  .map(
34
34
  ([_fileName, filePath]) =>
35
- `import './${path
35
+ `import '../${path
36
36
  .relative(ctx.client.rootDir, filePath)
37
37
  .replaceAll("\\", "/")}';`,
38
38
  )
39
39
  .join("\n");
40
40
 
41
41
  await fs.writeFile(
42
- path.resolve(ctx.client.rootDir, ctx.outputOptions.typesEntryPointFilename),
42
+ path.resolve(
43
+ ctx.client.buildDir,
44
+ ctx.outputOptions.typesEntryPointFilename,
45
+ ),
43
46
  typeImports,
44
47
  );
45
48
  }
@@ -51,7 +54,7 @@ async function build(ctx: any) {
51
54
  emptyOutDir: false,
52
55
  lib: {
53
56
  entry: path.resolve(
54
- ctx.client.rootDir,
57
+ ctx.client.buildDir,
55
58
  ctx.outputOptions.typesEntryPointFilename,
56
59
  ),
57
60
  formats: ["es"],
@@ -71,6 +74,6 @@ async function build(ctx: any) {
71
74
 
72
75
  async function cleanup(ctx: any) {
73
76
  await fs.rm(
74
- path.resolve(ctx.client.rootDir, "embeddable-types-entry-point.js"),
77
+ path.resolve(ctx.client.buildDir, "embeddable-types-entry-point.js"),
75
78
  );
76
79
  }
package/src/cleanup.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { findFiles } from "@embeddable.com/sdk-utils";
2
2
  import * as fs from "node:fs/promises";
3
3
  import * as path from "node:path";
4
+ import { getPackageVersion } from "./utils";
4
5
 
5
6
  export default async (ctx: any) => {
6
7
  await extractBuild(ctx);
@@ -10,6 +11,75 @@ export default async (ctx: any) => {
10
11
  await moveBuildTOBuildDir(ctx);
11
12
  };
12
13
 
14
+ type ManifestArgs = {
15
+ ctx: any;
16
+ typesFileName: string;
17
+ metaFileName: string;
18
+ editorsMetaFileName: string;
19
+ stencilWrapperFileName: string;
20
+ };
21
+
22
+ async function createManifest({
23
+ ctx,
24
+ typesFileName,
25
+ metaFileName,
26
+ editorsMetaFileName,
27
+ stencilWrapperFileName,
28
+ }: ManifestArgs) {
29
+ const packageNames = [
30
+ "@embeddable.com/core",
31
+ "@embeddable.com/react",
32
+ "@embeddable.com/sdk-core",
33
+ "@embeddable.com/sdk-react",
34
+ "@embeddable.com/sdk-utils",
35
+ ];
36
+
37
+ const sdkVersions = packageNames.reduce<Record<string, string>>(
38
+ (acc, packageName) => {
39
+ const version = getPackageVersion(packageName);
40
+ if (version) {
41
+ acc[packageName] = version;
42
+ }
43
+ return acc;
44
+ },
45
+ {},
46
+ );
47
+ // identify user's package manager and its version
48
+ let packageManager = "npm";
49
+ if (process.env.npm_config_user_agent?.includes("yarn")) {
50
+ packageManager = "yarn";
51
+ }
52
+ if (process.env.npm_config_user_agent?.includes("pnpm")) {
53
+ packageManager = "pnpm";
54
+ }
55
+
56
+ const packageManagerVersion =
57
+ process.env.npm_config_user_agent?.match(/(\d+\.\d+\.\d+)/)?.[0] ||
58
+ "unknown";
59
+
60
+ // write manifest file with files with hash
61
+ const manifest = {
62
+ entryFiles: {
63
+ "embeddable-types.js": typesFileName,
64
+ "embeddable-components-meta.js": metaFileName,
65
+ "embeddable-editors-meta.js": editorsMetaFileName,
66
+ "embeddable-wrapper.esm.js": stencilWrapperFileName,
67
+ },
68
+ metadata: {
69
+ nodeVersion: process.version,
70
+ platform: process.platform,
71
+ sdkVersions,
72
+ packageManager,
73
+ packageManagerVersion,
74
+ },
75
+ };
76
+
77
+ await fs.writeFile(
78
+ path.join(ctx.client.tmpDir, "embeddable-manifest.json"),
79
+ JSON.stringify(manifest),
80
+ );
81
+ }
82
+
13
83
  async function extractBuild(ctx: any) {
14
84
  const [[, stencilWrapperFilePath]] = await findFiles(
15
85
  ctx.client.stencilBuild,
@@ -47,20 +117,13 @@ async function extractBuild(ctx: any) {
47
117
  path.join(ctx.client.tmpDir, editorsMetaFileName),
48
118
  );
49
119
 
50
- // write manifest file with files with hash
51
- const manifest = {
52
- entryFiles: {
53
- "embeddable-types.js": typesFileName,
54
- "embeddable-components-meta.js": metaFileName,
55
- "embeddable-editors-meta.js": editorsMetaFileName,
56
- "embeddable-wrapper.esm.js": stencilWrapperFileName,
57
- },
58
- };
59
-
60
- await fs.writeFile(
61
- path.join(ctx.client.tmpDir, "embeddable-manifest.json"),
62
- JSON.stringify(manifest),
63
- );
120
+ await createManifest({
121
+ ctx,
122
+ typesFileName,
123
+ metaFileName,
124
+ editorsMetaFileName,
125
+ stencilWrapperFileName,
126
+ });
64
127
  }
65
128
 
66
129
  async function removeObsoleteDir(dir: string) {
package/src/dev.ts CHANGED
@@ -34,13 +34,29 @@ let ora: any;
34
34
  let previewWorkspace: string;
35
35
 
36
36
  const SERVER_PORT = 8926;
37
+ const BUILD_DEV_DIR = ".embeddable-dev-build";
37
38
 
38
39
  const buildWebComponent = async (config: any) => {
39
40
  await generate(config, "sdk-react");
40
41
  };
41
42
 
43
+ const addToGitingore = async () => {
44
+ try {
45
+ const fs = require("fs").promises;
46
+ const gitignorePath = path.resolve(process.cwd(), ".gitignore");
47
+ const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
48
+
49
+ if (!gitignoreContent.includes(BUILD_DEV_DIR)) {
50
+ await fs.appendFile(gitignorePath, `\n${BUILD_DEV_DIR}\n`);
51
+ }
52
+ } catch (e) {
53
+ // ignore
54
+ }
55
+ };
56
+
42
57
  export default async () => {
43
58
  checkNodeVersion();
59
+ addToGitingore();
44
60
 
45
61
  const http = require("http");
46
62
  ora = (await oraP).default;
@@ -50,13 +66,27 @@ export default async () => {
50
66
  const logger = createNodeLogger({ process });
51
67
  const sys = createNodeSys({ process });
52
68
 
69
+ const defaultConfig = await provideConfig();
70
+
71
+ const buildDir = path.resolve(
72
+ defaultConfig.client.rootDir,
73
+ ".embeddable-dev-build",
74
+ );
75
+
53
76
  const config = {
77
+ ...defaultConfig,
54
78
  dev: {
55
79
  watch: true,
56
80
  logger,
57
81
  sys,
58
82
  },
59
- ...(await provideConfig()),
83
+ client: {
84
+ ...defaultConfig.client,
85
+ buildDir: buildDir,
86
+ componentDir: path.resolve(buildDir, "component"),
87
+ stencilBuild: path.resolve(buildDir, "dist", "embeddable-wrapper"),
88
+ tmpDir: path.resolve(defaultConfig.client.rootDir, ".embeddable-dev-tmp"),
89
+ },
60
90
  };
61
91
 
62
92
  await prepare(config);
@@ -1,19 +1,7 @@
1
1
  import * as fsP from "node:fs/promises";
2
2
  import * as fs from "node:fs";
3
- import * as path from "node:path";
4
3
 
5
4
  export default async (ctx: any) => {
6
- const componentsEntryPath = path.resolve(
7
- ctx.client.rootDir,
8
- ctx.outputOptions.componentsEntryPointFilename,
9
- );
10
- const typesEntryPath = path.resolve(
11
- ctx.client.rootDir,
12
- ctx.outputOptions.typesEntryPointFilename,
13
- );
14
-
15
5
  if (fs.existsSync(ctx.client.buildDir))
16
6
  await fsP.rm(ctx.client.buildDir, { recursive: true });
17
- if (fs.existsSync(componentsEntryPath)) await fsP.rm(componentsEntryPath);
18
- if (fs.existsSync(typesEntryPath)) await fsP.rm(typesEntryPath);
19
7
  };
package/src/utils.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  const oraP = import("ora");
2
2
  import * as fs from "node:fs/promises";
3
3
  import { CREDENTIALS_DIR } from "./credentials";
4
+ import path from "node:path";
4
5
 
5
6
  let ora: any;
6
7
  export const checkNodeVersion = async () => {
@@ -82,3 +83,18 @@ export const checkBuildSuccess = async () => {
82
83
  return false;
83
84
  }
84
85
  };
86
+
87
+ export const getPackageVersion = (packageName: string) => {
88
+ const packageJsonPath = path.join(
89
+ process.cwd(),
90
+ "node_modules",
91
+ packageName,
92
+ "package.json",
93
+ );
94
+ try {
95
+ const packageJson = require(packageJsonPath);
96
+ return packageJson.version;
97
+ } catch (e) {
98
+ return undefined;
99
+ }
100
+ };