@bleedingdev/modern-js-server 3.2.0-ultramodern.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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/cjs/createDevServer.js +102 -0
- package/dist/cjs/dev-tools/https/index.js +57 -0
- package/dist/cjs/dev-tools/watcher/dependencyTree.js +94 -0
- package/dist/cjs/dev-tools/watcher/index.js +143 -0
- package/dist/cjs/dev-tools/watcher/statsCache.js +95 -0
- package/dist/cjs/dev.js +111 -0
- package/dist/cjs/helpers/devOptions.js +61 -0
- package/dist/cjs/helpers/fileReader.js +53 -0
- package/dist/cjs/helpers/index.js +173 -0
- package/dist/cjs/helpers/mock.js +136 -0
- package/dist/cjs/helpers/repack.js +50 -0
- package/dist/cjs/helpers/utils.js +37 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/types.js +18 -0
- package/dist/esm/createDevServer.mjs +58 -0
- package/dist/esm/dev-tools/https/index.mjs +23 -0
- package/dist/esm/dev-tools/watcher/dependencyTree.mjs +57 -0
- package/dist/esm/dev-tools/watcher/index.mjs +91 -0
- package/dist/esm/dev-tools/watcher/statsCache.mjs +50 -0
- package/dist/esm/dev.mjs +77 -0
- package/dist/esm/helpers/devOptions.mjs +24 -0
- package/dist/esm/helpers/fileReader.mjs +19 -0
- package/dist/esm/helpers/index.mjs +65 -0
- package/dist/esm/helpers/mock.mjs +86 -0
- package/dist/esm/helpers/repack.mjs +16 -0
- package/dist/esm/helpers/utils.mjs +3 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm-node/createDevServer.mjs +59 -0
- package/dist/esm-node/dev-tools/https/index.mjs +28 -0
- package/dist/esm-node/dev-tools/watcher/dependencyTree.mjs +58 -0
- package/dist/esm-node/dev-tools/watcher/index.mjs +93 -0
- package/dist/esm-node/dev-tools/watcher/statsCache.mjs +51 -0
- package/dist/esm-node/dev.mjs +78 -0
- package/dist/esm-node/helpers/devOptions.mjs +25 -0
- package/dist/esm-node/helpers/fileReader.mjs +20 -0
- package/dist/esm-node/helpers/index.mjs +67 -0
- package/dist/esm-node/helpers/mock.mjs +87 -0
- package/dist/esm-node/helpers/repack.mjs +18 -0
- package/dist/esm-node/helpers/utils.mjs +4 -0
- package/dist/esm-node/index.mjs +2 -0
- package/dist/esm-node/types.mjs +1 -0
- package/dist/types/createDevServer.d.ts +8 -0
- package/dist/types/dev-tools/https/index.d.ts +6 -0
- package/dist/types/dev-tools/watcher/dependencyTree.d.ts +28 -0
- package/dist/types/dev-tools/watcher/index.d.ts +17 -0
- package/dist/types/dev-tools/watcher/statsCache.d.ts +10 -0
- package/dist/types/dev.d.ts +9 -0
- package/dist/types/helpers/devOptions.d.ts +11 -0
- package/dist/types/helpers/fileReader.d.ts +3 -0
- package/dist/types/helpers/index.d.ts +15 -0
- package/dist/types/helpers/mock.d.ts +16 -0
- package/dist/types/helpers/repack.d.ts +2 -0
- package/dist/types/helpers/utils.d.ts +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types.d.ts +56 -0
- package/package.json +89 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
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/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
14
|
+
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
createDevServer: ()=>createDevServer
|
|
37
|
+
});
|
|
38
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
39
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
40
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
41
|
+
const node_namespaceObject = require("@modern-js/server-core/node");
|
|
42
|
+
const external_dev_js_namespaceObject = require("./dev.js");
|
|
43
|
+
const index_js_namespaceObject = require("./helpers/index.js");
|
|
44
|
+
async function createDevServer(options, applyPlugins) {
|
|
45
|
+
const { config, pwd, serverConfigPath, builder } = options;
|
|
46
|
+
const dev = (0, index_js_namespaceObject.getDevOptions)(options.dev);
|
|
47
|
+
const distDir = external_node_path_default().resolve(pwd, config.output.distPath?.root || 'dist');
|
|
48
|
+
const serverConfig = await (0, node_namespaceObject.loadServerRuntimeConfig)(serverConfigPath) || {};
|
|
49
|
+
const prodServerOptions = {
|
|
50
|
+
...options,
|
|
51
|
+
pwd: distDir,
|
|
52
|
+
serverConfig: {
|
|
53
|
+
...serverConfig,
|
|
54
|
+
...options.serverConfig
|
|
55
|
+
},
|
|
56
|
+
plugins: [
|
|
57
|
+
...serverConfig.plugins || [],
|
|
58
|
+
...options.plugins || []
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
const server = (0, server_core_namespaceObject.createServerBase)(prodServerOptions);
|
|
62
|
+
const devHttpsOption = 'object' == typeof dev && dev.https;
|
|
63
|
+
const isHttp2 = !!devHttpsOption;
|
|
64
|
+
let nodeServer;
|
|
65
|
+
if (devHttpsOption) {
|
|
66
|
+
const { genHttpsOptions } = await import("./dev-tools/https/index.js");
|
|
67
|
+
const httpsOptions = await genHttpsOptions(devHttpsOption, pwd);
|
|
68
|
+
nodeServer = await (0, node_namespaceObject.createNodeServer)(server.handle.bind(server), httpsOptions, isHttp2);
|
|
69
|
+
} else nodeServer = await (0, node_namespaceObject.createNodeServer)(server.handle.bind(server));
|
|
70
|
+
const promise = (0, index_js_namespaceObject.getDevAssetPrefix)(builder);
|
|
71
|
+
let compiler = null;
|
|
72
|
+
builder?.onAfterCreateCompiler((context)=>{
|
|
73
|
+
compiler = context.compiler;
|
|
74
|
+
});
|
|
75
|
+
const builderDevServer = await builder?.createDevServer({
|
|
76
|
+
runCompile: options.runCompile
|
|
77
|
+
});
|
|
78
|
+
server.addPlugins([
|
|
79
|
+
(0, external_dev_js_namespaceObject.devPlugin)({
|
|
80
|
+
...options,
|
|
81
|
+
builderDevServer
|
|
82
|
+
}, compiler)
|
|
83
|
+
]);
|
|
84
|
+
const assetPrefix = await promise;
|
|
85
|
+
if (assetPrefix) prodServerOptions.config.output.assetPrefix = assetPrefix;
|
|
86
|
+
await applyPlugins(server, prodServerOptions, nodeServer);
|
|
87
|
+
await server.init();
|
|
88
|
+
const afterListen = async ()=>{
|
|
89
|
+
await builderDevServer?.afterListen();
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
server: nodeServer,
|
|
93
|
+
afterListen
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
exports.createDevServer = __webpack_exports__.createDevServer;
|
|
97
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
98
|
+
"createDevServer"
|
|
99
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
100
|
+
Object.defineProperty(exports, '__esModule', {
|
|
101
|
+
value: true
|
|
102
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
genHttpsOptions: ()=>genHttpsOptions
|
|
28
|
+
});
|
|
29
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
30
|
+
const genHttpsOptions = async (userOptions, pwd)=>{
|
|
31
|
+
const httpsOptions = 'boolean' == typeof userOptions ? {} : userOptions;
|
|
32
|
+
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
33
|
+
let devcertPath;
|
|
34
|
+
try {
|
|
35
|
+
devcertPath = (0, utils_namespaceObject.tryResolve)('devcert', pwd, __dirname);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
const packageManager = await (0, utils_namespaceObject.getPackageManager)(pwd);
|
|
38
|
+
const command = utils_namespaceObject.chalk.yellow.bold(`${packageManager} add devcert@1.2.2 -D`);
|
|
39
|
+
utils_namespaceObject.logger.error('You have enabled "dev.https" option, but the "devcert" package is not installed.');
|
|
40
|
+
utils_namespaceObject.logger.error(`Please run ${command} to install manually, otherwise the https can not work.`);
|
|
41
|
+
throw new Error('[https] "devcert" is not found.');
|
|
42
|
+
}
|
|
43
|
+
const devcert = require(devcertPath);
|
|
44
|
+
const selfsign = await devcert.certificateFor([
|
|
45
|
+
'localhost'
|
|
46
|
+
]);
|
|
47
|
+
return selfsign;
|
|
48
|
+
}
|
|
49
|
+
return httpsOptions;
|
|
50
|
+
};
|
|
51
|
+
exports.genHttpsOptions = __webpack_exports__.genHttpsOptions;
|
|
52
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
53
|
+
"genHttpsOptions"
|
|
54
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
55
|
+
Object.defineProperty(exports, '__esModule', {
|
|
56
|
+
value: true
|
|
57
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
DependencyTree: ()=>DependencyTree,
|
|
28
|
+
defaultIgnores: ()=>defaultIgnores
|
|
29
|
+
});
|
|
30
|
+
const external_minimatch_namespaceObject = require("minimatch");
|
|
31
|
+
const defaultIgnores = [
|
|
32
|
+
'**/coverage/**',
|
|
33
|
+
'**/node_modules/**',
|
|
34
|
+
'**/.*/**',
|
|
35
|
+
'**/*.d.ts',
|
|
36
|
+
'**/*.log'
|
|
37
|
+
];
|
|
38
|
+
class DependencyTree {
|
|
39
|
+
getNode(path) {
|
|
40
|
+
return this.tree.get(path);
|
|
41
|
+
}
|
|
42
|
+
update(cache) {
|
|
43
|
+
this.tree.clear();
|
|
44
|
+
Object.keys(cache).forEach((path)=>{
|
|
45
|
+
if (!this.shouldIgnore(path)) {
|
|
46
|
+
const module = cache[path];
|
|
47
|
+
this.tree.set(module.filename, {
|
|
48
|
+
module,
|
|
49
|
+
parent: new Set(),
|
|
50
|
+
children: new Set()
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
for (const treeNode of this.tree.values()){
|
|
55
|
+
const { parent } = treeNode.module;
|
|
56
|
+
const { children } = treeNode.module;
|
|
57
|
+
if (parent && !this.shouldIgnore(parent.filename)) {
|
|
58
|
+
const parentTreeNode = this.tree.get(parent.filename);
|
|
59
|
+
if (parentTreeNode) treeNode.parent.add(parentTreeNode);
|
|
60
|
+
}
|
|
61
|
+
children?.forEach((child)=>{
|
|
62
|
+
if (!this.shouldIgnore(child.filename)) {
|
|
63
|
+
const childTreeNode = this.tree.get(child.filename);
|
|
64
|
+
if (childTreeNode) {
|
|
65
|
+
treeNode.children.add(childTreeNode);
|
|
66
|
+
childTreeNode.parent.add(treeNode);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
shouldIgnore(path) {
|
|
73
|
+
return !path || Boolean(this.ignore.find((rule)=>external_minimatch_namespaceObject.match([
|
|
74
|
+
path
|
|
75
|
+
], rule, {
|
|
76
|
+
dot: true
|
|
77
|
+
}).length > 0));
|
|
78
|
+
}
|
|
79
|
+
constructor(){
|
|
80
|
+
this.tree = new Map();
|
|
81
|
+
this.ignore = [
|
|
82
|
+
...defaultIgnores
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.DependencyTree = __webpack_exports__.DependencyTree;
|
|
87
|
+
exports.defaultIgnores = __webpack_exports__.defaultIgnores;
|
|
88
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
89
|
+
"DependencyTree",
|
|
90
|
+
"defaultIgnores"
|
|
91
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
92
|
+
Object.defineProperty(exports, '__esModule', {
|
|
93
|
+
value: true
|
|
94
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
default: ()=>Watcher,
|
|
37
|
+
defaultWatchOptions: ()=>defaultWatchOptions,
|
|
38
|
+
getWatchedFiles: ()=>getWatchedFiles,
|
|
39
|
+
mergeWatchOptions: ()=>mergeWatchOptions
|
|
40
|
+
});
|
|
41
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
42
|
+
const external_path_namespaceObject = require("path");
|
|
43
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
44
|
+
const external_dependencyTree_js_namespaceObject = require("./dependencyTree.js");
|
|
45
|
+
const external_statsCache_js_namespaceObject = require("./statsCache.js");
|
|
46
|
+
const defaultWatchOptions = {
|
|
47
|
+
ignoreInitial: true,
|
|
48
|
+
ignored: /api\/typings\/.*/
|
|
49
|
+
};
|
|
50
|
+
const getWatchedFiles = (watcher)=>{
|
|
51
|
+
const watched = watcher.getWatched();
|
|
52
|
+
const files = [];
|
|
53
|
+
Object.keys(watched).forEach((dir)=>{
|
|
54
|
+
const dirFiles = watched[dir];
|
|
55
|
+
if (!dirFiles) return;
|
|
56
|
+
dirFiles.forEach((fileName)=>{
|
|
57
|
+
files.push(external_path_default().join(dir, fileName));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return files;
|
|
61
|
+
};
|
|
62
|
+
const mergeWatchOptions = (options)=>{
|
|
63
|
+
const watchOptions = {
|
|
64
|
+
...options
|
|
65
|
+
};
|
|
66
|
+
if (watchOptions) {
|
|
67
|
+
const { ignored } = watchOptions;
|
|
68
|
+
const finalIgnored = ignored ? [
|
|
69
|
+
defaultWatchOptions.ignored,
|
|
70
|
+
...Array.isArray(ignored) ? ignored : [
|
|
71
|
+
ignored
|
|
72
|
+
]
|
|
73
|
+
] : ignored;
|
|
74
|
+
if (finalIgnored) watchOptions.ignored = finalIgnored;
|
|
75
|
+
}
|
|
76
|
+
const finalWatchOptions = {
|
|
77
|
+
...defaultWatchOptions,
|
|
78
|
+
...watchOptions
|
|
79
|
+
};
|
|
80
|
+
return finalWatchOptions;
|
|
81
|
+
};
|
|
82
|
+
class Watcher {
|
|
83
|
+
listen(files, options, callback) {
|
|
84
|
+
const watched = files.filter(Boolean);
|
|
85
|
+
const filenames = watched.map((filename)=>filename.replace(/\\/g, '/'));
|
|
86
|
+
const cache = new external_statsCache_js_namespaceObject.StatsCache();
|
|
87
|
+
const watcher = utils_namespaceObject.chokidar.watch(filenames, options);
|
|
88
|
+
watcher.on('ready', ()=>{
|
|
89
|
+
cache.add(getWatchedFiles(watcher));
|
|
90
|
+
});
|
|
91
|
+
watcher.on('change', (changed)=>{
|
|
92
|
+
if (!utils_namespaceObject.fs.existsSync(changed) || cache.isDiff(changed)) {
|
|
93
|
+
cache.refresh(changed);
|
|
94
|
+
callback(changed, 'change');
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
watcher.on('add', (changed)=>{
|
|
98
|
+
if (!cache.has(changed)) {
|
|
99
|
+
cache.add([
|
|
100
|
+
changed
|
|
101
|
+
]);
|
|
102
|
+
callback(changed, 'add');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
watcher.on('unlink', (changed)=>{
|
|
106
|
+
cache.del(changed);
|
|
107
|
+
callback(changed, 'unlink');
|
|
108
|
+
});
|
|
109
|
+
this.watcher = watcher;
|
|
110
|
+
}
|
|
111
|
+
createDepTree() {
|
|
112
|
+
this.dependencyTree = new external_dependencyTree_js_namespaceObject.DependencyTree();
|
|
113
|
+
}
|
|
114
|
+
updateDepTree() {
|
|
115
|
+
this.dependencyTree?.update(require.cache);
|
|
116
|
+
}
|
|
117
|
+
cleanDepCache(filepath) {
|
|
118
|
+
const node = this.dependencyTree?.getNode(filepath);
|
|
119
|
+
if (node && require.cache[filepath]) {
|
|
120
|
+
delete require.cache[filepath];
|
|
121
|
+
for (const parentNode of node.parent.values())this.cleanDepCache(parentNode.module.filename);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
close() {
|
|
125
|
+
return this.watcher.close();
|
|
126
|
+
}
|
|
127
|
+
constructor(){
|
|
128
|
+
this.dependencyTree = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports["default"] = __webpack_exports__["default"];
|
|
132
|
+
exports.defaultWatchOptions = __webpack_exports__.defaultWatchOptions;
|
|
133
|
+
exports.getWatchedFiles = __webpack_exports__.getWatchedFiles;
|
|
134
|
+
exports.mergeWatchOptions = __webpack_exports__.mergeWatchOptions;
|
|
135
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
136
|
+
"default",
|
|
137
|
+
"defaultWatchOptions",
|
|
138
|
+
"getWatchedFiles",
|
|
139
|
+
"mergeWatchOptions"
|
|
140
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
141
|
+
Object.defineProperty(exports, '__esModule', {
|
|
142
|
+
value: true
|
|
143
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
StatsCache: ()=>StatsCache
|
|
37
|
+
});
|
|
38
|
+
const external_crypto_namespaceObject = require("crypto");
|
|
39
|
+
var external_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_crypto_namespaceObject);
|
|
40
|
+
const external_fs_namespaceObject = require("fs");
|
|
41
|
+
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
42
|
+
class StatsCache {
|
|
43
|
+
add(files) {
|
|
44
|
+
const { cachedHash, cachedSize } = this;
|
|
45
|
+
for (const filename of files)if (external_fs_default().existsSync(filename)) {
|
|
46
|
+
const stats = external_fs_default().statSync(filename);
|
|
47
|
+
if (stats.isFile() && !cachedHash[filename]) {
|
|
48
|
+
cachedHash[filename] = this.hash(stats, filename);
|
|
49
|
+
cachedSize[filename] = stats.size;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
refresh(filename) {
|
|
54
|
+
const { cachedHash, cachedSize } = this;
|
|
55
|
+
if (external_fs_default().existsSync(filename)) {
|
|
56
|
+
const stats = external_fs_default().statSync(filename);
|
|
57
|
+
if (stats.isFile()) {
|
|
58
|
+
cachedHash[filename] = this.hash(stats, filename);
|
|
59
|
+
cachedSize[filename] = stats.size;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
del(filename) {
|
|
64
|
+
if (this.cachedHash[filename]) {
|
|
65
|
+
delete this.cachedHash[filename];
|
|
66
|
+
delete this.cachedSize[filename];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
isDiff(filename) {
|
|
70
|
+
const { cachedHash, cachedSize } = this;
|
|
71
|
+
const stats = external_fs_default().statSync(filename);
|
|
72
|
+
const hash = cachedHash[filename];
|
|
73
|
+
const size = cachedSize[filename];
|
|
74
|
+
if (stats.size !== size) return true;
|
|
75
|
+
if (this.hash(stats, filename) !== hash) return true;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
has(filename) {
|
|
79
|
+
return Boolean(this.cachedHash[filename]);
|
|
80
|
+
}
|
|
81
|
+
hash(stats, filename) {
|
|
82
|
+
return external_crypto_default().createHash('md5').update(external_fs_default().readFileSync(filename)).digest('hex');
|
|
83
|
+
}
|
|
84
|
+
constructor(){
|
|
85
|
+
this.cachedHash = {};
|
|
86
|
+
this.cachedSize = {};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.StatsCache = __webpack_exports__.StatsCache;
|
|
90
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
91
|
+
"StatsCache"
|
|
92
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
93
|
+
Object.defineProperty(exports, '__esModule', {
|
|
94
|
+
value: true
|
|
95
|
+
});
|
package/dist/cjs/dev.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
devPlugin: ()=>devPlugin
|
|
28
|
+
});
|
|
29
|
+
const node_namespaceObject = require("@modern-js/server-core/node");
|
|
30
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
31
|
+
const index_js_namespaceObject = require("./helpers/index.js");
|
|
32
|
+
const devPlugin = (options, compiler)=>({
|
|
33
|
+
name: '@modern-js/plugin-dev',
|
|
34
|
+
setup (api) {
|
|
35
|
+
const { config, pwd, builder, builderDevServer } = options;
|
|
36
|
+
const closeCb = [];
|
|
37
|
+
const dev = (0, index_js_namespaceObject.getDevOptions)(options.dev);
|
|
38
|
+
api.onPrepare(async ()=>{
|
|
39
|
+
const { middlewares: builderMiddlewares, close, connectWebSocket } = builderDevServer || {};
|
|
40
|
+
close && closeCb.push(close);
|
|
41
|
+
const { middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase } = api.getServerContext();
|
|
42
|
+
connectWebSocket && nodeServer && connectWebSocket({
|
|
43
|
+
server: nodeServer
|
|
44
|
+
});
|
|
45
|
+
const hooks = api.getHooks();
|
|
46
|
+
builder?.onDevCompileDone(({ stats })=>{
|
|
47
|
+
if ('server' !== stats.toJson({
|
|
48
|
+
all: false
|
|
49
|
+
}).name) (0, index_js_namespaceObject.onRepack)(distDirectory, hooks);
|
|
50
|
+
});
|
|
51
|
+
const { watchOptions } = config.server;
|
|
52
|
+
const watcher = (0, index_js_namespaceObject.startWatcher)({
|
|
53
|
+
pwd,
|
|
54
|
+
distDir: distDirectory,
|
|
55
|
+
apiDir: apiDirectory || utils_namespaceObject.API_DIR,
|
|
56
|
+
sharedDir: sharedDirectory || utils_namespaceObject.SHARED_DIR,
|
|
57
|
+
watchOptions,
|
|
58
|
+
server: serverBase
|
|
59
|
+
});
|
|
60
|
+
closeCb.push(watcher.close.bind(watcher));
|
|
61
|
+
closeCb.length > 0 && nodeServer?.on('close', ()=>{
|
|
62
|
+
closeCb.forEach((cb)=>{
|
|
63
|
+
cb();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const before = [];
|
|
67
|
+
const after = [];
|
|
68
|
+
const { setupMiddlewares = [] } = dev;
|
|
69
|
+
setupMiddlewares.forEach((handler)=>{
|
|
70
|
+
handler({
|
|
71
|
+
unshift: (...handlers)=>before.unshift(...handlers),
|
|
72
|
+
push: (...handlers)=>after.push(...handlers)
|
|
73
|
+
}, {
|
|
74
|
+
sockWrite: ()=>{}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
before.forEach((middleware, index)=>{
|
|
78
|
+
middlewares.push({
|
|
79
|
+
name: `before-dev-server-${index}`,
|
|
80
|
+
handler: (0, node_namespaceObject.connectMid2HonoMid)(middleware)
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
const mockMiddleware = await (0, index_js_namespaceObject.getMockMiddleware)(pwd);
|
|
84
|
+
middlewares.push({
|
|
85
|
+
name: 'mock-dev',
|
|
86
|
+
handler: mockMiddleware
|
|
87
|
+
});
|
|
88
|
+
builderMiddlewares && middlewares.push({
|
|
89
|
+
name: 'rsbuild-dev',
|
|
90
|
+
handler: (0, node_namespaceObject.connectMid2HonoMid)(builderMiddlewares)
|
|
91
|
+
});
|
|
92
|
+
after.forEach((middleware, index)=>{
|
|
93
|
+
middlewares.push({
|
|
94
|
+
name: `after-dev-server-${index}`,
|
|
95
|
+
handler: (0, node_namespaceObject.connectMid2HonoMid)(middleware)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
middlewares.push({
|
|
99
|
+
name: 'init-file-reader',
|
|
100
|
+
handler: (0, index_js_namespaceObject.initFileReader)(compiler)
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
exports.devPlugin = __webpack_exports__.devPlugin;
|
|
106
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
107
|
+
"devPlugin"
|
|
108
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
109
|
+
Object.defineProperty(exports, '__esModule', {
|
|
110
|
+
value: true
|
|
111
|
+
});
|