miaoda-react-devkit 0.1.1-beta.21 → 0.1.1-beta.24

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/bin/lint.mjs ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process';
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { createRequire } from 'node:module';
6
+ import { dirname, join, resolve } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const devkitRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
11
+
12
+ // 从 devkit 自己的依赖解析工具,兼容 pnpm 隔离安装与发布后的独立项目。
13
+ function resolveBin(packageName, binName) {
14
+ const packageJson = require.resolve(`${packageName}/package.json`, { paths: [devkitRoot] });
15
+ const metadata = JSON.parse(readFileSync(packageJson, 'utf8'));
16
+ const declaredBin = typeof metadata.bin === 'string' ? metadata.bin : metadata.bin?.[binName];
17
+ if (!declaredBin) {
18
+ throw new Error(`${packageName} 未声明 ${binName} 命令`);
19
+ }
20
+ return join(dirname(packageJson), declaredBin);
21
+ }
22
+
23
+ // lint 依赖 devkit 的构建产物(Oxlint 插件与 HTML 检查器)。发布包自带 dist;
24
+ // workspace 源码检出尚未构建时自动补一次构建,避免 lint 因产物缺失直接失败。
25
+ function ensureDevkitBuild() {
26
+ const artifacts = [
27
+ join(devkitRoot, 'dist/oxlint/index.js'),
28
+ join(devkitRoot, 'dist/html/check.js'),
29
+ ];
30
+ if (artifacts.every(path => existsSync(path))) {
31
+ return;
32
+ }
33
+ const build = spawnSync('pnpm', ['run', 'build'], { cwd: devkitRoot, stdio: 'inherit' });
34
+ if (build.error || build.status !== 0 || !artifacts.every(path => existsSync(path))) {
35
+ throw new Error('devkit 构建产物缺失,请先执行 pnpm --filter miaoda-react-devkit build');
36
+ }
37
+ }
38
+
39
+ try {
40
+ ensureDevkitBuild();
41
+ const result = spawnSync('bash', [join(devkitRoot, 'lint/lint.sh')], {
42
+ cwd: process.cwd(),
43
+ stdio: 'inherit',
44
+ env: {
45
+ ...process.env,
46
+ DEVKIT_ROOT: devkitRoot,
47
+ DEVKIT_TSGO: resolveBin('@typescript/native-preview', 'tsgo'),
48
+ DEVKIT_BIOME: resolveBin('@biomejs/biome', 'biome'),
49
+ DEVKIT_OXLINT: resolveBin('oxlint', 'oxlint'),
50
+ },
51
+ });
52
+ if (result.error) {
53
+ console.error(`无法启动 lint:${result.error.message}`);
54
+ }
55
+ process.exit(result.status ?? 1);
56
+ } catch (error) {
57
+ console.error(`无法启动 lint:${error.message}`);
58
+ process.exit(1);
59
+ }
package/bin/smoke.mjs ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+
3
+ // devkit-smoke 命令入口:只负责定位构建产物并转发调用,实际逻辑在 src/smoke(构建到 dist/smoke/cli.js)。
4
+ // 与 devkit-lint 一致:发布包自带 dist;workspace 源码检出尚未构建时自动补一次构建。
5
+
6
+ import { spawnSync } from 'node:child_process';
7
+ import { existsSync } from 'node:fs';
8
+ import { dirname, join, resolve } from 'node:path';
9
+ import { pathToFileURL, fileURLToPath } from 'node:url';
10
+
11
+ const devkitRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
12
+ const cliPath = join(devkitRoot, 'dist/smoke/cli.js');
13
+
14
+ function ensureCliBuild() {
15
+ if (existsSync(cliPath)) {
16
+ return;
17
+ }
18
+ // 发布包永远自带 dist,此分支只会在 workspace 源码检出中触发。
19
+ console.error(
20
+ '[startup-smoke] 尚未构建(缺少 dist/smoke/cli.js),正在自动构建 miaoda-react-devkit…',
21
+ );
22
+ const build = spawnSync('pnpm', ['run', 'build'], { cwd: devkitRoot, stdio: 'inherit' });
23
+ if (build.error || build.status !== 0 || !existsSync(cliPath)) {
24
+ console.error(
25
+ '[startup-smoke] 自动构建失败。请先安装依赖,再在仓库根目录手动执行:pnpm --filter miaoda-react-devkit build',
26
+ );
27
+ process.exit(1);
28
+ }
29
+ }
30
+
31
+ try {
32
+ ensureCliBuild();
33
+ // 应用侧依赖(vite)在 CLI 内部以应用目录为基准解析,此处无需注入任何路径。
34
+ const { runStartupSmokeCli } = await import(pathToFileURL(cliPath).href);
35
+ await runStartupSmokeCli();
36
+ } catch (error) {
37
+ console.error(`[startup-smoke] FAIL: ${error instanceof Error ? error.message : String(error)}`);
38
+ process.exit(1);
39
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "vcs": {
3
+ "enabled": true,
4
+ "clientKind": "git",
5
+ "useIgnoreFile": true
6
+ },
7
+ "linter": {
8
+ "enabled": true,
9
+ "rules": {
10
+ "recommended": false,
11
+ "correctness": {
12
+ "noUndeclaredDependencies": "error",
13
+ "useHookAtTopLevel": "error"
14
+ },
15
+ "suspicious": {
16
+ "noRedeclare": "error"
17
+ },
18
+ "style": {
19
+ "noCommonJs": "error"
20
+ }
21
+ }
22
+ },
23
+ "formatter": {
24
+ "enabled": false
25
+ },
26
+ "css": {
27
+ "parser": {
28
+ "cssModules": false,
29
+ "allowWrongLineComments": false,
30
+ "tailwindDirectives": true
31
+ }
32
+ },
33
+ "overrides": [
34
+ {
35
+ "includes": [
36
+ "tailwind.config.js"
37
+ ],
38
+ "linter": {
39
+ "rules": {
40
+ "style": {
41
+ "noCommonJs": "off"
42
+ }
43
+ }
44
+ }
45
+ }
46
+ ]
47
+ }
@@ -1,15 +1,15 @@
1
1
  // cloud/vite.config.ts
