Skip to content

Commit e9a75c0

Browse files
authored
Merge pull request #578 from raheeliftikhar5/remove-dev-utils
Remove lowcoder-dev-utils
2 parents 4304708 + 8130928 commit e9a75c0

31 files changed

+992
-278
lines changed

.DS_Store

2 KB
Binary file not shown.

client/config/test/jest.config.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import path from "node:path";
2-
import { buildVars } from "../../packages/lowcoder-dev-utils/buildVars.js";
3-
import { currentDirName } from "../../packages/lowcoder-dev-utils/util.js";
1+
import path, { dirname } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { buildVars } from "../../scripts/buildVars.js";
4+
5+
export function currentDirName(importMetaUrl) {
6+
return dirname(fileURLToPath(importMetaUrl));
7+
}
8+
49

510
const globals = {};
611
buildVars.forEach(({ name, defaultValue }) => {
@@ -9,34 +14,34 @@ buildVars.forEach(({ name, defaultValue }) => {
914
const edition = process.env.REACT_APP_EDITION;
1015
const isEEGlobal = edition === "enterprise-global";
1116
const isEE = edition === "enterprise" || isEEGlobal;
12-
const dirname = currentDirName(import.meta.url);
17+
const currentDir = currentDirName(import.meta.url);
1318

1419
export default {
1520
testEnvironment: "jsdom",
1621
moduleNameMapper: {
17-
"react-markdown": path.resolve(dirname, "./mocks/react-markdown.js"),
18-
"\\.md\\?url$": path.resolve(dirname, "./mocks/markdown-url-module.js"),
22+
"react-markdown": path.resolve(currentDir, "./mocks/react-markdown.js"),
23+
"\\.md\\?url$": path.resolve(currentDir, "./mocks/markdown-url-module.js"),
1924
"^@lowcoder-ee(.*)$": path.resolve(
20-
dirname,
25+
currentDir,
2126
isEE ? "../../packages/lowcoder/src/ee/$1" : "../../packages/lowcoder/src/$1"
2227
),
23-
"lowcoder-sdk": path.resolve(dirname, "../../packages/lowcoder/src/index.sdk"),
28+
"lowcoder-sdk": path.resolve(currentDir, "../../packages/lowcoder/src/index.sdk"),
2429
},
2530
globals,
2631
// roots: ["<rootDir>/src"],
2732
modulePaths: [
2833
"<rootDir>/src",
29-
path.resolve(dirname, "../../packages/lowcoder/src"),
30-
path.resolve(dirname, "../../packages/lowcoder-comps/src"),
31-
path.resolve(dirname, "../../packages/lowcoder-design/src"),
34+
path.resolve(currentDir, "../../packages/lowcoder/src"),
35+
path.resolve(currentDir, "../../packages/lowcoder-comps/src"),
36+
path.resolve(currentDir, "../../packages/lowcoder-design/src"),
3237
],
33-
setupFiles: [path.resolve(dirname, "./jest.setup.js")],
34-
setupFilesAfterEnv: [path.resolve(dirname, "./jest.setup-after-env.js")],
38+
setupFiles: [path.resolve(currentDir, "./jest.setup.js")],
39+
setupFilesAfterEnv: [path.resolve(currentDir, "./jest.setup-after-env.js")],
3540
transform: {
36-
"^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": path.resolve(dirname, "./transform/babelTransform.js"),
37-
"^.+\\.css$": path.resolve(dirname, "./transform/cssTransform.js"),
41+
"^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": path.resolve(currentDir, "./transform/babelTransform.js"),
42+
"^.+\\.css$": path.resolve(currentDir, "./transform/cssTransform.js"),
3843
"^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": path.resolve(
39-
dirname,
44+
currentDir,
4045
"./transform/fileTransform.js"
4146
),
4247
},

client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"jest-environment-jsdom": "^29.5.0",
5252
"lint-staged": "^13.0.1",
5353
"lowcoder-cli": "workspace:^",
54-
"lowcoder-dev-utils": "workspace:^",
5554
"mq-polyfill": "^1.1.8",
5655
"prettier": "^3.1.0",
5756
"rimraf": "^3.0.2",

client/packages/create-lowcoder-plugin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { spawn } from "cross-spawn";
55
import { writeFileSync, existsSync } from "node:fs";
66
import chalk from "chalk";
77
import { createCommand } from "commander";
8-
import { readJson, currentDirName } from "../lowcoder-dev-utils/util.js";
8+
import { readJson, currentDirName } from "../../dev-utils/util.js";
99

1010
const currentDir = currentDirName(import.meta.url);
1111
const pkg = readJson(path.resolve(currentDir, "./package.json"));

client/packages/create-lowcoder-plugin/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"chalk": "4",
88
"commander": "^9.4.1",
99
"cross-spawn": "^7.0.3",
10-
"fs-extra": "^10.1.0",
11-
"lowcoder-dev-utils": "workspace:^"
10+
"fs-extra": "^10.1.0"
1211
},
1312
"license": "MIT",
1413
"keywords": [

client/packages/lowcoder-cli/config/paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import fs from "node:fs";
3-
import { currentDirName } from "../../lowcoder-dev-utils/util.js";
3+
import { currentDirName } from "../dev-utils/util.js";
44

55
const currentDir = currentDirName(import.meta.url);
66
const appDirectory = fs.realpathSync(process.cwd());

client/packages/lowcoder-cli/config/vite.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import react from "@vitejs/plugin-react";
22
import svgrPlugin from "vite-plugin-svgr";
33
import global from "rollup-plugin-external-globals";
4-
import { buildVars } from "../../lowcoder-dev-utils/buildVars.js";
4+
import { buildVars } from "../dev-utils/buildVars.js";
55
import injectCss from "vite-plugin-css-injected-by-js";
6-
import { getLibNames, getAllLibGlobalVarNames } from "../../lowcoder-dev-utils/external.js";
6+
import { getLibNames, getAllLibGlobalVarNames } from "../dev-utils/external.js";
77
import paths from "./paths.js";
88
import { defineConfig } from "vite";
9-
import { readJson } from "../../lowcoder-dev-utils/util.js";
9+
import { readJson } from "../dev-utils/util.js";
1010

1111
const isProduction = process.env.NODE_ENV === "production";
1212
const packageJson = readJson(paths.appPackageJson);

client/packages/lowcoder-cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"commander": "^9.4.1",
3030
"cross-spawn": "^7.0.3",
3131
"fs-extra": "^10.1.0",
32-
"lowcoder-dev-utils": "workspace:^",
3332
"react": "^17",
3433
"react-dom": "^17",
3534
"react-json-view": "^1.21.3",

client/packages/lowcoder-dev-utils/package.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

client/packages/lowcoder-sdk/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@rollup/plugin-url": "^7.0.0",
3636
"@svgr/rollup": "^6.3.1",
3737
"@vitejs/plugin-react": "^2.2.0",
38-
"lowcoder-dev-utils": "workspace:^",
3938
"rollup": "^2",
4039
"rollup-plugin-cleaner": "^1.0.0",
4140
"rollup-plugin-node-builtins": "^2.1.2",
@@ -55,5 +54,8 @@
5554
"keywords": [
5655
"lowcoder"
5756
],
58-
"license": "MIT"
57+
"license": "MIT",
58+
"dependencies": {
59+
"prettier": "^3.1.1"
60+
}
5961
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
export const buildVars = [
2+
{
3+
name: "PUBLIC_URL",
4+
defaultValue: "/",
5+
},
6+
{
7+
name: "REACT_APP_EDITION",
8+
defaultValue: "community",
9+
},
10+
{
11+
name: "REACT_APP_LANGUAGES",
12+
defaultValue: "",
13+
},
14+
{
15+
name: "REACT_APP_COMMIT_ID",
16+
defaultValue: "00000",
17+
},
18+
{
19+
name: "REACT_APP_API_HOST",
20+
defaultValue: "",
21+
},
22+
{
23+
name: "LOWCODER_NODE_SERVICE_URL",
24+
defaultValue: "",
25+
},
26+
{
27+
name: "REACT_APP_ENV",
28+
defaultValue: "production",
29+
},
30+
{
31+
name: "REACT_APP_BUILD_ID",
32+
defaultValue: "",
33+
},
34+
{
35+
name: "REACT_APP_LOG_LEVEL",
36+
defaultValue: "error",
37+
},
38+
{
39+
name: "REACT_APP_IMPORT_MAP",
40+
defaultValue: "{}",
41+
},
42+
{
43+
name: "REACT_APP_SERVER_IPS",
44+
defaultValue: "",
45+
},
46+
{
47+
name: "REACT_APP_BUNDLE_BUILTIN_PLUGIN",
48+
defaultValue: "",
49+
},
50+
{
51+
name: "REACT_APP_BUNDLE_TYPE",
52+
defaultValue: "app",
53+
},
54+
{
55+
name: "REACT_APP_DISABLE_JS_SANDBOX",
56+
defaultValue: "",
57+
},
58+
];
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* libs to import as global var
3+
* name: module name
4+
* mergeDefaultAndNameExports: whether to merge default and named exports
5+
*/
6+
export const libs = [
7+
"axios",
8+
"redux",
9+
"react-router",
10+
"react-router-dom",
11+
"react-redux",
12+
"react",
13+
"react-dom",
14+
"lodash",
15+
"history",
16+
"antd",
17+
"@dnd-kit/core",
18+
"@dnd-kit/modifiers",
19+
"@dnd-kit/sortable",
20+
"@dnd-kit/utilities",
21+
{
22+
name: "moment",
23+
extractDefault: true,
24+
},
25+
{
26+
name: "dayjs",
27+
extractDefault: true,
28+
},
29+
{
30+
name: "lowcoder-sdk",
31+
from: "./src/index.sdk.ts",
32+
},
33+
{
34+
name: "styled-components",
35+
mergeDefaultAndNameExports: true,
36+
},
37+
];
38+
39+
/**
40+
* get global var name from module name
41+
* @param {string} name
42+
* @returns
43+
*/
44+
export const getLibGlobalVarName = (name) => {
45+
return "$" + name.replace(/@/g, "$").replace(/[\/\-]/g, "_");
46+
};
47+
48+
export const getLibNames = () => {
49+
return libs.map((i) => {
50+
if (typeof i === "object") {
51+
return i.name;
52+
}
53+
return i;
54+
});
55+
};
56+
57+
export const getAllLibGlobalVarNames = () => {
58+
const ret = {};
59+
libs.forEach((lib) => {
60+
let name = lib;
61+
if (typeof lib === "object") {
62+
name = lib.name;
63+
}
64+
ret[name] = getLibGlobalVarName(name);
65+
});
66+
return ret;
67+
};
68+
69+
export const libsImportCode = (exclude = []) => {
70+
const importLines = [];
71+
const assignLines = [];
72+
libs.forEach((i) => {
73+
let name = i;
74+
let merge = false;
75+
let from = name;
76+
let extractDefault = false;
77+
78+
if (typeof i === "object") {
79+
name = i.name;
80+
merge = i.mergeDefaultAndNameExports ?? false;
81+
from = i.from ?? name;
82+
extractDefault = i.extractDefault ?? false;
83+
}
84+
85+
if (exclude.includes(name)) {
86+
return;
87+
}
88+
89+
const varName = getLibGlobalVarName(name);
90+
if (merge) {
91+
importLines.push(`import * as ${varName}_named_exports from '${from}';`);
92+
importLines.push(`import ${varName} from '${from}';`);
93+
assignLines.push(`Object.assign(${varName}, ${varName}_named_exports);`);
94+
} else if (extractDefault) {
95+
importLines.push(`import ${varName} from '${from}';`);
96+
} else {
97+
importLines.push(`import * as ${varName} from '${from}';`);
98+
}
99+
assignLines.push(`window.${varName} = ${varName};`);
100+
});
101+
return importLines.concat(assignLines).join("\n");
102+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { libsImportCode } from "./external.js";
2+
3+
export function globalDepPlugin(exclude = []) {
4+
const virtualModuleId = "virtual:globals";
5+
return {
6+
name: "lowcoder-global-plugin",
7+
resolveId(id) {
8+
if (id === virtualModuleId) {
9+
return id;
10+
}
11+
},
12+
load(id) {
13+
if (id === virtualModuleId) {
14+
return libsImportCode(exclude);
15+
}
16+
},
17+
};
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from "node:fs";
2+
import { dirname } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
export function stripLastSlash(str) {
6+
if (str.endsWith("/")) {
7+
return str.slice(0, str.length - 1);
8+
}
9+
return str;
10+
}
11+
12+
export function ensureLastSlash(str) {
13+
if (!str) {
14+
return "/";
15+
}
16+
if (!str.endsWith("/")) {
17+
return `${str}/`;
18+
}
19+
return str;
20+
}
21+
22+
export function readJson(file) {
23+
return JSON.parse(fs.readFileSync(file).toString());
24+
}
25+
26+
export function currentDirName(importMetaUrl) {
27+
return dirname(fileURLToPath(importMetaUrl));
28+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck
22
import "../../lowcoder/src/index.less";
33
import "virtual:globals";
4-
import * as sdk from "lowcoder";
5-
export * from "lowcoder";
4+
import * as sdk from "../../lowcoder";
5+
export * from "../../lowcoder";
66

77
window.$lowcoder_sdk = sdk;

client/packages/lowcoder-sdk/vite.config.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import react from "@vitejs/plugin-react";
33
import viteTsconfigPaths from "vite-tsconfig-paths";
44
import svgrPlugin from "vite-plugin-svgr";
55
import path from "path";
6-
import { ensureLastSlash } from "../lowcoder-dev-utils/util";
7-
import { buildVars } from "../lowcoder-dev-utils/buildVars";
8-
import { globalDepPlugin } from "../lowcoder-dev-utils/globalDepPlguin";
6+
import { ensureLastSlash } from "./src/dev-utils/util";
7+
import { buildVars } from "./src/dev-utils/buildVars";
8+
import { globalDepPlugin } from "./src/dev-utils/globalDepPlguin";
99

1010
const define = {};
1111
buildVars.forEach(({ name, defaultValue }) => {

0 commit comments

Comments
 (0)