@qse/edu-scripts 2.0.0 → 2.0.2

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # 更新日志
2
2
 
3
+ ## 2.0.2 (2926-03-10)
4
+
5
+ - fix: 修复 react 兼容问题
6
+ - fix: 修复 mock 失效
7
+
8
+ ## 2.0.1 (2026-03-09)
9
+
10
+ - fix: 修复 pnpm 启动失败
11
+
3
12
  ## 2.0.0 (2026-03-02)
4
13
 
5
14
  - breakchange: 使用 rspack 重构
package/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # 教育工程化基础框架
2
2
 
3
- svn://192.168.10.168/edu/code/A0.New-system/0A2.front-end-component/edu-scripts/trunk
4
-
5
- <Alert>内网里的 @qsb/edu-scripts 已经弃用,请更换成公网的 @qse/edu-scripts </Alert>
3
+ svn://192.168.10.168/qsedu/code/00.common/02.front-end-component/06.edu-scripts/trunk
6
4
 
7
5
  ## 运行条件
8
6
 
9
- nodejs 版本至少 12+
7
+ nodejs 版本至少 18+
10
8
 
11
9
  ## 快速体验
12
10
 
@@ -95,7 +93,7 @@ npx edu-scripts g override
95
93
  根目录生成 `theme.js` 或 `theme.json`
96
94
 
97
95
  ```js
98
- module.exports = {
96
+ export default {
99
97
  '@primary-color': '#99f',
100
98
  }
101
99
  ```
package/dist/cli.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
- import "@swc-node/register/esm-register";
4
3
  import fs from "fs-extra";
5
4
  import path from "path";
6
5
  import { globby, globbySync } from "globby";
@@ -13,8 +12,9 @@ import { RspackDevServer } from "@rspack/dev-server";
13
12
  import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";
14
13
  import ReactRefreshPlugin from "@rspack/plugin-react-refresh";
15
14
  import HtmlWebpackPlugin from "html-webpack-plugin";
15
+ import path$1 from "node:path";
16
16
  import chokidar from "chokidar";
17
- import { debounce, memoize } from "lodash-es";
17
+ import { debounce, memoize } from "es-toolkit";
18
18
  import express from "express";
19
19
  import cookieParser from "cookie-parser";
20
20
  import multer from "multer";
@@ -31,6 +31,11 @@ import { checkbox, input, select } from "@inquirer/prompts";
31
31
  import cp from "child_process";
32
32
  import tmp from "tmp";
33
33
 
34
+ //#region src/utils/esm-register.ts
35
+ const { register } = createRequire(import.meta.url)("@swc-node/register/register");
36
+ register();
37
+
38
+ //#endregion
34
39
  //#region src/config/paths.ts
35
40
  function resolveApp(...filePath) {
36
41
  return path.resolve(process.cwd(), ...filePath);
@@ -124,7 +129,7 @@ if (!(appConfig.single || appConfig.mainProject)) {
124
129
  console.log(chalk.bgYellow("教育集成工程不能含有 public/static, 现已自动删除"));
125
130
  try {
126
131
  fs.rmSync(paths.static, { recursive: true });
127
- } catch (e) {}
132
+ } catch {}
128
133
  }
129
134
  }