2
2
  import * as vite from "vite";
3
3
  import { loadConfigFromFile, mergeConfig } from "vite";
4
- import { withSentryStub, hmrTogglePlugin, extractRouterPlugin } from "../dist/vite/index.js";
4
+ import { hmrTogglePlugin } from "../dist/vite/index.js";
5
5
  import {
6
6
  makeTagger,
7
7
  injectedGuiListenerPlugin,
8
8
  injectOnErrorPlugin,
9
- monitorPlugin,
10
9
  fontsCodePlugin,
11
10
  mdClickPlugin,
12
- patchSupabasePlugins
11
+ patchSupabasePlugins,
12
+ extractRouterPlugin
13
13
  } from "miaoda-sc-plugin";
14
14
  import path from "path";
15
15
  import fs from "fs";
@@ -17,9 +17,6 @@ var projectRoot = process.cwd();
17
17
  var appType = process.env.DEVKIT_APP_TYPE ?? "freestyle";
18
18
  var cdnHost = process.env.DEVKIT_CDN_HOST ?? "resource-static.cdn.bcebos.com";
19
19
  var env = process.env.DEVKIT_ENV ?? "";
20
- var sentryDsn = process.env.DEVKIT_SENTRY_DSN ?? "";
21
- var miaodaEnv = process.env.DEVKIT_MIAODA_ENV ?? "";
22
- var appId = process.env.DEVKIT_APP_ID ?? "";
23
20
  var isOnline = env === "online";
