@deot/dev-dever 2.7.0 → 2.8.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 +13 -11
- package/dist/index.js +13 -11
- package/package.json +6 -6
- package/shared.config.ts +59 -46
package/dist/index.cjs
CHANGED
|
@@ -35,35 +35,37 @@ const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
35
35
|
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
36
36
|
|
|
37
37
|
const dirname$1 = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
38
|
-
|
|
38
|
+
const target = {
|
|
39
39
|
entries: [],
|
|
40
40
|
html: ""
|
|
41
41
|
};
|
|
42
42
|
const excludes = ["tpl", "_", "dist", "node_modules", "__tests__"];
|
|
43
|
-
const walk = (dir) => {
|
|
43
|
+
const walk = (dir, playDir) => {
|
|
44
44
|
const { cwd, workspace } = devShared.Locals.impl();
|
|
45
|
-
dir = dir || ".";
|
|
46
45
|
const directory = path__namespace.join(cwd, workspace, dir);
|
|
47
46
|
fs__namespace.readdirSync(directory).forEach((file) => {
|
|
48
47
|
const fullpath = path__namespace.join(directory, file);
|
|
49
48
|
const paths = fullpath.split("/") || [];
|
|
50
49
|
const stat = fs__namespace.statSync(fullpath);
|
|
51
50
|
const extname = path__namespace.extname(fullpath);
|
|
52
|
-
if (stat.isFile() && /\.((t|j)sx?|vue)$/.test(extname) && paths.length >= 2 && paths[paths.length - 2]
|
|
51
|
+
if (stat.isFile() && /\.((t|j)sx?|vue|html)$/.test(extname) && paths.length >= 2 && playDir.includes(paths[paths.length - 2])) {
|
|
53
52
|
const basename = path__namespace.basename(file, extname);
|
|
54
|
-
|
|
55
|
-
name.splice(name.length - 2, 1);
|
|
56
|
-
|
|
53
|
+
const name = path__namespace.join(dir, basename).split("/");
|
|
54
|
+
playDir.length === 1 && name.splice(name.length - 2, 1);
|
|
55
|
+
const name$ = name.join("/");
|
|
56
|
+
if (!target.entries.includes(name$)) {
|
|
57
|
+
target.entries.push(name$);
|
|
58
|
+
}
|
|
57
59
|
} else if (stat.isDirectory() && !excludes.includes(file)) {
|
|
58
60
|
const subdir = path__namespace.join(dir, file);
|
|
59
|
-
walk(subdir);
|
|
61
|
+
walk(subdir, playDir);
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
64
|
};
|
|
63
|
-
const get = () => {
|
|
65
|
+
const get = (playDir) => {
|
|
64
66
|
if (target.html)
|
|
65
67
|
return target;
|
|
66
|
-
walk();
|
|
68
|
+
walk(".", playDir.split(","));
|
|
67
69
|
const tpl = fs__namespace.readFileSync(path__namespace.resolve(dirname$1, "../index.ejs"));
|
|
68
70
|
target.html = ejs.render(tpl.toString(), {
|
|
69
71
|
title: "demo",
|
|
@@ -98,7 +100,7 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
|
|
|
98
100
|
if (!options.workspace)
|
|
99
101
|
delete options.workspace;
|
|
100
102
|
delete options.packageName;
|
|
101
|
-
|
|
103
|
+
const { entries, html } = get(options.playDir);
|
|
102
104
|
if (!entries.length)
|
|
103
105
|
return devShared.Shell.spawn(`echo no entry file found!`);
|
|
104
106
|
let options$ = {
|
package/dist/index.js
CHANGED
|
@@ -10,35 +10,37 @@ import * as fs from 'node:fs';
|
|
|
10
10
|
import { render } from 'ejs';
|
|
11
11
|
|
|
12
12
|
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
|
|
13
|
+
const target = {
|
|
14
14
|
entries: [],
|
|
15
15
|
html: ""
|
|
16
16
|
};
|
|
17
17
|
const excludes = ["tpl", "_", "dist", "node_modules", "__tests__"];
|
|
18
|
-
const walk = (dir) => {
|
|
18
|
+
const walk = (dir, playDir) => {
|
|
19
19
|
const { cwd, workspace } = Locals.impl();
|
|
20
|
-
dir = dir || ".";
|
|
21
20
|
const directory = path.join(cwd, workspace, dir);
|
|
22
21
|
fs.readdirSync(directory).forEach((file) => {
|
|
23
22
|
const fullpath = path.join(directory, file);
|
|
24
23
|
const paths = fullpath.split("/") || [];
|
|
25
24
|
const stat = fs.statSync(fullpath);
|
|
26
25
|
const extname = path.extname(fullpath);
|
|
27
|
-
if (stat.isFile() && /\.((t|j)sx?|vue)$/.test(extname) && paths.length >= 2 && paths[paths.length - 2]
|
|
26
|
+
if (stat.isFile() && /\.((t|j)sx?|vue|html)$/.test(extname) && paths.length >= 2 && playDir.includes(paths[paths.length - 2])) {
|
|
28
27
|
const basename = path.basename(file, extname);
|
|
29
|
-
|
|
30
|
-
name.splice(name.length - 2, 1);
|
|
31
|
-
|
|
28
|
+
const name = path.join(dir, basename).split("/");
|
|
29
|
+
playDir.length === 1 && name.splice(name.length - 2, 1);
|
|
30
|
+
const name$ = name.join("/");
|
|
31
|
+
if (!target.entries.includes(name$)) {
|
|
32
|
+
target.entries.push(name$);
|
|
33
|
+
}
|
|
32
34
|
} else if (stat.isDirectory() && !excludes.includes(file)) {
|
|
33
35
|
const subdir = path.join(dir, file);
|
|
34
|
-
walk(subdir);
|
|
36
|
+
walk(subdir, playDir);
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
};
|
|
38
|
-
const get = () => {
|
|
40
|
+
const get = (playDir) => {
|
|
39
41
|
if (target.html)
|
|
40
42
|
return target;
|
|
41
|
-
walk();
|
|
43
|
+
walk(".", playDir.split(","));
|
|
42
44
|
const tpl = fs.readFileSync(path.resolve(dirname$1, "../index.ejs"));
|
|
43
45
|
target.html = render(tpl.toString(), {
|
|
44
46
|
title: "demo",
|
|
@@ -73,7 +75,7 @@ const run = (options) => Utils.autoCatch(async () => {
|
|
|
73
75
|
if (!options.workspace)
|
|
74
76
|
delete options.workspace;
|
|
75
77
|
delete options.packageName;
|
|
76
|
-
|
|
78
|
+
const { entries, html } = get(options.playDir);
|
|
77
79
|
if (!entries.length)
|
|
78
80
|
return Shell.spawn(`echo no entry file found!`);
|
|
79
81
|
let options$ = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-dever",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@deot/dev-react": "^2.
|
|
25
|
-
"@deot/dev-shared": "^2.
|
|
26
|
-
"@deot/dev-vue": "^2.
|
|
24
|
+
"@deot/dev-react": "^2.8.0",
|
|
25
|
+
"@deot/dev-shared": "^2.8.0",
|
|
26
|
+
"@deot/dev-vue": "^2.8.0",
|
|
27
27
|
"ejs": "^3.1.9",
|
|
28
|
-
"vite": "^5.0.
|
|
28
|
+
"vite": "^5.0.8"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@deot/dev-test": "^2.
|
|
31
|
+
"@deot/dev-test": "^2.8.0",
|
|
32
32
|
"cross-env": "^7.0.3"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/shared.config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
|
-
import { createRequire } from
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
4
|
import { defineConfig } from 'vitest/config';
|
|
5
5
|
import type { UserConfig, ViteDevServer } from 'vite';
|
|
6
6
|
|
|
@@ -8,15 +8,15 @@ import type { UserConfig, ViteDevServer } from 'vite';
|
|
|
8
8
|
* https://github.com/vuejs/core/issues/8303
|
|
9
9
|
* to fix error: ReferenceError: __name is not defined
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const __defProp = Object.defineProperty;
|
|
12
|
+
const __name = (target: any, value: any) => __defProp(target, 'name', { value, configurable: true });
|
|
13
13
|
globalThis.__name = globalThis.__name || __name;
|
|
14
14
|
|
|
15
15
|
const cwd = process.cwd();
|
|
16
16
|
|
|
17
17
|
// devOptions
|
|
18
18
|
const devOptions = JSON.parse(decodeURIComponent(process.env.DEV_OPTIONS || '{}'));
|
|
19
|
-
const { workspace, html, subpackagesMap } = devOptions;
|
|
19
|
+
const { playDir, workspace, html, subpackagesMap } = devOptions;
|
|
20
20
|
|
|
21
21
|
const generateIndexHtml = (url: string, inject: string) => {
|
|
22
22
|
let contents = '';
|
|
@@ -45,42 +45,56 @@ const getVirtualHtml = async (url: string) => {
|
|
|
45
45
|
const prefix = info.slice(0, -1);
|
|
46
46
|
const entry = info.slice(-1)[0];
|
|
47
47
|
|
|
48
|
-
if (prefix[prefix.length - 1] !== 'examples') {
|
|
49
|
-
prefix.push('examples');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
48
|
if (workspace && prefix[0] !== workspace) {
|
|
53
49
|
prefix.unshift(workspace);
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
const dir = path.join(cwd, prefix.join('/'));
|
|
57
52
|
const isExist = (ext: string) => {
|
|
58
|
-
const
|
|
59
|
-
|
|
53
|
+
const getFullpath = (dir: string) => path.join(dir, `${entry.replace(/(.*)(\..*)$/, '$1') + ext}`);
|
|
54
|
+
const last = prefix[prefix.length - 1];
|
|
55
|
+
const dirs = playDir.split(',');
|
|
56
|
+
|
|
57
|
+
if (dirs.some((i: string) => i === last)) {
|
|
58
|
+
const fullpath = getFullpath(path.join(cwd, prefix.join('/')));
|
|
59
|
+
return fs.existsSync(fullpath) ? fullpath : false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
63
|
+
let suffix = dirs[i];
|
|
64
|
+
if (last === suffix) {
|
|
65
|
+
suffix = '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const fullpath = getFullpath(path.join(cwd, prefix.concat([suffix]).join('/')));
|
|
69
|
+
if (fs.existsSync(fullpath)) {
|
|
70
|
+
return fullpath;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return false;
|
|
60
75
|
};
|
|
61
76
|
|
|
62
77
|
const getPreload = (fullpath: string) => {
|
|
63
|
-
let dir
|
|
78
|
+
let dir = path.dirname(fullpath);
|
|
64
79
|
let preload = '';
|
|
65
|
-
while (dir
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
path.resolve(dir
|
|
69
|
-
path.resolve(dir
|
|
70
|
-
path.resolve(dir
|
|
71
|
-
path.resolve(dir$, './preload.ts')
|
|
80
|
+
while (dir.includes(cwd) && !preload) {
|
|
81
|
+
const preloadFullPath = [
|
|
82
|
+
path.resolve(dir, './z.dev.preload.ts'),
|
|
83
|
+
path.resolve(dir, './dev.preload.ts'),
|
|
84
|
+
path.resolve(dir, './z.preload.ts'),
|
|
85
|
+
path.resolve(dir, './preload.ts')
|
|
72
86
|
].find(i => fs.existsSync(i));
|
|
73
87
|
|
|
74
88
|
if (preloadFullPath) {
|
|
75
89
|
preload = ` import "/${path.relative(cwd, preloadFullPath)}";\n`;
|
|
76
90
|
} else {
|
|
77
|
-
dir
|
|
91
|
+
dir = path.resolve(dir, '..');
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
return preload;
|
|
82
96
|
};
|
|
83
|
-
|
|
97
|
+
|
|
84
98
|
const htmlFullpath = isExist('.html');
|
|
85
99
|
if (htmlFullpath) {
|
|
86
100
|
return fs.readFileSync(htmlFullpath).toString();
|
|
@@ -118,7 +132,6 @@ const getVirtualHtml = async (url: string) => {
|
|
|
118
132
|
}
|
|
119
133
|
};
|
|
120
134
|
|
|
121
|
-
|
|
122
135
|
// alias
|
|
123
136
|
const require$ = createRequire(cwd);
|
|
124
137
|
const getPackageName = (name: string) => (require$(path.resolve(cwd, workspace ? `${workspace}/${name}` : '', 'package.json'))).name;
|
|
@@ -128,27 +141,27 @@ const name = getPackageName('index');
|
|
|
128
141
|
export default defineConfig({
|
|
129
142
|
resolve: workspace
|
|
130
143
|
? {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
alias: [
|
|
145
|
+
{
|
|
146
|
+
find: new RegExp(`^${name}$`),
|
|
147
|
+
replacement: replacement('index')
|
|
148
|
+
},
|
|
149
|
+
...Object.keys(subpackagesMap).reduce((pre, cur: string) => {
|
|
150
|
+
if (subpackagesMap[cur].length) {
|
|
151
|
+
pre.push({
|
|
152
|
+
find: new RegExp(`^${getPackageName(cur)}$`),
|
|
153
|
+
replacement: replacement(cur, true)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return pre;
|
|
157
|
+
}, [] as any),
|
|
158
|
+
{
|
|
159
|
+
|
|
160
|
+
find: new RegExp(`^${name}-(.*?)$`),
|
|
161
|
+
replacement: replacement('$1')
|
|
142
162
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
|
|
147
|
-
find: new RegExp(`^${name}-(.*?)$`),
|
|
148
|
-
replacement: replacement('$1')
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
152
165
|
: {},
|
|
153
166
|
plugins: [
|
|
154
167
|
{
|
|
@@ -156,13 +169,13 @@ export default defineConfig({
|
|
|
156
169
|
configureServer(server: ViteDevServer) {
|
|
157
170
|
server.middlewares.use(async (req, res, next) => {
|
|
158
171
|
if (res.writableEnded) {
|
|
159
|
-
|
|
172
|
+
return next();
|
|
160
173
|
}
|
|
161
174
|
if (req.url!.includes('html-proxy&')) {
|
|
162
175
|
return next();
|
|
163
176
|
}
|
|
164
177
|
|
|
165
|
-
|
|
178
|
+
const url = req.url?.replace(/[?#].*$/s, '') || '';
|
|
166
179
|
if (url === '/') return res.end(html);
|
|
167
180
|
|
|
168
181
|
// 文件已存在,这样xxx.png可以被获取,真实路径的.ts,.html都可以被获取
|
|
@@ -172,7 +185,7 @@ export default defineConfig({
|
|
|
172
185
|
|
|
173
186
|
let vHtml = await getVirtualHtml(url);
|
|
174
187
|
if (
|
|
175
|
-
(url?.endsWith('.html') || vHtml)
|
|
188
|
+
(url?.endsWith('.html') || vHtml)
|
|
176
189
|
&& req.headers['sec-fetch-dest'] !== 'script'
|
|
177
190
|
) {
|
|
178
191
|
if (!vHtml) {
|
|
@@ -191,4 +204,4 @@ export default defineConfig({
|
|
|
191
204
|
|
|
192
205
|
// 因为virtualHtml不需要入口,这样可以不弹出Skipping dependency pre-bundling.
|
|
193
206
|
optimizeDeps: { entries: [] }
|
|
194
|
-
}) as UserConfig;
|
|
207
|
+
}) as UserConfig;
|