jitsu-cli 2.14.0-beta.4 → 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/LICENSE +21 -0
- package/build.mts +39 -0
- package/compiled/package.json +6 -21
- package/compiled/src/commands/build.js +16 -24
- package/compiled/src/commands/deploy.js +3 -4
- package/compiled/src/lib/compiled-function.js +23 -21
- package/dist/main.js +42892 -92918
- package/dist/main.js.map +7 -1
- package/package.json +27 -42
- package/src/commands/build.ts +21 -26
- package/src/commands/deploy.ts +3 -2
- package/src/lib/compiled-function.ts +30 -23
- package/dist/140.js +0 -452
- package/dist/140.js.map +0 -1
- package/webpack.config.cjs +0 -53
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Jitsu Labs, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build.mts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as esbuild from "esbuild";
|
|
2
|
+
import { mkdirSync } from "fs";
|
|
3
|
+
|
|
4
|
+
// Ensure dist directory exists
|
|
5
|
+
mkdirSync("./dist", { recursive: true });
|
|
6
|
+
|
|
7
|
+
// External modules that should not be bundled
|
|
8
|
+
// These are either native modules or need to be loaded at runtime
|
|
9
|
+
const externalModules = [
|
|
10
|
+
// Native/binary modules
|
|
11
|
+
"figlet", // ASCII art library with data files
|
|
12
|
+
"fsevents", // macOS-only native file system events
|
|
13
|
+
"esbuild", // esbuild has native binaries, used at runtime to build user functions
|
|
14
|
+
|
|
15
|
+
// Large runtime dependencies
|
|
16
|
+
"typescript", // TypeScript compiler (large, used at runtime)
|
|
17
|
+
"jest-cli", // Jest test runner
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
// Bundle the CLI
|
|
21
|
+
esbuild
|
|
22
|
+
.build({
|
|
23
|
+
entryPoints: ["./src/index.ts"],
|
|
24
|
+
bundle: true,
|
|
25
|
+
platform: "node",
|
|
26
|
+
target: "node20",
|
|
27
|
+
format: "cjs",
|
|
28
|
+
outfile: "./dist/main.js",
|
|
29
|
+
sourcemap: true,
|
|
30
|
+
minify: false,
|
|
31
|
+
external: externalModules,
|
|
32
|
+
logLevel: "info",
|
|
33
|
+
loader: {
|
|
34
|
+
".json": "json",
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
.then(() => {
|
|
38
|
+
console.log("\nBuild complete!");
|
|
39
|
+
});
|
package/compiled/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jitsu-cli",
|
|
3
|
-
"version": "2.14.0-beta.
|
|
3
|
+
"version": "2.14.0-beta.56",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Jitsu Dev Team <dev@jitsu.com>",
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"private": false,
|
|
14
14
|
"scripts": {
|
|
15
|
-
"clean": "rm -rf ./dist",
|
|
15
|
+
"clean": "rm -rf ./dist ./compiled",
|
|
16
16
|
"typecheck": "tsc --noEmit",
|
|
17
|
-
"build": "tsc
|
|
17
|
+
"build": "tsc && tsx build.mts",
|
|
18
18
|
"run": "pnpm build && node dist/main.js",
|
|
19
19
|
"login": "pnpm build && node dist/main.js login",
|
|
20
20
|
"init child": "pnpm build && node dist/main.js init",
|
|
@@ -24,23 +24,16 @@
|
|
|
24
24
|
"deploy child": "pnpm build && node dist/main.js deploy"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"esbuild": "catalog:",
|
|
27
28
|
"figlet": "^1.6.0",
|
|
28
29
|
"jest-cli": "^29.7.0",
|
|
29
30
|
"tslib": "catalog:",
|
|
30
31
|
"typescript": "catalog:"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@swc-node/register": "catalog:",
|
|
34
|
-
"swc-loader": "catalog:",
|
|
35
|
-
"@swc/core": "catalog:",
|
|
36
34
|
"@jitsu/common-config": "workspace:*",
|
|
37
35
|
"@jitsu/functions-lib": "workspace:*",
|
|
38
36
|
"@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
37
|
"@types/chalk": "^2.2.0",
|
|
45
38
|
"@types/commander": "^2.12.2",
|
|
46
39
|
"@types/express": "^4.17.21",
|
|
@@ -48,8 +41,6 @@
|
|
|
48
41
|
"@types/lodash": "catalog:",
|
|
49
42
|
"@types/node": "catalog:",
|
|
50
43
|
"@vitest/ui": "catalog:",
|
|
51
|
-
"@types/webpack": "^5.28.5",
|
|
52
|
-
"@webpack-cli/generators": "^3.0.7",
|
|
53
44
|
"chalk": "^5.3.0",
|
|
54
45
|
"commander": "^11.0.0",
|
|
55
46
|
"cross-fetch": "^4.0.0",
|
|
@@ -60,15 +51,9 @@
|
|
|
60
51
|
"json5": "^2.2.3",
|
|
61
52
|
"juava": "workspace:*",
|
|
62
53
|
"lodash": "catalog:",
|
|
63
|
-
"node-fetch": "^3.3.2",
|
|
64
|
-
"node-loader": "^2.0.0",
|
|
65
54
|
"prismjs": "^1.30.0",
|
|
66
|
-
"rollup": "^3.29.5",
|
|
67
55
|
"semver": "^7.5.4",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"vitest": "catalog:",
|
|
71
|
-
"webpack": "catalog:",
|
|
72
|
-
"webpack-cli": "catalog:"
|
|
56
|
+
"tsx": "catalog:",
|
|
57
|
+
"vitest": "catalog:"
|
|
73
58
|
}
|
|
74
59
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { mkdirSync, readdirSync,
|
|
3
|
-
import
|
|
4
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
5
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
6
|
-
import rollupJson from "@rollup/plugin-json";
|
|
7
|
-
import { 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";
|
|
@@ -80,27 +76,23 @@ async function buildFiles(projectDir, dir = "") {
|
|
|
80
76
|
async function buildFile(projectDir, dir, fileName) {
|
|
81
77
|
const funcFile = path.resolve(projectDir, "src", path.join(dir, fileName));
|
|
82
78
|
process.chdir(projectDir);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
mkdirSync(path.resolve(projectDir, "dist/" + dir), { recursive: true });
|
|
80
|
+
const compiledFunctionPath = `dist/${dir}/${fileName.replace(".ts", ".js")}`;
|
|
81
|
+
await esbuild.build({
|
|
82
|
+
entryPoints: [funcFile],
|
|
83
|
+
absWorkingDir: projectDir,
|
|
84
|
+
bundle: true,
|
|
85
|
+
platform: "neutral",
|
|
86
|
+
format: "esm",
|
|
87
|
+
outfile: path.resolve(projectDir, compiledFunctionPath),
|
|
92
88
|
external: ["@jitsu/functions-lib"],
|
|
93
89
|
logLevel: "silent",
|
|
90
|
+
loader: {
|
|
91
|
+
".json": "json",
|
|
92
|
+
},
|
|
93
|
+
nodePaths: [path.resolve(projectDir, "node_modules")],
|
|
94
94
|
});
|
|
95
|
-
|
|
96
|
-
let output = await bundle.generate({
|
|
97
|
-
dir: projectDir,
|
|
98
|
-
format: format,
|
|
99
|
-
});
|
|
100
|
-
mkdirSync(path.resolve(projectDir, "dist/" + dir), { recursive: true });
|
|
101
|
-
const compiledFunctionPath = `dist/${dir}/${fileName.replace(".ts", ".js")}`;
|
|
102
|
-
writeFileSync(path.resolve(projectDir, compiledFunctionPath), output.output[0].code);
|
|
103
|
-
const compiledFunction = await getFunctionFromFilePath(path.resolve(projectDir, compiledFunctionPath), "function");
|
|
95
|
+
const compiledFunction = await getFunctionFromFilePath(projectDir, path.resolve(projectDir, compiledFunctionPath), "function");
|
|
104
96
|
console.log([`${green(`✓`)} Function ${b(fileName)} compiled successfully`, ` slug = ${b(compiledFunction.meta.slug)}`]
|
|
105
97
|
.filter(Boolean)
|
|
106
98
|
.join("\n"));
|
|
@@ -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";
|
|
@@ -105,12 +104,12 @@ async function deployFunctions({ host, apikey, name: names }, projectDir, packag
|
|
|
105
104
|
}
|
|
106
105
|
for (const file of selectedFiles) {
|
|
107
106
|
console.log(`${b(`𝑓`)} Deploying function ${b(path.basename(file))} to workspace ${workspace.name} (${host}/${workspace.slug || workspace.id})`);
|
|
108
|
-
await deployFunction({ host, apikey }, packageJson, workspace, kind, path.resolve(functionsDir, file), profileBuilders);
|
|
107
|
+
await deployFunction(projectDir, { host, apikey }, packageJson, workspace, kind, path.resolve(functionsDir, file), profileBuilders);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
|
-
async function deployFunction({ host, apikey }, packageJson, workspace, kind, file, profileBuilders = []) {
|
|
110
|
+
async function deployFunction(projectDir, { host, apikey }, packageJson, workspace, kind, file, profileBuilders = []) {
|
|
112
111
|
const code = readFileSync(file, "utf-8");
|
|
113
|
-
const wrapped = await getFunctionFromFilePath(file, kind, profileBuilders);
|
|
112
|
+
const wrapped = await getFunctionFromFilePath(projectDir, file, kind, profileBuilders);
|
|
114
113
|
const meta = wrapped.meta;
|
|
115
114
|
if (meta) {
|
|
116
115
|
console.log(` meta: slug=${meta.slug}, name=${meta.name || "not set"}`);
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
-
import
|
|
2
|
+
import * as esbuild from "esbuild";
|
|
3
3
|
import { assertDefined, assertTrue } from "juava";
|
|
4
4
|
function getSlug(filePath) {
|
|
5
|
-
return filePath.split("/").pop()?.replace(".ts", "");
|
|
5
|
+
return filePath.split("/").pop()?.replace(".ts", "").replace(".js", "");
|
|
6
6
|
}
|
|
7
|
-
export async function getFunctionFromFilePath(filePath, kind, profileBuilders = []) {
|
|
7
|
+
export async function getFunctionFromFilePath(projectDir, filePath, kind, profileBuilders = []) {
|
|
8
8
|
if (!fs.existsSync(filePath)) {
|
|
9
9
|
throw new Error(`Cannot load function from file ${filePath}: file doesn't exist`);
|
|
10
10
|
}
|
|
11
11
|
else if (!fs.statSync(filePath).isFile()) {
|
|
12
12
|
throw new Error(`Cannot load function from file ${filePath}: path is not a file`);
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const result = await esbuild.transform(fs.readFileSync(filePath, "utf-8"), {
|
|
15
|
+
loader: filePath.endsWith(".ts") ? "ts" : "js",
|
|
16
|
+
format: "cjs",
|
|
17
|
+
platform: "node",
|
|
18
18
|
});
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const code = result.code;
|
|
20
|
+
const module = { exports: {} };
|
|
21
|
+
const exports = module.exports;
|
|
22
|
+
const require = (id) => {
|
|
23
|
+
return {};
|
|
24
|
+
};
|
|
25
|
+
eval(code);
|
|
26
|
+
const moduleExports = module.exports;
|
|
27
|
+
assertDefined(moduleExports.default, `Function from ${filePath} doesn't have default export. Exported symbols: ${Object.keys(moduleExports)}`);
|
|
28
|
+
assertTrue(typeof moduleExports.default === "function", `Default export from ${filePath} is not a function`);
|
|
29
|
+
let name = moduleExports.config?.name || moduleExports.config?.slug || getSlug(filePath);
|
|
30
|
+
let id = moduleExports.config?.id;
|
|
29
31
|
if (kind === "profile") {
|
|
30
|
-
const profileBuilderId =
|
|
32
|
+
const profileBuilderId = moduleExports.config?.profileBuilderId;
|
|
31
33
|
const profileBuilder = profileBuilders.find(pb => pb.id === profileBuilderId);
|
|
32
34
|
if (!profileBuilder) {
|
|
33
35
|
throw new Error(`Cannot find profile builder with id ${profileBuilderId} for profile function ${filePath}. Please setup Profile Builder in UI first.`);
|
|
@@ -39,12 +41,12 @@ export async function getFunctionFromFilePath(filePath, kind, profileBuilders =
|
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
return {
|
|
42
|
-
func:
|
|
44
|
+
func: moduleExports.default,
|
|
43
45
|
meta: {
|
|
44
|
-
slug:
|
|
46
|
+
slug: moduleExports.config?.slug || getSlug(filePath),
|
|
45
47
|
id: id,
|
|
46
48
|
name: name,
|
|
47
|
-
description:
|
|
49
|
+
description: moduleExports.config?.description,
|
|
48
50
|
},
|
|
49
51
|
};
|
|
50
52
|
}
|