24
21
  var loaded = await loadConfigFromFile(
25
22
  { command: "serve", mode: "development" },
@@ -44,23 +41,6 @@ if (!hasReact) {
44
41
  }
45
42
  var possibleEntries = ["./src/main.tsx", "./src/main.ts", "./src/index.tsx", "./src/index.ts"];
46
43
  var warmupFiles = possibleEntries.filter((e) => fs.existsSync(path.join(projectRoot, e)));
47
- var SENTRY_IMPORT_RE = /from\s+['"]@sentry\/react['"]/;
48
- function entryHasSentryImport(root, entries) {
49
- for (const entry of entries) {
50
- const fullPath = path.join(root, entry);
51
- if (!fs.existsSync(fullPath)) {
52
- continue;
53
- }
54
- try {
55
- if (SENTRY_IMPORT_RE.test(fs.readFileSync(fullPath, "utf-8"))) {
56
- return true;
57
- }
58
- } catch {
59
- }
60
- }
61
- return false;
62
- }
63
- var hasSentryReact = entryHasSentryImport(projectRoot, possibleEntries);
64
44
  var viteVersionInfo = {
65
45
  version: vite.version,
66
46
  rollupVersion: vite.rollupVersion ?? null,
@@ -69,18 +49,11 @@ var viteVersionInfo = {
69
49
  };
70
50
  var injectedGuiUrl = `https://${cdnHost}/common/v2/${isOnline ? "" : `${env}/`}injected.js`;
71
51
  var cloudPlugins = [
72
- ...hasSentryReact ? [withSentryStub()] : [monitorPlugin({
73
- scriptSrc: `https://${cdnHost}/sentry/browser.sentry.min.js`,
74
- sentryDsn,
75
- environment: miaodaEnv,
76
- appId
77
- })],
78
52
  // web 类型需要 DOM 节点打标(GUI使用)
79
53
  ...appType === "web" ? [
80
54
  makeTagger(),
81
55
  mdClickPlugin({ appType }),
82
- fontsCodePlugin(),
83
- injectedGuiListenerPlugin({ path: injectedGuiUrl })
56
+ fontsCodePlugin()
84
57
  ] : [],
85
58
  injectedGuiListenerPlugin({ path: injectedGuiUrl }),
86
59
  injectOnErrorPlugin(),
@@ -0,0 +1,9 @@
1
+ interface HtmlDiagnostic {
2
+ message: string;
3
+ line: number;
4
+ column: number;
5
+ }
6
+ declare function checkHtml(source: string): HtmlDiagnostic[];
7
+ declare function checkHtmlFile(filePath: string): HtmlDiagnostic[];
8
+
9
+ export { type HtmlDiagnostic, checkHtml, checkHtmlFile };
@@ -0,0 +1,54 @@
1
+ // src/html/check.ts
2
+ import { readFileSync } from "fs";
3
+ import { parse } from "parse5";
4
+ var FORBIDDEN_VALUES = /* @__PURE__ */ new Set([
5
+ "content-security-policy",
6
+ "content-security-policy-report-only",
7
+ "x-frame-options"
8
+ ]);
9
+ var MESSAGE = "\u7981\u6B62\u5728 index.html \u5199\u5B89\u5168\u54CD\u5E94\u5934 meta\u3002\u53D1\u5E03\u6001 CSP \u7531\u5E73\u53F0\u4EE5 HTTP \u54CD\u5E94\u5934\u7EDF\u4E00\u4E0B\u53D1\uFF1B\u5B89\u5168\u52A0\u56FA\u8BF7\u5728\u4EE3\u7801\u5C42\u505A\uFF1ARLS\u3001\u8F93\u5165\u6821\u9A8C\u3001\u8F93\u51FA\u8F6C\u4E49\u3002";
10
+ function locationForOffset(source, offset) {
11
+ const before = source.slice(0, offset);
12
+ const line = before.split("\n").length;
13
+ const lastNewline = before.lastIndexOf("\n");
14
+ return { line, column: offset - lastNewline };
15
+ }
16
+ function walk(node, callback) {
17
+ callback(node);
18
+ for (const child of node.childNodes ?? []) walk(child, callback);
19
+ }
20
+ function checkHtml(source) {
21
+ const document = parse(source, { sourceCodeLocationInfo: true });
22
+ const diagnostics = [];
23
+ walk(document, (node) => {
24
+ if (node.nodeName?.toLowerCase() !== "meta") return;
25
+ const httpEquiv = node.attrs?.find((attr) => attr.name.toLowerCase() === "http-equiv");
26
+ if (!httpEquiv || !FORBIDDEN_VALUES.has(httpEquiv.value.trim().toLowerCase())) return;
27
+ const offset = node.sourceCodeLocation?.startTag?.startOffset ?? node.sourceCodeLocation?.startOffset ?? 0;
28
+ const location = locationForOffset(source, offset);
29
+ diagnostics.push({ ...location, message: MESSAGE });
30
+ });
31
+ return diagnostics;
32
+ }
33
+ function checkHtmlFile(filePath) {
34
+ return checkHtml(readFileSync(filePath, "utf8"));
35
+ }
36
+ if (process.argv[1] && process.argv[1].endsWith("check.js")) {
37
+ const filePath = process.argv[2] ?? "index.html";
38
+ try {
39
+ const diagnostics = checkHtmlFile(filePath);
40
+ for (const diagnostic of diagnostics) {
41
+ process.stderr.write(`${filePath}:${diagnostic.line}:${diagnostic.column}: error: ${diagnostic.message}
42
+ `);
43
+ }
44
+ process.exitCode = diagnostics.length > 0 ? 1 : 0;
45
+ } catch (error) {
46
+ process.stderr.write(`\u65E0\u6CD5\u68C0\u67E5 HTML \u6587\u4EF6 ${filePath}: ${error instanceof Error ? error.message : String(error)}
47
+ `);
48
+ process.exitCode = 1;
49
+ }
50
+ }
51
+ export {
52
+ checkHtml,
53
+ checkHtmlFile
54
+ };