openmrs 6.3.1-pre.2965 → 6.3.1-pre.2986
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/default-rspack-config.js +3 -0
- package/dist/cli.js +6 -1
- package/dist/commands/assemble.js +2 -2
- package/dist/commands/develop.js +5 -4
- package/dist/utils/debugger.js +18 -7
- package/dist/utils/{webpack.js → devserver.js} +4 -4
- package/dist/utils/importmap.js +17 -9
- package/package.json +20 -16
- package/src/cli.ts +7 -1
- package/src/commands/assemble.ts +2 -2
- package/src/commands/develop.ts +11 -11
- package/src/utils/debugger.ts +27 -10
- package/src/utils/{webpack.ts → devserver.ts} +2 -2
- package/src/utils/importmap.ts +18 -8
package/dist/cli.js
CHANGED
|
@@ -165,11 +165,16 @@ yargs_1.default.command('develop', 'Starts a new frontend module development ses
|
|
|
165
165
|
default: false,
|
|
166
166
|
describe: 'Determines if a service worker should be installed for offline support.',
|
|
167
167
|
type: 'boolean',
|
|
168
|
+
})
|
|
169
|
+
.option('use-rspack', {
|
|
170
|
+
default: undefined,
|
|
171
|
+
describe: "Set this flag to force the CLI to attempt to use the Rspack Dev Server. Note that this will fail if the project you are using it in doesn't use Rspack.",
|
|
172
|
+
type: 'boolean',
|
|
168
173
|
}), async (args) => runCommand('runDevelop', {
|
|
169
174
|
configUrls: args['config-url'],
|
|
170
175
|
configFiles: args['config-file'],
|
|
171
176
|
...args,
|
|
172
|
-
...(0, utils_1.proxyImportmapAndRoutes)(await (0, utils_1.mergeImportmapAndRoutes)(await (0, utils_1.getImportmapAndRoutes)(args.importmap, args.routes, args.port), await (0, utils_1.runProject)(args.port, args.sources), args.backend, args.spaPath), args.backend, args.spaPath),
|
|
177
|
+
...(0, utils_1.proxyImportmapAndRoutes)(await (0, utils_1.mergeImportmapAndRoutes)(await (0, utils_1.getImportmapAndRoutes)(args.importmap, args.routes, args.port), await (0, utils_1.runProject)(args.port, args.sources, args['use-rspack']), args.backend, args.spaPath), args.backend, args.spaPath),
|
|
173
178
|
}));
|
|
174
179
|
yargs_1.default.command('build', 'Builds a new app shell.', (argv) => argv
|
|
175
180
|
.option('target', {
|
|
@@ -9,7 +9,7 @@ const node_fs_1 = require("node:fs");
|
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
10
10
|
const node_stream_1 = require("node:stream");
|
|
11
11
|
const inquirer_1 = require("inquirer");
|
|
12
|
-
const rimraf_1 =
|
|
12
|
+
const rimraf_1 = require("rimraf");
|
|
13
13
|
const axios_1 = __importDefault(require("axios"));
|
|
14
14
|
const npm_registry_fetch_1 = __importDefault(require("npm-registry-fetch"));
|
|
15
15
|
const pacote_1 = __importDefault(require("pacote"));
|
|
@@ -174,7 +174,7 @@ async function runAssemble(args) {
|
|
|
174
174
|
(0, utils_1.logInfo)(`Assembling dependencies and building import map and routes registry...`);
|
|
175
175
|
const { frontendModules = {}, publicUrl = '.' } = config;
|
|
176
176
|
if (args.fresh && (0, node_fs_1.existsSync)(args.target)) {
|
|
177
|
-
await
|
|
177
|
+
await (0, rimraf_1.rimraf)(args.target);
|
|
178
178
|
}
|
|
179
179
|
await (0, promises_1.mkdir)(args.target, { recursive: true });
|
|
180
180
|
await Promise.all(Object.keys(frontendModules).map(async (esmName) => {
|
package/dist/commands/develop.js
CHANGED
|
@@ -142,10 +142,11 @@ async function runDevelop(args) {
|
|
|
142
142
|
(0, utils_1.logInfo)(`Listening at http://${host}:${port}`);
|
|
143
143
|
(0, utils_1.logInfo)(`SPA available at ${pageUrl}`);
|
|
144
144
|
if (open) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
Promise.resolve().then(() => __importStar(require('open'))).then(({ default: open }) => {
|
|
146
|
+
setTimeout(() => open(pageUrl, { wait: false }).catch(() => {
|
|
147
|
+
(0, utils_1.logWarn)(`Unable to open "${pageUrl}" in browser. If you are running in a headless environment, please do not use the --open flag.`);
|
|
148
|
+
}), 2000);
|
|
149
|
+
});
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
return new Promise(() => { });
|
package/dist/utils/debugger.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@rspack/core");
|
|
7
|
+
const dev_server_1 = require("@rspack/dev-server");
|
|
3
8
|
const node_path_1 = require("node:path");
|
|
9
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
10
|
+
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
4
11
|
const logger_1 = require("./logger");
|
|
5
12
|
function getWebpackEnv() {
|
|
6
13
|
return {
|
|
@@ -17,20 +24,24 @@ function loadConfig(configPath) {
|
|
|
17
24
|
}
|
|
18
25
|
return content;
|
|
19
26
|
}
|
|
20
|
-
function
|
|
21
|
-
const Webpack = require('webpack');
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
23
|
-
const WebpackDevServer = require('webpack-dev-server');
|
|
27
|
+
function startDevServer(configPath, port, useRspack = false) {
|
|
24
28
|
const config = loadConfig(configPath);
|
|
25
|
-
const compiler = Webpack(config);
|
|
26
29
|
const devServerOptions = {
|
|
27
30
|
...config.devServer,
|
|
28
31
|
port,
|
|
29
32
|
static: (0, node_path_1.dirname)(configPath),
|
|
30
33
|
};
|
|
31
|
-
|
|
34
|
+
let server;
|
|
35
|
+
if (!useRspack) {
|
|
36
|
+
const compiler = (0, webpack_1.default)(config);
|
|
37
|
+
server = new webpack_dev_server_1.default(devServerOptions, compiler);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const compiler = (0, core_1.rspack)(config);
|
|
41
|
+
server = new dev_server_1.RspackDevServer(devServerOptions, compiler);
|
|
42
|
+
}
|
|
32
43
|
server.startCallback(() => {
|
|
33
44
|
(0, logger_1.logInfo)(`Listening at http://localhost:${port}`);
|
|
34
45
|
});
|
|
35
46
|
}
|
|
36
|
-
process.on('message', ({ source, port }) =>
|
|
47
|
+
process.on('message', ({ source, port, useRspack }) => startDevServer(source, port, useRspack));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.startDevServer = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
|
-
function
|
|
6
|
+
function startDevServer(source, port, cwd = process.cwd(), useRspack = false) {
|
|
7
7
|
const runner = (0, path_1.resolve)(__dirname, 'debugger.js');
|
|
8
8
|
const ps = (0, child_process_1.fork)(runner, [], { cwd });
|
|
9
|
-
ps.send({ source, port });
|
|
9
|
+
ps.send({ source, port, useRspack });
|
|
10
10
|
return ps;
|
|
11
11
|
}
|
|
12
|
-
exports.
|
|
12
|
+
exports.startDevServer = startDevServer;
|
package/dist/utils/importmap.js
CHANGED
|
@@ -11,7 +11,7 @@ const node_path_1 = require("node:path");
|
|
|
11
11
|
const node_fs_1 = require("node:fs");
|
|
12
12
|
const child_process_1 = require("child_process");
|
|
13
13
|
const logger_1 = require("./logger");
|
|
14
|
-
const
|
|
14
|
+
const devserver_1 = require("./devserver");
|
|
15
15
|
const dependencies_1 = require("./dependencies");
|
|
16
16
|
async function readImportmap(path, backend, spaPath) {
|
|
17
17
|
if (path.startsWith('http://') || path.startsWith('https://')) {
|
|
@@ -111,14 +111,14 @@ async function matchAny(baseDir, patterns) {
|
|
|
111
111
|
return matches;
|
|
112
112
|
}
|
|
113
113
|
const defaultConfigPath = (0, node_path_1.resolve)(__dirname, '..', '..', 'default-webpack-config.js');
|
|
114
|
-
function
|
|
114
|
+
function runProjectDevServer(configPath, port, project, sourceDirectory, importMap, routes, useRspack = false) {
|
|
115
115
|
const bundle = (0, dependencies_1.getMainBundle)(project);
|
|
116
116
|
const host = `http://localhost:${port}`;
|
|
117
|
-
(0,
|
|
117
|
+
(0, devserver_1.startDevServer)(configPath, port, sourceDirectory, useRspack);
|
|
118
118
|
importMap[project.name] = `${host}/${bundle.name}`;
|
|
119
119
|
routes[project.name] = (0, dependencies_1.getAppRoutes)(sourceDirectory, project);
|
|
120
120
|
}
|
|
121
|
-
async function runProject(basePort, sourceDirectoryPatterns) {
|
|
121
|
+
async function runProject(basePort, sourceDirectoryPatterns, useRspack) {
|
|
122
122
|
const baseDir = process.cwd();
|
|
123
123
|
const sourceDirectories = await matchAny(baseDir, sourceDirectoryPatterns);
|
|
124
124
|
const importMap = {};
|
|
@@ -128,8 +128,11 @@ async function runProject(basePort, sourceDirectoryPatterns) {
|
|
|
128
128
|
for (let i = 0; i < sourceDirectories.length; i++) {
|
|
129
129
|
const sourceDirectory = (0, node_path_1.resolve)(baseDir, sourceDirectories[i]);
|
|
130
130
|
const projectFile = (0, node_path_1.resolve)(sourceDirectory, 'package.json');
|
|
131
|
-
const configPath = (0, node_path_1.resolve)(sourceDirectory, 'webpack.config.js');
|
|
132
131
|
const routesFile = (0, node_path_1.resolve)(sourceDirectory, 'src', 'routes.json');
|
|
132
|
+
const configPath = (0, node_path_1.resolve)(sourceDirectory, 'webpack.config.js');
|
|
133
|
+
const rspackConfigPath = (0, node_path_1.resolve)(sourceDirectory, 'rspack.config.js');
|
|
134
|
+
const hasConfig = typeof useRspack !== 'undefined' ? !useRspack : (0, node_fs_1.existsSync)(configPath);
|
|
135
|
+
const hasRspackConfig = typeof useRspack !== 'undefined' ? useRspack : (0, node_fs_1.existsSync)(rspackConfigPath);
|
|
133
136
|
const port = basePort + i + 1;
|
|
134
137
|
(0, logger_1.logInfo)(`Looking in directory "${sourceDirectory}" ...`);
|
|
135
138
|
if (!(0, node_fs_1.existsSync)(projectFile)) {
|
|
@@ -151,14 +154,19 @@ async function runProject(basePort, sourceDirectoryPatterns) {
|
|
|
151
154
|
// connect to either startup.url or a computed value based on startup.host
|
|
152
155
|
importMap[project.name] = startup.url || `${startup.host}/${(0, node_path_1.basename)(project.browser)}`;
|
|
153
156
|
}
|
|
154
|
-
else if (!
|
|
157
|
+
else if (!hasConfig && !hasRspackConfig) {
|
|
155
158
|
// try to locate and run via default webpack
|
|
156
159
|
(0, logger_1.logWarn)(`No "webpack.config.js" found in directory "${sourceDirectory}". Trying to use default config ...`);
|
|
157
|
-
|
|
160
|
+
runProjectDevServer(defaultConfigPath, port, project, sourceDirectory, importMap, routes);
|
|
158
161
|
}
|
|
159
162
|
else {
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
if (hasConfig) {
|
|
164
|
+
// run via specialized webpack.config.js
|
|
165
|
+
runProjectDevServer(configPath, port, project, sourceDirectory, importMap, routes);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
runProjectDevServer(rspackConfigPath, port, project, sourceDirectory, importMap, routes, true);
|
|
169
|
+
}
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
172
|
(0, logger_1.logInfo)(`Assembled dynamic import map and routes for packages (${Object.keys(importMap).join(', ')}).`);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openmrs",
|
|
3
|
-
"version": "6.3.1-pre.
|
|
3
|
+
"version": "6.3.1-pre.2986",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "./dist/cli.js",
|
|
7
|
-
"types": "
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">= 12.0.0"
|
|
10
10
|
},
|
|
@@ -29,10 +29,14 @@
|
|
|
29
29
|
],
|
|
30
30
|
"homepage": "https://github.com/openmrs/openmrs-esm-core#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@openmrs/esm-app-shell": "6.3.1-pre.
|
|
33
|
-
"@openmrs/
|
|
32
|
+
"@openmrs/esm-app-shell": "6.3.1-pre.2986",
|
|
33
|
+
"@openmrs/rspack-config": "6.3.1-pre.2986",
|
|
34
|
+
"@openmrs/webpack-config": "6.3.1-pre.2986",
|
|
34
35
|
"@pnpm/npm-conf": "^2.1.0",
|
|
35
|
-
"@
|
|
36
|
+
"@rspack/cli": "^1.3.11",
|
|
37
|
+
"@rspack/core": "^1.3.11",
|
|
38
|
+
"@rspack/dev-server": "^1.1.2",
|
|
39
|
+
"@swc/core": "^1.11.29",
|
|
36
40
|
"autoprefixer": "^10.4.20",
|
|
37
41
|
"axios": "^0.21.4",
|
|
38
42
|
"browserslist-config-openmrs": "^1.0.1",
|
|
@@ -49,34 +53,34 @@
|
|
|
49
53
|
"mini-css-extract-plugin": "^2.9.1",
|
|
50
54
|
"node-watch": "^0.7.4",
|
|
51
55
|
"npm-registry-fetch": "^14.0.5",
|
|
56
|
+
"open": "^10.1.1",
|
|
52
57
|
"pacote": "^15.0.0",
|
|
53
58
|
"postcss": "^8.4.41",
|
|
54
59
|
"postcss-loader": "^6.2.1",
|
|
55
|
-
"rimraf": "^
|
|
56
|
-
"sass-
|
|
60
|
+
"rimraf": "^6.0.1",
|
|
61
|
+
"sass-embedded": "^1.89.0",
|
|
62
|
+
"sass-loader": "^16.0.5",
|
|
57
63
|
"semver": "^7.3.4",
|
|
58
64
|
"style-loader": "^3.3.4",
|
|
59
65
|
"swc-loader": "^0.2.6",
|
|
60
66
|
"tar": "^6.0.5",
|
|
61
|
-
"typescript": "^4.
|
|
62
|
-
"webpack": "^5.
|
|
63
|
-
"webpack-bundle-analyzer": "^4.
|
|
64
|
-
"webpack-cli": "^
|
|
65
|
-
"webpack-dev-server": "^
|
|
67
|
+
"typescript": "^4.7.0",
|
|
68
|
+
"webpack": "^5.99.9",
|
|
69
|
+
"webpack-bundle-analyzer": "^4.10.2",
|
|
70
|
+
"webpack-cli": "^6.0.1",
|
|
71
|
+
"webpack-dev-server": "^5.2.1",
|
|
66
72
|
"webpack-pwa-manifest": "^4.3.0",
|
|
67
|
-
"webpack-stats-plugin": "^1.
|
|
73
|
+
"webpack-stats-plugin": "^1.1.3",
|
|
68
74
|
"workbox-webpack-plugin": "^6.4.1",
|
|
69
75
|
"yargs": "^17.6.2"
|
|
70
76
|
},
|
|
71
77
|
"devDependencies": {
|
|
72
78
|
"@types/express": "^4.11.1",
|
|
73
79
|
"@types/glob": "^7.1.1",
|
|
74
|
-
"@types/inquirer": "^6.5.0",
|
|
75
80
|
"@types/lodash-es": "^4.17.12",
|
|
76
81
|
"@types/node": "^18.11.11",
|
|
77
82
|
"@types/pacote": "^11.1.8",
|
|
78
|
-
"@types/react": "^18
|
|
79
|
-
"@types/rimraf": "^2.0.5",
|
|
83
|
+
"@types/react": "^18",
|
|
80
84
|
"@types/semver": "^7",
|
|
81
85
|
"@types/tar": "^4.0.3"
|
|
82
86
|
},
|
package/src/cli.ts
CHANGED
|
@@ -194,6 +194,12 @@ yargs.command(
|
|
|
194
194
|
default: false,
|
|
195
195
|
describe: 'Determines if a service worker should be installed for offline support.',
|
|
196
196
|
type: 'boolean',
|
|
197
|
+
})
|
|
198
|
+
.option('use-rspack', {
|
|
199
|
+
default: undefined,
|
|
200
|
+
describe:
|
|
201
|
+
"Set this flag to force the CLI to attempt to use the Rspack Dev Server. Note that this will fail if the project you are using it in doesn't use Rspack.",
|
|
202
|
+
type: 'boolean',
|
|
197
203
|
}),
|
|
198
204
|
async (args) =>
|
|
199
205
|
runCommand('runDevelop', {
|
|
@@ -203,7 +209,7 @@ yargs.command(
|
|
|
203
209
|
...proxyImportmapAndRoutes(
|
|
204
210
|
await mergeImportmapAndRoutes(
|
|
205
211
|
await getImportmapAndRoutes(args.importmap, args.routes, args.port),
|
|
206
|
-
await runProject(args.port, args.sources),
|
|
212
|
+
await runProject(args.port, args.sources, args['use-rspack']),
|
|
207
213
|
args.backend,
|
|
208
214
|
args.spaPath,
|
|
209
215
|
),
|
package/src/commands/assemble.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync } from 'node:fs';
|
|
|
3
3
|
import { resolve, dirname, basename } from 'node:path';
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import { prompt, type Question } from 'inquirer';
|
|
6
|
-
import rimraf from 'rimraf';
|
|
6
|
+
import { rimraf } from 'rimraf';
|
|
7
7
|
import axios from 'axios';
|
|
8
8
|
import npmRegistryFetch from 'npm-registry-fetch';
|
|
9
9
|
import pacote from 'pacote';
|
|
@@ -250,7 +250,7 @@ export async function runAssemble(args: AssembleArgs) {
|
|
|
250
250
|
const { frontendModules = {}, publicUrl = '.' } = config;
|
|
251
251
|
|
|
252
252
|
if (args.fresh && existsSync(args.target)) {
|
|
253
|
-
await
|
|
253
|
+
await rimraf(args.target);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
await mkdir(args.target, { recursive: true });
|
package/src/commands/develop.ts
CHANGED
|
@@ -170,17 +170,17 @@ export async function runDevelop(args: DevelopArgs) {
|
|
|
170
170
|
logInfo(`SPA available at ${pageUrl}`);
|
|
171
171
|
|
|
172
172
|
if (open) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
);
|
|
173
|
+
import('open').then(({ default: open }) => {
|
|
174
|
+
setTimeout(
|
|
175
|
+
() =>
|
|
176
|
+
open(pageUrl, { wait: false }).catch(() => {
|
|
177
|
+
logWarn(
|
|
178
|
+
`Unable to open "${pageUrl}" in browser. If you are running in a headless environment, please do not use the --open flag.`,
|
|
179
|
+
);
|
|
180
|
+
}),
|
|
181
|
+
2000,
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
186
|
|
package/src/utils/debugger.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rspack,
|
|
3
|
+
type Configuration as RspackConfiguration,
|
|
4
|
+
type DevServer as RspackDevServerConfiguration,
|
|
5
|
+
} from '@rspack/core';
|
|
6
|
+
import { RspackDevServer } from '@rspack/dev-server';
|
|
1
7
|
import { dirname } from 'node:path';
|
|
8
|
+
import webpack, { type Configuration as WebpackConfiguration } from 'webpack';
|
|
9
|
+
import WebpackDevServer from 'webpack-dev-server';
|
|
2
10
|
import { logInfo } from './logger';
|
|
3
|
-
import type { Configuration } from 'webpack';
|
|
4
11
|
|
|
5
12
|
function getWebpackEnv() {
|
|
6
13
|
return {
|
|
@@ -11,32 +18,42 @@ function getWebpackEnv() {
|
|
|
11
18
|
};
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
function loadConfig(configPath: string) {
|
|
15
|
-
const content:
|
|
21
|
+
function loadConfig(configPath: string): WebpackConfiguration | RspackConfiguration {
|
|
22
|
+
const content:
|
|
23
|
+
| WebpackConfiguration
|
|
24
|
+
| RspackConfiguration
|
|
25
|
+
| ((env: Record<string, unknown>) => WebpackConfiguration | RspackConfiguration) = require(configPath);
|
|
16
26
|
if (typeof content === 'function') {
|
|
17
27
|
return content(getWebpackEnv());
|
|
18
28
|
}
|
|
19
29
|
return content;
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
function
|
|
23
|
-
const Webpack = require('webpack');
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
25
|
-
const WebpackDevServer: typeof import('webpack-dev-server') = require('webpack-dev-server');
|
|
32
|
+
function startDevServer(configPath: string, port: number, useRspack: boolean = false) {
|
|
26
33
|
const config = loadConfig(configPath);
|
|
27
34
|
|
|
28
|
-
const compiler = Webpack(config);
|
|
29
35
|
const devServerOptions = {
|
|
30
36
|
...config.devServer,
|
|
31
37
|
port,
|
|
32
38
|
static: dirname(configPath),
|
|
33
39
|
};
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
let server: WebpackDevServer | RspackDevServer;
|
|
42
|
+
if (!useRspack) {
|
|
43
|
+
const compiler = webpack(config as WebpackConfiguration);
|
|
44
|
+
|
|
45
|
+
server = new WebpackDevServer(devServerOptions as WebpackDevServer.Configuration, compiler);
|
|
46
|
+
} else {
|
|
47
|
+
const compiler = rspack(config as RspackConfiguration);
|
|
48
|
+
|
|
49
|
+
server = new RspackDevServer(devServerOptions as RspackDevServerConfiguration, compiler);
|
|
50
|
+
}
|
|
36
51
|
|
|
37
52
|
server.startCallback(() => {
|
|
38
53
|
logInfo(`Listening at http://localhost:${port}`);
|
|
39
54
|
});
|
|
40
55
|
}
|
|
41
56
|
|
|
42
|
-
process.on('message', ({ source, port }: { source: string; port: number }) =>
|
|
57
|
+
process.on('message', ({ source, port, useRspack }: { source: string; port: number; useRspack: boolean }) =>
|
|
58
|
+
startDevServer(source, port, useRspack),
|
|
59
|
+
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { fork } from 'child_process';
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function startDevServer(source: string, port: number, cwd = process.cwd(), useRspack: boolean = false) {
|
|
5
5
|
const runner = resolve(__dirname, 'debugger.js');
|
|
6
6
|
const ps = fork(runner, [], { cwd });
|
|
7
7
|
|
|
8
|
-
ps.send({ source, port });
|
|
8
|
+
ps.send({ source, port, useRspack });
|
|
9
9
|
|
|
10
10
|
return ps;
|
|
11
11
|
}
|
package/src/utils/importmap.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { basename, resolve } from 'node:path';
|
|
|
5
5
|
import { existsSync, readFileSync } from 'node:fs';
|
|
6
6
|
import { exec } from 'child_process';
|
|
7
7
|
import { logFail, logInfo, logWarn } from './logger';
|
|
8
|
-
import {
|
|
8
|
+
import { startDevServer } from './devserver';
|
|
9
9
|
import { getMainBundle, getAppRoutes } from './dependencies';
|
|
10
10
|
|
|
11
11
|
async function readImportmap(path: string, backend?: string, spaPath?: string) {
|
|
@@ -146,18 +146,19 @@ async function matchAny(baseDir: string, patterns: Array<string>) {
|
|
|
146
146
|
|
|
147
147
|
const defaultConfigPath = resolve(__dirname, '..', '..', 'default-webpack-config.js');
|
|
148
148
|
|
|
149
|
-
function
|
|
149
|
+
function runProjectDevServer(
|
|
150
150
|
configPath: string,
|
|
151
151
|
port: number,
|
|
152
152
|
project: any,
|
|
153
153
|
sourceDirectory: string,
|
|
154
154
|
importMap: Record<string, string>,
|
|
155
155
|
routes: Record<string, unknown>,
|
|
156
|
+
useRspack: boolean = false,
|
|
156
157
|
) {
|
|
157
158
|
const bundle = getMainBundle(project);
|
|
158
159
|
const host = `http://localhost:${port}`;
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
startDevServer(configPath, port, sourceDirectory, useRspack);
|
|
161
162
|
importMap[project.name] = `${host}/${bundle.name}`;
|
|
162
163
|
routes[project.name] = getAppRoutes(sourceDirectory, project);
|
|
163
164
|
}
|
|
@@ -165,6 +166,7 @@ function runProjectWebpack(
|
|
|
165
166
|
export async function runProject(
|
|
166
167
|
basePort: number,
|
|
167
168
|
sourceDirectoryPatterns: Array<string>,
|
|
169
|
+
useRspack?: boolean,
|
|
168
170
|
): Promise<{
|
|
169
171
|
importMap: Record<string, string>;
|
|
170
172
|
routes: Record<string, unknown>;
|
|
@@ -181,9 +183,13 @@ export async function runProject(
|
|
|
181
183
|
for (let i = 0; i < sourceDirectories.length; i++) {
|
|
182
184
|
const sourceDirectory = resolve(baseDir, sourceDirectories[i]);
|
|
183
185
|
const projectFile = resolve(sourceDirectory, 'package.json');
|
|
184
|
-
const configPath = resolve(sourceDirectory, 'webpack.config.js');
|
|
185
186
|
const routesFile = resolve(sourceDirectory, 'src', 'routes.json');
|
|
186
187
|
|
|
188
|
+
const configPath = resolve(sourceDirectory, 'webpack.config.js');
|
|
189
|
+
const rspackConfigPath = resolve(sourceDirectory, 'rspack.config.js');
|
|
190
|
+
const hasConfig = typeof useRspack !== 'undefined' ? !useRspack : existsSync(configPath);
|
|
191
|
+
const hasRspackConfig = typeof useRspack !== 'undefined' ? useRspack : existsSync(rspackConfigPath);
|
|
192
|
+
|
|
187
193
|
const port = basePort + i + 1;
|
|
188
194
|
|
|
189
195
|
logInfo(`Looking in directory "${sourceDirectory}" ...`);
|
|
@@ -209,14 +215,18 @@ export async function runProject(
|
|
|
209
215
|
cp.stderr?.pipe(process.stderr);
|
|
210
216
|
// connect to either startup.url or a computed value based on startup.host
|
|
211
217
|
importMap[project.name] = startup.url || `${startup.host}/${basename(project.browser)}`;
|
|
212
|
-
} else if (!
|
|
218
|
+
} else if (!hasConfig && !hasRspackConfig) {
|
|
213
219
|
// try to locate and run via default webpack
|
|
214
220
|
logWarn(`No "webpack.config.js" found in directory "${sourceDirectory}". Trying to use default config ...`);
|
|
215
221
|
|
|
216
|
-
|
|
222
|
+
runProjectDevServer(defaultConfigPath, port, project, sourceDirectory, importMap, routes);
|
|
217
223
|
} else {
|
|
218
|
-
|
|
219
|
-
|
|
224
|
+
if (hasConfig) {
|
|
225
|
+
// run via specialized webpack.config.js
|
|
226
|
+
runProjectDevServer(configPath, port, project, sourceDirectory, importMap, routes);
|
|
227
|
+
} else {
|
|
228
|
+
runProjectDevServer(rspackConfigPath, port, project, sourceDirectory, importMap, routes, true);
|
|
229
|
+
}
|
|
220
230
|
}
|
|
221
231
|
}
|
|
222
232
|
|