@rsmax/build-store 1.0.1

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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 当轩
4
+ Copyright (c) 2019 - present Weizhu <yesmeck@gmail.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@rsmax/build-store`
2
+
3
+ 编译时各个阶段的状态存储。
package/lib/index.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { ComponentManifest, HostComponent } from '@rsmax/types';
2
+ export interface ExtractedTemplate {
3
+ template: string;
4
+ id: string;
5
+ module: string;
6
+ isEntry: boolean;
7
+ isolated?: boolean;
8
+ }
9
+ declare const Store: {
10
+ collectedComponents: Map<string, ComponentManifest>;
11
+ registeredHostComponents: Map<string, HostComponent>;
12
+ compositionComponents: Map<string, Map<string, {
13
+ import: string;
14
+ props: Set<string>;
15
+ }>>;
16
+ nativeComponents: Map<string, {
17
+ id: string;
18
+ }>;
19
+ pluginComponents: Map<string, {
20
+ id: string;
21
+ componentPath: string;
22
+ importers: Set<string>;
23
+ props: Set<string>;
24
+ }>;
25
+ skipHostComponents: string[];
26
+ appEvents: Map<string, Set<string>>;
27
+ pageEvents: Map<string, Set<string>>;
28
+ slotView: {
29
+ id: string;
30
+ props: string[];
31
+ };
32
+ extractedTemplates: Map<string, ExtractedTemplate>;
33
+ templateId: number;
34
+ registerNativeComponent(componentPath: string, output: string): string;
35
+ registerPluginComponent(componentPath: string, importer: string): string;
36
+ getCollectedComponents(): Map<string, ComponentManifest>;
37
+ generateTemplateId(filename: string): string;
38
+ resetTemplateId(): void;
39
+ reset(): void;
40
+ };
41
+ export default Store;
package/lib/index.js ADDED
@@ -0,0 +1,117 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const crypto = __importStar(require("crypto"));
27
+ const lodash_1 = require("lodash");
28
+ const shared_1 = require("@rsmax/shared");
29
+ function unique(array) {
30
+ return Array.from(new Set(array));
31
+ }
32
+ function generatePathHash(path) {
33
+ const hash = crypto.createHash('sha256');
34
+ hash.update(path);
35
+ return hash.digest('hex').slice(0, 7);
36
+ }
37
+ function generateComponentId(path) {
38
+ const [basename, dirname] = path.replace(/\.js$/, '').split('/').reverse();
39
+ const hash = generatePathHash(path);
40
+ return [(0, lodash_1.kebabCase)(dirname), (0, lodash_1.kebabCase)(basename), hash].filter(Boolean).join('-');
41
+ }
42
+ const Store = {
43
+ collectedComponents: new Map(),
44
+ registeredHostComponents: new Map(),
45
+ compositionComponents: new Map(),
46
+ nativeComponents: new Map(),
47
+ pluginComponents: new Map(),
48
+ skipHostComponents: [],
49
+ appEvents: new Map(),
50
+ pageEvents: new Map(),
51
+ slotView: {
52
+ id: 'slot-view',
53
+ props: [],
54
+ },
55
+ extractedTemplates: new Map(),
56
+ templateId: 1,
57
+ registerNativeComponent(componentPath, output) {
58
+ let component = this.nativeComponents.get(componentPath);
59
+ if (!component) {
60
+ const id = generateComponentId(output);
61
+ component = {
62
+ id,
63
+ };
64
+ }
65
+ this.nativeComponents.set(componentPath, component);
66
+ return component.id;
67
+ },
68
+ registerPluginComponent(componentPath, importer) {
69
+ let component = this.pluginComponents.get(componentPath);
70
+ if (!component) {
71
+ const id = generateComponentId(componentPath);
72
+ component = {
73
+ id,
74
+ componentPath,
75
+ importers: new Set(),
76
+ props: new Set(),
77
+ };
78
+ }
79
+ component.importers.add(importer);
80
+ this.pluginComponents.set(componentPath, component);
81
+ return component.id;
82
+ },
83
+ getCollectedComponents() {
84
+ this.registeredHostComponents.forEach((component, key) => {
85
+ if (!this.collectedComponents.has(key)) {
86
+ this.collectedComponents.set(key, {
87
+ id: key,
88
+ props: unique(component.props).sort(),
89
+ additional: component.additional,
90
+ });
91
+ }
92
+ });
93
+ return this.collectedComponents;
94
+ },
95
+ generateTemplateId(filename) {
96
+ const id = this.templateId;
97
+ const hash = generatePathHash((0, shared_1.slash)(filename));
98
+ this.templateId += 1;
99
+ return [hash, id.toString()].join('-');
100
+ },
101
+ resetTemplateId() {
102
+ this.templateId = 1;
103
+ },
104
+ reset() {
105
+ this.collectedComponents.clear();
106
+ this.registeredHostComponents.clear();
107
+ this.compositionComponents.clear();
108
+ this.nativeComponents.clear();
109
+ this.pluginComponents.clear();
110
+ this.slotView.props = [];
111
+ this.extractedTemplates.clear();
112
+ this.appEvents.clear();
113
+ this.pageEvents.clear();
114
+ this.templateId = 1;
115
+ },
116
+ };
117
+ exports.default = Store;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@rsmax/build-store",
3
+ "version": "1.0.1",
4
+ "description": "使用真正的 React 构建跨平台小程序",
5
+ "author": "Wei Zhu <yesmeck@gmail.com>",
6
+ "homepage": "https://remaxjs.org",
7
+ "license": "MIT",
8
+ "main": "lib/index.js",
9
+ "directories": {
10
+ "lib": "lib",
11
+ "test": "__tests__"
12
+ },
13
+ "files": [
14
+ "lib"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git@github.com:remaxjs/remax.git"
19
+ },
20
+ "scripts": {
21
+ "clean": "rimraf lib tsconfig.tsbuildinfo",
22
+ "prebuild": "npm run clean",
23
+ "build": "tsc"
24
+ },
25
+ "dependencies": {
26
+ "@rsmax/shared": "1.0.1",
27
+ "lodash": "^4.17.11"
28
+ },
29
+ "devDependencies": {
30
+ "@rsmax/types": "1.0.1",
31
+ "@types/lodash": "^4.14.135"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "gitHead": "d2ff644810449152d124a9da76218bcd9fdfff46"
37
+ }