@modern-js/app-tools 2.1.0 → 2.2.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.
- package/CHANGELOG.md +47 -0
- package/dist/js/modern/analyze/index.js +13 -4
- package/dist/js/modern/analyze/nestedRoutes.js +5 -1
- package/dist/js/modern/builder/index.js +4 -4
- package/dist/js/modern/commands/dev.js +1 -23
- package/dist/js/modern/hooks.js +0 -2
- package/dist/js/modern/index.js +8 -0
- package/dist/js/modern/locale/en.js +3 -1
- package/dist/js/modern/locale/zh.js +3 -1
- package/dist/js/modern/utils/generateWatchFiles.js +55 -0
- package/dist/js/modern/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +9 -8
- package/dist/js/node/analyze/index.js +10 -2
- package/dist/js/node/analyze/nestedRoutes.js +5 -1
- package/dist/js/node/builder/index.js +4 -4
- package/dist/js/node/commands/dev.js +1 -23
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +8 -0
- package/dist/js/node/locale/en.js +3 -1
- package/dist/js/node/locale/zh.js +3 -1
- package/dist/js/node/utils/{createFileWatcher.js → generateWatchFiles.js} +12 -66
- package/dist/js/node/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +12 -11
- package/dist/js/treeshaking/analyze/index.js +25 -11
- package/dist/js/treeshaking/analyze/nestedRoutes.js +12 -3
- package/dist/js/treeshaking/builder/index.js +5 -5
- package/dist/js/treeshaking/commands/dev.js +13 -31
- package/dist/js/treeshaking/hooks.js +0 -2
- package/dist/js/treeshaking/index.js +14 -0
- package/dist/js/treeshaking/locale/en.js +3 -1
- package/dist/js/treeshaking/locale/zh.js +3 -1
- package/dist/js/treeshaking/utils/{createFileWatcher.js → generateWatchFiles.js} +16 -85
- package/dist/js/treeshaking/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +8 -7
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/types/hooks.d.ts +0 -5
- package/dist/types/utils/generateWatchFiles.d.ts +3 -0
- package/dist/types/utils/getSelectedEntries.d.ts +6 -0
- package/package.json +22 -22
- package/dist/js/modern/utils/createFileWatcher.js +0 -115
- package/dist/types/utils/createFileWatcher.d.ts +0 -4
- package/dist/types/utils/getSpecifiedEntries.d.ts +0 -2
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.2.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -65,23 +65,23 @@
|
|
|
65
65
|
"@babel/types": "^7.18.0",
|
|
66
66
|
"es-module-lexer": "^1.1.0",
|
|
67
67
|
"esbuild": "0.15.7",
|
|
68
|
-
"@modern-js/builder": "2.
|
|
69
|
-
"@modern-js/builder-plugin-esbuild": "2.
|
|
70
|
-
"@modern-js/builder-plugin-node-polyfill": "2.
|
|
71
|
-
"@modern-js/builder-shared": "2.
|
|
72
|
-
"@modern-js/builder-webpack-provider": "2.
|
|
73
|
-
"@modern-js/core": "2.
|
|
74
|
-
"@modern-js/new-action": "2.
|
|
75
|
-
"@modern-js/node-bundle-require": "2.
|
|
76
|
-
"@modern-js/plugin": "2.
|
|
77
|
-
"@modern-js/plugin-data-loader": "2.
|
|
78
|
-
"@modern-js/plugin-i18n": "2.
|
|
79
|
-
"@modern-js/plugin-lint": "2.
|
|
80
|
-
"@modern-js/prod-server": "2.
|
|
81
|
-
"@modern-js/server": "2.
|
|
82
|
-
"@modern-js/types": "2.
|
|
83
|
-
"@modern-js/upgrade": "2.
|
|
84
|
-
"@modern-js/utils": "2.
|
|
68
|
+
"@modern-js/builder": "2.2.0",
|
|
69
|
+
"@modern-js/builder-plugin-esbuild": "2.2.0",
|
|
70
|
+
"@modern-js/builder-plugin-node-polyfill": "2.2.0",
|
|
71
|
+
"@modern-js/builder-shared": "2.2.0",
|
|
72
|
+
"@modern-js/builder-webpack-provider": "2.2.0",
|
|
73
|
+
"@modern-js/core": "2.2.0",
|
|
74
|
+
"@modern-js/new-action": "2.2.0",
|
|
75
|
+
"@modern-js/node-bundle-require": "2.2.0",
|
|
76
|
+
"@modern-js/plugin": "2.2.0",
|
|
77
|
+
"@modern-js/plugin-data-loader": "2.2.0",
|
|
78
|
+
"@modern-js/plugin-i18n": "2.2.0",
|
|
79
|
+
"@modern-js/plugin-lint": "2.2.0",
|
|
80
|
+
"@modern-js/prod-server": "2.2.0",
|
|
81
|
+
"@modern-js/server": "2.2.0",
|
|
82
|
+
"@modern-js/types": "2.2.0",
|
|
83
|
+
"@modern-js/upgrade": "2.2.0",
|
|
84
|
+
"@modern-js/utils": "2.2.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/babel__traverse": "^7.14.2",
|
|
@@ -90,10 +90,10 @@
|
|
|
90
90
|
"jest": "^27",
|
|
91
91
|
"typescript": "^4",
|
|
92
92
|
"webpack": "^5.75.0",
|
|
93
|
-
"@modern-js/builder-plugin-swc": "2.
|
|
94
|
-
"@modern-js/server-core": "2.
|
|
95
|
-
"@scripts/
|
|
96
|
-
"@scripts/
|
|
93
|
+
"@modern-js/builder-plugin-swc": "2.2.0",
|
|
94
|
+
"@modern-js/server-core": "2.2.0",
|
|
95
|
+
"@scripts/jest-config": "2.2.0",
|
|
96
|
+
"@scripts/build": "2.2.0"
|
|
97
97
|
},
|
|
98
98
|
"sideEffects": false,
|
|
99
99
|
"publishConfig": {
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import crypto from "crypto";
|
|
22
|
-
import fs from "fs";
|
|
23
|
-
import path from "path";
|
|
24
|
-
import {
|
|
25
|
-
isDev,
|
|
26
|
-
chokidar,
|
|
27
|
-
createDebugger,
|
|
28
|
-
isTest,
|
|
29
|
-
getServerConfig
|
|
30
|
-
} from "@modern-js/utils";
|
|
31
|
-
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
32
|
-
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
33
|
-
const json = JSON.parse(
|
|
34
|
-
fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8")
|
|
35
|
-
);
|
|
36
|
-
return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
37
|
-
};
|
|
38
|
-
const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) => __async(void 0, null, function* () {
|
|
39
|
-
const serverConfig = yield getServerConfig(appDirectory, serverConfigFile);
|
|
40
|
-
if (serverConfig) {
|
|
41
|
-
dependencies.push(serverConfig);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const debug = createDebugger("watch-files");
|
|
45
|
-
const md5 = (data) => crypto.createHash("md5").update(data).digest("hex");
|
|
46
|
-
const hashMap = /* @__PURE__ */ new Map();
|
|
47
|
-
const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0, null, function* () {
|
|
48
|
-
if (isDev() || isTest()) {
|
|
49
|
-
const { appDirectory, configFile } = appContext;
|
|
50
|
-
const extraFiles = yield hooksRunner.watchFiles();
|
|
51
|
-
const configPath = path.join(appDirectory, configDir);
|
|
52
|
-
const dependencies = getPackageConfig(
|
|
53
|
-
appContext.appDirectory,
|
|
54
|
-
appContext.packageName
|
|
55
|
-
) ? [path.resolve(appDirectory, "./package.json")] : [];
|
|
56
|
-
yield addServerConfigToDeps(
|
|
57
|
-
dependencies,
|
|
58
|
-
appContext.appDirectory,
|
|
59
|
-
appContext.serverConfigFile
|
|
60
|
-
);
|
|
61
|
-
const watched = [
|
|
62
|
-
`${configPath}/html`,
|
|
63
|
-
...extraFiles,
|
|
64
|
-
...dependencies,
|
|
65
|
-
configFile
|
|
66
|
-
].filter(Boolean);
|
|
67
|
-
debug(`watched: %o`, watched);
|
|
68
|
-
const watcher = chokidar.watch(watched, {
|
|
69
|
-
cwd: appDirectory,
|
|
70
|
-
ignoreInitial: true,
|
|
71
|
-
ignorePermissionErrors: true,
|
|
72
|
-
ignored: [
|
|
73
|
-
/node_modules/,
|
|
74
|
-
"**/__test__/**",
|
|
75
|
-
"**/*.test.(js|jsx|ts|tsx)",
|
|
76
|
-
"**/*.spec.(js|jsx|ts|tsx)",
|
|
77
|
-
"**/*.stories.(js|jsx|ts|tsx)"
|
|
78
|
-
]
|
|
79
|
-
});
|
|
80
|
-
watcher.on("change", (changed) => {
|
|
81
|
-
const lastHash = hashMap.get(changed);
|
|
82
|
-
const currentHash = md5(
|
|
83
|
-
fs.readFileSync(path.join(appDirectory, changed), "utf8")
|
|
84
|
-
);
|
|
85
|
-
if (currentHash !== lastHash) {
|
|
86
|
-
debug(`file change: %s`, changed);
|
|
87
|
-
hashMap.set(changed, currentHash);
|
|
88
|
-
hooksRunner.fileChange({ filename: changed, eventType: "change" });
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
watcher.on("add", (name) => {
|
|
92
|
-
debug(`add file: %s`, name);
|
|
93
|
-
const currentHash = md5(
|
|
94
|
-
fs.readFileSync(path.join(appDirectory, name), "utf8")
|
|
95
|
-
);
|
|
96
|
-
hashMap.set(name, currentHash);
|
|
97
|
-
hooksRunner.fileChange({ filename: name, eventType: "add" });
|
|
98
|
-
});
|
|
99
|
-
watcher.on("unlink", (name) => {
|
|
100
|
-
debug(`remove file: %s`, name);
|
|
101
|
-
if (hashMap.has(name)) {
|
|
102
|
-
hashMap.delete(name);
|
|
103
|
-
}
|
|
104
|
-
hooksRunner.fileChange({ filename: name, eventType: "unlink" });
|
|
105
|
-
});
|
|
106
|
-
watcher.on("error", (err) => {
|
|
107
|
-
throw err;
|
|
108
|
-
});
|
|
109
|
-
return watcher;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
export {
|
|
113
|
-
addServerConfigToDeps,
|
|
114
|
-
createFileWatcher
|
|
115
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { IAppContext, ToRunners } from '@modern-js/core';
|
|
2
|
-
import { AppToolsHooks } from '../types/hooks';
|
|
3
|
-
export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
|
|
4
|
-
export declare const createFileWatcher: (appContext: IAppContext, configDir: string | undefined, hooksRunner: ToRunners<AppToolsHooks>) => Promise<import("@modern-js/utils").FSWatcher | undefined>;
|