@samadhi1311/router 1.0.0 → 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/dist/index.cjs +9 -4
- package/dist/index.js +9 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,9 +36,11 @@ module.exports = __toCommonJS(index_exports);
|
|
|
36
36
|
var import_fs = __toESM(require("fs"), 1);
|
|
37
37
|
var import_path = __toESM(require("path"), 1);
|
|
38
38
|
function router(options = {}) {
|
|
39
|
+
let root;
|
|
39
40
|
const appDir = options.appDir || "app";
|
|
40
41
|
const virtualModuleId = "virtual:router";
|
|
41
42
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
43
|
+
const resolveFile = (p) => import_path.default.posix.join(root.replace(/\\/g, "/"), appDir, p);
|
|
42
44
|
function scanDirectory(dir, basePath = "") {
|
|
43
45
|
const routes = [];
|
|
44
46
|
const fullDir = import_path.default.join(process.cwd(), appDir, dir);
|
|
@@ -108,19 +110,19 @@ function router(options = {}) {
|
|
|
108
110
|
const loadingId = route.loadingPath ? `Loading${importCounter++}` : null;
|
|
109
111
|
const notFoundId = route.notFoundPath ? `NotFound${importCounter++}` : null;
|
|
110
112
|
if (componentId && route.componentPath) {
|
|
111
|
-
imports += `import ${componentId} from '
|
|
113
|
+
imports += `import ${componentId} from '${resolveFile(route.componentPath)}';
|
|
112
114
|
`;
|
|
113
115
|
}
|
|
114
116
|
if (layoutId && route.layoutPath) {
|
|
115
|
-
imports += `import ${layoutId} from '
|
|
117
|
+
imports += `import ${layoutId} from '${resolveFile(route.componentPath)}';
|
|
116
118
|
`;
|
|
117
119
|
}
|
|
118
120
|
if (loadingId && route.loadingPath) {
|
|
119
|
-
imports += `import ${loadingId} from '
|
|
121
|
+
imports += `import ${loadingId} from '${resolveFile(route.componentPath)}';
|
|
120
122
|
`;
|
|
121
123
|
}
|
|
122
124
|
if (notFoundId && route.notFoundPath) {
|
|
123
|
-
imports += `import ${notFoundId} from '
|
|
125
|
+
imports += `import ${notFoundId} from ''${resolveFile(route.componentPath)}';
|
|
124
126
|
`;
|
|
125
127
|
}
|
|
126
128
|
let config = `${indent}{
|
|
@@ -166,6 +168,9 @@ ${routeConfigs}];
|
|
|
166
168
|
return {
|
|
167
169
|
name: "router",
|
|
168
170
|
enforce: "pre",
|
|
171
|
+
configResolved(config) {
|
|
172
|
+
root = config.root;
|
|
173
|
+
},
|
|
169
174
|
resolveId(id) {
|
|
170
175
|
if (id === virtualModuleId) {
|
|
171
176
|
return resolvedVirtualModuleId;
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
function router(options = {}) {
|
|
5
|
+
let root;
|
|
5
6
|
const appDir = options.appDir || "app";
|
|
6
7
|
const virtualModuleId = "virtual:router";
|
|
7
8
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
9
|
+
const resolveFile = (p) => path.posix.join(root.replace(/\\/g, "/"), appDir, p);
|
|
8
10
|
function scanDirectory(dir, basePath = "") {
|
|
9
11
|
const routes = [];
|
|
10
12
|
const fullDir = path.join(process.cwd(), appDir, dir);
|
|
@@ -74,19 +76,19 @@ function router(options = {}) {
|
|
|
74
76
|
const loadingId = route.loadingPath ? `Loading${importCounter++}` : null;
|
|
75
77
|
const notFoundId = route.notFoundPath ? `NotFound${importCounter++}` : null;
|
|
76
78
|
if (componentId && route.componentPath) {
|
|
77
|
-
imports += `import ${componentId} from '
|
|
79
|
+
imports += `import ${componentId} from '${resolveFile(route.componentPath)}';
|
|
78
80
|
`;
|
|
79
81
|
}
|
|
80
82
|
if (layoutId && route.layoutPath) {
|
|
81
|
-
imports += `import ${layoutId} from '
|
|
83
|
+
imports += `import ${layoutId} from '${resolveFile(route.componentPath)}';
|
|
82
84
|
`;
|
|
83
85
|
}
|
|
84
86
|
if (loadingId && route.loadingPath) {
|
|
85
|
-
imports += `import ${loadingId} from '
|
|
87
|
+
imports += `import ${loadingId} from '${resolveFile(route.componentPath)}';
|
|
86
88
|
`;
|
|
87
89
|
}
|
|
88
90
|
if (notFoundId && route.notFoundPath) {
|
|
89
|
-
imports += `import ${notFoundId} from '
|
|
91
|
+
imports += `import ${notFoundId} from ''${resolveFile(route.componentPath)}';
|
|
90
92
|
`;
|
|
91
93
|
}
|
|
92
94
|
let config = `${indent}{
|
|
@@ -132,6 +134,9 @@ ${routeConfigs}];
|
|
|
132
134
|
return {
|
|
133
135
|
name: "router",
|
|
134
136
|
enforce: "pre",
|
|
137
|
+
configResolved(config) {
|
|
138
|
+
root = config.root;
|
|
139
|
+
},
|
|
135
140
|
resolveId(id) {
|
|
136
141
|
if (id === virtualModuleId) {
|
|
137
142
|
return resolvedVirtualModuleId;
|