jitsu-cli 2.14.0-beta.5 → 2.14.0-beta.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jitsu-cli",
3
- "version": "2.14.0-beta.5",
3
+ "version": "2.14.0-beta.56",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "publishConfig": {
@@ -11,45 +11,21 @@
11
11
  },
12
12
  "license": "MIT",
13
13
  "private": false,
14
- "scripts": {
15
- "clean": "rm -rf ./dist",
16
- "typecheck": "tsc --noEmit",
17
- "build": "tsc -p . && webpack",
18
- "run": "pnpm build && node dist/main.js",
19
- "login": "pnpm build && node dist/main.js login",
20
- "init child": "pnpm build && node dist/main.js init",
21
- "build child": "pnpm build && node dist/main.js build",
22
- "run child": "pnpm build && node dist/main.js run -e ./data/page.json",
23
- "test child": "pnpm build && node dist/main.js test",
24
- "deploy child": "pnpm build && node dist/main.js deploy"
25
- },
26
14
  "dependencies": {
15
+ "esbuild": "^0.27.0",
27
16
  "figlet": "^1.6.0",
28
17
  "jest-cli": "^29.7.0",
29
- "tslib": "catalog:",
30
- "typescript": "catalog:"
18
+ "tslib": "^2.6.3",
19
+ "typescript": "^5.6.3"
31
20
  },
32
21
  "devDependencies": {
33
- "@swc-node/register": "catalog:",
34
- "swc-loader": "catalog:",
35
- "@swc/core": "catalog:",
36
- "@jitsu/common-config": "workspace:*",
37
- "@jitsu/functions-lib": "workspace:*",
38
- "@jitsu/protocols": "workspace:*",
39
- "@rollup/plugin-commonjs": "^28.0.2",
40
- "@rollup/plugin-json": "^6.0.0",
41
- "@rollup/plugin-node-resolve": "^16.0.0",
42
- "@rollup/plugin-terser": "^0.4.3",
43
- "@rollup/plugin-typescript": "^11.1.3",
44
22
  "@types/chalk": "^2.2.0",
45
23
  "@types/commander": "^2.12.2",
46
24
  "@types/express": "^4.17.21",
47
25
  "@types/inquirer": "^9.0.3",
48
- "@types/lodash": "catalog:",
49
- "@types/node": "catalog:",
50
- "@vitest/ui": "catalog:",
51
- "@types/webpack": "^5.28.5",
52
- "@webpack-cli/generators": "^3.0.7",
26
+ "@types/lodash": "^4.17.7",
27
+ "@types/node": "^18.15.3",
28
+ "@vitest/ui": "^2.1.8",
53
29
  "chalk": "^5.3.0",
54
30
  "commander": "^11.0.0",
55
31
  "cross-fetch": "^4.0.0",
@@ -58,17 +34,26 @@
58
34
  "inquirer": "^9.2.11",
59
35
  "jest": "^29.7.0",
60
36
  "json5": "^2.2.3",
61
- "juava": "workspace:*",
62
- "lodash": "catalog:",
63
- "node-fetch": "^3.3.2",
64
- "node-loader": "^2.0.0",
37
+ "lodash": "^4.17.21",
65
38
  "prismjs": "^1.30.0",
66
- "rollup": "^3.29.5",
67
39
  "semver": "^7.5.4",
68
- "ts-loader": "^9.5.1",
69
- "ts-node": "catalog:",
70
- "vitest": "catalog:",
71
- "webpack": "catalog:",
72
- "webpack-cli": "catalog:"
40
+ "tsx": "^4.21.0",
41
+ "vitest": "^2.1.8",
42
+ "@jitsu/functions-lib": "2.14.0-beta.56",
43
+ "juava": "0.0.0",
44
+ "@jitsu/protocols": "2.14.0-beta.56",
45
+ "@jitsu/common-config": "0.0.0"
46
+ },
47
+ "scripts": {
48
+ "clean": "rm -rf ./dist ./compiled",
49
+ "typecheck": "tsc --noEmit",
50
+ "build": "tsc && tsx build.mts",
51
+ "run": "pnpm build && node dist/main.js",
52
+ "login": "pnpm build && node dist/main.js login",
53
+ "init child": "pnpm build && node dist/main.js init",
54
+ "build child": "pnpm build && node dist/main.js build",
55
+ "run child": "pnpm build && node dist/main.js run -e ./data/page.json",
56
+ "test child": "pnpm build && node dist/main.js test",
57
+ "deploy child": "pnpm build && node dist/main.js deploy"
73
58
  }
