piral-core 1.0.2 → 1.1.0-beta.5756
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/app.codegen.d.ts +1 -1
- package/dist/codegen.js +60 -24
- package/esm/Piral.js +1 -2
- package/esm/Piral.js.map +1 -1
- package/esm/components/PiralRoutes.js +10 -1
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/wrapComponent.js +1 -2
- package/esm/components/wrapComponent.js.map +1 -1
- package/esm/defaults/DefaultErrorInfo.js +2 -1
- package/esm/defaults/DefaultErrorInfo.js.map +1 -1
- package/esm/defaults/navigator_none.d.ts +1 -1
- package/esm/defaults/navigator_none.js +2 -1
- package/esm/defaults/navigator_none.js.map +1 -1
- package/esm/defaults/navigator_v5.d.ts +1 -1
- package/esm/defaults/navigator_v5.js +2 -1
- package/esm/defaults/navigator_v5.js.map +1 -1
- package/esm/defaults/navigator_v6.d.ts +1 -1
- package/esm/defaults/navigator_v6.js +2 -1
- package/esm/defaults/navigator_v6.js.map +1 -1
- package/esm/hooks/index.d.ts +0 -1
- package/esm/hooks/index.js +0 -1
- package/esm/hooks/index.js.map +1 -1
- package/esm/state/createActions.js +2 -2
- package/esm/state/createActions.js.map +1 -1
- package/esm/tools/codegen.js +51 -13
- package/esm/tools/codegen.js.map +1 -1
- package/esm/types/navigation.d.ts +4 -0
- package/lib/Piral.js +1 -2
- package/lib/Piral.js.map +1 -1
- package/lib/components/PiralRoutes.js +10 -1
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/wrapComponent.js +1 -2
- package/lib/components/wrapComponent.js.map +1 -1
- package/lib/defaults/DefaultErrorInfo.js +3 -2
- package/lib/defaults/DefaultErrorInfo.js.map +1 -1
- package/lib/defaults/navigator_none.d.ts +1 -1
- package/lib/defaults/navigator_none.js +2 -1
- package/lib/defaults/navigator_none.js.map +1 -1
- package/lib/defaults/navigator_v5.d.ts +1 -1
- package/lib/defaults/navigator_v5.js +2 -1
- package/lib/defaults/navigator_v5.js.map +1 -1
- package/lib/defaults/navigator_v6.d.ts +1 -1
- package/lib/defaults/navigator_v6.js +2 -1
- package/lib/defaults/navigator_v6.js.map +1 -1
- package/lib/hooks/index.d.ts +0 -1
- package/lib/hooks/index.js +0 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/state/createActions.js +1 -1
- package/lib/state/createActions.js.map +1 -1
- package/lib/tools/codegen.js +51 -13
- package/lib/tools/codegen.js.map +1 -1
- package/lib/types/navigation.d.ts +4 -0
- package/package.json +4 -4
- package/src/Piral.tsx +1 -2
- package/src/components/PiralRoutes.test.tsx +13 -22
- package/src/components/PiralRoutes.tsx +14 -2
- package/src/components/wrapComponent.tsx +1 -2
- package/src/defaults/DefaultErrorInfo.tsx +2 -1
- package/src/defaults/navigator_none.tsx +2 -1
- package/src/defaults/navigator_v5.tsx +2 -1
- package/src/defaults/navigator_v6.tsx +2 -1
- package/src/hooks/index.ts +0 -1
- package/src/state/createActions.ts +2 -2
- package/src/tools/codegen.ts +59 -13
- package/src/types/navigation.ts +4 -0
- package/esm/hooks/routes.d.ts +0 -2
- package/esm/hooks/routes.js +0 -11
- package/esm/hooks/routes.js.map +0 -1
- package/lib/hooks/routes.d.ts +0 -2
- package/lib/hooks/routes.js +0 -15
- package/lib/hooks/routes.js.map +0 -1
- package/src/hooks/routes.ts +0 -14
package/src/tools/codegen.ts
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
// this file is bundled, so the references here will not be at runtime (i.e., for a user)
|
|
2
2
|
import { getModulePath } from 'piral-cli/src/external/resolve';
|
|
3
|
+
import { readFileSync, existsSync } from 'fs';
|
|
4
|
+
import { resolve, dirname } from 'path';
|
|
5
|
+
|
|
6
|
+
function findPackagePath(moduleDir: string) {
|
|
7
|
+
const packageJson = 'package.json';
|
|
8
|
+
const packagePath = resolve(moduleDir, packageJson);
|
|
9
|
+
|
|
10
|
+
if (existsSync(packagePath)) {
|
|
11
|
+
return packagePath;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const newDir = resolve(moduleDir, '..');
|
|
15
|
+
|
|
16
|
+
if (newDir !== moduleDir) {
|
|
17
|
+
return findPackagePath(newDir);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getPackageJson(root: string, packageName: string) {
|
|
24
|
+
const moduleDir = dirname(getModulePath(root, packageName));
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const packagePath = findPackagePath(moduleDir);
|
|
28
|
+
const content = readFileSync(packagePath, 'utf8');
|
|
29
|
+
return JSON.parse(content) || {};
|
|
30
|
+
} catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
3
34
|
|
|
4
35
|
function getRouterVersion(root: string) {
|
|
5
36
|
const router = 'react-router';
|
|
6
37
|
|
|
7
38
|
try {
|
|
8
|
-
const
|
|
9
|
-
const { version } = require(modulePath);
|
|
39
|
+
const { version } = getPackageJson(root, router);
|
|
10
40
|
const [major] = version.split('.');
|
|
11
41
|
return parseInt(major, 10);
|
|
12
42
|
} catch {
|
|
@@ -16,17 +46,15 @@ function getRouterVersion(root: string) {
|
|
|
16
46
|
}
|
|
17
47
|
|
|
18
48
|
function getIdentifiers(root: string, packageName: string) {
|
|
19
|
-
const packageJson = `${packageName}/package.json`;
|
|
20
49
|
const identifiers = [packageName];
|
|
21
50
|
|
|
22
51
|
try {
|
|
23
|
-
const
|
|
24
|
-
const details = require(modulePath);
|
|
52
|
+
const details = getPackageJson(root, packageName);
|
|
25
53
|
|
|
26
54
|
if (details.version) {
|
|
27
55
|
identifiers.push(`${packageName}@${details.version}`);
|
|
28
56
|
|
|
29
|
-
if (details.name !== packageName) {
|
|
57
|
+
if (details.name && details.name !== packageName) {
|
|
30
58
|
identifiers.push(`${details.name}@${details.version}`);
|
|
31
59
|
}
|
|
32
60
|
}
|
|
@@ -63,22 +91,40 @@ interface CodegenOptions {
|
|
|
63
91
|
export function createDependencies(imports: Array<string>, exports: Array<string>, opts: CodegenOptions) {
|
|
64
92
|
const { root, appName, externals } = opts;
|
|
65
93
|
const assignments: Array<string> = [];
|
|
94
|
+
const asyncAssignments: Array<string> = [];
|
|
66
95
|
|
|
67
96
|
if (appName) {
|
|
68
97
|
assignments.push(`deps['${appName}']={}`);
|
|
69
98
|
}
|
|
70
99
|
|
|
71
|
-
for (const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
for (const external of externals) {
|
|
101
|
+
if (external.endsWith('?')) {
|
|
102
|
+
const name = external.replace(/\?+$/, '');
|
|
103
|
+
const identifiers = getIdentifiers(root, name);
|
|
104
|
+
const path = getModulePathOrDefault(root, name);
|
|
76
105
|
|
|
77
|
-
|
|
78
|
-
|
|
106
|
+
for (const id of identifiers) {
|
|
107
|
+
asyncAssignments.push(`registerModule(${JSON.stringify(id)}, () => import(${JSON.stringify(path)}))`);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const name = external;
|
|
111
|
+
const identifiers = getIdentifiers(root, name);
|
|
112
|
+
const path = getModulePathOrDefault(root, name);
|
|
113
|
+
const ref = `_${imports.length}`;
|
|
114
|
+
imports.push(`import * as ${ref} from ${JSON.stringify(path)}`);
|
|
115
|
+
|
|
116
|
+
for (const id of identifiers) {
|
|
117
|
+
assignments.push(`deps[${JSON.stringify(id)}]=${ref}`);
|
|
118
|
+
}
|
|
79
119
|
}
|
|
80
120
|
}
|
|
81
121
|
|
|
122
|
+
if (asyncAssignments.length) {
|
|
123
|
+
imports.push(`import { registerModule } from 'piral-base'`);
|
|
124
|
+
assignments.push(...asyncAssignments);
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
82
128
|
exports.push(`
|
|
83
129
|
export function fillDependencies(deps) {
|
|
84
130
|
${assignments.join(';')}
|
package/src/types/navigation.ts
CHANGED
package/esm/hooks/routes.d.ts
DELETED
package/esm/hooks/routes.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useGlobalState } from './globalState';
|
|
2
|
-
import { useRouteFilter } from '../../app.codegen';
|
|
3
|
-
export function useRoutes() {
|
|
4
|
-
const routes = useGlobalState((s) => s.routes);
|
|
5
|
-
const pages = useGlobalState((s) => s.registry.pages);
|
|
6
|
-
const paths = [];
|
|
7
|
-
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
8
|
-
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
9
|
-
return useRouteFilter(paths);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=routes.js.map
|
package/esm/hooks/routes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/hooks/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,MAAM,UAAU,SAAS;IACvB,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,MAAM,KAAK,GAAmB,EAAE,CAAC;IAEjC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACjF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAEzF,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
package/lib/hooks/routes.d.ts
DELETED
package/lib/hooks/routes.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRoutes = void 0;
|
|
4
|
-
const globalState_1 = require("./globalState");
|
|
5
|
-
const app_codegen_1 = require("../../app.codegen");
|
|
6
|
-
function useRoutes() {
|
|
7
|
-
const routes = (0, globalState_1.useGlobalState)((s) => s.routes);
|
|
8
|
-
const pages = (0, globalState_1.useGlobalState)((s) => s.registry.pages);
|
|
9
|
-
const paths = [];
|
|
10
|
-
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
11
|
-
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
12
|
-
return (0, app_codegen_1.useRouteFilter)(paths);
|
|
13
|
-
}
|
|
14
|
-
exports.useRoutes = useRoutes;
|
|
15
|
-
//# sourceMappingURL=routes.js.map
|
package/lib/hooks/routes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/hooks/routes.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAC/C,mDAAmD;AAGnD,SAAgB,SAAS;IACvB,MAAM,MAAM,GAAG,IAAA,4BAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,IAAA,4BAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,MAAM,KAAK,GAAmB,EAAE,CAAC;IAEjC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACjF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAEzF,OAAO,IAAA,4BAAc,EAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AATD,8BASC"}
|
package/src/hooks/routes.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useGlobalState } from './globalState';
|
|
2
|
-
import { useRouteFilter } from '../../app.codegen';
|
|
3
|
-
import { AppPath } from '../types';
|
|
4
|
-
|
|
5
|
-
export function useRoutes() {
|
|
6
|
-
const routes = useGlobalState((s) => s.routes);
|
|
7
|
-
const pages = useGlobalState((s) => s.registry.pages);
|
|
8
|
-
const paths: Array<AppPath> = [];
|
|
9
|
-
|
|
10
|
-
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
11
|
-
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
12
|
-
|
|
13
|
-
return useRouteFilter(paths);
|
|
14
|
-
}
|