@spcsn/taro-mini-runner 1.0.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/README.md +103 -0
- package/dist/entrypoints/mini-runner.d.ts +2 -0
- package/dist/entrypoints/mini-runner.js +96 -0
- package/dist/entrypoints/mini-runner.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mini-program/config.d.ts +3 -0
- package/dist/mini-program/config.js +237 -0
- package/dist/mini-program/config.js.map +1 -0
- package/dist/mini-program/default-config.d.ts +3 -0
- package/dist/mini-program/default-config.js +49 -0
- package/dist/mini-program/default-config.js.map +1 -0
- package/dist/mini-program/emit.d.ts +3 -0
- package/dist/mini-program/emit.js +247 -0
- package/dist/mini-program/emit.js.map +1 -0
- package/dist/mini-program/entry.d.ts +3 -0
- package/dist/mini-program/entry.js +142 -0
- package/dist/mini-program/entry.js.map +1 -0
- package/dist/mini-program/index.d.ts +3 -0
- package/dist/mini-program/index.js +29 -0
- package/dist/mini-program/index.js.map +1 -0
- package/dist/mini-program/native-support.d.ts +6 -0
- package/dist/mini-program/native-support.js +160 -0
- package/dist/mini-program/native-support.js.map +1 -0
- package/dist/mini-program/page.d.ts +4 -0
- package/dist/mini-program/page.js +223 -0
- package/dist/mini-program/page.js.map +1 -0
- package/dist/mini-program/pipeline.d.ts +3 -0
- package/dist/mini-program/pipeline.js +46 -0
- package/dist/mini-program/pipeline.js.map +1 -0
- package/dist/mini-program/postcss.d.ts +6 -0
- package/dist/mini-program/postcss.js +26 -0
- package/dist/mini-program/postcss.js.map +1 -0
- package/dist/mini-program/style.d.ts +3 -0
- package/dist/mini-program/style.js +67 -0
- package/dist/mini-program/style.js.map +1 -0
- package/dist/plugins/rollup-plugin-increment.d.ts +8 -0
- package/dist/plugins/rollup-plugin-increment.js +52 -0
- package/dist/plugins/rollup-plugin-increment.js.map +1 -0
- package/dist/plugins/vite-plugin-assets.d.ts +3 -0
- package/dist/plugins/vite-plugin-assets.js +135 -0
- package/dist/plugins/vite-plugin-assets.js.map +1 -0
- package/dist/plugins/vite-plugin-multi-platform.d.ts +3 -0
- package/dist/plugins/vite-plugin-multi-platform.js +71 -0
- package/dist/plugins/vite-plugin-multi-platform.js.map +1 -0
- package/dist/react-framework/index.d.ts +27 -0
- package/dist/react-framework/index.js +36 -0
- package/dist/react-framework/index.js.map +1 -0
- package/dist/react-framework/loader-meta.d.ts +3 -0
- package/dist/react-framework/loader-meta.js +151 -0
- package/dist/react-framework/loader-meta.js.map +1 -0
- package/dist/react-framework/runtime/connect-native.d.ts +10 -0
- package/dist/react-framework/runtime/connect-native.js +392 -0
- package/dist/react-framework/runtime/connect-native.js.map +1 -0
- package/dist/react-framework/runtime/connect.d.ts +14 -0
- package/dist/react-framework/runtime/connect.js +313 -0
- package/dist/react-framework/runtime/connect.js.map +1 -0
- package/dist/react-framework/runtime/hooks.d.ts +30 -0
- package/dist/react-framework/runtime/hooks.js +87 -0
- package/dist/react-framework/runtime/hooks.js.map +1 -0
- package/dist/react-framework/runtime/index.d.ts +3 -0
- package/dist/react-framework/runtime/index.js +49 -0
- package/dist/react-framework/runtime/index.js.map +1 -0
- package/dist/react-framework/runtime/react-meta.d.ts +7 -0
- package/dist/react-framework/runtime/react-meta.js +9 -0
- package/dist/react-framework/runtime/react-meta.js.map +1 -0
- package/dist/react-framework/runtime/utils.d.ts +13 -0
- package/dist/react-framework/runtime/utils.js +45 -0
- package/dist/react-framework/runtime/utils.js.map +1 -0
- package/dist/react-framework/vite.mini.d.ts +3 -0
- package/dist/react-framework/vite.mini.js +135 -0
- package/dist/react-framework/vite.mini.js.map +1 -0
- package/dist/react-runtime/component-tree.d.ts +19 -0
- package/dist/react-runtime/component-tree.js +65 -0
- package/dist/react-runtime/component-tree.js.map +1 -0
- package/dist/react-runtime/constant.d.ts +7 -0
- package/dist/react-runtime/constant.js +78 -0
- package/dist/react-runtime/constant.js.map +1 -0
- package/dist/react-runtime/dom-input.d.ts +12 -0
- package/dist/react-runtime/dom-input.js +86 -0
- package/dist/react-runtime/dom-input.js.map +1 -0
- package/dist/react-runtime/event.d.ts +13 -0
- package/dist/react-runtime/event.js +83 -0
- package/dist/react-runtime/event.js.map +1 -0
- package/dist/react-runtime/index.d.ts +33 -0
- package/dist/react-runtime/index.js +75 -0
- package/dist/react-runtime/index.js.map +1 -0
- package/dist/react-runtime/input-value-tracking.d.ts +3 -0
- package/dist/react-runtime/input-value-tracking.js +84 -0
- package/dist/react-runtime/input-value-tracking.js.map +1 -0
- package/dist/react-runtime/props.d.ts +7 -0
- package/dist/react-runtime/props.js +153 -0
- package/dist/react-runtime/props.js.map +1 -0
- package/dist/react-runtime/reconciler.d.ts +5 -0
- package/dist/react-runtime/reconciler.js +217 -0
- package/dist/react-runtime/reconciler.js.map +1 -0
- package/dist/react-runtime/render.d.ts +25 -0
- package/dist/react-runtime/render.js +97 -0
- package/dist/react-runtime/render.js.map +1 -0
- package/dist/react-runtime/work-tags.d.ts +26 -0
- package/dist/react-runtime/work-tags.js +29 -0
- package/dist/react-runtime/work-tags.js.map +1 -0
- package/dist/shared/compiler/base.d.ts +41 -0
- package/dist/shared/compiler/base.js +170 -0
- package/dist/shared/compiler/base.js.map +1 -0
- package/dist/shared/compiler/mini.d.ts +20 -0
- package/dist/shared/compiler/mini.js +147 -0
- package/dist/shared/compiler/mini.js.map +1 -0
- package/dist/shared/component.d.ts +2 -0
- package/dist/shared/component.js +21 -0
- package/dist/shared/component.js.map +1 -0
- package/dist/shared/constants.d.ts +47 -0
- package/dist/shared/constants.js +51 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/create-filter.d.ts +7 -0
- package/dist/shared/create-filter.js +97 -0
- package/dist/shared/create-filter.js.map +1 -0
- package/dist/shared/html.d.ts +1 -0
- package/dist/shared/html.js +19 -0
- package/dist/shared/html.js.map +1 -0
- package/dist/shared/index.d.ts +39 -0
- package/dist/shared/index.js +258 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/logger.d.ts +7 -0
- package/dist/shared/logger.js +146 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/map.d.ts +11 -0
- package/dist/shared/map.js +41 -0
- package/dist/shared/map.js.map +1 -0
- package/dist/shared/profile.d.ts +9 -0
- package/dist/shared/profile.js +52 -0
- package/dist/shared/profile.js.map +1 -0
- package/dist/shared/rollup.d.ts +8 -0
- package/dist/shared/rollup.js +40 -0
- package/dist/shared/rollup.js.map +1 -0
- package/dist/shared/runner/constant.d.ts +5 -0
- package/dist/shared/runner/constant.js +53 -0
- package/dist/shared/runner/constant.js.map +1 -0
- package/dist/shared/runner/index.d.ts +2 -0
- package/dist/shared/runner/index.js +19 -0
- package/dist/shared/runner/index.js.map +1 -0
- package/dist/shared/runner/vite.d.ts +3 -0
- package/dist/shared/runner/vite.js +10 -0
- package/dist/shared/runner/vite.js.map +1 -0
- package/dist/style-transforms/html-transform.d.ts +14 -0
- package/dist/style-transforms/html-transform.js +124 -0
- package/dist/style-transforms/html-transform.js.map +1 -0
- package/dist/style-transforms/px-transform.d.ts +40 -0
- package/dist/style-transforms/px-transform.js +252 -0
- package/dist/style-transforms/px-transform.js.map +1 -0
- package/dist/templates/comp.js +5 -0
- package/dist/templates/custom-wrapper.js +5 -0
- package/package.json +67 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = default_1;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const taro_helper_1 = require("@spcsn/taro-helper");
|
|
9
|
+
const shared_1 = require("../shared");
|
|
10
|
+
function isViteDepsPath(filePath) {
|
|
11
|
+
const normalizedPath = node_path_1.default.normalize(filePath);
|
|
12
|
+
// 判断路径是否包含 node_modules/.vite/deps
|
|
13
|
+
const isViteDeps = normalizedPath.includes(node_path_1.default.join('node_modules', '.vite', 'deps'));
|
|
14
|
+
return isViteDeps;
|
|
15
|
+
}
|
|
16
|
+
function default_1(compiler) {
|
|
17
|
+
const { taroConfig } = compiler;
|
|
18
|
+
return {
|
|
19
|
+
name: 'taro:vite-multi-platform-plugin',
|
|
20
|
+
enforce: 'pre',
|
|
21
|
+
async resolveId(source, importer, options) {
|
|
22
|
+
if ((0, shared_1.isVirtualModule)(source))
|
|
23
|
+
return null;
|
|
24
|
+
if (taro_helper_1.REG_NODE_MODULES.test(source))
|
|
25
|
+
return null;
|
|
26
|
+
const allowedExts = Array.from(new Set(taro_helper_1.SCRIPT_EXT.concat(taroConfig.frameworkExts || [])))
|
|
27
|
+
.map((item) => item.replace(/^\./, ''))
|
|
28
|
+
.join('|');
|
|
29
|
+
const miniPlatformReg = new RegExp(`\\.(weapp|mini)\\.(${allowedExts})`);
|
|
30
|
+
if (miniPlatformReg.test(source))
|
|
31
|
+
return null;
|
|
32
|
+
if (!importer)
|
|
33
|
+
return null;
|
|
34
|
+
const ext = node_path_1.default.extname(source);
|
|
35
|
+
const dir = node_path_1.default.dirname(source);
|
|
36
|
+
const basename = node_path_1.default.basename(source, ext);
|
|
37
|
+
// Note: H5 端的 dev 模式下,会存在 esbuild 预编译,会把 预编译的 chunk 文件放到 node_modules/.vite/deps 「cacheDir」 目录下,
|
|
38
|
+
// 当时 vite 的源码里面有个钩子,会对改目录下的 resolveId 进行拦截处理,vitejs/vite/packages/vite/src/node/plugins/optimizedDeps.ts,会直接返回传入的 id,所以不会返回 null
|
|
39
|
+
// 最全面的做法是,通过 config 钩子拿到 cacheDir,然后判断是否是 cacheDir 下的文件,如果是,则返回 null
|
|
40
|
+
// 目前先简单处理一下,如果是 node_modules/.vite/deps 目录下 先返回 null
|
|
41
|
+
const rawResolvedPath = node_path_1.default.resolve(node_path_1.default.dirname(importer), `${node_path_1.default.join(dir, basename)}${ext}`);
|
|
42
|
+
if (isViteDepsPath(rawResolvedPath))
|
|
43
|
+
return null;
|
|
44
|
+
let resolution = null;
|
|
45
|
+
const miniExtList = [`.weapp${ext}`, `/index.weapp${ext}`, `.mini${ext}`, `/index.mini${ext}`];
|
|
46
|
+
for (const multiExt of miniExtList) {
|
|
47
|
+
resolution = await this.resolve(node_path_1.default.resolve(node_path_1.default.dirname(importer), `${node_path_1.default.join(dir, basename)}${multiExt}`), importer, {
|
|
48
|
+
...options,
|
|
49
|
+
skipSelf: true,
|
|
50
|
+
});
|
|
51
|
+
if (resolution)
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (!resolution) {
|
|
55
|
+
resolution = await this.resolve(source, importer, {
|
|
56
|
+
...options,
|
|
57
|
+
skipSelf: true,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (!resolution?.id || resolution.external)
|
|
61
|
+
return resolution;
|
|
62
|
+
if ((0, shared_1.isVirtualModule)(resolution.id))
|
|
63
|
+
return resolution;
|
|
64
|
+
if (taro_helper_1.REG_NODE_MODULES.test(resolution.id))
|
|
65
|
+
return resolution;
|
|
66
|
+
if (miniPlatformReg.test(resolution.id))
|
|
67
|
+
return resolution;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=vite-plugin-multi-platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-multi-platform.js","sourceRoot":"","sources":["../../src/plugins/vite-plugin-multi-platform.ts"],"names":[],"mappings":";;;;;AAkBA,4BAwDC;AA1ED,0DAA6B;AAE7B,oDAAkE;AAElE,sCAA4C;AAK5C,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,cAAc,GAAG,mBAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEhD,mCAAmC;IACnC,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,mBAAI,CAAC,IAAI,CAAC,cAAc,E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AAE,OAAO,UAAU,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
export type Frameworks = 'react';
|
|
3
|
+
export interface FrameworkPluginContext {
|
|
4
|
+
initialConfig: {
|
|
5
|
+
framework?: unknown;
|
|
6
|
+
mini?: {
|
|
7
|
+
debugReact?: boolean;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
modifyRunnerOpts: (fn: (args: {
|
|
11
|
+
opts?: RunnerOptions;
|
|
12
|
+
}) => void) => void;
|
|
13
|
+
runnerUtils: {
|
|
14
|
+
getViteMiniCompilerContext: (rollupContext: unknown) => {
|
|
15
|
+
loaderMeta?: Record<string, unknown>;
|
|
16
|
+
} | undefined;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface RunnerOptions {
|
|
20
|
+
compiler?: string | {
|
|
21
|
+
type: string;
|
|
22
|
+
vitePlugins?: PluginOption[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function isReactLike(framework?: unknown): framework is Frameworks;
|
|
26
|
+
declare const _default: (ctx: FrameworkPluginContext) => void;
|
|
27
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isReactLike = isReactLike;
|
|
7
|
+
const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
|
|
8
|
+
const taro_shared_1 = require("@spcsn/taro-shared");
|
|
9
|
+
const vite_mini_1 = require("./vite.mini");
|
|
10
|
+
function isReactLike(framework = 'react') {
|
|
11
|
+
return framework === 'react';
|
|
12
|
+
}
|
|
13
|
+
exports.default = (ctx) => {
|
|
14
|
+
const { framework = 'react' } = ctx.initialConfig;
|
|
15
|
+
if (!isReactLike(framework))
|
|
16
|
+
return;
|
|
17
|
+
ctx.modifyRunnerOpts(({ opts }) => {
|
|
18
|
+
if (!opts?.compiler)
|
|
19
|
+
return;
|
|
20
|
+
if ((0, taro_shared_1.isString)(opts.compiler)) {
|
|
21
|
+
opts.compiler = {
|
|
22
|
+
type: opts.compiler,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const { compiler } = opts;
|
|
26
|
+
if (compiler.type !== 'vite')
|
|
27
|
+
return;
|
|
28
|
+
compiler.vitePlugins ||= [];
|
|
29
|
+
compiler.vitePlugins.push(VitePresetPlugin());
|
|
30
|
+
compiler.vitePlugins.push((0, vite_mini_1.miniVitePlugin)(ctx, framework));
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
function VitePresetPlugin() {
|
|
34
|
+
return (0, plugin_react_1.default)();
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react-framework/index.ts"],"names":[],"mappings":";;;;;AA+BA,kCAEC;AAjCD,wEAA+C;AAC/C,oDAA8C;AAE9C,2CAA6C;AA4B7C,SAAgB,WAAW,CAAC,YAAqB,OAAO;IACtD,OAAO,SAAS,KAAK,OAAO,CAAC;AAC/B,CAAC;AAED,kBAAe,CAAC,GAA2B,EAAE,EAAE;IAC7C,MAAM,EAAE,SAAS,GAAG,OAAO,EAAE,GAAG,GAAG,CAAC,aAAa,CAAC;IAElD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;QAAE,OAAO;IAEpC,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;QAChC,IAAI,CAAC,IAAI,EAAE,QAAQ;YAAE,OAAO;QAE5B,IAAI,IAAA,sBAAQ,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,QAAQ,GAAG;gBACd,IAAI,EAAE,IAAI,CAAC,QAAQ;aACpB,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO;QAErC,QAAQ,CAAC,WAAW,KAAK,EAAE,CAAC;QAC5B,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAC9C,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAA,0BAAc,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,SAAS,gBAAgB;IACvB,OAAO,IAAA,sBAAW,GAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getLoaderMeta = getLoaderMeta;
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const acorn = __importStar(require("acorn"));
|
|
42
|
+
const walk = __importStar(require("acorn-walk"));
|
|
43
|
+
function addConfig(source) {
|
|
44
|
+
const configsMap = {
|
|
45
|
+
enableShareAppMessage: ['onShareAppMessage', 'useShareAppMessage'],
|
|
46
|
+
enableShareTimeline: ['onShareTimeline', 'useShareTimeline'],
|
|
47
|
+
};
|
|
48
|
+
const ast = acorn.parse(source, {
|
|
49
|
+
ecmaVersion: 'latest',
|
|
50
|
+
sourceType: 'module',
|
|
51
|
+
});
|
|
52
|
+
const additionConfig = {};
|
|
53
|
+
function check(name) {
|
|
54
|
+
Object.keys(configsMap).forEach((configName) => {
|
|
55
|
+
const apis = configsMap[configName];
|
|
56
|
+
if (apis.includes(name)) {
|
|
57
|
+
additionConfig[configName] = true;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
walk.simple(ast, {
|
|
62
|
+
FunctionExpression(node) {
|
|
63
|
+
if (!node.id || !node.id.name)
|
|
64
|
+
return;
|
|
65
|
+
check(node.id.name);
|
|
66
|
+
},
|
|
67
|
+
FunctionDeclaration(node) {
|
|
68
|
+
if (!node.id || !node.id.name)
|
|
69
|
+
return;
|
|
70
|
+
check(node.id.name);
|
|
71
|
+
},
|
|
72
|
+
CallExpression(node) {
|
|
73
|
+
const { callee } = node;
|
|
74
|
+
if (callee.type === 'Identifier') {
|
|
75
|
+
check(callee.name);
|
|
76
|
+
}
|
|
77
|
+
else if (callee.type === 'MemberExpression') {
|
|
78
|
+
if (callee.property.type === 'Identifier') {
|
|
79
|
+
check(callee.property.name);
|
|
80
|
+
}
|
|
81
|
+
else if (callee.property.type === 'Literal' && typeof callee.property.value === 'string') {
|
|
82
|
+
check(callee.property.value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
node.arguments.forEach((item) => {
|
|
86
|
+
if (item.type === 'Literal' && item.value) {
|
|
87
|
+
check(item.value);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
ClassDeclaration(node) {
|
|
92
|
+
// 类声明: class Foo {}
|
|
93
|
+
if (node.id && node.id.name) {
|
|
94
|
+
check(node.id.name);
|
|
95
|
+
}
|
|
96
|
+
// 类体方法: class Foo { bar() {} }
|
|
97
|
+
node.body.body.forEach((method) => {
|
|
98
|
+
if (method.type === 'MethodDefinition') {
|
|
99
|
+
if (method.key.type === 'Identifier') {
|
|
100
|
+
check(method.key.name);
|
|
101
|
+
}
|
|
102
|
+
else if (method.key.type === 'Literal' && typeof method.key.value === 'string') {
|
|
103
|
+
check(method.key.value);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
ClassExpression(node) {
|
|
109
|
+
// 类表达式: const A = class B {}
|
|
110
|
+
if (node.id && node.id.name) {
|
|
111
|
+
check(node.id.name);
|
|
112
|
+
}
|
|
113
|
+
node.body.body.forEach((method) => {
|
|
114
|
+
if (method.type === 'MethodDefinition') {
|
|
115
|
+
if (method.key.type === 'Identifier') {
|
|
116
|
+
check(method.key.name);
|
|
117
|
+
}
|
|
118
|
+
else if (method.key.type === 'Literal' && typeof method.key.value === 'string') {
|
|
119
|
+
check(method.key.value);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
return additionConfig;
|
|
126
|
+
}
|
|
127
|
+
function getLoaderMeta(_framework) {
|
|
128
|
+
return {
|
|
129
|
+
importFrameworkStatement: `
|
|
130
|
+
import * as React from 'react'
|
|
131
|
+
import ReactDOM from 'react-dom'
|
|
132
|
+
`,
|
|
133
|
+
mockAppStatement: `
|
|
134
|
+
class App extends React.Component {
|
|
135
|
+
render () {
|
|
136
|
+
return this.props.children
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
`,
|
|
140
|
+
frameworkArgs: 'React, ReactDOM, config',
|
|
141
|
+
creator: 'createReactApp',
|
|
142
|
+
creatorLocation: node_path_1.default.join(__dirname, 'runtime'),
|
|
143
|
+
importFrameworkName: 'React',
|
|
144
|
+
extraImportForWeb: '',
|
|
145
|
+
execBeforeCreateWebApp: '',
|
|
146
|
+
modifyConfig(config, source) {
|
|
147
|
+
Object.assign(config, addConfig(source));
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=loader-meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-meta.js","sourceRoot":"","sources":["../../src/react-framework/loader-meta.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,sCAuBC;AAnHD,0DAA6B;AAE7B,6CAA+B;AAC/B,iDAAmC;AAMnC,SAAS,SAAS,CAAC,MAAc;IAC/B,MAAM,UAAU,GAA6B;QAC3C,qBAAqB,EAAE,CAAC,mBAAmB,EAAE,oBAAoB,CAAC;QAClE,mBAAmB,EAAE,CAAC,iBAAiB,EAAE,kBAAkB,C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QAC3C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type TReactDOM from 'react-dom';
|
|
3
|
+
import type TReactDOMClient from 'react-dom/client';
|
|
4
|
+
type ReactDOMRenderer = typeof TReactDOM & typeof TReactDOMClient & {
|
|
5
|
+
render: (element: React.ReactElement, container: unknown) => void;
|
|
6
|
+
};
|
|
7
|
+
declare let ReactDOM: ReactDOMRenderer;
|
|
8
|
+
export declare function createNativePageConfig(Component: any, pageName: string, data: Record<string, unknown>, react: typeof React, reactDOM: typeof ReactDOM, pageConfig: any): Record<string, any>;
|
|
9
|
+
export declare function createNativeComponentConfig(Component: any, react: typeof React, reactDOM: any, componentConfig: any): Record<string, any>;
|
|
10
|
+
export {};
|