74
- }
59
+ }
@@ -1,10 +1,6 @@
1
1
  import path from "path";
2
- import { mkdirSync, readdirSync, writeFileSync, existsSync, lstatSync } from "fs";
3
- import typescript from "@rollup/plugin-typescript";
4
- import resolve from "@rollup/plugin-node-resolve";
5
- import commonjs from "@rollup/plugin-commonjs";
6
- import rollupJson from "@rollup/plugin-json";
7
- import { ModuleFormat, rollup } from "rollup";
2
+ import { mkdirSync, readdirSync, existsSync, lstatSync } from "fs";
3
+ import * as esbuild from "esbuild";
8
4
  import { exec } from "child_process";
9
5
  import { loadPackageJson } from "./shared";
10
6
  import { b, green, red } from "../lib/chalk-code-highlight";
@@ -89,32 +85,31 @@ async function buildFile(projectDir: string, dir: string, fileName: string) {
89
85
  const funcFile = path.resolve(projectDir, "src", path.join(dir, fileName));
90
86
  process.chdir(projectDir);
91
87
 
92
- const rollupPlugins = [
93
- typescript(),
94
- resolve({ preferBuiltins: false }),
95
- commonjs(),
96
- rollupJson(),
97
- // terser(),
98
- ];
88
+ mkdirSync(path.resolve(projectDir, "dist/" + dir), { recursive: true });
89
+ const compiledFunctionPath = `dist/${dir}/${fileName.replace(".ts", ".js")}`;
99
90
 
100
- const bundle = await rollup({
101
- input: [funcFile],
102
- plugins: rollupPlugins,
91
+ await esbuild.build({
92
+ entryPoints: [funcFile],
93
+ absWorkingDir: projectDir,
94
+ bundle: true,
95
+ platform: "neutral",
96
+ format: "esm",
97
+ outfile: path.resolve(projectDir, compiledFunctionPath),
103
98
  external: ["@jitsu/functions-lib"],
104
99
  logLevel: "silent",
100
+ loader: {
101
+ ".json": "json",
102
+ },
103
+ // Resolve dependencies from the user's project node_modules
104
+ nodePaths: [path.resolve(projectDir, "node_modules")],
105
105
  });
106
106
 
107
- let format: ModuleFormat = "es";
108
- let output = await bundle.generate({
109
- dir: projectDir,
110
- format: format,
111
- });
112
-
113
- mkdirSync(path.resolve(projectDir, "dist/" + dir), { recursive: true });
114
- const compiledFunctionPath = `dist/${dir}/${fileName.replace(".ts", ".js")}`;
115
- writeFileSync(path.resolve(projectDir, compiledFunctionPath), output.output[0].code);
116
107
  //to verify that function is readable
117
- const compiledFunction = await getFunctionFromFilePath(path.resolve(projectDir, compiledFunctionPath), "function");
108
+ const compiledFunction = await getFunctionFromFilePath(
109
+ projectDir,
110
+ path.resolve(projectDir, compiledFunctionPath),
111
+ "function"
112
+ );
118
113
  console.log(
119
114
  [`${green(`✓`)} Function ${b(fileName)} compiled successfully`, ` slug = ${b(compiledFunction.meta.slug)}`]
120
115
  .filter(Boolean)
@@ -3,7 +3,6 @@ import { homedir } from "os";
3
3
  import inquirer from "inquirer";
4
4
  import { existsSync, readdirSync, readFileSync } from "fs";
5
5
  import { loadPackageJson } from "./shared";
6
- import fetch from "node-fetch";
7
6
  import cuid from "cuid";
8
7
  import { b, green, red } from "../lib/chalk-code-highlight";
9
8
  import { getFunctionFromFilePath } from "../lib/compiled-function";
@@ -151,6 +150,7 @@ async function deployFunctions(
151
150
  })`
152
151
  );
153
152
  await deployFunction(
153
+ projectDir,
154
154
  { host, apikey },
155
155
  packageJson,
156
156
  workspace,
@@ -162,6 +162,7 @@ async function deployFunctions(
162
162
  }
163
163
 
164
164
  async function deployFunction(
165
+ projectDir: string,
165
166
  { host, apikey }: Args,
166
167
  packageJson: any,
167
168
  workspace: Workspace,
@@ -171,7 +172,7 @@ async function deployFunction(
171
172
  ) {
172
173
  const code = readFileSync(file, "utf-8");
173
174
 
174
- const wrapped = await getFunctionFromFilePath(file, kind, profileBuilders);
175
+ const wrapped = await getFunctionFromFilePath(projectDir, file, kind, profileBuilders);
175
176
  const meta = wrapped.meta;
176
177
  if (meta) {
177
178
  console.log(` meta: slug=${meta.slug}, name=${meta.name || "not set"}`);
@@ -1,7 +1,8 @@
1
1
  import { JitsuFunction } from "@jitsu/protocols/functions";
2
2
  import fs from "fs";
3
- import { rollup } from "rollup";
3
+ import * as esbuild from "esbuild";
4
4
  import { assertDefined, assertTrue } from "juava";
5
+ import path from "path";
5
6
 
6
7
  export type CompiledFunction = {
7
8
  func: JitsuFunction;
@@ -14,10 +15,11 @@ export type CompiledFunction = {
14
15
  };
15
16
 
16
17
  function getSlug(filePath: string) {
17
- return filePath.split("/").pop()?.replace(".ts", "");
18
+ return filePath.split("/").pop()?.replace(".ts", "").replace(".js", "");
18
19
  }
19
20
 
20
21
  export async function getFunctionFromFilePath(
22
+ projectDir: string,
21
23
  filePath: string,
22
24
  kind: "function" | "profile",
23
25
  profileBuilders: any[] = []
@@ -28,29 +30,34 @@ export async function getFunctionFromFilePath(
28
30
  throw new Error(`Cannot load function from file ${filePath}: path is not a file`);
29
31
  }
30
32
 
31
- const bundle = await rollup({
32
- input: [filePath],
33
- external: ["@jitsu/functions-lib"],
34
- logLevel: "silent",
33
+ // Transform ESM to CJS without bundling - just convert the module format
34
+ // This avoids resolving dependencies which may be symlinked
35
+ const result = await esbuild.transform(fs.readFileSync(filePath, "utf-8"), {
36
+ loader: filePath.endsWith(".ts") ? "ts" : "js",
37
+ format: "cjs",
38
+ platform: "node",
35
39
  });
36
40
 
37
- const output = await bundle.generate({
38
- file: filePath,
39
- format: "commonjs",
40
- });
41
-
42
- const exports: Record<string, any> = {} as Record<string, any>;
43
- eval(output.output[0].code);
41
+ const code = result.code;
42
+ const module: { exports: Record<string, any> } = { exports: {} };
43
+ const exports = module.exports;
44
+ // Provide require stub for external imports that we mock out
45
+ const require = (id: string) => {
46
+ // External dependencies are not needed for config extraction
47
+ return {};
48
+ };
49
+ eval(code);
50
+ // After eval, module.exports contains the actual exports
51
+ const moduleExports = module.exports;
44
52
  assertDefined(
45
- exports.default,
46
- `Function from ${filePath} doesn't have default export. Exported symbols: ${Object.keys(exports)}`
53
+ moduleExports.default,
54
+ `Function from ${filePath} doesn't have default export. Exported symbols: ${Object.keys(moduleExports)}`
47
55
  );
48
- assertTrue(typeof exports.default === "function", `Default export from ${filePath} is not a function`);
49
-
50
- let name = exports.config?.name || exports.config?.slug || getSlug(filePath);
51
- let id = exports.config?.id;
56
+ assertTrue(typeof moduleExports.default === "function", `Default export from ${filePath} is not a function`);
57
+ let name = moduleExports.config?.name || moduleExports.config?.slug || getSlug(filePath);
58
+ let id = moduleExports.config?.id;
52
59
  if (kind === "profile") {
53
- const profileBuilderId = exports.config?.profileBuilderId;
60
+ const profileBuilderId = moduleExports.config?.profileBuilderId;
54
61
  const profileBuilder = profileBuilders.find(pb => pb.id === profileBuilderId);
55
62
  if (!profileBuilder) {
56
63
  throw new Error(
@@ -67,12 +74,12 @@ export async function getFunctionFromFilePath(
67
74
  }
68
75
 
69
76
  return {
70
- func: exports.default,
77
+ func: moduleExports.default,
71
78
  meta: {
72
- slug: exports.config?.slug || getSlug(filePath),
79
+ slug: moduleExports.config?.slug || getSlug(filePath),
73
80
  id: id,
74
81
  name: name,
75
- description: exports.config?.description,
82
+ description: moduleExports.config?.description,
76
83
  },
77
84
  };
78
85
  }