130
135
  if (!fs.existsSync(paths.public) && !process.argv.includes("auto-refactor")) {
@@ -147,6 +152,12 @@ if (appPkg$2.eslintConfig) {
147
152
  console.log(chalk.yellow("export default config"));
148
153
  }
149
154
 
155
+ //#endregion
156
+ //#region src/utils/resolveModule.ts
157
+ function resolveModule(mod) {
158
+ return mod.default ? mod.default : mod;
159
+ }
160
+
150
161
  //#endregion
151
162
  //#region src/config/plugins/postcss-safe-area.ts
152
163
  const expr = new RegExp(`env\\(\\s*(${[
@@ -165,16 +176,18 @@ const PostcssSafeAreaPlugin = () => {
165
176
  };
166
177
  };
167
178
 
168
- //#endregion
169
- //#region src/utils/resolveModule.ts
170
- function resolveModule(mod) {
171
- return mod.default ? mod.default : mod;
172
- }
173
-
174
179
  //#endregion
175
180
  //#region src/config/webpackConfig.ts
176
181
  const require$2 = createRequire(import.meta.url);
177
182
  const appPkg$1 = fs.readJsonSync(paths.package);
183
+ const hasJsxRuntime = (() => {
184
+ try {
185
+ require$2.resolve("react/jsx-runtime");
186
+ return appConfig.single;
187
+ } catch {
188
+ return false;
189
+ }
190
+ })();
178
191
  const jsMainPath = appConfig.grayscale ? `${appPkg$1.name}/beta/${appPkg$1.name}` : `${appPkg$1.name}/${appPkg$1.name}`;
179
192
  const assetPath = appConfig.grayscale ? `${appPkg$1.name}/beta/${appPkg$1.version}` : `${appPkg$1.name}/${appPkg$1.version}`;
180
193
  const cssRegex = /\.css$/;
@@ -294,6 +307,7 @@ function getWebpackConfig(args, override) {
294
307
  resolve: {
295
308
  alias: {
296
309
  "@": paths.src,
310
+ "@swc/helpers": path$1.dirname(require$2.resolve("@swc/helpers/package.json")),
297
311
  ...override.alias
298
312
  },
299
313
  extensions: [
@@ -342,7 +356,7 @@ function getWebpackConfig(args, override) {
342
356
  transform: {
343
357
  legacyDecorator: override.decorators,
344
358
  react: {
345
- runtime: "automatic",
359
+ runtime: hasJsxRuntime ? "automatic" : "classic",
346
360
  development: isDev,
347
361
  refresh: isDev
348
362
  }
@@ -559,9 +573,9 @@ const setupMock = debounce(function setupMock() {
559
573
  }
560
574
  }, 100);
561
575
  const getPathReAndKeys = memoize((path) => {
562
- const keys = [];
576
+ const { regexp, keys } = pathToRegexp(path);
563
577
  return {
564
- re: pathToRegexp(path, keys),
578
+ re: regexp,
565
579
  keys
566
580
  };
567
581
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qse/edu-scripts",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "author": "Kinoko",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,18 +14,17 @@
14
14
  "docs:build": "vitepress build docs",
15
15
  "docs:deploy": "ssh-sftp",
16
16
  "build": "tsdown",
17
- "deploy": "node scripts/deploy.js",
18
- "release": "npm run test && npm run build && npm publish && rimraf dist",
17
+ "deploy": "node scripts/deploy.js && rimraf .vitepress/dist",
18
+ "release": "npm run lint && npm run test && npm run build && npm publish && rimraf dist",
19
19
  "prettier": "prettier -c -w \"src/**/*.{js,jsx,tsx,ts,less,md,json}\"",
20
- "lint": "eslint --fix src",
20
+ "lint": "eslint --fix src && tsc --noEmit",
21
21
  "postversion": "npm run release",
22
22
  "test": "jest"
23
23
  },
24
24
  "homepage": "http://192.168.10.19:3339/qsxxwapdev/edu-scripts/",
25
25
  "publishConfig": {
26
26
  "registry": "https://registry.npmjs.org/",
27
- "access": "public",
28
- "tag": "beta"
27
+ "access": "public"
29
28
  },
30
29
  "bin": {
31
30
  "edu-scripts": "dist/cli.mjs",
@@ -35,6 +34,7 @@
35
34
  "typings": "dist/index.d.mts",
36
35
  "dependencies": {
37
36
  "@babel/core": "~7.29.0",
37
+ "@inquirer/prompts": "^8.3.0",
38
38
  "@qse/ssh-sftp": "^1.3.1",
39
39
  "@rsdoctor/rspack-plugin": "^1.5.2",
40
40
  "@rspack/core": "^1.7.6",
@@ -48,38 +48,37 @@
48
48
  "chokidar": "^3.6.0",
49
49
  "cookie-parser": "^1.4.7",
50
50
  "css-loader": "^6.11.0",
51
- "cssnano": "^6.1.2",
51
+ "cssnano": "^7.1.3",
52
+ "es-toolkit": "^1.45.1",
52
53
  "express": "^4.21.2",
53
54
  "filesize": "^8.0.7",
54
55
  "fs-extra": "^11.3.3",
55
56
  "globby": "^16.1.1",
56
57
  "gzip-size": "^7.0.0",
57
58
  "html-webpack-plugin": "^5.6.6",
58
- "@inquirer/prompts": "^8.3.0",
59
59
  "less": "^3.13.1",
60
60
  "less-loader": "^10.2.0",
61
- "lodash-es": "^4.17.23",
62
61
  "multer": "^2.1.0",
63
62
  "ora": "^9.3.0",
64
- "path-to-regexp": "^6.3.0",
63
+ "path-to-regexp": "^8.3.0",
65
64
  "postcss": "^8.5.3",
66
65
  "postcss-flexbugs-fixes": "^5.0.2",
67
- "postcss-loader": "^7.3.4",
66
+ "postcss-loader": "^8.2.1",
68
67
  "postcss-momentum-scrolling": "^3.14.22",
69
- "postcss-normalize": "^8.0.1",
70
- "postcss-preset-env": "^9.6.0",
68
+ "postcss-normalize": "^13.0.1",
69
+ "postcss-preset-env": "^11.2.0",
71
70
  "prettier": "^3.8.1",
72
71
  "prettier-plugin-tailwindcss": "^0.7.2",
73
- "react-refresh": "^0.14.2",
72
+ "react-refresh": "^0.18.0",
74
73
  "recursive-readdir": "^2.2.3",
75
74
  "semver": "^7.7.1",
76
- "strip-ansi": "^6.0.1",
77
- "style-loader": "^3.3.4",
75
+ "strip-ansi": "^7.2.0",
76
+ "style-loader": "^4.0.0",
78
77
  "tailwindcss": "^3.4.19",
79
78
  "tmp": "^0.2.3",
80
79
  "typescript": "^5.9.3",
81
80
  "url-loader": "^4.1.1",
82
- "yargs": "^17.7.2"
81
+ "yargs": "^18.0.0"
83
82
  },
84
83
  "devDependencies": {
85
84
  "@babel/preset-env": "~7.29.0",
@@ -88,7 +87,6 @@
88
87
  "@types/cookie-parser": "^1.4.10",
89
88
  "@types/fs-extra": "^11.0.4",
90
89
  "@types/jest": "^30.0.0",
91
- "@types/lodash-es": "^4.17.12",
92
90
  "@types/multer": "^2.0.0",
93
91
  "@types/semver": "^7.7.1",
94
92
  "@types/tmp": "^0.2.6",
@@ -98,5 +96,13 @@
98
96
  "rimraf": "^6.1.3",
99
97
  "tsdown": "^0.20.3",
100
98
  "vitepress": "^1.6.4"
99
+ },
100
+ "peerDependencies": {
101
+ "tailwindcss": "^3.0.0"
102
+ },
103
+ "peerDependenciesMeta": {
104
+ "tailwindcss": {
105
+ "optional": true
106
+ }
101
107
  }
102
108
  }
@@ -0,0 +1,2 @@
1
+ packages:
2
+ - 'test/app'
package/src/cli.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import '@swc-node/register/esm-register'
2
+ import './utils/esm-register'
3
+
3
4
  import './utils/beforeStart'
4
5
 
5
6
  import fs from 'fs-extra'
@@ -1,13 +1,13 @@
1
1
  import paths from '../../paths'
2
2
  import { globbySync } from 'globby'
3
3
  import chokidar from 'chokidar'
4
- import { debounce, memoize } from 'lodash-es'
4
+ import { debounce, memoize } from 'es-toolkit'
5
5
  import chalk from 'chalk'
6
6
  import fs from 'fs-extra'
7
7
  import express from 'express'
8
8
  import cookieParser from 'cookie-parser'
9
9
  import multer from 'multer'
10
- import { pathToRegexp, type Key } from 'path-to-regexp'
10
+ import { pathToRegexp } from 'path-to-regexp'
11
11
  import { createRequire } from 'node:module'
12
12
  import { resolveModule } from '@/utils/resolveModule'
13
13
  const require = createRequire(import.meta.url)
@@ -44,9 +44,8 @@ const setupMock = debounce(function setupMock() {
44
44
  }, 100)
45
45
 
46
46
  const getPathReAndKeys = memoize((path: string) => {
47
- const keys: Key[] = []
48
- const re = pathToRegexp(path, keys)
49
- return { re, keys }
47
+ const { regexp, keys } = pathToRegexp(path)
48
+ return { re: regexp, keys }
50
49
  })
51
50
 
52
51
  function decodeParam(val: string) {
@@ -1,20 +1,30 @@
1
+ import { resolveModule } from '@/utils/resolveModule'
1
2
  import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
3
+ import type { Compiler, Configuration, RuleSetRule, SwcLoaderOptions } from '@rspack/core'
2
4
  import { rspack } from '@rspack/core'
3
- import type { Configuration, Compiler, RuleSetRule, SwcLoaderOptions } from '@rspack/core'
4
5
  import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
5
6
  import chalk from 'chalk'
6
7
  import fs from 'fs-extra'
7
8
  import HtmlWebpackPlugin from 'html-webpack-plugin'
8
9
  import { createRequire } from 'node:module'
10
+ import path from 'node:path'
9
11
  import appConfig from '../utils/appConfig'
10
12
  import type { Configuration as CustomConfiguration } from '../utils/defineConfig'
11
13
  import paths from './paths'
12
14
  import PostcssSafeAreaPlugin from './plugins/postcss-safe-area'
13
- import { resolveModule } from '@/utils/resolveModule'
14
15
 
15
16
  const require = createRequire(import.meta.url)
16
17
  const appPkg = fs.readJsonSync(paths.package) as { name: string; version: string }
17
18
 
19
+ const hasJsxRuntime = (() => {
20
+ try {
21
+ require.resolve('react/jsx-runtime')
22
+ return appConfig.single
23
+ } catch {
24
+ return false
25
+ }
26
+ })()
27
+
18
28
  const jsMainPath = appConfig.grayscale
19
29
  ? `${appPkg.name}/beta/${appPkg.name}`
20
30
  : `${appPkg.name}/${appPkg.name}`
@@ -200,6 +210,7 @@ export default function getWebpackConfig(args: any, override: CustomConfiguratio
200
210
  resolve: {
201
211
  alias: {
202
212
  '@': paths.src,
213
+ '@swc/helpers': path.dirname(require.resolve('@swc/helpers/package.json')),
203
214
  ...override.alias,
204
215
  },
205
216
  extensions: ['.web.js', '.web.mjs', '.js', '.mjs', '.jsx', '.ts', '.tsx', '.json', '.wasm'],
@@ -247,7 +258,7 @@ export default function getWebpackConfig(args: any, override: CustomConfiguratio
247
258
  transform: {
248
259
  legacyDecorator: override.decorators,
249
260
  react: {
250
- runtime: 'automatic',
261
+ runtime: hasJsxRuntime ? 'automatic' : 'classic',
251
262
  development: isDev,
252
263
  refresh: isDev,
253
264
  },
@@ -402,7 +413,10 @@ export default function getWebpackConfig(args: any, override: CustomConfiguratio
402
413
  /@rspack\/dev-server\/client\/index\.js/,
403
414
  (resource) => {
404
415
  const myClientPath = paths.resolveOwn('asset', 'rspack-dev-server-client.js')
405
- resource.request = resource.request.replace(/.*dev-server\/client\/index\.js/, myClientPath)
416
+ resource.request = resource.request.replace(
417
+ /.*dev-server\/client\/index\.js/,
418
+ myClientPath
419
+ )
406
420
  }
407
421
  ),
408
422
  new rspack.IgnorePlugin({
@@ -35,7 +35,7 @@ if (!(appConfig.single || appConfig.mainProject)) {
35
35
  console.log(chalk.bgYellow('教育集成工程不能含有 public/static, 现已自动删除'))
36
36
  try {
37
37
  fs.rmSync(paths.static, { recursive: true })
38
- } catch (e) {}
38
+ } catch {}
39
39
  }
40
40
  }
41
41
 
@@ -0,0 +1,6 @@
1
+ import { createRequire } from 'node:module'
2
+
3
+ // 兼容 CommonJS 模块
4
+ const require = createRequire(import.meta.url)
5
+ const { register } = require('@swc-node/register/register')
6
+ register()